{"id":3670,"date":"2014-08-11T09:19:16","date_gmt":"2014-08-11T00:19:16","guid":{"rendered":"https:\/\/gunmagisgeek.com\/wordpress\/?p=3670"},"modified":"2014-08-11T09:19:16","modified_gmt":"2014-08-11T00:19:16","slug":"post-3670","status":"publish","type":"post","link":"https:\/\/gunmagisgeek.com\/blog\/d3-js\/3670","title":{"rendered":"\u3010D3.js\u3011\u591a\u89d2\u5f62Brush\u30d7\u30e9\u30b0\u30a4\u30f3"},"content":{"rendered":"<p><a href=\"https:\/\/gist.github.com\/gtb104\/3667340\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2014\/08\/polybrush140806-1.jpg\" alt=\"polybrush example\" width=\"590\" height=\"308\" class=\"aligncenter size-full wp-image-3668\" srcset=\"https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2014\/08\/polybrush140806-1.jpg 590w, https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2014\/08\/polybrush140806-1-287x150.jpg 287w\" sizes=\"auto, (max-width: 590px) 100vw, 590px\" \/><\/a><\/p>\n<p>D3.js\u306e<a href=\"https:\/\/gunmagisgeek.com\/blog\/d3-js\/3545\">brash\u6a5f\u80fd<\/a>\u3067\u306f\u9577\u65b9\u5f62\u3067\u306e\u9078\u629e\u3057\u304b\u3067\u304d\u307e\u305b\u3093\u304c\u3001<a href=\"https:\/\/gist.github.com\/gtb104\/3667340\">polybrush\u30d7\u30e9\u30b0\u30a4\u30f3<\/a>\u3092\u4f7f\u3046\u3068\u591a\u89d2\u5f62(\u30dd\u30ea\u30b4\u30f3)\u3067\u306e\u9078\u629e\u304c\u53ef\u80fd\u3068\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u516c\u5f0f\u306e\u30b5\u30f3\u30d7\u30eb\u3067\u306f\u30dc\u30ed\u30ce\u30a4\u63cf\u753b\u306a\u3069\u304c\u542b\u307e\u308c\u3066\u3044\u308b\u306e\u3067\u3001\u3082\u3063\u3068\u30b7\u30f3\u30d7\u30eb\u306b\u30b5\u30fc\u30af\u30eb\u3092\u9078\u629e\u3059\u308b\u3060\u3051\u306e\u4f8b\u984c\u3092\u4f5c\u6210\u3057\u307e\u3057\u305f\u3002<\/p>\n<h2>\u30b5\u30f3\u30d7\u30eb<\/h2>\n<p><a href=\"http:\/\/shimz.me\/example\/d3js\/brushing\/polybrush\/\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2014\/08\/polybrush140806-2.jpg\" alt=\"simple polybrush example\" width=\"590\" height=\"300\" class=\"aligncenter size-full wp-image-3669\" srcset=\"https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2014\/08\/polybrush140806-2.jpg 590w, https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2014\/08\/polybrush140806-2-295x150.jpg 295w\" sizes=\"auto, (max-width: 590px) 100vw, 590px\" \/><\/a><\/p>\n<p><a href=\"http:\/\/shimz.me\/example\/d3js\/brushing\/polybrush\/\">example<\/a><\/p>\n<p>d3.js\u3068\u3068\u3082\u306bpolybrush.js\u3092\u8aad\u307f\u8fbc\u3093\u3067\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre class=\"lang:xhtml decode:true \" >&lt;script type=\"text\/javascript\" src=\"http:\/\/d3js.org\/d3.v2.min.js\"&gt;&lt;\/script&gt;\r\n&lt;script type=\"text\/javascript\" src=\"polybrush.js\"&gt;&lt;\/script&gt;<\/pre>\n<pre class=\"lang:js decode:true \" >var w = 960;\r\nvar h = 500;\r\n\r\n\/\/svg\u8981\u7d20\u8a2d\u7f6e\r\nvar svg = d3.select(\"#chart\")\r\n\t.append(\"svg:svg\")\r\n\t.attr(\"width\", w)\r\n\t.attr(\"height\", h);\r\n\r\n\/\/\u30c7\u30fc\u30bf\u30bb\u30c3\u30c8\u4f5c\u6210\r\nvar dataSet = d3.range(200).map(function(d) {\r\n\treturn  {x:Math.random() * 1000, y:Math.random() * 1000};\r\n});\r\n\r\n\/\/\u30b9\u30b1\u30fc\u30eb\u521d\u671f\u5316\r\nvar xScale = d3.scale.linear().domain([0, 1000]).range([0, w]);\r\nvar yScale = d3.scale.linear().domain([0, 1000]).range([0, h]);\r\n\r\n\/\/brash\u521d\u671f\u5316\r\nvar brush = d3.svg.polybrush()\r\n\t.x(d3.scale.linear().range([0, w]))\u3000\r\n\t.y(d3.scale.linear().range([0, h]))\r\n\t.on(\"brushstart\", function() {\r\n\t\tsvg.selectAll(\".selected\").classed(\"selected\", false);\r\n\t})\r\n\t.on(\"brush\", function() {\r\n\t\t\/\/\u30dd\u30a4\u30f3\u30c8\u304cbrush\u9078\u629e\u7bc4\u56f2\u5185\u306b\u5b58\u5728\u3057\u3066\u3044\u305f\u3089selected\u30af\u30e9\u30b9\u3092\u4ed8\u52a0\u3059\u308b\r\n\t\tsvg.selectAll(\".point\").classed(\"selected\", function(d) {\t\t\r\n\t\t\tif ( brush.isWithinExtent(xScale(d.x), yScale(d.y)) ) {\r\n\t\t\t\tconsole.log(\"hit\", d.x+\":\"+d.y);\r\n\t\t\t\treturn true;\r\n\t\t\t} else {\r\n\t\t\t\treturn false;\r\n\t\t\t}\r\n\t\t});\r\n\t});\r\n\r\n\/\/brush\u8a2d\u7f6e\t\r\nsvg.append(\"svg:g\")\r\n\t.attr(\"class\", \"brush\")\r\n\t.call(brush);\r\n\r\n\/\/\u30dd\u30a4\u30f3\u30c8(circle)\u8a2d\u7f6e    \r\nvar  points = svg.append(\"svg:g\").attr(\"id\", \"points\");\r\npoints.selectAll(\"circle\")\r\n\t.data(dataSet)\r\n\t.enter()\r\n\t.append(\"svg:circle\")\r\n\t.attr(\"class\", \"point\")\r\n\t.attr(\"id\", function(d, i) { return \"point-\"+i; })\r\n\t.attr(\"transform\", function(d) { return \"translate(\" + [xScale(d.x), yScale(d.y)] + \")\"; })\r\n\t.attr(\"r\", 4)\r\n\t.attr('stroke', 'none');\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>D3.js\u306ebrash\u6a5f\u80fd\u3067\u306f\u9577\u65b9\u5f62\u3067\u306e\u9078\u629e\u3057\u304b\u3067&hellip;<\/p>\n","protected":false},"author":1,"featured_media":3668,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[],"class_list":["post-3670","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\/3670","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=3670"}],"version-history":[{"count":0,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/3670\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/media\/3668"}],"wp:attachment":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/media?parent=3670"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/categories?post=3670"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/tags?post=3670"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}