Skip to content

Commit 47349c7

Browse files
committed
fix box line/pts removal
1 parent 611581c commit 47349c7

File tree

2 files changed

+57
-2
lines changed

2 files changed

+57
-2
lines changed

src/traces/box/plot.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,9 @@ function plotBoxMean(sel, axes, trace, t) {
292292
var bPos = t.bPos;
293293
var bPosPxOffset = t.bPosPxOffset || 0;
294294

295+
// to support violin mean lines
296+
var mode = trace.boxmean || (trace.meanline || {}).visible;
297+
295298
// to support for one-sided box
296299
var bdPos0;
297300
var bdPos1;
@@ -325,14 +328,14 @@ function plotBoxMean(sel, axes, trace, t) {
325328
if(trace.orientation === 'h') {
326329
d3.select(this).attr('d',
327330
'M' + m + ',' + pos0 + 'V' + pos1 +
328-
(trace.boxmean === 'sd' ?
331+
(mode === 'sd' ?
329332
'm0,0L' + sl + ',' + posc + 'L' + m + ',' + pos0 + 'L' + sh + ',' + posc + 'Z' :
330333
'')
331334
);
332335
} else {
333336
d3.select(this).attr('d',
334337
'M' + pos0 + ',' + m + 'H' + pos1 +
335-
(trace.boxmean === 'sd' ?
338+
(mode === 'sd' ?
336339
'm0,0L' + posc + ',' + sl + 'L' + pos0 + ',' + m + 'L' + posc + ',' + sh + 'Z' :
337340
'')
338341
);

test/jasmine/tests/box_test.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ var Lib = require('@src/lib');
33

44
var Box = require('@src/traces/box');
55

6+
var d3 = require('d3');
67
var createGraphDiv = require('../assets/create_graph_div');
78
var destroyGraphDiv = require('../assets/destroy_graph_div');
89
var failTest = require('../assets/fail_test');
@@ -348,3 +349,54 @@ describe('Box edge cases', function() {
348349
.then(done);
349350
});
350351
});
352+
353+
describe('Test box restyle:', function() {
354+
var gd;
355+
356+
beforeEach(function() {
357+
gd = createGraphDiv();
358+
});
359+
360+
afterEach(destroyGraphDiv);
361+
362+
it('should be able to add/remove innner parts', function(done) {
363+
var fig = Lib.extendDeep({}, require('@mocks/box_plot_jitter.json'));
364+
// start with just 1 box
365+
delete fig.data[0].boxpoints;
366+
367+
function _assertOne(msg, exp, trace3, k, query) {
368+
expect(trace3.selectAll(query).size())
369+
.toBe(exp[k] || 0, k + ' - ' + msg);
370+
}
371+
372+
function _assert(msg, exp) {
373+
var trace3 = d3.select(gd).select('.boxlayer > .trace');
374+
_assertOne(msg, exp, trace3, 'boxCnt', 'path.box');
375+
_assertOne(msg, exp, trace3, 'meanlineCnt', 'path.mean');
376+
_assertOne(msg, exp, trace3, 'ptsCnt', 'path.point');
377+
}
378+
379+
Plotly.plot(gd, fig)
380+
.then(function() {
381+
_assert('base', {boxCnt: 1});
382+
})
383+
.then(function() { return Plotly.restyle(gd, 'boxmean', true); })
384+
.then(function() {
385+
_assert('with meanline', {boxCnt: 1, meanlineCnt: 1});
386+
})
387+
.then(function() { return Plotly.restyle(gd, 'boxmean', 'sd'); })
388+
.then(function() {
389+
_assert('with mean+sd line', {boxCnt: 1, meanlineCnt: 1});
390+
})
391+
.then(function() { return Plotly.restyle(gd, 'boxpoints', 'all'); })
392+
.then(function() {
393+
_assert('with mean+sd line + pts', {boxCnt: 1, meanlineCnt: 1, ptsCnt: 9});
394+
})
395+
.then(function() { return Plotly.restyle(gd, 'boxmean', false); })
396+
.then(function() {
397+
_assert('with pts', {boxCnt: 1, ptsCnt: 9});
398+
})
399+
.catch(failTest)
400+
.then(done);
401+
});
402+
});

0 commit comments

Comments
 (0)