In this section
- Substation Intelligence geodesy · globalgrid2050 / testcode/202609060528/atlas/cartridges/202609060528-substation-intelligence.js lines 3465–4164
Substation Intelligence
A JavaScript file in the cartridges folder of GlobalGrid2050 that maps elizabeth line and london underground, using haversine and SHA-256, and uses data from the ventus-grid-engine, data-federation-map-for-GlobalGrid2050-all-repos and spiders repositories.
Set aside from the main view: 100% of its lines are the same as apps/substation-finder/Si/202609060537-substation-intelligence.js (code-generator), which stays. (near-copy-of, proposed by families.py). 99% of lines shared with Substation Intelligence; read that one first. All set-aside files, with reasons. Nothing was deleted.
Evidence
- line-jaccard 0.9971 to code-generator@3897d83efcd0259d21dce87704b0c33118fe2c2e apps/substation-finder/Si/202609060537-substation-intelligence.js:1-5427 fd8aeb8a8884da62dc50991d5f4bf8cc48b33c43
- sha256 20bedcfc3a9037568e1bd9568512928a0a4781eaa0158ae62e2b46d4b3065db5
- target sha256 afc18391911f8ab467480aa8f22fd30467de554c76c58101956f9fec49ad9449
- group of 3 (identity.json near-copy edges >= 0.9)
- canonical rule: reachable, newest stamp, core repo, most lines
geodesyglobalgrid2050 / testcode/202609060528/atlas/cartridges/202609060528-substation-intelligence.js · lines 3465–4164 of 5420 · version 2026-09-06 05:28 (continued from section 361) · Not reached from any entry point (candidate for review) · pattern restoreLayers (shared by 2 files)
- What it does
- It maps elizabeth line, london underground, UK metros trams and hs2. Defines 232 functions or classes, including close, open, dockLayers, restoreLayers, show. Side effects: changes the web page (DOM); reads or writes files; makes network requests; uses storage (browser storage, DuckDB or Parquet).
- Why it exists in the grid workflow
- Domain stage experimental (path word 'testcode'): work its own path marks as experimental (sandbox, prototype, archive or similar words); by this evidence it is not part of a production workflow. Domain terms in the code: 400kV, 275kV, 132kV, 66kV, 33kV, 11kV.
- Inputs & outputs
- In: data source: ventus-grid-engine data; data source: data-federation-map-for-globalgrid2050-all-repos data; data source: spiders data; GeoJSON file elizabeth_line.geojson; GeoJSON file london_underground.geojson; GeoJSON file uk_metros_trams.geojson; GeoJSON file hs2.geojson; JSON file style.json. Out: CSV file gridatlas-polygon-vertices.csv; downloaded file gridatlas-polygon-; downloaded file gridatlas-polygon-vertices.csv; downloaded file gridatlas-; downloaded file globalgrid2050-map-; browser storage (setItem); interactive map; canvas drawing. Coordinate systems named: WGS84 / EPSG:4326. Voltage levels named: 400kV, 275kV, 132kV, 66kV, 33kV, 11kV.
- What it achieves
- It restores layers (`restoreLayers`), saves outline (`saveOutline`) and reads outline (`readOutline`). Its `snapLines` function gives line features whose first and last vertices are moved onto the nearest substation point within tolerance; other geometry unchanged from line features and substation point features (VEDIC: snap line ends to substations). Its code works with 400 kV and 100 MVA. It responds to fullscreenchange, webkitfullscreenchange and click events.
- Why it matters
- No other file in the estate was found to import it.
- Application
- globalgrid2050 · testcode/202609060528/atlas/cartridges · script
- VEDIC
- SNAP LINE ENDS TO SUBSTATIONS (GG2050-VEDIC-000106): GridAtlas / Substations · Geospatial data processing. line_features, substation_point_features → Line features whose first and last vertices are moved onto the nearest substation point within tolerance; other geometry unchanged.
- VEDIC
- MEASURE (GG2050-VEDIC-000001): GridAtlas / Geodesy · Mathematics / Spherical geometry. coordinate_pair, coordinate_pair → distance_km
- VEDIC
- REPRESENT (GG2050-VEDIC-000002): GridAtlas / Geodesy · Computer science / Geometry processing. geojson_geometry → coordinate_pair_or_null
- Uses
- Spider Full Po Test (estate URL), Data — Grid Studies Public Page (estate URL)
- Used by
- mentioned in Geodesy (comment link)
- Produces
- close, open, dockLayers, restoreLayers, show, clearValues, validOutline, saveOutline, readOutline, clearOutline, analyzeOutline, fail
- Defines here
- required, installStyle, syncAttribClearance, closeAll, syncLayer, syncAll, clampPanel, openMenu, buildBar, appendGroup, appendEngineModules, done, appendStudies, exportStamp, attributionText, generationText, buildPrintFurniture, installPrintStyle, printView, capture, clean, looksBlank, saveImage, say, grab, appendExport, appendEstateLinks, layerCheckbox, buildLayerControls, move
- Cannot conclude
- Whether this code runs, is used by a live app today, or is correct. This is a static reading.
- Evidence
- globalgrid2050@0aca5121f0795e469b6cf4fc3d3b628edba8d883 testcode/202609060528/atlas/cartridges/202609060528-substation-intelligence.js:3465-4164 · blob a4d79e151fc9f1a2b632f53187a97278a5ad843c · GitHub at these lines
- State
- achieves: code · context: readme_derived · stage: output · effects: dom, filesystem, network, storage · domain stage: experimental · users: ICP_grid_engineer · canonical: duplicate_candidate
function required(doc) {
var found = inventory(doc);
var nodes = {
host: doc.querySelector('.map-container'),
stack: doc.querySelector('.map-controls'),
search: doc.querySelector('.search-bar-wrapper'),
header: doc.querySelector('.hud-header'),
exportButton: doc.getElementById('btn-export'),
statusButton: doc.getElementById('btn-status'),
fullscreenButton: doc.getElementById('btn-fullscreen'),
radiusButton: doc.getElementById('btn-radius'),
radiusAreaButton: doc.getElementById('btn-radius-area'),
zoneButton: doc.getElementById('btn-zonedraw'),
measureButton: doc.getElementById('btn-measure')
};
var missing = Object.keys(nodes).filter(function (key) { return !nodes[key]; });
if (!found.complete) missing.push('63 unique layer controls');
return { found: found, nodes: nodes, missing: missing };
}
function installStyle(doc) {
if (doc.getElementById(STYLE_ID)) return;
var style = doc.createElement('style');
style.id = STYLE_ID;
style.textContent = [
'#' + BAR_ID + '{position:absolute;top:0;left:0;right:0;height:36px;z-index:10020;',
'display:flex;align-items:stretch;gap:0;padding-left:env(safe-area-inset-left);',
'padding-right:env(safe-area-inset-right);box-sizing:border-box;',
'background:rgba(4,10,13,.95);border-bottom:1px solid rgba(80,220,240,.3);',
'font:11px/1 ui-monospace,SFMono-Regular,Menlo,monospace;',
'-webkit-backdrop-filter:blur(7px);backdrop-filter:blur(7px);',
'isolation:isolate;pointer-events:auto}',
'#' + BAR_ID + ' .gm-menu{position:relative;min-width:0}',
'#' + BAR_ID + ' .gm-title{appearance:none;border:0;background:transparent;color:#cfeef6;',
'min-height:36px;padding:0 11px;cursor:pointer;font:inherit;letter-spacing:.05em;',
'text-transform:uppercase;white-space:nowrap}',
'#' + BAR_ID + ' .gm-title:hover,#' + BAR_ID + ' .gm-title:focus-visible,',
'#' + BAR_ID + ' .gm-menu.gm-open>.gm-title{background:rgba(80,220,240,.16);color:#fff}',
'#' + BAR_ID + ' .gm-title:focus-visible,#' + BAR_ID + ' .gm-panel :focus-visible{',
'outline:2px solid #6bebff;outline-offset:-2px}',
'#' + BAR_ID + ' .gm-side{display:flex;align-items:stretch;flex:1 1 0;min-width:0}',
'#' + BAR_ID + ' .gm-side-left{justify-content:flex-start}',
'#' + BAR_ID + ' .gm-side-right{justify-content:flex-end}',
'#' + BAR_ID + ' .gm-brand-slot{flex:0 1 auto;min-width:0;max-width:64%;',
'display:flex;align-items:center;justify-content:center;overflow:hidden;',
'padding:0 6px;text-align:center}',
'#' + BAR_ID + ' .gm-brand-slot .hud-header{display:flex!important;',
'position:static!important;width:auto!important;align-items:center;',
'justify-content:center;gap:11px;margin:0!important;padding:0!important;',
'background:none!important;border:0!important}',
'#' + BAR_ID + ' .gm-brand-slot .hud-header>div{flex:0 0 auto;line-height:1.05}',
'#' + BAR_ID + ' .gm-brand-slot .hud-header small{font-size:6.5px;white-space:nowrap}',
'#' + BAR_ID + ' .gm-brand-slot .hud-header .hud-val{font-size:10.5px;',
'text-shadow:none}',
'#' + BAR_ID + ' .gm-brand-slot .ventus-main{font-size:14px;font-weight:800;',
'letter-spacing:.2em;margin:0;color:#fff}',
'#' + BAR_ID + ' .gm-brand-slot .ventus-sub{font-size:5.5px;letter-spacing:.14em}',
'#' + BAR_ID + ' .gm-panel{position:absolute;top:100%;left:0;min-width:240px;',
'max-width:min(92vw,420px);max-height:min(72dvh,620px);overflow:auto;',
'overscroll-behavior:contain;padding:6px;background:rgba(4,10,13,.98);',
'border:1px solid rgba(80,220,240,.32);border-top:0;',
'box-shadow:0 12px 34px rgba(0,0,0,.68);box-sizing:border-box}',
'#' + BAR_ID + ' .gm-panel[hidden]{display:none!important}',
'#' + BAR_ID + ' .gm-side-right .gm-panel{left:auto;right:0}',
'#' + BAR_ID + ' .gm-panel button,#' + BAR_ID + ' .gm-panel [role="button"]{',
'display:flex;align-items:center;width:100%;min-height:44px;box-sizing:border-box;',
'position:static!important;inset:auto!important;transform:none!important;margin:0 0 3px;',
'padding:7px 10px;border:0;border-radius:2px;background:transparent;color:#cfeef6;',
'font:11px/1.35 ui-monospace,SFMono-Regular,Menlo,monospace;text-align:left;',
'letter-spacing:.03em;text-transform:none;cursor:pointer}',
'#' + BAR_ID + ' .gm-panel button:hover,#' + BAR_ID + ' .gm-panel [role="button"]:hover{',
'background:rgba(80,220,240,.14);color:#fff}',
'#' + BAR_ID + ' .gm-panel a[data-gm-estate],#' + BAR_ID + ' .gm-panel a[data-gm-engine],',
'#' + BAR_ID + ' .gm-panel a[data-gm-study]',
'{text-decoration:none}',
'#' + BAR_ID + ' .gm-panel a[data-gm-engine]{white-space:nowrap;overflow:hidden;',
'text-overflow:ellipsis;display:block;line-height:30px;min-height:44px}',
'#' + BAR_ID + ' .gm-panel .custom-map-attrib{position:static!important;',
'inset:auto!important;margin:4px 0 2px;padding:6px 8px;max-width:none;',
'background:transparent;border:0;white-space:normal;line-height:1.45;',
'font:10px/1.45 ui-monospace,SFMono-Regular,Menlo,monospace;color:#8fb6c0}',
'#' + BAR_ID + ' .gm-layer-group{margin:5px 0 2px;padding:6px 8px 3px;',
'border-top:1px solid #19343b;color:#6fa2ae;font-size:10px;letter-spacing:.08em;',
'text-transform:uppercase}',
'#' + BAR_ID + ' .gm-layer{position:relative;display:flex;align-items:center;gap:10px;',
'min-height:44px;box-sizing:border-box;padding:7px 9px;color:#cfeef6;cursor:pointer;',
'line-height:1.35}',
'#' + BAR_ID + ' .gm-layer:hover{background:rgba(80,220,240,.12)}',
'#' + BAR_ID + ' .gm-layer input{position:absolute;inset:0;width:100%;height:100%;',
'margin:0;opacity:0;cursor:pointer;z-index:1}',
'#' + BAR_ID + ' .gm-layer-box{width:20px;height:20px;flex:0 0 auto;',
'border:1.5px solid #4a8b96;border-radius:4px;position:relative;',
'background:rgba(255,255,255,.04)}',
'#' + BAR_ID + ' .gm-layer input:checked~.gm-layer-box{background:#4fd7ee;',
'border-color:#4fd7ee}',
'#' + BAR_ID + ' .gm-layer input:checked~.gm-layer-box::after{content:"";',
'position:absolute;left:6px;top:2px;width:5px;height:10px;',
'border:solid #04141a;border-width:0 2px 2px 0;transform:rotate(38deg)}',
'#' + BAR_ID + ' .gm-layer input:focus-visible~.gm-layer-box{outline:2px solid #6bebff;',
'outline-offset:2px}',
'#' + BAR_ID + ' .gm-layer-name{overflow-wrap:anywhere}',
'#' + BAR_ID + ' .gm-panel-grid{padding:0;overflow:hidden;display:flex;',
'flex-direction:column;min-width:min(94vw,360px);max-width:min(96vw,900px)}',
'#' + BAR_ID + ' .gm-panel-head{flex:0 0 auto;padding:8px 8px 0}',
'#' + BAR_ID + ' .gm-panel-head .scada-brand{padding:0 0 6px;margin:0 0 6px}',
'#' + BAR_ID + ' .gm-panel-head .status-legend{padding:0 0 8px;margin:0;border:0}',
'#' + BAR_ID + ' .gm-panel-body{flex:1 1 auto;overflow:auto;',
'overscroll-behavior:contain;padding:6px;min-height:0}',
'@media(min-width:560px){#' + BAR_ID + ' .gm-panel-body{column-count:2;',
'column-gap:14px}',
'#' + BAR_ID + ' .gm-panel-body .gm-layer-group{break-inside:avoid}',
'#' + BAR_ID + ' .gm-panel-body .gm-layer{break-inside:avoid}}',
'@media(min-width:900px){#' + BAR_ID + ' .gm-panel-body{column-count:3}}',
'#' + BAR_ID + ' .search-bar-wrapper{position:static!important;display:grid!important;',
'grid-template-columns:minmax(150px,1fr) auto;width:min(82vw,390px);gap:5px;margin:2px 0 6px}',
'#' + BAR_ID + ' .search-bar-wrapper>div{position:relative}',
'#' + BAR_ID + ' .search-input{width:100%!important;min-height:44px;box-sizing:border-box}',
'#' + BAR_ID + ' .search-results{position:static!important;max-height:42vh;overflow:auto}',
'#' + BAR_ID + ' .disclaimer-box,#' + BAR_ID + ' .podcast-shoutout{',
'display:block!important;position:static!important;max-width:380px;padding:8px;',
'box-sizing:border-box;text-align:left;pointer-events:auto}',
'.gridatlas-menu-hosted .map-controls[data-gridatlas-menu-emptied="1"]{display:none!important}',
'.gridatlas-menu-hosted .scada-wrapper{display:flex!important}',
'#gridatlas-dash-toggle{display:inline-flex!important}',
'html.gridatlas-sheet-open #' + BAR_ID + '{z-index:10020!important;pointer-events:auto!important}',
'html.gridatlas-sheet-open #' + BAR_ID + ' .gm-panel{pointer-events:auto!important}',
'body:not(.fs-active) #' + BAR_ID + ' #btn-fullscreen-exit{display:none!important}',
'body.fs-active #' + BAR_ID + ' #btn-fullscreen-exit{display:flex!important}',
'.gridatlas-menu-hosted .custom-map-attrib{',
'top:var(--gridatlas-menu-bar-clear,44px)!important;z-index:10025!important}',
'.gridatlas-menu-hosted #fs-letterhead{display:none!important}',
'@media(max-width:700px){#' + BAR_ID + '{height:34px}',
'#' + BAR_ID + ' .gm-title{min-height:34px;padding:0 6px;font-size:9px;letter-spacing:.025em}',
'#' + BAR_ID + ' .gm-brand-slot{max-width:48%;padding:0 2px}',
'#' + BAR_ID + ' .gm-brand-slot .hud-header>div:first-child,',
'#' + BAR_ID + ' .gm-brand-slot .hud-header>div:last-child{display:none}',
'#' + BAR_ID + ' .gm-brand-slot .ventus-main{font-size:11px;letter-spacing:.14em}',
'#' + BAR_ID + ' .gm-brand-slot .ventus-sub{font-size:4.5px}',
'#' + BAR_ID + ' .gm-panel{position:fixed;top:34px;left:4px!important;right:4px!important;',
'width:auto;max-width:none;max-height:calc(100dvh - 40px);padding-bottom:',
'calc(6px + env(safe-area-inset-bottom))}',
'#' + BAR_ID + ' .gm-panel-grid{max-width:none}}'
].join('');
(doc.head || doc.documentElement).appendChild(style);
}
function syncAttribClearance(doc) {
if (!bar || typeof bar.getBoundingClientRect !== 'function') return;
var root = doc.documentElement;
if (!root || !root.style || typeof root.style.setProperty !== 'function') return;
var rect = bar.getBoundingClientRect();
var height = Math.ceil(rect.height) || 36;
var clearance = height + 8;
root.style.setProperty('--gridatlas-menu-bar-clear', clearance + 'px');
state.attrib_clearance_px = clearance;
}
function closeAll(focusTitle) {
if (!bar) return;
array(bar.querySelectorAll('.gm-menu.gm-open')).forEach(function (menu) {
menu.classList.remove('gm-open');
var title = menu.querySelector('.gm-title');
var panel = menu.querySelector('.gm-panel');
if (title) title.setAttribute('aria-expanded', 'false');
if (panel) panel.hidden = true;
});
state.closed_at_rest = true;
openPanelRefs = null;
if (focusTitle && typeof focusTitle.focus === 'function') focusTitle.focus();
}
function syncLayer(key) {
var original = layerTargets[key];
var proxy = layerProxies[key];
if (!original || !proxy) return;
proxy.checked = !!original.checked;
proxy.disabled = !!original.disabled;
proxy.setAttribute('aria-label', layerLabel(original));
var name = proxy.parentNode && proxy.parentNode.querySelector
? proxy.parentNode.querySelector('.gm-layer-name') : null;
if (name) {
var nextLabel = layerLabel(original);
if (name.textContent !== nextLabel) name.textContent = nextLabel;
}
}
function syncAll() {
Object.keys(layerTargets).forEach(syncLayer);
}
function clampPanel(doc, menu, panel) {
if (!panel || typeof panel.getBoundingClientRect !== 'function') return;
if (!menu || typeof menu.getBoundingClientRect !== 'function') return;
panel.style.left = '';
panel.style.right = '';
var view = doc.defaultView || (typeof window !== 'undefined' ? window : null);
var vw = (view && view.innerWidth) || doc.documentElement.clientWidth;
if (!vw) return;
var margin = 4;
var panelRect = panel.getBoundingClientRect();
var desiredLeft = panelRect.left;
if (panelRect.left < margin) desiredLeft = margin;
else if (panelRect.right > vw - margin) desiredLeft = Math.max(margin, vw - margin - panelRect.width);
if (Math.round(desiredLeft) === Math.round(panelRect.left)) return;
var menuRect = menu.getBoundingClientRect();
panel.style.left = (desiredLeft - menuRect.left) + 'px';
panel.style.right = 'auto';
}
var openPanelRefs = null;
function openMenu(menu, title, panel) {
var wasOpen = menu.classList.contains('gm-open');
closeAll();
if (wasOpen) { openPanelRefs = null; return; }
if (title.textContent === 'Grid') syncAll();
menu.classList.add('gm-open');
title.setAttribute('aria-expanded', 'true');
panel.hidden = false;
state.closed_at_rest = false;
openPanelRefs = { menu: menu, panel: panel };
clampPanel(title.ownerDocument || document, menu, panel);
}
function buildBar(doc) {
var nav = doc.createElement('nav');
nav.id = BAR_ID;
nav.setAttribute('aria-label', 'Atlas menu');
var left = doc.createElement('div');
left.className = 'gm-side gm-side-left';
var right = doc.createElement('div');
right.className = 'gm-side gm-side-right';
var brand = doc.createElement('div');
brand.className = 'gm-brand-slot';
brandSlot = brand;
MENUS.forEach(function (name, index) {
var menu = doc.createElement('div');
menu.className = 'gm-menu';
var title = doc.createElement('button');
title.type = 'button';
title.className = 'gm-title';
title.textContent = name;
title.id = BAR_ID + '-title-' + index;
title.setAttribute('aria-haspopup', 'menu');
title.setAttribute('aria-expanded', 'false');
title.setAttribute('aria-controls', BAR_ID + '-panel-' + index);
var panel = doc.createElement('div');
panel.className = 'gm-panel';
panel.id = BAR_ID + '-panel-' + index;
panel.hidden = true;
panel.setAttribute('role', 'group');
panel.setAttribute('aria-labelledby', title.id);
if (name === 'Grid') {
var head = doc.createElement('div');
head.className = 'gm-panel-head';
var body = doc.createElement('div');
body.className = 'gm-panel-body';
panel.appendChild(head);
panel.appendChild(body);
panel.classList.add('gm-panel-grid');
gridHead = head;
gridBody = body;
}
title.addEventListener('click', function (event) {
event.stopPropagation();
openMenu(menu, title, panel);
});
menu.appendChild(title);
menu.appendChild(panel);
(index < 3 ? left : right).appendChild(menu);
panels[name] = panel;
titles.push(title);
});
nav.appendChild(left);
nav.appendChild(brand);
nav.appendChild(right);
nav.addEventListener('keydown', function (event) {
var active = doc.activeElement;
var index = titles.indexOf(active);
if (event.key === 'Escape') {
var owner = active && active.closest ? active.closest('.gm-menu') : null;
var ownerTitle = owner && owner.querySelector ? owner.querySelector('.gm-title') : null;
closeAll(ownerTitle);
event.preventDefault();
return;
}
if (index < 0) return;
if (event.key === 'ArrowRight' || event.key === 'ArrowLeft') {
var delta = event.key === 'ArrowRight' ? 1 : -1;
titles[(index + delta + titles.length) % titles.length].focus();
event.preventDefault();
} else if (event.key === 'Home' || event.key === 'End') {
titles[event.key === 'Home' ? 0 : titles.length - 1].focus();
event.preventDefault();
} else if (event.key === 'ArrowDown') {
var ownerMenu = active.closest('.gm-menu');
var ownerPanel = ownerMenu.querySelector('.gm-panel');
openMenu(ownerMenu, active, ownerPanel);
var first = ownerPanel.querySelector('button,input,[role="button"]');
if (first && first.focus) first.focus();
event.preventDefault();
}
});
return nav;
}
function appendGroup(panel, text) {
var heading = document.createElement('div');
heading.className = 'gm-layer-group';
heading.textContent = text;
panel.appendChild(heading);
}
var ESTATE_LINKS = [
{ href: 'https://ventusltd.github.io/ventus-grid-engine/?graph=engine-graph',
text: 'Grid engine · the maths' },
{ href: 'https://ventusltd.github.io/data-federation-map-for-globalgrid2050-all-repos/dashboard/sandbox/spider_full_po_test.html',
text: 'Federation map' },
{ href: 'https://ventusltd.github.io/spiders/spider_printer_v1/',
text: 'Spider printer' }
];
var ENGINE_GRAPH_URL =
'https://ventusltd.github.io/ventus-grid-engine/genome/engine-graph.json';
var ENGINE_VIEW_URL =
'https://ventusltd.github.io/ventus-grid-engine/?graph=engine-graph&focus=';
var engineFetchStarted = false;
function appendEngineModules(panel) {
if (!panel || !window.fetch || engineFetchStarted) return;
if (panel.querySelector('[data-gm-engine]')) return;
engineFetchStarted = true;
fetch(ENGINE_GRAPH_URL, { cache: 'no-cache' }).then(function (response) {
if (!response.ok) throw new Error('HTTP ' + response.status);
return response.json();
}).then(function (graph) {
var nodes = (graph && graph.nodes) || [];
if (!nodes.length || panel.querySelector('[data-gm-engine]')) return;
var ORDER = ['canonical', 'extract', 'reference', 'fragment'];
var FALLBACK_LABEL = {
canonical: 'Engine · the maths this runs on',
extract: 'Extracts',
reference: 'References',
fragment: 'Copies elsewhere in the estate'
};
var kindLabels = (graph && graph.kind_labels) || {};
var byKind = {};
nodes.forEach(function (node) {
if (!node || !node.label) return;
var kind = node.type || 'other';
if (!byKind[kind]) byKind[kind] = [];
byKind[kind].push(node);
});
var kinds = ORDER.filter(function (k) { return byKind[k]; })
.concat(Object.keys(byKind).filter(function (k) { return ORDER.indexOf(k) < 0; }).sort());
var RUN_COMMAND =
'git clone https://github.com/Ventusltd/ventus-grid-engine'
+ ' && cd ventus-grid-engine && node verify.mjs';
appendGroup(panel, 'Run the engine yourself · offline, no dependencies');
var run = document.createElement('button');
run.setAttribute('data-gm-engine', '1');
run.setAttribute('type', 'button');
run.title = RUN_COMMAND;
run.textContent = '⧉ Copy: clone the engine and run its 133 checks';
run.addEventListener('click', function () {
var done = function (ok) {
run.textContent = ok
? '✓ Copied — paste it into a terminal'
: '⧉ ' + RUN_COMMAND;
};
try {
if (navigator.clipboard && navigator.clipboard.writeText) {
navigator.clipboard.writeText(RUN_COMMAND).then(function () { done(true); },
function () { done(false); });
} else {
done(false);
}
} catch (_) { done(false); }
});
panel.appendChild(run);
var total = 0;
kinds.forEach(function (kind) {
var group = byKind[kind];
group.sort(function (a, b) { return String(a.label).localeCompare(String(b.label), 'en-GB'); });
appendGroup(panel, (FALLBACK_LABEL[kind] || kindLabels[kind] || kind) + ' · ' + group.length);
group.forEach(function (node) {
var a = document.createElement('a');
a.setAttribute('data-gm-engine', '1');
a.setAttribute('role', 'button');
a.href = ENGINE_VIEW_URL + encodeURIComponent(node.label);
a.target = '_blank';
a.rel = 'noopener';
a.textContent = node.label;
if (node.reason) a.title = node.reason;
panel.appendChild(a);
total += 1;
});
});
state.engine_modules = total;
}).catch(function () {
state.engine_modules = 0;
});
}
var STUDY_LINKS = [
{ href: 'https://globalgrid2050.com/data/grid_studies_public/'
+ 'great_britain_electricity_price_grid_constraint_trends_2016_2026.html',
text: 'GB electricity price & grid constraint trends · 2016–2026' }
];
function appendStudies(panel) {
if (!panel || panel.querySelector('[data-gm-study]')) return 0;
appendGroup(panel, 'Studies');
var added = 0;
STUDY_LINKS.forEach(function (item) {
var a = document.createElement('a');
a.setAttribute('data-gm-study', '1');
a.setAttribute('role', 'button');
a.href = item.href;
a.target = '_blank';
a.rel = 'noopener';
a.textContent = item.text;
panel.appendChild(a);
added += 1;
});
return added;
}
function exportStamp() {
var now = new Date();
return now.toISOString().replace('T', ' ').slice(0, 16) + ' UTC';
}
function attributionText(doc) {
var node = doc.querySelector('.custom-map-attrib');
return cleanText(node && node.textContent)
|| 'Data © OpenStreetMap contributors | © CARTO | EV data © Open Charge Map';
}
function generationText() {
var atlas = window.__GRIDATLAS_ATLAS__;
var generation = (atlas && atlas.generation)
|| (document.documentElement && document.documentElement.dataset
&& document.documentElement.dataset.gridatlasGeneration);
return generation ? 'generation ' + generation : '';
}
function buildPrintFurniture(doc) {
var box = doc.createElement('div');
box.id = 'gridatlas-print-furniture';
var selected = doc.querySelector('.project-popup .name, .gm-panel .project-name');
var title = cleanText(selected && selected.textContent) || 'GlobalGrid2050 · Grid Atlas';
box.innerHTML =
'<div class="gpf-head"><span class="gpf-brand">VENTUS</span>'
+ '<span class="gpf-sub">GLOBAL GRID 2050 · GRID ATLAS</span></div>'
+ '<div class="gpf-title"></div>'
+ '<div class="gpf-foot"><span class="gpf-attrib"></span>'
+ '<span class="gpf-stamp"></span></div>';
box.querySelector('.gpf-title').textContent = title;
box.querySelector('.gpf-attrib').textContent = attributionText(doc);
box.querySelector('.gpf-stamp').textContent =
[generationText(), exportStamp()].filter(Boolean).join(' · ');
doc.body.appendChild(box);
return box;
}
function installPrintStyle(doc) {
if (doc.getElementById('gridatlas-print-css')) return;
var style = doc.createElement('style');
style.id = 'gridatlas-print-css';
style.textContent = [
'#gridatlas-print-furniture{display:none}',
'@media print{',
' #' + BAR_ID + '{display:none!important}',
' #gridatlas-print-furniture{display:block;position:fixed;inset:0;',
' padding:8mm;box-sizing:border-box;pointer-events:none;z-index:9;',
' font:11px/1.4 ui-monospace,SFMono-Regular,Menlo,monospace;color:#0b1416}',
' #gridatlas-print-furniture .gpf-head{letter-spacing:.28em;font-size:13px}',
' #gridatlas-print-furniture .gpf-brand{font-weight:700;margin-right:10px}',
' #gridatlas-print-furniture .gpf-sub{opacity:.65;letter-spacing:.16em}',
' #gridatlas-print-furniture .gpf-title{margin-top:4mm;font-size:20px;',
' letter-spacing:.02em;max-width:70%}',
' #gridatlas-print-furniture .gpf-foot{position:absolute;left:10mm;right:10mm;',
' bottom:8mm;display:flex;justify-content:space-between;gap:8mm;',
' font-size:9px;opacity:.75}',
' @page{size:auto;margin:8mm}',
' html,body{background:#fff!important;height:100%!important;',
' margin:0!important;padding:0!important;overflow:hidden!important}',
' body{display:flex!important;flex-direction:column!important}',
' .map-container{',
' flex:1 1 auto!important;min-height:0!important;width:100%!important;',
' max-height:100%!important}',
' #map,.maplibregl-map,.maplibregl-canvas-container{',
' height:100%!important;width:100%!important;max-height:100%!important}',
' .maplibregl-canvas{width:100%!important;height:100%!important;',
' object-fit:contain}',
' body>*{break-inside:avoid;page-break-inside:avoid}',
' body{page-break-after:avoid}',
'}'
].join('');
doc.head.appendChild(style);
}
function printView(doc) {
var map = window.__GRIDATLAS_V9_MAP__;
var canvas = map && map.getCanvas && map.getCanvas();
if (!canvas) return;
var capture = function () {
var url;
try { url = canvas.toDataURL('image/png'); } catch (_) { return; }
if (looksBlank(canvas)) return;
var old = doc.getElementById('gridatlas-print-furniture');
if (old) old.remove();
var furniture = buildPrintFurniture(doc);
var image = doc.createElement('img');
image.className = 'gpf-map'; image.alt = 'Current Grid Atlas map'; image.src = url;
furniture.appendChild(image);
var style = doc.getElementById('gridatlas-print-css');
if (!style) { style = doc.createElement('style'); style.id = 'gridatlas-print-css'; doc.head.appendChild(style); }
style.textContent = '#gridatlas-print-furniture{display:none}' +
'@media print{@page{size:auto;margin:8mm}html,body{margin:0!important;padding:0!important;height:auto!important;overflow:visible!important;background:white!important}' +
'body>*:not(#gridatlas-print-furniture){display:none!important}' +
'#gridatlas-print-furniture{display:block!important;position:fixed;inset:0;box-sizing:border-box;padding:4mm;background:white;color:#101c22;font:11px/1.4 system-ui}' +
'.gpf-head{font-size:12px;letter-spacing:2px}.gpf-brand{font-weight:bold;margin-right:10px}.gpf-title{font-size:18px;margin-top:3mm}' +
'.gpf-map{position:absolute;left:4mm;top:22mm;width:calc(100% - 8mm);height:calc(100% - 42mm);object-fit:contain}' +
'.gpf-foot{position:absolute;left:4mm;right:4mm;bottom:3mm;display:flex;gap:12px;justify-content:space-between;font-size:9px}.gpf-stamp{white-space:nowrap}}';
var clean = function () { furniture.remove(); window.removeEventListener('afterprint', clean); };
window.addEventListener('afterprint', clean);
image.decode().then(function () { window.print(); }).catch(clean);
window.setTimeout(clean, 300000);
};
map.once('render', capture); map.triggerRepaint();
}
function looksBlank(canvas) {
try {
var probe = document.createElement('canvas');
probe.width = 40; probe.height = 40;
var context = probe.getContext('2d');
context.drawImage(canvas, 0, 0, 40, 40);
var data = context.getImageData(0, 0, 40, 40).data;
for (var i = 3; i < data.length; i += 4) if (data[i] !== 0) return false;
return true;
} catch (_) {
return false;
}
}
function saveImage(doc, button) {
var map = window.__GRIDATLAS_V9_MAP__;
if (!map || !map.getCanvas) {
map = (window.map && window.map.getCanvas) ? window.map : null;
}
var canvas = doc.querySelector('.maplibregl-canvas')
|| (map && map.getCanvas ? map.getCanvas() : null);
var say = function (text) { button.textContent = text; };
if (!canvas) { say('⊘ No map canvas to save — use Print'); return; }
var grab = function () {
var url;
try { url = canvas.toDataURL('image/png'); } catch (_) { url = null; }
if (!url || looksBlank(canvas)) {
say('⊘ The map could not be captured — use Print instead');
return;
}
var link = doc.createElement('a');
link.href = url;
link.download = 'gridatlas-' + exportStamp().replace(/[^0-9]/g, '').slice(0, 12) + '.png';
doc.body.appendChild(link);
link.click();
doc.body.removeChild(link);
say('✓ Image saved');
window.setTimeout(function () { say('⤓ Save an image of this view'); }, 4000);
};
if (map && map.once && map.triggerRepaint) {
map.once('render', grab);
map.triggerRepaint();
} else {
grab();
}
}
function appendExport(panel, doc) {
if (!panel || panel.querySelector('[data-gm-export]')) return 0;
appendGroup(panel, 'Export this view');
var print = doc.createElement('button');
print.setAttribute('data-gm-export', '1');
print.setAttribute('type', 'button');
print.textContent = '⎙ Print · or save as PDF';
print.addEventListener('click', function () { printView(doc); });
panel.appendChild(print);
var image = doc.createElement('button');
image.setAttribute('data-gm-export', '1');
image.setAttribute('type', 'button');
image.textContent = '⤓ Save an image of this view';
image.addEventListener('click', function () { saveImage(doc, image); });
panel.appendChild(image);
return 2;
}
function appendEstateLinks(panel) {
if (!panel || panel.querySelector('[data-gm-estate]')) return 0;
appendGroup(panel, 'Estate');
var added = 0;
ESTATE_LINKS.forEach(function (item) {
var a = document.createElement('a');
a.setAttribute('data-gm-estate', '1');
a.setAttribute('role', 'button');
a.href = item.href;
a.target = '_blank';
a.rel = 'noopener';
a.textContent = item.text;
panel.appendChild(a);
added += 1;
});
return added;
}
function layerCheckbox(kind) {
var proxy = document.createElement('input');
proxy.type = kind;
var box = document.createElement('span');
box.className = 'gm-layer-box';
box.setAttribute('aria-hidden', 'true');
return { proxy: proxy, box: box };
}
function buildLayerControls(found) {
var lastGroup = '';
found.controls.forEach(function (original) {
var key = layerKey(original);
var group = layerGroup(original);
if (group !== lastGroup) {
appendGroup(gridBody, group);
lastGroup = group;
}
var label = document.createElement('label');
label.className = 'gm-layer';
label.setAttribute('data-gridatlas-layer-key', key);
var built = layerCheckbox('checkbox');
var proxy = built.proxy;
proxy.setAttribute('data-gridatlas-layer-proxy', key);
var name = document.createElement('span');
name.className = 'gm-layer-name';
label.appendChild(proxy);
label.appendChild(built.box);
label.appendChild(name);
gridBody.appendChild(label);
layerTargets[key] = original;
layerProxies[key] = proxy;
proxy.addEventListener('change', function () {
if (!!original.checked !== !!proxy.checked && typeof original.click === 'function') {
forwardingLayerChoice = true;
try { original.click(); }
finally { forwardingLayerChoice = false; }
}
syncLayer(key);
});
syncLayer(key);
});
var basemaps = array(found.host.querySelectorAll('input[type="radio"][name="bm"]'));
if (basemaps.length) appendGroup(gridBody, 'Basemap');
basemaps.forEach(function (original) {
var label = document.createElement('label');
label.className = 'gm-layer';
var built = layerCheckbox('radio');
var proxy = built.proxy;
proxy.name = 'gridatlas-menu-basemap';
proxy.value = original.value;
proxy.checked = !!original.checked;
var name = document.createElement('span');
name.className = 'gm-layer-name';
name.textContent = cleanText(original.closest('label').textContent) || original.value;
proxy.addEventListener('change', function () {
if (proxy.checked && !original.checked && typeof original.click === 'function') original.click();
closeAll();
});
label.appendChild(proxy);
label.appendChild(built.box);
label.appendChild(name);
gridBody.appendChild(label);
});
}
function move(panel, node, label) {
if (!node || !panel || (bar && bar.contains(node))) return false;
if (label && node.setAttribute) node.setAttribute('aria-label', label);
panel.appendChild(node);
if (node.removeAttribute) node.removeAttribute('hidden');
state.controls_moved += 1;
return true;
}
function trayRoute(node) {
var text = cleanText(node && node.textContent).toLowerCase();
if (/\bclear\b|\bscope\b/.test(text)) return 'Scope';
if (/\bgrid\b|\bsubs\b/.test(text)) return 'Grid';
return '';
}
function chipStaysOnMap(node) {
var text = cleanText(node && node.textContent).toLowerCase();
if (!/\bgrid\b|\bsubs\b/.test(text)) return false;
var coarse = false;
try {
coarse = !!(window.matchMedia && window.matchMedia('(pointer: coarse)').matches);
} catch (error) {
coarse = false;
}
var width = Number(window.innerWidth);
var narrow = isFinite(width) && width > 0 && width <= 700;
return coarse || narrow;
}
function adoptLate(doc) {
if (!bar) return;
move(panels.View, doc.getElementById('gridatlas-gb-conditions'));
move(panels.About, doc.getElementById('gridatlas-version-ledger'));
move(panels.View, doc.getElementById('btn-fullscreen-exit'), 'Exit full screen');
var curtain = doc.getElementById('fs-curtain-tab');
if (curtain && !bar.contains(curtain)) {
curtain.setAttribute('role', 'button');
curtain.setAttribute('tabindex', '0');
curtain.setAttribute('aria-label', 'Open the fullscreen layer curtain');
move(panels.Grid, curtain);
}
var tray = doc.getElementById('gridatlas-mobile-tray');
if (tray) {
array(tray.querySelectorAll('button')).forEach(function (button) {
if (chipStaysOnMap(button)) return;
var route = trayRoute(button);
if (route) move(panels[route], button);