Skip to content

Commit a2db567

Browse files
committed
find min/max u/v/w norm in calc directly
... w/o using cone2mesh, and use that the find cmin & cmax which now correspond to "absolute" vector norm. This make cone/helpers.js obsolete.
1 parent a2c3694 commit a2db567

File tree

3 files changed

+69
-81
lines changed

3 files changed

+69
-81
lines changed

src/traces/cone/calc.js

+15-8
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,25 @@
88

99
'use strict';
1010

11-
var cone2mesh = require('./helpers').cone2mesh;
1211
var colorscaleCalc = require('../../components/colorscale/calc');
1312

1413
module.exports = function calc(gd, trace) {
15-
var fullLayout = gd._fullLayout;
14+
var u = trace.u;
15+
var v = trace.v;
16+
var w = trace.w;
17+
var len = Math.min(u.length, v.length, w.length);
18+
var normMax = -Infinity;
19+
var normMin = Infinity;
1620

17-
// TODO skip when 'cmin' and 'cmax' are set
18-
// TODO find way to "merge" this cone2mesh call with the one in convert.js
19-
//
20-
// TODO should show in absolute or normalize length?
21+
for(var i = 0; i < len; i++) {
22+
var uu = u[i];
23+
var vv = v[i];
24+
var ww = w[i];
25+
var norm = Math.sqrt(uu * uu + vv * vv + ww * ww);
2126

22-
var meshData = cone2mesh(trace, fullLayout[trace.scene]);
27+
normMax = Math.max(normMax, norm);
28+
normMin = Math.min(normMin, norm);
29+
}
2330

24-
colorscaleCalc(trace, meshData.vertexIntensity, '', 'c');
31+
colorscaleCalc(trace, [normMin, normMax], '', 'c');
2532
};

src/traces/cone/convert.js

+54-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@
99
'use strict';
1010

1111
var createScatterPlot = require('gl-scatter3d');
12+
var conePlot = require('gl-cone3d');
1213
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;
1417

1518
function Cone(scene, uid) {
1619
this.scene = scene;
@@ -43,8 +46,57 @@ proto.handlePick = function(selection) {
4346
}
4447
};
4548

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+
4660
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;
48100
}
49101

50102
proto.update = function(data) {

src/traces/cone/helpers.js

-71
This file was deleted.

0 commit comments

Comments
 (0)