@expofp/floorplan
Version:
Interactive floor plan library for expos and events
2 lines (1 loc) • 5.84 kB
JavaScript
import R from"color";import*as M from"d3-selection";import{autorun as X}from"mobx";import N from"../../core/Rect";import v from"../../data";import{getLayerSvg as U,getTrianglesFromFpPaths as D}from"../../data/svg";import{getNextId as O}from"../../tools/id";import S from"../../tools/logger";import w from"../../tools/settings";import{generateUniqueSlug as F}from"../../tools/slug";import{sortByName as V}from"../../utils";import{getStorage as P,saveStorage as z}from"../../utils/entity-storage";import{extractMetaFromString as T}from"../../utils/extractMetaFromString";import{RegularBooth as A,SpecialBooth as W}from"../BoothStore";import{Exhibitor as $}from"../ExhibitorStore";import{uiState as G}from"../index";const C=new Map,k=[];export function iniAllBooths(e){C.clear(),k.length=0;const d=parseInt(j("copy_exh"));for(const i of v.booths||[]){const{text:l,meta:h}=T(i.name);i.meta=h;const o=i.special?new W:new A;Object.assign(o,i),o.slug=F(o.name),C.set(o.name.toLowerCase(),o),q(o);const m=o;m.exhibitors=[];for(const p of i.exhibitors){const u=e.exhibitorStore.exhibitorById.get(p);u&&(m.exhibitors.push(u),d&&L(u,m,d),u.booths.push(m))}!i.exhibitors.length&&d&&L(null,m,d),o.schedule=e.eventStore.eventItems.filter(p=>p.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 e.exhibitorStore.exhibitors)V(i.booths);e.boothStore.booths=k,delete v.booths,S.log("initBooths",e.boothStore.booths.length),H(e)}function H(e){const l=(P("bookmarked").booths||[]).filter(h=>{const o=e.boothStore.boothById.get(h);return o&&o.exhibitors.length===0});e.boothStore.replaceBookmarked(l),X(()=>{const h=P("bookmarked"),o=e.boothStore.booths.filter(m=>m.exhibitors.length===0&&m.bookmarkedDirectly).map(m=>m.id);z("bookmarked",{exhibitors:h.exhibitors,events:h.events,speakers:h.speakers,booths:o})})}export default function Y(e,d){const i=d.name,{boothStore:l,layerStore:h}=e,o=[],m=!!window.__fpLayers,p=M.select(U(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 p){const B=r.closest("svg > [data-layer]").attributes["data-layer"]?.value;if(!B)continue;let a,I=!1;r.tagName==="rect"?a=r:(a=Array.from(r.children).find(s=>s.tagName==="rect"),I=a===r.firstElementChild);const g=(r.id||r.getAttribute("data-name")).substring(1).toLowerCase();let t=C.get(g),n=t instanceof A?t:null,E=t instanceof W?t:null;if(t||(S.error("SVG booth rect not found in __data:",g),t=n=new A,t.id=O(),t.name=g.toUpperCase(),t.slug=F(g),t.error=!0,t.exhibitors=[],C.set(g,t)),o.push(t),t.layer=m?h.layers.find(s=>s.name===B):null,t.borderColor=a?.getAttribute("stroke")||a?.style.stroke||w.boothBorderColor||"#FFFFFF",t.borderWidth=parseFloat(a?.getAttribute("stroke-width")||a?.style.strokeWidth),isNaN(t.borderWidth)&&(t.borderWidth=l.borderWidth),!G.heatmap)t.labelColor=a?.getAttribute("data-label-color");else{const s=e.heatmapStore.getTotalClicksByBooth(t),c=R(e.heatmapStore.getColorByClicks(s));t.labelColor=c.darken(.3).isLight()?"#555":"#fff"}t.rect=a?N.fromSvgRectElement(a):null,t.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=v.dimensionless?null:n.size||r.getAttribute("data-size"),n.status==="reserved"?n.reserved=!0:n.status==="onhold"&&(n.onHold=!0)):E.color=(parseInt(a.getAttribute("data-poi-type"))>0?a.style?.fill:r.getAttribute("data-color")||a.getAttribute("data-color"))||E.color;const y=a?.getAttribute("transform");if(y){const s=y.match(/translate\(([-0-9.]+) ([-0-9.]+)\) rotate\(([-0-9.]+)\)/);if(s){const f=parseFloat(s[3]);t.rotate=-f*Math.PI/180}else{const f=y.match(/rotate\(([-0-9.]+).*\)/);if(f){const b=parseFloat(f[1]);t.rotate=-b*Math.PI/180}else{const b=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*\)/);b&&(t.rotate=Math.asin(-parseFloat(b[2])))}}Math.abs(t.rotate*180/Math.PI)>180&&(t.rotate=t.rotate-90*Math.PI/180,t.rect=t.rect.getRotated90())}if(r.tagName==="g"){t.paths=[],t.pathsWithRect=I;var u=[];for(const s of M.select(r).selectAll("path, rect").nodes())if(s.tagName==="path"){const c=s;if(c.tagName!=="path")continue;const f=parseInt(c.getAttribute("data-index")),b=!!c.getAttribute("data-unblinking");t.paths.push({index:f,color:c.style.fill,unblinking:b}),a||u.push(...D(f,i))}if(u.length){let s=Number.MAX_VALUE,c=Number.MAX_VALUE,f=-Number.MAX_VALUE,b=-Number.MAX_VALUE;u.forEach(_=>{_.forEach(x=>{s=Math.min(s,x[0]),c=Math.min(c,x[1]),f=Math.max(f,x[0]),b=Math.max(b,x[1])})}),t.rect=N.fromXywh(s,c,f-s,b-c),t.noLabels=!0}}}for(const r of o)r.rect?r.store=l:(S.error("__data booth not found in SVG:",r.name,r),o.splice(o.indexOf(r),1));return o}function j(e){return new URLSearchParams(window.location.search).get(e)}function L(e,d,i){let l=new $;l.name="EXHIBITOR NAME",l.slug="exhibitor-name",l.booths=[],l=e||l;for(let h=0;h<i;h++){const o={...l,id:Date.now()};d.exhibitors.push(o)}}function q(e){w.EXPO==="cbresupplypartner"&&e instanceof A&&!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"))}