Skip to content
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

Set Cartesian axis attributes via template #4670

Merged
merged 7 commits into from
Mar 25, 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
25 changes: 14 additions & 11 deletions src/plots/cartesian/axis_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ module.exports = function handleAxisDefaults(containerIn, containerOut, coerce,

var visible = coerce('visible', !options.visibleDflt);

var axType = containerOut.type;
var axTemplate = containerOut._template || {};
var axType = containerOut.type || axTemplate.type || '-';

if(axType === 'date') {
var handleCalendarDefaults = Registry.getComponentMethod('calendars', 'handleDefaults');
Expand Down Expand Up @@ -105,10 +106,10 @@ module.exports = function handleAxisDefaults(containerIn, containerOut, coerce,

if(options.automargin) coerce('automargin');

var isMultiCategory = containerOut.type === 'multicategory';
var isMultiCategory = axType === 'multicategory';

if(!options.noTickson &&
(containerOut.type === 'category' || isMultiCategory) &&
(axType === 'category' || isMultiCategory) &&
(containerOut.ticks || containerOut.showgrid)
) {
var ticksonDflt;
Expand All @@ -124,14 +125,16 @@ module.exports = function handleAxisDefaults(containerIn, containerOut, coerce,
}
}

if(containerOut.type === 'date') {
var rangebreaks = containerIn.rangebreaks;
if(Array.isArray(rangebreaks) && rangebreaks.length) {
handleArrayContainerDefaults(containerIn, containerOut, {
name: 'rangebreaks',
inclusionAttr: 'enabled',
handleItemDefaults: rangebreaksDefaults
});
if(axType === 'date') {
handleArrayContainerDefaults(containerIn, containerOut, {
name: 'rangebreaks',
inclusionAttr: 'enabled',
handleItemDefaults: rangebreaksDefaults
});

if(!containerOut.rangebreaks.length) {
delete containerOut.rangebreaks;
} else {
setConvert(containerOut, layoutOut);

if(layoutOut._has('scattergl') || layoutOut._has('splom')) {
Expand Down
16 changes: 9 additions & 7 deletions src/plots/cartesian/tick_label_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,16 @@ function handleOtherDefaults(containerIn, containerOut, coerce, axType, options)

if(axType !== 'category') {
var tickFormat = coerce('tickformat');
var tickformatStops = containerIn.tickformatstops;
if(Array.isArray(tickformatStops) && tickformatStops.length) {
handleArrayContainerDefaults(containerIn, containerOut, {
name: 'tickformatstops',
inclusionAttr: 'enabled',
handleItemDefaults: tickformatstopDefaults
});

handleArrayContainerDefaults(containerIn, containerOut, {
name: 'tickformatstops',
inclusionAttr: 'enabled',
handleItemDefaults: tickformatstopDefaults
});
if(!containerOut.tickformatstops.length) {
delete containerOut.tickformatstops;
}

if(!tickFormat && axType !== 'date') {
coerce('showexponent', showAttrDflt);
coerce('exponentformat');
Expand Down
48 changes: 48 additions & 0 deletions test/jasmine/tests/axes_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5411,3 +5411,51 @@ describe('Test tickformatstops:', function() {
.then(done);
});
});

describe('Test template:', function() {
'use strict';

var gd;
beforeEach(function() {
gd = createGraphDiv();
});
afterEach(destroyGraphDiv);

it('apply axis *type*, *rangebreaks* and *tickformatstops* from template', function(done) {
Plotly.newPlot(gd, {
data: [{
x: [1e10, 2e10, 3e10, 4e10, 5e10, 6e10, 7e10],
y: [1, 2, 3, 4, 5, 6, 7]
}],
layout: {
template: {
layout: {
xaxis: {
type: 'date',
rangebreaks: [{
name: 'name1', // N.B. should provide name
bounds: ['sat', 'mon']
}],
tickformatstops: [{
name: 'name2', // N.B. should provide name
enabled: true,
dtickrange: [1000, 60000],
value: '%H:%M:%S s'
}]
}
}
}
}
})
.then(function() {
var xaxis = gd._fullLayout.xaxis;
expect(xaxis.type).toBe('date');
expect(xaxis.rangebreaks).not.toBe(undefined, 'rangebreaks');
expect(xaxis.rangebreaks.length).toBe(1);
expect(xaxis.tickformatstops).not.toBe(undefined, 'tickformatstops');
expect(xaxis.tickformatstops.length).toBe(1);
})
.catch(failTest)
.then(done);
});
});