quoslibero
Version:
FusionCharts JavaScript charting framework
1 lines • 8.2 kB
JavaScript
import AreaDataset from'../../../../fc-charts/src/dataset/area';import{hasSVG,getMouseCoordinate,mathAbs,pluck,pluckNumber,getValidValue,parseUnsafeString,parseTooltext,polyPathToPath,snapPoint}from'../../../../fc-core/src/lib';import{_restore,_getJSONData,updateDataValue}from'../dragcolumn';import dragAreaAnimation from'./index.animation';import{addDep}from'../../../../fc-core/src/dependency-manager';let _updateImage,_configure,__firePlotEvent,_drag,UNDEF,SETROLLOVERATTR='setRolloverAttr',SETROLLOUTATTR='setRolloutAttr',ROLLOUT='DataPlotRollOut',ROLLOVER='DataPlotRollOver',DRAGLINE='dragLine',DATAPLOTCLICK='dataplotclick',dragMouseAttr=hasSVG&&'ns-resize'||'n-resize',mathMin=Math.min,mathMax=Math.max,isVML=!1;addDep({name:'dragAreaAnimation',type:'animationRule',extension:dragAreaAnimation});class DragAreaDataset extends AreaDataset{getType(){return'dataset'}getName(){return'dragArea'}configureAttributes(a){var b=this,c=b.config,d=b.getFromEnv('chart-attrib'),e=c.JSONData;c.allowDrag=pluckNumber(e.allowdrag,1),c.allowNegDrag=pluckNumber(e.allownegativedrag,1),c.allowAxisChange=pluckNumber(d.allowaxischange,1),c.snapToDivOnly=pluckNumber(d.snaptodivonly,0),c.doNotSnap=pluckNumber(d.donotsnap,0),c.snapToDiv=pluckNumber(d.snaptodiv,1),c.snapToDivRelaxation=pluckNumber(d.snaptodivrelaxation,10),c.doNotSnap&&(c.snapToDiv=c.snapToDivOnly=0),super.configureAttributes(a)}_plotConfigure(a,b){let c,d,e=this.config,f=this.components.data;super._plotConfigure(a,b),c=f[a],d=c.config,d.allowDrag=pluckNumber(b.allowdrag,e.allowDrag),d.allowNegDrag=pluckNumber(b.allownegativedrag,e.allowNegDrag)}static updateImage(a){var b,c=a.graphics,d=c.image||c.element,e=a.config,f=e.anchorProps,g=e.hoverEffects,h=d&&d.data('imgRef'),i=f.imageScale,j=.01*(h.height*i),k=.01*(h.width*i),l=a._xPos,m=a._yPos,n=g.imageHoverScale,o=.01*(h.width*n),p=.01*(h.height*n),q=f.isAnchorRadius,r=f.radius=q?f.radius:mathMin(k,j)/2,s=f.imagePadding,t=r-s-.5*f.borderThickness,u=g.radius-s-.5*g.anchorBorderThickness,v=f.symbol[1],w=polyPathToPath([v||2,l,m,0<u?u:0,g.startAngle,g.dip]),x=polyPathToPath([v||2,l,m,0<t?t:0,f.startAngle,0]),y={x:l-.005*(h.width*i),y:m-.005*(h.height*i),width:k,height:j,alpha:100};y['clip-path']=x,b={x:l-.005*(h.width*n),y:m-.005*(h.height*n),width:o,height:p,alpha:100},b['clip-path']=w,d.attr(y),d.data(SETROLLOVERATTR,b),d.data(SETROLLOUTATTR,y)}drag(a,b,c,d){let e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I=this,J=I.config,K=J.index,L=I.getFromEnv('chart'),M=L.config,N=M.canvasTop,O=M.canvasBottom,P=I.getFromEnv('toolTipController'),Q=I.getFromEnv('number-formatter'),R=I.components.data,S=I.getFromEnv('paper').canvas,T=S.style,U=I.getFromEnv('yAxis'),V=U.getTicks(),W=mathAbs(U.getValue(U.getPixel(0)-J.snapToDivRelaxation)),X=J.snapToDivOnly?.5*mathAbs(V[1]-V[0]):W,Y=M.yaxisname,Z=M.xaxisname,$={xaxisName:Z,yaxisName:Y},_=I.getGraphicalElement(),aa=_.lineElement,ba=M.dragTolerance+1,ca=U.yBasePos,da=I.getFromEnv('chart-attrib'),ea=I.getName()===DRAGLINE,fa=J.JSONData,ga=I.getFromEnv('chart-container');d=d||getMouseCoordinate(ga,b,L);'dragstart'===a?(e=R[c],g=e.config,j=e._yPos,u=e._xPos,t=g.allowDrag,m=d.chartY,q=d.chartX,t&&m>=j-ba&&m<=j+ba&&q<=u+ba&&q>=u-ba?(g.dragStart=!0,g._pointerDy=0,g._dragStartY=m,g._dragBuffer=j-m,e.dragged=!0,e.startValue=g.setValue,e.name=J.seriesname,e.datasetIndex=J.index,o={dataIndex:n+1,datasetIndex:e.datasetIndex,startValue:e.startValue,datasetName:e.name},g.dragStart=!0):g.dragStart=!1):'dragmove'===a?(e=R[c],g=e.config,g.dragStart&&(m=d.chartY,g.allowDrag&&(T.cursor=dragMouseAttr),f=e.graphics.element,g._pointerDy++,w=e.graphics.image,u=e._xPos,B=f,m+=g._dragBuffer,z=g.allowNegDrag,l=z?O:ca,p=g.anchorProps,F=p.startAngle||90,E=g.hoverEffects,D=g.hoverEffects&&g.hoverEffects.enabled,C=p.imageUrl,m<N?m=N:m>l&&(m=l),e._yPos=j=m,g._y=h=g.setValue=U.getValue(j),g._Py=U.getPixel(g._y),i=Q.dataLabels(h),g.toolTipValue=i,g.displayValue=i,I.parseLabelAttributes(e,n),I.drawLabel(n,n+1),e.graphics.element=f,P.hide(J.currentToolTip),(D&&(k=B.data(SETROLLOVERATTR))&&(k.path=polyPathToPath([E.anchorSides||2,u,j,E.anchorRadius,E.startAngle,E.dip])),D&&(v=B.data(SETROLLOUTATTR))&&(v.path=polyPathToPath([p.symbol[1]||2,u,j,p.radius,p.startAngle,g.dip||0])),B&&B.attr(v||{path:polyPathToPath([p.symbol[1]||2,u,j,p.radius,F,0])})),w&&DragAreaDataset.updateImage(e),ea&&I.drawCommonElements(),aa&&(J=I.config,x=g.pathStartIndex,y=g.pathEndIndex,A=g.lastPath,A=I.getLinePath(R,{begin:x,end:y}),aa.attr({path:A.getPathArr()})),1===g._pointerDy&&(o={dataIndex:c,datasetIndex:K,startValue:e.startValue,datasetName:e.name},L.fireChartInstanceEvent('dataplotDragStart',o)))):'dragend'===a?(e=R[c],g=e.config,g.dragStart&&(I.setMaxMin(e),(J.snapToDiv||J.snapToDivOnly)&&(f=e.graphics.element,w=e.graphics.image,u=e._xPos,B=f,p=g.anchorProps,F=p.startAngle||90,E=g.hoverEffects,D=g.hoverEffects&&g.hoverEffects.enabled,C=p.imageUrl,g.setValue=snapPoint({snapPixel:X,datasetConf:J},V,e),m=U.getPixel(g.setValue),e._yPos=j=m,g._y=h=g.setValue,g._Py=U.getPixel(g._y),i=Q.dataLabels(h),g.toolTipValue=i,g.displayValue=i,I.parseLabelAttributes(e,n),I.drawLabel(n,n+1),e.graphics.element=f,(D&&(k=B.data(SETROLLOVERATTR))&&(k.path=polyPathToPath([E.anchorSides||2,u,j,E.anchorRadius,E.startAngle,E.dip])),D&&(v=B.data(SETROLLOUTATTR))&&(v.path=polyPathToPath([p.symbol[1]||2,u,j,p.radius,p.startAngle,g.dip||0])),B&&B.attr(v||{path:polyPathToPath([p.symbol[1]||2,u,j,p.radius,F,0])})),w&&DragAreaDataset.updateImage(e),ea&&I.drawCommonElements(),aa&&(J=I.config,x=g.pathStartIndex,y=g.pathEndIndex,A=g.lastPath,A=I.getLinePath(R,{begin:x,end:y}),aa.attr({path:A.getPathArr()}))),o={dataIndex:c,datasetIndex:K,startValue:e.startValue,endValue:g.setValue,datasetName:e.name},G=[L.getFromEnv('chartInstance').id,o.dataIndex,o.datasetIndex,o.datasetName,o.startValue,o.endValue],f&&updateDataValue.call(f,b,L),g._pointerDy&&(H&&I._hoverPlotAnchor(e,ROLLOUT),L.fireChartInstanceEvent('dataplotDragEnd',o),L.fireChartInstanceEvent('chartupdated',o,G)),r=getValidValue(parseUnsafeString(pluck(e.tooltext,fa.plottooltext,da.plottooltext))),r!==UNDEF&&($.formattedValue=g.toolTipValue,$.label=g.label,s=parseTooltext(r,[1,2,3,4,5,6,7],$,{value:g.toolTipValue},UNDEF,fa),g.setTooltext=s,r=s,g.toolText=s),s=g.finalTooltext=!1===g.toolText?'':r||g.toolText.substring(0,g.toolText.indexOf(g.formatedVal))+g.toolTipValue,!(m>=j-ba&&m<=j+ba&&q<=u+ba&&q>=u-ba)&&(T.cursor='default'),g._dragBuffer=0,g._pointerDy=0,g.dragStart=!1)):void 0}_firePlotEvent(a,b,c){var d,e,f,g,h,i,j,k,l,m,n,o,p,q=this,r=q.config,s=q.getFromEnv('chart'),t=q.getFromEnv('chartConfig'),u=t.drawTrendRegion,v=q.getFromEnv('paper'),w=q.getFromEnv('toolTipController'),x=v.canvas,y=x.style,z=q.components,A=z.data[b],B=r.currentToolTip,C=c.originalEvent;'touchend'===a&&(o=C.changedTouches[0],C.pageX=o&&o.pageX,C.pageY=o&&o.pageY),e=getMouseCoordinate(s.getFromEnv('chart-container'),C,s),f=e.chartY,g=e.chartX;A&&(j=A.graphics.element,n=A.config,p=n.anchorProps,l=n.finalTooltext,k=n.hoverEffects.enabled,m=n.eventArgs,h=A._yPos,i=A._xPos,n.dragTolerance=n.dragTolerance<p.markerRadius?p.markerRadius+.5:n.dragTolerance,d=mathMax(n.dragTolerance,n.hoverEffects.anchorRadius||0)+1,'fc-mouseover'===a?(n.allowDrag&&(y.cursor=dragMouseAttr),n.dragStart||!l||n.dragStart||u||(B?w.draw(C,l,B):B=r.currentToolTip=w.draw(C,l)),n.dragStart||(k&&q._hoverPlotAnchor(A,ROLLOVER),j&&s.plotEventHandler(j,c,ROLLOVER,m))):'fc-mouseout'===a?(y.cursor='default',k&&q._hoverPlotAnchor(A,ROLLOUT),j&&s.plotEventHandler(j,c,ROLLOUT,m),w.hide(r.currentToolTip)):'fc-mousemove'===a?!n.dragStart&&l&&f>=h-d&&f<=h+d&&g<=i+d&&g>=i-d?(n.allowDrag&&(y.cursor=dragMouseAttr),B?w.draw(C,l,B):B=r.currentToolTip=w.draw(C,l)):w.hide(r.currentToolTip):'fc-click'===a?j&&s.plotEventHandler(j,c,DATAPLOTCLICK,m):void 0)}restore(){_restore.call(this)}getJSONData(){return _getJSONData.call(this)}}_updateImage=DragAreaDataset.prototype.updateImage,__firePlotEvent=DragAreaDataset.prototype._firePlotEvent,_configure=DragAreaDataset.prototype.configureAttributes,_drag=DragAreaDataset.prototype.drag;export{__firePlotEvent,_configure as configurer,_updateImage,_drag};export default DragAreaDataset;