UNPKG

quoslibero

Version:

FusionCharts JavaScript charting framework

1 lines 7.42 kB
import ColumnDataset from'../../../../fc-charts/src/dataset/column';import{hasSVG,getMouseCoordinate,pluck,pluckNumber,getValidValue,parseUnsafeString,mathAbs,toRaphaelColor,preDefStr,parseTooltext,snapPoint}from'../../../../fc-core/src/lib';import dragColumnAnimation from'./index.animation';import{addDep}from'../../../../fc-core/src/dependency-manager';let _getJSONData,_restore,UNDEF,SETROLLOVERATTR=preDefStr.setRolloverAttrStr,SETROLLOUTATTR=preDefStr.setRolloutAttrStr,ROLLOUT='DataPlotRollOut',ROLLOVER='DataPlotRollOver',MOUSEOVER='mouseOver',MOUSEOUT='mouseOut',DATAPLOTCLICK=preDefStr.DATAPLOTCLICK,dragMouseAttr=hasSVG&&'ns-resize'||'n-resize',updateDataValue=function(a,b){let c,d=this,e=b.getChildren('yAxis')[0],f=b.getFromEnv('chart-container'),g=d.data('eventArgs');c=getMouseCoordinate(f,a,b),g.value=e.getValue(c.chartY),d.data('eventArgs',g)};addDep({name:'dragColumnAnimation',type:'animationRule',extension:dragColumnAnimation});class DragColumnDataset extends ColumnDataset{getType(){return'dataset'}getName(){return'dragColumn'}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.snapToDiv=c.snapToDivOnly?1:pluckNumber(d.snaptodiv,1),c.doNotSnap=pluckNumber(d.donotsnap,0),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)}drag(a,b,c,d){var e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z=this,A=z.config,B=z.getFromEnv('chart'),C=B.config,D=C.canvasTop,E=C.canvasBottom,F=z.getFromEnv('toolTipController'),G=z.getFromEnv('number-formatter'),H=z.components.data,I=z.getFromEnv('paper').canvas,J=I.style,K=z.getFromEnv('yAxis'),L=K.yBasePos,M=C.yaxisname,N=C.xaxisname,O={xaxisName:N,yaxisName:M},P=K.getTicks(),Q=C.dragTolerance+1,R=A.JSONData,S=z.getFromEnv('chart-attrib'),T=C.useplotgradientcolor,U=C.useroundedges,V=z.getFromEnv('chart-container'),W=mathAbs(K.getValue(K.getPixel(0)-A.snapToDivRelaxation)),X=A.snapToDivOnly?.5*mathAbs(P[1]-P[0]):W;d=d||getMouseCoordinate(V,b,B);'dragstart'===a?(v=H[c],f=v.config,e=v.graphics.element,k=v._yPos,m=v._height,g=0>f.setValue?k+m:k,y=f.allowDrag,p=d.chartY,y&&p>=g-Q&&p<=g+Q?(f.dragStart=!0,f._pointerDy=0,f._dragStartY=p,f._dragBuffer=g-p,v.startValue=f.setValue,v.name=A.seriesname,v.datasetIndex=A.index,v.dragged=!0):f.dragStart=!1):'dragmove'===a?(v=H[c],f=v.config,f.dragStart&&(e=v.graphics.element,s=f.plotIndex,j=f.allowNegDrag,o=j?E:L,p=d.chartY,f._rollOverResponseSetterFire=!1,J.cursor=dragMouseAttr,f._pointerDy++,p+=f._dragBuffer,p<D?p=D:p>o&&(p=o),k=L<p?L:p,m=mathAbs(L-p),v._yPos=k,v._height=m,g=k>=L?k+m:k,f._y=h=f.setValue=K.getValue(g),i=G.dataLabels(h),f.toolTipValue=i,f.displayValue=pluck(f.setDisplayValue,i),T&&!U&&(f.colorArr[0].FCcolor.angle=l=k<L?90:270),e.attr({y:v._yPos,height:v._height,fill:toRaphaelColor(f.colorArr[0])}),z.parseLabelAttributes(v),z.drawLabel(s,s+1),v.graphics.element=e,F.hide(A.currentToolTip),1===f._pointerDy&&(t={dataIndex:c,datasetIndex:v.datasetIndex,startValue:v.startValue,datasetName:v.name},B.fireChartInstanceEvent('dataplotDragStart',t)))):'dragend'===a?(v=H[c],f=v.config,f.dragStart&&(k=v._yPos,e=v.graphics.element,w=getValidValue(parseUnsafeString(pluck(v.tooltext,R.plottooltext,S.plottooltext))),p=d.chartY,z.setMaxMin(v),(A.snapToDiv||A.snapToDivOnly)&&(f.setValue=snapPoint({snapPixel:X,datasetConf:A},P,v),p=K.getPixel(f.setValue),k=L<p?L:p,m=mathAbs(L-p),v._yPos=k,v._height=m,e.attr({y:k,height:m,fill:toRaphaelColor(f.colorArr[0])}),i=G.dataLabels(f.setValue),f.toolTipValue=i,f.displayValue=pluck(f.setDisplayValue,i),z.parseLabelAttributes(v),z.drawLabel(s,s+1)),t={dataIndex:c,datasetIndex:v.datasetIndex,startValue:v.startValue,endValue:f.setValue,datasetName:v.name},u=[B.getFromEnv('chartInstance').id,t.dataIndex,t.datasetIndex,t.datasetName,t.startValue,t.endValue],updateDataValue.call(e,b,B),f._pointerDy&&(B.fireChartInstanceEvent('dataplotDragEnd',t),B.fireChartInstanceEvent('chartupdated',t,u)),T&&!U&&(l=k>=L?90:270,(n=e.data(SETROLLOVERATTR))&&n.fill&&(q=n.fill,q=q.split('-'),q[0]=l,n.fill=q.join('-')),(r=e.data(SETROLLOUTATTR))&&r.fill&&(q=r.fill,q=q.split('-'),q[0]=l,r.fill=q.join('-'))),f._dragBuffer=0,f._pointerDy=0,w!==UNDEF&&(O.formattedValue=f.toolTipValue,O.label=f.label,x=parseTooltext(w,[1,2,3,4,5,6,7],O,{value:f.toolTipValue},UNDEF,R),f.setTooltext=x,w=x,f.toolText=x),x=f.finalTooltext=!1===f.toolText?'':f.toolText+(w?'':f.toolTipValue),!(p>=g-Q&&p<=g+Q)&&(J.cursor='default'),f.dragStart=!1)):void 0}_firePlotEvent(a,b,c){var d,e,f=this,g=f.getFromEnv('chart'),h=f.config,i=h.currentToolTip,j=f.getFromEnv('chartConfig'),k=j.drawTrendRegion,l=f.getFromEnv('paper'),m=l.canvas,n=m.style,o=f.getFromEnv('toolTipController'),p=f.components.data[b],q=p.config,r=p.graphics.element,s=q.finalTooltext||q.toolText,t=c.originalEvent,u=getMouseCoordinate(f.getFromEnv('chart-container'),t,g),v=u.chartY,w=p._yPos,x=p._height,y=f.getFromEnv('yAxis'),z=y.yBasePos,A=q.allowDrag,B=w,C=w+x;d=j.dragTolerance+1,e=w>=z?w+x:w;r&&('fc-mouseover'===a?(v<=C-d&&v>=B+d&&!k&&s&&(i?o.draw(t,s,i):i=h.currentToolTip=o.draw(t,s)),!q._rollOverResponseSetterFire&&v<=C&&v>=B&&(DragColumnDataset._rolloverResponseSetter(g,r,c,this),q._rollOverResponseSetterFire=!0)):'fc-mouseout'===a?(n.cursor='default',q._rollOverResponseSetterFire&&DragColumnDataset._rolloutResponseSetter(g,r,c,this),q._rollOverResponseSetterFire=!1,o.hide(h.currentToolTip)):'fc-click'===a?g.plotEventHandler(r,c,DATAPLOTCLICK):'fc-mousemove'===a?q.dragStart||(e=0>q.setValue?w+x:w,A&&v>=e-d&&v<=e+d?(n.cursor=dragMouseAttr,o.hide(h.currentToolTip)):(n.cursor='default',q._rollOverResponseSetterFire&&!k&&s&&(i?o.draw(t,s,i):i=h.currentToolTip=o.draw(t,s))),!q._rollOverResponseSetterFire&&v<=C&&v>=B?(DragColumnDataset._rolloverResponseSetter(g,r,c),q._rollOverResponseSetterFire=!0):q._rollOverResponseSetterFire&&!(v<=C&&v>=B)&&(o.hide(h.currentToolTip),q._rollOverResponseSetterFire=!1,DragColumnDataset._rolloutResponseSetter(g,r,c,this))):void 0)}static _rolloverResponseSetter(a,b,c,d){let e=b&&b.getData(),f=a.getFromEnv('animationManager');b&&0!==e.showHoverEffect&&!0!==e.draged&&b&&(f.setAnimationState(MOUSEOVER),f.setAnimation({el:b,label:'rect',component:d,attr:b.getData().setRolloverAttr}),a.plotEventHandler(b,c,ROLLOVER))}static _rolloutResponseSetter(a,b,c,d){let e=b&&b.getData(),f=a.getFromEnv('animationManager');b&&0!==e.showHoverEffect&&!0!==e.draged&&(f.setAnimationState(MOUSEOUT),f.setAnimation({el:b,label:'rect',component:d,attr:b.getData().setRolloutAttr}),a.plotEventHandler(b,c,ROLLOUT))}getJSONData(){var a,b,c,d,e,f=this,g=f.config.JSONData.data,h=f.components.data,j=[],k={};for(e=0,d=g.length;e<d;e++){for(c in b=g[e],a=h[e],k={},b)k[c]='value'===c?a.config.setValue:b[c];j.push(k)}return{data:j}}restore(){var a=this;a.setData(a.config.JSONData,!0)}}_getJSONData=DragColumnDataset.prototype.getJSONData,_restore=DragColumnDataset.prototype.restore;export default DragColumnDataset;export{_getJSONData,_restore,updateDataValue};