Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 00ae2dd

Browse filesBrowse files
committed
fix and test layout.calendar inheritance
1 parent 8e1747f commit 00ae2dd
Copy full SHA for 00ae2dd
Expand file treeCollapse file tree

25 files changed

+384
-35
lines changed

‎src/components/colorbar/draw.js

Copy file name to clipboardExpand all lines: src/components/colorbar/draw.js
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,8 @@ module.exports = function draw(gd, id) {
174174
axisOptions = {
175175
letter: 'y',
176176
font: fullLayout.font,
177-
noHover: true
177+
noHover: true,
178+
calendar: fullLayout.calendar // not really necessary (yet?)
178179
};
179180

180181
// Coerce w.r.t. Axes layoutAttributes:

‎src/plots/cartesian/axis_defaults.js

Copy file name to clipboardExpand all lines: src/plots/cartesian/axis_defaults.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ module.exports = function handleAxisDefaults(containerIn, containerOut, coerce,
7474
}
7575
}
7676

77-
if(axType === 'date') coerce('calendar');
77+
if(axType === 'date') coerce('calendar', options.calendar);
7878

7979
setConvert(containerOut);
8080

‎src/plots/cartesian/layout_defaults.js

Copy file name to clipboardExpand all lines: src/plots/cartesian/layout_defaults.js
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,8 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {
126126
showGrid: !noGrids[axName],
127127
name: axName,
128128
data: fullData,
129-
bgColor: bgColor
129+
bgColor: bgColor,
130+
calendar: layoutOut.calendar
130131
},
131132
positioningOptions = {
132133
letter: axLetter,
@@ -140,7 +141,7 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {
140141
return Lib.coerce(axLayoutIn, axLayoutOut, layoutAttributes, attr, dflt);
141142
}
142143

143-
handleAxisDefaults(axLayoutIn, axLayoutOut, coerce, defaultOptions);
144+
handleAxisDefaults(axLayoutIn, axLayoutOut, coerce, defaultOptions, layoutOut);
144145
handlePositionDefaults(axLayoutIn, axLayoutOut, coerce, positioningOptions);
145146

146147
layoutOut[axName] = axLayoutOut;

‎src/plots/gl3d/layout/axis_defaults.js

Copy file name to clipboardExpand all lines: src/plots/gl3d/layout/axis_defaults.js
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, options) {
4646
letter: axName[0],
4747
data: options.data,
4848
showGrid: true,
49-
bgColor: options.bgColor
49+
bgColor: options.bgColor,
50+
calendar: options.calendar
5051
});
5152

5253
coerce('gridcolor', colorMix(containerOut.color, options.bgColor, gridLightness).toRgbString());

‎src/plots/gl3d/layout/defaults.js

Copy file name to clipboardExpand all lines: src/plots/gl3d/layout/defaults.js
+4-2Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {
4141
font: layoutOut.font,
4242
fullData: fullData,
4343
getDfltFromLayout: getDfltFromLayout,
44-
paper_bgcolor: layoutOut.paper_bgcolor
44+
paper_bgcolor: layoutOut.paper_bgcolor,
45+
calendar: layoutOut.calendar
4546
});
4647
};
4748

@@ -97,7 +98,8 @@ function handleGl3dDefaults(sceneLayoutIn, sceneLayoutOut, coerce, opts) {
9798
font: opts.font,
9899
scene: opts.id,
99100
data: opts.fullData,
100-
bgColor: bgColorCombined
101+
bgColor: bgColorCombined,
102+
calendar: opts.calendar
101103
});
102104

103105
coerce('dragmode', opts.getDfltFromLayout('dragmode'));

‎src/traces/contour/defaults.js

Copy file name to clipboardExpand all lines: src/traces/contour/defaults.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
2222
return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);
2323
}
2424

25-
var len = handleXYZDefaults(traceIn, traceOut, coerce);
25+
var len = handleXYZDefaults(traceIn, traceOut, coerce, layout);
2626
if(!len) {
2727
traceOut.visible = false;
2828
return;

‎src/traces/heatmap/defaults.js

Copy file name to clipboardExpand all lines: src/traces/heatmap/defaults.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
2222
return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);
2323
}
2424

