@vyr/echarts 0.0.1

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 ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "@vyr/echarts",
3
+ "version": "0.0.1",
4
+ "description": "",
5
+ "main": "./src/index.ts",
6
+ "author": "",
7
+ "sideEffects": true,
8
+ "license": "MIT",
9
+ "dependencies": {
10
+ "@vyr/locale": "0.0.1",
11
+ "@vyr/engine": "0.0.1",
12
+ "echarts": "^5.5.0"
13
+ },
14
+ "files": [
15
+ "package.json",
16
+ "src/"
17
+ ],
18
+ "vyr": {
19
+ "type": "universal",
20
+ "order": 10
21
+ }
22
+ }
@@ -0,0 +1,172 @@
1
+ import * as echarts from 'echarts'
2
+ import { DatasetDescriptor, HTMLActor, UpdateArgs } from "@vyr/engine";
3
+ import { EchartDescriptor } from "../descriptor";
4
+ import { ServiceEchartInterpreter } from '../interpreter';
5
+
6
+ interface EchartServiceOption {
7
+ [k: string]: any
8
+ }
9
+ interface AxisOption {
10
+ [k: string]: any
11
+ }
12
+
13
+ class EchartActor extends HTMLActor {
14
+ private _wrapper: HTMLElement | null = null
15
+ readonly DOM: HTMLElement
16
+ readonly instance
17
+ options: { [k: string]: any } = {}
18
+
19
+ constructor(uuid: string) {
20
+ super(uuid)
21
+ this.DOM = this.createDOM()
22
+ const wrapper = this.getWrapper()
23
+ wrapper.appendChild(this.DOM)
24
+ this.instance = echarts.init(this.DOM)
25
+ }
26
+
27
+ protected createWrapper() {
28
+ const wrapper = document.createElement('div')
29
+ wrapper.setAttribute('class', HTMLActor.className)
30
+ wrapper.setAttribute(HTMLActor.uuidKey, this.uuid)
31
+ return wrapper
32
+ }
33
+
34
+ getWrapper() {
35
+ if (this._wrapper === null) {
36
+ this._wrapper = this.createWrapper()
37
+ }
38
+
39
+ return this._wrapper
40
+ }
41
+
42
+ add() { }
43
+
44
+ remove() { }
45
+
46
+ getXAxis(descriptor: EchartDescriptor, args: UpdateArgs) {
47
+ const xAxis: AxisOption = {
48
+ show: descriptor.xAxisShow,
49
+ axisLine: descriptor.xAxisLine,
50
+ axisTick: descriptor.xAxisTick,
51
+ axisLabel: descriptor.xAxisLabel,
52
+ splitLine: descriptor.xAxisSplitLine,
53
+ }
54
+ if (descriptor.xAxisType) xAxis.type = descriptor.xAxisType
55
+ return xAxis
56
+ }
57
+ getYAxis(descriptor: EchartDescriptor, args: UpdateArgs) {
58
+ const yAxis: AxisOption = {
59
+ show: descriptor.yAxisShow,
60
+ axisLine: descriptor.yAxisLine,
61
+ axisTick: descriptor.yAxisTick,
62
+ axisLabel: descriptor.yAxisLabel,
63
+ splitLine: descriptor.yAxisSplitLine,
64
+ }
65
+ if (descriptor.yAxisType) yAxis.type = descriptor.yAxisType
66
+ return yAxis
67
+ }
68
+ getGrid(descriptor: EchartDescriptor, args: UpdateArgs) {
69
+ const grid = {
70
+ show: descriptor.gridShow,
71
+ ...descriptor.gridRect,
72
+ }
73
+
74
+ return grid
75
+ }
76
+ getLegend(descriptor: EchartDescriptor, args: UpdateArgs) {
77
+ const legend = {
78
+ show: descriptor.legendShow,
79
+ type: descriptor.legendType || undefined,
80
+ left: descriptor.legendRect.left,
81
+ top: descriptor.legendRect.top,
82
+ textStyle: {
83
+ color: descriptor.legendTextStyle.color,
84
+ }
85
+ }
86
+ return legend
87
+ }
88
+ getTooltip(descriptor: EchartDescriptor, args: UpdateArgs) {
89
+ const tooltip = {
90
+ show: descriptor.tooltipShow,
91
+ trigger: descriptor.tooltipTrigger,
92
+ }
93
+
94
+ return tooltip
95
+ }
96
+
97
+ getDataZoom(descriptor: EchartDescriptor, args: UpdateArgs) {
98
+ const dataZoom = [
99
+ {
100
+ // 设置滚动条的隐藏或显示
101
+ show: false,
102
+ // 设置类型
103
+ type: "slider",
104
+ // 数据窗口范围的起始数值
105
+ startValue: 0,
106
+ // 数据窗口范围的结束数值(一页显示多少条数据)
107
+ endValue: descriptor.scroll.end - 1,
108
+ // 控制哪个轴,如果是number表示控制一个轴,
109
+ // 如果是Array表示控制多个轴。此处控制第二根轴
110
+ yAxisIndex: [0, 1],
111
+ // empty:当前数据窗口外的数据,被设置为空。
112
+ // 即不会影响其他轴的数据范围
113
+ filterMode: "empty",
114
+ },
115
+ {
116
+ // 没有下面这块的话,只能拖动滚动条,
117
+ // 鼠标滚轮在区域内不能控制外部滚动条
118
+ type: "inside",
119
+ // 控制哪个轴,如果是number表示控制一个轴,
120
+ // 如果是Array表示控制多个轴。此处控制第二根轴
121
+ yAxisIndex: [0, 1],
122
+ // 滚轮是否触发缩放
123
+ zoomOnMouseWheel: false,
124
+ // 鼠标移动能否触发平移
125
+ moveOnMouseMove: true,
126
+ // 鼠标滚轮能否触发平移
127
+ moveOnMouseWheel: true,
128
+ },
129
+ ]
130
+
131
+ return dataZoom
132
+ }
133
+
134
+ setOptions(descriptor: EchartDescriptor, args: UpdateArgs) {
135
+ const dimensions: string[] = [descriptor.xAxisModelValue]
136
+ const children: EchartServiceOption[] = []
137
+ const graphics = HTMLActor.getGraphics(this)
138
+ for (const serie of descriptor.children) {
139
+ dimensions.push(serie.modelValue)
140
+ const interpreter = graphics.getInterpreter<ServiceEchartInterpreter>(serie)
141
+ children.push(interpreter.getService(serie, args))
142
+ }
143
+
144
+ const xAxis = this.getXAxis(descriptor, args)
145
+ const yAxis = this.getYAxis(descriptor, args)
146
+ const grid = this.getGrid(descriptor, args)
147
+ const legend = this.getLegend(descriptor, args)
148
+ const tooltip = this.getTooltip(descriptor, args)
149
+ const dataZoom = descriptor.scroll.end <= 0 ? undefined : this.getDataZoom(descriptor, args)
150
+ const dataset = { dimensions, source: DatasetDescriptor.getCollection(descriptor.dataset) }
151
+
152
+ this.options = { xAxis, yAxis, grid, legend, tooltip, dataset, dataZoom, series: children }
153
+ }
154
+
155
+ update(descriptor: EchartDescriptor, args: UpdateArgs) {
156
+ const wrapper = this.getWrapper()
157
+ this.setHTMLStyle(wrapper, this.getWrapperStyle(descriptor, args))
158
+ this.setHTMLInteraction(wrapper, descriptor, args)
159
+ this.setHTMLStyle(this.DOM, this.getLayoutStyle(descriptor, args))
160
+ this.setStyleClass(this.DOM, this.getStyleClass(descriptor, args))
161
+ this.setOptions(descriptor, args)
162
+ this.instance.clear()
163
+ this.instance.setOption(this.options)
164
+ const rect = wrapper.getBoundingClientRect()
165
+ this.instance.resize({ width: rect.width, height: rect.height, })
166
+ }
167
+ }
168
+
169
+ export {
170
+ EchartServiceOption,
171
+ EchartActor,
172
+ }
@@ -0,0 +1 @@
1
+ export * from './EchartActor'
@@ -0,0 +1,31 @@
1
+ import { DeserializationObject } from '@vyr/engine'
2
+ import { EchartItemStyle, ServiceEchartDescriptor } from './ServiceEchartDescriptor'
3
+
4
+ class BarServiceEchartDescriptor extends ServiceEchartDescriptor {
5
+ static type = 'BarServiceEchart'
6
+
7
+ barWidth: string
8
+ barMaxWidth: string
9
+ labelShow: boolean
10
+ labelColor: string
11
+ labelPosition: string
12
+
13
+ itemStyle: EchartItemStyle
14
+
15
+ constructor(descriptor: Partial<DeserializationObject<BarServiceEchartDescriptor>> = {}) {
16
+ super(descriptor)
17
+ this.echart = descriptor.echart ?? 'bar'
18
+ this.barWidth = descriptor.barWidth ?? ''
19
+ this.barMaxWidth = descriptor.barMaxWidth ?? ''
20
+ this.labelShow = descriptor.labelShow ?? false
21
+ this.labelColor = descriptor.labelColor ?? ''
22
+ this.labelPosition = descriptor.labelPosition ?? 'inside'
23
+
24
+ this.itemStyle = descriptor.itemStyle ? ServiceEchartDescriptor.deepClone(descriptor.itemStyle) : ServiceEchartDescriptor.getDefaultItemStyle()
25
+ }
26
+ }
27
+ ServiceEchartDescriptor.register(BarServiceEchartDescriptor)
28
+
29
+ export {
30
+ BarServiceEchartDescriptor
31
+ }
@@ -0,0 +1,106 @@
1
+ import { DeserializationObject, HTMLDescriptor } from '@vyr/engine'
2
+ import { ServiceEchartDescriptor } from './ServiceEchartDescriptor';
3
+
4
+ interface EchartRect {
5
+ left: string
6
+ top: string
7
+ width: string
8
+ height: string
9
+ }
10
+ interface EchartGridRect extends EchartRect {
11
+ right: string
12
+ bottom: string
13
+ }
14
+ interface EchartAxisLine {
15
+ show: boolean
16
+ }
17
+ interface EchartAxisTick {
18
+ show: boolean
19
+ }
20
+ interface EchartAxisLabel {
21
+ show: boolean
22
+ color: string
23
+ fontSize: number
24
+ }
25
+ interface EchartSplitLine {
26
+ show: boolean
27
+ }
28
+ interface EchartTextStyle {
29
+ color: string
30
+ }
31
+
32
+ interface EchartScroll {
33
+ end: number
34
+ }
35
+
36
+ class EchartDescriptor extends HTMLDescriptor {
37
+ static type = 'Echart'
38
+
39
+ declare children: ServiceEchartDescriptor[];
40
+
41
+ xAxisShow: boolean
42
+ xAxisType: string
43
+ xAxisModelValue: string
44
+ xAxisLine: EchartAxisLine
45
+ xAxisTick: EchartAxisTick
46
+ xAxisLabel: EchartAxisLabel
47
+ xAxisSplitLine: EchartSplitLine
48
+
49
+ yAxisShow: boolean
50
+ yAxisType: string
51
+ yAxisLine: EchartAxisLine
52
+ yAxisTick: EchartAxisTick
53
+ yAxisLabel: EchartAxisLabel
54
+ yAxisSplitLine: EchartSplitLine
55
+
56
+ gridShow: boolean
57
+ gridRect: EchartGridRect
58
+
59
+ legendType: string
60
+ legendShow: boolean
61
+ legendRect: EchartRect
62
+ legendTextStyle: EchartTextStyle
63
+
64
+ tooltipShow: boolean
65
+ tooltipTrigger: string
66
+
67
+ scroll: EchartScroll
68
+
69
+ constructor(descriptor: Partial<DeserializationObject<EchartDescriptor>> = {}) {
70
+ super(descriptor)
71
+ this.width = descriptor.width ?? 400
72
+ this.height = descriptor.height ?? 400
73
+ this.xAxisShow = descriptor.xAxisShow ?? true
74
+ this.xAxisType = descriptor.xAxisType ?? 'category'
75
+ this.xAxisModelValue = descriptor.xAxisModelValue ?? ''
76
+ this.xAxisLine = descriptor.xAxisLine ? HTMLDescriptor.deepClone(descriptor.xAxisLine) : { show: true }
77
+ this.xAxisTick = descriptor.xAxisTick ? HTMLDescriptor.deepClone(descriptor.xAxisTick) : { show: true }
78
+ this.xAxisLabel = descriptor.xAxisLabel ? HTMLDescriptor.deepClone(descriptor.xAxisLabel) : { show: true, color: '', fontSize: 12 }
79
+ this.xAxisSplitLine = descriptor.xAxisSplitLine ? HTMLDescriptor.deepClone(descriptor.xAxisSplitLine) : { show: false }
80
+
81
+ this.yAxisType = descriptor.yAxisType ?? ''
82
+ this.yAxisShow = descriptor.yAxisShow ?? true
83
+ this.yAxisLine = descriptor.yAxisLine ? HTMLDescriptor.deepClone(descriptor.yAxisLine) : { show: true }
84
+ this.yAxisTick = descriptor.yAxisTick ? HTMLDescriptor.deepClone(descriptor.yAxisTick) : { show: true, }
85
+ this.yAxisLabel = descriptor.yAxisLabel ? HTMLDescriptor.deepClone(descriptor.yAxisLabel) : { show: true, color: '', fontSize: 12 }
86
+ this.yAxisSplitLine = descriptor.yAxisSplitLine ? HTMLDescriptor.deepClone(descriptor.yAxisSplitLine) : { show: false }
87
+
88
+ this.gridShow = descriptor.gridShow ?? false
89
+ this.gridRect = descriptor.gridRect ? HTMLDescriptor.deepClone(descriptor.gridRect) : { top: '60', left: '10%', right: '10%', bottom: '60', width: 'auto', height: 'auto', }
90
+
91
+ this.legendType = descriptor.legendType ?? 'plain'
92
+ this.legendShow = descriptor.legendShow ?? true
93
+ this.legendRect = descriptor.legendRect ? HTMLDescriptor.deepClone(descriptor.legendRect) : { top: 'top', left: 'center', width: '', height: '', }
94
+ this.legendTextStyle = descriptor.legendTextStyle ? HTMLDescriptor.deepClone(descriptor.legendTextStyle) : { color: '#333' }
95
+
96
+ this.tooltipShow = descriptor.tooltipShow ?? true
97
+ this.tooltipTrigger = descriptor.tooltipTrigger ?? 'item'
98
+
99
+ this.scroll = descriptor.scroll ? HTMLDescriptor.deepClone(descriptor.scroll) : { end: -1 }
100
+ }
101
+ }
102
+ HTMLDescriptor.register(EchartDescriptor)
103
+
104
+ export {
105
+ EchartDescriptor
106
+ }
@@ -0,0 +1,30 @@
1
+ import { DefaultStyleColor, DeserializationObject, StyleColor } from '@vyr/engine'
2
+ import { ServiceEchartDescriptor } from './ServiceEchartDescriptor'
3
+
4
+ interface EchartLineStyle {
5
+ width: number
6
+ type: string
7
+ }
8
+
9
+ class LineServiceEchartDescriptor extends ServiceEchartDescriptor {
10
+ static type = 'LineServiceEchart'
11
+
12
+ smooth: boolean
13
+ lineStyle: EchartLineStyle
14
+ itemStyleColor: StyleColor
15
+ areaStyleColor: StyleColor
16
+
17
+ constructor(descriptor: Partial<DeserializationObject<LineServiceEchartDescriptor>> = {}) {
18
+ super(descriptor)
19
+ this.echart = descriptor.echart ?? 'line'
20
+ this.smooth = descriptor.smooth ?? false
21
+ this.lineStyle = descriptor.lineStyle ? ServiceEchartDescriptor.deepClone(descriptor.lineStyle) : { width: 0, type: 'solid', }
22
+ this.itemStyleColor = descriptor.itemStyleColor ? DefaultStyleColor.create(descriptor.itemStyleColor) : new DefaultStyleColor({ value: '#5470c6' })
23
+ this.areaStyleColor = descriptor.areaStyleColor ? DefaultStyleColor.create(descriptor.areaStyleColor) : new DefaultStyleColor({ value: '#849ae7' })
24
+ }
25
+ }
26
+ ServiceEchartDescriptor.register(LineServiceEchartDescriptor)
27
+
28
+ export {
29
+ LineServiceEchartDescriptor
30
+ }
@@ -0,0 +1,47 @@
1
+ import { DeserializationObject } from '@vyr/engine'
2
+ import { EchartItemStyle, ServiceEchartDescriptor } from './ServiceEchartDescriptor'
3
+
4
+ interface EchartCenter {
5
+ x: string
6
+ y: string
7
+ }
8
+
9
+ interface EchartRadius {
10
+ x: string
11
+ y: string
12
+ }
13
+
14
+ class PieServiceEchartDescriptor extends ServiceEchartDescriptor {
15
+ static type = 'PieServiceEchart'
16
+
17
+ roseType: string
18
+ width: string
19
+ height: string
20
+ radius: EchartRadius
21
+ center: EchartCenter
22
+ padAngle: number
23
+ labelShow: boolean
24
+ labelColor: string
25
+ labelPosition: string
26
+ itemStyle: EchartItemStyle
27
+
28
+ constructor(descriptor: Partial<DeserializationObject<PieServiceEchartDescriptor>> = {}) {
29
+ super(descriptor)
30
+ this.echart = descriptor.echart ?? 'pie'
31
+ this.roseType = descriptor.roseType ?? 'area'
32
+ this.width = descriptor.width ?? 'auto'
33
+ this.height = descriptor.height ?? 'auto'
34
+ this.radius = descriptor.radius ? ServiceEchartDescriptor.deepClone(descriptor.radius) : { x: '0', y: '75%' }
35
+ this.center = descriptor.center ? ServiceEchartDescriptor.deepClone(descriptor.center) : { x: '50%', y: '50%' }
36
+ this.padAngle = descriptor.padAngle ?? 4
37
+ this.labelShow = descriptor.labelShow ?? false
38
+ this.labelColor = descriptor.labelColor ?? ''
39
+ this.labelPosition = descriptor.labelPosition ?? 'outside'
40
+ this.itemStyle = descriptor.itemStyle ? ServiceEchartDescriptor.deepClone(descriptor.itemStyle) : ServiceEchartDescriptor.getDefaultItemStyle()
41
+ }
42
+ }
43
+ ServiceEchartDescriptor.register(PieServiceEchartDescriptor)
44
+
45
+ export {
46
+ PieServiceEchartDescriptor
47
+ }
@@ -0,0 +1,39 @@
1
+ import { DefaultStyleColor, Descriptor, DeserializationObject, StyleColor } from '@vyr/engine'
2
+
3
+ interface EchartItemStyle {
4
+ color: StyleColor
5
+ borderColor: DefaultStyleColor
6
+ borderWidth: number
7
+ borderType: string
8
+ borderRadius: number
9
+ }
10
+
11
+ class ServiceEchartDescriptor extends Descriptor {
12
+ static type = 'ServiceEchart'
13
+
14
+ static getDefaultItemStyle() {
15
+ const itemStyle: EchartItemStyle = {
16
+ color: new DefaultStyleColor({ value: '#5470c6' }),
17
+ borderColor: new DefaultStyleColor({ opacity: 0 }),
18
+ borderWidth: 0,
19
+ borderType: 'solid',
20
+ borderRadius: 0
21
+ }
22
+
23
+ return itemStyle
24
+ }
25
+
26
+ echart: string
27
+ modelValue: string
28
+
29
+ constructor(descriptor: Partial<DeserializationObject<ServiceEchartDescriptor>> = {}) {
30
+ super(descriptor)
31
+ this.echart = descriptor.echart ?? ''
32
+ this.modelValue = descriptor.modelValue ?? ''
33
+ }
34
+ }
35
+
36
+ export {
37
+ EchartItemStyle,
38
+ ServiceEchartDescriptor
39
+ }
@@ -0,0 +1,5 @@
1
+ export * from './EchartDescriptor'
2
+ export * from './ServiceEchartDescriptor'
3
+ export * from './BarServiceEchartDescriptor'
4
+ export * from './LineServiceEchartDescriptor'
5
+ export * from './PieServiceEchartDescriptor'
package/src/index.ts ADDED
@@ -0,0 +1,4 @@
1
+ export * from './locale'
2
+ export * from './descriptor'
3
+ export * from './interpreter'
4
+ export * from './actor'
@@ -0,0 +1,34 @@
1
+ import { UpdateArgs } from "@vyr/engine";
2
+ import { BarServiceEchartDescriptor } from "../descriptor";
3
+ import { ServiceEchartInterpreter } from "./ServiceEchartInterpreter";
4
+
5
+ class BarServiceEchartInterpreter extends ServiceEchartInterpreter {
6
+ static type = BarServiceEchartDescriptor.type
7
+
8
+ getService(descriptor: BarServiceEchartDescriptor, args: UpdateArgs) {
9
+ const service = super.getService(descriptor, args)
10
+
11
+ return {
12
+ ...service,
13
+ barWidth: descriptor.barWidth,
14
+ barMaxWidth: descriptor.barMaxWidth,
15
+ label: {
16
+ show: descriptor.labelShow,
17
+ color: descriptor.labelColor,
18
+ position: descriptor.labelPosition,
19
+ },
20
+ itemStyle: {
21
+ color: this.getStyleColor(descriptor.itemStyle.color),
22
+ borderType: descriptor.itemStyle.borderType,
23
+ borderWidth: descriptor.itemStyle.borderWidth,
24
+ borderColor: this.getStyleColor(descriptor.itemStyle.borderColor),
25
+ borderRadius: descriptor.itemStyle.borderRadius,
26
+ }
27
+ }
28
+ }
29
+ }
30
+ ServiceEchartInterpreter.register(BarServiceEchartInterpreter)
31
+
32
+ export {
33
+ BarServiceEchartInterpreter
34
+ }
@@ -0,0 +1,46 @@
1
+ import { Descriptor, HTMLActor, Interpreter, PickupObject, UpdateArgs } from "@vyr/engine";
2
+ import { EchartDescriptor } from "../descriptor";
3
+ import { EchartActor } from "../actor";
4
+
5
+ class EchartInterpreter extends Interpreter {
6
+ static type = EchartDescriptor.type
7
+
8
+ protected createActor(descriptor: EchartDescriptor, args: UpdateArgs) {
9
+ return new EchartActor(descriptor.uuid)
10
+ }
11
+
12
+ update(descriptor: EchartDescriptor, args: UpdateArgs) {
13
+ super.update(descriptor, args)
14
+
15
+ const actor = this.getActor<EchartActor>(descriptor, args)
16
+ actor.update(descriptor, args)
17
+ }
18
+
19
+ mount(descriptor: EchartDescriptor, args: UpdateArgs, parentInterpreter: Interpreter, parentDescriptor: Descriptor) {
20
+ super.mount(descriptor, args, parentInterpreter, parentDescriptor)
21
+ const actor = this.getActor<EchartActor>(descriptor, args)
22
+
23
+ const parenActor = parentInterpreter.getActor<HTMLActor>(parentDescriptor, args)
24
+ parenActor.add(actor)
25
+ }
26
+
27
+ unmount(descriptor: Descriptor, args: UpdateArgs, parentInterpreter: Interpreter, parentDescriptor: Descriptor) {
28
+ const actor = this.getActor<EchartActor>(descriptor, args)
29
+ actor.clearStyleClass(actor.DOM)
30
+ actor.cleanInteraction()
31
+
32
+ const parenActor = parentInterpreter.getActor<HTMLActor>(parentDescriptor, args)
33
+ parenActor.remove(actor)
34
+
35
+ super.unmount(descriptor, args, parentInterpreter, parentDescriptor)
36
+ }
37
+
38
+ pickup(descriptor: Descriptor, args: UpdateArgs, result: PickupObject[]) {
39
+ result.push({ uuid: descriptor.uuid, generatedBy: descriptor.generatedBy })
40
+ }
41
+ }
42
+ Interpreter.register(EchartInterpreter)
43
+
44
+ export {
45
+ EchartInterpreter
46
+ }
@@ -0,0 +1,31 @@
1
+ import { UpdateArgs } from "@vyr/engine";
2
+ import { LineServiceEchartDescriptor } from "../descriptor";
3
+ import { ServiceEchartInterpreter } from "./ServiceEchartInterpreter";
4
+
5
+ class LineServiceEchartInterpreter extends ServiceEchartInterpreter {
6
+ static type = LineServiceEchartDescriptor.type
7
+
8
+ getService(descriptor: LineServiceEchartDescriptor, args: UpdateArgs) {
9
+ const service = super.getService(descriptor, args)
10
+
11
+ return {
12
+ ...service,
13
+ smooth: descriptor.smooth,
14
+ lineStyle: {
15
+ type: descriptor.lineStyle.type,
16
+ width: descriptor.lineStyle.width,
17
+ },
18
+ itemStyle: {
19
+ color: this.getStyleColor(descriptor.itemStyleColor),
20
+ },
21
+ areaStyle: {
22
+ color: this.getStyleColor(descriptor.areaStyleColor),
23
+ }
24
+ }
25
+ }
26
+ }
27
+ ServiceEchartInterpreter.register(LineServiceEchartInterpreter)
28
+
29
+ export {
30
+ LineServiceEchartInterpreter
31
+ }
@@ -0,0 +1,38 @@
1
+ import { UpdateArgs } from "@vyr/engine";
2
+ import { PieServiceEchartDescriptor } from "../descriptor";
3
+ import { ServiceEchartInterpreter } from "./ServiceEchartInterpreter";
4
+
5
+ class PieServiceEchartInterpreter extends ServiceEchartInterpreter {
6
+ static type = PieServiceEchartDescriptor.type
7
+
8
+ getService(descriptor: PieServiceEchartDescriptor, args: UpdateArgs) {
9
+ const service = super.getService(descriptor, args)
10
+
11
+ return {
12
+ ...service,
13
+ roseType: descriptor.roseType,
14
+ width: descriptor.width,
15
+ height: descriptor.height,
16
+ radius: [descriptor.radius.x, descriptor.radius.y],
17
+ center: [descriptor.center.x, descriptor.center.y],
18
+ padAngle: descriptor.padAngle,
19
+ label: {
20
+ show: descriptor.labelShow,
21
+ color: descriptor.labelColor,
22
+ position: descriptor.labelPosition,
23
+ },
24
+ itemStyle: {
25
+ color: this.getStyleColor(descriptor.itemStyle.color),
26
+ borderType: descriptor.itemStyle.borderType,
27
+ borderWidth: descriptor.itemStyle.borderWidth,
28
+ borderColor: this.getStyleColor(descriptor.itemStyle.borderColor),
29
+ borderRadius: descriptor.itemStyle.borderRadius,
30
+ }
31
+ }
32
+ }
33
+ }
34
+ ServiceEchartInterpreter.register(PieServiceEchartInterpreter)
35
+
36
+ export {
37
+ PieServiceEchartInterpreter
38
+ }
@@ -0,0 +1,90 @@
1
+ import * as echarts from 'echarts'
2
+ import { Descriptor, StyleColor, Interpreter, Queue, UpdateArgs } from "@vyr/engine";
3
+ import { EchartDescriptor, ServiceEchartDescriptor } from "../descriptor";
4
+ import { EchartActor } from '../actor';
5
+
6
+ class ServiceEchartInterpreter extends Interpreter {
7
+ static type = ServiceEchartDescriptor.type
8
+
9
+ getLinearXYByAngle(angle: number) {
10
+ const radian = (angle * Math.PI) / 180
11
+ const x = Math.cos(radian)
12
+ const y = Math.sin(radian)
13
+ const x2 = Math.cos(radian + Math.PI)
14
+ const y2 = Math.sin(radian + Math.PI)
15
+
16
+ return { x, y, x2, y2 }
17
+ }
18
+
19
+ getStyleColor(color: StyleColor) {
20
+ if (color.type == 'linear') {
21
+ const { x, y, x2, y2 } = this.getLinearXYByAngle(color.angle)
22
+
23
+ const colorStops = []
24
+ for (const item of color.value) {
25
+ colorStops.push({ offset: item.ratio, color: echarts.color.modifyAlpha(item.value, item.opacity) })
26
+ }
27
+
28
+ const style = {
29
+ type: color.type,
30
+ x, y, x2, y2,
31
+ colorStops
32
+ }
33
+
34
+ return style
35
+ } else if (color.type === 'radial') {
36
+ const colorStops = []
37
+ for (const item of color.value) {
38
+ colorStops.push({ offset: item.ratio, color: echarts.color.modifyAlpha(item.value, item.opacity) })
39
+ }
40
+
41
+ const style = {
42
+ type: color.type,
43
+ r: color.radius,
44
+ x: color.center.x,
45
+ y: color.center.y,
46
+ colorStops
47
+ }
48
+
49
+ return style
50
+ } else {
51
+ return echarts.color.modifyAlpha(color.value, color.opacity)
52
+ }
53
+ }
54
+
55
+ getService(descriptor: ServiceEchartDescriptor, args: UpdateArgs) {
56
+ return { type: descriptor.echart, name: descriptor.name }
57
+ }
58
+
59
+ update(descriptor: ServiceEchartDescriptor, args: UpdateArgs) {
60
+ super.update(descriptor, args)
61
+ const unit = this.graphics.getUnit(descriptor.uuid)
62
+ const parentDescriptor = Descriptor.get(unit.parent)
63
+ if (parentDescriptor instanceof EchartDescriptor) {
64
+ const actor = this.graphics.getActor<EchartActor>(parentDescriptor, args)
65
+ if (actor === null) return
66
+ actor.setOptions(parentDescriptor, args)
67
+ actor.instance.setOption(actor.options)
68
+ }
69
+ }
70
+
71
+ mount(descriptor: EchartDescriptor, args: UpdateArgs, parentInterpreter: Interpreter, parentDescriptor: Descriptor) {
72
+ super.mount(descriptor, args, parentInterpreter, parentDescriptor)
73
+ if (parentDescriptor instanceof EchartDescriptor) {
74
+ const unit = this.graphics.getUnit(parentDescriptor.uuid)
75
+ if (unit) unit.trigger(Queue.Update)
76
+ }
77
+ }
78
+
79
+ unmount(descriptor: Descriptor, args: UpdateArgs, parentInterpreter: Interpreter, parentDescriptor: Descriptor) {
80
+ if (parentDescriptor instanceof EchartDescriptor) {
81
+ const unit = this.graphics.getUnit(parentDescriptor.uuid)
82
+ if (unit) unit.trigger(Queue.Update)
83
+ }
84
+ super.unmount(descriptor, args, parentInterpreter, parentDescriptor)
85
+ }
86
+ }
87
+
88
+ export {
89
+ ServiceEchartInterpreter
90
+ }
@@ -0,0 +1,5 @@
1
+ export * from './EchartInterpreter'
2
+ export * from './ServiceEchartInterpreter'
3
+ export * from './BarServiceEchartInterpreter'
4
+ export * from './LineServiceEchartInterpreter'
5
+ export * from './PieServiceEchartInterpreter'
@@ -0,0 +1,10 @@
1
+ import { Locale } from "@vyr/locale";
2
+ import { zhCnLanguageProvider, ZhCNLanguageProvider } from "./LanguageProvider";
3
+
4
+ Locale.register(zhCnLanguageProvider)
5
+
6
+ const language = Locale.getLanguage<ZhCNLanguageProvider>(zhCnLanguageProvider.name)
7
+
8
+ export {
9
+ language
10
+ }
@@ -0,0 +1,15 @@
1
+ import { LanguageProvider } from '@vyr/locale'
2
+
3
+ interface ZhCNLanguageProvider extends LanguageProvider {
4
+
5
+ }
6
+
7
+ const zhCnLanguageProvider: ZhCNLanguageProvider = {
8
+ id: 'zh_CN',
9
+ name: '@vyr/echarts',
10
+ }
11
+
12
+ export {
13
+ ZhCNLanguageProvider,
14
+ zhCnLanguageProvider,
15
+ }
@@ -0,0 +1,2 @@
1
+ export * from './LanguageProvider'
2
+ export * from './Language'