@stoker-platform/web-app 0.5.230 → 0.5.231

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @stoker-platform/web-app
2
2
 
3
+ ## 0.5.231
4
+
5
+ ### Patch Changes
6
+
7
+ - feat: pad empty months in Dashboard charts
8
+
3
9
  ## 0.5.230
4
10
 
5
11
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stoker-platform/web-app",
3
- "version": "0.5.230",
3
+ "version": "0.5.231",
4
4
  "type": "module",
5
5
  "license": "SEE LICENSE IN LICENSE.md",
6
6
  "scripts": {
@@ -215,20 +215,30 @@ export const DashboardChart = ({ chart, title, collection }: DashboardChartProps
215
215
  })
216
216
  }
217
217
 
218
- return chartData?.filter((item) => {
219
- const date = DateTime.fromISO(item.date).setZone(timezone).startOf(interval).toJSDate()
220
- const startDate = DateTime.now()
221
- .setZone(timezone)
222
- .startOf(interval)
223
- .plus({ [`${interval}s`]: offset })
224
- .toJSDate()
225
- const endDate = DateTime.now()
226
- .setZone(timezone)
227
- .endOf(interval)
228
- .plus({ [`${interval}s`]: (numberOfIntervals || 0) + offset })
229
- .toJSDate()
230
- return date >= startDate && date < endDate
231
- })
218
+ const startDate = DateTime.now()
219
+ .setZone(timezone)
220
+ .startOf(interval)
221
+ .plus({ [`${interval}s`]: offset })
222
+ const endDate = DateTime.now()
223
+ .setZone(timezone)
224
+ .endOf(interval)
225
+ .plus({ [`${interval}s`]: (numberOfIntervals || 0) + offset })
226
+
227
+ const byDate = new Map(chartData.map((item) => [item.date, item]))
228
+ const padMetric2 = !!(chart.metricField2 || chart.formula2)
229
+ const paddedChartData: ChartData = []
230
+ for (let cursor = startDate; cursor < endDate; cursor = cursor.plus({ [`${interval}s`]: 1 })) {
231
+ const key = cursor.toFormat("yyyy-MM-dd")
232
+ const existing = byDate.get(key)
233
+ if (existing) {
234
+ paddedChartData.push(existing)
235
+ } else if (padMetric2) {
236
+ paddedChartData.push({ date: key, metric1: 0, metric2: 0 })
237
+ } else {
238
+ paddedChartData.push({ date: key, metric1: 0 })
239
+ }
240
+ }
241
+ return paddedChartData
232
242
  }, [results])
233
243
 
234
244
  const metricField1 = chart.metricField1 ? getField(fields, chart.metricField1) : undefined