Skip to content

"calendars" component #1230

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Dec 7, 2016
23 changes: 23 additions & 0 deletions src/components/calendars/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,25 @@ var constants = require('../../constants/numerical');
var EPOCHJD = constants.EPOCHJD;
var ONEDAY = constants.ONEDAY;

var attributes = {
valType: 'enumerated',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need for a calendar valType anymore!

values: Object.keys(calendars.calendars),
role: 'info',
dflt: 'gregorian'
};

var handleDefaults = function(contIn, contOut, attr, dflt) {
var attrs = {};
attrs[attr] = attributes;

return Lib.coerce(contIn, contOut, attrs, attr, dflt);
};

var handleTraceDefaults = function(traceIn, traceOut, coords, layout) {
for(var i = 0; i < coords.length; i++) {
handleDefaults(traceIn, traceOut, coords[i] + 'calendar', layout.calendar);
}
};
// each calendar needs its own default canonical tick. I would love to use
// 2000-01-01 (or even 0000-01-01) for them all but they don't necessarily
// all support either of those dates. Instead I'll use the most significant
Expand Down Expand Up @@ -149,6 +168,10 @@ module.exports = {
moduleType: 'component',
name: 'calendars',


handleDefaults: handleDefaults,
handleTraceDefaults: handleTraceDefaults,

CANONICAL_SUNDAY: CANONICAL_SUNDAY,
CANONICAL_TICK: CANONICAL_TICK,
DFLTRANGE: DFLTRANGE,
Expand Down
15 changes: 0 additions & 15 deletions src/lib/coerce.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

'use strict';

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

Expand Down Expand Up @@ -268,20 +267,6 @@ exports.valObjects = {

return true;
}
},
calendar: {
description: [
'A string, one of the calendar systems available',
'in the `world-calendars` package, to be used in evaluating',
'or displaying date data. Defaults to built-in (Gregorian) dates.',
'available calendars:', '*' + calendarList.join('*, *') + '*'
].join(' '),
requiredOpts: [],
otherOpts: ['dflt'],
coerceFunction: function(v, propOut, dflt) {
if(v && calendarList.indexOf(v) !== -1) propOut.set(v);
else propOut.set(dflt);
}
}
};

Expand Down
5 changes: 4 additions & 1 deletion src/plots/cartesian/axis_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ module.exports = function handleAxisDefaults(containerIn, containerOut, coerce,
}
}

if(axType === 'date') coerce('calendar', options.calendar);
if(axType === 'date') {
var handleCalendarDefaults = Registry.getComponentMethod('calendars', 'handleDefaults');
handleCalendarDefaults(containerIn, containerOut, 'calendar', options.calendar);
}

setConvert(containerOut);