25-
var len = handleXYZDefaults(traceIn, traceOut, coerce);
25+
var len = handleXYZDefaults(traceIn, traceOut, coerce, layout);
2626
if(!len) {
2727
traceOut.visible = false;
2828
return;

‎src/traces/heatmap/xyz_defaults.js

Copy file name to clipboardExpand all lines: src/traces/heatmap/xyz_defaults.js
+4-3Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ var isNumeric = require('fast-isnumeric');
1414
var hasColumns = require('./has_columns');
1515

1616

17-
module.exports = function handleXYZDefaults(traceIn, traceOut, coerce) {
17+
module.exports = function handleXYZDefaults(traceIn, traceOut, coerce, layout) {
1818
var z = coerce('z');
1919
var x, y;
2020

@@ -37,8 +37,9 @@ module.exports = function handleXYZDefaults(traceIn, traceOut, coerce) {
3737
coerce('transpose');
3838
}
3939

40-
coerce('xcalendar');
41-
coerce('ycalendar');
40+
var dfltCalendar = layout.calendar;
41+
coerce('xcalendar', dfltCalendar);
42+
coerce('ycalendar', dfltCalendar);
4243

4344
return traceOut.z.length;
4445
};

‎src/traces/histogram/defaults.js

Copy file name to clipboardExpand all lines: src/traces/histogram/defaults.js
+4-3Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
2626
var x = coerce('x'),
2727
y = coerce('y');
2828

29-
coerce('xcalendar');
30-
coerce('ycalendar');
31-
3229
coerce('text');
3330

3431
var orientation = coerce('orientation', (y && !x) ? 'h' : 'v'),
@@ -39,6 +36,10 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
3936
return;
4037
}
4138

39+
var dfltCalendar = layout.calendar;
40+
coerce('xcalendar', dfltCalendar);
41+
coerce('ycalendar', dfltCalendar);
42+
4243
var hasAggregationData = traceOut[orientation === 'h' ? 'x' : 'y'];
4344
if(hasAggregationData) coerce('histfunc');
4445

‎src/traces/histogram2d/defaults.js

Copy file name to clipboardExpand all lines: src/traces/histogram2d/defaults.js
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ var colorscaleDefaults = require('../../components/colorscale/defaults');
1616
var attributes = require('./attributes');
1717

1818

19-
module.exports = function supplyDefaults(traceIn, traceOut, layout) {
19+
module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) {
2020
function coerce(attr, dflt) {
2121
return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);
2222
}
2323

24-
handleSampleDefaults(traceIn, traceOut, coerce);
24+
handleSampleDefaults(traceIn, traceOut, coerce, layout);
2525

2626
var zsmooth = coerce('zsmooth');
2727
if(zsmooth === false) {

‎src/traces/histogram2d/sample_defaults.js

Copy file name to clipboardExpand all lines: src/traces/histogram2d/sample_defaults.js
+4-3Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@
1212
var handleBinDefaults = require('../histogram/bin_defaults');
1313

1414

15-
module.exports = function handleSampleDefaults(traceIn, traceOut, coerce) {
15+
module.exports = function handleSampleDefaults(traceIn, traceOut, coerce, layout) {
1616
var x = coerce('x'),
1717
y = coerce('y');
1818

19-
coerce('xcalendar');
20-
coerce('ycalendar');
19+
var dfltCalendar = layout.calendar;
20+
coerce('xcalendar', dfltCalendar);
21+
coerce('ycalendar', dfltCalendar);
2122

2223
// we could try to accept x0 and dx, etc...
2324
// but that's a pretty weird use case.

‎src/traces/histogram2dcontour/defaults.js

Copy file name to clipboardExpand all lines: src/traces/histogram2dcontour/defaults.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
2121
return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);
2222
}
2323

24-
handleSampleDefaults(traceIn, traceOut, coerce);
24+
handleSampleDefaults(traceIn, traceOut, coerce, layout);
2525

2626
var contourStart = Lib.coerce2(traceIn, traceOut, attributes, 'contours.start'),
2727
contourEnd = Lib.coerce2(traceIn, traceOut, attributes, 'contours.end'),

‎test/jasmine/tests/axes_test.js

Copy file name to clipboardExpand all lines: test/jasmine/tests/axes_test.js
+28Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,34 @@ describe('Test axes', function() {
385385
expect(layoutOut.yaxis2.gridcolor)
386386
.toEqual(tinycolor.mix('#444', bgColor, frac).toRgbString());
387387
});
388+
389+
it('should inherit calendar from the layout', function() {
390+
layoutOut.calendar = 'nepali';
391+
layoutIn = {
392+
calendar: 'nepali',
393+
xaxis: {type: 'date'},
394+
yaxis: {type: 'date'}
395+
};
396+
397+
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
398+
399+
expect(layoutOut.xaxis.calendar).toBe('nepali');
400+
expect(layoutOut.yaxis.calendar).toBe('nepali');
401+
});
402+
403+
it('should allow its own calendar', function() {
404+
layoutOut.calendar = 'nepali';
405+
layoutIn = {
406+
calendar: 'nepali',
407+
xaxis: {type: 'date', calendar: 'coptic'},
408+
yaxis: {type: 'date', calendar: 'thai'}
409+
};
410+
411+
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
412+
413+
expect(layoutOut.xaxis.calendar).toBe('coptic');
414+
expect(layoutOut.yaxis.calendar).toBe('thai');
415+
});
388416
});
389417

