{"id":5973,"date":"2018-05-07T15:55:56","date_gmt":"2018-05-07T06:55:56","guid":{"rendered":"https:\/\/gunmagisgeek.com\/wordpress\/?p=5973"},"modified":"2018-05-07T15:55:56","modified_gmt":"2018-05-07T06:55:56","slug":"%e3%80%90d3-js%e3%80%91%e3%83%81%e3%83%a3%e3%83%bc%e3%83%88%e3%81%ae%e8%bb%b8%e3%81%a8%e7%9b%ae%e7%9b%9b%e3%82%8a%e3%82%92%e3%82%ab%e3%82%b9%e3%82%bf%e3%83%9e%e3%82%a4%e3%82%ba%e3%81%99%e3%82%8b","status":"publish","type":"post","link":"https:\/\/gunmagisgeek.com\/blog\/d3v4\/5973","title":{"rendered":"\u3010D3.js\u3011\u30c1\u30e3\u30fc\u30c8\u306e\u8ef8\u3068\u76ee\u76db\u308a\u3092\u30ab\u30b9\u30bf\u30de\u30a4\u30ba\u3059\u308b\uff15\u306e\u65b9\u6cd5"},"content":{"rendered":"<p>\u30b7\u30f3\u30d7\u30eb\u3067\u30b9\u30bf\u30c6\u30a3\u30c3\u30af(\u9759\u7684)\u306a\u30c1\u30e3\u30fc\u30c8\u3067\u3042\u3063\u3066\u3082\u3001\u7d30\u304b\u304f\u8981\u4ef6\u304c\u767a\u751f\u3057\u304c\u3061\u306a\u306e\u304c\u8ef8(axis)\u3068\u76ee\u76db\u308a(ticks)\u3067\u3059\u3002<\/p>\n<p>\u3053\u3053\u3067\u306fD3\u3092\u4f7f\u3063\u3066\u8ef8\u3084\u76ee\u76db\u308a\u3092\u63cf\u753b\u3059\u308b\u969b\u306b\u4f7f\u3048\u308b\u30c6\u30af\u30cb\u30c3\u30af\u3092\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n<p>\u305d\u308c\u305e\u308c\u6c17\u6301\u3061\u7a0b\u5ea6\u306e\u89e3\u8aac\u3092\u5165\u308c\u3066\u3044\u307e\u3059\u304c\u3001\u8a73\u3057\u304f\u306fexample\u30ea\u30f3\u30af\u5148\u306e\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9\u3092\u53c2\u7167\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<h3>\u30ec\u30b9\u30dd\u30f3\u30b7\u30d6<\/h3>\n<p>\u4e00\u756a\u8981\u671b\u304c\u591a\u3044\u3068\u3044\u3046\u304b\u3001\u6700\u8fd1\u3067\u306f\u57fa\u672c\u7684\u306a\u8981\u4ef6\u306b\u306a\u308a\u3064\u3064\u3042\u308b\u8ef8\u3092\u542b\u3081\u305f\u30ec\u30b9\u30dd\u30f3\u30b7\u30d6\u5bfe\u5fdc\u3067\u3059\u3002<br \/>\n\u3053\u3053\u3067\u306f\u3001\u5358\u306b\u30ea\u30b5\u30a4\u30ba\u3059\u308b\u3060\u3051\u3067\u306a\u304f\u3001\u6a2a\u5e45\u304c\u7279\u5b9a\u306e\u30d6\u30ec\u30a4\u30af\u30dd\u30a4\u30f3\u30c8\u4ee5\u4e0b\u306b\u306a\u3063\u305f\u5834\u5408\u306b\u76ee\u76db\u308a\u306e\u8868\u793a\u6570\u306a\u3069\u3082\u5909\u66f4\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p><a href=\"https:\/\/bl.ocks.org\/shimizu\/9af05d01ce753f9098f0b93ff961a3d6\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2018\/05\/axistips1.png\" alt=\"D3 Axis Tips#1 - Responsive\" width=\"763\" height=\"392\" class=\"aligncenter size-full wp-image-5968 border\" srcset=\"https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2018\/05\/axistips1.png 763w, https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2018\/05\/axistips1-292x150.png 292w\" sizes=\"auto, (max-width: 763px) 100vw, 763px\" \/><\/a><\/p>\n<p><a href=\"https:\/\/bl.ocks.org\/shimizu\/9af05d01ce753f9098f0b93ff961a3d6\">example<\/a><\/p>\n<p>axis\u3092\u51fa\u529b\u3059\u308b\u30a8\u30ec\u30e1\u30f3\u30c8\u306b\u5bfe\u3057\u3066\u3001\u4eee\u306e\u30c7\u30fc\u30bf\u3092\u30d0\u30a4\u30f3\u30c9\u3059\u308b\u3053\u3068\u3067d3\u306e\u5dee\u5206\u7ba1\u7406\u6a5f\u80fd\u3092axis\u306b\u5bfe\u3057\u3066\u3082\u4f7f\u3048\u308b\u3088\u3046\u306b\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre class=\"lang:js decode:true \" > yAxisUpdate = axis.selectAll(\".yAxis\").data([null]); \/\/\u4eee\u306e\u30c7\u30fc\u30bf\u3092\u30d0\u30a4\u30f3\u30c7\u30a3\u30f3\u30b0\nconst yAxisEnter = yAxisUpdate.enter().append(\"g\").classed(\"yAxis\", true); \/\/\u65b0\u305f\u306baxis\u3092\u8ffd\u52a0\u3059\u308b\u969b\u306e\u51e6\u7406\n\nyAxisUpdate.merge(yAxisEnter).call( d3.axisLeft().scale(yScale).ticks(yTicks) ); \/\/\u5c5e\u6027\u5024\u306e\u30a2\u30c3\u30d7\u30c7\u30fc\u30c8<\/pre>\n<h3>\u76ee\u76db\u308a\u306e\u30ab\u30b9\u30bf\u30de\u30a4\u30ba<\/h3>\n<p>\u4f8b\u3048\u3070\u3001\u300c\u4e00\u756a\u6700\u521d\u306e\u76ee\u76db\u308a\u306b\u3060\u3051\u5358\u4f4d\u3092\u3064\u3051\u3066\u8868\u793a\u3057\u305f\u3044\u300d\u3084\u300c\uff11\u6708\u306e\u6642\u3060\u3051\u5e74\u6708\u3067\u8868\u793a\u3057\u305f\u3044\u300d\u306a\u3069\u306e\u8981\u4ef6\u306b\u5bfe\u5fdc\u3059\u308b\u65b9\u6cd5\u3067\u3059\u3002<\/p>\n<p><a href=\"https:\/\/bl.ocks.org\/shimizu\/8fe074286cb4348609170d979895b1f5\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2018\/05\/axistips2.png\" alt=\"D3 Axis Tips#2&quot; - Custom Tick Label\" width=\"763\" height=\"393\" class=\"aligncenter size-full wp-image-5969 border\" srcset=\"https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2018\/05\/axistips2.png 763w, https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2018\/05\/axistips2-291x150.png 291w\" sizes=\"auto, (max-width: 763px) 100vw, 763px\" \/><\/a><\/p>\n<p><a href=\"https:\/\/bl.ocks.org\/shimizu\/8fe074286cb4348609170d979895b1f5\">example<\/a><\/p>\n<p>tickFormat\u306b\u6e21\u3059\u30b3\u30fc\u30eb\u30d0\u30c3\u30af\u306e\u4e2d\u3067\u3001\u76ee\u76db\u308a\u306e\u8868\u793a\u65b9\u6cd5\u3092\u7d30\u304b\u304f\u6307\u5b9a\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"lang:js decode:true \" >d3.axisLeft().scale(yScale)\n    .tickFormat( (d,i) =&gt; {\n        \/\/\u3053\u306e\u623b\u308a\u5024\u304c\u76ee\u76db\u308a\u3068\u3057\u3066\u8868\u793a\u3055\u308c\u307e\u3059\u3002\n        return d;\n    });\n<\/pre>\n<h3>\u76ee\u76db\u308a\u3092\u5185\u5074\u306b\u8868\u793a<\/h3>\n<p>\u8868\u793a\u9818\u57df\u306e\u72ed\u3044\u30b9\u30de\u30fc\u30c8\u30d5\u30a9\u30f3\u3067\u306f\u3001\u30c1\u30e3\u30fc\u30c8\u306e\u30de\u30fc\u30b8\u30f3\u3092\u5341\u5206\u306b\u53d6\u308b\u3053\u3068\u304c\u3067\u304d\u306a\u3044\u5834\u5408\u304c\u3042\u308a\u307e\u3059\u3002<br \/>\n\u305d\u3046\u3044\u3063\u305f\u5834\u5408\u306f\u3001\u76ee\u76db\u308a\u3092\u5185\u5074\u306b\u8868\u793a\u3059\u308b\u3053\u3068\u3067\u4f59\u8a08\u306a\u30de\u30fc\u30b8\u30f3\u3092\u53d6\u3089\u305a\u306b\u30b3\u30f3\u30d1\u30af\u30c8\u306a\u30c1\u30e3\u30fc\u30c8\u3092\u8868\u793a\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p><a href=\"https:\/\/bl.ocks.org\/shimizu\/61e5e06c2a9cc2cd9898694efb33f441\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2018\/05\/axistips3.png\" alt=\"D3 Axis Tips#3 - Inner Tick Label\" width=\"763\" height=\"397\" class=\"aligncenter size-full wp-image-5970 border\" srcset=\"https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2018\/05\/axistips3.png 763w, https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2018\/05\/axistips3-288x150.png 288w\" sizes=\"auto, (max-width: 763px) 100vw, 763px\" \/><\/a><\/p>\n<p><a href=\"https:\/\/bl.ocks.org\/shimizu\/61e5e06c2a9cc2cd9898694efb33f441\">example<\/a><\/p>\n<p>axisLeft, axisRight, axisTop, axisBottom\u306e\u5404\u30e2\u30b8\u30e5\u30fc\u30eb\u3067\u30e9\u30d9\u30eb\u306e\u8868\u793a\u4f4d\u7f6e\u3092\u6307\u5b9a\u3067\u304d\u307e\u3059\u3002<\/p>\n<h3>\u76ee\u76db\u308a\u306e\u6539\u884c<\/h3>\n<p>\u30ab\u30c6\u30b4\u30ea\u306e\u30e9\u30d9\u30eb\u306a\u3069\u3067\u3001\u3069\u3046\u3057\u3066\u3082\u6539\u884c\u304c\u5fc5\u8981\u306b\u306a\u308b\u5834\u5408\u304c\u3042\u308a\u307e\u3059\u3002<br \/>\nSVG\u306b\u306f\u57fa\u672c\u6298\u308a\u8fd4\u3059\u3068\u3044\u3046\u6a5f\u80fd\u304c\u306a\u3044\u305f\u3081\u3001\u975e\u5e38\u306b\u9762\u5012\u3067\u3059\u304c\u4e0b\u8a18\u65b9\u6cd5\u3067\u4e00\u5fdc\u5b9f\u88c5\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p><a href=\"https:\/\/bl.ocks.org\/shimizu\/867616426a9c05648d580efbbed45466\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2018\/05\/axistips4.png\" alt=\"D3 Axis Tips#4&quot; - Wrapping Tick Label\" width=\"763\" height=\"404\" class=\"aligncenter size-full wp-image-5971 border\" srcset=\"https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2018\/05\/axistips4.png 763w, https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2018\/05\/axistips4-283x150.png 283w\" sizes=\"auto, (max-width: 763px) 100vw, 763px\" \/><\/a><\/p>\n<p><a href=\"https:\/\/bl.ocks.org\/shimizu\/867616426a9c05648d580efbbed45466\">example<\/a><\/p>\n<p>d3.axis\u304c\u51fa\u529b\u3057\u305f\u30a8\u30ec\u30e1\u30f3\u30c8\u304b\u3089text\u8981\u7d20\u3092\u4e00\u65e6\u524a\u9664\u3057\u3001\u4ee3\u308f\u308a\u306btspan\u3067\u56f2\u3063\u305f\u30a8\u30ec\u30e1\u30f3\u30c8\u3092\u8ffd\u52a0\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre class=\"lang:js decode:true \" >yAxis.selectAll(\".tick text\")\n    .html(null) \/\/\u5143\u306etick\u30e9\u30d9\u30eb\u3092\u524a\u9664\n    .attr(\"text-anchor\", \"start\")\n    .attr(\"dominant-baseline\", \"middle\")\n    .each((text, i, nodes) =&gt; {\n        \/\/\u30e9\u30d9\u30eb\u306b\u9069\u7528\u3059\u308b\u30c6\u30ad\u30b9\u30c8\u3092\u6539\u884c\u30b3\u30fc\u30c9\u3092\u57fa\u6e96\u306b\u5206\u5272\n        const st = text.split(\"n\"); \n        \/\/\u30e9\u30d9\u30eb\u3092\u53f3\u63c3\u3048\u306b\u3059\u308b\u305f\u3081\u306b\u3001\u5206\u5272\u3057\u305f\u30c6\u30ad\u30b9\u30c8\u306e\u4e2d\u3067\u3082\u3063\u3068\u3082\u9577\u3044\u5024\u3092\u53d6\u5f97\u300c\n        const maxLength = d3.max(st, d =&gt; d.length ); \n        \/\/\u884c\u9593\u3092\u8a2d\u5b9a\n        const lineHight = 0.6;\n        \/\/\u5206\u5272\u3057\u305f\u30c6\u30ad\u30b9\u30c8\u306e\u6570\u304b\u3089\u3001Y\u5ea7\u6a19\u3092\u6c42\u3081\u308b\u305f\u3081\u306e\u30b9\u30b1\u30fc\u30eb\u3092\u8a2d\u5b9a\n        const ypos = d3.scaleLinear().domain([0, st.length]).range([-st.length * lineHight, st.length * lineHight]);\n        \n        \/\/\u5206\u5272\u3057\u305f\u30c6\u30ad\u30b9\u30c8\u3092tspan\u8981\u7d20\u3067\u62ec\u3063\u3066\u3001\u3082\u3068\u306e\u30ce\u30fc\u30c9\u306b\u30a2\u30da\u30f3\u30c9\u3059\u308b\n        const tspanUpdate = d3.select(nodes[i]).selectAll(\"tspan\").data(st);\n        const tspanEnter = tspanUpdate.enter().append(\"tspan\");\n        \n        \/\/tspan\u306b\u6539\u884c\u306e\u305f\u3081\u306e\u60c5\u5831\u3092\u4ed8\u52a0\u3059\u308b\n        tspanEnter\n            .attr(\"dy\", \"1em\")\n            .attr(\"y\", (d,i) =&gt;  ypos(i) + \"em\")\n            .attr(\"dx\", \"-\" + (maxLength + 0.5) + \"em\")\n            .attr(\"x\", (d,i) =&gt; { const l = maxLength - d.length;  return l + \"em\"})\n            .text(d =&gt; d)\n        \n    });<\/pre>\n<p>SVG\u3067\u306e\u6539\u884c\u306b\u3064\u3044\u3066\u306f\u3001<a href=\"https:\/\/bl.ocks.org\/shimizu\/9a1fb770ed60c86abf5d1ee32a2098da\">\u3053\u3061\u3089\u306e\u30b5\u30f3\u30d7\u30eb<\/a>\u3092\u53c2\u7167\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<h3>\u57fa\u8ef8\u306e\u79fb\u52d5<\/h3>\n<p>\u8868\u793a\u3059\u308b\u30c7\u30fc\u30bf\u306b0\u4ee5\u4e0b\u306e\u5024\u304c\u5165\u3063\u3066\u304f\u308b\u5834\u5408\u3001\u57fa\u8ef8\u30920\u306e\u4f4d\u7f6e\u3078\u8868\u793a\u3057\u305f\u3044\u3068\u3044\u3046\u8981\u671b\u304c\u3088\u304f\u3042\u308a\u307e\u3059\u3002\u3053\u3053\u3067\u306ftransform\u3092\u4f7f\u3063\u30660\u30d9\u30fc\u30b9\u30e9\u30a4\u30f3\u3092\u79fb\u52d5\u3057\u3066\u3044\u307e\u3059\u3002<br \/>\n\u4ee5\u4e0b\u306e\u4f8b\u3067\u306f\u4e09\u79d2\u3054\u3068\u306b\u30c7\u30fc\u30bf\u304c\u5165\u308c\u66ff\u308f\u308a\u3001\u305d\u308c\u306b\u4f34\u3063\u3066\u30d9\u30fc\u30b9\u30e9\u30a4\u30f3\u304c\u79fb\u52d5\u3057\u307e\u3059\u3002<\/p>\n<p><a href=\"https:\/\/bl.ocks.org\/shimizu\/2cc1f0ddd6eb49a7993b51b742b571ba\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2018\/05\/axistips5.png\" alt=\"D3 Axis Tips#5 - Move BaseLine\" width=\"763\" height=\"393\" class=\"aligncenter size-full wp-image-5972 border\" srcset=\"https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2018\/05\/axistips5.png 763w, https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2018\/05\/axistips5-291x150.png 291w\" sizes=\"auto, (max-width: 763px) 100vw, 763px\" \/><\/a><\/p>\n<p><a href=\"https:\/\/bl.ocks.org\/shimizu\/2cc1f0ddd6eb49a7993b51b742b571ba\">example<\/a><\/p>\n<pre class=\"lang:js decode:true \" >yAxis.select(\".domain\")\n    .attr(\"transform\", `translate(${xScale(0)}, 0)`); \/\/\u30d9\u30fc\u30b9\u30e9\u30a4\u30f3\u30920\u306e\u4f4d\u7f6e\u3078\u79fb\u52d5\u3059\u308b<\/pre>\n<h3>(\u304a\u307e\u3051)\u8ef8\u306e\u30af\u30e9\u30b9\u30bf\u30ea\u30f3\u30b0<\/h3>\n<p>\u4e8c\u3064\u306e\u30c1\u30e3\u30fc\u30c8\u3092\u4e26\u3079\u3066\u8868\u793a\u3057\u305f\u3044\u5834\u5408\u306a\u3069\u3002<br \/>\n\u3053\u3053\u3067\u306f\u3001Y\u8ef8\u3092\u30c8\u30c3\u30d7\u3068\u30dc\u30c8\u30e0\u306b\u5206\u3051\u3066\u8868\u793a\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p><a href=\"https:\/\/bl.ocks.org\/shimizu\/fed49212b162deaee6726d537b271fbb\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2018\/05\/axistips6.png\" alt=\"Clustered Column Chart\" width=\"763\" height=\"398\" class=\"aligncenter size-full wp-image-5974 border\" srcset=\"https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2018\/05\/axistips6.png 763w, https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2018\/05\/axistips6-288x150.png 288w\" sizes=\"auto, (max-width: 763px) 100vw, 763px\" \/><\/a><\/p>\n<p><a href=\"https:\/\/bl.ocks.org\/shimizu\/fed49212b162deaee6726d537b271fbb\">example<\/a><\/p>\n<p>\u7d20\u76f4\u306b\u4e8c\u3064\u30c1\u30e3\u30fc\u30c8\u3092\u4f5c\u3063\u3066\u4e26\u3079\u305f\u65b9\u304c\u65e9\u3044\u304b\u3082\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u30b7\u30f3\u30d7\u30eb\u3067\u30b9\u30bf\u30c6\u30a3\u30c3\u30af(\u9759\u7684)\u306a\u30c1\u30e3\u30fc\u30c8\u3067\u3042\u3063\u3066\u3082&hellip;<\/p>\n","protected":false},"author":1,"featured_media":5975,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[69],"tags":[],"class_list":["post-5973","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\/5973","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=5973"}],"version-history":[{"count":0,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/5973\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/media\/5975"}],"wp:attachment":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/media?parent=5973"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/categories?post=5973"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/tags?post=5973"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}