Skip to content

Commit

Permalink
no need to set 'stash.count'
Browse files Browse the repository at this point in the history
... just use trace._length instead (which is far less confusing).
  • Loading branch information
etpinard committed Oct 12, 2018
1 parent e66b508 commit f79c64c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 33 deletions.
50 changes: 23 additions & 27 deletions src/traces/scattergl/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ function calc(gd, trace) {
var xa = AxisIDs.getFromId(gd, trace.xaxis);
var ya = AxisIDs.getFromId(gd, trace.yaxis);
var subplot = fullLayout._plots[trace.xaxis + trace.yaxis];
var count = trace._length;
var count2 = count * 2;
var len = trace._length;
var len2 = len * 2;
var stash = {};
var i, xx, yy;

Expand All @@ -52,21 +52,21 @@ function calc(gd, trace) {

// we need hi-precision for scatter2d,
// regl-scatter2d uses NaNs for bad/missing values
var positions = new Array(count2);
for(i = 0; i < count; i++) {
var positions = new Array(len2);
for(i = 0; i < len; i++) {
xx = x[i];
yy = y[i];
positions[i * 2] = xx === BADNUM ? NaN : xx;
positions[i * 2 + 1] = yy === BADNUM ? NaN : yy;
}

if(xa.type === 'log') {
for(i = 0; i < count2; i += 2) {
for(i = 0; i < len2; i += 2) {
positions[i] = xa.c2l(positions[i]);
}
}
if(ya.type === 'log') {
for(i = 1; i < count2; i += 2) {
for(i = 1; i < len2; i += 2) {
positions[i] = ya.c2l(positions[i]);
}
}
Expand All @@ -77,8 +77,8 @@ function calc(gd, trace) {
// FIXME: delegate this to webworker
stash.tree = cluster(positions);
} else {
var ids = stash.ids = new Array(count);
for(i = 0; i < count; i++) {
var ids = stash.ids = new Array(len);
for(i = 0; i < len; i++) {
ids[i] = i;
}
}
Expand All @@ -92,12 +92,9 @@ function calc(gd, trace) {
// For graphs with very large number of points and array marker.size,
// use average marker size instead to speed things up.
setFirstScatter(fullLayout, trace);
var ppad;
if(count < TOO_MANY_POINTS) {
ppad = calcMarkerSize(trace, count);
} else if(opts.marker) {
ppad = 2 * (opts.marker.sizeAvg || Math.max(opts.marker.size, 3));
}
var ppad = len < TOO_MANY_POINTS ?
calcMarkerSize(trace, len) :
2 * (opts.marker.sizeAvg || Math.max(opts.marker.size, 3));
calcAxisExpansion(gd, trace, xa, ya, x, y, ppad);
if(opts.errorX) expandForErrorBars(trace, xa, opts.errorX);
if(opts.errorY) expandForErrorBars(trace, ya, opts.errorY);
Expand All @@ -111,7 +108,7 @@ function calc(gd, trace) {

// FIXME: organize it in a more appropriate manner, probably in sceneOptions
// put point-cluster instance for optimized regl calc
if(opts.marker && count >= TOO_MANY_POINTS) {
if(opts.marker && len >= TOO_MANY_POINTS) {
opts.marker.cluster = stash.tree;
}

Expand All @@ -129,13 +126,10 @@ function calc(gd, trace) {

// stash scene ref
stash._scene = scene;
stash.index = scene.count;
stash.index = scene.count++;
stash.x = x;
stash.y = y;
stash.positions = positions;
stash.count = count;

scene.count++;

return [{x: false, y: false, t: stash, trace: trace}];
}
Expand Down Expand Up @@ -554,6 +548,7 @@ function plot(gd, subplot, cdata) {
var trace = cd0.trace;
var stash = cd0.t;
var index = stash.index;
var len = trace._length;
var x = stash.x;
var y = stash.y;

Expand All @@ -574,7 +569,7 @@ function plot(gd, subplot, cdata) {
selDict[selPts[j]] = 1;
}
var unselPts = [];
for(j = 0; j < stash.count; j++) {
for(j = 0; j < len; j++) {
if(!selDict[j]) unselPts.push(j);
}
scene.unselectBatch[index] = unselPts;
Expand All @@ -585,9 +580,9 @@ function plot(gd, subplot, cdata) {
// - spin that in a webworker
// - compute selection from polygons in data coordinates
// (maybe just for linear axes)
var xpx = stash.xpx = new Array(stash.count);
var ypx = stash.ypx = new Array(stash.count);
for(j = 0; j < stash.count; j++) {
var xpx = stash.xpx = new Array(len);
var ypx = stash.ypx = new Array(len);
for(j = 0; j < len; j++) {
xpx[j] = xaxis.c2p(x[j]);
ypx[j] = yaxis.c2p(y[j]);
}
Expand Down Expand Up @@ -849,6 +844,7 @@ function selectPoints(searchInfo, selectionTester) {
var selection = [];
var trace = cd[0].trace;
var stash = cd[0].t;
var len = trace._length;
var x = stash.x;
var y = stash.y;
var scene = stash._scene;
Expand All @@ -868,7 +864,7 @@ function selectPoints(searchInfo, selectionTester) {
var i;
if(selectionTester !== false && !selectionTester.degenerate) {
els = [], unels = [];
for(i = 0; i < stash.count; i++) {
for(i = 0; i < len; i++) {
if(selectionTester.contains([stash.xpx[i], stash.ypx[i]], false, i, searchInfo)) {
els.push(i);
selection.push({
Expand All @@ -882,7 +878,7 @@ function selectPoints(searchInfo, selectionTester) {
}
}
} else {
unels = arrayRange(stash.count);
unels = arrayRange(len);
}

// make sure selectBatch is created
Expand Down Expand Up @@ -916,6 +912,7 @@ function selectPoints(searchInfo, selectionTester) {

function styleTextSelection(cd) {
var cd0 = cd[0];
var trace = cd0.trace;
var stash = cd0.t;
var scene = stash._scene;
var index = stash.index;
Expand All @@ -932,8 +929,7 @@ function styleTextSelection(cd) {
var utc = unselOpts.color;
var base = baseOpts.color;
var hasArrayBase = Array.isArray(base);
opts.color = new Array(stash.count);

opts.color = new Array(trace._length);

for(i = 0; i < els.length; i++) {
j = els[i];
Expand Down
11 changes: 5 additions & 6 deletions src/traces/scatterpolargl/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ function plot(container, subplot, cdata) {
var cd = cdscatter[0];
var trace = cd.trace;
var stash = cd.t;
var len = trace._length;
var rArray = stash.r;
var thetaArray = stash.theta;
var i;
Expand All @@ -74,12 +75,11 @@ function plot(container, subplot, cdata) {
}
}

var count = rArray.length;
var positions = new Array(count * 2);
var x = Array(count);
var y = Array(count);
var positions = new Array(len * 2);
var x = Array(len);
var y = Array(len);

for(i = 0; i < count; i++) {
for(i = 0; i < len; i++) {
var r = subRArray[i];
var xx, yy;

Expand Down Expand Up @@ -139,7 +139,6 @@ function plot(container, subplot, cdata) {
stash.r = rArray;
stash.theta = thetaArray;
stash.positions = positions;
stash.count = count;
});

return ScatterGl.plot(container, subplot, cdata);
Expand Down

0 comments on commit f79c64c

Please sign in to comment.