-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Implement notched box plots, closes #2286 #2305
Conversation
src/traces/box/defaults.js
Outdated
@@ -29,6 +29,9 @@ function supplyDefaults(traceIn, traceOut, defaultColor, layout) { | |||
coerce('whiskerwidth'); | |||
coerce('boxmean'); | |||
|
|||
var notched = coerce('notched'); | |||
if(notched) coerce('notchwidth'); |
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.
I wonder if we can get away with just a notchwidth
similar to how whiskers are set (with whiskerwidth
)?
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.
Are you suggesting to remove if(notched)
?
Btw. this line was modified after this comment: krassowski#1 (comment)
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.
Are you suggesting to remove if(notched)?
Yes, that's what I'm suggesting. Waiting on a concensus.
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.
I think @etpinard was suggesting removing the notched
attribute altogether and just defaulting to notchwidth=0
as no notch. I thought about this but would prefer the existing way so that we can pick a nice default notchwidth
rather than everyone making up random values. One thing we could do though is make the default for notched be true
if traceIn.notchwidth !== undefined
. That way if you do want a custom width you don’t also need to provide notched
.
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.
was suggesting removing the notched attribute altogether and just defaulting to notchwidth=0 as no notch
yes, this is what I meant. Sorry for the confusion.
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.
I thought about this but would prefer the existing way so that we can pick a nice default notchwidth rather than everyone making up random values
Good point here. I wonder if we should do the same for whiskers in v2? That is, adding a showwhiskers
boolean and making the whiskerswidth
default smarter?
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.
I wonder if we should do the same for whiskers in v2?
My argument doesn't really apply to whiskers - though I'm not sure I get what you mean by smarter default. If we're happy with the default whiskerwidth
staying at 0.5
then people can use 0
(a very non-random number 😄 ) to disable whiskers and any other number for a custom width.
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.
@krassowski in talking with @etpinard offline, we agreed that despite the correspondence with whiskerwidth
the Matlab convention makes more sense, to us anyway - so that's 0=no notch, 0.5=meet in the middle, with a default of 0.25.
And re: my comment:
One thing we could do though is make the default for notched be
true
iftraceIn.notchwidth !== undefined
.
That's just removing attributes.notched.dflt
and changing its coerce line to:
var notched = coerce('notched', traceIn.notchwidth !== undefined);
You'll also want to merge in the latest master so tests pass, then I think we're ready to go!
I deliberately removed `"notched":true` in one of test box traces so it is (indirectly) tested
src/traces/box/plot.js
Outdated
@@ -101,6 +101,8 @@ function plotBoxAndWhiskers(sel, axes, trace, t) { | |||
var wdPos = t.wdPos || 0; | |||
var bPosPxOffset = t.bPosPxOffset || 0; | |||
var whiskerWidth = trace.whiskerwidth || 0; | |||
var notched = trace.notched || false; | |||
var nw = notched ? 1 - trace.notchwidth : 1; |
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.
I think we're off by a factor of 2 here - 1 - 2 * trace.notchwidth
?
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.
So notchedwidth will accept a float from range (0, 0.5) instead of current (0, 1)?
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.
haha simultaneous comments :) yes.
src/traces/box/attributes.js
Outdated
notchwidth: { | ||
valType: 'number', | ||
min: 0, | ||
max: 1, |
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.
also in the matlab convention the max is 0.5
presumably for better consistency with Matlab
It seems that test "select box and lasso per trace" fails. I have no idea why. |
Seems to be a bad day for that test. You didn't break it, it's just glitchy. 💃 - once tests pass I'll merge this. Thanks for your work @krassowski! |
"name":"Notch width = 0.1", | ||
"notched":true, | ||
"orientation": "h", | ||
"notchwidth":0.1 |
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.
Actually looks like the mocks and baseline images got out of sync. This one uses 0.2 in both images.
https://6171-45646037-gh.circle-artifacts.com/0/home/ubuntu/plotly.js/build/test_images_diff/diff-box_notched.png
https://6171-45646037-gh.circle-artifacts.com/0/home/ubuntu/plotly.js/build/test_images_diff/diff-box_horz_notched.png
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.
You are right. I updated the baselines, hope that all will work this time.
I added a boolean option "notched" (default false) and a numerical "notchwidth" (default 0.25).
The options define if the box trace should be notched or not and if yes, determine the width of the notch (proportional to the width of the box).
I modified the svg path-generation code, utilizing conditional (ternary) operators so the common parts of the box (top & bottom edges for vertical, left & right edges for horizontal) are shared.
I added two test baselines:
box_notched
andbox_horz_notched
.Preliminary review was given by @alexcjohnson in my fork: krassowski#1.
Update: notch width behavior was changed to follow Matlab convention.
The previous version of this PR used the ggplot2 way.
Please let me know what you think.