@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.
- package/.editorconfig +29 -0
- package/.storybook/main.js +3 -0
- package/.storybook/preview.js +29 -0
- package/.storybook/server.mjs +8 -0
- package/CHANGELOG.md +17 -0
- package/README.md +0 -0
- package/assets/images/icon-editor-gradient-direction.png +0 -0
- package/assets/images/icon-properties-label.png +0 -0
- package/assets/images/icon-properties-line-type.png +0 -0
- package/assets/images/icon-properties-table.png +0 -0
- package/assets/images/no-image.png +0 -0
- package/demo/index.html +33 -0
- package/dist/src/chartjs/config-converter.d.ts +29 -0
- package/dist/src/chartjs/config-converter.js +218 -0
- package/dist/src/chartjs/config-converter.js.map +1 -0
- package/dist/src/chartjs/ox-chart-js.d.ts +17 -0
- package/dist/src/chartjs/ox-chart-js.js +46 -0
- package/dist/src/chartjs/ox-chart-js.js.map +1 -0
- package/dist/src/editors/configurer.d.ts +52 -0
- package/dist/src/editors/configurer.js +198 -0
- package/dist/src/editors/configurer.js.map +1 -0
- package/dist/src/editors/index.d.ts +6 -0
- package/dist/src/editors/index.js +8 -0
- package/dist/src/editors/index.js.map +1 -0
- package/dist/src/editors/input-chart-abstract.d.ts +27 -0
- package/dist/src/editors/input-chart-abstract.js +273 -0
- package/dist/src/editors/input-chart-abstract.js.map +1 -0
- package/dist/src/editors/input-chart-multi-series-abstract.d.ts +17 -0
- package/dist/src/editors/input-chart-multi-series-abstract.js +418 -0
- package/dist/src/editors/input-chart-multi-series-abstract.js.map +1 -0
- package/dist/src/editors/input-chart-styles.d.ts +1 -0
- package/dist/src/editors/input-chart-styles.js +167 -0
- package/dist/src/editors/input-chart-styles.js.map +1 -0
- package/dist/src/editors/ox-input-chart-hbar.d.ts +11 -0
- package/dist/src/editors/ox-input-chart-hbar.js +220 -0
- package/dist/src/editors/ox-input-chart-hbar.js.map +1 -0
- package/dist/src/editors/ox-input-chart-mixed.d.ts +8 -0
- package/dist/src/editors/ox-input-chart-mixed.js +237 -0
- package/dist/src/editors/ox-input-chart-mixed.js.map +1 -0
- package/dist/src/editors/ox-input-chart-pie.d.ts +11 -0
- package/dist/src/editors/ox-input-chart-pie.js +67 -0
- package/dist/src/editors/ox-input-chart-pie.js.map +1 -0
- package/dist/src/editors/ox-input-chart-radar.d.ts +8 -0
- package/dist/src/editors/ox-input-chart-radar.js +52 -0
- package/dist/src/editors/ox-input-chart-radar.js.map +1 -0
- package/dist/src/editors/ox-property-editor-chart.d.ts +10 -0
- package/dist/src/editors/ox-property-editor-chart.js +79 -0
- package/dist/src/editors/ox-property-editor-chart.js.map +1 -0
- package/dist/src/index.d.ts +0 -0
- package/dist/src/index.js +2 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/scichart/ox-scichart.d.ts +35 -0
- package/dist/src/scichart/ox-scichart.js +122 -0
- package/dist/src/scichart/ox-scichart.js.map +1 -0
- package/dist/src/scichart/scichart-builder.d.ts +8 -0
- package/dist/src/scichart/scichart-builder.js +46 -0
- package/dist/src/scichart/scichart-builder.js.map +1 -0
- package/dist/stories/common.d.ts +2 -0
- package/dist/stories/common.js +44 -0
- package/dist/stories/common.js.map +1 -0
- package/dist/stories/ox-input-chart-hbar.stories.d.ts +25 -0
- package/dist/stories/ox-input-chart-hbar.stories.js +171 -0
- package/dist/stories/ox-input-chart-hbar.stories.js.map +1 -0
- package/dist/stories/ox-input-chart-mixed.stories.d.ts +25 -0
- package/dist/stories/ox-input-chart-mixed.stories.js +180 -0
- package/dist/stories/ox-input-chart-mixed.stories.js.map +1 -0
- package/dist/stories/ox-input-chart-pie.stories.d.ts +27 -0
- package/dist/stories/ox-input-chart-pie.stories.js +111 -0
- package/dist/stories/ox-input-chart-pie.stories.js.map +1 -0
- package/dist/stories/ox-input-chart-radar.stories.d.ts +27 -0
- package/dist/stories/ox-input-chart-radar.stories.js +122 -0
- package/dist/stories/ox-input-chart-radar.stories.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +104 -0
- package/src/chartjs/config-converter.ts +307 -0
- package/src/chartjs/ox-chart-js.ts +46 -0
- package/src/editors/configurer.ts +243 -0
- package/src/editors/index.ts +8 -0
- package/src/editors/input-chart-abstract.ts +315 -0
- package/src/editors/input-chart-multi-series-abstract.ts +429 -0
- package/src/editors/input-chart-styles.ts +167 -0
- package/src/editors/ox-input-chart-hbar.ts +226 -0
- package/src/editors/ox-input-chart-mixed.ts +240 -0
- package/src/editors/ox-input-chart-pie.ts +75 -0
- package/src/editors/ox-input-chart-radar.ts +54 -0
- package/src/editors/ox-property-editor-chart.ts +79 -0
- package/src/globat.d.ts +1 -0
- package/src/index.ts +0 -0
- package/src/scichart/ox-scichart.ts +143 -0
- package/src/scichart/scichart-builder.ts +87 -0
- package/src/types.d.ts +74 -0
- package/stories/common.ts +47 -0
- package/stories/ox-input-chart-hbar.stories.ts +185 -0
- package/stories/ox-input-chart-mixed.stories.ts +194 -0
- package/stories/ox-input-chart-pie.stories.ts +126 -0
- package/stories/ox-input-chart-radar.stories.ts +137 -0
- package/themes/dark-hc.css +151 -0
- package/themes/dark-mc.css +151 -0
- package/themes/dark.css +151 -0
- package/themes/grist-theme.css +177 -0
- package/themes/light-hc.css +151 -0
- package/themes/light-mc.css +151 -0
- package/themes/light.css +151 -0
- package/themes/md-typescale-styles.css +100 -0
- package/themes/spacing.css +43 -0
- package/themes/state-color.css +6 -0
- package/translations/en.json +44 -0
- package/translations/ja.json +44 -0
- package/translations/ko.json +44 -0
- package/translations/ms.json +8 -0
- package/translations/zh.json +44 -0
- package/tsconfig.json +24 -0
- package/web-dev-server.config.mjs +27 -0
- 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
|
+
}
|