@operato/scene-chartjs 0.0.5

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/CHANGELOG.md +17 -0
  2. package/LICENSE +21 -0
  3. package/README.md +21 -0
  4. package/assets/bar-chart.png +0 -0
  5. package/assets/doughnut-chart.png +0 -0
  6. package/assets/horizontal-bar-chart.png +0 -0
  7. package/assets/line-chart.png +0 -0
  8. package/assets/mixed-chart.png +0 -0
  9. package/assets/pie-chart.png +0 -0
  10. package/assets/polar-area-chart.png +0 -0
  11. package/assets/radar-chart.png +0 -0
  12. package/demo/bar.html +266 -0
  13. package/demo/chartjs.html +73 -0
  14. package/demo/index.html +547 -0
  15. package/demo/legend.html +267 -0
  16. package/demo/things-scene-chartjs.html +7 -0
  17. package/dist/chartjs.d.ts +27 -0
  18. package/dist/chartjs.js +109 -0
  19. package/dist/chartjs.js.map +1 -0
  20. package/dist/config-converter.d.ts +1 -0
  21. package/dist/config-converter.js +343 -0
  22. package/dist/config-converter.js.map +1 -0
  23. package/dist/editors/index.d.ts +5 -0
  24. package/dist/editors/index.js +11 -0
  25. package/dist/editors/index.js.map +1 -0
  26. package/dist/editors/property-editor-chartjs-abstract.d.ts +44 -0
  27. package/dist/editors/property-editor-chartjs-abstract.js +250 -0
  28. package/dist/editors/property-editor-chartjs-abstract.js.map +1 -0
  29. package/dist/editors/property-editor-chartjs-hbar.d.ts +9 -0
  30. package/dist/editors/property-editor-chartjs-hbar.js +160 -0
  31. package/dist/editors/property-editor-chartjs-hbar.js.map +1 -0
  32. package/dist/editors/property-editor-chartjs-mixed.d.ts +20 -0
  33. package/dist/editors/property-editor-chartjs-mixed.js +193 -0
  34. package/dist/editors/property-editor-chartjs-mixed.js.map +1 -0
  35. package/dist/editors/property-editor-chartjs-multi-series-abstract.d.ts +31 -0
  36. package/dist/editors/property-editor-chartjs-multi-series-abstract.js +373 -0
  37. package/dist/editors/property-editor-chartjs-multi-series-abstract.js.map +1 -0
  38. package/dist/editors/property-editor-chartjs-pie.d.ts +14 -0
  39. package/dist/editors/property-editor-chartjs-pie.js +70 -0
  40. package/dist/editors/property-editor-chartjs-pie.js.map +1 -0
  41. package/dist/editors/property-editor-chartjs-radar.d.ts +10 -0
  42. package/dist/editors/property-editor-chartjs-radar.js +42 -0
  43. package/dist/editors/property-editor-chartjs-radar.js.map +1 -0
  44. package/dist/editors/property-editor-chartjs-styles.d.ts +1 -0
  45. package/dist/editors/property-editor-chartjs-styles.js +165 -0
  46. package/dist/editors/property-editor-chartjs-styles.js.map +1 -0
  47. package/dist/editors/property-editor-chartjs.d.ts +14 -0
  48. package/dist/editors/property-editor-chartjs.js +83 -0
  49. package/dist/editors/property-editor-chartjs.js.map +1 -0
  50. package/dist/index.d.ts +5 -0
  51. package/dist/index.js +8 -0
  52. package/dist/index.js.map +1 -0
  53. package/dist/ox-chart.d.ts +20 -0
  54. package/dist/ox-chart.js +137 -0
  55. package/dist/ox-chart.js.map +1 -0
  56. package/dist/plugins/chart-series-highlight.d.ts +5 -0
  57. package/dist/plugins/chart-series-highlight.js +37 -0
  58. package/dist/plugins/chart-series-highlight.js.map +1 -0
  59. package/dist/plugins/chartjs-plugin-data-binder.d.ts +5 -0
  60. package/dist/plugins/chartjs-plugin-data-binder.js +111 -0
  61. package/dist/plugins/chartjs-plugin-data-binder.js.map +1 -0
  62. package/helps/scene/component/chartjs.ko.md +332 -0
  63. package/helps/scene/component/chartjs.md +333 -0
  64. package/helps/scene/component/chartjs.zh.md +331 -0
  65. package/helps/scene/images/chart-bar-01.png +0 -0
  66. package/helps/scene/images/chart-bar-02.png +0 -0
  67. package/helps/scene/images/chart-bar-03.png +0 -0
  68. package/helps/scene/images/chart-bar-08.png +0 -0
  69. package/helps/scene/images/chart-bar-12.png +0 -0
  70. package/helps/scene/images/chart-data-01.png +0 -0
  71. package/helps/scene/images/chart-data-04.png +0 -0
  72. package/helps/scene/images/chart-doughnut-01.png +0 -0
  73. package/helps/scene/images/chart-horizontal-bar-01.png +0 -0
  74. package/helps/scene/images/chart-line-01.png +0 -0
  75. package/helps/scene/images/chart-mix-01.png +0 -0
  76. package/helps/scene/images/chart-mix-02.png +0 -0
  77. package/helps/scene/images/chart-pie-01.png +0 -0
  78. package/helps/scene/images/chart-polar-01.png +0 -0
  79. package/helps/scene/images/chart-radar-01.png +0 -0
  80. package/package.json +78 -0
  81. package/src/chartjs.ts +134 -0
  82. package/src/config-converter.ts +401 -0
  83. package/src/editors/index.ts +11 -0
  84. package/src/editors/property-editor-chartjs-abstract.ts +301 -0
  85. package/src/editors/property-editor-chartjs-hbar.ts +163 -0
  86. package/src/editors/property-editor-chartjs-mixed.ts +204 -0
  87. package/src/editors/property-editor-chartjs-multi-series-abstract.ts +393 -0
  88. package/src/editors/property-editor-chartjs-pie.ts +79 -0
  89. package/src/editors/property-editor-chartjs-radar.ts +43 -0
  90. package/src/editors/property-editor-chartjs-styles.ts +165 -0
  91. package/src/editors/property-editor-chartjs.ts +88 -0
  92. package/src/index.ts +7 -0
  93. package/src/ox-chart.ts +150 -0
  94. package/src/plugins/chart-series-highlight.ts +43 -0
  95. package/src/plugins/chartjs-plugin-data-binder.ts +138 -0
  96. package/src/scene-chart.d.ts +152 -0
  97. package/templates/bar-chart.js +124 -0
  98. package/templates/doughnut-chart.js +58 -0
  99. package/templates/horizontal-bar-chart.js +121 -0
  100. package/templates/index.js +22 -0
  101. package/templates/line-chart.js +155 -0
  102. package/templates/mixed-chart.js +152 -0
  103. package/templates/pie-chart.js +58 -0
  104. package/templates/polar-area-chart.js +92 -0
  105. package/templates/radar-chart.js +98 -0
  106. package/test/basic-test.html +61 -0
  107. package/test/index.html +20 -0
  108. package/things-scene.config.js +7 -0
  109. package/translations/en.json +5 -0
  110. package/translations/ko.json +5 -0
  111. package/translations/ms.json +5 -0
  112. package/translations/zh.json +5 -0
  113. package/tsconfig.json +22 -0
  114. package/tsconfig.tsbuildinfo +1 -0
