In this section
- Substation Intelligence geodesy · testcode / sandbox/202609060459/atlas/cartridges/202609060459-substation-intelligence.js lines 3230–3929
Substation Intelligence
A JavaScript file in the cartridges folder of Testcode 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: 99% 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.9913 to code-generator@3897d83efcd0259d21dce87704b0c33118fe2c2e apps/substation-finder/Si/202609060537-substation-intelligence.js:1-5427 fd8aeb8a8884da62dc50991d5f4bf8cc48b33c43
- sha256 916bad1b531c94d9acd3bc54f6ed205b467b96e6c1d86beea47a7d66e2f51669
- target sha256 afc18391911f8ab467480aa8f22fd30467de554c76c58101956f9fec49ad9449
- group of 3 (identity.json near-copy edges >= 0.9)
- canonical rule: reachable, newest stamp, core repo, most lines
geodesytestcode / sandbox/202609060459/atlas/cartridges/202609060459-substation-intelligence.js · lines 3230–3929 of 5400 · version 2026-09-06 04:59 (continued from section 453) · Not reached from any entry point (candidate for review) · pattern _zoneDrawRefreshEditor (shared by 3 files)
- What it does
- It maps elizabeth line, london underground, UK metros trams and hs2. Defines 230 functions or classes, including close, open, show, clearValues, validOutline. 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 'sandbox'): 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 saves outline (`saveOutline`), reads outline (`readOutline`) and exports outline (`exportOutline`). 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
- testcode · sandbox/202609060459/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 Standalone (comment link)
- Produces
- close, open, show, clearValues, validOutline, saveOutline, readOutline, clearOutline, analyzeOutline, fail, orient, on
- Defines here
- forCable, array, cleanText, layerKey, layerLabel, layerGroup, inventory, required, installStyle, syncAttribClearance, closeAll, syncLayer, syncAll, clampPanel, openMenu, buildBar, appendGroup, appendEngineModules, done, appendStudies, exportStamp, attributionText, generationText, buildPrintFurniture, installPrintStyle, printView
- Cannot conclude
- Whether this code runs, is used by a live app today, or is correct. This is a static reading.
- Evidence
- testcode@a8a215982b13d6e2f6019b40bf0bef5755719773 sandbox/202609060459/atlas/cartridges/202609060459-substation-intelligence.js:3230-3929 · blob fd03f2ae502f2d404cb773df8858c2746ada6401 · 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: unreached_review
expected: null, ref: null, bytes_seen: seen, bytes_expected: null };
}
const digest = await digestBytes(bytes);
const answer = { sha256: digest, expected: entry.sha256, ref: entry.ref,
bytes_seen: seen, bytes_expected: entry.bytes };
if (seen !== null && seen !== entry.bytes) {
answer.state = 'MISMATCH';
answer.detail = 'the response at ' + entry.ref + ' is ' + seen
+ ' bytes, not the recorded ' + entry.bytes;
} else if (digest === null) {
answer.state = 'unverified: no subtle crypto in this context';
} else if (digest === entry.sha256) {
answer.state = 'verified';
} else {
answer.state = 'MISMATCH';
answer.detail = 'bytes at ' + entry.ref + ' hash to ' + digest
+ ', not the recorded ' + entry.sha256;
}
return answer;
}
const NS = (window.__GRIDATLAS_MODULES__ = window.__GRIDATLAS_MODULES__ || {});
NS.pinnedProducts = Object.freeze({
schema: SCHEMA,
ids: Object.freeze(Object.keys(PINS)),
pin,
url,
digestHex,
verify,
why: 'A branch ref lets an immutable release change what it says without '
+ 'any of its own bytes changing. The schema string defends shape and is '
+ 'blind to values: a correction to data-grid-gb halves published '
+ 'transformer counts under the same schema. The ref is a commit and the '
+ 'bytes are hashed, so a data correction and a map release are one event.',
not_an_assessment: 'A pin says which bytes were read. It says nothing '
+ 'about whether those bytes are right.'
});
})();
(() => {
'use strict';
const VERSION_LEDGER = [{"g":"202608312121","v":"v9.16","s":"the project arriving from Pipeline News is visible: its own technology layer is enabled and a pin owned by this cartridge is dropped on it, with a toggle on the card"},{"g":"202608312133","v":"v9.17","s":"central AC sizing: the limiting nameplate, not a squared product"},{"g":"202608312140","v":"v9.18","s":"the project marker is a ring, … [line shortened here: 22,471 characters; full line on GitHub]
const REJECTED_PRE_PROMOTION = Object.freeze({
'202609040021': 'never live: the mobile project card could cover the engine layer panel',
'202609040046': 'never live: its generation proof reported 748/755',
'202609040047': 'never live: a late identity could restore an arrival after a user selection or clear'
});
for (const entry of VERSION_LEDGER) {
if (!REJECTED_PRE_PROMOTION[entry.g]) continue;
entry.status = 'REJECTED_PRE_PROMOTION';
entry.reason = REJECTED_PRE_PROMOTION[entry.g];
}
const NS = (window.__GRIDATLAS_MODULES__ = window.__GRIDATLAS_MODULES__ || {});
NS.versionLedger = Object.freeze({
schema: 'gridatlas.module.version-ledger.v1',
entries: VERSION_LEDGER,
written_by: 'tools/recompose.mjs, at the cut, never by hand',
not_an_assessment: 'A ledger row says what a generation changed. It does '
+ 'not say the change was right, and nothing here grades one.'
});
})();
(() => {
'use strict';
const SCHEMA = 'gridatlas.module.corridor-estimate.v1';
const CABLE_FACTOR = 1.245;
const OHL_FACTOR = 1.13;
const MINIMUM_KM = 1;
const BASIS = Object.freeze({
factor: CABLE_FACTOR,
median_absolute_error_pct: 8.45,
within_15_pct: 73,
circuits: 95,
distinct_site_pairs: 59,
source: 'published built lengths of GB transmission cable circuits',
sample_note: 'parallel circuits between the same two sites duplicate the '
+ 'geometry, so the sample is 59 distinct site pairs and not 95 circuits',
minimum_separation_km: MINIMUM_KM,
below_minimum: 'under about a kilometre the site-centroid resolution '
+ 'dominates: median published length 0.59 km against a median error of '
+ '52.5%, so a straight line between centroids is not measuring route '
+ 'factor and no estimate is offered'
});
const CAVEAT = 'Indicative highway-corridor screening only. Not a connection '
+ 'offer, not a constructability assessment and not a consenting design.';
const NOT_FOR_OVERHEAD = 'Calibrated on cable circuits, which follow the '
+ 'highway network. Overhead line crosses open country and measures 1.13; '
+ 'this factor is not applied to an overhead-line question.';
function forCable(km) {
const straight = Number(km);
if (!Number.isFinite(straight) || straight <= 0) return null;
if (straight < MINIMUM_KM) {
return { km: null, factor: CABLE_FACTOR, straight_km: straight,
withheld: BASIS.below_minimum };
}
return {
km: straight * CABLE_FACTOR,
factor: CABLE_FACTOR,
straight_km: straight,
withheld: null
};
}
const NS = (window.__GRIDATLAS_MODULES__ = window.__GRIDATLAS_MODULES__ || {});
NS.corridorEstimate = Object.freeze({
schema: SCHEMA,
factor: CABLE_FACTOR,
overhead_factor: OHL_FACTOR,
minimum_km: MINIMUM_KM,
basis: BASIS,
caveat: CAVEAT,
not_for_overhead: NOT_FOR_OVERHEAD,
forCable,
not_an_assessment: 'An estimated corridor length says nothing about '
+ 'whether a connection is available, consentable or affordable.'
});
})();
(function gridAtlasMenuBar() {
'use strict';
if (typeof window === 'undefined' || typeof document === 'undefined') return;
var SCHEMA = 'gridatlas.menu-bar.v2';
var BAR_ID = 'gridatlas-menu-bar';
var STYLE_ID = BAR_ID + '-css';
var FAILURE_ID = BAR_ID + '-failure';
var MENUS = ['File', 'Edit', 'View', 'Scope', 'Grid', 'About'];
var EXPECTED_ENGINE_LAYERS = 60;
var EXPECTED_PIPELINE_LAYERS = 3;
var EXPECTED_LAYER_CONTROLS = 63;
var MAX_TRIES = 160;
var NS = (window.__GRIDATLAS_MODULES__ = window.__GRIDATLAS_MODULES__ || {});
if (NS.menuBar && NS.menuBar.schema === SCHEMA) return;
var state = {
schema: SCHEMA,
menus: MENUS.slice(),
bar_id: BAR_ID,
installed: false,
controls_moved: 0,
layer_controls: 0,
engine_layer_controls: 0,
pipeline_layer_controls: 0,
expected_layer_controls: EXPECTED_LAYER_CONTROLS,
panel_counts: {},
failure: null,
tries: 0,
listeners: 0,
closed_at_rest: true,
one_identity_surface: false
};
NS.menuBar = state;
var bar = null;
var panels = {};
var titles = [];
var layerTargets = Object.create(null);
var layerProxies = Object.create(null);
var forwardingLayerChoice = false;
var observer = null;
var timer = null;
var brandSlot = null;
var gridHead = null;
var gridBody = null;
function array(value) {
return Array.prototype.slice.call(value || []);
}
function cleanText(value) {
return String(value == null ? '' : value).replace(/\s+/g, ' ').trim();
}
function layerKey(input) {
if (!input || !input.getAttribute) return '';
var engine = input.getAttribute('data-layer-id');
if (engine) return 'engine:' + engine;
var pipeline = input.getAttribute('data-pn-layer');
return pipeline ? 'pipeline:' + pipeline : '';
}
function layerLabel(input) {
var label = input && input.closest ? input.closest('label') : null;
var span = label && label.querySelector
? label.querySelector('[data-base-label], [data-pn-label], span') : null;
var base = span && span.getAttribute ? span.getAttribute('data-base-label') : '';
var text = cleanText((span && span.textContent) || base
|| (label && label.textContent) || layerKey(input).split(':').slice(1).join(':'));
return text || layerKey(input);
}
function layerGroup(input) {
var group = input && input.closest ? input.closest('.key-group') : null;
var title = group && group.querySelector ? group.querySelector('.key-title') : null;
return cleanText(title && title.textContent) || 'Other layers';
}
function inventory(doc) {
var host = doc.getElementById('scada-ui-container');
var engine = host ? array(host.querySelectorAll(
'input[type="checkbox"][data-layer-id]')) : [];
var pipeline = host ? array(host.querySelectorAll(
'input[type="checkbox"][data-pn-layer]')) : [];
var controls = engine.concat(pipeline);
var keys = controls.map(layerKey);
var unique = new Set(keys);
return {
host: host,
engine: engine,
pipeline: pipeline,
controls: controls,
keys: keys,
complete: engine.length === EXPECTED_ENGINE_LAYERS
&& pipeline.length === EXPECTED_PIPELINE_LAYERS
&& controls.length === EXPECTED_LAYER_CONTROLS
&& unique.size === EXPECTED_LAYER_CONTROLS
&& !keys.includes('')
};
}
state.inspect = function () {
var found = inventory(document);
return {
engine: found.engine.length,
pipeline: found.pipeline.length,
total: found.controls.length,
unique: new Set(found.keys).size,
complete: found.complete
};
};
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();