Skip to content

Commit 7b0036e

Browse files
committed
Merge pull request #267 from plotly/bug-hoverformat
Hoverformat bug with showTickLabels
2 parents d430e30 + 9b5663a commit 7b0036e

File tree

4 files changed

+127
-12
lines changed

4 files changed

+127
-12
lines changed

src/plots/cartesian/tick_defaults.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,29 +29,29 @@ module.exports = function handleTickDefaults(containerIn, containerOut, coerce,
2929
delete containerOut.tickcolor;
3030
}
3131

32+
var showAttrDflt = getShowAttrDflt(containerIn);
33+
34+
var tickPrefix = coerce('tickprefix');
35+
if(tickPrefix) coerce('showtickprefix', showAttrDflt);
36+
37+
var tickSuffix = coerce('ticksuffix');
38+
if(tickSuffix) coerce('showticksuffix', showAttrDflt);
39+
3240
var showTickLabels = coerce('showticklabels');
3341
if(showTickLabels) {
3442
Lib.coerceFont(coerce, 'tickfont', options.font || {});
3543
coerce('tickangle');
3644

37-
var showAttrDflt = getShowAttrDflt(containerIn);
38-
39-
if(axType !== 'category') {
45+
if(axType !== 'category'){
4046
var tickFormat = coerce('tickformat');
41-
if(!options.noHover) coerce('hoverformat');
42-
4347
if(!tickFormat && axType !== 'date') {
4448
coerce('showexponent', showAttrDflt);
4549
coerce('exponentformat');
4650
}
4751
}
48-
49-
var tickPrefix = coerce('tickprefix');
50-
if(tickPrefix) coerce('showtickprefix', showAttrDflt);
51-
52-
var tickSuffix = coerce('ticksuffix');
53-
if(tickSuffix) coerce('showticksuffix', showAttrDflt);
5452
}
53+
54+
if(axType !== 'category' && !options.noHover) coerce('hoverformat');
5555
};
5656

5757
/*

test/jasmine/tests/axes_test.js

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ var Color = require('@src/components/color');
77
var handleTickValueDefaults = require('@src/plots/cartesian/tick_value_defaults');
88
var Axes = PlotlyInternal.Axes;
99

10+
var createGraph = require('../assets/create_graph_div');
11+
var destroyGraph = require('../assets/destroy_graph_div');
12+
1013

1114
describe('Test axes', function() {
1215
'use strict';
@@ -252,6 +255,79 @@ describe('Test axes', function() {
252255
});
253256
});
254257

258+
describe('handleTickDefaults', function() {
259+
var data = [{ x: [1,2,3], y: [3,4,5] }],
260+
gd;
261+
262+
beforeEach(function() {
263+
gd = createGraph();
264+
});
265+
266+
afterEach(destroyGraph);
267+
268+
it('should set defaults on bad inputs', function() {
269+
var layout = {
270+
yaxis: {
271+
ticklen: 'invalid',
272+
tickwidth: 'invalid',
273+
tickcolor: 'invalid',
274+
showticklabels: 'invalid',
275+
tickfont: 'invalid',
276+
tickangle: 'invalid'
277+
}
278+
};
279+
280+
PlotlyInternal.plot(gd, data, layout);
281+
282+
var yaxis = gd._fullLayout.yaxis;
283+
expect(yaxis.ticklen).toBe(5);
284+
expect(yaxis.tickwidth).toBe(1);
285+
expect(yaxis.tickcolor).toBe('#444');
286+
expect(yaxis.ticks).toBe('outside');
287+
expect(yaxis.showticklabels).toBe(true);
288+
expect(yaxis.tickfont).toEqual({ family: '"Open Sans", verdana, arial, sans-serif', size: 12, color: '#444' });
289+
expect(yaxis.tickangle).toBe('auto');
290+
});
291+
292+
it('should use valid inputs', function() {
293+
var layout = {
294+
yaxis: {
295+
ticklen: 10,
296+
tickwidth: 5,
297+
tickcolor: '#F00',
298+
showticklabels: true,
299+
tickfont: { family: 'Garamond', size: 72, color: '#0FF' },
300+
tickangle: -20
301+
}
302+
};
303+
304+
PlotlyInternal.plot(gd, data, layout);
305+
306+
var yaxis = gd._fullLayout.yaxis;
307+
expect(yaxis.ticklen).toBe(10);
308+
expect(yaxis.tickwidth).toBe(5);
309+
expect(yaxis.tickcolor).toBe('#F00');
310+
expect(yaxis.ticks).toBe('outside');
311+
expect(yaxis.showticklabels).toBe(true);
312+
expect(yaxis.tickfont).toEqual({ family: 'Garamond', size: 72, color: '#0FF' });
313+
expect(yaxis.tickangle).toBe(-20);
314+
});
315+
316+
it('should conditionally coerce based on showticklabels', function() {
317+
var layout = {
318+
yaxis: {
319+
showticklabels: false,
320+
tickangle: -90
321+
}
322+
};
323+
324+
PlotlyInternal.plot(gd, data, layout);
325+
326+
var yaxis = gd._fullLayout.yaxis;
327+
expect(yaxis.tickangle).toBeUndefined();
328+
});
329+
});
330+
255331
describe('handleTickValueDefaults', function() {
256332
function mockSupplyDefaults(axIn, axOut, axType) {
257333
function coerce(attr, dflt) {

test/jasmine/tests/gl_plot_interact_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ describe('Test plot structure', function() {
153153

154154
describe('buttons resetCameraDefault3d and resetCameraLastSave3d', function() {
155155
// changes in scene objects are not instantaneous
156-
var DELAY = 200;
156+
var DELAY = 500;
157157

158158
it('should update the scene camera', function(done) {
159159
var sceneLayout = gd._fullLayout.scene,

test/jasmine/tests/hover_label_test.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ var Lib = require('@src/lib');
66

77
var createGraphDiv = require('../assets/create_graph_div');
88
var destroyGraphDiv = require('../assets/destroy_graph_div');
9+
var mouseEvent = require('../assets/mouse_event');
910

1011
describe('hover info', function() {
1112
'use strict';
@@ -242,4 +243,42 @@ describe('hover info', function() {
242243
expect(d3.selectAll('g.hovertext').select('text').selectAll('tspan').size()).toEqual(2);
243244
});
244245
});
246+
247+
describe('hoverformat', function() {
248+
249+
var data = [{
250+
x: [1, 2, 3],
251+
y: [0.12345, 0.23456, 0.34567]
252+
}],
253+
layout = {
254+
yaxis: { showticklabels: true, hoverformat: ',.2r' },
255+
width: 600,
256+
height: 400
257+
};
258+
259+
beforeEach(function() {
260+
this. gd = createGraphDiv();
261+
});
262+
263+
it('should display the correct format when ticklabels true', function() {
264+
Plotly.plot(this.gd, data, layout);
265+
mouseEvent('mousemove', 310, 220);
266+
267+
var hovers = d3.selectAll('g.hovertext');
268+
269+
expect(hovers.size()).toEqual(1);
270+
expect(hovers.select('text')[0][0].textContent).toEqual('0.23');
271+
});
272+
273+
it('should display the correct format when ticklabels false', function() {
274+
layout.yaxis.showticklabels = false;
275+
Plotly.plot(this.gd, data, layout);
276+
mouseEvent('mousemove', 310, 220);
277+
278+
var hovers = d3.selectAll('g.hovertext');
279+
280+
expect(hovers.size()).toEqual(1);
281+
expect(hovers.select('text')[0][0].textContent).toEqual('0.23');
282+
});
283+
});
245284
});

0 commit comments

Comments
 (0)