@record-evolution/widget-linechart 1.5.4 → 1.5.5

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.4",
6
+ "version": "1.5.5",
7
7
  "type": "module",
8
8
  "main": "dist/widget-linechart.js",
9
9
  "types": "dist/src/widget-linechart.d.ts",
@@ -161,7 +161,6 @@
161
161
  "description": "The data used to draw this data series.",
162
162
  "type": "array",
163
163
  "order": 5,
164
- "buffersize": 1000,
165
164
  "items": {
166
165
  "type": "object",
167
166
  "properties": {
@@ -11,13 +11,14 @@ import { InputData } from './definition-schema.js'
11
11
 
12
12
  type Dataseries = Exclude<InputData['dataseries'], undefined>[number]
13
13
  type Data = Exclude<Dataseries['data'], undefined>[number]
14
+ type ChartCombination = { chartJsInstance?: Chart; dataSets: ChartDataset[] }
14
15
 
15
16
  export class WidgetLinechart extends LitElement {
16
17
  @property({ type: Object })
17
18
  inputData?: InputData
18
19
 
19
20
  @state()
20
- private canvasList: Map<string, { chart?: any; dataSets: Dataseries[] }> = new Map()
21
+ private canvasList: Map<string, ChartCombination> = new Map()
21
22
 
22
23
  version: string = 'versionplaceholder'
23
24
  chartContainer?: HTMLElement | DocumentFragment
@@ -90,7 +91,11 @@ export class WidgetLinechart extends LitElement {
90
91
 
91
92
  if (!this.canvasList.has(chartName)) {
92
93
  // initialize new charts
93
- this.canvasList.set(chartName, { chart: undefined, dataSets: [] as Dataseries[] })
94
+ this.canvasList.set(chartName, {
95
+ chartJsInstance: undefined,
96
+ // @ts-ignore
97
+ dataSets: [] as Dataseries[]
98
+ })
94
99
  }
95
100
  this.canvasList.get(chartName)?.dataSets.push(pds)
96
101
  })
@@ -100,19 +105,28 @@ export class WidgetLinechart extends LitElement {
100
105
  // console.log('new linechart datasets', this.canvasList)
101
106
  }
102
107
 
103
- applyInputData() {
108
+ async applyInputData() {
104
109
  this.setupCharts()
105
110
 
106
111
  this.requestUpdate()
107
- this.canvasList.forEach(({ chart, dataSets }) => {
108
- if (chart) {
109
- chart.data.datasets = dataSets
110
- chart.options.scales.x.type = this.xAxisType()
111
- chart.options.scales.x.title.display = !!this.inputData?.axis?.xAxisLabel
112
- chart.options.scales.x.title.text = this.inputData?.axis?.xAxisLabel
113
- chart.options.scales.y.title.display = !!this.inputData?.axis?.yAxisLabel
114
- chart.options.scales.y.title.text = this.inputData?.axis?.yAxisLabel
115
- chart?.update('resize')
112
+ await this.updateComplete
113
+ this.canvasList.forEach(({ chartJsInstance, dataSets }) => {
114
+ if (chartJsInstance) {
115
+ chartJsInstance.data.datasets = dataSets
116
+ chartJsInstance.options ??= {}
117
+ chartJsInstance.options.scales ??= {}
118
+ chartJsInstance.options.scales.x ??= {}
119
+ chartJsInstance.options.scales.y ??= {}
120
+ chartJsInstance.options.scales.x.type = this.xAxisType()
121
+ // @ts-ignore
122
+ chartJsInstance.options.scales.x.title.display = !!this.inputData?.axis?.xAxisLabel
123
+ // @ts-ignore
124
+ chartJsInstance.options.scales.x.title.text = this.inputData?.axis?.xAxisLabel
125
+ // @ts-ignore
126
+ chartJsInstance.options.scales.y.title.display = !!this.inputData?.axis?.yAxisLabel
127
+ // @ts-ignore
128
+ chartJsInstance.options.scales.y.title.text = this.inputData?.axis?.yAxisLabel
129
+ chartJsInstance?.update('resize')
116
130
  }
117
131
  })
118
132
  }
@@ -131,7 +145,7 @@ export class WidgetLinechart extends LitElement {
131
145
  this.canvasList.delete(chartName)
132
146
  return
133
147
  }
134
- if (chartM.chart) return
148
+ if (chartM.chartJsInstance) return
135
149
 
136
150
  if (!this.chartContainer) throw new Error('chartContainer not found')
137
151
 
@@ -145,7 +159,7 @@ export class WidgetLinechart extends LitElement {
145
159
 
146
160
  if (!canvas) throw new Error('canvas not found')
147
161
  // console.log('chartM', canvas, chartM.chart)
148
- chartM.chart = new Chart(canvas, {
162
+ chartM.chartJsInstance = new Chart(canvas, {
149
163
  type: 'line',
150
164
  data: {
151
165
  // @ts-ignore
@@ -242,6 +256,17 @@ export class WidgetLinechart extends LitElement {
242
256
  font-size: 14px;
243
257
  line-height: 17px;
244
258
  }
259
+
260
+ .no-data {
261
+ font-size: 20px;
262
+ color: var(--re-text-color, #000);
263
+ display: flex;
264
+ height: 100%;
265
+ width: 100%;
266
+ text-align: center;
267
+ align-items: center;
268
+ justify-content: center;
269
+ }
245
270
  `
246
271
 
247
272
  render() {
@@ -252,6 +277,7 @@ export class WidgetLinechart extends LitElement {
252
277
  <p class="paging" ?active=${this.inputData?.subTitle}>${this.inputData?.subTitle}</p>
253
278
  </header>
254
279
 
280
+ <div class="paging no-data" ?active=${!this.canvasList.size}>No Data</div>
255
281
  <div
256
282
  class="chart-container ${this?.inputData?.axis?.columnLayout ? 'columnLayout' : ''}"
257
283
  ></div>