Skip to content

Commit 89ee533

Browse files
committed
add scatter and scatterternary cliponaxis tests
1 parent fe1f889 commit 89ee533

File tree

3 files changed

+273
-0
lines changed

3 files changed

+273
-0
lines changed

test/jasmine/assets/custom_assertions.js

+27
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,30 @@ exports.assertStyle = function(dims, color, opacity) {
4646
});
4747
});
4848
};
49+
50+
exports.assertClip = function(sel, isClipped, size, msg) {
51+
expect(sel.size()).toBe(size, msg + ' clip path (selection size)');
52+
53+
sel.each(function(d, i) {
54+
var clipPath = d3.select(this).attr('clip-path');
55+
56+
if(isClipped) {
57+
expect(String(clipPath).substr(0, 4))
58+
.toBe('url(', msg + ' clip path ' + '(item ' + i + ')');
59+
} else {
60+
expect(clipPath)
61+
.toBe(null, msg + ' clip path ' + '(item ' + i + ')');
62+
}
63+
});
64+
65+
};
66+
67+
exports.assertNodeVisibility = function(sel, expectation, msg) {
68+
expect(sel.size())
69+
.toBe(expectation.length, msg + ' visibility (selection size)');
70+
71+
sel.each(function(d, i) {
72+
expect(d3.select(this).attr('visibility'))
73+
.toBe(expectation[i], msg + ' visibility ' + '(item ' + i + ')');
74+
});
75+
};

test/jasmine/tests/scatter_test.js

+137
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@ var Plotly = require('@lib/index');
88
var createGraphDiv = require('../assets/create_graph_div');
99
var destroyGraphDiv = require('../assets/destroy_graph_div');
1010
var customMatchers = require('../assets/custom_matchers');
11+
var customAssertions = require('../assets/custom_assertions');
1112
var fail = require('../assets/fail_test');
1213

14+
var assertClip = customAssertions.assertClip;
15+
var assertNodeVisibility = customAssertions.assertNodeVisibility;
16+
1317
describe('Test scatter', function() {
1418
'use strict';
1519

@@ -670,3 +674,136 @@ describe('scatter hoverPoints', function() {
670674
.then(done);
671675
});
672676
});
677+
678+
describe('Test scatter *clipnaxis*', function() {
679+
afterEach(destroyGraphDiv);
680+
681+
it('should show/hide point/text/errorbars in clipped and non-clipped layers', function(done) {
682+
var gd = createGraphDiv();
683+
var fig = Lib.extendDeep({}, require('@mocks/cliponaxis_false.json'));
684+
var xRange0 = fig.layout.xaxis.range.slice();
685+
var yRange0 = fig.layout.yaxis.range.slice();
686+
687+
// only show *cliponaxis: false* trace
688+
fig.data = [fig.data[2]];
689+
690+
// add lines
691+
fig.data[0].mode = 'markers+lines+text';
692+
693+
function _assert(layerClips, nodeVisibilities, errorBarClips, lineClips) {
694+
var subplotLayer = d3.select('.plot');
695+
var scatterLayer = subplotLayer.select('.scatterlayer');
696+
697+
assertClip(subplotLayer, layerClips[0], 1, 'subplot layer');
698+
assertClip(subplotLayer.select('.barlayer'), layerClips[1], 1, 'bar layer');
699+
assertClip(scatterLayer, layerClips[2], 1, 'scatter layer');
700+
701+
assertNodeVisibility(
702+
scatterLayer.selectAll('.point'),
703+
nodeVisibilities,
704+
'scatter points'
705+
);
706+
assertNodeVisibility(
707+
scatterLayer.selectAll('.textpoint'),
708+
nodeVisibilities,
709+
'scatter text points'
710+
);
711+
712+
assertClip(
713+
scatterLayer.selectAll('.errorbar'),
714+
errorBarClips[0], errorBarClips[1],
715+
'error bars'
716+
);
717+
assertClip(
718+
scatterLayer.selectAll('.js-line'),
719+
lineClips[0], lineClips[1],
720+
'line clips'
721+
);
722+
}
723+
724+
Plotly.plot(gd, fig)
725+
.then(function() {
726+
_assert(
727+
[false, true, false],
728+
[null, null, null, null, null, null],
729+
[true, 6],
730+
[true, 1]
731+
);
732+
return Plotly.restyle(gd, 'visible', false);
733+
})
734+
.then(function() {
735+
_assert(
736+
[true, false, false],
737+
[],
738+
[false, 0],
739+
[false, 0]
740+
);
741+
return Plotly.restyle(gd, {visible: true, cliponaxis: null});
742+
})
743+
.then(function() {
744+
_assert(
745+
[true, false, false],
746+
[null, null, null, null, null, null],
747+
[false, 6],
748+
[false, 1]
749+
);
750+
return Plotly.restyle(gd, 'visible', 'legendonly');
751+
})
752+
.then(function() {
753+
_assert(
754+
[true, false, false],
755+
[],
756+
[false, 0],
757+
[false, 0]
758+
);
759+
return Plotly.restyle(gd, 'visible', true);
760+
})
761+
.then(function() {
762+
_assert(
763+
[true, false, false],
764+
[null, null, null, null, null, null],
765+
[false, 6],
766+
[false, 1]
767+
);
768+
return Plotly.restyle(gd, 'cliponaxis', false);
769+
})
770+
.then(function() {
771+
_assert(
772+
[false, true, false],
773+
[null, null, null, null, null, null],
774+
[true, 6],
775+
[true, 1]
776+
);
777+
return Plotly.relayout(gd, 'xaxis.range', [0, 1]);
778+
})
779+
.then(function() {
780+
_assert(
781+
[false, true, false],
782+
[null, null, 'hidden', 'hidden', 'hidden', 'hidden'],
783+
[true, 6],
784+
[true, 1]
785+
);
786+
return Plotly.relayout(gd, 'yaxis.range', [0, 1]);
787+
})
788+
.then(function() {
789+
_assert(
790+
[false, true, false],
791+
['hidden', null, 'hidden', 'hidden', 'hidden', 'hidden'],
792+
[true, 6],
793+
[true, 1]
794+
);
795+
return Plotly.relayout(gd, {'xaxis.range': xRange0, 'yaxis.range': yRange0});
796+
})
797+
.then(function() {
798+
_assert(
799+
[false, true, false],
800+
[null, null, null, null, null, null],
801+
[true, 6],
802+
[true, 1]
803+
);
804+
})
805+
.catch(fail)
806+
.then(done);
807+
});
808+
809+
});

