vislite 1.6.0 → 1.6.1

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 (176) hide show
  1. package/AUTHORS.txt +6 -6
  2. package/CHANGELOG +8 -1
  3. package/LICENSE +20 -20
  4. package/lib/BarLayout/index.es.js +105 -105
  5. package/lib/BarLayout/index.es.min.js +2 -2
  6. package/lib/Buffer/index.es.js +1 -1
  7. package/lib/Buffer/index.es.min.js +1 -1
  8. package/lib/Canvas/index.es.js +1 -1
  9. package/lib/Canvas/index.es.min.js +1 -1
  10. package/lib/Cardinal/index.es.js +1 -1
  11. package/lib/Cardinal/index.es.min.js +1 -1
  12. package/lib/Eoap/index.es.js +1 -1
  13. package/lib/Eoap/index.es.min.js +1 -1
  14. package/lib/Hermite/index.es.js +1 -1
  15. package/lib/Hermite/index.es.min.js +1 -1
  16. package/lib/MapCoordinate/index.es.js +1 -1
  17. package/lib/MapCoordinate/index.es.min.js +1 -1
  18. package/lib/Matrix4/index.es.js +1 -1
  19. package/lib/Matrix4/index.es.min.js +1 -1
  20. package/lib/Mercator/index.es.js +1 -1
  21. package/lib/Mercator/index.es.min.js +1 -1
  22. package/lib/PieLayout/index.es.js +105 -105
  23. package/lib/PieLayout/index.es.min.js +2 -2
  24. package/lib/RawCanvas/index.es.js +1 -1
  25. package/lib/RawCanvas/index.es.min.js +1 -1
  26. package/lib/SVG/index.es.js +2 -2
  27. package/lib/SVG/index.es.min.js +2 -2
  28. package/lib/Shader/index.es.js +1 -1
  29. package/lib/Shader/index.es.min.js +1 -1
  30. package/lib/Texture/index.es.js +1 -1
  31. package/lib/Texture/index.es.min.js +1 -1
  32. package/lib/TreeLayout/index.es.js +105 -105
  33. package/lib/TreeLayout/index.es.min.js +2 -2
  34. package/lib/animation/index.es.js +105 -105
  35. package/lib/animation/index.es.min.js +2 -2
  36. package/lib/assemble/index.es.js +1 -1
  37. package/lib/assemble/index.es.min.js +1 -1
  38. package/lib/getLoopColors/index.es.js +1 -1
  39. package/lib/getLoopColors/index.es.min.js +1 -1
  40. package/lib/getWebGLContext/index.es.js +1 -1
  41. package/lib/getWebGLContext/index.es.min.js +1 -1
  42. package/lib/index.umd.js +156 -156
  43. package/lib/index.umd.min.js +5 -5
  44. package/lib/initOption/index.es.js +1 -1
  45. package/lib/initOption/index.es.min.js +1 -1
  46. package/lib/mergeOption/index.es.js +1 -1
  47. package/lib/mergeOption/index.es.min.js +1 -1
  48. package/lib/move/index.es.js +1 -1
  49. package/lib/move/index.es.min.js +1 -1
  50. package/lib/rotate/index.es.js +1 -1
  51. package/lib/rotate/index.es.min.js +1 -1
  52. package/lib/ruler/index.es.js +1 -1
  53. package/lib/ruler/index.es.min.js +1 -1
  54. package/lib/scale/index.es.js +1 -1
  55. package/lib/scale/index.es.min.js +1 -1
  56. package/lib/throttle/index.es.js +51 -51
  57. package/lib/throttle/index.es.min.js +2 -2
  58. package/minialipay/ui-canvas/drawImage.js +35 -35
  59. package/minialipay/ui-canvas/index.acss +4 -4
  60. package/minialipay/ui-canvas/index.axml +3 -3
  61. package/minialipay/ui-canvas/index.d.ts +1 -1
  62. package/minialipay/ui-canvas/index.js +100 -100
  63. package/minialipay/ui-canvas/index.json +6 -6
  64. package/miniprogram/ui-canvas/drawImage.js +35 -35
  65. package/miniprogram/ui-canvas/index.js +125 -125
  66. package/miniprogram/ui-canvas/index.json +4 -4
  67. package/miniprogram/ui-canvas/index.wxml +4 -4
  68. package/miniprogram/ui-canvas/index.wxss +5 -5
  69. package/package/BarLayout/index.ts +2 -2
  70. package/package/Buffer/index.ts +2 -2
  71. package/package/Canvas/index.ts +2 -2
  72. package/package/Cardinal/index.ts +2 -2
  73. package/package/Eoap/index.ts +2 -2
  74. package/package/Hermite/index.ts +2 -2
  75. package/package/MapCoordinate/index.ts +2 -2
  76. package/package/Matrix4/index.ts +2 -2
  77. package/package/Mercator/index.ts +2 -2
  78. package/package/PieLayout/index.ts +2 -2
  79. package/package/RawCanvas/index.ts +2 -2
  80. package/package/SVG/index.ts +2 -2
  81. package/package/Shader/index.ts +2 -2
  82. package/package/Texture/index.ts +2 -2
  83. package/package/TreeLayout/index.ts +2 -2
  84. package/package/animation/index.ts +5 -5
  85. package/package/assemble/index.ts +2 -2
  86. package/package/getLoopColors/index.ts +2 -2
  87. package/package/getWebGLContext/index.ts +40 -40
  88. package/package/index.ts +84 -84
  89. package/package/initOption/index.ts +2 -2
  90. package/package/mergeOption/index.ts +2 -2
  91. package/package/move/index.ts +2 -2
  92. package/package/rotate/index.ts +2 -2
  93. package/package/ruler/index.ts +2 -2
  94. package/package/scale/index.ts +2 -2
  95. package/package/throttle/index.ts +2 -2
  96. package/package.json +2 -2
  97. package/src/Eoap.ts +66 -66
  98. package/src/Matrix4/index.ts +84 -84
  99. package/src/Matrix4/move.ts +12 -12
  100. package/src/Matrix4/rotate.ts +15 -15
  101. package/src/Matrix4/scale.ts +11 -11
  102. package/src/Matrix4/transform.ts +64 -64
  103. package/src/Mercator.ts +27 -27
  104. package/src/common/assemble.ts +22 -22
  105. package/src/common/canvas/arc.ts +51 -51
  106. package/src/common/canvas/config.ts +176 -176
  107. package/src/common/canvas/default.ts +64 -64
  108. package/src/common/canvas/gradient.ts +31 -31
  109. package/src/common/canvas/index.ts +188 -188
  110. package/src/common/canvas/texts.ts +18 -18
  111. package/src/common/map/getBoundary.ts +15 -15
  112. package/src/common/map/tool.ts +29 -29
  113. package/src/common/option.ts +29 -29
  114. package/src/common/setStyle.ts +5 -5
  115. package/src/common/svg/config.ts +213 -213
  116. package/src/common/svg/default.ts +29 -29
  117. package/src/common/svg/gradient.ts +53 -53
  118. package/src/common/svg/index.ts +332 -332
  119. package/src/common/svg/tool.ts +51 -51
  120. package/src/common/tree/index.ts +25 -25
  121. package/src/common/tree/toInnerTree.ts +61 -61
  122. package/src/common/type.ts +26 -26
  123. package/src/common/webgl/buffer.ts +79 -79
  124. package/src/common/webgl/getWebGLContext.ts +45 -45
  125. package/src/common/webgl/shader.ts +75 -75
  126. package/src/coordinate/MapCoordinate.ts +80 -80
  127. package/src/getLoopColors.ts +42 -42
  128. package/src/interpolation/Cardinal.ts +110 -110
  129. package/src/interpolation/Hermite.ts +65 -65
  130. package/src/move.ts +7 -7
  131. package/src/rotate.ts +7 -7
  132. package/src/ruler.ts +209 -209
  133. package/src/scale.ts +6 -6
  134. package/types/Bar.d.ts +91 -91
  135. package/types/BarConfig.d.ts +4 -4
  136. package/types/BarLayout.d.ts +48 -48
  137. package/types/BarOption.d.ts +31 -31
  138. package/types/Buffer.d.ts +23 -23
  139. package/types/CanvasConfig.d.ts +88 -88
  140. package/types/CanvasOption.d.ts +13 -13
  141. package/types/CanvasOpts.d.ts +9 -9
  142. package/types/Cardinal.d.ts +13 -13
  143. package/types/Gradient.d.ts +14 -14
  144. package/types/Hermite.d.ts +18 -18
  145. package/types/Map.d.ts +9 -9
  146. package/types/MapConfig.d.ts +27 -27
  147. package/types/MapCoordinate.d.ts +22 -22
  148. package/types/Matrix4.d.ts +47 -47
  149. package/types/Pie.d.ts +73 -73
  150. package/types/PieConfig.d.ts +26 -26
  151. package/types/PieLayout.d.ts +40 -40
  152. package/types/PieOption.d.ts +21 -21
  153. package/types/SVG.d.ts +247 -247
  154. package/types/SVGConfig.d.ts +71 -71
  155. package/types/Shader.d.ts +16 -16
  156. package/types/Texture.d.ts +16 -16
  157. package/types/Tree.d.ts +74 -74
  158. package/types/TreeConfig.d.ts +36 -36
  159. package/types/TreeLayout.d.ts +59 -59
  160. package/types/TreeOption.d.ts +48 -48
  161. package/types/animation.d.ts +11 -11
  162. package/types/assemble.d.ts +5 -5
  163. package/types/getLoopColors.d.ts +5 -5
  164. package/types/getWebGLContext.d.ts +7 -7
  165. package/types/index.d.ts +195 -195
  166. package/types/move.d.ts +5 -5
  167. package/types/option.d.ts +12 -12
  168. package/types/painterConfig.d.ts +4 -4
  169. package/types/rotate.d.ts +5 -5
  170. package/types/ruler.d.ts +10 -10
  171. package/types/scale.d.ts +5 -5
  172. package/types/throttle.d.ts +5 -5
  173. package/types/ui-canvas.d.ts +4 -4
  174. package/types/uni-canvas.d.ts +3 -3
  175. package/uni-app/drawImage.js +19 -19
  176. package/uni-app/ui-canvas.vue +295 -295
