vislite 0.7.0-alpha.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.
- package/CHANGELOG +8 -3
- package/README.md +20 -1
- package/lib/Buffer/index.umd.js +2 -2
- package/lib/Buffer/index.umd.min.js +2 -2
- package/lib/Canvas/index.umd.js +4 -4
- package/lib/Canvas/index.umd.min.js +3 -3
- package/lib/Cardinal/index.umd.js +2 -2
- package/lib/Cardinal/index.umd.min.js +2 -2
- package/lib/Eoap/index.umd.js +2 -2
- package/lib/Eoap/index.umd.min.js +2 -2
- package/lib/Geometry/index.umd.js +69 -8
- package/lib/Geometry/index.umd.min.js +3 -3
- package/lib/Hermite/index.umd.js +2 -2
- package/lib/Hermite/index.umd.min.js +2 -2
- package/lib/Matrix4/index.umd.js +2 -2
- package/lib/Matrix4/index.umd.min.js +2 -2
- package/lib/Mercator/index.umd.js +2 -2
- package/lib/Mercator/index.umd.min.js +2 -2
- package/lib/OralCanvas/index.es.js +3 -3
- package/lib/OralCanvas/index.es.min.js +3 -3
- package/lib/OralWebGL/index.es.js +21 -18
- package/lib/OralWebGL/index.es.min.js +3 -3
- package/lib/SVG/index.umd.js +2 -2
- package/lib/SVG/index.umd.min.js +2 -2
- package/lib/Shader/index.umd.js +3 -2
- package/lib/Shader/index.umd.min.js +3 -3
- package/lib/Texture/index.umd.js +2 -2
- package/lib/Texture/index.umd.min.js +2 -2
- package/lib/TreeLayout/index.umd.js +13 -11
- package/lib/TreeLayout/index.umd.min.js +3 -3
- package/lib/WebGL/index.umd.js +22 -19
- package/lib/WebGL/index.umd.min.js +3 -3
- package/lib/animation/index.umd.js +2 -2
- package/lib/animation/index.umd.min.js +2 -2
- package/lib/formatColor/index.umd.js +2 -2
- package/lib/formatColor/index.umd.min.js +2 -2
- package/lib/getLoopColors/index.umd.js +2 -2
- package/lib/getLoopColors/index.umd.min.js +2 -2
- package/lib/getWebGLContext/index.umd.js +4 -4
- package/lib/getWebGLContext/index.umd.min.js +3 -3
- package/lib/index.umd.js +104 -38
- package/lib/index.umd.min.js +3 -3
- package/lib/move/index.umd.js +2 -2
- package/lib/move/index.umd.min.js +2 -2
- package/lib/resizeObserver/index.umd.js +2 -2
- package/lib/resizeObserver/index.umd.min.js +2 -2
- package/lib/rotate/index.umd.js +2 -2
- package/lib/rotate/index.umd.min.js +2 -2
- package/lib/ruler/index.umd.js +4 -4
- package/lib/ruler/index.umd.min.js +3 -3
- package/lib/scale/index.umd.js +2 -2
- package/lib/scale/index.umd.min.js +2 -2
- package/lib/throttle/index.umd.js +2 -2
- package/lib/throttle/index.umd.min.js +2 -2
- package/lib/viewHandler/index.umd.js +2 -2
- package/lib/viewHandler/index.umd.min.js +2 -2
- package/package.json +1 -1
- package/src/Canvas.ts +70 -70
- package/src/Geometry.ts +126 -82
- package/src/Matrix4/rotate.ts +15 -15
- package/src/Matrix4/transform.ts +64 -64
- package/src/WebGL.ts +66 -66
- package/src/common/assemble.ts +22 -22
- package/src/common/canvas/index.ts +177 -177
- package/src/common/canvas/painter.ts +419 -417
- package/src/common/geometry/prism-vertical.ts +40 -40
- package/src/common/geometry/tool/rotateLine.ts +36 -0
- package/src/common/setStyle.ts +5 -5
- package/src/common/svg/config.ts +190 -186
- package/src/common/svg/tool.ts +44 -44
- package/src/common/tree/toInnerTree.ts +59 -57
- package/src/common/tree/toPlainTree.ts +132 -132
- package/src/common/webgl/buffer.ts +79 -79
- package/src/common/webgl/doDraw.ts +108 -108
- package/src/common/webgl/getWebGLContext.ts +28 -28
- package/src/common/webgl/index.ts +226 -224
- package/src/common/webgl/shader.ts +75 -75
- package/src/common/webgl/texture.ts +97 -97
- package/src/layout/TreeLayout.ts +188 -186
- package/src/resizeObserver.ts +37 -37
- package/src/ruler.ts +209 -209
- package/src/viewHandler.ts +160 -158
- package/types/Canvas.d.ts +308 -308
- package/types/Geometry.d.ts +65 -40
- package/types/TreeConfig.d.ts +36 -24
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* VISLite JavaScript Library v0.7.0
|
|
2
|
+
* VISLite JavaScript Library v0.7.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
|
-
* Publish Date:
|
|
9
|
+
* Publish Date: Sun Jan 14 2024 15:48:51 GMT+0800 (中国标准时间)
|
|
10
10
|
*/
|
|
11
11
|
var e,r;e=this,r=function(){"use strict";var e,r={},n=0;return function(o,t){try{return e||(e=new ResizeObserver((function(e){for(var n=0,o=e;n<o.length;n++){var t=o[n];r[t.target._resize_observer_]()}}))),n++,o._resize_observer_=n,r[n]=t,e.observe(o),function(){e&&(e.unobserve(o),delete r[o._resize_observer_])}}catch(e){t(),console.error("ResizeObserver undefined!")}}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(e="undefined"!=typeof globalThis?globalThis:e||self).VISLite_resizeObserver=r();
|
package/lib/rotate/index.umd.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* VISLite JavaScript Library v0.7.0
|
|
2
|
+
* VISLite JavaScript Library v0.7.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
|
-
* Publish Date:
|
|
9
|
+
* Publish Date: Sun Jan 14 2024 15:48:51 GMT+0800 (中国标准时间)
|
|
10
10
|
*/
|
|
11
11
|
(function (global, factory) {
|
|
12
12
|
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* VISLite JavaScript Library v0.7.0
|
|
2
|
+
* VISLite JavaScript Library v0.7.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
|
-
* Publish Date:
|
|
9
|
+
* Publish Date: Sun Jan 14 2024 15:48:51 GMT+0800 (中国标准时间)
|
|
10
10
|
*/
|
|
11
11
|
var e,t;e=this,t=function(){"use strict";return function(e,t,n,o,i){var f=Math.cos(n),d=Math.sin(n);return[(o-e)*f-(i-t)*d+e,(o-e)*d+(i-t)*f+t]}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).VISLite_rotate=t();
|
package/lib/ruler/index.umd.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* VISLite JavaScript Library v0.7.0
|
|
2
|
+
* VISLite JavaScript Library v0.7.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
|
-
* Publish Date:
|
|
9
|
+
* Publish Date: Sun Jan 14 2024 15:48:51 GMT+0800 (中国标准时间)
|
|
10
10
|
*/
|
|
11
11
|
(function (global, factory) {
|
|
12
12
|
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
|
@@ -80,7 +80,7 @@
|
|
|
80
80
|
var rulerArray = getResult(0);
|
|
81
81
|
var balanceMax = function () {
|
|
82
82
|
var rulerArray_temp = [];
|
|
83
|
-
var changeDist = rulerArray[rulerArray.length - 1] - option.max;
|
|
83
|
+
var changeDist = rulerArray[rulerArray.length - 1] - (option === null || option === void 0 ? void 0 : option.max);
|
|
84
84
|
for (var index = 0; index < rulerArray.length; index++) {
|
|
85
85
|
if (index + 1 < rulerArray.length && rulerArray[index + 1] - changeDist < minValue) ;
|
|
86
86
|
else {
|
|
@@ -91,7 +91,7 @@
|
|
|
91
91
|
};
|
|
92
92
|
var balanceMin = function () {
|
|
93
93
|
var rulerArray_temp = [];
|
|
94
|
-
var changeDist = rulerArray[0] - option.min;
|
|
94
|
+
var changeDist = rulerArray[0] - (option === null || option === void 0 ? void 0 : option.min);
|
|
95
95
|
for (var index = 0; index < rulerArray.length; index++) {
|
|
96
96
|
rulerArray_temp[index] = rulerArray[index] - changeDist;
|
|
97
97
|
if (maxValue <= rulerArray_temp[index])
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* VISLite JavaScript Library v0.7.0
|
|
2
|
+
* VISLite JavaScript Library v0.7.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
|
-
* Publish Date:
|
|
9
|
+
* Publish Date: Sun Jan 14 2024 15:48:51 GMT+0800 (中国标准时间)
|
|
10
10
|
*/
|
|
11
|
-
var n,e;n=this,e=function(){"use strict";return function(n,e,r,t){if(n<e){var i=e;e=n,n=i}else if(n==e)return[n];var f=function(n){for(var e=n<100&&n>-100?10:.1,r=-1,t=n;10==e?t>=-100&&t<=100:t<=-100||t>=100;)r+=1,t*=e;if(10==e)return Math.pow(10,r);for(var i="0.",f=1;f<r;f++)i+="0";return+(i+"1")}(n-e),
|
|
11
|
+
var n,e;n=this,e=function(){"use strict";return function(n,e,r,t){if(n<e){var i=e;e=n,n=i}else if(n==e)return[n];var f=function(n){for(var e=n<100&&n>-100?10:.1,r=-1,t=n;10==e?t>=-100&&t<=100:t<=-100||t>=100;)r+=1,t*=e;if(10==e)return Math.pow(10,r);for(var i="0.",f=1;f<r;f++)i+="0";return+(i+"1")}(n-e),u=Math.ceil((n-e)*f/r),a=function(r){var t=({3:2,4:5,6:5,7:5,8:10,9:10,11:10,12:10,13:15,14:15,16:15,17:15,18:20,19:20,21:20,22:20,23:25,24:25,26:25,27:25}[u+r]||u+r)/f,i=Math.floor(e/t)*t,a=[];a.push(i);for(var o=1;a[a.length-1]<n;o++)a.push(i+t*o);return a},o=a(0),l=function(){for(var n=[],r=o[o.length-1]-(null==t?void 0:t.max),i=0;i<o.length;i++)i+1<o.length&&o[i+1]-r<e||n.push(o[i]-r);return n},h=function(){for(var e=[],r=o[0]-(null==t?void 0:t.min),i=0;i<o.length&&(e[i]=o[i]-r,!(n<=e[i]));i++);return e};if(t){if("max"in t&&"min"in t&&t.max>=n&&t.min<=e){var m=function(){if(o[0]>=t.min&&o[o.length-1]<=t.max)return!0;var n=l();if(n[0]>=t.min&&n[n.length-1]<=t.max)return o=n,!0;var e=h();return e[0]>=t.min&&e[n.length-1]<=t.max?(o=e,!0):void 0};if(m())return o;for(var v=1;v<100;v++){if(o=a(v),m())return o;if(o=a(-v),m())return o}}"max"in t&&t.max>=n?t.max<o[o.length-1]&&(o=l()):"min"in t&&t.min<=e&&t.min>o[0]&&(o=h())}for(var s=0;s<o.length;s++){var d=o[s]+"";/\./.test(d)&&(/9{7,}$/.test(d)?(d=d.replace(/9{7,}$/,""),o[s]=+(d.substring(0,d.length-1)+(+d[d.length-1]+1))):/0{7,}\d$/.test(d)&&(o[s]=+d.replace(/0{7,}\d$/,"")))}return o}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(n="undefined"!=typeof globalThis?globalThis:n||self).VISLite_ruler=e();
|
package/lib/scale/index.umd.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* VISLite JavaScript Library v0.7.0
|
|
2
|
+
* VISLite JavaScript Library v0.7.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
|
-
* Publish Date:
|
|
9
|
+
* Publish Date: Sun Jan 14 2024 15:48:51 GMT+0800 (中国标准时间)
|
|
10
10
|
*/
|
|
11
11
|
(function (global, factory) {
|
|
12
12
|
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* VISLite JavaScript Library v0.7.0
|
|
2
|
+
* VISLite JavaScript Library v0.7.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
|
-
* Publish Date:
|
|
9
|
+
* Publish Date: Sun Jan 14 2024 15:48:51 GMT+0800 (中国标准时间)
|
|
10
10
|
*/
|
|
11
11
|
var e,t;e=this,t=function(){"use strict";return function(e,t,n,o,f){return[n*(o-e)+e,n*(f-t)+t]}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).VISLite_scale=t();
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* VISLite JavaScript Library v0.7.0
|
|
2
|
+
* VISLite JavaScript Library v0.7.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
|
-
* Publish Date:
|
|
9
|
+
* Publish Date: Sun Jan 14 2024 15:48:51 GMT+0800 (中国标准时间)
|
|
10
10
|
*/
|
|
11
11
|
(function (global, factory) {
|
|
12
12
|
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* VISLite JavaScript Library v0.7.0
|
|
2
|
+
* VISLite JavaScript Library v0.7.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
|
-
* Publish Date:
|
|
9
|
+
* Publish Date: Sun Jan 14 2024 15:48:51 GMT+0800 (中国标准时间)
|
|
10
10
|
*/
|
|
11
11
|
var e,t;e=this,t=function(){"use strict";return function(e,t){void 0===t&&(t={}),t=function(e,t){for(var n in e)t[n]=e[n];return t}(t,{time:200,keep:!1,opportunity:"end"});var n,o=!1,i=!1,r=!1;return function(){var p=this;if(n=arguments,o)i=!0,r=!0;else{"end"!=t.opportunity&&e.apply(p,n),o=!0;var f=setInterval((function(){i?t.keep||e.apply(p,n):("begin"!=t.opportunity&&(r||"end"==t.opportunity)&&e.apply(p,n),o=!1,r=!1,clearInterval(f)),i=!1}),t.time)}}}},"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).VISLite_throttle=t();
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* VISLite JavaScript Library v0.7.0
|
|
2
|
+
* VISLite JavaScript Library v0.7.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
|
-
* Publish Date:
|
|
9
|
+
* Publish Date: Sun Jan 14 2024 15:48:51 GMT+0800 (中国标准时间)
|
|
10
10
|
*/
|
|
11
11
|
(function (global, factory) {
|
|
12
12
|
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* VISLite JavaScript Library v0.7.0
|
|
2
|
+
* VISLite JavaScript Library v0.7.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
|
-
* Publish Date:
|
|
9
|
+
* Publish Date: Sun Jan 14 2024 15:48:51 GMT+0800 (中国标准时间)
|
|
10
10
|
*/
|
|
11
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,event:e}):"down"==t?n({type:"lookDown",normal:[],value:.1,event:e}):"left"==t?n({type:"lookLeft",normal:[],value:.1,event:e}):"right"==t&&n({type:"lookRight",normal:[],value:.1,event:e})}));var o=null,i=function(i){if(null==o)n({type:"hover",normal:[],value:0,event:i});else{var u=e(t,i),l=[u.x-o.x,u.y-o.y],a=[l[1],l[0],0];if(0==a[0]&&0==a[1])return;n({type:"rotate",normal:a,value:.01*(Math.abs(u.x-o.x)+Math.abs(u.y-o.y)),event:i}),o=u}};t.addEventListener("mousedown",(function(n){o=e(t,n)})),t.addEventListener("mouseup",(function(){o=null})),t.addEventListener("mousemove",(function(e){i(e)})),t.addEventListener("touchend",(function(){o=null})),t.addEventListener("touchstart",(function(n){o=e(t,n)})),t.addEventListener("touchmove",(function(e){i(e.touches[0])}));var u=function(e,t){0!=e&&n({type:"scale",value:e<0?.899:1.101,normal:[],event:t})};t.addEventListener("mousewheel",(function(e){u(e.wheelDelta,e)})),window.addEventListener&&window.addEventListener("DOMMouseScroll",(function(e){u(-1*e.detail,e)}),!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
package/src/Canvas.ts
CHANGED
|
@@ -1,71 +1,71 @@
|
|
|
1
|
-
import type CanvasType from '../types/Canvas'
|
|
2
|
-
import type CanvasOptionType from '../types/CanvasOption'
|
|
3
|
-
|
|
4
|
-
import OralCanvas from './common/canvas/index'
|
|
5
|
-
import mergeOption from './common/mergeOption'
|
|
6
|
-
|
|
7
|
-
class Canvas extends OralCanvas implements CanvasType {
|
|
8
|
-
private __canvas: HTMLCanvasElement
|
|
9
|
-
constructor(el: HTMLElement | null, option: CanvasOptionType = {}) {
|
|
10
|
-
if (!el) {
|
|
11
|
-
throw new Error("VISLite Canvas:The mount point requires an HTMLElement type but encountered null.")
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
option = mergeOption(option, {
|
|
15
|
-
region: true,
|
|
16
|
-
willReadFrequently: false
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
const width = el.clientWidth, height = el.clientHeight
|
|
20
|
-
|
|
21
|
-
let ViewCanvas: HTMLCanvasElement, RegionCanvas: HTMLCanvasElement
|
|
22
|
-
|
|
23
|
-
const _el = el as any
|
|
24
|
-
|
|
25
|
-
// 如果已经初始化过了
|
|
26
|
-
if (_el._vislite_canvas_) {
|
|
27
|
-
ViewCanvas = _el._vislite_canvas_[0]
|
|
28
|
-
RegionCanvas = _el._vislite_canvas_[1]
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// 否则就初始化
|
|
32
|
-
else {
|
|
33
|
-
ViewCanvas = document.createElement('canvas')
|
|
34
|
-
el.appendChild(ViewCanvas)
|
|
35
|
-
|
|
36
|
-
if (option.region) {
|
|
37
|
-
RegionCanvas = document.createElement('canvas')
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
_el._vislite_canvas_ = [ViewCanvas, RegionCanvas]
|
|
41
|
-
|
|
42
|
-
el.setAttribute('vislite', 'Canvas')
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// 设置画布大小
|
|
46
|
-
for (const canvas of [ViewCanvas, RegionCanvas]) {
|
|
47
|
-
|
|
48
|
-
if (canvas) {
|
|
49
|
-
canvas.style.width = width + "px"
|
|
50
|
-
canvas.setAttribute('width', width + "")
|
|
51
|
-
|
|
52
|
-
canvas.style.height = height + "px"
|
|
53
|
-
canvas.setAttribute('height', height + "")
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
super(ViewCanvas, RegionCanvas, {
|
|
58
|
-
willReadFrequently: option.willReadFrequently
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
this.__canvas = ViewCanvas
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
toDataURL(): Promise<string> {
|
|
65
|
-
return new Promise(resolve => {
|
|
66
|
-
resolve(this.__canvas.toDataURL())
|
|
67
|
-
})
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
1
|
+
import type CanvasType from '../types/Canvas'
|
|
2
|
+
import type CanvasOptionType from '../types/CanvasOption'
|
|
3
|
+
|
|
4
|
+
import OralCanvas from './common/canvas/index'
|
|
5
|
+
import mergeOption from './common/mergeOption'
|
|
6
|
+
|
|
7
|
+
class Canvas extends OralCanvas implements CanvasType {
|
|
8
|
+
private __canvas: HTMLCanvasElement
|
|
9
|
+
constructor(el: HTMLElement | null, option: CanvasOptionType = {}) {
|
|
10
|
+
if (!el) {
|
|
11
|
+
throw new Error("VISLite Canvas:The mount point requires an HTMLElement type but encountered null.")
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
option = mergeOption(option, {
|
|
15
|
+
region: true,
|
|
16
|
+
willReadFrequently: false
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
const width = el.clientWidth, height = el.clientHeight
|
|
20
|
+
|
|
21
|
+
let ViewCanvas: HTMLCanvasElement, RegionCanvas: HTMLCanvasElement | null = null
|
|
22
|
+
|
|
23
|
+
const _el = el as any
|
|
24
|
+
|
|
25
|
+
// 如果已经初始化过了
|
|
26
|
+
if (_el._vislite_canvas_) {
|
|
27
|
+
ViewCanvas = _el._vislite_canvas_[0]
|
|
28
|
+
RegionCanvas = _el._vislite_canvas_[1]
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// 否则就初始化
|
|
32
|
+
else {
|
|
33
|
+
ViewCanvas = document.createElement('canvas')
|
|
34
|
+
el.appendChild(ViewCanvas)
|
|
35
|
+
|
|
36
|
+
if (option.region) {
|
|
37
|
+
RegionCanvas = document.createElement('canvas')
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
_el._vislite_canvas_ = [ViewCanvas, RegionCanvas]
|
|
41
|
+
|
|
42
|
+
el.setAttribute('vislite', 'Canvas')
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// 设置画布大小
|
|
46
|
+
for (const canvas of [ViewCanvas, RegionCanvas]) {
|
|
47
|
+
|
|
48
|
+
if (canvas) {
|
|
49
|
+
canvas.style.width = width + "px"
|
|
50
|
+
canvas.setAttribute('width', width + "")
|
|
51
|
+
|
|
52
|
+
canvas.style.height = height + "px"
|
|
53
|
+
canvas.setAttribute('height', height + "")
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
super(ViewCanvas, RegionCanvas, {
|
|
58
|
+
willReadFrequently: option.willReadFrequently
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
this.__canvas = ViewCanvas
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
toDataURL(): Promise<string> {
|
|
65
|
+
return new Promise(resolve => {
|
|
66
|
+
resolve(this.__canvas.toDataURL())
|
|
67
|
+
})
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
71
|
export default Canvas
|
package/src/Geometry.ts
CHANGED
|
@@ -1,83 +1,127 @@
|
|
|
1
|
-
import type GeometryType from "../types/Geometry"
|
|
2
|
-
import type GeometryOptionType from "../types/GeometryOption"
|
|
3
|
-
import type GeometryResultType from "../types/GeometryResult"
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
1
|
+
import type GeometryType from "../types/Geometry"
|
|
2
|
+
import type GeometryOptionType from "../types/GeometryOption"
|
|
3
|
+
import type GeometryResultType from "../types/GeometryResult"
|
|
4
|
+
|
|
5
|
+
type rotateLineType = (x0: number, y0: number, z0: number, isNormal: boolean) => Array<number>
|
|
6
|
+
|
|
7
|
+
import { splitNum } from './common/geometry/tool/circle'
|
|
8
|
+
import prismHorizontal from './common/geometry/prism-horizontal'
|
|
9
|
+
import prismVertical from './common/geometry/prism-vertical'
|
|
10
|
+
import sphereFragment from './common/geometry/sphere-fragment'
|
|
11
|
+
import mergeOption from './common/mergeOption'
|
|
12
|
+
import rotateLineFactory from "./common/geometry/tool/rotateLine"
|
|
13
|
+
|
|
14
|
+
class Geometry implements GeometryType {
|
|
15
|
+
readonly name: string = 'Geometry'
|
|
16
|
+
|
|
17
|
+
private __option: GeometryOptionType
|
|
18
|
+
|
|
19
|
+
constructor(option: GeometryOptionType = {}) {
|
|
20
|
+
this.__option = mergeOption(option, {
|
|
21
|
+
precision: 0.1, // 精度
|
|
22
|
+
normal: false, // 是否需要法向量
|
|
23
|
+
})
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
config(option: GeometryOptionType) {
|
|
27
|
+
for (const key in option) {
|
|
28
|
+
this.__option[key] = option[key]
|
|
29
|
+
}
|
|
30
|
+
return this
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// 圆柱体
|
|
34
|
+
cylinder(x: number, y: number, z: number, radius: number, x2: number, y2?: number, z2?: number): Array<GeometryResultType> {
|
|
35
|
+
|
|
36
|
+
// 求解出需要切割多少份比较合理
|
|
37
|
+
const num = splitNum(this.__option.precision as number, radius)
|
|
38
|
+
|
|
39
|
+
if (arguments.length == 5) {
|
|
40
|
+
return this.prism(x, y, z, radius, x2, num)
|
|
41
|
+
} else {
|
|
42
|
+
return this.prism(x, y, z, radius, x2, y2 as number, z2, num)
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// 棱柱体
|
|
47
|
+
prism(x: number, y: number, z: number, radius: number, x2: number, y2: number, z2?: number, num?: number): Array<GeometryResultType> {
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
let height: number, rotateLine: rotateLineType | null = null
|
|
51
|
+
|
|
52
|
+
if (arguments.length == 6) {
|
|
53
|
+
height = x2
|
|
54
|
+
num = y2
|
|
55
|
+
} else {
|
|
56
|
+
height = Math.sqrt((x2 - x) * (x2 - x) + (y2 - y) * (y2 - y) + (z2 as number - z) * (z2 as number - z))
|
|
57
|
+
rotateLine = rotateLineFactory(x, y, z, x2, y2, z2 as number)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const result = [{
|
|
61
|
+
name: "bottom",
|
|
62
|
+
points: [],
|
|
63
|
+
length: 0,
|
|
64
|
+
method: "TRIANGLES" as const
|
|
65
|
+
}, {
|
|
66
|
+
name: "top",
|
|
67
|
+
points: [],
|
|
68
|
+
length: 0,
|
|
69
|
+
method: "TRIANGLES" as const
|
|
70
|
+
}, {
|
|
71
|
+
name: "side",
|
|
72
|
+
points: [],
|
|
73
|
+
length: 0,
|
|
74
|
+
method: "TRIANGLES" as const
|
|
75
|
+
}]
|
|
76
|
+
|
|
77
|
+
// 绘制底部的盖子
|
|
78
|
+
; (result[0].points as Array<number>).push(...prismHorizontal(this.__option.normal as boolean, x, y, z, radius, num as number, height > 0 ? -1 : 1))
|
|
79
|
+
|
|
80
|
+
// 绘制顶部的盖子
|
|
81
|
+
; (result[1].points as Array<number>).push(...prismHorizontal(this.__option.normal as boolean, x, y + height, z, radius, num as number, height > 0 ? 1 : -1))
|
|
82
|
+
|
|
83
|
+
// 绘制侧边部分
|
|
84
|
+
; (result[2].points as Array<number>).push(...prismVertical(this.__option.normal as boolean, x, y, z, radius, height, num as number))
|
|
85
|
+
|
|
86
|
+
for (let i = 0; i < result.length; i++) {
|
|
87
|
+
if (rotateLine) {
|
|
88
|
+
|
|
89
|
+
const points = []
|
|
90
|
+
let isNormal = false
|
|
91
|
+
for (let index = 0; index < result[i].points.length; index += 3) {
|
|
92
|
+
points.push(...rotateLine(result[i].points[index], result[i].points[index + 1], result[i].points[index + 2], (this.__option.normal as boolean) && isNormal))
|
|
93
|
+
isNormal = !isNormal
|
|
94
|
+
}
|
|
95
|
+
(result[i].points as Array<number>) = points
|
|
96
|
+
}
|
|
97
|
+
result[i].length = result[i].points.length / (this.__option.normal ? 6 : 3)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return result
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// 球体
|
|
104
|
+
sphere(cx: number, cy: number, cz: number, radius: number): Array<GeometryResultType> {
|
|
105
|
+
|
|
106
|
+
// 求解出需要切割多少份比较合理
|
|
107
|
+
const num = splitNum(this.__option.precision as number, radius)
|
|
108
|
+
|
|
109
|
+
// 然后一瓣瓣的绘制
|
|
110
|
+
const result = [{
|
|
111
|
+
name: "surface",
|
|
112
|
+
points: [],
|
|
113
|
+
length: 0,
|
|
114
|
+
method: "TRIANGLES" as const
|
|
115
|
+
}]
|
|
116
|
+
for (let i = 0; i < num; i++) {
|
|
117
|
+
; (result[0].points as Array<number>).push(...sphereFragment(this.__option.normal as boolean, cx, cy, cz, radius, num, i))
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
result[0].length = result[0].points.length / (this.__option.normal ? 6 : 3)
|
|
121
|
+
|
|
122
|
+
return result
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
}
|
|
126
|
+
|
|
83
127
|
export default Geometry
|
package/src/Matrix4/rotate.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 围绕
|
|
3
|
-
* 其它的旋转可以借助transform实现
|
|
4
|
-
* 旋转角度单位采用弧度制
|
|
5
|
-
*/
|
|
6
|
-
export default function (deg: number) {
|
|
7
|
-
const sin = Math.sin(deg),
|
|
8
|
-
cos = Math.cos(deg)
|
|
9
|
-
return [
|
|
10
|
-
cos, sin, 0, 0,
|
|
11
|
-
-sin, cos, 0, 0,
|
|
12
|
-
0, 0, 1, 0,
|
|
13
|
-
0, 0, 0, 1
|
|
14
|
-
]
|
|
15
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* 围绕OZ轴旋转
|
|
3
|
+
* 其它的旋转可以借助transform实现
|
|
4
|
+
* 旋转角度单位采用弧度制
|
|
5
|
+
*/
|
|
6
|
+
export default function (deg: number) {
|
|
7
|
+
const sin = Math.sin(deg),
|
|
8
|
+
cos = Math.cos(deg)
|
|
9
|
+
return [
|
|
10
|
+
cos, sin, 0, 0,
|
|
11
|
+
-sin, cos, 0, 0,
|
|
12
|
+
0, 0, 1, 0,
|
|
13
|
+
0, 0, 0, 1
|
|
14
|
+
]
|
|
15
|
+
}
|