Skip to content

Commit e718c66

Browse files
committed
fixup hover gl-scatter3d trace for cone with set cones.(x|y|z)
- only draw (invisible) pts at mesh positions - use x/y/z and u/v/w at those pts on hover
1 parent cb7ef43 commit e718c66

File tree

1 file changed

+48
-12
lines changed

1 file changed

+48
-12
lines changed

src/traces/cone/convert.js

+48-12
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,32 @@ 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+
}
3143

32-
var uu = this.data.u[selectIndex];
33-
var vv = this.data.v[selectIndex];
34-
var ww = this.data.w[selectIndex];
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+
}
3553

3654
selection.traceCoordinate = [
37-
this.data.x[selectIndex],
38-
this.data.y[selectIndex],
39-
this.data.z[selectIndex],
40-
41-
uu,
42-
vv,
43-
ww,
44-
55+
xx, yy, zz,
56+
uu, vv, ww,
4557
Math.sqrt(uu * uu + vv * vv + ww * ww)
4658
];
4759

@@ -107,7 +119,29 @@ function convert(scene, trace) {
107119
coneOpts.coneOffset = anchor2coneOffset[trace.anchor];
108120

109121
var meshOpts = conePlot(coneOpts);
110-
meshOpts._pts = coneOpts.positions;
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+
}
111145

112146
return meshOpts;
113147
}
@@ -145,6 +179,8 @@ function createConeTrace(scene, data) {
145179
cone.mesh = mesh;
146180
cone.pts = pts;
147181
cone.data = data;
182+
cone._xyz = meshData._xyz;
183+
cone._uvw = meshData._uvw;
148184
mesh._trace = cone;
149185
pts._trace = cone;
150186

0 commit comments

Comments
 (0)