Skip to content

Commit e367b07

Browse files
committed
fix and add hover test for prefix and tickformat
1 parent d8b9ba2 commit e367b07

File tree

2 files changed

+57
-6
lines changed

2 files changed

+57
-6
lines changed

src/plots/smith/layout_defaults.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ var Template = require('../../plot_api/plot_template');
77
var handleSubplotDefaults = require('../subplot_defaults');
88
var getSubplotData = require('../get_data').getSubplotData;
99

10+
var handlePrefixSuffixDefaults = require('../cartesian/prefix_suffix_defaults');
1011
var handleTickLabelDefaults = require('../cartesian/tick_label_defaults');
1112
var handleLineGridDefaults = require('../cartesian/line_grid_defaults');
1213

@@ -45,7 +46,6 @@ function handleDefaults(contIn, contOut, coerce, opts) {
4546

4647
axOut.type = 'linear';
4748
setConvert(axOut, contOut, layoutOut);
48-
delete axOut.type;
4949

5050
var dfltColor;
5151
var dfltFontColor;
@@ -67,14 +67,16 @@ function handleDefaults(contIn, contOut, coerce, opts) {
6767
// range[1] > range[0], and vice-versa for `autorange: 'reversed'` below.
6868
axOut._m = 1;
6969

70+
handlePrefixSuffixDefaults(axIn, axOut, coerceAxis, axOut.type);
71+
7072
if(visible) {
7173
if(axName === 'realaxis') {
7274
coerceAxis('side');
7375
}
7476

7577
coerceAxis('tickvals');
7678

77-
handleTickLabelDefaults(axIn, axOut, coerceAxis, axOut.type, {});
79+
handleTickLabelDefaults(axIn, axOut, coerceAxis, axOut.type);
7880

7981
Lib.coerce2(contIn, contOut, layoutAttributes, axName + '.ticklen');
8082
Lib.coerce2(contIn, contOut, layoutAttributes, axName + '.tickwidth');
@@ -114,6 +116,8 @@ function handleDefaults(contIn, contOut, coerce, opts) {
114116

115117
coerceAxis('hoverformat');
116118

119+
delete axOut.type;
120+
117121
axOut._input = axIn;
118122
}
119123
}

test/jasmine/tests/scattersmith_test.js

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
var Plotly = require('@lib/index');
2+
var Lib = require('@src/lib');
23
var ScatterSmith = require('@src/traces/scattersmith');
34

45
var basicMock = require('@mocks/zzz_smith_basic.json');
@@ -53,19 +54,65 @@ describe('Test scattersmith hover:', function() {
5354
function run(specs) {
5455
gd = createGraphDiv();
5556

56-
var fig = basicMock;
57-
var pos = specs.pos;
57+
var fig = Lib.extendDeep(basicMock);
58+
59+
if(specs.patch) {
60+
fig = specs.patch(fig);
61+
}
5862

5963
return Plotly.newPlot(gd, fig).then(function() {
60-
mouseEvent('mousemove', pos[0], pos[1]);
64+
mouseEvent('mousemove', 400, 70);
6165
assertHoverLabelContent(specs);
6266
});
6367
}
6468

6569
[{
6670
desc: 'base',
67-
pos: [400, 70],
6871
nums: 'real: 0\nimag: 1'
72+
}, {
73+
desc: 'with tickformat',
74+
patch: function(fig) {
75+
fig.layout.smith = {
76+
realaxis: { tickformat: '.1f' },
77+
imaginaryaxis: { tickformat: '.2f' }
78+
};
79+
return fig;
80+
},
81+
nums: 'real: 0.0\nimag: 1.00'
82+
}, {
83+
desc: 'with prefix and suffix',
84+
patch: function(fig) {
85+
fig.layout.smith = {
86+
realaxis: {
87+
tickprefix: '(',
88+
ticksuffix: ')'
89+
},
90+
imaginaryaxis: {
91+
tickprefix: '[',
92+
ticksuffix: ']'
93+
}
94+
};
95+
return fig;
96+
},
97+
nums: 'real: (0)\nimag: [1]'
98+
}, {
99+
desc: 'with prefix and suffix on invisible axes',
100+
patch: function(fig) {
101+
fig.layout.smith = {
102+
realaxis: {
103+
visible: false,
104+
tickprefix: '(',
105+
ticksuffix: ')'
106+
},
107+
imaginaryaxis: {
108+
visible: false,
109+
tickprefix: '[',
110+
ticksuffix: ']'
111+
}
112+
};
113+
return fig;
114+
},
115+
nums: 'real: (0)\nimag: [1]'
69116
}].forEach(function(specs) {
70117
it('should generate correct hover labels ' + specs.desc, function(done) {
71118
run(specs).then(done, done.fail);

0 commit comments

Comments
 (0)