d3.dart
d3.dart copied to clipboard
Primitive Map object of dart is not working in Force
In the great example -- force
Instead of using the d3 json method to retrieve data, I use a dart Map object directly, then the Force is not working.
original code:
json("miserables.json").then((graph) {
force
..nodes = graph['nodes']
..links = graph['links']
..start();
var link =
svg.selectAll(".link").data(graph['links']).enter().append("line")
..attr["class"] = "link"
..styleFn["stroke-width"] = (d) => math.sqrt(d['value']);
....
and I comment out the json method, and set data to Force with a dart Map object like this:
var graph = {
"nodes": [
{"name": "Myriel", "group": 1},
{"name": "Napoleon", "group": 2}
],
"links": [
{"source": 0, "target": 1, "value": 1},
{"source": 1, "target": 2, "value": 8}
]
};
// json("miserables.json").then((graph) {
force
..nodes = graph['nodes']
..links = graph['links']
..start();
...
the 'graph' data supposed is equivalent by these 2 means, but Force is not working anymore.