{"id":4125,"date":"2015-03-03T10:38:08","date_gmt":"2015-03-03T01:38:08","guid":{"rendered":"https:\/\/gunmagisgeek.com\/wordpress\/?p=4125"},"modified":"2015-03-03T10:38:08","modified_gmt":"2015-03-03T01:38:08","slug":"post-4125","status":"publish","type":"post","link":"https:\/\/gunmagisgeek.com\/blog\/d3-js\/4125","title":{"rendered":"\u524d\u6a4b\u5e02\u4e00\u6b21\u907f\u96e3\u5834\u6240"},"content":{"rendered":"<p>\u300c<a href=\"http:\/\/www.city.maebashi.gunma.jp\/sisei\/499\/509\/p012146.html\">\u524d\u6a4b\u5e02\u30aa\u30fc\u30d7\u30f3\u30c7\u30fc\u30bf\u30e9\u30a4\u30d6\u30e9\u30ea\u30fc<\/a>\u300d\u304b\u3089\u53d6\u5f97\u3057\u305f\u753a\u754c\u30c7\u30fc\u30bf\u3068\u4e00\u6b21\u907f\u96e3\u5834\u6240\u30c7\u30fc\u30bf\u3092D3\u3092\u4f7f\u3063\u3066\u8996\u899a\u5316\u3057\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<p>\u4e00\u6b21\u907f\u96e3\u5834\u6240\u306e\u4f4d\u7f6e\u3092\u6bcd\u70b9\u3068\u3057\u305f\u30dc\u30ed\u30ce\u30a4\u56f3\u3092\u63cf\u304d\u3001\u753a\u754c\u30c7\u30fc\u30bf\u3067\u30de\u30b9\u30af\u3092\u304b\u3051\u3066\u3044\u307e\u3059\u3002<br \/>\n\u30dc\u30ed\u30ce\u30a4\u9818\u57df\u306e\u5857\u308a\u5206\u3051\u30ab\u30e9\u30fc\u306f\u30e9\u30f3\u30c0\u30e0\u3002<br \/>\n\u5404\u30bb\u30eb(\u30dc\u30ed\u30ce\u30a4\u9818\u57df)\u304c\u6bcd\u70b9\u3068\u306a\u308b\u4e00\u6b21\u907f\u96e3\u5834\u6240\u306e\u304a\u304a\u3088\u305d\u306e\u62c5\u5f53\u9818\u57df\u307f\u305f\u3044\u306a\u611f\u3058\u306b\u306a\u308b\u308f\u3051\u3067\u3059\u304c\u3001\u5317\u306e\u65b9\u306f\u3060\u3044\u3076\u907f\u96e3\u6240\u307e\u3067\u9060\u3044\u3067\u3059\u306d\u3002<br \/>\n\u3053\u306e\u5730\u57df\u3067\u707d\u5bb3\u304c\u767a\u751f\u3057\u305f\u5834\u5408\u306e\u624b\u7b48\u304c\u3069\u3046\u306a\u3063\u3066\u3044\u308b\u306e\u304b\u306f\u5f8c\u3067\u8abf\u3079\u3066\u307f\u305f\u3044\u3068\u304a\u3082\u307e\u3059\u3002<\/p>\n<h2>\u30b5\u30f3\u30d7\u30eb<\/h2>\n<p><a href=\"http:\/\/shimz.me\/datavis\/gunma\/maebashi\/hinanbasho\/\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2015\/03\/64e52191c726b46b0fec27798f2cdef1.jpg\" alt=\"\u524d\u6a4b\u5e02\u4e00\u6b21\u907f\u96e3\u5834\u6240\" width=\"690\" height=\"388\" class=\"aligncenter size-full wp-image-4126 border\" srcset=\"https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2015\/03\/64e52191c726b46b0fec27798f2cdef1.jpg 690w, https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2015\/03\/64e52191c726b46b0fec27798f2cdef1-267x150.jpg 267w\" sizes=\"auto, (max-width: 690px) 100vw, 690px\" \/><\/a><\/p>\n<p><a href=\"http:\/\/shimz.me\/datavis\/gunma\/maebashi\/hinanbasho\/\">example<\/a><\/p>\n<p>\u30de\u30a6\u30b9\u30db\u30a4\u30fc\u30eb\u3067\u30d1\u30f3\uff0f\u30ba\u30fc\u30e0\u304c\u3001\u30c9\u30e9\u30c3\u30b0\u3067\u79fb\u52d5\u3067\u304d\u307e\u3059\u3002<br \/>\n\u753a\u5883\u306b\u30de\u30a6\u30b9\u30aa\u30fc\u30d0\u30fc\u3059\u308b\u3068\u30a8\u30ea\u30a2\u3092\u5f37\u8abf(\u8d64)\u3057\u305f\u4e0a\u3067\u30c4\u30fc\u30eb\u30c1\u30c3\u30d7\u3067\u4eba\u53e3\u3068\u4e16\u5e2f\u6570\u3092\u8868\u793a\u3002\u6bcd\u70b9(\u4e00\u6b21\u907f\u96e3\u5834\u6240)\u306b\u30de\u30a6\u30b9\u30aa\u30fc\u30d0\u30fc\u3059\u308b\u3068\u30dc\u30ed\u30ce\u30a4\u9818\u57df\u306e\u5354\u8abf(\u8d64)\u3068\u907f\u96e3\u5834\u6240\u306e\u540d\u79f0\u3068\u4f4f\u6240\u3092\u8868\u793a\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"lang:js decode:true \" >d3.json(\"maebashi_light.geojson\", function(maebashi) {\r\n\t\td3.json('refuge.geojson', function(refuge){\r\n\t\t\tdraw(maebashi, refuge);\r\n\t\t});\r\n});\r\n\r\n\r\nfunction draw(maebashi,refuge){\r\n\tvar geodata = maebashi.features;\t\/\/\u524d\u6a4b\u753a\u5883\u5730\u7406\u30c7\u30fc\u30bf\r\n\tvar pointdata = refuge.features;\t\/\/\u907f\u96e3\u6240\u30dd\u30a4\u30f3\u30c8\u30c7\u30fc\u30bf\r\n\tvar positions = [];\r\n\tvar  colorGen= function(){ \t\/\/\u30ab\u30e9\u30fc\u30b8\u30a7\u30cd\u30ec\u30fc\u30bf\u30fc\r\n\t    return '#'+Math.floor(Math.random()*16777215).toString(16); \r\n\t}\r\n\r\n\t\/\/\u30c4\u30fc\u30eb\u30c1\u30c3\u30d7\u8981\u7d20\u8ffd\u52a0\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 svg = d3.select(\"svg\");\r\n\tvar mask = svg.append(\"defs\").append(\"mask\").attr(\"id\", \"mask\").append(\"g\");\r\n\r\n\t\/\/\u30d7\u30ed\u30b8\u30a7\u30af\u30b7\u30e7\u30f3\u8a2d\u5b9a\r\n\tvar projection = d3.geo\r\n\t\t.mercator()\t\t\/\/\u6295\u5f71\u6cd5\u306e\u6307\u5b9a\r\n\t\t.scale(200000)\t\/\/\u30b9\u30b1\u30fc\u30eb\uff08\u30ba\u30fc\u30e0\uff09\u306e\u6307\u5b9a\r\n\t\t.translate([400,600])\r\n\t\t.center([139.0634281, 36.3894816]); \/\/\u4e2d\u5fc3\u306e\u5ea7\u6a19\u3092\u6307\u5b9a\r\n\r\n\t\/\/geo\u30d1\u30b9\u30b8\u30a7\u30cd\u30ec\u30fc\u30bf\u30fc\u751f\u6210\r\n\tvar path = d3.geo.path().projection(projection);\u3000\r\n\r\n\t\t\/\/cell\u3092\u8868\u793a\u3059\u308b\u30b0\u30eb\u30fc\u30d7\u3092\u4f5c\u6210\r\n\t\tvar cellgroup = svg.append(\"svg:g\").attr(\"id\", \"cells\"); \r\n\r\n\r\n\t\tpointdata.forEach(function(d) {\r\n\t\t\tvar xy = projection(d.geometry.coordinates);\r\n\t\t\tpositions.push({x:xy[0], y:xy[1], targetClass:\".cell\"+d.properties['OBJECTID'], properties:d.properties}); \/\/\u4f4d\u7f6e\u60c5\u5831\u2192\u30d4\u30af\u30bb\u30eb\r\n\t\t});\r\n\r\n\t\t\/\/\u30dc\u30ed\u30ce\u30a4\u5909\u63db\u95a2\u6570\r\n\t\tvar voronoi = d3.geom.voronoi()\r\n\t\t\t.x(function(d){ return d.x })\r\n\t\t\t.y(function(d){ return d.y });\r\n\t\t\r\n\t\tvar polygons = voronoi(positions);\r\n\r\n\t\t\/\/\u5883\u754c\u8981\u7d20\u8ffd\u52a0\r\n\t\tvar cell = svg.selectAll(\".voronoi\")\r\n\t\t\t\t.data(pointdata)\r\n\t\t\t\t.enter()\r\n\t\t\t\t.append(\"svg:path\")\r\n\t\t\t\t.attr({\r\n\t\t\t\t\t\"class\":function(d, i){return \"voronoi cell\" + pointdata[i].properties['OBJECTID']}, \r\n\t\t\t\t\t\"d\":function(d, i) {if(!polygons[i]) return ; return \"M\" + polygons[i].join(\"L\") + \"Z\"},\r\n\t\t\t\t\t\"stroke\": \"#ccc\",\r\n\t\t\t\t\t\"stroke-width\":2,\r\n\t\t\t\t\tfill:function(d, i){ return colorGen() },\r\n\t\t\t\t\t\"fill-opacity\": 0.5,\r\n\t\t\t\t\t\"mask\":\"url(#mask)\"\r\n\t\t\t\t});\r\n\t\t\t\r\n\t\t\t\/\/\u5730\u5f62(\u30de\u30b9\u30af)\u8981\u7d20\u8ffd\u52a0\r\n\t\tvar maskmap = mask.append(\"g\")\r\n\t\t\t\t.selectAll(\".mask\")\r\n\t\t\t\t.data(geodata)\r\n\t\t\t\t.enter()\r\n\t\t\t\t.append(\"svg:path\")\r\n\t\t\t\t.attr({\r\n\t\t\t\t\t\"class\":\"mask\",\r\n\t\t\t\t\t\"d\":path,\r\n\t\t\t\t\t\"fill\":\"white\",\r\n\t\t\t\t\t\"stroke\": \"black\",\r\n\t\t\t\t\t\"stroke-width\":2\r\n\t\t\t\t});\t\t\t\r\n\r\n\t\t\/\/\u5730\u5f62(\u5f37\u8abf\u7528)\u8981\u7d20\u8ffd\u52a0\r\n\t\tvar map = svg.append(\"g\")\r\n\t\t\t\t.selectAll(\".map\")\r\n\t\t\t\t.data(geodata)\r\n\t\t\t\t.enter()\r\n\t\t\t\t.append(\"svg:path\")\r\n\t\t\t\t.attr({\r\n\t\t\t\t\t\"class\":\"map\",\r\n\t\t\t\t\t\"d\": path,\r\n\t\t\t\t\t\"fill\":\"white\",\r\n\t\t\t\t\t\"fill-opacity\":0,\r\n\t\t\t\t\t\"stroke\": \"white\",\r\n\t\t\t\t\t\"stroke-opacity\":1\r\n\t\t\t\t})\r\n\t\t\t\t.on(\"mouseover\", function(d) {\r\n\t\t\t\t\ttooltip.style(\"visibility\", \"visible\");\r\n\t\t\t\t})\r\n\t\t\t\t.on(\"mouseout\", function(d) {\r\n\t\t\t\t\ttooltip.style(\"visibility\", \"hidden\");\t\t\r\n\t\t\t\t})\r\n\t\t\t\t.on(\"mousemove\", function(d){\r\n\t\t\t\t\tvar content = \"&lt;h2&gt;\"+d.properties['\u753a\u540d']+\"&lt;\/h2&gt;\" +\r\n\t\t\t\t\t\"&lt;p&gt;\u4eba\u53e3\uff1a\" + d.properties['\u4eba\u53e3'] +\"&lt;\/p&gt;\" +\r\n\t\t\t\t\t\"&lt;p&gt;\u4e16\u5e2f\uff1a\" + d.properties['\u4e16\u5e2f'] + \"&lt;\/p&gt;\";\r\n\t\t\t\t\ttooltip\r\n\t\t\t\t\t .style(\"top\", (d3.event.pageY-10)+\"px\")\r\n\t\t\t\t\t .style(\"left\",(d3.event.pageX+10)+\"px\")\r\n\t\t\t\t\t .html(content);\r\n\t\t\t\t});\r\n\t\t\t\t\t\t\t\t\r\n\t\t\/\/\u6bcd\u70b9\u8981\u7d20\u8ffd\u52a0\r\n\t\tvar point = svg.selectAll(\"point\")\r\n\t\t\t.data(positions)\r\n\t\t\t.enter()\r\n\t\t\t.append(\"svg:circle\")\r\n\t\t\t.attr({\r\n\t\t\t\t\"cx\":function(d, i) { return positions[i].x; },\r\n\t\t\t\t\"cy\":function(d, i) { return positions[i].y; },\r\n\t\t\t\t\"r\":4,\r\n\t\t\t\tfill:\"#1f3134\"\r\n\t\t\t})\r\n\t\t\t.on(\"mouseover\", function(d) {\r\n\t\t\t\ttooltip.style(\"visibility\", \"visible\");\r\n\t\t\t\tconsole.log(d);\r\n\t\t\t\td3.selectAll(d.targetClass).classed(\"emphasis\", true);\r\n\t\t\t\t\r\n\t\t\t})\r\n\t\t\t.on(\"mouseout\", function(d) {\r\n\t\t\t\ttooltip.style(\"visibility\", \"hidden\");\t\t\r\n\t\t\t\td3.selectAll(d.targetClass).classed(\"emphasis\", false);\r\n\t\t\t})\r\n\t\t\t.on(\"mousemove\", function(d){\r\n\t\t\t\tvar content = \"&lt;center&gt;&lt;h2&gt;\u907f\u96e3\u6240&lt;h2&gt;&lt;\/center&gt;\" +\r\n\t\t\t\t\"&lt;p&gt;\u540d\u79f0\uff1a\" + d.properties['\u4e00\u6b21\u907f\u96e3\u6240'] +\"&lt;\/p&gt;\" +\r\n\t\t\t\t\"&lt;p&gt;\u6240\u5728\u5730\uff1a\" + d.properties['\u6240\u5728\u5730'] +\"&lt;\/p&gt;\" ;\r\n\t\t\t\ttooltip\r\n\t\t\t\t .style(\"top\", (d3.event.pageY-10)+\"px\")\r\n\t\t\t\t .style(\"left\",(d3.event.pageX+10)+\"px\")\r\n\t\t\t\t .html(content);\r\n\t\t\t});\r\n\r\n\t\t\/\/\u30c9\u30e9\u30c3\u30b0\u30a4\u30d9\u30f3\u30c8\u8a2d\u5b9a\r\n\t\tvar drag = d3.behavior.drag().on('drag', function(){\r\n\t\t\t\tvar tl = projection.translate();\r\n\t\t\t\tprojection.translate([tl[0] + d3.event.dx, tl[1] + d3.event.dy]);\r\n\t\t\t\tupdate();\r\n\t\t});\r\n\t\t\r\n\t\t\/\/\u30ba\u30fc\u30e0\u30a4\u30d9\u30f3\u30c8\u8a2d\u5b9a    \r\n\t\tvar zoom = d3.behavior.zoom().on('zoom', function(){\r\n\t\t   projection.scale(200000 * d3.event.scale);       \r\n\t\t   update();   \r\n\t\t});\r\n\t\t\r\n\t\t\/\/\u30a4\u30d9\u30f3\u30c8\u3092svg\u8981\u7d20\u306b\u675f\u7e1b\r\n\t\tsvg.call(zoom);\t \r\n\t\tsvg.call(drag);\r\n\r\n\t\t\r\n\t\t\/\/\u30ba\u30fc\u30e0\u30fb\u30c9\u30e9\u30c3\u30b0\u6642\u306e\u30a2\u30c3\u30d7\u30c7\u30fc\u3068\r\n\t\tfunction update(){\r\n\t\t\t\t\/\/\u5730\u5f62(\u5f37\u8abf\u7528)\u30a2\u30c3\u30d7\u30c7\u30fc\u30c8\r\n\t\t\t\tmap.attr('d', path);\r\n\t\t\t\t\/\/\u5730\u5f62(\u30de\u30b9\u30af)\u30a2\u30c3\u30d7\u30c7\u30fc\u30c8\r\n\t\t\t\tmaskmap.attr('d', path);\r\n\t\t\t\t\/\/\u30dc\u30ed\u30ce\u30a4\u30a2\u30c3\u30d7\u30c7\u30fc\u30c8\r\n\t\t\t\tvar positions = [];\r\n\t\t\t\tpointdata.forEach(function(d) {\r\n\t\t\t\t\tvar xy = projection(d.geometry.coordinates);\r\n\t\t\t\t\tpositions.push({x:xy[0], y:xy[1], targetClass:\".cell\"+d.properties['OBJECTID'], properties:d.properties}); \/\/\u4f4d\u7f6e\u60c5\u5831\u2192\u30d4\u30af\u30bb\u30eb\r\n\t\t\t\t});\r\n\t\t\t\tvar polygons = voronoi(positions);\r\n\t\t\t\tcell.attr(\"d\", function(d, i) {if(!polygons[i]) return ; return \"M\" + polygons[i].join(\"L\") + \"Z\"});\t\t\t\r\n\t\t\t\t\/\/\u6bcd\u70b9\u30a2\u30c3\u30d7\u30c7\u30fc\u30c8\t\r\n\t\t\t\tpoint.attr({\r\n\t\t\t\t\t\"cx\":function(d, i) { return positions[i].x; },\r\n\t\t\t\t\t\"cy\":function(d, i) { return positions[i].y; }\t\t\t\r\n\t\t\t\t});\t\t\t\t\r\n\t\t}\t\r\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u300c\u524d\u6a4b\u5e02\u30aa\u30fc\u30d7\u30f3\u30c7\u30fc\u30bf\u30e9\u30a4\u30d6\u30e9\u30ea\u30fc\u300d\u304b\u3089\u53d6\u5f97\u3057\u305f\u753a&hellip;<\/p>\n","protected":false},"author":1,"featured_media":4126,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[],"class_list":["post-4125","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\/4125","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=4125"}],"version-history":[{"count":0,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/4125\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/media\/4126"}],"wp:attachment":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/media?parent=4125"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/categories?post=4125"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/tags?post=4125"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}