vislite 0.4.0 → 0.4.1-alpha.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 (50) hide show
  1. package/CHANGELOG +10 -1
  2. package/README.md +1 -1
  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 +2 -2
  6. package/lib/Canvas/index.umd.min.js +2 -2
  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/Hermite/index.umd.js +2 -2
  12. package/lib/Hermite/index.umd.min.js +2 -2
  13. package/lib/Matrix4/index.umd.js +2 -2
  14. package/lib/Matrix4/index.umd.min.js +2 -2
  15. package/lib/Mercator/index.umd.js +2 -2
  16. package/lib/Mercator/index.umd.min.js +2 -2
  17. package/lib/OralCanvas/index.es.js +2 -2
  18. package/lib/OralCanvas/index.es.min.js +2 -2
  19. package/lib/OralWebGL/index.es.js +2 -2
  20. package/lib/OralWebGL/index.es.min.js +2 -2
  21. package/lib/SVG/index.umd.js +2 -2
  22. package/lib/SVG/index.umd.min.js +2 -2
  23. package/lib/Shader/index.umd.js +2 -2
  24. package/lib/Shader/index.umd.min.js +2 -2
  25. package/lib/Texture/index.umd.js +2 -2
  26. package/lib/Texture/index.umd.min.js +2 -2
  27. package/lib/WebGL/index.umd.js +3 -2
  28. package/lib/WebGL/index.umd.min.js +3 -3
  29. package/lib/animation/index.umd.js +2 -2
  30. package/lib/animation/index.umd.min.js +2 -2
  31. package/lib/getLoopColors/index.umd.js +2 -2
  32. package/lib/getLoopColors/index.umd.min.js +2 -2
  33. package/lib/getWebGLContext/index.umd.js +2 -2
  34. package/lib/getWebGLContext/index.umd.min.js +2 -2
  35. package/lib/index.umd.js +135 -57
  36. package/lib/index.umd.min.js +3 -3
  37. package/lib/rotate/index.umd.js +2 -2
  38. package/lib/rotate/index.umd.min.js +2 -2
  39. package/lib/ruler/index.umd.js +95 -32
  40. package/lib/ruler/index.umd.min.js +3 -3
  41. package/lib/viewHandler/index.umd.js +41 -27
  42. package/lib/viewHandler/index.umd.min.js +3 -3
  43. package/package.json +2 -2
  44. package/src/WebGL.ts +1 -0
  45. package/src/common/webgl/index.ts +1 -1
  46. package/src/ruler.ts +126 -37
  47. package/src/viewHandler.ts +45 -26
  48. package/types/ruler.d.ts +6 -1
  49. package/types/viewHandler.d.ts +2 -1
  50. package/uni-app/ui-canvas.vue +3 -3
package/src/ruler.ts CHANGED
@@ -1,7 +1,9 @@
1
1
  // 刻度尺刻度求解
2
2
 
3
+ import { rulerOptionType } from '../types/ruler'
4
+
3
5
  // 需要注意的是,实际的间距个数可能是 num-1 或 num 或 num+1 或 1