Expand Down
10 changes: 0 additions & 10 deletions src/plots/cartesian/layout_attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,6 @@ module.exports = {
'the axis in question.'
].join(' ')
},
calendar: {
valType: 'calendar',
role: 'info',
description: [
'Sets the calendar system to use for `range` and `tick0`',
'if this is a date axis. This does not set the calendar for',
'interpreting data on this axis, that\'s specified in the trace',
'or via the global `layout.calendar`'
].join(' ')
},
autorange: {
valType: 'enumerated',
values: [true, false, 'reversed'],
Expand Down
1 change: 0 additions & 1 deletion src/plots/gl3d/layout/axis_attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ module.exports = {
title: axesAttrs.title,
titlefont: axesAttrs.titlefont,
type: axesAttrs.type,
calendar: axesAttrs.calendar,
autorange: axesAttrs.autorange,
rangemode: axesAttrs.rangemode,
range: axesAttrs.range,
Expand Down
9 changes: 0 additions & 9 deletions src/plots/layout_attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,6 @@ module.exports = {
role: 'info',
description: 'Determines whether or not a legend is drawn.'
},
calendar: {
valType: 'calendar',
role: 'info',
dflt: 'gregorian',
description: [
'Sets the default calendar system to use for interpreting and',
'displaying dates throughout the plot.'
].join(' ')
},
dragmode: {
valType: 'enumerated',
role: 'info',
Expand Down
3 changes: 2 additions & 1 deletion src/plots/plots.js
Original file line number Diff line number Diff line change
Expand Up @@ -942,7 +942,8 @@ plots.supplyLayoutGlobalDefaults = function(layoutIn, layoutOut) {
coerce('hidesources');
coerce('smith');

coerce('calendar');
var handleCalendarDefaults = Registry.getComponentMethod('calendars', 'handleDefaults');
handleCalendarDefaults(layoutIn, layoutOut, 'calendar');
};

plots.plotAutoSize = function plotAutoSize(gd, layout, fullLayout) {
Expand Down
2 changes: 0 additions & 2 deletions src/traces/bar/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ module.exports = {
y: scatterAttrs.y,
y0: scatterAttrs.y0,
dy: scatterAttrs.dy,
xcalendar: scatterAttrs.xcalendar,
ycalendar: scatterAttrs.ycalendar,

text: scatterAttrs.text,

Expand Down
6 changes: 3 additions & 3 deletions src/traces/box/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
'use strict';

var Lib = require('../../lib');
var Registry = require('../../registry');
var Color = require('../../components/color');

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

var dfltCalendar = layout.calendar;
coerce('xcalendar', dfltCalendar);
coerce('ycalendar', dfltCalendar);
var handleCalendarDefaults = Registry.getComponentMethod('calendars', 'handleTraceDefaults');
handleCalendarDefaults(traceIn, traceOut, ['x', 'y'], layout);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a little ugly, but Registry gets it done


coerce('orientation', defaultOrientation);

Expand Down
1 change: 0 additions & 1 deletion src/traces/candlestick/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ var directionAttrs = {

module.exports = {
x: OHLCattrs.x,
xcalendar: OHLCattrs.xcalendar,
open: OHLCattrs.open,
high: OHLCattrs.high,
low: OHLCattrs.low,
Expand Down
2 changes: 0 additions & 2 deletions src/traces/contour/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ module.exports = extendFlat({}, {
transpose: heatmapAttrs.transpose,
xtype: heatmapAttrs.xtype,
ytype: heatmapAttrs.ytype,
xcalendar: heatmapAttrs.xcalendar,
ycalendar: heatmapAttrs.ycalendar,

connectgaps: heatmapAttrs.connectgaps,

Expand Down
2 changes: 0 additions & 2 deletions src/traces/heatmap/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ module.exports = extendFlat({}, {
y: scatterAttrs.y,
y0: scatterAttrs.y0,
dy: scatterAttrs.dy,
xcalendar: scatterAttrs.xcalendar,
ycalendar: scatterAttrs.ycalendar,

text: {
valType: 'data_array',
Expand Down
6 changes: 3 additions & 3 deletions src/traces/heatmap/xyz_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

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

var Registry = require('../../registry');
var hasColumns = require('./has_columns');


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

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

return traceOut.z.length;
};
Expand Down
2 changes: 0 additions & 2 deletions src/traces/histogram/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ module.exports = {
'Sets the sample data to be binned on the y axis.'
].join(' ')
},
xcalendar: barAttrs.xcalendar,
ycalendar: barAttrs.ycalendar,

text: barAttrs.text,
orientation: barAttrs.orientation,
Expand Down
8 changes: 4 additions & 4 deletions src/traces/histogram/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

'use strict';

var Registry = require('../../registry');
var Lib = require('../../lib');
var Color = require('../../components/color');

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

var handleCalendarDefaults = Registry.getComponentMethod('calendars', 'handleTraceDefaults');
handleCalendarDefaults(traceIn, traceOut, ['x', 'y'], layout);

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

previously we coerced calendars after the return on no data - was it intentional to move this up?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops. My bad.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in cb2c54b

coerce('text');

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

var dfltCalendar = layout.calendar;
coerce('xcalendar', dfltCalendar);
coerce('ycalendar', dfltCalendar);

var hasAggregationData = traceOut[orientation === 'h' ? 'x' : 'y'];
if(hasAggregationData) coerce('histfunc');

Expand Down
2 changes: 0 additions & 2 deletions src/traces/histogram2d/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ module.exports = extendFlat({},
{
x: histogramAttrs.x,
y: histogramAttrs.y,
xcalendar: histogramAttrs.xcalendar,
ycalendar: histogramAttrs.ycalendar,

z: {
valType: 'data_array',
Expand Down
6 changes: 3 additions & 3 deletions src/traces/histogram2d/sample_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@

'use strict';

var Registry = require('../../registry');
var handleBinDefaults = require('../histogram/bin_defaults');


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

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

// we could try to accept x0 and dx, etc...
// but that's a pretty weird use case.
Expand Down
2 changes: 0 additions & 2 deletions src/traces/histogram2dcontour/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ var extendFlat = require('../../lib/extend').extendFlat;
module.exports = extendFlat({}, {
x: histogram2dAttrs.x,
y: histogram2dAttrs.y,
xcalendar: histogram2dAttrs.xcalendar,
ycalendar: histogram2dAttrs.ycalendar,
z: histogram2dAttrs.z,
marker: histogram2dAttrs.marker,

Expand Down
3 changes: 0 additions & 3 deletions src/traces/mesh3d/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ module.exports = {
'jointly represent the X, Y and Z coordinates of the nth vertex.'
].join(' ')
},
xcalendar: surfaceAtts.xcalendar,
ycalendar: surfaceAtts.ycalendar,
zcalendar: surfaceAtts.zcalendar,

i: {
valType: 'data_array',
Expand Down
10 changes: 6 additions & 4 deletions src/traces/mesh3d/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

'use strict';

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

// read in face/vertex properties
function readComponents(array, doCalendar) {
function readComponents(array) {
var ret = array.map(function(attr) {
var result = coerce(attr);

if(doCalendar) coerce(attr + 'calendar', layout.calendar);

if(result && Array.isArray(result)) return result;
return null;
});
Expand All @@ -35,9 +34,12 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
}) && ret;
}

var coords = readComponents(['x', 'y', 'z'], true);
var coords = readComponents(['x', 'y', 'z']);
var indices = readComponents(['i', 'j', 'k']);

var handleCalendarDefaults = Registry.getComponentMethod('calendars', 'handleTraceDefaults');
handleCalendarDefaults(traceIn, traceOut, ['x', 'y', 'z'], layout);

if(!coords) {
traceOut.visible = false;
return;
Expand Down
1 change: 0 additions & 1 deletion src/traces/ohlc/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ module.exports = {
'If absent, linear coordinate will be generated.'
].join(' ')
},
xcalendar: scatterAttrs.xcalendar,

open: {
valType: 'data_array',
Expand Down
6 changes: 5 additions & 1 deletion src/traces/ohlc/ohlc_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

'use strict';

var Registry = require('../../registry');


module.exports = function handleOHLC(traceIn, traceOut, coerce, layout) {
var len;

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

coerce('xcalendar', layout.calendar);
var handleCalendarDefaults = Registry.getComponentMethod('calendars', 'handleTraceDefaults');
handleCalendarDefaults(traceIn, traceOut, ['x'], layout);

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

Expand Down
10 changes: 0 additions & 10 deletions src/traces/scatter/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@ module.exports = {
'See `x0` for more info.'
].join(' ')
},
xcalendar: {
valType: 'calendar',
role: 'info',
description: 'Sets the calendar system to use with `x` date data'
},
y: {
valType: 'data_array',
description: 'Sets the y coordinates.'
Expand All @@ -70,11 +65,6 @@ module.exports = {
'See `y0` for more info.'
].join(' ')
},
ycalendar: {
valType: 'calendar',
role: 'info',
description: 'Sets the calendar system to use with `y` date data'
},
ids: {
valType: 'data_array',
description: 'A list of keys for object constancy of data points during animation'
Expand Down
7 changes: 4 additions & 3 deletions src/traces/scatter/xy_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@

'use strict';

var Registry = require('../../registry');


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

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

if(x) {
if(y) {
Expand Down
Loading