{"id":2607,"date":"2013-03-06T16:46:49","date_gmt":"2013-03-06T07:46:49","guid":{"rendered":"https:\/\/gunmagisgeek.com\/wordpress\/?p=2607"},"modified":"2018-03-05T15:05:29","modified_gmt":"2018-03-05T06:05:29","slug":"post-2607","status":"publish","type":"post","link":"https:\/\/gunmagisgeek.com\/blog\/d3v4\/2607","title":{"rendered":"\u3010D3.js\u3011\u6c34\u5e73\u30d1\u30f3\u30cb\u30f3\u30b0"},"content":{"rendered":"<p><a href=\"https:\/\/bl.ocks.org\/shimizu\/c9ce56d302c4766fe31037d593f52422\/82cc889d729e6de8dae25c84c7b0c6fc77d67307\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2013\/03\/panning.jpg\" alt=\"panning\" width=\"522\" height=\"417\" class=\"alignnone size-full wp-image-2608\" srcset=\"https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2013\/03\/panning.jpg 522w, https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2013\/03\/panning-188x150.jpg 188w\" sizes=\"auto, (max-width: 522px) 100vw, 522px\" \/><\/a><\/p>\n<p><a href=\"https:\/\/bl.ocks.org\/shimizu\/c9ce56d302c4766fe31037d593f52422\/82cc889d729e6de8dae25c84c7b0c6fc77d67307\">example<\/a><\/p>\n<p>\u30c7\u30fc\u30bf\u3092\u8868\u793a\u3059\u308b\u9818\u57df\u3092\u5236\u9650\u3057\u3066\u3001\u30c9\u30e9\u30c3\u30b0\u3057\u305f\u969b\u306b\u7d9a\u304d\u306e\u30c7\u30fc\u30bf\u3092\u898b\u305b\u308b\u65b9\u6cd5\u3002<br \/>\n\u53c2\u8003\u306b\u3057\u305f\u30b5\u30a4\u30c8\u3067\u306f\u3001\u3053\u306e\u8868\u793a\u65b9\u6cd5\u3092\u300chorizontal panning behavior\u300d\u3068\u547c\u3093\u3067\u3044\u305f\u306e\u3067\u300c\u6c34\u5e73\u30d1\u30f3\u30cb\u30f3\u30b0\u300d\u3068\u3057\u307e\u3057\u305f\u3002<br \/>\n\u30b3\u30fc\u30c9\u306e\u30b3\u30e1\u30f3\u30c8\u306b\u66f8\u3044\u305f\u4ee5\u4e0a\u306e\u8aac\u660e\u304c\u51fa\u6765\u306a\u3044\u306e\u3067\u3001\u8a73\u3057\u304f\u77e5\u308a\u305f\u3044\u65b9\u306f\u4e0b\u8a18\u306e\u30ea\u30f3\u30af\u5148\u3092\u53c2\u7167\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p>\u53c2\u8003<br \/>\n<a href=\"http:\/\/computationallyendowed.com\/blog\/2013\/01\/21\/bounded-panning-in-d3.html\">Bounded Panning in D3<\/a><\/p>\n<h2>\u30b5\u30f3\u30d7\u30eb<\/h2>\n<pre class=\"lang:js decode:true \" >\/\/\u30c7\u30fc\u30bf\u30bb\u30c3\u30c8\u306e\u4f5c\u6210\nconst dataSet = d3.range(1000).map( (d, i)  => { return {x: (i * 10), y: ~~(Math.random()*100)} })\n\n\/\/svg \u30b9\u30c6\u30fc\u30b8\u8a2d\u7f6e\nconst width = 980;\nconst maxWisth = width*4;\nconst thresholdWisth = maxWisth - width;\nconst height = 500;\nconst svg = d3.select('body')\n    .append('svg')\n    .attr('width', width)\n    .attr('height', height)\n    .attr('cursor', 'move'); \n\nconst stage = svg.append(\"g\")            \n            \n\/\/\u30c7\u30fc\u30bf\u30bb\u30c3\u30c8\u306e\u6700\u5927\u5024\u53d6\u5f97\nconst xMax = d3.max(dataSet, d => d.x ); \/\/X\u6700\u5927\u5024\u53d6\u5f97\nconst yMax = d3.max(dataSet, d => d.y ); \/\/Y\u6700\u5927\u5024\u53d6\u5f97\n\nconst margin = 20; \/\/X\u8ef8\u4e21\u7aef\u306e\u30de\u30fc\u30b8\u30f3\n\n\/\/\u30b9\u30b1\u30fc\u30eb\u95a2\u6570\u3092\u4f5c\u6210\nconst xScale = d3.scaleLinear().domain([0, xMax]).range([margin, maxWisth - margin]);\nconst yScale = d3.scaleLinear().domain([0, yMax]).range([height, 0]);\n\n\n\/\/\u30b9\u30b1\u30fc\u30eb\u3092\u5143\u306bpath\u306ed\u5c5e\u6027\u3092\u8a2d\u5b9a\u3059\u308bline\u95a2\u6570\u3092\u4f5c\u6210    \nconst line = d3.line()\n    .x(d => xScale(d.x) )\n    .y(d => yScale(d.y) )\n    .curve(d3.curveBasis)\n\n\/\/\u6298\u308c\u7dda\u30b0\u30e9\u30d5\u63cf\u753b        \nstage.append('g')\n    .datum(dataSet)\n    .append('path')\n    .attr('d', line) \n    .attr('stroke', 'red')\n    .attr('fill', 'none')\n\n\/\/X\u8ef8\u88dc\u52a9\u76ee\u76db\u7dda\u63cf\u753b\nconst x_axis = d3.axisBottom().scale(xScale); \/\/\u30b9\u30b1\u30fc\u30eb\u3092\u5143\u306b\u76ee\u76db\u7dda\u3092\u4f5c\u6210\nstage.append('g')\n    .attr('class', 'x axis')\n    .attr('transform', `translate(0, ${height-margin})`) \n    .call(x_axis);\n    \n\/\/\u30ba\u30fc\u30e0\u30a4\u30d9\u30f3\u30c8\u30ea\u30b9\u30ca\u30fc\u306e\u8a2d\u5b9a\nconst zoom = d3.zoom()\n    .on('zoom', function(){\n        const t = d3.event.transform; \/\/\u30de\u30a6\u30b9\u306e\u79fb\u52d5\u91cf\u3092\u53d6\u5f97\n        let tx = null;\n            \n        \/\/\u79fb\u52d5\u7bc4\u56f2\u3092\u5236\u9650\n        if(t.x <= -thresholdWisth){ \/\/\u53f3\u7aef\u306e\u6700\u5927\u79fb\u52d5\u91cf\u3092\u8a2d\u5b9a\n            tx = -thresholdWisth;\n        }else if(t.x >= 0){ \/\/\u5de6\u7aef\u306e\u6700\u5927\u79fb\u52d5\u91cf\u3092\u8a2d\u5b9a\n            tx = 0;\n        }else{\n            tx = t.x;\n        }\n        \n        \/\/\u30de\u30a6\u30b9\u306b\u79fb\u52d5\u91cf\u306b\u5408\u308f\u305b\u3066\u30b9\u30c6\u30fc\u30b8\u3092\u79fb\u52d5\n        stage.attr('transform', `translate(${tx}, 0)`);\n    });\n    \n\/\/\u30ba\u30fc\u30e0\u30a4\u30d9\u30f3\u30c8\u30ea\u30b9\u30ca\u30fc\u3092svg\u306b\u8a2d\u7f6e    \nsvg.call(zoom);\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>example \u30c7\u30fc\u30bf\u3092\u8868\u793a\u3059\u308b\u9818\u57df\u3092\u5236\u9650\u3057\u3066\u3001\u30c9&hellip;<\/p>\n","protected":false},"author":1,"featured_media":2608,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[69],"tags":[],"class_list":["post-2607","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\/2607","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=2607"}],"version-history":[{"count":0,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/2607\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/media\/2608"}],"wp:attachment":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/media?parent=2607"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/categories?post=2607"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/tags?post=2607"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}