-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Fixed size shapes #2532
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
Fixed size shapes #2532
Conversation
- Reason: prepare writing fixed size shape tests.
- Shapes (line, rect, circle as well as path) can now be sized by pixel while being positioned relative to data. - New shape attributes `xsizemode`, `xanchor`, `ysizemode` and `yanchor` introduced and semantics of `x0`, `x1`, `y0` and `y1` extended. - Shapes can be sized by pixel on one axis and sized by data on the other. - Fixed size shapes can be moved. - Fixed size lines, rectangles and circles can be resized, paths not. - Fixed size shapes are fully taken into account when an axis is in auto-range mode.
src/components/shapes/attributes.js
Outdated
xsizemode: { | ||
valType: 'enumerated', | ||
values: ['data', 'pixel'], | ||
dflt: 'data', |
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.
Ah, I hadn't thought of this before, but 'data'
mode applies not just to axis scaling but also plot fraction scaling, right? ie when xref='paper'
this option is still relevant, right? So how about we change 'data'
to 'scaled'
? That seems like it encompasses both cases and differentiates them from 'pixel'
sizing...
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.
Good point. I'll change that.
@rmoestl this is looking really great! I think there are enough new cases, re: axis vs paper referencing, autorange, and paths vs other shape types, that it deserves a new test image - similar to the shapes mock, so we can see that the autorange results are correct and the shapes are drawn as expected. That would also help me to try out the new dragging effects and see if our conclusion about edge vs center dragging really holds up 😄 |
- Note: not an exhaustive mock with all variations but rather a set of shapes covering the newly introduced capabilities, also useful for manually testing and debugging things.
The new test image is here: https://github.com/plotly/plotly.js/blob/fixed-size-shapes/test/image/baselines/fixed_size_shapes.png |
"config": { | ||
"editable": "true" | ||
} | ||
} |
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.
Very nice test image, and I think the interactions feel very natural as you have them. Other than adding a trailing newline to make the syntax test happy the only change I'd like to see is to use the other three axis types (log, date, category) on one axis each - no need to add more subplots, just convert a couple of the existing axes.
One thing I just noticed is the cursors start out wrong (at least in some cases) - the "top" cursor shows for most (or all!) of the shape, then after you cause a redraw (in the gif below I zoom in then double click to autorange again) the cursors look correct. I haven't looked to see if this is exclusive to pixel-sized shapes, nor if it's new with this PR... can you check it out @rmoestl ? |
I'll check out the cursor position thing. |
Re: drag cursors, unfortunately I was not yet able to reproduce this strange behavior. Looking at the code, the bounding box of the shape is obtained in Do you have some hints on how to reproduce the bug? I was testing in Chrome and FF by the way. Though I assume |
Thanks for the test image tweaks - love it! I figured out what the bug is - it's when you scroll the page after the plot draws (which I was doing naturally with your mock because it's fairly tall, whereas the original It's not new in this PR, but I think it has a simple solution so you might as well address it here. The issue is that |
- Bug revealed during review of #2193 - Bug: if a shape is not or not completely on screen at time of drag element setup, obtained bounding box would not be correct leading to the calculation of a wrong cursor once the shape scrolls into the viewport.
Wow, good catch!! |
Great, glad that's all it took! That bug fix may actually help performance too - ironically, since now we're calling I'm happy with this now, lets go! 💃 |
Thanks for this new feature! As a Python user, I understand that the |
@Juanlu001 ICYMI, online docs have been updated: https://plot.ly/javascript/reference/#layout-shapes |
This implements fixed size shapes specified in #2193. Please refer to the commit message for a rough overview of the feature.