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 その13

Last updated at Posted at 2023-11-26

概要

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

練習問題

オブジェクトからd3.hierarchy用の木構造を写し取る。

方針

  • 再帰でやる。

サンプルコード

function maketree(obj) {
	var obj2 = {};
	Object.keys(obj).forEach(function(key) {
		if (key == "Name")
		{
			obj2["name"] = obj.Name.Data;
		}
		if (key == "Children")
		{
			if (obj.Children != [])
			{
				obj2["children"] = [];
				obj.Children.forEach((childNode) => {
					obj2.children.push(maketree(childNode));
				});
			}
		}
	})
	return obj2;
}

実行結果

{"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":[]}]}]}]}]}]}]}]}

成果物

以上。

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?