{"id":4081,"date":"2015-02-06T18:49:03","date_gmt":"2015-02-06T09:49:03","guid":{"rendered":"https:\/\/gunmagisgeek.com\/wordpress\/?p=4081"},"modified":"2015-02-06T18:49:03","modified_gmt":"2015-02-06T09:49:03","slug":"post-4081","status":"publish","type":"post","link":"https:\/\/gunmagisgeek.com\/blog\/d3-js\/4081","title":{"rendered":"\u5f62\u304c\u304b\u3063\u3053\u3044\u3044\u9806\u306b\u90fd\u9053\u5e9c\u770c\u3092\u4e26\u3079\u3066\u307f\u305f\u3002"},"content":{"rendered":"<p><a href=\"http:\/\/shimz.me\/example\/d3js\/geo_example2\/prefrank\/index.html\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2015\/02\/prefcoolrankthm-e1423206654257.jpg\" alt=\"prefcoolrankthm\" width=\"690\" height=\"506\" class=\"aligncenter size-full wp-image-4082 border\" srcset=\"https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2015\/02\/prefcoolrankthm-e1423206654257.jpg 690w, https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2015\/02\/prefcoolrankthm-e1423206654257-205x150.jpg 205w\" sizes=\"auto, (max-width: 690px) 100vw, 690px\" \/><\/a><\/p>\n<p><a href=\"http:\/\/ranking.goo.ne.jp\/ranking\/category\/056\/4ruPipfGNy0v\/p1\/\">\u300c\u5f62\u304c\u304b\u3063\u3053\u3044\u3044\u300d\u3068\u601d\u3046\u90fd\u9053\u5e9c\u770c\u30e9\u30f3\u30ad\u30f3\u30b0 &#8211; goo\u30e9\u30f3\u30ad\u30f3\u30b0<\/a><\/p>\n<p>Goo\u306e\u30e9\u30f3\u30ad\u30f3\u30b0\u3067\u300c\u5f62\u304c\u304b\u3063\u3053\u3044\u3044\u300d\u90fd\u9053\u5e9c\u770c\u30e9\u30f3\u30ad\u30f3\u30b0\u304c\u516c\u958b\u3055\u308c\u3066\u3044\u305f\u306e\u3067\u3001\u5b9f\u969b\u306e\u90fd\u9053\u5e9c\u770c\u3092\u304b\u3063\u3053\u3044\u3044\u9806\u306b\u4e26\u3079\u3066\u307f\u307e\u3057\u305f\u3002<br \/>\n\u2193\u3053\u3093\u306a\u611f\u3058<\/p>\n<p><a href=\"http:\/\/shimz.me\/example\/d3js\/geo_example2\/prefrank\/index.html\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2015\/02\/prefcoolrank-129x1024.jpg\" alt=\"prefcoolrank\" width=\"129\" height=\"1024\" class=\"size-large wp-image-4083 border\" srcset=\"https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2015\/02\/prefcoolrank-129x1024.jpg 129w, https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2015\/02\/prefcoolrank-19x150.jpg 19w\" sizes=\"auto, (max-width: 129px) 100vw, 129px\" \/><\/a><\/p>\n<p>\u308f\u308a\u3068\u30a4\u30e1\u30fc\u30b8\u306e\u4e2d\u306b\u6d6e\u304b\u3076\u770c\u306e\u5f62\u3068\u3001\u5b9f\u969b\u306e\u5f62\u306b\u306f\u30ae\u30e3\u30c3\u30d7\u304c\u3042\u308b\u306e\u304b\u306a\u3068\u3002<br \/>\n\uff08\u5730\u5143\u6c11\u306f\u305d\u3093\u306a\u3053\u3068\u306a\u3044\u306e\u3067\u3057\u3087\u3046\u3051\u3069\uff09<\/p>\n<p>\u3042\u3068\u3001\u5317\u6d77\u9053\u5927\u304d\u3059\u304e\u3002<\/p>\n<p><a href=\"http:\/\/shimz.me\/example\/d3js\/geo_example2\/prefrank\/index.html\">example<\/a><\/p>\n<p>\u30af\u30ea\u30c3\u30af\u3059\u308b\u3068\u300c\u304b\u3063\u3053\u3044\u3044\u9806\u300d\u3068\u300c\u5143\u306e\u5730\u56f3\u306e\u5f62\u300d\u3068\u306b\u5207\u308a\u66ff\u308f\u308a\u307e\u3059\u3002<\/p>\n<h2>\u30b5\u30f3\u30d7\u30eb<\/h2>\n<pre class=\"lang:js decode:true \" >d3.json(\"prefrank.geojson\", function(json) {\r\n\td3main(json);\r\n});\r\n\r\n\r\nfunction d3main(json){\r\n\r\n\tvar tooltip = d3.select(\"body\")\r\n\t\t.append(\"div\")\r\n\t\t.attr(\"class\", \"tooltip\")\r\n\t\t.style(\"position\", \"absolute\")\r\n\t\t.style(\"z-index\", \"10\")\r\n\t\t.style(\"visibility\", \"hidden\");\r\n\r\n\tvar geodata = json.features;\r\n\r\n\tprojection = d3.geo\r\n\t    .mercator()\t\t\r\n\t    .scale(3000)\t\r\n\t    .translate([800,650])\r\n\t    .center([139.0032936, 36.3219088]); \r\n\r\n\tvar path = d3.geo.path().projection(projection);\u3000\r\n\r\n\tvar svg = d3.select(\"svg\");\t\r\n\r\n\tvar japan =  svg.append(\"svg:g\")\r\n\t\t.selectAll(\"path\")\r\n\t\t.data(geodata)\r\n\t\t.enter()\r\n\t\t.append(\"g\");\r\n\t\t\r\n\t\tjapan.append(\"svg:path\")\r\n\t\t.attr({\r\n\t\t\t\"d\": path,\r\n\t\t\t\"fill\": \"green\",\r\n\t\t\t\"fill-opacity\": 0.5,\r\n\t\t\t\"stroke\": \"black\"\r\n\t\t})\r\n\t\t.on(\"mouseover\", function(){\r\n\t\t\ttooltip.style(\"visibility\", \"visible\");\r\n\t\t})\t\t\r\n\t\t.on(\"mousemove\", function(d){\r\n\t\t\ttooltip\r\n\t\t\t.style(\"top\", (d3.event.pageY-10)+\"px\")\r\n\t\t\t.style(\"left\",(d3.event.pageX+10)+\"px\")\r\n\t\t\t.html(\r\n\t\t\t\t\"&lt;h2&gt;\" + d.properties.rank + \"\u4f4d \"+ d.properties.ObjName  + \"&lt;\/h2&gt;\"\r\n\t\t\t);\r\n\t\t})\r\n\t\t.on(\"mouseout\", function(){\r\n\t\t\ttooltip.style(\"visibility\", \"hidden\");\r\n\t\t})\t\t\t\r\n\t\t\r\n\t\tvar rankOrder = function(){\r\n\t\t\tjapan.transition().attr(\"transform\", function(d, i){\r\n\t\t\t\tvar center = path.centroid(d); \r\n\t\t\t\tvar x = ~~center[0]; \r\n\t\t\t\tvar y = ~~center[1];\r\n\t\t\t\tvar nx = 200; \r\n\t\t\t\tvar ny = d.properties.rank * 160 + 100; \r\n\t\t\t\treturn \"translate(\"+(0-x)+\",\"+(0-y)+\"),translate(\"+nx+\",\"+ny+\")\";\t\t    \r\n\t\t\t}).duration(4000);\t\t\t\r\n\t\t}\r\n\t\t\r\n\t\tvar mapOrder = function(){\r\n\t\t\tjapan.transition().attr(\"transform\", \"translate(0, 0)\").duration(4000);\t\t\r\n\t\t}\r\n\t\t\r\n\t\td3.select(\"body\").on(\"click\", toggle(mapOrder, rankOrder));\r\n\t\t\r\n\t\trankOrder();\r\n}\r\n\r\nfunction toggle(){\r\n    var fn = arguments;\r\n    var l = arguments.length;\r\n    var i = 0;\r\n    return function(){\r\n        if(l &lt;= i) i=0;\r\n        fn[i++]();            \r\n    }\r\n}<\/pre>\n<p>\u5b9f\u306e\u3068\u3053\u308d\u3001\u4ee5\u524d\u4f5c\u3063\u305f\u4e0b\u8a18\u8a18\u4e8b\u306e\u30b3\u30fc\u30c9\u3092\u3061\u3087\u3053\u3063\u3068\u5909\u3048\u305f\u3060\u3051\u3060\u3063\u305f\u308a\u3057\u307e\u3059\u3002<\/p>\n<p><a href=\"https:\/\/gunmagisgeek.com\/blog\/d3-js\/3147\">\u3010D3.js\u3011SVG\u3067\u4f5c\u6210\u3057\u305f\u90fd\u9053\u5e9c\u770c\u306e\u5730\u5f62\u3092\u4e26\u3079\u3066\u8868\u793a\u3059\u308b<\/a><br \/>\n<a href=\"https:\/\/gunmagisgeek.com\/blog\/d3-js\/3742\">\u3010D3.js\u3011Force-Directed Japan<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u300c\u5f62\u304c\u304b\u3063\u3053\u3044\u3044\u300d\u3068\u601d\u3046\u90fd\u9053\u5e9c\u770c\u30e9\u30f3\u30ad\u30f3\u30b0 &#038;#8&hellip;<\/p>\n","protected":false},"author":1,"featured_media":4082,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[],"class_list":["post-4081","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\/4081","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=4081"}],"version-history":[{"count":0,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/4081\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/media\/4082"}],"wp:attachment":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/media?parent=4081"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/categories?post=4081"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/tags?post=4081"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}