Skip to content

Commit

Permalink
formatting, truncate strategy on axis, but show full number on toolti…
Browse files Browse the repository at this point in the history
…ps (#4283)
  • Loading branch information
mwdchang authored Jul 26, 2024
1 parent 9c4bd73 commit 6288742
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions packages/client/hmi-client/src/services/charts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ const VEGALITE_SCHEMA = 'https://vega.github.io/schema/vega-lite/v5.json';
export const CATEGORICAL_SCHEME = ['#1B8073', '#6495E8', '#8F69B9', '#D67DBF', '#E18547', '#D2C446', '#84594D'];

export const NUMBER_FORMAT = '.3~s';
export const LABEL_EXPR = `
datum.value > -1 && datum.value < 1 ? format(datum.value, '.3~f') : format(datum.value, '${NUMBER_FORMAT}')
`;

interface BaseChartOptions {
title?: string;
Expand Down Expand Up @@ -167,7 +170,7 @@ export const createForecastChart = (
};
const yaxis = structuredClone(xaxis);
yaxis.title = options.yAxisTitle;
yaxis.format = NUMBER_FORMAT;
yaxis.labelExpr = LABEL_EXPR;

const translationMap = options.translationMap;
let labelExpr = '';
Expand Down Expand Up @@ -309,8 +312,7 @@ export const createForecastChart = (
const tooltipContent = statisticsLayer.variables?.map((d) => {
const tip: any = {
field: d,
type: 'quantitative',
format: NUMBER_FORMAT
type: 'quantitative'
};

if (options.translationMap && options.translationMap[d]) {
Expand All @@ -322,7 +324,7 @@ export const createForecastChart = (

const layerSpec = newLayer(statisticsLayer, 'line');
Object.assign(layerSpec.encoding, {
opacity: { value: 0 },
opacity: { value: 0.00000001 },
strokeWidth: { value: 16 },
tooltip: [{ field: statisticsLayer.timeField, type: 'quantitative' }, ...(tooltipContent || [])]
});
Expand Down Expand Up @@ -372,7 +374,7 @@ export function createSuccessCriteriaChart(
};
const yaxis = structuredClone(xaxis);
yaxis.title = options.yAxisTitle;
yaxis.format = NUMBER_FORMAT;
yaxis.labelExpr = LABEL_EXPR;

return {
$schema: VEGALITE_SCHEMA,
Expand Down

0 comments on commit 6288742

Please sign in to comment.