Skip to content

Commit 5984106

Browse files
committed
coerce calendar attributes in calenders component
- ... only when calendars is registered. - replace 'calendar' valType with the appropriate 'enumarated' val object -
1 parent 3143099 commit 5984106

File tree

30 files changed

+67
-115
lines changed

30 files changed

+67
-115
lines changed

src/components/calendars/index.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,25 @@ var constants = require('../../constants/numerical');
1616
var EPOCHJD = constants.EPOCHJD;
1717
var ONEDAY = constants.ONEDAY;
1818

19+
var attributes = {
20+
valType: 'enumerated',
21+
values: Object.keys(calendars.calendars),
22+
role: 'info',
23+
dflt: 'gregorian'
24+
};
25+
26+
var handleDefaults = function(contIn, contOut, attr, dflt) {
27+
var attrs = {};
28+
attrs[attr] = attributes;
29+
30+
return Lib.coerce(contIn, contOut, attrs, attr, dflt);
31+
};
32+
33+
var handleTraceDefaults = function(traceIn, traceOut, coords, layout) {
34+
for(var i = 0; i < coords.length; i++) {
35+
handleDefaults(traceIn, traceOut, coords[i] + 'calendar', layout.calendar);
36+
}
37+
};
1938
// each calendar needs its own default canonical tick. I would love to use
2039
// 2000-01-01 (or even 0000-01-01) for them all but they don't necessarily
2140
// all support either of those dates. Instead I'll use the most significant
@@ -149,6 +168,10 @@ module.exports = {
149168
moduleType: 'component',
150169
name: 'calendars',
151170

171+
172+
handleDefaults: handleDefaults,
173+
handleTraceDefaults: handleTraceDefaults,
174+
152175
CANONICAL_SUNDAY: CANONICAL_SUNDAY,
153176
CANONICAL_TICK: CANONICAL_TICK,
154177
DFLTRANGE: DFLTRANGE,

src/lib/coerce.js

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
'use strict';
1111

12-
var calendarList = Object.keys(require('world-calendars').calendars);
1312
var isNumeric = require('fast-isnumeric');
1413
var tinycolor = require('tinycolor2');
1514

@@ -268,20 +267,6 @@ exports.valObjects = {
268267

269268
return true;
270269
}
271-
},
272-
calendar: {
273-
description: [
274-
'A string, one of the calendar systems available',
275-
'in the `world-calendars` package, to be used in evaluating',
276-
'or displaying date data. Defaults to built-in (Gregorian) dates.',
277-
'available calendars:', '*' + calendarList.join('*, *') + '*'
278-
].join(' '),
279-
requiredOpts: [],
280-
otherOpts: ['dflt'],
281-
coerceFunction: function(v, propOut, dflt) {
282-
if(v && calendarList.indexOf(v) !== -1) propOut.set(v);
283-
else propOut.set(dflt);
284-
}
285270
}
286271
};
287272

src/plots/cartesian/axis_defaults.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,10 @@ module.exports = function handleAxisDefaults(containerIn, containerOut, coerce,
7474
}
7575
}
7676

77-
if(axType === 'date') coerce('calendar', options.calendar);
77+
if(axType === 'date') {
78+
var handleCalendarDefaults = Registry.getComponentMethod('calendars', 'handleDefaults');
79+
handleCalendarDefaults(containerIn, containerOut, 'calendar', options.calendar);
80+
}
7881

7982
setConvert(containerOut);
8083

