@ministryofjustice/hmpps-digital-prison-reporting-frontend 4.20.2 → 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 (134) hide show
  1. package/dpr/components/_catalogue/catalogue-list/utils.test.ts +1 -1
  2. package/dpr/components/_charts/chart/Chart.js +2 -0
  3. package/dpr/components/_charts/chart/Chart.js.map +7 -0
  4. package/dpr/components/_charts/chart/Chart.ts +89 -0
  5. package/dpr/components/_charts/chart/ChartColours.js +2 -0
  6. package/dpr/components/_charts/chart/ChartColours.js.map +7 -0
  7. package/dpr/components/_charts/chart/ChartColours.ts +36 -0
  8. package/dpr/components/_charts/chart/ChartTimeseries.js +2 -0
  9. package/dpr/components/_charts/chart/ChartTimeseries.js.map +7 -0
  10. package/dpr/components/_charts/chart/ChartTimeseries.ts +95 -0
  11. package/dpr/components/_charts/chart/bar/BarChart.js +2 -0
  12. package/dpr/components/_charts/chart/bar/BarChart.js.map +7 -0
  13. package/dpr/components/_charts/chart/bar/BarChart.ts +204 -0
  14. package/dpr/components/_charts/chart/bar/clientClass.mjs +0 -58
  15. package/dpr/components/_charts/chart/bar/types.js +2 -0
  16. package/dpr/components/_charts/chart/bar/types.js.map +7 -0
  17. package/dpr/components/_charts/chart/bar/types.ts +6 -0
  18. package/dpr/components/_charts/chart/bar/validate.js +2 -0
  19. package/dpr/components/_charts/chart/bar/validate.js.map +7 -0
  20. package/dpr/components/_charts/chart/bar/validate.ts +59 -0
  21. package/dpr/components/_charts/chart/bar-timeseries/BarTimeseriesChart.js +2 -0
  22. package/dpr/components/_charts/chart/bar-timeseries/BarTimeseriesChart.js.map +7 -0
  23. package/dpr/components/_charts/chart/bar-timeseries/BarTimeseriesChart.ts +57 -0
  24. package/dpr/components/_charts/chart/bar-timeseries/types.js +2 -0
  25. package/dpr/components/_charts/chart/bar-timeseries/types.js.map +7 -0
  26. package/dpr/components/_charts/chart/bar-timeseries/types.ts +5 -0
  27. package/dpr/components/_charts/chart/bar-timeseries/validate.js +2 -0
  28. package/dpr/components/_charts/chart/bar-timeseries/validate.js.map +7 -0
  29. package/dpr/components/_charts/chart/bar-timeseries/validate.ts +30 -0
  30. package/dpr/components/_charts/chart/buckets/Buckets.js +2 -0
  31. package/dpr/components/_charts/chart/buckets/Buckets.js.map +7 -0
  32. package/dpr/components/_charts/chart/{Buckets.ts → buckets/Buckets.ts} +18 -14
  33. package/dpr/components/_charts/chart/buckets/types.js +2 -0
  34. package/dpr/components/_charts/chart/buckets/types.js.map +7 -0
  35. package/dpr/components/_charts/chart/buckets/types.ts +4 -0
  36. package/dpr/components/_charts/chart/buckets/validate.js +2 -0
  37. package/dpr/components/_charts/chart/buckets/validate.js.map +7 -0
  38. package/dpr/components/_charts/chart/buckets/validate.ts +15 -0
  39. package/dpr/components/_charts/chart/chart-config.js +2 -0
  40. package/dpr/components/_charts/chart/chart-config.js.map +7 -0
  41. package/dpr/components/_charts/chart/chart-config.ts +108 -0
  42. package/dpr/components/_charts/chart/clientClass.mjs +28 -106
  43. package/dpr/components/_charts/chart/doughnut/DoughnutChart.js +2 -0
  44. package/dpr/components/_charts/chart/doughnut/DoughnutChart.js.map +7 -0
  45. package/dpr/components/_charts/chart/doughnut/DoughnutChart.ts +77 -0
  46. package/dpr/components/_charts/chart/doughnut/clientClass.mjs +0 -45
  47. package/dpr/components/_charts/chart/doughnut/types.js +2 -0
  48. package/dpr/components/_charts/chart/doughnut/types.js.map +7 -0
  49. package/dpr/components/_charts/chart/doughnut/types.ts +5 -0
  50. package/dpr/components/_charts/chart/doughnut/validate.js +2 -0
  51. package/dpr/components/_charts/chart/doughnut/validate.js.map +7 -0
  52. package/dpr/components/_charts/chart/doughnut/validate.ts +30 -0
  53. package/dpr/components/_charts/chart/heatmap/HeatmapChart.js +1 -1
  54. package/dpr/components/_charts/chart/heatmap/HeatmapChart.js.map +3 -3
  55. package/dpr/components/_charts/chart/heatmap/HeatmapChart.ts +122 -44
  56. package/dpr/components/_charts/chart/heatmap/clientClass.mjs +7 -89
  57. package/dpr/components/_charts/chart/heatmap/types.js +1 -1
  58. package/dpr/components/_charts/chart/heatmap/types.js.map +1 -1
  59. package/dpr/components/_charts/chart/heatmap/types.ts +5 -0
  60. package/dpr/components/_charts/chart/heatmap/validate.js +2 -0
  61. package/dpr/components/_charts/chart/heatmap/validate.js.map +7 -0
  62. package/dpr/components/_charts/chart/heatmap/validate.ts +25 -0
  63. package/dpr/components/_charts/chart/line/LineChart.js +2 -0
  64. package/dpr/components/_charts/chart/line/LineChart.js.map +7 -0
  65. package/dpr/components/_charts/chart/line/LineChart.ts +89 -0
  66. package/dpr/components/_charts/chart/line/clientClass.mjs +5 -36
  67. package/dpr/components/_charts/chart/line/types.js +2 -0
  68. package/dpr/components/_charts/chart/line/types.js.map +7 -0
  69. package/dpr/components/_charts/chart/line/types.ts +5 -0
  70. package/dpr/components/_charts/chart/line/validate.js +2 -0
  71. package/dpr/components/_charts/chart/line/validate.js.map +7 -0
  72. package/dpr/components/_charts/chart/line/validate.ts +30 -0
  73. package/dpr/components/_charts/chart/line-timeseries/LineTimeseriesChart.js +2 -0
  74. package/dpr/components/_charts/chart/line-timeseries/LineTimeseriesChart.js.map +7 -0
  75. package/dpr/components/_charts/chart/line-timeseries/LineTimeseriesChart.ts +57 -0
  76. package/dpr/components/_charts/chart/line-timeseries/types.js +2 -0
  77. package/dpr/components/_charts/chart/line-timeseries/types.js.map +7 -0
  78. package/dpr/components/_charts/chart/line-timeseries/types.ts +5 -0
  79. package/dpr/components/_charts/chart/line-timeseries/validate.js +2 -0
  80. package/dpr/components/_charts/chart/line-timeseries/validate.js.map +7 -0
  81. package/dpr/components/_charts/chart/line-timeseries/validate.ts +30 -0
  82. package/dpr/components/_charts/chart/view.njk +8 -1
  83. package/dpr/components/_charts/chart-tabs/view.njk +15 -14
  84. package/dpr/components/_charts/utils.js +1 -1
  85. package/dpr/components/_charts/utils.js.map +3 -3
  86. package/dpr/components/_charts/utils.test.ts +9 -3
  87. package/dpr/components/_charts/utils.ts +59 -193
  88. package/dpr/components/_dashboards/dashboard-list/types.js +2 -0
  89. package/dpr/components/_dashboards/dashboard-list/types.js.map +7 -0
  90. package/dpr/components/_dashboards/dashboard-list/types.ts +4 -0
  91. package/dpr/components/_dashboards/dashboard-list/validate.js +2 -0
  92. package/dpr/components/_dashboards/dashboard-list/validate.js.map +7 -0
  93. package/dpr/components/_dashboards/dashboard-list/validate.ts +28 -0
  94. package/dpr/components/_dashboards/dashboard-visualisation/Validate.js +2 -0
  95. package/dpr/components/_dashboards/dashboard-visualisation/Validate.js.map +7 -0
  96. package/dpr/components/_dashboards/dashboard-visualisation/Validate.ts +71 -0
  97. package/dpr/components/_dashboards/dashboard-visualisation/types.js +1 -1
  98. package/dpr/components/_dashboards/dashboard-visualisation/types.js.map +2 -2
  99. package/dpr/components/_dashboards/dashboard-visualisation/types.ts +32 -2
  100. package/dpr/components/_dashboards/scorecard/Scorecard.js +1 -1
  101. package/dpr/components/_dashboards/scorecard/Scorecard.js.map +3 -3
  102. package/dpr/components/_dashboards/scorecard/Scorecard.ts +82 -213
  103. package/dpr/components/_dashboards/scorecard/types.js +1 -1
  104. package/dpr/components/_dashboards/scorecard/types.js.map +1 -1
  105. package/dpr/components/_dashboards/scorecard/types.ts +11 -1
  106. package/dpr/components/_dashboards/scorecard/validate.js +2 -0
  107. package/dpr/components/_dashboards/scorecard/validate.js.map +7 -0
  108. package/dpr/components/_dashboards/scorecard/validate.ts +36 -0
  109. package/dpr/components/_dashboards/scorecard-group/ScorecardGroup.js +2 -0
  110. package/dpr/components/_dashboards/scorecard-group/ScorecardGroup.js.map +7 -0
  111. package/dpr/components/_dashboards/scorecard-group/ScorecardGroup.ts +228 -0
  112. package/dpr/components/_dashboards/scorecard-group/types.js +2 -0
  113. package/dpr/components/_dashboards/scorecard-group/types.js.map +7 -0
  114. package/dpr/components/_dashboards/scorecard-group/types.ts +5 -0
  115. package/dpr/components/_dashboards/scorecard-group/validate.js +2 -0
  116. package/dpr/components/_dashboards/scorecard-group/validate.js.map +7 -0
  117. package/dpr/components/_dashboards/scorecard-group/validate.ts +37 -0
  118. package/dpr/components/_filters/types.d.js.map +1 -1
  119. package/dpr/components/_filters/types.d.ts +6 -4
  120. package/dpr/routes/journeys/view-report/async/dashboard/utils.js +1 -1
  121. package/dpr/routes/journeys/view-report/async/dashboard/utils.js.map +3 -3
  122. package/dpr/routes/journeys/view-report/async/dashboard/utils.ts +22 -10
  123. package/dpr/routes/journeys/view-report/controller.js +1 -1
  124. package/dpr/routes/journeys/view-report/controller.js.map +3 -3
  125. package/dpr/routes/journeys/view-report/controller.ts +3 -1
  126. package/dpr/utils/ErrorHandler.js +1 -1
  127. package/dpr/utils/ErrorHandler.js.map +3 -3
  128. package/dpr/utils/ErrorHandler.ts +16 -0
  129. package/package.json +1 -1
  130. package/dpr/components/_charts/chart/Buckets.js +0 -2
  131. package/dpr/components/_charts/chart/Buckets.js.map +0 -7
  132. package/dpr/components/_dashboards/dashboard-visualisation/DashboardVisualisation.js +0 -2
  133. package/dpr/components/_dashboards/dashboard-visualisation/DashboardVisualisation.js.map +0 -7
  134. package/dpr/components/_dashboards/dashboard-visualisation/DashboardVisualisation.ts +0 -40
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/dpr/utils/ErrorHandler.ts"],
4
- "sourcesContent": ["import { components } from '../types/api'\nimport logger from './logger'\n\ninterface DprErrorMessage {\n userMessage?: string\n developerMessage?: string\n stack?: string\n moreInfo?: string\n status?: string | number\n}\n\ninterface DprErrorData {\n data: components['schemas']['ErrorResponse']\n}\n\nclass ErrorHandler {\n error: Error | components['schemas']['ErrorResponse'] | string | undefined | unknown | DprErrorData\n\n developerMessage?: string | undefined\n\n userMessage?: string | undefined\n\n moreInfo?: string | undefined\n\n stack?: string | undefined\n\n status?: number | string | undefined\n\n constructor(error: Error | components['schemas']['ErrorResponse'] | string | undefined | unknown) {\n this.error = error\n logger.error(`Error: ${JSON.stringify(error)}`)\n }\n\n formatError = (): DprErrorMessage => {\n return this.handleError()\n }\n\n private handleError = (): DprErrorMessage => {\n // status: FAILED\n if (typeof this.error === 'string') {\n this.developerMessage = this.error\n }\n\n // Error response\n else if ((<DprErrorData>this.error).data) {\n const error = (<DprErrorData>this.error).data\n this.developerMessage = error.developerMessage\n this.userMessage = error.userMessage\n this.moreInfo = error.moreInfo\n this.status = error.status\n }\n\n // client side error\n else if (Object.prototype.hasOwnProperty.call(this.error, 'message')) {\n const error = <Error>this.error\n this.userMessage = error.message\n this.stack = error.stack\n this.status = 500\n }\n\n // Server response error\n else if (Object.prototype.hasOwnProperty.call(this.error, 'developerMessage')) {\n const error = <components['schemas']['ErrorResponse']>this.error\n this.developerMessage = error.developerMessage\n this.userMessage = error.userMessage\n this.moreInfo = error.moreInfo\n this.status = error.status\n }\n\n const formattedError = {\n ...(this.developerMessage && { developerMessage: this.developerMessage }),\n ...(this.userMessage && { userMessage: this.userMessage }),\n ...(this.moreInfo && { moreInfo: this.moreInfo }),\n ...(this.stack && { stack: this.stack }),\n ...(this.status && { status: this.status }),\n }\n\n logger.error(JSON.stringify(formattedError, null, 2))\n\n return formattedError\n }\n}\n\nexport { ErrorHandler }\nexport default ErrorHandler\n"],
5
- "mappings": "0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,kBAAAE,EAAA,YAAAC,IAAA,eAAAC,EAAAJ,GACA,IAAAK,EAAmB,uBAcnB,MAAMH,CAAa,CAajB,YAAYI,EAAsF,CAKlG,iBAAc,IACL,KAAK,YAAY,EAG1B,KAAQ,YAAc,IAAuB,CAE3C,GAAI,OAAO,KAAK,OAAU,SACxB,KAAK,iBAAmB,KAAK,cAIP,KAAK,MAAO,KAAM,CACxC,MAAMA,EAAuB,KAAK,MAAO,KACzC,KAAK,iBAAmBA,EAAM,iBAC9B,KAAK,YAAcA,EAAM,YACzB,KAAK,SAAWA,EAAM,SACtB,KAAK,OAASA,EAAM,MACtB,SAGS,OAAO,UAAU,eAAe,KAAK,KAAK,MAAO,SAAS,EAAG,CACpE,MAAMA,EAAe,KAAK,MAC1B,KAAK,YAAcA,EAAM,QACzB,KAAK,MAAQA,EAAM,MACnB,KAAK,OAAS,GAChB,SAGS,OAAO,UAAU,eAAe,KAAK,KAAK,MAAO,kBAAkB,EAAG,CAC7E,MAAMA,EAAgD,KAAK,MAC3D,KAAK,iBAAmBA,EAAM,iBAC9B,KAAK,YAAcA,EAAM,YACzB,KAAK,SAAWA,EAAM,SACtB,KAAK,OAASA,EAAM,MACtB,CAEA,MAAMC,EAAiB,CACrB,GAAI,KAAK,kBAAoB,CAAE,iBAAkB,KAAK,gBAAiB,EACvE,GAAI,KAAK,aAAe,CAAE,YAAa,KAAK,WAAY,EACxD,GAAI,KAAK,UAAY,CAAE,SAAU,KAAK,QAAS,EAC/C,GAAI,KAAK,OAAS,CAAE,MAAO,KAAK,KAAM,EACtC,GAAI,KAAK,QAAU,CAAE,OAAQ,KAAK,MAAO,CAC3C,EAEA,SAAAC,QAAO,MAAM,KAAK,UAAUD,EAAgB,KAAM,CAAC,CAAC,EAE7CA,CACT,EAnDE,KAAK,MAAQD,EACb,EAAAE,QAAO,MAAM,UAAU,KAAK,UAAUF,CAAK,CAAC,EAAE,CAChD,CAkDF,CAGA,IAAOH,EAAQD",
6
- "names": ["ErrorHandler_exports", "__export", "ErrorHandler", "ErrorHandler_default", "__toCommonJS", "import_logger", "error", "formattedError", "logger"]
4
+ "sourcesContent": ["import { components } from '../types/api'\nimport logger from './logger'\n\ninterface DprErrorMessage {\n userMessage?: string\n developerMessage?: string\n stack?: string\n moreInfo?: string\n status?: string | number\n}\n\ninterface DprErrorData {\n data: components['schemas']['ErrorResponse']\n}\n\ninterface ZodValidationError {\n userMessage: string\n stack: string\n}\n\nclass ErrorHandler {\n error: Error | components['schemas']['ErrorResponse'] | string | undefined | unknown | DprErrorData\n\n developerMessage?: string | undefined\n\n userMessage?: string | undefined\n\n moreInfo?: string | undefined\n\n stack?: string | undefined\n\n status?: number | string | undefined\n\n constructor(error: Error | components['schemas']['ErrorResponse'] | string | undefined | unknown) {\n this.error = error\n logger.error(`Error: ${JSON.stringify(error)}`)\n }\n\n formatError = (): DprErrorMessage => {\n return this.handleError()\n }\n\n private handleError = (): DprErrorMessage => {\n // status: FAILED\n if (typeof this.error === 'string') {\n this.developerMessage = this.error\n }\n\n // Error response\n else if ((<DprErrorData>this.error).data) {\n const error = (<DprErrorData>this.error).data\n this.developerMessage = error.developerMessage\n this.userMessage = error.userMessage\n this.moreInfo = error.moreInfo\n this.status = error.status\n }\n\n // client side error\n else if (Object.prototype.hasOwnProperty.call(this.error, 'message')) {\n const error = <Error>this.error\n this.userMessage = error.message\n this.stack = error.stack\n this.status = 500\n }\n\n // Server response error\n else if (Object.prototype.hasOwnProperty.call(this.error, 'developerMessage')) {\n const error = <components['schemas']['ErrorResponse']>this.error\n this.developerMessage = error.developerMessage\n this.userMessage = error.userMessage\n this.moreInfo = error.moreInfo\n this.status = error.status\n }\n\n // Zod error\n else if (Object.prototype.hasOwnProperty.call(this.error, 'userMessage')) {\n const error = <ZodValidationError>this.error\n if (error.stack && error.stack.includes('ZodError')) {\n const errorArr: { message: string }[] = JSON.parse(error.userMessage)\n this.userMessage = errorArr.map((m) => m.message).join(', ')\n this.status = 500\n this.stack = error.stack\n }\n }\n\n const formattedError = {\n ...(this.developerMessage && { developerMessage: this.developerMessage }),\n ...(this.userMessage && { userMessage: this.userMessage }),\n ...(this.moreInfo && { moreInfo: this.moreInfo }),\n ...(this.stack && { stack: this.stack }),\n ...(this.status && { status: this.status }),\n }\n\n logger.error(JSON.stringify(formattedError, null, 2))\n\n return formattedError\n }\n}\n\nexport { ErrorHandler }\nexport default ErrorHandler\n"],
5
+ "mappings": "0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,kBAAAE,EAAA,YAAAC,IAAA,eAAAC,EAAAJ,GACA,IAAAK,EAAmB,uBAmBnB,MAAMH,CAAa,CAajB,YAAYI,E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AAAC,QAAO,MAAM,KAAK,UAAUD,EAAgB,KAAM,CAAC,CAAC,EAE7CA,CACT,EA9DE,KAAK,MAAQH,EACb,EAAAI,QAAO,MAAM,UAAU,KAAK,UAAUJ,CAAK,CAAC,EAAE,CAChD,CA6DF,CAGA,IAAOH,EAAQD",
6
+ "names": ["ErrorHandler_exports", "__export", "ErrorHandler", "ErrorHandler_default", "__toCommonJS", "import_logger", "error", "errorArr", "m", "formattedError", "logger"]
7
7
  }
