@ministryofjustice/hmpps-digital-prison-reporting-frontend
Version:
The Digital Prison Reporting Frontend contains templates and code to help display data effectively in UI applications.
47 lines (44 loc) • 1.57 kB
JavaScript
import { DashboardVisualisationType } from '../../../_dashboards/dashboard-visualisation/types.js';
import BarTimeseriesChartSchemas from './validate.js';
import { TimeseriesChart } from '../ChartTimeseries.js';
import { BarChart } from '../bar/BarChart.js';
/* eslint-disable prefer-destructuring */
class BarTimeseriesChart extends TimeseriesChart {
definition;
BarChartBuilder = new BarChart();
withDefinition = (definition) => {
this.definition = BarTimeseriesChartSchemas.BarTimeseriesSchema.parse(definition);
this.initFromDefinition(this.definition);
return this;
};
build = () => {
this.buildDatasets();
this.setStyles();
this.datasets = this.BarChartBuilder.augmentDataset(this.datasets);
this.BarChartBuilder.setBespokeOptions();
return {
type: DashboardVisualisationType.BAR,
options: {
unit: this.unit,
timeseries: true,
},
data: {
labels: this.labels,
datasets: this.datasets,
config: this.config,
},
};
};
setStyles = () => {
this.datasets = this.datasets.map((set, datasetIndex) => {
const colour = this.hexColours[datasetIndex];
return {
...set,
backgroundColor: colour,
borderColor: colour,
};
});
};
}
export { BarTimeseriesChart, BarTimeseriesChart as default };
//# sourceMappingURL=BarTimeseriesChart.js.map