-
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(wordcloud): accept custom canvas
- Loading branch information
Showing
5 changed files
with
76 additions
and
2 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,28 @@ | ||
import { chartWordCloudCanvas as render } from '../plots/api/chart-word-cloud-canvas'; | ||
import './utils/useSnapshotMatchers'; | ||
import { createNodeGCanvas } from './utils/createNodeGCanvas'; | ||
import './utils/useCustomFetch'; | ||
|
||
describe('word cloud canvas', () => { | ||
const canvas = createNodeGCanvas(640, 480); | ||
|
||
it('word cloud should use custom canvas.', async () => { | ||
// This no canvas in JSDOM environment, so it will throw error. | ||
// But it's ok, we just need to test if the ref is called. | ||
let ref; | ||
try { | ||
const rendered = render({ | ||
canvas, | ||
container: document.createElement('div'), | ||
}); | ||
ref = rendered.ref; | ||
await rendered.finished; | ||
} catch (e) { | ||
expect(ref.called).toBe(true); | ||
} | ||
}); | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { Chart } from '../../../src'; | ||
|
||
export function chartWordCloudCanvas(context) { | ||
const { container, canvas } = context; | ||
|
||
const chart = new Chart({ | ||
container, | ||
canvas, | ||
}); | ||
|
||
const ref = { called: false }; | ||
|
||
chart.options({ | ||
type: 'wordCloud', | ||
data: { | ||
type: 'fetch', | ||
value: 'data/philosophyWord.json', | ||
}, | ||
layout: { | ||
// random, | ||
canvas: () => { | ||
ref.called = true; | ||
return document.createElement('canvas'); | ||
}, | ||
}, | ||
}); | ||
|
||
const finished = chart.render(); | ||
|
||
return { chart, ref, 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