quoslibero
Version:
FusionCharts JavaScript charting framework
1 lines • 13 kB
JavaScript
import LineDataset from'../line';import{BLANKSTRING,BGRATIOSTRING,extend2,pluck,pluckNumber,toRaphaelColor,HUNDREDSTRING,getFirstValue,parseTooltext,parseUnsafeString,getDefinedColor,getDashStyle,getValidValue,getDarkColor,getLightColor,getFirstAlpha,getFirstColor}from'../../../../fc-core/src/lib';import{addDep}from'../../../../fc-core/src/dependency-manager';import KdTree from'../_internal/kdtree';import scatterAnimation from'./index.animation';const math=Math,mathMax=math.max,mathMin=math.min,mathRound=math.round;var UNDEF,COMMA=',',NONE='none',COMMASTRING=',',PLOTGRADIENTCOLOR='plotGradientColor',SHOWSHADOW='showShadow',getPointColor=function(a,b){var c,d,e;return a=getFirstColor(a),b=getFirstAlpha(b),d=getLightColor(a,70),e=getDarkColor(a,50),c={FCcolor:{gradientUnits:'objectBoundingBox',cx:.4,cy:.4,r:'100%',color:d+COMMASTRING+e,alpha:b+COMMASTRING+b,ratio:BGRATIOSTRING,radialGradient:!0}},c};addDep({name:'scatterAnimation',type:'animationRule',extension:scatterAnimation});class ScatterDataset extends LineDataset{getType(){return'dataset'}setupHoverTracker(){var a,b,c,d,e,f,g,h=this,k=h.config.searchDataArr=[],l=h.components,m=l.data,n={},o=h.getSkippingInfo&&h.getSkippingInfo(),p=o&&o.draw||[],q=p.length,r=o&&o.skippingApplied;for(c=m.length,r&&(c=q),b=0;b<c;b++)a=p[b]||[b],f=m[a],f&&(g=f.config,d=g._Px,e=g._Py,n=g.anchorProps,k.push({x:d,y:e,index:a,data:f,r:n.radius||0}));this.config.dataTree=new KdTree().buildKdTree(k)}getName(){return'scatter'}configureAttributes(a){if(!a)return!1;this.trimData(a),this.config.JSONData=a;var b,c,d,e,f,g=this,h=g.getFromEnv('chart'),i=g.config,j=i.JSONData,k=h.areaAlpha,l=h.getFromEnv('dataSource').chart,m=g.getFromEnv('color-manager'),n=pluckNumber(j.showplotborder,l.showplotborder||1),o=m.getPlotColor(g.index),p=i.lineDashed=pluckNumber(j.linedashed,j.dashed,l.linedashed,0),q=g.isLineSet;i.plotColor=o,e=pluckNumber(h.defaultPlotShadow,m.getColor(SHOWSHADOW)),i.xAxisLabelMode=pluck(l.xaxislabelmode,'categories'),i.toolTipSepChar=pluck(l.tooltipsepchar,', '),i.defaultValuePadding={left:0,right:0},i.parentYAxis=q?c=1:c='s'===pluck(j.parentyaxis&&j.parentyaxis.toLowerCase(),'p')?1:0,g.config.yAxis=g.getFromEnv('yAxis')[c],i.connectNullData=pluckNumber(l.connectnulldata,0),i.seriesname=parseUnsafeString(j.seriesname),i.includeinlegend=pluckNumber(j.includeinlegend,i.seriesname?1:0),i.enableAnimation=d=pluckNumber(l.animation,l.defaultanimation,1),i.animation=!!d&&{duration:1e3*pluckNumber(l.animationduration,1)},i.transposeanimation=pluckNumber(l.transposeanimation,d),i.transposeanimduration=1e3*pluckNumber(l.transposeanimduration,.2),i.showvalues=pluckNumber(j.showvalues,l.showvalues),i.valuePadding=pluckNumber(l.valuepadding,2),i.valuePosition=pluck(j.valueposition,l.valueposition,'auto'),i.showTooltip=pluckNumber(l.showtooltip,1),i.seriesNameInTooltip=pluckNumber(l.seriesnameintooltip,1),i.plotFillColor=i.plotfillcolor=pluck(j.color,l.plotfillcolor,o),i.plotFillAngle=i.plotFillAngle=pluck(l.plotfillangle,270),i.plotFillAlpha=i.plotfillalpha=pluck(j.alpha,l.plotfillalpha,k,'70'),f=pluckNumber(l.useplotgradientcolor,1),i.plotGradientColor=i.plotgradientcolor=0===f?'':getDefinedColor(l.plotgradientcolor,m.getColor(PLOTGRADIENTCOLOR)),i.fillColor=i.fillcolor={color:i.plotfillcolor+(i.plotgradientcolor?COMMA+i.plotgradientcolor:BLANKSTRING),alpha:i.plotfillalpha,angle:i.plotFillAngle},i.plotBorderAlpha=i.plotborderalpha=n?pluck(j.plotborderalpha,l.plotborderalpha,j.alpha,'95'):0,i.plotBorderColor=i.plotbordercolor=pluck(j.plotbordercolor,l.plotbordercolor,l.areabordercolor,'666666'),i.dashed=b=pluckNumber(j.dashed,l.plotborderdashed),i.plotBorderDashLen=i.plotborderdashlen=pluck(j.plotborderdashlen,l.plotborderdashlen,5),i.plotBorderDashGap=i.plotborderdashgap=pluck(j.plotborderdashgap,l.plotborderdashgap,4),i.plotBorderThickness=i.plotborderthickness=pluckNumber(j.plotborderthickness,l.plotborderthickness,1),i.plotBorderDashStyle=i.plotborderdashstyle=b?getDashStyle(i.plotborderdashlen,i.plotborderdashgap):'none',i.showHoverEffect=i.showhovereffect=pluckNumber(l.plothovereffect,l.anchorhovereffect,l.showhovereffect,UNDEF),i.rotateValues=pluckNumber(l.rotatevalues)?270:0,i.drawLine=pluckNumber(j.drawline,l.drawlines,0),i.lineThickness=i.linethickness=pluckNumber(j.linethickness,l.linethickness,2),i.lineDashLen=i.linedashlen=pluckNumber(j.linedashlen,l.linedashlen,5),i.lineDashGap=i.linedashgap=pluckNumber(j.linedashgap,l.linedashgap,4),i.lineAlpha=i.linealpha=pluckNumber(j.linealpha,l.linealpha,j.alpha,HUNDREDSTRING),i.lineColor=i.linecolor=pluck(j.linecolor,l.linecolor,j.color,i.plotColor),i.lineDashStyle=i.linedashstyle=getDashStyle(i.linedashlen,i.linedashgap),i.lineDashStyle=i.linedashstyle=p?i.linedashstyle:NONE,i.shadow={opacity:pluckNumber(l.showshadow,e)?i.linealpha/100:0},i.drawanchors=pluckNumber(j.drawanchors,j.showanchors,l.drawanchors,l.showanchors),i.anchorbgcolor=getFirstColor(pluck(j.anchorbgcolor,l.anchorbgcolor,m.getColor('anchorBgColor'))),i.anchorbordercolor=getFirstColor(pluck(j.anchorbordercolor,j.color,l.anchorbordercolor,i.linecolor)),i.anchorradius=pluckNumber(j.anchorradius,l.anchorradius,3),i.anchoralpha=pluck(j.anchoralpha,j.alpha,l.anchoralpha,HUNDREDSTRING),i.anchorbgalpha=pluck(j.anchorbgalpha,j.alpha,l.anchorbgalpha,HUNDREDSTRING),i.anchorborderthickness=pluck(j.anchorborderthickness,l.anchorborderthickness,1),i.anchorsides=pluckNumber(j.anchorsides,l.anchorsides,i.index+3),i.anchorimageurl=pluck(j.anchorimageurl,l.anchorimageurl),i.anchorimagealpha=pluckNumber(j.anchorimagealpha,l.anchorimagealpha,100),i.anchorimagescale=pluckNumber(j.anchorimagescale,l.anchorimagescale,100),i.anchorimagepadding=pluckNumber(j.anchorimagepadding,l.anchorimagepadding,1),i.anchorstartangle=pluckNumber(j.anchorstartangle,l.anchorstartangle,90),i.anchorshadow=pluckNumber(j.anchorshadow,l.anchorshadow,0),i.plotToolText=getValidValue(parseUnsafeString(pluck(j.plottooltext,l.plottooltext))),g.setState('visible',1===pluckNumber(j.visible,!+j.initiallyhidden,1)),g._setConfigure(),!1!==h.config.hasLegend&&h.config.showLegend&&g._addLegend(),g.setState('dirty',!0)}calculateScrollRange(){let a=this,b=a.config,c=a.getFromEnv('chart'),d=a.getFromEnv('xAxis'),e=c.hasScroll,f=a.components.data,g=f.length;b.scrollMinVal=e?mathMax(mathRound(d.getVisibleConfig().minValue)-1,0):0,b.scrollMaxVal=e?mathMin(mathRound(d.getVisibleConfig().maxValue)+2,g):g,b.scrollMinValForLabel=b.scrollMinVal,b.scrollMaxValForLabel=b.scrollMaxVal}_setConfigure(){var a,b,c,d,e,f,g,h,j,k,l,m,n=-Infinity,o=+Infinity,p=n,q=o,r=o,s=n,t=this,u=t.components.data||(t.components.data=[]),v=t.getFromEnv('chart'),w=t.config,x=w.JSONData,y=v.getFromEnv('dataSource').chart,z=x.data||[],A=z.length,B=t.getFromEnv('number-formatter'),C=parseUnsafeString(y.yaxisname),D=parseUnsafeString(y.xaxisname),E=w.lineDashed,F=w.linedashstyle,G=w.parentYAxis,H=w.toolTipSepChar,I=w.seriesname;for(w.imageCount=0,a=0;a<A;a+=1)d=z[a],c=u[a]||(u[a]={}),b=c.config||(c.config={}),b.setValue=e={x:B.getCleanValue(d.x),y:B.getCleanValue(d.y)},null!==e.x&&null!==e.y&&(e.x>s&&(s=e.x,w.rightMostData=c),e.x<r&&(r=e.x,w.leftMostData=c),e.y>p&&(p=e.y,w.topMostData=c),e.y<q&&(q=e.y,w.bottomMostData=c)),b._x=e.x,b._y=e.y,b.setLink=pluck(d.link),b.anchorProps=this._parseAnchorProperties(a),b.showValue=pluckNumber(d.showvalue,w.showvalues),b.dashed=pluckNumber(d.dashed,E),b.color=pluck(d.color,w.linecolor),b.alpha=pluck(d.alpha,w.linealpha),b.dashStyle=b.dashed?F:'none',b.toolTipValue=g=B.dataLabels(e.y,G),b.setDisplayValue=m=parseUnsafeString(d.displayvalue),k=b.formatedVal=pluck(d.toolTipValue,B.dataLabels(e.y,G)),l=B.xAxis(e.x),b.displayValue=pluck(m,g),b.setTooltext=getValidValue(parseUnsafeString(pluck(d.tooltext,w.plotToolText))),w.showTooltip?b.setTooltext===UNDEF?null===k?f=!1:(f=I?I+H:BLANKSTRING,f+=e.x?l+H:BLANKSTRING,f+=g):(h=[4,5,6,7,8,9,10,11],j={yaxisName:C,xaxisName:D,yDataValue:k,xDataValue:l},f=parseTooltext(b.setTooltext,h,j,d,y,x)):f=!1,b.toolText=f,c?!c.graphics&&(u[a].graphics={}):c=u[a]={graphics:{}},b.hoverEffects=this._parseHoverEffectOptions(c,d),b.anchorProps.isAnchorHoverRadius=b.hoverEffects.anchorRadius;w.xMax=s,w.xMin=r,w.yMin=q,w.yMax=p,t.ErrorValueConfigure&&t.ErrorValueConfigure()}_getHoveredPlot(a,b){var c=this.config.dataTree.getNeighbour({x:a,y:b},!0);if(c)return{pointIndex:c.index||c.i,hovered:!0,pointObj:c.data}}drawPlots(){super.drawPlots(),this.setupHoverTracker()}getRegressionPoints(){var a,b,c,d,e,f,g,h,l=Math.min,m=Math.max,n=this,o=n.getChildren('regression'),p=-Infinity,q=1/0,r=-Infinity,s=1/0;if(o&&o.length&&!o[0].getState('removed')){for(a=o[0]._config.regressionPoints||[],g=a.length,b=0;b<g;b++)for(e=a[b],c=0;c<e.length;c++)for(f=e[c]||[],h=f.length,d=0;d<h;d++)p=m(p,f[d].x),q=l(q,f[d].x),r=m(r,f[d].y),s=l(s,f[d].y);return{max:r,min:s,xMax:p,xMin:q}}}getDataLimits(){var a=Math.min,b=Math.max,c=this,d=c.config,e=c.getFromEnv('chart'),f=e.config,g=d.yMax,h=d.yMin,i=d.xMax,j=d.xMin,k=-Infinity,l=+Infinity,m=f.transposeAxis,n=c.getRegressionPoints();return!1===c.getState('visible')&&m&&(g=k,h=l,i=k,j=l),n&&(g=b(g,n.max),h=a(h,n.min),i=b(i,n.xMax),j=a(j,n.xMin)),{max:g,min:h,xMax:i,xMin:j}}getAxisValuePadding(){return this.config.defaultValuePadding}getCanvasPadding(){var a,b,c,d,e,f,g,h,j,k,l,m,n,o,p,q,r,s,t=Math.round,u=Math.sqrt,v=this,w=v.config||(v.config={}),x=v.components||{},y=v.getFromEnv('chartConfig'),z=y.rotatevalues,A=v.getFromEnv('xAxis'),B=v.getFromEnv('yAxis'),C=A.config.isReverse,D=v.getFromEnv('dataLabelStyle'),E=x.data||[],F=E.length,G=w.leftMostData||E[0],H=w.rightMostData||E[E.length-1],I=w.topMostData,J=w.bottomMostData,K=mathMin(y.canvasHeight,y.canvasWidth)/8,L=A.getValue(0),M=1,N=1,O=y.zMax,P=w.bubbleScale,Q={},R={},S=0,T=0,U=A.config.axisRange,V=U.min,W=U.max,X=B.config.axisRange,Y=X.min,Z=X.max,$=A.getPixel(V),_=A.getPixel(W),aa=v.getFromEnv('smartLabel'),ba={paddingLeft:0,paddingRight:0},ca=0;for(a=u(O),b=K/a,k=0;k<F;k++)c=E[k].config,d=G.config,e=H.config,h=u(c.z),p=t(h*b)*P||0,q=A.getValue(p)-L,l=c.x-q/2,1==M&&(h=u(d.z),p=t(h*b)*P||0,q=A.getValue(p)-L,m=d.x-q/2),1==N&&(h=u(e.z),p=t(h*b)*P||0,q=A.getValue(p)-L,n=e.x-q/2),M=0,N=0,m>l&&(G=E[k],M=1),n<l&&(H=E[k],N=1);return G&&(f=G.config,g=f.anchorProps.radius,r=f.showValue,r&&(o=f.displayValue,aa.useEllipsesOnOverflow(y.useEllipsesWhenOverflow),aa.setStyle(D),R=aa.getOriSize(o),ca=z?R.height:R.width),null!==f.setValue&&(l=A.getPixel(f.setValue.x),C?(j=l-.5*ca,T=_-j):(j=l-.5*ca,T=$-j),S=!C&&l-g<=$||C&&l-g<=_?C?_-(l-g):$-(l-g):0),ba.paddingLeft=mathMax(T,S)),H&&(f=H.config,r=f.showValue,g=f.anchorProps.radius,r&&(o=f.displayValue,aa.setStyle(D),Q=aa.getOriSize(o),ca=z?Q.height:Q.width),null!==f.setValue&&(l=A.getPixel(f.setValue.x),j=l-$+.5*ca,T=j-_+$,C&&(T=j),S=!C&&l+g>=_||C&&l+g>=$?C?l+g-$:l+g-_:0),ba.paddingRight=mathMax(T,S)),I&&(f=I.config,g=f.anchorProps.radius||0,Z=B.getPixel(Z),null!==f.setValue&&(s=B.getPixel(f.setValue.y),S=pluckNumber(g,0)+pluckNumber(f.anchorProps.borderThickness,0)/2),ba.paddingTop=0<Z-(s-S)?Z-(s-S):0),J&&(f=J.config,g=f.anchorProps.radius||0,Y=B.getPixel(Y),null!==f.setValue&&(s=B.getPixel(f.setValue.y),S=pluckNumber(g,0)+pluckNumber(f.anchorProps.borderThickness,0)/2),ba.paddingBottom=0<s+S-Y?s+S-Y:0),ba}_addLegend(){var a,b,c,d,e,f=this,g=f.getFromEnv('chart'),h=f.config,i=g.getChildren('legend')[0],j=pluckNumber(h.drawanchors,1),k={fillColor:getPointColor(h.anchorbgcolor,HUNDREDSTRING),lineColor:{FCcolor:{color:h.anchorbordercolor,alpha:h.anchoralpha}},lineWidth:h.anchorborderthickness},l=i.config.symbol3DLighting;l?k.fillcolor&&k.fillcolor.FCcolor?(a=extend2({},k.fillcolor),a.FCcolor.alpha='100'):a=pluck(k.fillColor):a={FCcolor:{color:pluck((b=k.fillColor)&&(b.FCcolor&&b.FCcolor.color.split(COMMA)[0]||b)),angle:0,ratio:'0',alpha:'100'}},d={enabled:h.includeInLegend,type:f.type,drawLine:pluck(h.drawLine,!0),anchorSide:j?h.anchorsides:0,label:getFirstValue(f.config.JSONData.seriesname)},h.includeinlegend?(e=i.getItem(f.config.legendItemId),e?e.configure({style:i.config.itemStyle,hiddenStyle:i.config.itemHiddenStyle,datasetVisible:i.config.datasetVisible,hoverStyle:i.config.itemHoverStyle}):(f.config.legendItemId=i.createItem(f),e=i.getItem(f.config.legendItemId),f.addExtEventListener('fc-click',function(){e.itemClickFn()},e)),e.configure(d),e.setStateCosmetics('default',{symbol:{fill:toRaphaelColor(a),rawFillColor:h.anchorbgcolor,rawStrokeColor:h.lineColor,stroke:toRaphaelColor(pluck((c=k.lineColor)&&(c.FCcolor&&c.FCcolor.color.split(COMMA)[0]||c))),"stroke-width":h.anchorborderthickness}}),f.getState('visible')?e.removeLegendState('hidden'):e.setLegendState('hidden')):f.config.legendItemId&&i.disposeItem(f.config.legendItemId)}getDSGroupdef(){return UNDEF}trimData(a){if(!this.config.JSONData)return;let b,c,d=this,e=d.config,f=e&&e.context,g=f&&f.prevCatlen,h=d.getFromEnv('xAxis'),i=h.getTicksLen(),j=g-i,k=e.JSONData,l=k.data&&k.data.length,m=a.data&&a.data.length||0,n=l-m;j>n?(b=j,c=i):(b=n,c=m),0<b&&this.removeData(c,b,!1)}}export default ScatterDataset;