简体   繁体   中英

Modify d3.js code to generate static 3d plot

I'm trying to create an interactive 3D plot using D3, but sourcing the data from numpy. I found a nice D3 example here: http://bl.ocks.org/hlvoorhees/5986172

Can anyone figure out which lines I'd need to change in this code to

  1. stop the animation
  2. supply xy data values of my choosing

?????

At the end of the Javascript file, replace this line:

setInterval( updateData, defaultDuration );

with this:

function waitForX3d(resolve) {
  if ( x3d.node() && x3d.node().runtime ) {
    resolve();
  } else {
    new Promise(r => setTimeout(r, 100))
    .then(() => waitForX3d(resolve));
  }
}
// setInterval( updateData, defaultDuration );
new Promise(r => waitForX3d(r))
.then(() => updateData());

Change the updateData function to load your data into the rows variable.

Eventually I realized that the rows variable is what I need to change. I modified that in initializeDataGrid()

Then in place of setInterval(updateData, defaultDuration) I put plotData()

Now I can plot any dataset in an interactive 3D grid yay!

@@ -235,11 +234,13 @@ function scatterPlot3d( parent )
   function initializeDataGrid() {
     var rows = [];
     // Follow the convention where y(x,z) is elevation.
+        //EDIT THIS FOR STATIC DATA!!!
     for (var x=-5; x<=5; x+=1) {
       for (var z=-5; z<=5; z+=1) {
-        rows.push({x: x, y: 0, z: z});
+        rows.push({x: x, y: (x+z)/2, z: z});
      }
     }
+    rows.push({x: 2.5, y: 0, z: 2.5});
     return rows;
   }
@@ -259,8 +261,5 @@ function scatterPlot3d( parent )

   initializeDataGrid();
   initializePlot();
-  setInterval( updateData, defaultDuration );
+  plotData();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM