Skip to content

Commit 2fbd97c

Browse files
committed
don't slice uneven arrays in scatter and related traces
instead just record the length as fullTrace._length
1 parent f01bab9 commit 2fbd97c

File tree

6 files changed

+26
-27
lines changed

6 files changed

+26
-27
lines changed

Diff for: src/plots/cartesian/set_convert.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -398,15 +398,16 @@ module.exports = function setConvert(ax, fullLayout) {
398398
// in case the expected data isn't there, make a list of
399399
// integers based on the opposite data
400400
ax.makeCalcdata = function(trace, axLetter) {
401-
var arrayIn, arrayOut, i;
401+
var arrayIn, arrayOut, i, len;
402402

403403
var cal = ax.type === 'date' && trace[axLetter + 'calendar'];
404404

405405
if(axLetter in trace) {
406406
arrayIn = trace[axLetter];
407-
arrayOut = new Array(arrayIn.length);
407+
len = trace._length || arrayIn.length;
408+
arrayOut = new Array(len);
408409

409-
for(i = 0; i < arrayIn.length; i++) {
410+
for(i = 0; i < len; i++) {
410411
arrayOut[i] = ax.d2c(arrayIn[i], 0, cal);
411412
}
412413
}
@@ -418,9 +419,10 @@ module.exports = function setConvert(ax, fullLayout) {
418419

419420
// the opposing data, for size if we have x and dx etc
420421
arrayIn = trace[{x: 'y', y: 'x'}[axLetter]];
421-
arrayOut = new Array(arrayIn.length);
422+
len = trace._length || arrayIn.length;
423+
arrayOut = new Array(len);
422424

423-
for(i = 0; i < arrayIn.length; i++) arrayOut[i] = v0 + i * dv;
425+
for(i = 0; i < len; i++) arrayOut[i] = v0 + i * dv;
424426
}
425427
return arrayOut;
426428
};

Diff for: src/traces/ohlc/transform.js

+1
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ exports.calcTransform = function calcTransform(gd, trace, opts) {
213213
trace.x = x;
214214
trace.y = y;
215215
trace.text = textOut;
216+
trace._length = x.length;
216217
};
217218

218219
function convertTickWidth(gd, xa, trace) {

Diff for: src/traces/scatter/calc.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,12 @@ function calc(gd, trace) {
2424
var ya = Axes.getFromId(gd, trace.yaxis || 'y');
2525
var x = xa.makeCalcdata(trace, 'x');
2626
var y = ya.makeCalcdata(trace, 'y');
27-
var serieslen = Math.min(x.length, y.length);
27+
var serieslen = trace._length;
2828

2929
// cancel minimum tick spacings (only applies to bars and boxes)
3030
xa._minDtick = 0;
3131
ya._minDtick = 0;
3232

33-
if(x.length > serieslen) x.splice(serieslen, x.length - serieslen);
34-
if(y.length > serieslen) y.splice(serieslen, y.length - serieslen);
35-
3633
// check whether bounds should be tight, padded, extended to zero...
3734
// most cases both should be padded on both ends, so start with that.
3835
var xOptions = {padded: true};
@@ -120,9 +117,13 @@ function calcMarkerSize(trace, serieslen) {
120117
Axes.setConvert(ax);
121118

122119
var s = ax.makeCalcdata(trace.marker, 'size');
123-
if(s.length > serieslen) s.splice(serieslen, s.length - serieslen);
124120

125-
return s.map(markerTrans);
121+
var sizeOut = new Array(serieslen);
122+
for(var i = 0; i < serieslen; i++) {
123+
sizeOut[i] = markerTrans(s[i]);
124+
}
125+
return sizeOut;
126+
126127
} else {
127128
return markerTrans(marker.size);
128129
}

Diff for: src/traces/scatter/xy_defaults.js

+3-7
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,6 @@ module.exports = function handleXYDefaults(traceIn, traceOut, layout, coerce) {
2323
if(x) {
2424
if(y) {
2525
len = Math.min(x.length, y.length);
26-
// TODO: not sure we should do this here... but I think
27-
// the way it works in calc is wrong, because it'll delete data
28-
// which could be a problem eg in streaming / editing if x and y
29-
// come in at different times
30-
// so we need to revisit calc before taking this out
31-
if(len < x.length) traceOut.x = x.slice(0, len);
32-
if(len < y.length) traceOut.y = y.slice(0, len);
3326
}
3427
else {
3528
len = x.length;
@@ -44,5 +37,8 @@ module.exports = function handleXYDefaults(traceIn, traceOut, layout, coerce) {
4437
coerce('x0');
4538
coerce('dx');
4639
}
40+
41+
traceOut._length = len;
42+
4743
return len;
4844
};

Diff for: src/traces/scattergl/index.js

+7-9
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ function calc(container, trace) {
5353
var x = xaxis.type === 'linear' ? trace.x : xaxis.makeCalcdata(trace, 'x');
5454
var y = yaxis.type === 'linear' ? trace.y : yaxis.makeCalcdata(trace, 'y');
5555

56-
var count = (x || y).length, i, l, xx, yy;
56+
var count = trace._length, i, l, xx, yy;
5757

5858
if(!x) {
5959
x = Array(count);
@@ -71,28 +71,26 @@ function calc(container, trace) {
7171
// get log converted positions
7272
var rawx, rawy;
7373
if(xaxis.type === 'log') {
74-
rawx = Array(x.length);
75-
for(i = 0, l = x.length; i < l; i++) {
76-
rawx[i] = x[i];
74+
rawx = x.slice(0, count);
75+
for(i = 0; i < count; i++) {
7776
x[i] = xaxis.d2l(x[i]);
7877
}
7978
}
8079
else {
8180
rawx = x;
82-
for(i = 0, l = x.length; i < l; i++) {
81+
for(i = 0; i < count; i++) {
8382
x[i] = parseFloat(x[i]);
8483
}
8584
}
8685
if(yaxis.type === 'log') {
87-
rawy = Array(y.length);
88-
for(i = 0, l = y.length; i < l; i++) {
89-
rawy[i] = y[i];
86+
rawy = y.slice(0, count);
87+
for(i = 0; i < count; i++) {
9088
y[i] = yaxis.d2l(y[i]);
9189
}
9290
}
9391
else {
9492
rawy = y;
95-
for(i = 0, l = y.length; i < l; i++) {
93+
for(i = 0; i < count; i++) {
9694
y[i] = parseFloat(y[i]);
9795
}
9896
}

Diff for: src/transforms/filter.js

+1
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ exports.calcTransform = function(gd, trace, opts) {
219219
}
220220

221221
opts._indexToPoints = indexToPoints;
222+
trace._length = index;
222223
};
223224

224225
function getFilterFunc(opts, d2c, targetCalendar) {

0 commit comments

Comments
 (0)