Skip to content
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

Adding box plots drawn on std-deviation instead of quartiles #6698

Merged
merged 21 commits into from
Aug 18, 2023
Merged

Adding box plots drawn on std-deviation instead of quartiles #6698

merged 21 commits into from
Aug 18, 2023

Conversation

28raining
Copy link
Contributor

To help with this issue
#6697

I've made below changes, I've tried to keep the change to the minimum. Resulting image of new plot is in the issue

  • To box plot I've added a new boolean setting "whiskerdisable", which will turn of whiskers and whisker caps. Unfortunately whiskerwidth = 0 (existing setting) only turns off whisker caps
  • I added 6 new options to box -> boxmean setting, for 1 thru 6 sigma plots
  • On hover the annotation shows mean +- sigma for these new settings
  • Added new mock called box_3sigma

I also touched CONTRIBUTING.md because this instructions opens an empty webpage and it's really not obvious how to use it

Creating sizemode and sdmultiple to allow plots with any standard deviation, and a simpler cleaner codebase.
use 'showwhisker' insteadk of 'whiskerdisable'
adding .png to allow unit test to pass
hover annotation labels number of std deviations chosen
@28raining
Copy link
Contributor Author

Hi @alexcjohnson thank you for the feedback.

  • whiskerdisable renamed to showwhiskers. Mock test now includes with and without whiskers. Sometimes the box is larger than the data so the whisker draws inwards. Changing that behavior might have unintended side effects, and I don't think it looks too bad
  • whiskers now draw to the extreme points, not upper/lower fence
  • Stopped using boxmean and instead used sdmultiple and sizemode
  • Implemented in a way so that diamond plots (boxmeas='sd') are impacted by sdmultiple

@28raining
Copy link
Contributor Author

Hey @alexcjohnson. The baselines for Violin and Candlesticks were failing, because inside box/plot.js "trace.showwhiskers" was undefined.

I see your earlier comment and started using !== false. Thanks!

The remaining failing test is [webgl-jasmine], but seems unrelated to these changes

@archmoj archmoj added feature something new community community contribution status: reviewable labels Aug 16, 2023

sdmultiple: {
valType: 'number',
min: 0,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the minimum be one instead of zero?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if you want 0.5σ? Might be weird but I don't see a reason to prohibit it.

CONTRIBUTING.md Outdated
#### Step 6b: Create a mock to test new features
Create a new JSON inside
`test\image\mocks\`
which you'll then be able to search from the test dashboard
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In several cases adding new image tests are not necessary.
So this step should be optional and it could be part of Step 6.
You may revert changes in CONTRIBUTING.md and possibly submit a separate PR to suggest improvements as well.
Thank you!

@@ -286,7 +286,9 @@ module.exports = function calc(gd, trace) {
q1: _(gd, 'q1:'),
q3: _(gd, 'q3:'),
max: _(gd, 'max:'),
mean: trace.boxmean === 'sd' ? _(gd, 'mean ± σ:') : _(gd, 'mean:'),
mean: (trace.boxmean === 'sd') || (trace.sizemode === 'sd') ?
_(gd, 'mean ± σ:').replace('σ', trace.sdmultiple === 1 ? 'σ' : (trace.sdmultiple + 'σ')) : // displaying mean +- Nσ whilst supporting translations
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is getting too long.
How about adding agetMean(gd, trace) and move & revise this logic there?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Putting the code into a function would make the code less readable - if readability is the concern here.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree - if it's only going to be used here, extracting to a function just means it takes another jump to read and understand the code. @archmoj if your concern is just line length we can break this onto more lines. Or leave it for now and sometime add prettier to our toolchain like we have in various other projects 😉

src/traces/box/defaults.js Outdated Show resolved Hide resolved
@28raining
Copy link
Contributor Author

I've taken action on the comments

Copy link
Collaborator

@alexcjohnson alexcjohnson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💃 Looks good from my side - thanks @28raining!

@archmoj archmoj merged commit e38c18b into plotly:master Aug 18, 2023
1 check passed
@28raining
Copy link
Contributor Author

Wow, thanks everyone!

@28raining 28raining deleted the dev-box-sigma-boxes branch August 18, 2023 17:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community community contribution feature something new
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants