{"id":3147,"date":"2013-11-14T09:03:16","date_gmt":"2013-11-14T00:03:16","guid":{"rendered":"https:\/\/gunmagisgeek.com\/wordpress\/?p=3147"},"modified":"2013-12-30T18:12:17","modified_gmt":"2013-12-30T09:12:17","slug":"post-3147","status":"publish","type":"post","link":"https:\/\/gunmagisgeek.com\/blog\/d3-js\/3147","title":{"rendered":"\u3010D3.js\u3011SVG\u3067\u4f5c\u6210\u3057\u305f\u90fd\u9053\u5e9c\u770c\u306e\u5730\u5f62\u3092\u4e26\u3079\u3066\u8868\u793a\u3059\u308b"},"content":{"rendered":"<p><a href=\"http:\/\/shimz.me\/example\/d3js\/geo_example2\/prefList\/\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2013\/11\/preflist.jpg\" alt=\"preflist\" width=\"590\" height=\"278\" class=\"aligncenter border size-full wp-image-3148\" srcset=\"https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2013\/11\/preflist.jpg 590w, https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2013\/11\/preflist-300x141.jpg 300w\" sizes=\"auto, (max-width: 590px) 100vw, 590px\" \/><\/a><\/p>\n<p><a href=\"http:\/\/shimz.me\/example\/d3js\/geo_example2\/prefList\/\">example<\/a><\/p>\n<p>\u898b\u305f\u307e\u3093\u307e\u3067\u3059\u3002<br \/>\nD3.js\u3067GeoJSON\u30c7\u30fc\u30bf\u3092\u8aad\u307f\u8fbc\u307f\u3001svg\u306ePath\u3067\u5730\u5f62\u3092\u63cf\u753b\u3057\u4e26\u3079\u3066\u8868\u793a\u3057\u3066\u3044\u307e\u3059\u3002<br \/>\n\u30dd\u30a4\u30f3\u30c8\u306f\u5404\u90fd\u9053\u5e9c\u770c\u306e\u4e2d\u5fc3\u5ea7\u6a19\u3092\u53d6\u5f97\u3057translate\u3067\u4e2d\u5fc3\u5ea7\u6a19\u306exy\u3092\u5f15\u304f\u3053\u3068\u3067\u3001\u4e00\u65e6\u5168\u3066\u306e\u5730\u5f62\u306e\u5ea7\u6a19\u30920,0\u306b\u521d\u671f\u5316\u3057\u3066\u3044\u308b\u3068\u3053\u308d\u3067\u3059\u3002<br \/>\n\u6c96\u7e04\u770c\u3060\u3051\u3001\u4e2d\u5fc3\u70b9\u306e\u5ea7\u6a19\u304c\u4e0a\u624b\u304f\u53d6\u5f97\u3067\u304d\u305a\u5909\u306a\u5834\u6240\u306b\u8868\u793a\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n<h2>\u30b5\u30f3\u30d7\u30eb<\/h2>\n<pre class=\"lang:js mark:26-32 decode:true \" >d3.json(&quot;japan.geojson&quot;, function(json) {\r\n\td3main(json);\r\n});\r\n\r\n\r\nfunction d3main(json){\r\n\r\n\tvar geodata = json.features;\r\n\r\n\tprojection = d3.geo\r\n\t    .mercator()\t\t\/\/\u6295\u5f71\u6cd5\u306e\u6307\u5b9a\r\n\t    .scale(1500)\t\/\/\u30b9\u30b1\u30fc\u30eb\uff08\u30ba\u30fc\u30e0\uff09\u306e\u6307\u5b9a\r\n\t    .translate([300,350])\r\n\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\/\/\u6295\u5f71\r\n\r\n\tvar svg = d3.select(&quot;svg&quot;);\t\r\n\r\n\tvar map =  svg.append(&quot;svg:g&quot;)\r\n\t\t.selectAll(&quot;path&quot;)\r\n\t\t.data(geodata)\r\n\t\t.enter()\r\n\t\t.append(&quot;g&quot;)\r\n\t\t.attr(&quot;transform&quot;, function(d, i){\r\n\t\t    var center = path.centroid(d); \/\/\u4e2d\u5fc3\u70b9\u53d6\u5f97\r\n\t\t    var x = ~~center[0]; \r\n\t\t    var y = ~~center[1];\r\n\t\t    var nx = Math.floor(i%10) * 150 + 100; \/\/\u4e26\u3073\u4f4d\u7f6e(x\u8ef8)\r\n\t\t    var ny = Math.floor(i\/10) * 120 + 100; \/\/\u4e26\u3073\u4f4d\u7f6e(y\u8ef8)\r\n\t\t    \/\/\u4e2d\u5fc3\u70b9\u5206\u3092\u5f15\u3044\u3066\u4e00\u5ea6\u5ea7\u6a19\u3092x=0,y=0\u306b\u623b\u3059\u3002\u305d\u306e\u5f8cnx,ny\u306e\u4f4d\u7f6e\u306b\u8868\u793a\r\n\t\t    return &quot;translate(-&quot;+x+&quot;,-&quot;+y+&quot;),translate(&quot;+nx+&quot;,&quot;+ny+&quot;)&quot;;\t\t    \r\n\t\t})\r\n\t\t.append(&quot;svg:path&quot;)\r\n\t\t.attr({\r\n\t\t\t&quot;d&quot;: path,\r\n\t\t\t&quot;fill&quot;: &quot;green&quot;,\r\n\t\t\t&quot;fill-opacity&quot;: 0.5,\r\n\t\t\t&quot;stroke&quot;: &quot;black&quot;\r\n\t\t})\r\n\t\t.append(&quot;title&quot;)\r\n\t\t.text(function(d){ return d.properties.PREF })\r\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>example \u898b\u305f\u307e\u3093\u307e\u3067\u3059\u3002 D3.js\u3067Ge&hellip;<\/p>\n","protected":false},"author":1,"featured_media":3148,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[],"class_list":["post-3147","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\/3147","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=3147"}],"version-history":[{"count":0,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/3147\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/media\/3148"}],"wp:attachment":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/media?parent=3147"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/categories?post=3147"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/tags?post=3147"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}