{"id":4052,"date":"2015-01-23T12:33:46","date_gmt":"2015-01-23T03:33:46","guid":{"rendered":"https:\/\/gunmagisgeek.com\/wordpress\/?p=4052"},"modified":"2018-03-06T11:53:18","modified_gmt":"2018-03-06T02:53:18","slug":"post-4052","status":"publish","type":"post","link":"https:\/\/gunmagisgeek.com\/blog\/d3v4\/4052","title":{"rendered":"\u5730\u8ef8\u3092\u50be\u3051\u306a\u304c\u3089SVG\u3067\u5730\u7403\u5100\u3092\u8868\u793a\u3059\u308b"},"content":{"rendered":"<p>\u4ee5\u524d\u3001<a href=\"https:\/\/gunmagisgeek.com\/blog\/d3-js\/2631\">svg\u3067\u5730\u7403\u5100\u3092\u63cf\u304d\u56de\u8ee2\u3055\u305b\u308b<\/a>\u3068\u3044\u3046\u8a18\u4e8b\u3092\u66f8\u304d\u307e\u3057\u305f\u304c\u3001\u305d\u306e\u8a18\u4e8b\u306b\u3064\u3044\u3066\u304a\u554f\u3044\u5408\u308f\u305b\u3044\u305f\u3060\u304d\u3001\u30e1\u30fc\u30eb\u306b\u3066\u8fd4\u4fe1\u3057\u305f\u3068\u3053\u308dmailer-daemon\u3055\u3093\u306b\u300c\u6b21\u306e\u53d7\u4fe1\u8005\u3078\u306e\u9001\u9054\u306f\u3001\u6052\u4e45\u7684\u306b\u5931\u6557\u3057\u307e\u3057\u305f\u3002\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9\u304c\u5b58\u5728\u3057\u307e\u305b\u3093\u300d\u3068\u8a00\u308f\u308c\u3066\u3057\u307e\u3063\u3066\u8fd4\u4fe1\u3067\u304d\u306a\u304b\u3063\u305f\u306e\u3067\u30d6\u30ed\u30b0\u306e\u8a18\u4e8b\u3068\u3057\u3066\u63b2\u8f09\u3057\u3066\u304a\u304d\u307e\u3059\u3002<\/p>\n<h2>\u5730\u8ef8\u3092\u50be\u3051\u306a\u304c\u3089\u5730\u7403\u5100\u3092\u8868\u793a\u3059\u308b<\/h2>\n<p>\u53f3\u306b23.4\u5ea6\u50be\u3051\u3066\u8868\u793a\u3057\u3066\u3044\u307e\u3059\u3002<br \/>\n\u30b0\u30eb\u30fc\u30d7(g)\u8981\u7d20\u306etransform\u5c5e\u6027\u3067rotate\u3092\u6307\u5b9a\u3057\u5168\u4f53\u3092\u50be\u3051\u3066\u3044\u307e\u3059\u3002<\/p>\n<h3>\u30b5\u30f3\u30d7\u30eb<\/h3>\n<p><a href=\"https:\/\/bl.ocks.org\/shimizu\/b7218e9160c5f813faaac14a0bbc5952\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2015\/01\/D3-v4-Earths-Axial-Tilt-Bl.ock-Builder-2018-03-06-11-49-00.png\" alt=\"\" width=\"954\" height=\"492\" class=\"aligncenter size-full wp-image-5643 border\" srcset=\"https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2015\/01\/D3-v4-Earths-Axial-Tilt-Bl.ock-Builder-2018-03-06-11-49-00.png 954w, https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2015\/01\/D3-v4-Earths-Axial-Tilt-Bl.ock-Builder-2018-03-06-11-49-00-291x150.png 291w, https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2015\/01\/D3-v4-Earths-Axial-Tilt-Bl.ock-Builder-2018-03-06-11-49-00-768x396.png 768w\" sizes=\"auto, (max-width: 954px) 100vw, 954px\" \/><\/a><\/p>\n<p><a href=\"https:\/\/bl.ocks.org\/shimizu\/b7218e9160c5f813faaac14a0bbc5952\">example<\/a><\/p>\n<pre class=\"lang:js decode:true \" >\/*\u5730\u56f3\u3092\u8868\u793a\u3059\u308b\u30b9\u30c6\u30fc\u30b8\u3092\u8ffd\u52a0*\/\nconst stage = d3.select(\"svg\");\nconst rotateStage = stage.append(\"g\");\nconst seaLayer = rotateStage.append(\"g\");\nconst landLayer = rotateStage.append(\"g\");\n\nconst projection = d3.geoOrthographic() \/\/\u6295\u5f71\u6cd5\u3092\u6307\u5b9a\nconst path = d3.geoPath()\/\/geometry\u3092svg\u306e\u30d1\u30b9\u306b\u5909\u63db\u3059\u308b\u95a2\u6570\n        \nd3.json(\"conuntries.topojson\", function(json){ \/\/\u5730\u56f3\u60c5\u5831\u306e\u8aad\u307f\u8fbc\u307f\n  \n  const  data = topojson.feature(json, json.objects.conuntries).features; \/\/topojson-&gt;geojson\u5909\u63db\n\n  \/*\u30d7\u30ed\u30b8\u30a7\u30af\u30b7\u30e7\u30f3\u8a2d\u5b9a*\/\n  projection\n    .rotate([0,0,0]) \/\/x,y,z\u56de\u8ee2\n    .clipAngle(90); \/\/\u8868\u793a\u3059\u308b\u89d2\u5ea6 180\u5ea6\u3092\u6307\u5b9a\u3059\u308b\u3068\u88cf\u5074\u306e\u5927\u9678\u307e\u3067\u8868\u793a\u3055\u308c\u308b\n  \n  \/*\u30d1\u30b9\u30b8\u30a7\u30cd\u30ec\u30fc\u30bf\u30fc\u306b\u30d7\u30ed\u30b8\u30a7\u30af\u30b7\u30e7\u30f3\u3092\u8a2d\u5b9a*\/\n  path.projection(projection);\n\n  \/*\u6d77\u9762\u3092\u63cf\u753b\u3059\u308b\u305f\u3081\u306e\u30d1\u30b9\u3092DOM\u306b\u8ffd\u52a0*\/\n  seaLayer.append(\"path\")\n    .datum({type: \"Sphere\"})\n    .attr(\"fill\", \"blue\")\n   \n   \/*\u5730\u56f3\u3092\u8868\u793a\u3059\u308b\u305f\u3081\u306e\u30d1\u30b9\u3092DOM\u306b\u8ffd\u52a0*\/\n  landLayer\n    .selectAll(\"path\")\n    .data(data) \n    .enter()\n    .append(\"path\")\n    .style(\"background-color\", \"blue\")\n    .attr(\"fill\", \"green\")\n    .attr(\"stroke\", \"#222\")\n    .on(\"mouseover\", function(){\n        d3.select(this).attr(\"fill\", \"red\");\n    })\n    .on(\"mouseout\", function(){\n        d3.select(this).transition().duration(500).attr(\"fill\", \"green\");\n    })\n       \n});\n    \n\/*\u5730\u5f62\u3092\u56de\u8ee2\u3055\u305b\u308b*\/ \nconst draw = () =&gt; {\n  let  i = 0;\n  return () =&gt; {\n    const w = stage.node().clientWidth;\n    const h = stage.node().clientHeight;\n    \n    rotateStage.attr(\"transform\", `rotate(23.4, ${w\/2}, ${h\/2})`)\/\/\u753b\u9762\u306e\u4e2d\u5fc3\u3092\u8ef8\u306b\u30b9\u30c6\u30fc\u30b8\u309223.4\u5ea6\u50be\u3051\u308b\n    \n    i = i+0.5;\n    projection\n      .rotate([i,0,0])  \/\/rotate\u306ex\u5024\u3092\u5897\u3084\u3057\u3066\u6a2a\u306b\u56de\u8ee2\u3055\u305b\u308b\n      .scale(d3.min([w, h]) \/ 2) \/\/\u753b\u9762\u30b5\u30a4\u30ba\u3092\u5143\u306b\u5730\u7403\u5100\u306e\u5927\u304d\u3055\u3092\u6c7a\u5b9a\n      .translate([w\/2, h\/2]) \/\/\u753b\u9762\u4e2d\u592e\u306b\u8868\u793a\u3055\u308c\u308b\u3088\u3046\u306b\u79fb\u52d5\u3059\u308b\n    path.projection(projection);    \/\/path\u95a2\u6570\u3092\u30a2\u30c3\u30d7\u30c7\u30fc\u30c8\n    \n    seaLayer.select(\"path\").attr(\"d\", path); \/\/\u6d77\u9762\u7528\u30d1\u30b9\u3092\u63cf\u753b\n    landLayer.selectAll(\"path\").attr(\"d\", path); \/\/\u5730\u56f3\u7528\u30d1\u30b9\u3092\u63cf\u753b\n    \n  }\n}\n    \nsetInterval(draw(), 100); \/\/\u5b9a\u671f\u7684\u306b\u56de\u8ee2\u3055\u305b\u308b<\/pre>\n<h2>topojson\u306b\u3064\u3044\u3066<\/h2>\n<p>topojson\u306fgeojson\u306b\u6bd4\u3079\u308b\u3068\u52b9\u7387\u306e\u3088\u3044\u30c7\u30fc\u30bf\u5f62\u5f0f\u306a\u306e\u3067\u30d5\u30a1\u30a4\u30eb\u30b5\u30a4\u30ba\u304c\u5c0f\u3055\u304f\u3066\u6e08\u3080\u306e\u3067\u3059\u304c\u3001\u6700\u7d42\u7684\u306b\u306ftopojson.js\u3092\u4f7f\u3063\u3066\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u5074\u3067geojson\u5f62\u5f0f\u306b\u623b\u3057\u3066\u4f7f\u3046\u4ed5\u69d8\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<br \/>\n\u306a\u306e\u3067\u3001<strong>topojson\u30c7\u30fc\u30bf\u304c\u7528\u610f\u3067\u304d\u306a\u3044\u6642\u306fgeojson\u306e\u307e\u307e\u3067\u3082\u554f\u984c\u3042\u308a\u307e\u305b\u3093\u3002<\/strong><br \/>\nfeatures\u30d7\u30ed\u30d1\u30c6\u30a3\u306e\u4e2d\u8eab\u3092\u3001\u30d1\u30b9\u30b8\u30a7\u30cd\u30ec\u30fc\u30bf\u306b\u6e21\u3057\u3066\u3042\u3052\u308c\u3070\u5f8c\u306fD3\u304c\u30d1\u30b9\u30c7\u30fc\u30bf\u306b\u5909\u63db\u3057\u3066\u304f\u308c\u307e\u3059\u3002<\/p>\n<p>Widonws\u7aef\u672b\u3057\u304b\u306a\u304f\u3066\u3001\u305d\u308c\u3067\u3082geojson\u5f62\u5f0f\u306e\u30c7\u30fc\u30bf\u3092topojson\u5f62\u5f0f\u306e\u30c7\u30fc\u30bf\u306b\u5909\u63db\u3057\u305f\u3044\u3068\u304d\u306f\u3001<a href=\"http:\/\/www.mapshaper.org\/\">mapshaper<\/a>\u3068\u3044\u3046Web\u30b5\u30fc\u30d3\u30b9\u3092\u4f7f\u3046\u3068\u3044\u3046\u65b9\u6cd5\u3082\u3042\u308a\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4ee5\u524d\u3001svg\u3067\u5730\u7403\u5100\u3092\u63cf\u304d\u56de\u8ee2\u3055\u305b\u308b\u3068\u3044\u3046\u8a18\u4e8b\u3092\u66f8&hellip;<\/p>\n","protected":false},"author":1,"featured_media":4053,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[69],"tags":[],"class_list":["post-4052","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-d3v4","has-post-thumbnail-archive"],"_links":{"self":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/4052","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=4052"}],"version-history":[{"count":1,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/4052\/revisions"}],"predecessor-version":[{"id":5642,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/4052\/revisions\/5642"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/media\/4053"}],"wp:attachment":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/media?parent=4052"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/categories?post=4052"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/tags?post=4052"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}