-
-
Couldn't load subscription status.
- Fork 1.9k
Fix shapes and images referencing a missing subplot #1481
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
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -103,75 +103,75 @@ describe('Test shapes defaults:', function() { | |
| }); | ||
| }); | ||
|
|
||
| describe('Test shapes:', function() { | ||
| 'use strict'; | ||
| function countShapesInLowerLayer(gd) { | ||
| return gd._fullLayout.shapes.filter(isShapeInLowerLayer).length; | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved these helpers to the root level so I could use them in a different |
||
|
|
||
| var mock = require('@mocks/shapes.json'); | ||
| var gd; | ||
| function countShapesInUpperLayer(gd) { | ||
| return gd._fullLayout.shapes.filter(isShapeInUpperLayer).length; | ||
| } | ||
|
|
||
| beforeEach(function(done) { | ||
| gd = createGraphDiv(); | ||
| function countShapesInSubplots(gd) { | ||
| return gd._fullLayout.shapes.filter(isShapeInSubplot).length; | ||
| } | ||
|
|
||
| var mockData = Lib.extendDeep([], mock.data), | ||
| mockLayout = Lib.extendDeep({}, mock.layout); | ||
| function isShapeInUpperLayer(shape) { | ||
| return shape.layer !== 'below'; | ||
| } | ||
|
|
||
| Plotly.plot(gd, mockData, mockLayout).then(done); | ||
| }); | ||
| function isShapeInLowerLayer(shape) { | ||
| return (shape.xref === 'paper' && shape.yref === 'paper') && | ||
| !isShapeInUpperLayer(shape); | ||
| } | ||
|
|
||
| afterEach(destroyGraphDiv); | ||
| function isShapeInSubplot(shape) { | ||
| return !isShapeInUpperLayer(shape) && !isShapeInLowerLayer(shape); | ||
| } | ||
|
|
||
| function countShapesInLowerLayer() { | ||
| return gd._fullLayout.shapes.filter(isShapeInLowerLayer).length; | ||
| } | ||
| function countShapeLowerLayerNodes() { | ||
| return d3.selectAll('.layer-below > .shapelayer').size(); | ||
| } | ||
|
|
||
| function countShapesInUpperLayer() { | ||
| return gd._fullLayout.shapes.filter(isShapeInUpperLayer).length; | ||
| } | ||
| function countShapeUpperLayerNodes() { | ||
| return d3.selectAll('.layer-above > .shapelayer').size(); | ||
| } | ||
|
|
||
| function countShapesInSubplots() { | ||
| return gd._fullLayout.shapes.filter(isShapeInSubplot).length; | ||
| } | ||
| function countShapeLayerNodesInSubplots() { | ||
| return d3.selectAll('.layer-subplot').size(); | ||
| } | ||
|
|
||
| function isShapeInUpperLayer(shape) { | ||
| return shape.layer !== 'below'; | ||
| } | ||
| function countSubplots(gd) { | ||
| return Object.keys(gd._fullLayout._plots || {}).length; | ||
| } | ||
|
|
||
| function isShapeInLowerLayer(shape) { | ||
| return (shape.xref === 'paper' && shape.yref === 'paper') && | ||
| !isShapeInUpperLayer(shape); | ||
| } | ||
| function countShapePathsInLowerLayer() { | ||
| return d3.selectAll('.layer-below > .shapelayer > path').size(); | ||
| } | ||
|
|
||
| function isShapeInSubplot(shape) { | ||
| return !isShapeInUpperLayer(shape) && !isShapeInLowerLayer(shape); | ||
| } | ||
| function countShapePathsInUpperLayer() { | ||
| return d3.selectAll('.layer-above > .shapelayer > path').size(); | ||
| } | ||
|
|
||
| function countShapeLowerLayerNodes() { | ||
| return d3.selectAll('.layer-below > .shapelayer').size(); | ||
| } | ||
| function countShapePathsInSubplots() { | ||
| return d3.selectAll('.layer-subplot > .shapelayer > path').size(); | ||
| } | ||
|
|
||
| function countShapeUpperLayerNodes() { | ||
| return d3.selectAll('.layer-above > .shapelayer').size(); | ||
| } | ||
| describe('Test shapes:', function() { | ||
| 'use strict'; | ||
|
|
||
| function countShapeLayerNodesInSubplots() { | ||
| return d3.selectAll('.layer-subplot').size(); | ||
| } | ||
| var mock = require('@mocks/shapes.json'); | ||
| var gd; | ||
|
|
||
| function countSubplots(gd) { | ||
| return Object.keys(gd._fullLayout._plots || {}).length; | ||
| } | ||
| beforeEach(function(done) { | ||
| gd = createGraphDiv(); | ||
|
|
||
| function countShapePathsInLowerLayer() { | ||
| return d3.selectAll('.layer-below > .shapelayer > path').size(); | ||
| } | ||
| var mockData = Lib.extendDeep([], mock.data), | ||
| mockLayout = Lib.extendDeep({}, mock.layout); | ||
|
|
||
| function countShapePathsInUpperLayer() { | ||
| return d3.selectAll('.layer-above > .shapelayer > path').size(); | ||
| } | ||
| Plotly.plot(gd, mockData, mockLayout).then(done); | ||
| }); | ||
|
|
||
| function countShapePathsInSubplots() { | ||
| return d3.selectAll('.layer-subplot > .shapelayer > path').size(); | ||
| } | ||
| afterEach(destroyGraphDiv); | ||
|
|
||
| describe('*shapeLowerLayer*', function() { | ||
| it('has one node', function() { | ||
|
|
@@ -180,14 +180,14 @@ describe('Test shapes:', function() { | |
|
|
||
| it('has as many *path* nodes as shapes in the lower layer', function() { | ||
| expect(countShapePathsInLowerLayer()) | ||
| .toEqual(countShapesInLowerLayer()); | ||
| .toEqual(countShapesInLowerLayer(gd)); | ||
| }); | ||
|
|
||
| it('should be able to get relayout', function(done) { | ||
| Plotly.relayout(gd, {height: 200, width: 400}).then(function() { | ||
| expect(countShapeLowerLayerNodes()).toEqual(1); | ||
| expect(countShapePathsInLowerLayer()) | ||
| .toEqual(countShapesInLowerLayer()); | ||
| .toEqual(countShapesInLowerLayer(gd)); | ||
| }) | ||
| .catch(failTest) | ||
| .then(done); | ||
|
|
@@ -201,14 +201,14 @@ describe('Test shapes:', function() { | |
|
|
||
| it('has as many *path* nodes as shapes in the upper layer', function() { | ||
| expect(countShapePathsInUpperLayer()) | ||
| .toEqual(countShapesInUpperLayer()); | ||
| .toEqual(countShapesInUpperLayer(gd)); | ||
| }); | ||
|
|
||
| it('should be able to get relayout', function(done) { | ||
| Plotly.relayout(gd, {height: 200, width: 400}).then(function() { | ||
| expect(countShapeUpperLayerNodes()).toEqual(1); | ||
| expect(countShapePathsInUpperLayer()) | ||
| .toEqual(countShapesInUpperLayer()); | ||
| .toEqual(countShapesInUpperLayer(gd)); | ||
| }) | ||
| .catch(failTest) | ||
| .then(done); | ||
|
|
@@ -223,15 +223,15 @@ describe('Test shapes:', function() { | |
|
|
||
| it('has as many *path* nodes as shapes in the subplot', function() { | ||
| expect(countShapePathsInSubplots()) | ||
| .toEqual(countShapesInSubplots()); | ||
| .toEqual(countShapesInSubplots(gd)); | ||
| }); | ||
|
|
||
| it('should be able to get relayout', function(done) { | ||
| Plotly.relayout(gd, {height: 200, width: 400}).then(function() { | ||
| expect(countShapeLayerNodesInSubplots()) | ||
| .toEqual(countSubplots(gd)); | ||
| expect(countShapePathsInSubplots()) | ||
| .toEqual(countShapesInSubplots()); | ||
| .toEqual(countShapesInSubplots(gd)); | ||
| }) | ||
| .catch(failTest) | ||
| .then(done); | ||
|
|
@@ -464,6 +464,49 @@ describe('shapes axis reference changes', function() { | |
| }); | ||
| }); | ||
|
|
||
| describe('shapes edge cases', function() { | ||
| 'use strict'; | ||
|
|
||
| var gd; | ||
|
|
||
| beforeAll(function() { | ||
| jasmine.addMatchers(customMatchers); | ||
| }); | ||
|
|
||
| beforeEach(function() { gd = createGraphDiv(); }); | ||
|
|
||
| afterEach(destroyGraphDiv); | ||
|
|
||
| it('falls back on shapeLowerLayer for below missing subplots', function(done) { | ||
| Plotly.newPlot(gd, [ | ||
| {x: [1, 3], y: [1, 3]}, | ||
| {x: [1, 3], y: [1, 3], xaxis: 'x2', yaxis: 'y2'} | ||
| ], { | ||
| xaxis: {domain: [0, 0.5]}, | ||
| yaxis: {domain: [0, 0.5]}, | ||
| xaxis2: {domain: [0.5, 1], anchor: 'y2'}, | ||
| yaxis2: {domain: [0.5, 1], anchor: 'x2'}, | ||
| shapes: [{ | ||
| x0: 1, x1: 2, y0: 1, y1: 2, type: 'circle', | ||
| layer: 'below', | ||
| xref: 'x', | ||
| yref: 'y2' | ||
| }, { | ||
| x0: 1, x1: 2, y0: 1, y1: 2, type: 'circle', | ||
| layer: 'below', | ||
| xref: 'x2', | ||
| yref: 'y' | ||
| }] | ||
| }).then(function() { | ||
| expect(countShapePathsInLowerLayer()).toBe(2); | ||
| expect(countShapePathsInUpperLayer()).toBe(0); | ||
| expect(countShapePathsInSubplots()).toBe(0); | ||
| }) | ||
| .catch(failTest) | ||
| .then(done); | ||
| }); | ||
| }); | ||
|
|
||
| describe('shapes autosize', function() { | ||
| 'use strict'; | ||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Looks good.
I see that annotations don't need a similar fix. @alexcjohnson Can I ask why?
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.
Annotations don't have the concept of layer. They're always on top.
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.
Right. That makes sense 👍