Skip to content

Fix setting array tickmode on date & log axes #4851

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 3 commits into from
May 21, 2020
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
16 changes: 5 additions & 11 deletions src/plots/cartesian/tick_value_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
'use strict';

var cleanTicks = require('./clean_ticks');
var isArrayOrTypedArray = require('../../lib').isArrayOrTypedArray;

module.exports = function handleTickValueDefaults(containerIn, containerOut, coerce, axType) {
function readInput(attr) {
Expand All @@ -21,18 +22,11 @@ module.exports = function handleTickValueDefaults(containerIn, containerOut, coe
var _tick0 = readInput('tick0');
var _dtick = readInput('dtick');
var _tickvals = readInput('tickvals');
var _tickmode = readInput('tickmode');
var tickmode;

if(_tickmode === 'array' &&
(axType === 'log' || axType === 'date')) {
tickmode = containerOut.tickmode = 'auto';
} else {
var tickmodeDefault = Array.isArray(_tickvals) ? 'array' :
_dtick ? 'linear' :
'auto';
tickmode = coerce('tickmode', tickmodeDefault);
}
var tickmodeDefault = isArrayOrTypedArray(_tickvals) ? 'array' :
_dtick ? 'linear' :
'auto';
var tickmode = coerce('tickmode', tickmodeDefault);

if(tickmode === 'auto') coerce('nticks');
else if(tickmode === 'linear') {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
58 changes: 58 additions & 0 deletions test/image/mocks/axes_custom-ticks_log-date.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"data": [{
"type": "scatter",
"x": [
"2010-01-01",
"2010-02-01",
"2010-03-01"
],
"y": [
1,
100,
10
]
}],
"layout": {
"width": 500,
"height": 300,
"title": {
"text": "custom ticks on date & log axes"
},
"paper_bgcolor": "lightblue",
"plot_bgcolor": "#ddd",
"yaxis": {
"type": "log",
"tickmode": "array",
"tickvals": [
1,
10,
100
],
"ticktext": [
"one",
"ten",
"one<br>hundred"
],
"gridwidth": 2,
"tickwidth": 15,
"tickcolor": "green",
"gridcolor": "green"
},
"xaxis": {
"type": "date",
"tickmode": "array",
"tickvals": [
"2010-01-16",
"2010-02-14"
],
"ticktext": [
"Jan 16",
"Feb 14"
],
"gridwidth": 10,
"tickwidth": 50,
"tickcolor": "rgba(255,0,0,0.75)",
"gridcolor": "rgba(255,0,0,0.25)"
}
}
}
17 changes: 16 additions & 1 deletion test/jasmine/tests/axes_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1887,10 +1887,16 @@ describe('Test axes', function() {
expect(axOut.tickmode).toBe('auto');
expect(axIn.tickmode).toBe('array');

axIn = {tickvals: [1, 2, 3]};
axOut = {};
mockSupplyDefaults(axIn, axOut, 'date');
expect(axOut.tickmode).toBe('array');
expect(axIn.tickmode).toBeUndefined();

axIn = {tickmode: 'array', tickvals: [1, 2, 3]};
axOut = {};
mockSupplyDefaults(axIn, axOut, 'date');
expect(axOut.tickmode).toBe('auto');
expect(axOut.tickmode).toBe('array');
expect(axIn.tickmode).toBe('array');

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

var arr = new Float32Array(2);
arr[0] = 0;
arr[1] = 1;
axIn = {tickvals: arr};
axOut = {};
mockSupplyDefaults(axIn, axOut, 'linear');
expect(axOut.tickmode).toBe('array');
expect(axIn.tickmode).toBeUndefined();

axIn = {dtick: 1};
axOut = {};
mockSupplyDefaults(axIn, axOut, 'linear');
Expand Down
2 changes: 2 additions & 0 deletions test/jasmine/tests/mock_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ var list = [
'axes_category_descending',
'axes_category_descending_with_gaps',
'axes_category_null',
'axes_custom-ticks_log-date',
'axes_enumerated_ticks',
'axes_free_default',
'axes_labels',
Expand Down Expand Up @@ -1108,6 +1109,7 @@ figs['axes_category_categoryarray_truncated_tails'] = require('@mocks/axes_categ
// figs['axes_category_descending'] = require('@mocks/axes_category_descending');
// figs['axes_category_descending_with_gaps'] = require('@mocks/axes_category_descending_with_gaps');
figs['axes_category_null'] = require('@mocks/axes_category_null');
figs['axes_custom-ticks_log-date'] = require('@mocks/axes_custom-ticks_log-date');
figs['axes_enumerated_ticks'] = require('@mocks/axes_enumerated_ticks');
figs['axes_free_default'] = require('@mocks/axes_free_default');
// figs['axes_labels'] = require('@mocks/axes_labels');
Expand Down