openatc-components 0.0.1 → 0.0.2

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 (154) hide show
  1. package/.babelrc +18 -18
  2. package/.editorconfig +9 -9
  3. package/.eslintignore +5 -5
  4. package/.eslintrc.js +29 -29
  5. package/.postcssrc.js +10 -10
  6. package/README.md +30 -30
  7. package/build/build.js +41 -41
  8. package/build/check-versions.js +54 -54
  9. package/build/package.config.js +58 -58
  10. package/build/package.dev.config.js +25 -25
  11. package/build/package.prod.config.js +60 -60
  12. package/build/utils.js +101 -101
  13. package/build/vue-loader.conf.js +22 -22
  14. package/build/webpack.base.conf.js +109 -109
  15. package/build/webpack.dev.conf.js +95 -95
  16. package/build/webpack.prod.conf.js +149 -149
  17. package/config/dev.env.js +7 -7
  18. package/config/index.js +76 -76
  19. package/config/prod.env.js +4 -4
  20. package/config/test.env.js +7 -7
  21. package/index.html +12 -12
  22. package/package/kisscomps/components/CircleMenu/KissCircleMenu.vue +398 -398
  23. package/package/kisscomps/components/CircleMenu/index.js +2 -2
  24. package/package/kisscomps/components/DashBoard/MakeGradientColor.js +84 -84
  25. package/package/kisscomps/components/DashBoard/dashboard.js +471 -471
  26. package/package/kisscomps/components/DashBoard/dashboard.vue +57 -57
  27. package/package/kisscomps/components/DashBoard/index.js +2 -2
  28. package/package/kisscomps/components/Horizontal/KissHorizontal.vue +146 -146
  29. package/package/kisscomps/components/Horizontal/index.js +2 -2
  30. package/package/kisscomps/components/HorizontalChildren/KissHorizontalChildren.vue +196 -196
  31. package/package/kisscomps/components/HorizontalChildren/index.js +2 -2
  32. package/package/kisscomps/components/KissCircleMenu/CircleMenu.vue +113 -113
  33. package/package/kisscomps/components/KissCircleMenu/index.js +2 -2
  34. package/package/kisscomps/components/KissCircleMenu/style/index.less +1 -1
  35. package/package/kisscomps/components/KissCircleMenu/style/main/core.less +161 -161
  36. package/package/kisscomps/components/KissCircleMenu/style/main/other.less +94 -94
  37. package/package/kisscomps/components/KissCircleMenu/style/mixin/mixin.less +36 -36
  38. package/package/kisscomps/components/KissCircleMenu/style/var/var.less +21 -21
  39. package/package/kisscomps/components/KissCircleMenu/utils/colorRE.js +5 -5
  40. package/package/kisscomps/components/KissMessageBox/KissMessageBox.vue +108 -108
  41. package/package/kisscomps/components/KissMessageBox/index.js +2 -2
  42. package/package/kisscomps/components/KissSearchInput/index.js +2 -2
  43. package/package/kisscomps/components/KissSearchInput/kisssearchinput.vue +77 -77
  44. package/package/kisscomps/components/KissSimulationProgress/KissSimulationProgress.vue +294 -294
  45. package/package/kisscomps/components/KissSimulationProgress/index.js +2 -2
  46. package/package/kisscomps/components/StatusBar/StatusBar.vue +222 -222
  47. package/package/kisscomps/components/StatusBar/index.js +2 -2
  48. package/package/kisscomps/components/TragResize/index.js +2 -2
  49. package/package/kisscomps/components/TragResize/kissdragresize.vue +536 -536
  50. package/package/kisscomps/components/TragResize/util/dom.js +23 -23
  51. package/package/kisscomps/components/TragResize/util/fns.js +3 -3
  52. package/package/kisscomps/components/XRDDirSelector/XRDDirSelector.1.vue +320 -320
  53. package/package/kisscomps/components/XRDDirSelector/XRDDirSelector.vue +345 -345
  54. package/package/kisscomps/components/XRDDirSelector/index.js +2 -2
  55. package/package/kisscomps/components/button/index.js +2 -2
  56. package/package/kisscomps/components/button/kissbutton.vue +168 -168
  57. package/package/kisscomps/components/compass3D/compass.vue +180 -180
  58. package/package/kisscomps/components/compass3D/index.js +2 -2
  59. package/package/kisscomps/components/header/index.js +2 -2
  60. package/package/kisscomps/components/header/kissHead.vue +83 -83
  61. package/package/kisscomps/components/horizontalMenu/index.js +2 -2
  62. package/package/kisscomps/components/horizontalMenu/kissHorizontalMenu.vue +254 -254
  63. package/package/kisscomps/components/input/index.js +2 -2
  64. package/package/kisscomps/components/input/kissinput.vue +57 -57
  65. package/package/kisscomps/components/menu/index.js +2 -2
  66. package/package/kisscomps/components/menu/kissmenu.vue +324 -324
  67. package/package/kisscomps/components/mutipletips/Tdrag.js +585 -585
  68. package/package/kisscomps/components/mutipletips/index.js +2 -2
  69. package/package/kisscomps/components/mutipletips/kissmutipletips.vue +192 -192
  70. package/package/kisscomps/components/panel/index.js +2 -2
  71. package/package/kisscomps/components/panel/kissPanel.vue +151 -151
  72. package/package/kisscomps/components/select/chosen.jquery.min.js +3 -3
  73. package/package/kisscomps/components/select/index.js +2 -2
  74. package/package/kisscomps/components/select/kissselect.vue +527 -527
  75. package/package/kisscomps/components/tablebutton/index.js +2 -2
  76. package/package/kisscomps/components/tablebutton/tablebutton.vue +97 -97
  77. package/package/kisscomps/components/timectrl/KissTimeCtrl.vue +67 -67
  78. package/package/kisscomps/components/timectrl/index.js +2 -2
  79. package/package/kisscomps/components/timectrl/timectrl.css +851 -851
  80. package/package/kisscomps/components/tip/Tdrag.js +585 -585
  81. package/package/kisscomps/components/tip/index.js +2 -2
  82. package/package/kisscomps/components/tip/kisstips.1.vue +154 -154
  83. package/package/kisscomps/components/tip/kisstips.vue +154 -154
  84. package/package/kisscomps/components/tip/kisstips.vue.bak +211 -211
  85. package/package/kisscomps/index.js +71 -71
  86. package/package/kissui.js +203 -203
  87. package/package/kissui.min.js +203 -203
  88. package/package.json +1 -1
  89. package/src/App.vue +25 -25
  90. package/src/kisscomps/components/CircleMenu/KissCircleMenu.vue +398 -398
  91. package/src/kisscomps/components/CircleMenu/index.js +2 -2
  92. package/src/kisscomps/components/DashBoard/MakeGradientColor.js +84 -84
  93. package/src/kisscomps/components/DashBoard/dashboard.js +471 -471
  94. package/src/kisscomps/components/DashBoard/dashboard.vue +57 -57
  95. package/src/kisscomps/components/DashBoard/index.js +2 -2
  96. package/src/kisscomps/components/KissCircleMenu/CircleMenu.vue +113 -113
  97. package/src/kisscomps/components/KissCircleMenu/index.js +2 -2
  98. package/src/kisscomps/components/KissCircleMenu/style/index.less +1 -1
  99. package/src/kisscomps/components/KissCircleMenu/style/main/core.less +161 -161
  100. package/src/kisscomps/components/KissCircleMenu/style/main/other.less +94 -94
  101. package/src/kisscomps/components/KissCircleMenu/style/mixin/mixin.less +36 -36
  102. package/src/kisscomps/components/KissCircleMenu/style/var/var.less +21 -21
  103. package/src/kisscomps/components/KissCircleMenu/utils/colorRE.js +5 -5
  104. package/src/kisscomps/components/KissSearchInput/index.js +2 -2
  105. package/src/kisscomps/components/KissSearchInput/kisssearchinput.vue +77 -77
  106. package/src/kisscomps/components/SchemeConfig/closePhaselControlModal/index.vue +193 -0
  107. package/src/kisscomps/components/SchemeConfig/index.js +2 -0
  108. package/src/kisscomps/components/SchemeConfig/lockingPhaselControlModal/index.vue +214 -0
  109. package/src/kisscomps/components/SchemeConfig/manualControlModal/index.vue +176 -0
  110. package/src/kisscomps/components/SchemeConfig/realtimeStatusModal/index.vue +294 -0
  111. package/src/kisscomps/components/SchemeConfig/schemeconfig.vue +711 -0
  112. package/src/kisscomps/components/StatusBar/StatusBar.vue +222 -222
  113. package/src/kisscomps/components/StatusBar/index.js +2 -2
  114. package/src/kisscomps/components/TragResize/index.js +2 -2
  115. package/src/kisscomps/components/TragResize/kissdragresize.vue +536 -536
  116. package/src/kisscomps/components/XRDDirSelector/XRDDirSelector.1.vue +320 -320
  117. package/src/kisscomps/components/XRDDirSelector/XRDDirSelector.vue +345 -345
  118. package/src/kisscomps/components/XRDDirSelector/index.js +2 -2
  119. package/src/kisscomps/components/button/index.js +2 -2
  120. package/src/kisscomps/components/button/kissbutton.vue +168 -168
  121. package/src/kisscomps/components/compass3D/compass.vue +180 -180
  122. package/src/kisscomps/components/compass3D/index.js +2 -2
  123. package/src/kisscomps/components/horizontalMenu/index.js +2 -2
  124. package/src/kisscomps/components/horizontalMenu/kissHorizontalMenu.vue +254 -254
  125. package/src/kisscomps/components/input/index.js +2 -2
  126. package/src/kisscomps/components/input/kissinput.vue +57 -57
  127. package/src/kisscomps/components/menu/index.js +2 -2
  128. package/src/kisscomps/components/menu/kissmenu.vue +324 -324
  129. package/src/kisscomps/components/mutipletips/Tdrag.js +585 -585
  130. package/src/kisscomps/components/mutipletips/index.js +2 -2
  131. package/src/kisscomps/components/mutipletips/kissmutipletips.vue +192 -192
  132. package/src/kisscomps/components/select/chosen.jquery.min.js +3 -3
  133. package/src/kisscomps/components/select/index.js +2 -2
  134. package/src/kisscomps/components/select/kissselect.vue +527 -527
  135. package/src/kisscomps/components/timectrl/KissTimeCtrl.vue +67 -67
  136. package/src/kisscomps/components/timectrl/index.js +2 -2
  137. package/src/kisscomps/components/tip/Tdrag.js +585 -585
  138. package/src/kisscomps/components/tip/index.js +2 -2
  139. package/src/kisscomps/components/tip/kisstips.1.vue +154 -154
  140. package/src/kisscomps/components/tip/kisstips.vue +154 -154
  141. package/src/kisscomps/components/tip/kisstips.vue.bak +211 -211
  142. package/src/kisscomps/index.js +73 -71
  143. package/src/main.js +23 -23
  144. package/src/router/index.js +15 -15
  145. package/src/views/home.1.vue +479 -479
  146. package/src/views/home.vue +196 -196
  147. package/test/e2e/custom-assertions/elementCount.js +27 -27
  148. package/test/e2e/nightwatch.conf.js +46 -46
  149. package/test/e2e/runner.js +48 -48
  150. package/test/e2e/specs/test.js +19 -19
  151. package/test/unit/.eslintrc +7 -7
  152. package/test/unit/jest.conf.js +30 -30
  153. package/test/unit/setup.js +3 -3
  154. package/test/unit/specs/HelloWorld.spec.js +11 -11
