UNPKG

@expofp/floorplan

Version:

Interactive floor plan library for expos and events

3 lines (2 loc) 3.58 kB
import{reaction as u}from"mobx";import{FONT_WEIGHT_PRIMARY_BOOTH as R,FONT_WEIGHT_PRIMARY_SPECIAL as x}from"../../../../constants";import{createTextDef as L,getRollValue as D,getRotation as v,shouldFlip as F,updateRectRotation as y,updateTextDefRotation as T}from"../../../../renderer";import{boothStore as P,heatmapStore as w,layersStore as z,uiState as l}from"../../../../store";import{SpecialBooth as k}from"../../../../store/BoothStore";import C from"../../../../tools/settings";import{getFont as I}from"./canvases";import{BoothLabelDrawer as M,getFontUrlByWeight as B,getMinZoomFactorForDot as W,isDirectionsMode as V}from"./config-booth-labels";import{Rect as d}from"./Rect";import _ from"./TextFitter";const p=new Map;function $(i){let t=p.get(i);if(!t){const s=[18,16,14,12,10,7].map(n=>n*i),o=14*i;t=new _(I,s,o),p.set(i,t),setTimeout(()=>p.delete(i),5e3)}return t}export default function H(i,t){if(!(!(t instanceof k)||t.noLabels))return new N(i,t)}class N extends M{steps;labelIsVertical;text;constructor(t,s){super(t,s);const o=s.borderWidth/2||P.borderWidth/2,n=this.booth.rect,S=Number(getComputedStyle(document.body).getPropertyValue(x))||Number(getComputedStyle(document.body).getPropertyValue(R))||500,g=B(S,this.rendererService.fontUrls),m=n.withPadding(n.w*.05+o,n.h*.05+o);this.setText(),this.canvasRect=d.fromCoreRect(m,s.rotate),this.setFactors(this.text),this.labelIsVertical=Math.abs(Math.abs(s.rotate)-Math.PI/2)<.01,this.fontSizes=[this.steps,[]],this.minZoomDotVisible=W(this.steps.map(e=>e.scaleFactor)),this.shapeLabel=L([{text:this.text,color:s.labelColor||C.boothLabelColor,fontUrl:g,fontSize:0}],d.fromCoreRect(m,s.rotate),[o,o],{horizontal:"center",text:"center",vertical:"center"}),this.getShapeDot(),u(()=>[this.booth.skipDim,l.selectedRoute,z.layersLoaded],()=>{const e=V();this.shapeLabel.dim=e||this.booth.skipDim?!1:void 0,this.shapeDot.dim=e||this.booth.skipDim?!1:void 0,this.rendererService.update(this.shapeLabel,this.shapeDot)});const f=e=>{let a=this.steps.find(r=>r.scaleFactor<1/e);return a?(this.shapeLabel.lines[0].fontSize=a.value/devicePixelRatio*e,this.shapeLabel.lines[0].text=a.lines.join(` `),this.shapeLabel.padding=[this.paddingScaled[0]*e+this.padding,this.paddingScaled[1]*e+this.padding],this.shapeLabel):(this.shapeLabel.lines[0].fontSize=0,this.shapeLabel)},b=e=>{let a=this.steps.find(c=>c.scaleFactor<1/e);const r=this.shapeDot.source.width*e,h=this.shapeDot.source.height*e;return this.shapeDot.bounds=new d({x:this.canvasRect.center.x-r/2,y:this.canvasRect.center.y-h/2},{x:this.canvasRect.center.x+r/2,y:this.canvasRect.center.y+h/2}),this.shapeDot.hidden=!!a,this.shapeDot};this.rendererService.onPtScale(`booth-special-label-${s.id}`,f),this.rendererService.onPtScale(`booth-special-dot-${s.id}`,b),u(()=>l.mapSettings,({roll:e})=>{D(e)&&this.rendererService.onRoll(`booth-special-roll-${s.id}`,a=>{const r=this.shapeLabel.bounds.rotation;if(this.labelIsVertical)F(a,r)&&(this.shapeLabel.bounds.rotation=-r);else{const h=v(a,r);if(h!==void 0){const{size:c}=this.canvasRect;this.shapeLabel=T(this.shapeLabel,h),c.x!==c.y&&!this.shapeLabel.hidden&&(this.canvasRect=y(this.canvasRect,h),this.setFactors(this.text),f(this.rendererService.scale),b(this.rendererService.scale))}}return[this.shapeLabel,this.shapeDot]})})}getShape(){return[this.shapeLabel,this.shapeDot]}setFactors(t){this.steps=$(devicePixelRatio).getStepsForRect(t,this.canvasRect.size.x,this.canvasRect.size.y)}setText(){const t=this.booth.title||this.booth.name,o=`Clicks: ${w.getTotalClicksByBooth(this.booth)}`;this.text=l.heatmap?`${t} - ${o}`:t}}