@ministryofjustice/hmpps-digital-prison-reporting-frontend 4.20.1 → 4.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (166) hide show
  1. package/dpr/components/_async/async-filters-form/types.d.js +1 -1
  2. package/dpr/components/_async/async-filters-form/types.d.js.map +1 -1
  3. package/dpr/components/_async/async-filters-form/types.d.ts +7 -4
  4. package/dpr/components/_async/async-filters-form/utils.js +1 -1
  5. package/dpr/components/_async/async-filters-form/utils.js.map +2 -2
  6. package/dpr/components/_async/async-filters-form/utils.ts +18 -17
  7. package/dpr/components/_catalogue/catalogue-list/utils.test.ts +1 -1
  8. package/dpr/components/_charts/chart/Chart.js +2 -0
  9. package/dpr/components/_charts/chart/Chart.js.map +7 -0
  10. package/dpr/components/_charts/chart/Chart.ts +89 -0
  11. package/dpr/components/_charts/chart/ChartColours.js +2 -0
  12. package/dpr/components/_charts/chart/ChartColours.js.map +7 -0
  13. package/dpr/components/_charts/chart/ChartColours.ts +36 -0
  14. package/dpr/components/_charts/chart/ChartTimeseries.js +2 -0
  15. package/dpr/components/_charts/chart/ChartTimeseries.js.map +7 -0
  16. package/dpr/components/_charts/chart/ChartTimeseries.ts +95 -0
  17. package/dpr/components/_charts/chart/bar/BarChart.js +2 -0
  18. package/dpr/components/_charts/chart/bar/BarChart.js.map +7 -0
  19. package/dpr/components/_charts/chart/bar/BarChart.ts +204 -0
  20. package/dpr/components/_charts/chart/bar/clientClass.mjs +0 -58
  21. package/dpr/components/_charts/chart/bar/types.js +2 -0
  22. package/dpr/components/_charts/chart/bar/types.js.map +7 -0
  23. package/dpr/components/_charts/chart/bar/types.ts +6 -0
  24. package/dpr/components/_charts/chart/bar/validate.js +2 -0
  25. package/dpr/components/_charts/chart/bar/validate.js.map +7 -0
  26. package/dpr/components/_charts/chart/bar/validate.ts +59 -0
  27. package/dpr/components/_charts/chart/bar-timeseries/BarTimeseriesChart.js +2 -0
  28. package/dpr/components/_charts/chart/bar-timeseries/BarTimeseriesChart.js.map +7 -0
  29. package/dpr/components/_charts/chart/bar-timeseries/BarTimeseriesChart.ts +57 -0
  30. package/dpr/components/_charts/chart/bar-timeseries/types.js +2 -0
  31. package/dpr/components/_charts/chart/bar-timeseries/types.js.map +7 -0
  32. package/dpr/components/_charts/chart/bar-timeseries/types.ts +5 -0
  33. package/dpr/components/_charts/chart/bar-timeseries/validate.js +2 -0
  34. package/dpr/components/_charts/chart/bar-timeseries/validate.js.map +7 -0
  35. package/dpr/components/_charts/chart/bar-timeseries/validate.ts +30 -0
  36. package/dpr/components/_charts/chart/buckets/Buckets.js +2 -0
  37. package/dpr/components/_charts/chart/buckets/Buckets.js.map +7 -0
  38. package/dpr/components/_charts/chart/{Buckets.ts → buckets/Buckets.ts} +18 -14
  39. package/dpr/components/_charts/chart/buckets/types.js +2 -0
  40. package/dpr/components/_charts/chart/buckets/types.js.map +7 -0
  41. package/dpr/components/_charts/chart/buckets/types.ts +4 -0
  42. package/dpr/components/_charts/chart/buckets/validate.js +2 -0
  43. package/dpr/components/_charts/chart/buckets/validate.js.map +7 -0
  44. package/dpr/components/_charts/chart/buckets/validate.ts +15 -0
  45. package/dpr/components/_charts/chart/chart-config.js +2 -0
  46. package/dpr/components/_charts/chart/chart-config.js.map +7 -0
  47. package/dpr/components/_charts/chart/chart-config.ts +108 -0
  48. package/dpr/components/_charts/chart/clientClass.mjs +28 -106
  49. package/dpr/components/_charts/chart/doughnut/DoughnutChart.js +2 -0
  50. package/dpr/components/_charts/chart/doughnut/DoughnutChart.js.map +7 -0
  51. package/dpr/components/_charts/chart/doughnut/DoughnutChart.ts +77 -0
  52. package/dpr/components/_charts/chart/doughnut/clientClass.mjs +0 -45
  53. package/dpr/components/_charts/chart/doughnut/types.js +2 -0
  54. package/dpr/components/_charts/chart/doughnut/types.js.map +7 -0
  55. package/dpr/components/_charts/chart/doughnut/types.ts +5 -0
  56. package/dpr/components/_charts/chart/doughnut/validate.js +2 -0
  57. package/dpr/components/_charts/chart/doughnut/validate.js.map +7 -0
  58. package/dpr/components/_charts/chart/doughnut/validate.ts +30 -0
  59. package/dpr/components/_charts/chart/heatmap/HeatmapChart.js +1 -1
  60. package/dpr/components/_charts/chart/heatmap/HeatmapChart.js.map +3 -3
  61. package/dpr/components/_charts/chart/heatmap/HeatmapChart.ts +122 -44
  62. package/dpr/components/_charts/chart/heatmap/clientClass.mjs +7 -89
  63. package/dpr/components/_charts/chart/heatmap/types.js +1 -1
  64. package/dpr/components/_charts/chart/heatmap/types.js.map +1 -1
  65. package/dpr/components/_charts/chart/heatmap/types.ts +5 -0
  66. package/dpr/components/_charts/chart/heatmap/validate.js +2 -0
  67. package/dpr/components/_charts/chart/heatmap/validate.js.map +7 -0
  68. package/dpr/components/_charts/chart/heatmap/validate.ts +25 -0
  69. package/dpr/components/_charts/chart/line/LineChart.js +2 -0
  70. package/dpr/components/_charts/chart/line/LineChart.js.map +7 -0
  71. package/dpr/components/_charts/chart/line/LineChart.ts +89 -0
  72. package/dpr/components/_charts/chart/line/clientClass.mjs +5 -36
  73. package/dpr/components/_charts/chart/line/types.js +2 -0
  74. package/dpr/components/_charts/chart/line/types.js.map +7 -0
  75. package/dpr/components/_charts/chart/line/types.ts +5 -0
  76. package/dpr/components/_charts/chart/line/validate.js +2 -0
  77. package/dpr/components/_charts/chart/line/validate.js.map +7 -0
  78. package/dpr/components/_charts/chart/line/validate.ts +30 -0
  79. package/dpr/components/_charts/chart/line-timeseries/LineTimeseriesChart.js +2 -0
  80. package/dpr/components/_charts/chart/line-timeseries/LineTimeseriesChart.js.map +7 -0
  81. package/dpr/components/_charts/chart/line-timeseries/LineTimeseriesChart.ts +57 -0
  82. package/dpr/components/_charts/chart/line-timeseries/types.js +2 -0
  83. package/dpr/components/_charts/chart/line-timeseries/types.js.map +7 -0
  84. package/dpr/components/_charts/chart/line-timeseries/types.ts +5 -0
  85. package/dpr/components/_charts/chart/line-timeseries/validate.js +2 -0
  86. package/dpr/components/_charts/chart/line-timeseries/validate.js.map +7 -0
  87. package/dpr/components/_charts/chart/line-timeseries/validate.ts +30 -0
  88. package/dpr/components/_charts/chart/view.njk +8 -1
  89. package/dpr/components/_charts/chart-tabs/view.njk +15 -14
  90. package/dpr/components/_charts/utils.js +1 -1
  91. package/dpr/components/_charts/utils.js.map +3 -3
  92. package/dpr/components/_charts/utils.test.ts +9 -3
  93. package/dpr/components/_charts/utils.ts +59 -193
  94. package/dpr/components/_dashboards/dashboard-list/types.js +2 -0
  95. package/dpr/components/_dashboards/dashboard-list/types.js.map +7 -0
  96. package/dpr/components/_dashboards/dashboard-list/types.ts +4 -0
  97. package/dpr/components/_dashboards/dashboard-list/validate.js +2 -0
  98. package/dpr/components/_dashboards/dashboard-list/validate.js.map +7 -0
  99. package/dpr/components/_dashboards/dashboard-list/validate.ts +28 -0
  100. package/dpr/components/_dashboards/dashboard-visualisation/Validate.js +2 -0
  101. package/dpr/components/_dashboards/dashboard-visualisation/Validate.js.map +7 -0
  102. package/dpr/components/_dashboards/dashboard-visualisation/Validate.ts +71 -0
  103. package/dpr/components/_dashboards/dashboard-visualisation/types.js +1 -1
  104. package/dpr/components/_dashboards/dashboard-visualisation/types.js.map +2 -2
  105. package/dpr/components/_dashboards/dashboard-visualisation/types.ts +32 -2
  106. package/dpr/components/_dashboards/scorecard/Scorecard.js +1 -1
  107. package/dpr/components/_dashboards/scorecard/Scorecard.js.map +3 -3
  108. package/dpr/components/_dashboards/scorecard/Scorecard.ts +82 -213
  109. package/dpr/components/_dashboards/scorecard/types.js +1 -1
  110. package/dpr/components/_dashboards/scorecard/types.js.map +1 -1
  111. package/dpr/components/_dashboards/scorecard/types.ts +11 -1
  112. package/dpr/components/_dashboards/scorecard/validate.js +2 -0
  113. package/dpr/components/_dashboards/scorecard/validate.js.map +7 -0
  114. package/dpr/components/_dashboards/scorecard/validate.ts +36 -0
  115. package/dpr/components/_dashboards/scorecard-group/ScorecardGroup.js +2 -0
  116. package/dpr/components/_dashboards/scorecard-group/ScorecardGroup.js.map +7 -0
  117. package/dpr/components/_dashboards/scorecard-group/ScorecardGroup.ts +228 -0
  118. package/dpr/components/_dashboards/scorecard-group/types.js +2 -0
  119. package/dpr/components/_dashboards/scorecard-group/types.js.map +7 -0
  120. package/dpr/components/_dashboards/scorecard-group/types.ts +5 -0
  121. package/dpr/components/_dashboards/scorecard-group/validate.js +2 -0
  122. package/dpr/components/_dashboards/scorecard-group/validate.js.map +7 -0
  123. package/dpr/components/_dashboards/scorecard-group/validate.ts +37 -0
  124. package/dpr/components/_filters/filter-input/types.d.js.map +1 -1
  125. package/dpr/components/_filters/filter-input/types.d.ts +1 -1
  126. package/dpr/components/_filters/types.d.js.map +1 -1
  127. package/dpr/components/_filters/types.d.ts +6 -4
  128. package/dpr/components/_reports/report-actions/types.d.js.map +1 -1
  129. package/dpr/components/_reports/report-actions/types.d.ts +1 -1
  130. package/dpr/components/report-list/types.d.js.map +1 -1
  131. package/dpr/components/report-list/types.d.ts +1 -1
  132. package/dpr/data/types.d.js +1 -1
  133. package/dpr/data/types.d.js.map +1 -1
  134. package/dpr/data/types.d.ts +2 -1
  135. package/dpr/routes/journeys/view-report/async/dashboard/utils.js +1 -1
  136. package/dpr/routes/journeys/view-report/async/dashboard/utils.js.map +3 -3
  137. package/dpr/routes/journeys/view-report/async/dashboard/utils.ts +22 -10
  138. package/dpr/routes/journeys/view-report/async/report/utils.js +1 -1
  139. package/dpr/routes/journeys/view-report/async/report/utils.js.map +2 -2
  140. package/dpr/routes/journeys/view-report/async/report/utils.ts +1 -1
  141. package/dpr/routes/journeys/view-report/controller.js +1 -1
  142. package/dpr/routes/journeys/view-report/controller.js.map +3 -3
  143. package/dpr/routes/journeys/view-report/controller.ts +3 -1
  144. package/dpr/types/Services.d.js +1 -1
  145. package/dpr/types/Services.d.js.map +1 -1
  146. package/dpr/types/Services.d.ts +0 -2
  147. package/dpr/utils/DataTableBuilder/types.d.js +1 -1
  148. package/dpr/utils/DataTableBuilder/types.d.js.map +1 -1
  149. package/dpr/utils/DataTableBuilder/types.d.ts +2 -2
  150. package/dpr/utils/ErrorHandler.js +1 -1
  151. package/dpr/utils/ErrorHandler.js.map +3 -3
  152. package/dpr/utils/ErrorHandler.ts +16 -0
  153. package/dpr/utils/ParentChildDataTableBuilder/types.d.js +1 -1
  154. package/dpr/utils/ParentChildDataTableBuilder/types.d.js.map +1 -1
  155. package/dpr/utils/ParentChildDataTableBuilder/types.d.ts +1 -0
  156. package/dpr/utils/Personalisation/types.d.js +1 -1
  157. package/dpr/utils/Personalisation/types.d.js.map +1 -1
  158. package/dpr/utils/Personalisation/types.d.ts +1 -0
  159. package/dpr/utils/UserStoreItemBuilder.js.map +2 -2
  160. package/dpr/utils/UserStoreItemBuilder.ts +1 -1
  161. package/package.json +1 -1
  162. package/dpr/components/_charts/chart/Buckets.js +0 -2
  163. package/dpr/components/_charts/chart/Buckets.js.map +0 -7
  164. package/dpr/components/_dashboards/dashboard-visualisation/DashboardVisualisation.js +0 -2
  165. package/dpr/components/_dashboards/dashboard-visualisation/DashboardVisualisation.js.map +0 -7
  166. package/dpr/components/_dashboards/dashboard-visualisation/DashboardVisualisation.ts +0 -40
