vislite 0.4.1 → 0.5.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 (180) hide show
  1. package/.editorconfig +18 -18
  2. package/AUTHORS.txt +6 -6
  3. package/CHANGELOG +16 -0
  4. package/LICENSE +20 -20
  5. package/README.md +69 -69
  6. package/lib/Buffer/index.umd.js +3 -3
  7. package/lib/Buffer/index.umd.min.js +3 -3
  8. package/lib/Canvas/index.umd.js +3 -3
  9. package/lib/Canvas/index.umd.min.js +3 -3
  10. package/lib/Cardinal/index.umd.js +3 -3
  11. package/lib/Cardinal/index.umd.min.js +3 -3
  12. package/lib/Eoap/index.umd.js +3 -3
  13. package/lib/Eoap/index.umd.min.js +3 -3
  14. package/lib/Geometry/index.umd.js +205 -0
  15. package/lib/Geometry/index.umd.min.js +11 -0
  16. package/lib/Hermite/index.umd.js +3 -3
  17. package/lib/Hermite/index.umd.min.js +3 -3
  18. package/lib/Matrix4/index.umd.js +3 -3
  19. package/lib/Matrix4/index.umd.min.js +3 -3
  20. package/lib/Mercator/index.umd.js +5 -4
  21. package/lib/Mercator/index.umd.min.js +4 -4
  22. package/lib/OralCanvas/index.es.js +3 -3
  23. package/lib/OralCanvas/index.es.min.js +3 -3
  24. package/lib/OralWebGL/index.es.js +11 -11
  25. package/lib/OralWebGL/index.es.min.js +4 -4
  26. package/lib/SVG/index.umd.js +10 -4
  27. package/lib/SVG/index.umd.min.js +4 -4
  28. package/lib/Shader/index.umd.js +11 -11
  29. package/lib/Shader/index.umd.min.js +4 -4
  30. package/lib/Texture/index.umd.js +3 -3
  31. package/lib/Texture/index.umd.min.js +3 -3
  32. package/lib/TreeLayout/index.umd.js +8 -5
  33. package/lib/TreeLayout/index.umd.min.js +4 -4
  34. package/lib/WebGL/index.umd.js +11 -11
  35. package/lib/WebGL/index.umd.min.js +4 -4
  36. package/lib/animation/index.umd.js +3 -3
  37. package/lib/animation/index.umd.min.js +3 -3
  38. package/lib/formatColor/index.umd.js +3 -3
  39. package/lib/formatColor/index.umd.min.js +3 -3
  40. package/lib/getLoopColors/index.umd.js +3 -3
  41. package/lib/getLoopColors/index.umd.min.js +3 -3
  42. package/lib/getWebGLContext/index.umd.js +3 -3
  43. package/lib/getWebGLContext/index.umd.min.js +3 -3
  44. package/lib/index.umd.js +166 -16
  45. package/lib/index.umd.min.js +4 -4
  46. package/lib/resizeObserver/index.umd.js +3 -3
  47. package/lib/resizeObserver/index.umd.min.js +3 -3
  48. package/lib/rotate/index.umd.js +3 -3
  49. package/lib/rotate/index.umd.min.js +3 -3
  50. package/lib/ruler/index.umd.js +3 -3
  51. package/lib/ruler/index.umd.min.js +3 -3
  52. package/lib/throttle/index.umd.js +3 -3
  53. package/lib/throttle/index.umd.min.js +3 -3
  54. package/lib/viewHandler/index.umd.js +3 -3
  55. package/lib/viewHandler/index.umd.min.js +3 -3
  56. package/miniprogram/ui-canvas/index.js +107 -107
  57. package/miniprogram/ui-canvas/index.json +4 -4
  58. package/miniprogram/ui-canvas/index.wxml +4 -4
  59. package/miniprogram/ui-canvas/index.wxss +5 -5
  60. package/package/Buffer/index.ts +2 -2
  61. package/package/Canvas/index.ts +2 -2
  62. package/package/Cardinal/index.ts +2 -2
  63. package/package/Eoap/index.ts +2 -2
  64. package/package/Geometry/index.ts +3 -0
  65. package/package/Hermite/index.ts +2 -2
  66. package/package/Matrix4/index.ts +2 -2
  67. package/package/Mercator/index.ts +2 -2
  68. package/package/OralCanvas/index.ts +2 -2
  69. package/package/OralWebGL/index.ts +2 -2
  70. package/package/SVG/index.ts +2 -2
  71. package/package/Shader/index.ts +39 -39
  72. package/package/Texture/index.ts +2 -2
  73. package/package/TreeLayout/index.ts +2 -2
  74. package/package/WebGL/index.ts +2 -2
  75. package/package/animation/index.ts +2 -2
  76. package/package/formatColor/index.ts +2 -2
  77. package/package/getLoopColors/index.ts +2 -2
  78. package/package/getWebGLContext/index.ts +39 -39
  79. package/package/index.ts +6 -1
  80. package/package/resizeObserver/index.ts +2 -2
  81. package/package/rotate/index.ts +2 -2
  82. package/package/ruler/index.ts +2 -2
  83. package/package/throttle/index.ts +2 -2
  84. package/package/viewHandler/index.ts +2 -2
  85. package/package.json +3 -1
  86. package/src/Canvas.ts +67 -67
  87. package/src/Eoap.ts +1 -1
  88. package/src/Geometry.ts +83 -0
  89. package/src/Matrix4/index.ts +2 -2
  90. package/src/Matrix4/move.ts +12 -12
  91. package/src/Matrix4/rotate.ts +15 -15
  92. package/src/Matrix4/scale.ts +11 -11
  93. package/src/Matrix4/transform.ts +64 -64
  94. package/src/Mercator.ts +3 -2
  95. package/src/SVG.ts +24 -24
  96. package/src/TreeLayout/index.ts +4 -3
  97. package/src/WebGL.ts +66 -66
  98. package/src/animation.ts +98 -98
  99. package/src/common/assemble.ts +22 -22
  100. package/src/common/canvas/arc.ts +50 -50
  101. package/src/common/canvas/config.ts +158 -158
  102. package/src/common/canvas/gradient.ts +29 -29
  103. package/src/common/canvas/index.ts +168 -168
  104. package/src/common/canvas/painter.ts +426 -426
  105. package/src/common/canvas/texts.ts +18 -18
  106. package/src/common/geometry/prism-horizontal.ts +33 -0
  107. package/src/common/geometry/prism-vertical.ts +40 -0
  108. package/src/common/geometry/sphere-fragment.ts +39 -0
  109. package/src/common/geometry/tool/circle.ts +12 -0
  110. package/src/common/mergeOption.ts +6 -6
  111. package/src/common/setStyle.ts +5 -5
  112. package/src/common/svg/config.ts +174 -174
  113. package/src/common/svg/index.ts +9 -1
  114. package/src/common/svg/tool.ts +44 -44
  115. package/src/common/tree/index.ts +25 -25
  116. package/src/common/tree/toInnerTree.ts +56 -56
  117. package/src/common/tree/toPlainTree.ts +131 -131
  118. package/src/common/webgl/buffer.ts +79 -79
  119. package/src/common/webgl/doDraw.ts +108 -108
  120. package/src/common/webgl/getColorFactory.ts +26 -26
  121. package/src/common/webgl/getShader.ts +48 -48
  122. package/src/common/webgl/getTexture.ts +11 -11
  123. package/src/common/webgl/getWebGLContext.ts +27 -27
  124. package/src/common/webgl/index.ts +223 -223
  125. package/src/common/webgl/shader.ts +75 -75
  126. package/src/common/webgl/texture.ts +96 -96
  127. package/src/formatColor.ts +44 -44
  128. package/src/getLoopColors.ts +42 -42
  129. package/src/interpolation/Cardinal.ts +110 -110
  130. package/src/interpolation/Hermite.ts +65 -65
  131. package/src/resizeObserver.ts +36 -36
  132. package/src/rotate.ts +1 -1
  133. package/src/ruler.ts +188 -188
  134. package/src/shader/fsColor.c +7 -7
  135. package/src/shader/fsColors.c +7 -7
  136. package/src/shader/fsCube.c +8 -8
  137. package/src/shader/fsImage.c +8 -8
  138. package/src/shader/vsColor.c +17 -17
  139. package/src/shader/vsColors.c +13 -13
  140. package/src/shader/vsCube.c +13 -13
  141. package/src/shader/vsImage.c +13 -13
  142. package/src/throttle.ts +51 -51
  143. package/src/viewHandler.ts +158 -158
  144. package/types/Buffer.d.ts +23 -23
  145. package/types/Canvas.d.ts +300 -300
  146. package/types/CanvasConfig.d.ts +24 -0
  147. package/types/CanvasOption.d.ts +7 -7
  148. package/types/Cardinal.d.ts +13 -13
  149. package/types/Geometry.d.ts +41 -0
  150. package/types/GeometryOption.d.ts +12 -0
  151. package/types/GeometryResult.d.ts +19 -0
  152. package/types/Gradient.d.ts +14 -14
  153. package/types/Hermite.d.ts +18 -18
  154. package/types/Map.d.ts +2 -2
  155. package/types/Matrix4.d.ts +4 -4
  156. package/types/Object3D.d.ts +114 -114
  157. package/types/SVG.d.ts +18 -13
  158. package/types/SVGConfig.d.ts +76 -60
  159. package/types/Scene3D.d.ts +6 -6
  160. package/types/Shader.d.ts +21 -21
  161. package/types/Texture.d.ts +16 -16
  162. package/types/Tree.d.ts +69 -69
  163. package/types/TreeConfig.d.ts +24 -24
  164. package/types/TreeLayout.d.ts +8 -2
  165. package/types/TreeOption.d.ts +48 -48
  166. package/types/WebGL.d.ts +38 -38
  167. package/types/WebGLOption.d.ts +7 -7
  168. package/types/animation.d.ts +6 -6
  169. package/types/formatColor.d.ts +2 -2
  170. package/types/getLoopColors.d.ts +2 -2
  171. package/types/getWebGLContext.d.ts +2 -2
  172. package/types/index.d.ts +15 -1
  173. package/types/painterConfig.d.ts +2 -2
  174. package/types/resizeObserver.d.ts +2 -2
  175. package/types/rotate.d.ts +1 -1
  176. package/types/ruler.d.ts +7 -7
  177. package/types/throttle.d.ts +4 -4
  178. package/types/throttleOption.d.ts +21 -21
  179. package/types/viewHandler.d.ts +13 -13
  180. package/uni-app/ui-canvas.vue +222 -222
