New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@visactor/vgrammar-coordinate

Package Overview
Dependencies
Maintainers
15
Versions
273
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@visactor/vgrammar-coordinate - npm Package Compare versions

Comparing version 0.2.1 to 0.3.0

1011

dist/index.js

@@ -1,1 +0,1010 @@

!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,e="~";function n(){}function s(t,i,e){this.fn=t,this.context=i,this.once=e||!1}function r(t,i,n,r,o){if("function"!=typeof n)throw new TypeError("The listener must be a function");var a=new s(n,r||t,o),h=e?e+i:i;return t._events[h]?t._events[h].fn?t._events[h]=[t._events[h],a]:t._events[h].push(a):(t._events[h]=a,t._eventsCount++),t}function o(t,i){0==--t._eventsCount?t._events=new n:delete t._events[i]}function a(){this._events=new n,this._eventsCount=0}Object.create&&(n.prototype=Object.create(null),(new n).__proto__||(e=!1)),a.prototype.eventNames=function(){var t,n,s=[];if(0===this._eventsCount)return s;for(n in t=this._events)i.call(t,n)&&s.push(e?n.slice(1):n);return Object.getOwnPropertySymbols?s.concat(Object.getOwnPropertySymbols(t)):s},a.prototype.listeners=function(t){var i=e?e+t:t,n=this._events[i];if(!n)return[];if(n.fn)return[n.fn];for(var s=0,r=n.length,o=new Array(r);s<r;s++)o[s]=n[s].fn;return o},a.prototype.listenerCount=function(t){var i=e?e+t:t,n=this._events[i];return n?n.fn?1:n.length:0},a.prototype.emit=function(t,i,n,s,r,o){var a=e?e+t:t;if(!this._events[a])return!1;var h,u,c=this._events[a],f=arguments.length;if(c.fn){switch(c.once&&this.removeListener(t,c.fn,void 0,!0),f){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,i),!0;case 3:return c.fn.call(c.context,i,n),!0;case 4:return c.fn.call(c.context,i,n,s),!0;case 5:return c.fn.call(c.context,i,n,s,r),!0;case 6:return c.fn.call(c.context,i,n,s,r,o),!0}for(u=1,h=new Array(f-1);u<f;u++)h[u-1]=arguments[u];c.fn.apply(c.context,h)}else{var l,y=c.length;for(u=0;u<y;u++)switch(c[u].once&&this.removeListener(t,c[u].fn,void 0,!0),f){case 1:c[u].fn.call(c[u].context);break;case 2:c[u].fn.call(c[u].context,i);break;case 3:c[u].fn.call(c[u].context,i,n);break;case 4:c[u].fn.call(c[u].context,i,n,s);break;default:if(!h)for(l=1,h=new Array(f-1);l<f;l++)h[l-1]=arguments[l];c[u].fn.apply(c[u].context,h)}}return!0},a.prototype.on=function(t,i,e){return r(this,t,i,e,!1)},a.prototype.once=function(t,i,e){return r(this,t,i,e,!0)},a.prototype.removeListener=function(t,i,n,s){var r=e?e+t:t;if(!this._events[r])return this;if(!i)return o(this,r),this;var a=this._events[r];if(a.fn)a.fn!==i||s&&!a.once||n&&a.context!==n||o(this,r);else{for(var h=0,u=[],c=a.length;h<c;h++)(a[h].fn!==i||s&&!a[h].once||n&&a[h].context!==n)&&u.push(a[h]);u.length?this._events[r]=1===u.length?u[0]:u:o(this,r)}return this},a.prototype.removeAllListeners=function(t){var i;return t?(i=e?e+t:t,this._events[i]&&o(this,i)):(this._events=new n,this._eventsCount=0),this},a.prototype.off=a.prototype.removeListener,a.prototype.addListener=a.prototype.on,a.prefixed=e,a.EventEmitter=a,t.exports=a}({exports:{}});var i=function(t,i){return toString.call(t)==="[object ".concat(i,"]")},e=function(t){return null==t};function n(t){return n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},n(t)}function s(t,i){for(var e=0;e<i.length;e++){var n=i[e];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,(s=n.key,r=void 0,"symbol"==typeof(r=function(t,i){if("object"!=typeof t||null===t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,i||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===i?String:Number)(t)}(s,"string"))?r:String(r)),n)}var s,r}var r=function(t){return Array.isArray?Array.isArray(t):i(t,"Array")},o=function(t){var e=arguments.length>1&&void 0!==arguments[1]&&arguments[1],s=n(t);return e?"number"===s:"number"===s||i(t,"Number")},a=function(t){return o(t)&&Number.isFinite(t)};function h(t,i){var e=arguments.length>3&&void 0!==arguments[3]?arguments[3]:1e-10,n=(arguments.length>2&&void 0!==arguments[2]?arguments[2]:1e-10)*Math.max(t,i);return Math.abs(t-i)<=Math.max(e,n)}try{"function"==typeof requestAnimationFrame&&"function"==typeof cancelAnimationFrame}catch(t){!1}var u=2*Math.PI;function c(t,i,e){return{x:t.x+i*Math.cos(e),y:t.y+i*Math.sin(e)}}var f,l=function(){function t(){var i=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:1,r=arguments.length>4&&void 0!==arguments[4]?arguments[4]:0,o=arguments.length>5&&void 0!==arguments[5]?arguments[5]:0;!function(t,i){if(!(t instanceof i))throw new TypeError("Cannot call a class as a function")}(this,t),this.a=i,this.b=e,this.c=n,this.d=s,this.e=r,this.f=o}var i,e,n;return i=t,e=[{key:"equalToMatrix",value:function(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)}},{key:"equalTo",value:function(t,i,e,n,s,r){return!(this.e!==s||this.f!==r||this.a!==t||this.d!==n||this.b!==i||this.c!==e)}},{key:"setValue",value:function(t,i,e,n,s,r){return this.a=t,this.b=i,this.c=e,this.d=n,this.e=s,this.f=r,this}},{key:"reset",value:function(){return this.a=1,this.b=0,this.c=0,this.d=1,this.e=0,this.f=0,this}},{key:"getInverse",value:function(){var i=this.a,e=this.b,n=this.c,s=this.d,r=this.e,o=this.f,a=new t,h=i*s-e*n;return a.a=s/h,a.b=-e/h,a.c=-n/h,a.d=i/h,a.e=(n*o-s*r)/h,a.f=-(i*o-e*r)/h,a}},{key:"rotate",value:function(t){var i=Math.cos(t),e=Math.sin(t),n=this.a*i+this.c*e,s=this.b*i+this.d*e,r=this.a*-e+this.c*i,o=this.b*-e+this.d*i;return this.a=n,this.b=s,this.c=r,this.d=o,this}},{key:"rotateByCenter",value:function(t,i,e){var n=Math.cos(t),s=Math.sin(t),r=(1-n)*i+s*e,o=(1-n)*e-s*i,a=n*this.a-s*this.b,h=s*this.a+n*this.b,u=n*this.c-s*this.d,c=s*this.c+n*this.d,f=n*this.e-s*this.f+r,l=s*this.e+n*this.f+o;return this.a=a,this.b=h,this.c=u,this.d=c,this.e=f,this.f=l,this}},{key:"scale",value:function(t,i){return this.a*=t,this.b*=t,this.c*=i,this.d*=i,this}},{key:"setScale",value:function(t,i){return this.b=this.b/this.a*t,this.c=this.c/this.d*i,this.a=t,this.d=i,this}},{key:"transform",value:function(t,i,e,n,s,r){return this.multiply(t,i,e,n,s,r),this}},{key:"translate",value:function(t,i){return this.e+=this.a*t+this.c*i,this.f+=this.b*t+this.d*i,this}},{key:"transpose",value:function(){var t=this.a,i=this.b,e=this.c,n=this.d,s=this.e,r=this.f;return this.a=i,this.b=t,this.c=n,this.d=e,this.e=r,this.f=s,this}},{key:"multiply",value:function(t,i,e,n,s,r){var o=this.a,a=this.b,h=this.c,u=this.d,c=o*t+h*i,f=a*t+u*i,l=o*e+h*n,y=a*e+u*n,v=o*s+h*r+this.e,d=a*s+u*r+this.f;return this.a=c,this.b=f,this.c=l,this.d=y,this.e=v,this.f=d,this}},{key:"interpolate",value:function(i,e){var n=new t;return n.a=this.a+(i.a-this.a)*e,n.b=this.b+(i.b-this.b)*e,n.c=this.c+(i.c-this.c)*e,n.d=this.d+(i.d-this.d)*e,n.e=this.e+(i.e-this.e)*e,n.f=this.f+(i.f-this.f)*e,n}},{key:"transformPoint",value:function(t,i){var e=this.a,n=this.b,s=this.c,r=this.d,o=this.e,a=this.f,h=e*r-n*s,u=r/h,c=-n/h,f=-s/h,l=e/h,y=(s*a-r*o)/h,v=-(e*a-n*o)/h,d=t.x,x=t.y;i.x=d*u+x*f+y,i.y=d*c+x*l+v}},{key:"onlyTranslate",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return this.a===t&&0===this.b&&0===this.c&&this.d===t}},{key:"clone",value:function(){return new t(this.a,this.b,this.c,this.d,this.e,this.f)}},{key:"toTransformAttrs",value:function(){var t=this.a,i=this.b,e=this.c,n=this.d,s=t*n-i*e,r={x:this.e,y:this.f,rotateDeg:0,scaleX:0,scaleY:0,skewX:0,skewY:0};if(0!==t||0!==i){var o=Math.sqrt(t*t+i*i);r.rotateDeg=i>0?Math.acos(t/o):-Math.acos(t/o),r.scaleX=o,r.scaleY=s/o,r.skewX=(t*e+i*n)/s,r.skewY=0}else if(0!==e||0!==n){var a=Math.sqrt(e*e+n*n);r.rotateDeg=Math.PI/2-(n>0?Math.acos(-e/a):-Math.acos(e/a)),r.scaleX=s/a,r.scaleY=a,r.skewX=0,r.skewY=(t*e+i*n)/s}return r.rotateDeg=180*r.rotateDeg/Math.PI,r}}],e&&s(i.prototype,e),n&&s(i,n),Object.defineProperty(i,"prototype",{writable:!1}),t}();!function(t){t[t.NONE=0]="NONE",t[t.BBOX1=1]="BBOX1",t[t.BBOX2=2]="BBOX2"}(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 e(t)?this.startPoint:(this.startPoint=this._parsePoint(t,i),this._updateSize(),this)}end(t,i){return e(t)?this.endPoint:(this.endPoint=this._parsePoint(t,i),this._updateSize(),this)}_parsePoint(t,i){const e={x:0,y:0};return r(t)?(e.x=t[0],e.y=t[1]):o(t)?(e.x=t,e.y=i):(e.x=t.x,e.y=t.y),e}_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 l,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(a(t.x1)||a(t.y1)){const i=this.convertPoint(t),e=this.convertPoint({x:t.x1??t.x,y:t.y1??t.y});return i.x1=e.x,i.y1=e.y,i}return this.convertPoint(t)}invert(t){if(a(t.x1)||a(t.y1)){const i=this.invertPoint(t),e=this.invertPoint({x:t.x1??t.x,y:t.y1??t.y});return i.x1=e.x,i.y1=e.y,i}return this.invertPoint(t)}getRangeByDimension(t,i,e){const n=this.start(),s=this.end(),r=this.isMainDimension(t)?[n.x,s.x]:[s.y,n.y];return e?[r[1],r[0]]:r}getVisiualPositionByDimension(t,i,e){return this.isMainDimension(t)?i?"top":"bottom":i?"right":"left"}getAxisPointsByDimension(t,i,n,s){const r=this.start(),o=this.end();if(this.isMainDimension(t)){const t=e(s)?i?[{x:r.x,y:r.y},{x:o.x,y:r.y}]:[{x:r.x,y:o.y},{x:o.x,y:o.y}]:[{x:r.x,y:s},{x:o.x,y:s}];return n?[t[1],t[0]]:t}const a=e(s)?i?[{x:o.x,y:o.y},{x:o.x,y:r.y}]:[{x:r.x,y:o.y},{x:r.x,y:r.y}]:[{x:s,y:o.y},{x:s,y:r.y}];return n?[a[1],a[0]]:a}convertPoint(t){const i=r(t)?{x:t[0],y:t[1]}:t,e=Object.assign({},i);return this.convertMatrix.transformPoint(i,e),e}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),e=Math.max(this.startAngle,this.endAngle),n=2*i/Math.PI,s=2*e/Math.PI,r=[i,e];let o=Math.ceil(n);for(;o<=s;)r.push(o*Math.PI/2),o++;const a=r.length,h=[],u=[];for(o=0;o<a;o++){const i=c(t,this.innerRadius,r[o]),e=c(t,this.outerRadius,r[o]);h.push(i.x),h.push(e.x),u.push(i.y),u.push(e.y)}const f=Math.min.apply(null,h),l=Math.min.apply(null,u),y=Math.max.apply(null,h),v=Math.max.apply(null,u);this.startPoint={x:f,y:l},this.endPoint={x:y,y:v}}_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 e(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 e(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 e(t)?this.originPoint:(this._isUserOrigin=!0,this.originPoint=this._parsePoint(t,i),this._updateStartEndPoint(),this._invokeTransforms(),this)}convert(t){if(a(t.r1)||a(t.theta1)){const i=this.convertPoint(t),e=this.convertPoint({r:t.r1??t.r,theta:t.theta1??t.theta});return i.x1=e.x,i.y1=e.y,i}if(a(t.x1)||a(t.y1)){const i=this.convertPoint(t),e=this.convertPoint({x:t.x1??t.x,y:t.y1??t.y});return i.x1=e.x,i.y1=e.y,i}return this.convertPoint(t)}invert(t){if(a(t.x1)||a(t.y1)){const i=this.invertPoint(t),e=this.invertPoint({x:t.x1??t.x,y:t.y1??t.y});return i.r1=e.r,i.theta1=e.theta,i}return this.invertPoint(t)}getRangeByDimension(t,i,e){const n=this.isMainDimension(t)?[this.startAngle,this.endAngle]:[this.innerRadius,this.outerRadius];return e?[n[1],n[0]]:n}getVisiualPositionByDimension(t,i,e){return this.isMainDimension(t)?i?"inside":"outside":i?"end":"start"}getAxisPointsByDimension(t,i,n,s){if(!this.isMainDimension(t)){const t=this.origin(),r=e(s)?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,s),c(t,this.outerRadius,s)];return n?[r[1],r[0]]:r}return null}convertPoint(t){const i=this.isTransposed();let n,s;e(t.r)||e(t.theta)?r(t)?(n=i?t[0]:t[1],s=i?t[1]:t[0]):(n=i?t.y:t.x,s=i?t.x:t.y):(n=i?t.r:t.theta,s=i?t.theta:t.r);const o={x:Math.cos(n)*s,y:Math.sin(n)*s};!1===t.defined&&(o.defined=!1);const a=Object.assign({},o);return this.convertMatrix.transformPoint(o,a),a}invertPoint(t){const i=Object.assign({},t);this.invertMatrix.transformPoint(t,i);const e=i.x,n=i.y;if(h(e,0)&&h(n,0)){const t={r:0,theta:0};return!1===i.defined&&(t.defined=!1),t}let s=Math.atan(n/e);s+=e>=0?2*Math.PI:Math.PI,s>=2*Math.PI&&(s-=2*Math.PI),s=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;if(t<0)for(;t<-u;)t+=u;else if(t>0)for(;t>u;)t-=u;return t}(s);const r=h(n,0)?e/Math.cos(s):n/Math.sin(s),o=this.isTransposed()?{r:s,theta:r}:{r:r,theta:s};return!1===i.defined&&(o.defined=!1),o}}}));
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.VGrammar = global.VGrammar || {}, global.VGrammar.Coordinate = {})));
})(this, (function (exports) { 'use strict';
var eventemitter3 = {exports: {}};
(function (module) {
var has = Object.prototype.hasOwnProperty,
prefix = '~';
/**
* Constructor to create a storage for our `EE` objects.
* An `Events` instance is a plain object whose properties are event names.
*
* @constructor
* @private
*/
function Events() {}
//
// We try to not inherit from `Object.prototype`. In some engines creating an
// instance in this way is faster than calling `Object.create(null)` directly.
// If `Object.create(null)` is not supported we prefix the event names with a
// character to make sure that the built-in object properties are not
// overridden or used as an attack vector.
//
if (Object.create) {
Events.prototype = Object.create(null);
//
// This hack is needed because the `__proto__` property is still inherited in
// some old browsers like Android 4, iPhone 5.1, Opera 11 and Safari 5.
//
if (!new Events().__proto__) prefix = false;
}
/**
* Representation of a single event listener.
*
* @param {Function} fn The listener function.
* @param {*} context The context to invoke the listener with.
* @param {Boolean} [once=false] Specify if the listener is a one-time listener.
* @constructor
* @private
*/
function EE(fn, context, once) {
this.fn = fn;
this.context = context;
this.once = once || false;
}
/**
* Add a listener for a given event.
*
* @param {EventEmitter} emitter Reference to the `EventEmitter` instance.
* @param {(String|Symbol)} event The event name.
* @param {Function} fn The listener function.
* @param {*} context The context to invoke the listener with.
* @param {Boolean} once Specify if the listener is a one-time listener.
* @returns {EventEmitter}
* @private
*/
function addListener(emitter, event, fn, context, once) {
if (typeof fn !== 'function') {
throw new TypeError('The listener must be a function');
}
var listener = new EE(fn, context || emitter, once),
evt = prefix ? prefix + event : event;
if (!emitter._events[evt]) emitter._events[evt] = listener, emitter._eventsCount++;else if (!emitter._events[evt].fn) emitter._events[evt].push(listener);else emitter._events[evt] = [emitter._events[evt], listener];
return emitter;
}
/**
* Clear event by name.
*
* @param {EventEmitter} emitter Reference to the `EventEmitter` instance.
* @param {(String|Symbol)} evt The Event name.
* @private
*/
function clearEvent(emitter, evt) {
if (--emitter._eventsCount === 0) emitter._events = new Events();else delete emitter._events[evt];
}
/**
* Minimal `EventEmitter` interface that is molded against the Node.js
* `EventEmitter` interface.
*
* @constructor
* @public
*/
function EventEmitter() {
this._events = new Events();
this._eventsCount = 0;
}
/**
* Return an array listing the events for which the emitter has registered
* listeners.
*
* @returns {Array}
* @public
*/
EventEmitter.prototype.eventNames = function eventNames() {
var names = [],
events,
name;
if (this._eventsCount === 0) return names;
for (name in events = this._events) {
if (has.call(events, name)) names.push(prefix ? name.slice(1) : name);
}
if (Object.getOwnPropertySymbols) {
return names.concat(Object.getOwnPropertySymbols(events));
}
return names;
};
/**
* Return the listeners registered for a given event.
*
* @param {(String|Symbol)} event The event name.
* @returns {Array} The registered listeners.
* @public
*/
EventEmitter.prototype.listeners = function listeners(event) {
var evt = prefix ? prefix + event : event,
handlers = this._events[evt];
if (!handlers) return [];
if (handlers.fn) return [handlers.fn];
for (var i = 0, l = handlers.length, ee = new Array(l); i < l; i++) {
ee[i] = handlers[i].fn;
}
return ee;
};
/**
* Return the number of listeners listening to a given event.
*
* @param {(String|Symbol)} event The event name.
* @returns {Number} The number of listeners.
* @public
*/
EventEmitter.prototype.listenerCount = function listenerCount(event) {
var evt = prefix ? prefix + event : event,
listeners = this._events[evt];
if (!listeners) return 0;
if (listeners.fn) return 1;
return listeners.length;
};
/**
* Calls each of the listeners registered for a given event.
*
* @param {(String|Symbol)} event The event name.
* @returns {Boolean} `true` if the event had listeners, else `false`.
* @public
*/
EventEmitter.prototype.emit = function emit(event, a1, a2, a3, a4, a5) {
var evt = prefix ? prefix + event : event;
if (!this._events[evt]) return false;
var listeners = this._events[evt],
len = arguments.length,
args,
i;
if (listeners.fn) {
if (listeners.once) this.removeListener(event, listeners.fn, undefined, true);
switch (len) {
case 1:
return listeners.fn.call(listeners.context), true;
case 2:
return listeners.fn.call(listeners.context, a1), true;
case 3:
return listeners.fn.call(listeners.context, a1, a2), true;
case 4:
return listeners.fn.call(listeners.context, a1, a2, a3), true;
case 5:
return listeners.fn.call(listeners.context, a1, a2, a3, a4), true;
case 6:
return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true;
}
for (i = 1, args = new Array(len - 1); i < len; i++) {
args[i - 1] = arguments[i];
}
listeners.fn.apply(listeners.context, args);
} else {
var length = listeners.length,
j;
for (i = 0; i < length; i++) {
if (listeners[i].once) this.removeListener(event, listeners[i].fn, undefined, true);
switch (len) {
case 1:
listeners[i].fn.call(listeners[i].context);
break;
case 2:
listeners[i].fn.call(listeners[i].context, a1);
break;
case 3:
listeners[i].fn.call(listeners[i].context, a1, a2);
break;
case 4:
listeners[i].fn.call(listeners[i].context, a1, a2, a3);
break;
default:
if (!args) for (j = 1, args = new Array(len - 1); j < len; j++) {
args[j - 1] = arguments[j];
}
listeners[i].fn.apply(listeners[i].context, args);
}
}
}
return true;
};
/**
* Add a listener for a given event.
*
* @param {(String|Symbol)} event The event name.
* @param {Function} fn The listener function.
* @param {*} [context=this] The context to invoke the listener with.
* @returns {EventEmitter} `this`.
* @public
*/
EventEmitter.prototype.on = function on(event, fn, context) {
return addListener(this, event, fn, context, false);
};
/**
* Add a one-time listener for a given event.
*
* @param {(String|Symbol)} event The event name.
* @param {Function} fn The listener function.
* @param {*} [context=this] The context to invoke the listener with.
* @returns {EventEmitter} `this`.
* @public
*/
EventEmitter.prototype.once = function once(event, fn, context) {
return addListener(this, event, fn, context, true);
};
/**
* Remove the listeners of a given event.
*
* @param {(String|Symbol)} event The event name.
* @param {Function} fn Only remove the listeners that match this function.
* @param {*} context Only remove the listeners that have this context.
* @param {Boolean} once Only remove one-time listeners.
* @returns {EventEmitter} `this`.
* @public
*/
EventEmitter.prototype.removeListener = function removeListener(event, fn, context, once) {
var evt = prefix ? prefix + event : event;
if (!this._events[evt]) return this;
if (!fn) {
clearEvent(this, evt);
return this;
}
var listeners = this._events[evt];
if (listeners.fn) {
if (listeners.fn === fn && (!once || listeners.once) && (!context || listeners.context === context)) {
clearEvent(this, evt);
}
} else {
for (var i = 0, events = [], length = listeners.length; i < length; i++) {
if (listeners[i].fn !== fn || once && !listeners[i].once || context && listeners[i].context !== context) {
events.push(listeners[i]);
}
}
//
// Reset the array, or remove it completely if we have no more listeners.
//
if (events.length) this._events[evt] = events.length === 1 ? events[0] : events;else clearEvent(this, evt);
}
return this;
};
/**
* Remove all listeners, or those of the specified event.
*
* @param {(String|Symbol)} [event] The event name.
* @returns {EventEmitter} `this`.
* @public
*/
EventEmitter.prototype.removeAllListeners = function removeAllListeners(event) {
var evt;
if (event) {
evt = prefix ? prefix + event : event;
if (this._events[evt]) clearEvent(this, evt);
} else {
this._events = new Events();
this._eventsCount = 0;
}
return this;
};
//
// Alias methods names because people roll like that.
//
EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
EventEmitter.prototype.addListener = EventEmitter.prototype.on;
//
// Expose the prefix.
//
EventEmitter.prefixed = prefix;
//
// Allow `EventEmitter` to be imported as module namespace.
//
EventEmitter.EventEmitter = EventEmitter;
//
// Expose the module.
//
{
module.exports = EventEmitter;
}
})(eventemitter3);
var isType = function isType(value, type) {
return toString.call(value) === "[object ".concat(type, "]");
};
var isNil = function isNil(value) {
return null == value;
};
function _typeof(obj) {
"@babel/helpers - typeof";
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
return typeof obj;
} : function (obj) {
return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
}, _typeof(obj);
}
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}
function _defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
}
}
function _createClass(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
if (staticProps) _defineProperties(Constructor, staticProps);
Object.defineProperty(Constructor, "prototype", {
writable: false
});
return Constructor;
}
function _toPrimitive(input, hint) {
if (typeof input !== "object" || input === null) return input;
var prim = input[Symbol.toPrimitive];
if (prim !== undefined) {
var res = prim.call(input, hint || "default");
if (typeof res !== "object") return res;
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return (hint === "string" ? String : Number)(input);
}
function _toPropertyKey(arg) {
var key = _toPrimitive(arg, "string");
return typeof key === "symbol" ? key : String(key);
}
var isArray = function isArray(value) {
return Array.isArray ? Array.isArray(value) : isType(value, "Array");
};
var isNumber = function isNumber(value) {
var fuzzy = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : !1;
var type = _typeof(value);
return fuzzy ? "number" === type : "number" === type || isType(value, "Number");
};
var isValidNumber = function isValidNumber(value) {
return isNumber(value) && Number.isFinite(value);
};
var DEFAULT_ABSOLUTE_TOLERATE = 1e-10,
DEFAULT_RELATIVE_TOLERATE = 1e-10;
function isNumberClose(a, b) {
var relTol = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : DEFAULT_RELATIVE_TOLERATE;
var absTol = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : DEFAULT_ABSOLUTE_TOLERATE;
var abs = absTol,
rel = relTol * Math.max(a, b);
return Math.abs(a - b) <= Math.max(abs, rel);
}
var hasRaf = !1;
try {
hasRaf = "function" == typeof requestAnimationFrame && "function" == typeof cancelAnimationFrame;
} catch (err) {
hasRaf = !1;
}
hasRaf = !1;
var pi = Math.PI;
var tau = 2 * pi;
function radianToDegree(radian) {
return 180 * radian / Math.PI;
}
var clampRadian = function clampRadian() {
var angle = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
if (angle < 0) for (; angle < -tau;) angle += tau;else if (angle > 0) for (; angle > tau;) angle -= tau;
return angle;
};
function polarToCartesian(center, radius, angleInRadian) {
return {
x: center.x + radius * Math.cos(angleInRadian),
y: center.y + radius * Math.sin(angleInRadian)
};
}
var Matrix = /*#__PURE__*/function () {
function Matrix() {
var a = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
var b = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
var c = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
var d = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 1;
var e = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;
var f = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 0;
_classCallCheck(this, Matrix);
this.a = a, this.b = b, this.c = c, this.d = d, this.e = e, this.f = f;
}
_createClass(Matrix, [{
key: "equalToMatrix",
value: function equalToMatrix(m2) {
return !(this.e !== m2.e || this.f !== m2.f || this.a !== m2.a || this.d !== m2.d || this.b !== m2.b || this.c !== m2.c);
}
}, {
key: "equalTo",
value: function equalTo(a, b, c, d, e, f) {
return !(this.e !== e || this.f !== f || this.a !== a || this.d !== d || this.b !== b || this.c !== c);
}
}, {
key: "setValue",
value: function setValue(a, b, c, d, e, f) {
return this.a = a, this.b = b, this.c = c, this.d = d, this.e = e, this.f = f, this;
}
}, {
key: "reset",
value: function reset() {
return this.a = 1, this.b = 0, this.c = 0, this.d = 1, this.e = 0, this.f = 0, this;
}
}, {
key: "getInverse",
value: function getInverse() {
var a = this.a,
b = this.b,
c = this.c,
d = this.d,
e = this.e,
f = this.f,
m = new Matrix(),
dt = a * d - b * c;
return m.a = d / dt, m.b = -b / dt, m.c = -c / dt, m.d = a / dt, m.e = (c * f - d * e) / dt, m.f = -(a * f - b * e) / dt, m;
}
}, {
key: "rotate",
value: function rotate(rad) {
var c = Math.cos(rad),
s = Math.sin(rad),
m11 = this.a * c + this.c * s,
m12 = this.b * c + this.d * s,
m21 = this.a * -s + this.c * c,
m22 = this.b * -s + this.d * c;
return this.a = m11, this.b = m12, this.c = m21, this.d = m22, this;
}
}, {
key: "rotateByCenter",
value: function rotateByCenter(rad, cx, cy) {
var cos = Math.cos(rad),
sin = Math.sin(rad),
rotateM13 = (1 - cos) * cx + sin * cy,
rotateM23 = (1 - cos) * cy - sin * cx,
m11 = cos * this.a - sin * this.b,
m21 = sin * this.a + cos * this.b,
m12 = cos * this.c - sin * this.d,
m22 = sin * this.c + cos * this.d,
m13 = cos * this.e - sin * this.f + rotateM13,
m23 = sin * this.e + cos * this.f + rotateM23;
return this.a = m11, this.b = m21, this.c = m12, this.d = m22, this.e = m13, this.f = m23, this;
}
}, {
key: "scale",
value: function scale(sx, sy) {
return this.a *= sx, this.b *= sx, this.c *= sy, this.d *= sy, this;
}
}, {
key: "setScale",
value: function setScale(sx, sy) {
return this.b = this.b / this.a * sx, this.c = this.c / this.d * sy, this.a = sx, this.d = sy, this;
}
}, {
key: "transform",
value: function transform(a, b, c, d, e, f) {
return this.multiply(a, b, c, d, e, f), this;
}
}, {
key: "translate",
value: function translate(x, y) {
return this.e += this.a * x + this.c * y, this.f += this.b * x + this.d * y, this;
}
}, {
key: "transpose",
value: function transpose() {
var a = this.a,
b = this.b,
c = this.c,
d = this.d,
e = this.e,
f = this.f;
return this.a = b, this.b = a, this.c = d, this.d = c, this.e = f, this.f = e, this;
}
}, {
key: "multiply",
value: function multiply(a2, b2, c2, d2, e2, f2) {
var a1 = this.a,
b1 = this.b,
c1 = this.c,
d1 = this.d,
m11 = a1 * a2 + c1 * b2,
m12 = b1 * a2 + d1 * b2,
m21 = a1 * c2 + c1 * d2,
m22 = b1 * c2 + d1 * d2,
dx = a1 * e2 + c1 * f2 + this.e,
dy = b1 * e2 + d1 * f2 + this.f;
return this.a = m11, this.b = m12, this.c = m21, this.d = m22, this.e = dx, this.f = dy, this;
}
}, {
key: "interpolate",
value: function interpolate(m2, t) {
var m = new Matrix();
return m.a = this.a + (m2.a - this.a) * t, m.b = this.b + (m2.b - this.b) * t, m.c = this.c + (m2.c - this.c) * t, m.d = this.d + (m2.d - this.d) * t, m.e = this.e + (m2.e - this.e) * t, m.f = this.f + (m2.f - this.f) * t, m;
}
}, {
key: "transformPoint",
value: function transformPoint(source, target) {
var a = this.a,
b = this.b,
c = this.c,
d = this.d,
e = this.e,
f = this.f,
dt = a * d - b * c,
nextA = d / dt,
nextB = -b / dt,
nextC = -c / dt,
nextD = a / dt,
nextE = (c * f - d * e) / dt,
nextF = -(a * f - b * e) / dt,
x = source.x,
y = source.y;
target.x = x * nextA + y * nextC + nextE, target.y = x * nextB + y * nextD + nextF;
}
}, {
key: "onlyTranslate",
value: function onlyTranslate() {
var scale = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
return this.a === scale && 0 === this.b && 0 === this.c && this.d === scale;
}
}, {
key: "clone",
value: function clone() {
return new Matrix(this.a, this.b, this.c, this.d, this.e, this.f);
}
}, {
key: "toTransformAttrs",
value: function toTransformAttrs() {
var a = this.a,
b = this.b,
c = this.c,
d = this.d,
delta = a * d - b * c,
result = {
x: this.e,
y: this.f,
rotateDeg: 0,
scaleX: 0,
scaleY: 0,
skewX: 0,
skewY: 0
};
if (0 !== a || 0 !== b) {
var r = Math.sqrt(a * a + b * b);
result.rotateDeg = b > 0 ? Math.acos(a / r) : -Math.acos(a / r), result.scaleX = r, result.scaleY = delta / r, result.skewX = (a * c + b * d) / delta, result.skewY = 0;
} else if (0 !== c || 0 !== d) {
var s = Math.sqrt(c * c + d * d);
result.rotateDeg = Math.PI / 2 - (d > 0 ? Math.acos(-c / s) : -Math.acos(c / s)), result.scaleX = delta / s, result.scaleY = s, result.skewX = 0, result.skewY = (a * c + b * d) / delta;
}
return result.rotateDeg = radianToDegree(result.rotateDeg), result;
}
}]);
return Matrix;
}();
var InnerBBox;
!function (InnerBBox) {
InnerBBox[InnerBBox.NONE = 0] = "NONE", InnerBBox[InnerBBox.BBOX1 = 1] = "BBOX1", InnerBBox[InnerBBox.BBOX2 = 2] = "BBOX2";
}(InnerBBox || (InnerBBox = {}));
class Coordinate {
type;
startPoint = { x: 0, y: 0 };
endPoint = { x: 0, y: 0 };
originPoint = { x: 0, y: 0 };
width = 0;
height = 0;
transforms = [];
convertMatrix;
invertMatrix;
start(x, y) {
if (isNil(x)) {
return this.startPoint;
}
this.startPoint = this._parsePoint(x, y);
this._updateSize();
return this;
}
end(x, y) {
if (isNil(x)) {
return this.endPoint;
}
this.endPoint = this._parsePoint(x, y);
this._updateSize();
return this;
}
_parsePoint(x, y) {
const point = { x: 0, y: 0 };
if (isArray(x)) {
point.x = x[0];
point.y = x[1];
}
else if (isNumber(x)) {
point.x = x;
point.y = y;
}
else {
point.x = x.x;
point.y = x.y;
}
return point;
}
_updateSize() {
this.width = this.endPoint.x - this.startPoint.x;
this.height = this.endPoint.y - this.startPoint.y;
}
isTransposed() {
return this.transforms && this.transforms.filter(transform => transform.type === 'transpose').length % 2 !== 0;
}
isMainDimension(dim) {
let isMain = dim === 'x' || dim === 'theta' || dim === '0';
if (this.isTransposed()) {
isMain = !isMain;
}
return isMain;
}
applyTransforms(transforms) {
this.transforms = transforms.slice();
this._invokeTransforms();
return this;
}
_invokeTransforms() {
this.invertMatrix = null;
this.convertMatrix = null;
this.invertMatrix = new Matrix();
this.invertMatrix.translate(this.originPoint.x, this.originPoint.y);
this.transforms.forEach(transform => {
switch (transform.type) {
case 'translate':
this.invertMatrix.translate(transform.offset.x, transform.offset.y);
break;
case 'rotate':
this.invertMatrix.rotateByCenter(transform.angle, this.originPoint.x, this.originPoint.y);
break;
case 'scale':
this.invertMatrix.scale(transform.scale.x, transform.scale.y);
break;
case 'transpose':
if (this.type !== 'polar') {
this.invertMatrix.transpose();
}
break;
}
});
this.invertMatrix;
this.convertMatrix = this.invertMatrix.getInverse();
}
}
class CartesianCoordinate extends Coordinate {
type = 'cartesian';
convert(point) {
if (isValidNumber(point.x1) || isValidNumber(point.y1)) {
const convertedPoint = this.convertPoint(point);
const convertedPoint1 = this.convertPoint({
x: point.x1 ?? point.x,
y: point.y1 ?? point.y
});
convertedPoint.x1 = convertedPoint1.x;
convertedPoint.y1 = convertedPoint1.y;
return convertedPoint;
}
return this.convertPoint(point);
}
invert(point) {
if (isValidNumber(point.x1) || isValidNumber(point.y1)) {
const invertedPoint = this.invertPoint(point);
const invertedPoint1 = this.invertPoint({ x: point.x1 ?? point.x, y: point.y1 ?? point.y });
invertedPoint.x1 = invertedPoint1.x;
invertedPoint.y1 = invertedPoint1.y;
return invertedPoint;
}
return this.invertPoint(point);
}
getRangeByDimension(dim, isSubshaft, reversed) {
const start = this.start();
const end = this.end();
const isMain = this.isMainDimension(dim);
const res = isMain ? [start.x, end.x] : [end.y, start.y];
return reversed ? [res[1], res[0]] : res;
}
getVisiualPositionByDimension(dim, isSubshaft, reversed) {
const isMain = this.isMainDimension(dim);
return isMain ? (isSubshaft ? 'top' : 'bottom') : isSubshaft ? 'right' : 'left';
}
getAxisPointsByDimension(dim, isSubshaft, reversed, baseValue) {
const start = this.start();
const end = this.end();
const isMain = this.isMainDimension(dim);
if (isMain) {
const res = !isNil(baseValue)
? [
{ x: start.x, y: baseValue },
{ x: end.x, y: baseValue }
]
: isSubshaft
? [
{ x: start.x, y: start.y },
{ x: end.x, y: start.y }
]
: [
{ x: start.x, y: end.y },
{ x: end.x, y: end.y }
];
return reversed ? [res[1], res[0]] : res;
}
const res = !isNil(baseValue)
? [
{ x: baseValue, y: end.y },
{ x: baseValue, y: start.y }
]
: isSubshaft
? [
{ x: end.x, y: end.y },
{ x: end.x, y: start.y }
]
: [
{ x: start.x, y: end.y },
{ x: start.x, y: start.y }
];
return reversed ? [res[1], res[0]] : res;
}
convertPoint(point) {
const originPoint = isArray(point) ? { x: point[0], y: point[1] } : point;
const transformedPoint = Object.assign({}, originPoint);
this.convertMatrix.transformPoint(originPoint, transformedPoint);
return transformedPoint;
}
invertPoint(point) {
const untransformedPoint = Object.assign({}, point);
this.invertMatrix.transformPoint(point, untransformedPoint);
return untransformedPoint;
}
}
class PolarCoordinate extends Coordinate {
type = 'polar';
_isUserOrigin = false;
_isUserRadius = false;
startAngle = 0;
endAngle = 2 * Math.PI;
innerRadius = 0;
outerRadius = 0;
_updateStartEndPoint() {
const origin = this.origin();
const minAngle = Math.min(this.startAngle, this.endAngle);
const maxAngle = Math.max(this.startAngle, this.endAngle);
const init0 = (2 * minAngle) / Math.PI;
const init1 = (2 * maxAngle) / Math.PI;
const angles = [minAngle, maxAngle];
let i = Math.ceil(init0);
while (i <= init1) {
angles.push((i * Math.PI) / 2);
i++;
}
const len = angles.length;
const xs = [];
const ys = [];
for (i = 0; i < len; i++) {
const p0 = polarToCartesian(origin, this.innerRadius, angles[i]);
const p1 = polarToCartesian(origin, this.outerRadius, angles[i]);
xs.push(p0.x);
xs.push(p1.x);
ys.push(p0.y);
ys.push(p1.y);
}
const minX = Math.min.apply(null, xs);
const minY = Math.min.apply(null, ys);
const maxX = Math.max.apply(null, xs);
const maxY = Math.max.apply(null, ys);
this.startPoint = { x: minX, y: minY };
this.endPoint = { x: maxX, y: maxY };
}
_updateSize() {
super._updateSize();
if (!this._isUserOrigin) {
this.originPoint = { x: this.width / 2, y: this.height / 2 };
this._invokeTransforms();
}
if (!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(angle, endAngle) {
if (isNil(angle)) {
return [this.startAngle, this.endAngle];
}
if (Array.isArray(angle)) {
this.startAngle = angle[0];
this.endAngle = angle[1];
}
else {
this.startAngle = angle;
this.endAngle = endAngle ?? angle;
}
this._updateStartEndPoint();
return this;
}
radius(radius, outerRadius) {
if (isNil(radius)) {
return [this.innerRadius, this.outerRadius];
}
this._isUserRadius = true;
if (Array.isArray(radius)) {
this.innerRadius = Math.min(radius[0], radius[1]);
this.outerRadius = Math.max(radius[1], radius[1]);
}
else {
this.innerRadius = Math.min(radius, outerRadius);
this.outerRadius = Math.max(radius, outerRadius);
}
this._updateStartEndPoint();
return this;
}
origin(x, y) {
if (isNil(x)) {
return this.originPoint;
}
this._isUserOrigin = true;
this.originPoint = this._parsePoint(x, y);
this._updateStartEndPoint();
this._invokeTransforms();
return this;
}
convert(point) {
if (isValidNumber(point.r1) || isValidNumber(point.theta1)) {
const convertedPoint = this.convertPoint(point);
const convertedPoint1 = this.convertPoint({
r: point.r1 ?? point.r,
theta: point.theta1 ?? point.theta
});
convertedPoint.x1 = convertedPoint1.x;
convertedPoint.y1 = convertedPoint1.y;
return convertedPoint;
}
else if (isValidNumber(point.x1) || isValidNumber(point.y1)) {
const convertedPoint = this.convertPoint(point);
const convertedPoint1 = this.convertPoint({
x: point.x1 ?? point.x,
y: point.y1 ?? point.y
});
convertedPoint.x1 = convertedPoint1.x;
convertedPoint.y1 = convertedPoint1.y;
return convertedPoint;
}
return this.convertPoint(point);
}
invert(point) {
if (isValidNumber(point.x1) || isValidNumber(point.y1)) {
const invertedPoint = this.invertPoint(point);
const invertedPoint1 = this.invertPoint({ x: point.x1 ?? point.x, y: point.y1 ?? point.y });
invertedPoint.r1 = invertedPoint1.r;
invertedPoint.theta1 = invertedPoint1.theta;
return invertedPoint;
}
return this.invertPoint(point);
}
getRangeByDimension(dim, isSubshaft, reversed) {
const isAngle = this.isMainDimension(dim);
const res = isAngle ? [this.startAngle, this.endAngle] : [this.innerRadius, this.outerRadius];
return reversed ? [res[1], res[0]] : res;
}
getVisiualPositionByDimension(dim, isSubshaft, reversed) {
const isAngle = this.isMainDimension(dim);
return isAngle ? (isSubshaft ? 'inside' : 'outside') : isSubshaft ? 'end' : 'start';
}
getAxisPointsByDimension(dim, isSubshaft, reversed, baseValue) {
const isAngle = this.isMainDimension(dim);
if (!isAngle) {
const origin = this.origin();
const res = !isNil(baseValue)
? [polarToCartesian(origin, this.innerRadius, baseValue), polarToCartesian(origin, this.outerRadius, baseValue)]
: isSubshaft
? [
polarToCartesian(origin, this.innerRadius, this.endAngle),
polarToCartesian(origin, this.outerRadius, this.endAngle)
]
: [
polarToCartesian(origin, this.innerRadius, this.startAngle),
polarToCartesian(origin, this.outerRadius, this.startAngle)
];
return reversed ? [res[1], res[0]] : res;
}
return null;
}
convertPoint(point) {
const isTransposed = this.isTransposed();
let theta;
let r;
if (!isNil(point.r) && !isNil(point.theta)) {
theta = isTransposed ? point.r : point.theta;
r = isTransposed ? point.theta : point.r;
}
else if (isArray(point)) {
theta = isTransposed ? point[0] : point[1];
r = isTransposed ? point[1] : point[0];
}
else {
theta = isTransposed ? point.y : point.x;
r = isTransposed ? point.x : point.y;
}
const convertedPoint = {
x: Math.cos(theta) * r,
y: Math.sin(theta) * r
};
if (point.defined === false) {
convertedPoint.defined = false;
}
const transformedPoint = Object.assign({}, convertedPoint);
this.convertMatrix.transformPoint(convertedPoint, transformedPoint);
return transformedPoint;
}
invertPoint(point) {
const untransformedPoint = Object.assign({}, point);
this.invertMatrix.transformPoint(point, untransformedPoint);
const cos = untransformedPoint.x;
const sin = untransformedPoint.y;
if (isNumberClose(cos, 0) && isNumberClose(sin, 0)) {
const invertedPoint = { r: 0, theta: 0 };
if (untransformedPoint.defined === false) {
invertedPoint.defined = false;
}
return invertedPoint;
}
let theta = Math.atan(sin / cos);
if (cos >= 0) {
theta += Math.PI * 2;
}
else {
theta += Math.PI;
}
if (theta >= Math.PI * 2) {
theta -= Math.PI * 2;
}
theta = clampRadian(theta);
const radius = isNumberClose(sin, 0) ? cos / Math.cos(theta) : sin / Math.sin(theta);
const invertedPoint = this.isTransposed()
? {
r: theta,
theta: radius
}
: {
r: radius,
theta
};
if (untransformedPoint.defined === false) {
invertedPoint.defined = false;
}
return invertedPoint;
}
}
exports.CartesianCoordinate = CartesianCoordinate;
exports.Coordinate = Coordinate;
exports.PolarCoordinate = PolarCoordinate;
}));

6

package.json
{
"name": "@visactor/vgrammar-coordinate",
"version": "0.2.1",
"version": "0.3.0",
"description": "Coordinates for VGrammar",

@@ -27,4 +27,4 @@ "keywords": [

"dependencies": {
"@visactor/vgrammar-util": "0.2.1",
"@visactor/vutils": "0.9.0-alpha.2"
"@visactor/vgrammar-util": "0.3.0",
"@visactor/vutils": "~0.11.1"
},

@@ -31,0 +31,0 @@ "devDependencies": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc