|
9 | 9 | 'use strict';
|
10 | 10 |
|
11 | 11 | var createScatterPlot = require('gl-scatter3d');
|
| 12 | +var conePlot = require('gl-cone3d'); |
12 | 13 | var createConeMesh = require('gl-cone3d').createConeMesh;
|
13 |
| -var cone2mesh = require('./helpers').cone2mesh; |
| 14 | + |
| 15 | +var simpleMap = require('../../lib').simpleMap; |
| 16 | +var parseColorScale = require('../../lib/gl_format_color').parseColorScale; |
14 | 17 |
|
15 | 18 | function Cone(scene, uid) {
|
16 | 19 | this.scene = scene;
|
@@ -43,8 +46,57 @@ proto.handlePick = function(selection) {
|
43 | 46 | }
|
44 | 47 | };
|
45 | 48 |
|
| 49 | +function zip3(x, y, z) { |
| 50 | + var result = new Array(x.length); |
| 51 | + for(var i = 0; i < x.length; i++) { |
| 52 | + result[i] = [x[i], y[i], z[i]]; |
| 53 | + } |
| 54 | + return result; |
| 55 | +} |
| 56 | + |
| 57 | +var axisName2scaleIndex = {xaxis: 0, yaxis: 1, zaxis: 2}; |
| 58 | +var sizeMode2sizeKey = {scaled: 'coneSize', absolute: 'absoluteConeSize'}; |
| 59 | + |
46 | 60 | function convert(scene, trace) {
|
47 |
| - return cone2mesh(trace, scene.fullSceneLayout, scene.dataScale); |
| 61 | + var sceneLayout = scene.fullSceneLayout; |
| 62 | + var dataScale = scene.dataScale; |
| 63 | + var coneOpts = {}; |
| 64 | + |
| 65 | + function toDataCoords(arr, axisName) { |
| 66 | + var ax = sceneLayout[axisName]; |
| 67 | + var scale = dataScale[axisName2scaleIndex[axisName]]; |
| 68 | + return simpleMap(arr, function(v) { return ax.d2l(v) * scale; }); |
| 69 | + } |
| 70 | + |
| 71 | + coneOpts.vectors = zip3( |
| 72 | + toDataCoords(trace.u, 'xaxis'), |
| 73 | + toDataCoords(trace.v, 'yaxis'), |
| 74 | + toDataCoords(trace.w, 'zaxis') |
| 75 | + ); |
| 76 | + |
| 77 | + coneOpts.positions = zip3( |
| 78 | + toDataCoords(trace.x, 'xaxis'), |
| 79 | + toDataCoords(trace.y, 'yaxis'), |
| 80 | + toDataCoords(trace.z, 'zaxis') |
| 81 | + ); |
| 82 | + |
| 83 | + if(trace.vx && trace.vy && trace.vz) { |
| 84 | + coneOpts.meshgrid = [ |
| 85 | + toDataCoords(trace.vx, 'xaxis'), |
| 86 | + toDataCoords(trace.vy, 'yaxis'), |
| 87 | + toDataCoords(trace.vz, 'zaxis') |
| 88 | + ]; |
| 89 | + } |
| 90 | + |
| 91 | + coneOpts.colormap = parseColorScale(trace.colorscale); |
| 92 | + coneOpts.vertexIntensityBounds = [trace.cmin / trace.cmax, 1]; |
| 93 | + |
| 94 | + coneOpts[sizeMode2sizeKey[trace.sizemode]] = trace.sizeref; |
| 95 | + |
| 96 | + var meshOpts = conePlot(coneOpts); |
| 97 | + meshOpts._pts = coneOpts.positions; |
| 98 | + |
| 99 | + return meshOpts; |
48 | 100 | }
|
49 | 101 |
|
50 | 102 | proto.update = function(data) {
|
|
0 commit comments