-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Fix box & violin inner parts removal #2785
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
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
611581c
sub fail -> failTest
etpinard 47349c7
fix box line/pts removal
etpinard 4e48cd7
fix violin box/meanline/pts removal
etpinard b2a55f6
fixup new box.plot logic for candlestick
etpinard 1e4900c
cleanup logic for data-bind fn / fallback to []
etpinard File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,18 +73,9 @@ function plot(gd, plotinfo, cdbox, boxLayer) { | |
// always split the distance to the closest box | ||
t.wHover = t.dPos * (group ? groupFraction / numBoxes : 1); | ||
|
||
// boxes and whiskers | ||
plotBoxAndWhiskers(sel, {pos: posAxis, val: valAxis}, trace, t); | ||
|
||
// draw points, if desired | ||
if(trace.boxpoints) { | ||
plotPoints(sel, {x: xa, y: ya}, trace, t); | ||
} | ||
|
||
// draw mean (and stdev diamond) if desired | ||
if(trace.boxmean) { | ||
plotBoxMean(sel, {pos: posAxis, val: valAxis}, trace, t); | ||
} | ||
plotPoints(sel, {x: xa, y: ya}, trace, t); | ||
plotBoxMean(sel, {pos: posAxis, val: valAxis}, trace, t); | ||
}); | ||
} | ||
|
||
|
@@ -109,7 +100,15 @@ function plotBoxAndWhiskers(sel, axes, trace, t) { | |
bdPos1 = t.bdPos; | ||
} | ||
|
||
var paths = sel.selectAll('path.box').data(Lib.identity); | ||
var fn; | ||
if(trace.type === 'box' || | ||
trace.type === 'candlestick' || | ||
(trace.type === 'violin' && (trace.box || {}).visible) | ||
) { | ||
fn = Lib.identity; | ||
} | ||
|
||
var paths = sel.selectAll('path.box').data(fn || []); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like this pattern! But two comments about it:
var fn;
if(...) fn = Lib.identity;
else fn = []; // or just var fn = []; and drop the else, dunno which is better
var paths = sel.selectAll('path.box').data(fn); |
||
|
||
paths.enter().append('path') | ||
.style('vector-effect', 'non-scaling-stroke') | ||
|
@@ -187,16 +186,18 @@ function plotPoints(sel, axes, trace, t) { | |
// repeatable pseudo-random number generator | ||
Lib.seedPseudoRandom(); | ||
|
||
var gPoints = sel.selectAll('g.points') | ||
// since box plot points get an extra level of nesting, each | ||
// box needs the trace styling info | ||
.data(function(d) { | ||
d.forEach(function(v) { | ||
v.t = t; | ||
v.trace = trace; | ||
}); | ||
return d; | ||
// since box plot points get an extra level of nesting, each | ||
// box needs the trace styling info | ||
var fn = function(d) { | ||
d.forEach(function(v) { | ||
v.t = t; | ||
v.trace = trace; | ||
}); | ||
return d; | ||
}; | ||
|
||
var gPoints = sel.selectAll('g.points') | ||
.data(mode ? fn : []); | ||
|
||
gPoints.enter().append('g') | ||
.attr('class', 'points'); | ||
|
@@ -292,6 +293,9 @@ function plotBoxMean(sel, axes, trace, t) { | |
var bPos = t.bPos; | ||
var bPosPxOffset = t.bPosPxOffset || 0; | ||
|
||
// to support violin mean lines | ||
var mode = trace.boxmean || (trace.meanline || {}).visible; | ||
|
||
// to support for one-sided box | ||
var bdPos0; | ||
var bdPos1; | ||
|
@@ -303,7 +307,14 @@ function plotBoxMean(sel, axes, trace, t) { | |
bdPos1 = t.bdPos; | ||
} | ||
|
||
var paths = sel.selectAll('path.mean').data(Lib.identity); | ||
var fn; | ||
if(trace.type === 'box' && trace.boxmean || | ||
(trace.type === 'violin' && (trace.box || {}).visible && (trace.meanline || {}).visible) | ||
) { | ||
fn = Lib.identity; | ||
} | ||
|
||
var paths = sel.selectAll('path.mean').data(fn || []); | ||
|
||
paths.enter().append('path') | ||
.attr('class', 'mean') | ||
|
@@ -325,14 +336,14 @@ function plotBoxMean(sel, axes, trace, t) { | |
if(trace.orientation === 'h') { | ||
d3.select(this).attr('d', | ||
'M' + m + ',' + pos0 + 'V' + pos1 + | ||
(trace.boxmean === 'sd' ? | ||
(mode === 'sd' ? | ||
'm0,0L' + sl + ',' + posc + 'L' + m + ',' + pos0 + 'L' + sh + ',' + posc + 'Z' : | ||
'') | ||
); | ||
} else { | ||
d3.select(this).attr('d', | ||
'M' + pos0 + ',' + m + 'H' + pos1 + | ||
(trace.boxmean === 'sd' ? | ||
(mode === 'sd' ? | ||
'm0,0L' + posc + ',' + sl + 'L' + pos0 + ',' + m + 'L' + posc + ',' + sh + 'Z' : | ||
'') | ||
); | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps
trace.type !== 'violin' || trace.box
? NBD either way, we'd of course figure it out pretty quick if we add any other trace type that reuses box drawing.