UNPKG

@fusioncharts/widgets

Version:

FusionCharts JavaScript charting framework

1 lines 17.1 kB
"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");exports.__esModule=true;exports.default=void 0;var _inheritsLoose2=_interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));var _lib=require("@fusioncharts/core/src/lib");var _dependencyManager=require("@fusioncharts/core/src/dependency-manager");var _index=_interopRequireDefault(require("./index.animation"));var _cylinderthermometerbase=_interopRequireDefault(require("../_internal/cylinderthermometerbase"));var configStr=_lib.preDefStr.configStr,POSITION_TOP=_lib.preDefStr.POSITION_TOP,POSITION_MIDDLE=_lib.preDefStr.POSITION_MIDDLE,ROLLOVER="DataPlotRollOver",ROLLOUT="DataPlotRollOut",EVENTARGS="eventArgs",topLightGlowAlphaStr="40,0",topLightGlowRatioStr="0,80",topLightGlowRStr="70%",bulbBorderLightRStr="50%",bulbBorderLightAlphaStr="0,50",bulbBorderLightRatioStr="78,30",bulbTopLightAlphaStr="60,0",bulbTopLightRatioStr="0,30",bulbCenterLightAlphaStr="80,0",bulbCenterLightRatioStr="0,70",cylLeftLightAlphaStr="50,0",cylLeftLightRatioStr="0,80",cylRightLightAlphaStr="50,0,0",cylRightLightRatioStr="0,40,60",HUNDREDPERCENT="100%",zeroCommaHundredStr="0,100",M="M",A="A",L="L",Z="Z",cos50=.643,sin50=.766,win=window,userAgent=win.navigator.userAgent,isIE=/msie/i.test(userAgent)&&!win.opera,TRACKER_FILL="rgba(192,192,192,"+(isIE?.002:1e-6)+")",getScaleFactor=function getScaleFactor(origWParam,origHParam,canvasWidth,canvasHeight){var scaleFactor,origH=origHParam,origW=origWParam;origH=(0,_lib.pluckNumber)(origH,canvasHeight);origW=(0,_lib.pluckNumber)(origW,canvasWidth);if(!origH||!origW){scaleFactor=1}else if(origW/canvasWidth===origH/canvasHeight){scaleFactor=canvasWidth/origW}else{scaleFactor=Math.min(canvasWidth/origW,canvasHeight/origH)}return scaleFactor};(0,_dependencyManager.addDep)({name:"thermometerAnimation",type:"animationRule",extension:_index.default});var ThermometerDataset=function(_CylinderThermometerB){function ThermometerDataset(){var _this;_this=_CylinderThermometerB.call(this)||this;_this.addData=_lib.stubFN;_this.removeData=_lib.stubFN;return _this}(0,_inheritsLoose2.default)(ThermometerDataset,_CylinderThermometerB);var _proto=ThermometerDataset.prototype;_proto.getName=function getName(){return"thermometer"};_proto.getType=function getType(){return"dataset"};_proto._manageSpace=function _manageSpace(){var ds=this,dsConfig=ds.config,chart=ds.getFromEnv("chart"),chartConfig=chart.config,chartWidth=chartConfig.width,chartHeight=chartConfig.height,canvasWidth=chartConfig.canvasWidth,canvasHeight=chartConfig.canvasHeight,canvasLeft=chartConfig.canvasLeft,canvasRight=chartConfig.canvasRight,canvasTop=chartConfig.canvasTop,xDefined=chartConfig.xDefined,yDefined=chartConfig.yDefined,rDefined=chartConfig.rDefined,hDefined=chartConfig.hDefined,thmOriginX=chartConfig.thmOriginX,thmOriginY=chartConfig.thmOriginY,thmBulbRadius=chartConfig.thmBulbRadius,thmHeight=chartConfig.thmHeight,scaleFactor=getScaleFactor(chartConfig.origW,chartConfig.origH,chartWidth,chartHeight),top=0,bottom=0,left=0,right=0,thmCylenderRight,thmhalfWidth,centerPos,thmWidth,bulbHeight,measure,canvasLeftShift;chartConfig.dataLabelStyle.fontSize=this.computeFontSize(chartConfig.dataLabelStyle.fontSizeWithUnit);measure=ds._getLabelSpace();canvasHeight-=measure;bottom+=measure;if(!rDefined){thmBulbRadius=Math.min(canvasWidth/2,(0,_lib.pluckNumber)(thmHeight,canvasHeight)*.13);rDefined=true}else{thmBulbRadius=thmBulbRadius*scaleFactor}chartConfig.effectiveR=thmBulbRadius;thmhalfWidth=thmBulbRadius*cos50;thmWidth=2*thmhalfWidth;bulbHeight=thmBulbRadius*(1+sin50);top+=thmhalfWidth;canvasTop+=thmhalfWidth;canvasHeight-=thmhalfWidth;if(xDefined){thmOriginX=thmOriginX*scaleFactor;canvasLeftShift=thmOriginX-thmhalfWidth-canvasLeft}else{centerPos=(canvasRight-canvasLeft)/2;canvasLeftShift=centerPos-thmhalfWidth;thmCylenderRight=canvasLeftShift+thmWidth;if(thmCylenderRight>canvasWidth){canvasLeftShift=canvasWidth-thmWidth}}left+=canvasLeftShift;canvasLeft+=canvasLeftShift;canvasWidth-=canvasLeftShift;right+=canvasWidth-thmWidth;if(yDefined){thmOriginY=thmOriginY*scaleFactor}if(!hDefined){if(yDefined){thmHeight=thmOriginY-canvasTop}else{thmHeight=Math.max(canvasHeight-bulbHeight,3*thmBulbRadius);thmOriginY=canvasTop+thmHeight}}else{thmHeight=thmHeight*scaleFactor;if(yDefined){top+=thmOriginY-thmHeight-canvasTop}else{thmOriginY=canvasTop+thmHeight}}bottom+=canvasTop+canvasHeight-thmOriginY;dsConfig.thmBulbRadius=thmBulbRadius;dsConfig.thmHeight=thmHeight;return{top:top,bottom:bottom,left:left,right:right}};_proto.draw=function draw(){var dataSet=this,dsConfig=dataSet.config,smartLabel=dataSet.getFromEnv("smartLabel"),chart=dataSet.getFromEnv("chart"),dataLabelsLayer=chart.getChildContainer("datalabelsGroup"),trackerLayer=chart.getChildContainer("trackerGroup"),toolTipController=dataSet.getFromEnv("toolTipController"),scale=dataSet.getFromEnv("scale"),parentContainer=chart.getChildContainer().plotGroup,chartConfig=chart.get(configStr),canvasLeft=chartConfig.canvasLeft,canvasTop=chartConfig.canvasTop,canvasHeight=chartConfig.canvasHeight,r=chartConfig.effectiveR||10,cylinderWidthHalf=r*cos50,use3DLighting=chartConfig.use3DLighting,x=canvasLeft+cylinderWidthHalf,y=canvasTop-cylinderWidthHalf,h=canvasHeight,canvasHorizontalDiff=Math.abs(chartConfig.width-chartConfig.canvasRight-canvasLeft),ypos,scaleTop=cylinderWidthHalf,bulbCenterDistance=r*sin50,scaleY=y+scaleTop,y1=scaleY+h,y2=y1+bulbCenterDistance,value=(0,_lib.pluckNumber)(dsConfig.value,scale.getLimit().min),thmPos=scale.getPixel(value),topRoundR=cylinderWidthHalf*.33,y4=y+topRoundR,y6=thmPos,lCylWidthHalf=cylinderWidthHalf*.9,topRoundRDistance=cylinderWidthHalf-topRoundR,lR=r+lCylWidthHalf-cylinderWidthHalf,x1=x-cylinderWidthHalf,x2=x+cylinderWidthHalf,x3=x-topRoundRDistance,x4=x+topRoundRDistance,lx1=x-lCylWidthHalf,lx2=x+lCylWidthHalf,l1Distance=cylinderWidthHalf*.6,l1x=parseInt(x-l1Distance,10),l2x=x+cylinderWidthHalf/2,ly=dsConfig.thmBaseY=y2-Math.abs(Math.sqrt(lR*lR-lCylWidthHalf*lCylWidthHalf)),containerDummy=dataSet.getContainer("container"),fluidDummy=dataSet.getGraphicalElement("fluid"),topLightGlowDummy=dataSet.getGraphicalElement("topLightGlow"),topLightDummy=dataSet.getGraphicalElement("topLight"),labelDummy=dataSet.getGraphicalElement("label"),label,dataLabelTooltext,dataLabelObj,container,fluid,topLightGlow,topLight,dataLabelContainerDummy=dataSet.getContainer("dataLabelContainer"),canvasBorderElementDummy=dataSet.getGraphicalElement("canvasBorderElement"),bulbBorderLightDummy=dataSet.getGraphicalElement("bulbBorderLight"),bulbTopLightDummy=dataSet.getGraphicalElement("bulbTopLight"),bulbCenterLightDummy=dataSet.getGraphicalElement("bulbCenterLight"),trackerContainerDummy=dataSet.getContainer("trackerContainer"),cylLeftLightDummy=dataSet.getGraphicalElement("cylLeftLight"),cylRightLightDummy=dataSet.getGraphicalElement("cylRightLight"),cylLeftLight1Dummy=dataSet.getGraphicalElement("cylLeftLight1"),cylRightLight1Dummy=dataSet.getGraphicalElement("cylRightLight1"),hotElementDummy=dataSet.getGraphicalElement("hotElement"),dataLabelContainer,canvasBorderElement,bulbBorderLight,bulbTopLight,bulbCenterLight,trackerContainer,cylLeftLight,cylRightLight,cylLeftLight1,cylRightLight1,hotElement,gaugeFillColor=(0,_lib.getDarkColor)(dsConfig.gaugeFillColor,use3DLighting?70:80),gaugeFillAlpha=dsConfig.gaugeFillAlpha,conColor=dsConfig.gaugeContainerColor,darkConColor=(0,_lib.getDarkColor)(conColor,80),lightConColor=(0,_lib.getLightColor)(conColor,80),gaugeBorderThickness=dsConfig.gaugeBorderThickness,gaugeBorderColor=dsConfig.gaugeBorderColor,thPath,bulbPathType1,showHoverEffect=dsConfig.showHoverEffect,plotFillHoverAlpha=dsConfig.plotFillHoverAlpha,plotFillHoverColor=dsConfig.plotFillHoverColor,animationManager=dataSet.getFromEnv("animationManager"),eventArgs,style=chart.config.dataLabelStyle,canvasBorderElementAttr,topLightAttr,hotElementAttr,topLightGlowAttr,bulbBorderLightAttr,bulbTopLightAttr,bulbCenterLightAttr,cylLeftLightAttr,cylRightLightAttr,cylLeftLight1Attr,cylRightLight1Attr,fluidAttr=dsConfig.fluidAttr;if(!fluidAttr){fluidAttr=dsConfig.fluidAttr={}}if(showHoverEffect){fluidAttr.hover={fill:(0,_lib.convertColor)((0,_lib.getDarkColor)(plotFillHoverColor,use3DLighting?70:80),plotFillHoverAlpha)}}fluidAttr.out={fill:(0,_lib.convertColor)(gaugeFillColor,gaugeFillAlpha)};thPath=[M,x3,y,A,topRoundR,topRoundR,0,0,0,x1,y4,L,x1,y1,A,r,r,0,1,0,x2,y1,L,x2,y4,A,topRoundR,topRoundR,0,0,0,x4,y,Z];eventArgs={value:dsConfig.value,displayValue:dsConfig.displayValue,toolText:dsConfig.toolText,thmFillColor:dsConfig.gaugeFillColor,thmBulbRadius:dsConfig.thmBulbRadius,thmHeight:dsConfig.thmHeight,thmGlassColor:dsConfig.gaugeContainerColor,gaugeFillColor:dsConfig.gaugeFillColor,gaugeFillAlpha:dsConfig.gaugeFillAlpha,showGaugeBorder:dsConfig.showGaugeBorder,gaugeBorderColor:dsConfig.rawGaugeBorderColor,gaugeBorderThickness:dsConfig.gaugeBorderThickness,gaugeBorderAlpha:dsConfig.gaugeBorderAlpha};fluidAttr.out.path=[M,lx1,ly,A,lR,lR,0,1,0,lx2,ly,L,lx2,y6,lx1,y6,Z];fluidAttr.out["stroke-width"]=0;canvasBorderElementAttr={"stroke-width":gaugeBorderThickness,stroke:gaugeBorderColor,path:thPath};topLightAttr={path:[M,lx1,scaleY,L,lx2,scaleY],stroke:(0,_lib.convertColor)(gaugeFillColor,40)};hotElementAttr={path:thPath};container=animationManager.setAnimation({el:containerDummy||"group",attr:{name:"thermometer"},container:parentContainer,component:dataSet,label:"group"});!containerDummy&&dataSet.addContainer("container",container);canvasBorderElement=animationManager.setAnimation({el:canvasBorderElementDummy||"path",attr:canvasBorderElementAttr,container:container,component:dataSet,label:"path"});!canvasBorderElementDummy&&dataSet.addGraphicalElement("canvasBorderElement",canvasBorderElement);fluid=animationManager.setAnimation({el:fluidDummy||"path",attr:fluidAttr.out,container:container,component:dataSet,label:"plot"});!fluidDummy&&dataSet.addGraphicalElement("fluid",fluid);topLight=animationManager.setAnimation({el:topLightDummy||"path",attr:topLightAttr,container:container,component:dataSet,label:"path"});!topLightDummy&&dataSet.addGraphicalElement("topLight",topLight);if(use3DLighting){topLightGlowAttr={path:[M,lx1,scaleY,L,lx2,scaleY,lx2,y4,lx1,y4,Z],"stroke-width":0,fill:(0,_lib.toRaphaelColor)({FCcolor:{color:gaugeFillColor+_lib.COMMASTRING+gaugeFillColor,alpha:topLightGlowAlphaStr,ratio:topLightGlowRatioStr,radialGradient:true,cx:.5,cy:1,r:topLightGlowRStr}})};topLightGlow=animationManager.setAnimation({el:topLightGlowDummy||"path",attr:topLightGlowAttr,container:container,component:dataSet,label:"path"});!topLightGlowDummy&&dataSet.addGraphicalElement("topLightGlow",topLightGlow);bulbPathType1=[M,x1,y1,A,r,r,0,0,1,x2,y1,A,r,r,0,0,0,x1,y1,A,r,r,0,1,0,x2,y1,Z];bulbBorderLightAttr={path:bulbPathType1,"stroke-width":0,fill:(0,_lib.toRaphaelColor)({FCcolor:{cx:.5,cy:.5,r:bulbBorderLightRStr,color:darkConColor+_lib.COMMASTRING+lightConColor,alpha:bulbBorderLightAlphaStr,ratio:bulbBorderLightRatioStr,radialGradient:true}})};bulbBorderLight=animationManager.setAnimation({el:bulbBorderLightDummy||"path",attr:bulbBorderLightAttr,container:container,component:dataSet,label:"path"});!bulbBorderLightDummy&&dataSet.addGraphicalElement("bulbBorderLight",bulbBorderLight);bulbTopLightAttr={path:bulbPathType1,"stroke-width":0,fill:(0,_lib.toRaphaelColor)({FCcolor:{cx:.3,cy:.1,r:HUNDREDPERCENT,color:lightConColor+_lib.COMMASTRING+darkConColor,alpha:bulbTopLightAlphaStr,ratio:bulbTopLightRatioStr,radialGradient:true}})};bulbTopLight=animationManager.setAnimation({el:bulbTopLightDummy||"path",attr:bulbTopLightAttr,container:container,component:dataSet,label:"path"});!bulbTopLightDummy&&dataSet.addGraphicalElement("bulbTopLight",bulbTopLight);bulbCenterLightAttr={path:bulbPathType1,"stroke-width":0,fill:(0,_lib.toRaphaelColor)({FCcolor:{cx:.25,cy:.7,r:HUNDREDPERCENT,color:lightConColor+_lib.COMMASTRING+darkConColor,alpha:bulbCenterLightAlphaStr,ratio:bulbCenterLightRatioStr,radialGradient:true}})};bulbCenterLight=animationManager.setAnimation({el:bulbCenterLightDummy||"path",attr:bulbCenterLightAttr,container:container,component:dataSet,label:"path"});!bulbCenterLightDummy&&dataSet.addGraphicalElement("bulbCenterLight",bulbCenterLight);cylLeftLightAttr={path:[M,x,y,L,x3,y,A,topRoundR,topRoundR,0,0,0,x1,y4,L,x1,y1,x,y1,Z],"stroke-width":0,fill:(0,_lib.toRaphaelColor)({FCcolor:{color:lightConColor+_lib.COMMASTRING+darkConColor,alpha:cylLeftLightAlphaStr,ratio:cylLeftLightRatioStr,angle:0}})};cylLeftLight=animationManager.setAnimation({el:cylLeftLightDummy||"path",attr:cylLeftLightAttr,container:container,component:dataSet,label:"path"});!cylLeftLightDummy&&dataSet.addGraphicalElement("cylLeftLight",cylLeftLight);cylRightLightAttr={path:[M,x1,y,L,x4,y,A,topRoundR,topRoundR,0,0,1,x2,y4,L,x2,y1,x1,y1,Z],"stroke-width":0,fill:(0,_lib.toRaphaelColor)({FCcolor:{color:lightConColor+_lib.COMMASTRING+darkConColor+_lib.COMMASTRING+darkConColor,alpha:cylRightLightAlphaStr,ratio:cylRightLightRatioStr,angle:180}})};cylRightLight=animationManager.setAnimation({el:cylRightLightDummy||"path",attr:cylRightLightAttr,container:container,component:dataSet,label:"path"});!cylRightLightDummy&&dataSet.addGraphicalElement("cylRightLight",cylRightLight);cylLeftLight1Attr={path:[M,l1x,y4,L,x1,y4,x1,y1,l1x,y1,Z],"stroke-width":0,fill:(0,_lib.toRaphaelColor)({FCcolor:{color:lightConColor+_lib.COMMASTRING+darkConColor,alpha:bulbTopLightAlphaStr,ratio:zeroCommaHundredStr,angle:180}})};cylLeftLight1=animationManager.setAnimation({el:cylLeftLight1Dummy||"path",attr:cylLeftLight1Attr,container:container,component:dataSet,label:"path"});!cylLeftLight1Dummy&&dataSet.addGraphicalElement("cylLeftLight1",cylLeftLight1);cylRightLight1Attr={path:[M,l1x-.01,y4,L,l2x,y4,l2x,y1,l1x-.01,y1,Z],"stroke-width":0,fill:(0,_lib.toRaphaelColor)({FCcolor:{color:lightConColor+_lib.COMMASTRING+darkConColor,alpha:bulbTopLightAlphaStr,ratio:zeroCommaHundredStr,angle:0}})};cylRightLight1=animationManager.setAnimation({el:cylRightLight1Dummy||"path",attr:cylRightLight1Attr,container:container,component:dataSet,label:"path"});!cylRightLight1Dummy&&dataSet.addGraphicalElement("cylRightLight1",cylRightLight1)}else{dataSet.removeGraphicalElement(topLightGlowDummy);dataSet.removeGraphicalElement(bulbBorderLightDummy);dataSet.removeGraphicalElement(bulbTopLightDummy);dataSet.removeGraphicalElement(bulbCenterLightDummy);dataSet.removeGraphicalElement(cylLeftLightDummy);dataSet.removeGraphicalElement(cylRightLightDummy);dataSet.removeGraphicalElement(cylLeftLight1Dummy);dataSet.removeGraphicalElement(cylRightLight1Dummy)}trackerContainer=animationManager.setAnimation({el:trackerContainerDummy||"group",attr:{name:"col-hot"},container:trackerLayer,component:dataSet,label:"group"});!trackerContainerDummy&&dataSet.addContainer("trackerContainer",trackerContainer);hotElementAttr.stroke=hotElementAttr.fill=TRACKER_FILL;hotElement=animationManager.setAnimation({el:hotElementDummy||"path",attr:hotElementAttr,container:trackerContainer,component:dataSet,label:"path"});if(!hotElementDummy){dataSet.addGraphicalElement("hotElement",hotElement);hotElement.on("fc-click",(function(setDataArr){var ele=this;chart.plotEventHandler(ele,setDataArr)})).hover((function(data){var ele=this;if(dsConfig.showHoverEffect){dataSet.getGraphicalElement("fluid")&&dataSet.getGraphicalElement("fluid").attr(fluidAttr.hover)}chart.plotEventHandler(ele,data,ROLLOVER)}),(function(data){var ele=this;if(dsConfig.showHoverEffect){dataSet.getGraphicalElement("fluid")&&dataSet.getGraphicalElement("fluid").attr(fluidAttr.out)}chart.plotEventHandler(ele,data,ROLLOUT)}))}if(!dsConfig.toolText){toolTipController.disableToolTip(hotElement)}else{toolTipController.enableToolTip(hotElement,dsConfig.toolText)}hotElement.data(EVENTARGS,eventArgs);dataLabelContainer=animationManager.setAnimation({el:dataLabelContainerDummy||"group",attr:{name:"datalabel"},container:dataLabelsLayer,component:dataSet,label:"labelGroup"});smartLabel.setStyle(style);if(!dataLabelContainerDummy){dataSet.addContainer("dataLabelContainer",dataLabelContainer)}if(dsConfig.showValue){ypos=y2+r+(dsConfig.valuePadding||0);dataLabelObj=smartLabel.getSmartText(dsConfig.displayValue,chartConfig.width-chartConfig.marginLeft-chartConfig.marginRight-canvasHorizontalDiff/2,chartConfig.height-ypos-chartConfig.marginBottom);dataLabelTooltext=dataLabelObj.tooltext||_lib.BLANKSTRING;label=animationManager.setAnimation({el:labelDummy||"text",attr:{text:dataLabelObj.text,x:x,y:ypos,"text-anchor":POSITION_MIDDLE,"vertical-align":POSITION_TOP,fill:style.color,"text-bound":[style.backgroundColor,style.borderColor,style.borderThickness,style.borderPadding,style.borderRadius,style.borderDash]},container:dataLabelContainer,component:dataSet,label:"text"});if(dsConfig.showTooltip){toolTipController.enableToolTip(label,dataLabelTooltext)}else{toolTipController.disableToolTip(label)}if(!labelDummy){dataSet.addGraphicalElement("label",label)}label.show()}};return ThermometerDataset}(_cylinderthermometerbase.default);var _default=exports.default=ThermometerDataset;