@record-evolution/widget-linechart 1.6.4 → 1.6.6

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.4",
6
+ "version": "1.6.6",
7
7
  "type": "module",
8
8
  "main": "dist/widget-linechart.js",
9
9
  "types": "dist/src/widget-linechart.d.ts",
@@ -19,9 +19,7 @@
19
19
  "build": "rollup -c rollup.config.js",
20
20
  "watch": "rollup -w -c rollup.config.js",
21
21
  "types": "cat src/definition-schema.json | json2ts --style.tabWidth=4 > src/definition-schema.d.ts",
22
- "patch": "npm version patch --tag-version-prefix=''",
23
- "minor": "npm version minor --tag-version-prefix=''",
24
- "release": "npm run build && npm run types && git push && git push --tag"
22
+ "release": "npm run build && npm run types && npm version patch --tag-version-prefix='' && git push && git push --tag"
25
23
  },
26
24
  "dependencies": {
27
25
  "echarts": "5.6.0",
@@ -52,7 +52,7 @@ export type ChartName = string;
52
52
  * If timeseries is checked in the settings, then this should be an ISO String date like 2023-11-04T22:47:52.351152+00:00. But this works with many other formats as well.
53
53
  */
54
54
  export type XValue = string;
55
- export type YValue = number;
55
+ export type YValue = string;
56
56
  /**
57
57
  * Controls the symbol size for line and scatter charts.
58
58
  */
@@ -179,7 +179,7 @@
179
179
  },
180
180
  "y": {
181
181
  "title": "Y-Value",
182
- "type": "number",
182
+ "type": "string",
183
183
  "order": 2,
184
184
  "required": true
185
185
  },
@@ -33,16 +33,17 @@ import { InputData } from './definition-schema'
33
33
  import { EChartsOption, ScatterSeriesOption, SeriesOption } from 'echarts'
34
34
  import { TitleOption } from 'echarts/types/dist/shared'
35
35
 
36
+ type Theme = {
37
+ theme_name: string
38
+ theme_object: any
39
+ }
36
40
  @customElement('widget-linechart-versionplaceholder')
37
41
  export class WidgetLinechart extends LitElement {
38
42
  @property({ type: Object })
39
43
  inputData?: InputData
40
44
 
41
45
  @property({ type: Object })
42
- themeObject?: any
43
-
44
- @property({ type: String })
45
- themeName?: string
46
+ theme?: Theme
46
47
 
47
48
  @state()
48
49
  private canvasList: Map<
@@ -172,12 +173,8 @@ export class WidgetLinechart extends LitElement {
172
173
  this.applyData()
173
174
  }
174
175
 
175
- if (changedProperties.has('themeObject')) {
176
- this.registerTheme(this.themeName, this.themeObject)
177
- }
178
-
179
- if (changedProperties.has('themeName')) {
180
- this.registerTheme(this.themeName, this.themeObject)
176
+ if (changedProperties.has('theme')) {
177
+ this.registerTheme(this.theme)
181
178
  this.deleteCharts()
182
179
  this.transformData()
183
180
  this.applyData()
@@ -200,10 +197,11 @@ export class WidgetLinechart extends LitElement {
200
197
  }
201
198
  }
202
199
 
203
- registerTheme(themeName?: string, themeObject?: any) {
204
- if (!themeObject || !themeName) return
200
+ registerTheme(theme?: Theme) {
201
+ if (!theme || !theme.theme_object || !theme.theme_name) return
205
202
 
206
- echarts.registerTheme(themeName, this.themeObject)
203
+ console.log('Registering theme', theme)
204
+ echarts.registerTheme(theme.theme_name, theme.theme_object)
207
205
  }
208
206
 
209
207
  transformData() {
@@ -270,9 +268,7 @@ export class WidgetLinechart extends LitElement {
270
268
  data: data2 ?? []
271
269
  }
272
270
  let chartName = ds.advanced?.chartName ?? ''
273
- if (chartName.includes('#split#')) {
274
- chartName = prefix + '-' + chartName
275
- }
271
+ chartName = chartName.replace('#split#', prefix)
276
272
 
277
273
  const chart = this.setupChart(chartName)
278
274
  chart?.series.push(pds)
@@ -298,6 +294,12 @@ export class WidgetLinechart extends LitElement {
298
294
  return 'category'
299
295
  }
300
296
 
297
+ yAxisType(): 'value' | 'log' | 'category' | undefined {
298
+ const onePoint = this.inputData?.dataseries?.[0]?.data?.[0]
299
+ if (!isNaN(Number(onePoint?.y))) return 'value'
300
+ return 'category'
301
+ }
302
+
301
303
  applyData() {
302
304
  const modifier = 1
303
305
 
@@ -317,6 +319,7 @@ export class WidgetLinechart extends LitElement {
317
319
  // option.xAxis.axisLine.lineStyle.width = 2 * modifier
318
320
  // option.xAxis.axisLabel.fontSize = 20 * modifier
319
321
  option.xAxis.type = this.xAxisType()
322
+ option.yAxis.type = this.yAxisType()
320
323
 
321
324
  option.yAxis.name = this.inputData?.axis?.yAxisLabel ?? ''
322
325
  // option.yAxis.axisLine.lineStyle.width = 2 * modifier
@@ -324,7 +327,7 @@ export class WidgetLinechart extends LitElement {
324
327
  option.yAxis.scale = this.inputData?.axis?.yAxisScaling ?? false
325
328
 
326
329
  option.series = chart.series
327
-
330
+ // console.log('Applying data to chart', label, option)
328
331
  if (chart.series.length <= 1) option.legend.show = false
329
332
  const oldOption: any = chart.echart?.getOption() ?? {}
330
333
  const notMerge = oldOption.series?.length !== chart.series.length
@@ -358,7 +361,7 @@ export class WidgetLinechart extends LitElement {
358
361
  newContainer.setAttribute('class', 'sizer')
359
362
  this.chartContainer.appendChild(newContainer)
360
363
 
361
- const newChart = echarts.init(newContainer, this.themeName)
364
+ const newChart = echarts.init(newContainer, this.theme?.theme_name)
362
365
  const chart = { echart: newChart, series: [] as SeriesOption[], element: newContainer }
363
366
  this.canvasList.set(label, chart)
364
367
  //@ts-ignore