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.
Files changed (85) hide show
  1. package/CHANGELOG +8 -3
  2. package/README.md +20 -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 +4 -4
  6. package/lib/Canvas/index.umd.min.js +3 -3
  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/Geometry/index.umd.js +69 -8
  12. package/lib/Geometry/index.umd.min.js +3 -3
  13. package/lib/Hermite/index.umd.js +2 -2
  14. package/lib/Hermite/index.umd.min.js +2 -2
  15. package/lib/Matrix4/index.umd.js +2 -2
  16. package/lib/Matrix4/index.umd.min.js +2 -2
  17. package/lib/Mercator/index.umd.js +2 -2
  18. package/lib/Mercator/index.umd.min.js +2 -2
  19. package/lib/OralCanvas/index.es.js +3 -3
  20. package/lib/OralCanvas/index.es.min.js +3 -3
  21. package/lib/OralWebGL/index.es.js +21 -18
  22. package/lib/OralWebGL/index.es.min.js +3 -3
  23. package/lib/SVG/index.umd.js +2 -2
  24. package/lib/SVG/index.umd.min.js +2 -2
  25. package/lib/Shader/index.umd.js +3 -2
  26. package/lib/Shader/index.umd.min.js +3 -3
  27. package/lib/Texture/index.umd.js +2 -2
  28. package/lib/Texture/index.umd.min.js +2 -2
  29. package/lib/TreeLayout/index.umd.js +13 -11
  30. package/lib/TreeLayout/index.umd.min.js +3 -3
  31. package/lib/WebGL/index.umd.js +22 -19
  32. package/lib/WebGL/index.umd.min.js +3 -3
  33. package/lib/animation/index.umd.js +2 -2
  34. package/lib/animation/index.umd.min.js +2 -2
  35. package/lib/formatColor/index.umd.js +2 -2
  36. package/lib/formatColor/index.umd.min.js +2 -2
  37. package/lib/getLoopColors/index.umd.js +2 -2
  38. package/lib/getLoopColors/index.umd.min.js +2 -2
  39. package/lib/getWebGLContext/index.umd.js +4 -4
  40. package/lib/getWebGLContext/index.umd.min.js +3 -3
  41. package/lib/index.umd.js +104 -38
  42. package/lib/index.umd.min.js +3 -3
  43. package/lib/move/index.umd.js +2 -2
  44. package/lib/move/index.umd.min.js +2 -2
  45. package/lib/resizeObserver/index.umd.js +2 -2
  46. package/lib/resizeObserver/index.umd.min.js +2 -2
  47. package/lib/rotate/index.umd.js +2 -2
  48. package/lib/rotate/index.umd.min.js +2 -2
  49. package/lib/ruler/index.umd.js +4 -4
  50. package/lib/ruler/index.umd.min.js +3 -3
  51. package/lib/scale/index.umd.js +2 -2
  52. package/lib/scale/index.umd.min.js +2 -2
  53. package/lib/throttle/index.umd.js +2 -2
  54. package/lib/throttle/index.umd.min.js +2 -2
  55. package/lib/viewHandler/index.umd.js +2 -2
  56. package/lib/viewHandler/index.umd.min.js +2 -2
  57. package/package.json +1 -1
  58. package/src/Canvas.ts +70 -70
  59. package/src/Geometry.ts +126 -82
  60. package/src/Matrix4/rotate.ts +15 -15
  61. package/src/Matrix4/transform.ts +64 -64
  62. package/src/WebGL.ts +66 -66
  63. package/src/common/assemble.ts +22 -22
  64. package/src/common/canvas/index.ts +177 -177
  65. package/src/common/canvas/painter.ts +419 -417
  66. package/src/common/geometry/prism-vertical.ts +40 -40
  67. package/src/common/geometry/tool/rotateLine.ts +36 -0
  68. package/src/common/setStyle.ts +5 -5
  69. package/src/common/svg/config.ts +190 -186
  70. package/src/common/svg/tool.ts +44 -44
  71. package/src/common/tree/toInnerTree.ts +59 -57
  72. package/src/common/tree/toPlainTree.ts +132 -132
  73. package/src/common/webgl/buffer.ts +79 -79
  74. package/src/common/webgl/doDraw.ts +108 -108
  75. package/src/common/webgl/getWebGLContext.ts +28 -28
  76. package/src/common/webgl/index.ts +226 -224
  77. package/src/common/webgl/shader.ts +75 -75
  78. package/src/common/webgl/texture.ts +97 -97
  79. package/src/layout/TreeLayout.ts +188 -186
  80. package/src/resizeObserver.ts +37 -37
  81. package/src/ruler.ts +209 -209
  82. package/src/viewHandler.ts +160 -158
  83. package/types/Canvas.d.ts +308 -308
  84. package/types/Geometry.d.ts +65 -40
  85. package/types/TreeConfig.d.ts +36 -24
