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