{"id":200584,"date":"2013-11-02T04:15:03","date_gmt":"2013-11-02T00:15:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=200584"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=200584","title":{"rendered":"<span class=\"post_title\">\u0412\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0432 3D, \u0438\u043b\u0438 \u043a\u0430\u043a \u043f\u043e\u0434\u0440\u0443\u0436\u0438\u0442\u044c D3 \u0438 Three.js<\/span>"},"content":{"rendered":"<div class=\"content html_format\">   \t\u0415\u0441\u043b\u0438 \u0412\u044b \u0443\u0436\u0435 \u0441\u043b\u044b\u0448\u0430\u043b\u0438 \u043e <a href=\"http:\/\/habrahabr.ru\/search\/?q=[d3.js]&amp;target_type=posts\">D3<\/a> \u0438 <a href=\"http:\/\/habrahabr.ru\/search\/?q=[three.js]&amp;target_type=posts\">Three.js<\/a>, \u044d\u0442\u0430 \u0441\u0442\u0430\u0442\u044c\u044f \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f \u0412\u0430\u043c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0439. \u0412 \u043d\u0435\u0439 \u0440\u0435\u0447\u044c \u043f\u043e\u0439\u0434\u0451\u0442 \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u0437\u0430\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u044d\u0442\u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0432\u043c\u0435\u0441\u0442\u0435 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0442\u0440\u0451\u0445\u043c\u0435\u0440\u043d\u044b\u0445 \u0441\u0446\u0435\u043d, \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u044d\u0442\u043e\u0439 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0433\u0438\u0441\u0442\u043e\u0433\u0440\u0430\u043c\u043c\u044b:<\/p>\n<p>  <a href=\"http:\/\/fiddle.jshell.net\/LHtAx\/4\/show\/\"><\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\"  src=\"http:\/\/habr.habrastorage.org\/post_images\/b2f\/609\/334\/b2f6093343773649f58b954ca4ced0a2.gif\"\/><\/div>\n<p><\/a><\/p>\n<p>  <a name=\"habracut\"><\/a><\/p>\n<h4>\u041e\u0442\u043a\u0443\u0434\u0430 \u043d\u043e\u0433\u0438 \u0440\u0430\u0441\u0442\u0443\u0442?<\/h4>\n<p>  \u041d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u043d\u0430\u0437\u0430\u0434 \u043c\u044b \u0432 <a href=\"http:\/\/habrahabr.ru\/users\/codeorchestra\/\" class=\"user_link\">CodeOrchestra<\/a> \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043b\u0438 \u0441 \u043f\u043e\u0440\u0442\u043e\u043c D3 \u043d\u0430 AS3\/DSL \u043f\u043e\u0434 \u043a\u043e\u0434\u043e\u0432\u044b\u043c \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c \u00abD6\u00bb (\u043e\u0442 D3 + 3D). \u041d\u0430\u0448 \u043f\u043e\u0440\u0442 \u043f\u043e\u043a\u0440\u044b\u0432\u0430\u043b \u043b\u0438\u0448\u044c \u0441\u0430\u043c\u044b\u0435 \u0431\u0430\u0437\u043e\u0432\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 D3, \u043d\u043e \u0437\u0430\u0442\u043e \u0443\u043c\u0435\u043b \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u043c\u0438 3D \u0434\u0432\u0438\u0436\u043a\u0430\u043c\u0438 \u043d\u0430 AS3 \u00ab\u0438\u0437 \u043a\u043e\u0440\u043e\u0431\u043a\u0438\u00bb. \u0418 \u0445\u043e\u0442\u044f \u043c\u044b \u0442\u0430\u043a \u0438 \u043d\u0435 \u0432\u044b\u0432\u0435\u043b\u0438 D6 \u0432 \u0441\u0432\u0435\u0442, \u0442\u0430 \u0441\u0430\u043c\u0430\u044f \u0438\u0434\u0435\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c D3 \u0434\u043b\u044f 3D \u0441 \u0442\u0435\u0445 \u043f\u043e\u0440 \u043d\u0435 \u043f\u043e\u043a\u0438\u0434\u0430\u0435\u0442 \u043d\u0430\u0448\u0438 \u0443\u043c\u044b. \u0414\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e, \u0435\u0441\u043b\u0438 \u0412\u044b \u0437\u0430\u0433\u043b\u044f\u043d\u0435\u0442\u0435 \u0432 <a href=\"https:\/\/github.com\/mbostock\/d3\/wiki\/Gallery\">\u0433\u0430\u043b\u0435\u0440\u0435\u044e D3<\/a>, \u0412\u044b \u043d\u0435 \u043d\u0430\u0439\u0434\u0451\u0442\u0435 \u0442\u0430\u043c \u043d\u0438 \u043e\u0434\u043d\u043e\u0433\u043e \u0442\u0440\u0451\u0445\u043c\u0435\u0440\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430. \u041f\u0440\u0438\u0447\u0438\u043d\u0430 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e D3 \u0441\u0438\u043b\u044c\u043d\u043e \u0437\u0430\u0442\u043e\u0447\u0435\u043d\u0430 \u043d\u0430 \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 DOM \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0430, \u0438 \u0432\u0440\u043e\u0434\u0435 \u043a\u0430\u043a \u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432. \u041e\u0434\u043d\u0430\u043a\u043e, \u043e\u0431\u043b\u0430\u0434\u0430\u044f \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e\u0439 \u043c\u043e\u0442\u0438\u0432\u0430\u0446\u0438\u0435\u0439, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0435\u0451 \u0437\u0430\u0441\u0442\u0430\u0432\u0438\u0442\u044c.<\/p>\n<p>  <\/p>\n<h4>\u0418\u0442\u0430\u043a, \u043d\u0430\u0447\u043d\u0451\u043c<\/h4>\n<p>  \u041d\u0430\u0447\u043d\u0451\u043c \u0441 <a href=\"http:\/\/jsfiddle.net\/LHtAx\/\">\u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0434\u0432\u0443\u0445\u043c\u0435\u0440\u043d\u043e\u0439 \u0433\u0438\u0441\u0442\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c D3<\/a> (\u0442\u0443\u0442 \u0438 \u0434\u0430\u043b\u0435\u0435 \u043a\u043e\u0434 \u0430\u0434\u0430\u043f\u0442\u0438\u0440\u043e\u0432\u0430\u043d \u0438\u0437 \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0445 \u0443\u0440\u043e\u043a\u043e\u0432 D3 [<a href=\"http:\/\/mbostock.github.io\/d3\/tutorial\/bar-1.html\">1<\/a>] \u0438 [<a href=\"http:\/\/mbostock.github.io\/d3\/tutorial\/bar-2.html\">2<\/a>], \u0438 \u0441\u043e\u043a\u0440\u0430\u0449\u0451\u043d \u0440\u0430\u0434\u0438 \u0447\u0438\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438):<\/p>\n<pre><code class=\"javascript\">d3.select(&quot;.chart&quot;)   .selectAll()     .data(data)   .enter().append(&quot;div&quot;)     .style(&quot;width&quot;, function(d) { return d * 10 + &quot;px&quot;; }); <\/code><\/pre>\n<p>  \u0412 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b D3 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0442 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0432\u043e\u043b\u0448\u0435\u0431\u043d\u044b\u0435 DOM-\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 (\u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a \u0441\u0435\u043b\u0435\u043a\u0442\u043e\u0440 <code>.chart<\/code> \u0438\u043b\u0438 \u0438\u043c\u044f \u0442\u0435\u0433\u0430 <code>div<\/code>), \u0447\u0442\u043e \u043a\u0440\u0430\u0439\u043d\u0435 \u043d\u0435\u0443\u0434\u043e\u0431\u043d\u043e \u0434\u043b\u044f \u043d\u0430\u0448\u0438\u0445 \u0446\u0435\u043b\u0435\u0439. \u041a \u0441\u0447\u0430\u0441\u0442\u044c\u044e, \u0443 \u044d\u0442\u0438\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0438\u043c\u0435\u044e\u0442\u0441\u044f \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0435 \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u044b. \u042d\u0442\u0438 \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u044b \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u0434\u043b\u044f \u0441\u043a\u0443\u0447\u043d\u044b\u0445 \u0432\u0435\u0449\u0435\u0439 \u0432\u0440\u043e\u0434\u0435 \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0432\u044b\u0431\u043e\u0440\u043e\u043a. \u041c\u044b \u0436\u0435 \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f \u0438\u043c\u0438, \u0447\u0442\u043e\u0431\u044b \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0442\u044c \u043d\u0430\u0448 \u043f\u0440\u0438\u043c\u0435\u0440 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"javascript\">function newDiv() {     return document.createElement(&quot;div&quot;); }   var chart = {     appendChild: function (child) {         \/\/ \u044d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u0432\u0430\u043d\u0430 \u0438\u0437 append() \u043f\u043e\u0441\u043b\u0435 newDiv()         return document.getElementById(&quot;chartId&quot;)             .appendChild(child);     },     querySelectorAll: function () {         \/\/ \u044d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0437\u0432\u0430\u043d\u0430 \u0438\u0437 selectAll()         return [];     } }   d3.select( chart )   .selectAll()     .data(data)   .enter().append( newDiv )     .style(&quot;width&quot;, function(d) { return d * 10 + &quot;px&quot;; }); <\/code><\/pre>\n<p>  \u041a\u0430\u043a \u0432\u0438\u0434\u0438\u043c, \u043c\u044b 1) \u0443\u043a\u0430\u0437\u0430\u043b\u0438 D3 \u043a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c <code>div<\/code> \u0432 \u044f\u0432\u043d\u043e\u043c \u0432\u0438\u0434\u0435, \u0438 2) \u0443\u0431\u0435\u0434\u0438\u043b\u0438 D3 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043d\u0430\u0448 \u043e\u0431\u044a\u0435\u043a\u0442 chart \u2014 <a href=\"http:\/\/ru.wikipedia.org\/wiki\/\u0423\u0442\u0438\u043d\u0430\u044f_\u0442\u0438\u043f\u0438\u0437\u0430\u0446\u0438\u044f\">\u0443\u0442\u043a\u0430<\/a>. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c <a href=\"http:\/\/jsfiddle.net\/LHtAx\/1\/\">\u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043e\u0434\u0430<\/a> \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e \u043d\u0435 \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u0441\u044f.<\/p>\n<p>  <\/p>\n<h4>\u0422\u0430\u043a \u0447\u0442\u043e \u043d\u0430\u0441\u0447\u0451\u0442 3D ?<\/h4>\n<p>  \u0421\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043e\u043c \u0434\u0435-\u0444\u0430\u043a\u0442\u043e \u0434\u043b\u044f 3D \u0433\u0440\u0430\u0444\u0438\u043a\u0438 \u0432 JavaScript \u043d\u0430 \u0441\u0435\u0433\u043e\u0434\u043d\u044f\u0448\u043d\u0438\u0439 \u0434\u0435\u043d\u044c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f Three.js. \u0415\u0441\u043b\u0438 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0434\u0435\u043b\u0430\u0442\u044c 3D \u0432 D3, \u043d\u0430\u043c \u043d\u0430\u0434\u043e \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0443\u0431\u0435\u0434\u0438\u0442\u044c D3 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0432\u044b\u0431\u043e\u0440\u043a\u0430\u043c\u0438 \u0438\u0437 \u0442\u0440\u0451\u0445\u043c\u0435\u0440\u043d\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 Three.js. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0432 \u043f\u0440\u043e\u0442\u043e\u0442\u0438\u043f Object3D:<\/p>\n<pre><code class=\"javascript\">\/\/ \u044d\u0442\u0438 \u043c\u0435\u0442\u043e\u0434\u044b \u043d\u0443\u0436\u043d\u044b \u0434\u043b\u044f D3-\u0448\u043d\u044b\u0445 .append() \u0438 .selectAll() THREE.Object3D.prototype.appendChild = function (c) { this.add(c); return c; }; THREE.Object3D.prototype.querySelectorAll = function () { return []; };  \/\/ \u0430 \u044d\u0442\u043e\u0442 - \u0434\u043b\u044f D3-\u0448\u043d\u043e\u0433\u043e .attr() THREE.Object3D.prototype.setAttribute = function (name, value) {     var chain = name.split('.');     var object = this;     for (var i = 0; i &lt; chain.length - 1; i++) {         object = object[chain[i]];     }     object[chain[chain.length - 1]] = value; } <\/code><\/pre>\n<p>  \u042d\u0442\u043e\u0433\u043e \u0432\u043f\u043e\u043b\u043d\u0435 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f <a href=\"http:\/\/jsfiddle.net\/LHtAx\/2\/\">\u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0435\u0439 \u0442\u0440\u0451\u0445\u043c\u0435\u0440\u043d\u043e\u0439 \u0433\u0438\u0441\u0442\u043e\u0433\u0440\u0430\u043c\u043c\u044b<\/a>:<\/p>\n<pre><code class=\"javascript\">function newBar () {     return new THREE.Mesh( geometry, material ); }  chart3d = new THREE.Object3D();  d3.select( chart3d )   .selectAll()     .data(data)   .enter().append( newBar )     .attr(&quot;position.x&quot;, function(d, i) { return 30 * (i - 3); })     .attr(&quot;position.y&quot;, function(d, i) { return d; })     .attr(&quot;scale.y&quot;, function(d, i) { return d \/ 10; }) <\/code><\/pre>\n<p>  <\/p>\n<h4>\u042d\u0442\u043e \u0432\u0441\u0451 ?<\/h4>\n<p>  \u0412\u043e\u0432\u0441\u0435 \u043d\u0435\u0442. \u0427\u0442\u043e\u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0433\u043b\u0430\u0432\u043d\u0443\u044e \u0444\u0438\u0448\u043a\u0443 D3 \u2014 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u2014 \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0435\u0440\u0435\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430\u0448\u0438 \u043e\u0431\u043c\u0430\u043d\u043a\u0438. \u0412\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, \u0447\u0442\u043e\u0431\u044b D3 \u043c\u043e\u0433\u043b\u0430 \u0438\u043d\u0442\u0435\u0440\u043f\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u00ab\u0430\u0442\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432\u00bb, \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432 \u043f\u0440\u043e\u0442\u043e\u0442\u0438\u043f Object3D \u043c\u0435\u0442\u043e\u0434 getAttribute:<\/p>\n<pre><code class=\"javascript\">THREE.Object3D.prototype.getAttribute = function (name) {     var chain = name.split('.');     var object = this;     for (var i = 0; i &lt; chain.length - 1; i++) {         object = object[chain[i]];     }     return object[chain[chain.length - 1]]; } <\/code><\/pre>\n<p>  \u0412\u043e-\u0432\u0442\u043e\u0440\u044b\u0445, selectAll() \u0434\u043e\u043b\u0436\u0435\u043d \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0432\u044b\u0431\u043e\u0440\u043a\u0443 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u044e\u0449\u0438\u0445\u0441\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0442\u0431\u043e\u0440 \u043d\u0430\u0441\u043b\u0435\u0434\u043d\u0438\u043a\u043e\u0432 Object3D \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430:<\/p>\n<pre><code class=\"javascript\">THREE.Object3D.prototype.querySelectorAll = function (selector) {     var matches = [];     var type = eval(selector);     for (var i = 0; i &lt; this.children.length; i++) {         var child = this.children[i];         if (child instanceof type) {             matches.push(child);         }     }     return matches; } <\/code><\/pre>\n<p>  \u0427\u0442\u043e\u0431\u044b <a href=\"http:\/\/jsfiddle.net\/LHtAx\/3\/\">\u0437\u0430\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043d\u0430\u0448\u0438 \u0441\u0442\u043e\u043b\u0431\u0446\u044b \u0442\u0430\u043d\u0446\u0435\u0432\u0430\u0442\u044c<\/a>, \u0442\u0435\u043f\u0435\u0440\u044c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0435\u0440\u0438\u043e\u0434\u0438\u0447\u0435\u0441\u043a\u0438 \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435:<\/p>\n<pre><code class=\"javascript\">var N = 9, v = 30, data = d3.range(9).map(next);  function next () {     return (v = ~~Math.max(10, Math.min(90, v + 20 * (Math.random() - .5)))); }  setInterval(function () {   data.shift(); data.push(next()); update(); }, 1500);  function update () {     \/\/ \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c D3 \u0434\u043b\u044f \u0441\u0442\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f 3D \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432     var bars = d3.select( chart3d )         .selectAll(&quot;THREE.Mesh&quot;)         .data(data);          bars.enter().append( newBar )         .attr(&quot;position.x&quot;, function(d, i) { return 30 * (i - N\/2); });          bars.transition()         .duration(1000)         .attr(&quot;position.y&quot;, function(d, i) { return d; })         .attr(&quot;scale.y&quot;, function(d, i) { return d \/ 10; }); } <\/code><\/pre>\n<p>  \u0418\u0442\u0430\u043a, \u043e\u0431\u0449\u0438\u0439 \u043f\u0440\u0438\u043d\u0446\u0438\u043f \u0441\u043f\u0430\u0440\u0438\u0432\u0430\u043d\u0438\u044f D3 \u0441 Three.js \u0412\u0430\u043c \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u044f\u0441\u0435\u043d \u2014 \u043c\u044b \u043f\u043e\u0441\u0442\u0435\u043f\u0435\u043d\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0432 \u043f\u0440\u043e\u0442\u043e\u0442\u0438\u043f Object3D \u043c\u0435\u0442\u043e\u0434\u044b, \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u044b\u0435 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u044e\u0449\u0435\u0433\u043e \u043d\u0430\u0441 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u0430 D3. \u041d\u043e \u0434\u043b\u044f \u0437\u0430\u043a\u0440\u0435\u043f\u043b\u0435\u043d\u0438\u044f \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0433\u0438\u0441\u0442\u043e\u0433\u0440\u0430\u043c\u043c\u044b, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043f\u0440\u0438\u0432\u044f\u0437\u043a\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e \u043a\u043b\u044e\u0447\u0443 \u0438 \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u0432\u044b\u0431\u043e\u0440\u043a\u043e\u0439 \u0443\u0434\u0430\u043b\u044f\u0435\u043c\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432. \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u0432 \u043f\u0440\u043e\u0442\u043e\u0442\u0438\u043f Object3D \u043c\u0435\u0442\u043e\u0434 removeChild:<\/p>\n<pre><code class=\"javascript\">THREE.Object3D.prototype.removeChild = function (c) { this.remove(c); } <\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u0431\u044b \u0412\u044b \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u043b\u0438 \u0442\u0435\u043f\u0435\u0440\u044c \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043c\u0435\u0442\u043e\u0434\u043e\u043c remove() \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \u0443\u0434\u0430\u043b\u044f\u0435\u043c\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u0442\u043e \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u043b\u0438 \u0431\u044b, \u0447\u0442\u043e \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442. \u041f\u043e\u0447\u0435\u043c\u0443? \u041e\u0442\u0432\u0435\u0442 \u043b\u0435\u0433\u043a\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0432 <a href=\"https:\/\/github.com\/mbostock\/d3\/blob\/fd5ee5de64338f55e95cacddd80a8c86633be526\/src\/selection\/remove.js\">\u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0430\u0445 D3<\/a> \u2014 \u043c\u0435\u0442\u043e\u0434 remove() \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 parentNode \u0432\u044b\u0431\u043e\u0440\u043a\u0438, \u0430 \u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f \u0443\u0434\u0430\u043b\u044f\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442 \u0438\u0437 \u0441\u0432\u043e\u0435\u0433\u043e \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044f. \u0427\u0442\u043e\u0431\u044b \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u043c, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u043a\u043e\u0440\u0440\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0448\u0443 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e appendChild():<\/p>\n<pre><code class=\"javascript\">THREE.Object3D.prototype.appendChild = function (c) {     this.add(c);     \/\/ \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e parentNode     c.parentNode = this;     return c; } <\/code><\/pre>\n<p>  <\/p>\n<h4>\u0418\u0442\u043e\u0433<\/h4>\n<p>  \u0410 \u0432 \u0438\u0442\u043e\u0433\u0435 \u0443 \u043d\u0430\u0441 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0430\u0441\u044c <a href=\"http:\/\/jsfiddle.net\/LHtAx\/4\/\">\u0432\u043e\u0442 \u0442\u0430\u043a\u0430\u044f \u043a\u0440\u0430\u0441\u043e\u0442\u0430<\/a>:<\/p>\n<pre><code class=\"javascript\">var N = 9, t = 123, v = 30, data = d3.range(9).map(next);  function next () {   return {     time: ++t,     value: v = ~~Math.max(10, Math.min(90, v + 20 * (Math.random() - .5)))   }; }  function update () { \t\/\/ \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c D3 \u0434\u043b\u044f \u0441\u0442\u043e\u0437\u0434\u0430\u043d\u0438\u044f, \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0438 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f 3D \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432 \tvar bars = d3.select( chart3d ) \t\t.selectAll(&quot;THREE.Mesh&quot;) \t\t.data(data, function(d) { return d.time; });  \tbars.transition() \t\t.duration(1000) \t\t.attr(&quot;position.x&quot;, function(d, i) { return 30 * (i - N \/ 2); })  \tbars.enter().append( newBar ) \t\t.attr(&quot;position.x&quot;, function(d, i) { return 30 * (i - N \/ 2 + 1); }) \t\t.attr(&quot;position.y&quot;, 0) \t\t.attr(&quot;scale.y&quot;, 1e-3) \t  .transition() \t\t.duration(1000) \t\t.attr(&quot;position.x&quot;, function(d, i) { return 30 * (i - N \/ 2); }) \t\t.attr(&quot;position.y&quot;, function(d, i) { return d.value; }) \t\t.attr(&quot;scale.y&quot;, function(d, i) { return d.value \/ 10; }) \t\t \tbars.exit().transition() \t\t.duration(1000) \t\t.attr(&quot;position.x&quot;, function(d, i) { return 30 * (i - N \/ 2 - 1); }) \t\t.attr(&quot;position.y&quot;, 0) \t\t.attr(&quot;scale.y&quot;, 1e-3) \t\t.remove() } <\/code><\/pre>\n<p>  \u041a\u0430\u043a \u0432\u0438\u0434\u0438\u043c, D3 \u043f\u0440\u0435\u043a\u0440\u0430\u0441\u043d\u043e \u0441\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441 3D, \u0435\u0441\u043b\u0438 \u0435\u0439 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u043e\u043c\u043e\u0447\u044c, \u0430 Three.js \u043d\u0435 \u0441\u043e\u0437\u0434\u0430\u0451\u0442 \u0432 \u044d\u0442\u043e\u043c \u043d\u0438\u043a\u0430\u043a\u0438\u0445 \u043f\u0440\u043e\u0431\u043b\u0435\u043c. \u041e\u0431\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0438\u043c\u0435\u044e\u0442 \u0441\u0432\u043e\u0438 \u0441\u0438\u043b\u044c\u043d\u044b\u0435 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u0438 \u044f \u043d\u0430\u0434\u0435\u044e\u0441\u044c, \u0447\u0442\u043e \u044d\u0442\u0430 \u0441\u0442\u0430\u0442\u044c\u044f \u043e\u0442\u043a\u0440\u044b\u043b\u0430 \u0412\u0430\u043c \u043f\u0443\u0442\u044c \u043a \u0438\u0445 \u0433\u0430\u0440\u043c\u043e\u043d\u0438\u0447\u043d\u043e\u043c\u0443 \u0441\u043e\u0447\u0435\u0442\u0430\u043d\u0438\u044e \u0432 \u0412\u0430\u0448\u0438\u0445 \u0431\u0443\u0434\u0443\u0449\u0438\u0445 \u0440\u0430\u0431\u043e\u0442\u0430\u0445.    \t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/200584\/\"> http:\/\/habrahabr.ru\/post\/200584\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">   \t\u0415\u0441\u043b\u0438 \u0412\u044b \u0443\u0436\u0435 \u0441\u043b\u044b\u0448\u0430\u043b\u0438 \u043e <a href=\"http:\/\/habrahabr.ru\/search\/?q=[d3.js]&amp;target_type=posts\">D3<\/a> \u0438 <a href=\"http:\/\/habrahabr.ru\/search\/?q=[three.js]&amp;target_type=posts\">Three.js<\/a>, \u044d\u0442\u0430 \u0441\u0442\u0430\u0442\u044c\u044f \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f \u0412\u0430\u043c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0439. \u0412 \u043d\u0435\u0439 \u0440\u0435\u0447\u044c \u043f\u043e\u0439\u0434\u0451\u0442 \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u0437\u0430\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u044d\u0442\u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0432\u043c\u0435\u0441\u0442\u0435 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0442\u0440\u0451\u0445\u043c\u0435\u0440\u043d\u044b\u0445 \u0441\u0446\u0435\u043d, \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u044d\u0442\u043e\u0439 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0433\u0438\u0441\u0442\u043e\u0433\u0440\u0430\u043c\u043c\u044b:<\/p>\n<p>  <a href=\"http:\/\/fiddle.jshell.net\/LHtAx\/4\/show\/\"><\/p>\n<div style=\"text-align:center;\"><img decoding=\"async\"  src=\"http:\/\/habr.habrastorage.org\/post_images\/b2f\/609\/334\/b2f6093343773649f58b954ca4ced0a2.gif\"\/><\/div>\n<p><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-200584","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/200584","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=200584"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/200584\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=200584"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=200584"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=200584"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}