0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

plunkerでd3 その12

Posted at

概要

plunkerでd3やってみた。
練習問題、やってみた。

練習問題

v5でtree表示せよ。

写真

image.png

サンプルコード

	var width = document.querySelector("svg").clientWidth;
	var height = document.querySelector("svg").clientHeight;
	var data2 = {"name":"test1","children":[{"name":"T","children":[{"name":"Visual","children":[{"name":"Canvas","children":[{"name":"Image","children":[{"name":"Image","children":[{"name":"ConnectPoint","children":[]}]},{"name":"Vertical Layout","children":[{"name":"Text","children":[]}]}]}]}]}]},{"name":"Display","children":[{"name":"Visual","children":[{"name":"Canvas","children":[{"name":"Image","children":[{"name":"Image","children":[{"name":"ConnectPoint","children":[{"name":"Wire","children":[]}]}]},{"name":"Vertical Layout","children":[{"name":"Vertical Layout","children":[{"name":"Text","children":[]}]}]}]}]}]}]}]};
	root = d3.hierarchy(data2);
	var tree = d3.tree().size([height, width - 160])
	tree(root);
	g = d3.select("svg").append("g").attr("transform", "translate(80,0)");
	var link = g.selectAll(".link").data(root.descendants().slice(1))
		.enter().append("path").attr("class", "link")
		.attr("d", function(d) {
			return "M" + d.y + "," + d.x +
				"C" + (d.parent.y + 100) + "," + d.x +
				" " + (d.parent.y + 100) + "," + d.parent.x +
				" " + d.parent.y + "," + d.parent.x;
		});
	var node = g.selectAll(".node").data(root.descendants())
		.enter().append("g").attr("class", "node")
		.attr("transform", function(d) { 
			return "translate(" + d.y + "," + d.x + ")"; 
		});
	node.append("circle").attr("r", 8).attr("fill", "#999");
  node.append("text").attr("dy", 3).attr("x", function(d) { 
		return d.children ? -12 : 12; 
	}).style("text-anchor", function(d) { 
		return d.children ? "end" : "start"; 
	}).attr("font-size", "200%").text(function(d) { 
		return d.data.name; 
	});




成果物

以上

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?