Skip to content

Recycled commits from abandoned fast trace toggle PRs #2860

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Aug 2, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
69dc0c4
DRY and small pref boost for scattergl
etpinard Jul 31, 2018
41ad08a
push trace module into fullLayout._modules even if visible:false
etpinard Jul 23, 2018
9c8ba02
fill in list of visible:true module in fullLayout._visibleModules
etpinard Jul 23, 2018
8ef5cb3
fix and :lock: splom trace visible toggling
etpinard Jul 23, 2018
cf0b19d
sub fail -> failTest
etpinard Jul 26, 2018
9cc5fbe
add scatter visibility restyles tests
etpinard Jul 25, 2018
dfada6a
add bar autorange tests & move 'b' init to setPositions
etpinard Jul 26, 2018
be44366
add findExtremes
etpinard Jul 25, 2018
ad1ac1f
adapt getAutoRange and doAutoRange to trace _extremes
etpinard Jul 25, 2018
769c160
fill trace._extremes with findExtremes in calc
etpinard Jul 25, 2018
736ab69
replace Axex.expand -> findExtremes in annotations and shapes
etpinard Jul 25, 2018
6194457
:hocho: ax._min / ax._max logic for rangeslider
etpinard Jul 25, 2018
8cd06ae
adapt enforceConstraints to new per trace/item _extremes
etpinard Jul 25, 2018
2a745de
adapt polar to new per trace/item _extremes
etpinard Jul 25, 2018
82d4bcc
adapt gl2d to findExtremes
etpinard Jul 26, 2018
29db388
:hocho: Axes.expand & adapt test for findExtremes
etpinard Jul 26, 2018
72f06a6
improve concatExtremes perf
etpinard Jul 27, 2018
a0bfaf3
collapse trace extremes before getAutorange
etpinard Jul 30, 2018
33b4085
mv repeat -> Lib.repeat
etpinard Aug 1, 2018
d233f3b
fix and :lock: _extremes in polar tranformed traces
etpinard Aug 1, 2018
89aebd1
fix typos in :books:
etpinard Aug 1, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/plots/cartesian/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ function plotOne(gd, plotinfo, cdSubplot, transitionOpts, makeOnCompleteCallback
var className = (_module.layerName || name + 'layer');
var plotMethod = _module.plot;

// plot all traces of this type on this subplot at once
// plot all visible traces of this type on this subplot at once
cdModuleAndOthers = getModuleCalcData(cdSubplot, plotMethod);
cdModule = cdModuleAndOthers[0];
// don't need to search the found traces again - in fact we need to NOT
Expand Down
1 change: 1 addition & 0 deletions src/plots/get_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ exports.getModuleCalcData = function(calcdata, arg1) {
for(var i = 0; i < calcdata.length; i++) {
var cd = calcdata[i];
var trace = cd[0].trace;
// N.B. 'legendonly' traces do not make it pass here
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pass past

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in 89aebd1

if(trace.visible !== true) continue;

// group calcdata trace not by 'module' (as the name of this function
Expand Down
4 changes: 2 additions & 2 deletions src/plots/plots.js
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ plots._hasPlotType = function(category) {
if(basePlotModules[i].name === category) return true;
}

// check trace modules
// check trace modules (including non-visible:true)
var modules = this._modules || [];
for(i = 0; i < modules.length; i++) {
var name = modules[i].name;
Expand Down Expand Up @@ -912,7 +912,7 @@ plots.supplyDataDefaults = function(dataIn, dataOut, layout, fullLayout) {
var _module = fullTrace._module;
if(!_module) return;

if(fullTrace.visible === true) Lib.pushUnique(modules, _module);
Lib.pushUnique(modules, _module);
Lib.pushUnique(basePlotModules, fullTrace._module.basePlotModule);

cnt++;
Expand Down
150 changes: 71 additions & 79 deletions src/traces/scattergl/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,17 @@ function calc(gd, trace) {
scene.textOptions.push(opts.text);
scene.textSelectedOptions.push(opts.textSel);
scene.textUnselectedOptions.push(opts.textUnsel);
scene.count++;

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

scene.count++;

gd.firstscatter = false;
return [{x: false, y: false, t: stash, trace: trace}];
}
Expand Down Expand Up @@ -230,19 +231,16 @@ function sceneUpdate(gd, subplot) {

// apply new option to all regl components (used on drag)
scene.update = function update(opt) {
var i;
var opts = new Array(scene.count);
for(i = 0; i < scene.count; i++) {
opts[i] = opt;
}
var opts = repeat(opt, scene.count);

if(scene.fill2d) scene.fill2d.update(opts);
if(scene.scatter2d) scene.scatter2d.update(opts);
if(scene.line2d) scene.line2d.update(opts);
if(scene.error2d) scene.error2d.update(opts.concat(opts));
if(scene.select2d) scene.select2d.update(opts);
if(scene.glText) {
for(i = 0; i < scene.count; i++) {
scene.glText[i].update(opts[i]);
for(var i = 0; i < scene.count; i++) {
scene.glText[i].update(opt);
}
}

Expand Down Expand Up @@ -290,18 +288,7 @@ function sceneUpdate(gd, subplot) {
};

scene.clear = function clear() {
var fullLayout = gd._fullLayout;
var vpSize = fullLayout._size;
var width = fullLayout.width;
var height = fullLayout.height;
var xaxis = subplot.xaxis;
var yaxis = subplot.yaxis;
var vp = [
vpSize.l + xaxis.domain[0] * vpSize.w,
vpSize.b + yaxis.domain[0] * vpSize.h,
(width - vpSize.r) - (1 - xaxis.domain[1]) * vpSize.w,
(height - vpSize.t) - (1 - yaxis.domain[1]) * vpSize.h
];
var vp = getViewport(gd._fullLayout, subplot.xaxis, subplot.yaxis);

if(scene.select2d) {
clearViewport(scene.select2d, vp);
Expand Down Expand Up @@ -352,6 +339,18 @@ function sceneUpdate(gd, subplot) {
return scene;
}

function getViewport(fullLayout, xaxis, yaxis) {
var gs = fullLayout._size;
var width = fullLayout.width;
var height = fullLayout.height;
return [
gs.l + xaxis.domain[0] * gs.w,
gs.b + yaxis.domain[0] * gs.h,
(width - gs.r) - (1 - xaxis.domain[1]) * gs.w,
(height - gs.t) - (1 - yaxis.domain[1]) * gs.h
];
}

function clearViewport(comp, vp) {
var gl = comp.regl._gl;
gl.enable(gl.SCISSOR_TEST);
Expand All @@ -360,22 +359,26 @@ function clearViewport(comp, vp) {
gl.clear(gl.COLOR_BUFFER_BIT);
}

function repeat(opt, cnt) {
var opts = new Array(cnt);
for(var i = 0; i < cnt; i++) {
opts[i] = opt;
}
return opts;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

non blocking, would probably make a good Lib function. Pretty sure we use this in other places as well, though I'm not quite sure how to search for it...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in 33b4085

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't find any other usage of a repeat helper in src/, but making a lib function now should help us remember that this helper exists.


function plot(gd, subplot, cdata) {
if(!cdata.length) return;

var i;

var fullLayout = gd._fullLayout;
var scene = cdata[0][0].t._scene;
var dragmode = fullLayout.dragmode;
var scene = subplot._scene;
var xaxis = subplot.xaxis;
var yaxis = subplot.yaxis;
var i, j;

// we may have more subplots than initialized data due to Axes.getSubplots method
if(!scene) return;

var vpSize = fullLayout._size;
var width = fullLayout.width;
var height = fullLayout.height;

var success = prepareRegl(gd, ['ANGLE_instanced_arrays', 'OES_element_index_uint']);
if(!success) {
scene.init();
Expand Down Expand Up @@ -516,38 +519,20 @@ function plot(gd, subplot, cdata) {
}
}

var selectMode = dragmode === 'lasso' || dragmode === 'select';
// form batch arrays, and check for selected points
scene.selectBatch = null;
scene.unselectBatch = null;
var dragmode = fullLayout.dragmode;
var selectMode = dragmode === 'lasso' || dragmode === 'select';

// provide viewport and range
var vpRange = cdata.map(function(cdscatter) {
if(!cdscatter || !cdscatter[0] || !cdscatter[0].trace) return;
var cd = cdscatter[0];
var trace = cd.trace;
var stash = cd.t;
var id = stash.index;
for(i = 0; i < cdata.length; i++) {
var cd0 = cdata[i][0];
var trace = cd0.trace;
var stash = cd0.t;
var index = stash.index;
var x = stash.x;
var y = stash.y;

var xaxis = subplot.xaxis || AxisIDs.getFromId(gd, trace.xaxis || 'x');
var yaxis = subplot.yaxis || AxisIDs.getFromId(gd, trace.yaxis || 'y');
var i;

var range = [
(xaxis._rl || xaxis.range)[0],
(yaxis._rl || yaxis.range)[0],
(xaxis._rl || xaxis.range)[1],
(yaxis._rl || yaxis.range)[1]
];

var viewport = [
vpSize.l + xaxis.domain[0] * vpSize.w,
vpSize.b + yaxis.domain[0] * vpSize.h,
(width - vpSize.r) - (1 - xaxis.domain[1]) * vpSize.w,
(height - vpSize.t) - (1 - yaxis.domain[1]) * vpSize.h
];

if(trace.selectedpoints || selectMode) {
if(!selectMode) selectMode = true;

Expand All @@ -558,37 +543,35 @@ function plot(gd, subplot, cdata) {

// regenerate scene batch, if traces number changed during selection
if(trace.selectedpoints) {
var selPts = scene.selectBatch[id] = Lib.selIndices2selPoints(trace);
var selPts = scene.selectBatch[index] = Lib.selIndices2selPoints(trace);

var selDict = {};
for(i = 0; i < selPts.length; i++) {
selDict[selPts[i]] = 1;
for(j = 0; j < selPts.length; j++) {
selDict[selPts[j]] = 1;
}
var unselPts = [];
for(i = 0; i < stash.count; i++) {
if(!selDict[i]) unselPts.push(i);
for(j = 0; j < stash.count; j++) {
if(!selDict[j]) unselPts.push(j);
}
scene.unselectBatch[id] = unselPts;
scene.unselectBatch[index] = unselPts;
}

// precalculate px coords since we are not going to pan during select
var xpx = new Array(stash.count);
var ypx = new Array(stash.count);
for(i = 0; i < stash.count; i++) {
xpx[i] = xaxis.c2p(x[i]);
ypx[i] = yaxis.c2p(y[i]);
// TODO, could do better here e.g.
// - 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++) {
xpx[j] = xaxis.c2p(x[j]);
ypx[j] = yaxis.c2p(y[j]);
}
stash.xpx = xpx;
stash.ypx = ypx;
}
else {
} else {
stash.xpx = stash.ypx = null;
}
}

return trace.visible ?
{viewport: viewport, range: range} :
null;
});

if(selectMode) {
// create select2d
Expand Down Expand Up @@ -618,6 +601,19 @@ function plot(gd, subplot, cdata) {
}
}

// provide viewport and range
var vpRange0 = {
viewport: getViewport(fullLayout, xaxis, yaxis),
// TODO do we need those fallbacks?
range: [
(xaxis._rl || xaxis.range)[0],
(yaxis._rl || yaxis.range)[0],
(xaxis._rl || xaxis.range)[1],
(yaxis._rl || yaxis.range)[1]
]
};
var vpRange = repeat(vpRange0, scene.count);

// upload viewport/range data to GPU
if(scene.fill2d) {
scene.fill2d.update(vpRange);
Expand All @@ -635,14 +631,10 @@ function plot(gd, subplot, cdata) {
scene.select2d.update(vpRange);
}
if(scene.glText) {
scene.glText.forEach(function(text, i) {
text.update(vpRange[i]);
});
scene.glText.forEach(function(text) { text.update(vpRange0); });
}

scene.draw();

return;
}


Expand Down
2 changes: 1 addition & 1 deletion test/jasmine/tests/cartesian_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ describe('restyle', function() {
return Plotly.restyle(gd, {visible: 'legendonly'}, 1);
})
.then(function() {
expect(!!gd._fullLayout._plots.x2y2._scene).toBe(false);
expect(!!gd._fullLayout._plots.x2y2._scene).toBe(true);
return Plotly.restyle(gd, {visible: true}, 1);
})
.then(function() {
Expand Down
15 changes: 13 additions & 2 deletions test/jasmine/tests/gl2d_plot_interact_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,27 +358,38 @@ describe('@gl Test gl2d plots', function() {
var _mock = Lib.extendDeep({}, mock);
_mock.data[0].line.width = 5;

function assertDrawCall(msg, exp) {
var draw = gd._fullLayout._plots.xy._scene.scatter2d.draw;
expect(draw).toHaveBeenCalledTimes(exp, msg);
draw.calls.reset();
}

Plotly.plot(gd, _mock)
.then(delay(30))
.then(function() {
spyOn(gd._fullLayout._plots.xy._scene.scatter2d, 'draw');
return Plotly.restyle(gd, 'visible', 'legendonly');
})
.then(function() {
expect(gd.querySelector('.gl-canvas-context')).toBe(null);
expect(readPixel(gd.querySelector('.gl-canvas-context'), 108, 100)[0]).toBe(0);
assertDrawCall('legendonly', 0);

return Plotly.restyle(gd, 'visible', true);
})
.then(function() {
expect(readPixel(gd.querySelector('.gl-canvas-context'), 108, 100)[0]).not.toBe(0);
assertDrawCall('back to visible', 1);

return Plotly.restyle(gd, 'visible', false);
})
.then(function() {
expect(gd.querySelector('.gl-canvas-context')).toBe(null);
expect(readPixel(gd.querySelector('.gl-canvas-context'), 108, 100)[0]).toBe(0);
assertDrawCall('visible false', 0);

return Plotly.restyle(gd, 'visible', true);
})
.then(function() {
assertDrawCall('back up', 1);
expect(readPixel(gd.querySelector('.gl-canvas-context'), 108, 100)[0]).not.toBe(0);
})
.catch(failTest)
Expand Down