@@ -1,97 +1,97 @@
1
- // 初始化一个纹理对象
2
- // type = gl.TEXTURE_2D 二维纹理
3
- // type = gl.TEXTURE_CUBE_MAP 立方体纹理
4
- // unit表示开启的纹理单元编号
5
- let initTexture = (painter: WebGLRenderingContext, type: number, unit: number) => {
6
-
7
- // 创建纹理对象
8
- let texture = painter.createTexture()
9
-
10
- // 开启纹理单元,unit表示开启的编号
11
- painter.activeTexture(painter['TEXTURE' + unit])
12
-
13
- // 绑定纹理对象到目标上
14
- painter.bindTexture(type, texture)
15
-
16
- return texture
17
- }
18
-
19
- // 链接资源图片
20
- // level默认传入0即可,和金字塔纹理有关
21
- // format表示图像的内部格式:
22
- // gl.RGB(红绿蓝)
23
- // gl.RGBA(红绿蓝透明度)
24
- // gl.ALPHA(0.0,0.0,0.0,透明度)
25
- // gl.LUMINANCE(L、L、L、1L:流明)
26
- // gl.LUMINANCE_ALPHA(L、L、L,透明度)
27
- // textureType表示纹理数据的格式:
28
- // gl.UNSIGNED_BYTE: 表示无符号整形,每一个颜色分量占据1字节
29
- // gl.UNSIGNED_SHORT_5_6_5: 表示RGB,每一个分量分别占据占据5, 6, 5比特
30
- // gl.UNSIGNED_SHORT_4_4_4_4: 表示RGBA,每一个分量分别占据占据4, 4, 4, 4比特
31
- // gl.UNSIGNED_SHORT_5_5_5_1: 表示RGBA,每一个分量分别占据占据5比特,A分量占据1比特
32
- let linkImage = (painter: WebGLRenderingContext, type: number, level: number, format: number, textureType: number, image: TexImageSource) => {
33
- painter.texImage2D(type, level, format, format, textureType, image)
34
- }
35
-
36
- let linkCube = (painter: WebGLRenderingContext, type: number, level: number, format: number, textureType: number, images: TexImageSource[], width: number, height: number, texture: WebGLTexture) => {
37
-
38
- let types = [
39
- painter.TEXTURE_CUBE_MAP_POSITIVE_X, // 右
40
- painter.TEXTURE_CUBE_MAP_NEGATIVE_X, // 左
41
- painter.TEXTURE_CUBE_MAP_POSITIVE_Y, // 上
42
- painter.TEXTURE_CUBE_MAP_NEGATIVE_Y, // 下
43
- painter.TEXTURE_CUBE_MAP_POSITIVE_Z, // 后
44
- painter.TEXTURE_CUBE_MAP_NEGATIVE_Z // 前
45
- ], target: number
46
-
47
- for (let i = 0; i < types.length; i++) {
48
- if (images[i]) {
49
- target = types[i]
50
- painter.texImage2D(target, level, format, width, height, 0, format, textureType, null)
51
- painter.bindTexture(type, texture)
52
- painter.texImage2D(target, level, format, format, textureType, images[i])
53
- }
54
- }
55
-
56
- painter.generateMipmap(type)
57
- }
58
-
59
- class TextureObject {
60
-
61
- private __painter: WebGLRenderingContext
62
- private __type: number
63
-
64
- private __texture: WebGLTexture
65
-
66
- constructor(painter: WebGLRenderingContext, type: string, unit = 0) {
67
- this.__painter = painter
68
- this.__type = {
69
- "2d": painter.TEXTURE_2D,
70
- "cube": painter.TEXTURE_CUBE_MAP
71
- }[type]
72
-
73
- // 创建纹理
74
- this.__texture = initTexture(painter, this.__type, unit)
75
-
76
- // 配置纹理
77
- painter.texParameteri(this.__type, painter.TEXTURE_MIN_FILTER, painter.NEAREST)
78
- painter.texParameteri(this.__type, painter.TEXTURE_MAG_FILTER, painter.NEAREST)
79
- painter.texParameteri(this.__type, painter.TEXTURE_WRAP_S, painter.CLAMP_TO_EDGE)
80
- painter.texParameteri(this.__type, painter.TEXTURE_WRAP_T, painter.CLAMP_TO_EDGE)
81
- }
82
-
83
- // 链接图片资源(单一)
84
- useImage(image: TexImageSource) {
85
- linkImage(this.__painter, this.__type, 0, this.__painter.RGBA, this.__painter.UNSIGNED_BYTE, image)
86
- return this
87
- }
88
-
89
- // 链接图片资源(多张)
90
- useCube(images: TexImageSource[], width: number, height: number) {
91
- linkCube(this.__painter, this.__type, 0, this.__painter.RGBA, this.__painter.UNSIGNED_BYTE, images, width, height, this.__texture)
92
- return this
93
- }
94
-
95
- }
96
-
1
+ // 初始化一个纹理对象
2
+ // type = gl.TEXTURE_2D 二维纹理
3
+ // type = gl.TEXTURE_CUBE_MAP 立方体纹理
4
+ // unit表示开启的纹理单元编号
5
+ let initTexture = (painter: WebGLRenderingContext, type: number, unit: number) => {
6
+
7
+ // 创建纹理对象
8
+ let texture = painter.createTexture()
9
+
10
+ // 开启纹理单元,unit表示开启的编号
11
+ painter.activeTexture(painter['TEXTURE' + unit])
12
+
13
+ // 绑定纹理对象到目标上
14
+ painter.bindTexture(type, texture)
15
+
16
+ return texture
17
+ }
18
+
19
+ // 链接资源图片
20
+ // level默认传入0即可,和金字塔纹理有关
21
+ // format表示图像的内部格式:
22
+ // gl.RGB(红绿蓝)
23
+ // gl.RGBA(红绿蓝透明度)
24
+ // gl.ALPHA(0.0,0.0,0.0,透明度)
25
+ // gl.LUMINANCE(L、L、L、1L:流明)
26
+ // gl.LUMINANCE_ALPHA(L、L、L,透明度)
27
+ // textureType表示纹理数据的格式:
28
+ // gl.UNSIGNED_BYTE: 表示无符号整形,每一个颜色分量占据1字节
29
+ // gl.UNSIGNED_SHORT_5_6_5: 表示RGB,每一个分量分别占据占据5, 6, 5比特
30
+ // gl.UNSIGNED_SHORT_4_4_4_4: 表示RGBA,每一个分量分别占据占据4, 4, 4, 4比特
31
+ // gl.UNSIGNED_SHORT_5_5_5_1: 表示RGBA,每一个分量分别占据占据5比特,A分量占据1比特
32
+ let linkImage = (painter: WebGLRenderingContext, type: number, level: number, format: number, textureType: number, image: TexImageSource) => {
33
+ painter.texImage2D(type, level, format, format, textureType, image)
34
+ }
35
+
36
+ let linkCube = (painter: WebGLRenderingContext, type: number, level: number, format: number, textureType: number, images: TexImageSource[], width: number, height: number, texture: WebGLTexture) => {
37
+
38
+ let types = [
39
+ painter.TEXTURE_CUBE_MAP_POSITIVE_X, // 右
40
+ painter.TEXTURE_CUBE_MAP_NEGATIVE_X, // 左
41
+ painter.TEXTURE_CUBE_MAP_POSITIVE_Y, // 上
42
+ painter.TEXTURE_CUBE_MAP_NEGATIVE_Y, // 下
43
+ painter.TEXTURE_CUBE_MAP_POSITIVE_Z, // 后
44
+ painter.TEXTURE_CUBE_MAP_NEGATIVE_Z // 前
45
+ ], target: number
46
+
47
+ for (let i = 0; i < types.length; i++) {
48
+ if (images[i]) {
49
+ target = types[i]
50
+ painter.texImage2D(target, level, format, width, height, 0, format, textureType, null)
51
+ painter.bindTexture(type, texture)
52
+ painter.texImage2D(target, level, format, format, textureType, images[i])
53
+ }
54
+ }
55
+
56
+ painter.generateMipmap(type)
57
+ }
58
+
59
+ class TextureObject {
60
+
61
+ private __painter: WebGLRenderingContext
62
+ private __type: number
63
+
64
+ private __texture: WebGLTexture
65
+
66
+ constructor(painter: WebGLRenderingContext, type: string, unit = 0) {
67
+ this.__painter = painter
68
+ this.__type = {
69
+ "2d": painter.TEXTURE_2D,
70
+ "cube": painter.TEXTURE_CUBE_MAP
71
+ }[type]
72
+
73
+ // 创建纹理
74
+ this.__texture = initTexture(painter, this.__type, unit)
75
+
76
+ // 配置纹理
77
+ painter.texParameteri(this.__type, painter.TEXTURE_MIN_FILTER, painter.NEAREST)
78
+ painter.texParameteri(this.__type, painter.TEXTURE_MAG_FILTER, painter.NEAREST)
79
+ painter.texParameteri(this.__type, painter.TEXTURE_WRAP_S, painter.CLAMP_TO_EDGE)
80
+ painter.texParameteri(this.__type, painter.TEXTURE_WRAP_T, painter.CLAMP_TO_EDGE)
81
+ }
82
+
83
+ // 链接图片资源(单一)
84
+ useImage(image: TexImageSource) {
85
+ linkImage(this.__painter, this.__type, 0, this.__painter.RGBA, this.__painter.UNSIGNED_BYTE, image)
86
+ return this
87
+ }
88
+
89
+ // 链接图片资源(多张)
90
+ useCube(images: TexImageSource[], width: number, height: number) {
91
+ linkCube(this.__painter, this.__type, 0, this.__painter.RGBA, this.__painter.UNSIGNED_BYTE, images, width, height, this.__texture)
92
+ return this
93
+ }
94
+
95
+ }
96
+
97
97
  export default TextureObject