@@ -13,6 +13,11 @@ interface DprErrorData {
13
13
  data: components['schemas']['ErrorResponse']
14
14
  }
15
15
 
16
+ interface ZodValidationError {
17
+ userMessage: string
18
+ stack: string
19
+ }
20
+
16
21
  class ErrorHandler {
17
22
  error: Error | components['schemas']['ErrorResponse'] | string | undefined | unknown | DprErrorData
18
23
 
@@ -67,6 +72,17 @@ class ErrorHandler {
67
72
  this.status = error.status
68
73
  }
69
74
 
75
+ // Zod error
76
+ else if (Object.prototype.hasOwnProperty.call(this.error, 'userMessage')) {
77
+ const error = <ZodValidationError>this.error
78
+ if (error.stack && error.stack.includes('ZodError')) {
79
+ const errorArr: { message: string }[] = JSON.parse(error.userMessage)
80
+ this.userMessage = errorArr.map((m) => m.message).join(', ')
81
+ this.status = 500
82
+ this.stack = error.stack
83
+ }
84
+ }
85
+
70
86
  const formattedError = {
71
87
  ...(this.developerMessage && { developerMessage: this.developerMessage }),
72
88
  ...(this.userMessage && { userMessage: this.userMessage }),
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ministryofjustice/hmpps-digital-prison-reporting-frontend",
3
3
  "description": "The Digital Prison Reporting Frontend contains templates and code to help display data effectively in UI applications.",
4
- "version": "4.20.2",
4
+ "version": "4.21.0",
5
5
  "main": "dpr/all.mjs",
6
6
  "sass": "dpr/all.scss",
7
7
  "engines": {
@@ -1,2 +0,0 @@
1
- "use strict";var h=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var k=Object.getOwnPropertyNames;var b=Object.prototype.hasOwnProperty;var m=(u,t)=>{for(var s in t)h(u,s,{get:t[s],enumerable:!0})},f=(u,t,s,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let e of k(t))!b.call(u,e)&&e!==s&&h(u,e,{get:()=>t[e],enumerable:!(i=p(t,e))||i.enumerable});return u};var C=u=>f(h({},"__esModule",{value:!0}),u);var g={};m(g,{Buckets:()=>c,default:()=>d});module.exports=C(g);var l=require("with-alpha-hex");class c{constructor(t,s,i,e,o){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.options={};this.initFromOptions=t=>{this.options=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(s=>!s.max&&!s.min&&s.hexColour!==void 0):!1};this.initBuckets=()=>{const{buckets:t}=this.options;this.setBucketCount(),this.initBucketColours(),t?this.hasRagScore?this.onlyBucketColoursDefined&&(this.buckets=t):!this.hasRagScore&&this.onlyBucketColoursDefined&&this.autoBucketing?this.initAutomaticThresholdBucket():this.initCustomThresholdBuckets():!t&&!this.hasRagScore&&this.autoBucketing&&this.initAutomaticThresholdBucket()};this.initCustomThresholdBuckets=()=>{this.buckets=this.options.buckets?this.options.buckets.map((t,s)=>({...this.buckets[s],...t})):[]};this.initAutomaticThresholdBucket=()=>{const{min:t,max:s,bucketSize:i}=this.setAutomaticThresholdSize();let e=0;this.buckets=this.buckets.map((o,a)=>{let r=t;return a!==0&&(r=e+1),e=i*(a+1)+t,a===this.buckets.length-1&&(e=s),{hexColour:this.options?.buckets?this.options.buckets[a]?.hexColour:o.hexColour,min:r,max:e}})};this.initBucketColours=()=>{if(this.useRagColour&&this.bucketCount===3)this.buckets=Array.from(new Array(this.bucketCount)).map((t,s)=>({hexColour:this.ragColours[s]}));else{const t=1/this.bucketCount;this.buckets=Array.from(new Array(this.bucketCount)).map((s,i)=>{const e=t*(i+1);return{hexColour:(0,l.withAlphaHex)(this.baseColour,e)}})}};this.setAutomaticThresholdSize=()=>{const t=this.responseData.map(o=>Number(o[this.valueKey].raw)),s=Math.min(...t),i=Math.max(...t),e=Math.ceil((i-s)/this.bucketCount);return{min:s,max:i,bucketSize:e}};this.setBucketCount=()=>{const{buckets:t}=this.options;if(this.hasRagScore)if(this.useRagColour)this.bucketCount=3;else{const s=this.responseData.reduce((i,e)=>(e[this.valueKey].rag!==void 0&&i.push(e[this.valueKey].rag),i),[]);this.bucketCount=Math.max(...s)+1}else t?this.bucketCount=t.length:this.bucketCount=3};this.getBucketForValue=(t,s)=>{let i="",e=0;return s!==void 0?{colour:this.buckets[s].hexColour||i,score:s}:(this.buckets.forEach((o,a)=>{const{min:r,max:n}=o;!r&&n&&t<=n&&(i=o.hexColour||i,e=a),r&&t>=r&&n&&t<=n&&(i=o.hexColour||i,e=a),r&&!n&&t>=r&&(i=o.hexColour||i,e=a)}),{colour:i,score:e})};this.getBuckets=()=>this.buckets;this.responseData=t,this.initFromOptions(s),this.valueKey=i,this.hasRagScore=t[0][this.valueKey].rag!==void 0,this.autoBucketing=!!e,o&&(this.ragColours=o),this.initBuckets()}}var d=c;0&&(module.exports={Buckets});
2
- //# sourceMappingURL=Buckets.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../../../src/dpr/components/_charts/chart/Buckets.ts"],
4
- "sourcesContent": ["/* eslint-disable prefer-destructuring */\nimport { withAlphaHex } from 'with-alpha-hex'\nimport { DashboardDataResponse } from '../../../types/Metrics'\nimport {\n DashboardVisualisationBucket,\n BucketDashboardVisualisationOptions,\n} from '../../_dashboards/dashboard-visualisation/types'\nimport { components } from '../../../types/api'\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: BucketDashboardVisualisationOptions = {}\n\n responseData: DashboardDataResponse[]\n\n constructor(\n responseData: DashboardDataResponse[],\n definition: components['schemas']['DashboardVisualisationDefinition'],\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: components['schemas']['DashboardVisualisationDefinition']) => {\n this.options = <BucketDashboardVisualisationOptions>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) {\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 (!buckets && !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: this.options?.buckets ? 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) {\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": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,EAAA,YAAAC,IAAA,eAAAC,EAAAJ,GACA,IAAAK,EAA6B,0BAQ7B,MAAMH,CAAQ,CAuBZ,YACEI,EACAC,EACAC,EACAC,EACAC,EACA,CA5BF,KAAQ,WAAa,UAErB,KAAQ,WAAuB,CAAC,UAAW,UAAW,SAAS,EAE/D,KAAQ,QAA0C,CAAC,EAEnD,KAAQ,aAAe,GAEvB,KAAQ,YAAc,EAEtB,KAAQ,yBAA2B,GAEnC,KAAQ,cAAgB,GAExB,KAAQ,YAAc,GAItB,KAAQ,QAA+C,CAAC,EAoBxD,KAAQ,gBAAmBH,GAA0E,CACnG,KAAK,QAA+CA,EAAW,SAAW,CAAC,EAC3E,KAAK,WAAa,KAAK,SAAS,YAAc,KAAK,WACnD,KAAK,aAAe,KAAK,SAAS,cAAgB,GAClD,KAAK,yBACH,KAAK,SAAW,KAAK,QAAQ,QACzB,KAAK,SAAS,SAAS,MAAOI,GAAW,CAACA,EAAO,KAAO,CAACA,EAAO,KAAOA,EAAO,YAAc,MAAS,EACrG,EACR,EAEA,KAAQ,YAAc,IAAM,CAC1B,KAAM,CAAE,QAAAC,CAAQ,EAAI,KAAK,QAEzB,KAAK,eAAe,EACpB,KAAK,kBAAkB,EAEnBA,EACE,KAAK,YACH,KAAK,2BACP,KAAK,QAAUA,GAER,CAAC,KAAK,aAAe,KAAK,0BAA4B,KAAK,cACpE,KAAK,6BAA6B,EAElC,KAAK,2BAA2B,EAEzB,CAACA,GAAW,CAAC,KAAK,aAAe,KAAK,eAC/C,KAAK,6BAA6B,CAEtC,EAEA,KAAQ,2BAA6B,IAAM,CACzC,KAAK,QAAU,KAAK,QAAQ,QACxB,KAAK,QAAQ,QAAQ,IAAI,CAACD,EAAQ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AaA,GAClC,KAAK,YAAY,CACnB,CA4JF,CAGA,IAAOP,EAAQD",
6
- "names": ["Buckets_exports", "__export", "Buckets", "Buckets_default", "__toCommonJS", "import_with_alpha_hex", "responseData", "definition", "valueKey", "autoBucketing", "ragColours", "bucket", "buckets", "i", "min", "max", "bucketSize", "maxValue", "minValue", "_d", "alphaDivision", "division", "values", "resData", "allRags", "acc", "value", "ragScore", "colour", "score", "index"]
7
- }
@@ -1,2 +0,0 @@
1
- "use strict";var a=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var h=Object.getOwnPropertyNames;var u=Object.prototype.hasOwnProperty;var c=(i,s)=>{for(var n in s)a(i,n,{get:s[n],enumerable:!0})},r=(i,s,n,e)=>{if(s&&typeof s=="object"||typeof s=="function")for(let o of h(s))!u.call(i,o)&&o!==n&&a(i,o,{get:()=>s[o],enumerable:!(e=m(s,o))||e.enumerable});return i};var D=i=>r(a({},"__esModule",{value:!0}),i);var p={};c(p,{DashboardVisualisationClass:()=>t,default:()=>l});module.exports=D(p);class t{constructor(s,n){this.initUnit=()=>{this.unit=this.columns.measures[0].unit?this.columns.measures[0].unit:void 0};this.definition=n,this.columns=n.columns,this.measures=this.columns.measures,this.keys=this.columns.keys||[],this.type=this.definition.type.split("-")[0],this.initUnit(),this.responseData=s}}var l=t;0&&(module.exports={DashboardVisualisationClass});
2
- //# sourceMappingURL=DashboardVisualisation.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../../../src/dpr/components/_dashboards/dashboard-visualisation/DashboardVisualisation.ts"],
4
- "sourcesContent": ["/* eslint-disable prefer-destructuring */\nimport { components } from '../../../types/api'\nimport { DashboardDataResponse } from '../../../types/Metrics'\n\nclass DashboardVisualisationClass {\n responseData: DashboardDataResponse[]\n\n definition: components['schemas']['DashboardVisualisationDefinition']\n\n columns: components['schemas']['DashboardVisualisationColumnsDefinition']\n\n measures: components['schemas']['DashboardVisualisationColumnDefinition'][]\n\n keys: components['schemas']['DashboardVisualisationColumnDefinition'][]\n\n unit: components['schemas']['DashboardVisualisationColumnDefinition']['unit']\n\n type: components['schemas']['DashboardVisualisationDefinition']['type']\n\n constructor(\n responseData: DashboardDataResponse[],\n definition: components['schemas']['DashboardVisualisationDefinition'],\n ) {\n this.definition = definition\n this.columns = definition.columns\n this.measures = this.columns.measures\n this.keys = this.columns.keys || []\n this.type = this.definition.type.split('-')[0] as components['schemas']['DashboardVisualisationDefinition']['type']\n this.initUnit()\n this.responseData = responseData\n }\n\n initUnit = () => {\n // todo\n this.unit = this.columns.measures[0].unit ? this.columns.measures[0].unit : undefined\n }\n}\n\nexport { DashboardVisualisationClass }\nexport default DashboardVisualisationClass\n"],
5
- "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,iCAAAE,EAAA,YAAAC,IAAA,eAAAC,EAAAJ,GAIA,MAAME,CAA4B,CAehC,YACEG,EACAC,EACA,CAUF,cAAW,IAAM,CAEf,KAAK,KAAO,KAAK,QAAQ,SAAS,CAAC,EAAE,KAAO,KAAK,QAAQ,SAAS,CAAC,EAAE,KAAO,MAC9E,EAZE,KAAK,WAAaA,EAClB,KAAK,QAAUA,EAAW,QAC1B,KAAK,SAAW,KAAK,QAAQ,SAC7B,KAAK,KAAO,KAAK,QAAQ,MAAQ,CAAC,EAClC,KAAK,KAAO,KAAK,WAAW,KAAK,MAAM,GAAG,EAAE,CAAC,EAC7C,KAAK,SAAS,EACd,KAAK,aAAeD,CACtB,CAMF,CAGA,IAAOF,EAAQD",
6
- "names": ["DashboardVisualisation_exports", "__export", "DashboardVisualisationClass", "DashboardVisualisation_default", "__toCommonJS", "responseData", "definition"]
7
- }
@@ -1,40 +0,0 @@
1
- /* eslint-disable prefer-destructuring */
2
- import { components } from '../../../types/api'
3
- import { DashboardDataResponse } from '../../../types/Metrics'
4
-
5
- class DashboardVisualisationClass {
6
- responseData: DashboardDataResponse[]
7
-
8
- definition: components['schemas']['DashboardVisualisationDefinition']
9
-
10
- columns: components['schemas']['DashboardVisualisationColumnsDefinition']
11
-
12
- measures: components['schemas']['DashboardVisualisationColumnDefinition'][]
13
-
14
- keys: components['schemas']['DashboardVisualisationColumnDefinition'][]
15
-
16
- unit: components['schemas']['DashboardVisualisationColumnDefinition']['unit']
17
-
18
- type: components['schemas']['DashboardVisualisationDefinition']['type']
19
-
20
- constructor(
21
- responseData: DashboardDataResponse[],
22
- definition: components['schemas']['DashboardVisualisationDefinition'],
23
- ) {
24
- this.definition = definition
25
- this.columns = definition.columns
26
- this.measures = this.columns.measures
27
- this.keys = this.columns.keys || []
28
- this.type = this.definition.type.split('-')[0] as components['schemas']['DashboardVisualisationDefinition']['type']
29
- this.initUnit()
30
- this.responseData = responseData
31
- }
32
-
33
- initUnit = () => {
34
- // todo
35
- this.unit = this.columns.measures[0].unit ? this.columns.measures[0].unit : undefined
36
- }
37
- }
38
-
39
- export { DashboardVisualisationClass }
40
- export default DashboardVisualisationClass