{"id":5139,"date":"2016-09-06T11:30:37","date_gmt":"2016-09-06T02:30:37","guid":{"rendered":"https:\/\/gunmagisgeek.com\/wordpress\/?p=5139"},"modified":"2016-09-06T15:41:25","modified_gmt":"2016-09-06T06:41:25","slug":"post-5139","status":"publish","type":"post","link":"https:\/\/gunmagisgeek.com\/blog\/javascript\/5139","title":{"rendered":"\u3010D3.js\u3011proxy\u3092\u4f7f\u3063\u3066\u30c7\u30fc\u30bf\u30bb\u30c3\u30c8\u304c\u5909\u66f4\u3055\u308c\u305f\u3089\u30c1\u30e3\u30fc\u30c8\u3092\u518d\u63cf\u753b\u3059\u308b\u3002"},"content":{"rendered":"<p>D3.js\u3092\u4f7f\u3063\u3066\u30c7\u30fc\u30bf\u30d3\u30b8\u30e5\u30a2\u30e9\u30a4\u30bc\u30fc\u30b7\u30e7\u30f3\u3092\u4f5c\u6210\u3059\u308b\u3068\u304d\u306b\u3042\u308a\u304c\u3061\u306a\u51e6\u7406\u3068\u3057\u3066\u3001\u5165\u529b\u30d5\u30a9\u30fc\u30e0\u306e\u5024\u304c\u5909\u66f4\u3055\u308c\u305f\u3089\u30c1\u30e3\u30fc\u30c8\u3092\u518d\u63cf\u753b\u3059\u308b\u3068\u3044\u3046\u306e\u304c\u3042\u308a\u307e\u3059\u3002\u5165\u529b\u30d5\u30a9\u30fc\u30e0\u306echange\u30a4\u30d9\u30f3\u30c8\u304c\u767a\u706b\u3057\u305f\u3089\u30d5\u30a9\u30fc\u30e0\u306e\u5024\u3092\u53d6\u5f97\u3057\u3066redraw\u3059\u308b\u308f\u3051\u3067\u3059\u304c\u3001\u5165\u529b\u9805\u76ee\u306e\u6570\u304c\u5897\u3048\u3066\u304d\u305f\u308a\u3059\u308b\u3068\u7ba1\u7406\u304c\u9762\u5012\u306b\u306a\u3063\u3066\u304d\u307e\u3059\u3002<br \/>\n\u3067\u304d\u308b\u3053\u3068\u306a\u3089\u3001\u5165\u529b\u30d5\u30a9\u30fc\u30e0\u306e\u30a4\u30d9\u30f3\u30c8\u3068\u30c1\u30e3\u30fc\u30c8\u306e\u63cf\u753b\u306f\u758e\u7d50\u5408\u306b\u3057\u3066\u3001\u30c7\u30fc\u30bf\u30bb\u30c3\u30c8\u304c\u5909\u66f4\u3055\u308c\u305f\u3089\u30c1\u30e3\u30fc\u30c8\u3092\u63cf\u753b\u3059\u308b\u3088\u3046\u306a\u51e6\u7406\u306b\u3057\u305f\u3044\u3068\u3053\u308d\u3067\u3059\u3002<br \/>\nECMAScript 2015\u306b\u3066\u5b9f\u88c5\u3055\u308c\u305fproxy\u6a5f\u80fd\u3092\u4f7f\u3046\u3068\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u5909\u66f4\u3092\u7c21\u5358\u306b\u76e3\u8996\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u306e\u3067\u3001\u30c7\u30fc\u30bf\u30bb\u30c3\u30c8\u306e\u5909\u66f4\u3092\u76e3\u8996\u3057\u3066\u518d\u63cf\u753b\u51e6\u7406\u3092\u884c\u3046\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u203b Proxy Object\u306f2016\/9\/6\u73fe\u5728\u3001\u4e00\u90e8\u306e\u30d6\u30e9\u30a6\u30b6\u3067\u3057\u304b\u4f7f\u7528\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u305b\u3093\u3002<\/p>\n<p><a href=\"http:\/\/caniuse.com\/#search=proxy%20object\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2016\/09\/Can-I-use...-Support-tables-for-HTML5-CSS3-etc-2016-09-06-10-52-51.png\" alt=\"Can I use Proxy Object\" width=\"590\" height=\"211\" class=\"aligncenter size-full wp-image-5140 border\" srcset=\"https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2016\/09\/Can-I-use...-Support-tables-for-HTML5-CSS3-etc-2016-09-06-10-52-51.png 590w, https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2016\/09\/Can-I-use...-Support-tables-for-HTML5-CSS3-etc-2016-09-06-10-52-51-300x107.png 300w\" sizes=\"auto, (max-width: 590px) 100vw, 590px\" \/><\/a><\/p>\n<p><a href=\"http:\/\/caniuse.com\/#search=proxy%20object\">Can I use&#8230; Support tables for HTML5, CSS3, etc<\/a><\/p>\n<h2>\u7c21\u5358\u306a\u4f7f\u3044\u65b9<\/h2>\n<p>proxy\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u6a5f\u80fd\u306b\u3064\u3044\u3066\u306f\u3001<a href=\"https:\/\/developer.mozilla.org\/ja\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/Proxy\">MDN<\/a>\u3092\u53c2\u7167\u3057\u3066\u3044\u305f\u3060\u304f\u3068\u3057\u3066\u3001\u6700\u3082\u5358\u7d14\u306ageter,seter\u306e\u76e3\u8996\u51e6\u7406\u3092\u8a66\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n<pre class=\"lang:js decode:true \" >\/\/\u30c7\u30fc\u30bf\u30bb\u30c3\u30c8\r\nvar data = {}\r\n\r\n\/\/proxy\u306b\u8a2d\u5b9a\u3059\u308b\u30cf\u30f3\u30c9\u30e9\r\nvar proxyHandler = {\r\n    get: function(target, prop, value){\r\n        console.log(\"get!\", target)\r\n       return target[prop]\r\n    },\r\n    set: function(target, prop, value){\r\n        console.log(\"set!\", target)\r\n        target[prop] = value\r\n    }\r\n}\r\n\r\n\/\/\u30c7\u30fc\u30bf\u30bb\u30c3\u30c8\u3092\u675f\u7e1b\u3057\u305f\u30d7\u30ed\u30ad\u30b7\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u751f\u6210\r\nvar proxy = new Proxy(data, proxyHandler) \r\n    <\/pre>\n<p>\u4e0a\u8a18\u306e\u30b3\u30fc\u30c9\u306f\u3001data\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306bgeter,seter\u306e\u30c8\u30e9\u30c3\u30d7\u3092\u5b9a\u7fa9\u3057\u305f\u30cf\u30f3\u30c9\u30e9\u3092\u675f\u7e1b\u3057\u3001proxy\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u751f\u6210\u3057\u3066\u3044\u307e\u3059\u3002<br \/>\n\u5b9f\u969b\u306b\u30d6\u30e9\u30a6\u30b6\u306eJavaScript\u30b3\u30f3\u30bd\u30fc\u30eb\u4e0a\u3067proxy\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u64cd\u4f5c\u3057\u305f\u7d50\u679c\u304c\u4ee5\u4e0b\u3067\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2016\/09\/proxy2016-09-06-10-20-19.png\" alt=\"proxy2016-09-06 10-20-19\" width=\"369\" height=\"377\" class=\"alignnone size-full wp-image-5141 border\" srcset=\"https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2016\/09\/proxy2016-09-06-10-20-19.png 369w, https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2016\/09\/proxy2016-09-06-10-20-19-147x150.png 147w\" sizes=\"auto, (max-width: 369px) 100vw, 369px\" \/><\/p>\n<p>proxy\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306b\u65b0\u305f\u306a\u30d7\u30ed\u30d1\u30c6\u30a3\u3092\u8a2d\u5b9a\u3059\u308b\u3068data\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306b\u305d\u306e\u5185\u5bb9\u304c\u53cd\u6620\u3055\u308c\u3066\u3044\u308b\u306e\u304c\u898b\u3066\u53d6\u308c\u307e\u3059\u3002<br \/>\n\u540c\u6642\u306b\u30cf\u30f3\u30c9\u30e9\u5185\u306b\u8a18\u8ff0\u3055\u308c\u305fconsole.log\u304c\u5b9f\u884c\u3055\u308c\u3066\u3044\u307e\u3059\u3002<br \/>\nproxy\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u3067\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306b\u7c21\u5358\u306bobserve\u3092\u4ed5\u8fbc\u3080\u3053\u3068\u304c\u3067\u304d\u307e\u3057\u305f\u3002<\/p>\n<h2>D3\u30b5\u30f3\u30d7\u30eb<\/h2>\n<p>proxy\u30cf\u30f3\u30c9\u30e9\u5185\u306b\u30c1\u30e3\u30fc\u30c8\u3092\u518d\u63cf\u753b\u3059\u308b\u51e6\u7406\u3092\u631f\u307f\u8fbc\u307f\u3001\u30c7\u30fc\u30bf\u30bb\u30c3\u30c8\u306b\u5909\u66f4\u304c\u3042\u3063\u305f\u3089\u30c1\u30e3\u30fc\u30c8\u3092\u518d\u63cf\u753b\u3059\u308b\u30b5\u30f3\u30d7\u30eb\u3067\u3059\u3002<\/p>\n<p><a href=\"http:\/\/bl.ocks.org\/shimizu\/b8ac61e2f8dd42add0f87644c5c0c7c6\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2016\/09\/D3-use-Proxy-bl.ocks_.org-2016-09-06-11-25-03.png\" alt=\"D3 - use Proxy\" width=\"955\" height=\"505\" class=\"aligncenter size-full wp-image-5142\" srcset=\"https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2016\/09\/D3-use-Proxy-bl.ocks_.org-2016-09-06-11-25-03.png 955w, https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2016\/09\/D3-use-Proxy-bl.ocks_.org-2016-09-06-11-25-03-284x150.png 284w, https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2016\/09\/D3-use-Proxy-bl.ocks_.org-2016-09-06-11-25-03-768x406.png 768w\" sizes=\"auto, (max-width: 955px) 100vw, 955px\" \/><\/a><\/p>\n<p><a href=\"http:\/\/bl.ocks.org\/shimizu\/b8ac61e2f8dd42add0f87644c5c0c7c6\">bl.ocks &#8211; D3 use Proxy<\/a><\/p>\n<pre class=\"lang:js decode:true \" >!(function(){\r\n    \"use strict\";\r\n    \r\n    const dataSet = [\r\n        {name:\"tokyo\", value:\"100\"},\r\n        {name:\"gunma\", value:\"200\"},\r\n        {name:\"saitama\", value:\"300\"}\r\n    ]\r\n    \r\n    \/\/\u30d0\u30fc\u30c1\u30e3\u30fc\u30c8\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u751f\u6210\r\n    const BarChart = createVBarChart()\r\n        .margin({top:40, left:100, bottom:40, right:10})\r\n        .x(function(d){ return d[\"name\"] })\r\n        .y(function(d){ return d[\"value\"] })\r\n    \r\n    \/\/\u30c1\u30e3\u30fc\u30c8\u3092\u63cf\u753b\u3059\u308b\r\n    const selector =  d3.selectAll(\"#chart\").datum(dataSet)\r\n        .call(BarChart)\r\n        \r\n    \/\/\u30c7\u30fc\u30bf\u30bb\u30c3\u30c8\u306e\u5185\u5bb9\u304c\u5909\u66f4\u3055\u308c\u305f\u3089\u30c1\u30e3\u30fc\u30c8\u3092\u30a2\u30c3\u30d7\u30c7\u30fc\u30c8\u3059\u308b    \r\n    const proxyHandler = {\r\n        get: function(target, name, value){\r\n           return target[name]\r\n        },\r\n        set: function(target, name, value){\r\n            if (name == \"value\" &amp;&amp; isNaN(+value)) throw new TypeError(\"\u578b\u304c\u3061\u304c\u3046\u3088\")\r\n            target[name] = value\r\n            selector.update(dataSet) \/\/\u30c1\u30e3\u30fc\u30c8\u30a2\u30c3\u30d7\u30c7\u30fc\u30c8\r\n        }\r\n    }\r\n    \r\n    \/\/\u30c7\u30fc\u30bf\u30bb\u30c3\u30c8\u3092\u30cd\u30b9\u30c8\u3057\u3001proxy\u3067\u5305\u3080\r\n    const nested = d3.nest()\r\n        .rollup(function(d){ return new Proxy(d[0], proxyHandler) })\r\n        .key(function(d){ return d.name })\r\n        .map(dataSet)\r\n    \r\n    \r\n    \/\/\u30c6\u30ad\u30b9\u30c8\u30dc\u30c3\u30af\u30b9\u306e\u5024\u304c\u5909\u66f4\u3055\u308c\u305f\u3089\u30c7\u30fc\u30bf\u30bb\u30c3\u30c8\u3092porxy\u7d4c\u7531\u3067\u5909\u66f4\u3059\u308b    \r\n    const  updateDataset = function() {\r\n        nested[\"$\"+this.name].value = this.value    \r\n    }\r\n    \r\n    const textBox = d3.selectAll(\".input\")\r\n        .on(\"change\", updateDataset)    \r\n    \r\n    \/\/\u30c6\u30ad\u30b9\u30c8\u30dc\u30c3\u30af\u30b9\u306b\u521d\u671f\u5024\u3092\u6e21\u3059\u3002    \r\n    textBox.each(function(){\r\n            this.value = nested[\"$\"+this.name].value\r\n        })\r\n\r\n}());<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>D3.js\u3092\u4f7f\u3063\u3066\u30c7\u30fc\u30bf\u30d3\u30b8\u30e5\u30a2\u30e9\u30a4\u30bc\u30fc\u30b7\u30e7\u30f3\u3092\u4f5c&hellip;<\/p>\n","protected":false},"author":1,"featured_media":5141,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[69,6],"tags":[],"class_list":["post-5139","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-d3v4","category-javascript","has-post-thumbnail-archive"],"_links":{"self":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/5139","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=5139"}],"version-history":[{"count":0,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/5139\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/media\/5141"}],"wp:attachment":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/media?parent=5139"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/categories?post=5139"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/tags?post=5139"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}