Skip to content

Commit 3c79068

Browse files
committed
Admit isDateTime === true values (e.g. date strings) in non-fancy scattergl
1 parent f5d6113 commit 3c79068

File tree

2 files changed

+34
-11
lines changed

2 files changed

+34
-11
lines changed

src/traces/scattergl/convert.js

+19-11
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,13 @@ proto.handlePick = function(pickResult) {
114114
index = this.idToIndex[pickResult.pointId];
115115
}
116116

117+
var x = this.pickXData[index];
118+
117119
return {
118120
trace: this,
119121
dataCoord: pickResult.dataCoord,
120122
traceCoord: [
121-
Number(this.pickXData[index]), // non-fancy scattergl has Dates
123+
isNumeric(x) || !Lib.isDateTime(x) ? x : Lib.dateTime2ms(x),
122124
this.pickYData[index]
123125
],
124126
textLabel: Array.isArray(this.textLabels) ?
@@ -270,7 +272,7 @@ proto.updateFast = function(options) {
270272
pId = 0,
271273
ptr = 0;
272274

273-
var xx, yy;
275+
var xx, yy, fastType;
274276

275277
// TODO add 'very fast' mode that bypasses this loop
276278
// TODO bypass this on modebar +/- zoom
@@ -279,18 +281,24 @@ proto.updateFast = function(options) {
279281
yy = y[i];
280282

281283
// check for isNaN is faster but doesn't skip over nulls
282-
if(!isNumeric(yy)) continue;
283-
if(!isNumeric(xx) && !(xx instanceof Date)) continue;
284+
fastType = isNumeric(xx) || xx instanceof Date;
284285

285-
idToIndex[pId++] = i;
286+
if(isNumeric(yy) && (fastType || Lib.isDateTime(xx))) {
286287

287-
positions[ptr++] = xx;
288-
positions[ptr++] = yy;
288+
if(!fastType) {
289+
xx = Lib.dateTime2ms(xx);
290+
}
291+
292+
idToIndex[pId++] = i;
289293

290-
bounds[0] = Math.min(bounds[0], xx);
291-
bounds[1] = Math.min(bounds[1], yy);
292-
bounds[2] = Math.max(bounds[2], xx);
293-
bounds[3] = Math.max(bounds[3], yy);
294+
positions[ptr++] = xx;
295+
positions[ptr++] = yy;
296+
297+
bounds[0] = Math.min(bounds[0], xx);
298+
bounds[1] = Math.min(bounds[1], yy);
299+
bounds[2] = Math.max(bounds[2], xx);
300+
bounds[3] = Math.max(bounds[3], yy);
301+
}
294302
}
295303

296304
positions = truncate(positions, ptr);

test/jasmine/tests/gl2d_date_axis_render_test.js

+15
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,19 @@ describe('date axis', function() {
8181
expect(gd._fullLayout._plots.xy._scene2d.glplot.objects[3].pointCount).toBe(2);
8282
});
8383

84+
it('should use the non-fancy gl-vis/gl-scatter2d with string dates', function() {
85+
PlotlyInternal.plot(gd, [{
86+
type: 'scattergl',
87+
mode: 'markers', // important, as otherwise lines are assumed (which needs fancy)
88+
x: ['2016-10-10', '2016-10-11'],
89+
y: [15, 16]
90+
}]);
91+
92+
expect(gd._fullLayout.xaxis.type).toBe('date');
93+
expect(gd._fullLayout.yaxis.type).toBe('linear');
94+
expect(gd._fullData[0].type).toBe('scattergl');
95+
expect(gd._fullData[0]._module.basePlotModule.name).toBe('gl2d');
96+
97+
expect(gd._fullLayout._plots.xy._scene2d.glplot.objects[3].pointCount).toBe(2);
98+
});
8499
});

0 commit comments

Comments
 (0)