diff --git a/src/plots/cartesian/axis_defaults.js b/src/plots/cartesian/axis_defaults.js index b1cae96206d..9c7887df813 100644 --- a/src/plots/cartesian/axis_defaults.js +++ b/src/plots/cartesian/axis_defaults.js @@ -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'); @@ -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; @@ -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')) { diff --git a/src/plots/cartesian/tick_label_defaults.js b/src/plots/cartesian/tick_label_defaults.js index 877c1acb40e..ad3a1d166a1 100644 --- a/src/plots/cartesian/tick_label_defaults.js +++ b/src/plots/cartesian/tick_label_defaults.js @@ -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'); diff --git a/test/jasmine/tests/axes_test.js b/test/jasmine/tests/axes_test.js index ad06ff73e53..94887094815 100644 --- a/test/jasmine/tests/axes_test.js +++ b/test/jasmine/tests/axes_test.js @@ -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); + }); +});