@record-evolution/widget-linechart 1.4.9 → 1.4.10

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.4.9",
6
+ "version": "1.4.10",
7
7
  "type": "module",
8
8
  "main": "dist/widget-linechart.js",
9
9
  "types": "dist/src/widget-linechart.d.ts",
@@ -16,6 +16,7 @@
16
16
  "start": "tsc && concurrently -k -r \"tsc --watch --preserveWatchOutput\" \"wds\"",
17
17
  "build": "rollup -c rollup.config.js --bundleConfigAsCjs",
18
18
  "watch": "rollup -w -c rollup.config.js --bundleConfigAsCjs",
19
+ "types": "cat src/definition-schema.json | json2ts > src/definition-schema.d.ts",
19
20
  "release": "npm version patch --tag-version-prefix='' && git push && git push --tag"
20
21
  },
21
22
  "dependencies": {
@@ -39,6 +40,7 @@
39
40
  "@types/tinycolor2": "^1.4.6",
40
41
  "@web/dev-server": "^0.4.0",
41
42
  "concurrently": "^8.2.2",
43
+ "json-schema-to-typescript": "^13.1.1",
42
44
  "tslib": "^2.6.2",
43
45
  "typescript": "^5.2.2"
44
46
  },
@@ -0,0 +1,115 @@
1
+ /* eslint-disable */
2
+ /**
3
+ * This file was automatically generated by json-schema-to-typescript.
4
+ * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
5
+ * and run json-schema-to-typescript to regenerate this file.
6
+ */
7
+
8
+ export type Title = string;
9
+ export type Subtitle = string;
10
+ /**
11
+ * This will apply a proper time series x-Axis. Check if your x-values are timestamps.
12
+ */
13
+ export type TimeseriesChart = boolean;
14
+ export type XAxisLabel = string;
15
+ export type YAxisLabel = string;
16
+ /**
17
+ * When multiple charts are drawn, then they will be layed out horizontically or vertically.
18
+ */
19
+ export type VerticalLayout = boolean;
20
+ /**
21
+ * The name for this data series
22
+ */
23
+ export type Label = string;
24
+ /**
25
+ * Determines the draw order of the series. Dataseries with lower numbers are drawn on top of ones with higher numbers.
26
+ */
27
+ export type DrawOrder = number;
28
+ /**
29
+ * If two dataseries have the same 'Chart' name, they will be drawn in the same chart. Otherwise they will get their own chart. If the name ends with #pivot# then a separat chart will be drawn for each pivoted dataseries.
30
+ */
31
+ export type Chart = string;
32
+ export type DrawingStyle = "bar" | "line" | "bubble";
33
+ /**
34
+ * To disable points, set this to 0.
35
+ */
36
+ export type PointRadius = number;
37
+ export type PointStyle =
38
+ | "circle"
39
+ | "cross"
40
+ | "crossRot"
41
+ | "dash"
42
+ | "line"
43
+ | "rect"
44
+ | "rectRounded"
45
+ | "rectRot"
46
+ | "star"
47
+ | "triangle";
48
+ /**
49
+ * The inner color of the bars if you chose Drawing Type 'bar' or the inner colors of the points if you chose Drawing Type 'line'.
50
+ */
51
+ export type PointOrBarColor = string;
52
+ export type LineColor = string;
53
+ /**
54
+ * In case of Drawing Type 'bar' this determines the bar's border line width.
55
+ */
56
+ export type LineWidth = number;
57
+ /**
58
+ * Specify dash length and space-between-dashes length like this: [10, 5].
59
+ */
60
+ export type LineDashStyle = string;
61
+ /**
62
+ * Check this box to turn a line chart into an area chart.
63
+ */
64
+ export type LineAreaFill = boolean;
65
+ /**
66
+ * Valid only for Bubble Chart type.
67
+ */
68
+ export type PointRadius1 = number;
69
+ /**
70
+ * You can specify a column in the input data to autogenerate dataseries for each distinct entry in this column. E.g. if you have a table with columns [city, timestamp, temperature] and specify 'city' as pivot column, then you will get a line for each city.
71
+ */
72
+ export type PivotColumn = string;
73
+ /**
74
+ * The data used to draw this data series.
75
+ */
76
+ export type Data = {
77
+ /**
78
+ * 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.
79
+ */
80
+ x: string;
81
+ y: number;
82
+ r?: PointRadius1;
83
+ pivot?: PivotColumn;
84
+ [k: string]: unknown;
85
+ }[];
86
+ export type Dataseries = {
87
+ label: Label;
88
+ order?: DrawOrder;
89
+ chartName?: Chart;
90
+ type: DrawingStyle;
91
+ radius?: PointRadius;
92
+ pointStyle?: PointStyle;
93
+ backgroundColor?: PointOrBarColor;
94
+ borderColor?: LineColor;
95
+ borderWidth?: LineWidth;
96
+ borderDash?: LineDashStyle;
97
+ fill?: LineAreaFill;
98
+ data?: Data;
99
+ [k: string]: unknown;
100
+ }[];
101
+
102
+ export interface ConfigureTheChart {
103
+ settings?: GlobalSettings;
104
+ dataseries?: Dataseries;
105
+ [k: string]: unknown;
106
+ }
107
+ export interface GlobalSettings {
108
+ title?: Title;
109
+ subTitle?: Subtitle;
110
+ timeseries?: TimeseriesChart;
111
+ xAxisLabel?: XAxisLabel;
112
+ yAxisLabel?: YAxisLabel;
113
+ columnLayout?: VerticalLayout;
114
+ [k: string]: unknown;
115
+ }
@@ -48,6 +48,7 @@
48
48
  "order": 2,
