-
PauJune 30, 2016 at 6:24 am #6284
Hi,
Could you be more specific on implementing the example with JSON? I’ve done the following changes using the example JSON you provided but it does not work.
function loadData() { d3.json("data/flare.json", function(json){ data.values=prepData(json); console.log(data.values); initialize(); }) }
function prepData(nest) { var values=[]; //This will be a viz.data function; vizuly.data.aggregateNest(nest, valueFields, function (a, b) { return Number(a) + Number(b); }); //Remove empty child nodes left at end of aggregation and add unqiue ids function removeEmptyNodes(node,parentId,childId) { if (!node) return; node.id=parentId + "_" + childId; if (node.values) { for(var i = node.values.length - 1; i >= 0; i--) { node.id=parentId + "_" + i; if(!node.values[i].key && !node.values[i].Level4) { node.values.splice(i, 1); } else { removeEmptyNodes(node.values[i],node.id,i) } } } } var node={}; node.values = nest; removeEmptyNodes(node,"0","0"); return nest; }
viz.data(data) // Expects hierarchical array of objects. .width(600) // Width of component .height(600) // Height of component .children(function (d) { return d.children }) // Denotes the property that holds child object array .key(function (d) { return d.name }) // Unique key .value(function (d) { return Number(d["agg_" + valueField]) }) // The property of the datum that will be used for the branch and node size .fixedSpan(-1) // fixedSpan > 0 will use this pixel value for horizontal spread versus auto size based on viz width .label(function (d) { // returns label for each node. return trimLabel(d.key || (d['Level' + d.depth]))}) .on("measure",onMeasure) // Make any measurement changes .on("mouseover",onMouseOver) // mouseover callback - all viz components issue these events .on("mouseout",onMouseOut) // mouseout callback - all viz components issue these events .on("click",onClick);
I specially don’t get how to change this last snippet.
Thanks!
You must be logged in to reply to this topic.
© 2024 — vizuly.io