-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #495 from Kitware/update-api
Add update / destroy API for VisComponent
- Loading branch information
Showing
12 changed files
with
269 additions
and
80 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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,68 @@ | ||
import { select } from 'd3-selection'; | ||
import test from 'tape-catch'; | ||
|
||
import BarChart from '..'; | ||
|
||
test('BarChart component', t => { | ||
t.plan(7); | ||
|
||
const data = [ | ||
{id: 0, a: 1, b: 3, c: 3}, | ||
{id: 1, a: 10, b: 4, c: 3}, | ||
{id: 2, a: 7, b: 6, c: 3}, | ||
{id: 3, a: 4, b: 2, c: 3}, | ||
{id: 4, a: 5, b: 5, c: 3}, | ||
{id: 5, a: 7, b: 6, c: 3}, | ||
{id: 6, a: 2, b: 9, c: 3}, | ||
{id: 7, a: 5, b: 7, c: 3} | ||
]; | ||
|
||
let el = document.createElement('div'); | ||
let vis = new BarChart(el, { | ||
data: data, | ||
x: 'id', | ||
y: 'a', | ||
color: 'b', | ||
width: 625, | ||
height: 540, | ||
padding: { | ||
left: 45, | ||
right: 130, | ||
top: 20, | ||
bottom: 40 | ||
}, | ||
renderer: 'svg' | ||
}); | ||
|
||
vis.chart.then(() => { | ||
t.equal(el.childNodes.length, 1, 'VegaCharts should have a single element under the top-level div'); | ||
|
||
let container = el.childNodes[0]; | ||
t.equal(container.nodeName, 'DIV', 'The single element should be a div'); | ||
t.equal(container.childNodes.length, 1, 'The div should have a single child element.'); | ||
|
||
let svg = container.childNodes[0]; | ||
t.equal(svg.nodeName, 'svg', 'The single child should be an svg.'); | ||
|
||
let bars = select(svg) | ||
.select('g.mark-rect') | ||
.selectAll('rect'); | ||
t.equal(bars.size(), data.length, 'The number of bars in the chart should equal the number of data items'); | ||
|
||
vis.update({ | ||
data: data.concat([{id: 8, a: 10, b: 6, c: 3}]) | ||
}).then(() => vis.render()) | ||
.then(() => { | ||
vis.render(); | ||
|
||
bars = select(svg) | ||
.select('g.mark-rect') | ||
.selectAll('rect'); | ||
t.equal(bars.size(), data.length + 1, 'After data update, the number of bars in the chart should equal the original number of data items, plus one'); | ||
|
||
vis.destroy(); | ||
let contents = select(vis.el).selectAll('*'); | ||
t.equal(contents.size(), 0, 'After destroy(), container element should have no children'); | ||
}); | ||
}); | ||
}); |
This file contains 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 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 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
Oops, something went wrong.