Spaces:
Running
Running
Match Grid Atlas to the Electrocheap theme
Browse files19 unmodified lines20212223242534 unmodified lines60616263646566676869707172737475763 unmodified lines808182838485868788899091929394959675 unmodified lines17217317417517617717811 unmodified lines19019119219319419519619719819920020120220320420515 unmodified lines22122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625719 unmodified linesconst atlasMonthLabels = Array.from({length: 12}, (_, month) =>new Intl.DateTimeFormat('en', {month: 'short', timeZone: 'UTC'}).format(Date.UTC(2024, month)));function AtlasWheel({points, selection, onSelect, low, high}) {const canvas = useRef(null);const hitTargets = useRef([]);34 unmodified linesconst yearStep = Math.max(1, Math.ceil((lastYear - firstYear) / 7));for (let year = firstYear; year <= lastYear; year += yearStep) {const ring = Array.from({length: 73}, (_, index) => project(index / 6, year, 1.08));line(ring, '#f6ddb150');ctx.font = '11px system-ui';ctx.fillStyle = '#e3cfae';ctx.fillText(year, Math.min(width - 33, width / 2 + radius * 1.12), ring[0].y);}for (let month = 0; month < 12; month += 3) {const start = project(month, firstYear, 1.08);const end = project(month, lastYear, 1.08);line([start, end], '#f6ddb150');ctx.font = '11px system-ui';ctx.fillStyle = '#e3cfae';ctx.fillText(atlasMonthLabels[month], start.x - 9, start.y + 20 + (lastYear === firstYear ? 4 : 0));}const nodes = points.map(point => {3 unmodified linesfor (let i = 1; i < nodes.length; i++) {const before = nodes[i - 1];const after = nodes[i];if (after.point.index - before.point.index === 1) line([before, after], '#f9a94e82', 1.6);}hitTargets.current = [...nodes].sort((a, b) => a.depth - b.depth);for (const node of hitTargets.current) {const active = node.point.key === selection;ctx.beginPath();ctx.arc(node.x, node.y, active ? 8 : 3.4 + node.fraction * 1.2, 0, Math.PI * 2);ctx.fillStyle = active ? '#fff5d5' : `hsl(${21 + node.fraction * 29} 96% ${51 + node.fraction * 19}%)`;ctx.fill();if (active) {ctx.strokeStyle = '#ffb852';ctx.lineWidth = 2.5;ctx.stroke();}75 unmodified lines<style>{gridAtlasStyles}</style><div className="atlas-heading"><div><p className="atlas-kicker">{publisher} grid history</p><h2>Grid Atlas</h2><p>{market.scope} · {points[0].key} to {latest.key}</p></div><div className="atlas-modes" aria-label="Visualization"><button type="button" aria-pressed={mode === 'wheel'} onClick={() => setMode('wheel')}>Seasonal orbit</button><button type="button" aria-pressed={mode === 'calendar'} onClick={() => setMode('calendar')}>Calendar</button></div>11 unmodified linesreturn point ? <button type="button" key={label} aria-pressed={point.key === selected.key}aria-label={`${label} ${year}, ${num(point.value, 1)} GWh`}title={`${label} ${year} · ${num(point.value, 1)} GWh`}style={{backgroundColor: `hsl(${44 - 23 * amount} 90% ${92 - 40 * amount}%)`}}onClick={() => setSelectedKey(point.key)} /> :<span key={label} className="atlas-gap" title={`${label} ${year} · no record`}>—</span>;})}</div>)}</div>}<p className="atlas-scale">{mode === 'wheel' ? 'One turn per year · farther from the centre means more energy. Drag to rotate.' : 'Darker orange means more energy. Blank cells mark months without a record.'}<span>{num(low)}–{num(high)} GWh</span></p></div><div className="atlas-detail"><label>History range<select value={windowSize} onChange={event => setWindowSize(event.target.value)}>15 unmodified lines}const gridAtlasStyles = `.grid-atlas{border-radius:22px;background:#fffdf8;color:#27211e;padding:clamp(15px,3vw,28px);border:1px solid #efded0}.atlas-heading,.atlas-modes,.atlas-camera,.atlas-scale{display:flex;align-items:center;gap:9px}.atlas-heading{justify-content:space-between;flex-wrap:wrap;margin-bottom:18px}.atlas-heading h2{font-size:clamp(32px,5vw,50px);letter-spacing:-.068em;margin:0;line-height:1.05;font-weight:710}.atlas-heading p{margin:6px 0 0;color:#675349;font-size:13px}.atlas-heading .atlas-kicker{color:#99501d;font-size:11px;font-weight:750;letter-spacing:.13em;text-transform:uppercase;margin:0 0 5px}.atlas-modes button,.atlas-camera button{background:#fff5e7;color:#311f17;border:1px solid #ead0b7;border-radius:999px;padding:6px 11px;cursor:pointer;font-size:12px;font-weight:700}.atlas-modes button[aria-pressed=true]{background:#ffb660;border-color:#b96725}.atlas-body{display:grid;grid-template-columns:minmax(0,1fr) minmax(175px,.36fr);gap:16px}.atlas-visual{min-width:0}.atlas-wheel{overflow:hidden;position:relative;border-radius:15px;background:radial-gradient(ellipse at 47% 43%,#49291f,#1d1516 77%);border:1px solid #1d1516}.atlas-wheel canvas{display:block;width:100%;height:clamp(285px,43vw,430px);touch-action:pan-y;cursor:grab}.atlas-wheel canvas:active{cursor:grabbing}.atlas-camera{position:absolute;bottom:10px;left:50%;transform:translateX(-50%);white-space:nowrap}.atlas-camera button{background:#31201f;color:#ffe7c2;border-color:#805a43}.atlas-detail{display:grid;align-content:start;gap:17px;background:#fff3e2;border:1px solid #f0dac4;border-radius:15px;padding:15px}.atlas-detail label{display:grid;gap:6px;font-size:12px;font-weight:700;color:#57372b}.atlas-detail select{width:100%;border-radius:9px;padding:7px;background:#fffdf7;color:#332219;border:1px solid #dbbca2}.atlas-detail input{width:100%;min-width:0;accent-color:#b34f15}.atlas-detail a{font-size:12px;font-weight:700;color:#814316;text-underline-offset:3px}.atlas-readout span,.atlas-readout p{font-size:12px;color:#654032;margin:4px 0}.atlas-readout strong{display:block;font-size:clamp(25px,4vw,38px);letter-spacing:-.05em;line-height:1.15;overflow-wrap:anywhere}.atlas-readout small{font-size:13px;letter-spacing:0}.atlas-scale{justify-content:space-between;flex-wrap:wrap;color:#685247;font-size:12px;margin:8px 0 0}.atlas-scale span{white-space:nowrap;font-variant-numeric:tabular-nums}.atlas-calendar{overflow:auto;max-height:430px;border:1px solid #f0dac4;border-radius:15px;padding:10px;background:#fff9ee}.atlas-calendar-row{min-width:430px;display:grid;grid-template-columns:45px repeat(12,minmax(25px,1fr));gap:4px;align-items:center;text-align:center;color:#5c473a;font-size:10px;padding:3px 0}.atlas-calendar-row button,.atlas-gap{height:23px;border:1px solid transparent;border-radius:4px}.atlas-calendar-row button{cursor:pointer}.atlas-calendar-row button[aria-pressed=true]{border:2px solid #342014}.grid-atlas button:focus-visible,.grid-atlas select:focus-visible,.grid-atlas input:focus-visible,.grid-atlas a:focus-visible{outline:2px solid #944511;outline-offset:2px}@media(max-width:820px){.atlas-body{grid-template-columns:minmax(0,1fr)}}`;19 unmodified lines2021222324252627282930313233343536373839404134 unmodified lines76777879808182838485868788899091923 unmodified lines9697989910010110210310410510610710810911011111275 unmodified lines18818919019119219319411 unmodified lines20620720820921021121221321421521621721821922022122222322422522615 unmodified lines24224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428519 unmodified linesconst atlasMonthLabels = Array.from({length: 12}, (_, month) =>new Intl.DateTimeFormat('en', {month: 'short', timeZone: 'UTC'}).format(Date.UTC(2024, month)));const gridDemandStops = [[69, 184, 126],[240, 211, 94],[248, 160, 76],[231, 98, 91]];function gridDemandColor(fraction) {const position = Math.max(0, Math.min(1, fraction)) * (gridDemandStops.length - 1);const lower = Math.floor(position);const mix = position - lower;const start = gridDemandStops[lower];const end = gridDemandStops[Math.ceil(position)];return `rgb(${start.map((value, index) => Math.round(value + (end[index] - value) * mix)).join(', ')})`;}function AtlasWheel({points, selection, onSelect, low, high}) {const canvas = useRef(null);const hitTargets = useRef([]);34 unmodified linesconst yearStep = Math.max(1, Math.ceil((lastYear - firstYear) / 7));for (let year = firstYear; year <= lastYear; year += yearStep) {const ring = Array.from({length: 73}, (_, index) => project(index / 6, year, 1.08));line(ring, '#b5ced23b');ctx.font = '11px system-ui';ctx.fillStyle = '#b9cbd0';ctx.fillText(year, Math.min(width - 33, width / 2 + radius * 1.12), ring[0].y);}for (let month = 0; month < 12; month += 3) {const start = project(month, firstYear, 1.08);const end = project(month, lastYear, 1.08);line([start, end], '#b5ced23b');ctx.font = '11px system-ui';ctx.fillStyle = '#b9cbd0';ctx.fillText(atlasMonthLabels[month], start.x - 9, start.y + 20 + (lastYear === firstYear ? 4 : 0));}const nodes = points.map(point => {3 unmodified linesfor (let i = 1; i < nodes.length; i++) {const before = nodes[i - 1];const after = nodes[i];if (after.point.index - before.point.index === 1) line([before, after], '#90b7ba78', 1.6);}hitTargets.current = [...nodes].sort((a, b) => a.depth - b.depth);for (const node of hitTargets.current) {const active = node.point.key === selection;ctx.beginPath();ctx.arc(node.x, node.y, active ? 8 : 3.4 + node.fraction * 1.2, 0, Math.PI * 2);ctx.fillStyle = gridDemandColor(node.fraction);ctx.fill();if (active) {ctx.strokeStyle = '#ffffff';ctx.lineWidth = 2.5;ctx.stroke();}75 unmodified lines<style>{gridAtlasStyles}</style><div className="atlas-heading"><div><p className="atlas-kicker">{publisher} grid history</p><h2>Grid Atlas</h2><p>{market.scope} · {points[0].key} to {latest.key}</p></div><div className="atlas-modes" role="group" aria-label="Visualization"><button type="button" aria-pressed={mode === 'wheel'} onClick={() => setMode('wheel')}>Seasonal orbit</button><button type="button" aria-pressed={mode === 'calendar'} onClick={() => setMode('calendar')}>Calendar</button></div>11 unmodified linesreturn point ? <button type="button" key={label} aria-pressed={point.key === selected.key}aria-label={`${label} ${year}, ${num(point.value, 1)} GWh`}title={`${label} ${year} · ${num(point.value, 1)} GWh`}style={{backgroundColor: gridDemandColor(amount)}}onClick={() => setSelectedKey(point.key)} /> :<span key={label} className="atlas-gap" title={`${label} ${year} · no record`}>—</span>;})}</div>)}</div>}<div className="atlas-scale"><p>{mode === 'wheel' ? 'One turn per year. Distance from the centre shows demand. Drag to rotate.' : 'Select a month to inspect demand. A dash marks a gap in the record.'}</p><div className="atlas-demand-key" aria-label={`Grid demand from ${num(low)} to ${num(high)} GWh`}><span>{num(low)}</span><span className="atlas-demand-ramp" aria-hidden="true"style={{background: `linear-gradient(90deg, ${gridDemandStops.map((_, index) => gridDemandColor(index / (gridDemandStops.length - 1))).join(', ')})`}} /><span>{num(high)} GWh</span></div></div></div><div className="atlas-detail"><label>History range<select value={windowSize} onChange={event => setWindowSize(event.target.value)}>15 unmodified lines}const gridAtlasStyles = `.grid-atlas{color:#1b2e37}.atlas-heading,.atlas-modes,.atlas-camera,.atlas-scale{display:flex;align-items:center;gap:8px}.atlas-heading{justify-content:space-between;flex-wrap:wrap;margin-bottom:18px}.atlas-heading h2{font-size:clamp(23px,3.6vw,33px);letter-spacing:-.045em;margin:0;line-height:1.08}.atlas-heading p{margin:6px 0 0;color:#52666a;font-size:12px}.atlas-heading .atlas-kicker{color:#306f5e;font-size:10px;font-weight:700;letter-spacing:.13em;text-transform:uppercase;margin:0 0 6px}.atlas-modes{padding:4px;gap:3px;border-radius:9px;background:#e9efec}.atlas-modes button,.atlas-camera button{border-radius:6px;padding:7px 11px;cursor:pointer;font-size:11px;font-weight:700}.atlas-modes button{color:#526761;background:transparent}.atlas-modes button[aria-pressed=true]{background:#fff;color:#234d3d;box-shadow:0 2px 6px #18332b14}.atlas-modes button:hover{color:#1b4f41}.atlas-body{display:grid;grid-template-columns:minmax(0,1fr) minmax(175px,.36fr);gap:16px}.atlas-visual{min-width:0}.atlas-wheel{overflow:hidden;position:relative;border-radius:10px;background:radial-gradient(ellipse at 47% 43%,#203947,#13212e 78%);border:1px solid #233746}.atlas-wheel canvas{display:block;width:100%;height:clamp(285px,43vw,430px);touch-action:pan-y;cursor:grab}.atlas-wheel canvas:active{cursor:grabbing}.atlas-camera{position:absolute;bottom:10px;left:50%;transform:translateX(-50%);white-space:nowrap}.atlas-camera button{background:#1f3540;color:#e3eeef;border:1px solid #55717a}.atlas-camera button:hover{background:#2c4b52}.atlas-detail{display:grid;align-content:start;gap:17px;background:#f5f8f7;border:1px solid #e2e9e6;border-radius:10px;padding:15px}.atlas-detail label{display:grid;gap:6px;font-size:12px;font-weight:700;color:#3b5651}.atlas-detail select{width:100%;border-radius:7px;padding:7px;background:#fff;color:#1b2e37;border:1px solid #ccdad5}.atlas-detail input{width:100%;min-width:0;accent-color:#238b70}.atlas-detail a{font-size:12px;font-weight:700;color:#176653;text-underline-offset:3px}.atlas-readout span,.atlas-readout p{font-size:12px;color:#52666a;margin:4px 0}.atlas-readout strong{display:block;font-size:clamp(25px,4vw,38px);letter-spacing:-.05em;line-height:1.15;overflow-wrap:anywhere}.atlas-readout small{font-size:13px;letter-spacing:0}.atlas-scale{justify-content:space-between;flex-wrap:wrap;color:#52666a;font-size:12px;margin:8px 0 0}.atlas-scale p{margin:0}.atlas-demand-key{display:flex;align-items:center;gap:6px;white-space:nowrap;font-variant-numeric:tabular-nums}.atlas-demand-ramp{display:block;width:clamp(66px,10vw,108px);height:7px;border-radius:99px}.atlas-calendar{overflow:auto;max-height:430px;border:1px solid #e2e9e6;border-radius:10px;padding:10px;background:#f5f8f7}.atlas-calendar-row{min-width:430px;display:grid;grid-template-columns:45px repeat(12,minmax(25px,1fr));gap:4px;align-items:center;text-align:center;color:#42595a;font-size:10px;padding:3px 0}.atlas-calendar-row button,.atlas-gap{height:23px;border:1px solid transparent;border-radius:4px}.atlas-calendar-row button{cursor:pointer}.atlas-calendar-row button[aria-pressed=true]{border:2px solid #13212e;box-shadow:inset 0 0 0 1px #fff}.grid-atlas button:focus-visible,.grid-atlas select:focus-visible,.grid-atlas input:focus-visible,.grid-atlas a:focus-visible{outline:2px solid #1b7d65;outline-offset:2px}.atlas-camera button:focus-visible{outline-color:#d9efea}@media(max-width:820px){.atlas-body{grid-template-columns:minmax(0,1fr)}}`;
App.jsx+62-34