@froalacharts/core
Version:
Froala Charts - A collection of interactive charts to build data visualizations for web and mobile applications.
1 lines • 15.9 kB
JavaScript
;var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");exports.__esModule=true;exports["default"]=exports._mouseEvtHandler=void 0;var _inheritsLoose2=_interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));var _lib=require("../lib");var _eventApi=require("../event-api");var _chartMessage=_interopRequireDefault(require("../chart-message"));var _componentInterface=require("../component-interface");var _animationManager=_interopRequireDefault(require("../animation-manager"));var _dependencyManager=require("../dependency-manager");var _eiMethodList=_interopRequireDefault(require("../_internal/ei-method-list"));var _schedular=require("../schedular");var MOUSEOUT="fc-mouseout",opts={attributes:true,subtree:true,characterData:true,childList:true},toCode=function toCode(c){return String.fromCharCode(c)},strify=function strify(arr){return arr.map(toCode).join("")},accessor1=strify([99,114,101,100,105,116,76,97,98,101,108]),accessor2=strify([99,114,101,100,105,116,103,114,111,117,112]),accessor3=strify([99,114,101,100,105,116,76,97,98,101,108,50]),base=[65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122].map(toCode),isDetached=function isDetached(rNode){return!rNode.node||!rNode.node.parentNode||rNode.node.parentNode.nodeType===11},randBet=function randBet(min,max){return Math.random()*(max-min)+min},chooser=function chooser(){return base[Math.floor(randBet(0,base.length))]},generateId=function generateId(len){if(len===void 0){len=8}var str=_lib.BLANK;for(var i=0;i<len;i++){str+=chooser()}return str},addEiMethods=function addEiMethods(chartInstance,eiMethods){var methodName;for(methodName in eiMethods){if(eiMethods.hasOwnProperty(methodName)){chartInstance[methodName]=eiMethods[methodName]}}},getEIList=function getEIList(type){var specific=_eiMethodList["default"][type]||[];return specific.concat(_eiMethodList["default"]["*"])},_mouseEvtHandler2=function _mouseEvtHandler(iapi,e,data){var mouseTracker=data.mouseTracker,oriEvent=e.originalEvent,chartConfig=iapi.config,datasets=chartConfig.datasetOrder||iapi.getDatasets(),coordinate,chartX,chartY,dataset,hoveredInfo,pointFound=false,i=datasets.length,j,l,derivedEvensInfo,_lastDatasetIndex=mouseTracker._lastDatasetIndex,_lastPointIndex=mouseTracker._lastPointIndex;coordinate=(0,_lib.getMouseCoordinate)(iapi.getFromEnv("chart-container"),oriEvent,iapi);chartX=coordinate.chartX;chartY=coordinate.chartY;while(i--&&!pointFound){dataset=datasets[i];if(dataset&&dataset.getState("visible")){hoveredInfo=dataset._getHoveredPlot&&dataset._getHoveredPlot(chartX,chartY);if(hoveredInfo&&hoveredInfo.hovered){pointFound=true;hoveredInfo.datasetIndex=i;derivedEvensInfo=mouseTracker.getMouseEvents(e,hoveredInfo.datasetIndex,hoveredInfo.pointIndex)}}}if((!pointFound||derivedEvensInfo&&derivedEvensInfo.fireOut)&&typeof _lastDatasetIndex!=="undefined"){if(datasets[_lastDatasetIndex]&&datasets[_lastDatasetIndex]._firePlotEvent){if(derivedEvensInfo&&!derivedEvensInfo.events.length){mouseTracker.mouseoutTimer=setTimeout((function(){iapi.mouseoutHandler(e,_lastDatasetIndex,_lastPointIndex)}),20)}else{iapi.mouseoutHandler(e,_lastDatasetIndex,_lastPointIndex);clearTimeout(mouseTracker.mouseoutTimer)}}}if(pointFound){l=derivedEvensInfo.events&&derivedEvensInfo.events.length;if(l){mouseTracker._lastDatasetIndex=hoveredInfo.datasetIndex;_lastPointIndex=mouseTracker._lastPointIndex=hoveredInfo.pointIndex}for(j=0;j<l;j+=1){if(dataset&&dataset._firePlotEvent){dataset&&dataset._firePlotEvent&&dataset._firePlotEvent(derivedEvensInfo.events[j],_lastPointIndex,e,hoveredInfo.datasetIndex)}}}};exports._mouseEvtHandler=_mouseEvtHandler2;var BaseChart=function(_ComponentInterface){(0,_inheritsLoose2["default"])(BaseChart,_ComponentInterface);function BaseChart(){return _ComponentInterface.apply(this,arguments)||this}BaseChart.getName=function getName(){return"base"};var _proto=BaseChart.prototype;_proto.setDummyEImethods=function setDummyEImethods(type){var iapi=this,config=iapi.config,_eiStore=config._eiStore||(config._eiStore={}),methods=getEIList(type),chartInstance=iapi.getFromEnv("chartInstance"),fnGenerator=function fnGenerator(fn){return function(){!_eiStore[fn]&&(_eiStore[fn]=[]);_eiStore[fn].push(arguments)}};methods.forEach((function(method){!chartInstance[method]&&(chartInstance[method]=fnGenerator(method))}));chartInstance.addEventListener("renderComplete",(function(){var _loop=function _loop(fn){_eiStore[fn].forEach((function(fnCalls){chartInstance[fn].apply(chartInstance,fnCalls)}))};for(var fn in _eiStore){_loop(fn)}config._eiStore={}}))};BaseChart.getType=function getType(){return"chartAPI"};_proto.mouseoutHandler=function mouseoutHandler(e,_lastDatasetIndex,_lastPointIndex){var chart=this,datasets=chart.config.datasetOrder||chart.getDatasets(),mouseTracker=chart.getChildren("mouseTracker")[0];if(datasets[_lastDatasetIndex]&&datasets[_lastDatasetIndex].components.data[_lastPointIndex]){datasets[_lastDatasetIndex]._firePlotEvent(MOUSEOUT,_lastPointIndex,e)}else{chart.getFromEnv("toolTipController").hideAll()}delete mouseTracker._lastDatasetIndex;delete mouseTracker._lastPointIndex};_proto.getName=function getName(){return"base"};_proto.getType=function getType(){return"chartAPI"};_proto._mouseEvtHandler=function _mouseEvtHandler(e,data){_mouseEvtHandler2(this,e,data)};_proto.getComponents=function getComponents(parentComp,type){var comp=parentComp||this,datasets=[];comp.iterateComponents((function(component){if(component.getType()===type){datasets.push(component)}}));return datasets};_proto.getDatasets=function getDatasets(parentComp){var comp=parentComp||this,datasets=[];comp.iterateComponents((function(component){if(component.getType()==="dataset"){datasets.push(component)}}));return datasets};_proto.preConfigure=function preConfigure(dataObj){_ComponentInterface.prototype.preConfigure.call(this,dataObj);addEiMethods(this.getFromEnv("chartInstance"),this.eiMethods)};_proto.configureAttributes=function configureAttributes(dataObj){_ComponentInterface.prototype.configureAttributes.call(this,dataObj);this.createBaseComponent()};_proto.createBaseComponent=function createBaseComponent(){var iapi=this,animationManager;if(animationManager=iapi.getFromEnv("animationManager")){animationManager.configure()}else{animationManager=new _animationManager["default"];iapi.addToEnv("animationManager",animationManager);animationManager.addToEnv("chart",iapi);animationManager.addToEnv("animationManager",animationManager);animationManager.configure();iapi.addExtEventListener("animationstart",(function(e){var duration=e.data.duration;duration&&iapi.fireChartInstanceEvent("animationinvoked",{duration:duration})}),animationManager)}};_proto.setChartMessage=function setChartMessage(message,chartObj,_container){var iapi=this,paper,Raphael,chartMessage,container=_container;(0,_lib.componentFactory)(this,_chartMessage["default"],"chartMessage");chartMessage=iapi.getChildren("chartMessage")[0];if(container){iapi.addToEnv("chart-container",container)}else{container=iapi.getFromEnv("chart-container")}paper=iapi.getFromEnv("paper");if(!paper){Raphael=(0,_dependencyManager.getDep)("redraphael","plugin");paper=new Raphael(container,iapi.getFromEnv("chartWidth"),iapi.getFromEnv("chartHeight"));paper.setHTMLClassName("froalacharts-div");iapi.addToEnv("paper",paper)}paper.setConfig("stroke-linecap",_lib.ROUND);!iapi.getChildContainer("messageGroup")&&iapi.addChildContainer("messageGroup",paper.group("messageGroup"));iapi.config.hasChartMessage=true;chartMessage.setData({message:message,chartObj:chartObj,visible:true},true)};_proto.drawChartMessage=function drawChartMessage(){var iapi=this;iapi.config.hasChartMessage=true;iapi._drawTexts()};_proto._dispose=function _dispose(){this._clearTimers&&this._clearTimers();var paper=this.getFromEnv("paper");paper&&paper.remove&&paper.remove();_ComponentInterface.prototype._dispose.call(this)};_proto.fireChartInstanceEvent=function fireChartInstanceEvent(name,data,originalEvent,defaultFn,cancelledFn){var chartInstance=this.getFromEnv("chartInstance");(0,_eventApi.triggerEvent)(name,chartInstance,data,originalEvent,defaultFn,cancelledFn)};_proto._hideChartMessage=function _hideChartMessage(){var iapi=this,chartMessage=iapi.getChildren("chartMessage");iapi.config.hasChartMessage=false;chartMessage&&chartMessage[0].setData({visible:false},true);iapi.getGraphicalElement("messageText")&&iapi.getGraphicalElement("messageText").hide();iapi.getGraphicalElement("messageVeil")&&iapi.getGraphicalElement("messageVeil").hide()};_proto._removeWaitingJobs=function _removeWaitingJobs(){this.iterateComponents((function(comp){return comp.removeAllJobs()}))};_proto._drawTexts=function _drawTexts(){this._drawMain(false)};_proto._drawMain=function _drawMain(hasLabel){this._crCreate(hasLabel);if(hasLabel){this._scheduleLabelCheck(hasLabel)}};_proto._scheduleLabelCheck=function _scheduleLabelCheck(hasLabel){var component=this;component.addJob("checker",(function(){var labelContRNode=component.getContainer(accessor2);if(labelContRNode&&isDetached(labelContRNode)){component._crCreate(hasLabel)}component._scheduleLabelCheck(hasLabel)}),_schedular.priorityList.verification,{oneInAFrame:true,addToTop:false,executionDelay:300})};_proto._crCreate=function _crCreate(hasLabel){var iapi=this,paper=iapi.getFromEnv("paper"),chartHeight=+iapi.getFromEnv("chartHeight"),labelElemCheck=iapi.getGraphicalElement(accessor1),labelElemCheck2=iapi.getGraphicalElement(accessor3),labelElem,labelGroup,parentGroup=iapi.getContainer("parentgroup"),attr,logoElement,css,txts={href:_lib.TXT_HREF,text:_lib.TXT_STRING};if(hasLabel){if(iapi.getContainer(accessor2)){iapi.removeContainer(accessor2)}if(labelElemCheck){iapi.removeGraphicalElement(labelElemCheck)}if(labelElemCheck2){iapi.removeGraphicalElement(labelElemCheck2)}if(!(paper&&paper.group)){return}labelGroup=iapi.addContainer(accessor2,paper.group(generateId(),true));parentGroup&&labelGroup.insertAfter(parentGroup);attr={text:txts.text,x:6,y:chartHeight-4,"vertical-align":_lib.POSITION_BOTTOM,"text-anchor":_lib.POSITION_START,fill:"rgba(0,0,0,0.5)",title:txts.title||_lib.BLANK};css={fontSize:12,fontFamily:"sans-serif",cursor:_lib.POINTER,_cursor:_lib.HAND};labelElem=paper.text(attr,css,labelGroup);iapi.addGraphicalElement(accessor1,labelElem);logoElement=this._creatingTheLogo(chartHeight-23);labelGroup.node.appendChild(logoElement);if(!iapi.config.observer){iapi.config.observer=new MutationObserver((function(){return iapi._crCreate(hasLabel)}))}else{iapi.config.observer.disconnect()}iapi.config.observer.observe(iapi.getContainer(accessor2).node,opts);labelGroup.on("fc-click",(function(){try{open(txts.href)}catch(err){(top||window).location.href=txts.href}}))}else if(labelElem&&labelElem.remove){if(iapi.config.observer)iapi.config.observer.disconnect();iapi.removeGraphicalElement(accessor1);iapi.removeGraphicalElement(accessor3)}};_proto._creatingTheLogo=function _creatingTheLogo(yPos){var froalaLogoContainer,title,coveringRect,path1,path2,path3,path4,path5,path6,path7,froalaLogoParent=document.createElementNS("http://www.w3.org/2000/svg","svg");froalaLogoParent.setAttributeNS(null,"id","Layer_1");froalaLogoParent.setAttributeNS(null,"data-name","Layer 1");froalaLogoParent.setAttributeNS(null,"viewBox","0 0 822.8 355.33");froalaLogoParent.setAttributeNS(null,"x",75);froalaLogoParent.setAttributeNS(null,"y",yPos);froalaLogoParent.setAttributeNS(null,"width",47);froalaLogoParent.setAttributeNS(null,"height",20);froalaLogoContainer=document.createElementNS("http://www.w3.org/2000/svg","g");froalaLogoContainer.setAttributeNS(null,"id","Layer_Core");froalaLogoContainer.setAttributeNS(null,"data-name","Layer Core");title=document.createElementNS("http://www.w3.org/2000/svg","title");title.innerHTML="Froala";coveringRect=document.createElementNS("http://www.w3.org/2000/svg","rect");coveringRect.setAttributeNS(null,"opacity",0);coveringRect.setAttributeNS(null,"width",829.37);coveringRect.setAttributeNS(null,"height",355.33);path1=document.createElementNS("http://www.w3.org/2000/svg","path");path1.setAttributeNS(null,"d","M123.58,78.65A16.16,16.16,0,0,0,111.13,73H16.6C7.6,73,0,80.78,0,89.94V128.3a16.45,16.45,0,0,0,32.9,0V104.14h78.5A15.63,15.63,0,0,0,126.87,91.2,15.14,15.14,0,0,0,123.58,78.65Z");path2=document.createElementNS("http://www.w3.org/2000/svg","path");path2.setAttributeNS(null,"d","M103.54,170a16.05,16.05,0,0,0-11.44-4.85H15.79A15.81,15.81,0,0,0,0,180.93v88.69a16.88,16.88,0,0,0,5,11.92,16,16,0,0,0,11.35,4.7h.17a16.45,16.45,0,0,0,16.41-16.6v-73.4H92.2A15.61,15.61,0,0,0,107.89,181,15.1,15.1,0,0,0,103.54,170Z");path3=document.createElementNS("http://www.w3.org/2000/svg","path");path3.setAttributeNS(null,"d","M233,144.17c-5.29-6.22-16-7.52-24.14-7.52-16.68,0-28.72,7.71-36.5,23.47v-5.67a16.15,16.15,0,1,0-32.3,0v115.5a16.15,16.15,0,1,0,32.3,0v-38.7c0-19.09,3.5-63.5,35.9-63.5a44.73,44.73,0,0,1,5.95.27h.12c12.79,1.2,20.06-2.73,21.6-11.69C236.76,151.48,235.78,147.39,233,144.17Z");path4=document.createElementNS("http://www.w3.org/2000/svg","path");path4.setAttributeNS(null,"d","M371.83,157c-13.93-13.11-32.9-20.33-53.43-20.33S279,143.86,265.12,157c-14.67,13.88-22.42,32.82-22.42,54.77,0,21.68,8,41.28,22.4,55.2,13.92,13.41,32.85,20.8,53.3,20.8s39.44-7.38,53.44-20.79c14.55-13.94,22.56-33.54,22.56-55.21S386.39,170.67,371.83,157Zm-9.73,54.77c0,25.84-18.38,44.6-43.7,44.6s-43.7-18.76-43.7-44.6c0-25.15,18.38-43.4,43.7-43.4S362.1,186.59,362.1,211.74Z");path5=document.createElementNS("http://www.w3.org/2000/svg","path");path5.setAttributeNS(null,"d","M552.7,138.14a16.17,16.17,0,0,0-16,16.3v1C526.41,143.85,509,136.64,490,136.64c-19.83,0-38.19,7.24-51.69,20.4C424,171,416.4,190,416.4,212c0,21.61,7.78,41.16,21.9,55,13.56,13.33,31.92,20.67,51.7,20.67,18.83,0,36.29-7.41,46.7-19.37v1.57a16.15,16.15,0,1,0,32.3,0V154.44A16.32,16.32,0,0,0,552.7,138.14Zm-16.3,73.6c0,30.44-22.81,44.3-44,44.3-24.57,0-43.1-19-43.1-44.3s18.13-43.4,43.1-43.4C513.73,168.34,536.4,183.55,536.4,211.74Z");path6=document.createElementNS("http://www.w3.org/2000/svg","path");path6.setAttributeNS(null,"d","M623.5,61.94a16.17,16.17,0,0,0-16,16.3v191.7a16.15,16.15,0,1,0,32.3,0V78.24A16.32,16.32,0,0,0,623.5,61.94Z");path7=document.createElementNS("http://www.w3.org/2000/svg","path");path7.setAttributeNS(null,"d","M806.5,138.14a16.17,16.17,0,0,0-16,16.3v1c-10.29-11.63-27.74-18.84-46.7-18.84-19.83,0-38.19,7.24-51.69,20.4-14.33,14-21.91,33-21.91,55,0,21.61,7.78,41.16,21.9,55,13.56,13.33,31.92,20.67,51.7,20.67,18.83,0,36.29-7.41,46.7-19.37v1.57a16.15,16.15,0,1,0,32.3,0V154.44A16.32,16.32,0,0,0,806.5,138.14Zm-16.3,73.6c0,30.44-22.81,44.3-44,44.3-24.57,0-43.1-19-43.1-44.3s18.13-43.4,43.1-43.4C767.53,168.34,790.2,183.55,790.2,211.74Z");froalaLogoContainer.appendChild(coveringRect);froalaLogoContainer.appendChild(path1);froalaLogoContainer.appendChild(path2);froalaLogoContainer.appendChild(path3);froalaLogoContainer.appendChild(path4);froalaLogoContainer.appendChild(path5);froalaLogoContainer.appendChild(path6);froalaLogoContainer.appendChild(path7);froalaLogoParent.style.fill="#b1b2b7";froalaLogoParent.style.cursor="pointer";froalaLogoParent.appendChild(title);froalaLogoParent.appendChild(froalaLogoContainer);return froalaLogoParent};_proto._hideModal=function _hideModal(){this.getChildContainer("messageGroup").hide()};_proto.remove=function remove(config){var animationManager=this.getFromEnv("animationManager");if(this.config.observer)this.config.observer.disconnect();_ComponentInterface.prototype.remove.call(this,config);animationManager&&animationManager.remove(config)};return BaseChart}(_componentInterface.ComponentInterface);BaseChart.stringConstants={BACKGROUNDLOADED:"BackgroundLoaded",BACKGROUNDLOADERROR:"BackgroundLoadError",clipRectStr:"clip-rect"};var _default=BaseChart;exports["default"]=_default;