390418
describe('categoryorder', function() {

‎test/jasmine/tests/bar_test.js

Copy file name to clipboardExpand all lines: test/jasmine/tests/bar_test.js
+27-1Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ describe('Bar.supplyDefaults', function() {
106106
font: {family: 'arial', color: '#AAA', size: 13}
107107
};
108108

109-
supplyDefaults(traceIn, traceOut, defaultColor, layout, {});
109+
supplyDefaults(traceIn, traceOut, defaultColor, layout);
110110

111111
expect(traceOut.textposition).toBe('inside');
112112
expect(traceOut.textfont).toEqual(layout.font);
@@ -116,6 +116,32 @@ describe('Bar.supplyDefaults', function() {
116116
expect(traceOut.insidetextfont).not.toBe(traceOut.textfont);
117117
expect(traceOut.outsidetexfont).toBeUndefined();
118118
});
119+
120+
it('should inherit layout.calendar', function() {
121+
traceIn = {
122+
x: [1, 2, 3],
123+
y: [1, 2, 3]
124+
};
125+
supplyDefaults(traceIn, traceOut, defaultColor, {calendar: 'islamic'});
126+
127+
// we always fill calendar attributes, because it's hard to tell if
128+
// we're on a date axis at this point.
129+
expect(traceOut.xcalendar).toBe('islamic');
130+
expect(traceOut.ycalendar).toBe('islamic');
131+
});
132+
133+
it('should take its own calendars', function() {
134+
traceIn = {
135+
x: [1, 2, 3],
136+
y: [1, 2, 3],
137+
xcalendar: 'coptic',
138+
ycalendar: 'ethiopian'
139+
};
140+
supplyDefaults(traceIn, traceOut, defaultColor, {calendar: 'islamic'});
141+
142+
expect(traceOut.xcalendar).toBe('coptic');
143+
expect(traceOut.ycalendar).toBe('ethiopian');
144+
});
119145
});
120146

121147
describe('heatmap calc / setPositions', function() {

‎test/jasmine/tests/box_test.js

Copy file name to clipboardExpand all lines: test/jasmine/tests/box_test.js
+26Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,32 @@ describe('Test boxes', function() {
8181

8282
});
8383

84+
it('should inherit layout.calendar', function() {
85+
traceIn = {
86+
y: [1, 2, 3]
87+
};
88+
supplyDefaults(traceIn, traceOut, defaultColor, {calendar: 'islamic'});
89+
90+
// we always fill calendar attributes, because it's hard to tell if
91+
// we're on a date axis at this point.
92+
expect(traceOut.xcalendar).toBe('islamic');
93+
expect(traceOut.ycalendar).toBe('islamic');
94+
});
95+
96+
it('should take its own calendars', function() {
97+
traceIn = {
98+
y: [1, 2, 3],
99+
xcalendar: 'coptic',
100+
ycalendar: 'ethiopian'
101+
};
102+
supplyDefaults(traceIn, traceOut, defaultColor, {calendar: 'islamic'});
103+
104+
// we always fill calendar attributes, because it's hard to tell if
105+
// we're on a date axis at this point.
106+
expect(traceOut.xcalendar).toBe('coptic');
107+
expect(traceOut.ycalendar).toBe('ethiopian');
108+
});
109+
84110
});
85111

86112
});

‎test/jasmine/tests/contour_test.js

