@operato/chart 2.0.0-beta.25

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.
Files changed (114) hide show
  1. package/.editorconfig +29 -0
  2. package/.storybook/main.js +3 -0
  3. package/.storybook/preview.js +29 -0
  4. package/.storybook/server.mjs +8 -0
  5. package/CHANGELOG.md +17 -0
  6. package/README.md +0 -0
  7. package/assets/images/icon-editor-gradient-direction.png +0 -0
  8. package/assets/images/icon-properties-label.png +0 -0
  9. package/assets/images/icon-properties-line-type.png +0 -0
  10. package/assets/images/icon-properties-table.png +0 -0
  11. package/assets/images/no-image.png +0 -0
  12. package/demo/index.html +33 -0
  13. package/dist/src/chartjs/config-converter.d.ts +29 -0
  14. package/dist/src/chartjs/config-converter.js +218 -0
  15. package/dist/src/chartjs/config-converter.js.map +1 -0
  16. package/dist/src/chartjs/ox-chart-js.d.ts +17 -0
  17. package/dist/src/chartjs/ox-chart-js.js +46 -0
  18. package/dist/src/chartjs/ox-chart-js.js.map +1 -0
  19. package/dist/src/editors/configurer.d.ts +52 -0
  20. package/dist/src/editors/configurer.js +198 -0
  21. package/dist/src/editors/configurer.js.map +1 -0
  22. package/dist/src/editors/index.d.ts +6 -0
  23. package/dist/src/editors/index.js +8 -0
  24. package/dist/src/editors/index.js.map +1 -0
  25. package/dist/src/editors/input-chart-abstract.d.ts +27 -0
  26. package/dist/src/editors/input-chart-abstract.js +273 -0
  27. package/dist/src/editors/input-chart-abstract.js.map +1 -0
  28. package/dist/src/editors/input-chart-multi-series-abstract.d.ts +17 -0
  29. package/dist/src/editors/input-chart-multi-series-abstract.js +418 -0
  30. package/dist/src/editors/input-chart-multi-series-abstract.js.map +1 -0
  31. package/dist/src/editors/input-chart-styles.d.ts +1 -0
  32. package/dist/src/editors/input-chart-styles.js +167 -0
  33. package/dist/src/editors/input-chart-styles.js.map +1 -0
  34. package/dist/src/editors/ox-input-chart-hbar.d.ts +11 -0
  35. package/dist/src/editors/ox-input-chart-hbar.js +220 -0
  36. package/dist/src/editors/ox-input-chart-hbar.js.map +1 -0
  37. package/dist/src/editors/ox-input-chart-mixed.d.ts +8 -0
  38. package/dist/src/editors/ox-input-chart-mixed.js +237 -0
  39. package/dist/src/editors/ox-input-chart-mixed.js.map +1 -0
  40. package/dist/src/editors/ox-input-chart-pie.d.ts +11 -0
  41. package/dist/src/editors/ox-input-chart-pie.js +67 -0
  42. package/dist/src/editors/ox-input-chart-pie.js.map +1 -0
  43. package/dist/src/editors/ox-input-chart-radar.d.ts +8 -0
  44. package/dist/src/editors/ox-input-chart-radar.js +52 -0
  45. package/dist/src/editors/ox-input-chart-radar.js.map +1 -0
  46. package/dist/src/editors/ox-property-editor-chart.d.ts +10 -0
  47. package/dist/src/editors/ox-property-editor-chart.js +79 -0
  48. package/dist/src/editors/ox-property-editor-chart.js.map +1 -0
  49. package/dist/src/index.d.ts +0 -0
  50. package/dist/src/index.js +2 -0
  51. package/dist/src/index.js.map +1 -0
  52. package/dist/src/scichart/ox-scichart.d.ts +35 -0
  53. package/dist/src/scichart/ox-scichart.js +122 -0
  54. package/dist/src/scichart/ox-scichart.js.map +1 -0
  55. package/dist/src/scichart/scichart-builder.d.ts +8 -0
  56. package/dist/src/scichart/scichart-builder.js +46 -0
  57. package/dist/src/scichart/scichart-builder.js.map +1 -0
  58. package/dist/stories/common.d.ts +2 -0
  59. package/dist/stories/common.js +44 -0
  60. package/dist/stories/common.js.map +1 -0
  61. package/dist/stories/ox-input-chart-hbar.stories.d.ts +25 -0
  62. package/dist/stories/ox-input-chart-hbar.stories.js +171 -0
  63. package/dist/stories/ox-input-chart-hbar.stories.js.map +1 -0
  64. package/dist/stories/ox-input-chart-mixed.stories.d.ts +25 -0
  65. package/dist/stories/ox-input-chart-mixed.stories.js +180 -0
  66. package/dist/stories/ox-input-chart-mixed.stories.js.map +1 -0
  67. package/dist/stories/ox-input-chart-pie.stories.d.ts +27 -0
  68. package/dist/stories/ox-input-chart-pie.stories.js +111 -0
  69. package/dist/stories/ox-input-chart-pie.stories.js.map +1 -0
  70. package/dist/stories/ox-input-chart-radar.stories.d.ts +27 -0
  71. package/dist/stories/ox-input-chart-radar.stories.js +122 -0
  72. package/dist/stories/ox-input-chart-radar.stories.js.map +1 -0
  73. package/dist/tsconfig.tsbuildinfo +1 -0
  74. package/package.json +104 -0
  75. package/src/chartjs/config-converter.ts +307 -0
  76. package/src/chartjs/ox-chart-js.ts +46 -0
  77. package/src/editors/configurer.ts +243 -0
  78. package/src/editors/index.ts +8 -0
  79. package/src/editors/input-chart-abstract.ts +315 -0
  80. package/src/editors/input-chart-multi-series-abstract.ts +429 -0
  81. package/src/editors/input-chart-styles.ts +167 -0
  82. package/src/editors/ox-input-chart-hbar.ts +226 -0
  83. package/src/editors/ox-input-chart-mixed.ts +240 -0
  84. package/src/editors/ox-input-chart-pie.ts +75 -0
  85. package/src/editors/ox-input-chart-radar.ts +54 -0
  86. package/src/editors/ox-property-editor-chart.ts +79 -0
  87. package/src/globat.d.ts +1 -0
  88. package/src/index.ts +0 -0
  89. package/src/scichart/ox-scichart.ts +143 -0
  90. package/src/scichart/scichart-builder.ts +87 -0
  91. package/src/types.d.ts +74 -0
  92. package/stories/common.ts +47 -0
  93. package/stories/ox-input-chart-hbar.stories.ts +185 -0
  94. package/stories/ox-input-chart-mixed.stories.ts +194 -0
  95. package/stories/ox-input-chart-pie.stories.ts +126 -0
  96. package/stories/ox-input-chart-radar.stories.ts +137 -0
  97. package/themes/dark-hc.css +151 -0
  98. package/themes/dark-mc.css +151 -0
  99. package/themes/dark.css +151 -0
  100. package/themes/grist-theme.css +177 -0
  101. package/themes/light-hc.css +151 -0
  102. package/themes/light-mc.css +151 -0
  103. package/themes/light.css +151 -0
  104. package/themes/md-typescale-styles.css +100 -0
  105. package/themes/spacing.css +43 -0
  106. package/themes/state-color.css +6 -0
  107. package/translations/en.json +44 -0
  108. package/translations/ja.json +44 -0
  109. package/translations/ko.json +44 -0
  110. package/translations/ms.json +8 -0
  111. package/translations/zh.json +44 -0
  112. package/tsconfig.json +24 -0
  113. package/web-dev-server.config.mjs +27 -0
  114. package/web-test-runner.config.mjs +41 -0
