The normal approach in D3 is to have lists of data associated with nodes. See Data Section in Selection API . D3 puts this in the __data__ property of the __data__ nodes that it creates / modifies. Internally, D3 pulls out this property and passes it as a parameter to various functions, but you can directly access it directly.
You can also associate an arbitrary data structure with a single node using the Datum method .
Without the rest of the context, this is hard to say, but below is a modified version of what I think you are trying to do:
var vis = d3.select("body").append("svg").attr("width", 400).attr("height", 300); var groupData = {x: 100, y:100, height: 50, width: 50, theanswer : 42, thecolor: "blue", somedouble: 45.1651654 }; var embeddedElemContainer = vis.append('svg:g') .datum( groupData ) .attr( 'id', 'mygroup' ) .attr( 'x', function(d) { return dx; } ) .attr( 'y', function(d) { return dy; } ) .attr( 'height', function(d) { return d.height; } ) .attr( 'width', function(d) { return d.width; } )
Both console.log outputs are output:
height: 50 somedouble: 45.1651654 theanswer: 42 thecolor: "blue" width: 50 x: 100 y: 100
explunit
source share