Copy file name to clipboardExpand all lines: test/jasmine/tests/contour_test.js
+30Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,36 @@ describe('contour defaults', function() {
5151
supplyDefaults(traceIn, traceOut, defaultColor, layout);
5252
expect(traceOut.autocontour).toBe(true);
5353
});
54+
55+
it('should inherit layout.calendar', function() {
56+
traceIn = {
57+
x: [1, 2],
58+
y: [1, 2],
59+
z: [[1, 2], [3, 4]]
60+
};
61+
supplyDefaults(traceIn, traceOut, defaultColor, {calendar: 'islamic'});
62+
63+
// we always fill calendar attributes, because it's hard to tell if
64+
// we're on a date axis at this point.
65+
expect(traceOut.xcalendar).toBe('islamic');
66+
expect(traceOut.ycalendar).toBe('islamic');
67+
});
68+
69+
it('should take its own calendars', function() {
70+
traceIn = {
71+
x: [1, 2],
72+
y: [1, 2],
73+
z: [[1, 2], [3, 4]],
74+
xcalendar: 'coptic',
75+
ycalendar: 'ethiopian'
76+
};
77+
supplyDefaults(traceIn, traceOut, defaultColor, {calendar: 'islamic'});
78+
79+
// we always fill calendar attributes, because it's hard to tell if
80+
// we're on a date axis at this point.
81+
expect(traceOut.xcalendar).toBe('coptic');
82+
expect(traceOut.ycalendar).toBe('ethiopian');
83+
});
5484
});
5585

5686
describe('contour makeColorMap', function() {

‎test/jasmine/tests/finance_test.js

Copy file name to clipboardExpand all lines: test/jasmine/tests/finance_test.js
+36Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,42 @@ describe('finance charts defaults:', function() {
331331
expect(out1.layout.xaxis.rangeslider).toBeDefined();
332332
expect(out1._fullLayout.xaxis.rangeslider.visible).toBe(false);
333333
});
334+
335+
it('pushes layout.calendar to all output traces', function() {
336+
var trace0 = Lib.extendDeep({}, mock0, {
337+
type: 'ohlc'
338+
});
339+
340+
var trace1 = Lib.extendDeep({}, mock1, {
341+
type: 'candlestick'
342+
});
343+
344+
var out = _supply([trace0, trace1], {calendar: 'nanakshahi'});
345+
346+
347+
out._fullData.forEach(function(fullTrace) {
348+
expect(fullTrace.xcalendar).toBe('nanakshahi');
349+
});
350+
});
351+
352+
it('accepts a calendar per input trace', function() {
353+
var trace0 = Lib.extendDeep({}, mock0, {
354+
type: 'ohlc',
355+
xcalendar: 'hebrew'
356+
});
357+
358+
var trace1 = Lib.extendDeep({}, mock1, {
359+
type: 'candlestick',
360+
xcalendar: 'julian'
361+
});
362+
363+
var out = _supply([trace0, trace1], {calendar: 'nanakshahi'});
364+
365+
366+
out._fullData.forEach(function(fullTrace, i) {
367+
expect(fullTrace.xcalendar).toBe(i < 2 ? 'hebrew' : 'julian');
368+
});
369+
});
334370
});
335371

336372
describe('finance charts calc transforms:', function() {

‎test/jasmine/tests/gl3daxes_test.js

Copy file name to clipboardExpand all lines: test/jasmine/tests/gl3daxes_test.js
+30Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,5 +75,35 @@ describe('Test Gl3dAxes', function() {
7575
checkKeys(expected[axis], layoutOut[axis]);
7676
});
7777
});
78+
79+
it('should inherit layout.calendar', function() {
80+
layoutIn = {
81+
xaxis: {type: 'date'},
82+
yaxis: {type: 'date'},
83+
zaxis: {type: 'date'}
84+
};
85+
options.calendar = 'taiwan';
86+
87+
supplyLayoutDefaults(layoutIn, layoutOut, options);
88+
89+
expect(layoutOut.xaxis.calendar).toBe('taiwan');
90+
expect(layoutOut.yaxis.calendar).toBe('taiwan');
91+
expect(layoutOut.zaxis.calendar).toBe('taiwan');
92+
});
93+
94+
it('should accept its own calendar', function() {
95+
layoutIn = {
96+
xaxis: {type: 'date', calendar: 'hebrew'},
97+
yaxis: {type: 'date', calendar: 'ummalqura'},
98+
zaxis: {type: 'date', calendar: 'discworld'}
99+
};
100+
options.calendar = 'taiwan';
101+
102+
supplyLayoutDefaults(layoutIn, layoutOut, options);
103+
104+
expect(layoutOut.xaxis.calendar).toBe('hebrew');
105+
expect(layoutOut.yaxis.calendar).toBe('ummalqura');
106+
expect(layoutOut.zaxis.calendar).toBe('discworld');
107+
});
78108
});
79109
});

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.