@expofp/floorplan
Version:
Interactive floor plan library for expos and events
3 lines (2 loc) • 3.48 kB
JavaScript
import{Rect as d}from"@expofp/geometry";import{update as L}from"@expofp/renderer";import{reaction as u}from"mobx";import{FONT_WEIGHT_PRIMARY_BOOTH as g,FONT_WEIGHT_PRIMARY_SPECIAL as y}from"../../../../constants";import{createTextDef as S,SHAPE_DOT_CSS_PX as m}from"../../../../engine/defs";import{loadCustomFontsUrls as F}from"../../../../engine/fonts";import{getQuarterTurns as R,getRollValue as x,rotateRectByQuarters as D,rotateTextDefByQuarters as T,shouldFlip as _}from"../../../../engine/update-def";import{heatmapStore as I,layersStore as O,uiState as b}from"../../../../store";import{SpecialBooth as B}from"../../../../store/BoothStore";import P from"../../../../tools/settings";import{getFont as v}from"./canvases";import{BoothLabelDrawer as C,getFontUrlByWeight as M,getMinZoomFactorForDot as N}from"./config-booth-labels";import{LABEL_MARGIN_FRACTION as f}from"./label-inset.js";import z from"./TextFitter";const A=[18,16,14,12,10,7],E=14;export default function w(i){if(!(!(i instanceof B)||i.noLabels))return new BoothLabelSpecialDrawer(i)}export class BoothLabelSpecialDrawer extends C{constructor(t){super(t),this.steps=[],this.text="";const s=this.booth.rect,e=Number(getComputedStyle(document.body).getPropertyValue(y))||Number(getComputedStyle(document.body).getPropertyValue(g))||500,r=M(e,F()),o=s.expand({x:-(s.size.width*f+this.padding),y:-(s.size.height*f+this.padding)});this.setText(),this.canvasRect=new d(o.center,o.size,t.rotate,t.elevation),this.setFactors(this.text),this.labelIsVertical=Math.abs(Math.abs(t.rotate)-Math.PI/2)<.01,this.fontSizes=[this.steps,[]],this.minZoomDotVisible=N(this.steps.map(a=>a.scaleFactor)),this.shapeLabel=S([{text:this.text,color:t.labelColor||P.boothLabelColor,fontUrl:r,fontSize:0}],new d(o.center,o.size,t.rotate,t.elevation),[this.padding,this.padding],{horizontal:"center",text:"center",vertical:"center"}),this.shapeLabel.onScale=({pixelSize:a})=>this.layOutLabel(a),this.getShapeDot(),u(()=>O.layersLoaded&&this.booth.skipDim===!0,a=>{this.shapeLabel.dim=a?0:void 0,this.shapeDot.dim=a?0:void 0,L(this.shapeLabel,this.shapeDot)}),u(()=>b.mapSettings,({roll:a})=>{x(a??0)&&(this.shapeLabel.onRoll=({roll:l,pixelSize:c})=>{const h=this.shapeLabel.bounds.rotation;if(this.labelIsVertical)return _(l,h)?(this.shapeLabel.bounds.rotate(-2*h,this.shapeLabel.bounds),[this.shapeLabel,this.shapeDot]):void 0;const n=R(l,h);if(n===0)return;const{size:p}=this.canvasRect;return this.shapeLabel=T(this.shapeLabel,n),p.x!==p.y&&!this.shapeLabel.hidden&&(this.canvasRect=D(this.canvasRect,n),this.setFactors(this.text),this.layOutLabel(c),this.layOutDot(c)),[this.shapeLabel,this.shapeDot]})},{fireImmediately:!0})}getShape(){return[this.shapeLabel,this.shapeDot]}layOutLabel(t){const s=this.steps.find(e=>e.scaleFactor<1/t);return s?(this.shapeLabel.lines[0].fontSize=s.value*t,this.shapeLabel.lines[0].text=s.lines.join(`
`),this.shapeLabel.padding=[this.paddingScaled[0]*t+this.padding,this.paddingScaled[1]*t+this.padding],[this.shapeLabel]):(this.shapeLabel.lines[0].fontSize=0,[this.shapeLabel])}layOutDot(t){const s=this.steps.find(r=>r.scaleFactor<1/t),e=this.shapeDot.bounds;return e.scale({x:m*t/e.size.x,y:m*t/e.size.y},e.center,e),this.shapeDot.hidden=!!s,[this.shapeDot]}setFactors(t){this.steps=new z(v,A,E).getStepsForRect(t,this.canvasRect.size.x,this.canvasRect.size.y)}setText(){const t=this.booth.title||this.booth.name,e=`Clicks: ${I.getTotalClicksByBooth(this.booth)}`;this.text=b.heatmap?`${t} - ${e}`:t}}