Skip to content

Commit 68af287

Browse files
committed
add schema attributes in calendars module
- ++ allow trace and transform attributes to be filled by component modules.
1 parent 61ecd42 commit 68af287

File tree

3 files changed

+103
-1
lines changed

3 files changed

+103
-1
lines changed

src/components/calendars/index.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ var handleTraceDefaults = function(traceIn, traceOut, coords, layout) {
3535
handleDefaults(traceIn, traceOut, coords[i] + 'calendar', layout.calendar);
3636
}
3737
};
38+
3839
// each calendar needs its own default canonical tick. I would love to use
3940
// 2000-01-01 (or even 0000-01-01) for them all but they don't necessarily
4041
// all support either of those dates. Instead I'll use the most significant
@@ -164,10 +165,77 @@ function getCal(calendar) {
164165
return calendarObj;
165166
}
166167

168+
function makeAttrs(description) {
169+
return Lib.extendFlat({}, attributes, { description: description });
170+
}
171+
172+
function makeTraceAttrsDescription(coord) {
173+
return 'Sets the calendar system to use with `' + coord + '` date data.';
174+
}
175+
176+
var xAttrs = {
177+
xcalendar: makeAttrs(makeTraceAttrsDescription('x'))
178+
};
179+
180+
var xyAttrs = Lib.extendFlat({}, xAttrs, {
181+
ycalendar: makeAttrs(makeTraceAttrsDescription('y'))
182+
});
183+
184+
var xyzAttrs = Lib.extendFlat({}, xyAttrs, {
185+
zcalendar: makeAttrs(makeTraceAttrsDescription('z'))
186+
});
187+
188+
var axisAttrs = makeAttrs([
189+
'Sets the calendar system to use for `range` and `tick0`',
190+
'if this is a date axis. This does not set the calendar for',
191+
'interpreting data on this axis, that\'s specified in the trace',
192+
'or via the global `layout.calendar`'
193+
].join(' '));
194+
167195
module.exports = {
168196
moduleType: 'component',
169197
name: 'calendars',
170198

199+
schema: {
200+
traces: {
201+
scatter: xyAttrs,
202+
bar: xyAttrs,
203+
heatmap: xyAttrs,
204+
contour: xyAttrs,
205+
histogram: xyAttrs,
206+
histogram2d: xyAttrs,
207+
histogram2dcontour: xyAttrs,
208+
scatter3d: xyzAttrs,
209+
surface: xyzAttrs,
210+
mesh3d: xyzAttrs,
211+
scattergl: xyAttrs,
212+
ohlc: xAttrs,
213+
candlestick: xAttrs
214+
},
215+
layout: {
216+
calendar: makeAttrs([
217+
'Sets the default calendar system to use for interpreting and',
218+
'displaying dates throughout the plot.'
219+
].join(' ')),
220+
'xaxis.calendar': axisAttrs,
221+
'yaxis.calendar': axisAttrs,
222+
'scene.xaxis.calendar': axisAttrs,
223+
'scene.yaxis.calendar': axisAttrs,
224+
'scene.zaxis.calendar': axisAttrs
225+
},
226+
transforms: {
227+
filter: {
228+
calendar: makeAttrs([
229+
'Sets the calendar system to use for `value`, if it is a date.',
230+
'Note that this is not necessarily the same calendar as is used',
231+
'for the target data; that is set by its own calendar attribute,',
232+
'ie `trace.x` uses `trace.xcalendar` etc.'
233+
].join(' '))
234+
}
235+
}
236+
},
237+
238+
layoutAttributes: attributes,
171239

172240
handleDefaults: handleDefaults,
173241
handleTraceDefaults: handleTraceDefaults,

src/plot_api/plot_schema.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,17 @@ function getTraceAttributes(type) {
212212
extendDeep(attributes, basePlotModule.attributes);
213213
}
214214

215+
// add registered components trace attributes
216+
Object.keys(Registry.componentsRegistry).forEach(function(k) {
217+
var _module = Registry.componentsRegistry[k];
218+
219+
if(_module.schema && _module.schema.traces && _module.schema.traces[type]) {
220+
Object.keys(_module.schema.traces[type]).forEach(function(v) {
221+
insertAttrs(attributes, _module.schema.traces[type][v], v);
222+
});
223+
}
224+
});
225+
215226
// 'type' gets overwritten by baseAttributes; reset it here
216227
attributes.type = type;
217228

@@ -280,9 +291,21 @@ function getLayoutAttributes() {
280291

281292
function getTransformAttributes(type) {
282293
var _module = Registry.transformsRegistry[type];
294+
var attributes = extendDeep({}, _module.attributes);
295+
296+
// add registered components transform attributes
297+
Object.keys(Registry.componentsRegistry).forEach(function(k) {
298+
var _module = Registry.componentsRegistry[k];
299+
300+
if(_module.schema && _module.schema.transforms && _module.schema.transforms[type]) {
301+
Object.keys(_module.schema.transforms[type]).forEach(function(v) {
302+
insertAttrs(attributes, _module.schema.transforms[type][v], v);
303+
});
304+
}
305+
});
283306

284307
return {
285-
attributes: formatAttributes(_module.attributes)
308+
attributes: formatAttributes(attributes)
286309
};
287310
}
288311

test/jasmine/tests/plotschema_test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,17 @@ describe('plot schema', function() {
188188
});
189189
});
190190

191+
it('should work with registered components', function() {
192+
expect(plotSchema.traces.scatter.attributes.xcalendar.valType).toEqual('enumerated');
193+
expect(plotSchema.traces.scatter3d.attributes.zcalendar.valType).toEqual('enumerated');
194+
195+
expect(plotSchema.layout.layoutAttributes.calendar.valType).toEqual('enumerated');
196+
expect(plotSchema.layout.layoutAttributes.xaxis.calendar.valType).toEqual('enumerated');
197+
expect(plotSchema.layout.layoutAttributes.scene.xaxis.calendar.valType).toEqual('enumerated');
198+
199+
expect(plotSchema.transforms.filter.attributes.calendar.valType).toEqual('enumerated');
200+
});
201+
191202
it('should list correct defs', function() {
192203
expect(plotSchema.defs.valObjects).toBeDefined();
193204

0 commit comments

Comments
 (0)