{"id":3548,"date":"2014-05-31T11:18:06","date_gmt":"2014-05-31T02:18:06","guid":{"rendered":"https:\/\/gunmagisgeek.com\/wordpress\/?p=3548"},"modified":"2014-05-31T11:18:06","modified_gmt":"2014-05-31T02:18:06","slug":"post-3548","status":"publish","type":"post","link":"https:\/\/gunmagisgeek.com\/blog\/d3-js\/3548","title":{"rendered":"\u3010D3.js\u3011\u6587\u5b57\u3067\u65e5\u672c\u5730\u56f3\u66f8\u3044\u3066\u307f\u305f\u3002"},"content":{"rendered":"<p><a href=\"http:\/\/shimz.me\/example\/d3js\/geo_example3\/04\/\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2014\/05\/textPahtJapan.jpg\" alt=\"textPahtJapan\" width=\"590\" height=\"521\" class=\"aligncenter size-full wp-image-3546\" srcset=\"https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2014\/05\/textPahtJapan.jpg 590w, https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2014\/05\/textPahtJapan-170x150.jpg 170w\" sizes=\"auto, (max-width: 590px) 100vw, 590px\" \/><\/a><\/p>\n<p><a href=\"http:\/\/shimz.me\/example\/d3js\/geo_example3\/04\/index.html\">example<\/a><\/p>\n<p>\u307e\u305f\u3082\u3084\u5c0f\u30cd\u30bf\u3067\u3059\u3002<br \/>\n\u6587\u5b57\u3092\u4f7f\u3063\u3066\u65e5\u672c\u5730\u56f3\u3092\u63cf\u3044\u3066\u307f\u307e\u3057\u305f\u3002<br \/>\n\u5317\u6d77\u9053\u306f\u300cHokkaido\u300d\u3067\u3068\u3001\u4e00\u5fdc\u5404\u770c\u540d\u3067\u30a8\u30ea\u30a2\u3092\u63cf\u753b\u3057\u3066\u3044\u308b\u3093\u3067\u3059\u304c\u2026\u2026\u307e\u3063\u305f\u304f\u5206\u304b\u308a\u307e\u305b\u3093\u306d\u3002<\/p>\n<p>\u7dba\u9e97\u306b\u8868\u793a\u3059\u308b\u65b9\u6cd5\u304c\u5206\u304b\u3063\u305f\u3089\u3001\u307e\u305f\u6311\u6226\u3057\u3066\u307f\u305f\u3044\u3068\u304a\u3082\u3044\u307e\u3059\u3002<\/p>\n<h2>\u30b5\u30f3\u30d7\u30eb<\/h2>\n<p>\u30dd\u30a4\u30f3\u30c8\u306f\u5730\u5f62\u306epath\u3092def\u8981\u7d20\u306e\u4e2d\u306b\u63cf\u304d\u3001\u770c\u540d\u3092id\u3068\u3057\u3066textpath\u306b\u30ea\u30f3\u30af\u3055\u305b\u3066\u3044\u308b\u3068\u3053\u308d\u3067\u3059\u3002<br \/>\n\u3053\u308c\u3060\u3051\u3067\u3001path\u306b\u6cbf\u3063\u3066\u30c6\u30ad\u30b9\u30c8\u304c\u8868\u793a\u3055\u308c\u307e\u3059\u3002<\/p>\n<pre class=\"lang:js decode:true \" >d3.json(\"ken.topojson\", function(json) {\r\n\tdraw(json);\r\n});\r\n\r\n\r\nfunction draw(json){\r\n\tvar geodata = json.objects.ken;\r\n\t\r\n\tvar projection = d3.geo\r\n\t\t.mercator()\t\t\/\/\u6295\u5f71\u6cd5\u306e\u6307\u5b9a\r\n\t\t.scale(1900)\t\/\/\u30b9\u30b1\u30fc\u30eb\uff08\u30ba\u30fc\u30e0\uff09\u306e\u6307\u5b9a\r\n\t\t.translate([500,450]) \/\/\u8868\u793a\u4f4d\u7f6e\u8abf\u6574\r\n\t\t.center([139.0032936, 36.3219088]); \/\/\u4e2d\u5fc3\u306e\u5ea7\u6a19\u3092\u6307\u5b9a\r\n\r\n\tvar path = d3.geo.path().projection(projection);\u3000\/\/\u30d1\u30b9\u30b8\u30a7\u30cd\u30ec\u30fc\u30bf\u30fc\r\n\r\n\tvar svg = d3.select(\"svg\");\u3000\r\n\tvar def = svg.append(\"def\"); \/\/svg\u306b\u304a\u3051\u308b\u95a2\u6570\u306e\u3088\u3046\u306a\u8981\u7d20\u3002\u518d\u5229\u7528\u304c\u53ef\u80fd\r\n\t\t\r\n\t\/\/\u5730\u56f3\u63cf\u753b(path\u3092def\u5185\u306b\u4f5c\u6210)\r\n\tvar map = def.append(\"g\")\r\n\t\t.attr(\"class\", \"land\")\r\n\t\t.selectAll(\"path\")\r\n\t\t.data(topojson.feature(json, geodata).features)\r\n\t    .enter().append(\"path\")\r\n\t\t.attr(\"d\", path)\r\n\t\t.attr(\"stroke\", \"red\")\r\n\t\t.attr(\"id\", function(d){\r\n\t\t\t\/\/path\u306eid\u3068\u3057\u3066\u770c\u540d\u3092\u6307\u5b9a\r\n\t\t\treturn d.properties.ObjName_1;\r\n\t\t})\r\n\t\r\n\t\/\/\u30c6\u30ad\u30b9\u30c8\u8981\u7d20\u8ffd\u52a0\t\r\n\tvar text = svg.selectAll('text')\r\n\t\t.data(topojson.feature(json, geodata).features)\r\n\t\t.enter()\r\n\t\t.append(\"text\")\r\n\t\t.append(\"textPath\")\r\n\t\t.attr(\"xlink:href\", function(d){\r\n\t\t\t\/\/def\u306e\u4e2d\u306b\u66f8\u304d\u3053\u307e\u308c\u305fpath\u3092id\u3067\u547c\u3073\u51fa\u3057\u30c6\u30ad\u30b9\u30c8\u306b\u9069\u7528\u3059\u308b\r\n\t\t\treturn \"#\"+d.properties.ObjName_1;\r\n\t\t})\u3000\r\n\t\t.text(function(d){\r\n\t\t\tvar a = d3.range(0,50)\r\n\t\t\t.map(function(){ return d.properties.ObjName_1 });\r\n\t\t\treturn a\r\n\t\t})\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>example \u307e\u305f\u3082\u3084\u5c0f\u30cd\u30bf\u3067\u3059\u3002 \u6587\u5b57\u3092\u4f7f\u3063\u3066&hellip;<\/p>\n","protected":false},"author":1,"featured_media":3546,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[],"class_list":["post-3548","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-d3-js","has-post-thumbnail-archive"],"_links":{"self":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/3548","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/comments?post=3548"}],"version-history":[{"count":0,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/3548\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/media\/3546"}],"wp:attachment":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/media?parent=3548"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/categories?post=3548"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/tags?post=3548"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}