-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Add tests for table trace type with Plotly.restyle and Plotly.relayout #2096
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
Closed
Closed
Changes from 1 commit
Commits
Show all changes
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"data": [ | ||
{ | ||
"mode": "markers", | ||
"type": "scatter" | ||
} | ||
], | ||
"layout": { | ||
"hovermode": "closest" | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,135 @@ | ||
var Plotly = require('@lib'); | ||
var Lib = require('@src/lib'); | ||
var d3 = require('d3'); | ||
var createGraphDiv = require('../assets/create_graph_div'); | ||
var destroyGraphDiv = require('../assets/destroy_graph_div'); | ||
|
||
describe('table plots', function() { | ||
'use strict'; | ||
var gd; | ||
|
||
beforeEach(function() { | ||
gd = createGraphDiv(); | ||
}); | ||
|
||
afterEach(destroyGraphDiv); | ||
|
||
function initialize(mock, gd) { | ||
return Plotly.plot(gd, mock.data, mock.layout); | ||
} | ||
|
||
function countCells() { | ||
return d3.selectAll('.cell-rect').size(); | ||
} | ||
|
||
it('should be able switch to table trace from another plot type', function(done) { | ||
var mock = Lib.extendDeep({}, require('@mocks/workspace_starter_state.json')); | ||
initialize(mock, gd) | ||
.then(function() { | ||
return Plotly.restyle(gd, {type: 'table'}) | ||
.then(function() { | ||
return Plotly.restyle( | ||
gd, {'header.values[0]': ['First Column']} | ||
); | ||
}) | ||
.then(function() { | ||
return Plotly.restyle( | ||
gd, {'header.values[1]': ['Second Column']} | ||
); | ||
}) | ||
.then(function() { | ||
return Plotly.restyle(gd, | ||
{ | ||
'cells.values': [ | ||
['First Row First Col', 'First Row Second Col'], | ||
['Second Row First Col', 'Second Row Second Col'] | ||
] | ||
} | ||
); | ||
}); | ||
}) | ||
.then(function() { | ||
expect(gd.data[0].type).toBe('table'); | ||
expect(countCells()).toBe(6); | ||
}) | ||
.then(done); | ||
}); | ||
|
||
it('should be able to use Plotly.restyle on an existing table', function(done) { | ||
var mock = Lib.extendDeep({}, require('@mocks/table_plain_birds.json')); | ||
var newColors = ['yellow', 'gray']; | ||
|
||
initialize(mock, gd) | ||
.then(function() { | ||
return Plotly.restyle(gd, {'cells.fill': newColors}) | ||
.then(function() { | ||
Plotly.restyle(gd, {'header.font.size': 20}); | ||
}); | ||
}) | ||
.then(function() { | ||
expect(gd.data[0].cells[0]).toBe('yellow'); | ||
expect(gd.data[0].cells[1]).toBe('gray'); | ||
expect(gd.data[0].header.font.size).toBe(20); | ||
}) | ||
.then(done); | ||
}); | ||
|
||
it('should work with Plotly.restyle for a specific trace index', function(done) { | ||
var mock = Lib.extendDeep({}, require('@mocks/table_latex_multitrace.json')); | ||
var initialFontSizeFirstTrace; | ||
var initialFontSizeSecondTrace; | ||
|
||
initialize(mock, gd) | ||
.then(function() { | ||
initialFontSizeFirstTrace = gd.data[0].header.font.size; | ||
initialFontSizeSecondTrace = gd.data[1].header.font.size; | ||
|
||
expect(initialFontSizeFirstTrace === initialFontSizeSecondTrace).toBe(true); | ||
|
||
return Plotly.restyle(gd, {'header.font.size': initialFontSizeFirstTrace + 1}, 0) | ||
.then(function() { | ||
Plotly.restyle(gd, {'header.font.size': initialFontSizeSecondTrace + 2}, 1); | ||
}); | ||
}) | ||
.then(function() { | ||
expect(gd.data[0].header.font.size).toBe(initialFontSizeFirstTrace + 1); | ||
expect(gd.data[1].header.font.size).toBe(initialFontSizeFirstTrace + 2); | ||
expect(initialFontSizeFirstTrace !== initialFontSizeSecondTrace).toBe(true); | ||
}) | ||
.then(done); | ||
}); | ||
|
||
it('should work with Plotly.relayout', function(done) { | ||
var mock = Lib.extendDeep({}, require('@mocks/table_latex_multitrace.json')); | ||
var newTitle = 'New Title'; | ||
|
||
initialize(mock, gd) | ||
.then(function() { | ||
return Plotly.relayout(gd, {'title': newTitle}); | ||
}) | ||
.then(function() { | ||
expect(gd.layout.title).toBe(newTitle); | ||
}) | ||
.then(done); | ||
}); | ||
|
||
it('should work with Plotly.update', function(done) { | ||
var mock = Lib.extendDeep({}, require('@mocks/table_plain_birds.json')); | ||
var newTitle = 'New Title'; | ||
var initialFontSize; | ||
|
||
initialize(mock, gd) | ||
.then(function() { | ||
initialFontSize = gd.data[0].header.font.size; | ||
return Plotly.update(gd, | ||
{'header.font.size': initialFontSize + 1}, | ||
{'title': newTitle} | ||
); | ||
}) | ||
.then(function() { | ||
expect(gd.layout.title).toBe(newTitle); | ||
expect(gd.data[0].header.font.size).toBe(initialFontSize + 1); | ||
}) | ||
.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.
@VeraZab would you mind replacing this
require
call with:as each json mock in
test/image/mocks/
is expected to have a corresponding image intest/image/baselines/
? This should make the test go ✅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.
sure, thanks!