vislite 1.3.0 → 1.4.0
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/AUTHORS.txt +6 -6
- package/CHANGELOG +12 -5
- package/LICENSE +20 -20
- package/README.md +284 -284
- package/lib/BarLayout/index.es.d.ts +3 -0
- package/lib/BarLayout/index.es.js +467 -0
- package/lib/BarLayout/index.es.min.d.ts +3 -0
- package/lib/BarLayout/index.es.min.js +10 -0
- package/lib/Buffer/index.es.js +1 -1
- package/lib/Buffer/index.es.min.js +1 -1
- package/lib/Canvas/index.es.js +2 -2
- package/lib/Canvas/index.es.min.js +1 -1
- package/lib/Cardinal/index.es.js +1 -1
- package/lib/Cardinal/index.es.min.js +1 -1
- package/lib/Eoap/index.es.js +1 -1
- package/lib/Eoap/index.es.min.js +1 -1
- package/lib/Hermite/index.es.js +1 -1
- package/lib/Hermite/index.es.min.js +1 -1
- package/lib/MapCoordinate/index.es.js +1 -1
- package/lib/MapCoordinate/index.es.min.js +1 -1
- package/lib/Matrix4/index.es.js +1 -1
- package/lib/Matrix4/index.es.min.js +1 -1
- package/lib/Mercator/index.es.js +1 -1
- package/lib/Mercator/index.es.min.js +1 -1
- package/lib/PieLayout/index.es.d.ts +3 -0
- package/lib/PieLayout/index.es.js +234 -0
- package/lib/PieLayout/index.es.min.d.ts +3 -0
- package/lib/PieLayout/index.es.min.js +9 -0
- package/lib/RawCanvas/index.es.js +2 -2
- package/lib/RawCanvas/index.es.min.js +1 -1
- package/lib/SVG/index.es.js +29 -6
- package/lib/SVG/index.es.min.js +2 -2
- package/lib/Shader/index.es.js +1 -1
- package/lib/Shader/index.es.min.js +1 -1
- package/lib/Texture/index.es.js +1 -1
- package/lib/Texture/index.es.min.js +1 -1
- package/lib/TreeLayout/index.es.js +109 -102
- package/lib/TreeLayout/index.es.min.js +6 -2
- package/lib/animation/index.es.js +114 -103
- package/lib/animation/index.es.min.js +6 -2
- package/lib/assemble/index.es.js +1 -1
- package/lib/assemble/index.es.min.js +1 -1
- package/lib/getLoopColors/index.es.js +1 -1
- package/lib/getLoopColors/index.es.min.js +1 -1
- package/lib/getWebGLContext/index.es.js +1 -1
- package/lib/getWebGLContext/index.es.min.js +1 -1
- package/lib/index.umd.js +510 -158
- package/lib/index.umd.min.js +12 -2
- package/lib/initOption/index.es.js +1 -1
- package/lib/initOption/index.es.min.js +1 -1
- package/lib/mergeOption/index.es.js +1 -1
- package/lib/mergeOption/index.es.min.js +1 -1
- package/lib/move/index.es.js +1 -1
- package/lib/move/index.es.min.js +1 -1
- package/lib/rotate/index.es.js +1 -1
- package/lib/rotate/index.es.min.js +1 -1
- package/lib/ruler/index.es.js +1 -1
- package/lib/ruler/index.es.min.js +1 -1
- package/lib/scale/index.es.js +1 -1
- package/lib/scale/index.es.min.js +1 -1
- package/lib/throttle/index.es.js +55 -50
- package/lib/throttle/index.es.min.js +5 -1
- package/minialipay/ui-canvas/drawImage.js +35 -35
- package/minialipay/ui-canvas/index.acss +4 -4
- package/minialipay/ui-canvas/index.axml +3 -3
- package/minialipay/ui-canvas/index.d.ts +1 -1
- package/minialipay/ui-canvas/index.js +100 -100
- package/minialipay/ui-canvas/index.json +6 -6
- package/miniprogram/ui-canvas/drawImage.js +35 -35
- package/miniprogram/ui-canvas/index.js +117 -117
- package/miniprogram/ui-canvas/index.json +4 -4
- package/miniprogram/ui-canvas/index.wxml +4 -4
- package/miniprogram/ui-canvas/index.wxss +5 -5
- package/package/BarLayout/index.ts +3 -0
- package/package/Buffer/index.ts +2 -2
- package/package/Canvas/index.ts +2 -2
- package/package/Cardinal/index.ts +2 -2
- package/package/Eoap/index.ts +2 -2
- package/package/Hermite/index.ts +2 -2
- package/package/MapCoordinate/index.ts +2 -2
- package/package/Matrix4/index.ts +2 -2
- package/package/Mercator/index.ts +2 -2
- package/package/PieLayout/index.ts +3 -0
- package/package/RawCanvas/index.ts +2 -2
- package/package/SVG/index.ts +2 -2
- package/package/Shader/index.ts +2 -2
- package/package/Texture/index.ts +2 -2
- package/package/TreeLayout/index.ts +2 -2
- package/package/animation/index.ts +5 -2
- package/package/assemble/index.ts +2 -2
- package/package/getLoopColors/index.ts +2 -2
- package/package/getWebGLContext/index.ts +40 -40
- package/package/index.ts +4 -0
- package/package/initOption/index.ts +2 -2
- package/package/mergeOption/index.ts +2 -2
- package/package/move/index.ts +2 -2
- package/package/rotate/index.ts +2 -2
- package/package/ruler/index.ts +2 -2
- package/package/scale/index.ts +2 -2
- package/package/throttle/index.ts +1 -1
- package/package.json +3 -3
- package/src/Canvas.ts +84 -84
- package/src/Eoap.ts +66 -66
- package/src/Matrix4/index.ts +84 -84
- package/src/Matrix4/move.ts +12 -12
- package/src/Matrix4/rotate.ts +15 -15
- package/src/Matrix4/scale.ts +11 -11
- package/src/Matrix4/transform.ts +64 -64
- package/src/Mercator.ts +27 -27
- package/src/SVG.ts +31 -0
- package/src/common/assemble.ts +22 -22
- package/src/common/canvas/arc.ts +51 -51
- package/src/common/canvas/config.ts +176 -176
- package/src/common/canvas/default.ts +64 -64
- package/src/common/canvas/gradient.ts +1 -1
- package/src/common/canvas/index.ts +188 -188
- package/src/common/canvas/painter.ts +443 -443
- package/src/common/canvas/texts.ts +18 -18
- package/src/common/map/getBoundary.ts +15 -15
- package/src/common/map/tool.ts +29 -29
- package/src/common/option.ts +29 -29
- package/src/common/setStyle.ts +5 -5
- package/src/common/svg/config.ts +213 -213
- package/src/common/svg/default.ts +2 -2
- package/src/common/svg/gradient.ts +2 -2
- package/src/common/svg/index.ts +1 -1
- package/src/common/svg/tool.ts +51 -51
- package/src/common/tree/index.ts +25 -25
- package/src/common/tree/toInnerTree.ts +61 -61
- package/src/common/tree/toPlainTree.ts +3 -0
- package/src/common/type.ts +26 -26
- package/src/common/webgl/buffer.ts +79 -79
- package/src/common/webgl/getWebGLContext.ts +45 -45
- package/src/common/webgl/shader.ts +75 -75
- package/src/common/webgl/texture.ts +1 -0
- package/src/coordinate/MapCoordinate.ts +80 -80
- package/src/getLoopColors.ts +42 -42
- package/src/interpolation/Cardinal.ts +110 -110
- package/src/interpolation/Hermite.ts +65 -65
- package/src/layout/BarLayout.ts +249 -0
- package/src/layout/PieLayout.ts +142 -0
- package/src/layout/TreeLayout.ts +4 -1
- package/src/move.ts +7 -7
- package/src/rotate.ts +7 -7
- package/src/ruler.ts +209 -209
- package/src/scale.ts +6 -6
- package/types/Bar.d.ts +92 -0
- package/types/BarConfig.d.ts +5 -0
- package/types/BarLayout.d.ts +49 -0
- package/types/BarOption.d.ts +32 -0
- package/types/Buffer.d.ts +23 -23
- package/types/Canvas.d.ts +352 -352
- package/types/CanvasConfig.d.ts +88 -88
- package/types/CanvasOption.d.ts +8 -8
- package/types/CanvasOpts.d.ts +9 -9
- package/types/Cardinal.d.ts +13 -13
- package/types/Gradient.d.ts +14 -14
- package/types/Hermite.d.ts +18 -18
- package/types/Map.d.ts +9 -9
- package/types/MapConfig.d.ts +27 -27
- package/types/MapCoordinate.d.ts +22 -22
- package/types/Matrix4.d.ts +47 -47
- package/types/Pie.d.ts +74 -0
- package/types/PieConfig.d.ts +27 -0
- package/types/PieLayout.d.ts +41 -0
- package/types/PieOption.d.ts +22 -0
- package/types/SVG.d.ts +4 -0
- package/types/SVGConfig.d.ts +71 -71
- package/types/Shader.d.ts +16 -16
- package/types/Texture.d.ts +16 -16
- package/types/Tree.d.ts +74 -74
- package/types/TreeConfig.d.ts +36 -36
- package/types/TreeLayout.d.ts +59 -59
- package/types/TreeOption.d.ts +48 -48
- package/types/animation.d.ts +7 -1
- package/types/assemble.d.ts +5 -5
- package/types/getLoopColors.d.ts +5 -5
- package/types/getWebGLContext.d.ts +7 -7
- package/types/index.d.ts +16 -0
- package/types/move.d.ts +5 -5
- package/types/option.d.ts +12 -12
- package/types/painterConfig.d.ts +4 -4
- package/types/rotate.d.ts +5 -5
- package/types/ruler.d.ts +10 -10
- package/types/scale.d.ts +5 -5
- package/types/throttle.d.ts +1 -1
- package/types/throttleOption.d.ts +1 -1
- package/types/ui-canvas.d.ts +4 -4
- package/types/uni-canvas.d.ts +3 -3
- package/uni-app/drawImage.js +19 -19
- package/uni-app/ui-canvas.vue +284 -284
package/src/ruler.ts
CHANGED
|
@@ -1,210 +1,210 @@
|
|
|
1
|
-
// 刻度尺刻度求解
|
|
2
|
-
|
|
3
|
-
import type { rulerOptionType } from '../types/ruler'
|
|
4
|
-
|
|
5
|
-
// 需要注意的是,实际的间距个数可能是 num-1 或 num 或 num+1 或 1
|
|
6
|
-
export default function (maxValue: number, minValue: number, num: number, option?: rulerOptionType) {
|
|
7
|
-
|
|
8
|
-
// 如果最大值最小值反了
|
|
9
|
-
if (maxValue < minValue) {
|
|
10
|
-
const temp = minValue
|
|
11
|
-
minValue = maxValue
|
|
12
|
-
maxValue = temp
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
// 如果相等
|
|
16
|
-
else if (maxValue == minValue) {
|
|
17
|
-
return [maxValue]
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// 为了变成 -100 ~ 100 需要放大或者缩小的倍数
|
|
21
|
-
const times100 =
|
|
22
|
-
|
|
23
|
-
(function (_value) {
|
|
24
|
-
|
|
25
|
-
// 先确定基调,是放大还是缩小
|
|
26
|
-
const _times100_base = (_value < 100 && _value > -100) ? 10 : 0.1
|
|
27
|
-
|
|
28
|
-
// 记录当前缩放倍数
|
|
29
|
-
let _times100 = -1, _tiemsValue = _value
|
|
30
|
-
|
|
31
|
-
while (_times100_base == 10 ?
|
|
32
|
-
// 如果是放大,超过 -100 ~ 100 就应该停止
|
|
33
|
-
(_tiemsValue >= -100 && _tiemsValue <= 100)
|
|
34
|
-
:
|
|
35
|
-
// 如果是缩小,进入 -100 ~ 100 就应该停止
|
|
36
|
-
(_tiemsValue <= -100 || _tiemsValue >= 100)
|
|
37
|
-
) {
|
|
38
|
-
|
|
39
|
-
_times100 += 1
|
|
40
|
-
_tiemsValue *= _times100_base
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
if (_times100_base == 10) {
|
|
45
|
-
return Math.pow(10, _times100)
|
|
46
|
-
} else {
|
|
47
|
-
|
|
48
|
-
// 解决类似 0.1 * 0.1 = 0.010000000000000002 浮点运算不准确问题
|
|
49
|
-
let temp = "0."
|
|
50
|
-
for (let i = 1; i < _times100; i++) {
|
|
51
|
-
temp += "0";
|
|
52
|
-
}
|
|
53
|
-
return +(temp + "1")
|
|
54
|
-
}
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
// 根据差值来缩放
|
|
58
|
-
(maxValue - minValue)
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
// 求解出 -100 ~ 100 的最佳间距值 后直接转换原来的倍数
|
|
62
|
-
const distance100_oral = Math.ceil((maxValue - minValue) * times100 / num)
|
|
63
|
-
|
|
64
|
-
const getResult = (changValue: number) => {
|
|
65
|
-
// 校对一下
|
|
66
|
-
const distance100 = {
|
|
67
|
-
3: 2,
|
|
68
|
-
4: 5,
|
|
69
|
-
6: 5,
|
|
70
|
-
7: 5,
|
|
71
|
-
8: 10,
|
|
72
|
-
9: 10,
|
|
73
|
-
11: 10,
|
|
74
|
-
12: 10,
|
|
75
|
-
13: 15,
|
|
76
|
-
14: 15,
|
|
77
|
-
16: 15,
|
|
78
|
-
17: 15,
|
|
79
|
-
18: 20,
|
|
80
|
-
19: 20,
|
|
81
|
-
21: 20,
|
|
82
|
-
22: 20,
|
|
83
|
-
23: 25,
|
|
84
|
-
24: 25,
|
|
85
|
-
26: 25,
|
|
86
|
-
27: 25
|
|
87
|
-
}[distance100_oral + changValue] || (distance100_oral + changValue)
|
|
88
|
-
|
|
89
|
-
const distance = distance100 / times100
|
|
90
|
-
|
|
91
|
-
// 最小值,也就是起点
|
|
92
|
-
const begin = Math.floor(minValue / distance) * distance
|
|
93
|
-
|
|
94
|
-
const rulerArray = []
|
|
95
|
-
// 获取最终的刻度尺数组
|
|
96
|
-
rulerArray.push(begin)
|
|
97
|
-
for (let index = 1; rulerArray[rulerArray.length - 1] < maxValue; index++) {
|
|
98
|
-
rulerArray.push(begin + distance * index)
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
return rulerArray
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
let rulerArray = getResult(0)
|
|
105
|
-
|
|
106
|
-
const balanceMax = () => {
|
|
107
|
-
const rulerArray_temp = []
|
|
108
|
-
|
|
109
|
-
const changeDist = rulerArray[rulerArray.length - 1] - (option?.max as number)
|
|
110
|
-
for (let index = 0; index < rulerArray.length; index++) {
|
|
111
|
-
if (index + 1 < rulerArray.length && rulerArray[index + 1] - changeDist < minValue) {
|
|
112
|
-
// 多余的
|
|
113
|
-
} else {
|
|
114
|
-
rulerArray_temp.push(rulerArray[index] - changeDist)
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
return rulerArray_temp
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
const balanceMin = () => {
|
|
122
|
-
const rulerArray_temp = []
|
|
123
|
-
|
|
124
|
-
const changeDist = rulerArray[0] - (option?.min as number)
|
|
125
|
-
for (let index = 0; index < rulerArray.length; index++) {
|
|
126
|
-
rulerArray_temp[index] = rulerArray[index] - changeDist
|
|
127
|
-
if (maxValue <= rulerArray_temp[index]) break
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
return rulerArray_temp
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
if (option) {
|
|
134
|
-
|
|
135
|
-
// 上下界限制
|
|
136
|
-
if ('max' in option && 'min' in option && (option.max as number) >= maxValue && (option.min as number) <= minValue) {
|
|
137
|
-
|
|
138
|
-
const isAnswer = () => {
|
|
139
|
-
|
|
140
|
-
// 先判断原始的是否可行
|
|
141
|
-
if (rulerArray[0] >= (option.min as number) && rulerArray[rulerArray.length - 1] <= (option.max as number)) return true
|
|
142
|
-
|
|
143
|
-
// 再判断max调整是否可行
|
|
144
|
-
const rulerArray_max = balanceMax()
|
|
145
|
-
if (rulerArray_max[0] >= (option.min as number) && rulerArray_max[rulerArray_max.length - 1] <= (option.max as number)) {
|
|
146
|
-
rulerArray = rulerArray_max
|
|
147
|
-
return true
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
// 再判断max调整是否可行
|
|
151
|
-
const rulerArray_min = balanceMin()
|
|
152
|
-
if (rulerArray_min[0] >= (option.min as number) && rulerArray_min[rulerArray_max.length - 1] <= (option.max as number)) {
|
|
153
|
-
rulerArray = rulerArray_min
|
|
154
|
-
return true
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
if (isAnswer()) return rulerArray
|
|
160
|
-
|
|
161
|
-
for (let changValue = 1; changValue < 100; changValue++) {
|
|
162
|
-
|
|
163
|
-
rulerArray = getResult(changValue)
|
|
164
|
-
if (isAnswer()) return rulerArray
|
|
165
|
-
|
|
166
|
-
rulerArray = getResult(-changValue)
|
|
167
|
-
if (isAnswer()) return rulerArray
|
|
168
|
-
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
// 单界限制
|
|
173
|
-
if ('max' in option && (option.max as number) >= maxValue) {
|
|
174
|
-
|
|
175
|
-
// 上越界了
|
|
176
|
-
if ((option.max as number) < rulerArray[rulerArray.length - 1]) {
|
|
177
|
-
rulerArray = balanceMax()
|
|
178
|
-
}
|
|
179
|
-
} else if ('min' in option && (option.min as number) <= minValue) {
|
|
180
|
-
|
|
181
|
-
// 下越界了
|
|
182
|
-
if ((option.min as number) > rulerArray[0]) {
|
|
183
|
-
rulerArray = balanceMin()
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
// 对结果进行对齐
|
|
189
|
-
// 2023年11月15日 于南京
|
|
190
|
-
for (let index = 0; index < rulerArray.length; index++) {
|
|
191
|
-
let valStr = rulerArray[index] + ""
|
|
192
|
-
|
|
193
|
-
// 只有小数需要处理
|
|
194
|
-
if (/\./.test(valStr)) {
|
|
195
|
-
|
|
196
|
-
// 1.0999999999999999
|
|
197
|
-
if (/9{7,}$/.test(valStr)) {
|
|
198
|
-
valStr = valStr.replace(/9{7,}$/, '')
|
|
199
|
-
rulerArray[index] = +(valStr.substring(0, valStr.length - 1) + ((+valStr[valStr.length - 1]) + 1))
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
// 0.30000000000000004
|
|
203
|
-
else if (/0{7,}\d$/.test(valStr)) {
|
|
204
|
-
rulerArray[index] = +(valStr.replace(/0{7,}\d$/, ''))
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
return rulerArray
|
|
1
|
+
// 刻度尺刻度求解
|
|
2
|
+
|
|
3
|
+
import type { rulerOptionType } from '../types/ruler'
|
|
4
|
+
|
|
5
|
+
// 需要注意的是,实际的间距个数可能是 num-1 或 num 或 num+1 或 1
|
|
6
|
+
export default function (maxValue: number, minValue: number, num: number, option?: rulerOptionType) {
|
|
7
|
+
|
|
8
|
+
// 如果最大值最小值反了
|
|
9
|
+
if (maxValue < minValue) {
|
|
10
|
+
const temp = minValue
|
|
11
|
+
minValue = maxValue
|
|
12
|
+
maxValue = temp
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// 如果相等
|
|
16
|
+
else if (maxValue == minValue) {
|
|
17
|
+
return [maxValue]
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// 为了变成 -100 ~ 100 需要放大或者缩小的倍数
|
|
21
|
+
const times100 =
|
|
22
|
+
|
|
23
|
+
(function (_value) {
|
|
24
|
+
|
|
25
|
+
// 先确定基调,是放大还是缩小
|
|
26
|
+
const _times100_base = (_value < 100 && _value > -100) ? 10 : 0.1
|
|
27
|
+
|
|
28
|
+
// 记录当前缩放倍数
|
|
29
|
+
let _times100 = -1, _tiemsValue = _value
|
|
30
|
+
|
|
31
|
+
while (_times100_base == 10 ?
|
|
32
|
+
// 如果是放大,超过 -100 ~ 100 就应该停止
|
|
33
|
+
(_tiemsValue >= -100 && _tiemsValue <= 100)
|
|
34
|
+
:
|
|
35
|
+
// 如果是缩小,进入 -100 ~ 100 就应该停止
|
|
36
|
+
(_tiemsValue <= -100 || _tiemsValue >= 100)
|
|
37
|
+
) {
|
|
38
|
+
|
|
39
|
+
_times100 += 1
|
|
40
|
+
_tiemsValue *= _times100_base
|
|
41
|
+
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (_times100_base == 10) {
|
|
45
|
+
return Math.pow(10, _times100)
|
|
46
|
+
} else {
|
|
47
|
+
|
|
48
|
+
// 解决类似 0.1 * 0.1 = 0.010000000000000002 浮点运算不准确问题
|
|
49
|
+
let temp = "0."
|
|
50
|
+
for (let i = 1; i < _times100; i++) {
|
|
51
|
+
temp += "0";
|
|
52
|
+
}
|
|
53
|
+
return +(temp + "1")
|
|
54
|
+
}
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
// 根据差值来缩放
|
|
58
|
+
(maxValue - minValue)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
// 求解出 -100 ~ 100 的最佳间距值 后直接转换原来的倍数
|
|
62
|
+
const distance100_oral = Math.ceil((maxValue - minValue) * times100 / num)
|
|
63
|
+
|
|
64
|
+
const getResult = (changValue: number) => {
|
|
65
|
+
// 校对一下
|
|
66
|
+
const distance100 = {
|
|
67
|
+
3: 2,
|
|
68
|
+
4: 5,
|
|
69
|
+
6: 5,
|
|
70
|
+
7: 5,
|
|
71
|
+
8: 10,
|
|
72
|
+
9: 10,
|
|
73
|
+
11: 10,
|
|
74
|
+
12: 10,
|
|
75
|
+
13: 15,
|
|
76
|
+
14: 15,
|
|
77
|
+
16: 15,
|
|
78
|
+
17: 15,
|
|
79
|
+
18: 20,
|
|
80
|
+
19: 20,
|
|
81
|
+
21: 20,
|
|
82
|
+
22: 20,
|
|
83
|
+
23: 25,
|
|
84
|
+
24: 25,
|
|
85
|
+
26: 25,
|
|
86
|
+
27: 25
|
|
87
|
+
}[distance100_oral + changValue] || (distance100_oral + changValue)
|
|
88
|
+
|
|
89
|
+
const distance = distance100 / times100
|
|
90
|
+
|
|
91
|
+
// 最小值,也就是起点
|
|
92
|
+
const begin = Math.floor(minValue / distance) * distance
|
|
93
|
+
|
|
94
|
+
const rulerArray = []
|
|
95
|
+
// 获取最终的刻度尺数组
|
|
96
|
+
rulerArray.push(begin)
|
|
97
|
+
for (let index = 1; rulerArray[rulerArray.length - 1] < maxValue; index++) {
|
|
98
|
+
rulerArray.push(begin + distance * index)
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return rulerArray
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
let rulerArray = getResult(0)
|
|
105
|
+
|
|
106
|
+
const balanceMax = () => {
|
|
107
|
+
const rulerArray_temp = []
|
|
108
|
+
|
|
109
|
+
const changeDist = rulerArray[rulerArray.length - 1] - (option?.max as number)
|
|
110
|
+
for (let index = 0; index < rulerArray.length; index++) {
|
|
111
|
+
if (index + 1 < rulerArray.length && rulerArray[index + 1] - changeDist < minValue) {
|
|
112
|
+
// 多余的
|
|
113
|
+
} else {
|
|
114
|
+
rulerArray_temp.push(rulerArray[index] - changeDist)
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return rulerArray_temp
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const balanceMin = () => {
|
|
122
|
+
const rulerArray_temp = []
|
|
123
|
+
|
|
124
|
+
const changeDist = rulerArray[0] - (option?.min as number)
|
|
125
|
+
for (let index = 0; index < rulerArray.length; index++) {
|
|
126
|
+
rulerArray_temp[index] = rulerArray[index] - changeDist
|
|
127
|
+
if (maxValue <= rulerArray_temp[index]) break
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return rulerArray_temp
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (option) {
|
|
134
|
+
|
|
135
|
+
// 上下界限制
|
|
136
|
+
if ('max' in option && 'min' in option && (option.max as number) >= maxValue && (option.min as number) <= minValue) {
|
|
137
|
+
|
|
138
|
+
const isAnswer = () => {
|
|
139
|
+
|
|
140
|
+
// 先判断原始的是否可行
|
|
141
|
+
if (rulerArray[0] >= (option.min as number) && rulerArray[rulerArray.length - 1] <= (option.max as number)) return true
|
|
142
|
+
|
|
143
|
+
// 再判断max调整是否可行
|
|
144
|
+
const rulerArray_max = balanceMax()
|
|
145
|
+
if (rulerArray_max[0] >= (option.min as number) && rulerArray_max[rulerArray_max.length - 1] <= (option.max as number)) {
|
|
146
|
+
rulerArray = rulerArray_max
|
|
147
|
+
return true
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// 再判断max调整是否可行
|
|
151
|
+
const rulerArray_min = balanceMin()
|
|
152
|
+
if (rulerArray_min[0] >= (option.min as number) && rulerArray_min[rulerArray_max.length - 1] <= (option.max as number)) {
|
|
153
|
+
rulerArray = rulerArray_min
|
|
154
|
+
return true
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
if (isAnswer()) return rulerArray
|
|
160
|
+
|
|
161
|
+
for (let changValue = 1; changValue < 100; changValue++) {
|
|
162
|
+
|
|
163
|
+
rulerArray = getResult(changValue)
|
|
164
|
+
if (isAnswer()) return rulerArray
|
|
165
|
+
|
|
166
|
+
rulerArray = getResult(-changValue)
|
|
167
|
+
if (isAnswer()) return rulerArray
|
|
168
|
+
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// 单界限制
|
|
173
|
+
if ('max' in option && (option.max as number) >= maxValue) {
|
|
174
|
+
|
|
175
|
+
// 上越界了
|
|
176
|
+
if ((option.max as number) < rulerArray[rulerArray.length - 1]) {
|
|
177
|
+
rulerArray = balanceMax()
|
|
178
|
+
}
|
|
179
|
+
} else if ('min' in option && (option.min as number) <= minValue) {
|
|
180
|
+
|
|
181
|
+
// 下越界了
|
|
182
|
+
if ((option.min as number) > rulerArray[0]) {
|
|
183
|
+
rulerArray = balanceMin()
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// 对结果进行对齐
|
|
189
|
+
// 2023年11月15日 于南京
|
|
190
|
+
for (let index = 0; index < rulerArray.length; index++) {
|
|
191
|
+
let valStr = rulerArray[index] + ""
|
|
192
|
+
|
|
193
|
+
// 只有小数需要处理
|
|
194
|
+
if (/\./.test(valStr)) {
|
|
195
|
+
|
|
196
|
+
// 1.0999999999999999
|
|
197
|
+
if (/9{7,}$/.test(valStr)) {
|
|
198
|
+
valStr = valStr.replace(/9{7,}$/, '')
|
|
199
|
+
rulerArray[index] = +(valStr.substring(0, valStr.length - 1) + ((+valStr[valStr.length - 1]) + 1))
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// 0.30000000000000004
|
|
203
|
+
else if (/0{7,}\d$/.test(valStr)) {
|
|
204
|
+
rulerArray[index] = +(valStr.replace(/0{7,}\d$/, ''))
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
return rulerArray
|
|
210
210
|
}
|
package/src/scale.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
// 点(x,y)围绕中心(cx,cy)缩放times倍
|
|
2
|
-
export default function (cx: number, cy: number, times: number, x: number, y: number): [number, number] {
|
|
3
|
-
return [
|
|
4
|
-
times * (x - cx) + cx,
|
|
5
|
-
times * (y - cy) + cy
|
|
6
|
-
]
|
|
1
|
+
// 点(x,y)围绕中心(cx,cy)缩放times倍
|
|
2
|
+
export default function (cx: number, cy: number, times: number, x: number, y: number): [number, number] {
|
|
3
|
+
return [
|
|
4
|
+
times * (x - cx) + cx,
|
|
5
|
+
times * (y - cy) + cy
|
|
6
|
+
]
|
|
7
7
|
}
|
package/types/Bar.d.ts
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
interface categoryAxios {
|
|
2
|
+
type: "category"
|
|
3
|
+
data: Array<string>
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
interface valueAxios {
|
|
7
|
+
type: "value"
|
|
8
|
+
data: Array<number>
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface BarResultType {
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* 坐标系
|
|
15
|
+
*/
|
|
16
|
+
coordinate: {
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* 坐标系左下角横坐标
|
|
20
|
+
*/
|
|
21
|
+
x: number
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* 坐标系左下角纵坐标
|
|
25
|
+
*/
|
|
26
|
+
y: number
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* 坐标系的宽
|
|
30
|
+
*/
|
|
31
|
+
width: number
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* 坐标系的高
|
|
35
|
+
*/
|
|
36
|
+
height: number
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* x坐标轴
|
|
40
|
+
*/
|
|
41
|
+
xAxis: categoryAxios | valueAxios
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* y坐标轴
|
|
45
|
+
*/
|
|
46
|
+
yAxis: categoryAxios | valueAxios
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* 直方矩形
|
|
51
|
+
*/
|
|
52
|
+
node: Array<{
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* 分类名称
|
|
56
|
+
* 如果是一维的,就不存在此项
|
|
57
|
+
*/
|
|
58
|
+
name?: string
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* 当前分类的一个个直方矩形
|
|
62
|
+
*/
|
|
63
|
+
bar: Array<{
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* 矩形原始的值
|
|
67
|
+
*/
|
|
68
|
+
value: number
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* 矩形左下角横坐标
|
|
72
|
+
*/
|
|
73
|
+
x: number
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* 矩形左下角纵坐标
|
|
77
|
+
*/
|
|
78
|
+
y: number
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* 矩形宽
|
|
82
|
+
*/
|
|
83
|
+
width: number
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* 矩形高
|
|
87
|
+
*/
|
|
88
|
+
height: number
|
|
89
|
+
}>
|
|
90
|
+
}>
|
|
91
|
+
|
|
92
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { BarResultType } from "./Bar"
|
|
2
|
+
import BarOptionType from './BarOption'
|
|
3
|
+
|
|
4
|
+
interface dataType {
|
|
5
|
+
category: Array<string>
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
interface singleDataType extends dataType {
|
|
9
|
+
data: Array<number>
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
interface doublieDataType extends dataType {
|
|
13
|
+
value: Array<{
|
|
14
|
+
name: string,
|
|
15
|
+
data: Array<number>
|
|
16
|
+
}>
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export default interface BarLayoutType {
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* 设置布局的行为
|
|
23
|
+
* @param option
|
|
24
|
+
*/
|
|
25
|
+
setOption(option: BarOptionType): this
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* 单纯的直方图计算
|
|
29
|
+
* @param initBar 原始数据
|
|
30
|
+
*/
|
|
31
|
+
use(initBar: singleDataType | doublieDataType): BarResultType
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* 绑定新的数据和渲染方法
|
|
35
|
+
* @param initBar 原始数据
|
|
36
|
+
* @param renderBack 渲染方法
|
|
37
|
+
*/
|
|
38
|
+
bind(initBar: singleDataType | doublieDataType, renderBack: (bar: BarResultType) => void): this
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* 解除绑定
|
|
42
|
+
*/
|
|
43
|
+
unbind(): this
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* 主动触发绘制更新
|
|
47
|
+
*/
|
|
48
|
+
doUpdate(): this
|
|
49
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export default interface BarOptionType {
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 直方图左下角横坐标
|
|
5
|
+
*/
|
|
6
|
+
x?: number
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* 直方图左下角纵坐标
|
|
10
|
+
*/
|
|
11
|
+
y?: number
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* 直方图宽
|
|
15
|
+
*/
|
|
16
|
+
width?: number
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* 直方图高
|
|
20
|
+
*/
|
|
21
|
+
height?: number
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* 直方图分类刻度尺
|
|
25
|
+
*/
|
|
26
|
+
category?: "xAxis" | "yAxis"
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* 切换时长
|
|
30
|
+
*/
|
|
31
|
+
duration?: number
|
|
32
|
+
}
|
package/types/Buffer.d.ts
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
export default interface BufferType {
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* 使用这个缓冲区对象
|
|
5
|
-
* (先于写入和分配)
|
|
6
|
-
*/
|
|
7
|
-
use(): this
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* 写入数据
|
|
11
|
-
* @param data 具体的数据内容
|
|
12
|
-
*/
|
|
13
|
-
write(data: Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array): this
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* 分配使用
|
|
17
|
-
* @param location 变量位置
|
|
18
|
-
* @param size 一个数据的长度
|
|
19
|
-
* @param stride 一组数据的长度(可能包含多组)
|
|
20
|
-
* @param offset 读取位置偏移
|
|
21
|
-
*/
|
|
22
|
-
divide(location: number, size: number, stride: number, offset?: number): this
|
|
23
|
-
|
|
1
|
+
export default interface BufferType {
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 使用这个缓冲区对象
|
|
5
|
+
* (先于写入和分配)
|
|
6
|
+
*/
|
|
7
|
+
use(): this
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* 写入数据
|
|
11
|
+
* @param data 具体的数据内容
|
|
12
|
+
*/
|
|
13
|
+
write(data: Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array): this
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* 分配使用
|
|
17
|
+
* @param location 变量位置
|
|
18
|
+
* @param size 一个数据的长度
|
|
19
|
+
* @param stride 一组数据的长度(可能包含多组)
|
|
20
|
+
* @param offset 读取位置偏移
|
|
21
|
+
*/
|
|
22
|
+
divide(location: number, size: number, stride: number, offset?: number): this
|
|
23
|
+
|
|
24
24
|
}
|