@stdlib/esm
Version:
ES module distribution for Stdlib, a standard library for JavaScript and Node.js.
3 lines • 8.06 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"./../../../vendor/events.js";import t from"./../../../vendor/debug.js";import i from"./../../../utils/define-property.js";import r from"./../../../utils/define-read-only-property.js";import n from"./../../../utils/keys.js";import a from"./../../../utils/copy.js";import o from"./../../../utils/merge.js";import s from"./../../../assert/is-plain-object.js";import u from"./../../../assert/instance-of.js";import l from"./../../../utils/inherit.js";import c from"./../../../assert/is-nan.js";import f from"./../../../assert/is-boolean.js";import h from"./../../../assert/is-string.js";import m from"./../../../assert/is-function.js";import d from"./../../../assert/is-array-like.js";import p from"./../../../assert/is-number.js";import g from"./../../../utils/index-of.js";import v from"./../../../assert/is-nonnegative-integer.js";import b from"./../../../vendor/virtual-dom/h.js";import{scaleLinear as _}from"./../../../vendor/d3-scale.js";var y=t,w=c.isPrimitive,j=y("rug:accessor:is-defined");function V(e){var t=!w(e);return j("Datum: %s. Defined: %s.",JSON.stringify(e),t),t}var N=!1,R="#aaa",D=[],E=null,k="",z=.9,C="bottom",P=null,T=6,O={autoRender:N,color:R,data:D,isDefined:E,label:k,opacity:z,orientation:C,scale:P,size:T},J=t,S=f.isPrimitive,x=J("rug:set:auto-render");function A(e){if(!S(e))throw new TypeError("invalid value. `autoRender` must be a boolean primitive. Value: `"+e+".`");e!==this._autoRender&&(x("Current value: %d.",this._autoRender),this._autoRender=e,x("New Value: %d.",this._autoRender),this.emit("change"))}function G(){return this._autoRender}var M=t,F=h.isPrimitive,q=m,B=M("rug:set:color");function H(e){if(!F(e)&&!q(e))throw new TypeError("invalid value. `color` must be a string primitive or a function. Value: `"+e+".`");e!==this._color&&(B("Current value: %d.",this._color),this._color=e,B("New Value: %d.",this._color),this.emit("change"))}var I=h.isPrimitive;function K(){var e=this;return I(this._color)?function(){return e._color}:this._color}var L=t,Q=d,U=L("rug:set:data");function W(e){if(!Q(e))throw new TypeError("invalid value. `data` must be array-like. Value: `"+e+".`");U("Current value: %s.",JSON.stringify(this._data)),this._data=e,U("New Value: %s.",JSON.stringify(this._data)),this.emit("change")}function X(){return this._data}var Y=t,Z=m,$=Y("rug:set:is-defined");function ee(e){if(!Z(e))throw new TypeError("invalid value. `isDefined` must be a function. Value: `"+e+".`");e!==this._isDefined&&($("Current value: %s.",this._isDefined),this._isDefined=e,$("New Value: %s.",this._isDefined),this.emit("change"))}function te(){return this._isDefined}var ie=t,re=h.isPrimitive,ne=m,ae=ie("rug:set:label");function oe(e){if(!re(e)&&!ne(e))throw new TypeError("invalid value. `label` must be a string primitive or a function. Value: `"+e+".`");e!==this._label&&(ae("Current value: %d.",this._label),this._label=e,ae("New Value: %d.",this._label),this.emit("change"))}var se=h.isPrimitive;function ue(){var e=this;return se(this._label)?function(){return e._label}:this._label}var le=t,ce=p.isPrimitive,fe=m,he=le("rug:set:opacity");function me(e){var t=ce(e);if(!t&&!fe(e))throw new TypeError("invalid value. `opacity` must be a number or a function. Value: `"+e+".`");if(t&&(e!=e||e<0||e>1))throw new RangeError("invalid value. `opacity` must be a number on the interval `[0,1]`. Value: `"+e+"`.");e!==this._opacity&&(he("Current value: %d.",this._opacity),this._opacity=e,he("New Value: %d.",this._opacity),this.emit("change"))}var de=p.isPrimitive;function pe(){var e=this;return de(this._opacity)?function(){return e._opacity}:this._opacity}var ge=["bottom","left","right","top"],ve=t,be=g,_e=ge,ye=ve("rug:set:orientation");function we(e){if(-1===be(_e,e))throw new Error("invalid value. `orientation` must be one of `["+_e.join(",")+"]`. Value: `"+e+".`");e!==this._orientation&&(ye("Current value: %d.",this._orientation),this._orientation=e,ye("New Value: %d.",this._orientation),this.emit("change"))}function je(){return this._orientation}var Ve=t,Ne=Ve("rug:pos");function Re(){var e=this.scale;return function(t){var i=e(t);return Ne("Value: %d => Pixel: %d.",t,i),i}}var De=t,Ee=m,ke=De("rug:set:scale");function ze(e){if(!Ee(e))throw new TypeError("invalid value. `scale` must be a function. Value: `"+e+".`");e!==this._scale&&(ke("Current value: %s.",this._scale),this._scale=e,ke("New Value: %s.",this._scale),this.emit("change"))}function Ce(){return this._scale}var Pe=t,Te=v.isPrimitive,Oe=Pe("rug:set:size");function Je(e){if(!Te(e))throw new TypeError("invalid value. `size` must be a nonnegative integer. Value: `"+e+".`");e!==this._size&&(Oe("Current value: %d.",this._size),this._size=e,Oe("New Value: %d.",this._size),this.emit("change"))}function Se(){return this._size}function xe(e){return"left"===e||"right"===e?"x":"y"}function Ae(e){return"left"===e||"right"===e?"y":"x"}function Ge(e){return"bottom"===e||"right"===e?-1:1}var Me=t,Fe=b,qe=xe,Be=Ae,He=Ge,Ie=Me("rug:render:ticks"),Ke="line";function Le(e){var t,i,r,n,a,o,s,u,l,c;for(Ie("Rendering ticks..."),i=e.data,n=e.pos,s=qe(e.orientation),u=Be(e.orientation),a=He(e.orientation),r=new Array(i.length),c=0;c<i.length;c++)l=i[c],e.isDefined(l,c)?(t={namespace:"http://www.w3.org/2000/svg",property:"rug.tick",className:"tick",attributes:{fill:"none",opacity:e.opacity(l,c),stroke:e.color(l,c),"stroke-width":1,"data-label":e.label(l,c)}},o=n(l),t.attributes[s+"1"]=0,t.attributes[s+"2"]=a*e.size,t.attributes[u+"1"]=o,t.attributes[u+"2"]=o,Ie("Rendering tick %d with value %s...",c,l),Ie("Generating a virtual DOM tree (%s) with properties: %s.",Ke,JSON.stringify(t)),r[c]=Fe(Ke,t,[])):Ie("Datum %d is not defined. Value: %s.",c,l);return Ie("Finished rendering ticks."),r}var Qe=t,Ue=b,We=Le,Xe=Qe("rug:render"),Ye="g";function Ze(){var e,t,i;return Xe("Rendering..."),t={namespace:"http://www.w3.org/2000/svg",property:"rug",className:"rug"},e=We(this),Xe("Generating a virtual DOM tree (%s) with properties: %s.",Ye,JSON.stringify(t)),i=Ue(Ye,t,e),this.emit("_render",i),i}var $e=e.EventEmitter,et=t,tt=i,it=r,rt=n,nt=a,at=o,ot=s,st=u,ut=l,lt=V,ct=O,ft=A,ht=G,mt=H,dt=K,pt=W,gt=X,vt=ee,bt=te,_t=oe,yt=ue,wt=me,jt=pe,Vt=we,Nt=je,Rt=Re,Dt=ze,Et=Ce,kt=Je,zt=Se,Ct=Ze,Pt=et("rug:main"),Tt=["_autoRender","_color","_data","_isDefined","_label","_opacity","_orientation","_scale","_size"];function Ot(e){var t,i,r,n,a;if(!st(this,Ot))return arguments.length?new Ot(e):new Ot;if(t=this,(r=nt(ct)).isDefined=lt,r.scale=_(),arguments.length){if(!ot(e))throw new TypeError("invalid argument. `options` argument must be an object. Value: `"+e+"`.");r=at(r,e)}for(Pt("Creating an instance with the following configuration: %s.",JSON.stringify(r)),$e.call(this),a=0;a<Tt.length;a++)tt(this,Tt[a],{configurable:!1,enumerable:!1,writable:!0,value:null});for(i=rt(r),a=0;a<i.length;a++)this[n=i[a]]=r[n];return this.on("change",o),this.on("_render",s),this;function o(){Pt("Received a change event."),t._autoRender&&t.render()}function s(){var e,i;for(Pt("Received a render event. Re-emitting..."),(e=new Array(arguments.length+1))[0]="render",i=0;i<arguments.length;i++)e[i+1]=arguments[i];t.emit.apply(t,e)}}ut(Ot,$e),tt(Ot.prototype,"autoRender",{configurable:!1,enumerable:!0,set:ft,get:ht}),tt(Ot.prototype,"color",{configurable:!1,enumerable:!0,set:mt,get:dt}),tt(Ot.prototype,"data",{configurable:!1,enumerable:!0,set:pt,get:gt}),tt(Ot.prototype,"isDefined",{configurable:!1,enumerable:!0,set:vt,get:bt}),tt(Ot.prototype,"label",{configurable:!1,enumerable:!0,set:_t,get:yt}),tt(Ot.prototype,"opacity",{configurable:!1,enumerable:!0,set:wt,get:jt}),tt(Ot.prototype,"orientation",{configurable:!1,enumerable:!0,set:Vt,get:Nt}),tt(Ot.prototype,"pos",{configurable:!1,enumerable:!0,get:Rt}),tt(Ot.prototype,"scale",{configurable:!1,enumerable:!0,set:Dt,get:Et}),tt(Ot.prototype,"size",{configurable:!1,enumerable:!0,set:kt,get:zt}),it(Ot.prototype,"render",Ct);var Jt=Ot;export default Jt;
//# sourceMappingURL=rug.js.map