ここに私のコードがあります:1ページに多くの電子メールスレッドのトピックごとに複数のデンドグラムが必要です:
var w = 1350, h;
var margin = {top: 20, right: 120, bottom: 20, left: 120}
var tree = d3.layout.tree();
//.size([h, w - 160]);
var diagonal = d3.svg.diagonal().projection(function(d) {
return [d.y, d.x];
});
// .attr("width", w + 200)
// .attr("height", h + 160)
//.append("svg:g")
// .attr("transform", "translate(40, 0)");
d3.json("flare2.json", function(error, json) {
for (var tree_key in json.children) {
build_tree(json.children[tree_key])
}
});
function build_tree(tree_obj) {
var vis = d3.select("#chart").append("svg:svg")
h = 20
h = h + (tree_obj.count * 15)
tree.size([h, w]);
vis.attr("width", w +1000)
.attr("height", h)
var nodes = tree.nodes(tree_obj);
var link = vis.selectAll("path.link").data(tree.links(nodes)).enter().append("svg:path").attr("class", "link").attr("d", diagonal);
// .attr("d", diagonal);
var node = vis.selectAll("g.node").data(nodes).enter().append("svg:g").attr("class", "node").attr("transform", function(d) {
return "translate(" + d.y + "," + d.x + ")";
})
node.append("svg:circle").attr("r", 4.5);
node.append("svg:text").attr("dx", function(d) {
return d.children ? -8 : 8;
}).attr("dy", 3).attr("text-anchor", function(d) {
return d.children ? "end" : "start";
}).text(function(d) {
return d.name;
});
}
この結果:
それらを表示する方法がわかりません。翻訳しようとしましたが、うまくいきません。
svg ノードの結果は次のとおりです。
<svg width="2350" height="170"><path class="link" d="M0,85C225,85 225,17 450,17"></path><path class="link" d="M0,85C225,85 225,85 450,85"></path><path class="link" d="M0,85C225,85 225,153 450,153"></path><path class="link" d="M450,17C675,17 675,17 900,17"></path><path class="link" d="M900,17C1125,17 1125,17 1350,17"></path><path class="link" d="M450,85C675,85 675,85 900,85"></path><path class="link" d="M900,85C1125,85 1125,85 1350,85"></path><path class="link" d="M450,153C675,153 675,153 900,153"></path><path class="link" d="M900,153C1125,153 1125,153 1350,153"></path><g class="node" transform="translate(0,85)"><circle r="4.5"></circle><text dx="-8" dy="3" text-anchor="end">Re: Amusing atheists and anarchists</text></g><g class="node" transform="translate(450,17)"><circle r="4.5"></circle><text dx="-8" dy="3" text-anchor="end">Re: Amusing atheists and anarchists</text></g><g class="node" transform="translate(900,17)"><circle r="4.5"></circle><text dx="-8" dy="3" text-anchor="end">timmbake@mcl.ucsb.edu (Bake Timmons)</text></g><g class="node" transform="translate(1350,17)"><circle r="4.5"></circle><text dx="8" dy="3" text-anchor="start">alt.atheism</text></g><g class="node" transform="translate(450,85)"><circle r="4.5"></circle><text dx="-8" dy="3" text-anchor="end">Hard/Soft == Strong/Weak. KISS!</text></g><g class="node" transform="translate(900,85)"><circle r="4.5"></circle><text dx="-8" dy="3" text-anchor="end">mam@mouse.cmhnet.org (Mike McAngus)</text></g><g class="node" transform="translate(1350,85)"><circle r="4.5"></circle><text dx="8" dy="3" text-anchor="start">alt.atheism</text></g><g class="node" transform="translate(450,153)"><circle r="4.5"></circle><text dx="-8" dy="3" text-anchor="end">Re: Amusing atheists and anarchists</text></g><g class="node" transform="translate(900,153)"><circle r="4.5"></circle><text dx="-8" dy="3" text-anchor="end">mccullou@snake2.cs.wisc.edu (Mark McCullough)</text></g><g class="node" transform="translate(1350,153)"><circle r="4.5"></circle><text dx="8" dy="3" text-anchor="start">alt.atheism</text></g></svg>