-
-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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,82 @@ 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 pathCount = countShapePaths(); | ||
var index = countShapes(gd); | ||
var shape = getRandomShape(); | ||
|
||
Plotly.relayout(gd, 'shapes[' + index + ']', shape).then(function() { | ||
expect(countShapeLayers()).toEqual(1); | ||
expect(countShapePaths()).toEqual(pathCount + 1); | ||
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 pathCount = countShapePaths(); | ||
var index = countShapes(gd); | ||
var shape = getRandomShape(); | ||
|
||
Plotly.relayout(gd, 'shapes[' + index + ']', shape).then(function() { | ||
expect(countShapeLayers()).toEqual(1); | ||
expect(countShapePaths()).toEqual(pathCount + 1); | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Oops. My bad. I meant But testing 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. Oh... that makes sense. I should've guessed you meant that. |
||
expect(countShapePaths()).toEqual(pathCount); | ||
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. 🎉 |
||
expect(countShapes(gd)).toEqual(index); | ||
}).then(done); | ||
}); | ||
}); | ||
}); |
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