8000 [take 2] Implement scatter `cliponaxis: false` by etpinard · Pull Request #1861 · plotly/plotly.js · GitHub
[go: up one dir, main page]

Skip to content

[take 2] Implement scatter cliponaxis: false #1861

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
Jul 13, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
c28b26a
lint in drawing/
etpinard Jul 7, 2017
8f72d1f
implement cliponaxis
etpinard Jul 7, 2017
1909034
hide outside range points on drag and transitions
etpinard Jul 7, 2017
4b5c4bb
implement `cliponaxis: false` for scatterternary
etpinard Jul 7, 2017
d46cae7
merge custom shared assertions into single assets/ module
etpinard Jul 7, 2017
7228d5d
add cliponaxis false mock
etpinard Jul 7, 2017
fe1f889
showcase new cliponaxis logic in ternary_markers
etpinard Jul 7, 2017
89ee533
add scatter and scatterternary cliponaxis tests
etpinard Jul 7, 2017
e4d7889
fix panning for ternary lines under `cliponaxis: false`
etpinard Jul 7, 2017
091473b
fix lint
etpinard Jul 10, 2017
9becb7c
hide points using `display: 'none'` instead of visibility attr
etpinard Jul 11, 2017
62ab845
remove obsolete code from old d.{xp|yp} optimization attempt
etpinard Jul 11, 2017
0496144
stash layer clipId value (null or same as clipId)
etpinard Jul 11, 2017
7b62b73
handle cliponaxis false/true traces coexisting on same subplot
etpinard Jul 11, 2017
02b9fbc
rename 'layers' cartesian constant -> 'traceLayerClasses'
etpinard Jul 11, 2017
1c85de6
8000 add 'layer' axis attribute
etpinard Jul 11, 2017
e44aa4d
improve cliponaxis_false mock
etpinard Jul 11, 2017
e84701f
replace strict-d3 IIFE with browserify 'require' transform
etpinard Jul 12, 2017
e234827
fixes #1873 - apply transform on <clipPath> child
etpinard Jul 12, 2017
6f494c6
talk about 'cliponaxis' in axis 'layer' description and vice-versa
etpinard Jul 12, 2017
bbb31f4
Merge pull request #1871 from plotly/axis-layer-above-below
etpinard Jul 13, 2017
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
Prev Previous commit
Next Next commit
add 'layer' axis attribute
- has 2 possible values: 'above traces' and 'below traces' for now,
  but opens the door for other values down the road.
  • Loading branch information
etpinard committed Jul 11, 2017
commit 1c85de675ada7c46b688e49034612439a4178dc2
8000
7 changes: 6 additions & 1 deletion src/plots/cartesian/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,10 @@ module.exports = {
'carpetlayer',
'boxlayer',
'scatterlayer'
]
],