@@ -0,0 +1,204 @@
1
+ /* eslint-disable prefer-destructuring */
2
+ import { DashboardDataResponse } from '../../../../types/Metrics'
3
+ import {
4
+ DashboardVisualisationType,
5
+ DashboardVisualisationData,
6
+ DashboardVisualisationDataSet,
7
+ VisualisationDefinitionKey,
8
+ } from '../../../_dashboards/dashboard-visualisation/types'
9
+ import { components } from '../../../../types/api'
10
+ import DatasetHelper from '../../../../utils/datasetHelper'
11
+ import Chart from '../Chart'
12
+ import BarChartSchemas from './validate'
13
+ import { BarDefinitionMeasure, BarDefinitionOptions, BarDefinitionType } from './types'
14
+ import { ChartColours } from '../ChartColours'
15
+
16
+ class BarChart extends Chart {
17
+ private definition!: BarDefinitionType
18
+
19
+ private measures!: BarDefinitionMeasure[]
20
+
21
+ private keys!: VisualisationDefinitionKey[]
22
+
23
+ private options: BarDefinitionOptions | undefined
24
+
25
+ override responseData: DashboardDataResponse[] = []
26
+
27
+ private isList = false
28
+
29
+ override datasets: DashboardVisualisationDataSet[] = []
30
+
31
+ private groupsData: DashboardDataResponse[][] = []
32
+
33
+ private groupKey: BarDefinitionMeasure | undefined
34
+
35
+ private xAxisColumn: BarDefinitionMeasure | undefined
36
+
37
+ private yAxisColumn: BarDefinitionMeasure | undefined
38
+
39
+ private barCount = 0
40
+
41
+ withDefinition = (definition: components['schemas']['DashboardVisualisationDefinition']) => {
42
+ this.definition = BarChartSchemas.BarSchema.parse(definition)
43
+ this.initFromDefinitionData()
44
+
45
+ return this
46
+ }
47
+
48
+ override withData = (responseData: DashboardDataResponse[]) => {
49
+ this.responseData = responseData
50
+ if (this.isList) this.initListData()
51
+ return this
52
+ }
53
+
54
+ getCanvasHeight = () => {
55
+ this.barCount = this.datasets.length * this.datasets[0].data.length
56
+ return this.options?.horizontal ? this.barCount * 40 + 60 : 400
57
+ }
58
+
59
+ build = (): DashboardVisualisationData => {
60
+ if (!this.isList) {
61
+ this.getBarChartData()
62
+ } else {
63
+ this.getListBarChartData()
64
+ }
65
+ const height = this.getCanvasHeight()
66
+
67
+ return {
68
+ type: DashboardVisualisationType.BAR,
69
+ options: {
70
+ height,
71
+ unit: this.unit,
72
+ timeseries: false,
73
+ },
74
+ data: {
75
+ labels: this.labels,
76
+ datasets: this.datasets,
77
+ config: this.config,
78
+ },
79
+ }
80
+ }
81
+
82
+ augmentDataset = (datasets: DashboardVisualisationDataSet[]) => {
83
+ return datasets.map((set) => {
84
+ return {
85
+ ...set,
86
+ borderWidth: [0, 0],
87
+ datalabels: {
88
+ align: 'center',
89
+ anchor: 'bottom',
90
+ },
91
+ }
92
+ })
93
+ }
94
+
95
+ setBespokeOptions = () => {
96
+ let indexAxis = 'x'
97
+ let scales
98
+
99
+ if (this.options) {
100
+ const { horizontal, xStacked, yStacked } = this.options
101
+ indexAxis = horizontal ? 'y' : indexAxis
102
+ if (xStacked || yStacked) {
103
+ scales = {
104
+ ...(xStacked && { x: { stacked: xStacked } }),
105
+ ...(yStacked && { y: { stacked: yStacked } }),
106
+ }
107
+ }
108
+ }
109
+
110
+ return {
111
+ ...this.config,
112
+ indexAxis,
113
+ ...(scales && { scales }),
114
+ }
115
+ }
116
+
117
+ private getBarChartData = () => {
118
+ this.createDatasets(this.measures, this.responseData)
119
+ this.datasets = this.augmentDataset(this.datasets)
120
+ this.config = this.setBespokeOptions()
121
+ this.createLabels(this.measures)
122
+ }
123
+
124
+ private getListBarChartData = () => {
125
+ this.createListLabels()
126
+ this.createListDatasets()
127
+ this.datasets = this.augmentDataset(this.datasets)
128
+ this.config = this.setBespokeOptions()
129
+ }
130
+
131
+ private initFromDefinitionData = () => {
132
+ this.measures = this.definition.columns.measures
133
+ this.options = this.definition.options
134
+ this.keys = this.definition.columns.keys || []
135
+ this.isList = !!this.measures.find((col) => col.axis)
136
+ this.initUnit(this.measures)
137
+
138
+ if (!this.isList) this.getLabelId(this.keys)
139
+ }
140
+
141
+ private initListData = () => {
142
+ this.xAxisColumn = this.measures.find((col) => col.axis === 'x')
143
+ this.yAxisColumn = this.measures.find((col) => col.axis === 'y')
144
+ this.groupKey = <BarDefinitionMeasure>(
145
+ DatasetHelper.getGroupKey(
146
+ this.responseData,
147
+ <Array<components['schemas']['DashboardVisualisationColumnDefinition']>>this.keys,
148
+ )
149
+ )
150
+ this.groupsData = this.groupKey
151
+ ? DatasetHelper.groupRowsByKey(this.responseData, this.groupKey.id)
152
+ : [this.responseData]
153
+ }
154
+
155
+ private createListDatasets = () => {
156
+ this.hexColours = new ChartColours().getHexPallette()
157
+ this.datasets = this.groupsData.map((groupData, groupIndex) => {
158
+ const data = Array(this.labels.length)
159
+ groupData.forEach((row) => {
160
+ // Validation will ensure these columns exist
161
+ const yId = this.yAxisColumn?.id || ''
162
+ const xId = this.xAxisColumn?.id || ''
163
+
164
+ const labelField = row[xId]
165
+ const valueField = row[yId]
166
+
167
+ const raw = valueField && valueField.raw ? Number(valueField.raw) : 0
168
+ const dataIndex = this.labels.findIndex((l) => l === labelField.raw)
169
+ if (dataIndex !== -1) {
170
+ data[dataIndex] = Number(raw)
171
+ }
172
+ })
173
+
174
+ let label = ''
175
+ if (this.groupKey) {
176
+ const groupKeyId = this.groupKey.id
177
+ const groupRow = groupData[0]
178
+ label = groupRow && groupRow[groupKeyId] ? `${groupRow[groupKeyId].raw}` : ''
179
+ } else {
180
+ label = this.yAxisColumn?.display || label
181
+ }
182
+
183
+ return {
184
+ label,
185
+ data,
186
+ total: data.reduce((acc: number, val: number) => acc + val, 0),
187
+ ...this.setStyles(groupIndex),
188
+ }
189
+ })
190
+ }
191
+
192
+ private createListLabels = () => {
193
+ this.labels = this.groupsData.flatMap((gd) => {
194
+ const id = this.xAxisColumn?.id || ''
195
+ return gd.map((row) => {
196
+ const field = row[id]
197
+ return field ? `${field.raw}` : ''
198
+ })
199
+ })
200
+ }
201
+ }
202
+
203
+ export { BarChart }
204
+ export default BarChart
@@ -16,49 +16,8 @@ class BarChartVisualisation extends ChartVisualisation {
16
16
 
17
17
  initSettings() {
18
18
  return {
19
- options: this.setOptions(),
20
19
  toolTipOptions: this.setToolTipOptions(),
21
20
  datalabels: this.setDataLabels(),
22
- styling: this.setDatasetStyling(),
23
- }
24
- }
25
-
26
- setDatasetStyling() {
27
- const pallette = this.getColourPallette()
28
- return pallette.map((colour) => {
29
- return {
30
- borderColor: colour.hex,
31
- ...this.setBackgroundColour(colour.hex),
32
- datalabels: {
33
- align: 'center',
34
- anchor: 'center',
35
- },
36
- }
37
- })
38
- }
39
-
40
- setBackgroundColour(colour) {
41
- const lastIndex = this.chartParams.labels.length - 1
42
- const backgroundColors = []
43
- const borderWidths = []
44
- const borderColors = []
45
-
46
- this.chartParams.labels.forEach((label, i) => {
47
- if ((this.partialEnd && i === lastIndex) || (this.partialStart && i === 0)) {
48
- backgroundColors.push(colour)
49
- borderWidths.push(3)
50
- borderColors.push('#b1b4b6')
51
- } else {
52
- backgroundColors.push(colour)
53
- borderWidths.push(0)
54
- borderColors.push(colour)
55
- }
56
- })
57
-
58
- return {
59
- backgroundColor: backgroundColors,
60
- borderWidth: borderWidths,
61
- borderColor: borderColors,
62
21
  }
63
22
  }
64
23
 
@@ -83,23 +42,6 @@ class BarChartVisualisation extends ChartVisualisation {
83
42
  }
84
43
  }
