Skip to content

Commit c54c815

Browse files
committed
Fix autorange computation when a category match a range extreme
1 parent 8b76d46 commit c54c815

File tree

4 files changed

+42
-1
lines changed

4 files changed

+42
-1
lines changed

src/plots/cartesian/set_convert.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,15 @@ module.exports = function setConvert(ax, fullLayout) {
180180
function getCategoryPosition(v) {
181181
// d2l/d2c variant that that won't add categories but will also
182182
// allow numbers to be mapped to the linearized axis positions
183-
var index = getCategoryIndex(v);
183+
var index = getRangePosition(v);
184184
if(index !== undefined) return index;
185185
if(isNumeric(v)) return +v;
186186
}
187187

188+
function getRangePosition(v) {
189+
return isNumeric(v) ? +v : getCategoryIndex(v);
190+
}
191+
188192
// include 2 fractional digits on pixel, for PDF zooming etc
189193
function _l2p(v, m, b) { return d3.round(b + m * v, 2); }
190194

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"data": [{
3+
"x" : [ "1.5", "2.5", "3.5", "6.5", "7.5", "8.5", "10.5", "Not Known" ],
4+
"y" : [ "1.0", "1.0", "2.0", "1.0", "1.0", "2.0", "1.0", "1.0" ],
5+
"name" : "Double with string \"N/A\" Exposure",
6+
"type" : "bar",
7+
"showlegend" : false,
8+
"visible" : true
9+
} ],
10+
"layout": {
11+
"xaxis" : {
12+
"type" : "category",
13+
"showticklabels" : true,
14+
"zeroline" : false,
15+
"fixedrange" : false,
16+
"showgrid" : false,
17+
"autorange" : true,
18+
"autotick" : true,
19+
"showline" : false,
20+
"visible" : true,
21+
"automargin" : false
22+
},
23+
"toResize" : true,
24+
"showlegend" : true
25+
}
26+
}

test/jasmine/tests/axes_test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1779,6 +1779,15 @@ describe('Test axes', function() {
17791779
expect(gd._fullLayout.xaxis.categoryarray).toEqual(['b', 'a', 'd', 'e', 'c']);
17801780
});
17811781
});
1782+
1783+
describe('a category has the same value of one of the auto range computed extreme', function() {
1784+
it('should compute the right range for X axis', function() {
1785+
Plotly.plot(gd, [{x: ['1.5', '2.5', '3.5', '6.5', '7.5', '8.5', 'Not Known'], y: [ '1.0', '1.0', '2.0', '1.0', '1.0', '2.0', '1.0'], type: 'bar'}], {
1786+
xaxis: {type: 'category', autorange: true}
1787+
});
1788+
expect(gd._fullLayout.xaxis._rl).toEqual([-0.5, 6.5]);
1789+
});
1790+
});
17821791
});
17831792

17841793
describe('handleTickDefaults', function() {

test/jasmine/tests/mock_test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ var list = [
118118
'bar_hide_nulls',
119119
'bar_line',
120120
'bar_marker_array',
121+
'bar_max_range_eq_category',
121122
'bar_multiline_labels',
122123
'bar_nonnumeric_sizes',
123124
'bar_show_narrow',
@@ -1181,6 +1182,7 @@ figs['bar_group_percent'] = require('@mocks/bar_group_percent');
11811182
figs['bar_hide_nulls'] = require('@mocks/bar_hide_nulls');
11821183
figs['bar_line'] = require('@mocks/bar_line');
11831184
figs['bar_marker_array'] = require('@mocks/bar_marker_array');
1185+
figs['bar_max_range_eq_category'] = require('@mocks/bar_max_range_eq_category');
11841186
figs['bar_multiline_labels'] = require('@mocks/bar_multiline_labels');
11851187
figs['bar_nonnumeric_sizes'] = require('@mocks/bar_nonnumeric_sizes');
11861188
figs['bar_show_narrow'] = require('@mocks/bar_show_narrow');

0 commit comments

Comments
 (0)