Skip to content

Add redrawReglTraces subroutine #3067

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 7 commits into from
Oct 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
82 changes: 68 additions & 14 deletions src/plot_api/subroutines.js
Original file line number Diff line number Diff line change
Expand Up @@ -462,21 +462,21 @@ exports.drawMainTitle = function(gd) {
});
};

// First, see if we need to do arraysToCalcdata
// call it regardless of what change we made, in case
// supplyDefaults brought in an array that was already
// in gd.data but not in gd._fullData previously
exports.doTraceStyle = function(gd) {
var fullLayout = gd._fullLayout;
var calcdata = gd.calcdata;
var editStyleCalls = [];
var i;

for(i = 0; i < gd.calcdata.length; i++) {
var cd = gd.calcdata[i];
for(i = 0; i < calcdata.length; i++) {
var cd = calcdata[i];
var cd0 = cd[0] || {};
var trace = cd0.trace || {};
var _module = trace._module || {};

// See if we need to do arraysToCalcdata
// call it regardless of what change we made, in case
// supplyDefaults brought in an array that was already
// in gd.data but not in gd._fullData previously
var arraysToCalcdata = _module.arraysToCalcdata;
if(arraysToCalcdata) arraysToCalcdata(cd, trace);

Expand All @@ -485,16 +485,12 @@ exports.doTraceStyle = function(gd) {
}

if(editStyleCalls.length) {
clearGlCanvases(gd);

if(fullLayout._hasOnlyLargeSploms) {
fullLayout._splomGrid.draw();
}

for(i = 0; i < editStyleCalls.length; i++) {
var edit = editStyleCalls[i];
edit.fn(gd, edit.cd0);
}
clearGlCanvases(gd);
exports.redrawReglTraces(gd);
}

Plots.style(gd);
Expand Down Expand Up @@ -546,8 +542,9 @@ exports.doTicksRelayout = function(gd) {
Axes.doTicks(gd, 'redraw');

if(gd._fullLayout._hasOnlyLargeSploms) {
Registry.subplotsRegistry.splom.updateGrid(gd);
clearGlCanvases(gd);
Registry.subplotsRegistry.splom.plot(gd);
exports.redrawReglTraces(gd);
}

exports.drawMainTitle(gd);
Expand Down Expand Up @@ -600,6 +597,8 @@ exports.drawData = function(gd) {
basePlotModules[i].plot(gd);
}

exports.redrawReglTraces(gd);

// styling separate from drawing
Plots.style(gd);

Expand All @@ -613,6 +612,61 @@ exports.drawData = function(gd) {
return Plots.previousPromises(gd);
};

// Draw (or redraw) all traces in one go,
// useful during drag and selection where buffers of targeted traces are updated,
// but all traces need to be redrawn following clearGlCanvases.
//
// Note that _module.plot for regl trace does NOT draw things
// on the canvas, they only update the buffers.
// Drawing is perform here.
//
// TODO try adding per-subplot option using gl.SCISSOR_TEST for
// non-overlaying, disjoint subplots.
//
// TODO try to include parcoords in here.
exports.redrawReglTraces = function(gd) {
var fullLayout = gd._fullLayout;

if(fullLayout._has('regl')) {
var fullData = gd._fullData;
var cartesianIds = [];
var polarIds = [];
var i, sp;

if(fullLayout._hasOnlyLargeSploms) {
fullLayout._splomGrid.draw();
}

// N.B.
// - Loop over fullData (not _splomScenes) to preserve splom trace-to-trace ordering
// - Fill list if subplot ids (instead of fullLayout._subplots) to handle cases where all traces
// of a given module are `visible !== true`
for(i = 0; i < fullData.length; i++) {
var trace = fullData[i];

if(trace.visible === true) {
if(trace.type === 'splom') {
fullLayout._splomScenes[trace.uid].draw();
} else if(trace.type === 'scattergl') {
Lib.pushUnique(cartesianIds, trace.xaxis + trace.yaxis);
} else if(trace.type === 'scatterpolargl') {
Lib.pushUnique(polarIds, trace.subplot);
}
}
}

for(i = 0; i < cartesianIds.length; i++) {
sp = fullLayout._plots[cartesianIds[i]];
if(sp._scene) sp._scene.draw();
}

for(i = 0; i < polarIds.length; i++) {
sp = fullLayout[polarIds[i]]._subplot;
if(sp._scene) sp._scene.draw();
}
}
};

exports.doAutoRangeAndConstraints = function(gd) {
var axList = Axes.list(gd, '', true);

Expand Down
26 changes: 11 additions & 15 deletions src/plots/cartesian/dragbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ var supportsPassive = require('has-passive-events');
var Registry = require('../../registry');
var Lib = require('../../lib');
var svgTextUtils = require('../../lib/svg_text_utils');
var clearGlCanvases = require('../../lib/clear_gl_canvases');
var Color = require('../../components/color');
var Drawing = require('../../components/drawing');
var Fx = require('../../components/fx');
var setCursor = require('../../lib/setcursor');
var dragElement = require('../../components/dragelement');
var FROM_TL = require('../../constants/alignment').FROM_TL;
var clearGlCanvases = require('../../lib/clear_gl_canvases');
var redrawReglTraces = require('../../plot_api/subroutines').redrawReglTraces;

var Plots = require('../plots');

Expand Down Expand Up @@ -84,7 +85,7 @@ function makeDragBox(gd, plotinfo, x, y, w, h, ns, ew) {
// do we need to edit x/y ranges?
var editX, editY;
// graph-wide optimization flags
var hasScatterGl, hasOnlyLargeSploms, hasSplom, hasSVG;
var hasScatterGl, hasSplom, hasSVG;
// collected changes to be made to the plot by relayout at the end
var updates;

Expand Down Expand Up @@ -125,8 +126,7 @@ function makeDragBox(gd, plotinfo, x, y, w, h, ns, ew) {

var fullLayout = gd._fullLayout;
hasScatterGl = fullLayout._has('scattergl');
hasOnlyLargeSploms = fullLayout._hasOnlyLargeSploms;
hasSplom = hasOnlyLargeSploms || fullLayout._has('splom');
hasSplom = fullLayout._has('splom');
hasSVG = fullLayout._has('svg');
}

Expand Down Expand Up @@ -744,33 +744,29 @@ function makeDragBox(gd, plotinfo, x, y, w, h, ns, ew) {
var subplots = fullLayout._subplots.cartesian;
var i, sp, xa, ya;

if(hasSplom || hasScatterGl) {
clearGlCanvases(gd);
}

if(hasSplom) {
Registry.subplotsRegistry.splom.drag(gd);
if(hasOnlyLargeSploms) return;
}

if(hasScatterGl) {
// loop over all subplots (w/o exceptions) here,
// as we cleared the gl canvases above
for(i = 0; i < subplots.length; i++) {
sp = plotinfos[subplots[i]];
xa = sp.xaxis;
ya = sp.yaxis;

var scene = sp._scene;
if(scene) {
// FIXME: possibly we could update axis internal _r and _rl here
if(sp._scene) {
var xrng = Lib.simpleMap(xa.range, xa.r2l);
var yrng = Lib.simpleMap(ya.range, ya.r2l);
scene.update({range: [xrng[0], yrng[0], xrng[1], yrng[1]]});
sp._scene.update({range: [xrng[0], yrng[0], xrng[1], yrng[1]]});
}
}
}

if(hasSplom || hasScatterGl) {
clearGlCanvases(gd);
redrawReglTraces(gd);
}

if(hasSVG) {
var xScaleFactor = viewBox[2] / xa0._length;
var yScaleFactor = viewBox[3] / ya0._length;
Expand Down
47 changes: 15 additions & 32 deletions src/plots/cartesian/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ var polygon = require('../../lib/polygon');
var throttle = require('../../lib/throttle');
var makeEventData = require('../../components/fx/helpers').makeEventData;
var getFromId = require('./axis_ids').getFromId;
var sortModules = require('../sort_modules').sortModules;
var clearGlCanvases = require('../../lib/clear_gl_canvases');
var redrawReglTraces = require('../../plot_api/subroutines').redrawReglTraces;

var constants = require('./constants');
var MINSELECT = constants.MINSELECT;
Expand Down Expand Up @@ -663,7 +664,7 @@ function isOnlyOnePointSelected(searchTraces) {
}

function updateSelectedState(gd, searchTraces, eventData) {
var i, j, searchInfo, trace;
var i, searchInfo, cd, trace;

if(eventData) {
var pts = eventData.points || [];
Expand Down Expand Up @@ -696,43 +697,25 @@ function updateSelectedState(gd, searchTraces, eventData) {
}
}

// group searchInfo traces by trace modules
var lookup = {};
var hasRegl = false;

for(i = 0; i < searchTraces.length; i++) {
searchInfo = searchTraces[i];
cd = searchInfo.cd;
trace = cd[0].trace;

var name = searchInfo._module.name;
if(lookup[name]) {
lookup[name].push(searchInfo);
} else {
lookup[name] = [searchInfo];
if(Registry.traceIs(trace, 'regl')) {
hasRegl = true;
}

var _module = searchInfo._module;
var fn = _module.styleOnSelect || _module.style;
if(fn) fn(gd, cd);
}

var keys = Object.keys(lookup).sort(sortModules);

for(i = 0; i < keys.length; i++) {
var items = lookup[keys[i]];
var len = items.length;
var item0 = items[0];
var trace0 = item0.cd[0].trace;
var _module = item0._module;
var styleSelection = _module.styleOnSelect || _module.style;

if(Registry.traceIs(trace0, 'regl')) {
// plot regl traces per module
var cds = new Array(len);
for(j = 0; j < len; j++) {
cds[j] = items[j].cd;
}
styleSelection(gd, cds);
} else {
// plot svg trace per trace
for(j = 0; j < len; j++) {
styleSelection(gd, items[j].cd);
}
}
if(hasRegl) {
clearGlCanvases(gd);
redrawReglTraces(gd);
}
}

Expand Down
4 changes: 0 additions & 4 deletions src/plots/plots.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ var Color = require('../components/color');
var BADNUM = require('../constants/numerical').BADNUM;

var axisIDs = require('../plots/cartesian/axis_ids');
var sortBasePlotModules = require('./sort_modules').sortBasePlotModules;

var animationAttrs = require('./animation_attributes');
var frameAttrs = require('./frame_attributes');
Expand Down Expand Up @@ -487,9 +486,6 @@ plots.supplyDefaults = function(gd, opts) {
if(!skipUpdateCalc && oldCalcdata.length === newFullData.length) {
plots.supplyDefaultsUpdateCalc(oldCalcdata, newFullData);
}

// sort base plot modules for consistent ordering
newFullLayout._basePlotModules.sort(sortBasePlotModules);
};

plots.supplyDefaultsUpdateCalc = function(oldCalcdata, newFullData) {
Expand Down
18 changes: 16 additions & 2 deletions src/plots/polar/polar.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ var prepSelect = require('../cartesian/select').prepSelect;
var selectOnClick = require('../cartesian/select').selectOnClick;
var clearSelect = require('../cartesian/select').clearSelect;
var setCursor = require('../../lib/setcursor');
var clearGlCanvases = require('../../lib/clear_gl_canvases');
var redrawReglTraces = require('../../plot_api/subroutines').redrawReglTraces;

var MID_SHIFT = require('../../constants/alignment').MID_SHIFT;
var constants = require('./constants');
Expand Down Expand Up @@ -1058,14 +1060,20 @@ proto.updateRadialDrag = function(fullLayout, polarLayout, rngIndex) {
.attr('transform', strTranslate(cx, cy))
.selectAll('path').attr('transform', null);

if(_this._scene) _this._scene.clear();
var hasRegl = false;

for(var traceType in _this.traceHash) {
var moduleCalcData = _this.traceHash[traceType];
var moduleCalcDataVisible = Lib.filterVisible(moduleCalcData);
var _module = moduleCalcData[0][0].trace._module;
var polarLayoutNow = gd._fullLayout[_this.id];
_module.plot(gd, _this, moduleCalcDataVisible, polarLayoutNow);
if(Registry.traceIs(traceType, 'gl') && moduleCalcDataVisible.length) hasRegl = true;
}

if(hasRegl) {
clearGlCanvases(gd);
redrawReglTraces(gd);
}
}

Expand Down Expand Up @@ -1185,16 +1193,22 @@ proto.updateAngularDrag = function(fullLayout) {
scatterTraces.call(Drawing.hideOutsideRangePoints, _this);
}

if(_this._scene) _this._scene.clear();
var hasRegl = false;

for(var traceType in _this.traceHash) {
if(Registry.traceIs(traceType, 'gl')) {
var moduleCalcData = _this.traceHash[traceType];
var moduleCalcDataVisible = Lib.filterVisible(moduleCalcData);
var _module = moduleCalcData[0][0].trace._module;
_module.plot(gd, _this, moduleCalcDataVisible, polarLayoutNow);
if(moduleCalcDataVisible.length) hasRegl = true;
}
}

if(hasRegl) {
clearGlCanvases(gd);
redrawReglTraces(gd);
}
}

function doneFn() {
Expand Down
25 changes: 0 additions & 25 deletions src/plots/sort_modules.js

This file was deleted.

Loading