UNPKG

@expofp/floorplan

Version:

Interactive floor plan library for expos and events

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