quoslibero
Version:
FusionCharts JavaScript charting framework
1 lines • 4 kB
JavaScript
import CandleStick from'./candlestick';import isValidNumber from'../../../../../fc-utils/src/type/is-valid-number';import{defined,pluckNumber}from'../../../../../fc-core/src/lib';import{addDep}from'../../../../../fc-core/src/dependency-manager';import OHLCAnimation from'./ohlc.animation';addDep({name:'ohlcAnimation',type:'animationRule',extension:OHLCAnimation});let tooltipYbuffer=10;class OHLC extends CandleStick{__setDefaultConfig(){super.__setDefaultConfig(),this.config.defaultBearStyle.stroke='868AC8'}_drawPlot(){var a,b,c=this,d=c.config,e=d.dataInfo,f=defined(d.bullOpacity),g=defined(d['bull-fill-opacity']),h=defined(d['bull-stroke-opacity']),i=defined(d.bearOpacity),j=defined(d['bear-fill-opacity']),k=defined(d['bear-stroke-opacity']),l={},m={};f&&(l.opacity=d.bullOpacity),g&&(l.opacity=d['bull-fill-opacity']),h&&(l.opacity=d['bull-stroke-opacity']),i&&(m.opacity=d.bearOpacity),j&&(m.opacity=d['bear-fill-opacity']),k&&(m.opacity=d['bear-stroke-opacity']),e.forEach((d,f)=>{d.groupConfig&&(b='bull'===d.groupId?l:m,1<!!d.lowStickYEntend+!!d.highStickYExtend+!!d.open+!!d.close?'bull'===d.groupId?(a=Object.assign({path:`M${d.midX},${d.highStickYExtend||d.open||d.close},V${d.lowStickYEntend||d.close||d.open}`,"stroke-linecap":'round'},b),d.style&&Object.assign(a,d.style),c.addGraphicalElement({el:'path',component:c,container:{label:'group',id:'meso-'+d.groupId},props:{index:f,dataLength:e.length},label:'highlow',attr:a},!0)):(a=Object.assign({path:`M${d.midX},${d.highStickYExtend||d.close},V${d.lowStickYEntend||d.open}`,"stroke-linecap":'round'},b),d.style&&Object.assign(a,d.style),c.addGraphicalElement({el:'path',component:c,container:{label:'group',id:'meso-'+d.groupId},props:{index:f,dataLength:e.length},label:'highlow',attr:a},!0)):(d.lowStickYEntend||d.highStickYExtend)&&(a=Object.assign({path:`M${d.midX},${d.lowStickYEntend||d.highStickYExtend},V${d.lowStickYEntend||d.highStickYExtend}`,"stroke-linecap":'round'},b),d.style&&Object.assign(a,d.style),c.addGraphicalElement({el:'path',component:c,container:{label:'group',id:'meso-'+d.groupId},props:{index:f,dataLength:e.length},label:'highlow',attr:a},!0)),d.open&&(a=Object.assign({path:`M${d.midX},${d.open},H${d.leftExtend}`},b),d.style&&Object.assign(a,d.style),c.addGraphicalElement({el:'path',component:c,container:{label:'group',id:'meso-'+d.groupId},props:{index:f,dataLength:e.length},label:'open',attr:a},!0)),d.close&&(a=Object.assign({path:`M${d.midX},${d.close},H${d.rightExtend}`},b),d.style&&Object.assign(a,d.style),c.addGraphicalElement({el:'path',component:c,container:{label:'group',id:'meso-'+d.groupId},props:{index:f,dataLength:e.length},label:'close',attr:a},!0),d.style=void 0))}),d.hoverInfo=[]}allocatePosition(){var a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r=this,s=r.getFromEnv('binDecider'),t=r.getFromEnv('xScale'),u=r.getFromEnv('yScale'),v=r.config,[w,x,y,z,A]=v.indices,B=v.dataInfo,C=v.data;(v.repositioningDone=r._isRepositioningNeeded())&&(v.timeStampGap=s.getRangeThreshold()[2],o=t.getRangeValue(s.getRangeThreshold()[2])-t.getRangeValue(0),a=o*(1-v.plotSpacePercent/100),B=v.dataInfo=[],C.forEach((l,o)=>{b=l[w],c=t.getRangeValue(new Date(b.start),new Date(b.end)),d=l[x],e=l[A],f=l[y],g=l[z],o||(i=v.firstTimeStamp=b.start),p=u.getRangeValue(e),q=u.getRangeValue(d),n=u.getRangeValue(f),m=u.getRangeValue(g),isValidNumber(q)&&isValidNumber(p)&&(k=d>e?'bear':'bull'),j={startDate:b.start,endDate:b.end},j.rightExtend=c+a/2,j.leftExtend=j.x=c-a/2,j.y=n,j.width=a,j.close=p,j.openValue=d,j.closeValue=e,j.highValue=f,j.lowValue=g,j.value=e,j.open=q,j.midX=c,j.groupId=k||'bull',j.lowStickYEntend=m,j.highStickYExtend=n,j.height=m-n||0,j.colY=j.height/2+n-tooltipYbuffer,j['stroke-width']=pluckNumber(v['default-stroke-width'],1),j.groupConfig='bull'===k?'bullConfig':'bearConfig',h=t.getBinIndex(b.start,i),B[h]=j})),(l=v.hoverInfo)&&l.forEach(a=>{'object'==typeof B[a.index]&&(B[a.index].style=a[B[a.index].groupId+'Style'])})}getName(){return'timeseries-ohlc'}}export default OHLC;