@record-evolution/widget-linechart 1.4.14 → 1.5.1

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.
@@ -2,19 +2,19 @@ import { html, css, LitElement } from 'lit'
2
2
  import { repeat } from 'lit/directives/repeat.js'
3
3
  import { property, state } from 'lit/decorators.js'
4
4
  import Chart, { ChartDataset } from 'chart.js/auto'
5
- import tinycolor from 'tinycolor2'
5
+ import tinycolor, { ColorInput } from 'tinycolor2'
6
6
  // This does not work. See comments at the end of the file.
7
7
  // import 'chartjs-adapter-dayjs-4/dist/chartjs-adapter-dayjs-4.esm';
8
8
  // import 'chartjs-adapter-moment';
9
9
  // import 'chartjs-adapter-date-fns';
10
- import { ConfigureTheChart } from './definition-schema.js'
10
+ import { InputData } from './definition-schema.js'
11
11
 
12
- type Dataseries = Exclude<ConfigureTheChart['dataseries'], undefined>[number]
12
+ type Dataseries = Exclude<InputData['dataseries'], undefined>[number]
13
13
  type Data = Exclude<Dataseries['data'], undefined>[number]
14
14
 
15
15
  export class WidgetLinechart extends LitElement {
16
16
  @property({ type: Object })
17
- inputData?: ConfigureTheChart
17
+ inputData?: InputData
18
18
 
19
19
  @state()
20
20
  private canvasList: Map<string, { chart?: any; dataSets: Dataseries[] }> = new Map()
@@ -38,8 +38,10 @@ export class WidgetLinechart extends LitElement {
38
38
 
39
39
  // reset all existing chart dataseries
40
40
  this.canvasList.forEach((chartM) => (chartM.dataSets = []))
41
+ this.inputData.dataseries.sort((a, b) => (a.advanced?.drawOrder ?? 0) - (b.advanced?.drawOrder ?? 0))
41
42
  this.inputData.dataseries.forEach((ds) => {
42
- ds.chartName = ds.chartName ?? ''
43
+ ds.advanced ??= {}
44
+ ds.advanced.chartName ??= ''
43
45
  if (ds.borderDash && typeof ds.borderDash === 'string') {
44
46
  ds.borderDash = JSON.parse(ds.borderDash)
45
47
  } else {
@@ -48,45 +50,46 @@ export class WidgetLinechart extends LitElement {
48
50
 
49
51
  // pivot data
50
52
  const distincts = [...new Set(ds.data?.map((d: Data) => d.pivot))].sort()
51
- const derivedBgColors = tinycolor(ds.backgroundColor)
53
+ const derivedBgColors = tinycolor(ds.backgroundColor as ColorInput | undefined)
52
54
  .monochromatic(distincts.length)
53
55
  .map((c: any) => c.toHexString())
54
- const derivedBdColors = tinycolor(ds.borderColor)
56
+ const derivedBdColors = tinycolor(ds.borderColor as ColorInput | undefined)
55
57
  .monochromatic(distincts.length)
56
58
  .map((c: any) => c.toHexString())
59
+ //sd
60
+ distincts.forEach((piv, i) => {
61
+ const prefix = piv ? `${piv} - ` : ''
62
+ const pds: any = {
63
+ label: prefix + ds.label,
64
+ type: ds.type,
65
+ showLine: true,
66
+ borderColor: ds.advanced?.chartName?.includes('#split#')
67
+ ? ds.borderColor
68
+ : derivedBdColors[i],
69
+ backgroundColor: ds.advanced?.chartName?.includes('#split#')
70
+ ? ds.backgroundColor
71
+ : derivedBdColors[i],
72
+ styling: ds.styling,
73
+ pointStyle: ds.styling?.pointStyle,
74
+ radius: ds.styling?.radius,
75
+ fill: ds.styling?.fill,
76
+ borderWidth: ds.styling?.borderWidth,
77
+ borderDash: ds.borderDash,
78
+ advanced: ds.advanced,
79
+ data: distincts.length === 1 ? ds.data : ds.data?.filter((d) => d.pivot === piv)
80
+ }
81
+ let chartName = ds.advanced?.chartName ?? ''
82
+ if (chartName.includes('#split#')) {
83
+ chartName = chartName + '-' + piv
84
+ }
85
+ // If the chartName ends with :pivot: then create a seperate chart for each pivoted dataseries
57
86
 
58
- if (distincts.length > 1) {
59
- distincts.forEach((piv, i) => {
60
- const pds: any = {
61
- label: ds.label + ' ' + piv,
62
- type: ds.type,
63
- showLine: true,
64
- radius: ds.radius,
65
- pointStyle: ds.pointStyle,
66
- backgroundColor: derivedBgColors[i],
67
- borderColor: derivedBdColors[i],
68
- borderWidth: ds.borderWidth,
69
- borderDash: ds.borderDash,
70
- fill: ds.fill,
71
- data: ds.data?.filter((d) => d.pivot === piv)
72
- }
73
- // If the chartName ends with :pivot: then create a seperate chart for each pivoted dataseries
74
- const chartName = ds.chartName?.includes('#pivot#')
75
- ? ds.chartName + piv
76
- : ds.chartName ?? ''
77
- if (!this.canvasList.has(chartName)) {
78
- // initialize new charts
79
- this.canvasList.set(chartName, { chart: undefined, dataSets: [] as Dataseries[] })
80
- }
81
- this.canvasList.get(chartName)?.dataSets.push(pds)
82
- })
83
- } else {
84
- if (!this.canvasList.has(ds.chartName)) {
87
+ if (!this.canvasList.has(chartName)) {
85
88
  // initialize new charts
86
- this.canvasList.set(ds.chartName, { chart: undefined, dataSets: [] as Dataseries[] })
89
+ this.canvasList.set(chartName, { chart: undefined, dataSets: [] as Dataseries[] })
87
90
  }
88
- this.canvasList.get(ds.chartName)?.dataSets.push(ds)
89
- }
91
+ this.canvasList.get(chartName)?.dataSets.push(pds)
92
+ })
90
93
  })
91
94
  // prevent duplicate transformation
92
95
  this.inputData.dataseries = []
@@ -101,17 +104,17 @@ export class WidgetLinechart extends LitElement {
101
104
  if (chart) {
102
105
  chart.data.datasets = dataSets
103
106
  chart.options.scales.x.type = this.xAxisType()
104
- chart.options.scales.x.title.display = !!this.inputData?.settings?.xAxisLabel
105
- chart.options.scales.x.title.text = this.inputData?.settings?.xAxisLabel
106
- chart.options.scales.y.title.display = !!this.inputData?.settings?.yAxisLabel
107
- chart.options.scales.y.title.text = this.inputData?.settings?.yAxisLabel
107
+ chart.options.scales.x.title.display = !!this.inputData?.axis?.xAxisLabel
108
+ chart.options.scales.x.title.text = this.inputData?.axis?.xAxisLabel
109
+ chart.options.scales.y.title.display = !!this.inputData?.axis?.yAxisLabel
110
+ chart.options.scales.y.title.text = this.inputData?.axis?.yAxisLabel
108
111
  chart?.update('resize')
109
112
  }
110
113
  })
111
114
  }
112
115
 
113
116
  xAxisType(): 'linear' | 'logarithmic' | 'category' | 'time' | 'timeseries' | undefined {
114
- if (this.inputData?.settings?.timeseries) return 'time'
117
+ if (this.inputData?.axis?.timeseries) return 'time'
115
118
  const onePoint = this.inputData?.dataseries?.[0].data?.[0]
116
119
  if (!isNaN(Number(onePoint?.x))) return 'linear'
117
120
  return 'category'
@@ -148,14 +151,14 @@ export class WidgetLinechart extends LitElement {
148
151
  x: {
149
152
  type: this.xAxisType(),
150
153
  title: {
151
- display: !!this.inputData?.settings?.xAxisLabel,
152
- text: this.inputData?.settings?.xAxisLabel
154
+ display: !!this.inputData?.axis?.xAxisLabel,
155
+ text: this.inputData?.axis?.xAxisLabel
153
156
  }
154
157
  },
155
158
  y: {
156
159
  title: {
157
- display: !!this.inputData?.settings?.yAxisLabel,
158
- text: this.inputData?.settings?.yAxisLabel
160
+ display: !!this.inputData?.axis?.yAxisLabel,
161
+ text: this.inputData?.axis?.yAxisLabel
159
162
  }
160
163
  }
161
164
  }
@@ -227,15 +230,11 @@ export class WidgetLinechart extends LitElement {
227
230
  return html`
228
231
  <div class="wrapper">
229
232
  <header>
230
- <h3 class="paging" ?active=${this.inputData?.settings?.title}>
231
- ${this.inputData?.settings?.title}
232
- </h3>
233
- <p class="paging" ?active=${this.inputData?.settings?.subTitle}>
234
- ${this.inputData?.settings?.subTitle}
235
- </p>
233
+ <h3 class="paging" ?active=${this.inputData?.title}>${this.inputData?.title}</h3>
234
+ <p class="paging" ?active=${this.inputData?.subTitle}>${this.inputData?.subTitle}</p>
236
235
  </header>
237
236
 
238
- <div class="chart-container ${this?.inputData?.settings?.columnLayout ? 'columnLayout' : ''}">
237
+ <div class="chart-container ${this?.inputData?.axis?.columnLayout ? 'columnLayout' : ''}">
239
238
  ${repeat(
240
239
  [...this.canvasList.entries()].sort(),
241
240
  ([chartName, chartM]) => chartName,