{"id":4334,"date":"2015-06-23T18:40:39","date_gmt":"2015-06-23T09:40:39","guid":{"rendered":"https:\/\/gunmagisgeek.com\/wordpress\/?p=4334"},"modified":"2017-03-08T17:04:58","modified_gmt":"2017-03-08T08:04:58","slug":"post-4334","status":"publish","type":"post","link":"https:\/\/gunmagisgeek.com\/blog\/d3-js\/4334","title":{"rendered":"D3.js\u3067\u68d2\u30b0\u30e9\u30d5\u3092\u5e83\u3052\u308bUI\u3092\u4f5c\u3063\u3066\u307f\u305f\u3002"},"content":{"rendered":"<p><a href=\"http:\/\/bl.ocks.org\/shimizu\/ac0cdd479c3f4424f4a4\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2015\/06\/barchart_ui_example150623.jpg\" alt=\"barchart ui example\" width=\"590\" height=\"307\" class=\"aligncenter size-full wp-image-4335 border\" srcset=\"https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2015\/06\/barchart_ui_example150623.jpg 590w, https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2015\/06\/barchart_ui_example150623-288x150.jpg 288w\" sizes=\"auto, (max-width: 590px) 100vw, 590px\" \/><\/a><\/p>\n<p><a href=\"http:\/\/bl.ocks.org\/shimizu\/ac0cdd479c3f4424f4a4\">example<\/a><\/p>\n<p>\u68d2\u30b0\u30e9\u30d5\u3092\u30af\u30ea\u30c3\u30af\u3057\u305f\u3089\u3001\u753b\u9762\u3044\u3063\u3071\u3044\u307e\u3067\u5e83\u304c\u3063\u3066\u8a73\u7d30\u3092\u8868\u793a\u3059\u308b\u3068\u3044\u3046UI\u3092\u4f5c\u3063\u3066\u307f\u307e\u3057\u305f\u3002<br \/>\n\u8a73\u7d30\u60c5\u5831\u3092\u6ca2\u5c71\u8868\u793a\u3057\u305f\u3044\u5834\u5408\u306b\u306f\u4fbf\u5229\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002<\/p>\n<p>D3\u3092\u4f7f\u3048\u3070\u7c21\u5358\u306b\u4f5c\u308c\u308b\u304b\u306a\uff1f\u3068\u601d\u3063\u3066\u3044\u305f\u306e\u3067\u3059\u304c\u3001SVG\u306e\u8868\u793a\u9806\u306e\u7f60\u306b\u306f\u307e\u3063\u3066\u7d50\u69cb\u9762\u5012\u306a\u3053\u3068\u306b\u3002<br \/>\nSVG\u306b\u3082z-index\u304c\u6b32\u3057\u304f\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n<h2>\u8868\u793a\u9806\u306e\u7f60<\/h2>\n<p>SVG\u3067\u306f\u8981\u7d20\u306e\u9806\u756a\u3067\u91cd\u306a\u308a\u65b9\u304c\u6c7a\u307e\u308a\u307e\u3059\u3002<br \/>\n\u4e0b\u8a18\u306e\u4f8b\u3067\u306f\u3001\u8d64\u3044circle\u8981\u7d20\u306e\u5f8c\u306b\u9752\u3044circle\u8981\u7d20\u304c\u8a2d\u7f6e\u3055\u308c\u3066\u3044\u308b\u305f\u3081\u3001\u9752\u3044\u5186\u304c\u8d64\u3044\u5186\u306e\u4e0a\u306b\u91cd\u306a\u3063\u3066\u8868\u793a\u3055\u308c\u3066\u3044\u307e\u3059\u3002 <\/p>\n<pre class=\"lang:js decode:true \" >&lt;svg width=\"300\" height=\"100\"&gt;\r\n\t&lt;circle cx=\"100\" cy=\"50\" r=\"50\" fill=\"red\" \/&gt;\r\n\t&lt;circle cx=\"150\" cy=\"50\" r=\"50\" fill=\"blue\" \/&gt;\r\n&lt;\/svg&gt;<\/pre>\n<p>SVG\u8981\u7d20\u306b\u306f\u300cz-index\u300d\u304c\u52b9\u304b\u306a\u3044\u305f\u3081\u3001\u8981\u7d20\u306e\u91cd\u306a\u308a\u3092\u5909\u66f4\u3057\u305f\u3044\u5834\u5408\u306f\u8981\u7d20\u306e\u4e26\u3073\u3092\u5165\u308c\u66ff\u3048\u308b\u3057\u304b\u65b9\u6cd5\u304c\u3042\u308a\u307e\u305b\u3093\u3002\u3053\u308c\u304c\u7d50\u69cb\u9762\u5012\u3067\u3059\u3002<\/p>\n<h2>\u3061\u3087\u3063\u3068\u3060\u3051\u89e3\u8aac<\/h2>\n<p>\u5168\u30b3\u30fc\u30c9\u306fbl.ocks.org\u306e\u65b9\u3067\u516c\u958b\u3057\u3066\u3044\u308b\u306e\u3067\u3001\u30cf\u30de\u30ea\u30dd\u30a4\u30f3\u30c8\u3060\u3051\u8aac\u660e\u3057\u307e\u3059\u3002<\/p>\n<p>\u3000<br \/>\n\u521d\u3081\u306bg\u8981\u7d20(\u30b0\u30eb\u30fc\u30d7\u5316)\u3092\u4f7f\u3063\u3066\uff13\u5c64\u4f5c\u3063\u3066\u304a\u304f\u3053\u3068\u3067\u524d\u8ff0\u306e\u91cd\u306a\u308a\u554f\u984c\u3092\u56de\u907f\u3057\u3066\u3044\u307e\u3059\u3002<br \/>\nid=stage\u306e\u5c64\u306f\u68d2\u30b0\u30e9\u30d5\u3092\u8868\u793a\u3059\u308b\u5c64\u3001id=overlay\u306e\u5c64\u306f\u30af\u30ea\u30c3\u30af\u3055\u308c\u305f\u969b\u306e\u30c8\u30e9\u30f3\u30b8\u30b7\u30e7\u30f3\u3092\u884c\u3046\u5c64\u3001id=info\u5c64\u306f\u30aa\u30fc\u30d0\u30fc\u30ec\u30a4\u306e\u4e0a\u306b\u8a73\u7d30\u60c5\u5831\u7b49\u3092\u51fa\u529b\u3059\u308b\u5c64\u3068\u3057\u3066\u8a2d\u7f6e\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre class=\"lang:xhtml decode:true \" >&lt;svg&gt;\r\n&lt;g id=\"stage\"&gt;&lt;\/g&gt;\r\n&lt;g id=\"overlay\"&gt;&lt;\/g&gt;\r\n&lt;g id=\"info\"&gt;&lt;\/g&gt;\r\n&lt;\/svg&gt;<\/pre>\n<p>\u4e0b\u8a18\u306f\u3001\u68d2\u30b0\u30e9\u30d5\u304c\u30af\u30ea\u30c3\u30af\u3055\u308c\u305f\u969b\u306e\u51e6\u7406\u3067\u3059\u3002<br \/>\n\u4e00\u898b\u8907\u96d1\u306a\u3053\u3068\u3092\u3084\u3063\u3066\u3044\u308b\u3088\u3046\u306b\u898b\u3048\u306a\u304f\u3082\u306a\u3044\u3067\u3059\u304c\u3001\u5b9f\u969b\u306b\u306f\u5358\u7d14\u306a\u51e6\u7406\u3067\u3059\u3002 <\/p>\n<pre class=\"lang:js decode:true \" >barChart.on('click', function(d, i){\r\n\t\/\/\u68d2\u30b0\u30e9\u30d5\u306e\u30b3\u30d4\u30fc\u3092\u4f5c\u308b\r\n\tvar copryRect = overlay.append('rect')\r\n\t\t.on('click', function(){\t\t\/\/\u30b3\u30d4\u30fc\u304c\u30af\u30ea\u30c3\u30af\u3055\u308c\u305f\u969b\u306e\u51e6\u7406(\u9589\u3058\u308b)\r\n\t\t\tlabel.text(\"\").style('opacity', 0);\r\n\t\t\tdescription.text(\"\").style('opacity', 0);\r\n\t\t\tcopryRect.transition().attr({\r\n\t\t\t\t'x': (i * 100) +  margin.left,\r\n\t\t\t\t'y': h - yScale(d.value),\r\n\t\t\t\t'height':yScale(d.value),\r\n\t\t\t\t'width':50,\r\n\t\t\t})\r\n\t\t\t.call(endall, function(){\r\n\t\t\t\tcopryRect.remove();\t\t\t\r\n\t\t\t})\r\n\t\t});\r\n\t\t\r\n\t\/\/\u30aa\u30ea\u30b8\u30ca\u30eb\u304b\u3089attributes\u3092\u53d6\u5f97\u3057\u3001\u30b3\u30d4\u30fc\u306b\u9069\u7528\u3059\u308b\r\n\tArray.prototype.slice.call(d3.select(this).node().attributes).forEach(function(d){\r\n\t\tcopryRect.attr(d.name, d.value)\r\n\t});\r\n\t\r\n\t\/\/\u30b3\u30d4\u30fc\u3092\u753b\u9762\u3044\u3063\u3071\u3044\u307e\u3067\u5e83\u3052\u308b\r\n\tcopryRect.transition().attr({\r\n\t\tx:0,\r\n\t\ty:0,\r\n\t\twidth:w,\r\n\t\theight:h\r\n\t})\r\n\t.call(endall, function(){\r\n\t\tlabel.text(d.label).transition().style('opacity', 1);\r\n\t\tdescription.text(d.description).transition().style('opacity', 1);\r\n\t});\r\n});\r\n<\/pre>\n<p>\u68d2\u30b0\u30e9\u30d5\u304c\u30af\u30ea\u30c3\u30af\u3055\u308c\u308b\u3068\u3001\u307e\u305aoverlay\u5c64\u306b\u30af\u30ea\u30c3\u30af\u3055\u308c\u305f\u68d2\u30b0\u30e9\u30d5(rect)\u8981\u7d20\u306e\u30b3\u30d4\u30fc\u3092\u4f5c\u308a\u307e\u3059\u3002<br \/>\n\u305d\u306e\u5f8c\u3001\u30b3\u30d4\u30fc\u3092\u753b\u9762\u3044\u3063\u3071\u3044\u306b\u307e\u3067\u5e83\u3052\u3001info\u5c64\u306b\u8a73\u7d30\u60c5\u5831\u3092\u51fa\u529b\u3057\u3066\u3044\u307e\u3059\u3002<br \/>\n\u30b3\u30d4\u30fc\u81ea\u8eab\u304c\u30af\u30ea\u30c3\u30af\u3055\u308c\u308b\u3068\u3001\u5143\u306e\u30b9\u30c6\u30fc\u30bf\u30b9\u307e\u3067\u30c8\u30e9\u30f3\u30b8\u30b7\u30e7\u30f3\u3057\u3066\u304b\u3089remove\u3055\u308c\u3066\u6d88\u3048\u307e\u3059\u3002<\/p>\n<p>\u5f53\u521d\u306f\u3001\u30af\u30ea\u30c3\u30af\u3055\u308c\u305f\u68d2\u30b0\u30e9\u30d5(rect)\u8981\u7d20\u81ea\u8eab\u3092\u753b\u9762\u3044\u3063\u3071\u3044\u306b\u307e\u3067\u5e83\u3052\u308b\u3064\u3082\u308a\u3060\u3063\u305f\u306e\u3067\u3059\u304c\u3001\u305d\u308c\u3060\u3068\u4ed6\u306e\u68d2\u30b0\u30e9\u30d5\u306e\u8981\u7d20\u304c\u4e0a\u4f4d\u306b\u8868\u793a\u3055\u308c\u3066\u3057\u307e\u3046\u554f\u984c\u304c\u3042\u3063\u305f\u305f\u3081\u3001\u30b3\u30d4\u30fc\u3092\u4f5c\u6210\u3059\u308b\u65b9\u6cd5\u3067\u56de\u907f\u3057\u307e\u3057\u305f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>example \u68d2\u30b0\u30e9\u30d5\u3092\u30af\u30ea\u30c3\u30af\u3057\u305f\u3089\u3001\u753b\u9762\u3044\u3063&hellip;<\/p>\n","protected":false},"author":1,"featured_media":4335,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18,50],"tags":[],"class_list":["post-4334","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-d3-js","category-svg","has-post-thumbnail-archive"],"_links":{"self":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/4334","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=4334"}],"version-history":[{"count":0,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/4334\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/media\/4335"}],"wp:attachment":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/media?parent=4334"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/categories?post=4334"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/tags?post=4334"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}