vislite 0.2.0-alpha.7 → 0.2.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 (42) hide show
  1. package/CHANGELOG +2 -1
  2. package/README.md +1 -1
  3. package/lib/Canvas/index.umd.js +2 -6
  4. package/lib/Canvas/index.umd.min.js +2 -6
  5. package/lib/Cardinal/index.umd.js +2 -6
  6. package/lib/Cardinal/index.umd.min.js +2 -6
  7. package/lib/Eoap/index.umd.js +2 -6
  8. package/lib/Eoap/index.umd.min.js +2 -6
  9. package/lib/Hermite/index.umd.js +2 -6
  10. package/lib/Hermite/index.umd.min.js +2 -6
  11. package/lib/Matrix4/index.umd.js +2 -6
  12. package/lib/Matrix4/index.umd.min.js +2 -6
  13. package/lib/Mercator/index.umd.js +2 -6
  14. package/lib/Mercator/index.umd.min.js +2 -6
  15. package/lib/OralCanvas/index.es.js +2 -6
  16. package/lib/OralCanvas/index.es.min.js +2 -6
  17. package/lib/OralWebGL/index.es.js +6 -9
  18. package/lib/OralWebGL/index.es.min.js +3 -7
  19. package/lib/SVG/index.umd.js +2 -6
  20. package/lib/SVG/index.umd.min.js +2 -6
  21. package/lib/WebGL/index.umd.js +6 -9
  22. package/lib/WebGL/index.umd.min.js +3 -7
  23. package/lib/animation/index.umd.js +2 -6
  24. package/lib/animation/index.umd.min.js +2 -6
  25. package/lib/getLoopColors/index.umd.js +2 -6
  26. package/lib/getLoopColors/index.umd.min.js +2 -6
  27. package/lib/index.umd.js +8 -11
  28. package/lib/index.umd.min.js +3 -7
  29. package/lib/rotate/index.umd.js +2 -6
  30. package/lib/rotate/index.umd.min.js +2 -6
  31. package/lib/ruler/index.umd.js +2 -6
  32. package/lib/ruler/index.umd.min.js +2 -6
  33. package/lib/viewHandler/index.umd.js +4 -8
  34. package/lib/viewHandler/index.umd.min.js +3 -7
  35. package/package.json +1 -1
  36. package/src/common/webgl/getShader.ts +9 -1
  37. package/src/common/webgl/index.ts +4 -3
  38. package/src/common/webgl/texture.ts +1 -0
  39. package/src/viewHandler.ts +2 -2
  40. package/types/Object3D.d.ts +3 -2
  41. package/types/WebGL.d.ts +10 -0
  42. package/uni-app/ui-canvas.vue +43 -40
@@ -1,16 +1,12 @@
1
1
  /*!
2
- * VISLite JavaScript Library v0.2.0-alpha.7
2
+ * VISLite JavaScript Library v0.2.0
3
3
  * git+https://github.com/oi-contrib/VISLite.git
4
4
  *
5
5
  * Copyright zxl20070701
6
6
  * Released under the MIT license
7
7
  * https://zxl20070701.github.io/notebook/home.html
8
8
  *
9
- * 本版本系测试版本,请认真阅读下述说明再使用:
10
- *
11
- *【测试版本细则】
12
- * alpha:内测版本,仅供开发人员提供测试环境而发布,后续的修改可能极具破坏性,非有明确了解前请勿直接用于项目中
13
- * beta:外测版本,正式发布前的确认测试,或者新功能紧急发布,一般可以直接用于实际项目,因为即使后续发现了问题,直接使用正式版即可,不会有破坏性
9
+ * Publish Date: Sat Jun 03 2023 09:32:28 GMT+0800 (中国标准时间)
14
10
  */