@@ -1,471 +1,471 @@
1
- /**
2
- * @Description: 这个类封装了仪表盘
3
- * @Author: chengcheng
4
- * @Date: Create in 10:26 2019/04/03
5
- * @Modified By:
6
- */
7
- import MakeGradientColot from './MakeGradientColor'
8
- const PIDEG = Math.PI / 180
9
- export default class DashBoard {
10
- constructor (id, options) {
11
- this.m_id = id // id 用来获取dom节点
12
- this.m_options = options // 设置的选项
13
- this.m_canvas = null // canvas
14
- this.m_save_canvas = null // 用来保存状态的canvas 暂时还不理解
15
- this.m_context = null
16
- this.m_save_context = null // canvas绘制环境
17
- this.m_percent = 0
18
- this.m_target_percent = 0
19
- this.m_tickmask_offset = 0
20
- this.m_halfCanvasWidth = 0
21
- this.m_halfCanvasHeight = 0
22
- this.m_rotation_deg = 0
23
-
24
- this.default_option = {
25
- style: 'bar',
26
- bar_radius: 200,
27
- bar_bg_w: 20,
28
- bar_w: 18,
29
- bar_bg_color: '#193b43',
30
- bar_bg_ring_color: '#193b43',
31
- bar_start_color: '#42daff',
32
- bar_stop_color: 'yellow',
33
- title: '交通强度',
34
- title_font_color: '#FFFFFF',
35
- title_font_size: 40,
36
- title_show: true,
37
- title_font_family: 'HanHei SC, PingFang SC, Helvetica Neue Thin, Helvetica, STHeitiSC-Light, Arial, sans-serif',
38
- sides_font_color: '#FFFFFF',
39
- sides_font_size: 30,
40
- sides_show: true,
41
- sides_font_family: 'HanHei SC, PingFang SC, Helvetica Neue Thin, Helvetica, STHeitiSC-Light, Arial, sans-serif',
42
- tick_length: 12,
43
- large_tick_length: 22,
44
- tick_thickness: 1,
45
- tick_group_length: 9,
46
- ticks_groups_begin: 0,
47
- total_degrees: 200,
48
- total_tick: 101,
49
- tick_color: '#555962',
50
- tick_on_color: '#527d98',
51
- on_color_gradient: null,
52
- bg_color: 'rgba(255, 255, 255, 0)',
53
- gauge_scale: 1,
54
- animation_duration: 2000,
55
- show_num: true,
56
- show_center_num: true,
57
- center_font_size: 100,
58
- center_font_color: '#FFFFFF',
59
- cur_score_circle_color: '#555962',
60
- center_offset: {
61
- x: 0,
62
- y: -30
63
- },
64
- center_num_font_family: 'HanHei SC, PingFang SC, Helvetica Neue Thin, Helvetica, STHeitiSC-Light, Arial, sans-serif',
65
- num_gap: 1,
66
- num_begin: 0,
67
- num_font_size: 18,
68
- tickmask_offset: 0,
69
- num_font_family: 'HanHei SC, PingFang SC, Helvetica Neue Thin, Helvetica, STHeitiSC-Light, Arial, sans-serif',
70
- circle_radius: 5,
71
- circle_offset: 0,
72
- center_text_unit: '%',
73
- center_text_offset: {
74
- x: 16,
75
- y: 8 - 30
76
- }
77
- } // 默认选项
78
- this.m_default_option = {}
79
- Object.assign(this.m_default_option, this.default_option, options)
80
- // 初始化绘制环境
81
- this.InitCanvas()
82
- }
83
-
84
- /**
85
- * 初始化绘图环境
86
- */
87
- InitCanvas () {
88
- this.m_canvas = document.getElementById(this.m_id)
89
- this.m_save_canvas = document.createElement('canvas')
90
-
91
- let canvas = this.m_canvas
92
-
93
- this.m_save_canvas.width = canvas.width
94
- this.m_save_canvas.height = canvas.height
95
- this.delatLength = this.m_default_option.large_tick_length - this.m_default_option.tick_length
96
-
97
- this.m_save_context = this.m_save_canvas.getContext('2d')
98
- this.m_context = canvas.getContext('2d')
99
- // this.m_save_context.scale(4, 4)
100
- this.m_percent = this.m_default_option.percent || 0
101
- this.m_target_percent = this.m_percent
102
- this.m_tickmask_offset = this.getTickMarkOffset()
103
- this.m_halfCanvasHeight = this.m_save_canvas.height / 2
104
- this.m_halfCanvasWidth = this.m_save_canvas.width / 2
105
- this.m_rotation_deg = this.getRotationDeg()
106
- }
107
-
108
- getTickMarkOffset () {
109
- return this.m_default_option.tickmask_offset + this.m_default_option.circle_radius * 2 + this.m_default_option.circle_offset
110
- }
111
- getRotationDeg () {
112
- return this.m_default_option.total_degrees / (this.m_default_option.total_tick - 1) * PIDEG
113
- }
114
- /**
115
- * 准备舞台, 绘制背景和中间数值
116
- */
117
- prepareStage () {
118
- let saveCanvas = this.m_save_canvas
119
- let saveContext = this.m_save_context
120
- // 清除canvas画布
121
- saveContext.clearRect(0, 0, saveCanvas.width, saveCanvas.height)
122
- // 设置背景
123
- this.applyBg()
124
- // 设置旋转中心
125
- saveContext.translate(this.m_halfCanvasWidth,
126
- this.m_halfCanvasHeight - this.m_default_option.tick_thickness / 2)
127
- // 设置缩放比例
128
- saveContext.scale(this.m_default_option.gauge_scale,
129
- this.m_default_option.gauge_scale)
130
- // 绘制内容
131
- this.drawContent()
132
- }
133
-
134
- /**
135
- * 绘制弧度
136
- * @param {*} r 半径
137
- * @param {*} start 开始角度
138
- * @param {*} end 结束角度
139
- * @param {*} w 弧宽度
140
- * @param {*} colorStyle 圆环颜色 支持渐变
141
- */
142
- drawDonuts (r, start, end, w, colorStyle) {
143
- let saveContext = this.m_save_context
144
- saveContext.lineWidth = w
145
- saveContext.lineCap = 'round'
146
- saveContext.beginPath()
147
- saveContext.arc(0, 0, r, start, end, false)
148
- saveContext.strokeStyle = colorStyle// '#DC143C'
149
- saveContext.stroke()
150
- saveContext.closePath()
151
- }
152
-
153
- // 绘制中间数字
154
- drawContent () {
155
- let saveCanvas = this.m_save_canvas
156
- let saveContext = this.m_save_context
157
-
158
- if (this.m_default_option.show_center_num) {
159
- let fillColor = this.m_default_option.center_font_color
160
- ? this.m_default_option.center_font_color.split('-') : [this.m_default_option.tick_on_color]
161
- let centerText = Math.floor(
162
- this.m_percent * ((this.m_default_option.total_tick - 1) *
163
- this.m_default_option.num_gap +
164
- this.m_default_option.num_begin) / 100)
165
-
166
- var gaugeWidth = saveCanvas.width / 2 -
167
- this.m_default_option.circle_radius * 2 -
168
- this.m_default_option.circle_offset - this.m_default_option.large_tick_length - this.m_default_option.tickmask_offset
169
-
170
- saveContext.save()
171
- if (fillColor.length === 2) {
172
- var gradient = saveContext.createLinearGradient(-gaugeWidth, 0, gaugeWidth, 0)
173
- gradient.addColorStop('0', fillColor[0])
174
- gradient.addColorStop('0.7', fillColor[1])
175
- gradient.addColorStop('1', fillColor[1])
176
- saveContext.fillStyle = gradient
177
- } else {
178
- saveContext.fillStyle = fillColor[0]
179
- }
180
- saveContext.font = this.m_default_option.center_font_size + 'px ' + this.m_default_option.center_num_font_family
181
- saveContext.textAlign = 'center'
182
- saveContext.textBaseline = 'middle'
183
- var centerTextWidth = Math.floor(saveContext.measureText(centerText).width)
184
- saveContext.fillText(centerText, this.m_default_option.center_offset.x, this.m_default_option.center_offset.y)
185
- saveContext.font = '30px ' + this.m_default_option.num_font_family
186
- saveContext.textAlign = 'center'
187
- saveContext.textBaseline = 'middle'
188
- saveContext.fillText(this.m_default_option.center_text_unit, centerTextWidth / 2 +
189
- this.m_default_option.center_text_offset.x, this.m_default_option.center_text_offset.y)
190
- }
191
- let x, y, titleY
192
- let totalDegrees = this.m_default_option.total_degrees
193
- if (totalDegrees < 180) {
194
- x = this.m_default_option.bar_radius * Math.sin(totalDegrees / 2 * PIDEG)
195
- y = this.m_default_option.bar_radius * Math.cos(totalDegrees / 2 * PIDEG)
196
- y = -y
197
- titleY = 0
198
- } else if (totalDegrees === 180) {
199
- x = this.m_default_option.bar_radius
200
- y = 0
201
- titleY = 0
202
- } else {
203
- x = this.m_default_option.bar_radius * Math.cos((totalDegrees - 180) / 2 * PIDEG)
204
- y = this.m_default_option.bar_radius * Math.sin((totalDegrees - 180) / 2 * PIDEG)
205
- titleY = y
206
- }
207
- if (this.m_default_option.sides_show) {
208
- // 绘制最大值和最小值
209
- saveContext.font = this.m_default_option.sides_font_size + 'px ' + this.m_default_option.sides_font_family
210
- saveContext.fillStyle = this.m_default_option.sides_font_color
211
- saveContext.fillText(0, -x, y + 30)
212
- saveContext.fillText(this.m_default_option.total_tick, x, y + 30)
213
- }
214
- if (this.m_default_option.title_show) {
215
- saveContext.font = this.m_default_option.title_font_size + 'px ' + this.m_default_option.title_font_family
216
- saveContext.fillStyle = this.m_default_option.title_font_color
217
- saveContext.fillText(this.m_default_option.title, 0, titleY + 30)
218
- }
219
- saveContext.restore()
220
- }
221
- /**
222
- * 绘制刻度帧数, 刻度长度 和 第几个数字
223
- * @param {*} tickLength
224
- * @param {*} tickIndex
225
- */
226
- drawGaugeNum (tickLength, tickIndex) {
227
- let saveContext = this.m_save_context
228
- let text = this.m_default_option.num_begin + this.m_default_option.num_gap * tickIndex - 1
229
- // saveContext.measureText(text)
230
- saveContext.save()
231
- saveContext.translate(-1 * this.m_halfCanvasWidth +
232
- tickLength + this.m_default_option.circle_radius * 2 +
233
- this.m_default_option.circle_offset +
234
- this.m_default_option.num_font_size / 2, -this.m_default_option.tick_thickness / 2)
235
- saveContext.rotate(-90 * PIDEG)
236
- saveContext.font = this.m_default_option.num_font_size + 'px ' + this.m_default_option.num_font_family
237
- saveContext.textAlign = 'center'
238
- saveContext.textBaseline = 'middle'
239
- saveContext.fillText(text, 0, this.m_default_option.tickmask_offset)
240
- saveContext.restore()
241
- }
242
- /**
243
- * 应用背景
244
- */
245
- applyBg () {
246
- let saveCanvas = this.m_save_canvas
247
- let saveContext = this.m_save_context
248
- saveContext.save()
249
- saveContext.fillStyle = this.m_default_option.bg_color // 填充绘画的颜色
250
- saveContext.fillRect(0, 0, saveCanvas.width, saveCanvas.height) // 绘制“被填充”的矩形
251
- saveContext.restore() // 返回之前保存过的路径状态和属性
252
- }
253
- /**
254
- * 绘制提示圆点
255
- * @param {*} beginX
256
- * @param {*} beginY
257
- */
258
- drawScoreTipCircle (beginX, beginY) {
259
- let saveContext = this.m_save_context
260
- saveContext.save()
261
- saveContext.fillStyle = this.m_percent > 0.01
262
- ? this.m_default_option.cur_score_circle_color : this.m_default_option.tick_color
263
- saveContext.rotate(this.m_percent * this.m_default_option.total_degrees / 100 * PIDEG)
264
- saveContext.beginPath()
265
- /**
266
- * arc方法用来绘制圆
267
- * 参数1 圆心的x坐标
268
- * 参数2 圆心的y坐标
269
- * 参数3 圆的半径
270
- * 参数4 起始角 弧度单位
271
- * 参数5 结束角 弧度
272
- * 参数6 False = 顺时针 True = 逆时针
273
- */
274
- saveContext.arc(-beginX, -beginY, this.m_default_option.circle_radius, 0, Math.PI * 2, true)
275
- saveContext.closePath()
276
- saveContext.fill()
277
- saveContext.restore()
278
- }
279
- /**
280
- * 样式一 bar样式
281
- */
282
- drawProgressBar () {
283
- let dutyCycle = this.m_default_option.total_degrees
284
- let startAngle = (270 - dutyCycle / 2) * PIDEG
285
- let endAngle = startAngle + dutyCycle * PIDEG
286
-
287
- // bar_bg_color: '#193b43',
288
- let baroffset = 3
289
- this.drawDonuts(this.m_default_option.bar_radius,
290
- startAngle, endAngle,
291
- this.m_default_option.bar_bg_w, this.m_default_option.bar_bg_color)
292
- this.drawDonuts(this.m_default_option.bar_radius + this.m_default_option.bar_bg_w + baroffset,
293
- startAngle, endAngle,
294
- 3, this.m_default_option.bar_bg_ring_color)
295
-
296
- if (this.m_percent === 0) return
297
- let curNum = this.m_percent
298
- if (curNum >= this.m_default_option.total_tick) curNum = this.m_default_option.total_tick
299
- let curendAngle = startAngle + dutyCycle * curNum / 100 * PIDEG
300
-
301
- let saveContext = this.m_save_context
302
- let ring = saveContext.createLinearGradient(-205, 0, 205, 0)
303
- ring.addColorStop('0', this.m_default_option.bar_start_color)
304
- ring.addColorStop('1.0', this.m_default_option.bar_stop_color)
305
- this.drawDonuts(this.m_default_option.bar_radius,
306
- startAngle, curendAngle, this.m_default_option.bar_w, ring)
307
- }
308
-
309
- /**
310
- * 绘制刻度盘的样式
311
- */
312
- drawTickType () {
313
- let saveContext = this.m_save_context
314
- let startingDeg = (180 - this.m_default_option.total_degrees) / 2 // 计算开始旋转度数
315
- saveContext.rotate(startingDeg * PIDEG) // 旋转到初始位置
316
- // 绘制提示原点
317
- this.drawScoreTipCircle(this.m_halfCanvasWidth - this.m_default_option.circle_radius,
318
- this.m_default_option.circle_radius)
319
-
320
- let numTicks = this.m_default_option.total_tick // 总刻度
321
- for (let i = 1; i <= numTicks; i++) {
322
- // should this tick be on or off?
323
- let isOn = (((i - 1) / numTicks) * 100 < this.m_percent)
324
-
325
- // 判断是否最大
326
- let isLargeTick = this.isLargeTick(i)
327
- // let rectScale = isLargeTick ? this.large_tick_scale : 1
328
- let tickLength = isLargeTick ? this.m_default_option.large_tick_length : this.m_default_option.tick_length
329
-
330
- // 获取刻度颜色
331
- var color = this.getTickColor(isOn, i)
332
- saveContext.fillStyle = color
333
- if (isLargeTick) {
334
- saveContext.fillRect(-1 * this.m_halfCanvasWidth + this.m_default_option.circle_radius * 2 +
335
- this.m_default_option.circle_offset,
336
- -this.m_default_option.tick_thickness / 2,
337
- tickLength, this.m_default_option.tick_thickness)
338
- if (this.m_default_option.show_num) {
339
- this.drawGaugeNum(tickLength, i)
340
- }
341
- } else {
342
- saveContext.fillRect(-1 * this.m_halfCanvasWidth +
343
- this.m_default_option.circle_radius * 2 + this.m_default_option.circle_offset +
344
- this.delatLength,
345
- -this.m_default_option.tick_thickness / 2,
346
- tickLength, this.m_default_option.tick_thickness)
347
- }
348
- // rotate for next tick to be placed
349
- saveContext.rotate(this.m_rotation_deg)
350
- }
351
- }
352
-
353
- /**
354
- * @param {*} currentNum
355
- * 判断当前最大刻度
356
- */
357
- isLargeTick (currentNum) {
358
- return (currentNum + this.m_default_option.ticks_groups_begin - 1) % (this.m_default_option.tick_group_length + 1) === 0
359
- }
360
-
361
- gradientColorArray = function () {
362
- let colorArray = []
363
- if (!this.m_default_option.on_color_gradient || !this.m_target_percent) {
364
- return
365
- }
366
- for (let i = 0; i < this.m_default_option.on_color_gradient.length - 1; i++) {
367
- let next = this.m_default_option.on_color_gradient[i + 1]
368
- let cur = this.m_default_option.on_color_gradient[i]
369
- let colorStep = (next.percent - cur.percent) / 100 * this.total_tick
370
- colorArray = colorArray.concat(MakeGradientColot(cur.color, next.color, colorStep))
371
- }
372
- return colorArray
373
- }
374
-
375
- /**
376
- * 获取刻度颜色
377
- * @param {*} isOn
378
- * @param {*} index
379
- */
380
- getTickColor (isOn, index) {
381
- let indexTemp = index < 1 ? 1 : index
382
- if (isOn) {
383
- if (this.colorArray && this.colorArray.length > 0) {
384
- return this.colorArray[indexTemp - 1]
385
- } else {
386
- return this.m_default_option.tick_on_color
387
- }
388
- } else {
389
- return this.m_default_option.tick_color
390
- }
391
- }
392
- /**
393
- * 进行渲染绘制
394
- * @param percent
395
- */
396
- render (percent) {
397
- if (percent !== undefined) {
398
- this.m_percent = percent
399
- }
400
-
401
- // let saveCanvas = this.m_save_canvas
402
- let saveContext = this.m_save_context
403
- saveContext.save() // 用来保存Canvas的状态. save之后,可以调用Canvas的平移、放缩、旋转、错切、裁剪等操作
404
-
405
- // 绘制基本舞台 包括当前分值
406
- this.prepareStage()
407
- switch (this.m_default_option.style) {
408
- case 'bar': this.drawProgressBar(); break
409
- case 'tick': this.drawTickType(); break
410
- default: break
411
- }
412
- this.m_context.clearRect(0, 0, this.m_canvas.width, this.m_canvas.height)
413
- this.m_context.drawImage(this.m_save_canvas, 0, 0)
414
- saveContext.restore()
415
- }
416
-
417
- /**
418
- * 更新百分比以及实时显示信息
419
- */
420
- updatedPercent (percent, options = {}) {
421
- if (percent - 0.1 < 0) {
422
- return
423
- }
424
- let that = this
425
- this.m_target_percent = percent
426
- options = options || {}
427
- let duration = ('animation_duration' in options) ? options.animation_duration : that.m_default_option.animation_duration
428
- if (duration) {
429
- let lastUpdate = new Date()
430
- let start = this.m_percent
431
- let end = this.m_target_percent
432
- let changePerms = (end - start) / duration
433
- var increasing = changePerms > 0 ? 1 : 0
434
- this.colorArray = this.gradientColorArray()
435
- let update = () => {
436
- let now = new Date()
437
- let elapsed = now - lastUpdate
438
- that.m_percent += elapsed * changePerms
439
- lastUpdate = now
440
- // check if we've made it to our stopping point
441
- if ((increasing && that.m_percent < that.m_target_percent) ||
442
- (!increasing && that.m_percent > that.m_target_percent)) {
443
- that.render()
444
- that.requestAnimFrame(update)
445
- } else {
446
- that.m_percent = that.m_target_percent
447
- that.render()
448
- }
449
- }
450
- that.requestAnimFrame(update)
451
- } else {
452
- that.m_percent = percent
453
- that.render()
454
- }
455
- }
456
- requestAnimFrame (f) {
457
- let anim = window.requestAnimationFrame ||
458
- window.webkitRequestAnimationFrame ||
459
- window.mozRequestAnimationFrame ||
460
- window.oRequestAnimationFrame ||
461
- window.msRequestAnimationFrame ||
462
- function (callback, element) {
463
- window.setTimeout(function () {
464
- callback(new Date())
465
- }, 1000 / 60)
466
- }
467
- anim(f)
468
- }
469
-
470
- mergeOption () {}
471
- }
1
+ /**
2
+ * @Description: 这个类封装了仪表盘
3
+ * @Author: chengcheng
4
+ * @Date: Create in 10:26 2019/04/03
5
+ * @Modified By:
6
+ */
7
+ import MakeGradientColot from './MakeGradientColor'
8
+ const PIDEG = Math.PI / 180
9
+ export default class DashBoard {
10
+ constructor (id, options) {
11
+ this.m_id = id // id 用来获取dom节点
12
+ this.m_options = options // 设置的选项
13
+ this.m_canvas = null // canvas
14
+ this.m_save_canvas = null // 用来保存状态的canvas 暂时还不理解
15
+ this.m_context = null
16
+ this.m_save_context = null // canvas绘制环境
17
+ this.m_percent = 0
18
+ this.m_target_percent = 0
19
+ this.m_tickmask_offset = 0
20
+ this.m_halfCanvasWidth = 0
21
+ this.m_halfCanvasHeight = 0
22
+ this.m_rotation_deg = 0
23
+
24
+ this.default_option = {
25
+ style: 'bar',
26
+ bar_radius: 200,
27
+ bar_bg_w: 20,
28
+ bar_w: 18,
29
+ bar_bg_color: '#193b43',
30
+ bar_bg_ring_color: '#193b43',
31
+ bar_start_color: '#42daff',
32
+ bar_stop_color: 'yellow',
33
+ title: '交通强度',
34
+ title_font_color: '#FFFFFF',
35
+ title_font_size: 40,
36
+ title_show: true,
37
+ title_font_family: 'HanHei SC, PingFang SC, Helvetica Neue Thin, Helvetica, STHeitiSC-Light, Arial, sans-serif',
38
+ sides_font_color: '#FFFFFF',
39
+ sides_font_size: 30,
40
+ sides_show: true,
41
+ sides_font_family: 'HanHei SC, PingFang SC, Helvetica Neue Thin, Helvetica, STHeitiSC-Light, Arial, sans-serif',
42
+ tick_length: 12,
43
+ large_tick_length: 22,
44
+ tick_thickness: 1,
45
+ tick_group_length: 9,
46
+ ticks_groups_begin: 0,
47
+ total_degrees: 200,
48
+ total_tick: 101,
49
+ tick_color: '#555962',
50
+ tick_on_color: '#527d98',
51
+ on_color_gradient: null,
52
+ bg_color: 'rgba(255, 255, 255, 0)',
53
+ gauge_scale: 1,
54
+ animation_duration: 2000,
55
+ show_num: true,
56
+ show_center_num: true,
57
+ center_font_size: 100,
58
+ center_font_color: '#FFFFFF',
59
+ cur_score_circle_color: '#555962',
60
+ center_offset: {
61
+ x: 0,
62
+ y: -30
63
+ },
64
+ center_num_font_family: 'HanHei SC, PingFang SC, Helvetica Neue Thin, Helvetica, STHeitiSC-Light, Arial, sans-serif',
65
+ num_gap: 1,
66
+ num_begin: 0,
67
+ num_font_size: 18,
68
+ tickmask_offset: 0,
69
+ num_font_family: 'HanHei SC, PingFang SC, Helvetica Neue Thin, Helvetica, STHeitiSC-Light, Arial, sans-serif',
70
+ circle_radius: 5,
71
+ circle_offset: 0,
72
+ center_text_unit: '%',
73
+ center_text_offset: {
74
+ x: 16,
75
+ y: 8 - 30
76
+ }
77
+ } // 默认选项
78
+ this.m_default_option = {}
79
+ Object.assign(this.m_default_option, this.default_option, options)
80
+ // 初始化绘制环境
81
+ this.InitCanvas()
82
+ }
83
+
84
+ /**
85
+ * 初始化绘图环境
86
+ */
87
+ InitCanvas () {
88
+ this.m_canvas = document.getElementById(this.m_id)
89
+ this.m_save_canvas = document.createElement('canvas')
90
+
91
+ let canvas = this.m_canvas
92
+
93
+ this.m_save_canvas.width = canvas.width
94
+ this.m_save_canvas.height = canvas.height
95
+ this.delatLength = this.m_default_option.large_tick_length - this.m_default_option.tick_length
96
+
97
+ this.m_save_context = this.m_save_canvas.getContext('2d')
98
+ this.m_context = canvas.getContext('2d')
99
+ // this.m_save_context.scale(4, 4)
100
+ this.m_percent = this.m_default_option.percent || 0
101
+ this.m_target_percent = this.m_percent
102
+ this.m_tickmask_offset = this.getTickMarkOffset()
103
+ this.m_halfCanvasHeight = this.m_save_canvas.height / 2
104
+ this.m_halfCanvasWidth = this.m_save_canvas.width / 2
105
+ this.m_rotation_deg = this.getRotationDeg()
106
+ }
107
+
108
+ getTickMarkOffset () {
109
+ return this.m_default_option.tickmask_offset + this.m_default_option.circle_radius * 2 + this.m_default_option.circle_offset
110
+ }
111
+ getRotationDeg () {
112
+ return this.m_default_option.total_degrees / (this.m_default_option.total_tick - 1) * PIDEG
113
+ }
114
+ /**
115
+ * 准备舞台, 绘制背景和中间数值
116
+ */
117
+ prepareStage () {
118
+ let saveCanvas = this.m_save_canvas
119
+ let saveContext = this.m_save_context
120
+ // 清除canvas画布
121
+ saveContext.clearRect(0, 0, saveCanvas.width, saveCanvas.height)
122
+ // 设置背景
123
+ this.applyBg()
124
+ // 设置旋转中心
125
+ saveContext.translate(this.m_halfCanvasWidth,
126
+ this.m_halfCanvasHeight - this.m_default_option.tick_thickness / 2)
127
+ // 设置缩放比例
128
+ saveContext.scale(this.m_default_option.gauge_scale,
129
+ this.m_default_option.gauge_scale)
130
+ // 绘制内容
131
+ this.drawContent()
132
+ }
133
+
134
+ /**
135
+ * 绘制弧度
136
+ * @param {*} r 半径
137
+ * @param {*} start 开始角度
138
+ * @param {*} end 结束角度
139
+ * @param {*} w 弧宽度
140
+ * @param {*} colorStyle 圆环颜色 支持渐变
141
+ */
142
+ drawDonuts (r, start, end, w, colorStyle) {
143
+ let saveContext = this.m_save_context
144
+ saveContext.lineWidth = w
145
+ saveContext.lineCap = 'round'
146
+ saveContext.beginPath()
147
+ saveContext.arc(0, 0, r, start, end, false)
148
+ saveContext.strokeStyle = colorStyle// '#DC143C'
149
+ saveContext.stroke()
150
+ saveContext.closePath()
151
+ }
152
+
153
+ // 绘制中间数字
154
+ drawContent () {
155
+ let saveCanvas = this.m_save_canvas
156
+ let saveContext = this.m_save_context
157
+
158
+ if (this.m_default_option.show_center_num) {
159
+ let fillColor = this.m_default_option.center_font_color
160
+ ? this.m_default_option.center_font_color.split('-') : [this.m_default_option.tick_on_color]
161
+ let centerText = Math.floor(
162
+ this.m_percent * ((this.m_default_option.total_tick - 1) *
163
+ this.m_default_option.num_gap +
164
+ this.m_default_option.num_begin) / 100)
165
+
166
+ var gaugeWidth = saveCanvas.width / 2 -
167
+ this.m_default_option.circle_radius * 2 -
168
+ this.m_default_option.circle_offset - this.m_default_option.large_tick_length - this.m_default_option.tickmask_offset
169
+
170
+ saveContext.save()
171
+ if (fillColor.length === 2) {
172
+ var gradient = saveContext.createLinearGradient(-gaugeWidth, 0, gaugeWidth, 0)
173
+ gradient.addColorStop('0', fillColor[0])
174
+ gradient.addColorStop('0.7', fillColor[1])
175
+ gradient.addColorStop('1', fillColor[1])
176
+ saveContext.fillStyle = gradient
177
+ } else {
178
+ saveContext.fillStyle = fillColor[0]
179
+ }
180
+ saveContext.font = this.m_default_option.center_font_size + 'px ' + this.m_default_option.center_num_font_family
181
+ saveContext.textAlign = 'center'
182
+ saveContext.textBaseline = 'middle'
183
+ var centerTextWidth = Math.floor(saveContext.measureText(centerText).width)
184
+ saveContext.fillText(centerText, this.m_default_option.center_offset.x, this.m_default_option.center_offset.y)
185
+ saveContext.font = '30px ' + this.m_default_option.num_font_family
186
+ saveContext.textAlign = 'center'
187
+ saveContext.textBaseline = 'middle'
188
+ saveContext.fillText(this.m_default_option.center_text_unit, centerTextWidth / 2 +
189
+ this.m_default_option.center_text_offset.x, this.m_default_option.center_text_offset.y)
190
+ }
191
+ let x, y, titleY
192
+ let totalDegrees = this.m_default_option.total_degrees
193
+ if (totalDegrees < 180) {
194
+ x = this.m_default_option.bar_radius * Math.sin(totalDegrees / 2 * PIDEG)
195
+ y = this.m_default_option.bar_radius * Math.cos(totalDegrees / 2 * PIDEG)
196
+ y = -y
197
+ titleY = 0
198
+ } else if (totalDegrees === 180) {
199
+ x = this.m_default_option.bar_radius
200
+ y = 0
201
+ titleY = 0
202
+ } else {
203
+ x = this.m_default_option.bar_radius * Math.cos((totalDegrees - 180) / 2 * PIDEG)
204
+ y = this.m_default_option.bar_radius * Math.sin((totalDegrees - 180) / 2 * PIDEG)
205
+ titleY = y
206
+ }
207
+ if (this.m_default_option.sides_show) {
208
+ // 绘制最大值和最小值
209
+ saveContext.font = this.m_default_option.sides_font_size + 'px ' + this.m_default_option.sides_font_family
210
+ saveContext.fillStyle = this.m_default_option.sides_font_color
211
+ saveContext.fillText(0, -x, y + 30)
212
+ saveContext.fillText(this.m_default_option.total_tick, x, y + 30)
213
+ }
214
+ if (this.m_default_option.title_show) {
215
+ saveContext.font = this.m_default_option.title_font_size + 'px ' + this.m_default_option.title_font_family
216
+ saveContext.fillStyle = this.m_default_option.title_font_color
217
+ saveContext.fillText(this.m_default_option.title, 0, titleY + 30)
218
+ }
219
+ saveContext.restore()
220
+ }
221
+ /**
222
+ * 绘制刻度帧数, 刻度长度 和 第几个数字
223
+ * @param {*} tickLength
224
+ * @param {*} tickIndex
225
+ */
226
+ drawGaugeNum (tickLength, tickIndex) {
227
+ let saveContext = this.m_save_context
228
+ let text = this.m_default_option.num_begin + this.m_default_option.num_gap * tickIndex - 1
229
+ // saveContext.measureText(text)
230
+ saveContext.save()
231
+ saveContext.translate(-1 * this.m_halfCanvasWidth +
232
+ tickLength + this.m_default_option.circle_radius * 2 +
233
+ this.m_default_option.circle_offset +
234
+ this.m_default_option.num_font_size / 2, -this.m_default_option.tick_thickness / 2)
235
+ saveContext.rotate(-90 * PIDEG)
236
+ saveContext.font = this.m_default_option.num_font_size + 'px ' + this.m_default_option.num_font_family
237
+ saveContext.textAlign = 'center'
238
+ saveContext.textBaseline = 'middle'
239
+ saveContext.fillText(text, 0, this.m_default_option.tickmask_offset)
240
+ saveContext.restore()
241
+ }
242
+ /**
243
+ * 应用背景
244
+ */
245
+ applyBg () {
246
+ let saveCanvas = this.m_save_canvas
247
+ let saveContext = this.m_save_context
248
+ saveContext.save()
249
+ saveContext.fillStyle = this.m_default_option.bg_color // 填充绘画的颜色
250
+ saveContext.fillRect(0, 0, saveCanvas.width, saveCanvas.height) // 绘制“被填充”的矩形
251
+ saveContext.restore() // 返回之前保存过的路径状态和属性
252
+ }
253
+ /**
254
+ * 绘制提示圆点
255
+ * @param {*} beginX
256
+ * @param {*} beginY
257
+ */
258
+ drawScoreTipCircle (beginX, beginY) {
259
+ let saveContext = this.m_save_context
260
+ saveContext.save()
261
+ saveContext.fillStyle = this.m_percent > 0.01
262
+ ? this.m_default_option.cur_score_circle_color : this.m_default_option.tick_color
263
+ saveContext.rotate(this.m_percent * this.m_default_option.total_degrees / 100 * PIDEG)
264
+ saveContext.beginPath()
265
+ /**
266
+ * arc方法用来绘制圆
267
+ * 参数1 圆心的x坐标
268
+ * 参数2 圆心的y坐标
269
+ * 参数3 圆的半径
270
+ * 参数4 起始角 弧度单位
271
+ * 参数5 结束角 弧度
272
+ * 参数6 False = 顺时针 True = 逆时针
273
+ */
274
+ saveContext.arc(-beginX, -beginY, this.m_default_option.circle_radius, 0, Math.PI * 2, true)
275
+ saveContext.closePath()
276
+ saveContext.fill()
277
+ saveContext.restore()
278
+ }
279
+ /**
280
+ * 样式一 bar样式
281
+ */
282
+ drawProgressBar () {
283
+ let dutyCycle = this.m_default_option.total_degrees
284
+ let startAngle = (270 - dutyCycle / 2) * PIDEG
285
+ let endAngle = startAngle + dutyCycle * PIDEG
286
+
287
+ // bar_bg_color: '#193b43',
288
+ let baroffset = 3
289
+ this.drawDonuts(this.m_default_option.bar_radius,
290
+ startAngle, endAngle,
291
+ this.m_default_option.bar_bg_w, this.m_default_option.bar_bg_color)
292
+ this.drawDonuts(this.m_default_option.bar_radius + this.m_default_option.bar_bg_w + baroffset,
293
+ startAngle, endAngle,
294
+ 3, this.m_default_option.bar_bg_ring_color)
295
+
296
+ if (this.m_percent === 0) return
297
+ let curNum = this.m_percent
298
+ if (curNum >= this.m_default_option.total_tick) curNum = this.m_default_option.total_tick
299
+ let curendAngle = startAngle + dutyCycle * curNum / 100 * PIDEG
300
+
301
+ let saveContext = this.m_save_context
302
+ let ring = saveContext.createLinearGradient(-205, 0, 205, 0)
303
+ ring.addColorStop('0', this.m_default_option.bar_start_color)
304
+ ring.addColorStop('1.0', this.m_default_option.bar_stop_color)
305
+ this.drawDonuts(this.m_default_option.bar_radius,
306
+ startAngle, curendAngle, this.m_default_option.bar_w, ring)
307
+ }
308
+
309
+ /**
310
+ * 绘制刻度盘的样式
311
+ */
312
+ drawTickType () {
313
+ let saveContext = this.m_save_context
314
+ let startingDeg = (180 - this.m_default_option.total_degrees) / 2 // 计算开始旋转度数
315
+ saveContext.rotate(startingDeg * PIDEG) // 旋转到初始位置
316
+ // 绘制提示原点
317
+ this.drawScoreTipCircle(this.m_halfCanvasWidth - this.m_default_option.circle_radius,
318
+ this.m_default_option.circle_radius)
319
+
320
+ let numTicks = this.m_default_option.total_tick // 总刻度
321
+ for (let i = 1; i <= numTicks; i++) {
322
+ // should this tick be on or off?
323
+ let isOn = (((i - 1) / numTicks) * 100 < this.m_percent)
324
+
325
+ // 判断是否最大
326
+ let isLargeTick = this.isLargeTick(i)
327
+ // let rectScale = isLargeTick ? this.large_tick_scale : 1
328
+ let tickLength = isLargeTick ? this.m_default_option.large_tick_length : this.m_default_option.tick_length
329
+
330
+ // 获取刻度颜色
331
+ var color = this.getTickColor(isOn, i)
332
+ saveContext.fillStyle = color
333
+ if (isLargeTick) {
334
+ saveContext.fillRect(-1 * this.m_halfCanvasWidth + this.m_default_option.circle_radius * 2 +
335
+ this.m_default_option.circle_offset,
336
+ -this.m_default_option.tick_thickness / 2,
337
+ tickLength, this.m_default_option.tick_thickness)
338
+ if (this.m_default_option.show_num) {
339
+ this.drawGaugeNum(tickLength, i)
340
+ }
341
+ } else {
342
+ saveContext.fillRect(-1 * this.m_halfCanvasWidth +
343
+ this.m_default_option.circle_radius * 2 + this.m_default_option.circle_offset +
344
+ this.delatLength,
345
+ -this.m_default_option.tick_thickness / 2,
346
+ tickLength, this.m_default_option.tick_thickness)
347
+ }
348
+ // rotate for next tick to be placed
349
+ saveContext.rotate(this.m_rotation_deg)
350
+ }
351
+ }
352
+
353
+ /**
354
+ * @param {*} currentNum
355
+ * 判断当前最大刻度
356
+ */
357
+ isLargeTick (currentNum) {
358
+ return (currentNum + this.m_default_option.ticks_groups_begin - 1) % (this.m_default_option.tick_group_length + 1) === 0
359
+ }
360
+
361
+ gradientColorArray = function () {
362
+ let colorArray = []
363
+ if (!this.m_default_option.on_color_gradient || !this.m_target_percent) {
364
+ return
365
+ }
366
+ for (let i = 0; i < this.m_default_option.on_color_gradient.length - 1; i++) {
367
+ let next = this.m_default_option.on_color_gradient[i + 1]
368
+ let cur = this.m_default_option.on_color_gradient[i]
369
+ let colorStep = (next.percent - cur.percent) / 100 * this.total_tick
370
+ colorArray = colorArray.concat(MakeGradientColot(cur.color, next.color, colorStep))
371
+ }
372
+ return colorArray
373
+ }
374
+
375
+ /**
376
+ * 获取刻度颜色
377
+ * @param {*} isOn
378
+ * @param {*} index
379
+ */
380
+ getTickColor (isOn, index) {
381
+ let indexTemp = index < 1 ? 1 : index
382
+ if (isOn) {
383
+ if (this.colorArray && this.colorArray.length > 0) {
384
+ return this.colorArray[indexTemp - 1]
385
+ } else {
386
+ return this.m_default_option.tick_on_color
387
+ }
388
+ } else {
389
+ return this.m_default_option.tick_color
390
+ }
391
+ }
392
+ /**
393
+ * 进行渲染绘制
394
+ * @param percent
395
+ */
396
+ render (percent) {
397
+ if (percent !== undefined) {
398
+ this.m_percent = percent
399
+ }
400
+
401
+ // let saveCanvas = this.m_save_canvas
402
+ let saveContext = this.m_save_context
403
+ saveContext.save() // 用来保存Canvas的状态. save之后,可以调用Canvas的平移、放缩、旋转、错切、裁剪等操作
404
+
405
+ // 绘制基本舞台 包括当前分值
406
+ this.prepareStage()
407
+ switch (this.m_default_option.style) {
408
+ case 'bar': this.drawProgressBar(); break
409
+ case 'tick': this.drawTickType(); break
410
+ default: break
411
+ }
412
+ this.m_context.clearRect(0, 0, this.m_canvas.width, this.m_canvas.height)
413
+ this.m_context.drawImage(this.m_save_canvas, 0, 0)
414
+ saveContext.restore()
415
+ }
416
+
417
+ /**
418
+ * 更新百分比以及实时显示信息
419
+ */
420
+ updatedPercent (percent, options = {}) {
421
+ if (percent - 0.1 < 0) {
422
+ return
423
+ }
424
+ let that = this
425
+ this.m_target_percent = percent
426
+ options = options || {}
427
+ let duration = ('animation_duration' in options) ? options.animation_duration : that.m_default_option.animation_duration
428
+ if (duration) {
429
+ let lastUpdate = new Date()
430
+ let start = this.m_percent
431
+ let end = this.m_target_percent
432
+ let changePerms = (end - start) / duration
433
+ var increasing = changePerms > 0 ? 1 : 0
434
+ this.colorArray = this.gradientColorArray()
435
+ let update = () => {
436
+ let now = new Date()
437
+ let elapsed = now - lastUpdate
438
+ that.m_percent += elapsed * changePerms
439
+ lastUpdate = now
440
+ // check if we've made it to our stopping point
441
+ if ((increasing && that.m_percent < that.m_target_percent) ||
442
+ (!increasing && that.m_percent > that.m_target_percent)) {
443
+ that.render()
444
+ that.requestAnimFrame(update)
445
+ } else {
446
+ that.m_percent = that.m_target_percent
447
+ that.render()
448
+ }
449
+ }
450
+ that.requestAnimFrame(update)
451
+ } else {
452
+ that.m_percent = percent
453
+ that.render()
454
+ }
455
+ }
456
+ requestAnimFrame (f) {
457
+ let anim = window.requestAnimationFrame ||
458
+ window.webkitRequestAnimationFrame ||
459
+ window.mozRequestAnimationFrame ||
460
+ window.oRequestAnimationFrame ||
461
+ window.msRequestAnimationFrame ||
462
+ function (callback, element) {
463
+ window.setTimeout(function () {
464
+ callback(new Date())
465
+ }, 1000 / 60)
466
+ }
467
+ anim(f)
468
+ }
469
+
470
+ mergeOption () {}
471
+ }