src/plots/cartesian/layout_attributes.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,6 @@ module.exports = {
5252
'the axis in question.'
5353
].join(' ')
5454
},
55-
calendar: {
56-
valType: 'calendar',
57-
role: 'info',
58-
description: [
59-
'Sets the calendar system to use for `range` and `tick0`',
60-
'if this is a date axis. This does not set the calendar for',
61-
'interpreting data on this axis, that\'s specified in the trace',
62-
'or via the global `layout.calendar`'
63-
].join(' ')
64-
},
6555
autorange: {
6656
valType: 'enumerated',
6757
values: [true, false, 'reversed'],

src/plots/gl3d/layout/axis_attributes.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ module.exports = {
7373
title: axesAttrs.title,
7474
titlefont: axesAttrs.titlefont,
7575
type: axesAttrs.type,
76-
calendar: axesAttrs.calendar,
7776
autorange: axesAttrs.autorange,
7877
rangemode: axesAttrs.rangemode,
7978
range: axesAttrs.range,

src/plots/layout_attributes.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -170,15 +170,6 @@ module.exports = {
170170
role: 'info',
171171
description: 'Determines whether or not a legend is drawn.'
172172
},
173-
calendar: {
174-
valType: 'calendar',
175-
role: 'info',
176-
dflt: 'gregorian',
177-
description: [
178-
'Sets the default calendar system to use for interpreting and',
179-
'displaying dates throughout the plot.'
180-
].join(' ')
181-
},
182173
dragmode: {
183174
valType: 'enumerated',
184175
role: 'info',

src/plots/plots.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,8 @@ plots.supplyLayoutGlobalDefaults = function(layoutIn, layoutOut) {
942942
coerce('hidesources');
943943
coerce('smith');
944944

945-
coerce('calendar');
945+
var handleCalendarDefaults = Registry.getComponentMethod('calendars', 'handleDefaults');
946+
handleCalendarDefaults(layoutIn, layoutOut, 'calendar');
946947
};
947948

948949
plots.plotAutoSize = function plotAutoSize(gd, layout, fullLayout) {

src/traces/bar/attributes.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ module.exports = {
4747
y: scatterAttrs.y,
4848
y0: scatterAttrs.y0,
4949
dy: scatterAttrs.dy,
50-
xcalendar: scatterAttrs.xcalendar,
51-
ycalendar: scatterAttrs.ycalendar,
5250

5351
text: scatterAttrs.text,
5452

src/traces/box/defaults.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
'use strict';
1010

1111
var Lib = require('../../lib');
12+
var Registry = require('../../registry');
1213
var Color = require('../../components/color');
1314

1415
var attributes = require('./attributes');
@@ -33,9 +34,8 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
3334
return;
3435
}
3536

36-
var dfltCalendar = layout.calendar;
37-
coerce('xcalendar', dfltCalendar);
38-
coerce('ycalendar', dfltCalendar);
37+
var handleCalendarDefaults = Registry.getComponentMethod('calendars', 'handleTraceDefaults');
38+
handleCalendarDefaults(traceIn, traceOut, ['x', 'y'], layout);
3939

4040
coerce('orientation', defaultOrientation);
4141

src/traces/candlestick/attributes.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ var directionAttrs = {
2727

2828
module.exports = {
2929
x: OHLCattrs.x,
30-
xcalendar: OHLCattrs.xcalendar,
3130
open: OHLCattrs.open,
3231
high: OHLCattrs.high,
3332
low: OHLCattrs.low,

src/traces/contour/attributes.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ module.exports = extendFlat({}, {
2828
transpose: heatmapAttrs.transpose,
2929
xtype: heatmapAttrs.xtype,
3030
ytype: heatmapAttrs.ytype,
31-
xcalendar: heatmapAttrs.xcalendar,
32-
ycalendar: heatmapAttrs.ycalendar,
3331

3432
connectgaps: heatmapAttrs.connectgaps,
3533

src/traces/heatmap/attributes.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ module.exports = extendFlat({}, {
2525
y: scatterAttrs.y,
2626
y0: scatterAttrs.y0,
2727
dy: scatterAttrs.dy,
28-
xcalendar: scatterAttrs.xcalendar,
29-
ycalendar: scatterAttrs.ycalendar,
3028

3129
text: {
3230
valType: 'data_array',

src/traces/heatmap/xyz_defaults.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
var isNumeric = require('fast-isnumeric');
1313

14+
var Registry = require('../../registry');
1415
var hasColumns = require('./has_columns');
1516

1617

@@ -37,9 +38,8 @@ module.exports = function handleXYZDefaults(traceIn, traceOut, coerce, layout) {
3738
coerce('transpose');
3839
}
3940

40-
var dfltCalendar = layout.calendar;
41-
coerce('xcalendar', dfltCalendar);
42-
coerce('ycalendar', dfltCalendar);
41+
var handleCalendarDefaults = Registry.getComponentMethod('calendars', 'handleTraceDefaults');
42+
handleCalendarDefaults(traceIn, traceOut, ['x', 'y'], layout);
4343

4444
return traceOut.z.length;
4545
};

src/traces/histogram/attributes.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ module.exports = {
2424
'Sets the sample data to be binned on the y axis.'
2525
].join(' ')
2626
},
27-
xcalendar: barAttrs.xcalendar,
28-
ycalendar: barAttrs.ycalendar,
2927

3028
text: barAttrs.text,
3129
orientation: barAttrs.orientation,

src/traces/histogram/defaults.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
'use strict';
1111

12+
var Registry = require('../../registry');
1213
var Lib = require('../../lib');
1314
var Color = require('../../components/color');
1415

@@ -26,6 +27,9 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
2627
var x = coerce('x'),
2728
y = coerce('y');
2829

30+
var handleCalendarDefaults = Registry.getComponentMethod('calendars', 'handleTraceDefaults');
31+
handleCalendarDefaults(traceIn, traceOut, ['x', 'y'], layout);
32+
2933
coerce('text');
3034

3135
var orientation = coerce('orientation', (y && !x) ? 'h' : 'v'),
@@ -36,10 +40,6 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
3640
return;
3741
}
3842

39-
var dfltCalendar = layout.calendar;
40-
coerce('xcalendar', dfltCalendar);
41-
coerce('ycalendar', dfltCalendar);
42-
4343
var hasAggregationData = traceOut[orientation === 'h' ? 'x' : 'y'];
4444
if(hasAggregationData) coerce('histfunc');
4545

src/traces/histogram2d/attributes.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ module.exports = extendFlat({},
1919
{
2020
x: histogramAttrs.x,
2121
y: histogramAttrs.y,
22-
xcalendar: histogramAttrs.xcalendar,
23-
ycalendar: histogramAttrs.ycalendar,
2422

2523
z: {
2624
valType: 'data_array',

src/traces/histogram2d/sample_defaults.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@
99

1010
'use strict';
1111

12+
var Registry = require('../../registry');
1213
var handleBinDefaults = require('../histogram/bin_defaults');
1314

1415

1516
module.exports = function handleSampleDefaults(traceIn, traceOut, coerce, layout) {
1617
var x = coerce('x'),
1718
y = coerce('y');
1819

19-
var dfltCalendar = layout.calendar;
20-
coerce('xcalendar', dfltCalendar);
21-
coerce('ycalendar', dfltCalendar);
20+
var handleCalendarDefaults = Registry.getComponentMethod('calendars', 'handleTraceDefaults');
21+
handleCalendarDefaults(traceIn, traceOut, ['x', 'y'], layout);
2222

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

src/traces/histogram2dcontour/attributes.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ var extendFlat = require('../../lib/extend').extendFlat;
1818
module.exports = extendFlat({}, {
1919
x: histogram2dAttrs.x,
2020
y: histogram2dAttrs.y,
21-
xcalendar: histogram2dAttrs.xcalendar,
22-
ycalendar: histogram2dAttrs.ycalendar,
2321
z: histogram2dAttrs.z,
2422
marker: histogram2dAttrs.marker,
2523

src/traces/mesh3d/attributes.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@ module.exports = {
3737
'jointly represent the X, Y and Z coordinates of the nth vertex.'
3838
].join(' ')
3939
},
40-
xcalendar: surfaceAtts.xcalendar,
41-
ycalendar: surfaceAtts.ycalendar,
42-
zcalendar: surfaceAtts.zcalendar,
4340

4441
i: {
4542
valType: 'data_array',

src/traces/mesh3d/defaults.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
'use strict';
1111

12+
var Registry = require('../../registry');
1213
var Lib = require('../../lib');
1314
var colorbarDefaults = require('../../components/colorbar/defaults');
1415
var attributes = require('./attributes');
@@ -20,12 +21,10 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
2021
}
2122

2223
// read in face/vertex properties
23-
function readComponents(array, doCalendar) {
24+
function readComponents(array) {
2425
var ret = array.map(function(attr) {
2526
var result = coerce(attr);
2627

27-
if(doCalendar) coerce(attr + 'calendar', layout.calendar);
28-
2928
if(result && Array.isArray(result)) return result;
3029
return null;
3130
});
@@ -35,9 +34,12 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
3534
}) && ret;
3635
}
3736

38-
var coords = readComponents(['x', 'y', 'z'], true);
37+
var coords = readComponents(['x', 'y', 'z']);
3938
var indices = readComponents(['i', 'j', 'k']);
4039

40+
var handleCalendarDefaults = Registry.getComponentMethod('calendars', 'handleTraceDefaults');
41+
handleCalendarDefaults(traceIn, traceOut, ['x', 'y', 'z'], layout);
42+
4143
if(!coords) {
4244
traceOut.visible = false;
4345
return;

src/traces/ohlc/attributes.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ module.exports = {
5353
'If absent, linear coordinate will be generated.'
5454
].join(' ')
5555
},
56-
xcalendar: scatterAttrs.xcalendar,
5756

5857
open: {
5958
valType: 'data_array',

src/traces/ohlc/ohlc_defaults.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99

1010
'use strict';
1111

12+
var Registry = require('../../registry');
13+
14+
1215
module.exports = function handleOHLC(traceIn, traceOut, coerce, layout) {
1316
var len;
1417

@@ -18,7 +21,8 @@ module.exports = function handleOHLC(traceIn, traceOut, coerce, layout) {
1821
low = coerce('low'),
1922
close = coerce('close');
2023

21-
coerce('xcalendar', layout.calendar);
24+
var handleCalendarDefaults = Registry.getComponentMethod('calendars', 'handleTraceDefaults');
25+
handleCalendarDefaults(traceIn, traceOut, ['x'], layout);
2226

2327
len = Math.min(open.length, high.length, low.length, close.length);
2428

src/traces/scatter/attributes.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,6 @@ module.exports = {
4141
'See `x0` for more info.'
4242
].join(' ')
4343
},
44-
xcalendar: {
45-
valType: 'calendar',
46-
role: 'info',
47-
description: 'Sets the calendar system to use with `x` date data'
48-
},
4944
y: {
5045
valType: 'data_array',
5146
description: 'Sets the y coordinates.'
@@ -70,11 +65,6 @@ module.exports = {
7065
'See `y0` for more info.'
7166
].join(' ')
7267
},
73-
ycalendar: {
74-
valType: 'calendar',
75-
role: 'info',
76-
description: 'Sets the calendar system to use with `y` date data'
77-
},
7868
ids: {
7969
valType: 'data_array',
8070
description: 'A list of keys for object constancy of data points during animation'

src/traces/scatter/xy_defaults.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,16 @@
99

1010
'use strict';
1111

12+
var Registry = require('../../registry');
13+
1214

1315
module.exports = function handleXYDefaults(traceIn, traceOut, layout, coerce) {
1416
var len,
1517
x = coerce('x'),
1618
y = coerce('y');
1719

18-
var dfltCalendar = layout.calendar;
19-
coerce('xcalendar', dfltCalendar);
20-
coerce('ycalendar', dfltCalendar);
20+
var handleCalendarDefaults = Registry.getComponentMethod('calendars', 'handleTraceDefaults');
21+
handleCalendarDefaults(traceIn, traceOut, ['x', 'y'], layout);
2122

2223
if(x) {
2324
if(y) {

0 commit comments

Comments
 (0)