@record-evolution/widget-linechart 1.6.13 → 1.6.14

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/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Webcomponent widget-linechart following open-wc recommendations",
4
4
  "license": "MIT",
5
5
  "author": "widget-linechart",
6
- "version": "1.6.13",
6
+ "version": "1.6.14",
7
7
  "type": "module",
8
8
  "main": "dist/widget-linechart.js",
9
9
  "types": "dist/src/widget-linechart.d.ts",
@@ -37,6 +37,8 @@ type Theme = {
37
37
  theme_name: string
38
38
  theme_object: any
39
39
  }
40
+
41
+ type SeriesOptionX = SeriesOption & { minDate?: number; maxDate?: number }
40
42
  @customElement('widget-linechart-versionplaceholder')
41
43
  export class WidgetLinechart extends LitElement {
42
44
  @property({ type: Object })
@@ -48,7 +50,7 @@ export class WidgetLinechart extends LitElement {
48
50
  @state()
49
51
  private canvasList: Map<
50
52
  string,
51
- { echart?: echarts.ECharts; series: SeriesOption[]; doomed?: boolean; element?: HTMLDivElement }
53
+ { echart?: echarts.ECharts; series: SeriesOptionX[]; doomed?: boolean; element?: HTMLDivElement }
52
54
  > = new Map()
53
55
 
54
56
  @state() private themeBgColor?: string
@@ -248,13 +250,27 @@ export class WidgetLinechart extends LitElement {
248
250
  : derivedBgColors[i]
249
251
  : undefined
250
252
  const data = distincts.length === 1 ? ds.data : ds.data?.filter((d) => d.pivot === piv)
251
- const data2 = this.inputData?.axis?.timeseries
252
- ? data?.map((d) => [new Date(d.x ?? ''), d.y, d.r])
253
- : data?.map((d) => [d.x, d.y, d.r])
254
-
255
- // preparing the echarts series option for later application
256
- const pds: SeriesOption = {
253
+ let data2 = this.inputData?.axis?.timeseries
254
+ ? (data?.map((d) => ({ name: d.x, value: [new Date(d.x ?? '').getTime(), d.y, d.r] })) ??
255
+ [])
256
+ : (data?.map((d) => ({ name: d.x, value: [d.x, d.y, d.r] })) ?? [])
257
+
258
+ let minDate: number = 0,
259
+ maxDate: number = 0,
260
+ extraData: (string | number | undefined)[][] = []
261
+ if (this.xAxisType() === 'time' && data2) {
262
+ const dates = data2.map((d: any) => d.value[0] as number)
263
+ minDate = Math.min(...dates)
264
+ maxDate = Math.max(...dates)
265
+ // extraData = (pds?.data as any[][])?.filter((d: any) => d[0] < minDate) ?? []
266
+ // data2.unshift(...extraData) // add old data to the beginning of the new data
267
+ // data2 = [...extraData, ...data2] // leave old data in for smooth shifting animation and delete after draw
268
+ }
269
+ const pds: SeriesOptionX = {
270
+ id: name,
257
271
  name: name,
272
+ minDate,
273
+ maxDate,
258
274
  type: ds.type ?? 'line',
259
275
  lineStyle: {
260
276
  color: lineColor,
@@ -269,7 +285,7 @@ export class WidgetLinechart extends LitElement {
269
285
  },
270
286
  areaStyle: ds.styling?.fill ? { color: fillColor } : undefined,
271
287
  symbol: ds.styling?.pointStyle ?? 'circle',
272
- symbolSize: (data) => data[2] ?? 4,
288
+ symbolSize: (d: any[]) => d[2] ?? 4,
273
289
  showSymbol: ds.styling?.pointStyle === 'none' ? false : true,
274
290
  data: data2 ?? []
275
291
  }
@@ -319,6 +335,18 @@ export class WidgetLinechart extends LitElement {
319
335
 
320
336
  // Axis
321
337
  option.xAxis.name = this.inputData?.axis?.xAxisLabel ?? ''
338
+ if (this.xAxisType() === 'time') {
339
+ const axisMax = chart.series.map((s) => s.maxDate ?? 0).reduce((a, b) => Math.max(a, b), 0)
340
+ const axisMin = chart.series
341
+ .map((s) => s.minDate ?? Infinity)
342
+ .reduce((a, b) => Math.min(a, b), Infinity)
343
+ // console.log('Setting xAxis time range', label, new Date(axisMin), new Date(axisMax))
344
+ option.xAxis = {
345
+ ...option.xAxis,
346
+ min: axisMin ?? new Date().getTime() - 1 * 24 * 60 * 60 * 1000, // 1 days ago,
347
+ max: axisMax ?? new Date().getTime() // today
348
+ }
349
+ }
322
350
  option.dataZoom[0].show = this.inputData?.axis?.xAxisZoom ?? false
323
351
  option.toolbox.show = this.inputData?.axis?.xAxisZoom ?? false
324
352
  // option.xAxis.axisLine.lineStyle.width = 2 * modifier