15
11
  (function (global, factory) {
16
12
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
@@ -71,10 +67,10 @@
71
67
  if (mouseP == null)
72
68
  return;
73
69
  var tempMouseP = mousePosition(el, event);
74
- var normal = [tempMouseP.x - mouseP.x, mouseP.y - tempMouseP.y];
70
+ var normal = [tempMouseP.x - mouseP.x, tempMouseP.y - mouseP.y];
75
71
  var rotateNormal = [
76
72
  normal[1],
77
- normal[0] * -1,
73
+ normal[0],
78
74
  0
79
75
  ];
80
76
  if (rotateNormal[0] == 0 && rotateNormal[1] == 0)
@@ -1,15 +1,11 @@
1
1
  /*!
2
- * VISLite JavaScript Library v0.2.0-alpha.7
2
+ * VISLite JavaScript Library v0.2.0
3
3
  * git+https://github.com/oi-contrib/VISLite.git
4
4
  *
5
5
  * Copyright zxl20070701
6
6
  * Released under the MIT license
7
7
  * https://zxl20070701.github.io/notebook/home.html
8
8
  *
9
- * 本版本系测试版本,请认真阅读下述说明再使用:
10
- *
11
- *【测试版本细则】
12
- * alpha:内测版本,仅供开发人员提供测试环境而发布,后续的修改可能极具破坏性,非有明确了解前请勿直接用于项目中
13
- * beta:外测版本,正式发布前的确认测试,或者新功能紧急发布,一般可以直接用于实际项目,因为即使后续发现了问题,直接使用正式版即可,不会有破坏性
9
+ * Publish Date: Sat Jun 03 2023 09:32:28 GMT+0800 (中国标准时间)
14
10
  */
15
- var e,n;e=this,n=function(){"use strict";var e=function(e,n){var t=e.getBoundingClientRect();return{x:n.clientX-t.left,y:n.clientY-t.top}};return function(n){var t=document.getElementsByTagName("body")[0];t.addEventListener("keydown",(function(e){var t=function(e){return{37:"left",38:"up",39:"right",40:"down"}[e.keyCode||e.which]}(e);"up"==t?n({type:"lookUp",normal:[],value:.1}):"down"==t?n({type:"lookDown",normal:[],value:.1}):"left"==t?n({type:"lookLeft",normal:[],value:.1}):"right"==t&&n({type:"lookRight",normal:[],value:.1})}));var o=null,i=function(i){if(null!=o){var u=e(t,i),l=[u.x-o.x,o.y-u.y],a=[l[1],-1*l[0],0];0==a[0]&&0==a[1]||(n({type:"rotate",normal:a,value:.01*(Math.abs(u.x-o.x)+Math.abs(u.y-o.y))}),o=u)}};t.addEventListener("mousedown",(function(n){o=e(t,n)})),t.addEventListener("mouseup",(function(e){o=null})),t.addEventListener("mousemove",(function(e){i(e)})),t.addEventListener("touchend",(function(e){o=null})),t.addEventListener("touchstart",(function(n){o=e(t,n)})),t.addEventListener("touchmove",(function(e){i(e.touches[0])}));var u=function(e){0!=e&&n({type:"scale",value:e<0?.899:1.101,normal:[]})};t.addEventListener("mousewheel",(function(e){u(e.wheelDelta)})),window.addEventListener&&window.addEventListener("DOMMouseScroll",(function(e){u(-1*e.detail)}),!1)}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).VISLite_viewHandler=n();
11
+ var e,n;e=this,n=function(){"use strict";var e=function(e,n){var t=e.getBoundingClientRect();return{x:n.clientX-t.left,y:n.clientY-t.top}};return function(n){var t=document.getElementsByTagName("body")[0];t.addEventListener("keydown",(function(e){var t=function(e){return{37:"left",38:"up",39:"right",40:"down"}[e.keyCode||e.which]}(e);"up"==t?n({type:"lookUp",normal:[],value:.1}):"down"==t?n({type:"lookDown",normal:[],value:.1}):"left"==t?n({type:"lookLeft",normal:[],value:.1}):"right"==t&&n({type:"lookRight",normal:[],value:.1})}));var o=null,i=function(i){if(null!=o){var u=e(t,i),l=[u.x-o.x,u.y-o.y],a=[l[1],l[0],0];0==a[0]&&0==a[1]||(n({type:"rotate",normal:a,value:.01*(Math.abs(u.x-o.x)+Math.abs(u.y-o.y))}),o=u)}};t.addEventListener("mousedown",(function(n){o=e(t,n)})),t.addEventListener("mouseup",(function(e){o=null})),t.addEventListener("mousemove",(function(e){i(e)})),t.addEventListener("touchend",(function(e){o=null})),t.addEventListener("touchstart",(function(n){o=e(t,n)})),t.addEventListener("touchmove",(function(e){i(e.touches[0])}));var u=function(e){0!=e&&n({type:"scale",value:e<0?.899:1.101,normal:[]})};t.addEventListener("mousewheel",(function(e){u(e.wheelDelta)})),window.addEventListener&&window.addEventListener("DOMMouseScroll",(function(e){u(-1*e.detail)}),!1)}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).VISLite_viewHandler=n();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vislite",
3
- "version": "0.2.0-alpha.7",
3
+ "version": "0.2.0",
4
4
  "description": "灵活、快速、简单的数据可视化交互式跨端前端库",
5
5
  "main": "./lib/index.umd.min.js",
6
6
  "typings": "./types/index.d.ts",
@@ -25,12 +25,20 @@ export default function (type: string, painter: WebGLRenderingContext, mesh: mes
25
25
  ${mesh.material.image ? 'attribute vec2 a_textcoord;varying vec2 v_textcoord;' : ''}
26
26
 
27
27
  void main(){
28
- vec4 temp = u_matrix_proporion * u_matrix_world * u_matrix_mesh * a_position;
28
+ vec4 temp = a_position;
29
+
30
+ // 应用变换矩阵:屏幕比调平矩阵、世界矩阵、物体矩阵
31
+ temp = u_matrix_proporion * u_matrix_world * u_matrix_mesh * temp;
32
+
33
+ // 把原生的WebGL使用的左手坐标系变成了右手坐标系
34
+ temp.z = -1.0 * temp.z;
29
35
 
30
36
  // 表示眼睛距离vec4(0.0,0.0,1.0)的距离
31
37
  float dist = 4.0;
32
38
 
33
39
  // 使用投影直接计算
40
+ // 为保证纹理和相对位置正确
41
+ // x、y、z的改变满足线性变换
34
42
  gl_Position = vec4((dist + 1.0) * temp.x, (dist + 1.0) * temp.y, dist * (dist + temp.z) + 1.0 - dist * dist, temp.w * 2.0 * (dist + temp.z));
35
43
 
36
44
  ${mesh.geometry.attributes.normal ? 'v_normal = normalize(vec3(a_normal));' : ''}
@@ -2,7 +2,7 @@ import getWebGLContext from './getWebGLContext'
2
2
  import Object3DType from '../../../types/Object3D'
3
3
  import Scene3DType from '../../../types/Scene3D'
4
4
  import getColorFactory from './getColorFactory'
5
- import Matrix4 from '../../Matrix4/index'
5
+ import Matrix4 from '..//../Matrix4/index'
6
6
  import doDraw from './doDraw'
7
7
  import assemble from '../assemble'
8
8
 
@@ -32,7 +32,7 @@ class WebGL {
32
32
  matrix: new Matrix4([
33
33
  1, 0, 0, 0,
34
34
  0, 1, 0, 0,
35
- 0, 0, -1, 0,
35
+ 0, 0, 1, 0,
36
36
  0, 0, 0, scale
37
37
  ])
38
38
  }
@@ -131,13 +131,14 @@ class WebGL {
131
131
  }
132
132
  }
133
133
  }, meshWorld, globalWorld)
134
+
135
+ this.__getColor = getColorFactory(this.__regionPainter)
134
136
  } else {
135
137
  // 画布上
136
138
  doDraw("region" + this.__unique, this.painter, object3D.mesh[index], meshWorld, globalWorld)
137
139
  }
