mirror of
https://github.com/chartjs/Chart.js.git
synced 2026-03-09 17:56:51 +01:00
Add tests for rendering to offscreen canvas (#7175)
Add tests for using an offscreen canvas for Chart.js. These tests are almost identical to existing tests, but with offscreen canvas enabled. Co-authored-by: David Winegar <david.winegar@getcruise.com>
This commit is contained in:
26
test/BasicChartWebWorker.js
Normal file
26
test/BasicChartWebWorker.js
Normal file
@@ -0,0 +1,26 @@
|
||||
// This file is a basic example of using a chart inside a web worker.
|
||||
// All it creates a new chart from a transferred OffscreenCanvas and then assert that the correct platform type was
|
||||
// used.
|
||||
|
||||
// Receives messages with data of type: { type: 'initialize', canvas: OffscreenCanvas }
|
||||
// Sends messages with data of types: { type: 'success' } | { type: 'error', errorMessage: string }
|
||||
|
||||
import Chart from '../src';
|
||||
|
||||
onmessage = function(event) {
|
||||
try {
|
||||
const {type, canvas} = event.data;
|
||||
if (type !== 'initialize') {
|
||||
throw new Error('invalid message type received by worker: ' + type);
|
||||
}
|
||||
|
||||
const chart = new Chart(canvas);
|
||||
if (!(chart.platform instanceof Chart.platforms.BasicPlatform)) {
|
||||
throw new Error('did not use basic platform for chart in web worker');
|
||||
}
|
||||
|
||||
postMessage({type: 'success'});
|
||||
} catch (error) {
|
||||
postMessage({type: 'error', errorMessage: error.stack});
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user