quoslibero
Version:
FusionCharts JavaScript charting framework
1 lines • 5.8 kB
JavaScript
import{pluck,pluckNumber,getValidValue,parseUnsafeString,preDefStr,getDashStyle,mapSymbolName,getFirstColor}from'../../../../fc-core/src/lib';import Line from'../../../../fc-charts/src/dataset/line';import{_parseToolText as __parseToolText}from'./candlestick';let colorStrings=preDefStr.colors,COLOR_B90000=colorStrings.B90000,COLOR_FFFFFF=colorStrings.FFFFFF,UNDERSCORE='_',BLANK='',SHOWSHADOW='showShadow',ZEROSTRING='0',HUNDRED='100';class CandleStickline extends Line{configureAttributes(a){var b=Math.min,c=Math.max;if(!a)return!1;this.trimData(a),this.config.JSONData=a;var d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,y=this,z=y.config,A=y.config.JSONData,B=A.data||[],C=y.getFromEnv('chart-attrib'),D=B.length,E=y.getFromEnv('number-formatter'),F=y.getFromEnv('color-manager'),G=z.bearBorderColor=getFirstColor(pluck(C.bearbordercolor,COLOR_B90000)),H=z.bearFillColor=getFirstColor(pluck(C.bearfillcolor,COLOR_B90000)),I=z.bullBorderColor=getFirstColor(pluck(C.bullbordercolor,F.getColor('canvasBorderColor'))),J=z.bullFillColor=getFirstColor(pluck(C.bullfillcolor,COLOR_FFFFFF)),K=z.linethickness=z.plotBorderThickness=pluckNumber(C.plotlinethickness,2),L=z.plotLineDashLen=pluckNumber(C.plotlinedashlen,5),M=z.plotLineDashGap=pluckNumber(C.plotlinedashgap,4),N=!!pluckNumber(C.drawanchors,0),O=pluckNumber(C.anchorstartangle,90),P=pluckNumber(C.anchorradius,this.anchorRadius,3),Q=getFirstColor(pluck(C.anchorbordercolor,I)),R=pluckNumber(C.anchorborderthickness,this.anchorBorderThickness,1),S=getFirstColor(pluck(C.anchorbgcolor,F.getColor('anchorBgColor'))),T=pluck(C.anchoralpha,ZEROSTRING),U=pluck(C.anchorbgalpha,T),V=-Infinity,W=+Infinity,X=-Infinity,Y=+Infinity;for(y.setState('visible',1===pluckNumber(A.visible,1)),y._conatinerHidden=!!y.getState('visible'),z.defaultPadding={left:.5,right:.5},z.plotType='line',z.parentYAxis=0,z.toolText=getValidValue(parseUnsafeString(pluck(A.tooltext,C.plottooltext))),z.name=getValidValue(A.seriesname),z.showTooltip=pluck(C.showtooltip,1),v=pluck(C.maxcolwidth),z.maxColWidth=Math.abs(pluckNumber(v,50))||1,z.enableAnimation=w=pluckNumber(C.animation,C.defaultanimation,1),z.animation=!!w&&{duration:1e3*pluckNumber(C.animationduration,1)},z.lineAlpha=pluck(C.plotlinealpha,HUNDRED),u=c(pluckNumber(C.plotspacepercent,20)%100,0),z.plotSpacePercent=z.groupPadding=u/200,r=y.components.data=y.components.data||(y.components.data=[]),z.valuePadding=pluckNumber(A.valuepadding,C.valuepadding,2),z.plotBorderThickness=K,z.showvalues=1,z.showShadow=pluckNumber(C.showshadow,F.getColor(SHOWSHADOW)),i=0;i<D;i+=1)s=B[i],j=r[i],j||(j=r[i]={}),j.config||(j.config={}),j.graphics||(j.graphics={}),t=j.config,s&&!s.vline&&(t.setLink=pluck(s.link),k=t.open=E.getCleanValue(s.open),l=t.close=E.getCleanValue(s.close),m=t.high=E.getCleanValue(s.high),n=t.low=E.getCleanValue(s.low),t.volume=E.getCleanValue(s.volume,!0),q=t.x=E.getCleanValue(s.x),t.closeVal=b(k,l),t.yVal=c(k,l),o=b(k,l,m,n),p=c(k,l,m,n),e=getFirstColor(pluck(s.bordercolor,l<k?G:I)),f=pluck(s.alpha,z.lineAlpha),d=getFirstColor(pluck(s.color,l<k?H:J)),g=pluckNumber(s.dashed)?getDashStyle(L,M):'none',t.dashStyle=g,h={opacity:z.showShadow?f/100:0},t.color=e,t.alpha=f,t.setColor=t.color,t.setAlpha=t.alpha,t.anchorImageUrl=pluck(s.anchorimageurl,A.anchorimageurl,C.anchorimageurl),t.borderColor=e,t.borderAlpha=t.plotLineAlpha,t.colorArr=[{color:t.color,alpha:t.alpha},{color:t.borderColor,alpha:t.borderAlpha}],t.anchorSides=pluckNumber(s.anchorsides,A.anchorsides,C.anchorsides),t.symbol=mapSymbolName(t.anchorSides).split(UNDERSCORE),t.anchorProps={enabled:N,bgColor:S,symbol:t.symbol,bgAlpha:U*T/100+BLANK,borderColor:Q,borderAlpha:T,anchorAlpha:T,borderThickness:R,imageUrl:t.anchorImageUrl,radius:P,imageScale:pluckNumber(s.imagescale,A.imagescale,C.imagescale,100),imagePadding:pluckNumber(s.anchorimagepadding,A.anchorimagepadding,C.anchorimagepadding,1),imageAlpha:pluckNumber(A.anchorimagealpha,C.anchorimagealpha,100),startAngle:O},t.showValue=s.displayvalue?1:0,t.hoverEffects={},t.anchorSides=pluckNumber(s.anchorsides,A.anchorsides,C.anchorsides),t.symbol=mapSymbolName(t.anchorSides).split(UNDERSCORE),t.hoverEffects={},t.y=l,t.link=pluck(s.link),t.toolText=y._parseToolText(i),t.toolTipValue='',t.setValue=t._y=t.y,t.displayValue=parseUnsafeString(pluck(s.displayvalue,s.valuetext,BLANK)),null!==o&&(V=c(V,o),W=b(W,o)),null!==p&&(V=c(V,p),W=b(W,p)),null!==q&&(X=c(X,q),Y=b(Y,q)),q=q||i+1,t._x=t.x=q,t.high=c(k,l,m,n),t.low=b(k,l,m,n),t.shadow=h);z.yMax=V,z.yMin=W,z.xMax=X,z.xMin=Y,y.setState('dirty',!0)}__setDefaultConfig(){super.__setDefaultConfig(),this.config.drawLine=1}trimData(a){if(!(!this.components&&this.components.data&&this.components.data.length)){let b=this,c=b.components,d=c&&c.data,e=d&&d.length,f=a.data,g=Array.isArray(f)&&f.filter(a=>a.high||a.open||a.close||a.low).length||0,h=e-g;0<h&&this.removeData(g,h,!1)}}calculateScrollRange(){let a=this,b=a.config,c=a.components.data&&a.components.data.length;b.scrollMinVal=b.scrollMinValForLabel=0,b.scrollMaxVal=b.scrollMaxValForLabel=c}getDataLimits(){var a=this.config;return{max:a.yMax,min:a.yMin,xMax:a.xMax,xMin:a.xMin}}getPlotIndices(a){var b,c,d=this,e=Math.floor(a),f=Math.ceil(a),g=[],h=d.config.JSONData&&d.config.JSONData.data;for(b=h.length;b--;)c=h[b],c.x>=e&&c.x<=f&&g.push(b);return g}_parseToolText(a){return __parseToolText.call(this,a)}_getHoveredPlot(a,b){var c,d,e,f,g,h,j=this,k=j.getFromEnv('xAxis'),l=j.components,m=l.data,n=m.length,o=j.config,p=o&&o.radius||0;for(a+=k.getTranslation(),d=j.getPlotIndices(Math.floor(Math.max(k.getValue(a-p),0))),e=d[0],d=j.getPlotIndices(Math.ceil(Math.min(k.getValue(a+p),n-1))),f=d[d.length-1],[e,f]=e>f?[f,e]:[e,f],h=f;h>=e&&(c=m[h],!(c&&(g=j.isWithinShape(c,h,a,b),g)));h--);return g}getName(){return'candlestickline'}}export default CandleStickline;