@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,307 @@
|
|
|
1
|
+
import { TinyColor } from '@ctrl/tinycolor'
|
|
2
|
+
|
|
3
|
+
const _data = [
|
|
4
|
+
{ year: 2010, count: 10 },
|
|
5
|
+
{ year: 2011, count: 20 },
|
|
6
|
+
{ year: 2012, count: 15 },
|
|
7
|
+
{ year: 2013, count: 25 },
|
|
8
|
+
{ year: 2014, count: 22 },
|
|
9
|
+
{ year: 2015, count: 30 },
|
|
10
|
+
{ year: 2016, count: 28 }
|
|
11
|
+
]
|
|
12
|
+
|
|
13
|
+
function getBaseColorFromTheme(theme?: 'light' | 'dark') {
|
|
14
|
+
return new TinyColor(theme == 'dark' ? '#fff' : '#000')
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function convertConfigure(
|
|
18
|
+
config: OperatoChart.ChartConfig,
|
|
19
|
+
{ fontSize, fontFamily, fontColor }: { fontSize?: number; fontFamily?: string; fontColor?: string }
|
|
20
|
+
) {
|
|
21
|
+
if (!config) {
|
|
22
|
+
return
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const { type: chartType, options, data: fromData } = config
|
|
26
|
+
const {
|
|
27
|
+
theme,
|
|
28
|
+
animation,
|
|
29
|
+
tooltip,
|
|
30
|
+
stacked,
|
|
31
|
+
legend,
|
|
32
|
+
scales: fromScales,
|
|
33
|
+
xGridLine,
|
|
34
|
+
yGridLine,
|
|
35
|
+
y2ndGridLine,
|
|
36
|
+
multiAxis
|
|
37
|
+
} = options || {}
|
|
38
|
+
const { datasets = [] } = fromData || {}
|
|
39
|
+
|
|
40
|
+
const { xAxes = [], yAxes = [] } = fromScales || {}
|
|
41
|
+
const toScales = {} as any
|
|
42
|
+
|
|
43
|
+
chartType != 'pie' &&
|
|
44
|
+
xAxes.forEach((xAxis, index) => {
|
|
45
|
+
const { axisTitle, barSpacing, categorySpacing, barPercentage, ticks } = xAxis
|
|
46
|
+
const id = xAxes.length > 1 ? `x${index + 1}` : 'x'
|
|
47
|
+
|
|
48
|
+
toScales[id] = setupScale(
|
|
49
|
+
{
|
|
50
|
+
axis: 'x',
|
|
51
|
+
id,
|
|
52
|
+
position: 'bottom',
|
|
53
|
+
display: true,
|
|
54
|
+
title: {
|
|
55
|
+
display: !!axisTitle,
|
|
56
|
+
text: axisTitle
|
|
57
|
+
},
|
|
58
|
+
grid: {
|
|
59
|
+
display: xGridLine
|
|
60
|
+
},
|
|
61
|
+
beginAtZero: false,
|
|
62
|
+
ticks
|
|
63
|
+
},
|
|
64
|
+
{ fontSize, fontFamily, fontColor, theme }
|
|
65
|
+
)
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
chartType != 'pie' &&
|
|
69
|
+
yAxes.forEach((yAxis, index) => {
|
|
70
|
+
const { axisTitle, barSpacing, categorySpacing, barPercentage, ticks } = yAxis
|
|
71
|
+
const id = yAxes.length > 1 ? `right` : 'left'
|
|
72
|
+
|
|
73
|
+
toScales[id] = setupScale(
|
|
74
|
+
{
|
|
75
|
+
axis: 'y',
|
|
76
|
+
id,
|
|
77
|
+
position: id,
|
|
78
|
+
display: true,
|
|
79
|
+
title: {
|
|
80
|
+
display: !!axisTitle,
|
|
81
|
+
text: axisTitle
|
|
82
|
+
},
|
|
83
|
+
grid: {
|
|
84
|
+
display: index == 0 ? yGridLine : y2ndGridLine
|
|
85
|
+
},
|
|
86
|
+
ticks,
|
|
87
|
+
stacked: stacked ? true : false
|
|
88
|
+
},
|
|
89
|
+
{ fontSize, fontFamily, fontColor, theme }
|
|
90
|
+
)
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
// setup series configure
|
|
94
|
+
// for (let i in datasets) {
|
|
95
|
+
// let series = datasets[i]
|
|
96
|
+
|
|
97
|
+
// if (stacked && !series.stack) {
|
|
98
|
+
// series.stack = 'A'
|
|
99
|
+
// }
|
|
100
|
+
|
|
101
|
+
// /*
|
|
102
|
+
// * TODO from chartjs 2.9, categoryPercentage, barPercentage properties move to dataset.
|
|
103
|
+
// * so need to move related properties - categorySpacing, barSpacing should be moved to series.
|
|
104
|
+
// */
|
|
105
|
+
// if (chartType == 'bar') {
|
|
106
|
+
// let categorySpacing = (xAxes && xAxes[0].categorySpacing) || 0
|
|
107
|
+
// let barSpacing = (xAxes && xAxes[0].barSpacing) || 0
|
|
108
|
+
|
|
109
|
+
// series.categoryPercentage = 1 - categorySpacing || 1
|
|
110
|
+
// series.barPercentage = 1 - barSpacing || 0.8
|
|
111
|
+
// } else if (chartType == 'horizontalBar') {
|
|
112
|
+
// let categorySpacing = (yAxes && yAxes[0].categorySpacing) || 0
|
|
113
|
+
// let barSpacing = (yAxes && yAxes[0].barSpacing) || 0
|
|
114
|
+
|
|
115
|
+
// series.categoryPercentage = 1 - categorySpacing || 1
|
|
116
|
+
// series.barPercentage = 1 - barSpacing || 0.8
|
|
117
|
+
// }
|
|
118
|
+
|
|
119
|
+
// // _setSeriesConfigures(series, chart)
|
|
120
|
+
|
|
121
|
+
// if (!multiAxis) {
|
|
122
|
+
// if (series.yAxisID == 'right') series.yAxisID = 'left'
|
|
123
|
+
// }
|
|
124
|
+
// }
|
|
125
|
+
|
|
126
|
+
const converted = {
|
|
127
|
+
type: chartType == 'horizontalBar' ? 'bar' : chartType,
|
|
128
|
+
options: {
|
|
129
|
+
animation,
|
|
130
|
+
stacked,
|
|
131
|
+
plugins: {
|
|
132
|
+
legend: setupLegend(legend || {}, { fontSize, fontFamily, fontColor, theme }),
|
|
133
|
+
tooltip: setupTooltip({ enabled: tooltip }, { fontSize, fontFamily }),
|
|
134
|
+
title: {
|
|
135
|
+
/* new option candidate - subtitle */
|
|
136
|
+
display: false,
|
|
137
|
+
text: 'Custom Chart Title'
|
|
138
|
+
},
|
|
139
|
+
subtitle: {
|
|
140
|
+
/* new option candidate - subtitle */
|
|
141
|
+
display: false,
|
|
142
|
+
text: 'Custom Chart Subtitle'
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
scales: toScales,
|
|
146
|
+
indexAxis: chartType == 'horizontalBar' ? 'y' : chartType != 'pie' ? 'x' : ''
|
|
147
|
+
},
|
|
148
|
+
data: {
|
|
149
|
+
labels: _data.map(row => row.year),
|
|
150
|
+
datasets: datasets.map(dataset => {
|
|
151
|
+
return setupSeries(chartType!, {
|
|
152
|
+
...dataset,
|
|
153
|
+
stack:
|
|
154
|
+
chartType == 'pie' || chartType == 'doughnut'
|
|
155
|
+
? undefined
|
|
156
|
+
: stacked && !dataset.stack
|
|
157
|
+
? 'A'
|
|
158
|
+
: `${dataset.yAxisID} ${dataset.stack || dataset.dataKey}`,
|
|
159
|
+
type: dataset.type == 'horizontalBar' ? 'bar' : dataset.type,
|
|
160
|
+
data: _data.map(row => row.count)
|
|
161
|
+
})
|
|
162
|
+
})
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
console.error('converted', config, converted)
|
|
167
|
+
return converted
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function setupLegend(
|
|
171
|
+
legend: any,
|
|
172
|
+
{
|
|
173
|
+
fontSize,
|
|
174
|
+
fontFamily,
|
|
175
|
+
fontColor,
|
|
176
|
+
theme
|
|
177
|
+
}: { fontSize?: number; fontFamily?: string; fontColor?: string; theme?: 'light' | 'dark' }
|
|
178
|
+
) {
|
|
179
|
+
legend.labels = legend.labels ? legend.labels : {}
|
|
180
|
+
|
|
181
|
+
if (fontSize) {
|
|
182
|
+
legend.labels.fontSize = fontSize
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
if (fontFamily) {
|
|
186
|
+
legend.labels.fontFamily = fontFamily
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
var baseColor = getBaseColorFromTheme(theme)
|
|
190
|
+
|
|
191
|
+
legend.labels = legend.labels ? legend.labels : {}
|
|
192
|
+
legend.labels.fontColor = fontColor ? fontColor : baseColor.clone().setAlpha(0.5).toString()
|
|
193
|
+
|
|
194
|
+
return legend
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function setupTooltip(
|
|
198
|
+
tooltip: any,
|
|
199
|
+
{
|
|
200
|
+
fontSize,
|
|
201
|
+
fontFamily,
|
|
202
|
+
fontColor,
|
|
203
|
+
theme
|
|
204
|
+
}: { fontSize?: number; fontFamily?: string; fontColor?: string; theme?: 'light' | 'dark' }
|
|
205
|
+
) {
|
|
206
|
+
if (fontSize) {
|
|
207
|
+
tooltip.titleFontSize = tooltip.bodyFontSize = tooltip.footerFontSize = fontSize
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
if (fontFamily) {
|
|
211
|
+
tooltip.titleFontFamily = tooltip.bodyFontFamily = tooltip.footerFontFamily = fontFamily
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
tooltip.mode = 'index'
|
|
215
|
+
tooltip.intersect = false
|
|
216
|
+
tooltip.callbacks = {
|
|
217
|
+
...tooltip.callbacks,
|
|
218
|
+
label: function ({ dataset, label }: { dataset: any; label: any }) {
|
|
219
|
+
var prefix = dataset.valuePrefix || ''
|
|
220
|
+
var suffix = dataset.valueSuffix || ''
|
|
221
|
+
|
|
222
|
+
return `${prefix + label + suffix}`
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
return tooltip
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
function setupScale(
|
|
230
|
+
axis: any,
|
|
231
|
+
{
|
|
232
|
+
fontSize,
|
|
233
|
+
fontFamily,
|
|
234
|
+
fontColor,
|
|
235
|
+
theme
|
|
236
|
+
}: { fontSize?: number; fontFamily?: string; fontColor?: string; theme?: 'light' | 'dark' }
|
|
237
|
+
) {
|
|
238
|
+
axis.ticks = axis.ticks ? axis.ticks : {}
|
|
239
|
+
|
|
240
|
+
if (fontSize) {
|
|
241
|
+
axis.ticks.fontSize = fontSize
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
if (fontFamily) {
|
|
245
|
+
axis.ticks.fontFamily = fontFamily
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
axis.pointLabels = {
|
|
249
|
+
fontSize,
|
|
250
|
+
fontFamily
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/* TODO move min, max, autoMin, autoMax from ticks to axis */
|
|
254
|
+
const { min, max, autoMin, autoMax } = axis.ticks
|
|
255
|
+
|
|
256
|
+
axis.min = min
|
|
257
|
+
axis.max = max
|
|
258
|
+
|
|
259
|
+
if (autoMin) {
|
|
260
|
+
delete axis.min
|
|
261
|
+
}
|
|
262
|
+
if (autoMax) {
|
|
263
|
+
delete axis.max
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
var baseColor = getBaseColorFromTheme(theme)
|
|
267
|
+
|
|
268
|
+
axis.grid = axis.grid ? axis.grid : {}
|
|
269
|
+
if (axis.grid) {
|
|
270
|
+
axis.grid.tickColor = baseColor.clone().setAlpha(0.5).toString()
|
|
271
|
+
axis.grid.color = baseColor.clone().setAlpha(0.1).toString()
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
axis.ticks = axis.ticks ? axis.ticks : {}
|
|
275
|
+
axis.ticks.color = baseColor.clone().setAlpha(0.5).toString()
|
|
276
|
+
axis.ticks.textStrokeColor = fontColor ? fontColor : baseColor.clone().setAlpha(0.5).toString()
|
|
277
|
+
|
|
278
|
+
return axis
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
function setupSeries(chartType: string, series: OperatoChart.Dataset) {
|
|
282
|
+
var type = series.type || chartType
|
|
283
|
+
|
|
284
|
+
var color = series.color ? series.color : series.backgroundColor
|
|
285
|
+
|
|
286
|
+
switch (type) {
|
|
287
|
+
case 'bar':
|
|
288
|
+
case 'horizontalBar':
|
|
289
|
+
series.borderColor = series.backgroundColor = color
|
|
290
|
+
break
|
|
291
|
+
|
|
292
|
+
case 'line':
|
|
293
|
+
case 'radar':
|
|
294
|
+
color = series.color ? series.color : series.borderColor
|
|
295
|
+
series.pointBackgroundColor = series.pointBorderColor = series.borderColor = series.backgroundColor = color
|
|
296
|
+
series.pointBorderWidth = (series.borderWidth as number) * 0.5
|
|
297
|
+
series.pointHoverRadius = series.pointRadius
|
|
298
|
+
if (series.fill == undefined) series.fill = false
|
|
299
|
+
break
|
|
300
|
+
|
|
301
|
+
default:
|
|
302
|
+
series.borderColor = series.backgroundColor = color
|
|
303
|
+
break
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
return series
|
|
307
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { LitElement, html, css } from 'lit'
|
|
2
|
+
import { property, query, customElement } from 'lit/decorators.js'
|
|
3
|
+
import { Chart, ChartConfiguration } from 'chart.js/auto'
|
|
4
|
+
|
|
5
|
+
@customElement('ox-chart-js')
|
|
6
|
+
class OxChartJs extends LitElement {
|
|
7
|
+
@property({ type: Object }) config: ChartConfiguration | null = null
|
|
8
|
+
private chart: Chart | null = null
|
|
9
|
+
|
|
10
|
+
@query('canvas') canvas!: HTMLCanvasElement
|
|
11
|
+
|
|
12
|
+
static styles = css`
|
|
13
|
+
:host {
|
|
14
|
+
display: block;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
canvas {
|
|
18
|
+
width: 100%;
|
|
19
|
+
height: 100%;
|
|
20
|
+
}
|
|
21
|
+
`
|
|
22
|
+
|
|
23
|
+
firstUpdated() {
|
|
24
|
+
if (this.config) {
|
|
25
|
+
this.chart = new Chart(this.canvas, this.config)
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
updated(changedProperties: Map<string | number | symbol, unknown>) {
|
|
30
|
+
if (changedProperties.has('config') && this.config) {
|
|
31
|
+
this.chart && this.chart.destroy()
|
|
32
|
+
this.chart = new Chart(this.canvas, this.config)
|
|
33
|
+
console.log('new chart', this.chart)
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
render() {
|
|
38
|
+
return html`<canvas></canvas>`
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
declare global {
|
|
43
|
+
interface HTMLElementTagNameMap {
|
|
44
|
+
'ox-chart-js': OxChartJs
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
export class Configurer {
|
|
2
|
+
public value: OperatoChart.ChartConfig
|
|
3
|
+
public currentSeriesIndex: number = 0
|
|
4
|
+
public initializer: () => OperatoChart.ChartConfig
|
|
5
|
+
|
|
6
|
+
constructor(value: OperatoChart.ChartConfig | null, initializer: () => OperatoChart.ChartConfig) {
|
|
7
|
+
this.initializer = initializer
|
|
8
|
+
this.value = value || initializer.call(this)
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
setCurrentSeriesIndex(currentSeriesIndex: number) {
|
|
12
|
+
this.currentSeriesIndex = currentSeriesIndex
|
|
13
|
+
this.series = this.datasets[this.currentSeriesIndex]!
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
get series() {
|
|
17
|
+
console.log('series', this.datasets[this.currentSeriesIndex]!)
|
|
18
|
+
return this.datasets[this.currentSeriesIndex]!
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
set series(series) {
|
|
22
|
+
if (!this.data) {
|
|
23
|
+
this.config.data = { datasets: [series] }
|
|
24
|
+
} else {
|
|
25
|
+
this.datasets[this.currentSeriesIndex] = series
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
get config() {
|
|
30
|
+
if (!this.value) {
|
|
31
|
+
this.value = this.initializer.call(this)
|
|
32
|
+
}
|
|
33
|
+
return this.value
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
get data() {
|
|
37
|
+
return this.config.data
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
set data(data) {
|
|
41
|
+
this.config.data = data
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
get datasets() {
|
|
45
|
+
if (!this.data.datasets) {
|
|
46
|
+
this.data.datasets = []
|
|
47
|
+
}
|
|
48
|
+
return this.data.datasets
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
set datasets(datasets) {
|
|
52
|
+
this.datasets = datasets
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
set dataKey(key) {
|
|
56
|
+
if (this.series) {
|
|
57
|
+
this.series!.dataKey = key
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
get dataKey() {
|
|
62
|
+
return this.series.dataKey
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
get legend() {
|
|
66
|
+
!this.config.options && (this.config.options = {})
|
|
67
|
+
return this.config.options.legend
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
set legend(legend) {
|
|
71
|
+
if (!this.config.options) {
|
|
72
|
+
this.config.options = {}
|
|
73
|
+
}
|
|
74
|
+
this.config.options.legend = legend
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
get theme() {
|
|
78
|
+
return this.config.options && this.config.options.theme
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
set theme(theme) {
|
|
82
|
+
!this.config.options && (this.config.options = {})
|
|
83
|
+
this.config.options.theme = theme
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
get tooltip() {
|
|
87
|
+
return !this.config.options || this.config.options.tooltip !== false
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
set tooltip(tooltip) {
|
|
91
|
+
if (!this.config.options) {
|
|
92
|
+
this.config.options = {}
|
|
93
|
+
}
|
|
94
|
+
this.config.options.tooltip = tooltip
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
get animation() {
|
|
98
|
+
return !this.config.options || this.config.options.animation !== false
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
set animation(animation) {
|
|
102
|
+
if (!this.config.options) {
|
|
103
|
+
this.config.options = {}
|
|
104
|
+
}
|
|
105
|
+
this.config.options.animation = animation
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
get scales() {
|
|
109
|
+
if (!this.config.options) {
|
|
110
|
+
this.config.options = {}
|
|
111
|
+
}
|
|
112
|
+
return this.config.options.scales
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
set scales(scales) {
|
|
116
|
+
!this.config.options && (this.config.options = {})
|
|
117
|
+
this.config.options.scales = scales
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
get display() {
|
|
121
|
+
return this.legend && this.legend.display
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
set display(display) {
|
|
125
|
+
if (!this.legend) {
|
|
126
|
+
this.legend = {}
|
|
127
|
+
}
|
|
128
|
+
this.legend.display = display
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
get position() {
|
|
132
|
+
if (!this.legend) {
|
|
133
|
+
this.legend = {}
|
|
134
|
+
}
|
|
135
|
+
return this.legend.position
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
set position(position) {
|
|
139
|
+
if (!this.legend) {
|
|
140
|
+
this.legend = {}
|
|
141
|
+
}
|
|
142
|
+
this.legend.position = position
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
get stacked() {
|
|
146
|
+
if (!this.config.options) {
|
|
147
|
+
this.config.options = {}
|
|
148
|
+
}
|
|
149
|
+
return this.config.options.stacked
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
set stacked(stacked) {
|
|
153
|
+
if (!this.config.options) {
|
|
154
|
+
this.config.options = {}
|
|
155
|
+
}
|
|
156
|
+
this.config.options.stacked = stacked
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
get labelDataKey() {
|
|
160
|
+
return this.data && this.data.labelDataKey
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
set labelDataKey(labelDataKey) {
|
|
164
|
+
this.data.labelDataKey = labelDataKey
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
set options(options) {
|
|
168
|
+
this.config.options = options
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
get options() {
|
|
172
|
+
return this.config.options
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
get color() {
|
|
176
|
+
var oldVersionColor = this.series.backgroundColor
|
|
177
|
+
if (this.series.type == 'line') oldVersionColor = this.series.borderColor
|
|
178
|
+
if (this.series.type == 'radar') oldVersionColor = this.series.borderColor
|
|
179
|
+
return this.series.color || oldVersionColor
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
set color(color) {
|
|
183
|
+
this.series.color = color // Array.isArray(color) ? color[0] : color
|
|
184
|
+
delete this.series.backgroundColor
|
|
185
|
+
delete this.series.borderColor
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
get xAxes0() {
|
|
189
|
+
return this.scales!.xAxes![0]
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
set xAxes0(xAxes0) {
|
|
193
|
+
this.scales!.xAxes![0] = xAxes0
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
get yAxes0() {
|
|
197
|
+
return this.scales!.yAxes![0]
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
set yAxes0(yAxes0) {
|
|
201
|
+
this.scales!.yAxes![0] = yAxes0
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
get yAxes1() {
|
|
205
|
+
return this.scales!.yAxes![1]
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
set yAxes1(yAxes1) {
|
|
209
|
+
this.scales!.yAxes![1] = yAxes1
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
get multiAxis() {
|
|
213
|
+
return this.config.options!.multiAxis
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
set multiAxis(multiAxis) {
|
|
217
|
+
this.config.options!.multiAxis = multiAxis
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
get valuePrefix() {
|
|
221
|
+
return this.series.valuePrefix
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
set valuePrefix(valuePrefix) {
|
|
225
|
+
this.series.valuePrefix = valuePrefix
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
get valueSuffix() {
|
|
229
|
+
return this.series.valueSuffix
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
set valueSuffix(valueSuffix) {
|
|
233
|
+
this.series.valueSuffix = valueSuffix
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
get displayValue() {
|
|
237
|
+
return this.series.displayValue
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
set displayValue(displayValue) {
|
|
241
|
+
this.series.displayValue = displayValue
|
|
242
|
+
}
|
|
243
|
+
}
|