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

Skip to content

Implement scatter cliponaxis: false #1824

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

Closed
wants to merge 10 commits into from
Prev Previous commit
add / update jasmine test for cliponaxis: false behavior
  • Loading branch information
etpinard committed Jun 27, 2017
commit 1152d19f8a34eeec7d4119c8663e7e9cf2418edf
4 changes: 2 additions & 2 deletions test/jasmine/tests/plot_interact_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ describe('Test plot structure', function() {
expect(countDraggers()).toEqual(1);
});

it('has one *scatterlayer* node', function() {
it('has two *scatterlayer* node (one clipped, one non-clipped)', function() {
var nodes = d3.selectAll('g.scatterlayer');
expect(nodes.size()).toEqual(1);
expect(nodes.size()).toEqual(2);
});

it('has as many *trace scatter* nodes as there are traces', function() {
Expand Down
64 changes: 64 additions & 0 deletions test/jasmine/tests/scatter_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -670,3 +670,67 @@ describe('scatter hoverPoints', function() {
.then(done);
});
});

describe('Test scatter *clipnaxis*', function() {
afterEach(destroyGraphDiv);

it('should show/hide point/text/errorbars in clipped and non-clipped layers', function(done) {
var gd = createGraphDiv();
var fig = Lib.extendDeep({}, require('@mocks/cliponaxis_false.json'));
var xRange0 = fig.layout.xaxis.range.slice();
var yRange0 = fig.layout.yaxis.range.slice();

function assertVisible(cnt, cntNoClip, msg) {
var selectors = ['.point', '.textpoint', '.yerror', '.xerror'];
var scatterLayer = d3.select('.plot > .scatterlayer');
var scatterLayerNoClip = d3.select('.plotnoclip > .scatterlayer');

selectors.forEach(function(s) {
expect(scatterLayer.selectAll(s).size())
.toBe(cnt, s + ' ' + msg);
expect(scatterLayerNoClip.selectAll(s).size())
.toBe(cntNoClip, s + ' (noclip) ' + msg);
});
}

Plotly.plot(gd, fig)
.then(function() {
assertVisible(0, 6, 'cliponaxis:false');
return Plotly.restyle(gd, 'visible', false);
})
.then(function() {
assertVisible(0, 0, 'visible:false');
return Plotly.restyle(gd, {visible: true, cliponaxis: null});
})
.then(function() {
assertVisible(6, 0, 'cliponaxis:dflt');
return Plotly.restyle(gd, 'visible', 'legendonly');
})
.then(function() {
assertVisible(0, 0, 'visible:legendonly');
return Plotly.restyle(gd, 'visible', true);
})
.then(function() {
assertVisible(6, 0, 'back to clipnaxis:dflt');
return Plotly.restyle(gd, 'cliponaxis', false);
})
.then(function() {
assertVisible(0, 6, 'back to cliponaxis:false');
return Plotly.relayout(gd, 'xaxis.range', [0, 1]);
})
.then(function() {
assertVisible(0, 2, 'smaller x-range');
return Plotly.relayout(gd, 'yaxis.range', [0, 1]);
})
.then(function() {
assertVisible(0, 1, 'smaller y-range');
return Plotly.relayout(gd, {'xaxis.range': xRange0, 'yaxis.range': yRange0});
})
.then(function() {
assertVisible(0, 6, 'back to original xy ranges');
})
.catch(fail)
.then(done);
});

});
62 changes: 62 additions & 0 deletions test/jasmine/tests/scatterternary_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var ScatterTernary = require('@src/traces/scatterternary');
var d3 = require('d3');
var createGraphDiv = require('../assets/create_graph_div');
var destroyGraphDiv = require('../assets/destroy_graph_div');
var fail = require('../assets/fail_test');
var customMatchers = require('../assets/custom_matchers');


Expand Down Expand Up @@ -374,3 +375,64 @@ describe('scatterternary hover', function() {
});

});

describe('Test scatterternary *cliponaxis*', function() {
afterEach(destroyGraphDiv);

it('should show/hide point/text/errorbars in clipped and non-clipped layers', function(done) {
var gd = createGraphDiv();
var fig = Lib.extendDeep({}, require('@mocks/ternary_markers.json'));

function assertVisible(cnt, cntNoClip, msg) {
var selectors = ['.point', '.textpoint'];
var scatterLayer = d3.select('.frontplot > .scatterlayer');
var scatterLayerNoClip = d3.select('.frontplotnoclip > .scatterlayer');

selectors.forEach(function(s) {
expect(scatterLayer.selectAll(s).size())
.toBe(cnt, s + ' ' + msg);
expect(scatterLayerNoClip.selectAll(s).size())
.toBe(cntNoClip, s + ' (noclip) ' + msg);
});
}

Plotly.plot(gd, fig)
.then(function() {
assertVisible(0, 11, 'cliponaxis:false');
return Plotly.restyle(gd, 'visible', false);
})
.then(function() {
assertVisible(0, 0, 'visible:false');
return Plotly.restyle(gd, {visible: true, cliponaxis: null});
})
.then(function() {
assertVisible(11, 0, 'cliponaxis:dflt');
return Plotly.restyle(gd, 'cliponaxis', false);
})
.then(function() {
assertVisible(0, 11, 'back to cliponaxis:false');
return Plotly.relayout(gd, 'ternary.aaxis.min', 20);
})
.then(function() {
assertVisible(0, 5, 'zoomed about a-axis');
return Plotly.relayout(gd, 'ternary.baxis.min', 20);
})
.then(function() {
assertVisible(0, 3, 'zoomed about b-axis');
return Plotly.relayout(gd, 'ternary.caxis.min', 10);
})
.then(function() {
assertVisible(0, 1, 'zoomed about c-axis');
return Plotly.relayout(gd, {
'ternary.aaxis.min': null,
'ternary.baxis.min': null,
'ternary.caxis.min': null
});
})
.then(function() {
assertVisible(0, 11, 'back to original view');
})
.catch(fail)
.then(done);
});
});
0