UNPKG

@stdlib/esm

Version:

ES module distribution for Stdlib, a standard library for JavaScript and Node.js.

3 lines 14.2 kB
// This file is a part of stdlib. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 import t from"./../../../vendor/events.js";import e from"./../../../vendor/debug.js";import i from"./../../../utils/define-property.js";import r from"./../../../utils/define-read-only-property.js";import n from"./../../../utils/copy.js";import a from"./../../../utils/keys.js";import o from"./../../../assert/is-plain-object.js";import s from"./../../../assert/has-own-property.js";import u from"./../../../assert/is-boolean.js";import l from"./../../../assert/is-string.js";import c from"./../../../assert/is-null.js";import m from"./../../../assert/is-nonnegative-integer.js";import f from"./../../../utils/index-of.js";import h from"./../../../assert/is-function.js";import v from"./../../../assert/is-array.js";import g from"./../../../utils/identity-function.js";import{format as k}from"./../../../vendor/d3-format.js";import p from"./../../../vendor/virtual-dom/h.js";import{scaleLinear as b}from"./../../../vendor/d3-scale.js";var d=null,w="",_=null,y=null,T=null,S=6,x=6,z=6,V=3,N="bottom",R=!1,j={scale:d,label:w,ticks:_,numTicks:y,tickFormat:T,tickSize:S,innerTickSize:x,outerTickSize:z,tickPadding:V,orientation:N,autoRender:R},P=u.isPrimitive;function F(t){return P(t)?null:new TypeError("invalid value. `autoRender` must be a boolean primitive. Value: `"+t+".`")}var O=l.isPrimitive;function E(t){return O(t)?null:new TypeError("invalid value. `label` must be a string. Value: `"+t+".`")}var C=c,J=m.isPrimitive;function D(t){return C(t)||J(t)?null:new TypeError("invalid value. `numTicks` must be a nonnegative integer or null. Value: `"+t+".`")}var A=["left","right","top","bottom"],M=f,G=A;function H(t){return-1===M(G,t)?new TypeError("invalid value. `orientation` must be one of `["+G.join(",")+"]`. Value: `"+t+".`"):null}var q=h;function B(t){return q(t)?null:new TypeError("invalid value. `scale` must be a function. Value: `"+t+".`")}var I=c,K=l.isPrimitive,L=h;function Q(t){return I(t)||K(t)||L(t)?null:new TypeError("invalid value. `tickFormat` must be a string, function, or null. Value: `"+t+".`")}var U=m.isPrimitive;function W(t){return U(t)?null:new TypeError("invalid value. `tickPadding` must be a nonnegative integer. Value: `"+t+".`")}var X=c,Y=v;function Z(t){return X(t)||Y(t)?null:new TypeError("invalid value. `ticks` must be either null or an array. Value: `"+t+".`")}var $=m.isPrimitive;function tt(t){return $(t)?null:new TypeError("invalid value. `tickSize` must be a nonnegative integer. Value: `"+t+".`")}var et=m.isPrimitive;function it(t){return et(t)?null:new TypeError("invalid value. `innerTickSize` must be a nonnegative integer. Value: `"+t+".`")}var rt=m.isPrimitive;function nt(t){return rt(t)?null:new TypeError("invalid value. `outerTickSize` must be a nonnegative integer. Value: `"+t+".`")}var at=F,ot=E,st=D,ut=H,lt=B,ct=Q,mt=W,ft=Z,ht=tt,vt=it,gt=nt,kt={autoRender:at,label:ot,numTicks:st,orientation:ut,scale:lt,tickFormat:ct,tickPadding:mt,ticks:ft,tickSize:ht,innerTickSize:vt,outerTickSize:gt},pt=a,bt=o,dt=s,wt=kt,_t=pt(wt);function yt(t,e){var i,r,n,a;if(!bt(e))return new TypeError("invalid argument. Options argument must be an object. Value: `"+e+"`.");for(a=0;a<_t.length;a++)if(r=_t[a],dt(e,r)){if(n=e[r],i=wt[r](n))return i;t[r]=n}return null}var Tt="change",St="change",xt="change",zt="change",Vt="change",Nt="change",Rt="change",jt="change",Pt="change",Ft="change",Ot="change",Et={label:Tt,numTicks:St,orientation:xt,scale:zt,tickFormat:Vt,tickPadding:Nt,ticks:Rt,tickSize:jt,innerTickSize:Pt,outerTickSize:Ft,autoRender:Ot},Ct=Et;function Jt(t){return Ct[t]}var Dt=e,At=Jt,Mt=B,Gt=Dt("axis:set:scale"),Ht=At("scale");function qt(t){var e=Mt(t);if(e)throw e;Gt("Current value: %s.",this._scale),this._scale=t,Gt("New Value: %s.",this._scale),this.emit(Ht)}function Bt(){return this._scale}var It=e,Kt=Jt,Lt=H,Qt=It("axis:set:orientation"),Ut=Kt("orientation");function Wt(t){var e=Lt(t);if(e)throw e;Qt("Current value: %s.",this._orientation),this._orientation=t,Qt("New Value: %s.",this._orientation),this.emit(Ut)}function Xt(){return this._orientation}var Yt=e,Zt=Jt,$t=E,te=Yt("axis:set:xlabel"),ee=Zt("label");function ie(t){var e=$t(t);if(e)throw e;te("Current value: %s.",this._label),this._label=t,te("New value: %s.",this._label),this.emit(ee)}function re(){return this._label}var ne=e,ae=c,oe=Jt,se=Z,ue=ne("axis:set:ticks"),le=oe("ticks");function ce(t){var e=se(t);if(e)throw e;ue("Current value: %s.",JSON.stringify(this._ticks)),ae(t)?this._ticks=t:this._ticks=t.slice(),ue("New Value: %s.",JSON.stringify(this._ticks)),this.emit(le)}var me=c;function fe(){return me(this._ticks)?this._scale.ticks?this._scale.ticks(this._numTicks,this._tickFormat):this._scale.domain():this._ticks.slice()}var he=e,ve=Jt,ge=D,ke=he("axis:set:numticks"),pe=ve("numTicks");function be(t){var e=ge(t);if(e)throw e;ke("Current value: %d.",t),this._numTicks=t,ke("New Value: %s.",this._numTicks),this.emit(pe)}function de(){return this._numTicks}var we=e,_e=Jt,ye=Q,Te=we("axis:set:tickformat"),Se=_e("tickFormat");function xe(t){var e=ye(t);if(e)throw e;Te("Current value: %s.",this._tickFormat),this._tickFormat=t,Te("New Value: %s.",this._tickFormat),this.emit(Se)}var ze=l.isPrimitive,Ve=c,Ne=g;function Re(){return ze(this._tickFormat)?k(this._tickFormat):Ve(this._tickFormat)?this._scale.tickFormat?this._scale.tickFormat(this._numTicks,this._tickFormat):Ne:this._tickFormat}var je=e,Pe=Jt,Fe=tt,Oe=je("axis:set:ticksize"),Ee=Pe("tickSize");function Ce(t){var e=Fe(t);if(e)throw e;Oe("Current value: %d.",t),this._tickSize=t,Oe("New Value: %s.",this._tickSize),this.emit(Ee)}function Je(){return this._tickSize}var De=e,Ae=Jt,Me=it,Ge=De("axis:set:ticksize-inner"),He=Ae("innerTickSize");function qe(t){var e=Me(t);if(e)throw e;Ge("Current value: %d.",t),this._innerTickSize=t,Ge("New Value: %s.",this._innerTickSize),this.emit(He)}function Be(){return this._innerTickSize}var Ie=e,Ke=Jt,Le=nt,Qe=Ie("axis:set:ticksize-outer"),Ue=Ke("outerTickSize");function We(t){var e=Le(t);if(e)throw e;Qe("Current value: %d.",t),this._outerTickSize=t,Qe("New Value: %s.",this._outerTickSize),this.emit(Ue)}function Xe(){return this._outerTickSize}var Ye=e,Ze=Jt,$e=W,ti=Ye("axis:set:tickpadding"),ei=Ze("tickPadding");function ii(t){var e=$e(t);if(e)throw e;ti("Current value: %d.",t),this._tickPadding=t,ti("New Value: %s.",this._tickPadding),this.emit(ei)}function ri(){return this._tickPadding}function ni(){return this._innerTickSize+this._tickPadding}function ai(){return"top"===this._orientation||"left"===this._orientation?-1:1}var oi=e,si=oi("axis:center");function ui(){var t=this._scale.bandwidth()/2;return function(e){var i=this._scale(e)+t;return si("Value: %s => Coordinate: %d",e,i),i}}var li=ui;function ci(){var t=this._scale.copy();return t.bandwidth?li():t}var mi=e,fi=Jt,hi=F,vi=mi("axis:set:auto-render"),gi=fi("autoRender");function ki(t){var e=hi(t);if(e)throw e;vi("Current value: %d.",this._autoRender),this._autoRender=t,vi("New Value: %d.",this._autoRender),this.emit(gi)}function pi(){return this._autoRender}function bi(t){return"left"===t?"end":"right"===t?"start":"middle"}var di=e,wi=p,_i=di("axis:components:domain"),yi="path";function Ti(t){var e,i,r,n,a,o,s,u;return e=t._orientation,_i("Axis orientation: %s.",e),o=t._scale.range(),_i("Axis range: %s.",JSON.stringify(o)),r=o[0]+.5,n=o[o.length-1]+.5,a=t.tickDir*t._outerTickSize,u="","left"===e||"right"===e?(u+="M"+a+","+r,u+="H0.5",u+="V"+n,u+="H"+a,i="none"):(u+="M"+r+","+a,u+="V0.5",u+="H"+n,u+="V"+a,i="#aaa"),s={namespace:"http://www.w3.org/2000/svg",property:"axis.domain",className:"domain",attributes:{fill:"none",stroke:i,"stroke-width":1,d:u}},_i("Generating a virtual DOM tree (%s) with properties: %s.",yi,JSON.stringify(s)),wi(yi,s,[])}var Si=e,xi=Si("axis:engine:translate-x");function zi(t){return function(e){var i="translate("+t(e)+",0)";return xi("Value: %s => Transform: %s.",e,i),i}}var Vi=e,Ni=Vi("axis:engine:translate-y");function Ri(t){return function(e){var i="translate(0,"+t(e)+")";return Ni("Value: %s => Transform: %s.",e,i),i}}var ji=zi,Pi=Ri;function Fi(t,e){return"top"===t||"bottom"===t?ji(e):Pi(e)}function Oi(t){return"left"===t||"right"===t?"x":"y"}function Ei(t){return"left"===t||"right"===t?"y":"x"}var Ci=e,Ji=p,Di=Oi,Ai=Ei,Mi=Ci("axis:components:line"),Gi="line";function Hi(t){var e,i,r;return e={namespace:"http://www.w3.org/2000/svg",attributes:{stroke:"#aaa","stroke-width":1}},i=Di(t._orientation),r=Ai(t._orientation),e.attributes[i+"2"]=t.tickDir*t._innerTickSize,e.attributes[r+"1"]=.5,e.attributes[r+"2"]=.5,Mi("Generating a virtual DOM tree (%s) with properties: %s.",Gi,JSON.stringify(e)),Ji(Gi,e,[])}function qi(t){return"top"===t?"0em":"bottom"===t?".71em":".32em"}var Bi=e,Ii=p,Ki=qi,Li=Oi,Qi=Ei,Ui=Bi("axis:components:text"),Wi="text";function Xi(t,e){var i,r,n,a,o;return i=t._orientation,Ui("Axis orientation: %s.",i),r={namespace:"http://www.w3.org/2000/svg",attributes:{fill:"#000",dy:Ki(i)}},a=Li(i),o=Qi(i),r.attributes[a]=t.tickDir*t.tickSpacing,r.attributes[o]=.5,n=t.tickFormat(e),Ui("Tick text: %s.",n),Ui("Generating a virtual DOM tree (%s) with properties: %s.",Wi,JSON.stringify(r)),Ii(Wi,r,n)}var Yi=e,Zi=p,$i=Hi,tr=Xi,er=Yi("axis:components:tick"),ir="g";function rr(t,e,i){var r,n;return n={namespace:"http://www.w3.org/2000/svg",property:"axis.tick",className:"tick",attributes:{opacity:1,transform:i(e)}},r=new Array(2),er("Rendering a tick line..."),r[0]=$i(t),er("Rendering tick text..."),r[1]=tr(t,e),er("Generating a virtual DOM tree (%s) with properties: %s.",ir,JSON.stringify(n)),Zi(ir,n,r)}var nr=e,ar=Fi,or=rr,sr=nr("axis:components:ticks");function ur(t){var e,i,r,n;for(i=t.ticks,sr("Tick values: %s.",JSON.stringify(i)),sr("Generating tick transform..."),e=ar(t._orientation,t._scale),sr("Rendering ticks..."),r=new Array(i.length),n=0;n<i.length;n++)sr("Rendering tick %d with value %s...",n,i[n]),r[n]=or(t,i[n],e);return sr("Finished rendering ticks."),r}function lr(t){return"bottom"===t||"top"===t?"rotate(0)":"left"===t?"rotate(-90)":"rotate(90)"}function cr(t,e){return"left"===t||"right"===t?-e[0]/2:e[1]/2}function mr(t){return"left"===t?-72:"right"===t?72:"bottom"===t?45:-45}var fr=e,hr=p,vr=lr,gr=cr,kr=mr,pr=fr("axis:components:label"),br="text";function dr(t){var e,i;return e=t._orientation,pr("Axis orientation: %s.",e),i={namespace:"http://www.w3.org/2000/svg",property:"axis.label",className:"label noselect",attributes:{fill:"#000",stroke:"none","text-anchor":"middle",transform:vr(e),x:gr(e,t._scale.range()),y:kr(e)}},pr("Axis label: %s.",t._label),pr("Generating a virtual DOM tree (%s) with properties: %s.",br,JSON.stringify(i)),hr(br,i,t._label)}var wr=e,_r=p,yr=bi,Tr=Ti,Sr=ur,xr=dr,zr=wr("axis:components:main"),Vr="g";function Nr(t){var e,i;return i={namespace:"http://www.w3.org/2000/svg",property:"axis",className:"axis",attributes:{fill:"none","font-size":10,"font-family":"sans-serif","text-anchor":yr(t._orientation)}},zr("Rendering tick marks..."),e=Sr(t),zr("Rendering domain line..."),e.unshift(Tr(t)),zr("Rendering label..."),e.push(xr(t)),zr("Generating a virtual DOM tree (%s) with properties: %s.",Vr,JSON.stringify(i)),_r(Vr,i,e)}var Rr=e,jr=Nr,Pr=Rr("axis:render");function Fr(){var t;return Pr("Rendering..."),t=jr(this),this.emit("_render",t),t}var Or=t.EventEmitter,Er=e,Cr=i,Jr=r,Dr=n,Ar=j,Mr=yt,Gr=qt,Hr=Bt,qr=Wt,Br=Xt,Ir=ie,Kr=re,Lr=ce,Qr=fe,Ur=be,Wr=de,Xr=xe,Yr=Re,Zr=Ce,$r=Je,tn=qe,en=Be,rn=We,nn=Xe,an=ii,on=ri,sn=ni,un=ai,ln=ci,cn=ki,mn=pi,fn=Fr,hn=Er("axis:main");function vn(t){var e,i,r;if(!(this instanceof vn))return new vn(t);if(e=this,i=Dr(Ar),r=Mr(i,t))throw r;return hn("Creating an instance with the following configuration: %s.",JSON.stringify(i)),Or.call(this),Cr(this,"_scale",{configurable:!1,enumerable:!1,writable:!0,value:i.scale||b()}),Cr(this,"_orientation",{configurable:!1,enumerable:!1,writable:!0,value:i.orientation}),Cr(this,"_label",{configurable:!1,enumerable:!1,writable:!0,value:i.label}),Cr(this,"_ticks",{configurable:!1,enumerable:!1,writable:!0,value:i.ticks}),Cr(this,"_numTicks",{configurable:!1,enumerable:!1,writable:!0,value:i.numTicks}),Cr(this,"_tickFormat",{configurable:!1,enumerable:!1,writable:!0,value:i.tickFormat}),Cr(this,"_tickSize",{configurable:!1,enumerable:!1,writable:!0,value:i.tickSize}),Cr(this,"_innerTickSize",{configurable:!1,enumerable:!1,writable:!0,value:i.innerTickSize}),Cr(this,"_outerTickSize",{configurable:!1,enumerable:!1,writable:!0,value:i.outerTickSize}),Cr(this,"_tickPadding",{configurable:!1,enumerable:!1,writable:!0,value:i.tickPadding}),Cr(this,"_autoRender",{configurable:!1,enumerable:!1,writable:!0,value:i.autoRender}),this.on("change",(function(){hn("Received a change event."),e._autoRender&&e.render()})),this.on("_render",(function(){var t,i;for(hn("Received a render event. Re-emitting..."),(t=new Array(arguments.length+1))[0]="render",i=0;i<arguments.length;i++)t[i+1]=arguments[i];e.emit.apply(e,t)})),this}vn.prototype=Object.create(Or.prototype),vn.prototype.constructor=vn,Cr(vn.prototype,"scale",{configurable:!1,enumerable:!0,set:Gr,get:Hr}),Cr(vn.prototype,"orientation",{configurable:!1,enumerable:!0,set:qr,get:Br}),Cr(vn.prototype,"label",{configurable:!1,enumerable:!0,set:Ir,get:Kr}),Cr(vn.prototype,"ticks",{configurable:!1,enumerable:!0,set:Lr,get:Qr}),Cr(vn.prototype,"numTicks",{configurable:!1,enumerable:!0,set:Ur,get:Wr}),Cr(vn.prototype,"tickFormat",{configurable:!1,enumerable:!0,set:Xr,get:Yr}),Cr(vn.prototype,"tickSize",{configurable:!1,enumerable:!0,set:Zr,get:$r}),Cr(vn.prototype,"innerTickSize",{configurable:!1,enumerable:!0,set:tn,get:en}),Cr(vn.prototype,"outerTickSize",{configurable:!1,enumerable:!0,set:rn,get:nn}),Cr(vn.prototype,"tickPadding",{configurable:!1,enumerable:!0,set:an,get:on}),Cr(vn.prototype,"tickSpacing",{configurable:!1,enumerable:!0,get:sn}),Cr(vn.prototype,"tickDir",{configurable:!1,enumerable:!0,get:un}),Cr(vn.prototype,"tickPos",{configurable:!1,enumerable:!0,get:ln}),Cr(vn.prototype,"autoRender",{configurable:!1,enumerable:!0,set:cn,get:mn}),Jr(vn.prototype,"render",fn);var gn=vn;export default gn; //# sourceMappingURL=axis.js.map