Skip to content

Commit f833c1e

Browse files
committed
filters use valuecalendar and targetcalendar instead of calendar
1 parent ef7a965 commit f833c1e

File tree

3 files changed

+60
-8
lines changed

3 files changed

+60
-8
lines changed

src/components/calendars/index.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -230,11 +230,13 @@ module.exports = {
230230
},
231231
transforms: {
232232
filter: {
233-
calendar: makeAttrs([
234-
'Sets the calendar system to use for `value`, if it is a date.',
235-
'Note that this is not necessarily the same calendar as is used',
236-
'for the target data; that is set by its own calendar attribute,',
237-
'ie `trace.x` uses `trace.xcalendar` etc.'
233+
valuecalendar: makeAttrs([
234+
'Sets the calendar system to use for `value`, if it is a date.'
235+
].join(' ')),
236+
targetcalendar: makeAttrs([
237+
'Sets the calendar system to use for `target`, if it is an',
238+
'array of dates. If `target` is a string (eg *x*) this is ignored',
239+
'and we use the corresponding trace attribute (eg `xcalendar`).'
238240
].join(' '))
239241
}
240242
}

src/transforms/filter.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ exports.supplyDefaults = function(transformIn) {
119119
coerce('target');
120120

121121
var handleCalendarDefaults = Registry.getComponentMethod('calendars', 'handleDefaults');
122-
handleCalendarDefaults(transformIn, transformOut, 'calendar', null);
122+
handleCalendarDefaults(transformIn, transformOut, 'valuecalendar', null);
123+
handleCalendarDefaults(transformIn, transformOut, 'targetcalendar', null);
123124
}
124125

125126
return transformOut;
@@ -134,7 +135,9 @@ exports.calcTransform = function(gd, trace, opts) {
134135

135136
if(!len) return;
136137

137-
var targetCalendar = Lib.nestedProperty(trace, target + 'calendar').get(),
138+
var targetCalendar = (typeof target === 'string') ?
139+
Lib.nestedProperty(trace, target + 'calendar').get() :
140+
opts.targetcalendar,
138141
dataToCoord = getDataToCoordFunc(gd, trace, target),
139142
filterFunc = getFilterFunc(opts, dataToCoord, targetCalendar),
140143
arrayAttrs = PlotSchema.findArrayAttributes(trace),
@@ -226,7 +229,7 @@ function getFilterFunc(opts, d2c, targetCalendar) {
226229
return array.indexOf(operation) !== -1;
227230
}
228231

229-
var d2cValue = function(v) { return d2c(v, 0, opts.calendar); },
232+
var d2cValue = function(v) { return d2c(v, 0, opts.valuecalendar); },
230233
d2cTarget = function(v) { return d2c(v, 0, targetCalendar); };
231234

232235
var coercedValue;

test/jasmine/tests/transform_filter_test.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,53 @@ describe('filter transforms calc:', function() {
142142
expect(out[0].z).toEqual(['2016-10-21', '2016-12-02']);
143143
});
144144

145+
it('should use the calendar from the target attribute if target is a string', function() {
146+
// this is the same data as in "filters should handle 3D *z* data"
147+
// but with different calendars
148+
var out = _transform([Lib.extendDeep({}, base, {
149+
type: 'scatter3d',
150+
// the same array as above but in nanakshahi dates
151+
z: ['0547-05-05', '0548-05-17', '0548-06-17', '0548-08-07', '0548-09-19'],
152+
zcalendar: 'nanakshahi',
153+
transforms: [{
154+
type: 'filter',
155+
operation: '>',
156+
value: '5776-06-28',
157+
valuecalendar: 'hebrew',
158+
target: 'z',
159+
// targetcalendar is ignored!
160+
targetcalendar: 'taiwan'
161+
}]
162+
})]);
163+
164+
expect(out[0].x).toEqual([0, 1]);
165+
expect(out[0].y).toEqual([1, 2]);
166+
expect(out[0].z).toEqual(['0548-08-07', '0548-09-19']);
167+
});
168+
169+
it('should use targetcalendar if target is an array', function() {
170+
// this is the same data as in "filters should handle 3D *z* data"
171+
// but with different calendars
172+
var out = _transform([Lib.extendDeep({}, base, {
173+
type: 'scatter3d',
174+
// the same array as above but in nanakshahi dates
175+
z: ['0547-05-05', '0548-05-17', '0548-06-17', '0548-08-07', '0548-09-19'],
176+
zcalendar: 'nanakshahi',
177+
transforms: [{
178+
type: 'filter',
179+
operation: '>',
180+
value: '5776-06-28',
181+
valuecalendar: 'hebrew',
182+
target: ['0104-07-20', '0105-08-01', '0105-09-01', '0105-10-21', '0105-12-02'],
183+
targetcalendar: 'taiwan'
184+
}]
185+
})]);
186+
187+
expect(out[0].x).toEqual([0, 1]);
188+
expect(out[0].y).toEqual([1, 2]);
189+
expect(out[0].z).toEqual(['0548-08-07', '0548-09-19']);
190+
});
191+
145192
it('filters should handle geographical *lon* data', function() {
146193
var trace0 = {
147194
type: 'scattergeo',

0 commit comments

Comments
 (0)