4
- export default function (maxValue: number, minValue: number, num: number) {
6
+ export default function (maxValue: number, minValue: number, num: number, option?: rulerOptionType) {
5
7
 
6
8
  // 如果最大值最小值反了
7
9
  if (maxValue < minValue) {
@@ -57,43 +59,130 @@ export default function (maxValue: number, minValue: number, num: number) {
57
59
 
58
60
 
59
61
  // 求解出 -100 ~ 100 的最佳间距值 后直接转换原来的倍数
60
- let distance100 = Math.ceil((maxValue - minValue) * times100 / num)
61
-
62
- // 校对一下
63
- distance100 = {
64
- 3: 2,
65
- 4: 5,
66
- 6: 5,
67
- 7: 5,
68
- 8: 10,
69
- 9: 10,
70
- 11: 10,
71
- 12: 10,
72
- 13: 15,
73
- 14: 15,
74
- 16: 15,
75
- 17: 15,
76
- 18: 20,
77
- 19: 20,
78
- 21: 20,
79
- 22: 20,
80
- 23: 25,
81
- 24: 25,
82
- 26: 25,
83
- 27: 25
84
- }[distance100] || distance100
85
-
86
- let distance = distance100 / times100
87
-
88
- // 最小值,也就是起点
89
- let begin = Math.floor(minValue / distance) * distance
90
-
91
- let rulerArray = []
92
- // 获取最终的刻度尺数组
93
- rulerArray.push(begin)
94
- for (let index = 1; rulerArray[rulerArray.length - 1] < maxValue; index++) {
95
- rulerArray.push(begin + distance * index)
62
+ let distance100_oral = Math.ceil((maxValue - minValue) * times100 / num)
63
+
64
+ let getResult = (changValue: number) => {
65
+ // 校对一下
66
+ let 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
+ let distance = distance100 / times100
90
+
91
+ // 最小值,也就是起点
92
+ let begin = Math.floor(minValue / distance) * distance
93
+
94
+ let 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
96
102
  }
97
103
 
104
+ let rulerArray = getResult(0)
105
+
106
+ let balanceMax = () => {
107
+ let rulerArray_temp = []
108
+
109
+ let changeDist = rulerArray[rulerArray.length - 1] - option.max
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
+ let balanceMin = () => {
122
+ let rulerArray_temp = []
123
+
124
+ let changeDist = rulerArray[0] - option.min
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 >= maxValue && option.min <= minValue) {
137
+
138
+ let isAnswer = () => {
139
+
140
+ // 先判断原始的是否可行
141
+ if (rulerArray[0] >= option.min && rulerArray[rulerArray.length - 1] <= option.max) return true
142
+
143
+ // 再判断max调整是否可行
144
+ let rulerArray_max = balanceMax()
145
+ if (rulerArray_max[0] >= option.min && rulerArray_max[rulerArray_max.length - 1] <= option.max) {
146
+ rulerArray = rulerArray_max
147
+ return true
148
+ }
149
+
150
+ // 再判断max调整是否可行
151
+ let rulerArray_min = balanceMin()
152
+ if (rulerArray_min[0] >= option.min && rulerArray_min[rulerArray_max.length - 1] <= option.max) {
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 >= maxValue) {
174
+
175
+ // 上越界了
176
+ if (option.max < rulerArray[rulerArray.length - 1]) {
177
+ rulerArray = balanceMax()
178
+ }
179
+ } else if ('min' in option && option.min <= minValue) {
180
+
181
+ // 下越界了
182
+ if (option.min > rulerArray[0]) {
183
+ rulerArray = balanceMin()
184
+ }
185
+ }
186
+ }
98
187
  return rulerArray
99
188
  }
@@ -30,7 +30,8 @@ export default function (callback: callbackFun) {
30
30
  callback({
31
31
  type: "lookUp",
32
32
  normal: [],
33
- value: 0.1
33
+ value: 0.1,
34
+ event
34
35
  })
35
36
  }
36
37
 
@@ -39,7 +40,8 @@ export default function (callback: callbackFun) {
39
40
  callback({
40
41
  type: "lookDown",
41
42
  normal: [],
42
- value: 0.1
43
+ value: 0.1,
44
+ event
43
45
  })
44
46
  }
45
47
 
@@ -48,7 +50,8 @@ export default function (callback: callbackFun) {
48
50
  callback({
49
51
  type: "lookLeft",
50
52
  normal: [],
51
- value: 0.1
53
+ value: 0.1,
54
+ event
52
55
  })
53
56
  }
54
57
 
@@ -57,7 +60,8 @@ export default function (callback: callbackFun) {
57
60
  callback({
58
61
  type: "lookRight",
59
62
  normal: [],
60
- value: 0.1
63
+ value: 0.1,
64
+ event
61
65
  })
62
66
  }
63
67
 
@@ -66,30 +70,44 @@ export default function (callback: callbackFun) {
66
70
  // 鼠标控制
67
71
  let mouseP = null;
68
72
  let doMove = function (event) {
69
- if (mouseP == null) return
70
73
 
71
- let tempMouseP = mousePosition(el, event)
74
+ // 单纯移动
75
+ if (mouseP == null) {
76
+ callback({
77
+ type: "hover",
78
+ normal: [],
79
+ value: 0,
80
+ event
81
+ })
82
+ }
72
83
 
73
- // 先求解出轨迹向量
74
- let normal = [tempMouseP.x - mouseP.x, tempMouseP.y - mouseP.y]
84
+ // 按下移动
85
+ else {
75
86
 
76
- // 方向向量旋转90deg得到旋转向量
77
- let rotateNormal = [
78
- normal[1],
79
- normal[0],
80
- 0
81
- ]
87
+ let tempMouseP = mousePosition(el, event)
82
88
 
83
- // 非法射线忽略
84
- if (rotateNormal[0] == 0 && rotateNormal[1] == 0) return
89
+ // 先求解出轨迹向量
90
+ let normal = [tempMouseP.x - mouseP.x, tempMouseP.y - mouseP.y]
85
91
 
86
- callback({
87
- type: "rotate",
88
- normal: rotateNormal,
89
- value: (Math.abs(tempMouseP.x - mouseP.x) + Math.abs(tempMouseP.y - mouseP.y)) * 0.01
90
- })
92
+ // 方向向量旋转90deg得到旋转向量
93
+ let rotateNormal = [
94
+ normal[1],
95
+ normal[0],
96
+ 0
97
+ ]
91
98
 
92
- mouseP = tempMouseP
99
+ // 非法射线忽略
100
+ if (rotateNormal[0] == 0 && rotateNormal[1] == 0) return
101
+
102
+ callback({
103
+ type: "rotate",
104
+ normal: rotateNormal,
105
+ value: (Math.abs(tempMouseP.x - mouseP.x) + Math.abs(tempMouseP.y - mouseP.y)) * 0.01,
106
+ event
107
+ })
108
+
109
+ mouseP = tempMouseP
110
+ }
93
111
  }
94
112
 
95
113
  el.addEventListener("mousedown", (event) => {
@@ -113,27 +131,28 @@ export default function (callback: callbackFun) {
113
131
  doMove(event.touches[0])
114
132
  })
115
133
 
116
- let doScale = function (value: number) {
134
+ let doScale = function (value: number, event: Event) {
117
135
  if (value == 0) return
118
136
 
119
137
  let baseTimes = 0.899
120
138
  callback({
121
139
  type: "scale",
122
140
  value: value < 0 ? baseTimes : 2 - baseTimes,
123
- normal: []
141
+ normal: [],
142
+ event
124
143
  })
125
144
  }
126
145
 
127
146
  // 滚轮控制
128
147
  el.addEventListener("mousewheel", function (event: any) {
129
- doScale(event.wheelDelta)
148
+ doScale(event.wheelDelta, event)
130
149
  })
131
150
 
132
151
  if (window.addEventListener) {
133
152
 
134
153
  // 针对火狐浏览器
135
154
  window.addEventListener('DOMMouseScroll', function (event: any) {
136
- doScale(-1 * event.detail)
155
+ doScale(-1 * event.detail, event)
137
156
  }, false)
138
157
  }
139
158
 
package/types/ruler.d.ts CHANGED
@@ -1,3 +1,8 @@
1
+ export interface rulerOptionType {
2
+ max?: number
3
+ min?: number
4
+ }
5
+
1
6
  export default interface rulerType {
2
- (maxValue: number, minValue: number, num: number): number[]
7
+ (maxValue: number, minValue: number, num: number, option: rulerOptionType): number[]
3
8
  }
@@ -1,7 +1,8 @@
1
1
  export interface paramsType {
2
2
  type: string
3
3
  value: number,
4
- normal: number[]
4
+ normal: number[],
5
+ event: Event
5
6
  }
6
7
 
7
8
  export interface callbackFun {
@@ -112,9 +112,9 @@ export default {
112
112
  },
113
113
  }
114
114
  );
115
- this.help.instance.draw = () => {
116
- painter.draw();
117
- region.draw();
115
+ this.help.instance.draw = (reserve = false, callback = () => { }) => {
116
+ painter.draw(reserve, callback);
117
+ region.draw(reserve, callback);
118
118
 
119
119
  // 如果不使用原生渲染
120
120
  if (!this.cover && !this.isH5) {