-
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 (#6354)
* feat(wordcloud): accept custom canvas * docs: update wordcloud docs * feat(data-transform): pass createCanvas * refactor(runtime): simplfy library param
- Loading branch information
Showing
12 changed files
with
142 additions
and
78 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,28 @@ | ||
import { Chart } from '../../../src'; | ||
|
||
export function chartWordCloudCanvas(context) { | ||
const { container, canvas } = context; | ||
|
||
const ref = { called: false }; | ||
|
||
const chart = new Chart({ | ||
container, | ||
canvas, | ||
createCanvas: () => { | ||
ref.called = true; | ||
return document.createElement('canvas'); | ||
}, | ||
}); | ||
|
||
chart.options({ | ||
type: 'wordCloud', | ||
data: { | ||
type: 'fetch', | ||
value: 'data/philosophyWord.json', | ||
}, | ||
}); | ||
|
||
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
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.