Skip to content

Commit 28a179f

Browse files
authored
Merge pull request #1414 from plotly/gl3d-hover-text-fixes
3D hover text fixes for date axes
2 parents f685823 + cbf1f86 commit 28a179f

File tree

2 files changed

+59
-17
lines changed

2 files changed

+59
-17
lines changed

src/plots/gl3d/scene.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,9 @@ function render(scene) {
5858
}
5959

6060
function formatter(axisName, val) {
61-
if(typeof val === 'string') return val;
62-
6361
var axis = scene.fullSceneLayout[axisName];
64-
return Axes.tickText(axis, axis.c2l(val), 'hover').text;
62+
63+
return Axes.tickText(axis, axis.d2l(val), 'hover').text;
6564
}
6665

6766
var oldEventData;

test/jasmine/tests/gl_plot_interact_test.js

Lines changed: 57 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ describe('Test gl plot interactions', function() {
8888

8989
describe('scatter3d hover', function() {
9090

91-
var node, ptData;
91+
var ptData;
9292

9393
beforeEach(function(done) {
9494
gd.on('plotly_hover', function(eventData) {
@@ -100,27 +100,70 @@ describe('Test gl plot interactions', function() {
100100
delay(done);
101101
});
102102

103-
it('should have', function() {
104-
node = d3.selectAll('g.hovertext');
105-
expect(node.size()).toEqual(1, 'one hover text group');
103+
function assertHoverText(xLabel, yLabel, zLabel) {
104+
var node = d3.selectAll('g.hovertext');
105+
expect(node.size()).toEqual(1, 'hover text group');
106+
107+
var tspan = d3.selectAll('g.hovertext').selectAll('tspan')[0];
108+
expect(tspan[0].innerHTML).toEqual(xLabel, 'x val');
109+
expect(tspan[1].innerHTML).toEqual(yLabel, 'y val');
110+
expect(tspan[2].innerHTML).toEqual(zLabel, 'z val');
111+
}
112+
113+
it('makes the right hover text and point data', function(done) {
114+
115+
function hover() {
116+
mouseEventScatter3d('mouseover');
117+
return delay;
118+
}
106119

107-
node = d3.selectAll('g.hovertext').selectAll('tspan')[0];
108-
expect(node[0].innerHTML).toEqual('x: 140.72', 'x val on hover');
109-
expect(node[1].innerHTML).toEqual('y: −96.97', 'y val on hover');
110-
expect(node[2].innerHTML).toEqual('z: −96.97', 'z val on hover');
120+
assertHoverText('x: 140.72', 'y: −96.97', 'z: −96.97');
111121

112122
expect(Object.keys(ptData)).toEqual([
113123
'x', 'y', 'z',
114124
'data', 'fullData', 'curveNumber', 'pointNumber'
115125
], 'correct hover data fields');
116126

117-
expect(ptData.x).toBe('140.72', 'x val hover data');
118-
expect(ptData.y).toBe('−96.97', 'y val hover data');
119-
expect(ptData.z).toEqual('−96.97', 'z val hover data');
120-
expect(ptData.curveNumber).toEqual(0, 'curveNumber hover data');
121-
expect(ptData.pointNumber).toEqual(2, 'pointNumber hover data');
122-
});
127+
expect(ptData.x).toBe('140.72', 'x val');
128+
expect(ptData.y).toBe('−96.97', 'y val');
129+
expect(ptData.z).toEqual('−96.97', 'z val');
130+
expect(ptData.curveNumber).toEqual(0, 'curveNumber');
131+
expect(ptData.pointNumber).toEqual(2, 'pointNumber');
132+
133+
Plotly.restyle(gd, {
134+
x: [['2016-01-11', '2016-01-12', '2017-01-01', '2017-02']]
135+
})
136+
.then(hover)
137+
.then(function() {
138+
assertHoverText('x: Jan 1, 2017', 'y: −96.97', 'z: −96.97');
139+
140+
return Plotly.restyle(gd, {
141+
x: [[new Date(2017, 2, 1), new Date(2017, 2, 2), new Date(2017, 2, 3), new Date(2017, 2, 4)]]
142+
});
143+
})
144+
.then(hover)
145+
.then(function() {
146+
assertHoverText('x: Mar 3, 2017', 'y: −96.97', 'z: −96.97');
147+
148+
return Plotly.update(gd, {
149+
y: [['a', 'b', 'c', 'd']],
150+
z: [[10, 1e3, 1e5, 1e10]]
151+
}, {
152+
'scene.zaxis.type': 'log'
153+
});
154+
})
155+
.then(hover)
156+
.then(function() {
157+
assertHoverText('x: Mar 3, 2017', 'y: c', 'z: 100k');
123158

159+
return Plotly.relayout(gd, 'scene.xaxis.calendar', 'chinese');
160+
})
161+
.then(hover)
162+
.then(function() {
163+
assertHoverText('x: 二 6, 2017', 'y: c', 'z: 100k');
164+
})
165+
.then(done);
166+
});
124167
});
125168

126169
describe('scatter3d click events', function() {

0 commit comments

Comments
 (0)