@operato/scene-gauge 0.0.16
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/@types/global/index.d.ts +1 -0
- package/CHANGELOG.md +16 -0
- package/LICENSE +21 -0
- package/README.md +15 -0
- package/assets/gauge-circle.png +0 -0
- package/assets/gauge-horizontal.png +0 -0
- package/assets/gauge-vertical.png +0 -0
- package/dist/gauge-circle.d.ts +57 -0
- package/dist/gauge-circle.js +211 -0
- package/dist/gauge-circle.js.map +1 -0
- package/dist/gauge-horizon.d.ts +56 -0
- package/dist/gauge-horizon.js +145 -0
- package/dist/gauge-horizon.js.map +1 -0
- package/dist/gauge-properties.d.ts +39 -0
- package/dist/gauge-properties.js +114 -0
- package/dist/gauge-properties.js.map +1 -0
- package/dist/gauge-vertical.d.ts +56 -0
- package/dist/gauge-vertical.js +143 -0
- package/dist/gauge-vertical.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/helps/scene/component/gauge-circle.ko.md +168 -0
- package/helps/scene/component/gauge-circle.md +167 -0
- package/helps/scene/component/gauge-circle.zh.md +164 -0
- package/helps/scene/component/gauge-horizon.ko.md +145 -0
- package/helps/scene/component/gauge-horizon.md +145 -0
- package/helps/scene/component/gauge-horizon.zh.md +145 -0
- package/helps/scene/component/gauge-vertical.ko.md +12 -0
- package/helps/scene/component/gauge-vertical.md +9 -0
- package/helps/scene/component/gauge-vertical.zh.md +10 -0
- package/helps/scene/images/gauge-circle-01.png +0 -0
- package/helps/scene/images/gauge-circle-02.png +0 -0
- package/helps/scene/images/gauge-circle-03.png +0 -0
- package/helps/scene/images/gauge-circle-04.png +0 -0
- package/helps/scene/images/gauge-circle-05.png +0 -0
- package/helps/scene/images/gauge-circle-06.png +0 -0
- package/helps/scene/images/gauge-circle-07.png +0 -0
- package/helps/scene/images/gauge-circle-08.png +0 -0
- package/helps/scene/images/gauge-circle-09.png +0 -0
- package/helps/scene/images/gauge-circle-10.png +0 -0
- package/helps/scene/images/gauge-circle-11.png +0 -0
- package/helps/scene/images/gauge-circle-12.png +0 -0
- package/helps/scene/images/gauge-circle-13.png +0 -0
- package/helps/scene/images/gauge-circle-14.png +0 -0
- package/helps/scene/images/gauge-circle-15.png +0 -0
- package/helps/scene/images/gauge-circle-16.png +0 -0
- package/helps/scene/images/gauge-circle-17.png +0 -0
- package/helps/scene/images/gauge-circle-18.png +0 -0
- package/helps/scene/images/gauge-circle-19.png +0 -0
- package/helps/scene/images/gauge-circle-20.png +0 -0
- package/helps/scene/images/gauge-circle-21.png +0 -0
- package/helps/scene/images/gauge-horizontal-01.png +0 -0
- package/helps/scene/images/gauge-vertical-01.png +0 -0
- package/helps/scene/images/gauge-vertical-02.png +0 -0
- package/helps/scene/images/gauge-vertical-03.png +0 -0
- package/helps/scene/images/gauge-vertical-04.png +0 -0
- package/helps/scene/images/gauge-vertical-05.png +0 -0
- package/helps/scene/images/gauge-vertical-06.png +0 -0
- package/helps/scene/images/gauge-vertical-07.png +0 -0
- package/helps/scene/images/gauge-vertical-08.png +0 -0
- package/helps/scene/images/gauge-vertical-09.png +0 -0
- package/helps/scene/images/gauge-vertical-10.png +0 -0
- package/helps/scene/images/gauge-vertical-11.png +0 -0
- package/helps/scene/images/gauge-vertical-12.png +0 -0
- package/helps/scene/images/gauge-vertical-13.png +0 -0
- package/helps/scene/images/gauge-vertical-14.png +0 -0
- package/helps/scene/images/gauge-vertical-15.png +0 -0
- package/helps/scene/images/gauge-vertical-16.png +0 -0
- package/helps/scene/images/gauge-vertical-17.png +0 -0
- package/helps/scene/images/gauge-vertical-18.png +0 -0
- package/package.json +61 -0
- package/src/gauge-circle.ts +310 -0
- package/src/gauge-horizon.ts +204 -0
- package/src/gauge-properties.ts +114 -0
- package/src/gauge-vertical.ts +203 -0
- package/src/index.ts +6 -0
- package/test/basic-test.html +67 -0
- package/test/index.html +22 -0
- package/things-scene.config.js +158 -0
- package/translations/en.json +3 -0
- package/translations/ko.json +3 -0
- package/translations/ms.json +3 -0
- package/translations/zh.json +3 -0
- package/tsconfig.json +22 -0
- package/tsconfig.tsbuildinfo +1 -0
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
# gauge horizon
|
|
2
|
+
![组件-仪表(垂直)][gauge-vertical-01]
|
|
3
|
+
用竖条形状,显示仪表的组件。
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
## properties
|
|
7
|
+
|
|
8
|
+
1. Value(Number) - 仪表的值。
|
|
9
|
+
<figure style="text-align: center;">
|
|
10
|
+
|
|
11
|
+
![仪表-Value适用结果][gauge-vertical-02]
|
|
12
|
+
<figurecaption>(value: 85)</figurecaption>
|
|
13
|
+
</figure>
|
|
14
|
+
|
|
15
|
+
2. startValue - 仪表的起始值。
|
|
16
|
+
<figure style="text-align: center;">
|
|
17
|
+
|
|
18
|
+
![仪表-BackgroundColor适用结果][gauge-vertical-03]
|
|
19
|
+
<figurecaption>(startValue: 10)</figurecaption>
|
|
20
|
+
</figure>
|
|
21
|
+
|
|
22
|
+
3. endValue - 仪表的最终值。
|
|
23
|
+
<figure style="text-align: center;">
|
|
24
|
+
|
|
25
|
+
![仪表-BackgroundColor适用结果][gauge-vertical-04]
|
|
26
|
+
<figurecaption>(endValue: 120)</figurecaption>
|
|
27
|
+
</figure>
|
|
28
|
+
|
|
29
|
+
4. step - 仪表的刻度间隔。
|
|
30
|
+
<figure style="text-align: center;">
|
|
31
|
+
|
|
32
|
+
![仪表-BackgroundColor适用结果][gauge-vertical-05]
|
|
33
|
+
<figurecaption>(step: 30)</figurecaption>
|
|
34
|
+
</figure>
|
|
35
|
+
|
|
36
|
+
5. stepTextSize - 仪表的刻度文本大小。
|
|
37
|
+
<figure style="text-align: center;">
|
|
38
|
+
|
|
39
|
+
![仪表-BackgroundColor适用结果][gauge-vertical-06]
|
|
40
|
+
<figurecaption>(stepTextSize: 10)</figurecaption>
|
|
41
|
+
</figure>
|
|
42
|
+
|
|
43
|
+
6. subStep - 仪表的刻度之间间隔。
|
|
44
|
+
<figure style="text-align: center;">
|
|
45
|
+
|
|
46
|
+
![仪表-BackgroundColor适用结果][gauge-vertical-07]
|
|
47
|
+
<figurecaption>(subStep: 10)</figurecaption>
|
|
48
|
+
</figure>
|
|
49
|
+
|
|
50
|
+
7. stepNeedleSize - 仪表的刻度大小。
|
|
51
|
+
<figure style="text-align: center;">
|
|
52
|
+
|
|
53
|
+
![仪表-BackgroundColor适用结果][gauge-vertical-08]
|
|
54
|
+
<figurecaption>(stepNeedleSize: 3)</figurecaption>
|
|
55
|
+
</figure>
|
|
56
|
+
|
|
57
|
+
8. textColor - 仪表的刻度文本颜色。
|
|
58
|
+
<figure style="text-align: center;">
|
|
59
|
+
|
|
60
|
+
![仪表-BackgroundColor适用结果][gauge-vertical-09]
|
|
61
|
+
<figurecaption>(textColor: #ec5324)</figurecaption>
|
|
62
|
+
</figure>
|
|
63
|
+
|
|
64
|
+
9. needleFillStyle - 仪表的针色。
|
|
65
|
+
<figure style="text-align: center;">
|
|
66
|
+
|
|
67
|
+
![仪表-BackgroundColor适用结果][gauge-vertical-10]
|
|
68
|
+
<figurecaption>(needleFillStyle: #ec5324)</figurecaption>
|
|
69
|
+
</figure>
|
|
70
|
+
|
|
71
|
+
10. needleSize - 仪表指针大小。
|
|
72
|
+
<figure style="text-align: center;">
|
|
73
|
+
|
|
74
|
+
![仪表-BackgroundColor适用结果][gauge-vertical-11]
|
|
75
|
+
<figurecaption>(needleSize: 10)</figurecaption>
|
|
76
|
+
</figure>
|
|
77
|
+
|
|
78
|
+
11. stepFillStyle - 仪表刻度的颜色。
|
|
79
|
+
<figure style="text-align: center;">
|
|
80
|
+
|
|
81
|
+
![仪表-BackgroundColor适用结果][gauge-vertical-12]
|
|
82
|
+
<figurecaption>(stepFillStyle: #ec5324)</figurecaption>
|
|
83
|
+
</figure>
|
|
84
|
+
|
|
85
|
+
12. colorStops - 仪表的各个区间的颜色。可以通过双击而添加区间,也可以向下拖动标记而删除区间。
|
|
86
|
+
<figure style="text-align: center;">
|
|
87
|
+
|
|
88
|
+
![仪表-BackgroundColor适用结果][gauge-vertical-13]
|
|
89
|
+
<figurecaption>(colorStops: <img src="{{site.baseurl}}/assets/components/color-stops-value.png" height="30" alt="color stops">)</figurecaption>
|
|
90
|
+
</figure>
|
|
91
|
+
|
|
92
|
+
13. showStartValue - 决定是否显示仪表的起始值。
|
|
93
|
+
<figure style="text-align: center;">
|
|
94
|
+
|
|
95
|
+
![仪表-BackgroundColor适用结果][gauge-vertical-14]
|
|
96
|
+
<figurecaption>(showStartValue: unchecked)</figurecaption>
|
|
97
|
+
</figure>
|
|
98
|
+
|
|
99
|
+
14. showEndValue - 决定是否显示仪表的最终值。
|
|
100
|
+
<figure style="text-align: center;">
|
|
101
|
+
|
|
102
|
+
![仪表-BackgroundColor适用结果][gauge-vertical-15]
|
|
103
|
+
<figurecaption>(showEndValue: unchecked)</figurecaption>
|
|
104
|
+
</figure>
|
|
105
|
+
|
|
106
|
+
15. showStepLine - 决定是否显示仪表的刻度。
|
|
107
|
+
<figure style="text-align: center;">
|
|
108
|
+
|
|
109
|
+
![仪表-BackgroundColor适用结果][gauge-vertical-16]
|
|
110
|
+
<figurecaption>(showStepLine: unchecked)</figurecaption>
|
|
111
|
+
</figure>
|
|
112
|
+
|
|
113
|
+
16. showStepText - 决定是否显示仪表的刻度值。
|
|
114
|
+
<figure style="text-align: center;">
|
|
115
|
+
|
|
116
|
+
![仪表-BackgroundColor适用结果][gauge-vertical-17]
|
|
117
|
+
<figurecaption>(showStepText: unchecked)</figurecaption>
|
|
118
|
+
</figure>
|
|
119
|
+
|
|
120
|
+
17. showSubStep - 决定是否显示仪表的分刻度。
|
|
121
|
+
<figure style="text-align: center;">
|
|
122
|
+
|
|
123
|
+
![仪表-BackgroundColor适用结果][gauge-vertical-18]
|
|
124
|
+
<figurecaption>(showSubStep: unchecked)</figurecaption>
|
|
125
|
+
</figure>
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
[gauge-vertical-01]:../images/gauge-vertical-01.png
|
|
129
|
+
[gauge-vertical-02]:../images/gauge-vertical-02.png
|
|
130
|
+
[gauge-vertical-03]:../images/gauge-vertical-03.png
|
|
131
|
+
[gauge-vertical-04]:../images/gauge-vertical-04.png
|
|
132
|
+
[gauge-vertical-05]:../images/gauge-vertical-05.png
|
|
133
|
+
[gauge-vertical-06]:../images/gauge-vertical-06.png
|
|
134
|
+
[gauge-vertical-07]:../images/gauge-vertical-07.png
|
|
135
|
+
[gauge-vertical-08]:../images/gauge-vertical-08.png
|
|
136
|
+
[gauge-vertical-09]:../images/gauge-vertical-09.png
|
|
137
|
+
[gauge-vertical-10]:../images/gauge-vertical-10.png
|
|
138
|
+
[gauge-vertical-11]:../images/gauge-vertical-11.png
|
|
139
|
+
[gauge-vertical-12]:../images/gauge-vertical-12.png
|
|
140
|
+
[gauge-vertical-13]:../images/gauge-vertical-13.png
|
|
141
|
+
[gauge-vertical-14]:../images/gauge-vertical-14.png
|
|
142
|
+
[gauge-vertical-15]:../images/gauge-vertical-15.png
|
|
143
|
+
[gauge-vertical-16]:../images/gauge-vertical-16.png
|
|
144
|
+
[gauge-vertical-17]:../images/gauge-vertical-17.png
|
|
145
|
+
[gauge-vertical-18]:../images/gauge-vertical-18.png
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/package.json
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@operato/scene-gauge",
|
|
3
|
+
"version": "0.0.16",
|
|
4
|
+
"description": "Things Scene Gauge Component",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "heartyoh",
|
|
7
|
+
"main": "dist/index.js",
|
|
8
|
+
"module": "dist/index.js",
|
|
9
|
+
"things-scene": true,
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"access": "public",
|
|
12
|
+
"@operato:registry": "https://registry.npmjs.org"
|
|
13
|
+
},
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/things-scene/operato-scene.git",
|
|
17
|
+
"directory": "packages/gauge"
|
|
18
|
+
},
|
|
19
|
+
"scripts": {
|
|
20
|
+
"serve": "tsc && things-factory-dev",
|
|
21
|
+
"start": "tsc && concurrently -k -r \"tsc --watch --preserveWatchOutput\" \"wds\"",
|
|
22
|
+
"build": "tsc",
|
|
23
|
+
"prepublish": "tsc",
|
|
24
|
+
"lint": "eslint --ext .ts,.html . --ignore-path .gitignore && prettier \"**/*.ts\" --check --ignore-path .gitignore",
|
|
25
|
+
"format": "eslint --ext .ts,.html . --fix --ignore-path .gitignore && prettier \"**/*.ts\" --write --ignore-path .gitignore",
|
|
26
|
+
"migration": "things-factory-migration"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@hatiolab/things-scene": "^2.7.25"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@hatiolab/prettier-config": "^1.0.0",
|
|
33
|
+
"@operato/board": "^0.2.44",
|
|
34
|
+
"@things-factory/builder": "^4.0.12",
|
|
35
|
+
"@things-factory/operato-board": "^4.0.12",
|
|
36
|
+
"@typescript-eslint/eslint-plugin": "^4.33.0",
|
|
37
|
+
"@typescript-eslint/parser": "^4.33.0",
|
|
38
|
+
"@web/dev-server": "^0.1.28",
|
|
39
|
+
"concurrently": "^5.3.0",
|
|
40
|
+
"eslint": "^7.32.0",
|
|
41
|
+
"eslint-config-prettier": "^8.3.0",
|
|
42
|
+
"husky": "^4.3.8",
|
|
43
|
+
"lint-staged": "^10.5.4",
|
|
44
|
+
"prettier": "^2.4.1",
|
|
45
|
+
"tslib": "^2.3.1",
|
|
46
|
+
"typescript": "^4.5.2"
|
|
47
|
+
},
|
|
48
|
+
"prettier": "@hatiolab/prettier-config",
|
|
49
|
+
"husky": {
|
|
50
|
+
"hooks": {
|
|
51
|
+
"pre-commit": "lint-staged"
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
"lint-staged": {
|
|
55
|
+
"*.ts": [
|
|
56
|
+
"eslint --fix",
|
|
57
|
+
"prettier --write"
|
|
58
|
+
]
|
|
59
|
+
},
|
|
60
|
+
"gitHead": "29382f4c11826d2e6514c545ab4d7b4d2f3bbf0d"
|
|
61
|
+
}
|
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright © HatioLab Inc. All rights reserved.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { Component, Donut, ValueHolder } from '@hatiolab/things-scene';
|
|
6
|
+
|
|
7
|
+
import { PROPERTIES } from './gauge-properties';
|
|
8
|
+
|
|
9
|
+
const NATURE = {
|
|
10
|
+
mutable: false,
|
|
11
|
+
resizable: true,
|
|
12
|
+
rotatable: true,
|
|
13
|
+
properties: [
|
|
14
|
+
...PROPERTIES,
|
|
15
|
+
{
|
|
16
|
+
type: 'number',
|
|
17
|
+
label: 'start-angle',
|
|
18
|
+
name: 'startAngle',
|
|
19
|
+
property: 'startAngle'
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
type: 'number',
|
|
23
|
+
label: 'end-angle',
|
|
24
|
+
name: 'endAngle',
|
|
25
|
+
property: 'endAngle'
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
type: 'color',
|
|
29
|
+
label: 'text-fill-style',
|
|
30
|
+
name: 'textFillStyle',
|
|
31
|
+
property: 'textFillStyle'
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
type: 'color',
|
|
35
|
+
label: 'needle-fill-style',
|
|
36
|
+
name: 'needleFillStyle',
|
|
37
|
+
property: 'needleFillStyle'
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
type: 'color',
|
|
41
|
+
label: 'inner-circle-fill-style',
|
|
42
|
+
name: 'innerCircleFillStyle',
|
|
43
|
+
property: 'innerCircleFillStyle'
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
type: 'checkbox',
|
|
47
|
+
label: 'in-text',
|
|
48
|
+
name: 'inText',
|
|
49
|
+
property: 'inText'
|
|
50
|
+
}
|
|
51
|
+
],
|
|
52
|
+
help: 'scene/component/gauge-circle'
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function drawStepLine(context: CanvasRenderingContext2D, ang: number, rx: number, stepNeedleSize: number) {
|
|
56
|
+
context.rotate(ang)
|
|
57
|
+
context.translate(0, -rx)
|
|
58
|
+
|
|
59
|
+
context.fillRect(0, -rx * 0.14, stepNeedleSize, rx * 0.175)
|
|
60
|
+
context.translate(0, rx)
|
|
61
|
+
context.rotate(-ang)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function drawSubStepLine(context: CanvasRenderingContext2D, ang: number, rx: number, stepNeedleSize: number) {
|
|
65
|
+
context.rotate(ang)
|
|
66
|
+
context.translate(0, -rx)
|
|
67
|
+
|
|
68
|
+
context.fillRect(0, -rx * 0.04, stepNeedleSize, rx * 0.075)
|
|
69
|
+
context.translate(0, rx)
|
|
70
|
+
context.rotate(-ang)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function drawStepText(context: CanvasRenderingContext2D, text: string, ang: number, rx: number) {
|
|
74
|
+
context.rotate(ang)
|
|
75
|
+
context.translate(0, -rx * 0.83)
|
|
76
|
+
context.rotate(-ang)
|
|
77
|
+
|
|
78
|
+
context.fillText(text, 0, 0)
|
|
79
|
+
context.rotate(ang)
|
|
80
|
+
context.translate(0, rx * 0.83)
|
|
81
|
+
context.rotate(-ang)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function drawNeedle(context: CanvasRenderingContext2D, rx: number, ang: number) {
|
|
85
|
+
context.rotate(ang)
|
|
86
|
+
|
|
87
|
+
context.beginPath()
|
|
88
|
+
|
|
89
|
+
context.moveTo(rx * 0.035, 0) // 중앙 두께
|
|
90
|
+
|
|
91
|
+
context.lineTo(0, rx * 0.8) // 끝 점
|
|
92
|
+
|
|
93
|
+
context.lineTo(-rx * 0.035, 0) // 중앙 두께
|
|
94
|
+
|
|
95
|
+
context.lineTo(-rx * 0.015, -rx * 0.2) // 뒷쪽 두께
|
|
96
|
+
context.lineTo(rx * 0.015, -rx * 0.2) // 뒷쪽 두께
|
|
97
|
+
|
|
98
|
+
context.rotate(-ang)
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export default class GaugeCircle extends ValueHolder(Donut) {
|
|
102
|
+
_draw(context: CanvasRenderingContext2D) {
|
|
103
|
+
var {
|
|
104
|
+
lineWidth = 20,
|
|
105
|
+
startValue,
|
|
106
|
+
endValue,
|
|
107
|
+
step,
|
|
108
|
+
subStep,
|
|
109
|
+
startAngle = 0,
|
|
110
|
+
endAngle = 180,
|
|
111
|
+
fontColor = 'black',
|
|
112
|
+
showStepText = true,
|
|
113
|
+
showStartValue = true,
|
|
114
|
+
showEndValue = true,
|
|
115
|
+
showStepLine = true,
|
|
116
|
+
showSubStep = true,
|
|
117
|
+
inText = true,
|
|
118
|
+
colorStops, // 스텝별 각각 다른 색
|
|
119
|
+
fillStyle,
|
|
120
|
+
textFillStyle = 'black',
|
|
121
|
+
needleFillStyle = 'black',
|
|
122
|
+
innerCircleFillStyle = 'gray',
|
|
123
|
+
stepNeedleSize = 2,
|
|
124
|
+
stepFillStyle,
|
|
125
|
+
stepTextSize,
|
|
126
|
+
cx,
|
|
127
|
+
cy,
|
|
128
|
+
rx,
|
|
129
|
+
ry,
|
|
130
|
+
ratio,
|
|
131
|
+
animFromBase = false
|
|
132
|
+
} = this.model
|
|
133
|
+
|
|
134
|
+
startValue = Number(startValue)
|
|
135
|
+
|
|
136
|
+
this.animOnValueChange(this.value, animFromBase, startValue)
|
|
137
|
+
|
|
138
|
+
const RADIAN = 0.0174533 / Math.PI
|
|
139
|
+
const rxRatio = (rx / 100) * ratio // 원 안에 지워지는 비율을 계산한 rx - ratio의 비율에 따라 크기가 변함
|
|
140
|
+
const ryRatio = (ry / 100) * ratio // 원 안에 지워지는 비율을 계산한 ry - ratio의 비율에 따라 크기가 변함
|
|
141
|
+
const circleSize = (endAngle - startAngle) / 180 // 원의 총 길이. - PI * 2가 원이므로 (360도 = 2, 180도 = 1)
|
|
142
|
+
const totalValue = endValue - startValue // 게이지의 시작과 끝 값의 크기
|
|
143
|
+
|
|
144
|
+
startAngle = startAngle * RADIAN - 0.5 // 맨 위쪽을 중심으로 앵글의 범위에 따라 왼쪽으로 넓어짐
|
|
145
|
+
endAngle = endAngle * RADIAN - 0.5 // 맨 위쪽을 중심으로 앵글의 범위에 따라 오른쪽으로 넓어짐
|
|
146
|
+
|
|
147
|
+
context.translate(cx, cy)
|
|
148
|
+
|
|
149
|
+
//// 메인 게이지 원 그리기 ////
|
|
150
|
+
context.beginPath()
|
|
151
|
+
|
|
152
|
+
context.ellipse(
|
|
153
|
+
0,
|
|
154
|
+
0,
|
|
155
|
+
Math.abs(rx),
|
|
156
|
+
Math.abs(ry),
|
|
157
|
+
0,
|
|
158
|
+
startAngle * Math.PI,
|
|
159
|
+
endAngle * Math.PI
|
|
160
|
+
)
|
|
161
|
+
this.drawStroke(context)
|
|
162
|
+
context.ellipse(
|
|
163
|
+
0,
|
|
164
|
+
0,
|
|
165
|
+
Math.abs(rxRatio),
|
|
166
|
+
Math.abs(ryRatio),
|
|
167
|
+
0,
|
|
168
|
+
endAngle * Math.PI,
|
|
169
|
+
startAngle * Math.PI,
|
|
170
|
+
true
|
|
171
|
+
) // 반대로 그리며 원을 지움.
|
|
172
|
+
// this.drawFill(context)
|
|
173
|
+
|
|
174
|
+
context.closePath()
|
|
175
|
+
|
|
176
|
+
//// 스텝별 색 칠하기 ////
|
|
177
|
+
if (colorStops) {
|
|
178
|
+
let beforeValue = 0
|
|
179
|
+
let endStepAngle = 0
|
|
180
|
+
context.moveTo(0, 0)
|
|
181
|
+
|
|
182
|
+
colorStops.forEach(function (v: {position: number; color: string;}, idx: number, arr: {position: number; color: string;}[]) {
|
|
183
|
+
context.beginPath()
|
|
184
|
+
|
|
185
|
+
let value = Math.max(Math.min(v.position - startValue, totalValue), 0) // v.position 범위의 최소값은 0, 최대값은 totalValue가 되야함.
|
|
186
|
+
let startStepAngle = endStepAngle || Math.PI * (startAngle + (circleSize * beforeValue) / totalValue)
|
|
187
|
+
|
|
188
|
+
if (idx === arr.length - 1)
|
|
189
|
+
// 마지막값은 무조건 끝까지 채워주도록 한다
|
|
190
|
+
endStepAngle = Math.PI * (startAngle + circleSize)
|
|
191
|
+
else endStepAngle = Math.PI * (startAngle + (circleSize * value) / totalValue)
|
|
192
|
+
|
|
193
|
+
if (beforeValue > totalValue || beforeValue > value)
|
|
194
|
+
// 값이 게이지의 최대 값을 넘어가거나 이전 값 보다 현재값이 작으면 다시 그릴 필요 없음
|
|
195
|
+
return false
|
|
196
|
+
|
|
197
|
+
context.ellipse(0, 0, Math.abs(rx), Math.abs(ry), 0, startStepAngle, endStepAngle)
|
|
198
|
+
context.ellipse(0, 0, Math.abs(rxRatio), Math.abs(ryRatio), 0, endStepAngle, startStepAngle, true)
|
|
199
|
+
context.fillStyle = v.color
|
|
200
|
+
context.fill()
|
|
201
|
+
|
|
202
|
+
beforeValue = value
|
|
203
|
+
})
|
|
204
|
+
}
|
|
205
|
+
context.scale(1, ry / rx)
|
|
206
|
+
|
|
207
|
+
//// 바늘 그리기 ////
|
|
208
|
+
context.beginPath()
|
|
209
|
+
let drawingValue = this.animValue
|
|
210
|
+
drawingValue = Math.max(Math.min(drawingValue, endValue), startValue) // 그려지는 값은 startValue보다 작을 수 없고, endValue보다 클 수 없음.
|
|
211
|
+
|
|
212
|
+
let ang = Math.PI * ((circleSize * (drawingValue - startValue)) / totalValue + startAngle - 0.5)
|
|
213
|
+
|
|
214
|
+
drawNeedle(context, rx, ang)
|
|
215
|
+
|
|
216
|
+
context.fillStyle = needleFillStyle
|
|
217
|
+
context.fill()
|
|
218
|
+
|
|
219
|
+
//// 중앙 원 그리기 ////
|
|
220
|
+
context.beginPath()
|
|
221
|
+
context.ellipse(0, 0, Math.abs(rx) / 15, Math.abs(rx) / 15, 0, 0, 2 * Math.PI)
|
|
222
|
+
context.fillStyle = innerCircleFillStyle
|
|
223
|
+
context.fill()
|
|
224
|
+
|
|
225
|
+
//// 스텝 선 그리기 ////
|
|
226
|
+
context.fillStyle = stepFillStyle
|
|
227
|
+
if (showStepLine) {
|
|
228
|
+
let count = totalValue / step
|
|
229
|
+
|
|
230
|
+
// Draw StartValue
|
|
231
|
+
drawStepLine(context, Math.PI * (startAngle + 0.5), rx * 0.8, stepNeedleSize) // 원을 그릴때 PI는 45도 부터 그리지만 angle은 0도부터 틀어서 + 0.5도를 곱해줘야함
|
|
232
|
+
// Draw StepValue
|
|
233
|
+
for (let num = 1; num < count; num++) {
|
|
234
|
+
let ang = Math.PI * ((circleSize / count) * num + startAngle + 0.5)
|
|
235
|
+
|
|
236
|
+
drawStepLine(context, ang, rx * 0.8, stepNeedleSize)
|
|
237
|
+
}
|
|
238
|
+
// Draw EndValue
|
|
239
|
+
drawStepLine(context, Math.PI * (endAngle + 0.5), rx * 0.8, stepNeedleSize)
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
//// 서브 스탭 그리기 ////
|
|
243
|
+
if (showSubStep) {
|
|
244
|
+
let count = totalValue
|
|
245
|
+
|
|
246
|
+
// Draw StepValue
|
|
247
|
+
for (let num = 1; num <= count; num++) {
|
|
248
|
+
if (num % step == 0 || num % subStep != 0) {
|
|
249
|
+
// 메인 스탭과 서브 스탭은 그리지 않음
|
|
250
|
+
continue
|
|
251
|
+
}
|
|
252
|
+
let ang = Math.PI * ((circleSize / count) * num + startAngle + 0.5)
|
|
253
|
+
|
|
254
|
+
drawSubStepLine(context, ang, rx * 0.8, stepNeedleSize)
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
//// 스텝 텍스트 그리기 ////
|
|
259
|
+
context.fillStyle = textFillStyle
|
|
260
|
+
context.font = (rx * stepTextSize) / 50 + 'px arial'
|
|
261
|
+
context.textBaseline = 'middle'
|
|
262
|
+
context.textAlign = 'center'
|
|
263
|
+
let textLocation = inText ? 0.8 : 1.35
|
|
264
|
+
|
|
265
|
+
if (showStartValue) {
|
|
266
|
+
// Draw StartText
|
|
267
|
+
drawStepText(context, startValue, Math.PI * (startAngle + 0.5), rx * textLocation)
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
if (showEndValue) {
|
|
271
|
+
// Draw EndText
|
|
272
|
+
drawStepText(context, endValue, Math.PI * (endAngle + 0.5), rx * textLocation)
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
if (showStepText) {
|
|
276
|
+
// Draw StepText
|
|
277
|
+
let count = totalValue / step
|
|
278
|
+
|
|
279
|
+
for (let num = 1; num < count; num++) {
|
|
280
|
+
let value = startValue + step * num
|
|
281
|
+
let ang = Math.PI * ((circleSize / count) * num + startAngle + 0.5)
|
|
282
|
+
|
|
283
|
+
drawStepText(context, value, ang, rx * textLocation)
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
context.scale(1, rx / ry)
|
|
288
|
+
context.translate(-cx, -cy)
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
contains(x: number, y: number): boolean {
|
|
292
|
+
// 컨테인즈는 Ellipse로 정의함
|
|
293
|
+
var { cx, cy, rx, ry } = this.model
|
|
294
|
+
|
|
295
|
+
var normx = (x - cx) / (rx * 2 - 0.5)
|
|
296
|
+
var normy = (y - cy) / (ry * 2 - 0.5)
|
|
297
|
+
|
|
298
|
+
return normx * normx + normy * normy < 0.25
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
_post_draw(context: CanvasRenderingContext2D) {
|
|
302
|
+
this.drawText(context)
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
get nature() {
|
|
306
|
+
return NATURE
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
Component.register('gauge-circle', GaugeCircle)
|