Skip to content

Better polar setConvert + a few misc polar touch ups #2895

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 18 commits into from
Aug 15, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions src/plots/polar/polar.js
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,7 @@ proto.updateRadialDrag = function(fullLayout, polarLayout) {
var _module = moduleCalcData[0][0].trace._module;
var polarLayoutNow = gd._fullLayout[_this.id];

if(_this._scene) _this._scene.clear();
_module.plot(gd, _this, moduleCalcDataVisible, polarLayoutNow);

if(!Registry.traceIs(k, 'gl')) {
Expand Down Expand Up @@ -1136,6 +1137,7 @@ proto.updateAngularDrag = function(fullLayout, polarLayout) {
var moduleCalcData = _this.traceHash[k];
var moduleCalcDataVisible = Lib.filterVisible(moduleCalcData);
var _module = moduleCalcData[0][0].trace._module;
if(_this._scene) _this._scene.clear();
_module.plot(gd, _this, moduleCalcDataVisible, polarLayoutNow);
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/traces/scattergl/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,8 @@ function sceneUpdate(gd, subplot) {
}
if(scene.scatter2d) {
clearViewport(scene.scatter2d, vp);
} else if(scene.line2d) {
clearViewport(scene.line2d, vp);
Copy link
Collaborator

Choose a reason for hiding this comment

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

The first arg to clearViewport is just used to find the regl._gl context... and so I guess the reason select2d is off by itself is that select gets its own context separate from the main data context?

Might be clearer then to refactor this as something like

var anyComponent = scene.scatter2d || scene.line2d || (scene.glText || [])[0];
if(anyComponent) clearViewport(anyComponent, vp);

Which would also make it easier to add error2d (can that ever be the only thing drawn?) and fill2d to the lookup list, looks plausible that these also have bugs similar to #2888.

BTW, looking at what clearViewport does - ie clears a rectangle from the context - what happens if two polar subplots have overlapping bounding boxes? Like if you made a hexagonal packing of polar subplots or you do something funny with sectors, like you make one large pac-man subplot eating a smaller one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

what happens if two polar subplots have overlapping bounding boxes?

This happens -> #2797

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Might be clearer then to refactor this as something like

Absolutely -> c3044e0

add error2d (can that ever be the only thing drawn?)

Traces with error bar will always have either an active scene.scatter2d or scene.line2d.

BTW, looking at what clearViewport does - ie clears a rectangle from the context -

We should take a look at how much of a perf gain is to clear only a fraction of the canvas on pan/select. If that's negligible, then I'm thinking we should be keeping track of a graph-wide regl-draw-queue instead, always clear the whole canvas and draw all regl parts on pan/select. This should make this a lot more manageable. cc @dy

Copy link
Collaborator

Choose a reason for hiding this comment

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

Traces with error bar will always have either an active scene.scatter2d or scene.line2d.

Even if mode: 'none'? That works fine for scatter, and sometimes tries to work with scattergl #2900

fill works with mode: 'none' too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Bulletproofed in 75786e4

} else if(scene.glText) {
clearViewport(scene.glText[0], vp);
}
Expand Down
1 change: 0 additions & 1 deletion src/traces/scatterpolargl/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ function plot(container, subplot, cdata) {
var angularAxis = subplot.angularAxis;

var scene = ScatterGl.sceneUpdate(container, subplot);
scene.clear();

cdata.forEach(function(cdscatter, traceIndex) {
if(!cdscatter || !cdscatter[0] || !cdscatter[0].trace) return;
Expand Down
86 changes: 86 additions & 0 deletions test/jasmine/tests/polar_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1076,6 +1076,92 @@ describe('Test polar interactions:', function() {
.catch(failTest)
.then(done);
});

describe('@gl should update scene during drag interactions on radial and angular drag area', function() {
var objs = ['scatter2d', 'line2d'];
var scene, gl, nTraces;

function _dragRadial() {
var node = d3.select('.polar > .draglayer > .radialdrag').node();
var p0 = [375, 200];
var dp = [-50, 0];
return drag(node, dp[0], dp[1], null, p0[0], p0[1], 2);
}

function _dragAngular() {
var node = d3.select('.polar > .draglayer > .angulardrag').node();
var p0 = [350, 150];
var dp = [-20, 20];
return drag(node, dp[0], dp[1], null, p0[0], p0[1]);
}

// once on drag, once on mouseup relayout
function _assert() {
expect(gl.clear).toHaveBeenCalledTimes(2);
gl.clear.calls.reset();

objs.forEach(function(o) {
if(scene[o]) {
expect(scene[o].draw).toHaveBeenCalledTimes(2 * nTraces);
scene[o].draw.calls.reset();
}
});
}

var specs = [{
desc: 'scatter marker case',
// mode: 'markers' by default
}, {
desc: 'line case',
// start with lines to lock down fix for #2888
patch: function(fig) {
fig.data.forEach(function(trace) { trace.mode = 'lines'; });
}
}, {
desc: 'line & markers case',
patch: function(fig) {
fig.data.forEach(function(trace) { trace.mode = 'markers+lines'; });
}
}];

specs.forEach(function(s) {
it('- ' + s.desc, function(done) {
var fig = Lib.extendDeep({}, require('@mocks/glpolar_scatter.json'));
scene = null;
gl = null;

fig.layout.hovermode = false;
fig.layout.width = 400;
fig.layout.height = 400;
fig.layout.margin = {l: 50, t: 50, b: 50, r: 50};

if(s.patch) s.patch(fig);
nTraces = fig.data.length;

Plotly.newPlot(gd, fig).then(function() {
scene = gd._fullLayout.polar._subplot._scene;

objs.forEach(function(o) {
if(scene[o]) {
spyOn(scene[o], 'draw').and.callThrough();
if(!gl) {
// all objects have the same _gl ref,
// spy on it just once
gl = scene[o].regl._gl;
spyOn(gl, 'clear').and.callThrough();
}
}
});
})
.then(function() { return _dragRadial(); })
.then(_assert)
.then(function() { return _dragAngular(); })
.then(_assert)
.catch(failTest)
.then(done);
});
});
});
});

describe('Test polar *gridshape linear* interactions', function() {
Expand Down