UNPKG

@ministryofjustice/hmpps-digital-prison-reporting-frontend

Version:

The Digital Prison Reporting Frontend contains templates and code to help display data effectively in UI applications.

62 lines (58 loc) 1.93 kB
'use strict'; var VisualisationUnitHelper = require('../../../utils/Dashboards/VisualisationUnitHelper.js'); class ChartLabelsHelper { /** * Gets the axis labels * * @param {ChartMeasure} measures * @memberof ChartLabelsHelper */ getLabels = (measures) => { return measures.map(col => { const { unit, display } = col; return VisualisationUnitHelper.setUnitOnValue(display || '', VisualisationUnitHelper.mapUnitToSymbol(unit)); }); }; /** * Gets the dataset label * Dataset label = the label seen in the legend * * @memberof ChartLabels */ getDatasetLabel = (keys, row) => { const labelKeys = keys.filter((key) => { return key.type !== 'timestamp'; }); return labelKeys .map((key) => { // Only set the label if there is more than one key const label = key.display && labelKeys.length > 1 ? `${key.display}: ` : ''; // Use the row/col value as the value const value = row[key.id]?.raw ?? ''; return `${label}${value}`; }) .join(', '); }; /** * Gets the axis labels when the column values are used * * @param {DashboardDataResponse[][]} groups * @param {string} axisId * @memberof ChartLabelsHelper */ getListLabels = (groups, axisId, unitSymbol) => { const allLabels = groups.flatMap(gd => { return gd.map(row => { const field = row[axisId]; let label = ''; if (field) { label = VisualisationUnitHelper.setUnitOnValue(field.raw || '', unitSymbol); } return label; }); }); return Array.from(new Set(allLabels)); }; } module.exports = ChartLabelsHelper; //# sourceMappingURL=ChartLabels.js.map