138
140
  }
139
141
 
140
- this.__getColor = getColorFactory(this.__regionPainter)
141
142
  }
142
143
 
143
144
  render(object3D: Object3DType) {
@@ -78,6 +78,7 @@ class TextureObject {
78
78
 
79
79
  // 配置纹理
80
80
  painter.texParameteri(this.__type, painter.TEXTURE_MIN_FILTER, painter.NEAREST)
81
+ painter.texParameteri(this.__type, painter.TEXTURE_MAG_FILTER, painter.NEAREST)
81
82
  painter.texParameteri(this.__type, painter.TEXTURE_WRAP_S, painter.CLAMP_TO_EDGE)
82
83
  painter.texParameteri(this.__type, painter.TEXTURE_WRAP_T, painter.CLAMP_TO_EDGE)
83
84
  }
@@ -71,12 +71,12 @@ export default function (callback: callbackFun) {
71
71
  let tempMouseP = mousePosition(el, event)
72
72
 
73
73
  // 先求解出轨迹向量
74
- let normal = [tempMouseP.x - mouseP.x, mouseP.y - tempMouseP.y]
74
+ let normal = [tempMouseP.x - mouseP.x, tempMouseP.y - mouseP.y]
75
75
 
76
76
  // 方向向量旋转90deg得到旋转向量
77
77
  let rotateNormal = [
78
78
  normal[1],
79
- normal[0] * -1,
79
+ normal[0],
80
80
  0
81
81
  ]
82
82
 
@@ -37,7 +37,8 @@ export interface meshType {
37
37
  }
38
38
 
39
39
  // 点、线、还是三角形
40
- type: string // "POINTS" | "LINES" | "INE_STRIP" | "LINE_LOOP" | "TRIANGLES" | "TRIANGLE_STRIP" | "TRIANGLE_FAN"
40
+ // "POINTS" | "LINES" | "INE_STRIP" | "LINE_LOOP" | "TRIANGLES" | "TRIANGLE_STRIP" | "TRIANGLE_FAN"
41
+ type: string
41
42
  }
42
43
 
43
44
  // 材质
@@ -95,7 +96,7 @@ export interface meshType {
95
96
 
96
97
  export default interface Object3D {
97
98
 
98
- // 区域名称,如果设置为空字符串,表示此区域无需记录
99
+ // 区域名称,不设置或设置为空字符串,表示此区域无需记录
99
100
  region?: string
100
101
 
101
102
  // 变换矩阵
package/types/WebGL.d.ts CHANGED
@@ -26,4 +26,14 @@ export default interface WebGLType {
26
26
  */
27
27
  getObject3D(): Object3DType[]
28
28
 
29
+ /**
30
+ * 设置区域
31
+ */
32
+ setRegion(regionName: string | number): this
33
+
34
+ /**
35
+ * 获取区域
36
+ */
37
+ getRegion(x: number, y: number): Promise<string>
38
+
29
39
  }
@@ -57,10 +57,10 @@ export default {
57
57
  help: {},
58
58
  viewImg: "",
59
59
  // #ifdef H5
60
- isH5: true
60
+ isH5: true,
61
61
  // #endif
62
62
  // #ifndef H5
63
- isH5: false
63
+ isH5: false,
64
64
  // #endif
65
65
  };
66
66
  },
@@ -75,26 +75,27 @@ export default {
75
75
  },
76
76
  touchstart: {
77
77
  type: Function,
78
- default: () => { },
78
+ default: () => {},
79
79
  },
80
80
  cover: {
81
81
  type: Boolean,
82
- default: true
83
- }
82
+ default: true,
83
+ },
84
84
  },
