@ministryofjustice/hmpps-digital-prison-reporting-frontend
Version:
The Digital Prison Reporting Frontend contains templates and code to help display data effectively in UI applications.
60 lines (57 loc) • 1.85 kB
JavaScript
import { setUnitOnValue, mapUnitToSymbol } from '../../../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 setUnitOnValue(display || '', 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 = setUnitOnValue(field.raw || '', unitSymbol);
}
return label;
});
});
return Array.from(new Set(allLabels));
};
}
export { ChartLabelsHelper as default };
//# sourceMappingURL=ChartLabels.js.map