@@ -1,11 +1,11 @@
1
1
  /*!
2
- * VISLite JavaScript Library v0.7.0-alpha.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: Fri Dec 29 2023 22:39:54 GMT+0800 (中国标准时间)
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();
@@ -1,12 +1,12 @@
1
1
  /*!
2
- * VISLite JavaScript Library v0.7.0-alpha.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: Fri Dec 29 2023 22:39:54 GMT+0800 (中国标准时间)
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-alpha.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: Fri Dec 29 2023 22:39:54 GMT+0800 (中国标准时间)
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();
@@ -1,12 +1,12 @@
1
1
  /*!
2
- * VISLite JavaScript Library v0.7.0-alpha.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: Fri Dec 29 2023 22:39:54 GMT+0800 (中国标准时间)
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-alpha.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: Fri Dec 29 2023 22:39:54 GMT+0800 (中国标准时间)
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),a=Math.ceil((n-e)*f/r),u=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}[a+r]||a+r)/f,i=Math.floor(e/t)*t,u=[];u.push(i);for(var o=1;u[u.length-1]<n;o++)u.push(i+t*o);return u},o=u(0),l=function(){for(var n=[],r=o[o.length-1]-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]-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 s=1;s<100;s++){if(o=u(s),m())return o;if(o=u(-s),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 v=0;v<o.length;v++){var g=o[v]+"";/\./.test(g)&&(/9{7,}$/.test(g)?(g=g.replace(/9{7,}$/,""),o[v]=+(g.substring(0,g.length-1)+(+g[g.length-1]+1))):/0{7,}\d$/.test(g)&&(o[v]=+g.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();
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();
@@ -1,12 +1,12 @@
1
1
  /*!
2
- * VISLite JavaScript Library v0.7.0-alpha.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: Fri Dec 29 2023 22:39:54 GMT+0800 (中国标准时间)
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-alpha.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: Fri Dec 29 2023 22:39:54 GMT+0800 (中国标准时间)
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-alpha.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: Fri Dec 29 2023 22:39:54 GMT+0800 (中国标准时间)
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-alpha.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: Fri Dec 29 2023 22:39:54 GMT+0800 (中国标准时间)
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-alpha.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: Fri Dec 29 2023 22:39:54 GMT+0800 (中国标准时间)
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-alpha.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: Fri Dec 29 2023 22:39:54 GMT+0800 (中国标准时间)
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vislite",
3
- "version": "0.7.0-alpha.0",
3
+ "version": "0.7.0",
4
4
  "description": "灵活、快速、简单的数据可视化交互式跨端前端库",
5
5
  "main": "./lib/index.umd.min.js",
6
6
  "typings": "./types/index.d.ts",
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
- import { splitNum } from './common/geometry/tool/circle'
6
- import prismHorizontal from './common/geometry/prism-horizontal'
7
- import prismVertical from './common/geometry/prism-vertical'
8
- import sphereFragment from './common/geometry/sphere-fragment'
9
- import mergeOption from './common/mergeOption'
10
-
11
- class Geometry implements GeometryType {
12
- readonly name: string = 'Geometry'
13
-
14
- private __option: GeometryOptionType
15
-
16
- constructor(option: GeometryOptionType = {}) {
17
- this.__option = mergeOption(option, {
18
- precision: 0.1, // 精度
19
- normal: false, // 是否需要法向量
20
- })
21
- }
22
-
23
- config(option: GeometryOptionType) {
24
- for (const key in option) {
25
- this.__option[key] = option[key]
26
- }
27
- return this
28
- }
29
-
30
- // 圆柱体
31
- cylinder(x: number, y: number, z: number, radius: number, height: number): Array<GeometryResultType> {
32
-
33
- // 求解出需要切割多少份比较合理
34
- const num = splitNum(this.__option.precision, radius)
35
- return this.prism(x, y, z, radius, height, num)
36
- }
37
-
38
- // 棱柱体
39
- prism(x: number, y: number, z: number, radius: number, height: number, num: number): Array<GeometryResultType> {
40
-
41
- const result = [{
42
- points: [],
43
- length: 0,
44
- method: "TRIANGLES" as const
45
- }]
46
-
47
- // 绘制底部的盖子
48
- result[0].points.push(...prismHorizontal(this.__option.normal, x, y, z, radius, num, height > 0 ? -1 : 1))
49
-
50
- // 绘制顶部的盖子
51
- result[0].points.push(...prismHorizontal(this.__option.normal, x, y + height, z, radius, num, height > 0 ? 1 : -1))
52
-
53
- // 绘制侧边部分
54
- result[0].points.push(...prismVertical(this.__option.normal, x, y, z, radius, height, num))
55
-
56
- result[0].length = 12 * num
57
- return result
58
- }
59
-
60
- // 球体
61
- sphere(cx: number, cy: number, cz: number, radius: number): Array<GeometryResultType> {
62
-
63
- // 求解出需要切割多少份比较合理
64
- const num = splitNum(this.__option.precision, radius)
65
-
66
- // 然后一瓣瓣的绘制
67
- const result = [{
68
- points: [],
69
- length: 0,
70
- method: "TRIANGLES" as const
71
- }]
72
- for (let i = 0; i < num; i++) {
73
- result[0].points.push(...sphereFragment(this.__option.normal, cx, cy, cz, radius, num, i))
74
- }
75
-
76
- result[0].length = result[0].points.length / (this.__option.normal ? 6 : 3)
77
-
78
- return result
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
@@ -1,15 +1,15 @@
1
- /**
2
- * 围绕0Z轴旋转
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
+ }