@record-evolution/widget-linechart 1.5.1 → 1.5.3

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.5.1",
6
+ "version": "1.5.3",
7
7
  "type": "module",
8
8
  "main": "dist/widget-linechart.js",
9
9
  "types": "dist/src/widget-linechart.d.ts",
@@ -20,9 +20,10 @@ export class WidgetLinechart extends LitElement {
20
20
  private canvasList: Map<string, { chart?: any; dataSets: Dataseries[] }> = new Map()
21
21
 
22
22
  version: string = 'versionplaceholder'
23
+ chartContainer?: HTMLElement | DocumentFragment
23
24
 
24
25
  update(changedProperties: Map<string, any>) {
25
- if (changedProperties.has('inputData')) {
26
+ if (changedProperties.has('inputData') && this.chartContainer) {
26
27
  this.transformInputData()
27
28
  this.applyInputData()
28
29
  }
@@ -30,6 +31,8 @@ export class WidgetLinechart extends LitElement {
30
31
  }
31
32
 
32
33
  protected firstUpdated(): void {
34
+ this.chartContainer = this.shadowRoot?.querySelector('.chart-container') as HTMLElement
35
+ this.transformInputData()
33
36
  this.applyInputData()
34
37
  }
35
38
 
@@ -47,9 +50,10 @@ export class WidgetLinechart extends LitElement {
47
50
  } else {
48
51
  ds.borderDash = undefined
49
52
  }
53
+ ds.data ??= []
50
54
 
51
55
  // pivot data
52
- const distincts = [...new Set(ds.data?.map((d: Data) => d.pivot))].sort()
56
+ const distincts = [...new Set(ds.data.map((d: Data) => d.pivot))].sort()
53
57
  const derivedBgColors = tinycolor(ds.backgroundColor as ColorInput | undefined)
54
58
  .monochromatic(distincts.length)
55
59
  .map((c: any) => c.toHexString())
@@ -68,7 +72,7 @@ export class WidgetLinechart extends LitElement {
68
72
  : derivedBdColors[i],
69
73
  backgroundColor: ds.advanced?.chartName?.includes('#split#')
70
74
  ? ds.backgroundColor
71
- : derivedBdColors[i],
75
+ : derivedBgColors[i],
72
76
  styling: ds.styling,
73
77
  pointStyle: ds.styling?.pointStyle,
74
78
  radius: ds.styling?.radius,
@@ -80,7 +84,7 @@ export class WidgetLinechart extends LitElement {
80
84
  }
81
85
  let chartName = ds.advanced?.chartName ?? ''
82
86
  if (chartName.includes('#split#')) {
83
- chartName = chartName + '-' + piv
87
+ chartName = prefix + chartName
84
88
  }
85
89
  // If the chartName ends with :pivot: then create a seperate chart for each pivoted dataseries
86
90
 
@@ -92,7 +96,7 @@ export class WidgetLinechart extends LitElement {
92
96
  })
93
97
  })
94
98
  // prevent duplicate transformation
95
- this.inputData.dataseries = []
99
+ // this.inputData.dataseries = []
96
100
  // console.log('new linechart datasets', this.canvasList)
97
101
  }
98
102
 
@@ -115,17 +119,31 @@ export class WidgetLinechart extends LitElement {
115
119
 
116
120
  xAxisType(): 'linear' | 'logarithmic' | 'category' | 'time' | 'timeseries' | undefined {
117
121
  if (this.inputData?.axis?.timeseries) return 'time'
118
- const onePoint = this.inputData?.dataseries?.[0].data?.[0]
122
+ const onePoint = this.inputData?.dataseries?.[0]?.data?.[0]
119
123
  if (!isNaN(Number(onePoint?.x))) return 'linear'
120
124
  return 'category'
121
125
  }
122
126
 
123
127
  setupCharts() {
124
128
  this.canvasList.forEach((chartM, chartName) => {
125
- if (!chartM.dataSets.length) this.canvasList.delete(chartName)
129
+ if (!chartM.dataSets.length) {
130
+ this.shadowRoot?.querySelector(`div[name="${chartName}"]`)?.remove()
131
+ this.canvasList.delete(chartName)
132
+ return
133
+ }
126
134
  if (chartM.chart) return
127
- const canvas = this.shadowRoot?.querySelector(`[name="${chartName}"]`) as HTMLCanvasElement
128
- if (!canvas) return
135
+
136
+ if (!this.chartContainer) throw new Error('chartContainer not found')
137
+
138
+ const newContainer = document.createElement('div')
139
+ newContainer.setAttribute('name', chartName)
140
+ newContainer.setAttribute('class', 'sizer')
141
+ const canvas = document.createElement('canvas')
142
+ canvas.setAttribute('name', chartName)
143
+ newContainer.appendChild(canvas)
144
+ this.chartContainer.appendChild(newContainer)
145
+
146
+ if (!canvas) throw new Error('canvas not found')
129
147
  // console.log('chartM', canvas, chartM.chart)
130
148
  chartM.chart = new Chart(canvas, {
131
149
  type: 'line',
@@ -234,17 +252,9 @@ export class WidgetLinechart extends LitElement {
234
252
  <p class="paging" ?active=${this.inputData?.subTitle}>${this.inputData?.subTitle}</p>
235
253
  </header>
236
254
 
237
- <div class="chart-container ${this?.inputData?.axis?.columnLayout ? 'columnLayout' : ''}">
238
- ${repeat(
239
- [...this.canvasList.entries()].sort(),
240
- ([chartName, chartM]) => chartName,
241
- ([chartName]) => html`
242
- <div class="sizer">
243
- <canvas name="${chartName}"></canvas>
244
- </div>
245
- `
246
- )}
247
- </div>
255
+ <div
256
+ class="chart-container ${this?.inputData?.axis?.columnLayout ? 'columnLayout' : ''}"
257
+ ></div>
248
258
  </div>
249
259
  `
250
260
  }