@@ -1,76 +1,76 @@
1
- // 着色器分为两类:顶点着色器 + 片段着色器
2
- // 前者用于定义一个点的特性,比如位置,大小,颜色等
3
- // 后者用于针对每个片段(可以理解为像素)进行处理
4
-
5
- // 着色器采用的语言是:GLSL ES语言
6
-
7
- // 把着色器字符串加载成着色器对象
8
- const loadShader = (painter: WebGLRenderingContext, type: number, source: string) => {
9
-
10
- // 创建着色器对象
11
- const shader = painter.createShader(type)
12
- if (shader == null) throw new Error('Unable to create shader!')
13
-
14
- // 绑定资源
15
- painter.shaderSource(shader, source)
16
-
17
- // 编译着色器
18
- painter.compileShader(shader)
19
-
20
- // 检测着色器编译是否成功
21
- if (!painter.getShaderParameter(shader, painter.COMPILE_STATUS))
22
- throw new Error('Failed to compile shader:' + painter.getShaderInfoLog(shader))
23
-
24
- return shader
25
- }
26
-
27
- // 建立着色器
28
- const useShader = (painter: WebGLRenderingContext, vshaderSource: string, fshaderSource: string) => {
29
-
30
- // 分别加载顶点着色器对象和片段着色器对象
31
- const vertexShader = loadShader(painter, painter.VERTEX_SHADER, vshaderSource)
32
- const fragmentShader = loadShader(painter, painter.FRAGMENT_SHADER, fshaderSource)
33
-
34
- // 创建一个着色器程序
35
- const glProgram = painter.createProgram() as WebGLProgram
36
-
37
- // 把前面创建的两个着色器对象添加到着色器程序中
38
- painter.attachShader(glProgram, vertexShader)
39
- painter.attachShader(glProgram, fragmentShader)
40
-
41
- // 把着色器程序链接成一个完整的程序
42
- painter.linkProgram(glProgram)
43
-
44
- // 检测着色器程序链接是否成功
45
- if (!painter.getProgramParameter(glProgram, painter.LINK_STATUS))
46
- throw new Error('Failed to link program: ' + painter.getProgramInfoLog(glProgram))
47
-
48
- return glProgram
49
- }
50
-
51
- class ShaderObject {
52
-
53
- private __painter: WebGLRenderingContext
54
-
55
- program: WebGLProgram
56
-
57
- constructor(painter: WebGLRenderingContext) {
58
- this.__painter = painter
59
- }
60
-
61
- // 使用这个程序
62
- // (后于编译)
63
- use() {
64
- this.__painter.useProgram(this.program)
65
- return this
66
- }
67
-
68
- // 编译着色器程序
69
- compile(vshaderSource: string, fshaderSource: string) {
70
- this.program = useShader(this.__painter, vshaderSource, fshaderSource) as WebGLProgram
71
- return this
72
- }
73
-
74
- }
75
-
1
+ // 着色器分为两类:顶点着色器 + 片段着色器
2
+ // 前者用于定义一个点的特性,比如位置,大小,颜色等
3
+ // 后者用于针对每个片段(可以理解为像素)进行处理
4
+
5
+ // 着色器采用的语言是:GLSL ES语言
6
+
7
+ // 把着色器字符串加载成着色器对象
8
+ const loadShader = (painter: WebGLRenderingContext, type: number, source: string) => {
9
+
10
+ // 创建着色器对象
11
+ const shader = painter.createShader(type)
12
+ if (shader == null) throw new Error('Unable to create shader!')
13
+
14
+ // 绑定资源
15
+ painter.shaderSource(shader, source)
16
+
17
+ // 编译着色器
18
+ painter.compileShader(shader)
19
+
20
+ // 检测着色器编译是否成功
21
+ if (!painter.getShaderParameter(shader, painter.COMPILE_STATUS))
22
+ throw new Error('Failed to compile shader:' + painter.getShaderInfoLog(shader))
23
+
24
+ return shader
25
+ }
26
+
27
+ // 建立着色器
28
+ const useShader = (painter: WebGLRenderingContext, vshaderSource: string, fshaderSource: string) => {
29
+
30
+ // 分别加载顶点着色器对象和片段着色器对象
31
+ const vertexShader = loadShader(painter, painter.VERTEX_SHADER, vshaderSource)
32
+ const fragmentShader = loadShader(painter, painter.FRAGMENT_SHADER, fshaderSource)
33
+
34
+ // 创建一个着色器程序
35
+ const glProgram = painter.createProgram() as WebGLProgram
36
+
37
+ // 把前面创建的两个着色器对象添加到着色器程序中
38
+ painter.attachShader(glProgram, vertexShader)
39
+ painter.attachShader(glProgram, fragmentShader)
40
+
41
+ // 把着色器程序链接成一个完整的程序
42
+ painter.linkProgram(glProgram)
43
+
44
+ // 检测着色器程序链接是否成功
45
+ if (!painter.getProgramParameter(glProgram, painter.LINK_STATUS))
46
+ throw new Error('Failed to link program: ' + painter.getProgramInfoLog(glProgram))
47
+
48
+ return glProgram
49
+ }
50
+
51
+ class ShaderObject {
52
+
53
+ private __painter: WebGLRenderingContext
54
+
55
+ program: WebGLProgram
56
+
57
+ constructor(painter: WebGLRenderingContext) {
58
+ this.__painter = painter
59
+ }
60
+
61
+ // 使用这个程序
62
+ // (后于编译)
63
+ use() {
64
+ this.__painter.useProgram(this.program)
65
+ return this
66
+ }
67
+
68
+ // 编译着色器程序
69
+ compile(vshaderSource: string, fshaderSource: string) {
70
+ this.program = useShader(this.__painter, vshaderSource, fshaderSource) as WebGLProgram
71
+ return this
72
+ }
73
+
74
+ }
75
+
76
76
  export default ShaderObject