85
44
 
86
- setOptions() {
87
- const { indexAxis, stacked } = this.chartParams
88
- return {
89
- indexAxis: indexAxis || 'x',
90
- ...(stacked && {
91
- scales: {
92
- x: {
93
- stacked: true,
94
- },
95
- y: {
96
- stacked: true,
97
- },
98
- },
99
- }),
100
- }
101
- }
102
-
103
45
  setDataLabels() {
104
46
  return {
105
47
  color: '#FFF',
@@ -0,0 +1,2 @@
1
+ "use strict";var i=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var h=Object.prototype.hasOwnProperty;var m=(r,e,o,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of f(e))!h.call(r,a)&&a!==o&&i(r,a,{get:()=>e[a],enumerable:!(t=p(e,a))||t.enumerable});return r};var n=r=>m(i({},"__esModule",{value:!0}),r);var B={};module.exports=n(B);
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../../src/dpr/components/_charts/chart/bar/types.ts"],
4
+ "sourcesContent": ["import z from 'zod'\nimport BarChartSchemas from './validate'\n\nexport type BarDefinitionType = z.infer<typeof BarChartSchemas.BarSchema>\nexport type BarDefinitionMeasure = z.infer<typeof BarChartSchemas.BarMeasureShema>\nexport type BarDefinitionOptions = z.infer<typeof BarChartSchemas.BarOptionsSchema>\n"],
5
+ "mappings": "+WAAA,IAAAA,EAAA,kBAAAC,EAAAD",
6
+ "names": ["types_exports", "__toCommonJS"]
7
+ }
@@ -0,0 +1,6 @@
1
+ import z from 'zod'
2
+ import BarChartSchemas from './validate'
3
+
4
+ export type BarDefinitionType = z.infer<typeof BarChartSchemas.BarSchema>
5
+ export type BarDefinitionMeasure = z.infer<typeof BarChartSchemas.BarMeasureShema>
6
+ export type BarDefinitionOptions = z.infer<typeof BarChartSchemas.BarOptionsSchema>
@@ -0,0 +1,2 @@
1
+ "use strict";var r=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var c=Object.prototype.hasOwnProperty;var x=(a,i)=>{for(var t in i)r(a,t,{get:i[t],enumerable:!0})},p=(a,i,t,o)=>{if(i&&typeof i=="object"||typeof i=="function")for(let n of u(i))!c.call(a,n)&&n!==t&&r(a,n,{get:()=>i[n],enumerable:!(o=f(i,n))||o.enumerable});return a};var h=a=>p(r({},"__esModule",{value:!0}),a);var S={};x(S,{default:()=>y});module.exports=h(S);var e=require("zod"),s=require("../../../_dashboards/dashboard-visualisation/Validate");const l=e.z.object({id:e.z.string(),display:e.z.string().optional(),unit:e.z.enum(["NUMBER","PERCENTAGE"]).optional(),axis:e.z.enum(["x","y"]).optional()}),d=e.z.object({showLatest:e.z.boolean().default(!0),horizontal:e.z.boolean().default(!1),xStacked:e.z.boolean().default(!1),yStacked:e.z.boolean().default(!1)}),m=e.z.object({...s.DashboardVisualisationSchema.shape,type:e.z.literal("bar"),display:e.z.string(),options:e.z.object(d.shape).optional(),columns:e.z.object({...s.DashboardColumns.shape,measures:e.z.array(l).refine(a=>{const i=a.find(n=>n.axis==="x"),t=a.find(n=>n.axis==="y");let o=!0;return(i!==void 0&&!t||t!==void 0&&!i)&&(o=!1),o},{error:"X and Y axis must be defined in measure"}).refine(a=>{const i=a.find(n=>n.axis==="x"),t=a.find(n=>n.axis==="y");let o=!0;return i!==void 0&&t!==void 0&&a.length>2&&(o=!1),o},{error:"Measure must contain only 2 items when axis is specified"})})}),b={BarSchema:m,BarMeasureShema:l,BarOptionsSchema:d};var y=b;
2
+ //# sourceMappingURL=validate.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../../src/dpr/components/_charts/chart/bar/validate.ts"],
4
+ "sourcesContent": ["import { z } from 'zod'\nimport { DashboardVisualisationSchema, DashboardColumns } from '../../../_dashboards/dashboard-visualisation/Validate'\n\nconst BarMeasureShema = z.object({\n id: z.string(),\n display: z.string().optional(),\n unit: z.enum(['NUMBER', 'PERCENTAGE']).optional(),\n axis: z.enum(['x', 'y']).optional(),\n})\n\nconst BarOptionsSchema = z.object({\n showLatest: z.boolean().default(true),\n horizontal: z.boolean().default(false),\n xStacked: z.boolean().default(false),\n yStacked: z.boolean().default(false),\n})\n\nconst BarSchema = z.object({\n ...DashboardVisualisationSchema.shape,\n type: z.literal('bar'),\n display: z.string(),\n options: z.object(BarOptionsSchema.shape).optional(),\n columns: z.object({\n ...DashboardColumns.shape,\n measures: z\n .array(BarMeasureShema)\n .refine(\n (measures) => {\n const xAxis = measures.find((m) => m.axis === 'x')\n const yAxis = measures.find((m) => m.axis === 'y')\n\n let valid = true\n if ((xAxis !== undefined && !yAxis) || (yAxis !== undefined && !xAxis)) {\n valid = false\n }\n return valid\n },\n { error: 'X and Y axis must be defined in measure' },\n )\n .refine(\n (measures) => {\n const xAxis = measures.find((m) => m.axis === 'x')\n const yAxis = measures.find((m) => m.axis === 'y')\n let valid = true\n if (xAxis !== undefined && yAxis !== undefined && measures.length > 2) valid = false\n return valid\n },\n { error: 'Measure must contain only 2 items when axis is specified' },\n ),\n }),\n})\n\nconst BarChartSchemas = {\n BarSchema,\n BarMeasureShema,\n BarOptionsSchema,\n}\n\nexport default BarChartSchemas\n"],
5
+ "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAkB,eAClBC,EAA+D,iEAE/D,MAAMC,EAAkB,IAAE,OAAO,CAC/B,GAAI,IAAE,OAAO,EACb,QAAS,IAAE,OAAO,EAAE,SAAS,EAC7B,KAAM,IAAE,KAAK,CAAC,SAAU,YAAY,CAAC,EAAE,SAAS,EAChD,KAAM,IAAE,KAAK,CAAC,IAAK,GAAG,CAAC,EAAE,SAAS,CACpC,CAAC,EAEKC,EAAmB,IAAE,OAAO,CAChC,WAAY,IAAE,QAAQ,EAAE,QAAQ,EAAI,EACpC,WAAY,IAAE,QAAQ,EAAE,QAAQ,EAAK,EACrC,SAAU,IAAE,QAAQ,EAAE,QAAQ,EAAK,EACnC,SAAU,IAAE,QAAQ,EAAE,QAAQ,EAAK,CACrC,CAAC,EAEKC,EAAY,IAAE,OAAO,CACzB,GAAG,+BAA6B,MAChC,KAAM,IAAE,QAAQ,KAAK,EACrB,QAAS,IAAE,OAAO,EAClB,QAAS,IAAE,OAAOD,EAAiB,KAAK,EAAE,SAAS,EACnD,QAAS,IAAE,OAAO,CAChB,GAAG,mBAAiB,MACpB,SAAU,IACP,MAAMD,CAAe,EACrB,OACEG,GAAa,CACZ,MAAMC,EAAQD,EAAS,KAAME,GAAMA,EAAE,OAAS,GAAG,EAC3CC,EAAQH,EAAS,KAAME,GAAMA,EAAE,OAAS,GAAG,EAEjD,IAAIE,EAAQ,GACZ,OAAKH,IAAU,QAAa,CAACE,GAAWA,IAAU,QAAa,CAACF,KAC9DG,EAAQ,IAEHA,CACT,EACA,CAAE,MAAO,yCAA0C,CACrD,EACC,OACEJ,GAAa,CACZ,MAAMC,EAAQD,EAAS,KAAME,GAAMA,EAAE,OAAS,GAAG,EAC3CC,EAAQH,EAAS,KAAME,GAAMA,EAAE,OAAS,GAAG,EACjD,IAAIE,EAAQ,GACZ,OAAIH,IAAU,QAAaE,IAAU,QAAaH,EAAS,OAAS,IAAGI,EAAQ,IACxEA,CACT,EACA,CAAE,MAAO,0DAA2D,CACtE,CACJ,CAAC,CACH,CAAC,EAEKC,EAAkB,CACtB,UAAAN,EACA,gBAAAF,EACA,iBAAAC,CACF,EAEA,IAAOL,EAAQY",
6
+ "names": ["validate_exports", "__export", "validate_default", "__toCommonJS", "import_zod", "import_Validate", "BarMeasureShema", "BarOptionsSchema", "BarSchema", "measures", "xAxis", "m", "yAxis", "valid", "BarChartSchemas"]
7
+ }
@@ -0,0 +1,59 @@
1
+ import { z } from 'zod'
2
+ import { DashboardVisualisationSchema, DashboardColumns } from '../../../_dashboards/dashboard-visualisation/Validate'
3
+
4
+ const BarMeasureShema = z.object({
5
+ id: z.string(),
6
+ display: z.string().optional(),
7
+ unit: z.enum(['NUMBER', 'PERCENTAGE']).optional(),
8
+ axis: z.enum(['x', 'y']).optional(),
9
+ })
10
+
11
+ const BarOptionsSchema = z.object({
12
+ showLatest: z.boolean().default(true),
13
+ horizontal: z.boolean().default(false),
14
+ xStacked: z.boolean().default(false),
15
+ yStacked: z.boolean().default(false),
16
+ })
17
+
18
+ const BarSchema = z.object({
19
+ ...DashboardVisualisationSchema.shape,
20
+ type: z.literal('bar'),
21
+ display: z.string(),
22
+ options: z.object(BarOptionsSchema.shape).optional(),
23
+ columns: z.object({
24
+ ...DashboardColumns.shape,
25
+ measures: z
26
+ .array(BarMeasureShema)
27
+ .refine(
28
+ (measures) => {
29
+ const xAxis = measures.find((m) => m.axis === 'x')
30
+ const yAxis = measures.find((m) => m.axis === 'y')
31
+
32
+ let valid = true
33
+ if ((xAxis !== undefined && !yAxis) || (yAxis !== undefined && !xAxis)) {
34
+ valid = false
35
+ }
36
+ return valid
37
+ },
38
+ { error: 'X and Y axis must be defined in measure' },
39
+ )
40
+ .refine(
41
+ (measures) => {
42
+ const xAxis = measures.find((m) => m.axis === 'x')
43
+ const yAxis = measures.find((m) => m.axis === 'y')
44
+ let valid = true
45
+ if (xAxis !== undefined && yAxis !== undefined && measures.length > 2) valid = false
46
+ return valid
47
+ },
48
+ { error: 'Measure must contain only 2 items when axis is specified' },
49
+ ),
50
+ }),
51
+ })
52
+
53
+ const BarChartSchemas = {
54
+ BarSchema,
55
+ BarMeasureShema,
56
+ BarOptionsSchema,
57
+ }
58
+
59
+ export default BarChartSchemas
@@ -0,0 +1,2 @@
1
+ "use strict";var u=Object.create;var r=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var B=Object.getOwnPropertyNames;var D=Object.getPrototypeOf,c=Object.prototype.hasOwnProperty;var C=(i,t)=>{for(var s in t)r(i,s,{get:t[s],enumerable:!0})},h=(i,t,s,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let e of B(t))!c.call(i,e)&&e!==s&&r(i,e,{get:()=>t[e],enumerable:!(a=f(t,e))||a.enumerable});return i};var o=(i,t,s)=>(s=i!=null?u(D(i)):{},h(t||!i||!i.__esModule?r(s,"default",{value:i,enumerable:!0}):s,i)),b=i=>h(r({},"__esModule",{value:!0}),i);var y={};C(y,{BarTimeseriesChart:()=>n,default:()=>T});module.exports=b(y);var m=require("../../../_dashboards/dashboard-visualisation/types"),d=o(require("./validate")),p=o(require("../ChartTimeseries")),l=o(require("../bar/BarChart"));class n extends p.default{constructor(){super(...arguments);this.BarChartBuilder=new l.default;this.withDefinition=s=>(this.definition=d.default.BarTimeseriesSchema.parse(s),this.initFromDefinition(this.definition),this);this.build=()=>(this.buildDatasets(),this.setStyles(),this.datasets=this.BarChartBuilder.augmentDataset(this.datasets),this.BarChartBuilder.setBespokeOptions(),{type:m.DashboardVisualisationType.BAR,options:{unit:this.unit,timeseries:!0},data:{labels:this.labels,datasets:this.datasets,config:this.config}});this.setStyles=()=>{this.datasets=this.datasets.map((s,a)=>{const e=this.hexColours[a];return{...s,backgroundColor:e,borderColor:e}})}}}var T=n;0&&(module.exports={BarTimeseriesChart});
2
+ //# sourceMappingURL=BarTimeseriesChart.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../../src/dpr/components/_charts/chart/bar-timeseries/BarTimeseriesChart.ts"],
4
+ "sourcesContent": ["/* eslint-disable prefer-destructuring */\nimport {\n DashboardVisualisationType,\n DashboardVisualisationData,\n} from '../../../_dashboards/dashboard-visualisation/types'\nimport { components } from '../../../../types/api'\nimport { BarTimeseriesDefinitionType } from './types'\nimport BarTimeseriesChartSchemas from './validate'\nimport TimeseriesChart from '../ChartTimeseries'\nimport BarChart from '../bar/BarChart'\n\nclass BarTimeseriesChart extends TimeseriesChart {\n private definition!: BarTimeseriesDefinitionType\n\n private BarChartBuilder: BarChart = new BarChart()\n\n withDefinition = (definition: components['schemas']['DashboardVisualisationDefinition']) => {\n this.definition = BarTimeseriesChartSchemas.BarTimeseriesSchema.parse(definition)\n this.initFromDefinition(this.definition)\n\n return this\n }\n\n build = (): DashboardVisualisationData => {\n this.buildDatasets()\n this.setStyles()\n this.datasets = this.BarChartBuilder.augmentDataset(this.datasets)\n this.BarChartBuilder.setBespokeOptions()\n\n return {\n type: DashboardVisualisationType.BAR,\n options: {\n unit: this.unit,\n timeseries: true,\n },\n data: {\n labels: this.labels,\n datasets: this.datasets,\n config: this.config,\n },\n }\n }\n\n private setStyles = () => {\n this.datasets = this.datasets.map((set, datasetIndex) => {\n const colour = this.hexColours[datasetIndex]\n return {\n ...set,\n backgroundColor: colour,\n borderColor: colour,\n }\n })\n }\n}\n\nexport { BarTimeseriesChart }\nexport default BarTimeseriesChart\n"],
5
+ "mappings": "0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,wBAAAE,EAAA,YAAAC,IAAA,eAAAC,EAAAJ,GACA,IAAAK,EAGO,8DAGPC,EAAsC,yBACtCC,EAA4B,iCAC5BC,EAAqB,8BAErB,MAAMN,UAA2B,EAAAO,OAAgB,CAAjD,kCAGE,KAAQ,gBAA4B,IAAI,EAAAC,QAExC,oBAAkBC,IAChB,KAAK,WAAa,EAAAC,QAA0B,oBAAoB,MAAMD,CAAU,EAChF,KAAK,mBAAmB,KAAK,UAAU,EAEhC,MAGT,WAAQ,KACN,KAAK,cAAc,EACnB,KAAK,UAAU,EACf,KAAK,SAAW,KAAK,gBAAgB,eAAe,KAAK,QAAQ,EACjE,KAAK,gBAAgB,kBAAkB,EAEhC,CACL,KAAM,6BAA2B,IACjC,QAAS,CACP,KAAM,KAAK,KACX,WAAY,EACd,EACA,KAAM,CACJ,OAAQ,KAAK,OACb,SAAU,KAAK,SACf,OAAQ,KAAK,MACf,CACF,GAGF,KAAQ,UAAY,IAAM,CACxB,KAAK,SAAW,KAAK,SAAS,IAAI,CAACE,EAAKC,IAAiB,CACvD,MAAMC,EAAS,KAAK,WAAWD,CAAY,EAC3C,MAAO,CACL,GAAGD,EACH,gBAAiBE,EACjB,YAAaA,CACf,CACF,CAAC,CACH,EACF,CAGA,IAAOZ,EAAQD",
6
+ "names": ["BarTimeseriesChart_exports", "__export", "BarTimeseriesChart", "BarTimeseriesChart_default", "__toCommonJS", "import_types", "import_validate", "import_ChartTimeseries", "import_BarChart", "TimeseriesChart", "BarChart", "definition", "BarTimeseriesChartSchemas", "set", "datasetIndex", "colour"]
7
+ }
@@ -0,0 +1,57 @@
1
+ /* eslint-disable prefer-destructuring */
2
+ import {
3
+ DashboardVisualisationType,
4
+ DashboardVisualisationData,
5
+ } from '../../../_dashboards/dashboard-visualisation/types'
6
+ import { components } from '../../../../types/api'
7
+ import { BarTimeseriesDefinitionType } from './types'
8
+ import BarTimeseriesChartSchemas from './validate'
9
+ import TimeseriesChart from '../ChartTimeseries'
10
+ import BarChart from '../bar/BarChart'
11
+
12
+ class BarTimeseriesChart extends TimeseriesChart {
13
+ private definition!: BarTimeseriesDefinitionType
14
+
15
+ private BarChartBuilder: BarChart = new BarChart()
16
+
17
+ withDefinition = (definition: components['schemas']['DashboardVisualisationDefinition']) => {
18
+ this.definition = BarTimeseriesChartSchemas.BarTimeseriesSchema.parse(definition)
19
+ this.initFromDefinition(this.definition)
20
+
21
+ return this
22
+ }
23
+
24
+ build = (): DashboardVisualisationData => {
25
+ this.buildDatasets()
26
+ this.setStyles()
27
+ this.datasets = this.BarChartBuilder.augmentDataset(this.datasets)
28
+ this.BarChartBuilder.setBespokeOptions()
29
+
30
+ return {
31
+ type: DashboardVisualisationType.BAR,
32
+ options: {
33
+ unit: this.unit,
34
+ timeseries: true,
35
+ },
36
+ data: {
37
+ labels: this.labels,
38
+ datasets: this.datasets,
39
+ config: this.config,
40
+ },
41
+ }
42
+ }
43
+
44
+ private setStyles = () => {
45
+ this.datasets = this.datasets.map((set, datasetIndex) => {
46
+ const colour = this.hexColours[datasetIndex]
47
+ return {
48
+ ...set,
49
+ backgroundColor: colour,
50
+ borderColor: colour,
51
+ }
52
+ })
53
+ }
54
+ }
55
+
56
+ export { BarTimeseriesChart }
57
+ export default BarTimeseriesChart
@@ -0,0 +1,2 @@
1
+ "use strict";var a=Object.defineProperty;var t=Object.getOwnPropertyDescriptor;var o=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var f=(r,e,m,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of o(e))!p.call(r,i)&&i!==m&&a(r,i,{get:()=>e[i],enumerable:!(s=t(e,i))||s.enumerable});return r};var h=r=>f(a({},"__esModule",{value:!0}),r);var T={};module.exports=h(T);
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../../src/dpr/components/_charts/chart/bar-timeseries/types.ts"],
4
+ "sourcesContent": ["import z from 'zod'\nimport BarTimeseriesChartSchemas from './validate'\n\nexport type BarTimeseriesDefinitionType = z.infer<typeof BarTimeseriesChartSchemas.BarTimeseriesSchema>\nexport type BarTimeseriesDefinitionMeasure = z.infer<typeof BarTimeseriesChartSchemas.BarTimeseriesMeasureSchema>\n"],
5
+ "mappings": "+WAAA,IAAAA,EAAA,kBAAAC,EAAAD",
6
+ "names": ["types_exports", "__toCommonJS"]
7
+ }
@@ -0,0 +1,5 @@
1
+ import z from 'zod'
2
+ import BarTimeseriesChartSchemas from './validate'
3
+
4
+ export type BarTimeseriesDefinitionType = z.infer<typeof BarTimeseriesChartSchemas.BarTimeseriesSchema>
5
+ export type BarTimeseriesDefinitionMeasure = z.infer<typeof BarTimeseriesChartSchemas.BarTimeseriesMeasureSchema>
@@ -0,0 +1,2 @@
1
+ "use strict";var r=Object.defineProperty;var c=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var h=(a,s)=>{for(var i in s)r(a,i,{get:s[i],enumerable:!0})},u=(a,s,i,n)=>{if(s&&typeof s=="object"||typeof s=="function")for(let t of l(s))!p.call(a,t)&&t!==i&&r(a,t,{get:()=>s[t],enumerable:!(n=c(s,t))||n.enumerable});return a};var b=a=>u(r({},"__esModule",{value:!0}),a);var f={};h(f,{default:()=>T});module.exports=b(f);var e=require("zod"),o=require("../../../_dashboards/dashboard-visualisation/Validate");const m=e.z.object({id:e.z.string(),display:e.z.string().optional(),unit:e.z.enum(["NUMBER","PERCENTAGE"]).optional()}),d=e.z.object({showLatest:e.z.literal(!1)}),j=e.z.object({...o.DashboardVisualisationSchema.shape,display:e.z.string(),type:e.z.literal("bar-timeseries"),options:e.z.object(d.shape).optional(),columns:e.z.object({...o.DashboardColumns.shape,measures:e.z.array(m).min(1,"Measure must contain at least one item")})}),B={BarTimeseriesMeasureSchema:m,BarTimeseriesSchema:j};var T=B;
2
+ //# sourceMappingURL=validate.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../../src/dpr/components/_charts/chart/bar-timeseries/validate.ts"],
4
+ "sourcesContent": ["import { z } from 'zod'\nimport { DashboardVisualisationSchema, DashboardColumns } from '../../../_dashboards/dashboard-visualisation/Validate'\n\nconst BarTimeseriesMeasureSchema = z.object({\n id: z.string(),\n display: z.string().optional(),\n unit: z.enum(['NUMBER', 'PERCENTAGE']).optional(),\n})\n\nconst BarTimeseriesOptions = z.object({\n showLatest: z.literal(false),\n})\n\nconst BarTimeseriesSchema = z.object({\n ...DashboardVisualisationSchema.shape,\n display: z.string(),\n type: z.literal('bar-timeseries'),\n options: z.object(BarTimeseriesOptions.shape).optional(),\n columns: z.object({\n ...DashboardColumns.shape,\n measures: z.array(BarTimeseriesMeasureSchema).min(1, 'Measure must contain at least one item'),\n }),\n})\n\nconst BarTimeseriesChartSchemas = {\n BarTimeseriesMeasureSchema,\n BarTimeseriesSchema,\n}\n\nexport default BarTimeseriesChartSchemas\n"],
5
+ "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAkB,eAClBC,EAA+D,iEAE/D,MAAMC,EAA6B,IAAE,OAAO,CAC1C,GAAI,IAAE,OAAO,EACb,QAAS,IAAE,OAAO,EAAE,SAAS,EAC7B,KAAM,IAAE,KAAK,CAAC,SAAU,YAAY,CAAC,EAAE,SAAS,CAClD,CAAC,EAEKC,EAAuB,IAAE,OAAO,CACpC,WAAY,IAAE,QAAQ,EAAK,CAC7B,CAAC,EAEKC,EAAsB,IAAE,OAAO,CACnC,GAAG,+BAA6B,MAChC,QAAS,IAAE,OAAO,EAClB,KAAM,IAAE,QAAQ,gBAAgB,EAChC,QAAS,IAAE,OAAOD,EAAqB,KAAK,EAAE,SAAS,EACvD,QAAS,IAAE,OAAO,CAChB,GAAG,mBAAiB,MACpB,SAAU,IAAE,MAAMD,CAA0B,EAAE,IAAI,EAAG,wCAAwC,CAC/F,CAAC,CACH,CAAC,EAEKG,EAA4B,CAChC,2BAAAH,EACA,oBAAAE,CACF,EAEA,IAAON,EAAQO",
6
+ "names": ["validate_exports", "__export", "validate_default", "__toCommonJS", "import_zod", "import_Validate", "BarTimeseriesMeasureSchema", "BarTimeseriesOptions", "BarTimeseriesSchema", "BarTimeseriesChartSchemas"]
7
+ }
@@ -0,0 +1,30 @@
1
+ import { z } from 'zod'
2
+ import { DashboardVisualisationSchema, DashboardColumns } from '../../../_dashboards/dashboard-visualisation/Validate'
3
+
4
+ const BarTimeseriesMeasureSchema = z.object({
5
+ id: z.string(),
6
+ display: z.string().optional(),
7
+ unit: z.enum(['NUMBER', 'PERCENTAGE']).optional(),
8
+ })
9
+
10
+ const BarTimeseriesOptions = z.object({
11
+ showLatest: z.literal(false),
12
+ })
13
+
14
+ const BarTimeseriesSchema = z.object({
15
+ ...DashboardVisualisationSchema.shape,
16
+ display: z.string(),
17
+ type: z.literal('bar-timeseries'),
18
+ options: z.object(BarTimeseriesOptions.shape).optional(),
19
+ columns: z.object({
20
+ ...DashboardColumns.shape,
21
+ measures: z.array(BarTimeseriesMeasureSchema).min(1, 'Measure must contain at least one item'),
22
+ }),
23
+ })
24
+
25
+ const BarTimeseriesChartSchemas = {
26
+ BarTimeseriesMeasureSchema,
27
+ BarTimeseriesSchema,
28
+ }
29
+
30
+ export default BarTimeseriesChartSchemas
@@ -0,0 +1,2 @@
1
+ "use strict";var m=Object.create;var h=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var C=Object.getPrototypeOf,d=Object.prototype.hasOwnProperty;var g=(o,t)=>{for(var e in t)h(o,e,{get:t[e],enumerable:!0})},l=(o,t,e,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of b(t))!d.call(o,i)&&i!==e&&h(o,i,{get:()=>t[i],enumerable:!(s=f(t,i))||s.enumerable});return o};var B=(o,t,e)=>(e=o!=null?m(C(o)):{},l(t||!o||!o.__esModule?h(e,"default",{value:o,enumerable:!0}):e,o)),D=o=>l(h({},"__esModule",{value:!0}),o);var y={};g(y,{Buckets:()=>c,default:()=>v});module.exports=D(y);var p=require("with-alpha-hex"),k=B(require("./validate"));class c{constructor(t,e,s,i,r){this.baseColour="#1d70b8";this.ragColours=["#00703c","#ffdd00","#d4351c"];this.buckets=[];this.useRagColour=!1;this.bucketCount=0;this.onlyBucketColoursDefined=!1;this.autoBucketing=!1;this.hasRagScore=!1;this.initFromOptions=t=>{this.options=k.default.parse(t.options),this.baseColour=this.options?.baseColour||this.baseColour,this.useRagColour=this.options?.useRagColour||!1,this.onlyBucketColoursDefined=this.options&&this.options.buckets?this.options?.buckets?.every(e=>!e.max&&!e.min&&e.hexColour!==void 0):!1};this.initBuckets=()=>{const{buckets:t}=this.options;this.setBucketCount(),this.initBucketColours(),t&&t.length?this.hasRagScore?this.onlyBucketColoursDefined&&(this.buckets=t):!this.hasRagScore&&this.onlyBucketColoursDefined&&this.autoBucketing?this.initAutomaticThresholdBucket():this.initCustomThresholdBuckets():!this.hasRagScore&&this.autoBucketing&&this.initAutomaticThresholdBucket()};this.initCustomThresholdBuckets=()=>{this.buckets=this.options.buckets?this.options.buckets.map((t,e)=>({...this.buckets[e],...t})):[]};this.initAutomaticThresholdBucket=()=>{const{min:t,max:e,bucketSize:s}=this.setAutomaticThresholdSize();let i=0;this.buckets=this.buckets.map((r,u)=>{let n=t;return u!==0&&(n=i+1),i=s*(u+1)+t,u===this.buckets.length-1&&(i=e),{hexColour:this.options?.buckets&&this.options?.buckets.length?this.options.buckets[u]?.hexColour:r.hexColour,min:n,max:i}})};this.initBucketColours=()=>{if(this.useRagColour&&this.bucketCount===3)this.buckets=Array.from(new Array(this.bucketCount)).map((t,e)=>({hexColour:this.ragColours[e]}));else{const t=1/this.bucketCount;this.buckets=Array.from(new Array(this.bucketCount)).map((e,s)=>{const i=t*(s+1);return{hexColour:(0,p.withAlphaHex)(this.baseColour,i)}})}};this.setAutomaticThresholdSize=()=>{const t=this.responseData.map(r=>Number(r[this.valueKey].raw)),e=Math.min(...t),s=Math.max(...t),i=Math.ceil((s-e)/this.bucketCount);return{min:e,max:s,bucketSize:i}};this.setBucketCount=()=>{const{buckets:t}=this.options;if(this.hasRagScore)if(this.useRagColour)this.bucketCount=3;else{const e=this.responseData.reduce((s,i)=>(i[this.valueKey].rag!==void 0&&s.push(i[this.valueKey].rag),s),[]);this.bucketCount=Math.max(...e)+1}else t&&t.length?this.bucketCount=t.length:this.bucketCount=3};this.getBucketForValue=(t,e)=>{let s="",i=0;return e!==void 0?{colour:this.buckets[e].hexColour||s,score:e}:(this.buckets.forEach((r,u)=>{const{min:n,max:a}=r;!n&&a&&t<=a&&(s=r.hexColour||s,i=u),n&&t>=n&&a&&t<=a&&(s=r.hexColour||s,i=u),n&&!a&&t>=n&&(s=r.hexColour||s,i=u)}),{colour:s,score:i})};this.getBuckets=()=>this.buckets;this.responseData=t,this.initFromOptions(e),this.valueKey=s,this.hasRagScore=t[0][this.valueKey].rag!==void 0,this.autoBucketing=!!i,r&&(this.ragColours=r),this.initBuckets()}}var v=c;0&&(module.exports={Buckets});
2
+ //# sourceMappingURL=Buckets.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../../src/dpr/components/_charts/chart/buckets/Buckets.ts"],
4
+ "sourcesContent": ["/* eslint-disable prefer-destructuring */\nimport { withAlphaHex } from 'with-alpha-hex'\nimport { ScorecardDefinitionType } from '../../../_dashboards/scorecard/types'\nimport { ScorecardGroupDefinitionType } from '../../../_dashboards/scorecard-group/types'\nimport { DashboardDataResponse } from '../../../../types/Metrics'\nimport { DashboardVisualisationBucket } from '../../../_dashboards/dashboard-visualisation/types'\nimport { MatrixTimeseriesDefinitionType } from '../heatmap/types'\nimport BucketOptionsSchema from './validate'\nimport { BucketOptionsDefinition } from './types'\n\ntype DefinitionsWithBuckets = MatrixTimeseriesDefinitionType | ScorecardGroupDefinitionType | ScorecardDefinitionType\n\nclass Buckets {\n private baseColour = '#1d70b8'\n\n private ragColours: string[] = ['#00703c', '#ffdd00', '#d4351c']\n\n private buckets: DashboardVisualisationBucket[] = []\n\n private useRagColour = false\n\n private bucketCount = 0\n\n private onlyBucketColoursDefined = false\n\n private autoBucketing = false\n\n private hasRagScore = false\n\n private valueKey: string\n\n private options!: BucketOptionsDefinition\n\n responseData: DashboardDataResponse[]\n\n constructor(\n responseData: DashboardDataResponse[],\n definition: DefinitionsWithBuckets,\n valueKey: string,\n autoBucketing?: boolean,\n ragColours?: string[],\n ) {\n this.responseData = responseData\n this.initFromOptions(definition)\n this.valueKey = valueKey\n this.hasRagScore = responseData[0][this.valueKey].rag !== undefined\n this.autoBucketing = Boolean(autoBucketing)\n if (ragColours) this.ragColours = ragColours\n this.initBuckets()\n }\n\n private initFromOptions = (definition: DefinitionsWithBuckets) => {\n this.options = BucketOptionsSchema.parse(definition.options)\n this.baseColour = this.options?.baseColour || this.baseColour\n this.useRagColour = this.options?.useRagColour || false\n this.onlyBucketColoursDefined =\n this.options && this.options.buckets\n ? this.options?.buckets?.every((bucket) => !bucket.max && !bucket.min && bucket.hexColour !== undefined)\n : false\n }\n\n private initBuckets = () => {\n const { buckets } = this.options\n\n this.setBucketCount()\n this.initBucketColours()\n\n if (buckets && buckets.length) {\n if (this.hasRagScore) {\n if (this.onlyBucketColoursDefined) {\n this.buckets = buckets\n }\n } else if (!this.hasRagScore && this.onlyBucketColoursDefined && this.autoBucketing) {\n this.initAutomaticThresholdBucket()\n } else {\n this.initCustomThresholdBuckets()\n }\n } else if (!this.hasRagScore && this.autoBucketing) {\n this.initAutomaticThresholdBucket()\n }\n }\n\n private initCustomThresholdBuckets = () => {\n this.buckets = this.options.buckets\n ? this.options.buckets.map((bucket, i) => {\n return {\n ...this.buckets[i],\n ...bucket,\n }\n })\n : []\n }\n\n /**\n * Initialises the bucket thresholds by defining the range between the min and max\n * and dividing into 3 equal parts\n */\n private initAutomaticThresholdBucket = () => {\n const { min, max, bucketSize } = this.setAutomaticThresholdSize()\n let maxValue = 0\n this.buckets = this.buckets.map((bucket, i) => {\n let minValue = min\n if (i !== 0) minValue = maxValue + 1\n maxValue = bucketSize * (i + 1) + min\n if (i === this.buckets.length - 1) maxValue = max\n\n return {\n hexColour:\n this.options?.buckets && this.options?.buckets.length ? this.options.buckets[i]?.hexColour : bucket.hexColour,\n min: minValue,\n max: maxValue,\n }\n })\n }\n\n private initBucketColours = () => {\n if (this.useRagColour && this.bucketCount === 3) {\n this.buckets = Array.from(new Array(this.bucketCount)).map((_d, i) => {\n return {\n hexColour: this.ragColours[i],\n }\n })\n } else {\n const alphaDivision = 1 / this.bucketCount\n this.buckets = Array.from(new Array(this.bucketCount)).map((_d, i) => {\n const division = alphaDivision * (i + 1)\n return {\n hexColour: withAlphaHex(this.baseColour, division),\n }\n })\n }\n }\n\n private setAutomaticThresholdSize = () => {\n const values = this.responseData.map((resData) => Number(resData[this.valueKey].raw))\n const min = Math.min(...values)\n const max = Math.max(...values)\n const bucketSize = Math.ceil((max - min) / this.bucketCount)\n\n return {\n min,\n max,\n bucketSize,\n }\n }\n\n private setBucketCount = () => {\n const { buckets } = this.options\n if (this.hasRagScore) {\n if (this.useRagColour) {\n this.bucketCount = 3\n } else {\n const allRags: number[] = this.responseData.reduce((acc: number[], resData: DashboardDataResponse) => {\n if (resData[this.valueKey].rag !== undefined) {\n acc.push(<number>resData[this.valueKey].rag)\n }\n return acc\n }, [])\n this.bucketCount = Math.max(...allRags) + 1\n }\n } else if (buckets && buckets.length) {\n this.bucketCount = buckets.length\n } else {\n this.bucketCount = 3\n }\n }\n\n getBucketForValue = (value: number, ragScore?: number): { colour: string; score: number } => {\n let colour = ''\n let score = 0\n\n if (ragScore !== undefined) {\n return {\n colour: this.buckets[ragScore].hexColour || colour,\n score: ragScore,\n }\n }\n\n this.buckets.forEach((bucket, index) => {\n const { min, max } = bucket\n // First bucket\n if (!min && max && value <= max) {\n colour = bucket.hexColour || colour\n score = index\n }\n // middle buckets\n if (min && value >= min && max && value <= max) {\n colour = bucket.hexColour || colour\n score = index\n }\n // last bucket\n if (min && !max && value >= min) {\n colour = bucket.hexColour || colour\n score = index\n }\n })\n\n return {\n colour,\n score,\n }\n }\n\n getBuckets = () => {\n return this.buckets\n }\n}\n\nexport { Buckets }\nexport default Buckets\n"],
5
+ "mappings": "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",
6
+ "names": ["Buckets_exports", "__export", "Buckets", "Buckets_default", "__toCommonJS", "import_with_alpha_hex", "import_validate", "responseData", "definition", "valueKey", "autoBucketing", "ragColours", "BucketOptionsSchema", "bucket", "buckets", "i", "min", "max", "bucketSize", "maxValue", "minValue", "_d", "alphaDivision", "division", "values", "resData", "allRags", "acc", "value", "ragScore", "colour", "score", "index"]
7
+ }
@@ -1,11 +1,14 @@
1
1
  /* eslint-disable prefer-destructuring */
