Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 554d95e

Browse files
committed
accept targetcalendar if attribute has no allowed calendar
and fix tests
1 parent f833c1e commit 554d95e

File tree

5 files changed

+43
-8
lines changed

5 files changed

+43
-8
lines changed

src/components/calendars/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,9 @@ module.exports = {
235235
].join(' ')),
236236
targetcalendar: makeAttrs([
237237
'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`).'
238+
'array of dates. If `target` is a string (eg *x*) we use the',
239+
'corresponding trace attribute (eg `xcalendar`) if it exists,',
240+
'even if `targetcalendar` is provided.'
240241
].join(' '))
241242
}
242243
}

src/transforms/filter.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,21 @@ exports.calcTransform = function(gd, trace, opts) {
135135

136136
if(!len) return;
137137

138-
var targetCalendar = (typeof target === 'string') ?
139-
Lib.nestedProperty(trace, target + 'calendar').get() :
140-
opts.targetcalendar,
141-
dataToCoord = getDataToCoordFunc(gd, trace, target),
138+
var targetCalendar = opts.targetcalendar;
139+
140+
// even if you provide targetcalendar, if target is a string and there
141+
// is a calendar attribute matching target it will get used instead.
142+
if(typeof target === 'string') {
143+
var attrTargetCalendar = Lib.nestedProperty(trace, target + 'calendar').get();
144+
if(attrTargetCalendar) targetCalendar = attrTargetCalendar;
145+
}
146+
147+
// if target points to an axis, use the type we already have for that
148+
// axis to find the data type. Otherwise use the values to autotype.
149+
var d2cTarget = (target === 'x' || target === 'y' || target === 'z') ?
150+
target : filterArray;
151+
152+
var dataToCoord = getDataToCoordFunc(gd, trace, d2cTarget),
142153
filterFunc = getFilterFunc(opts, dataToCoord, targetCalendar),
143154
arrayAttrs = PlotSchema.findArrayAttributes(trace),
144155
originalArrays = {};

test/image/mocks/world-cals.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@
350350
{
351351
"type": "filter",
352352
"operation": "[]",
353-
"calendar": "jalali",
353+
"valuecalendar": "jalali",
354354
"value": [
355355
"0818-08",
356356
"0819-06"

test/jasmine/tests/plotschema_test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,8 @@ describe('plot schema', function() {
196196
expect(plotSchema.layout.layoutAttributes.xaxis.calendar.valType).toEqual('enumerated');
197197
expect(plotSchema.layout.layoutAttributes.scene.xaxis.calendar.valType).toEqual('enumerated');
198198

199-
expect(plotSchema.transforms.filter.attributes.calendar.valType).toEqual('enumerated');
199+
expect(plotSchema.transforms.filter.attributes.valuecalendar.valType).toEqual('enumerated');
200+
expect(plotSchema.transforms.filter.attributes.targetcalendar.valType).toEqual('enumerated');
200201
});
201202

202203
it('should list correct defs', function() {

test/jasmine/tests/transform_filter_test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,28 @@ describe('filter transforms calc:', function() {
166166
expect(out[0].z).toEqual(['0548-08-07', '0548-09-19']);
167167
});
168168

169+
it('should use targetcalendar anyway if there is no matching calendar attribute', 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: 'scatter',
174+
// the same array as above but in taiwanese dates
175+
text: ['0104-07-20', '0105-08-01', '0105-09-01', '0105-10-21', '0105-12-02'],
176+
transforms: [{
177+
type: 'filter',
178+
operation: '>',
179+
value: '5776-06-28',
180+
valuecalendar: 'hebrew',
181+
target: 'text',
182+
targetcalendar: 'taiwan'
183+
}]
184+
})]);
185+
186+
expect(out[0].x).toEqual([0, 1]);
187+
expect(out[0].y).toEqual([1, 2]);
188+
expect(out[0].text).toEqual(['0105-10-21', '0105-12-02']);
189+
});
190+
169191
it('should use targetcalendar if target is an array', function() {
170192
// this is the same data as in "filters should handle 3D *z* data"
171193
// but with different calendars

0 commit comments

Comments
 (0)