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.

67 lines (62 loc) 1.94 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var types = require('../../../_dashboards/dashboard-visualisation/types.js'); var Chart = require('../Chart.js'); var validate = require('./validate.js'); /* eslint-disable prefer-destructuring */ class DoughnutChart extends Chart.Chart { definition; measures; keys; init = () => { this.measures = this.definition.columns.measures; this.keys = this.definition.columns.keys || []; this.initUnit(this.measures); }; withDefinition = (definition) => { this.definition = validate.DoughnutSchema.parse(definition); this.init(); return this; }; build = () => { this.createDatasets(this.measures, this.keys); this.augmentDataset(); this.setBespokeOptions(); return { type: types.DashboardVisualisationType.DONUT, options: { unit: this.unit, }, data: { labels: this.labels, datasets: this.datasets, config: this.config, }, }; }; augmentDataset = () => { const hexColours = this.chartColoursHelper.getHexPallette(); this.datasets = this.datasets.map(set => { return { ...set, backgroundColor: [...hexColours, ...hexColours], borderColor: '#FFFFFF', hoverOffset: 4, datalabels: { anchor: 'center', borderWidth: 0, }, }; }); }; setBespokeOptions = () => { const cutout = this.datasets.length === 1 ? '50%' : '20%'; this.config = { ...this.config, cutout, }; }; } exports.DoughnutChart = DoughnutChart; exports.default = DoughnutChart; //# sourceMappingURL=DoughnutChart.js.map