@@ -0,0 +1,88 @@
1
+ /*
2
+ * Copyright © HatioLab Inc. All rights reserved.
3
+ */
4
+ import '@polymer/iron-icon'
5
+ import '@polymer/iron-icons'
6
+ import '@polymer/paper-icon-button'
7
+ import '@polymer/paper-tabs'
8
+ import './property-editor-chartjs-hbar'
9
+ import './property-editor-chartjs-mixed'
10
+ import './property-editor-chartjs-pie'
11
+ import './property-editor-chartjs-radar'
12
+
13
+ import { css, html } from 'lit'
14
+
15
+ import { OxPropertyEditor } from '@operato/property-editor'
16
+
17
+ export default class ChartJSEditor extends OxPropertyEditor {
18
+ static get is() {
19
+ return 'property-editor-chartjs'
20
+ }
21
+
22
+ static get styles() {
23
+ return [
24
+ css`
25
+ :host {
26
+ display: block;
27
+ padding: 5px;
28
+ }
29
+
30
+ #chart-type {
31
+ display: grid;
32
+ grid-template-columns: repeat(10, 1fr);
33
+ grid-gap: 5px;
34
+ }
35
+
36
+ #chart-type > label {
37
+ box-sizing: border-box;
38
+ grid-column: span 3;
39
+
40
+ text-align: right;
41
+
42
+ color: var(--primary-text-color);
43
+ font-size: 0.8em;
44
+ line-height: 2;
45
+ text-transform: capitalize;
46
+ }
47
+
48
+ #chart-type > input {
49
+ box-sizing: border-box;
50
+ grid-column: span 7;
51
+ border: 1px solid rgba(0, 0, 0, 0.2);
52
+ }
53
+ `
54
+ ]
55
+ }
56
+
57
+ editorTemplate(props: any) {
58
+ return html`
59
+ ${props.value
60
+ ? html`
61
+ <div id="chart-type">
62
+ <label> <i18n-msg msgid="label.chart-type">Chart Type</i18n-msg> </label>
63
+ <input type="text" .value=${props.value.type} readonly />
64
+ </div>
65
+ `
66
+ : html``}
67
+ ${!props.value
68
+ ? html``
69
+ : props.value.type == 'line'
70
+ ? html` <property-editor-chartjs-mixed .value=${props.value} fullwidth></property-editor-chartjs-mixed> `
71
+ : props.value.type == 'horizontalBar'
72
+ ? html` <property-editor-chartjs-hbar .value=${props.value} fullwidth></property-editor-chartjs-hbar> `
73
+ : props.value.type == 'bar'
74
+ ? html` <property-editor-chartjs-mixed .value=${props.value} fullwidth></property-editor-chartjs-mixed> `
75
+ : props.value.type == 'pie'
76
+ ? html` <property-editor-chartjs-pie .value=${props.value} fullwidth></property-editor-chartjs-pie> `
77
+ : props.value.type == 'doughnut'
78
+ ? html` <property-editor-chartjs-pie .value=${props.value} fullwidth></property-editor-chartjs-pie> `
79
+ : props.value.type == 'polarArea'
80
+ ? html` <property-editor-chartjs-pie .value=${props.value} fullwidth></property-editor-chartjs-pie> `
81
+ : props.value.type == 'radar'
82
+ ? html` <property-editor-chartjs-radar .value=${props.value} fullwidth></property-editor-chartjs-radar> `
83
+ : html``}
84
+ `
85
+ }
86
+ }
87
+
88
+ customElements.define(ChartJSEditor.is, ChartJSEditor)
package/src/index.ts ADDED
@@ -0,0 +1,7 @@
1
+ /*
2
+ * Copyright © HatioLab Inc. All rights reserved.
3
+ */
4
+ import 'core-js/stable'
5
+ import 'regenerator-runtime/runtime'
6
+ import './chartjs'
7
+ export default './chartjs'
@@ -0,0 +1,150 @@
1
+ /*
2
+ * Copyright © HatioLab Inc. All rights reserved.
3
+ */
4
+
5
+ import 'chartjs-plugin-datalabels'
6
+ import 'chartjs-plugin-style'
7
+
8
+ import { LitElement, PropertyValues, html } from 'lit'
9
+ import { customElement, property, query } from 'lit/decorators.js'
10
+
11
+ import { Chart } from 'chart.js'
12
+ import DataBinderPlugin from './plugins/chartjs-plugin-data-binder'
13
+ import { convertConfigure } from './config-converter'
14
+
15
+ Chart.plugins.register(DataBinderPlugin)
16
+
17
+ @customElement('ox-chart')
18
+ export class OxChart extends LitElement {
19
+ @property({ type: Number }) width!: number
20
+ @property({ type: Number }) height!: number
21
+ @property({ type: Object }) options!: SceneChart.ChartConfig
22
+ @property({ type: Object }) data!: SceneChart.ChartData
23
+
24
+ private _initialized?: boolean
25
+ private _chart?: SceneChart
26
+
27
+ @query('canvas') _canvas!: HTMLCanvasElement
28
+
29
+ firstUpdated() {
30
+ this.initChart()
31
+ }
32
+
33
+ render() {
34
+ return html` <canvas></canvas> `
35
+ }
36
+
37
+ updated(changes: PropertyValues<this>) {
38
+ if (changes.has('width') || changes.has('height')) {
39
+ this.updateChartSize()
40
+ }
41
+
42
+ if (changes.has('options')) {
43
+ this.updateChartConfig()
44
+ }
45
+
46
+ if (changes.has('data')) {
47
+ this._chart!.data.rawData = this.data
48
+ this._chart!.update()
49
+ }
50
+ }
51
+
52
+ initChart() {
53
+ const { data, options, type } = this.options
54
+ options!.maintainAspectRatio = false
55
+
56
+ this.attachPluginOptions(options)
57
+ convertConfigure(this.options as SceneChart.ChartConfig)
58
+
59
+ this._chart = new Chart(this._canvas, {
60
+ type,
61
+ data,
62
+ options
63
+ }) as SceneChart
64
+
65
+ this.updateChartSize()
66
+
67
+ this._initialized = true
68
+ }
69
+
70
+ updateChartSize() {
71
+ const width = Math.floor(this.width)
72
+ const height = Math.floor(this.height)
73
+
74
+ this._canvas.style.width = `${width}px`
75
+ this._canvas.style.height = `${height}px`
76
+
77
+ const _ = () => {
78
+ if (this._canvas.offsetWidth == 0 || this._canvas.offsetHeight == 0) {
79
+ requestAnimationFrame(_)
80
+ } else {
81
+ /*
82
+ 주의 : chart.resize() 내에서 pixel ratio를 감안해서, canvas 의 width, height를 설정하기때문에,
83
+ 별도 처리가 필요하지 않다.
84
+ */
85
+ this._chart!.resize()
86
+ }
87
+ }
88
+
89
+ requestAnimationFrame(_)
90
+ }
91
+
92
+ updateChartConfig() {
93
+ if (!this._chart) return
94
+
95
+ const { data, options, type } = this.options
96
+ options!.maintainAspectRatio = false
97
+
98
+ this.attachPluginOptions(options)
99
+ convertConfigure(this.options as SceneChart.ChartConfig)
100
+
101
+ this._chart.type = type
102
+ this._chart.data = data
103
+ this._chart.options = options
104
+ this._chart.data.rawData = this.data
105
+ this._chart.update()
106
+ }
107
+
108
+ attachPluginOptions(options: SceneChart.ChartOptions) {
109
+ if (!options.plugins) {
110
+ options.plugins = {}
111
+ }
112
+
113
+ this.attachDatalabelPluginOptions(options.plugins)
114
+ }
115
+
116
+ attachDatalabelPluginOptions(pluginOptions: SceneChart.ChartPluginsOptions) {
117
+ pluginOptions.datalabels = {
118
+ ...pluginOptions.datalabels,
119
+ display: function (context) {
120
+ //@ts-ignore
121
+ return !!context.dataset.displayValue
122
+ },
123
+ anchor: function (context) {
124
+ //@ts-ignore
125
+ return context.dataset.dataLabelAnchor || 'center'
126
+ },
127
+ color: function (context) {
128
+ //@ts-ignore
129
+ return context.dataset.defaultFontColor || '#000'
130
+ },
131
+ font: function (context) {
132
+ return {
133
+ //@ts-ignore
134
+ size: context.dataset.defaultFontSize
135
+ }
136
+ },
137
+ clamp: true,
138
+ formatter: function (value, context) {
139
+ //@ts-ignore
140
+ var prefix = context.dataset.valuePrefix || ''
141
+ //@ts-ignore
142
+ var suffix = context.dataset.valueSuffix || ''
143
+ if (value == undefined) return value
144
+
145
+ var stringValue = String(value)
146
+ return prefix + stringValue.toLocaleString() + suffix
147
+ }
148
+ }
149
+ }
150
+ }
@@ -0,0 +1,43 @@
1
+ import Chart from 'chart.js'
2
+
3
+ /*
4
+ * Copyright © HatioLab Inc. All rights reserved.
5
+ */
6
+ function seriesHighlight(chartInstance: SceneChart, seriesData: SceneChart.DataSeries) {
7
+ chartInstance.data.datasets?.forEach(dataset => {
8
+ let highlight = dataset.highlight
9
+ if (!highlight) {
10
+ return
11
+ }
12
+
13
+ let highlightColor = highlight.color
14
+ let highlightCondition = highlight.condition
15
+
16
+ seriesData.forEach((sdata, sIndex) => {
17
+ sdata.forEach((data: SceneChart.Data, i: number) => {
18
+ if (!eval(highlightCondition)) {
19
+ return
20
+ }
21
+
22
+ let meta = chartInstance.getDatasetMeta(sIndex)
23
+ meta.data[i]._model.backgroundColor = highlightColor
24
+ //@ts-ignore
25
+ meta.data[i]._model.hoverBackgroundColor = highlightColor
26
+
27
+ // dataset.backgroundColor = highlightColor
28
+ })
29
+ })
30
+ })
31
+ }
32
+
33
+ export default {
34
+ id: 'chart-series-highlight',
35
+ beforeDraw: function (chartInstance: SceneChart) {
36
+ if (!chartInstance.data.rawData) {
37
+ return
38
+ }
39
+
40
+ let seriesData = chartInstance.data.rawData.seriesData
41
+ seriesHighlight(chartInstance, seriesData)
42
+ }
43
+ }
@@ -0,0 +1,138 @@
1
+ /*
2
+ * Copyright © HatioLab Inc. All rights reserved.
3
+ */
4
+
5
+ function convertObject(
6
+ dataArray: string | SceneChart.DataSeries | Object,
7
+ chartInstance: SceneChart
8
+ ): null | Object | SceneChart.DataSeries {
9
+ if (!dataArray) {
10
+ return null
11
+ }
12
+
13
+ if (typeof dataArray == 'string') {
14
+ try {
15
+ dataArray = JSON.parse(dataArray)
16
+ } catch (e) {
17
+ console.warn('invalid chart data format', e)
18
+ return null
19
+ }
20
+ }
21
+
22
+ if (!(dataArray instanceof Array)) {
23
+ // is not Array
24
+ if (dataArray instanceof Object) {
25
+ return dataArray
26
+ }
27
+ return null
28
+ }
29
+
30
+ if (dataArray.length === 0) {
31
+ return null
32
+ }
33
+
34
+ // modeling중 변수 기본값에 대한 처리
35
+ if (dataArray[0].hasOwnProperty('__field1')) {
36
+ dataArray = toObjectArrayValue(dataArray) as SceneChart.DataSeries
37
+ }
38
+
39
+ let label = chartInstance.data.labelDataKey
40
+ let seriesKeys = []
41
+
42
+ for (let i in chartInstance.data.datasets) {
43
+ seriesKeys.push(chartInstance.data.datasets[Number(i)].dataKey)
44
+ }
45
+
46
+ let seriesData: SceneChart.DataSeries = []
47
+ let labelData: SceneChart.DataSeries = []
48
+
49
+ let convertedObject = {
50
+ seriesData,
51
+ labelData
52
+ }
53
+
54
+ for (let i in dataArray) {
55
+ let currData: SceneChart.Data = (dataArray as SceneChart.DataSeries)[Number(i)]
56
+ labelData.push(currData[label!])
57
+
58
+ for (let i in seriesKeys) {
59
+ if (!seriesKeys[i]) continue
60
+
61
+ if (!seriesData[i]) seriesData[i] = []
62
+
63
+ // 값이 NaN 경우엔 차트를 그리지 않음
64
+ if (Number(currData[seriesKeys[i]]) == NaN) {
65
+ currData[seriesKeys[i]] = NaN
66
+ }
67
+
68
+ seriesData[i].push(currData[seriesKeys[i]])
69
+ }
70
+ }
71
+
72
+ return convertedObject
73
+ }
74
+
75
+ function toObjectArrayValue(array: SceneChart.DataSeries): SceneChart.DataSeries | null {
76
+ if (!array || array.length === 0) {
77
+ return null
78
+ }
79
+
80
+ let indexKeyMap: SceneChart.Data = {}
81
+ let value = []
82
+
83
+ for (let key in array[0]) {
84
+ indexKeyMap[key] = array[0][key]
85
+ }
86
+
87
+ for (var i = 1; i < array.length; i++) {
88
+ let object: SceneChart.Data = {}
89
+ let thisObject = array[i]
90
+
91
+ for (let key in indexKeyMap) {
92
+ let k = indexKeyMap[key]
93
+ let v = thisObject[key]
94
+ object[k] = v
95
+ }
96
+
97
+ value.push(object)
98
+ }
99
+
100
+ return value
101
+ }
102
+
103
+ function updateSeriesDatas(chartInstance: SceneChart) {
104
+ if (!chartInstance.data.rawData) {
105
+ return
106
+ }
107
+
108
+ let seriesData = chartInstance.data.rawData.seriesData
109
+
110
+ if (!seriesData || seriesData.length === 0) seriesData = [null]
111
+
112
+ for (let key in chartInstance.data.datasets) {
113
+ chartInstance.data.datasets[Number(key)].data = seriesData[key] || []
114
+ }
115
+ }
116
+
117
+ function updateLabelDatas(chartInstance: SceneChart) {
118
+ let labelData = chartInstance.data.rawData.labelData
119
+ chartInstance.config.data!.labels = labelData || []
120
+ }
121
+
122
+ export default {
123
+ id: 'data-binder',
124
+ beforeUpdate: function (chartInstance: SceneChart) {
125
+ if (!chartInstance.data) return
126
+
127
+ if (!chartInstance.data.rawData) chartInstance.data.rawData = []
128
+
129
+ chartInstance.data.rawData = convertObject(chartInstance.data.rawData, chartInstance) || {
130
+ seriesData: [],
131
+ labelData: []
132
+ }
133
+
134
+ let seriesData = chartInstance.data.rawData.seriesData
135
+ updateLabelDatas(chartInstance)
136
+ updateSeriesDatas(chartInstance)
137
+ }
138
+ }
@@ -0,0 +1,152 @@
1
+ declare class SceneChart extends Chart {
2
+ type: Chart.ChartType | string
3
+ data: SceneChart.ChartData
4
+ }
5
+
6
+ declare namespace SceneChart {
7
+ type Theme = 'light' | 'dark'
8
+ type Data = { [key: string]: any }
9
+ type DataSeries = Array<Data>
10
+
11
+ interface TickOptions extends Chart.TickOptions {
12
+ autoMax?: boolean
13
+ autoMin?: boolean
14
+ }
15
+
16
+ interface ChartScales {
17
+ type?: Chart.ScaleType | string
18
+ display?: boolean
19
+ position?: Chart.PositionType | string
20
+ gridLines?: GridLineOptions
21
+ scaleLabel?: Chart.ScaleTitleOptions
22
+ ticks?: TickOptions
23
+ xAxes?: ChartXAxe[]
24
+ yAxes?: ChartYAxe[]
25
+ }
26
+
27
+ interface ChartDataSets extends Chart.ChartDataSets {
28
+ color: string
29
+ dataKey: string
30
+ valuePrefix: string
31
+ valueSuffix: string
32
+ displayValue: string
33
+ dataLabelAnchor: string
34
+ defaultFontColor: string
35
+ defaultFontSize: number
36
+ highlight: {
37
+ color: string
38
+ condition: string
39
+ }
40
+ }
41
+
42
+ interface ChartData {
43
+ labels?: Array<string | string[]>
44
+ datasets?: ChartDataSets[]
45
+ rawData?: any
46
+ labelDataKey?: string
47
+ }
48
+
49
+ interface ChartXAxe extends Chart.ChartXAxe {
50
+ categorySpacing?: number
51
+ barSpacing?: number
52
+ ticks?: TickOptions
53
+ axisTitle?: string
54
+ }
55
+ interface ChartYAxe extends ChartXAxe {}
56
+
57
+ interface GridLineOptions extends Chart.GridLineOptions {}
58
+ interface ChartLegendOptions extends Chart.ChartLegendOptions {}
59
+ interface ChartTooltipOptions extends Chart.ChartTooltipOptions {}
60
+ interface ChartTooltipItem extends Chart.ChartTooltipItem {}
61
+ interface RadialLinearScale extends Chart.RadialLinearScale {}
62
+ interface ChartPluginsOptions extends Chart.ChartPluginsOptions {}
63
+ // datalabels?: DataLabelsPluginOptions
64
+ // [plugin: string]: any
65
+ // }
66
+
67
+ // interface ChartOptions {
68
+ // responsive?: boolean
69
+ // responsiveAnimationDuration?: number
70
+ // aspectRatio?: number
71
+ // maintainAspectRatio?: boolean
72
+ // events?: string[]
73
+ // legendCallback?(chart: Chart): string
74
+ // onHover?(this: Chart, event: MouseEvent, activeElements: Array<{}>): any
75
+ // onClick?(event?: MouseEvent, activeElements?: Array<{}>): any
76
+ // onResize?(this: Chart, newSize: ChartSize): void
77
+ // title?: ChartTitleOptions
78
+ // legend?: ChartLegendOptions
79
+ // tooltips?: ChartTooltipOptions
80
+ // hover?: ChartHoverOptions
81
+ // animation?: ChartAnimationOptions
82
+ // elements?: ChartElementsOptions
83
+ // layout?: ChartLayoutOptions
84
+ // scale?: RadialLinearScale
85
+ // scales?: ChartScales | LinearScale | LogarithmicScale | TimeScale
86
+ // showLines?: boolean
87
+ // spanGaps?: boolean
88
+ // cutoutPercentage?: number
89
+ // circumference?: number
90
+ // rotation?: number
91
+ // devicePixelRatio?: number
92
+ // plugins?: ChartPluginsOptions
93
+ // }
94
+
95
+ interface Context {
96
+ dataset: ChartDataSets
97
+ }
98
+
99
+ interface DataLabelsPluginOptions {
100
+ display: (context: Context) => true | false | 'auto'
101
+ anchor: (context: Context) => 'center' | 'start' | 'end' | string
102
+ color: (context: Context) => string
103
+ font: (context: Context) => { size: number }
104
+ clamp: boolean
105
+ formatter: (value: any, context: Context) => string
106
+ }
107
+
108
+ interface ChartOptions extends Chart.ChartOptions {
109
+ scales: ChartScales
110
+ scale: RadialLinearScale
111
+ legend: ChartLegendOptions
112
+ tooltips: ChartTooltipOptions
113
+ multiAxis: boolean
114
+ defaultFontSize: number | string
115
+ defaultFontFamily: string
116
+ defaultFontColor: string
117
+ theme: Theme
118
+ stacked?: boolean
119
+ xGridLine: boolean
120
+ fillStyle: string
121
+ maintainAspectRatio?: boolean
122
+ // plugins: ChartPluginsOptions
123
+
124
+ // responsive?: boolean
125
+ // responsiveAnimationDuration?: number
126
+ // aspectRatio?: number
127
+ // events?: string[]
128
+ // legendCallback?(chart: Chart): string
129
+ // onHover?(this: Chart, event: MouseEvent, activeElements: Array<{}>): any
130
+ // onClick?(event?: MouseEvent, activeElements?: Array<{}>): any
131
+ // onResize?(this: Chart, newSize: ChartSize): void
132
+ // title?: ChartTitleOptions
133
+ // hover?: ChartHoverOptions
134
+ // animation?: ChartAnimationOptions
135
+ // elements?: ChartElementsOptions
136
+ // layout?: ChartLayoutOptions
137
+ // // scale?: RadialLinearScale
138
+ // // scales?: ChartScales | LinearScale | LogarithmicScale | TimeScale
139
+ // showLines?: boolean
140
+ // spanGaps?: boolean
141
+ // cutoutPercentage?: number
142
+ // circumference?: number
143
+ // rotation?: number
144
+ // devicePixelRatio?: number
145
+ }
146
+
147
+ interface ChartConfig {
148
+ type: string
149
+ data: ChartData
150
+ options: ChartOptions
151
+ }
152
+ }
@@ -0,0 +1,124 @@
1
+ /*
2
+ * Copyright © HatioLab Inc. All rights reserved.
3
+ */
4
+ import icon from '../assets/bar-chart.png'
5
+
6
+ export default {
7
+ type: 'bar chart',
8
+ description: 'ChartJS - barchart',
9
+ icon: icon,
10
+ group: 'chartAndGauge',
11
+ /* line|shape|textAndMedia|chartAndGauge|table|container|dataSource|IoT|3D|warehouse|form|etc */
12
+ model: {
13
+ type: 'chartjs',
14
+ top: 200,
15
+ left: 300,
16
+ width: 200,
17
+ height: 200,
18
+ chart: {
19
+ type: 'bar',
20
+ data: {
21
+ labels: [],
22
+ datasets: [
23
+ {
24
+ label: 'series 1',
25
+ type: 'bar',
26
+ data: [],
27
+ backgroundColor: 'rgb(66, 110, 164)',
28
+ borderColor: 'rgb(66, 110, 164)',
29
+ borderWidth: 0,
30
+ dataKey: 'value',
31
+ yAxisID: 'left'
32
+ }
33
+ ],
34
+ labelDataKey: 'color'
35
+ },
36
+ options: {
37
+ theme: 'dark',
38
+ xGridLine: false,
39
+ yGridLine: true,
40
+ legend: {
41
+ display: true,
42
+ position: 'top'
43
+ },
44
+ scales: {
45
+ xAxes: [
46
+ {
47
+ gridLines: {
48
+ display: false
49
+ },
50
+ scaleLabel: {
51
+ labelString: '',
52
+ display: false
53
+ },
54
+ ticks: {
55
+ display: true
56
+ }
57
+ }
58
+ ],
59
+ yAxes: [
60
+ {
61
+ id: 'left',
62
+ position: 'left',
63
+ gridLines: {
64
+ display: true
65
+ },
66
+ scaleLabel: {
67
+ labelString: '',
68
+ display: false
69
+ },
70
+ ticks: {
71
+ autoMin: true,
72
+ autoMax: true,
73
+ display: true
74
+ }
75
+ },
76
+ {
77
+ id: 'right',
78
+ position: 'right',
79
+ display: false,
80
+ gridLines: {
81
+ display: false
82
+ },
83
+ scaleLabel: {
84
+ labelString: '',
85
+ display: false
86
+ },
87
+ ticks: {
88
+ autoMin: true,
89
+ autoMax: true,
90
+ display: true
91
+ }
92
+ }
93
+ ]
94
+ }
95
+ }
96
+ },
97
+ data: [
98
+ {
99
+ color: 'Red',
100
+ value: 12
101
+ },
102
+ {
103
+ color: 'Blue',
104
+ value: 19
105
+ },
106
+ {
107
+ color: 'Yellow',
108
+ value: 3
109
+ },
110
+ {
111
+ color: 'Green',
112
+ value: 5
113
+ },
114
+ {
115
+ color: 'Purple',
116
+ value: 2
117
+ },
118
+ {
119
+ color: 'Orange',
120
+ value: 3
121
+ }
122
+ ]
123
+ }
124
+ }