-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Shape clean up #378
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
Shape clean up #378
Conversation
@n-riesco This looks like a solid plan! I like the way you cleaned up the shapes drawing step. Before moving on to the other 2 step, it would be nice add a few interaction tests for shapes. To do so,
|
Although I managed to move all the shapes into each subplot (at the correct positions), this has an undesired side effect: all the shapes that lie outside of a subplot aren't visible. I think this means the approach I was following isn't feasible. I'm considering an alternative approach: move @etpinard , what do you think? |
Could you elaborate? Do you mean all data-referenced shapes here? See this codepen id the distinction between data-refs and paper-ref isn't clear to you. |
I'm taking into account the effect of xref. You can see the implementation in this branch. I modified shapePath to account for xref. The way I understand the problem is that by moving the shapelayer into this svg, I'm clipping the shapelayer to the viewBox of that svg. |
Correct. This is the desired behavior for data-referenced shapes but not for paper-referenced annotations. Currently, data-referenced shapes are clipped using |
Just to be clear, we're now thinking of moving the shapelayer between these two lines? |
After looking through the requirements for issues #359 and #148 more closely, I think it is worth waiting a couple weeks before putting more work into them. Starting soon @mdtusz will remove the nested subplot This PR in its current states looks good. Were you planning on adding any other patches to it? If not, I'm thinking about merging it for the next release. |
I'm testing a PR that addresses #359 , but I can open another PR for it. |
For our future selves, here's a list of the approaches I tried:
|
Plotly.Lib.extendFlat({}, value) : | ||
{text: 'New text'}; | ||
updateShape(gd, index, opt, value); | ||
return; |
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.
no need for that return
. Save the bytes.
One more thing I almost forgot. I think here we're missing a |
@etpinard I've just removed the |
delete layout.shapes; | ||
fullLayout.shapes = []; | ||
shapes.drawAll(gd); | ||
deleteAllShapes(gd); |
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.
it would be nice add a few test cases for adding and removing shapes.
Here's the official way to add/remove shapes (and annotations for that matter): http://codepen.io/etpinard/pen/xVPoYG
* Removed call to `.remove()` in `shapes.drawAll()`, since `.remove()` is also call in `shapes.draw()`. * No new test failed after this change.
46ad23d
to
e9f91de
Compare
* Test whether Plotly.relayout() can add and remove shapes.
e9f91de
to
22d7248
Compare
|
||
Plotly.relayout(gd, 'shapes[' + index + ']', shape).then(function() { | ||
expect(getLastShape(gd)).toEqual(shape); | ||
expect(countShapes(gd)).toEqual(index + 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.
@n-riesco nice test. Thanks.
Could you also add an expect(countShapeLayers())
to make sure that the shapes are drawn correctly on relayout
?
* Count number of shape layers after relayout.
expect(getLastShape(gd)).toEqual(shape); | ||
expect(countShapes(gd)).toEqual(index + 1); | ||
}).then(function() { | ||
Plotly.relayout(gd, 'shapes[' + index + ']', 'remove'); | ||
}).then(function() { | ||
expect(countShapeLayers()).toEqual(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.
Oops. My bad. I meant expect(countShapeLayerPaths())
.
But testing expect(countShapeLayers())
isn't bad either. test 🐅 🐅
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.
Oh... that makes sense. I should've guessed you meant that.
* Count the number of paths in the shape layer after relayout.
expect(getLastShape(gd)).toEqual(shape); | ||
expect(countShapes(gd)).toEqual(index + 1); | ||
}).then(function() { | ||
Plotly.relayout(gd, 'shapes[' + index + ']', 'remove'); | ||
}).then(function() { | ||
expect(countShapeLayers()).toEqual(1); | ||
expect(countShapePaths()).toEqual(pathCount); |
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.
🎉
Great job @n-riesco 🍻 |
Here's an outline of the plan I'm following to fix issues #359 and #148:
shapes.draw
into smaller functionsshapelayer
into functionplotLayers
inmakeCartesianPlotFramwork
(this fixes Zoom overlay drawn beneath shapes. #359)shapelayer
intoshapeLowerLayer
andshapeUpperLayer
(this fixes Drawing traces on top of shapes #148)I've checked refactoring
shapes.draw
hasn't introduced new bugs by running both the image and the jasmine tests.