85
85
  methods: {
86
86
  fetch() {
87
+ let painter, region, painterid, regionid;
87
88
  // #ifdef MP-WEIXIN
88
- let painter = uni.createCanvasContext("painter", this);
89
- let region = uni.createCanvasContext("region", this);
90
- let painterid = "painter";
91
- let regionid = "region";
89
+ painter = uni.createCanvasContext("painter", this);
90
+ region = uni.createCanvasContext("region", this);
91
+ painterid = "painter";
92
+ regionid = "region";
92
93
  // #endif
93
94
  // #ifndef MP-WEIXIN
94
- let painter = uni.createCanvasContext("painter-" + this.uniqueid, this);
95
- let region = uni.createCanvasContext("region-" + this.uniqueid, this);
96
- let painterid = "painter-" + this.uniqueid;
97
- let regionid = "region-" + this.uniqueid;
95
+ painter = uni.createCanvasContext("painter-" + this.uniqueid, this);
96
+ region = uni.createCanvasContext("region-" + this.uniqueid, this);
97
+ painterid = "painter-" + this.uniqueid;
98
+ regionid = "region-" + this.uniqueid;
98
99
  // #endif
99
100
 
100
101
  let _this = this;
@@ -106,6 +107,9 @@ export default {
106
107
  },
107
108
  {
108
109
  getContext() {
110
+ // #ifdef MP-ALIPAY
111
+ let getImageData = region.getImageData;
112
+ // #endif
109
113
  region.getImageData = (x, y, width, height) => {
110
114
  return new Promise((resolve, reject) => {
111
115
  let options = {
@@ -123,7 +127,7 @@ export default {
123
127
  };
124
128
 
125
129
  // #ifdef MP-ALIPAY
126
- region.getImageData(options, _this);
130
+ getImageData(options, _this);
127
131
  // #endif
128
132
  // #ifndef MP-ALIPAY
129
133
  uni.canvasGetImageData(options, _this);
@@ -140,14 +144,16 @@ export default {
140
144
 
141
145
  // 如果不使用原生渲染
142
146
  if (!this.cover && !this.isH5) {
143
- uni.canvasToTempFilePath({
144
- canvasId: painterid,
145
- success: (e) => {
146
- this.viewImg = e.tempFilePath;
147
- }
148
- }, this);
147
+ uni.canvasToTempFilePath(
148
+ {
149
+ canvasId: painterid,
150
+ success: (e) => {
151
+ this.viewImg = e.tempFilePath;
152
+ },
153
+ },
154
+ this
155
+ );
149
156
  }
150
-
151
157
  };
152
158
  return new Promise((resolve, reject) => {
153
159
  this.help.instance.toDataURL = () => {
@@ -171,7 +177,7 @@ export default {
171
177
  let doRun = (x, y) => {
172
178
  this.help.instance.getRegion(x, y).then((regionName) => {
173
179
  // 兼容旧语法
174
- if (doback) doback(regionName);
180
+ if (typeof doback == "function") doback(regionName);
175
181
 
176
182
  this.$emit("dotouchstart", {
177
183
  name: regionName,
@@ -182,30 +188,27 @@ export default {
182
188
  };
183
189
 
184
190
  if (this.cover || this.isH5) {
185
-
186
- // #ifdef MP-ALIPAY
191
+ let x = event.touches[0].x;
192
+ let y = event.touches[0].y;
193
+ doRun(x, y);
194
+ } else {
187
195
  uni
188
196
  .createSelectorQuery()
189
197
  .selectViewport()
190
198
  .scrollOffset()
191
199
  .exec((ret) => {
192
- let x = event.touches[0].x + ret[0].scrollLeft;
193
- let y = event.touches[0].y + ret[0].scrollTop;
194
- doRun(x, y);
200
+ uni
201
+ .createSelectorQuery()
202
+ .in(this)
203
+ .select(".view-" + this.uniqueid)
204
+ .boundingClientRect((data) => {
205
+ doRun(
206
+ event.touches[0].pageX - data.left - ret[0].scrollLeft,
207
+ event.touches[0].pageY - data.top - ret[0].scrollTop
208
+ );
209
+ })
210
+ .exec();
195
211
  });
196
- // #endif
197
- // #ifndef MP-ALIPAY
198
- let x = event.touches[0].x;
199
- let y = event.touches[0].y;
200
- doRun(x, y);
201
- // #endif
202
-
203
- } else {
204
-
205
- uni.createSelectorQuery().in(this).select('.view-' + this.uniqueid).boundingClientRect(data => {
206
- doRun(event.touches[0].pageX - data.left, event.touches[0].pageY - data.top);
207
- }).exec()
208
-
209
212
  }
210
213
  },
211
214
  doitstart(event) {