2
2
  import { withAlphaHex } from 'with-alpha-hex'
3
- import { DashboardDataResponse } from '../../../types/Metrics'
4
- import {
5
- DashboardVisualisationBucket,
6
- BucketDashboardVisualisationOptions,
7
- } from '../../_dashboards/dashboard-visualisation/types'
8
- import { components } from '../../../types/api'
3
+ import { ScorecardDefinitionType } from '../../../_dashboards/scorecard/types'
4
+ import { ScorecardGroupDefinitionType } from '../../../_dashboards/scorecard-group/types'
5
+ import { DashboardDataResponse } from '../../../../types/Metrics'
6
+ import { DashboardVisualisationBucket } from '../../../_dashboards/dashboard-visualisation/types'
7
+ import { MatrixTimeseriesDefinitionType } from '../heatmap/types'
8
+ import BucketOptionsSchema from './validate'
9
+ import { BucketOptionsDefinition } from './types'
10
+
11
+ type DefinitionsWithBuckets = MatrixTimeseriesDefinitionType | ScorecardGroupDefinitionType | ScorecardDefinitionType
9
12
 
10
13
  class Buckets {
11
14
  private baseColour = '#1d70b8'
@@ -26,13 +29,13 @@ class Buckets {
26
29
 
27
30
  private valueKey: string
28
31
 
29
- private options: BucketDashboardVisualisationOptions = {}
32
+ private options!: BucketOptionsDefinition
30
33
 
31
34
  responseData: DashboardDataResponse[]
32
35
 
33
36
  constructor(
34
37
  responseData: DashboardDataResponse[],
35
- definition: components['schemas']['DashboardVisualisationDefinition'],
38
+ definition: DefinitionsWithBuckets,
36
39
  valueKey: string,
37
40
  autoBucketing?: boolean,
38
41
  ragColours?: string[],
@@ -46,8 +49,8 @@ class Buckets {
46
49
  this.initBuckets()
47
50
  }
48
51
 
49
- private initFromOptions = (definition: components['schemas']['DashboardVisualisationDefinition']) => {
50
- this.options = <BucketDashboardVisualisationOptions>definition.options || {}
52
+ private initFromOptions = (definition: DefinitionsWithBuckets) => {
53
+ this.options = BucketOptionsSchema.parse(definition.options)
51
54
  this.baseColour = this.options?.baseColour || this.baseColour
52
55
  this.useRagColour = this.options?.useRagColour || false
53
56
  this.onlyBucketColoursDefined =
@@ -62,7 +65,7 @@ class Buckets {
62
65
  this.setBucketCount()
63
66
  this.initBucketColours()
64
67
 
65
- if (buckets) {
68
+ if (buckets && buckets.length) {
66
69
  if (this.hasRagScore) {
67
70
  if (this.onlyBucketColoursDefined) {
68
71
  this.buckets = buckets
@@ -72,7 +75,7 @@ class Buckets {
72
75
  } else {
73
76
  this.initCustomThresholdBuckets()
74
77
  }
75
- } else if (!buckets && !this.hasRagScore && this.autoBucketing) {
78
+ } else if (!this.hasRagScore && this.autoBucketing) {
76
79
  this.initAutomaticThresholdBucket()
77
80
  }
78
81
  }
@@ -102,7 +105,8 @@ class Buckets {
102
105
  if (i === this.buckets.length - 1) maxValue = max
103
106
 
104
107
  return {
105
- hexColour: this.options?.buckets ? this.options.buckets[i]?.hexColour : bucket.hexColour,
108
+ hexColour:
109
+ this.options?.buckets && this.options?.buckets.length ? this.options.buckets[i]?.hexColour : bucket.hexColour,
106
110
  min: minValue,
107
111
  max: maxValue,
108
112
  }
@@ -154,7 +158,7 @@ class Buckets {
154
158
  }, [])
155
159
  this.bucketCount = Math.max(...allRags) + 1
156
160
  }
157
- } else if (buckets) {
161
+ } else if (buckets && buckets.length) {
158
162
  this.bucketCount = buckets.length
159
163
  } else {
160
164
  this.bucketCount = 3
@@ -0,0 +1,2 @@
1
+ "use strict";var p=Object.defineProperty;var n=Object.getOwnPropertyDescriptor;var r=Object.getOwnPropertyNames;var c=Object.prototype.hasOwnProperty;var f=(e,t,m,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of r(t))!c.call(e,o)&&o!==m&&p(e,o,{get:()=>t[o],enumerable:!(i=n(t,o))||i.enumerable});return e};var k=e=>f(p({},"__esModule",{value:!0}),e);var s={};module.exports=k(s);
2
+ //# sourceMappingURL=types.js.map