layerValue2layerClass: {
'above traces': 'above',
'below traces': 'below'
}
};
51 changes: 41 additions & 10 deletions src/plots/cartesian/index.js
8000
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,8 @@ function makeSubplotData(gd) {
function makeSubplotLayer(plotinfo) {
var plotgroup = plotinfo.plotgroup;
var id = plotinfo.id;
var xLayer = constants.layerValue2layerClass[plotinfo.xaxis.layer];
var yLayer = constants.layerValue2layerClass[plotinfo.yaxis.layer];

if(!plotinfo.mainplot) {
var backLayer = joinLayer(plotgroup, 'g', 'layer-subplot');
Expand All @@ -308,19 +310,36 @@ function makeSubplotLayer(plotinfo) {
plotinfo.zerolinelayer = joinLayer(plotgroup, 'g', 'zerolinelayer');
plotinfo.overzero = joinLayer(plotgroup, 'g', 'overzero');

joinLayer(plotgroup, 'path', 'xlines-below');
joinLayer(plotgroup, 'path', 'ylines-below');
plotinfo.overlinesBelow = joinLayer(plotgroup, 'g', 'overlines-below');

joinLayer(plotgroup, 'g', 'xaxislayer-below');
joinLayer(plotgroup, 'g', 'yaxislayer-below');
plotinfo.overaxesBelow = joinLayer(plotgroup, 'g', 'overaxes-below');

plotinfo.plot = joinLayer(plotgroup, 'g', 'plot');
plotinfo.overplot = joinLayer(plotgroup, 'g', 'overplot');

plotinfo.xlines = joinLayer(plotgroup, 'path', 'xlines');
plotinfo.ylines = joinLayer(plotgroup, 'path', 'ylines');
plotinfo.overlines = joinLayer(plotgroup, 'g', 'overlines');
joinLayer(plotgroup, 'path', 'xlines-above');
joinLayer(plotgroup, 'path', 'ylines-above');
plotinfo.overlinesAbove = joinLayer(plotgroup, 'g', 'overlines-above');

joinLayer(plotgroup, 'g', 'xaxislayer-above');
joinLayer(plotgroup, 'g', 'yaxislayer-above');
plotinfo.overaxesAbove = joinLayer(plotgroup, 'g', 'overaxes-above');

plotinfo.xaxislayer = joinLayer(plotgroup, 'g', 'xaxislayer');
plotinfo.yaxislayer = joinLayer(plotgroup, 'g', 'yaxislayer');
plotinfo.overaxes = joinLayer(plotgroup, 'g', 'overaxes');
// set refs to correct layers as determined by 'axis.layer'
plotinfo.xlines = plotgroup.select('.xlines-' + xLayer);
plotinfo.ylines = plotgroup.select('.ylines-' + yLayer);
plotinfo.xaxislayer = plotgroup.select('.xaxislayer-' + xLayer);
plotinfo.yaxislayer = plotgroup.select('.yaxislayer-' + yLayer);
}
else {
var mainplotinfo = plotinfo.mainplotinfo;
var mainplotgroup = mainplotinfo.plotgroup;
var xId = id + '-x';
var yId = id + '-y';

// now make the components of overlaid subplots
// overlays don't have backgrounds, and append all
Expand All @@ -330,11 +349,23 @@ function makeSubplotLayer(plotinfo) {
plotinfo.gridlayer = joinLayer(mainplotinfo.overgrid, 'g', id);
plotinfo.zerolinelayer = joinLayer(mainplotinfo.overzero, 'g', id);

joinLayer(mainplotinfo.overlinesBelow, 'path', xId);
joinLayer(mainplotinfo.overlinesBelow, 'path', yId);
joinLayer(mainplotinfo.overaxesBelow, 'g', xId);
joinLayer(mainplotinfo.overaxesBelow, 'g', yId);

plotinfo.plot = joinLayer(mainplotinfo.overplot, 'g', id);
plotinfo.xlines = joinLayer(mainplotinfo.overlines, 'path', id + '-x');
plotinfo.ylines = joinLayer(mainplotinfo.overlines, 'path', id + '-y');
plotinfo.xaxislayer = joinLayer(mainplotinfo.overaxes, 'g', id + '-x');
plotinfo.yaxislayer = joinLayer(mainplotinfo.overaxes, 'g', id + '-y');

joinLayer(mainplotinfo.overlinesAbove, 'path', xId);
joinLayer(mainplotinfo.overlinesAbove, 'path', yId);
joinLayer(mainplotinfo.overaxesAbove, 'g', xId);
joinLayer(mainplotinfo.overaxesAbove, 'g', yId);

// set refs to correct layers as determined by 'abovetraces'
plotinfo.xlines = mainplotgroup.select('.overlines-' + xLayer).select('.' + xId);
plotinfo.ylines = mainplotgroup.select('.overlines-' + yLayer).select('.' + yId);
plotinfo.xaxislayer = mainplotgroup.select('.overaxes-' + xLayer).select('.' + xId);
plotinfo.yaxislayer = mainplotgroup.select('.overaxes-' + yLayer).select('.' + yId);
}

// common attributes for all subplots, overlays or not
Expand Down
12 changes: 12 additions & 0 deletions src/plots/cartesian/layout_attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,18 @@ module.exports = {
'If *false*, this axis does not overlay any same-letter axes.'
].join(' ')
},
layer: {
valType: 'enumerated',
values: ['above traces', 'below traces'],
dflt: 'above traces',
role: 'info',
description: [
'Sets the layer on which this axis is displayed.',
'If *above traces*, this axis is displayed above all the subplot\'s traces',
'If *below traces*, this axis is displayed below all the subplot\'s traces,',
'but above the grid lines.'
].join(' ')
},
domain: {
valType: 'info_array',
role: 'info',
Expand Down
2 changes: 2 additions & 0 deletions src/plots/cartesian/position_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,7 @@ module.exports = function handlePositionDefaults(containerIn, containerOut, coer
Lib.noneOrAll(containerIn.domain, containerOut.domain, [0, 1]);
}

coerce('layer');

return containerOut;
};
25 changes: 18 additions & 7 deletions src/plots/plots.js
Original file line number Diff line number Diff line change
Expand Up @@ -638,24 +638,35 @@ plots.linkSubplots = function(newFullData, newFullLayout, oldFullData, oldFullLa
var ids = Plotly.Axes.getSubplots(mockGd);

for(var i = 0; i < ids.length; i++) {
var id = ids[i],
oldSubplot = oldSubplots[id],
plotinfo;
var id = ids[i];
var oldSubplot = oldSubplots[id];
var xaxis = Plotly.Axes.getFromId(mockGd, id, 'x');
var yaxis = Plotly.Axes.getFromId(mockGd, id, 'y');
var plotinfo;

if(oldSubplot) {
plotinfo = newSubplots[id] = oldSubplot;

if(plotinfo._scene2d) {
plotinfo._scene2d.updateRefs(newFullLayout);
}
}
else {

if(plotinfo.xaxis.layer !== xaxis.layer) {
plotinfo.xlines.attr('d', null);
plotinfo.xaxislayer.selectAll('*').remove();
}

if(plotinfo.yaxis.layer !== yaxis.layer) {
plotinfo.ylines.attr('d', null);
plotinfo.yaxislayer.selectAll('*').remove();
}
} else {
plotinfo = newSubplots[id] = {};
plotinfo.id = id;
}

plotinfo.xaxis = Plotly.Axes.getFromId(mockGd, id, 'x');
plotinfo.yaxis = Plotly.Axes.getFromId(mockGd, id, 'y');
plotinfo.xaxis = xaxis;
plotinfo.yaxis = yaxis;

// By default, we clip at the subplot level,
// but if one trace on a given subplot has *cliponaxis* set to false,
Expand Down
75 changes: 75 additions & 0 deletions test/jasmine/tests/cartesian_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -403,4 +403,79 @@ describe('subplot creation / deletion:', function() {
.catch(failTest)
.then(done);
});

it('should clear obsolete content out of axis layers when relayout\'ing *layer*', function(done) {
var fig = Lib.extendDeep({}, require('@mocks/overlaying-axis-lines.json'));

function assertPathDatum(sel, expected, msg) {
expect(sel.attr('d') === null ? false : true).toBe(expected, msg);
}

function assertChildrenCnt(sel, expected, msg) {
expect(sel.selectAll('*').size()).toBe(expected, msg);
}

function _assert(xBelow, yBelow, xAbove, yAbove) {
var g = d3.select('.subplot.xy');

assertPathDatum(g.select('.xlines-below'), xBelow[0], 'xlines below');
assertChildrenCnt(g.select('.xaxislayer-below'), xBelow[1], 'xaxislayer below');

assertPathDatum(g.select('.ylines-below'), yBelow[0], 'ylines below');
assertChildrenCnt(g.select('.yaxislayer-below'), yBelow[1], 'yaxislayer below');

assertPathDatum(g.select('.xlines-above'), xAbove[0], 'xlines above');
assertChildrenCnt(g.select('.xaxislayer-above'), xAbove[1], 'xaxislayer above');

assertPathDatum(g.select('.ylines-above'), yAbove[0], 'ylines above');
assertChildrenCnt(g.select('.yaxislayer-above'), yAbove[1], 'yaxislayer above');
}

Plotly.plot(gd, fig).then(function() {
_assert(
[false, 0],
[false, 0],
[true, 10],
[true, 10]
);
return Plotly.relayout(gd, 'xaxis.layer', 'below traces');
})
.then(function() {
_assert(
[true, 10],
[false, 0],
[false, 0],
[true, 10]
);
return Plotly.relayout(gd, 'yaxis.layer', 'below traces');
})
.then(function() {
_assert(
[true, 10],
[true, 10],
[false, 0],
[false, 0]
);
return Plotly.relayout(gd, { 'xaxis.layer': null, 'yaxis.layer': null });
})
.then(function() {
_assert(
[false, 0],
[false, 0],
[true, 10],
[true, 10]
);
return Plotly.relayout(gd, { 'xaxis.layer': 'below traces', 'yaxis.layer': 'below traces' });
})
.then(function() {
_assert(
[true, 10],
[true, 10],
[false, 0],
[false, 0]
);
})
.catch(failTest)
.then(done);
});
});
10 changes: 8 additions & 2 deletions test/jasmine/tests/plots_test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var Plotly = require('@lib/index');
var Plots = require('@src/plots/plots');
var Lib = require('@src/lib');

var d3 = require('d3');
var createGraphDiv = require('../assets/create_graph_div');
Expand Down Expand Up @@ -38,13 +39,18 @@ describe('Test Plots', function() {

var oldFullLayout = {
_plots: { xy: { plot: {} } },
xaxis: { c2p: function() {} },
yaxis: { _m: 20 },
xaxis: { c2p: function() {}, layer: 'above traces' },
yaxis: { _m: 20, layer: 'above traces' },
scene: { _scene: {} },
annotations: [{ _min: 10, }, { _max: 20 }],
someFunc: function() {}
};

Lib.extendFlat(oldFullLayout._plots.xy, {
xaxis: oldFullLayout.xaxis,
yaxis: oldFullLayout.yaxis
});

var newData = [{
type: 'scatter3d',
z: [1, 2, 3, 4]
Expand Down
0