Skip to content

Commit

Permalink
link rangebreaks and tickformatstops from template
Browse files Browse the repository at this point in the history
  • Loading branch information
archmoj committed Mar 22, 2020
1 parent 6de4c75 commit 5f8b280
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/plots/array_container_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ module.exports = function handleArrayContainerDefaults(parentObjIn, parentObjOut

var previousContOut = parentObjOut[name];

var contIn = Lib.isArrayOrTypedArray(parentObjIn[name]) ? parentObjIn[name] : [];
var contIn = Lib.isArrayOrTypedArray(parentObjIn[name]) ? parentObjIn[name] : (opts.fromTemplate || []);
var contOut = parentObjOut[name] = [];
var templater = Template.arrayTemplater(parentObjOut, name, inclusionAttr);
var i, itemOut;
Expand Down
7 changes: 5 additions & 2 deletions src/plots/cartesian/axis_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ module.exports = function handleAxisDefaults(containerIn, containerOut, coerce,

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

var axType = containerOut.type;
var axType = containerOut.type || options.axTemplate.type || '-';

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

if(containerOut.type === 'date') {
var rangebreaks = containerIn.rangebreaks;
var fromTemplate = (options.axTemplate || {}).rangebreaks;
var rangebreaks = containerIn.rangebreaks || fromTemplate;

if(Array.isArray(rangebreaks) && rangebreaks.length) {
handleArrayContainerDefaults(containerIn, containerOut, {
fromTemplate: fromTemplate,
name: 'rangebreaks',
inclusionAttr: 'enabled',
handleItemDefaults: rangebreaksDefaults
Expand Down
12 changes: 12 additions & 0 deletions src/plots/cartesian/layout_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,13 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {
axHasImage[axName]
));

var axTemplate;
if(Lib.isPlainObject(layoutOut._template)) {
axTemplate = layoutOut._template[axLayoutOut._name];
}

var defaultOptions = {
axTemplate: axTemplate || {},
letter: axLetter,
font: layoutOut.font,
outerTicks: outerTicks[axName],
Expand Down Expand Up @@ -295,7 +301,13 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {
axLayoutOut = Template.newContainer(layoutOut, axName, axLetter + 'axis');
newAxLayoutOut();

var axTemplate2;
if(Lib.isPlainObject(layoutOut._template)) {
axTemplate2 = layoutOut._template[axLayoutOut._name];
}

var defaultOptions2 = {
axTemplate: axTemplate2 || {},
letter: axLetter,
font: layoutOut.font,
outerTicks: outerTicks[axName],
Expand Down
5 changes: 4 additions & 1 deletion src/plots/cartesian/tick_label_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,12 @@ function handleOtherDefaults(containerIn, containerOut, coerce, axType, options)

if(axType !== 'category') {
var tickFormat = coerce('tickformat');
var tickformatStops = containerIn.tickformatstops;
var fromTemplate = (options.axTemplate || {}).tickformatstops;
var tickformatStops = containerIn.tickformatstops || fromTemplate;

if(Array.isArray(tickformatStops) && tickformatStops.length) {
handleArrayContainerDefaults(containerIn, containerOut, {
fromTemplate: fromTemplate,
name: 'tickformatstops',
inclusionAttr: 'enabled',
handleItemDefaults: tickformatstopDefaults
Expand Down
46 changes: 46 additions & 0 deletions test/jasmine/tests/axes_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5411,3 +5411,49 @@ 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: [{
bounds: ['sat', 'mon']
}],
tickformatstops: [{
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);
});
});

0 comments on commit 5f8b280

Please sign in to comment.