-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(interaction): brushFilter emit filter event
- Loading branch information
Showing
8 changed files
with
195 additions
and
74 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { chartOnBrushFilter as render } from '../plots/api/chart-on-brush-filter'; | ||
import { PLOT_CLASS_NAME } from '../../src'; | ||
import { dblclick, brush } from '../plots/interaction/penguins-point-brush'; | ||
import { createDOMGCanvas } from './utils/createDOMGCanvas'; | ||
import { createPromise, receiveExpectData } from './utils/event'; | ||
import './utils/useCustomFetch'; | ||
|
||
describe('chart.on', () => { | ||
const canvas = createDOMGCanvas(640, 480); | ||
const { finished, chart } = render({ canvas }); | ||
|
||
chart.off(); | ||
|
||
it('chart.on("element:filter", callback) should provide selection when filtering', async () => { | ||
await finished; | ||
const { document } = canvas; | ||
const plot = document.getElementsByClassName(PLOT_CLASS_NAME)[0]; | ||
|
||
// Brush plot. | ||
const [filtered, resolve] = createPromise(); | ||
chart.on( | ||
'brush:filter', | ||
receiveExpectData(resolve, { | ||
selection: [ | ||
[34.99184225303586, 44.72635552737214], | ||
[15.877014192597635, 20.13017874955966], | ||
], | ||
}), | ||
); | ||
brush(plot, 100, 100, 300, 300); | ||
await filtered; | ||
|
||
// Reset plot. | ||
const [rested, resolve1] = createPromise(); | ||
chart.off(); | ||
chart.on( | ||
'brush:filter', | ||
receiveExpectData(resolve1, { | ||
selection: [ | ||
[32.1, 59.6], | ||
[13.1, 21.5], | ||
], | ||
}), | ||
); | ||
setTimeout(() => dblclick(plot), 1000); | ||
await rested; | ||
}); | ||
|
||
afterAll(() => { | ||
canvas?.destroy(); | ||
}); | ||
}); |
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,33 @@ | ||
import { Chart } from '../../../src'; | ||
|
||
export function chartOnBrushFilter(context) { | ||
const { container, canvas } = context; | ||
|
||
const chart = new Chart({ | ||
theme: 'classic', | ||
container, | ||
canvas, | ||
}); | ||
|
||
chart.options({ | ||
type: 'point', | ||
data: { | ||
type: 'fetch', | ||
value: 'data/penguins.csv', | ||
}, | ||
encode: { | ||
color: 'species', | ||
x: 'culmen_length_mm', | ||
y: 'culmen_depth_mm', | ||
}, | ||
interaction: { brushFilter: true }, | ||
}); | ||
|
||
chart.on('brush:filter', (event) => { | ||
console.log(event.data.selection); | ||
}); | ||
|
||
const finished = chart.render(); | ||
|
||
return { chart, finished }; | ||
} |
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