@isoftdata/utility-dashboard-backend 1.5.6 → 1.5.8

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.
package/chart-helper.js CHANGED
@@ -216,13 +216,19 @@ module.exports = {
216
216
 
217
217
  return { cols, rows }
218
218
  },
219
- makeDataCumulative: dataTable => {
219
+ /**
220
+ * Replace all null values with the previous non-null value, and optionally make data cumulative
221
+ * @param {Object} dataTable - the data table
222
+ * @param {Boolean} cumulative - whether to make the data cumulative, or fill remove holes in the data. Defaults to true.
223
+ * @returns
224
+ */
225
+ makeDataCumulative: (dataTable, cumulative = true) => {
220
226
  dataTable.rows.forEach((row, rowIndex) => {
221
227
  if (rowIndex > 0) {
222
228
  row.c.forEach((col, colIndex) => {
223
229
  if (colIndex > 0 && col.v == null) {
224
230
  col.v = Number(dataTable.rows[rowIndex - 1].c[colIndex].v)
225
- } else if (colIndex > 0) {
231
+ } else if (cumulative && colIndex > 0) {
226
232
  col.v = Number(col.v) + Number(dataTable.rows[rowIndex - 1].c[colIndex].v)
227
233
  }
228
234
  })
package/index.js CHANGED
@@ -9,6 +9,7 @@ const {
9
9
  makeDataCumulative,
10
10
  getRactiveTableDataFormat: getRactiveTableDataFormat } = require('./chart-helper.js')
11
11
  const { datesFromRange } = require('@isoftdata/utility-date-time')
12
+ const { formatterTemplates } = require('./formatter-templates.json')
12
13
  const formatDate = require('date-fns/format')
13
14
  const camelcase = require('camelcase')
14
15
 
@@ -35,7 +36,7 @@ const handleChartTypeSpecificQuirks = (chartType, resultSet) => {
35
36
  return resultSet
36
37
  }
37
38
 
38
- const loadChartData = async(mysqlConnection, { name, query: queryObject, formatting, chartWrapper, multiSeries, table, parameters, supertype, ...theRest }) => { // needs database connection
39
+ const loadChartData = async(mysqlConnection, { query: queryObject, formatting, chartWrapper, multiSeries, table, supertype, cumulative, ...theRest }) => { // needs database connection
39
40
  if (!chartWrapper) {
40
41
  chartWrapper = {
41
42
  chartType: supertype,
@@ -44,7 +45,12 @@ const loadChartData = async(mysqlConnection, { name, query: queryObject, formatt
44
45
  },
45
46
  }
46
47
  }
47
- const { dataTable, processedFormatting } = await loadDataTableAndProcessedFormatting(mysqlConnection, { query: queryObject, multiSeries, formatting, chartType: chartWrapper?.chartType })
48
+
49
+ // There are area charts in the wild that need to be cumulative but aren't specifically flagged as such,
50
+ // So make area charts cumulative unless they're explicitly set not to be
51
+ cumulative = cumulative || (chartWrapper?.chartType === 'AreaChart' && cumulative !== false)
52
+
53
+ const { dataTable, processedFormatting } = await loadDataTableAndProcessedFormatting(mysqlConnection, { query: queryObject, multiSeries, formatting, chartType: chartWrapper?.chartType, cumulative })
48
54
 
49
55
  if (chartWrapper?.chartType === 'Table') {
50
56
  return {
@@ -57,6 +63,7 @@ const loadChartData = async(mysqlConnection, { name, query: queryObject, formatt
57
63
  }
58
64
  return {
59
65
  ...theRest,
66
+ cumulative,
60
67
  supertype,
61
68
  chartWrapper: {
62
69
  ...chartWrapper,
@@ -70,7 +77,7 @@ const loadChartData = async(mysqlConnection, { name, query: queryObject, formatt
70
77
  * Otherwise, it will return data in the google chart Datatable object literal format.
71
78
  * multiSeries, formatting properties should be deconstructed from the chart object, chartType should be deconstructed from the chart's chartWrapper property
72
79
  */
73
- const loadDataTableAndProcessedFormatting = async(mysqlConnection, { query: queryObject, multiSeries, formatting, chartType }) => {
80
+ const loadDataTableAndProcessedFormatting = async(mysqlConnection, { query: queryObject, multiSeries, formatting, chartType, cumulative }) => {
74
81
  let { results: queryResultSet, fields } = (queryObject && queryObject.sql) ? await queryWithFields(mysqlConnection, queryObject) : { fields: [], results: [] }
75
82
  let data = handleChartTypeSpecificQuirks(chartType, queryResultSet)
76
83
 
@@ -91,10 +98,10 @@ const loadDataTableAndProcessedFormatting = async(mysqlConnection, { query: quer
91
98
 
92
99
  let dataTable = getDataTableFormat(data, fields, multiSeries) //per the Google Charts docs, the DataTable object literal format is the most performant, so we'll turn it into that format before returning
93
100
 
94
- // Stacked area charts will have holes / jagged lines if there are nulls in the middle of a column
95
- // Presumably we'll also want to be able to have non-cumulative area charts at some point
96
- if (chartType === 'AreaChart') {
97
- dataTable = makeDataCumulative(dataTable)
101
+ // Stacked area charts will have holes / jagged lines if there are nulls in the middle of a column,
102
+ // so always do this for those, even if we don't need it to be cumulative.
103
+ if (cumulative || chartType === 'AreaChart') {
104
+ dataTable = makeDataCumulative(dataTable, cumulative)
98
105
  }
99
106
 
100
107
  return { dataTable, processedFormatting }
@@ -255,4 +262,5 @@ module.exports = {
255
262
  loadDataTableAndProcessedFormatting,
256
263
  parameterizeQuery,
257
264
  handleFormattingTemplates,
265
+ formatterTemplates,
258
266
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@isoftdata/utility-dashboard-backend",
3
- "version": "1.5.6",
3
+ "version": "1.5.8",
4
4
  "description": "A utility for formatting chart and report data to be usable by the frontend dashboard component.",
5
5
  "main": "index.js",
6
6
  "scripts": {