Skip to content

Commit 71e46af

Browse files
committed
hook in hover labels for cones
... using an invisible gl-scatter3d trace
1 parent fa32a74 commit 71e46af

File tree

5 files changed

+42
-24
lines changed

5 files changed

+42
-24
lines changed

Diff for: src/traces/cone/attributes.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,9 @@ var attrs = {
110110
arrayOk: true,
111111
editType: 'calc',
112112
description: [
113-
113+
'Sets the text elements associated with the cones.',
114+
'If trace `hoverinfo` contains a *text* flag and *hovertext* is not set,',
115+
'these elements will be seen in the hover labels.'
114116
].join(' ')
115117
}
116118
};

Diff for: src/traces/cone/convert.js

+35-15
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,24 @@
66
* LICENSE file in the root directory of this source tree.
77
*/
88

9-
109
'use strict';
1110

12-
var createMesh = require('gl-cone3d').createConeMesh;
11+
var createScatterPlot = require('gl-scatter3d');
12+
var createConeMesh = require('gl-cone3d').createConeMesh;
1313
var cone2mesh = require('./helpers').cone2mesh;
1414

15-
function Mesh3DTrace(scene, mesh, uid) {
15+
function Cone(scene, uid) {
1616
this.scene = scene;
1717
this.uid = uid;
18-
this.mesh = mesh;
18+
this.mesh = null;
19+
this.pts = null;
1920
this.data = null;
2021
}
2122

22-
var proto = Mesh3DTrace.prototype;
23+
var proto = Cone.prototype;
2324

2425
proto.handlePick = function(selection) {
25-
if(selection.object === this.mesh) {
26+
if(selection.object === this.pts) {
2627
var selectIndex = selection.index = selection.data.index;
2728

2829
selection.traceCoordinate = [
@@ -48,25 +49,44 @@ function convert(scene, trace) {
4849

4950
proto.update = function(data) {
5051
this.data = data;
51-
this.mesh.update(convert(this.scene, data));
52+
53+
var meshData = convert(this.scene, data);
54+
55+
this.mesh.update(meshData);
56+
this.pts.update({position: meshData._pts});
5257
};
5358

5459
proto.dispose = function() {
60+
this.scene.glplot.remove(this.pts);
61+
this.pts.dispose();
5562
this.scene.glplot.remove(this.mesh);
5663
this.mesh.dispose();
5764
};
5865

59-
function createMesh3DTrace(scene, data) {
66+
function createConeTrace(scene, data) {
6067
var gl = scene.glplot.gl;
61-
var meshData = convert(scene, data);
62-
var mesh = createMesh(gl, meshData);
63-
var result = new Mesh3DTrace(scene, mesh, data.uid);
6468

65-
result.data = data;
66-
mesh._trace = result;
69+
var meshData = convert(scene, data);
70+
var mesh = createConeMesh(gl, meshData);
71+
72+
var pts = createScatterPlot({
73+
gl: gl,
74+
position: meshData._pts,
75+
project: false,
76+
opacity: 0
77+
});
78+
79+
var cone = new Cone(scene, data.uid);
80+
cone.mesh = mesh;
81+
cone.pts = pts;
82+
cone.data = data;
83+
mesh._trace = cone;
84+
pts._trace = cone;
85+
86+
scene.glplot.add(pts);
6787
scene.glplot.add(mesh);
6888

69-
return result;
89+
return cone;
7090
}
7191

72-
module.exports = createMesh3DTrace;
92+
module.exports = createConeTrace;

Diff for: src/traces/cone/helpers.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,8 @@ exports.cone2mesh = function cone2mesh(trace, sceneLayout, dataScale) {
6464

6565
coneOpts[sizeMode2sizeKey[trace.sizemode]] = trace.sizeref;
6666

67-
return conePlot(coneOpts);
67+
var meshOpts = conePlot(coneOpts);
68+
meshOpts._pts = coneOpts.positions;
69+
70+
return meshOpts;
6871
};

Diff for: test/image/baselines/gl3d_cone-simple.png

-148 Bytes
Loading

Diff for: test/image/mocks/gl3d_cone-simple.json

-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
{
22
"data": [
3-
{
4-
"type": "scatter3d",
5-
"mode": "markers",
6-
"x": [1, 2, 3],
7-
"y": [1, 2, 3],
8-
"z": [1, 2, 3]
9-
},
103
{
114
"type": "cone",
125
"x": [1, 2, 3],

0 commit comments

Comments
 (0)