Skip to content

Commit f651eec

Browse files
committed
use stashed gl-cone3d field as hover x/y/z u/v/w fields
1 parent e718c66 commit f651eec

File tree

3 files changed

+16
-55
lines changed

3 files changed

+16
-55
lines changed

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
"es6-promise": "^3.0.2",
7171
"fast-isnumeric": "^1.1.1",
7272
"font-atlas-sdf": "^1.3.3",
73-
"gl-cone3d": "[email protected]:gl-vis/gl-cone3d#cc6c768d844d0c7ad7dc4dd0d2cdd71eadf92620",
73+
"gl-cone3d": "[email protected]:gl-vis/gl-cone3d#8900460f871bb6a569d613a3df1858e6a336e8b4",
7474
"gl-contour2d": "^1.1.4",
7575
"gl-error3d": "^1.0.7",
7676
"gl-heatmap2d": "^1.0.4",

src/traces/cone/convert.js

+14-53
Original file line numberDiff line numberDiff line change
@@ -28,28 +28,13 @@ var proto = Cone.prototype;
2828
proto.handlePick = function(selection) {
2929
if(selection.object === this.pts) {
3030
var selectIndex = selection.index = selection.data.index;
31-
var xx, yy, zz;
32-
var uu, vv, ww;
33-
34-
if(this._uvw) {
35-
uu = this._uvw[selectIndex][0];
36-
vv = this._uvw[selectIndex][1];
37-
ww = this._uvw[selectIndex][2];
38-
} else {
39-
uu = this.data.u[selectIndex];
40-
vv = this.data.v[selectIndex];
41-
ww = this.data.w[selectIndex];
42-
}
43-
44-
if(this._xyz) {
45-
xx = this._xyz[selectIndex][0];
46-
yy = this._xyz[selectIndex][1];
47-
zz = this._xyz[selectIndex][2];
48-
} else {
49-
xx = this.data.x[selectIndex];
50-
yy = this.data.y[selectIndex];
51-
zz = this.data.z[selectIndex];
52-
}
31+
var dataScale = this.scene.dataScale;
32+
var xx = this._positions[selectIndex][0] / dataScale[0];
33+
var yy = this._positions[selectIndex][1] / dataScale[1];
34+
var zz = this._positions[selectIndex][2] / dataScale[2];
35+
var uu = this._vectors[selectIndex][0] / dataScale[0];
36+
var vv = this._vectors[selectIndex][1] / dataScale[1];
37+
var ww = this._vectors[selectIndex][2] / dataScale[2];
5338

5439
selection.traceCoordinate = [
5540
xx, yy, zz,
@@ -83,7 +68,6 @@ var anchor2coneOffset = {tip: 1, tail: 0, cm: 0.25, center: 0.5};
8368
function convert(scene, trace) {
8469
var sceneLayout = scene.fullSceneLayout;
8570
var dataScale = scene.dataScale;
86-
var hasConesPos = trace.cones && trace.cones.x && trace.cones.y && trace.cones.z;
8771
var coneOpts = {};
8872

8973
function toDataCoords(arr, axisName) {
@@ -104,7 +88,7 @@ function convert(scene, trace) {
10488
toDataCoords(trace.z, 'zaxis')
10589
);
10690

107-
if(hasConesPos) {
91+
if(trace.cones && trace.cones.x && trace.cones.y && trace.cones.z) {
10892
coneOpts.meshgrid = [
10993
toDataCoords(trace.cones.x, 'xaxis'),
11094
toDataCoords(trace.cones.y, 'yaxis'),
@@ -118,32 +102,7 @@ function convert(scene, trace) {
118102
coneOpts[sizeMode2sizeKey[trace.sizemode]] = trace.sizeref;
119103
coneOpts.coneOffset = anchor2coneOffset[trace.anchor];
120104

121-
var meshOpts = conePlot(coneOpts);
122-
123-
if(hasConesPos) {
124-
// used for transparent gl-scatter3d hover trace
125-
var pts = meshOpts._pts = [];
126-
// used on hover
127-
var xyz = meshOpts._xyz = [];
128-
var uvw = meshOpts._uvw = [];
129-
130-
// that 48 increment comes from gl-vis/gl-cone3d/cone.js
131-
for(var i = 0; i < meshOpts.positions.length; i += 48) {
132-
var pos = meshOpts.positions[i];
133-
pts.push([pos[0], pos[1], pos[2]]);
134-
xyz.push([pos[0] / dataScale[0], pos[1] / dataScale[1], pos[2] / dataScale[2]]);
135-
136-
var vec = meshOpts.vectors[i];
137-
uvw.push([vec[0] / dataScale[0], vec[1] / dataScale[1], vec[2] / dataScale[2]]);
138-
}
139-
140-
} else {
141-
meshOpts._pts = coneOpts.positions;
142-
// don't fill _xyz and _uvw here,
143-
// trace arrays do just fine on hover
144-
}
145-
146-
return meshOpts;
105+
return conePlot(coneOpts);
147106
}
148107

149108
proto.update = function(data) {
@@ -170,7 +129,7 @@ function createConeTrace(scene, data) {
170129

171130
var pts = createScatterPlot({
172131
gl: gl,
173-
position: meshData._pts,
132+
position: meshData._positions,
174133
project: false,
175134
opacity: 0
176135
});
@@ -179,11 +138,13 @@ function createConeTrace(scene, data) {
179138
cone.mesh = mesh;
180139
cone.pts = pts;
181140
cone.data = data;
182-
cone._xyz = meshData._xyz;
183-
cone._uvw = meshData._uvw;
184141
mesh._trace = cone;
185142
pts._trace = cone;
186143

144+
// stash these for hover
145+
cone._positions = meshData._positions;
146+
cone._vectors = meshData._vectors;
147+
187148
scene.glplot.add(pts);
188149
scene.glplot.add(mesh);
189150

0 commit comments

Comments
 (0)