@visactor/vgrammar-coordinate
Advanced tools
Comparing version 0.3.2 to 0.4.0
@@ -322,3 +322,3 @@ (function (global, factory) { | ||
const isType = (value, type) => toString.call(value) === `[object ${type}]`; | ||
const isType = (value, type) => Object.prototype.toString.call(value) === `[object ${type}]`; | ||
@@ -528,2 +528,7 @@ const isNil = value => null == value; | ||
var LoggerLevel; | ||
!function (LoggerLevel) { | ||
LoggerLevel[LoggerLevel.None = 0] = "None", LoggerLevel[LoggerLevel.Error = 1] = "Error", LoggerLevel[LoggerLevel.Warn = 2] = "Warn", LoggerLevel[LoggerLevel.Info = 3] = "Info", LoggerLevel[LoggerLevel.Debug = 4] = "Debug"; | ||
}(LoggerLevel || (LoggerLevel = {})); | ||
class Coordinate { | ||
@@ -530,0 +535,0 @@ type; |
@@ -1,1 +0,1 @@ | ||
!function(t,i){"object"==typeof exports&&"undefined"!=typeof module?i(exports):"function"==typeof define&&define.amd?define(["exports"],i):i(((t="undefined"!=typeof globalThis?globalThis:t||self).VGrammar=t.VGrammar||{},t.VGrammar.Coordinate={}))}(this,(function(t){"use strict";!function(t){var i=Object.prototype.hasOwnProperty,s="~";function e(){}function n(t,i,s){this.fn=t,this.context=i,this.once=s||!1}function r(t,i,e,r,h){if("function"!=typeof e)throw new TypeError("The listener must be a function");var o=new n(e,r||t,h),a=s?s+i:i;return t._events[a]?t._events[a].fn?t._events[a]=[t._events[a],o]:t._events[a].push(o):(t._events[a]=o,t._eventsCount++),t}function h(t,i){0==--t._eventsCount?t._events=new e:delete t._events[i]}function o(){this._events=new e,this._eventsCount=0}Object.create&&(e.prototype=Object.create(null),(new e).__proto__||(s=!1)),o.prototype.eventNames=function(){var t,e,n=[];if(0===this._eventsCount)return n;for(e in t=this._events)i.call(t,e)&&n.push(s?e.slice(1):e);return Object.getOwnPropertySymbols?n.concat(Object.getOwnPropertySymbols(t)):n},o.prototype.listeners=function(t){var i=s?s+t:t,e=this._events[i];if(!e)return[];if(e.fn)return[e.fn];for(var n=0,r=e.length,h=new Array(r);n<r;n++)h[n]=e[n].fn;return h},o.prototype.listenerCount=function(t){var i=s?s+t:t,e=this._events[i];return e?e.fn?1:e.length:0},o.prototype.emit=function(t,i,e,n,r,h){var o=s?s+t:t;if(!this._events[o])return!1;var a,c,u=this._events[o],l=arguments.length;if(u.fn){switch(u.once&&this.removeListener(t,u.fn,void 0,!0),l){case 1:return u.fn.call(u.context),!0;case 2:return u.fn.call(u.context,i),!0;case 3:return u.fn.call(u.context,i,e),!0;case 4:return u.fn.call(u.context,i,e,n),!0;case 5:return u.fn.call(u.context,i,e,n,r),!0;case 6:return u.fn.call(u.context,i,e,n,r,h),!0}for(c=1,a=new Array(l-1);c<l;c++)a[c-1]=arguments[c];u.fn.apply(u.context,a)}else{var f,y=u.length;for(c=0;c<y;c++)switch(u[c].once&&this.removeListener(t,u[c].fn,void 0,!0),l){case 1:u[c].fn.call(u[c].context);break;case 2:u[c].fn.call(u[c].context,i);break;case 3:u[c].fn.call(u[c].context,i,e);break;case 4:u[c].fn.call(u[c].context,i,e,n);break;default:if(!a)for(f=1,a=new Array(l-1);f<l;f++)a[f-1]=arguments[f];u[c].fn.apply(u[c].context,a)}}return!0},o.prototype.on=function(t,i,s){return r(this,t,i,s,!1)},o.prototype.once=function(t,i,s){return r(this,t,i,s,!0)},o.prototype.removeListener=function(t,i,e,n){var r=s?s+t:t;if(!this._events[r])return this;if(!i)return h(this,r),this;var o=this._events[r];if(o.fn)o.fn!==i||n&&!o.once||e&&o.context!==e||h(this,r);else{for(var a=0,c=[],u=o.length;a<u;a++)(o[a].fn!==i||n&&!o[a].once||e&&o[a].context!==e)&&c.push(o[a]);c.length?this._events[r]=1===c.length?c[0]:c:h(this,r)}return this},o.prototype.removeAllListeners=function(t){var i;return t?(i=s?s+t:t,this._events[i]&&h(this,i)):(this._events=new e,this._eventsCount=0),this},o.prototype.off=o.prototype.removeListener,o.prototype.addListener=o.prototype.on,o.prefixed=s,o.EventEmitter=o,t.exports=o}({exports:{}});const i=(t,i)=>toString.call(t)===`[object ${i}]`,s=t=>null==t,e=t=>Array.isArray?Array.isArray(t):i(t,"Array"),n=function(t){const s=typeof t;return arguments.length>1&&void 0!==arguments[1]&&arguments[1]?"number"===s:"number"===s||i(t,"Number")},r=t=>n(t)&&Number.isFinite(t);function h(t,i){const s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:1e-10,e=(arguments.length>2&&void 0!==arguments[2]?arguments[2]:1e-10)*Math.max(t,i);return Math.abs(t-i)<=Math.max(s,e)}let o=!1;try{o="function"==typeof requestAnimationFrame&&"function"==typeof cancelAnimationFrame}catch(t){o=!1}o=!1;const a=2*Math.PI;function c(t,i,s){return{x:t.x+i*Math.cos(s),y:t.y+i*Math.sin(s)}}class u{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,e=arguments.length>3&&void 0!==arguments[3]?arguments[3]:1,n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:0,r=arguments.length>5&&void 0!==arguments[5]?arguments[5]:0;this.a=t,this.b=i,this.c=s,this.d=e,this.e=n,this.f=r}equalToMatrix(t){return!(this.e!==t.e||this.f!==t.f||this.a!==t.a||this.d!==t.d||this.b!==t.b||this.c!==t.c)}equalTo(t,i,s,e,n,r){return!(this.e!==n||this.f!==r||this.a!==t||this.d!==e||this.b!==i||this.c!==s)}setValue(t,i,s,e,n,r){return this.a=t,this.b=i,this.c=s,this.d=e,this.e=n,this.f=r,this}reset(){return this.a=1,this.b=0,this.c=0,this.d=1,this.e=0,this.f=0,this}getInverse(){const t=this.a,i=this.b,s=this.c,e=this.d,n=this.e,r=this.f,h=new u,o=t*e-i*s;return h.a=e/o,h.b=-i/o,h.c=-s/o,h.d=t/o,h.e=(s*r-e*n)/o,h.f=-(t*r-i*n)/o,h}rotate(t){const i=Math.cos(t),s=Math.sin(t),e=this.a*i+this.c*s,n=this.b*i+this.d*s,r=this.a*-s+this.c*i,h=this.b*-s+this.d*i;return this.a=e,this.b=n,this.c=r,this.d=h,this}rotateByCenter(t,i,s){const e=Math.cos(t),n=Math.sin(t),r=(1-e)*i+n*s,h=(1-e)*s-n*i,o=e*this.a-n*this.b,a=n*this.a+e*this.b,c=e*this.c-n*this.d,u=n*this.c+e*this.d,l=e*this.e-n*this.f+r,f=n*this.e+e*this.f+h;return this.a=o,this.b=a,this.c=c,this.d=u,this.e=l,this.f=f,this}scale(t,i){return this.a*=t,this.b*=t,this.c*=i,this.d*=i,this}setScale(t,i){return this.b=this.b/this.a*t,this.c=this.c/this.d*i,this.a=t,this.d=i,this}transform(t,i,s,e,n,r){return this.multiply(t,i,s,e,n,r),this}translate(t,i){return this.e+=this.a*t+this.c*i,this.f+=this.b*t+this.d*i,this}transpose(){const{a:t,b:i,c:s,d:e,e:n,f:r}=this;return this.a=i,this.b=t,this.c=e,this.d=s,this.e=r,this.f=n,this}multiply(t,i,s,e,n,r){const h=this.a,o=this.b,a=this.c,c=this.d,u=h*t+a*i,l=o*t+c*i,f=h*s+a*e,y=o*s+c*e,d=h*n+a*r+this.e,x=o*n+c*r+this.f;return this.a=u,this.b=l,this.c=f,this.d=y,this.e=d,this.f=x,this}interpolate(t,i){const s=new u;return s.a=this.a+(t.a-this.a)*i,s.b=this.b+(t.b-this.b)*i,s.c=this.c+(t.c-this.c)*i,s.d=this.d+(t.d-this.d)*i,s.e=this.e+(t.e-this.e)*i,s.f=this.f+(t.f-this.f)*i,s}transformPoint(t,i){const{a:s,b:e,c:n,d:r,e:h,f:o}=this,a=s*r-e*n,c=r/a,u=-e/a,l=-n/a,f=s/a,y=(n*o-r*h)/a,d=-(s*o-e*h)/a,{x:x,y:p}=t;i.x=x*c+p*l+y,i.y=x*u+p*f+d}onlyTranslate(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return this.a===t&&0===this.b&&0===this.c&&this.d===t}clone(){return new u(this.a,this.b,this.c,this.d,this.e,this.f)}toTransformAttrs(){const t=this.a,i=this.b,s=this.c,e=this.d,n=t*e-i*s,r={x:this.e,y:this.f,rotateDeg:0,scaleX:0,scaleY:0,skewX:0,skewY:0};if(0!==t||0!==i){const h=Math.sqrt(t*t+i*i);r.rotateDeg=i>0?Math.acos(t/h):-Math.acos(t/h),r.scaleX=h,r.scaleY=n/h,r.skewX=(t*s+i*e)/n,r.skewY=0}else if(0!==s||0!==e){const h=Math.sqrt(s*s+e*e);r.rotateDeg=Math.PI/2-(e>0?Math.acos(-s/h):-Math.acos(s/h)),r.scaleX=n/h,r.scaleY=h,r.skewX=0,r.skewY=(t*s+i*e)/n}return r.rotateDeg=180*r.rotateDeg/Math.PI,r}}var l;!function(t){t[t.NONE=0]="NONE",t[t.BBOX1=1]="BBOX1",t[t.BBOX2=2]="BBOX2"}(l||(l={}));class f{type;startPoint={x:0,y:0};endPoint={x:0,y:0};originPoint={x:0,y:0};width=0;height=0;transforms=[];convertMatrix;invertMatrix;start(t,i){return s(t)?this.startPoint:(this.startPoint=this._parsePoint(t,i),this._updateSize(),this)}end(t,i){return s(t)?this.endPoint:(this.endPoint=this._parsePoint(t,i),this._updateSize(),this)}_parsePoint(t,i){const s={x:0,y:0};return e(t)?(s.x=t[0],s.y=t[1]):n(t)?(s.x=t,s.y=i):(s.x=t.x,s.y=t.y),s}_updateSize(){this.width=this.endPoint.x-this.startPoint.x,this.height=this.endPoint.y-this.startPoint.y}isTransposed(){return this.transforms&&this.transforms.filter((t=>"transpose"===t.type)).length%2!=0}isMainDimension(t){let i="x"===t||"theta"===t||"0"===t;return this.isTransposed()&&(i=!i),i}applyTransforms(t){return this.transforms=t.slice(),this._invokeTransforms(),this}_invokeTransforms(){this.invertMatrix=null,this.convertMatrix=null,this.invertMatrix=new u,this.invertMatrix.translate(this.originPoint.x,this.originPoint.y),this.transforms.forEach((t=>{switch(t.type){case"translate":this.invertMatrix.translate(t.offset.x,t.offset.y);break;case"rotate":this.invertMatrix.rotateByCenter(t.angle,this.originPoint.x,this.originPoint.y);break;case"scale":this.invertMatrix.scale(t.scale.x,t.scale.y);break;case"transpose":"polar"!==this.type&&this.invertMatrix.transpose()}})),this.invertMatrix,this.convertMatrix=this.invertMatrix.getInverse()}}t.CartesianCoordinate=class extends f{type="cartesian";convert(t){if(r(t.x1)||r(t.y1)){const i=this.convertPoint(t),s=this.convertPoint({x:t.x1??t.x,y:t.y1??t.y});return i.x1=s.x,i.y1=s.y,i}return this.convertPoint(t)}invert(t){if(r(t.x1)||r(t.y1)){const i=this.invertPoint(t),s=this.invertPoint({x:t.x1??t.x,y:t.y1??t.y});return i.x1=s.x,i.y1=s.y,i}return this.invertPoint(t)}getRangeByDimension(t,i,s){const e=this.start(),n=this.end(),r=this.isMainDimension(t)?[e.x,n.x]:[n.y,e.y];return s?[r[1],r[0]]:r}getVisiualPositionByDimension(t,i,s){return this.isMainDimension(t)?i?"top":"bottom":i?"right":"left"}getAxisPointsByDimension(t,i,e,n){const r=this.start(),h=this.end();if(this.isMainDimension(t)){const t=s(n)?i?[{x:r.x,y:r.y},{x:h.x,y:r.y}]:[{x:r.x,y:h.y},{x:h.x,y:h.y}]:[{x:r.x,y:n},{x:h.x,y:n}];return e?[t[1],t[0]]:t}const o=s(n)?i?[{x:h.x,y:h.y},{x:h.x,y:r.y}]:[{x:r.x,y:h.y},{x:r.x,y:r.y}]:[{x:n,y:h.y},{x:n,y:r.y}];return e?[o[1],o[0]]:o}convertPoint(t){const i=e(t)?{x:t[0],y:t[1]}:t,s=Object.assign({},i);return this.convertMatrix.transformPoint(i,s),s}invertPoint(t){const i=Object.assign({},t);return this.invertMatrix.transformPoint(t,i),i}},t.Coordinate=f,t.PolarCoordinate=class extends f{type="polar";_isUserOrigin=!1;_isUserRadius=!1;startAngle=0;endAngle=2*Math.PI;innerRadius=0;outerRadius=0;_updateStartEndPoint(){const t=this.origin(),i=Math.min(this.startAngle,this.endAngle),s=Math.max(this.startAngle,this.endAngle),e=2*i/Math.PI,n=2*s/Math.PI,r=[i,s];let h=Math.ceil(e);for(;h<=n;)r.push(h*Math.PI/2),h++;const o=r.length,a=[],u=[];for(h=0;h<o;h++){const i=c(t,this.innerRadius,r[h]),s=c(t,this.outerRadius,r[h]);a.push(i.x),a.push(s.x),u.push(i.y),u.push(s.y)}const l=Math.min.apply(null,a),f=Math.min.apply(null,u),y=Math.max.apply(null,a),d=Math.max.apply(null,u);this.startPoint={x:l,y:f},this.endPoint={x:y,y:d}}_updateSize(){super._updateSize(),this._isUserOrigin||(this.originPoint={x:this.width/2,y:this.height/2},this._invokeTransforms()),this._isUserRadius||(this.outerRadius=Math.min(Math.abs(this.startPoint.x-this.originPoint.x),Math.abs(this.endPoint.x-this.originPoint.x),Math.abs(this.startPoint.y-this.originPoint.y),Math.abs(this.endPoint.y-this.originPoint.y)))}angle(t,i){return s(t)?[this.startAngle,this.endAngle]:(Array.isArray(t)?(this.startAngle=t[0],this.endAngle=t[1]):(this.startAngle=t,this.endAngle=i??t),this._updateStartEndPoint(),this)}radius(t,i){return s(t)?[this.innerRadius,this.outerRadius]:(this._isUserRadius=!0,Array.isArray(t)?(this.innerRadius=Math.min(t[0],t[1]),this.outerRadius=Math.max(t[1],t[1])):(this.innerRadius=Math.min(t,i),this.outerRadius=Math.max(t,i)),this._updateStartEndPoint(),this)}origin(t,i){return s(t)?this.originPoint:(this._isUserOrigin=!0,this.originPoint=this._parsePoint(t,i),this._updateStartEndPoint(),this._invokeTransforms(),this)}convert(t){if(r(t.r1)||r(t.theta1)){const i=this.convertPoint(t),s=this.convertPoint({r:t.r1??t.r,theta:t.theta1??t.theta});return i.x1=s.x,i.y1=s.y,i}if(r(t.x1)||r(t.y1)){const i=this.convertPoint(t),s=this.convertPoint({x:t.x1??t.x,y:t.y1??t.y});return i.x1=s.x,i.y1=s.y,i}return this.convertPoint(t)}invert(t){if(r(t.x1)||r(t.y1)){const i=this.invertPoint(t),s=this.invertPoint({x:t.x1??t.x,y:t.y1??t.y});return i.r1=s.r,i.theta1=s.theta,i}return this.invertPoint(t)}getRangeByDimension(t,i,s){const e=this.isMainDimension(t)?[this.startAngle,this.endAngle]:[this.innerRadius,this.outerRadius];return s?[e[1],e[0]]:e}getVisiualPositionByDimension(t,i,s){return this.isMainDimension(t)?i?"inside":"outside":i?"end":"start"}getAxisPointsByDimension(t,i,e,n){if(!this.isMainDimension(t)){const t=this.origin(),r=s(n)?i?[c(t,this.innerRadius,this.endAngle),c(t,this.outerRadius,this.endAngle)]:[c(t,this.innerRadius,this.startAngle),c(t,this.outerRadius,this.startAngle)]:[c(t,this.innerRadius,n),c(t,this.outerRadius,n)];return e?[r[1],r[0]]:r}return null}convertPoint(t){const i=this.isTransposed();let n,r;s(t.r)||s(t.theta)?e(t)?(n=i?t[0]:t[1],r=i?t[1]:t[0]):(n=i?t.y:t.x,r=i?t.x:t.y):(n=i?t.r:t.theta,r=i?t.theta:t.r);const h={x:Math.cos(n)*r,y:Math.sin(n)*r};!1===t.defined&&(h.defined=!1);const o=Object.assign({},h);return this.convertMatrix.transformPoint(h,o),o}invertPoint(t){const i=Object.assign({},t);this.invertMatrix.transformPoint(t,i);const s=i.x,e=i.y;if(h(s,0)&&h(e,0)){const t={r:0,theta:0};return!1===i.defined&&(t.defined=!1),t}let n=Math.atan(e/s);n+=s>=0?2*Math.PI:Math.PI,n>=2*Math.PI&&(n-=2*Math.PI),n=function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;if(t<0)for(;t<-a;)t+=a;else if(t>0)for(;t>a;)t-=a;return t}(n);const r=h(e,0)?s/Math.cos(n):e/Math.sin(n),o=this.isTransposed()?{r:n,theta:r}:{r:r,theta:n};return!1===i.defined&&(o.defined=!1),o}}})); | ||
!function(t,i){"object"==typeof exports&&"undefined"!=typeof module?i(exports):"function"==typeof define&&define.amd?define(["exports"],i):i(((t="undefined"!=typeof globalThis?globalThis:t||self).VGrammar=t.VGrammar||{},t.VGrammar.Coordinate={}))}(this,(function(t){"use strict";!function(t){var i=Object.prototype.hasOwnProperty,s="~";function e(){}function n(t,i,s){this.fn=t,this.context=i,this.once=s||!1}function r(t,i,e,r,h){if("function"!=typeof e)throw new TypeError("The listener must be a function");var o=new n(e,r||t,h),a=s?s+i:i;return t._events[a]?t._events[a].fn?t._events[a]=[t._events[a],o]:t._events[a].push(o):(t._events[a]=o,t._eventsCount++),t}function h(t,i){0==--t._eventsCount?t._events=new e:delete t._events[i]}function o(){this._events=new e,this._eventsCount=0}Object.create&&(e.prototype=Object.create(null),(new e).__proto__||(s=!1)),o.prototype.eventNames=function(){var t,e,n=[];if(0===this._eventsCount)return n;for(e in t=this._events)i.call(t,e)&&n.push(s?e.slice(1):e);return Object.getOwnPropertySymbols?n.concat(Object.getOwnPropertySymbols(t)):n},o.prototype.listeners=function(t){var i=s?s+t:t,e=this._events[i];if(!e)return[];if(e.fn)return[e.fn];for(var n=0,r=e.length,h=new Array(r);n<r;n++)h[n]=e[n].fn;return h},o.prototype.listenerCount=function(t){var i=s?s+t:t,e=this._events[i];return e?e.fn?1:e.length:0},o.prototype.emit=function(t,i,e,n,r,h){var o=s?s+t:t;if(!this._events[o])return!1;var a,c,u=this._events[o],l=arguments.length;if(u.fn){switch(u.once&&this.removeListener(t,u.fn,void 0,!0),l){case 1:return u.fn.call(u.context),!0;case 2:return u.fn.call(u.context,i),!0;case 3:return u.fn.call(u.context,i,e),!0;case 4:return u.fn.call(u.context,i,e,n),!0;case 5:return u.fn.call(u.context,i,e,n,r),!0;case 6:return u.fn.call(u.context,i,e,n,r,h),!0}for(c=1,a=new Array(l-1);c<l;c++)a[c-1]=arguments[c];u.fn.apply(u.context,a)}else{var f,y=u.length;for(c=0;c<y;c++)switch(u[c].once&&this.removeListener(t,u[c].fn,void 0,!0),l){case 1:u[c].fn.call(u[c].context);break;case 2:u[c].fn.call(u[c].context,i);break;case 3:u[c].fn.call(u[c].context,i,e);break;case 4:u[c].fn.call(u[c].context,i,e,n);break;default:if(!a)for(f=1,a=new Array(l-1);f<l;f++)a[f-1]=arguments[f];u[c].fn.apply(u[c].context,a)}}return!0},o.prototype.on=function(t,i,s){return r(this,t,i,s,!1)},o.prototype.once=function(t,i,s){return r(this,t,i,s,!0)},o.prototype.removeListener=function(t,i,e,n){var r=s?s+t:t;if(!this._events[r])return this;if(!i)return h(this,r),this;var o=this._events[r];if(o.fn)o.fn!==i||n&&!o.once||e&&o.context!==e||h(this,r);else{for(var a=0,c=[],u=o.length;a<u;a++)(o[a].fn!==i||n&&!o[a].once||e&&o[a].context!==e)&&c.push(o[a]);c.length?this._events[r]=1===c.length?c[0]:c:h(this,r)}return this},o.prototype.removeAllListeners=function(t){var i;return t?(i=s?s+t:t,this._events[i]&&h(this,i)):(this._events=new e,this._eventsCount=0),this},o.prototype.off=o.prototype.removeListener,o.prototype.addListener=o.prototype.on,o.prefixed=s,o.EventEmitter=o,t.exports=o}({exports:{}});const i=(t,i)=>Object.prototype.toString.call(t)===`[object ${i}]`,s=t=>null==t,e=t=>Array.isArray?Array.isArray(t):i(t,"Array"),n=function(t){const s=typeof t;return arguments.length>1&&void 0!==arguments[1]&&arguments[1]?"number"===s:"number"===s||i(t,"Number")},r=t=>n(t)&&Number.isFinite(t);function h(t,i){const s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:1e-10,e=(arguments.length>2&&void 0!==arguments[2]?arguments[2]:1e-10)*Math.max(t,i);return Math.abs(t-i)<=Math.max(s,e)}let o=!1;try{o="function"==typeof requestAnimationFrame&&"function"==typeof cancelAnimationFrame}catch(t){o=!1}o=!1;const a=2*Math.PI;function c(t,i,s){return{x:t.x+i*Math.cos(s),y:t.y+i*Math.sin(s)}}class u{constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,e=arguments.length>3&&void 0!==arguments[3]?arguments[3]:1,n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:0,r=arguments.length>5&&void 0!==arguments[5]?arguments[5]:0;this.a=t,this.b=i,this.c=s,this.d=e,this.e=n,this.f=r}equalToMatrix(t){return!(this.e!==t.e||this.f!==t.f||this.a!==t.a||this.d!==t.d||this.b!==t.b||this.c!==t.c)}equalTo(t,i,s,e,n,r){return!(this.e!==n||this.f!==r||this.a!==t||this.d!==e||this.b!==i||this.c!==s)}setValue(t,i,s,e,n,r){return this.a=t,this.b=i,this.c=s,this.d=e,this.e=n,this.f=r,this}reset(){return this.a=1,this.b=0,this.c=0,this.d=1,this.e=0,this.f=0,this}getInverse(){const t=this.a,i=this.b,s=this.c,e=this.d,n=this.e,r=this.f,h=new u,o=t*e-i*s;return h.a=e/o,h.b=-i/o,h.c=-s/o,h.d=t/o,h.e=(s*r-e*n)/o,h.f=-(t*r-i*n)/o,h}rotate(t){const i=Math.cos(t),s=Math.sin(t),e=this.a*i+this.c*s,n=this.b*i+this.d*s,r=this.a*-s+this.c*i,h=this.b*-s+this.d*i;return this.a=e,this.b=n,this.c=r,this.d=h,this}rotateByCenter(t,i,s){const e=Math.cos(t),n=Math.sin(t),r=(1-e)*i+n*s,h=(1-e)*s-n*i,o=e*this.a-n*this.b,a=n*this.a+e*this.b,c=e*this.c-n*this.d,u=n*this.c+e*this.d,l=e*this.e-n*this.f+r,f=n*this.e+e*this.f+h;return this.a=o,this.b=a,this.c=c,this.d=u,this.e=l,this.f=f,this}scale(t,i){return this.a*=t,this.b*=t,this.c*=i,this.d*=i,this}setScale(t,i){return this.b=this.b/this.a*t,this.c=this.c/this.d*i,this.a=t,this.d=i,this}transform(t,i,s,e,n,r){return this.multiply(t,i,s,e,n,r),this}translate(t,i){return this.e+=this.a*t+this.c*i,this.f+=this.b*t+this.d*i,this}transpose(){const{a:t,b:i,c:s,d:e,e:n,f:r}=this;return this.a=i,this.b=t,this.c=e,this.d=s,this.e=r,this.f=n,this}multiply(t,i,s,e,n,r){const h=this.a,o=this.b,a=this.c,c=this.d,u=h*t+a*i,l=o*t+c*i,f=h*s+a*e,y=o*s+c*e,d=h*n+a*r+this.e,x=o*n+c*r+this.f;return this.a=u,this.b=l,this.c=f,this.d=y,this.e=d,this.f=x,this}interpolate(t,i){const s=new u;return s.a=this.a+(t.a-this.a)*i,s.b=this.b+(t.b-this.b)*i,s.c=this.c+(t.c-this.c)*i,s.d=this.d+(t.d-this.d)*i,s.e=this.e+(t.e-this.e)*i,s.f=this.f+(t.f-this.f)*i,s}transformPoint(t,i){const{a:s,b:e,c:n,d:r,e:h,f:o}=this,a=s*r-e*n,c=r/a,u=-e/a,l=-n/a,f=s/a,y=(n*o-r*h)/a,d=-(s*o-e*h)/a,{x:x,y:p}=t;i.x=x*c+p*l+y,i.y=x*u+p*f+d}onlyTranslate(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return this.a===t&&0===this.b&&0===this.c&&this.d===t}clone(){return new u(this.a,this.b,this.c,this.d,this.e,this.f)}toTransformAttrs(){const t=this.a,i=this.b,s=this.c,e=this.d,n=t*e-i*s,r={x:this.e,y:this.f,rotateDeg:0,scaleX:0,scaleY:0,skewX:0,skewY:0};if(0!==t||0!==i){const h=Math.sqrt(t*t+i*i);r.rotateDeg=i>0?Math.acos(t/h):-Math.acos(t/h),r.scaleX=h,r.scaleY=n/h,r.skewX=(t*s+i*e)/n,r.skewY=0}else if(0!==s||0!==e){const h=Math.sqrt(s*s+e*e);r.rotateDeg=Math.PI/2-(e>0?Math.acos(-s/h):-Math.acos(s/h)),r.scaleX=n/h,r.scaleY=h,r.skewX=0,r.skewY=(t*s+i*e)/n}return r.rotateDeg=180*r.rotateDeg/Math.PI,r}}var l,f;!function(t){t[t.NONE=0]="NONE",t[t.BBOX1=1]="BBOX1",t[t.BBOX2=2]="BBOX2"}(l||(l={})),function(t){t[t.None=0]="None",t[t.Error=1]="Error",t[t.Warn=2]="Warn",t[t.Info=3]="Info",t[t.Debug=4]="Debug"}(f||(f={}));class y{type;startPoint={x:0,y:0};endPoint={x:0,y:0};originPoint={x:0,y:0};width=0;height=0;transforms=[];convertMatrix;invertMatrix;start(t,i){return s(t)?this.startPoint:(this.startPoint=this._parsePoint(t,i),this._updateSize(),this)}end(t,i){return s(t)?this.endPoint:(this.endPoint=this._parsePoint(t,i),this._updateSize(),this)}_parsePoint(t,i){const s={x:0,y:0};return e(t)?(s.x=t[0],s.y=t[1]):n(t)?(s.x=t,s.y=i):(s.x=t.x,s.y=t.y),s}_updateSize(){this.width=this.endPoint.x-this.startPoint.x,this.height=this.endPoint.y-this.startPoint.y}isTransposed(){return this.transforms&&this.transforms.filter((t=>"transpose"===t.type)).length%2!=0}isMainDimension(t){let i="x"===t||"theta"===t||"0"===t;return this.isTransposed()&&(i=!i),i}applyTransforms(t){return this.transforms=t.slice(),this._invokeTransforms(),this}_invokeTransforms(){this.invertMatrix=null,this.convertMatrix=null,this.invertMatrix=new u,this.invertMatrix.translate(this.originPoint.x,this.originPoint.y),this.transforms.forEach((t=>{switch(t.type){case"translate":this.invertMatrix.translate(t.offset.x,t.offset.y);break;case"rotate":this.invertMatrix.rotateByCenter(t.angle,this.originPoint.x,this.originPoint.y);break;case"scale":this.invertMatrix.scale(t.scale.x,t.scale.y);break;case"transpose":"polar"!==this.type&&this.invertMatrix.transpose()}})),this.invertMatrix,this.convertMatrix=this.invertMatrix.getInverse()}}t.CartesianCoordinate=class extends y{type="cartesian";convert(t){if(r(t.x1)||r(t.y1)){const i=this.convertPoint(t),s=this.convertPoint({x:t.x1??t.x,y:t.y1??t.y});return i.x1=s.x,i.y1=s.y,i}return this.convertPoint(t)}invert(t){if(r(t.x1)||r(t.y1)){const i=this.invertPoint(t),s=this.invertPoint({x:t.x1??t.x,y:t.y1??t.y});return i.x1=s.x,i.y1=s.y,i}return this.invertPoint(t)}getRangeByDimension(t,i,s){const e=this.start(),n=this.end(),r=this.isMainDimension(t)?[e.x,n.x]:[n.y,e.y];return s?[r[1],r[0]]:r}getVisiualPositionByDimension(t,i,s){return this.isMainDimension(t)?i?"top":"bottom":i?"right":"left"}getAxisPointsByDimension(t,i,e,n){const r=this.start(),h=this.end();if(this.isMainDimension(t)){const t=s(n)?i?[{x:r.x,y:r.y},{x:h.x,y:r.y}]:[{x:r.x,y:h.y},{x:h.x,y:h.y}]:[{x:r.x,y:n},{x:h.x,y:n}];return e?[t[1],t[0]]:t}const o=s(n)?i?[{x:h.x,y:h.y},{x:h.x,y:r.y}]:[{x:r.x,y:h.y},{x:r.x,y:r.y}]:[{x:n,y:h.y},{x:n,y:r.y}];return e?[o[1],o[0]]:o}convertPoint(t){const i=e(t)?{x:t[0],y:t[1]}:t,s=Object.assign({},i);return this.convertMatrix.transformPoint(i,s),s}invertPoint(t){const i=Object.assign({},t);return this.invertMatrix.transformPoint(t,i),i}},t.Coordinate=y,t.PolarCoordinate=class extends y{type="polar";_isUserOrigin=!1;_isUserRadius=!1;startAngle=0;endAngle=2*Math.PI;innerRadius=0;outerRadius=0;_updateStartEndPoint(){const t=this.origin(),i=Math.min(this.startAngle,this.endAngle),s=Math.max(this.startAngle,this.endAngle),e=2*i/Math.PI,n=2*s/Math.PI,r=[i,s];let h=Math.ceil(e);for(;h<=n;)r.push(h*Math.PI/2),h++;const o=r.length,a=[],u=[];for(h=0;h<o;h++){const i=c(t,this.innerRadius,r[h]),s=c(t,this.outerRadius,r[h]);a.push(i.x),a.push(s.x),u.push(i.y),u.push(s.y)}const l=Math.min.apply(null,a),f=Math.min.apply(null,u),y=Math.max.apply(null,a),d=Math.max.apply(null,u);this.startPoint={x:l,y:f},this.endPoint={x:y,y:d}}_updateSize(){super._updateSize(),this._isUserOrigin||(this.originPoint={x:this.width/2,y:this.height/2},this._invokeTransforms()),this._isUserRadius||(this.outerRadius=Math.min(Math.abs(this.startPoint.x-this.originPoint.x),Math.abs(this.endPoint.x-this.originPoint.x),Math.abs(this.startPoint.y-this.originPoint.y),Math.abs(this.endPoint.y-this.originPoint.y)))}angle(t,i){return s(t)?[this.startAngle,this.endAngle]:(Array.isArray(t)?(this.startAngle=t[0],this.endAngle=t[1]):(this.startAngle=t,this.endAngle=i??t),this._updateStartEndPoint(),this)}radius(t,i){return s(t)?[this.innerRadius,this.outerRadius]:(this._isUserRadius=!0,Array.isArray(t)?(this.innerRadius=Math.min(t[0],t[1]),this.outerRadius=Math.max(t[1],t[1])):(this.innerRadius=Math.min(t,i),this.outerRadius=Math.max(t,i)),this._updateStartEndPoint(),this)}origin(t,i){return s(t)?this.originPoint:(this._isUserOrigin=!0,this.originPoint=this._parsePoint(t,i),this._updateStartEndPoint(),this._invokeTransforms(),this)}convert(t){if(r(t.r1)||r(t.theta1)){const i=this.convertPoint(t),s=this.convertPoint({r:t.r1??t.r,theta:t.theta1??t.theta});return i.x1=s.x,i.y1=s.y,i}if(r(t.x1)||r(t.y1)){const i=this.convertPoint(t),s=this.convertPoint({x:t.x1??t.x,y:t.y1??t.y});return i.x1=s.x,i.y1=s.y,i}return this.convertPoint(t)}invert(t){if(r(t.x1)||r(t.y1)){const i=this.invertPoint(t),s=this.invertPoint({x:t.x1??t.x,y:t.y1??t.y});return i.r1=s.r,i.theta1=s.theta,i}return this.invertPoint(t)}getRangeByDimension(t,i,s){const e=this.isMainDimension(t)?[this.startAngle,this.endAngle]:[this.innerRadius,this.outerRadius];return s?[e[1],e[0]]:e}getVisiualPositionByDimension(t,i,s){return this.isMainDimension(t)?i?"inside":"outside":i?"end":"start"}getAxisPointsByDimension(t,i,e,n){if(!this.isMainDimension(t)){const t=this.origin(),r=s(n)?i?[c(t,this.innerRadius,this.endAngle),c(t,this.outerRadius,this.endAngle)]:[c(t,this.innerRadius,this.startAngle),c(t,this.outerRadius,this.startAngle)]:[c(t,this.innerRadius,n),c(t,this.outerRadius,n)];return e?[r[1],r[0]]:r}return null}convertPoint(t){const i=this.isTransposed();let n,r;s(t.r)||s(t.theta)?e(t)?(n=i?t[0]:t[1],r=i?t[1]:t[0]):(n=i?t.y:t.x,r=i?t.x:t.y):(n=i?t.r:t.theta,r=i?t.theta:t.r);const h={x:Math.cos(n)*r,y:Math.sin(n)*r};!1===t.defined&&(h.defined=!1);const o=Object.assign({},h);return this.convertMatrix.transformPoint(h,o),o}invertPoint(t){const i=Object.assign({},t);this.invertMatrix.transformPoint(t,i);const s=i.x,e=i.y;if(h(s,0)&&h(e,0)){const t={r:0,theta:0};return!1===i.defined&&(t.defined=!1),t}let n=Math.atan(e/s);n+=s>=0?2*Math.PI:Math.PI,n>=2*Math.PI&&(n-=2*Math.PI),n=function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;if(t<0)for(;t<-a;)t+=a;else if(t>0)for(;t>a;)t-=a;return t}(n);const r=h(e,0)?s/Math.cos(n):e/Math.sin(n),o=this.isTransposed()?{r:n,theta:r}:{r:r,theta:n};return!1===i.defined&&(o.defined=!1),o}}})); |
{ | ||
"name": "@visactor/vgrammar-coordinate", | ||
"version": "0.3.2", | ||
"version": "0.4.0", | ||
"description": "Coordinates for VGrammar", | ||
@@ -27,4 +27,4 @@ "keywords": [ | ||
"dependencies": { | ||
"@visactor/vgrammar-util": "0.3.2", | ||
"@visactor/vutils": "~0.11.1" | ||
"@visactor/vgrammar-util": "0.4.0", | ||
"@visactor/vutils": "~0.13.0" | ||
}, | ||
@@ -36,2 +36,3 @@ "devDependencies": { | ||
"jest": "~29.5.0", | ||
"jest-environment-jsdom": "~29.5.0", | ||
"@jest/globals": "~29.5.0", | ||
@@ -38,0 +39,0 @@ "ts-jest": "~29.1.0", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
168080
1860
14
+ Added@visactor/vgrammar-util@0.4.0(transitive)
+ Added@visactor/vutils@0.13.3(transitive)
- Removed@visactor/vgrammar-util@0.3.2(transitive)
- Removed@visactor/vutils@0.11.1(transitive)
Updated@visactor/vutils@~0.13.0