@@ -1,45 +1,45 @@
1
- let toHex = (value: number) => {
2
- let hex = value.toString(16)
3
- return hex.length == 1 ? ("0" + hex) : hex
4
- }
5
-
6
- export default function (color: string, format: string) {
7
-
8
- let colorNode = document.getElementsByTagName('head')[0]
9
- colorNode.style['color'] = color
10
-
11
- // 获取结点的全部样式
12
- let allStyle = document.defaultView && document.defaultView.getComputedStyle ?
13
- document.defaultView.getComputedStyle(colorNode, null) :
14
- (colorNode as any).currentStyle
15
-
16
- let 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
+ let toHex = (value: number) => {
2
+ let hex = value.toString(16)
3
+ return hex.length == 1 ? ("0" + hex) : hex
4
+ }
5
+
6
+ export default function (color: string, format: string) {
7
+
8
+ let colorNode = document.getElementsByTagName('head')[0]
9
+ colorNode.style['color'] = color
10
+
11
+ // 获取结点的全部样式
12
+ let allStyle = document.defaultView && document.defaultView.getComputedStyle ?
13
+ document.defaultView.getComputedStyle(colorNode, null) :
14
+ (colorNode as any).currentStyle
15
+
16
+ let 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
- let 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
+ let 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
- var 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
+ var 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