{"id":4682,"date":"2016-01-15T13:09:41","date_gmt":"2016-01-15T04:09:41","guid":{"rendered":"https:\/\/gunmagisgeek.com\/wordpress\/?p=4682"},"modified":"2018-03-05T10:57:56","modified_gmt":"2018-03-05T01:57:56","slug":"post-4682","status":"publish","type":"post","link":"https:\/\/gunmagisgeek.com\/blog\/d3v4\/4682","title":{"rendered":"\u3010D3.js\u3011\u5186\u306e\u5916\u5468\u304b\u3089\u5916\u5468\u306b\u30e9\u30a4\u30f3\u3092\u5f15\u304f"},"content":{"rendered":"<p><a href=\"https:\/\/bl.ocks.org\/shimizu\/3c6e6f1d28ff6df52d0d60c80efa0b62\" rel=\"attachment wp-att-4684\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2016\/01\/circleline.png\" alt=\"\u5186\u306e\u5916\u5468\u304b\u3089\u5916\u5468\u306b\u30e9\u30a4\u30f3\u3092\u5f15\u304f\" width=\"590\" height=\"196\" class=\"aligncenter size-full wp-image-4684 border\" srcset=\"https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2016\/01\/circleline.png 590w, https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2016\/01\/circleline-300x100.png 300w\" sizes=\"auto, (max-width: 590px) 100vw, 590px\" \/><\/a><\/p>\n<p><a href=\"https:\/\/bl.ocks.org\/shimizu\/3c6e6f1d28ff6df52d0d60c80efa0b62\">example<\/a><br \/>\n* \u8868\u793a\u3055\u308c\u306a\u3044\u5834\u5408\u306f\u30ea\u30ed\u30fc\u30c9\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p>\u307e\u3041\u3001\u898b\u3066\u306e\u3068\u304a\u308a\u306a\u306e\u3067\u3059\u304c\u3002<br \/>\n\u30b5\u30fc\u30af\u30eb\u8981\u7d20\u3068\u30b5\u30fc\u30af\u30eb\u8981\u7d20\u3092\u30e9\u30a4\u30f3\u8981\u7d20\u3067\u7d50\u3076\u969b\u306b\u3001\u30b5\u30fc\u30af\u30eb\u306e\u5916\u5468\u306b\u30e9\u30a4\u30f3\u3092\u63a5\u7d9a\u3059\u308b\u30b5\u30f3\u30d7\u30eb\u3067\u3059\u3002<br \/>\n\u3053\u306e\u65b9\u6cd5\u3060\u3068\u8a08\u7b97\u304c\u697d\u306a\u306e\u3067\u3059\u304c\u3001\u8907\u6570\u306e\u30b5\u30fc\u30af\u30eb\u3092\u30e9\u30a4\u30f3\u3067\u7d50\u3076\u3068\u3042\u307e\u308a\u898b\u6804\u3048\u304c\u826f\u304f\u3042\u308a\u307e\u305b\u3093\u3002<br \/>\n\u305d\u3053\u3089\u3078\u3093\u304c\u89e3\u6c7a\u3067\u304d\u305f\u3089\u3001\u6539\u826f\u7248\u3092\u307e\u305f\u8f09\u305b\u3088\u3046\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<h2>\u30b5\u30f3\u30d7\u30eb<\/h2>\n<p>\u30a2\u30cb\u30e1\u30fc\u30b7\u30e7\u30f3\u306a\u3069\u4f59\u8a08\u306a\u3082\u306e\u3092\u7701\u3044\u305f\u30b5\u30f3\u30d7\u30eb<\/p>\n<pre class=\"lang:js decode:true \" >const svg = d3.select(\"svg\");\nconst w = document.querySelector(\"#stage\").clientWidth;\nconst h = document.querySelector(\"#stage\").clientHeight;\nconst r = Math.min(w,h) \/ 10;\n\nconst margin = r;\n\nsvg.selectAll(\"circle\").data([[],[]]).enter().append(\"circle\")\n    .attr(\"cx\", (d,i) => i * (r*4) + r)\n    .attr(\"cy\", r*2)\n    .attr(\"fill\", \"none\")\n    .attr(\"stroke\", \"black\")\n    .attr(\"r\", r)\n    \nsvg.append(\"line\").attr(\"stroke\", \"black\")\n    .attr(\"x1\", r*2)\n    .attr(\"y1\", r*2)\n    .attr(\"x2\", r*4)\n    .attr(\"y2\", r*2)\n\nsetInterval(animation, 1000)\n\nfunction animation(args) {\n    \/\/\u5186\uff11\u306e\u4e2d\u5fc3\u5ea7\u6a19\n    const cx1 = Math.floor(Math.random() * (w-margin)) + margin;\n    const cy1 = Math.floor(Math.random() * (h-margin)) + margin;\n    \n    \/\/\u5186\uff12\u306e\u4e2d\u5fc3\u5ea7\u6a19\n    const cx2 = Math.floor(Math.random() * (w-margin)) + margin;\n    const cy2 = Math.floor(Math.random() * (h-margin)) + margin;\n    \n    \/\/\u5186\u3092\u8ffd\u52a0\u3059\u308b\n    const circle = svg.selectAll(\"circle\").data([[cx1, cy1], [cx2, cy2]])\n    circle\n        .transition().duration(500)\n        .attr(\"cx\", d => d[0])\n        .attr(\"cy\", d=> d[1])\n    \n    \/\/\u5916\u5468\u306e\u5ea7\u6a19\u3092\u8a08\u7b97\u3059\u308b    \n    const cp = circuitsPoint(cx1, cy1, cx2, cy2, r)\n    \n    \/\/\u5186\uff11\u306e\u5916\u5468\u304b\u3089\u3001\u5186\uff12\u306e\u5916\u5468\u307e\u3067\u30e9\u30a4\u30f3\u3092\u5f15\u304f    \n    svg.select(\"line\").transition().duration(500)\n        .attr(\"x1\", cx1 + cp.ox)\n        .attr(\"y1\", cy1 + cp.oy)\n        .attr(\"x2\", cx2 - cp.ox)\n        .attr(\"y2\", cy2 - cp.oy)\n}\n\n\n\n\nfunction circuitsPoint(cx1, cy1, cx2, cy2, r){\n    const atan2 = Math.atan2(cy2 - cy1, cx2 - cx1);\n    \n    const ox = Math.cos(atan2) * r;\n    const oy = Math.sin(atan2) * r;\n    \n    return { ox:ox, oy:oy }\n\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>example * \u8868\u793a\u3055\u308c\u306a\u3044\u5834\u5408\u306f\u30ea\u30ed\u30fc\u30c9\u3057\u3066&hellip;<\/p>\n","protected":false},"author":1,"featured_media":4684,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[69],"tags":[],"class_list":["post-4682","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\/4682","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=4682"}],"version-history":[{"count":1,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/4682\/revisions"}],"predecessor-version":[{"id":4685,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/4682\/revisions\/4685"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/media\/4684"}],"wp:attachment":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/media?parent=4682"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/categories?post=4682"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/tags?post=4682"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}