vislite 0.6.0 → 0.7.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.
Files changed (118) hide show
  1. package/CHANGELOG +15 -1
  2. package/README.md +24 -5
  3. package/lib/Buffer/index.umd.js +2 -2
  4. package/lib/Buffer/index.umd.min.js +2 -2
  5. package/lib/Canvas/index.umd.js +4 -4
  6. package/lib/Canvas/index.umd.min.js +3 -3
  7. package/lib/Cardinal/index.umd.js +2 -2
  8. package/lib/Cardinal/index.umd.min.js +2 -2
  9. package/lib/Eoap/index.umd.js +2 -2
  10. package/lib/Eoap/index.umd.min.js +2 -2
  11. package/lib/Geometry/index.umd.js +69 -8
  12. package/lib/Geometry/index.umd.min.js +3 -3
  13. package/lib/Hermite/index.umd.js +2 -2
  14. package/lib/Hermite/index.umd.min.js +2 -2
  15. package/lib/Matrix4/index.umd.js +2 -2
  16. package/lib/Matrix4/index.umd.min.js +2 -2
  17. package/lib/Mercator/index.umd.js +2 -2
  18. package/lib/Mercator/index.umd.min.js +2 -2
  19. package/lib/OralCanvas/index.es.js +3 -3
  20. package/lib/OralCanvas/index.es.min.js +3 -3
  21. package/lib/OralWebGL/index.es.js +21 -18
  22. package/lib/OralWebGL/index.es.min.js +3 -3
  23. package/lib/SVG/index.umd.js +2 -2
  24. package/lib/SVG/index.umd.min.js +2 -2
  25. package/lib/Shader/index.umd.js +3 -2
  26. package/lib/Shader/index.umd.min.js +3 -3
  27. package/lib/Texture/index.umd.js +2 -2
  28. package/lib/Texture/index.umd.min.js +2 -2
  29. package/lib/TreeLayout/index.umd.js +13 -11
  30. package/lib/TreeLayout/index.umd.min.js +3 -3
  31. package/lib/WebGL/index.umd.js +22 -19
  32. package/lib/WebGL/index.umd.min.js +3 -3
  33. package/lib/animation/index.umd.js +2 -2
  34. package/lib/animation/index.umd.min.js +2 -2
  35. package/lib/formatColor/index.umd.js +2 -2
  36. package/lib/formatColor/index.umd.min.js +2 -2
  37. package/lib/getLoopColors/index.umd.js +2 -2
  38. package/lib/getLoopColors/index.umd.min.js +2 -2
  39. package/lib/getWebGLContext/index.umd.js +4 -4
  40. package/lib/getWebGLContext/index.umd.min.js +3 -3
  41. package/lib/index.umd.js +104 -38
  42. package/lib/index.umd.min.js +3 -3
  43. package/lib/move/index.umd.js +2 -2
  44. package/lib/move/index.umd.min.js +2 -2
  45. package/lib/resizeObserver/index.umd.js +2 -2
  46. package/lib/resizeObserver/index.umd.min.js +2 -2
  47. package/lib/rotate/index.umd.js +2 -2
  48. package/lib/rotate/index.umd.min.js +2 -2
  49. package/lib/ruler/index.umd.js +4 -4
  50. package/lib/ruler/index.umd.min.js +3 -3
  51. package/lib/scale/index.umd.js +2 -2
  52. package/lib/scale/index.umd.min.js +2 -2
  53. package/lib/throttle/index.umd.js +2 -2
  54. package/lib/throttle/index.umd.min.js +2 -2
  55. package/lib/viewHandler/index.umd.js +2 -2
  56. package/lib/viewHandler/index.umd.min.js +2 -2
  57. package/package/TreeLayout/index.ts +2 -2
  58. package/package.json +1 -1
  59. package/src/Canvas.ts +1 -1
  60. package/src/Eoap.ts +66 -66
  61. package/src/Geometry.ts +57 -13
  62. package/src/Matrix4/index.ts +84 -84
  63. package/src/Matrix4/move.ts +12 -12
  64. package/src/Matrix4/rotate.ts +1 -1
  65. package/src/Matrix4/transform.ts +1 -1
  66. package/src/Mercator.ts +27 -27
  67. package/src/SVG.ts +24 -24
  68. package/src/WebGL.ts +1 -1
  69. package/src/animation.ts +98 -98
  70. package/src/common/assemble.ts +1 -1
  71. package/src/common/canvas/arc.ts +51 -51
  72. package/src/common/canvas/config.ts +158 -158
  73. package/src/common/canvas/gradient.ts +29 -29
  74. package/src/common/canvas/index.ts +2 -2
  75. package/src/common/canvas/painter.ts +2 -0
  76. package/src/common/geometry/prism-horizontal.ts +35 -35
  77. package/src/common/geometry/prism-vertical.ts +1 -1
  78. package/src/common/geometry/sphere-fragment.ts +40 -40
  79. package/src/common/geometry/tool/circle.ts +11 -11
  80. package/src/common/geometry/tool/rotateLine.ts +36 -0
  81. package/src/common/mergeOption.ts +6 -6
  82. package/src/common/setStyle.ts +1 -1
  83. package/src/common/svg/config.ts +10 -6
  84. package/src/common/svg/gradient.ts +63 -63
  85. package/src/common/svg/index.ts +5 -5
  86. package/src/common/svg/tool.ts +6 -6
  87. package/src/common/tree/toInnerTree.ts +8 -6
  88. package/src/common/tree/toPlainTree.ts +1 -1
  89. package/src/common/webgl/buffer.ts +1 -1
  90. package/src/common/webgl/doDraw.ts +16 -16
  91. package/src/common/webgl/getColorFactory.ts +26 -26
  92. package/src/common/webgl/getShader.ts +48 -48
  93. package/src/common/webgl/getTexture.ts +11 -11
  94. package/src/common/webgl/getWebGLContext.ts +3 -3
  95. package/src/common/webgl/index.ts +6 -4
  96. package/src/common/webgl/shader.ts +3 -3
  97. package/src/common/webgl/texture.ts +2 -2
  98. package/src/formatColor.ts +44 -44
  99. package/src/getLoopColors.ts +42 -42
  100. package/src/interpolation/Cardinal.ts +110 -110
  101. package/src/interpolation/Hermite.ts +65 -65
  102. package/src/layout/TreeLayout.ts +13 -11
  103. package/src/move.ts +7 -7
  104. package/src/resizeObserver.ts +2 -2
  105. package/src/rotate.ts +7 -7
  106. package/src/ruler.ts +10 -10
  107. package/src/throttle.ts +52 -52
  108. package/src/viewHandler.ts +4 -2
  109. package/types/Canvas.d.ts +1 -1
  110. package/types/CanvasOption.d.ts +8 -8
  111. package/types/CanvasOpts.d.ts +9 -9
  112. package/types/Geometry.d.ts +65 -40
  113. package/types/Matrix4.d.ts +47 -47
  114. package/types/SVGConfig.d.ts +79 -76
  115. package/types/TreeConfig.d.ts +36 -24
  116. package/uni-app/ui-canvas.vue +9 -31
  117. package/.editorconfig +0 -19
  118. package/.eslintrc.js +0 -26
