Skip to content

Commit

Permalink
Use Roboto font for rendering plots
Browse files Browse the repository at this point in the history
- this may fix the CI issues with rendering differences of fonts
  • Loading branch information
smarr committed Jun 13, 2023
1 parent 4cb12ca commit 13223b6
Show file tree
Hide file tree
Showing 32 changed files with 1,093 additions and 1,058 deletions.
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"license": "MIT",
"type": "module",
"dependencies": {
"@fontsource/roboto": "5.0.3",
"@octokit/auth-app": "4.0.13",
"@octokit/rest": "19.0.11",
"chart.js": "^3.5.1",
Expand Down
27 changes: 25 additions & 2 deletions src/charts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
BoxAndWiskers
} from '@sgratzl/chartjs-chart-boxplot';
import { medianUnsorted } from '../src/stats.js';
import { siteAesthetics } from './util.js';
import { robustPath, siteAesthetics } from './util.js';

const fullyTransparent = 'rgba(0, 0, 0, 0)';

Expand Down Expand Up @@ -145,6 +145,8 @@ export function createCanvas(settings: CanvasSettings): ChartJSNodeCanvas {
backgroundColour: siteAesthetics.backgroundColor,
plugins: { modern: plugins },
chartCallback: (ChartJS) => {
ChartJS.defaults.font.family = 'Roboto';

ChartJS.register({
id: 'my_background_color',
beforeDraw: (chart, _options) => {
Expand All @@ -171,7 +173,28 @@ export function createCanvas(settings: CanvasSettings): ChartJSNodeCanvas {
if (settings.outputType === 'svg') {
(<any>canvasOptions).type = 'svg'; // work around the readonly property
}
return new ChartJSNodeCanvas(canvasOptions);

const canvas = new ChartJSNodeCanvas(canvasOptions);

canvas.registerFont(
robustPath(
'../node_modules/@fontsource/roboto/files/roboto-latin-400-normal.woff'
),
{
family: 'Roboto',
weight: '400'
}
);
canvas.registerFont(
robustPath(
'../node_modules/@fontsource/roboto/files/roboto-latin-700-normal.woff'
),
{
family: 'Roboto',
weight: '700'
}
);
return canvas;
}

async function renderDataOnCanvas(
Expand Down
7 changes: 2 additions & 5 deletions src/logging.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import { Logger } from 'tslog';
import { isRunningTests } from './util.js';

// 0: silly, 1: trace, 2: debug, 3: info, 4: warn, 5: error, 6: fatal
const trace = 2;
const info = 3;
const error = 5;

function getLoggingLevel(): number {
if (
('NODE_ENV' in process.env && process.env.NODE_ENV === 'test') ||
('JEST_WORKER_ID' in process.env &&
process.env.JEST_WORKER_ID !== undefined)
) {
if (isRunningTests()) {
return error;
}

Expand Down
8 changes: 8 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ export function isReBenchDotDev(): boolean {
return siteConfig.publicUrl === _rebench_dev;
}

export function isRunningTests(): boolean {
return (
('NODE_ENV' in process.env && process.env.NODE_ENV === 'test') ||
('JEST_WORKER_ID' in process.env &&
process.env.JEST_WORKER_ID !== undefined)
);
}

export const statsConfig = {
numberOfBootstrapSamples: 50
};
Expand Down
82 changes: 41 additions & 41 deletions tests/data/expected-results/charts/inline-1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/data/expected-results/charts/jssom-som.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
96 changes: 48 additions & 48 deletions tests/data/expected-results/charts/jssom-som.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/data/expected-results/charts/jssom.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/data/expected-results/charts/trufflesom-macro-startup.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
130 changes: 65 additions & 65 deletions tests/data/expected-results/charts/trufflesom-macro-startup.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/data/expected-results/charts/trufflesom-macro-steady.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
76 changes: 38 additions & 38 deletions tests/data/expected-results/charts/trufflesom-macro-steady.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/data/expected-results/charts/trufflesom-micro-somsom.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
72 changes: 36 additions & 36 deletions tests/data/expected-results/charts/trufflesom-micro-somsom.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/data/expected-results/charts/trufflesom-micro-startup.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
242 changes: 121 additions & 121 deletions tests/data/expected-results/charts/trufflesom-micro-startup.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/data/expected-results/charts/trufflesom-micro-steady.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
132 changes: 66 additions & 66 deletions tests/data/expected-results/charts/trufflesom-micro-steady.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/data/expected-results/charts/trufflesom.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
80 changes: 40 additions & 40 deletions tests/data/expected-results/stats-data-prep/jssom/inline-24.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
80 changes: 40 additions & 40 deletions tests/data/expected-results/stats-data-prep/jssom/inline-4.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
96 changes: 48 additions & 48 deletions tests/data/expected-results/stats-data-prep/jssom/overview-som.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/data/expected-results/stats-data-prep/jssom/overview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
306 changes: 153 additions & 153 deletions tests/data/expected-results/stats-data-prep/tsom/inline-111.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
58 changes: 29 additions & 29 deletions tests/data/expected-results/stats-data-prep/tsom/inline-156.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Large diffs are not rendered by default.

Binary file modified tests/data/expected-results/stats-data-prep/tsom/overview.png

0 comments on commit 13223b6

Please sign in to comment.