Skip to content

3D hover text fixes for date axes #1414

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/plots/gl3d/scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,9 @@ function render(scene) {
}

function formatter(axisName, val) {
if(typeof val === 'string') return val;

var axis = scene.fullSceneLayout[axisName];
return Axes.tickText(axis, axis.c2l(val), 'hover').text;

return Axes.tickText(axis, axis.d2l(val), 'hover').text;
}

var oldEventData;
Expand Down
71 changes: 57 additions & 14 deletions test/jasmine/tests/gl_plot_interact_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ describe('Test gl plot interactions', function() {

describe('scatter3d hover', function() {

var node, ptData;
var ptData;

beforeEach(function(done) {
gd.on('plotly_hover', function(eventData) {
Expand All @@ -100,27 +100,70 @@ describe('Test gl plot interactions', function() {
delay(done);
});

it('should have', function() {
node = d3.selectAll('g.hovertext');
expect(node.size()).toEqual(1, 'one hover text group');
function assertHoverText(xLabel, yLabel, zLabel) {
var node = d3.selectAll('g.hovertext');
expect(node.size()).toEqual(1, 'hover text group');

var tspan = d3.selectAll('g.hovertext').selectAll('tspan')[0];
expect(tspan[0].innerHTML).toEqual(xLabel, 'x val');
expect(tspan[1].innerHTML).toEqual(yLabel, 'y val');
expect(tspan[2].innerHTML).toEqual(zLabel, 'z val');
}

it('makes the right hover text and point data', function(done) {

function hover() {
mouseEventScatter3d('mouseover');
return delay;
}

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

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

expect(ptData.x).toBe('140.72', 'x val hover data');
expect(ptData.y).toBe('−96.97', 'y val hover data');
expect(ptData.z).toEqual('−96.97', 'z val hover data');
expect(ptData.curveNumber).toEqual(0, 'curveNumber hover data');
expect(ptData.pointNumber).toEqual(2, 'pointNumber hover data');
});
expect(ptData.x).toBe('140.72', 'x val');
expect(ptData.y).toBe('−96.97', 'y val');
expect(ptData.z).toEqual('−96.97', 'z val');
expect(ptData.curveNumber).toEqual(0, 'curveNumber');
expect(ptData.pointNumber).toEqual(2, 'pointNumber');

Plotly.restyle(gd, {
x: [['2016-01-11', '2016-01-12', '2017-01-01', '2017-02']]
})
.then(hover)
.then(function() {
assertHoverText('x: Jan 1, 2017', 'y: −96.97', 'z: −96.97');

return Plotly.restyle(gd, {
x: [[new Date(2017, 2, 1), new Date(2017, 2, 2), new Date(2017, 2, 3), new Date(2017, 2, 4)]]
});
})
.then(hover)
.then(function() {
assertHoverText('x: Mar 3, 2017', 'y: −96.97', 'z: −96.97');

return Plotly.update(gd, {
y: [['a', 'b', 'c', 'd']],
z: [[10, 1e3, 1e5, 1e10]]
}, {
'scene.zaxis.type': 'log'
});
})
.then(hover)
.then(function() {
assertHoverText('x: Mar 3, 2017', 'y: c', 'z: 100k');

return Plotly.relayout(gd, 'scene.xaxis.calendar', 'chinese');
})
.then(hover)
.then(function() {
assertHoverText('x: 二 6, 2017', 'y: c', 'z: 100k');
})
.then(done);
});
});

describe('scatter3d click events', function() {
Expand Down