@@ -1,81 +1,81 @@
1
- import type MapConfigType from '../../types/MapConfig'
2
- import type MapCoordinateType from '../../types/MapCoordinate'
3
- import type MapType from '../../types/Map'
4
-
5
- import { initOption, mergeOption } from '../common/option'
6
- import getBoundary from '../common/map/getBoundary'
7
- import Mercator from '../Mercator'
8
- import Eoap from '../Eoap'
9
-
10
- class MapCoordinate implements MapCoordinateType {
11
- readonly name: string = 'MapCoordinate'
12
-
13
- private __config: MapConfigType
14
- private __map: MapType
15
- private __boundary: Array<number>
16
-
17
- constructor(config: MapConfigType = {}) {
18
- this.__config = initOption(config, {
19
- api: "Mercator",
20
- width: 400,
21
- height: 300,
22
- left: 0,
23
- top: 0
24
- })
25
- }
26
-
27
- private $$updateMap() {
28
- const [minLongitude, maxLongitude, minLatitude, maxLatitude] = this.__boundary
29
-
30
- if (this.__config.api == "Eoap") {
31
-
32
- const xScale = (this.__config.width as number) * 0.836 / (maxLongitude - minLongitude)
33
- const yScale = (this.__config.height as number) * 0.557 / (maxLatitude - minLatitude)
34
-
35
- this.__map = new Eoap(xScale < yScale ? xScale : yScale, [
36
- (minLongitude + maxLongitude) * 0.5 * 0.9778,
37
- (minLatitude + maxLatitude) * 0.5 * 1.025
38
- ])
39
-
40
- } else if (this.__config.api == "Mercator") {
41
-
42
- const xScale = (this.__config.width as number) * 0.72 / (maxLongitude - minLongitude)
43
- const yScale = (this.__config.height as number) * 0.575 / (maxLatitude - minLatitude)
44
-
45
- this.__map = new Mercator(xScale < yScale ? xScale : yScale, [
46
- (minLongitude + maxLongitude) * 0.5,
47
- (minLatitude + maxLatitude) * 0.5
48
- ])
49
-
50
- } else {
51
- throw new Error("Unexpected API types:" + this.__config.api)
52
- }
53
- }
54
-
55
- setConfig(config: MapConfigType) {
56
- mergeOption(this.__config, config)
57
- this.$$updateMap()
58
- return this
59
- }
60
-
61
- setGeos(...geos: any[]) {
62
- this.__boundary = getBoundary(...geos)
63
- this.$$updateMap()
64
- return this
65
- }
66
-
67
- use(λ: number, φ: number): [number, number] {
68
- if (this.__map) {
69
- const dxyz = this.__map.use(λ, φ)
70
- return [
71
- (this.__config.left as number) + (this.__config.width as number) * 0.5 + dxyz[0],
72
- (this.__config.top as number) + (this.__config.height as number) * 0.5 + dxyz[1],
73
- ]
74
- } else {
75
- throw new Error("Geographic data not set")
76
- }
77
- }
78
-
79
- }
80
-
1
+ import type MapConfigType from '../../types/MapConfig'
2
+ import type MapCoordinateType from '../../types/MapCoordinate'
3
+ import type MapType from '../../types/Map'
4
+
5
+ import { initOption, mergeOption } from '../common/option'
6
+ import getBoundary from '../common/map/getBoundary'
7
+ import Mercator from '../Mercator'
8
+ import Eoap from '../Eoap'
9
+
10
+ class MapCoordinate implements MapCoordinateType {
11
+ readonly name: string = 'MapCoordinate'
12
+
13
+ private __config: MapConfigType
14
+ private __map: MapType
15
+ private __boundary: Array<number>
16
+
17
+ constructor(config: MapConfigType = {}) {
18
+ this.__config = initOption(config, {
19
+ api: "Mercator",
20
+ width: 400,
21
+ height: 300,
22
+ left: 0,
23
+ top: 0
24
+ })
25
+ }
26
+
27
+ private $$updateMap() {
28
+ const [minLongitude, maxLongitude, minLatitude, maxLatitude] = this.__boundary
29
+
30
+ if (this.__config.api == "Eoap") {
31
+
32
+ const xScale = (this.__config.width as number) * 0.836 / (maxLongitude - minLongitude)
33
+ const yScale = (this.__config.height as number) * 0.557 / (maxLatitude - minLatitude)
34
+
35
+ this.__map = new Eoap(xScale < yScale ? xScale : yScale, [
36
+ (minLongitude + maxLongitude) * 0.5 * 0.9778,
37
+ (minLatitude + maxLatitude) * 0.5 * 1.025
38
+ ])
39
+
40
+ } else if (this.__config.api == "Mercator") {
41
+
42
+ const xScale = (this.__config.width as number) * 0.72 / (maxLongitude - minLongitude)
43
+ const yScale = (this.__config.height as number) * 0.575 / (maxLatitude - minLatitude)
44
+
45
+ this.__map = new Mercator(xScale < yScale ? xScale : yScale, [
46
+ (minLongitude + maxLongitude) * 0.5,
47
+ (minLatitude + maxLatitude) * 0.5
48
+ ])
49
+
50
+ } else {
51
+ throw new Error("Unexpected API types:" + this.__config.api)
52
+ }
53
+ }
54
+
55
+ setConfig(config: MapConfigType) {
56
+ mergeOption(this.__config, config)
57
+ this.$$updateMap()
58
+ return this
59
+ }
60
+
61
+ setGeos(...geos: any[]) {
62
+ this.__boundary = getBoundary(...geos)
63
+ this.$$updateMap()
64
+ return this
65
+ }
66
+
67
+ use(λ: number, φ: number): [number, number] {
68
+ if (this.__map) {
69
+ const dxyz = this.__map.use(λ, φ)
70
+ return [
71
+ (this.__config.left as number) + (this.__config.width as number) * 0.5 + dxyz[0],
72
+ (this.__config.top as number) + (this.__config.height as number) * 0.5 + dxyz[1],
73
+ ]
74
+ } else {
75
+ throw new Error("Geographic data not set")
76
+ }
77
+ }
78
+
79
+ }
80
+
81
81
  export default MapCoordinate
@@ -1,42 +1,42 @@
1
- // 获取一组循环色彩
2
- export default function (num: number, alpha: number = 1, colorsFactory?: (alpha: number) => Array<string>) {
3
- // 颜色集合
4
- const colorList = colorsFactory ? colorsFactory(alpha) : [
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, colorsFactory?: (alpha: number) => Array<string>) {
3
+ // 颜色集合
4
+ const colorList = colorsFactory ? colorsFactory(alpha) : [
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