text: import{SmartRenderer}from'../../../../fc-core/src/component-interface';import{utcMillisecond,utcSecond,utcMinute,utcHour,utcDay,utcWeek,utcMonth,utcYear}from'../../../../fc-utils/src/time-intervals/utc';import{timeMillisecond,timeSecond,timeMinute,timeHour,timeDay,timeWeek,timeMonth,timeYear}from'../../../../fc-utils/src/time-intervals';import{pluckNumber,pluck,BLANKSTRING,extend2,parseUnsafeString,DEFAULT_FT_FONT}from'../../../../fc-core/src/lib';import TimeConverter from'../../../../fc-utils/src/time-converter';const GUTTER_5=5,GUTTER_8=8,GUTTER_14=14,COLOR_858585='#858585',COLOR_5F5F5F='#5f5f5f',M='M',v='v';function isValidUnit(a){return!('year'!==a&&'quarter'!==a&&'month'!==a&&'week'!==a&&'day'!==a&&'hour'!==a&&'minute'!==a&&'second'!==a&&'millisecond'!==a)}function getInterVal(a,b){return'year'===a?b?utcYear:timeYear:'quarter'===a?b?utcMonth:timeMonth:'month'===a?b?utcMonth:timeMonth:'week'===a?b?utcWeek:timeWeek:'day'===a?b?utcDay:timeDay:'hour'===a?b?utcHour:timeHour:'minute'===a?b?utcMinute:timeMinute:'second'===a?b?utcSecond:timeSecond:'millisecond'===a?b?utcMillisecond:timeMillisecond:void 0}function isWithinMarker(a,b,c,d){let e,f,g,h,j=!1,k=d.markerDim,l=a.getLinkedParent().config,m=l.padding,n=m.left,o=m.right,p=m.top,q=m.bottom;for(b+=o-n,c+=q-p,(g=0,h=k.length);g<h;g++)if(b>=k[g].x&&b<=k[g].x+k[g].width&&c>=k[g].y&&c<=k[g].y+k[g].height){j=!0,a.config.previouslyHoveredIndex=d.index,e=k[g];break}return f={pointIndex:d.index,hovered:j,thresholdY:d.thresholdY+l.borderConfig.bottomBorder,pointObj:{hoveredMarkerDim:e,index:j&&g},previouslyHoveredIndex:a.config.previouslyHoveredIndex,component:a},f}class TimeInstanceMarker extends SmartRenderer{__setDefaultConfig(){super.__setDefaultConfig(),this.config.defaultStyle={text:{fill:'#808080',"font-family":DEFAULT_FT_FONT,"font-size":'11px',"font-weight":'normal',"font-style":'normal',"vertical-align":'middle',"text-anchor":'middle'},marker:{fill:'#f8b8b7',opacity:1,stroke:'#666666',"border-radius":2,"stroke-width":'1'}},this.config.toolTipOpacity=.9,this.config.hoveredMarkerIndex=void 0,this.config.hoveredDomainIndex=void 0,this.config.previouslyHoveredIndex=void 0,this.config.hoveredFromOutside=!1,this.config.hoveredMarkerFill='#f2726f',this.config.hoveredLabelFill='#ffffff',this.config.hoveredMarkerRadius='1.5',this.config.valueArr=[],this.config.textArr=[],this.config.styleArr=[],this.config.domainArr=[],this.config.repeatationArr=[],this.config.markerDetails=[]}getHoveredMarker(a,b){let c,d,e=this,f=e.config,g=e.getLinkedParent(),h=g.getTranslation(),j=f.markerDetails;for(a-=h.x,b-=h.y,d=j.length-1;0<=d&&(c=isWithinMarker(e,a,b,j[d]),!c.hovered);d--);return c}setHoverInEffect(a,b,c){let d=this,e=d.getFromEnv('chart');d.setData({hoveredMarkerIndex:a,hoveredDomainIndex:b,hoveredFromOutside:c},!0),e.fireEvent('timeInstanceMarkerHovered',{senderTimeMarker:d,hoveredMarkerIndex:a,hoveredDomainIndex:b,hoveredFromOutside:!0})}setHoverOutEffect(){let a=this,b=a.getFromEnv('chart');a.setData({hoveredMarkerIndex:void 0,hoveredDomainIndex:void 0},!0),b.fireEvent('timeInstanceMarkerHovered',{senderTimeMarker:a,hoveredMarkerIndex:void 0,hoveredDomainIndex:void 0,hoveredFromOutside:!0})}getToolTextConfiguration(a){var b=Math.max;let c,d,e,f=this,g=f.config.toolTipOpacity,h=40,j=46,k=f.getFromEnv('smartLabel'),l={};if(k.setStyle({"font-size":'12px',"font-family":DEFAULT_FT_FONT,"font-weight":'600'}),e=k.getSmartText(a[0]),h+=e.width,j+=e.height,l.toolText=`<div style='opacity:${g};'>
                           <div style='font-weight: 600; margin: 5px;font-size: 12px; color:${COLOR_858585}'>${a[0]}</div>`,k.setStyle({"font-size":'11px',"font-family":DEFAULT_FT_FONT,"font-weight":'normal'}),2<a.length)for(l.toolText+=`</br>`,c=1,d=a.length;c<d;c++)e=k.getSmartText(a[c]),j+=e.height,h=b(h,e.width),l.toolText+=`<div style= 'font-size: 11px; margin: 5px;color:${COLOR_5F5F5F}'>${c}. ${a[c]}</div>`;else 2===a.length&&(l.toolText+=`</br>`,e=k.getSmartText(a[1]),j+=e.height,h=b(h,e.width),l.toolText+=`<div style= 'font-size: 11px; margin: 5px;color:${COLOR_5F5F5F}'>${a[1]}</div>`);return l.toolText+=`</div>`,l.dimensions={width:h,height:j},l}getMarkerAndLabelConfiguration(a,b){let c,d,e=this,f=e.config,g=e.getLinkedParent().config,h=g.padding,i=h.left,j=h.right,k=h.top,l=h.bottom,m=e.config.xScale,n=m.getDomain(),o=f.valueArr[a],p=o.repeat,q=b.text['line-height'];c=m.getRangeValue(o.start),f.markerDetails[a].markerDim=[],f.markerDetails[a].index=a,f.domainArr[a]=[],f.markerDetails[a].thresholdY=q/2,!p&&+o.start>=+n[0]?(f.domainArr[a].push(o.start),f.markerDetails[a].markerDim.push({x:c-q/2-i+j,y:g.canvasTop+g.canvasHeight-q/2-k+l,width:2*q/2,height:2*q/2})):p&&(f.domainArr[a]=d=e.getAllValidDomains(o.start,o.repeat),d.length&&d.forEach(b=>{c=m.getRangeValue(b),f.markerDetails[a].markerDim.push({x:c-q/2-i+j,y:g.canvasTop+g.canvasHeight-q/2-k+l,width:2*q/2,height:2*q/2})}))}getAllValidDomains(a,b){let c=this,d=c.config.xScale,e=d.getDomain(),f=[];if(+a<+e[0]&&0<b.multiplier)for(;+a<+e[0];)a=b.interval.offset(a,b.multiplier);for(;+a<=+e[1];)f.push(a),a=b.interval.offset(a,b.multiplier);return f}configureAttributes(a={}){super.configureAttributes(a);let b,c,d,e,f,g,h,j=this,k=j.config,l=[],m=[],n=j.getFromEnv('isUTC'),o=[],p=j.getFromEnv('getStyleDef'),q=a.timeMarker||[];for(g=0,h=q.length;g<h;g++)q[g].start&&q[g].start!==BLANKSTRING&&(f=pluck(q[g].timeformat,a.defaultFormat),c=n?TimeConverter.utcParser(f):TimeConverter.parser(f),d=c.parse(q[g].start),!!d)&&(b={start:d,startString:q[g].start,timeFormat:f},q[g].repeat&&q[g].repeat.unit&&0!==Math.floor(+q[g].repeat.multiplier)&&isValidUnit(e=q[g].repeat.unit.toLowerCase())&&(b.repeat={interval:getInterVal(e,n),multiplier:('quarter'===e?3:1)*pluckNumber(q[g].repeat.multiplier,1)}),o.push(b),l.push(p(q[g].style)),m.push(pluck(parseUnsafeString(q[g].label),'')));a.xScale&&(k.xScale=a.xScale),k.hoveredMarkerIndex=a.hoveredMarkerIndex,k.hoveredDomainIndex=a.hoveredDomainIndex,k.hoveredFromOutside=a.hoveredFromOutside,a.timeMarker&&(k.valueArr=o,k.styleArr=l,k.textArr=m)}createToolipConfiguration(){let a,b,c,d,e,f,g=this,h=g.config,k=h.markerDetails,l=h.domainArr,m=h.repeatationArr,n=h.valueArr,o=g.getFromEnv('isUTC'),p=[];for(e=0;e<l.length;e++)for(a=l[e],b=n[e].timeFormat,c=o?TimeConverter.utcFormatter(b):TimeConverter.formatter(b),f=0;f<a.length;f++)p=[],d=c.format(a[f]),p=p.concat([d],m[e][f].labels),k[e].markerDim[f].toolTextArr=p}getRepeatationArr(){let a,b,c,d,e,f,g,h=this,k=h.config,l=k.domainArr,m=k.textArr,n=k.markerDetails,o=[];for(f=0;f<l.length;f++)for(d=l[f],o[f]=[],g=0;g<d.length;g++)for(a=f,e=d[g],o[f][g]={domainValue:e,labels:[m[f]],markerDimIndex:g};a+1<l.length;)c=l[a+1].map(a=>+a),-1!==(b=c.indexOf(+e))&&(o[f][g].labels.push(m[a+1]),l[a+1]=l[a+1].filter(a=>+a!=+e),n[a+1].markerDim=n[a+1].markerDim.filter((a,c)=>c!==b)),a++;return o}draw(){let a,b,c,d=this,e=d.config,f=e.valueArr,g=d.getFromEnv('smartLabel'),h=d.getFromEnv('textStyle'),j=e.defaultStyle,k=e.styleArr;for(d.addGraphicalElement({el:'group',container:{id:'thermo',label:'thermo',isParent:!0},component:d,label:'timeMarkerHoverGroup',attr:{name:'time-marker-hover-elem-group'},id:'timeMarker'}),d.addGraphicalElement({el:'group',container:{id:'thermo',label:'thermo',isParent:!0},component:d,label:'timeMarker',attr:{name:'time-marker-group'},id:'timeMarker'}),e.markerDetails=[],(b=0,c=f.length);b<c;b++)e.markerDetails[b]={},a=extend2(extend2(extend2({},{text:h}),j),k[b]),g.setStyle({"font-size":a.text['font-size'],"font-family":a.text['font-family'],"font-weight":a.text['font-weight'],"font-style":a.text['font-style']}),d.getMarkerAndLabelConfiguration(b,a);e.repeatationArr=d.getRepeatationArr(),d.createToolipConfiguration(),d.drawTimeMarkers(),d.drawTimeMarkerLabels()}drawTimeMarkers(){let a,b,c,d,e,f,g=this,h=g.config,k=h.markerDetails,l=g.getLinkedParent().config,m=l.padding,n=h.styleArr,o=g.getFromEnv('textStyle'),p=h.defaultStyle;for(e=0;e<k.length;e++)for(a=k[e].markerDim,d=extend2(extend2(extend2({},{label:o}),p),n[e]),f=0;f<a.length;f++)b=a[f],c=e===h.hoveredMarkerIndex&&f===h.hoveredDomainIndex,c&&(g.addGraphicalElement({el:'path',attr:{path:[M,b.x+b.width/2,b.y+b.height/2,v,-l.canvasHeight],"stroke-width":d.marker['stroke-width'],stroke:h.hoveredMarkerFill,opacity:d.marker.opacity},container:{label:'timeMarkerHoverGroup'},id:'time-instance-marker-path-'+e+f,component:g,label:'path'}),g.addGraphicalElement({el:'circle',attr:{cx:b.x+b.width/2,cy:l.canvasTop+h.hoveredMarkerRadius+m.bottom-m.top,r:h.hoveredMarkerRadius,fill:h.hoveredMarkerFill,opacity:d.marker.opacity},container:{label:'timeMarkerHoverGroup'},id:'time-instance-marker-circle-'+e+f,component:g,label:'path'})),g.addGraphicalElement({el:'rect',attr:{x:b.x,y:b.y,width:b.width,height:b.height,stroke:d.marker.stroke,"stroke-width":d.marker['stroke-width'],r:d.marker['border-radius'],ry:d.marker['border-radius'],fill:c?h.hoveredMarkerFill:d.marker.fill,opacity:d.marker.opacity},container:{label:'timeMarker'},id:'time-instance-marker-rect-'+e+f,component:g,label:'rect'})}drawTimeMarkerLabels(){let a,b,c,d,e,f,g,h,k=this,l=k.config,m=l.markerDetails,n=l.repeatationArr,o=l.styleArr,p=k.getFromEnv('textStyle'),q=l.defaultStyle;for(g=0;g<n.length;g++)for(b=n[g],f=extend2(extend2(extend2({},{label:p}),q),o[g]),h=0;h<b.length;h++)d=b[h],c=g===l.hoveredMarkerIndex&&h===l.hoveredDomainIndex,1<(e=d.labels.length)&&(a=m[g].markerDim[d.markerDimIndex],k.addGraphicalElement({el:'text',attr:{x:a.x+a.width/2,y:a.y+a.height/2,fill:c?l.hoveredLabelFill:f.text.fill,"font-size":f.text['font-size'],"font-weight":f.text['font-weight'],"font-style":f.text['font-style'],"font-family":f.text['font-family'],"text-anchor":f.text['text-anchor'],"vertical-align":f.text['vertical-align'],text:e,opacity:f.marker.opacity},container:{label:'timeMarker'},id:'time-instance-marker-text-'+g+h,component:k,label:'text'}))}getType(){return'timeMarker'}getName(){return'timeInstanceMarker'}}export default TimeInstanceMarker;