Skip to content

Commit bee2455

Browse files
authored
Merge pull request #4851 from plotly/fix4848-tickmode-array-date-log
Fix setting array tickmode on date & log axes
2 parents 0b54b3f + 3833064 commit bee2455

File tree

5 files changed

+81
-12
lines changed

5 files changed

+81
-12
lines changed

src/plots/cartesian/tick_value_defaults.js

+5-11
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
'use strict';
1010

1111
var cleanTicks = require('./clean_ticks');
12+
var isArrayOrTypedArray = require('../../lib').isArrayOrTypedArray;
1213

1314
module.exports = function handleTickValueDefaults(containerIn, containerOut, coerce, axType) {
1415
function readInput(attr) {
@@ -21,18 +22,11 @@ module.exports = function handleTickValueDefaults(containerIn, containerOut, coe
2122
var _tick0 = readInput('tick0');
2223
var _dtick = readInput('dtick');
2324
var _tickvals = readInput('tickvals');
24-
var _tickmode = readInput('tickmode');
25-
var tickmode;
2625

27-
if(_tickmode === 'array' &&
28-
(axType === 'log' || axType === 'date')) {
29-
tickmode = containerOut.tickmode = 'auto';
30-
} else {
31-
var tickmodeDefault = Array.isArray(_tickvals) ? 'array' :
32-
_dtick ? 'linear' :
33-
'auto';
34-
tickmode = coerce('tickmode', tickmodeDefault);
35-
}
26+
var tickmodeDefault = isArrayOrTypedArray(_tickvals) ? 'array' :
27+
_dtick ? 'linear' :
28+
'auto';
29+
var tickmode = coerce('tickmode', tickmodeDefault);
3630

3731
if(tickmode === 'auto') coerce('nticks');
3832
else if(tickmode === 'linear') {
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"data": [{
3+
"type": "scatter",
4+
"x": [
5+
"2010-01-01",
6+
"2010-02-01",
7+
"2010-03-01"
8+
],
9+
"y": [
10+
1,
11+
100,
12+
10
13+
]
14+
}],
15+
"layout": {
16+
"width": 500,
17+
"height": 300,
18+
"title": {
19+
"text": "custom ticks on date & log axes"
20+
},
21+
"paper_bgcolor": "lightblue",
22+
"plot_bgcolor": "#ddd",
23+
"yaxis": {
24+
"type": "log",
25+
"tickmode": "array",
26+
"tickvals": [
27+
1,
28+
10,
29+
100
30+
],
31+
"ticktext": [
32+
"one",
33+
"ten",
34+
"one<br>hundred"
35+
],
36+
"gridwidth": 2,
37+
"tickwidth": 15,
38+
"tickcolor": "green",
39+
"gridcolor": "green"
40+
},
41+
"xaxis": {
42+
"type": "date",
43+
"tickmode": "array",
44+
"tickvals": [
45+
"2010-01-16",
46+
"2010-02-14"
47+
],
48+
"ticktext": [
49+
"Jan 16",
50+
"Feb 14"
51+
],
52+
"gridwidth": 10,
53+
"tickwidth": 50,
54+
"tickcolor": "rgba(255,0,0,0.75)",
55+
"gridcolor": "rgba(255,0,0,0.25)"
56+
}
57+
}
58+
}

test/jasmine/tests/axes_test.js

+16-1
Original file line numberDiff line numberDiff line change
@@ -1887,10 +1887,16 @@ describe('Test axes', function() {
18871887
expect(axOut.tickmode).toBe('auto');
18881888
expect(axIn.tickmode).toBe('array');
18891889

1890+
axIn = {tickvals: [1, 2, 3]};
1891+
axOut = {};
1892+
mockSupplyDefaults(axIn, axOut, 'date');
1893+
expect(axOut.tickmode).toBe('array');
1894+
expect(axIn.tickmode).toBeUndefined();
1895+
18901896
axIn = {tickmode: 'array', tickvals: [1, 2, 3]};
18911897
axOut = {};
18921898
mockSupplyDefaults(axIn, axOut, 'date');
1893-
expect(axOut.tickmode).toBe('auto');
1899+
expect(axOut.tickmode).toBe('array');
18941900
expect(axIn.tickmode).toBe('array');
18951901

18961902
axIn = {tickvals: [1, 2, 3]};
@@ -1899,6 +1905,15 @@ describe('Test axes', function() {
18991905
expect(axOut.tickmode).toBe('array');
19001906
expect(axIn.tickmode).toBeUndefined();
19011907

1908+
var arr = new Float32Array(2);
1909+
arr[0] = 0;
1910+
arr[1] = 1;
1911+
axIn = {tickvals: arr};
1912+
axOut = {};
1913+
mockSupplyDefaults(axIn, axOut, 'linear');
1914+
expect(axOut.tickmode).toBe('array');
1915+
expect(axIn.tickmode).toBeUndefined();
1916+
19021917
axIn = {dtick: 1};
19031918
axOut = {};
19041919
mockSupplyDefaults(axIn, axOut, 'linear');

test/jasmine/tests/mock_test.js

+2
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ var list = [
7373
'axes_category_descending',
7474
'axes_category_descending_with_gaps',
7575
'axes_category_null',
76+
'axes_custom-ticks_log-date',
7677
'axes_enumerated_ticks',
7778
'axes_free_default',
7879
'axes_labels',
@@ -1108,6 +1109,7 @@ figs['axes_category_categoryarray_truncated_tails'] = require('@mocks/axes_categ
11081109
// figs['axes_category_descending'] = require('@mocks/axes_category_descending');
11091110
// figs['axes_category_descending_with_gaps'] = require('@mocks/axes_category_descending_with_gaps');
11101111
figs['axes_category_null'] = require('@mocks/axes_category_null');
1112+
figs['axes_custom-ticks_log-date'] = require('@mocks/axes_custom-ticks_log-date');
11111113
figs['axes_enumerated_ticks'] = require('@mocks/axes_enumerated_ticks');
11121114
figs['axes_free_default'] = require('@mocks/axes_free_default');
11131115
// figs['axes_labels'] = require('@mocks/axes_labels');

0 commit comments

Comments
 (0)