@expofp/floorplan
Version:
Interactive floor plan library for expos and events
2 lines (1 loc) • 5.79 kB
JavaScript
import{Box as v,degToRad as A,radToDeg as z}from"@expofp/geometry";import D from"color";import*as F from"d3-selection";import{autorun as M}from"mobx";import E from"../../data";import{getLayerSvg as O,getTrianglesFromFpPaths as T}from"../../data/svg";import{getNextId as U}from"../../tools/id";import B from"../../tools/logger";import N from"../../tools/settings";import{generateUniqueSlug as W}from"../../tools/slug";import{sortByName as V}from"../../utils";import{areLayersEnabled as $}from"../../utils/areLayersEnabled";import{getStorage as P,saveStorage as G}from"../../utils/entity-storage";import{extractMetaFromString as H}from"../../utils/extractMetaFromString";import{RegularBooth as x,SpecialBooth as L}from"../BoothStore";import{Exhibitor as X}from"../ExhibitorStore";import{uiState as j}from"../index";const C=new Map,k=[];export function iniAllBooths(t){C.clear(),k.length=0;const d=parseInt(_("copy_exh"));for(const i of E.booths||[]){const{text:l,meta:c}=H(i.name),o=i.special?new L:new x;Object.assign(o,i),o.meta=c,o.slug=W(o.name),C.set(o.name.toLowerCase(),o),J(o);const m=o;m.exhibitors=[];for(const u of i.exhibitors){const b=t.exhibitorStore.exhibitorById.get(u);b&&(m.exhibitors.push(b),d&&R(b,m,d),b.booths.push(m))}!i.exhibitors.length&&d&&R(null,m,d),o.schedule=t.eventStore.eventItems.filter(u=>u.boothId===o.id),o.name=l,k.push(o)}k.sort((i,l)=>i.name.localeCompare(l.name,void 0,{sensitivity:"base",numeric:!0}));for(const i of t.exhibitorStore.exhibitors)V(i.booths);t.boothStore.booths=k,B.log("initBooths",t.boothStore.booths.length),q(t)}function q(t){const l=(P("bookmarked").booths||[]).filter(c=>{const o=t.boothStore.boothById.get(c);return o&&o.exhibitors.length===0});t.boothStore.replaceBookmarked(l),M(()=>{const c=P("bookmarked"),o=t.boothStore.booths.filter(m=>m.exhibitors.length===0&&m.bookmarkedDirectly).map(m=>m.id);G("bookmarked",{exhibitors:c.exhibitors,events:c.events,speakers:c.speakers,booths:o})})}export default function Q(t,d){const i=d.name,{boothStore:l,layerStore:c}=t,o=[],m=$(),u=F.select(O(d)).selectAll(`[data-layer='${i}'] > [data-tagname='efp-booth'], [data-layer='${i}'] > g[id^=b], [data-layer='${i}'] > rect[id^=b]`).nodes();for(const r of u){const S=r.closest("svg > [data-layer]").attributes["data-layer"]?.value;if(!S)continue;let a,I=!1;r.tagName==="rect"?a=r:(a=Array.from(r.children).find(h=>h.tagName==="rect"),I=a===r.firstElementChild);const g=(r.id||r.getAttribute("data-name")).substring(1).toLowerCase();let e=C.get(g),n=e instanceof x?e:null,w=e instanceof L?e:null;if(e||(B.error("SVG booth rect not found in the event data:",g),e=n=new x,e.id=U(),e.name=g.toUpperCase(),e.slug=W(g),e.error=!0,e.exhibitors=[],C.set(g,e)),o.push(e),e.layer=m?c.layers.find(h=>h.name===S):null,e.borderColor=a?.getAttribute("stroke")||a?.style.stroke||N.boothBorderColor||"#FFFFFF",e.borderWidth=parseFloat(a?.getAttribute("stroke-width")||a?.style.strokeWidth),isNaN(e.borderWidth)&&(e.borderWidth=l.borderWidth),!j.heatmap)e.labelColor=a?.getAttribute("data-label-color");else{const h=t.heatmapStore.getTotalClicksByBooth(e),f=D(t.heatmapStore.getColorByClicks(h));e.labelColor=f.darken(.3).isLight()?"#555":"#fff"}e.rect=a?v.fromSvg(a):null,e.noLabels=!!a?.dataset.nolabel||a?.id.startsWith("no"),n?(n.availColor=r.getAttribute("data-avail-color")||a?.getAttribute("data-avail-color")||n.availColor,n.soldColor=r.getAttribute("data-sold-color")||a?.getAttribute("data-sold-color")||n.soldColor,n.holdColor=r.getAttribute("data-hold-color")||a?.getAttribute("data-hold-color")||n.holdColor,n.size=E.dimensionless?null:n.size||r.getAttribute("data-size"),n.status==="reserved"?n.reserved=!0:n.status==="onhold"&&(n.onHold=!0)):w.color=(parseInt(a.getAttribute("data-poi-type"))>0?a.style?.fill:r.getAttribute("data-color")||a.getAttribute("data-color"))||w.color;const y=a?.getAttribute("transform");if(y){const h=y.match(/translate\(([-0-9.]+) ([-0-9.]+)\) rotate\(([-0-9.]+)\)/);if(h){const s=parseFloat(h[3]);e.rotate=A(s)}else{const s=y.match(/rotate\(([-0-9.]+).*\)/);if(s){const p=parseFloat(s[1]);e.rotate=A(p)}else{const p=y.match(/matrix\(\s*([-0-9.]+)\s*(?:,|\s)\s*([-0-9.]+)\s*(?:,|\s)\s*([-0-9.]+)\s*(?:,|\s)\s*([-0-9.]+)\s*(?:,|\s)\s*([-0-9.]+)\s*(?:,|\s)\s*([-0-9.]+)\s*\)/);p&&(e.rotate=Math.asin(parseFloat(p[2])))}}if(Math.abs(z(e.rotate))>180){e.rotate+=A(90);const s=e.rect;e.rect=new v(s.center.x-s.size.height/2,s.center.y-s.size.width/2,s.size.height,s.size.width)}}if(r.tagName==="g"){e.paths=[],e.pathsWithRect=I;var b=[];for(const h of F.select(r).selectAll("path, rect").nodes())if(h.tagName==="path"){const f=h;if(f.tagName!=="path")continue;const s=parseInt(f.getAttribute("data-index")),p=!!f.getAttribute("data-unblinking");e.paths.push({index:s,color:f.style.fill,unblinking:p}),a||b.push(...T(s,i))}if(b.length){const h=b.flatMap(f=>f.map(s=>({x:s[0],y:s[1]})));e.rect=v.fromPoints(h),e.noLabels=!0}}}for(const r of o)r.rect?r.store=l:(B.error("event data booth not found in SVG:",r.name,r),o.splice(o.indexOf(r),1));return o}function _(t){return new URLSearchParams(window.location.search).get(t)}function R(t,d,i){let l=new X;l.name="EXHIBITOR NAME",l.slug="exhibitor-name",l.booths=[],l=t||l;for(let c=0;c<i;c++){const o={...l,id:Date.now()};d.exhibitors.push(o)}}function J(t){N.EXPO==="cbresupplypartner"&&t instanceof x&&!t.availColor&&t.type&&(t.type.indexOf("Premium A - 2m height restriction Passport")!==-1?t.availColor="#939393":t.type.indexOf("No free-standing")!==-1?t.availColor="#BA3DC8":t.type.endsWith("Passport")?t.availColor="#939393":t.type.startsWith("Premium A - 2m")?t.availColor="#FF9E4E":t.type.startsWith("Premium A - 4m")?t.availColor="#EA4335":t.type.startsWith("Premium B - 2m")?t.availColor="#523BC0":t.type.startsWith("Premium C - 2.4m")&&(t.availColor="#3ECC78"))}