@@ -0,0 +1,315 @@
1
+ import '@operato/i18n/ox-i18n.js'
2
+
3
+ import { html, PropertyValueMap } from 'lit'
4
+ import { property } from 'lit/decorators.js'
5
+ import { random as randomColor, TinyColor } from '@ctrl/tinycolor'
6
+
7
+ import { InputChartStyles } from './input-chart-styles'
8
+ import { Configurer } from './configurer'
9
+ import { OxFormField } from '@operato/input'
10
+
11
+ export class InputChartAbstract extends OxFormField {
12
+ static styles = [InputChartStyles]
13
+
14
+ @property({ type: Object }) value: OperatoChart.ChartConfig | null = null
15
+
16
+ configurer: Configurer = new Configurer(this.value || null, () => {
17
+ return this.getDefaultChartConfig(this.getChartType(), this.getDefaultDatasets())
18
+ })
19
+
20
+ render() {
21
+ const configurer = this.configurer
22
+
23
+ return html`
24
+ <legend><ox-i18n msgid="label.chart">Chart</ox-i18n></legend>
25
+
26
+ <label for="theme"> <ox-i18n msgid="label.theme">Theme</ox-i18n> </label>
27
+ <select id="theme" value-key="theme" class="select-content" .value=${configurer.theme || ''}>
28
+ <option value="dark">dark</option>
29
+ <option value="light">light</option>
30
+ </select>
31
+
32
+ <input id="tooltip" type="checkbox" value-key="tooltip" ?checked=${configurer.tooltip} />
33
+ <label for="tooltip"> <ox-i18n msgid="label.tooltip">Tooltip</ox-i18n> </label>
34
+
35
+ <input id="animation" type="checkbox" value-key="animation" ?checked=${configurer.animation} />
36
+ <label for="animation"> <ox-i18n msgid="label.animation">Animation</ox-i18n> </label>
37
+
38
+ <input id="display" type="checkbox" value-key="display" ?checked=${configurer.display} />
39
+ <label for="display"> <ox-i18n msgid="label.legend">Legend</ox-i18n> </label>
40
+
41
+ <input id="stacked" type="checkbox" value-key="stacked" ?checked=${configurer.stacked} />
42
+ <label for="stacked"> <ox-i18n msgid="label.stacked">Stacked</ox-i18n> </label>
43
+
44
+ ${configurer.display
45
+ ? html`
46
+ <label for="position"> <ox-i18n msgid="label.position">Position</ox-i18n> </label>
47
+ <select id="position" value-key="position" class="select-content" .value=${configurer.position || ''}>
48
+ <option value="top">top</option>
49
+ <option value="right">right</option>
50
+ <option value="bottom">bottom</option>
51
+ <option value="left">left</option>
52
+ </select>
53
+ `
54
+ : html``}
55
+ ${this.subTemplate()}
56
+ `
57
+ }
58
+
59
+ connectedCallback() {
60
+ super.connectedCallback()
61
+
62
+ this.renderRoot.addEventListener('change', this.onValuesChanged.bind(this))
63
+ }
64
+
65
+ displayValueTemplate() {
66
+ const configurer = this.configurer
67
+
68
+ return html`
69
+ <label for="value-prefix"> <ox-i18n msgid="label.value-prefix">Value Prefix</ox-i18n> </label>
70
+ <input
71
+ id="value-prefix"
72
+ type="text"
73
+ value-key="series.valuePrefix"
74
+ .value=${configurer.series.valuePrefix || ''}
75
+ />
76
+
77
+ <label for="value-suffix"> <ox-i18n msgid="label.value-suffix">Value Suffix</ox-i18n> </label>
78
+ <input
79
+ id="value-suffix"
80
+ type="text"
81
+ value-key="series.valueSuffix"
82
+ .value=${configurer.series.valueSuffix || ''}
83
+ />
84
+
85
+ <input
86
+ id="display-value"
87
+ type="checkbox"
88
+ value-key="series.displayValue"
89
+ ?checked=${!!configurer.series.displayValue}
90
+ />
91
+ <label for="display-value"> <ox-i18n msgid="label.value-display">Value Display</ox-i18n> </label>
92
+
93
+ ${configurer.series.displayValue
94
+ ? html`
95
+ <label for="font-color"> <ox-i18n msgid="label.font-color">Font Color</ox-i18n> </label>
96
+ <ox-input-color
97
+ id="font-color"
98
+ value-key="series.defaultFontColor"
99
+ .value=${configurer.series.defaultFontColor || '#000'}
100
+ ></ox-input-color>
101
+ <label for="font-size"> <ox-i18n msgid="label.font-size">Font Size</ox-i18n> </label>
102
+ <input
103
+ id="font-size"
104
+ type="number"
105
+ value-key="series.defaultFontSize"
106
+ value=${configurer.series.defaultFontSize || 10}
107
+ />
108
+ <label for="data-label-anchor"> <ox-i18n msgid="label.position">Position</ox-i18n> </label>
109
+ <select
110
+ id="data-label-anchor"
111
+ value-key="series.dataLabelAnchor"
112
+ value=${configurer.series.dataLabelAnchor || 'center'}
113
+ >
114
+ <option value="start">Start</option>
115
+ <option value="center" selected>Center</option>
116
+ <option value="end">End</option>
117
+ </select>
118
+ `
119
+ : html``}
120
+ `
121
+ }
122
+
123
+ subTemplate() {
124
+ return html``
125
+ }
126
+
127
+ getChartType(): 'bar' | 'horizontalBar' | 'line' | 'radar' | 'pie' | 'mixed' {
128
+ return 'bar'
129
+ }
130
+
131
+ getDefaultDatasets(): OperatoChart.Dataset[] {
132
+ return [this.getDefaultDataset('bar')]
133
+ }
134
+
135
+ getDefaultDataset(seriesType: 'bar' | 'horizontalBar' | 'line' | 'radar' | 'pie'): OperatoChart.Dataset {
136
+ return {
137
+ label: 'Series 1',
138
+ data: [],
139
+ borderWidth: 1,
140
+ dataKey: '',
141
+ yAxisID: 'left',
142
+ color: '#000',
143
+ backgroundColor: '#FFFFFF',
144
+ type: seriesType,
145
+ stack: '',
146
+ fill: false,
147
+ lineTension: 0.4,
148
+ pointStyle: 'circle',
149
+ pointRadius: 3,
150
+ valuePrefix: '',
151
+ valueSuffix: '',
152
+ displayValue: false
153
+ }
154
+ }
155
+
156
+ getDefaultChartConfig(
157
+ type: 'bar' | 'horizontalBar' | 'line' | 'radar' | 'pie' | 'mixed',
158
+ datasets?: OperatoChart.Dataset[]
159
+ ): OperatoChart.ChartConfig {
160
+ return {
161
+ data: {
162
+ datasets: datasets || [],
163
+ labelDataKey: ''
164
+ },
165
+ options: {
166
+ theme: 'light',
167
+ tooltip: true,
168
+ animation: true,
169
+ legend: {
170
+ display: true,
171
+ position: 'top'
172
+ },
173
+ scales: {
174
+ xAxes: [this.getDefaultAxisOptions()],
175
+ yAxes: [this.getDefaultAxisOptions()]
176
+ },
177
+ stacked: false,
178
+ xGridLine: true,
179
+ yGridLine: true,
180
+ y2ndGridLine: false,
181
+ multiAxis: false
182
+ },
183
+ type
184
+ }
185
+ }
186
+
187
+ getDefaultAxisOptions(): OperatoChart.AxisOptions {
188
+ return {
189
+ axisTitle: '',
190
+ barSpacing: 0,
191
+ categorySpacing: 0,
192
+ barPercentage: 0.9,
193
+ ticks: {
194
+ display: true,
195
+ autoMin: true,
196
+ autoMax: true,
197
+ min: undefined,
198
+ max: undefined,
199
+ stepSize: undefined
200
+ }
201
+ }
202
+ }
203
+
204
+ onValuesChanged(e: Event) {
205
+ e.stopPropagation()
206
+
207
+ const element = e.target as HTMLInputElement
208
+ let key = element.getAttribute('value-key')
209
+ let value = element.value
210
+
211
+ if (!key) {
212
+ return
213
+ }
214
+
215
+ value = this._getElementValue(element)
216
+
217
+ const attrs = key.split('.')
218
+ let attr = attrs.shift() || ''
219
+ let variable: any = this.configurer
220
+
221
+ while (attrs.length > 0) {
222
+ variable = variable[attr]
223
+ attr = attrs.shift() || ''
224
+ }
225
+
226
+ variable[attr] = value
227
+
228
+ this.value = { ...this.configurer.value }
229
+
230
+ this.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true }))
231
+ this.requestUpdate()
232
+ }
233
+
234
+ onTapAddTab(e: Event) {
235
+ const configurer = this.configurer
236
+
237
+ if (!configurer.config.data.datasets) return
238
+
239
+ const lastSeriesIndex = configurer.config.data.datasets.length
240
+ const chartType = configurer.series.type || configurer.config.type
241
+ const color = configurer.datasets[lastSeriesIndex - 1]?.backgroundColor
242
+ const lastSeriesColor = new TinyColor(Array.isArray(color) ? color[0] : color)
243
+
244
+ const seriesModel = this._getSeriesModel({
245
+ chartType: chartType!,
246
+ datasetsLength: lastSeriesIndex,
247
+ lastSeriesColor
248
+ })
249
+
250
+ configurer.config.data.datasets.push(seriesModel)
251
+ this.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true }))
252
+ configurer.currentSeriesIndex = lastSeriesIndex
253
+
254
+ this.value = { ...this.configurer.value }
255
+ }
256
+
257
+ onTapRemoveCurrentTab(e: Event) {
258
+ const configurer = this.configurer
259
+
260
+ if (!configurer.config.data.datasets) return
261
+
262
+ let currIndex = configurer.currentSeriesIndex
263
+ this.configurer.data.datasets.splice(currIndex, 1)
264
+
265
+ currIndex--
266
+
267
+ if (currIndex < 0) currIndex = 0
268
+
269
+ this.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true }))
270
+ configurer.currentSeriesIndex = currIndex
271
+
272
+ this.requestUpdate()
273
+ }
274
+
275
+ _getSeriesModel({
276
+ chartType,
277
+ datasetsLength,
278
+ lastSeriesColor
279
+ }: {
280
+ chartType: string
281
+ datasetsLength: number
282
+ lastSeriesColor: TinyColor
283
+ }) {
284
+ const addSeriesOption: any = {
285
+ label: `series ${datasetsLength + 1}`,
286
+ data: [],
287
+ borderWidth: 1,
288
+ dataKey: '',
289
+ yAxisID: 'left',
290
+ color: randomColor({
291
+ hue: lastSeriesColor.toHsv().h
292
+ }).toRgbString(),
293
+ stack: ''
294
+ }
295
+
296
+ addSeriesOption.type = addSeriesOption.chartType = chartType
297
+ return addSeriesOption
298
+ }
299
+
300
+ _getElementValue(element: HTMLElement) {
301
+ switch (element.tagName) {
302
+ case 'INPUT':
303
+ switch ((element as HTMLInputElement).type) {
304
+ case 'checkbox':
305
+ return (element as HTMLInputElement).checked
306
+ case 'number':
307
+ return Number((element as HTMLInputElement).value) || 0
308
+ case 'text':
309
+ return String((element as HTMLInputElement).value)
310
+ }
311
+ default:
312
+ return (element as any).value
313
+ }
314
+ }
315
+ }