Skip to content

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

Merged
merged 5 commits into from
Apr 7, 2016
Merged

Shape clean up #378

merged 5 commits into from
Apr 7, 2016

Conversation

n-riesco
Copy link
Contributor

@n-riesco n-riesco commented Apr 1, 2016

Here's an outline of the plan I'm following to fix issues #359 and #148:

I've checked refactoring shapes.drawhasn't introduced new bugs by running both the image and the jasmine tests.

@etpinard
Copy link
Contributor

etpinard commented Apr 1, 2016

@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,

  • add a shapes_test.js file in test/jasmine/tests/
  • add a suite similar to this one using the shapes.json mock.
  • assert the shape nodes in the right place after Plotly.relayout

@n-riesco n-riesco mentioned this pull request Apr 2, 2016
3 tasks
@n-riesco
Copy link
Contributor Author

n-riesco commented Apr 4, 2016

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 shapelayer, zoombox and zoombox-corners outside plotinfo.plot.

@etpinard , what do you think?

@etpinard
Copy link
Contributor

etpinard commented Apr 4, 2016

this has an undesired side effect: all the shapes that lie outside of a subplot aren't visible.

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.

@n-riesco
Copy link
Contributor Author

n-riesco commented Apr 4, 2016

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.

@etpinard
Copy link
Contributor

etpinard commented Apr 4, 2016

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 <svg> clip paths here. We should be able to use the same pattern in the case where the <g class="shapelayer"> is below the plotinfo.plot layer.

@n-riesco
Copy link
Contributor Author

n-riesco commented Apr 4, 2016

Just to be clear, we're now thinking of moving the shapelayer between these two lines?

@etpinard
Copy link
Contributor

etpinard commented Apr 5, 2016

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 <svg> in favor of clipPath. Those nested <svg> have been plaguing us for quite some time now. Among others, Abobe illustrator and RStudio don't like them. Moreover, without the nested <svg>s, a lot of the shape layer ordering logic should be simplified.

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.

@n-riesco
Copy link
Contributor Author

n-riesco commented Apr 5, 2016

I'm testing a PR that addresses #359 , but I can open another PR for it.

@n-riesco
Copy link
Contributor Author

n-riesco commented Apr 6, 2016

Plotly.Lib.extendFlat({}, value) :
{text: 'New text'};
updateShape(gd, index, opt, value);
return;
Copy link
Contributor

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.

@etpinard etpinard changed the title [WIP] Fix issues #359 and #148 Shape clean up Apr 6, 2016
@n-riesco
Copy link
Contributor Author

n-riesco commented Apr 6, 2016

One more thing I almost forgot. I think here we're missing a layout.shapes.push({});. This may explain this failure.

@n-riesco
Copy link
Contributor Author

n-riesco commented Apr 6, 2016

@etpinard I've just removed the returns.

delete layout.shapes;
fullLayout.shapes = [];
shapes.drawAll(gd);
deleteAllShapes(gd);
Copy link
Contributor

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

n-riesco added 2 commits April 6, 2016 23:40
* Removed call to `.remove()` in `shapes.drawAll()`, since `.remove()`
  is also call in `shapes.draw()`.

* No new test failed after this change.
@n-riesco n-riesco force-pushed the issue-148-and-359 branch from 46ad23d to e9f91de Compare April 6, 2016 22:48
* Test whether Plotly.relayout() can add and remove shapes.
@n-riesco n-riesco force-pushed the issue-148-and-359 branch from e9f91de to 22d7248 Compare April 6, 2016 23:16

Plotly.relayout(gd, 'shapes[' + index + ']', shape).then(function() {
expect(getLastShape(gd)).toEqual(shape);
expect(countShapes(gd)).toEqual(index + 1);
Copy link
Contributor

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);
Copy link
Contributor

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 🐅 🐅

Copy link
Contributor Author

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);
Copy link
Contributor

Choose a reason for hiding this comment

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

🎉

@etpinard
Copy link
Contributor

etpinard commented Apr 7, 2016

Great job @n-riesco 🍻

@etpinard etpinard merged commit e8fc236 into plotly:master Apr 7, 2016
@n-riesco n-riesco deleted the issue-148-and-359 branch April 15, 2016 12:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Zoom overlay drawn beneath shapes. Drawing traces on top of shapes
2 participants