-
-
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
Merged
Merged
Shape clean up #378
Changes from 3 commits
Commits
Show all changes
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ var createGraphDiv = require('../assets/create_graph_div'); | |
var destroyGraphDiv = require('../assets/destroy_graph_div'); | ||
|
||
|
||
describe('Test shapes nodes', function() { | ||
describe('Test shapes:', function() { | ||
'use strict'; | ||
|
||
var mock = require('@mocks/shapes.json'); | ||
|
@@ -28,26 +28,74 @@ describe('Test shapes nodes', function() { | |
return d3.selectAll('.shapelayer').size(); | ||
} | ||
|
||
function countPaths() { | ||
function countShapePaths() { | ||
return d3.selectAll('.shapelayer > path').size(); | ||
} | ||
|
||
it('has one *shapelayer* node', function() { | ||
expect(countShapeLayers()).toEqual(1); | ||
}); | ||
describe('DOM', function() { | ||
it('has one *shapelayer* node', function() { | ||
expect(countShapeLayers()).toEqual(1); | ||
}); | ||
|
||
it('has as many *path* nodes as there are shapes', function() { | ||
expect(countShapePaths()).toEqual(mock.layout.shapes.length); | ||
}); | ||
|
||
it('has as many *path* nodes as there are shapes', function() { | ||
expect(countPaths()).toEqual(mock.layout.shapes.length); | ||
it('should be able to get relayout', function(done) { | ||
expect(countShapeLayers()).toEqual(1); | ||
expect(countShapePaths()).toEqual(mock.layout.shapes.length); | ||
|
||
Plotly.relayout(gd, {height: 200, width: 400}).then(function() { | ||
expect(countShapeLayers()).toEqual(1); | ||
expect(countShapePaths()).toEqual(mock.layout.shapes.length); | ||
}).then(done); | ||
}); | ||
}); | ||
|
||
it('should be able to get relayout', function(done) { | ||
expect(countShapeLayers()).toEqual(1); | ||
expect(countPaths()).toEqual(mock.layout.shapes.length); | ||
function countShapes(gd) { | ||
return gd.layout.shapes ? | ||
gd.layout.shapes.length : | ||
0; | ||
} | ||
|
||
function getLastShape(gd) { | ||
return gd.layout.shapes ? | ||
gd.layout.shapes[gd.layout.shapes.length - 1] : | ||
null; | ||
} | ||
|
||
Plotly.relayout(gd, {height: 200, width: 400}).then(function() { | ||
expect(countShapeLayers()).toEqual(1); | ||
expect(countPaths()).toEqual(mock.layout.shapes.length); | ||
done(); | ||
function getRandomShape() { | ||
return { | ||
x0: Math.random(), | ||
y0: Math.random(), | ||
x1: Math.random(), | ||
y1: Math.random() | ||
}; | ||
} | ||
|
||
describe('Plotly.relayout', function() { | ||
it('should be able to add a shape', function(done) { | ||
var index = countShapes(gd); | ||
var shape = getRandomShape(); | ||
|
||
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 commentThe reason will be displayed to describe this comment to others. Learn more. @n-riesco nice test. Thanks. Could you also add an |
||
}).then(done); | ||
}); | ||
|
||
it('should be able to remove a shape', function(done) { | ||
var index = countShapes(gd); | ||
var shape = getRandomShape(); | ||
|
||
Plotly.relayout(gd, 'shapes[' + index + ']', shape).then(function() { | ||
expect(getLastShape(gd)).toEqual(shape); | ||
expect(countShapes(gd)).toEqual(index + 1); | ||
}).then(function() { | ||
Plotly.relayout(gd, 'shapes[' + index + ']', 'remove'); | ||
}).then(function() { | ||
expect(countShapes(gd)).toEqual(index); | ||
}).then(done); | ||
}); | ||
}); | ||
}); |
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.
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