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

"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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Dec 7, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add schema attributes in calendars module
- ++ allow trace and transform attributes to
  be filled by component modules.
  • Loading branch information
etpinard committed Dec 6, 2016
commit 68af28745fba7551e57ae166a95e64bad76bf6d0
68 changes: 68 additions & 0 deletions 68 src/components/calendars/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ var handleTraceDefaults = function(traceIn, traceOut, coords, layout) {
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 @@ -164,10 +165,77 @@ function getCal(calendar) {
return calendarObj;
}

function makeAttrs(description) {
return Lib.extendFlat({}, attributes, { description: description });
}

function makeTraceAttrsDescription(coord) {
return 'Sets the calendar system to use with `' + coord + '` date data.';
}

var xAttrs = {
xcalendar: makeAttrs(makeTraceAttrsDescription('x'))
};

var xyAttrs = Lib.extendFlat({}, xAttrs, {
ycalendar: makeAttrs(makeTraceAttrsDescription('y'))
});

var xyzAttrs = Lib.extendFlat({}, xyAttrs, {
zcalendar: makeAttrs(makeTraceAttrsDescription('z'))
});

var axisAttrs = makeAttrs([
'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(' '));

module.exports = {
moduleType: 'component',
name: 'calendars',

schema: {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

some fancy (slightly hacky) declaration to make sure that calendar attributes will show up on https://community.plot.ly/

Copy link
Collaborator

Choose a reason for hiding this comment

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

how will we know to keep this up to date?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

how will we know to keep this up to date?

good question. There's got to be a way to test this.

traces: {
scatter: xyAttrs,
bar: xyAttrs,
heatmap: xyAttrs,
contour: xyAttrs,
histogram: xyAttrs,
histogram2d: xyAttrs,
histogram2dcontour: xyAttrs,
scatter3d: xyzAttrs,
surface: xyzAttrs,
mesh3d: xyzAttrs,
scattergl: xyAttrs,
ohlc: xAttrs,
candlestick: xAttrs
},
layout: {
calendar: makeAttrs([
'Sets the default calendar system to use for interpreting and',
'displaying dates throughout the plot.'
].join(' ')),
'xaxis.calendar': axisAttrs,
'yaxis.calendar': axisAttrs,
'scene.xaxis.calendar': axisAttrs,
'scene.yaxis.calendar': axisAttrs,
'scene.zaxis.calendar': axisAttrs
},
transforms: {
filter: {
calendar: makeAttrs([
'Sets the calendar system to use for `value`, if it is a date.',
'Note that this is not necessarily the same calendar as is used',
'for the target data; that is set by its own calendar attribute,',
'ie `trace.x` uses `trace.xcalendar` etc.'
].join(' '))
}
}
},

layoutAttributes: attributes,

handleDefaults: handleDefaults,
handleTraceDefaults: handleTraceDefaults,
Expand Down
25 changes: 24 additions & 1 deletion 25 src/plot_api/plot_schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,17 @@ function getTraceAttributes(type) {
extendDeep(attributes, basePlotModule.attributes);
}

// add registered components trace attributes
Object.keys(Registry.componentsRegistry).forEach(function(k) {
var _module = Registry.componentsRegistry[k];

if(_module.schema && _module.schema.traces && _module.schema.traces[type]) {
Object.keys(_module.schema.traces[type]).forEach(function(v) {
insertAttrs(attributes, _module.schema.traces[type][v], v);
});
}
});

// 'type' gets overwritten by baseAttributes; reset it here
attributes.type = type;

Expand Down Expand Up @@ -280,9 +291,21 @@ function getLayoutAttributes() {

function getTransformAttributes(type) {
var _module = Registry.transformsRegistry[type];
var attributes = extendDeep({}, _module.attributes);

// add registered components transform attributes
Object.keys(Registry.componentsRegistry).forEach(function(k) {
var _module = Registry.componentsRegistry[k];

if(_module.schema && _module.schema.transforms && _module.schema.transforms[type]) {
Object.keys(_module.schema.transforms[type]).forEach(function(v) {
insertAttrs(attributes, _module.schema.transforms[type][v], v);
});
}
});

return {
attributes: formatAttributes(_module.attributes)
attributes: formatAttributes(attributes)
};
}

Expand Down
11 changes: 11 additions & 0 deletions 11 test/jasmine/tests/plotschema_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,17 @@ describe('plot schema', function() {
});
});

it('should work with registered components', function() {
expect(plotSchema.traces.scatter.attributes.xcalendar.valType).toEqual('enumerated');
expect(plotSchema.traces.scatter3d.attributes.zcalendar.valType).toEqual('enumerated');

expect(plotSchema.layout.layoutAttributes.calendar.valType).toEqual('enumerated');
expect(plotSchema.layout.layoutAttributes.xaxis.calendar.valType).toEqual('enumerated');
expect(plotSchema.layout.layoutAttributes.scene.xaxis.calendar.valType).toEqual('enumerated');

expect(plotSchema.transforms.filter.attributes.calendar.valType).toEqual('enumerated');
});

it('should list correct defs', function() {
expect(plotSchema.defs.valObjects).toBeDefined();

Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.