UNPKG

quoslibero

Version:

FusionCharts JavaScript charting framework

1 lines 1.49 kB
import Path from'./path';import constant from'../../../fc-core/src/axis/utils/constant';import CurveLinear from'./curve-factories/linear';class LineGenerator{constructor(){this.xAccessor=a=>a[0],this.yAccessor=a=>a[1],this.isDefined=constant(!0),this.Curve=CurveLinear,this.ctx=null,this._output=null}generate(a=[]){let b,c,d,e=0,f=a.length;for((null===this.ctx||'undefined'==typeof this.ctx)&&(d=new Path,this._output=new this.Curve(d)),e=0;e<=f;++e)b=a[e],c?this.isDefined(b,e,a)?this._output.point(this.xAccessor(b,e,a),this.yAccessor(b,e,a)):(this._output.lineEnd(),c=!1):this.isDefined(b,e,a)&&(c=!0,this._output.lineStart(),this._output.point(this.xAccessor(b,e,a),this.yAccessor(b,e,a)));if(d)return this._output=null,d.toString()}setXAccessor(a=a=>a[0]){return this.xAccessor='function'==typeof a?a:constant(+a),this}getXAccessor(){return this.xAccessor}setYAccessor(a=a=>a[1]){return this.yAccessor='function'==typeof a?a:constant(+a),this}getYAccessor(){return this.yAccessor}setDefined(a=constant(!0)){return this.isDefined='function'==typeof a?a:constant(!!a),this}getDefined(){return this.isDefined}setCurve(a=CurveLinear){return this.Curve=a,('undefined'!=typeof this.ctx||null!==this.ctx)&&(this._output=new this.Curve(this.ctx)),this}getCurve(){return this.Curve}setContext(a){return null===a||'undefined'==typeof a?(this.ctx=null,this._output=this.ctx):(this.ctx=a,this._output=new this.Curve(this.ctx)),this}getContext(){return this.ctx}}export default LineGenerator;