test/jasmine/tests/scatterternary_test.js

+109
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@ var ScatterTernary = require('@src/traces/scatterternary');
66
var d3 = require('d3');
77
var createGraphDiv = require('../assets/create_graph_div');
88
var destroyGraphDiv = require('../assets/destroy_graph_div');
9+
var fail = require('../assets/fail_test');
910
var customMatchers = require('../assets/custom_matchers');
11+
var customAssertions = require('../assets/custom_assertions');
1012

13+
var assertClip = customAssertions.assertClip;
14+
var assertNodeVisibility = customAssertions.assertNodeVisibility;
1115

1216
describe('scatterternary defaults', function() {
1317
'use strict';
@@ -374,3 +378,108 @@ describe('scatterternary hover', function() {
374378
});
375379

376380
});
381+
382+
describe('Test scatterternary *cliponaxis*', function() {
383+
afterEach(destroyGraphDiv);
384+
385+
it('should show/hide point/text/errorbars in clipped and non-clipped layers', function(done) {
386+
var gd = createGraphDiv();
387+
var fig = Lib.extendDeep({}, require('@mocks/ternary_markers.json'));
388+
389+
function _assert(layerClips, nodeVisibilities, lineClips) {
390+
var frontLayer = d3.select('.frontplot');
391+
var scatterLayer = d3.select('.scatterlayer');
392+
393+
assertClip(frontLayer, layerClips[0], 1, 'front layer');
394+
assertClip(scatterLayer, layerClips[1], 1, 'scatter layer');
395+
396+
assertNodeVisibility(
397+
scatterLayer.selectAll('.point'),
398+
nodeVisibilities,
399+
'scatter points'
400+
);
401+
assertNodeVisibility(
402+
scatterLayer.selectAll('.textpoint'),
403+
nodeVisibilities,
404+
'scatter text points'
405+
);
406+
407+
assertClip(
408+
scatterLayer.selectAll('.js-line'),
409+
lineClips[0], lineClips[1],
410+
'line clips'
411+
);
412+
}
413+
414+
Plotly.plot(gd, fig)
415+
.then(function() {
416+
_assert(
417+
[false, false],
418+
[null, 'hidden', null, null, null, null, null, null, 'hidden', 'hidden', 'hidden'],
419+
[true, 1]
420+
);
421+
return Plotly.restyle(gd, 'visible', 'legendonly');
422+
})
423+
.then(function() {
424+
_assert(
425+
[false, false],
426+
[],
427+
[false, 0]
428+
);
429+
return Plotly.restyle(gd, {visible: true, cliponaxis: null});
430+
})
431+
.then(function() {
432+
_assert(
433+
[true, false],
434+
[null, null, null, null, null, null, null, null, null, null, null],
435+
[false, 1]
436+
);
437+
return Plotly.restyle(gd, 'cliponaxis', false);
438+
})
439+
.then(function() {
440+
_assert(
441+
[false, false],
442+
[null, 'hidden', null, null, null, null, null, null, 'hidden', 'hidden', 'hidden'],
443+
[true, 1]
444+
);
445+
return Plotly.relayout(gd, 'ternary.aaxis.min', 20);
446+
})
447+
.then(function() {
448+
_assert(
449+
[false, false],
450+
[null, 'hidden', null, 'hidden', 'hidden', 'hidden', null, 'hidden', 'hidden', 'hidden', 'hidden'],
451+
[true, 1]
452+
);
453+
return Plotly.relayout(gd, 'ternary.baxis.min', 40);
454+
})
455+
.then(function() {
456+
_assert(
457+
[false, false],
458+
['hidden', 'hidden', 'hidden', 'hidden', 'hidden', 'hidden', null, 'hidden', 'hidden', 'hidden', 'hidden'],
459+
[true, 1]
460+
);
461+
return Plotly.relayout(gd, 'ternary.caxis.min', 30);
462+
})
463+
.then(function() {
464+
_assert(
465+
[false, false],
466+
['hidden', 'hidden', 'hidden', 'hidden', 'hidden', 'hidden', 'hidden', 'hidden', 'hidden', 'hidden', 'hidden'],
467+
[true, 1]
468+
);
469+
return Plotly.relayout(gd, {
470+
'ternary.aaxis.min': null,
471+
'ternary.baxis.min': null,
472+
'ternary.caxis.min': null
473+
});
474+
})
475+
.then(function() {
476+
_assert(
477+
[false, false],
478+
[null, null, null, null, null, null, null, null, null, null, null],
479+
[true, 1]
480+
);
481+
})
482+
.catch(fail)
483+
.then(done);
484+
});
485+
});

0 commit comments

Comments
 (0)