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,

0 commit comments

Comments
 (0)