49
49
  "items": {
50
50
  "type": "object",
51
+ "required": ["label", "type"],
51
52
  "properties": {
52
53
  "label": {
53
54
  "title": "Label",
@@ -93,11 +94,13 @@
93
94
  "title": "Point or Bar Color",
94
95
  "description": "The inner color of the bars if you chose Drawing Type 'bar' or the inner colors of the points if you chose Drawing Type 'line'.",
95
96
  "type": "color",
97
+ "color": true,
96
98
  "order": 8
97
99
  },
98
100
  "borderColor": {
99
101
  "title": "Line Color",
100
102
  "type": "color",
103
+ "color": true,
101
104
  "order": 9
102
105
  },
103
106
  "borderWidth": {
@@ -126,6 +129,7 @@
126
129
  "buffersize": 1000,
127
130
  "items": {
128
131
  "type": "object",
132
+ "required": ["x", "y"],
129
133
  "properties": {
130
134
  "x": {
131
135
  "description": "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.",
@@ -7,12 +7,15 @@ import tinycolor from "tinycolor2";
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 { InputData, Data, Dataseries } from './types.js'
10
+ import { ConfigureTheChart } from './definition-schema.js';
11
+
12
+ type Dataseries = Exclude<ConfigureTheChart['dataseries'], undefined>[number]
13
+ type Data = Exclude<Dataseries['data'], undefined>[number]
11
14
 
12
15
  export class WidgetLinechart extends LitElement {
13
16
 
14
17
  @property({type: Object})
15
- inputData = {} as InputData
18
+ inputData?: ConfigureTheChart
16
19
 
17
20
  @state()
18
21
  private canvasList: Map<string, {chart?: any, dataSets: Dataseries[]}> = new Map()
@@ -33,7 +36,7 @@ export class WidgetLinechart extends LitElement {
33
36
 
34
37
  transformInputData() {
35
38
 
36
- if (!this?.inputData?.dataseries.length) return
39
+ if (!this?.inputData?.dataseries?.length) return
37
40
 
38
41
  // reset all existing chart dataseries
39
42
  this.canvasList.forEach(chartM => chartM.dataSets = [])
@@ -46,7 +49,7 @@ export class WidgetLinechart extends LitElement {
46
49
  }
47
50
 
48
51
  // pivot data
49
- const distincts = [...new Set(ds.data.map((d: Data) => d.pivot))]
52
+ const distincts = [...new Set(ds.data?.map((d: Data) => d.pivot))]
50
53
  const derivedBgColors = tinycolor(ds.backgroundColor).monochromatic(distincts.length).map((c: any) => c.toHexString())
51
54
  const derivedBdColors = tinycolor(ds.borderColor).monochromatic(distincts.length).map((c: any) => c.toHexString())
52
55
 
@@ -63,10 +66,10 @@ export class WidgetLinechart extends LitElement {
63
66
  borderWidth: ds.borderWidth,
64
67
  borderDash: ds.borderDash,
65
68
  fill: ds.fill,
66
- data: ds.data.filter(d => d.pivot === piv)
69
+ data: ds.data?.filter(d => d.pivot === piv)
67
70
  }
68
71
  // If the chartName ends with :pivot: then create a seperate chart for each pivoted dataseries
69
- const chartName = ds.chartName.endsWith('#pivot#') ? ds.chartName + piv : ds.chartName
72
+ const chartName = ds.chartName?.endsWith('#pivot#') ? ds.chartName + piv : ds.chartName ?? ''
70
73
  if (!this.canvasList.has(chartName)) {
71
74
  // initialize new charts
72
75
  this.canvasList.set(chartName, {chart: undefined, dataSets: [] as Dataseries[]})
@@ -103,11 +106,10 @@ export class WidgetLinechart extends LitElement {
103
106
  })
104
107
  }
105
108
 
106
- xAxisType() {
109
+ xAxisType(): "linear" | "logarithmic" | "category" | "time" | "timeseries" | undefined {
107
110
  if (this.inputData?.settings?.timeseries) return 'time'
108
- const onePoint = this.inputData.dataseries?.[0].data?.[0]
109
- // @ts-ignore
110
- if (onePoint && !isNaN(onePoint.x)) return 'linear'
111
+ const onePoint = this.inputData?.dataseries?.[0].data?.[0]
112
+ if (!isNaN(Number(onePoint?.x))) return 'linear'
111
113
  return 'category'
112
114
  }
113
115