@stdlib/esm
Version:
ES module distribution for Stdlib, a standard library for JavaScript and Node.js.
3 lines • 5.27 kB
JavaScript
// This file is a part of stdlib. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0
import e from"./../../utils/define-property.js";import t from"./../../math/base/assert/is-nan.js";import r from"./../../math/base/special/round.js";import n from"./../../math/base/assert/is-infinite.js";import i from"./../../assert/is-plain-object.js";import a from"./../../assert/is-function.js";import o from"./../../assert/is-array.js";import l from"./../../assert/is-typed-array.js";import s from"./../../assert/is-positive-integer.js";import u from"./../../assert/has-own-property.js";import f from"./../../utils/copy.js";import p from"./../../math/base/special/floor.js";import h from"./../../math/base/special/exp10.js";function y(e){return e}function g(e){return e}var m=t,v=r,c=n;function b(e,t){var r,n,i;for(r=new Array(e.length),i=0;i<e.length;i++)n=t(e[i],i),m(n)||c(n)||(r[i]=v(n));return r}var V=i,x=a,w=o,d=l,_=s.isPrimitive,j=u;function S(e){return V(e)?!j(e,"x")||w(e.x)||d(e.x)?j(e,"xValue")&&!x(e.xValue)?new TypeError("invalid option. `xValue` option must be a function. Option: `"+e.xValue+"`."):!j(e,"y")||w(e.y)||d(e.y)?j(e,"yValue")&&!x(e.yValue)?new TypeError("invalid option. `yValue` option must be a function. Option: `"+e.yValue+"`."):j(e,"leafDigits")&&!_(e.leafDigits)?new TypeError("invalid option. `leafDigits` option must be a positive integer. Option: `"+e.leafDigits+"`."):null:new TypeError("invalid option. `y` option must be an array or typed array. Option: `"+e.y+"`."):new TypeError("invalid option. `x` option must be an array or typed array. Option: `"+e.x+"`."):new TypeError("invalid argument. Options argument must be an object. Value: `"+e+"`.")}var E=a;function T(e){if(!E(e))throw new TypeError("invalid value. `xValue` must be a function. Value: `"+e+"`.");this._xValue=e}function D(){return this._xValue}var O=a;function A(e){if(!O(e))throw new TypeError("invalid value. `yValue` must be a function. Value: `"+e+"`.");this._yValue=e}function M(){return this._yValue}var X=l,Y=o,L=b;function P(e){if(!Y(e)&&!X(e))throw new TypeError("invalid value. Must be an array or typed array. Value: `"+e+"`.");this._x=L(e,this._xValue)}var k=f;function q(){return k(this._x)}var z=l,B=o,C=b;function F(e){if(!B(e)&&!z(e))throw new TypeError("invalid value. Must be an array or typed array. Value: `"+e+"`.");this._y=C(e,this._yValue)}var G=f;function H(){return G(this._y)}var I=p,J=h;function K(e,t){return e-t}function N(e,t){return e.val-t.val}function Q(e){return new Array(e).join(" ")}function R(e,t){var r,n,i,a,o,l,s,u,f,p,h;for(e.sort(K),o=e.length,s=new Array(o),u=new Array(o),r=0,n=0,f=0;f<o;f++)s[f]=I(e[f]/t),(a=s[f].toString().length)>r&&(r=a),u[f]=e[f]%t,(a=u[f].toString().length)>n&&(n=a);for(l="",f=0;f<o;f++){for(;i<s[f];)l+="\n",h=(i+=1).toString().length-1,l+=" "+i+Q(r-h),l+=" | ";s[f]!==i&&(l+="\n",l+=" "+(p=s[f].toString())+Q(r-(h=p.length-1)),l+=" | "),l+=(p=u[f].toString())+Q(n-(h=p.length))+" ",i=s[f]}return l}function U(e,t,r){var n,i,a,o,l,s,u,f,p,h,y,g,m,v,c,b;for(p=[],v=0;v<e.length;v++)c={val:e[v],class:"x"},p.push(c);for(v=0;v<t.length;v++)c={val:t[v],class:"y"},p.push(c);for(g=p.length,p.sort(N),i=0,n=0,m=new Array(g),y=new Array(g),v=0;v<g;v++)m[v]=I(p[v].val/r),(f=m[v].toString().length)>i&&(i=f),"x"===p[v].class?(y[v]=p[v].val%r,(f=y[v].toString().length)>n&&(n=f)):"y"===p[v].class&&(y[v]=p[v].val%r,f=y[v].toString().length);for(l=[],s="",v=0;v<g;v++){for(;a<m[v];)l.push(s),s="& | "+Q(i-(b=(a+=1).toString().length-1))+a+" | ";m[v]!==a&&(s&&l.push(s),s="& | ",s+=Q(i-(b=(c=m[v].toString()).length-1))+c,s+=" | "),b=(c=y[v].toString()).length,"x"===p[v].class?s=c+Q(n-b)+" "+s:"y"===p[v].class&&(s=s+c+Q(n-b)+" "),a=m[v]}for(u=0,v=0;v<l.length;v++)(c=l[v].indexOf("|"))>u&&(u=c);for(v=0;v<l.length;v++)o=u-(h=l[v].split("&",2))[0].length,h[0]=Q(o)+h[0],l[v]=h[0]+h[1];return l.join("\n")}function W(){var e,t,r,n,i;return n=this._x,i=this._y,t=this._leafDigits,e=J(t),n.length&&i.length?r=U(n,i,e):n.length&&!i.length?r=R(n,e):i.length&&!n.length&&(r=R(i,e)),r+="\n\n",r+="Legend: ",r+="\n X | Y => "+e+" * X + Y\n"}var Z=e,$=y,ee=g,te=b,re=S,ne=T,ie=D,ae=A,oe=M,le=P,se=q,ue=F,fe=H,pe=W;function he(e){var t,r;if(!(this instanceof he))return arguments.length?new he(e):new he;if(arguments.length){if(r=re(t=e))throw r}else t={};return Z(this,"_x",{configurable:!1,enumerable:!1,writable:!0,value:[]}),Z(this,"_xValue",{configurable:!1,enumerable:!1,writable:!0,value:$}),Z(this,"_y",{configurable:!1,enumerable:!1,writable:!0,value:[]}),Z(this,"_yValue",{configurable:!1,enumerable:!1,writable:!0,value:ee}),Z(this,"_leafDigits",{configurable:!1,enumerable:!1,writable:!0,value:1}),void 0!==t.xValue&&(this._xValue=t.xValue),void 0!==t.yValue&&(this._yValue=t.yValue),void 0!==t.x&&(this._x=te(t.x,this._yValue)),void 0!==t.y&&(this._y=te(t.y,this._yValue)),void 0!==t.leafDigits&&(this._leafDigits=t.leafDigits),this}Z(he.prototype,"xValue",{configurable:!1,enumerable:!0,set:ne,get:ie}),Z(he.prototype,"yValue",{configurable:!1,enumerable:!0,set:ae,get:oe}),Z(he.prototype,"x",{configurable:!1,enumerable:!0,set:le,get:se}),Z(he.prototype,"y",{configurable:!1,enumerable:!0,set:ue,get:fe}),he.prototype.render=pe;var ye=he;export default ye;
//# sourceMappingURL=stemleaf.js.map