@@ -1,45 +1,45 @@
1
- const toHex = (value: number) => {
2
- const hex = value.toString(16)
3
- return hex.length == 1 ? ("0" + hex) : hex
4
- }
5
-
6
- export default function (color: string, format: string) {
7
-
8
- const colorNode = document.getElementsByTagName('head')[0]
9
- colorNode.style['color'] = color
10
-
11
- // 获取结点的全部样式
12
- const allStyle = document.defaultView && document.defaultView.getComputedStyle ?
13
- document.defaultView.getComputedStyle(colorNode, null) :
14
- (colorNode as any).currentStyle
15
-
16
- const oralFormat = allStyle.getPropertyValue('color').replace(/rgba?\(/, '').replace(")", "").split(',')
17
- for (let index = 0; index < oralFormat.length; index++) {
18
- oralFormat[index] = +oralFormat[index]
19
- }
20
- oralFormat.push(1)
21
-
22
- switch (format) {
23
- case "3d": {
24
- return [
25
- oralFormat[0] / 255,
26
- oralFormat[1] / 255,
27
- oralFormat[2] / 255,
28
- oralFormat[3]
29
- ]
30
- }
31
- case "rgba": {
32
- return `rgba(${oralFormat[0]}, ${oralFormat[1]}, ${oralFormat[2]}, ${oralFormat[3]})`
33
- }
34
- case "rgb": {
35
- return `rgb(${oralFormat[0]}, ${oralFormat[1]}, ${oralFormat[2]})`
36
- }
37
- case "hexAlpha": {
38
- return `#${toHex(oralFormat[0])}${toHex(oralFormat[1])}${toHex(oralFormat[2])}${toHex(+(oralFormat[3] * 255).toFixed(0))}`
39
- }
40
- case "hex": {
41
- return `#${toHex(oralFormat[0])}${toHex(oralFormat[1])}${toHex(oralFormat[2])}`
42
- }
43
- }
44
- throw new Error("Unsupported color format: " + format)
1
+ const toHex = (value: number) => {
2
+ const hex = value.toString(16)
3
+ return hex.length == 1 ? ("0" + hex) : hex
4
+ }
5
+
6
+ export default function (color: string, format: string) {
7
+
8
+ const colorNode = document.getElementsByTagName('head')[0]
9
+ colorNode.style['color'] = color
10
+
11
+ // 获取结点的全部样式
12
+ const allStyle = document.defaultView && document.defaultView.getComputedStyle ?
13
+ document.defaultView.getComputedStyle(colorNode, null) :
14
+ (colorNode as any).currentStyle
15
+
16
+ const oralFormat = allStyle.getPropertyValue('color').replace(/rgba?\(/, '').replace(")", "").split(',')
17
+ for (let index = 0; index < oralFormat.length; index++) {
18
+ oralFormat[index] = +oralFormat[index]
19
+ }
20
+ oralFormat.push(1)
21
+
22
+ switch (format) {
23
+ case "3d": {
24
+ return [
25
+ oralFormat[0] / 255,
26
+ oralFormat[1] / 255,
27
+ oralFormat[2] / 255,
28
+ oralFormat[3]
29
+ ]
30
+ }
31
+ case "rgba": {
32
+ return `rgba(${oralFormat[0]}, ${oralFormat[1]}, ${oralFormat[2]}, ${oralFormat[3]})`
33
+ }
34
+ case "rgb": {
35
+ return `rgb(${oralFormat[0]}, ${oralFormat[1]}, ${oralFormat[2]})`
36
+ }
37
+ case "hexAlpha": {
38
+ return `#${toHex(oralFormat[0])}${toHex(oralFormat[1])}${toHex(oralFormat[2])}${toHex(+(oralFormat[3] * 255).toFixed(0))}`
39
+ }
40
+ case "hex": {
41
+ return `#${toHex(oralFormat[0])}${toHex(oralFormat[1])}${toHex(oralFormat[2])}`
42
+ }
43
+ }
44
+ throw new Error("Unsupported color format: " + format)
45
45
  }
@@ -1,42 +1,42 @@
1
- // 获取一组循环色彩
2
- export default function (num: number, alpha: number = 1) {
3
- // 颜色集合
4
- const colorList = [
5
- 'rgba(84,112,198,' + alpha + ")", 'rgba(145,204,117,' + alpha + ")",
6
- 'rgba(250,200,88,' + alpha + ")", 'rgba(238,102,102,' + alpha + ")",
7
- 'rgba(115,192,222,' + alpha + ")", 'rgba(59,162,114,' + alpha + ")",
8
- 'rgba(252,132,82,' + alpha + ")", 'rgba(154,96,180,' + alpha + ")",
9
- 'rgba(234,124,204,' + alpha + ")"
10
- ]
11
-
12
- let colors: string[] = []
13
-
14
- // 根据情况返回颜色数组
15
- if (num <= colorList.length) {
16
- // 这种情况就不需要任何处理
17
- return colorList
18
- } else {
19
- // 如果正好是集合长度的倍数
20
- if (num % colorList.length == 0) {
21
- // 将颜色数组循环加入后再返回
22
- for (let i = 0; i < (num / colorList.length); i++) {
23
- colors = colors.concat(colorList)
24
- }
25
- } else {
26
- for (let j = 1; j < (num / colorList.length); j++) {
27
- colors = colors.concat(colorList)
28
- }
29
- // 防止最后一个颜色和第一个颜色重复
30
- if (num % colorList.length == 1) {
31
- colors = colors.concat(colorList[4])
32
- } else {
33
- for (let k = 0; k < num % colorList.length; k++) {
34
- colors = colors.concat(colorList[k])
35
- }
36
- }
37
- }
38
- }
39
-
40
- // 返回结果
41
- return colors
42
- }
1
+ // 获取一组循环色彩
2
+ export default function (num: number, alpha: number = 1) {
3
+ // 颜色集合
4
+ const colorList = [
5
+ 'rgba(84,112,198,' + alpha + ")", 'rgba(145,204,117,' + alpha + ")",
6
+ 'rgba(250,200,88,' + alpha + ")", 'rgba(238,102,102,' + alpha + ")",
7
+ 'rgba(115,192,222,' + alpha + ")", 'rgba(59,162,114,' + alpha + ")",
8
+ 'rgba(252,132,82,' + alpha + ")", 'rgba(154,96,180,' + alpha + ")",
9
+ 'rgba(234,124,204,' + alpha + ")"
10
+ ]
11
+
12
+ let colors: string[] = []
13
+
14
+ // 根据情况返回颜色数组
15
+ if (num <= colorList.length) {
16
+ // 这种情况就不需要任何处理
17
+ return colorList
18
+ } else {
19
+ // 如果正好是集合长度的倍数
20
+ if (num % colorList.length == 0) {
21
+ // 将颜色数组循环加入后再返回
22
+ for (let i = 0; i < (num / colorList.length); i++) {
23
+ colors = colors.concat(colorList)
24
+ }
25
+ } else {
26
+ for (let j = 1; j < (num / colorList.length); j++) {
27
+ colors = colors.concat(colorList)
28
+ }
29
+ // 防止最后一个颜色和第一个颜色重复
30
+ if (num % colorList.length == 1) {
31
+ colors = colors.concat(colorList[4])
32
+ } else {
33
+ for (let k = 0; k < num % colorList.length; k++) {
34
+ colors = colors.concat(colorList[k])
35
+ }
36
+ }
37
+ }
38
+ }
39
+
40
+ // 返回结果
41
+ return colors
42
+ }
@@ -1,111 +1,111 @@
1
- /**
2
- * Cardinal三次插值
3
- * ----------------------------
4
- * Hermite拟合的计算是,确定两个点和两个点的斜率
5
- * 用一个y=ax(3)+bx(2)+cx+d的三次多项式来求解
6
- * 而Cardinal是建立在此基础上
7
- * 给定需要拟合的两个点和第一个点的前一个点+最后一个点的后一个点
8
- * 第一个点的斜率由第一个点的前一个点和第二个点的斜率确定
9
- * 第二个点的斜率由第一个点和第二个点的后一个点的斜率确定
10
- */
11
-
12
- import type CardinalType from '../../types/Cardinal'
13
-
14
- import Hermite from './Hermite'
15
-
16
- class Cardinal implements CardinalType {
17
- readonly name: string = 'Cardinal'
18
-
19
- // 该参数用于调整曲线走势,默认数值t=0,分水岭t=-1,|t-(-1)|的值越大,曲线走势调整的越严重
20
- private __t: number
21
-
22
- private __HS: {
23
- x: number[],
24
- h: Hermite[]
25
- }
26
- private __i: number
27
-
28
- constructor(t: number = 0) {
29
- this.__t = t
30
- }
31
-
32
- // 设置点的位置
33
- // 参数格式:[[x1, y1], [x2, y2], ... ]
34
- // 至少两个点
35
- setP(points: number[][]) {
36
-
37
- this.__HS = {
38
- "x": [],
39
- "h": []
40
- };
41
- let flag: number,
42
- slope = (points[1][1] - points[0][1]) / (points[1][0] - points[0][0]),
43
- temp: number
44
- this.__HS.x[0] = points[0][0]
45
- for (flag = 1; flag < points.length; flag++) {
46
- if (points[flag][0] <= points[flag - 1][0]) throw new Error('The point position should be increamented!')
47
- this.__HS.x[flag] = points[flag][0]
48
-
49
- // 求点斜率
50
-
51
- // temp = flag < points.length - 1 ?
52
- // (points[flag + 1][1] - points[flag - 1][1]) / (points[flag + 1][0] - points[flag - 1][0]) :
53
- // (points[flag][1] - points[flag - 1][1]) / (points[flag][0] - points[flag - 1][0])
54
-
55
- // 修复超过界限的值问题
56
- // 2023年6月25日 于南京
57
- if (flag < points.length - 1) {
58
- if (
59
- (points[flag + 1][1] > points[flag][1] && points[flag - 1][1] > points[flag][1]) ||
60
- (points[flag + 1][1] < points[flag][1] && points[flag - 1][1] < points[flag][1]) ||
61
- points[flag + 1][1] == points[flag][1] ||
62
- points[flag - 1][1] == points[flag][1]
63
- ) {
64
- temp = 0
65
- } else {
66
- temp = (points[flag + 1][1] - points[flag - 1][1]) / (points[flag + 1][0] - points[flag - 1][0])
67
- }
68
- } else {
69
- temp = (points[flag][1] - points[flag - 1][1]) / (points[flag][0] - points[flag - 1][0])
70
- }
71
-
72
- // 求解两个点直接的插值方程
73
- // 第一个点的前一个点直接取第一个点
74
- // 最后一个点的后一个点直接取最后一个点
75
- this.__HS.h[flag - 1] = new Hermite((1 - this.__t) * 0.5).setP(points[flag - 1][0], points[flag - 1][1], points[flag][0], points[flag][1], slope, temp)
76
- slope = temp
77
- }
78
- return this
79
-
80
- }
81
-
82
- // 根据x值返回y值
83
- use(x: number) {
84
- if (this.__HS) {
85
- this.__i = -1
86
-
87
- // 寻找记录x所在位置的区间
88
- // 这里就是寻找对应的拟合函数
89
- while (this.__i + 1 < this.__HS.x.length && (x > this.__HS.x[this.__i + 1] || (this.__i == -1 && x >= this.__HS.x[this.__i + 1]))) {
90
- this.__i += 1
91
- }
92
-
93
- // 由于js浮点运算不准确,我们对于越界的情况进行兼容
94
-
95
- if (this.__i < 0) {
96
- return this.__HS.h[0].use(this.__HS.x[0])
97
- }
98
-
99
- else if (this.__i >= this.__HS.h.length) {
100
- return this.__HS.h[this.__HS.h.length - 1].use(this.__HS.x[this.__HS.x.length - 1])
101
- }
102
-
103
- return this.__HS.h[this.__i].use(x)
104
- } else {
105
- throw new Error('You shoud first set the position!')
106
- }
107
- }
108
-
109
- }
110
-
1
+ /**
2
+ * Cardinal三次插值
3
+ * ----------------------------
4
+ * Hermite拟合的计算是,确定两个点和两个点的斜率
5
+ * 用一个y=ax(3)+bx(2)+cx+d的三次多项式来求解
6
+ * 而Cardinal是建立在此基础上
7
+ * 给定需要拟合的两个点和第一个点的前一个点+最后一个点的后一个点
8
+ * 第一个点的斜率由第一个点的前一个点和第二个点的斜率确定
9
+ * 第二个点的斜率由第一个点和第二个点的后一个点的斜率确定
10
+ */
11
+
12
+ import type CardinalType from '../../types/Cardinal'
13
+
14
+ import Hermite from './Hermite'
15
+
16
+ class Cardinal implements CardinalType {
17
+ readonly name: string = 'Cardinal'
18
+
19
+ // 该参数用于调整曲线走势,默认数值t=0,分水岭t=-1,|t-(-1)|的值越大,曲线走势调整的越严重
20
+ private __t: number
21
+
22
+ private __HS: {
23
+ x: number[],
24
+ h: Hermite[]
25
+ }
26
+ private __i: number
27
+
28
+ constructor(t: number = 0) {
29
+ this.__t = t
30
+ }
31
+
32
+ // 设置点的位置
33
+ // 参数格式:[[x1, y1], [x2, y2], ... ]
34
+ // 至少两个点
35
+ setP(points: number[][]) {
36
+
37
+ this.__HS = {
38
+ "x": [],
39
+ "h": []
40
+ };
41
+ let flag: number,
42
+ slope = (points[1][1] - points[0][1]) / (points[1][0] - points[0][0]),
43
+ temp: number
44
+ this.__HS.x[0] = points[0][0]
45
+ for (flag = 1; flag < points.length; flag++) {
46
+ if (points[flag][0] <= points[flag - 1][0]) throw new Error('The point position should be increamented!')
47
+ this.__HS.x[flag] = points[flag][0]
48
+
49
+ // 求点斜率
50
+
51
+ // temp = flag < points.length - 1 ?
52
+ // (points[flag + 1][1] - points[flag - 1][1]) / (points[flag + 1][0] - points[flag - 1][0]) :
53
+ // (points[flag][1] - points[flag - 1][1]) / (points[flag][0] - points[flag - 1][0])
54
+
55
+ // 修复超过界限的值问题
56
+ // 2023年6月25日 于南京
57
+ if (flag < points.length - 1) {
58
+ if (
59
+ (points[flag + 1][1] > points[flag][1] && points[flag - 1][1] > points[flag][1]) ||
60
+ (points[flag + 1][1] < points[flag][1] && points[flag - 1][1] < points[flag][1]) ||
61
+ points[flag + 1][1] == points[flag][1] ||
62
+ points[flag - 1][1] == points[flag][1]
63
+ ) {
64
+ temp = 0
65
+ } else {
66
+ temp = (points[flag + 1][1] - points[flag - 1][1]) / (points[flag + 1][0] - points[flag - 1][0])
67
+ }
68
+ } else {
69
+ temp = (points[flag][1] - points[flag - 1][1]) / (points[flag][0] - points[flag - 1][0])
70
+ }
71
+
72
+ // 求解两个点直接的插值方程
73
+ // 第一个点的前一个点直接取第一个点
74
+ // 最后一个点的后一个点直接取最后一个点
75
+ this.__HS.h[flag - 1] = new Hermite((1 - this.__t) * 0.5).setP(points[flag - 1][0], points[flag - 1][1], points[flag][0], points[flag][1], slope, temp)
76
+ slope = temp
77
+ }
78
+ return this
79
+
80
+ }
81
+
82
+ // 根据x值返回y值
83
+ use(x: number) {
84
+ if (this.__HS) {
85
+ this.__i = -1
86
+
87
+ // 寻找记录x所在位置的区间
88
+ // 这里就是寻找对应的拟合函数
89
+ while (this.__i + 1 < this.__HS.x.length && (x > this.__HS.x[this.__i + 1] || (this.__i == -1 && x >= this.__HS.x[this.__i + 1]))) {
90
+ this.__i += 1
91
+ }
92
+
93
+ // 由于js浮点运算不准确,我们对于越界的情况进行兼容
94
+
95
+ if (this.__i < 0) {
96
+ return this.__HS.h[0].use(this.__HS.x[0])
97
+ }
98
+
99
+ else if (this.__i >= this.__HS.h.length) {
100
+ return this.__HS.h[this.__HS.h.length - 1].use(this.__HS.x[this.__HS.x.length - 1])
101
+ }
102
+
103
+ return this.__HS.h[this.__i].use(x)
104
+ } else {
105
+ throw new Error('You shoud first set the position!')
106
+ }
107
+ }
108
+
109
+ }
110
+
111
111
  export default Cardinal
@@ -1,66 +1,66 @@
1
- import type HermiteType from '../../types/Hermite'
2
-
3
- class Hermite implements HermiteType {
4
- readonly name: string = 'Hermite'
5
-
6
- private __u: number // 张弛系数
7
-
8
- private __MR: number[]
9
- private __a: number
10
- private __b: number
11
-
12
- constructor(u: number = 0.5) {
13
- this.__u = u
14
- }
15
-
16
- /**
17
- * 设置点的位置
18
- * @param {Number} x1 左边点的位置
19
- * @param {Number} y1
20
- * @param {Number} x2 右边点的位置
21
- * @param {Number} y2
22
- * @param {Number} s1 两个点的斜率
23
- * @param {Number} s2
24
- */
25
- setP(x1: number, y1: number, x2: number, y2: number, s1: number, s2: number) {
26
- if (x1 < x2) {
27
- // 记录原始尺寸
28
- this.__a = x1
29
- this.__b = x2
30
- const p3 = this.__u * s1,
31
- p4 = this.__u * s2
32
- // 缩放到[0,1]定义域
33
- y1 /= (x2 - x1)
34
- y2 /= (x2 - x1)
35
- // MR是提前计算好的多项式通解矩阵
36
- // 为了加速计算
37
- // 如上面说的
38
- // 统一在[0,1]上计算后再通过缩放和移动恢复
39
- // 避免了动态求解矩阵的麻烦
40
- this.__MR = [
41
- 2 * y1 - 2 * y2 + p3 + p4,
42
- 3 * y2 - 3 * y1 - 2 * p3 - p4,
43
- p3,
44
- y1
45
- ]
46
- } else throw new Error('The point x-position should be increamented!')
47
- return this
48
- }
49
-
50
-
51
- /**
52
- * 根据x值返回y值
53
- * @param {Number} x
54
- */
55
- use(x: number) {
56
- if (this.__MR) {
57
- const sx = (x - this.__a) / (this.__b - this.__a),
58
- sx2 = sx * sx,
59
- sx3 = sx * sx2
60
- const sResult = sx3 * this.__MR[0] + sx2 * this.__MR[1] + sx * this.__MR[2] + this.__MR[3]
61
- return sResult * (this.__b - this.__a)
62
- } else throw new Error('You shoud first set the position!')
63
- }
64
- }
65
-
1
+ import type HermiteType from '../../types/Hermite'
2
+
3
+ class Hermite implements HermiteType {
4
+ readonly name: string = 'Hermite'
5
+
6
+ private __u: number // 张弛系数
7
+
8
+ private __MR: number[]
9
+ private __a: number
10
+ private __b: number
11
+
12
+ constructor(u: number = 0.5) {
13
+ this.__u = u
14
+ }
15
+
16
+ /**
17
+ * 设置点的位置
18
+ * @param {Number} x1 左边点的位置
19
+ * @param {Number} y1
20
+ * @param {Number} x2 右边点的位置
21
+ * @param {Number} y2
22
+ * @param {Number} s1 两个点的斜率
23
+ * @param {Number} s2
24
+ */
25
+ setP(x1: number, y1: number, x2: number, y2: number, s1: number, s2: number) {
26
+ if (x1 < x2) {
27
+ // 记录原始尺寸
28
+ this.__a = x1
29
+ this.__b = x2
30
+ const p3 = this.__u * s1,
31
+ p4 = this.__u * s2
32
+ // 缩放到[0,1]定义域
33
+ y1 /= (x2 - x1)
34
+ y2 /= (x2 - x1)
35
+ // MR是提前计算好的多项式通解矩阵
36
+ // 为了加速计算
37
+ // 如上面说的
38
+ // 统一在[0,1]上计算后再通过缩放和移动恢复
39
+ // 避免了动态求解矩阵的麻烦
40
+ this.__MR = [
41
+ 2 * y1 - 2 * y2 + p3 + p4,
42
+ 3 * y2 - 3 * y1 - 2 * p3 - p4,
43
+ p3,
44
+ y1
45
+ ]
46
+ } else throw new Error('The point x-position should be increamented!')
47
+ return this
48
+ }
49
+
50
+
51
+ /**
52
+ * 根据x值返回y值
53
+ * @param {Number} x
54
+ */
55
+ use(x: number) {
56
+ if (this.__MR) {
57
+ const sx = (x - this.__a) / (this.__b - this.__a),
58
+ sx2 = sx * sx,
59
+ sx3 = sx * sx2
60
+ const sResult = sx3 * this.__MR[0] + sx2 * this.__MR[1] + sx * this.__MR[2] + this.__MR[3]
61
+ return sResult * (this.__b - this.__a)
62
+ } else throw new Error('You shoud first set the position!')
63
+ }
64
+ }
65
+
66
66
  export default Hermite
@@ -10,7 +10,7 @@ import rotate from '../rotate'
10
10
  class TreeLayout extends Tree implements TreeLayoutType {
11
11
  readonly name: string = 'TreeLayout'
12
12
 
13
- private __option: TreeOptionType = {
13
+ private __option = {
14
14
  offsetX: 0,
15
15
  offsetY: 0,
16
16
  duration: 500,
@@ -25,7 +25,7 @@ class TreeLayout extends Tree implements TreeLayoutType {
25
25
 
26
26
  private __rback: (tree: TreeResultType) => void
27
27
  private __oralTree: any
28
- private __preTree: TreeResultType
28
+ private __preTree: TreeResultType | null
29
29
 
30
30
  private __noOpens = {}
31
31
 
@@ -127,7 +127,7 @@ class TreeLayout extends Tree implements TreeLayoutType {
127
127
  }
128
128
 
129
129
  unbind() {
130
- this.__rback = null
130
+ this.__rback = () => null
131
131
  this.__oralTree = null
132
132
  this.__preTree = null
133
133
  this.__noOpens = {}
@@ -141,12 +141,14 @@ class TreeLayout extends Tree implements TreeLayoutType {
141
141
 
142
142
  animation((deep) => {
143
143
 
144
- for (const key in cacheTree.node) {
145
- if (newTree.node[key].show || this.__preTree.node[key].show) {
146
- cacheTree.node[key].show = true
144
+ if (this.__preTree) {
145
+ for (const key in cacheTree.node) {
146
+ if (newTree.node[key].show || this.__preTree.node[key].show) {
147
+ cacheTree.node[key].show = true
147
148
 
148
- cacheTree.node[key].left = this.__preTree.node[key].left + (newTree.node[key].left - this.__preTree.node[key].left) * deep
149
- cacheTree.node[key].top = this.__preTree.node[key].top + (newTree.node[key].top - this.__preTree.node[key].top) * deep
149
+ cacheTree.node[key].left = this.__preTree.node[key].left + (newTree.node[key].left - this.__preTree.node[key].left) * deep
150
+ cacheTree.node[key].top = this.__preTree.node[key].top + (newTree.node[key].top - this.__preTree.node[key].top) * deep
151
+ }
150
152
  }
151
153
  }
152
154
  this.__rback(cacheTree)
@@ -159,7 +161,7 @@ class TreeLayout extends Tree implements TreeLayoutType {
159
161
  }
160
162
 
161
163
  closeNode(id: string) {
162
- if (!this.__preTree) return
164
+ if (!this.__preTree) return this
163
165
  this.__noOpens[id] = true
164
166
 
165
167
  this.doUpdate()
@@ -167,7 +169,7 @@ class TreeLayout extends Tree implements TreeLayoutType {
167
169
  }
168
170
 
169
171
  openNode(id: string) {
170
- if (!this.__preTree) return
172
+ if (!this.__preTree) return this
171
173
  this.__noOpens[id] = false
172
174
 
173
175
  this.doUpdate()
@@ -175,7 +177,7 @@ class TreeLayout extends Tree implements TreeLayoutType {
175
177
  }
176
178
 
177
179
  toggleNode(id: string) {
178
- if (!this.__preTree) return
180
+ if (!this.__preTree) return this
179
181
  this.__noOpens[id] = !this.__noOpens[id]
180
182
 
181
183
  this.doUpdate()
package/src/move.ts CHANGED
@@ -1,8 +1,8 @@
1
- // 点(x,y)沿着向量(ax,ay)方向移动距离d
2
- export default function (ax: number, ay: number, d: number, x: number, y: number): [number, number] {
3
- const sqrt = Math.sqrt(ax * ax + ay * ay)
4
- return [
5
- ax * d / sqrt + x,
6
- ay * d / sqrt + y
7
- ]
1
+ // 点(x,y)沿着向量(ax,ay)方向移动距离d
2
+ export default function (ax: number, ay: number, d: number, x: number, y: number): [number, number] {
3
+ const sqrt = Math.sqrt(ax * ax + ay * ay)
4
+ return [
5
+ ax * d / sqrt + x,
6
+ ay * d / sqrt + y
7
+ ]
8
8
  }
@@ -20,11 +20,11 @@ export default function (el: HTMLElement | null, callback: Function) {
20
20
  (el as any)._resize_observer_ = uniqueid
21
21
  attrValueToCallback[uniqueid] = callback
22
22
 
23
- observer.observe(el)
23
+ observer.observe(el as HTMLElement)
24
24
 
25
25
  return function () {
26
26
  if (observer) {
27
- observer.unobserve(el)
27
+ observer.unobserve(el as HTMLElement)
28
28
  delete attrValueToCallback[(el as any)._resize_observer_]
29
29
  }
30
30
  }
package/src/rotate.ts CHANGED
@@ -1,8 +1,8 @@
1
- // 点(x,y)围绕中心(cx,cy)旋转deg度
2
- export default function (cx: number, cy: number, deg: number, x: number, y: number): [number, number] {
3
- const cos = Math.cos(deg), sin = Math.sin(deg)
4
- return [
5
- (x - cx) * cos - (y - cy) * sin + cx,
6
- (x - cx) * sin + (y - cy) * cos + cy
7
- ]
1
+ // 点(x,y)围绕中心(cx,cy)旋转deg度
2
+ export default function (cx: number, cy: number, deg: number, x: number, y: number): [number, number] {
3
+ const cos = Math.cos(deg), sin = Math.sin(deg)
4
+ return [
5
+ (x - cx) * cos - (y - cy) * sin + cx,
6
+ (x - cx) * sin + (y - cy) * cos + cy
7
+ ]
8
8
  }