Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chart tweaks #6563

Merged
merged 3 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ const defaultChartConfig: Partial<Config> = {
tooltipFormat: {
numberFormat: 'tooltipFormatter',
numberFormatType: 'tooltipFormatter'
},
axis: {
labelFontSize: 12
}
};

Expand Down
30 changes: 11 additions & 19 deletions packages/client/hmi-client/src/services/charts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { flattenInterventionData } from './intervention-policy';
import type { FunmanBox, FunmanConstraintsResponse } from './models/funman-service';

const VEGALITE_SCHEMA = 'https://vega.github.io/schema/vega-lite/v5.json';
const GLOBAL_FONT = 'Figtree';

const NUMBER_FORMAT = '.3~s';
export const expressionFunctions = {
Expand Down Expand Up @@ -135,7 +136,6 @@ export function createErrorChart(dataset: Record<string, any>[], options: ErrorC
const axisColor = '#EEE';
const labelColor = '#667085';
const labelFontWeight = 'normal';
const globalFont = 'Figtree';

const areaChartColor = options.color ?? '#1B8073';
const dotColor = options.color ?? '#1B8073';
Expand Down Expand Up @@ -180,7 +180,7 @@ export function createErrorChart(dataset: Record<string, any>[], options: ErrorC

const config = {
facet: { spacing: 2 },
font: globalFont,
font: GLOBAL_FONT,
mark: { opacity: 1 },
view: { stroke: 'transparent' },
axis: {
Expand Down Expand Up @@ -324,7 +324,6 @@ export function createHistogramChart(dataset: Record<string, any>[], options: Hi
const axisColor = '#EEE';
const labelColor = '#667085';
const labelFontWeight = 'normal';
const globalFont = 'Figtree';
const titleObj = options.title
? {
text: options.title,
Expand Down Expand Up @@ -376,7 +375,7 @@ export function createHistogramChart(dataset: Record<string, any>[], options: Hi
},
layer: [],
config: {
font: globalFont
font: GLOBAL_FONT
}
};

Expand Down Expand Up @@ -508,7 +507,6 @@ export function createForecastChart(
const axisColor = '#EEE';
const labelColor = '#667085';
const labelFontWeight = 'normal';
const globalFont = 'Figtree';
const titleObj = options.title
? {
text: options.title,
Expand Down Expand Up @@ -597,7 +595,7 @@ export function createForecastChart(
type: options.autosize || AUTOSIZE.FIT_X
},
config: {
font: globalFont,
font: GLOBAL_FONT,
legend: {
layout: {
anchor: 'start'
Expand Down Expand Up @@ -1129,7 +1127,6 @@ export function createQuantilesForecastChart(
const axisColor = '#EEE';
const labelColor = '#667085';
const labelFontWeight = 'normal';
const globalFont = 'Figtree';
const titleObj = options.title
? {
text: options.title,
Expand Down Expand Up @@ -1221,7 +1218,7 @@ export function createQuantilesForecastChart(
type: options.autosize || AUTOSIZE.FIT_X
},
config: {
font: globalFont,
font: GLOBAL_FONT,
legend: {
layout: {
direction: legendProperties.direction,
Expand Down Expand Up @@ -1376,12 +1373,10 @@ export function createSimulateSensitivityScatter(
/* -------------------------------------------------------------------------- */

export function createSensitivityRankingChart(data: { parameter: string; score: number }[], options: BaseChartOptions) {
const globalFont = 'Figtree';

const spec: any = {
$schema: VEGALITE_SCHEMA,
config: {
font: globalFont,
font: GLOBAL_FONT,
bar: {
discreteBandSize: 8 // Fixed bar width
}
Expand Down Expand Up @@ -1477,7 +1472,8 @@ export function createForecastChartAnnotation(axis: 'x' | 'y', datum: number, la
dx: 16,
dy: -16,
angle: isVertical ? 90 : 0,
baseline: 'top'
baseline: 'top',
fontSize: 12
},
encoding: {
text: { value: label }
Expand Down Expand Up @@ -1749,7 +1745,6 @@ export function createFunmanStateChart(
if (isEmpty(trajectories)) return null;

const threshold = 1e25;
const globalFont = 'Figtree';

const stateIdConstraints = constraints.filter((c) => c.variables.includes(stateId));
// Find min/max values to set an appropriate viewing range for y-axis
Expand Down Expand Up @@ -1791,7 +1786,7 @@ export function createFunmanStateChart(
return {
$schema: VEGALITE_SCHEMA,
id: stateId,
config: { font: globalFont },
config: { font: GLOBAL_FONT },
width: 600,
height: 300,
title: {
Expand Down Expand Up @@ -1907,11 +1902,10 @@ export function createFunmanParameterCharts(
});
});

const globalFont = 'Figtree';
return {
$schema: VEGALITE_SCHEMA,
config: {
font: globalFont,
font: GLOBAL_FONT,
tick: { thickness: 2 }
},
width: 600,
Expand Down Expand Up @@ -2073,12 +2067,10 @@ export function createRankingInterventionsChart(
title: string | null = null,
variableName: string | null = null
) {
const globalFont = 'Figtree';

return {
$schema: VEGALITE_SCHEMA,
config: {
font: globalFont,
font: GLOBAL_FONT,
bar: {
discreteBandSize: 20 // Fixed bar width
},
Expand Down
Loading