Skip to content

Commit

Permalink
Use SVG renderer in Vega to drop canvas dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
fcollonval committed Jul 8, 2022
1 parent 62ea73b commit 4199f44
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ jobs:
run: |
# Publish image to cml.dev
echo "" >> ${REPORT}
cml-publish ./benchmark-results/lab-benchmark.png --md >> ${REPORT}
cml-publish ./benchmark-results/lab-benchmark.svg --md >> ${REPORT}
echo "" >> ${REPORT}
# Test if metadata have changed
Expand Down
4 changes: 2 additions & 2 deletions galata/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -411,8 +411,8 @@ A special report will be generated in the folder `benchmark-results` that will c

- `lab-benchmark.json`: The execution time of the tests and some metadata.
- `lab-benchmark.md`: A report in Markdown
- `lab-benchmark.png`: A comparison of execution time distribution
- `lab-benchmark.vl.json`: The [_Vega-Lite_](https://vega.github.io/vega-lite) description used to produce the PNG file.
- `lab-benchmark.svg`: A comparison of execution time distribution
- `lab-benchmark.vl.json`: The [_Vega-Lite_](https://vega.github.io/vega-lite) description used to produce the figure.

The reference, tagged _expected_, is stored in `lab-benchmark-expected.json`. It can be
created using the `-u` option of Playwright; i.e. `jlpm run test:benchmark -u`.
Expand Down
1 change: 0 additions & 1 deletion galata/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
"@lumino/coreutils": "^1.12.0",
"@playwright/test": "^1.17.0",
"@stdlib/stats": "~0.0.13",
"canvas": "^2.9.1",
"fs-extra": "^9.0.1",
"http-server": "^13.0.0",
"json5": "^2.1.1",
Expand Down
23 changes: 4 additions & 19 deletions galata/src/benchmarkReporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
TestResult
} from '@playwright/test/reporter';
import { dists, meanpw, variancepn } from '@stdlib/stats/base';
import * as canvas from 'canvas';
import fs from 'fs';
import path from 'path';
import si from 'systeminformation';
Expand Down Expand Up @@ -466,25 +465,11 @@ class BenchmarkReporter implements Reporter {
const vegaSpec = vl.compile(config as any).spec;

const view = new vega.View(vega.parse(vegaSpec), {
renderer: 'canvas'
renderer: 'svg'
}).initialize();
const canvas = (await view.toCanvas()) as any as canvas.Canvas;
const graphFile = path.resolve(outputDir, `${baseName}.png`);
const fileStream = fs.createWriteStream(graphFile);

// Wait for pipe operation to finish
let resolver: (v: unknown) => void;
const waitForPipe = new Promise(resolve => {
resolver = resolve;
});
fileStream.once('finish', () => {
resolver(void 0);
});

const stream = canvas.createPNGStream();
stream.pipe(fileStream, {});

await waitForPipe;
const svgFigure = await view.toSVG();
const graphFile = path.resolve(outputDir, `${baseName}.svg`);
fs.writeFileSync(graphFile, svgFigure);
} else {
console.log(reportString);
}
Expand Down

0 comments on commit 4199f44

Please sign in to comment.