[object Object]

← back to Nationalrealestate

M3: ACS 2023 5-yr county demographics (19.3k rows), FHFA HPI all-transactions metro+state w/ MSAD primary-division crosswalk (5.2k rows), derived affordability/rent_yield/zhvi_yoy (9k rows), /api/market endpoint, market.html detail page w/ vendored uPlot, map click wired

aae13b5538e7786e38c00ac03c9c2ac31e72bc8f · 2026-07-21 12:55:24 -0700 · Steve Abrams

Files touched

Diff

commit aae13b5538e7786e38c00ac03c9c2ac31e72bc8f
Author: Steve Abrams <steve@designerwallcoverings.com>
Date:   Tue Jul 21 12:55:24 2026 -0700

    M3: ACS 2023 5-yr county demographics (19.3k rows), FHFA HPI all-transactions metro+state w/ MSAD primary-division crosswalk (5.2k rows), derived affordability/rent_yield/zhvi_yoy (9k rows), /api/market endpoint, market.html detail page w/ vendored uPlot, map click wired
---
 SOURCES.md                      |  18 +++++
 data/crosswalk-unmatched.json   | 122 ++++++++++++++++++++++++++++++
 public/index.html               |   6 +-
 public/market.html              | 164 ++++++++++++++++++++++++++++++++++++++++
 public/vendor/uPlot.iife.min.js |   2 +
 public/vendor/uPlot.min.css     |   1 +
 src/ingest/census_acs.ts        | 116 ++++++++++++++++++++++++++++
 src/ingest/derive_metrics.ts    |  85 +++++++++++++++++++++
 src/ingest/fhfa_hpi.ts          | 151 ++++++++++++++++++++++++++++++++++++
 src/server/index.ts             |  96 +++++++++++++++++++++++
 10 files changed, 756 insertions(+), 5 deletions(-)

diff --git a/SOURCES.md b/SOURCES.md
index 9925db0..b8e02bf 100644
--- a/SOURCES.md
+++ b/SOURCES.md
@@ -58,3 +58,21 @@ Metrics ingested per row: `median_sale_price`, `median_sale_price_yoy`, `homes_s
 
 - `data/crosswalk-overrides.json` — manual overrides consulted BEFORE fuzzy matching. Shape: `{ "zillow": { "<RegionName>": "<canonical_key>" }, "redfin": { "<REGION or TABLE_ID>": "<canonical_key>" } }`.
 - `data/crosswalk-unmatched.json` — written by each run; unmatched regions are SKIPPED, never guessed.
+
+## Census ACS 5-year 2023 (api.census.gov) — source `acs` (M3, probed 2026-07-21)
+
+- URL: `https://api.census.gov/data/2023/acs/acs5?get=NAME,B19013_001E,B25077_001E,B25064_001E,B01003_001E,B25002_001E,B25002_003E,B25003_001E,B25003_003E&for=county:*`
+- **Keyless FAILED**: the keyless call 302-redirects to `api.census.gov/data/missing_key.html` — a key is now required even at low volume. Ran with `CENSUS_API_KEY` from `~/Projects/secrets-manager/.env` → 200, 3,223 rows (header + 3,222 counties), every county FIPS matched.
+- Format: JSON array-of-arrays, row 0 = header, then `[NAME, ...values, state, county]`. FIPS = `state`(2) + `county`(3) zero-padded.
+- Metrics (period `2023-07-01`): median_hh_income (B19013), median_home_value_acs (B25077), median_gross_rent (B25064), population (B01003, also written to `region.population`), vacancy_rate (B25002_003/B25002_001), renter_share (B25003_003/B25003_001). Negative sentinels (e.g. -666666666) skipped.
+
+## FHFA HPI (fhfa.gov) — source `fhfa` (M3, probed 2026-07-21)
+
+- **URL DRIFT**: the documented `https://www.fhfa.gov/DataTools/Downloads/Documents/HPI/HPI_master.csv` → 404 (Drupal 11 rebuild). Current path: `https://www.fhfa.gov/hpi/download/monthly/hpi_master.csv` → 200, text/csv, ~18.9 MB (serves the full master file despite the `/monthly/` path segment).
+- **Flavor choice**: `purchase-only` quarterly covers only **100** MSA place_ids vs **410** for `all-transactions` → we use `hpi_type='traditional'`, `hpi_flavor='all-transactions'`, `frequency='quarterly'`, levels `MSA` + `State`. Value = `index_nsa` (index_sa blank for many MSAs).
+- Metro crosswalk: `place_id` IS the CBSA code for MSA rows (verified against region.cbsa_code, 373 direct matches). For the largest metros FHFA lists **(MSAD) divisions instead of the parent CBSA** — the primary division (first-named city == parent CBSA first city, e.g. `31084 Los Angeles-Long Beach-Glendale, CA (MSAD)` → `metro:31080`) is matched via the metro city-prefix matcher (match_method `msad_primary_city`, never overwrites a direct cbsa match); 24 secondary divisions (Anaheim, Camden, Cambridge…) stay unmatched-and-skipped by design. Total metro coverage: 386/935. State: 2-letter `place_id` → region.state_code (51/51).
+- Period = quarter-end date (Q1→03-31 … Q4→12-31), last 12 quarters kept. Latest at probe: 2026Q1.
+
+## Derived metrics — source `derived` (M3)
+
+- `affordability` = latest zhvi / ACS median_hh_income (annual ACS joins to any zhvi month); `rent_yield` = (zori×12)/zhvi at latest common period; `zhvi_yoy` = zhvi latest vs 12 months prior (fraction). period = the zhvi period used. Counts on first run: affordability 3,063 · rent_yield 2,047 · zhvi_yoy 3,918.
diff --git a/data/crosswalk-unmatched.json b/data/crosswalk-unmatched.json
index 61f334b..fff4b8b 100644
--- a/data/crosswalk-unmatched.json
+++ b/data/crosswalk-unmatched.json
@@ -999,5 +999,127 @@
       "region": "West Point, MS metro area",
       "stateCode": "MS"
     }
+  ],
+  "fhfa": [
+    {
+      "level": "MSA",
+      "place_id": "11244",
+      "place_name": "Anaheim-Santa Ana-Irvine, CA (MSAD)"
+    },
+    {
+      "level": "MSA",
+      "place_id": "11694",
+      "place_name": "Arlington-Alexandria-Reston, VA-WV (MSAD)"
+    },
+    {
+      "level": "MSA",
+      "place_id": "15764",
+      "place_name": "Cambridge-Newton-Framingham, MA (MSAD)"
+    },
+    {
+      "level": "MSA",
+      "place_id": "15804",
+      "place_name": "Camden, NJ (MSAD)"
+    },
+    {
+      "level": "MSA",
+      "place_id": "20994",
+      "place_name": "Elgin, IL (MSAD)"
+    },
+    {
+      "level": "MSA",
+      "place_id": "21794",
+      "place_name": "Everett, WA (MSAD)"
+    },
+    {
+      "level": "MSA",
+      "place_id": "22744",
+      "place_name": "Fort Lauderdale-Pompano Beach-Sunrise, FL (MSAD)"
+    },
+    {
+      "level": "MSA",
+      "place_id": "23104",
+      "place_name": "Fort Worth-Arlington-Grapevine, TX (MSAD)"
+    },
+    {
+      "level": "MSA",
+      "place_id": "23224",
+      "place_name": "Frederick-Gaithersburg-Bethesda, MD (MSAD)"
+    },
+    {
+      "level": "MSA",
+      "place_id": "29404",
+      "place_name": "Lake County, IL (MSAD)"
+    },
+    {
+      "level": "MSA",
+      "place_id": "29414",
+      "place_name": "Lake County-Porter County-Jasper County, IN (MSAD)"
+    },
+    {
+      "level": "MSA",
+      "place_id": "29484",
+      "place_name": "Lakewood-New Brunswick, NJ (MSAD)"
+    },
+    {
+      "level": "MSA",
+      "place_id": "31924",
+      "place_name": "Marietta, GA (MSAD)"
+    },
+    {
+      "level": "MSA",
+      "place_id": "33874",
+      "place_name": "Montgomery County-Bucks County-Chester County, PA (MSAD)"
+    },
+    {
+      "level": "MSA",
+      "place_id": "35004",
+      "place_name": "Nassau County-Suffolk County, NY (MSAD)"
+    },
+    {
+      "level": "MSA",
+      "place_id": "35084",
+      "place_name": "Newark, NJ (MSAD)"
+    },
+    {
+      "level": "MSA",
+      "place_id": "36084",
+      "place_name": "Oakland-Fremont-Berkeley, CA (MSAD)"
+    },
+    {
+      "level": "MSA",
+      "place_id": "40484",
+      "place_name": "Rockingham County-Strafford County, NH (MSAD)"
+    },
+    {
+      "level": "MSA",
+      "place_id": "41304",
+      "place_name": "St. Petersburg-Clearwater-Largo, FL (MSAD)"
+    },
+    {
+      "level": "MSA",
+      "place_id": "42034",
+      "place_name": "San Rafael, CA (MSAD)"
+    },
+    {
+      "level": "MSA",
+      "place_id": "45104",
+      "place_name": "Tacoma-Lakewood, WA (MSAD)"
+    },
+    {
+      "level": "MSA",
+      "place_id": "47664",
+      "place_name": "Warren-Troy-Farmington Hills, MI (MSAD)"
+    },
+    {
+      "level": "MSA",
+      "place_id": "48424",
+      "place_name": "West Palm Beach-Boca Raton-Delray Beach, FL (MSAD)"
+    },
+    {
+      "level": "MSA",
+      "place_id": "48864",
+      "place_name": "Wilmington, DE-MD-NJ (MSAD)"
+    }
   ]
 }
\ No newline at end of file
diff --git a/public/index.html b/public/index.html
index 874e5e8..b7a6ba2 100644
--- a/public/index.html
+++ b/public/index.html
@@ -157,11 +157,7 @@ function onEachFeature(f, layer){
     ).openTooltip();
   });
   layer.on('mouseout', () => { geoLayer.resetStyle(layer); layer.closeTooltip(); });
-  layer.on('click', () => {
-    const url = `/market.html?key=county:${f.id}`;
-    // detail page lands in M3 — href is wired, alert placeholder until then
-    alert(`${f.properties.NAME} ${f.properties.LSAD || 'County'}\nDetail page lands in M3:\n${url}`);
-  });
+  layer.on('click', () => { location.href = `/market.html?key=county:${f.id}`; });
 }
 
 (async function init(){
diff --git a/public/market.html b/public/market.html
new file mode 100644
index 0000000..ccce346
--- /dev/null
+++ b/public/market.html
@@ -0,0 +1,164 @@
+<!doctype html>
+<html lang="en">
+<head>
+<meta charset="utf-8">
+<meta name="viewport" content="width=device-width, initial-scale=1">
+<title>USRealEstate — Market Detail</title>
+<link rel="stylesheet" href="/vendor/uPlot.min.css">
+<style>
+  :root{--bg:#0a0d13;--panel:#11151d;--line:#222936;--fg:#e8ecf2;--muted:#8a93a3;--gold:#c8a24b;
+    --green:#5fae7c;--red:#c96a5a;}
+  *{box-sizing:border-box;}
+  html,body{margin:0;background:var(--bg);color:var(--fg);
+    font:14px/1.5 -apple-system,Segoe UI,Roboto,sans-serif;}
+  #topbar{position:sticky;top:0;z-index:1000;display:flex;align-items:center;gap:18px;
+    padding:10px 18px;background:rgba(17,21,29,.94);border-bottom:1px solid var(--line);backdrop-filter:blur(6px);}
+  #topbar .brand{font-size:16px;font-weight:700;white-space:nowrap;}
+  #topbar .brand b{color:var(--gold);}
+  nav{display:flex;gap:14px;font-size:13px;}
+  nav a{color:var(--muted);text-decoration:none;} nav a:hover,nav a.active{color:var(--gold);}
+  main{max-width:1180px;margin:0 auto;padding:24px 18px 60px;}
+  #hdr{display:flex;align-items:baseline;gap:18px;flex-wrap:wrap;margin-bottom:8px;}
+  #hdr h1{margin:0;font-size:26px;font-weight:700;}
+  #hdr .st{color:var(--muted);font-size:15px;}
+  #hdr .zhvi{font-size:22px;color:var(--gold);font-variant-numeric:tabular-nums;font-weight:700;}
+  .badge{display:inline-block;padding:3px 10px;border-radius:14px;font-size:12px;font-weight:700;
+    font-variant-numeric:tabular-nums;border:1px solid var(--line);}
+  .badge.up{color:var(--green);border-color:var(--green);}
+  .badge.down{color:var(--red);border-color:var(--red);}
+  #sub{color:var(--muted);font-size:12px;margin-bottom:20px;}
+  .grid2{display:grid;grid-template-columns:repeat(auto-fit,minmax(440px,1fr));gap:16px;}
+  .panel{background:var(--panel);border:1px solid var(--line);border-radius:12px;padding:14px 16px;}
+  .panel h3{margin:0 0 8px;font-size:13px;color:var(--gold);font-weight:700;text-transform:uppercase;
+    letter-spacing:.5px;}
+  .panel .nodata{color:var(--muted);font-size:12px;padding:30px 0;text-align:center;}
+  #stats{display:grid;grid-template-columns:repeat(auto-fill,minmax(150px,1fr));gap:10px;}
+  .stat{background:var(--bg);border:1px solid var(--line);border-radius:10px;padding:10px 12px;}
+  .stat .k{font-size:11px;color:var(--muted);text-transform:uppercase;letter-spacing:.4px;}
+  .stat .v{font-size:17px;font-weight:700;font-variant-numeric:tabular-nums;margin-top:2px;}
+  #foot{margin-top:22px;color:var(--muted);font-size:11px;}
+  .u-legend{color:var(--muted);font-size:11px;}
+  .u-legend .u-label{color:var(--muted);}
+</style>
+</head>
+<body>
+<div id="topbar">
+  <div class="brand"><b>USRealEstate</b> — Market Detail</div>
+  <nav>
+    <a href="/">Map</a>
+    <a href="/markets.html">Markets</a>
+    <a href="/watchlist.html">Watchlist</a>
+    <a href="/admin.html">Admin</a>
+  </nav>
+</div>
+<main>
+  <div id="hdr"><h1>Loading…</h1></div>
+  <div id="sub"></div>
+  <div class="grid2" id="charts">
+    <div class="panel"><h3>ZHVI — Home Value Index</h3><div id="c_zhvi"></div></div>
+    <div class="panel"><h3>Median Sale Price</h3><div id="c_msp"></div></div>
+    <div class="panel"><h3>Inventory + New Listings</h3><div id="c_inv"></div></div>
+    <div class="panel"><h3>Days on Market + Months of Supply</h3><div id="c_dom"></div></div>
+    <div class="panel"><h3>ZORI — Observed Rent Index</h3><div id="c_zori"></div></div>
+    <div class="panel"><h3>FHFA HPI (all-transactions, NSA)</h3><div id="c_hpi"></div></div>
+  </div>
+  <div class="panel" style="margin-top:16px;">
+    <h3>Demographics &amp; Derived</h3>
+    <div id="stats"></div>
+  </div>
+  <div class="panel" style="margin-top:16px;">
+    <h3>Parcels</h3>
+    <div class="nodata">Parcels — county data not yet loaded</div>
+  </div>
+  <div id="foot">Income, rent, population, vacancy, renter share: ACS 2023 5-yr vintage.
+    ZHVI/ZORI: Zillow Research. Sale metrics: Redfin Data Center. HPI: FHFA.</div>
+</main>
+
+<script src="/vendor/uPlot.iife.min.js"></script>
+<script>
+const qs = new URLSearchParams(location.search);
+const key = qs.get('key') || 'county:06037';
+
+const usd0 = v => v == null ? '—' : '$' + Math.round(v).toLocaleString();
+const int0 = v => v == null ? '—' : Math.round(v).toLocaleString();
+const pct1 = v => v == null ? '—' : (v * 100).toFixed(1) + '%';
+const num2 = v => v == null ? '—' : (+v).toFixed(2);
+
+const AXIS = { stroke: '#8a93a3', grid: { stroke: '#222936', width: 1 }, ticks: { stroke: '#222936' },
+  font: '11px -apple-system, Segoe UI, Roboto, sans-serif' };
+
+function toSeries(pairs){
+  return [pairs.map(p => new Date(p[0] + 'T00:00:00Z').getTime() / 1000), pairs.map(p => p[1])];
+}
+
+function chart(elId, entries, fmt){
+  // entries: [{label, pairs, color, dash?}] — aligned onto the union of timestamps
+  const el = document.getElementById(elId);
+  const present = entries.filter(e => e.pairs && e.pairs.length);
+  if (!present.length){ el.innerHTML = '<div class="nodata">no data for this region</div>'; return; }
+  const tsSet = new Set();
+  for (const e of present) for (const p of e.pairs) tsSet.add(new Date(p[0] + 'T00:00:00Z').getTime() / 1000);
+  const ts = [...tsSet].sort((a, b) => a - b);
+  const idx = new Map(ts.map((t, i) => [t, i]));
+  const data = [ts];
+  for (const e of present){
+    const col = new Array(ts.length).fill(null);
+    for (const p of e.pairs) col[idx.get(new Date(p[0] + 'T00:00:00Z').getTime() / 1000)] = p[1];
+    data.push(col);
+  }
+  const w = el.closest('.panel').clientWidth - 32;
+  new uPlot({
+    width: Math.max(320, w), height: 220,
+    cursor: { points: { size: 6 } },
+    scales: { x: { time: true } },
+    axes: [ { ...AXIS }, { ...AXIS, values: (u, vals) => vals.map(v => fmt(v)) } ],
+    series: [ {},
+      ...present.map(e => ({ label: e.label, stroke: e.color, width: 2, dash: e.dash,
+        points: { show: false }, value: (u, v) => fmt(v) })) ],
+  }, data, el);
+}
+
+(async function init(){
+  const res = await fetch('/api/market?key=' + encodeURIComponent(key));
+  if (!res.ok){ document.querySelector('#hdr h1').textContent = 'Region not found: ' + key; return; }
+  const d = await res.json();
+  const { region, series, latest } = d;
+
+  document.title = 'USRealEstate — ' + region.name;
+  const hdr = document.getElementById('hdr');
+  const yoy = latest.zhvi_yoy;
+  hdr.innerHTML = `<h1>${region.name}</h1><span class="st">${region.state_code || ''} · ${region.region_type}</span>` +
+    `<span class="zhvi">${usd0(latest.zhvi)}</span>` +
+    (yoy != null ? `<span class="badge ${yoy >= 0 ? 'up' : 'down'}">${yoy >= 0 ? '▲' : '▼'} ${pct1(Math.abs(yoy))} YoY</span>` : '');
+  document.getElementById('sub').textContent =
+    `${region.canonical_key} · population ${int0(region.population)} · 36-month history, all sources`;
+
+  chart('c_zhvi', [{ label: 'ZHVI', pairs: series.zhvi, color: '#c8a24b' }], usd0);
+  chart('c_msp', [{ label: 'Median Sale', pairs: series.median_sale_price, color: '#5f9ac0' }], usd0);
+  chart('c_inv', [
+    { label: 'Inventory', pairs: series.inventory, color: '#c8a24b' },
+    { label: 'New Listings', pairs: series.new_listings, color: '#5fae7c' },
+  ], int0);
+  chart('c_dom', [
+    { label: 'DOM', pairs: series.dom, color: '#c96a5a' },
+    { label: 'Months Supply', pairs: series.months_of_supply, color: '#8a93a3', dash: [5, 5] },
+  ], v => v == null ? '—' : (+v).toFixed(1));
+  chart('c_zori', [{ label: 'ZORI', pairs: series.zori, color: '#5fae7c' }], usd0);
+  chart('c_hpi', [{ label: 'HPI', pairs: series.hpi, color: '#b59b5c' }], v => v == null ? '—' : Math.round(v));
+
+  const STATS = [
+    ['Median HH Income', usd0(latest.median_hh_income)],
+    ['Median Gross Rent', usd0(latest.median_gross_rent)],
+    ['Population', int0(latest.population ?? region.population)],
+    ['Vacancy Rate', pct1(latest.vacancy_rate)],
+    ['Renter Share', pct1(latest.renter_share)],
+    ['Affordability (ZHVI/Income)', num2(latest.affordability)],
+    ['Rent Yield (ZORI×12/ZHVI)', pct1(latest.rent_yield)],
+    ['Sale-to-List', pct1(latest.sale_to_list)],
+  ];
+  document.getElementById('stats').innerHTML = STATS.map(([k, v]) =>
+    `<div class="stat"><div class="k">${k}</div><div class="v">${v}</div></div>`).join('');
+})();
+</script>
+</body>
+</html>
diff --git a/public/vendor/uPlot.iife.min.js b/public/vendor/uPlot.iife.min.js
new file mode 100644
index 0000000..047f29b
--- /dev/null
+++ b/public/vendor/uPlot.iife.min.js
@@ -0,0 +1,2 @@
+/*! https://github.com/leeoniya/uPlot (v1.6.32) */
+var uPlot=function(){"use strict";const l="u-off",e="u-label",t="width",n="height",i="top",o="bottom",s="left",r="right",u="#000",a=u+"0",f="mousemove",c="mousedown",h="mouseup",d="mouseenter",p="mouseleave",m="dblclick",g="change",x="dppxchange",w="--",_="undefined"!=typeof window,b=_?document:null,v=_?window:null,k=_?navigator:null;let y,M;function S(l,e){if(null!=e){let t=l.classList;!t.contains(e)&&t.add(e)}}function T(l,e){let t=l.classList;t.contains(e)&&t.remove(e)}function E(l,e,t){l.style[e]=t+"px"}function z(l,e,t,n){let i=b.createElement(l);return null!=e&&S(i,e),null!=t&&t.insertBefore(i,n),i}function D(l,e){return z("div",l,e)}const P=new WeakMap;function A(e,t,n,i,o){let s="translate("+t+"px,"+n+"px)";s!=P.get(e)&&(e.style.transform=s,P.set(e,s),0>t||0>n||t>i||n>o?S(e,l):T(e,l))}const W=new WeakMap;function Y(l,e,t){let n=e+t;n!=W.get(l)&&(W.set(l,n),l.style.background=e,l.style.borderColor=t)}const C=new WeakMap;function H(l,e,t,n){let i=e+""+t;i!=C.get(l)&&(C.set(l,i),l.style.height=t+"px",l.style.width=e+"px",l.style.marginLeft=n?-e/2+"px":0,l.style.marginTop=n?-t/2+"px":0)}const F={passive:!0},R={...F,capture:!0};function G(l,e,t,n){e.addEventListener(l,t,n?R:F)}function I(l,e,t){e.removeEventListener(l,t,F)}function L(l,e,t,n){let i;t=t||0;let o=2147483647>=(n=n||e.length-1);for(;n-t>1;)i=o?t+n>>1:sl((t+n)/2),l>e[i]?t=i:n=i;return l-e[t]>e[n]-l?n:t}function O(l){return(e,t,n)=>{let i=-1,o=-1;for(let o=t;n>=o;o++)if(l(e[o])){i=o;break}for(let i=n;i>=t;i--)if(l(e[i])){o=i;break}return[i,o]}}_&&function l(){let e=devicePixelRatio;y!=e&&(y=e,M&&I(g,M,l),M=matchMedia(`(min-resolution: ${y-.001}dppx) and (max-resolution: ${y+.001}dppx)`),G(g,M,l),v.dispatchEvent(new CustomEvent(x)))}();const N=l=>null!=l,j=l=>null!=l&&l>0,U=O(N),V=O(j);function B(l,e,t,n){let i=hl(l),o=hl(e);l==e&&(-1==i?(l*=t,e/=t):(l/=t,e*=t));let s=10==t?dl:pl,r=1==o?ul:sl,u=(1==i?sl:ul)(s(ol(l))),a=r(s(ol(e))),f=cl(t,u),c=cl(t,a);return 10==t&&(0>u&&(f=Al(f,-u)),0>a&&(c=Al(c,-a))),n||2==t?(l=f*i,e=c*o):(l=Pl(l,f),e=Dl(e,c)),[l,e]}function $(l,e,t,n){let i=B(l,e,t,n);return 0==l&&(i[0]=0),0==e&&(i[1]=0),i}const J=.1,q={mode:3,pad:J},K={pad:0,soft:null,mode:0},X={min:K,max:K};function Z(l,e,t,n){return Ol(t)?ll(l,e,t):(K.pad=t,K.soft=n?0:null,K.mode=n?3:0,ll(l,e,X))}function Q(l,e){return null==l?e:l}function ll(l,e,t){let n=t.min,i=t.max,o=Q(n.pad,0),s=Q(i.pad,0),r=Q(n.hard,-gl),u=Q(i.hard,gl),a=Q(n.soft,gl),f=Q(i.soft,-gl),c=Q(n.mode,0),h=Q(i.mode,0),d=e-l,p=dl(d),m=fl(ol(l),ol(e)),g=dl(m),x=ol(g-p);(1e-24>d||x>10)&&(d=0,0!=l&&0!=e||(d=1e-24,2==c&&a!=gl&&(o=0),2==h&&f!=-gl&&(s=0)));let w=d||m||1e3,_=dl(w),b=cl(10,sl(_)),v=Al(Pl(l-w*(0==d?0==l?.1:1:o),b/10),24),k=a>l||1!=c&&(3!=c||v>a)&&(2!=c||a>v)?gl:a,y=fl(r,k>v&&l>=k?k:al(k,v)),M=Al(Dl(e+w*(0==d?0==e?.1:1:s),b/10),24),S=e>f||1!=h&&(3!=h||f>M)&&(2!=h||M>f)?-gl:f,T=al(u,M>S&&S>=e?S:fl(S,M));return y==T&&0==y&&(T=100),[y,T]}const el=new Intl.NumberFormat(_?k.language:"en-US"),tl=l=>el.format(l),nl=Math,il=nl.PI,ol=nl.abs,sl=nl.floor,rl=nl.round,ul=nl.ceil,al=nl.min,fl=nl.max,cl=nl.pow,hl=nl.sign,dl=nl.log10,pl=nl.log2,ml=(l,e=1)=>nl.asinh(l/e),gl=1/0;function xl(l){return 1+(0|dl((l^l>>31)-(l>>31)))}function wl(l,e,t){return al(fl(l,e),t)}function _l(l){return"function"==typeof l}function bl(l){return _l(l)?l:()=>l}const vl=l=>l,kl=(l,e)=>e,yl=()=>null,Ml=()=>!0,Sl=(l,e)=>l==e,Tl=/\.\d*?(?=9{6,}|0{6,})/gm,El=l=>{if(Il(l)||Wl.has(l))return l;const e=""+l,t=e.match(Tl);if(null==t)return l;let n=t[0].length-1;if(-1!=e.indexOf("e-")){let[l,t]=e.split("e");return+`${El(l)}e${t}`}return Al(l,n)};function zl(l,e){return El(Al(El(l/e))*e)}function Dl(l,e){return El(ul(El(l/e))*e)}function Pl(l,e){return El(sl(El(l/e))*e)}function Al(l,e=0){if(Il(l))return l;let t=10**e;return rl(l*t*(1+Number.EPSILON))/t}const Wl=new Map;function Yl(l){return((""+l).split(".")[1]||"").length}function Cl(l,e,t,n){let i=[],o=n.map(Yl);for(let s=e;t>s;s++){let e=ol(s),t=Al(cl(l,s),e);for(let r=0;n.length>r;r++){let u=10==l?+`${n[r]}e${s}`:n[r]*t,a=(0>s?e:0)+(o[r]>s?o[r]:0),f=10==l?u:Al(u,a);i.push(f),Wl.set(f,a)}}return i}const Hl={},Fl=[],Rl=[null,null],Gl=Array.isArray,Il=Number.isInteger;function Ll(l){return"string"==typeof l}function Ol(l){let e=!1;if(null!=l){let t=l.constructor;e=null==t||t==Object}return e}function Nl(l){return null!=l&&"object"==typeof l}const jl=Object.getPrototypeOf(Uint8Array),Ul="__proto__";function Vl(l,e=Ol){let t;if(Gl(l)){let n=l.find((l=>null!=l));if(Gl(n)||e(n)){t=Array(l.length);for(let n=0;l.length>n;n++)t[n]=Vl(l[n],e)}else t=l.slice()}else if(l instanceof jl)t=l.slice();else if(e(l)){t={};for(let n in l)n!=Ul&&(t[n]=Vl(l[n],e))}else t=l;return t}function Bl(l){let e=arguments;for(let t=1;e.length>t;t++){let n=e[t];for(let e in n)e!=Ul&&(Ol(l[e])?Bl(l[e],Vl(n[e])):l[e]=Vl(n[e]))}return l}function $l(l,e,t){for(let n,i=0,o=-1;e.length>i;i++){let s=e[i];if(s>o){for(n=s-1;n>=0&&null==l[n];)l[n--]=null;for(n=s+1;t>n&&null==l[n];)l[o=n++]=null}}}const Jl="undefined"==typeof queueMicrotask?l=>Promise.resolve().then(l):queueMicrotask,ql=["January","February","March","April","May","June","July","August","September","October","November","December"],Kl=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];function Xl(l){return l.slice(0,3)}const Zl=Kl.map(Xl),Ql=ql.map(Xl),le={MMMM:ql,MMM:Ql,WWWW:Kl,WWW:Zl};function ee(l){return(10>l?"0":"")+l}const te={YYYY:l=>l.getFullYear(),YY:l=>(l.getFullYear()+"").slice(2),MMMM:(l,e)=>e.MMMM[l.getMonth()],MMM:(l,e)=>e.MMM[l.getMonth()],MM:l=>ee(l.getMonth()+1),M:l=>l.getMonth()+1,DD:l=>ee(l.getDate()),D:l=>l.getDate(),WWWW:(l,e)=>e.WWWW[l.getDay()],WWW:(l,e)=>e.WWW[l.getDay()],HH:l=>ee(l.getHours()),H:l=>l.getHours(),h:l=>{let e=l.getHours();return 0==e?12:e>12?e-12:e},AA:l=>12>l.getHours()?"AM":"PM",aa:l=>12>l.getHours()?"am":"pm",a:l=>12>l.getHours()?"a":"p",mm:l=>ee(l.getMinutes()),m:l=>l.getMinutes(),ss:l=>ee(l.getSeconds()),s:l=>l.getSeconds(),fff:l=>function(l){return(10>l?"00":100>l?"0":"")+l}(l.getMilliseconds())};function ne(l,e){e=e||le;let t,n=[],i=/\{([a-z]+)\}|[^{]+/gi;for(;t=i.exec(l);)n.push("{"==t[0][0]?te[t[1]]:t[0]);return l=>{let t="";for(let i=0;n.length>i;i++)t+="string"==typeof n[i]?n[i]:n[i](l,e);return t}}const ie=(new Intl.DateTimeFormat).resolvedOptions().timeZone,oe=l=>l%1==0,se=[1,2,2.5,5],re=Cl(10,-32,0,se),ue=Cl(10,0,32,se),ae=ue.filter(oe),fe=re.concat(ue),ce="{YYYY}",he="\n"+ce,de="{M}/{D}",pe="\n"+de,me=pe+"/{YY}",ge="{aa}",xe="{h}:{mm}"+ge,we="\n"+xe,_e=":{ss}",be=null;function ve(l){let e=1e3*l,t=60*e,n=60*t,i=24*n,o=30*i,s=365*i;return[(1==l?Cl(10,0,3,se).filter(oe):Cl(10,-3,0,se)).concat([e,5*e,10*e,15*e,30*e,t,5*t,10*t,15*t,30*t,n,2*n,3*n,4*n,6*n,8*n,12*n,i,2*i,3*i,4*i,5*i,6*i,7*i,8*i,9*i,10*i,15*i,o,2*o,3*o,4*o,6*o,s,2*s,5*s,10*s,25*s,50*s,100*s]),[[s,ce,be,be,be,be,be,be,1],[28*i,"{MMM}",he,be,be,be,be,be,1],[i,de,he,be,be,be,be,be,1],[n,"{h}"+ge,me,be,pe,be,be,be,1],[t,xe,me,be,pe,be,be,be,1],[e,_e,me+" "+xe,be,pe+" "+xe,be,we,be,1],[l,_e+".{fff}",me+" "+xe,be,pe+" "+xe,be,we,be,1]],function(e){return(r,u,a,f,c,h)=>{let d=[],p=c>=s,m=c>=o&&s>c,g=e(a),x=Al(g*l,3),w=Pe(g.getFullYear(),p?0:g.getMonth(),m||p?1:g.getDate()),_=Al(w*l,3);if(m||p){let t=m?c/o:0,n=p?c/s:0,i=x==_?x:Al(Pe(w.getFullYear()+n,w.getMonth()+t,1)*l,3),r=new Date(rl(i/l)),u=r.getFullYear(),a=r.getMonth();for(let o=0;f>=i;o++){let s=Pe(u+n*o,a+t*o,1),r=s-e(Al(s*l,3));i=Al((+s+r)*l,3),i>f||d.push(i)}}else{let o=i>c?c:i,s=_+(sl(a)-sl(x))+Dl(x-_,o);d.push(s);let p=e(s),m=p.getHours()+p.getMinutes()/t+p.getSeconds()/n,g=c/n,w=h/r.axes[u]._space;for(;s=Al(s+c,1==l?0:3),f>=s;)if(g>1){let l=sl(Al(m+g,6))%24,t=e(s).getHours()-l;t>1&&(t=-1),s-=t*n,m=(m+g)%24,.7>Al((s-d[d.length-1])/c,3)*w||d.push(s)}else d.push(s)}return d}}]}const[ke,ye,Me]=ve(1),[Se,Te,Ee]=ve(.001);function ze(l,e){return l.map((l=>l.map(((t,n)=>0==n||8==n||null==t?t:e(1==n||0==l[8]?t:l[1]+t)))))}function De(l,e){return(t,n,i,o,s)=>{let r,u,a,f,c,h,d=e.find((l=>s>=l[0]))||e[e.length-1];return n.map((e=>{let t=l(e),n=t.getFullYear(),i=t.getMonth(),o=t.getDate(),s=t.getHours(),p=t.getMinutes(),m=t.getSeconds(),g=n!=r&&d[2]||i!=u&&d[3]||o!=a&&d[4]||s!=f&&d[5]||p!=c&&d[6]||m!=h&&d[7]||d[1];return r=n,u=i,a=o,f=s,c=p,h=m,g(t)}))}}function Pe(l,e,t){return new Date(l,e,t)}function Ae(l,e){return e(l)}function We(l,e){return(t,n,i,o)=>null==o?w:e(l(n))}Cl(2,-53,53,[1]);const Ye={show:!0,live:!0,isolate:!1,mount:()=>{},markers:{show:!0,width:2,stroke:function(l,e){let t=l.series[e];return t.width?t.stroke(l,e):t.points.width?t.points.stroke(l,e):null},fill:function(l,e){return l.series[e].fill(l,e)},dash:"solid"},idx:null,idxs:null,values:[]},Ce=[0,0];function He(l,e,t,n=!0){return l=>{0==l.button&&(!n||l.target==e)&&t(l)}}function Fe(l,e,t,n=!0){return l=>{(!n||l.target==e)&&t(l)}}const Re={show:!0,x:!0,y:!0,lock:!1,move:function(l,e,t){return Ce[0]=e,Ce[1]=t,Ce},points:{one:!1,show:function(l,e){let i=l.cursor.points,o=D(),s=i.size(l,e);E(o,t,s),E(o,n,s);let r=s/-2;E(o,"marginLeft",r),E(o,"marginTop",r);let u=i.width(l,e,s);return u&&E(o,"borderWidth",u),o},size:function(l,e){return l.series[e].points.size},width:0,stroke:function(l,e){let t=l.series[e].points;return t._stroke||t._fill},fill:function(l,e){let t=l.series[e].points;return t._fill||t._stroke}},bind:{mousedown:He,mouseup:He,click:He,dblclick:He,mousemove:Fe,mouseleave:Fe,mouseenter:Fe},drag:{setScale:!0,x:!0,y:!1,dist:0,uni:null,click:(l,e)=>{e.stopPropagation(),e.stopImmediatePropagation()},_x:!1,_y:!1},focus:{dist:(l,e,t,n,i)=>n-i,prox:-1,bias:0},hover:{skip:[void 0],prox:null,bias:0},left:-10,top:-10,idx:null,dataIdx:null,idxs:null,event:null},Ge={show:!0,stroke:"rgba(0,0,0,0.07)",width:2},Ie=Bl({},Ge,{filter:kl}),Le=Bl({},Ie,{size:10}),Oe=Bl({},Ge,{show:!1}),Ne='12px system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"',je="bold "+Ne,Ue={show:!0,scale:"x",stroke:u,space:50,gap:5,alignTo:1,size:50,labelGap:0,labelSize:30,labelFont:je,side:2,grid:Ie,ticks:Le,border:Oe,font:Ne,lineGap:1.5,rotate:0},Ve={show:!0,scale:"x",auto:!1,sorted:1,min:gl,max:-gl,idxs:[]};function Be(l,e){return e.map((l=>null==l?"":tl(l)))}function $e(l,e,t,n,i,o,s){let r=[],u=Wl.get(i)||0;for(let l=t=s?t:Al(Dl(t,i),u);n>=l;l=Al(l+i,u))r.push(Object.is(l,-0)?0:l);return r}function Je(l,e,t,n,i){const o=[],s=l.scales[l.axes[e].scale].log,r=sl((10==s?dl:pl)(t));i=cl(s,r),10==s&&(i=fe[L(i,fe)]);let u=t,a=i*s;10==s&&(a=fe[L(a,fe)]);do{o.push(u),u+=i,10!=s||Wl.has(u)||(u=Al(u,Wl.get(i))),a>u||(a=(i=u)*s,10==s&&(a=fe[L(a,fe)]))}while(n>=u);return o}function qe(l,e,t,n,i){let o=l.scales[l.axes[e].scale].asinh,s=n>o?Je(l,e,fl(o,t),n,i):[o],r=0>n||t>0?[]:[0];return(-o>t?Je(l,e,fl(o,-n),-t,i):[o]).reverse().map((l=>-l)).concat(r,s)}const Ke=/./,Xe=/[12357]/,Ze=/[125]/,Qe=/1/,lt=(l,e,t,n)=>l.map(((l,i)=>4==e&&0==l||i%n==0&&t.test(l.toExponential()[0>l?1:0])?l:null));function et(l,e,t){let n=l.axes[t],i=n.scale,o=l.scales[i],s=l.valToPos,r=n._space,u=s(10,i),a=s(9,i)-u<r?s(7,i)-u<r?s(5,i)-u<r?Qe:Ze:Xe:Ke;if(a==Qe){let l=ol(s(1,i)-u);if(r>l)return lt(e.slice().reverse(),o.distr,a,ul(r/l)).reverse()}return lt(e,o.distr,a,1)}function tt(l,e,t){let n=l.axes[t],i=n.scale,o=n._space,s=l.valToPos,r=ol(s(1,i)-s(2,i));return o>r?lt(e.slice().reverse(),3,Ke,ul(o/r)).reverse():e}function nt(l,e,t,n){return null==n?w:null==e?"":tl(e)}const it={show:!0,scale:"y",stroke:u,space:30,gap:5,alignTo:1,size:50,labelGap:0,labelSize:30,labelFont:je,side:3,grid:Ie,ticks:Le,border:Oe,font:Ne,lineGap:1.5,rotate:0},ot={scale:null,auto:!0,sorted:0,min:gl,max:-gl},st=(l,e,t,n,i)=>i,rt={show:!0,auto:!0,sorted:0,gaps:st,alpha:1,facets:[Bl({},ot,{scale:"x"}),Bl({},ot,{scale:"y"})]},ut={scale:"y",auto:!0,sorted:0,show:!0,spanGaps:!1,gaps:st,alpha:1,points:{show:function(l,e){let{scale:t,idxs:n}=l.series[0],i=l._data[0],o=l.valToPos(i[n[0]],t,!0),s=l.valToPos(i[n[1]],t,!0);return ol(s-o)/(l.series[e].points.space*y)>=n[1]-n[0]},filter:null},values:null,min:gl,max:-gl,idxs:[],path:null,clip:null};function at(l,e,t){return t/10}const ft={time:!0,auto:!0,distr:1,log:10,asinh:1,min:null,max:null,dir:1,ori:0},ct=Bl({},ft,{time:!1,ori:1}),ht={};function dt(l){let e=ht[l];return e||(e={key:l,plots:[],sub(l){e.plots.push(l)},unsub(l){e.plots=e.plots.filter((e=>e!=l))},pub(l,t,n,i,o,s,r){for(let u=0;e.plots.length>u;u++)e.plots[u]!=t&&e.plots[u].pub(l,t,n,i,o,s,r)}},null!=l&&(ht[l]=e)),e}function pt(l,e,t){const n=l.mode,i=l.series[e],o=2==n?l._data[e]:l._data,s=l.scales,r=l.bbox;let u=o[0],a=2==n?o[1]:o[e],f=2==n?s[i.facets[0].scale]:s[l.series[0].scale],c=2==n?s[i.facets[1].scale]:s[i.scale],h=r.left,d=r.top,p=r.width,m=r.height,g=l.valToPosH,x=l.valToPosV;return 0==f.ori?t(i,u,a,f,c,g,x,h,d,p,m,kt,Mt,Tt,zt,Pt):t(i,u,a,f,c,x,g,d,h,m,p,yt,St,Et,Dt,At)}function mt(l,e){let t=0,n=0,i=Q(l.bands,Fl);for(let l=0;i.length>l;l++){let o=i[l];o.series[0]==e?t=o.dir:o.series[1]==e&&(n|=1==o.dir?1:2)}return[t,1==n?-1:2==n?1:3==n?2:0]}function gt(l,e,t,n,i){let o=l.series[e],s=l.scales[2==l.mode?o.facets[1].scale:o.scale];return-1==i?s.min:1==i?s.max:3==s.distr?1==s.dir?s.min:s.max:0}function xt(l,e,t,n,i,o){return pt(l,e,((l,e,s,r,u,a,f,c,h,d,p)=>{let m=l.pxRound;const g=0==r.ori?Mt:St;let x,w;1==r.dir*(0==r.ori?1:-1)?(x=t,w=n):(x=n,w=t);let _=m(a(e[x],r,d,c)),b=m(f(s[x],u,p,h)),v=m(a(e[w],r,d,c)),k=m(f(1==o?u.max:u.min,u,p,h)),y=new Path2D(i);return g(y,v,k),g(y,_,k),g(y,_,b),y}))}function wt(l,e,t,n,i,o){let s=null;if(l.length>0){s=new Path2D;const r=0==e?Tt:Et;let u=t;for(let e=0;l.length>e;e++){let t=l[e];if(t[1]>t[0]){let l=t[0]-u;l>0&&r(s,u,n,l,n+o),u=t[1]}}let a=t+i-u,f=10;a>0&&r(s,u,n-f/2,a,n+o+f)}return s}function _t(l,e,t,n,i,o,s){let r=[],u=l.length;for(let a=1==i?t:n;a>=t&&n>=a;a+=i)if(null===e[a]){let f=a,c=a;if(1==i)for(;++a<=n&&null===e[a];)c=a;else for(;--a>=t&&null===e[a];)c=a;let h=o(l[f]),d=c==f?h:o(l[c]),p=f-i;h=s>0||0>p||p>=u?h:o(l[p]);let m=c+i;d=0>s||0>m||m>=u?d:o(l[m]),h>d||r.push([h,d])}return r}function bt(l){return 0==l?vl:1==l?rl:e=>zl(e,l)}function vt(l){let e=0==l?kt:yt,t=0==l?(l,e,t,n,i,o)=>{l.arcTo(e,t,n,i,o)}:(l,e,t,n,i,o)=>{l.arcTo(t,e,i,n,o)},n=0==l?(l,e,t,n,i)=>{l.rect(e,t,n,i)}:(l,e,t,n,i)=>{l.rect(t,e,i,n)};return(l,i,o,s,r,u=0,a=0)=>{0==u&&0==a?n(l,i,o,s,r):(u=al(u,s/2,r/2),a=al(a,s/2,r/2),e(l,i+u,o),t(l,i+s,o,i+s,o+r,u),t(l,i+s,o+r,i,o+r,a),t(l,i,o+r,i,o,a),t(l,i,o,i+s,o,u),l.closePath())}}const kt=(l,e,t)=>{l.moveTo(e,t)},yt=(l,e,t)=>{l.moveTo(t,e)},Mt=(l,e,t)=>{l.lineTo(e,t)},St=(l,e,t)=>{l.lineTo(t,e)},Tt=vt(0),Et=vt(1),zt=(l,e,t,n,i,o)=>{l.arc(e,t,n,i,o)},Dt=(l,e,t,n,i,o)=>{l.arc(t,e,n,i,o)},Pt=(l,e,t,n,i,o,s)=>{l.bezierCurveTo(e,t,n,i,o,s)},At=(l,e,t,n,i,o,s)=>{l.bezierCurveTo(t,e,i,n,s,o)};function Wt(){return(l,e,t,n,i)=>pt(l,e,((e,o,s,r,u,a,f,c,h,d,p)=>{let m,g,{pxRound:x,points:w}=e;0==r.ori?(m=kt,g=zt):(m=yt,g=Dt);const _=Al(w.width*y,3);let b=(w.size-w.width)/2*y,v=Al(2*b,3),k=new Path2D,M=new Path2D,{left:S,top:T,width:E,height:z}=l.bbox;Tt(M,S-v,T-v,E+2*v,z+2*v);const D=l=>{if(null!=s[l]){let e=x(a(o[l],r,d,c)),t=x(f(s[l],u,p,h));m(k,e+b,t),g(k,e,t,b,0,2*il)}};if(i)i.forEach(D);else for(let l=t;n>=l;l++)D(l);return{stroke:_>0?k:null,fill:k,clip:M,flags:3}}))}function Yt(l){return(e,t,n,i,o,s)=>{n!=i&&(o!=n&&s!=n&&l(e,t,n),o!=i&&s!=i&&l(e,t,i),l(e,t,s))}}const Ct=Yt(Mt),Ht=Yt(St);function Ft(l){const e=Q(l?.alignGaps,0);return(l,t,n,i)=>pt(l,t,((o,s,r,u,a,f,c,h,d,p,m)=>{[n,i]=U(r,n,i);let g,x,w=o.pxRound,_=l=>w(f(l,u,p,h)),b=l=>w(c(l,a,m,d));0==u.ori?(g=Mt,x=Ct):(g=St,x=Ht);const v=u.dir*(0==u.ori?1:-1),k={stroke:new Path2D,fill:null,clip:null,band:null,gaps:null,flags:1},y=k.stroke;let M=!1;if(i-n<4*p)for(let l=1==v?n:i;l>=n&&i>=l;l+=v){let e=r[l];null===e?M=!0:null!=e&&g(y,_(s[l]),b(e))}else{let e,t,o,a=e=>l.posToVal(e,u.key,!0),f=null,c=null,h=_(s[1==v?n:i]),d=_(s[n]),p=_(s[i]),m=a(1==v?d+1:p-1);for(let l=1==v?n:i;l>=n&&i>=l;l+=v){let n=s[l],i=(1==v?m>n:n>m)?h:_(n),o=r[l];i==h?null!=o?(t=o,null==f?(g(y,i,b(t)),e=f=c=t):f>t?f=t:t>c&&(c=t)):null===o&&(M=!0):(null!=f&&x(y,h,b(f),b(c),b(e),b(t)),null!=o?(t=o,g(y,i,b(t)),f=c=e=t):(f=c=null,null===o&&(M=!0)),h=i,m=a(h+v))}null!=f&&f!=c&&o!=h&&x(y,h,b(f),b(c),b(e),b(t))}let[S,T]=mt(l,t);if(null!=o.fill||0!=S){let e=k.fill=new Path2D(y),r=b(o.fillTo(l,t,o.min,o.max,S)),u=_(s[n]),a=_(s[i]);-1==v&&([a,u]=[u,a]),g(e,a,r),g(e,u,r)}if(!o.spanGaps){let a=[];M&&a.push(..._t(s,r,n,i,v,_,e)),k.gaps=a=o.gaps(l,t,n,i,a),k.clip=wt(a,u.ori,h,d,p,m)}return 0!=T&&(k.band=2==T?[xt(l,t,n,i,y,-1),xt(l,t,n,i,y,1)]:xt(l,t,n,i,y,T)),k}))}function Rt(l,e,t,n,i,o,s=gl){if(l.length>1){let r=null;for(let u=0,a=1/0;l.length>u;u++)if(void 0!==e[u]){if(null!=r){let e=ol(l[u]-l[r]);a>e&&(a=e,s=ol(t(l[u],n,i,o)-t(l[r],n,i,o)))}r=u}}return s}function Gt(l,e,t,n,i){const o=l.length;if(2>o)return null;const s=new Path2D;if(t(s,l[0],e[0]),2==o)n(s,l[1],e[1]);else{let t=Array(o),n=Array(o-1),r=Array(o-1),u=Array(o-1);for(let t=0;o-1>t;t++)r[t]=e[t+1]-e[t],u[t]=l[t+1]-l[t],n[t]=r[t]/u[t];t[0]=n[0];for(let l=1;o-1>l;l++)0===n[l]||0===n[l-1]||n[l-1]>0!=n[l]>0?t[l]=0:(t[l]=3*(u[l-1]+u[l])/((2*u[l]+u[l-1])/n[l-1]+(u[l]+2*u[l-1])/n[l]),isFinite(t[l])||(t[l]=0));t[o-1]=n[o-2];for(let n=0;o-1>n;n++)i(s,l[n]+u[n]/3,e[n]+t[n]*u[n]/3,l[n+1]-u[n]/3,e[n+1]-t[n+1]*u[n]/3,l[n+1],e[n+1])}return s}const It=new Set;function Lt(){for(let l of It)l.syncRect(!0)}_&&(G("resize",v,Lt),G("scroll",v,Lt,!0),G(x,v,(()=>{en.pxRatio=y})));const Ot=Ft(),Nt=Wt();function jt(l,e,t,n){return(n?[l[0],l[1]].concat(l.slice(2)):[l[0]].concat(l.slice(1))).map(((l,n)=>Ut(l,n,e,t)))}function Ut(l,e,t,n){return Bl({},0==e?t:n,l)}function Vt(l,e,t){return null==e?Rl:[e,t]}const Bt=Vt;function $t(l,e,t){return null==e?Rl:Z(e,t,J,!0)}function Jt(l,e,t,n){return null==e?Rl:B(e,t,l.scales[n].log,!1)}const qt=Jt;function Kt(l,e,t,n){return null==e?Rl:$(e,t,l.scales[n].log,!1)}const Xt=Kt;function Zt(l,e,t,n,i){let o=fl(xl(l),xl(e)),s=e-l,r=L(i/n*s,t);do{let l=t[r],e=n*l/s;if(e>=i&&17>=o+(5>l?Wl.get(l):0))return[l,e]}while(++r<t.length);return[0,0]}function Qt(l){let e,t;return[l=l.replace(/(\d+)px/,((l,n)=>(e=rl((t=+n)*y))+"px")),e,t]}function ln(l){l.show&&[l.font,l.labelFont].forEach((l=>{let e=Al(l[2]*y,1);l[0]=l[0].replace(/[0-9.]+px/,e+"px"),l[1]=e}))}function en(u,g,_){const k={mode:Q(u.mode,1)},M=k.mode;function P(l,e,t,n){let i=e.valToPct(l);return n+t*(-1==e.dir?1-i:i)}function W(l,e,t,n){let i=e.valToPct(l);return n+t*(-1==e.dir?i:1-i)}function C(l,e,t,n){return 0==e.ori?P(l,e,t,n):W(l,e,t,n)}k.valToPosH=P,k.valToPosV=W;let F=!1;k.status=0;const R=k.root=D("uplot");null!=u.id&&(R.id=u.id),S(R,u.class),u.title&&(D("u-title",R).textContent=u.title);const O=z("canvas"),K=k.ctx=O.getContext("2d"),X=D("u-wrap",R);G("click",X,(l=>{l.target===el&&(Nn!=Gn||jn!=In)&&Zn.click(k,l)}),!0);const ll=k.under=D("u-under",X);X.appendChild(O);const el=k.over=D("u-over",X),tl=+Q((u=Vl(u)).pxAlign,1),sl=bt(tl);(u.plugins||[]).forEach((l=>{l.opts&&(u=l.opts(k,u)||u)}));const hl=u.ms||.001,pl=k.series=1==M?jt(u.series||[],Ve,ut,!1):function(l,e){return l.map(((l,t)=>0==t?{}:Bl({},e,l)))}(u.series||[null],rt),xl=k.axes=jt(u.axes||[],Ue,it,!0),vl=k.scales={},Tl=k.bands=u.bands||[];Tl.forEach((l=>{l.fill=bl(l.fill||null),l.dir=Q(l.dir,-1)}));const El=2==M?pl[1].facets[0].scale:pl[0].scale,Dl={axes:function(){for(let l=0;xl.length>l;l++){let e=xl[l];if(!e.show||!e._show)continue;let t,n,u=e.side,a=u%2,f=e.stroke(k,l),c=0==u||3==u?-1:1,[h,d]=e._found;if(null!=e.label){let s=rl((e._lpos+e.labelGap*c)*y);_n(e.labelFont[0],f,"center",2==u?i:o),K.save(),1==a?(t=n=0,K.translate(s,rl(lt+st/2)),K.rotate((3==u?-il:il)/2)):(t=rl(Qe+ot/2),n=s);let r=_l(e.label)?e.label(k,l,h,d):e.label;K.fillText(r,t,n),K.restore()}if(0==d)continue;let p=vl[e.scale],m=0==a?ot:st,g=0==a?Qe:lt,x=e._splits,w=2==p.distr?x.map((l=>pn[l])):x,_=2==p.distr?pn[x[1]]-pn[x[0]]:h,b=e.ticks,v=e.border,M=b.show?b.size:0,S=rl(M*y),T=rl((2==e.alignTo?e._size-M-e.gap:e.gap)*y),E=e._rotate*-il/180,z=sl(e._pos*y),D=z+(S+T)*c;n=0==a?D:0,t=1==a?D:0,_n(e.font[0],f,1==e.align?s:2==e.align?r:E>0?s:0>E?r:0==a?"center":3==u?r:s,E||1==a?"middle":2==u?i:o);let P=e.font[1]*e.lineGap,A=x.map((l=>sl(C(l,p,m,g)))),W=e._values;for(let l=0;W.length>l;l++){let e=W[l];if(null!=e){0==a?t=A[l]:n=A[l],e=""+e;let i=-1==e.indexOf("\n")?[e]:e.split(/\n/gm);for(let l=0;i.length>l;l++){let e=i[l];E?(K.save(),K.translate(t,n+l*P),K.rotate(E),K.fillText(e,0,0),K.restore()):K.fillText(e,t,n+l*P)}}}b.show&&zn(A,b.filter(k,w,l,d,_),a,u,z,S,Al(b.width*y,3),b.stroke(k,l),b.dash,b.cap);let Y=e.grid;Y.show&&zn(A,Y.filter(k,w,l,d,_),a,0==a?2:1,0==a?lt:Qe,0==a?st:ot,Al(Y.width*y,3),Y.stroke(k,l),Y.dash,Y.cap),v.show&&zn([z],[1],0==a?1:0,0==a?1:2,1==a?lt:Qe,1==a?st:ot,Al(v.width*y,3),v.stroke(k,l),v.dash,v.cap)}Ci("drawAxes")},series:function(){if(Gt>0){let l=pl.some((l=>l._focus))&&dn!=Tt.alpha;l&&(K.globalAlpha=dn=Tt.alpha),pl.forEach(((l,e)=>{if(e>0&&l.show&&(kn(e,!1),kn(e,!0),null==l._paths)){let t=dn;dn!=l.alpha&&(K.globalAlpha=dn=l.alpha);let n=2==M?[0,g[e][0].length-1]:function(l){let e=wl(Lt-1,0,Gt-1),t=wl(en+1,0,Gt-1);for(;null==l[e]&&e>0;)e--;for(;null==l[t]&&Gt-1>t;)t++;return[e,t]}(g[e]);l._paths=l.paths(k,e,n[0],n[1]),dn!=t&&(K.globalAlpha=dn=t)}})),pl.forEach(((l,e)=>{if(e>0&&l.show){let t=dn;dn!=l.alpha&&(K.globalAlpha=dn=l.alpha),null!=l._paths&&yn(e,!1);{let t=null!=l._paths?l._paths.gaps:null,n=l.points.show(k,e,Lt,en,t),i=l.points.filter(k,e,n,t);(n||i)&&(l.points._paths=l.points.paths(k,e,Lt,en,i),yn(e,!0))}dn!=t&&(K.globalAlpha=dn=t),Ci("drawSeries",e)}})),l&&(K.globalAlpha=dn=1)}}},Pl=(u.drawOrder||["axes","series"]).map((l=>Dl[l]));function Cl(l){const e=3==l.distr?e=>dl(e>0?e:l.clamp(k,e,l.min,l.max,l.key)):4==l.distr?e=>ml(e,l.asinh):100==l.distr?e=>l.fwd(e):l=>l;return t=>{let n=e(t),{_min:i,_max:o}=l;return(n-i)/(o-i)}}function Il(l){let e=vl[l];if(null==e){let t=(u.scales||Hl)[l]||Hl;if(null!=t.from){Il(t.from);let e=Bl({},vl[t.from],t,{key:l});e.valToPct=Cl(e),vl[l]=e}else{e=vl[l]=Bl({},l==El?ft:ct,t),e.key=l;let n=e.time,i=e.range,o=Gl(i);if((l!=El||2==M&&!n)&&(!o||null!=i[0]&&null!=i[1]||(i={min:null==i[0]?q:{mode:1,hard:i[0],soft:i[0]},max:null==i[1]?q:{mode:1,hard:i[1],soft:i[1]}},o=!1),!o&&Ol(i))){let l=i;i=(e,t,n)=>null==t?Rl:Z(t,n,l)}e.range=bl(i||(n?Bt:l==El?3==e.distr?qt:4==e.distr?Xt:Vt:3==e.distr?Jt:4==e.distr?Kt:$t)),e.auto=bl(!o&&e.auto),e.clamp=bl(e.clamp||at),e._min=e._max=null,e.valToPct=Cl(e)}}}Il("x"),Il("y"),1==M&&pl.forEach((l=>{Il(l.scale)})),xl.forEach((l=>{Il(l.scale)}));for(let l in u.scales)Il(l);const jl=vl[El],Ul=jl.distr;let $l,ql;0==jl.ori?(S(R,"u-hz"),$l=P,ql=W):(S(R,"u-vt"),$l=W,ql=P);const Kl={};for(let l in vl){let e=vl[l];null==e.min&&null==e.max||(Kl[l]={min:e.min,max:e.max},e.min=e.max=null)}const Xl=u.tzDate||(l=>new Date(rl(l/hl))),Zl=u.fmtDate||ne,Ql=1==hl?Me(Xl):Ee(Xl),le=De(Xl,ze(1==hl?ye:Te,Zl)),ee=We(Xl,Ae("{YYYY}-{MM}-{DD} {h}:{mm}{aa}",Zl)),te=[],ie=k.legend=Bl({},Ye,u.legend),oe=k.cursor=Bl({},Re,{drag:{y:2==M}},u.cursor),se=ie.show,re=oe.show,ue=ie.markers;let ce,he,de;ie.idxs=te,ue.width=bl(ue.width),ue.dash=bl(ue.dash),ue.stroke=bl(ue.stroke),ue.fill=bl(ue.fill);let pe,me=[],ge=[],xe=!1,we={};if(ie.live){const l=pl[1]?pl[1].values:null;xe=null!=l,pe=xe?l(k,1,0):{_:0};for(let l in pe)we[l]=w}if(se)if(ce=z("table","u-legend",R),de=z("tbody",null,ce),ie.mount(k,ce),xe){he=z("thead",null,ce,de);let l=z("tr",null,he);for(var _e in z("th",null,l),pe)z("th",e,l).textContent=_e}else S(ce,"u-inline"),ie.live&&S(ce,"u-live");const be={show:!0},ve={show:!1},Pe=new Map;function Ce(l,e,t,n=!0){const i=Pe.get(e)||{},o=oe.bind[l](k,e,t,n);o&&(G(l,e,i[l]=o),Pe.set(e,i))}function He(l,e){const t=Pe.get(e)||{};for(let n in t)null!=l&&n!=l||(I(n,e,t[n]),delete t[n]);null==l&&Pe.delete(e)}let Fe=0,Ge=0,Ie=0,Le=0,Oe=0,Ne=0,je=Oe,Ke=Ne,Xe=Ie,Ze=Le,Qe=0,lt=0,ot=0,st=0;k.bbox={};let ht=!1,pt=!1,mt=!1,xt=!1,wt=!1,_t=!1;function vt(l,e,t){(t||l!=k.width||e!=k.height)&&kt(l,e),An(!1),mt=!0,pt=!0,Jn()}function kt(l,e){k.width=Fe=Ie=l,k.height=Ge=Le=e,Oe=Ne=0,function(){let l=!1,e=!1,t=!1,n=!1;xl.forEach((i=>{if(i.show&&i._show){let{side:o,_size:s}=i,r=s+(null!=i.label?i.labelSize:0);r>0&&(o%2?(Ie-=r,3==o?(Oe+=r,n=!0):t=!0):(Le-=r,0==o?(Ne+=r,l=!0):e=!0))}})),Ct[0]=l,Ct[1]=t,Ct[2]=e,Ct[3]=n,Ie-=Rt[1]+Rt[3],Oe+=Rt[3],Le-=Rt[2]+Rt[0],Ne+=Rt[0]}(),function(){let l=Oe+Ie,e=Ne+Le,t=Oe,n=Ne;function i(i,o){switch(i){case 1:return l+=o,l-o;case 2:return e+=o,e-o;case 3:return t-=o,t+o;case 0:return n-=o,n+o}}xl.forEach((l=>{if(l.show&&l._show){let e=l.side;l._pos=i(e,l._size),null!=l.label&&(l._lpos=i(e,l.labelSize))}}))}();let t=k.bbox;Qe=t.left=zl(Oe*y,.5),lt=t.top=zl(Ne*y,.5),ot=t.width=zl(Ie*y,.5),st=t.height=zl(Le*y,.5)}const yt=3;if(k.setSize=function({width:l,height:e}){vt(l,e)},null==oe.dataIdx){let l=oe.hover,e=l.skip=new Set(l.skip??[]);e.add(void 0);let t=l.prox=bl(l.prox),n=l.bias??=0;oe.dataIdx=(l,i,o,s)=>{if(0==i)return o;let r=o,u=t(l,i,o,s)??gl,a=u>=0&&gl>u,f=0==jl.ori?Ie:Le,c=oe.left,h=g[0],d=g[i];if(e.has(d[o])){r=null;let l,t=null,i=null;if(0==n||-1==n)for(l=o;null==t&&l-- >0;)e.has(d[l])||(t=l);if(0==n||1==n)for(l=o;null==i&&l++<d.length;)e.has(d[l])||(i=l);if(null!=t||null!=i)if(a){let l=c-(null==t?-1/0:$l(h[t],jl,f,0)),e=(null==i?1/0:$l(h[i],jl,f,0))-c;l>e?e>u||(r=i):l>u||(r=t)}else r=null==i?t:null==t||o-t>i-o?i:t}else a&&ol(c-$l(h[o],jl,f,0))>u&&(r=null);return r}}const Mt=l=>{oe.event=l};oe.idxs=te,oe._lock=!1;let St=oe.points;St.show=bl(St.show),St.size=bl(St.size),St.stroke=bl(St.stroke),St.width=bl(St.width),St.fill=bl(St.fill);const Tt=k.focus=Bl({},u.focus||{alpha:.3},oe.focus),Et=Tt.prox>=0,zt=Et&&St.one;let Dt=[],Pt=[],At=[];function Wt(l,e){let t=St.show(k,e);if(t instanceof HTMLElement)return S(t,"u-cursor-pt"),S(t,l.class),A(t,-10,-10,Ie,Le),el.insertBefore(t,Dt[e]),t}function Yt(t,n){if(1==M||n>0){let l=1==M&&vl[t.scale].time,e=t.value;t.value=l?Ll(e)?We(Xl,Ae(e,Zl)):e||ee:e||nt,t.label=t.label||(l?"Time":"Value")}if(zt||n>0){t.width=null==t.width?1:t.width,t.paths=t.paths||Ot||yl,t.fillTo=bl(t.fillTo||gt),t.pxAlign=+Q(t.pxAlign,tl),t.pxRound=bt(t.pxAlign),t.stroke=bl(t.stroke||null),t.fill=bl(t.fill||null),t._stroke=t._fill=t._paths=t._focus=null;let l=function(l){return Al(1*(3+2*(l||1)),3)}(fl(1,t.width)),e=t.points=Bl({},{size:l,width:fl(1,.2*l),stroke:t.stroke,space:2*l,paths:Nt,_stroke:null,_fill:null},t.points);e.show=bl(e.show),e.filter=bl(e.filter),e.fill=bl(e.fill),e.stroke=bl(e.stroke),e.paths=bl(e.paths),e.pxAlign=t.pxAlign}if(se){let i=function(t,n){if(0==n&&(xe||!ie.live||2==M))return Rl;let i=[],o=z("tr","u-series",de,de.childNodes[n]);S(o,t.class),t.show||S(o,l);let s=z("th",null,o);if(ue.show){let l=D("u-marker",s);if(n>0){let e=ue.width(k,n);e&&(l.style.border=e+"px "+ue.dash(k,n)+" "+ue.stroke(k,n)),l.style.background=ue.fill(k,n)}}let r=D(e,s);for(var u in t.label instanceof HTMLElement?r.appendChild(t.label):r.textContent=t.label,n>0&&(ue.show||(r.style.color=t.width>0?ue.stroke(k,n):ue.fill(k,n)),Ce("click",s,(l=>{if(oe._lock)return;Mt(l);let e=pl.indexOf(t);if((l.ctrlKey||l.metaKey)!=ie.isolate){let l=pl.some(((l,t)=>t>0&&t!=e&&l.show));pl.forEach(((t,n)=>{n>0&&oi(n,l?n==e?be:ve:be,!0,Fi.setSeries)}))}else oi(e,{show:!t.show},!0,Fi.setSeries)}),!1),Et&&Ce(d,s,(l=>{oe._lock||(Mt(l),oi(pl.indexOf(t),ai,!0,Fi.setSeries))}),!1)),pe){let l=z("td","u-value",o);l.textContent="--",i.push(l)}return[o,i]}(t,n);me.splice(n,0,i[0]),ge.splice(n,0,i[1]),ie.values.push(null)}if(re){te.splice(n,0,null);let l=null;zt?0==n&&(l=Wt(t,n)):n>0&&(l=Wt(t,n)),Dt.splice(n,0,l),Pt.splice(n,0,0),At.splice(n,0,0)}Ci("addSeries",n)}k.addSeries=function(l,e){e=null==e?pl.length:e,l=1==M?Ut(l,e,Ve,ut):Ut(l,e,{},rt),pl.splice(e,0,l),Yt(pl[e],e)},k.delSeries=function(l){if(pl.splice(l,1),se){ie.values.splice(l,1),ge.splice(l,1);let e=me.splice(l,1)[0];He(null,e.firstChild),e.remove()}re&&(te.splice(l,1),Dt.splice(l,1)[0].remove(),Pt.splice(l,1),At.splice(l,1)),Ci("delSeries",l)};const Ct=[!1,!1,!1,!1];function Ht(l,e,t){let[n,i,o,s]=t,r=e%2,u=0;return 0==r&&(s||i)&&(u=0==e&&!n||2==e&&!o?rl(Ue.size/3):0),1==r&&(n||o)&&(u=1==e&&!i||3==e&&!s?rl(it.size/2):0),u}const Ft=k.padding=(u.padding||[Ht,Ht,Ht,Ht]).map((l=>bl(Q(l,Ht)))),Rt=k._padding=Ft.map(((l,e)=>l(k,e,Ct,0)));let Gt,Lt=null,en=null;const tn=1==M?pl[0].idxs:null;let nn,on,sn,rn,un,an,fn,cn,hn,dn,pn=null,mn=!1;function gn(l,e){if(k.data=k._data=g=null==l?[]:l,2==M){Gt=0;for(let l=1;pl.length>l;l++)Gt+=g[l][0].length}else{0==g.length&&(k.data=k._data=g=[[]]),pn=g[0],Gt=pn.length;let l=g;if(2==Ul){l=g.slice();let e=l[0]=Array(Gt);for(let l=0;Gt>l;l++)e[l]=l}k._data=g=l}if(An(!0),Ci("setData"),2==Ul&&(mt=!0),!1!==e){let l=jl;l.auto(k,mn)?xn():ii(El,l.min,l.max),xt=xt||oe.left>=0,_t=!0,Jn()}}function xn(){let l,e;mn=!0,1==M&&(Gt>0?(Lt=tn[0]=0,en=tn[1]=Gt-1,l=g[0][Lt],e=g[0][en],2==Ul?(l=Lt,e=en):l==e&&(3==Ul?[l,e]=B(l,l,jl.log,!1):4==Ul?[l,e]=$(l,l,jl.log,!1):jl.time?e=l+rl(86400/hl):[l,e]=Z(l,e,J,!0))):(Lt=tn[0]=l=null,en=tn[1]=e=null)),ii(El,l,e)}function wn(l,e,t,n,i,o){l??=a,t??=Fl,n??="butt",i??=a,o??="round",l!=nn&&(K.strokeStyle=nn=l),i!=on&&(K.fillStyle=on=i),e!=sn&&(K.lineWidth=sn=e),o!=un&&(K.lineJoin=un=o),n!=an&&(K.lineCap=an=n),t!=rn&&K.setLineDash(rn=t)}function _n(l,e,t,n){e!=on&&(K.fillStyle=on=e),l!=fn&&(K.font=fn=l),t!=cn&&(K.textAlign=cn=t),n!=hn&&(K.textBaseline=hn=n)}function bn(l,e,t,n,i=0){if(n.length>0&&l.auto(k,mn)&&(null==e||null==e.min)){let e=Q(Lt,0),o=Q(en,n.length-1),s=null==t.min?function(l,e,t,n=0,i=!1){let o=i?V:U,s=i?j:N;[e,t]=o(l,e,t);let r=l[e],u=l[e];if(e>-1)if(1==n)r=l[e],u=l[t];else if(-1==n)r=l[t],u=l[e];else for(let n=e;t>=n;n++){let e=l[n];s(e)&&(r>e?r=e:e>u&&(u=e))}return[r??gl,u??-gl]}(n,e,o,i,3==l.distr):[t.min,t.max];l.min=al(l.min,t.min=s[0]),l.max=fl(l.max,t.max=s[1])}}k.setData=gn;const vn={min:null,max:null};function kn(l,e){let t=e?pl[l].points:pl[l];t._stroke=t.stroke(k,l),t._fill=t.fill(k,l)}function yn(l,e){let t=e?pl[l].points:pl[l],{stroke:n,fill:i,clip:o,flags:s,_stroke:r=t._stroke,_fill:u=t._fill,_width:a=t.width}=t._paths;a=Al(a*y,3);let f=null,c=a%2/2;e&&null==u&&(u=a>0?"#fff":r);let h=1==t.pxAlign&&c>0;if(h&&K.translate(c,c),!e){let l=Qe-a/2,e=lt-a/2,t=ot+a,n=st+a;f=new Path2D,f.rect(l,e,t,n)}e?Sn(r,a,t.dash,t.cap,u,n,i,s,o):function(l,e,t,n,i,o,s,r,u,a,f){let c=!1;0!=u&&Tl.forEach(((h,d)=>{if(h.series[0]==l){let l,p=pl[h.series[1]],m=g[h.series[1]],x=(p._paths||Hl).band;Gl(x)&&(x=1==h.dir?x[0]:x[1]);let w=null;p.show&&x&&function(l,e,t){for(e=Q(e,0),t=Q(t,l.length-1);t>=e;){if(null!=l[e])return!0;e++}return!1}(m,Lt,en)?(w=h.fill(k,d)||o,l=p._paths.clip):x=null,Sn(e,t,n,i,w,s,r,u,a,f,l,x),c=!0}})),c||Sn(e,t,n,i,o,s,r,u,a,f)}(l,r,a,t.dash,t.cap,u,n,i,s,f,o),h&&K.translate(-c,-c)}const Mn=3;function Sn(l,e,t,n,i,o,s,r,u,a,f,c){wn(l,e,t,n,i),(u||a||c)&&(K.save(),u&&K.clip(u),a&&K.clip(a)),c?(r&Mn)==Mn?(K.clip(c),f&&K.clip(f),En(i,s),Tn(l,o,e)):2&r?(En(i,s),K.clip(c),Tn(l,o,e)):1&r&&(K.save(),K.clip(c),f&&K.clip(f),En(i,s),K.restore(),Tn(l,o,e)):(En(i,s),Tn(l,o,e)),(u||a||c)&&K.restore()}function Tn(l,e,t){t>0&&(e instanceof Map?e.forEach(((l,e)=>{K.strokeStyle=nn=e,K.stroke(l)})):null!=e&&l&&K.stroke(e))}function En(l,e){e instanceof Map?e.forEach(((l,e)=>{K.fillStyle=on=e,K.fill(l)})):null!=e&&l&&K.fill(e)}function zn(l,e,t,n,i,o,s,r,u,a){let f=s%2/2;1==tl&&K.translate(f,f),wn(r,s,u,a,r),K.beginPath();let c,h,d,p,m=i+(0==n||3==n?-o:o);0==t?(h=i,p=m):(c=i,d=m);for(let n=0;l.length>n;n++)null!=e[n]&&(0==t?c=d=l[n]:h=p=l[n],K.moveTo(c,h),K.lineTo(d,p));K.stroke(),1==tl&&K.translate(-f,-f)}function Dn(l){let e=!0;return xl.forEach(((t,n)=>{if(!t.show)return;let i=vl[t.scale];if(null==i.min)return void(t._show&&(e=!1,t._show=!1,An(!1)));t._show||(e=!1,t._show=!0,An(!1));let o=t.side,s=o%2,{min:r,max:u}=i,[a,f]=function(l,e,t,n){let i,o=xl[l];if(n>0){let s=o._space=o.space(k,l,e,t,n);i=Zt(e,t,o._incrs=o.incrs(k,l,e,t,n,s),n,s)}else i=[0,0];return o._found=i}(n,r,u,0==s?Ie:Le);if(0==f)return;let c=t._splits=t.splits(k,n,r,u,a,f,2==i.distr),h=2==i.distr?c.map((l=>pn[l])):c,d=2==i.distr?pn[c[1]]-pn[c[0]]:a,p=t._values=t.values(k,t.filter(k,h,n,f,d),n,f,d);t._rotate=2==o?t.rotate(k,p,n,f):0;let m=t._size;t._size=ul(t.size(k,p,n,l)),null!=m&&t._size!=m&&(e=!1)})),e}function Pn(l){let e=!0;return Ft.forEach(((t,n)=>{let i=t(k,n,Ct,l);i!=Rt[n]&&(e=!1),Rt[n]=i})),e}function An(l){pl.forEach(((e,t)=>{t>0&&(e._paths=null,l&&(1==M?(e.min=null,e.max=null):e.facets.forEach((l=>{l.min=null,l.max=null}))))}))}let Wn,Yn,Cn,Hn,Fn,Rn,Gn,In,Ln,On,Nn,jn,Un=!1,Vn=!1,Bn=[];function $n(){Vn=!1;for(let l=0;Bn.length>l;l++)Ci(...Bn[l]);Bn.length=0}function Jn(){Un||(Jl(qn),Un=!0)}function qn(){if(ht&&(function(){for(let l in vl){let e=vl[l];null==Kl[l]&&(null==e.min||null!=Kl[El]&&e.auto(k,mn))&&(Kl[l]=vn)}for(let l in vl){let e=vl[l];null==Kl[l]&&null!=e.from&&null!=Kl[e.from]&&(Kl[l]=vn)}null!=Kl[El]&&An(!0);let l={};for(let e in Kl){let t=Kl[e];if(null!=t){let n=l[e]=Vl(vl[e],Nl);if(null!=t.min)Bl(n,t);else if(e!=El||2==M)if(0==Gt&&null==n.from){let l=n.range(k,null,null,e);n.min=l[0],n.max=l[1]}else n.min=gl,n.max=-gl}}if(Gt>0){pl.forEach(((e,t)=>{if(1==M){let n=e.scale,i=Kl[n];if(null==i)return;let o=l[n];if(0==t){let l=o.range(k,o.min,o.max,n);o.min=l[0],o.max=l[1],Lt=L(o.min,g[0]),en=L(o.max,g[0]),en-Lt>1&&(o.min>g[0][Lt]&&Lt++,g[0][en]>o.max&&en--),e.min=pn[Lt],e.max=pn[en]}else e.show&&e.auto&&bn(o,i,e,g[t],e.sorted);e.idxs[0]=Lt,e.idxs[1]=en}else if(t>0&&e.show&&e.auto){let[n,i]=e.facets,o=n.scale,s=i.scale,[r,u]=g[t],a=l[o],f=l[s];null!=a&&bn(a,Kl[o],n,r,n.sorted),null!=f&&bn(f,Kl[s],i,u,i.sorted),e.min=i.min,e.max=i.max}}));for(let e in l){let t=l[e],n=Kl[e];if(null==t.from&&(null==n||null==n.min)){let l=t.range(k,t.min==gl?null:t.min,t.max==-gl?null:t.max,e);t.min=l[0],t.max=l[1]}}}for(let e in l){let t=l[e];if(null!=t.from){let n=l[t.from];if(null==n.min)t.min=t.max=null;else{let l=t.range(k,n.min,n.max,e);t.min=l[0],t.max=l[1]}}}let e={},t=!1;for(let n in l){let i=l[n],o=vl[n];if(o.min!=i.min||o.max!=i.max){o.min=i.min,o.max=i.max;let l=o.distr;o._min=3==l?dl(o.min):4==l?ml(o.min,o.asinh):100==l?o.fwd(o.min):o.min,o._max=3==l?dl(o.max):4==l?ml(o.max,o.asinh):100==l?o.fwd(o.max):o.max,e[n]=t=!0}}if(t){pl.forEach(((l,t)=>{2==M?t>0&&e.y&&(l._paths=null):e[l.scale]&&(l._paths=null)}));for(let l in e)mt=!0,Ci("setScale",l);re&&oe.left>=0&&(xt=_t=!0)}for(let l in Kl)Kl[l]=null}(),ht=!1),mt&&(function(){let l=!1,e=0;for(;!l;){e++;let t=Dn(e),n=Pn(e);l=e==yt||t&&n,l||(kt(k.width,k.height),pt=!0)}}(),mt=!1),pt){if(E(ll,s,Oe),E(ll,i,Ne),E(ll,t,Ie),E(ll,n,Le),E(el,s,Oe),E(el,i,Ne),E(el,t,Ie),E(el,n,Le),E(X,t,Fe),E(X,n,Ge),O.width=rl(Fe*y),O.height=rl(Ge*y),xl.forEach((({_el:e,_show:t,_size:n,_pos:i,side:o})=>{if(null!=e)if(t){let t=o%2==1;E(e,t?"left":"top",i-(3===o||0===o?n:0)),E(e,t?"width":"height",n),E(e,t?"top":"left",t?Ne:Oe),E(e,t?"height":"width",t?Le:Ie),T(e,l)}else S(e,l)})),nn=on=sn=un=an=fn=cn=hn=rn=null,dn=1,_i(!0),Oe!=je||Ne!=Ke||Ie!=Xe||Le!=Ze){An(!1);let l=Ie/Xe,e=Le/Ze;if(re&&!xt&&oe.left>=0){oe.left*=l,oe.top*=e,Cn&&A(Cn,rl(oe.left),0,Ie,Le),Hn&&A(Hn,0,rl(oe.top),Ie,Le);for(let t=0;Dt.length>t;t++){let n=Dt[t];null!=n&&(Pt[t]*=l,At[t]*=e,A(n,ul(Pt[t]),ul(At[t]),Ie,Le))}}if(ei.show&&!wt&&ei.left>=0&&ei.width>0){ei.left*=l,ei.width*=l,ei.top*=e,ei.height*=e;for(let l in ki)E(ti,l,ei[l])}je=Oe,Ke=Ne,Xe=Ie,Ze=Le}Ci("setSize"),pt=!1}Fe>0&&Ge>0&&(K.clearRect(0,0,O.width,O.height),Ci("drawClear"),Pl.forEach((l=>l())),Ci("draw")),ei.show&&wt&&(ni(ei),wt=!1),re&&xt&&(xi(null,!0,!1),xt=!1),ie.show&&ie.live&&_t&&(mi(),_t=!1),F||(F=!0,k.status=1,Ci("ready")),mn=!1,Un=!1}function Kn(l,e){let t=vl[l];if(null==t.from){if(0==Gt){let n=t.range(k,e.min,e.max,l);e.min=n[0],e.max=n[1]}if(e.min>e.max){let l=e.min;e.min=e.max,e.max=l}if(Gt>1&&null!=e.min&&null!=e.max&&1e-16>e.max-e.min)return;l==El&&2==t.distr&&Gt>0&&(e.min=L(e.min,g[0]),e.max=L(e.max,g[0]),e.min==e.max&&e.max++),Kl[l]=e,ht=!0,Jn()}}k.batch=function(l,e=!1){Un=!0,Vn=e,l(k),qn(),e&&Bn.length>0&&queueMicrotask($n)},k.redraw=(l,e)=>{mt=e||!1,!1!==l?ii(El,jl.min,jl.max):Jn()},k.setScale=Kn;let Xn=!1;const Zn=oe.drag;let Qn=Zn.x,li=Zn.y;re&&(oe.x&&(Wn=D("u-cursor-x",el)),oe.y&&(Yn=D("u-cursor-y",el)),0==jl.ori?(Cn=Wn,Hn=Yn):(Cn=Yn,Hn=Wn),Nn=oe.left,jn=oe.top);const ei=k.select=Bl({show:!0,over:!0,left:0,width:0,top:0,height:0},u.select),ti=ei.show?D("u-select",ei.over?el:ll):null;function ni(l,e){if(ei.show){for(let e in l)ei[e]=l[e],e in ki&&E(ti,e,l[e]);!1!==e&&Ci("setSelect")}}function ii(l,e,t){Kn(l,{min:e,max:t})}function oi(e,t,n,i){null!=t.focus&&function(l){if(l!=ui){let e=null==l,t=1!=Tt.alpha;pl.forEach(((n,i)=>{if(1==M||i>0){let o=e||0==i||i==l;n._focus=e?null:o,t&&function(l,e){pl[l].alpha=e,re&&null!=Dt[l]&&(Dt[l].style.opacity=e),se&&me[l]&&(me[l].style.opacity=e)}(i,o?1:Tt.alpha)}})),ui=l,t&&Jn()}}(e),null!=t.show&&pl.forEach(((n,i)=>{0>=i||e!=i&&null!=e||(n.show=t.show,function(e){if(pl[e].show)se&&T(me[e],l);else if(se&&S(me[e],l),re){let l=zt?Dt[0]:Dt[e];null!=l&&A(l,-10,-10,Ie,Le)}}(i),2==M?(ii(n.facets[0].scale,null,null),ii(n.facets[1].scale,null,null)):ii(n.scale,null,null),Jn())})),!1!==n&&Ci("setSeries",e,t),i&&Ii("setSeries",k,e,t)}let si,ri,ui;k.setSelect=ni,k.setSeries=oi,k.addBand=function(l,e){l.fill=bl(l.fill||null),l.dir=Q(l.dir,-1),Tl.splice(e=null==e?Tl.length:e,0,l)},k.setBand=function(l,e){Bl(Tl[l],e)},k.delBand=function(l){null==l?Tl.length=0:Tl.splice(l,1)};const ai={focus:!0};function fi(l,e,t){let n=vl[e];t&&(l=l/y-(1==n.ori?Ne:Oe));let i=Ie;1==n.ori&&(i=Le,l=i-l),-1==n.dir&&(l=i-l);let o=n._min,s=o+l/i*(n._max-o),r=n.distr;return 3==r?cl(10,s):4==r?((l,e=1)=>nl.sinh(l)*e)(s,n.asinh):100==r?n.bwd(s):s}function ci(l,e){E(ti,s,ei.left=l),E(ti,t,ei.width=e)}function hi(l,e){E(ti,i,ei.top=l),E(ti,n,ei.height=e)}se&&Et&&Ce(p,ce,(l=>{oe._lock||(Mt(l),null!=ui&&oi(null,ai,!0,Fi.setSeries))})),k.valToIdx=l=>L(l,g[0]),k.posToIdx=function(l,e){return L(fi(l,El,e),g[0],Lt,en)},k.posToVal=fi,k.valToPos=(l,e,t)=>0==vl[e].ori?P(l,vl[e],t?ot:Ie,t?Qe:0):W(l,vl[e],t?st:Le,t?lt:0),k.setCursor=(l,e,t)=>{Nn=l.left,jn=l.top,xi(null,e,t)};let di=0==jl.ori?ci:hi,pi=1==jl.ori?ci:hi;function mi(l,e){if(null!=l&&(l.idxs?l.idxs.forEach(((l,e)=>{te[e]=l})):(l=>void 0===l)(l.idx)||te.fill(l.idx),ie.idx=te[0]),se&&ie.live){for(let l=0;pl.length>l;l++)(l>0||1==M&&!xe)&&gi(l,te[l]);!function(){if(se&&ie.live)for(let l=2==M?1:0;pl.length>l;l++){if(0==l&&xe)continue;let e=ie.values[l],t=0;for(let n in e)ge[l][t++].firstChild.nodeValue=e[n]}}()}_t=!1,!1!==e&&Ci("setLegend")}function gi(l,e){let t,n=pl[l],i=0==l&&2==Ul?pn:g[l];xe?t=n.values(k,l,e)??we:(t=n.value(k,null==e?null:i[e],l,e),t=null==t?we:{_:t}),ie.values[l]=t}function xi(l,e,t){let n;Ln=Nn,On=jn,[Nn,jn]=oe.move(k,Nn,jn),oe.left=Nn,oe.top=jn,re&&(Cn&&A(Cn,rl(Nn),0,Ie,Le),Hn&&A(Hn,0,rl(jn),Ie,Le)),si=gl,ri=null;let i=0==jl.ori?Ie:Le,o=1==jl.ori?Ie:Le;if(0>Nn||0==Gt||Lt>en){n=oe.idx=null;for(let l=0;pl.length>l;l++){let e=Dt[l];null!=e&&A(e,-10,-10,Ie,Le)}Et&&oi(null,ai,!0,null==l&&Fi.setSeries),ie.live&&(te.fill(n),_t=!0)}else{let l,e,t;1==M&&(l=0==jl.ori?Nn:jn,e=fi(l,El),n=oe.idx=L(e,g[0],Lt,en),t=$l(g[0][n],jl,i,0));let s=-10,r=-10,u=0,a=0,f=!0,c="",h="";for(let l=2==M?1:0;pl.length>l;l++){let d=pl[l],p=te[l],m=null==p?null:1==M?g[l][p]:g[l][1][p],x=oe.dataIdx(k,l,n,e),w=null==x?null:1==M?g[l][x]:g[l][1][x];if(_t=_t||w!=m||x!=p,te[l]=x,l>0&&d.show){let e=null==x?-10:x==n?t:$l(1==M?g[0][x]:g[l][0][x],jl,i,0),p=null==w?-10:ql(w,1==M?vl[d.scale]:vl[d.facets[1].scale],o,0);if(Et&&null!=w){let e=1==jl.ori?Nn:jn,t=ol(Tt.dist(k,l,x,p,e));if(si>t){let n=Tt.bias;if(0!=n){let i=fi(e,d.scale),o=0>i?-1:1;o!=(0>w?-1:1)||(1==o?1==n?i>w:w>i:1==n?w>i:i>w)||(si=t,ri=l)}else si=t,ri=l}}if(_t||zt){let t,n;0==jl.ori?(t=e,n=p):(t=p,n=e);let i,o,d,m,g,x,w=!0,_=St.bbox;if(null!=_){w=!1;let e=_(k,l);d=e.left,m=e.top,i=e.width,o=e.height}else d=t,m=n,i=o=St.size(k,l);if(x=St.fill(k,l),g=St.stroke(k,l),zt)l!=ri||si>Tt.prox||(s=d,r=m,u=i,a=o,f=w,c=x,h=g);else{let e=Dt[l];null!=e&&(Pt[l]=d,At[l]=m,H(e,i,o,w),Y(e,x,g),A(e,ul(d),ul(m),Ie,Le))}}}}if(zt){let l=Tt.prox;if(_t||(null==ui?l>=si:si>l||ri!=ui)){let l=Dt[0];null!=l&&(Pt[0]=s,At[0]=r,H(l,u,a,f),Y(l,c,h),A(l,ul(s),ul(r),Ie,Le))}}}if(ei.show&&Xn)if(null!=l){let[e,t]=Fi.scales,[n,s]=Fi.match,[r,u]=l.cursor.sync.scales,a=l.cursor.drag;if(Qn=a._x,li=a._y,Qn||li){let a,f,c,h,d,{left:p,top:m,width:g,height:x}=l.select,w=l.scales[r].ori,_=l.posToVal,b=null!=e&&n(e,r),v=null!=t&&s(t,u);b&&Qn?(0==w?(a=p,f=g):(a=m,f=x),c=vl[e],h=$l(_(a,r),c,i,0),d=$l(_(a+f,r),c,i,0),di(al(h,d),ol(d-h))):di(0,i),v&&li?(1==w?(a=p,f=g):(a=m,f=x),c=vl[t],h=ql(_(a,u),c,o,0),d=ql(_(a+f,u),c,o,0),pi(al(h,d),ol(d-h))):pi(0,o)}else yi()}else{let l=ol(Ln-Fn),e=ol(On-Rn);if(1==jl.ori){let t=l;l=e,e=t}Qn=Zn.x&&l>=Zn.dist,li=Zn.y&&e>=Zn.dist;let t,n,s=Zn.uni;null!=s?Qn&&li&&(Qn=l>=s,li=e>=s,Qn||li||(e>l?li=!0:Qn=!0)):Zn.x&&Zn.y&&(Qn||li)&&(Qn=li=!0),Qn&&(0==jl.ori?(t=Gn,n=Nn):(t=In,n=jn),di(al(t,n),ol(n-t)),li||pi(0,o)),li&&(1==jl.ori?(t=Gn,n=Nn):(t=In,n=jn),pi(al(t,n),ol(n-t)),Qn||di(0,i)),Qn||li||(di(0,0),pi(0,0))}if(Zn._x=Qn,Zn._y=li,null==l){if(t){if(null!=Ri){let[l,e]=Fi.scales;Fi.values[0]=null!=l?fi(0==jl.ori?Nn:jn,l):null,Fi.values[1]=null!=e?fi(1==jl.ori?Nn:jn,e):null}Ii(f,k,Nn,jn,Ie,Le,n)}if(Et){let l=t&&Fi.setSeries,e=Tt.prox;null==ui?si>e||oi(ri,ai,!0,l):si>e?oi(null,ai,!0,l):ri!=ui&&oi(ri,ai,!0,l)}}_t&&(ie.idx=n,mi()),!1!==e&&Ci("setCursor")}k.setLegend=mi;let wi=null;function _i(l=!1){l?wi=null:(wi=el.getBoundingClientRect(),Ci("syncRect",wi))}function bi(l,e,t,n,i,o){oe._lock||Xn&&null!=l&&0==l.movementX&&0==l.movementY||(vi(l,e,t,n,i,o,0,!1,null!=l),null!=l?xi(null,!0,!0):xi(e,!0,!1))}function vi(l,e,t,n,i,o,s,r,u){if(null==wi&&_i(!1),Mt(l),null!=l)t=l.clientX-wi.left,n=l.clientY-wi.top;else{if(0>t||0>n)return Nn=-10,void(jn=-10);let[l,s]=Fi.scales,r=e.cursor.sync,[u,a]=r.values,[f,c]=r.scales,[h,d]=Fi.match,p=e.axes[0].side%2==1,m=0==jl.ori?Ie:Le,g=1==jl.ori?Ie:Le,x=p?o:i,w=p?i:o,_=p?n:t,b=p?t:n;if(t=null!=f?h(l,f)?C(u,vl[l],m,0):-10:m*(_/x),n=null!=c?d(s,c)?C(a,vl[s],g,0):-10:g*(b/w),1==jl.ori){let l=t;t=n,n=l}}!u||null!=e&&e.cursor.event.type!=f||(t>1&&Ie-1>t||(t=zl(t,Ie)),n>1&&Le-1>n||(n=zl(n,Le))),r?(Fn=t,Rn=n,[Gn,In]=oe.move(k,t,n)):(Nn=t,jn=n)}Object.defineProperty(k,"rect",{get:()=>(null==wi&&_i(!1),wi)});const ki={width:0,height:0,left:0,top:0};function yi(){ni(ki,!1)}let Mi,Si,Ti,Ei;function zi(l,e,t,n,i,o){Xn=!0,Qn=li=Zn._x=Zn._y=!1,vi(l,e,t,n,i,o,0,!0,!1),null!=l&&(Ce(h,b,Di,!1),Ii(c,k,Gn,In,Ie,Le,null));let{left:s,top:r,width:u,height:a}=ei;Mi=s,Si=r,Ti=u,Ei=a}function Di(l,e,t,n,i,o){Xn=Zn._x=Zn._y=!1,vi(l,e,t,n,i,o,0,!1,!0);let{left:s,top:r,width:u,height:a}=ei,f=u>0||a>0,c=Mi!=s||Si!=r||Ti!=u||Ei!=a;if(f&&c&&ni(ei),Zn.setScale&&f&&c){let l=s,e=u,t=r,n=a;if(1==jl.ori&&(l=r,e=a,t=s,n=u),Qn&&ii(El,fi(l,El),fi(l+e,El)),li)for(let l in vl){let e=vl[l];l!=El&&null==e.from&&e.min!=gl&&ii(l,fi(t+n,l),fi(t,l))}yi()}else oe.lock&&(oe._lock=!oe._lock,xi(e,!0,null!=l));null!=l&&(He(h,b),Ii(h,k,Nn,jn,Ie,Le,null))}function Pi(l){oe._lock||(Mt(l),xn(),yi(),null!=l&&Ii(m,k,Nn,jn,Ie,Le,null))}function Ai(){xl.forEach(ln),vt(k.width,k.height,!0)}G(x,v,Ai);const Wi={};Wi.mousedown=zi,Wi.mousemove=bi,Wi.mouseup=Di,Wi.dblclick=Pi,Wi.setSeries=(l,e,t,n)=>{-1!=(t=(0,Fi.match[2])(k,e,t))&&oi(t,n,!0,!1)},re&&(Ce(c,el,zi),Ce(f,el,bi),Ce(d,el,(l=>{Mt(l),_i(!1)})),Ce(p,el,(function(l){if(oe._lock)return;Mt(l);let e=Xn;if(Xn){let l,e,t=!0,n=!0,i=10;0==jl.ori?(l=Qn,e=li):(l=li,e=Qn),l&&e&&(t=i>=Nn||Nn>=Ie-i,n=i>=jn||jn>=Le-i),l&&t&&(Nn=Gn>Nn?0:Ie),e&&n&&(jn=In>jn?0:Le),xi(null,!0,!0),Xn=!1}Nn=-10,jn=-10,te.fill(null),xi(null,!0,!0),e&&(Xn=e)})),Ce(m,el,Pi),It.add(k),k.syncRect=_i);const Yi=k.hooks=u.hooks||{};function Ci(l,e,t){Vn?Bn.push([l,e,t]):l in Yi&&Yi[l].forEach((l=>{l.call(null,k,e,t)}))}(u.plugins||[]).forEach((l=>{for(let e in l.hooks)Yi[e]=(Yi[e]||[]).concat(l.hooks[e])}));const Hi=(l,e,t)=>t,Fi=Bl({key:null,setSeries:!1,filters:{pub:Ml,sub:Ml},scales:[El,pl[1]?pl[1].scale:null],match:[Sl,Sl,Hi],values:[null,null]},oe.sync);2==Fi.match.length&&Fi.match.push(Hi),oe.sync=Fi;const Ri=Fi.key,Gi=dt(Ri);function Ii(l,e,t,n,i,o,s){Fi.filters.pub(l,e,t,n,i,o,s)&&Gi.pub(l,e,t,n,i,o,s)}function Li(){Ci("init",u,g),gn(g||u.data,!1),Kl[El]?Kn(El,Kl[El]):xn(),wt=ei.show&&(ei.width>0||ei.height>0),xt=_t=!0,vt(u.width,u.height)}return Gi.sub(k),k.pub=function(l,e,t,n,i,o,s){Fi.filters.sub(l,e,t,n,i,o,s)&&Wi[l](null,e,t,n,i,o,s)},k.destroy=function(){Gi.unsub(k),It.delete(k),Pe.clear(),I(x,v,Ai),R.remove(),ce?.remove(),Ci("destroy")},pl.forEach(Yt),xl.forEach((function(l,e){if(l._show=l.show,l.show){let t=vl[l.scale];null==t&&(l.scale=l.side%2?pl[1].scale:El,t=vl[l.scale]);let n=t.time;l.size=bl(l.size),l.space=bl(l.space),l.rotate=bl(l.rotate),Gl(l.incrs)&&l.incrs.forEach((l=>{!Wl.has(l)&&Wl.set(l,Yl(l))})),l.incrs=bl(l.incrs||(2==t.distr?ae:n?1==hl?ke:Se:fe)),l.splits=bl(l.splits||(n&&1==t.distr?Ql:3==t.distr?Je:4==t.distr?qe:$e)),l.stroke=bl(l.stroke),l.grid.stroke=bl(l.grid.stroke),l.ticks.stroke=bl(l.ticks.stroke),l.border.stroke=bl(l.border.stroke);let i=l.values;l.values=Gl(i)&&!Gl(i[0])?bl(i):n?Gl(i)?De(Xl,ze(i,Zl)):Ll(i)?function(l,e){let t=ne(e);return(e,n)=>n.map((e=>t(l(e))))}(Xl,i):i||le:i||Be,l.filter=bl(l.filter||(3>t.distr||10!=t.log?3==t.distr&&2==t.log?tt:kl:et)),l.font=Qt(l.font),l.labelFont=Qt(l.labelFont),l._size=l.size(k,null,e,0),l._space=l._rotate=l._incrs=l._found=l._splits=l._values=null,l._size>0&&(Ct[e]=!0,l._el=D("u-axis",X))}})),_?_ instanceof HTMLElement?(_.appendChild(R),Li()):_(k,Li):Li(),k}en.assign=Bl,en.fmtNum=tl,en.rangeNum=Z,en.rangeLog=B,en.rangeAsinh=$,en.orient=pt,en.pxRatio=y,en.join=function(l,e){if(function(l){let e=l[0][0],t=e.length;for(let n=1;l.length>n;n++){let i=l[n][0];if(i.length!=t)return!1;if(i!=e)for(let l=0;t>l;l++)if(i[l]!=e[l])return!1}return!0}(l)){let e=l[0].slice();for(let t=1;l.length>t;t++)e.push(...l[t].slice(1));return function(l,e=100){const t=l.length;if(1>=t)return!0;let n=0,i=t-1;for(;i>=n&&null==l[n];)n++;for(;i>=n&&null==l[i];)i--;if(n>=i)return!0;const o=fl(1,sl((i-n+1)/e));for(let e=l[n],t=n+o;i>=t;t+=o){const n=l[t];if(null!=n){if(e>=n)return!1;e=n}}return!0}(e[0])||(e=function(l){let e=l[0],t=e.length,n=Array(t);for(let l=0;n.length>l;l++)n[l]=l;n.sort(((l,t)=>e[l]-e[t]));let i=[];for(let e=0;l.length>e;e++){let o=l[e],s=Array(t);for(let l=0;t>l;l++)s[l]=o[n[l]];i.push(s)}return i}(e)),e}let t=new Set;for(let e=0;l.length>e;e++){let n=l[e][0],i=n.length;for(let l=0;i>l;l++)t.add(n[l])}let n=[Array.from(t).sort(((l,e)=>l-e))],i=n[0].length,o=new Map;for(let l=0;i>l;l++)o.set(n[0][l],l);for(let t=0;l.length>t;t++){let s=l[t],r=s[0];for(let l=1;s.length>l;l++){let u=s[l],a=Array(i).fill(void 0),f=e?e[t][l]:1,c=[];for(let l=0;u.length>l;l++){let e=u[l],t=o.get(r[l]);null===e?0!=f&&(a[t]=e,2==f&&c.push(t)):a[t]=e}$l(a,c,i),n.push(a)}}return n},en.fmtDate=ne,en.tzDate=function(l,e){let t;return"UTC"==e||"Etc/UTC"==e?t=new Date(+l+6e4*l.getTimezoneOffset()):e==ie?t=l:(t=new Date(l.toLocaleString("en-US",{timeZone:e})),t.setMilliseconds(l.getMilliseconds())),t},en.sync=dt;{en.addGap=function(l,e,t){let n=l[l.length-1];n&&n[0]==e?n[1]=t:l.push([e,t])},en.clipGaps=wt;let l=en.paths={points:Wt};l.linear=Ft,l.stepped=function(l){const e=Q(l.align,1),t=Q(l.ascDesc,!1),n=Q(l.alignGaps,0),i=Q(l.extend,!1);return(l,o,s,r)=>pt(l,o,((u,a,f,c,h,d,p,m,g,x,w)=>{[s,r]=U(f,s,r);let _=u.pxRound,{left:b,width:v}=l.bbox,k=l=>_(d(l,c,x,m)),M=l=>_(p(l,h,w,g)),S=0==c.ori?Mt:St;const T={stroke:new Path2D,fill:null,clip:null,band:null,gaps:null,flags:1},E=T.stroke,z=c.dir*(0==c.ori?1:-1);let D=M(f[1==z?s:r]),P=k(a[1==z?s:r]),A=P,W=P;i&&-1==e&&(W=b,S(E,W,D)),S(E,P,D);for(let l=1==z?s:r;l>=s&&r>=l;l+=z){let t=f[l];if(null==t)continue;let n=k(a[l]),i=M(t);1==e?S(E,n,D):S(E,A,i),S(E,n,i),D=i,A=n}let Y=A;i&&1==e&&(Y=b+v,S(E,Y,D));let[C,H]=mt(l,o);if(null!=u.fill||0!=C){let e=T.fill=new Path2D(E),t=M(u.fillTo(l,o,u.min,u.max,C));S(e,Y,t),S(e,W,t)}if(!u.spanGaps){let i=[];i.push(..._t(a,f,s,r,z,k,n));let h=u.width*y/2,d=t||1==e?h:-h,p=t||-1==e?-h:h;i.forEach((l=>{l[0]+=d,l[1]+=p})),T.gaps=i=u.gaps(l,o,s,r,i),T.clip=wt(i,c.ori,m,g,x,w)}return 0!=H&&(T.band=2==H?[xt(l,o,s,r,E,-1),xt(l,o,s,r,E,1)]:xt(l,o,s,r,E,H)),T}))},l.bars=function(l){const e=Q((l=l||Hl).size,[.6,gl,1]),t=l.align||0,n=l.gap||0;let i=l.radius;i=null==i?[0,0]:"number"==typeof i?[i,0]:i;const o=bl(i),s=1-e[0],r=Q(e[1],gl),u=Q(e[2],1),a=Q(l.disp,Hl),f=Q(l.each,(()=>{})),{fill:c,stroke:h}=a;return(l,e,i,d)=>pt(l,e,((p,m,g,x,w,_,b,v,k,M,S)=>{let T,E,z=p.pxRound,D=t,P=n*y,A=r*y,W=u*y;0==x.ori?[T,E]=o(l,e):[E,T]=o(l,e);const Y=x.dir*(0==x.ori?1:-1);let C,H,F,R=0==x.ori?Tt:Et,G=0==x.ori?f:(l,e,t,n,i,o,s)=>{f(l,e,t,i,n,s,o)},I=Q(l.bands,Fl).find((l=>l.series[0]==e)),L=p.fillTo(l,e,p.min,p.max,null!=I?I.dir:0),O=z(b(L,w,S,k)),N=M,j=z(p.width*y),U=!1,V=null,B=null,$=null,J=null;null==c||0!=j&&null==h||(U=!0,V=c.values(l,e,i,d),B=new Map,new Set(V).forEach((l=>{null!=l&&B.set(l,new Path2D)})),j>0&&($=h.values(l,e,i,d),J=new Map,new Set($).forEach((l=>{null!=l&&J.set(l,new Path2D)}))));let{x0:q,size:K}=a;if(null!=q&&null!=K){D=1,m=q.values(l,e,i,d),2==q.unit&&(m=m.map((e=>l.posToVal(v+e*M,x.key,!0))));let t=K.values(l,e,i,d);H=2==K.unit?t[0]*M:_(t[0],x,M,v)-_(0,x,M,v),N=Rt(m,g,_,x,M,v,N),F=N-H+P}else N=Rt(m,g,_,x,M,v,N),F=N*s+P,H=N-F;1>F&&(F=0),H/2>j||(j=0),5>F&&(z=vl);let X=F>0;H=z(wl(N-F-(X?j:0),W,A)),C=(0==D?H/2:D==Y?0:H)-D*Y*((0==D?P/2:0)+(X?j/2:0));const Z={stroke:null,fill:null,clip:null,band:null,gaps:null,flags:0},ll=U?null:new Path2D;let el=null;if(null!=I)el=l.data[I.series[1]];else{let{y0:t,y1:n}=a;null!=t&&null!=n&&(g=n.values(l,e,i,d),el=t.values(l,e,i,d))}let tl=T*H,nl=E*H;for(let t=1==Y?i:d;t>=i&&d>=t;t+=Y){let n=g[t];if(null==n)continue;if(null!=el){let l=el[t]??0;if(n-l==0)continue;O=b(l,w,S,k)}let i=_(2!=x.distr||null!=a?m[t]:t,x,M,v),o=b(Q(n,L),w,S,k),s=z(i-C),r=z(fl(o,O)),u=z(al(o,O)),f=r-u;if(null!=n){let i=0>n?nl:tl,o=0>n?tl:nl;U?(j>0&&null!=$[t]&&R(J.get($[t]),s,u+sl(j/2),H,fl(0,f-j),i,o),null!=V[t]&&R(B.get(V[t]),s,u+sl(j/2),H,fl(0,f-j),i,o)):R(ll,s,u+sl(j/2),H,fl(0,f-j),i,o),G(l,e,t,s-j/2,u,H+j,f)}}return j>0?Z.stroke=U?J:ll:U||(Z._fill=0==p.width?p._fill:p._stroke??p._fill,Z.width=0),Z.fill=U?B:ll,Z}))},l.spline=function(l){return function(l,e){const t=Q(e?.alignGaps,0);return(e,n,i,o)=>pt(e,n,((s,r,u,a,f,c,h,d,p,m,g)=>{[i,o]=U(u,i,o);let x,w,_,b=s.pxRound,v=l=>b(c(l,a,m,d)),k=l=>b(h(l,f,g,p));0==a.ori?(x=kt,_=Mt,w=Pt):(x=yt,_=St,w=At);const y=a.dir*(0==a.ori?1:-1);let M=v(r[1==y?i:o]),S=M,T=[],E=[];for(let l=1==y?i:o;l>=i&&o>=l;l+=y)if(null!=u[l]){let e=v(r[l]);T.push(S=e),E.push(k(u[l]))}const z={stroke:l(T,E,x,_,w,b),fill:null,clip:null,band:null,gaps:null,flags:1},D=z.stroke;let[P,A]=mt(e,n);if(null!=s.fill||0!=P){let l=z.fill=new Path2D(D),t=k(s.fillTo(e,n,s.min,s.max,P));_(l,S,t),_(l,M,t)}if(!s.spanGaps){let l=[];l.push(..._t(r,u,i,o,y,v,t)),z.gaps=l=s.gaps(e,n,i,o,l),z.clip=wt(l,a.ori,d,p,m,g)}return 0!=A&&(z.band=2==A?[xt(e,n,i,o,D,-1),xt(e,n,i,o,D,1)]:xt(e,n,i,o,D,A)),z}))}(Gt,l)}}return en}();
diff --git a/public/vendor/uPlot.min.css b/public/vendor/uPlot.min.css
new file mode 100644
index 0000000..a030d63
--- /dev/null
+++ b/public/vendor/uPlot.min.css
@@ -0,0 +1 @@
+.uplot, .uplot *, .uplot *::before, .uplot *::after {box-sizing: border-box;}.uplot {font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";line-height: 1.5;width: min-content;}.u-title {text-align: center;font-size: 18px;font-weight: bold;}.u-wrap {position: relative;user-select: none;}.u-over, .u-under {position: absolute;}.u-under {overflow: hidden;}.uplot canvas {display: block;position: relative;width: 100%;height: 100%;}.u-axis {position: absolute;}.u-legend {font-size: 14px;margin: auto;text-align: center;}.u-inline {display: block;}.u-inline * {display: inline-block;}.u-inline tr {margin-right: 16px;}.u-legend th {font-weight: 600;}.u-legend th > * {vertical-align: middle;display: inline-block;}.u-legend .u-marker {width: 1em;height: 1em;margin-right: 4px;background-clip: padding-box !important;}.u-inline.u-live th::after {content: ":";vertical-align: middle;}.u-inline:not(.u-live) .u-value {display: none;}.u-series > * {padding: 4px;}.u-series th {cursor: pointer;}.u-legend .u-off > * {opacity: 0.3;}.u-select {background: rgba(0,0,0,0.07);position: absolute;pointer-events: none;}.u-cursor-x, .u-cursor-y {position: absolute;left: 0;top: 0;pointer-events: none;will-change: transform;}.u-hz .u-cursor-x, .u-vt .u-cursor-y {height: 100%;border-right: 1px dashed #607D8B;}.u-hz .u-cursor-y, .u-vt .u-cursor-x {width: 100%;border-bottom: 1px dashed #607D8B;}.u-cursor-pt {position: absolute;top: 0;left: 0;border-radius: 50%;border: 0 solid;pointer-events: none;will-change: transform;/*this has to be !important since we set inline "background" shorthand */background-clip: padding-box !important;}.u-axis.u-off, .u-select.u-off, .u-cursor-x.u-off, .u-cursor-y.u-off, .u-cursor-pt.u-off {display: none;}
\ No newline at end of file
diff --git a/src/ingest/census_acs.ts b/src/ingest/census_acs.ts
new file mode 100644
index 0000000..dc993e8
--- /dev/null
+++ b/src/ingest/census_acs.ts
@@ -0,0 +1,116 @@
+/**
+ * Census ACS 5-year (2023 vintage) — one call for all counties.
+ * Metrics -> metric_series source 'acs', period 2023-07-01 (mid-vintage anchor).
+ * Also updates region.population from B01003.
+ * Keyless was probed 2026-07-21 and REDIRECTS to missing_key.html — a key is required;
+ * we read CENSUS_API_KEY from ./.env then ~/Projects/secrets-manager/.env.
+ */
+import { readFileSync, existsSync } from 'node:fs';
+import { join } from 'node:path';
+import { homedir } from 'node:os';
+import { query, pool } from '../../db/pool.ts';
+import { openRun, closeRun } from './run.ts';
+import { loadRegionMaps, upsertMetricRows, UnmatchedCollector, type MetricRow } from './crosswalk.ts';
+
+const ACS_PERIOD = '2023-07-01';
+const SOURCE = 'acs';
+const VARS = 'NAME,B19013_001E,B25077_001E,B25064_001E,B01003_001E,B25002_001E,B25002_003E,B25003_001E,B25003_003E';
+const BASE = `https://api.census.gov/data/2023/acs/acs5?get=${VARS}&for=county:*`;
+
+function findCensusKey(): string | null {
+  if (process.env.CENSUS_API_KEY) return process.env.CENSUS_API_KEY;
+  for (const p of [join(process.cwd(), '.env'), join(homedir(), 'Projects', 'secrets-manager', '.env')]) {
+    if (!existsSync(p)) continue;
+    const m = readFileSync(p, 'utf8').match(/^CENSUS_API_KEY=(.+)$/m);
+    if (m) return m[1].trim().replace(/^["']|["']$/g, '');
+  }
+  return null;
+}
+
+/** Census sentinel negatives (-666666666 etc.) and null -> undefined. */
+function num(v: string | null): number | undefined {
+  if (v == null || v === '') return undefined;
+  const n = Number(v);
+  if (!Number.isFinite(n) || n < 0) return undefined;
+  return n;
+}
+
+async function main() {
+  const key = findCensusKey();
+  const url = key ? `${BASE}&key=${key}` : BASE;
+  const runId = await openRun(SOURCE, BASE);
+  try {
+    const res = await fetch(url, { redirect: 'follow' });
+    if (!res.ok) throw new Error(`ACS fetch failed: ${res.status} ${res.statusText}`);
+    if (res.url.includes('missing_key')) throw new Error('ACS redirected to missing_key.html — CENSUS_API_KEY required/invalid');
+    const data: string[][] = await res.json();
+    if (!Array.isArray(data) || data.length < 2) throw new Error(`ACS returned ${Array.isArray(data) ? data.length : 0} rows`);
+
+    const header = data[0];
+    const col = (name: string) => {
+      const i = header.indexOf(name);
+      if (i < 0) throw new Error(`ACS header missing ${name}: ${header.join(',')}`);
+      return i;
+    };
+    const iIncome = col('B19013_001E'), iValue = col('B25077_001E'), iRent = col('B25064_001E'),
+      iPop = col('B01003_001E'), iUnits = col('B25002_001E'), iVacant = col('B25002_003E'),
+      iOccTot = col('B25003_001E'), iRenter = col('B25003_003E'),
+      iState = col('state'), iCounty = col('county'), iName = col('NAME');
+
+    const maps = await loadRegionMaps();
+    const unmatched = new UnmatchedCollector();
+    const rows: MetricRow[] = [];
+    const popUpdates: { regionId: number; population: number }[] = [];
+    let skipped = 0;
+
+    for (const r of data.slice(1)) {
+      const fips = r[iState].padStart(2, '0') + r[iCounty].padStart(3, '0');
+      const region = maps.byFips.get(fips);
+      if (!region) {
+        unmatched.add(SOURCE, { fips, name: r[iName] });
+        skipped++;
+        continue;
+      }
+      const push = (metric: string, value: number | undefined) => {
+        if (value !== undefined) rows.push({ regionId: region.id, source: SOURCE, metric, period: ACS_PERIOD, value });
+      };
+      push('median_hh_income', num(r[iIncome]));
+      push('median_home_value_acs', num(r[iValue]));
+      push('median_gross_rent', num(r[iRent]));
+      const pop = num(r[iPop]);
+      push('population', pop);
+      if (pop !== undefined) popUpdates.push({ regionId: region.id, population: pop });
+      const units = num(r[iUnits]), vacant = num(r[iVacant]);
+      if (units !== undefined && units > 0 && vacant !== undefined) push('vacancy_rate', vacant / units);
+      const occ = num(r[iOccTot]), renter = num(r[iRenter]);
+      if (occ !== undefined && occ > 0 && renter !== undefined) push('renter_share', renter / occ);
+    }
+
+    if (rows.length === 0) throw new Error('ACS parse produced 0 metric rows');
+
+    const upserted = await upsertMetricRows(rows, runId);
+    for (let i = 0; i < popUpdates.length; i += 500) {
+      const batch = popUpdates.slice(i, i + 500);
+      const params: unknown[] = [];
+      const values = batch.map((u, j) => { params.push(u.regionId, u.population); return `($${j * 2 + 1}::int,$${j * 2 + 2}::int)`; });
+      await query(
+        `UPDATE region rg SET population = v.pop FROM (VALUES ${values.join(',')}) AS v(id, pop) WHERE rg.id = v.id`,
+        params,
+      );
+    }
+    unmatched.flush();
+    await closeRun(runId, 'ok', {
+      upserted, skipped,
+      notes: `counties=${data.length - 1} key=${key ? 'used' : 'keyless'} pop_updates=${popUpdates.length} unmatched=${unmatched.count(SOURCE)}`,
+    });
+    console.log(`[acs] ok: ${upserted} metric rows, ${popUpdates.length} region.population updates, ${skipped} skipped`);
+  } catch (e) {
+    await closeRun(runId, 'failed', { notes: String(e) });
+    console.error('[acs] FAILED:', e);
+    process.exitCode = 1;
+  } finally {
+    await pool.end();
+  }
+}
+
+main();
diff --git a/src/ingest/derive_metrics.ts b/src/ingest/derive_metrics.ts
new file mode 100644
index 0000000..ea385f9
--- /dev/null
+++ b/src/ingest/derive_metrics.ts
@@ -0,0 +1,85 @@
+/**
+ * Derived metrics -> metric_series source 'derived'.
+ * For every county + metro:
+ *   affordability = latest zhvi / ACS median_hh_income (annual ACS joins to any zhvi month)
+ *   rent_yield    = (zori * 12) / zhvi at the latest common zhvi+zori period
+ *   zhvi_yoy      = zhvi latest vs 12 months prior (fraction)
+ * period stored = the zhvi period used. Idempotent upserts via the shared harness.
+ */
+import { pool, query } from '../../db/pool.ts';
+import { openRun, closeRun } from './run.ts';
+import { upsertMetricRows, type MetricRow } from './crosswalk.ts';
+
+const SOURCE = 'derived';
+
+interface SeriesRow { region_id: number; metric: string; period: string; value: string }
+
+async function main() {
+  const runId = await openRun(SOURCE);
+  try {
+    const r = await query<SeriesRow>(
+      `SELECT ms.region_id, ms.metric, to_char(ms.period, 'YYYY-MM-DD') AS period, ms.value::text AS value
+         FROM metric_series ms
+         JOIN region rg ON rg.id = ms.region_id AND rg.region_type IN ('county','metro')
+        WHERE (ms.source = 'zillow' AND ms.metric IN ('zhvi','zori'))
+           OR (ms.source = 'acs' AND ms.metric = 'median_hh_income')`,
+    );
+
+    type Per = { zhvi: Map<string, number>; zori: Map<string, number>; income?: number };
+    const byRegion = new Map<number, Per>();
+    for (const row of r.rows) {
+      let p = byRegion.get(row.region_id);
+      if (!p) { p = { zhvi: new Map(), zori: new Map() }; byRegion.set(row.region_id, p); }
+      const v = Number(row.value);
+      if (row.metric === 'zhvi') p.zhvi.set(row.period, v);
+      else if (row.metric === 'zori') p.zori.set(row.period, v);
+      else p.income = v;
+    }
+
+    const rows: MetricRow[] = [];
+    const monthsBack = (period: string, n: number) => {
+      const [y, m] = period.split('-').map(Number);
+      const total = y * 12 + (m - 1) - n;
+      return `${Math.floor(total / 12)}-${String((total % 12) + 1).padStart(2, '0')}-01`;
+    };
+
+    for (const [regionId, p] of byRegion) {
+      if (p.zhvi.size === 0) continue;
+      const zhviPeriods = [...p.zhvi.keys()].sort();
+      const latest = zhviPeriods[zhviPeriods.length - 1];
+      const zhvi = p.zhvi.get(latest)!;
+      if (!(zhvi > 0)) continue;
+
+      if (p.income && p.income > 0)
+        rows.push({ regionId, source: SOURCE, metric: 'affordability', period: latest, value: zhvi / p.income });
+
+      // rent_yield at the latest period where BOTH zhvi and zori exist
+      const common = [...p.zori.keys()].filter(k => p.zhvi.has(k)).sort();
+      if (common.length) {
+        const cp = common[common.length - 1];
+        const z = p.zhvi.get(cp)!, rent = p.zori.get(cp)!;
+        if (z > 0 && rent > 0)
+          rows.push({ regionId, source: SOURCE, metric: 'rent_yield', period: cp, value: (rent * 12) / z });
+      }
+
+      const prior = p.zhvi.get(monthsBack(latest, 12));
+      if (prior && prior > 0)
+        rows.push({ regionId, source: SOURCE, metric: 'zhvi_yoy', period: latest, value: zhvi / prior - 1 });
+    }
+
+    if (rows.length === 0) throw new Error('derive produced 0 rows — are zillow + acs ingests loaded?');
+    const upserted = await upsertMetricRows(rows, runId);
+    const counts: Record<string, number> = {};
+    for (const row of rows) counts[row.metric] = (counts[row.metric] || 0) + 1;
+    await closeRun(runId, 'ok', { upserted, notes: JSON.stringify(counts) });
+    console.log(`[derive] ok: ${upserted} rows`, counts);
+  } catch (e) {
+    await closeRun(runId, 'failed', { notes: String(e) });
+    console.error('[derive] FAILED:', e);
+    process.exitCode = 1;
+  } finally {
+    await pool.end();
+  }
+}
+
+main();
diff --git a/src/ingest/fhfa_hpi.ts b/src/ingest/fhfa_hpi.ts
new file mode 100644
index 0000000..3467d0c
--- /dev/null
+++ b/src/ingest/fhfa_hpi.ts
@@ -0,0 +1,151 @@
+/**
+ * FHFA House Price Index (HPI_master.csv) -> metric 'hpi', quarterly, metro + state.
+ * URL DRIFT (probed 2026-07-21): the old /DataTools/Downloads/Documents/HPI/HPI_master.csv
+ * 404s; current path is /hpi/download/monthly/hpi_master.csv (serves the full master file).
+ * Flavor choice: purchase-only quarterly covers only 100 MSAs vs 410 for all-transactions,
+ * so we use hpi_type='traditional', hpi_flavor='all-transactions', frequency='quarterly'.
+ * Metro match: place_id IS the CBSA code -> region.cbsa_code. State match: 2-letter place_id.
+ * Last 12 quarters only; period = quarter-end date; value = index_nsa (SA blank for many MSAs).
+ */
+import { readFileSync } from 'node:fs';
+import { pool } from '../../db/pool.ts';
+import { openRun, closeRun, download } from './run.ts';
+import { loadRegionMaps, loadOverrides, buildMetroMatcher, upsertMetricRows, upsertSourceRegionMap, UnmatchedCollector, type MetricRow } from './crosswalk.ts';
+
+const SOURCE = 'fhfa';
+const URL = 'https://www.fhfa.gov/hpi/download/monthly/hpi_master.csv';
+const QUARTERS_KEPT = 12;
+
+function parseCsvLine(line: string): string[] {
+  const out: string[] = [];
+  let cur = '', inQ = false;
+  for (let i = 0; i < line.length; i++) {
+    const c = line[i];
+    if (inQ) {
+      if (c === '"') { if (line[i + 1] === '"') { cur += '"'; i++; } else inQ = false; }
+      else cur += c;
+    } else if (c === '"') inQ = true;
+    else if (c === ',') { out.push(cur); cur = ''; }
+    else cur += c;
+  }
+  out.push(cur);
+  return out;
+}
+
+const QUARTER_END: Record<string, string> = { '1': '03-31', '2': '06-30', '3': '09-30', '4': '12-31' };
+
+async function main() {
+  const runId = await openRun(SOURCE, URL);
+  try {
+    const { path, sha256 } = await download(URL, 'hpi_master.csv');
+    const lines = readFileSync(path, 'utf8').split('\n');
+    const header = parseCsvLine(lines[0].trim());
+    const idx = (name: string) => {
+      const i = header.indexOf(name);
+      if (i < 0) throw new Error(`HPI header missing ${name}: ${header.join(',')}`);
+      return i;
+    };
+    const iType = idx('hpi_type'), iFlavor = idx('hpi_flavor'), iFreq = idx('frequency'),
+      iLevel = idx('level'), iName = idx('place_name'), iId = idx('place_id'),
+      iYr = idx('yr'), iPeriod = idx('period'), iNsa = idx('index_nsa');
+
+    type Parsed = { level: string; placeId: string; placeName: string; yr: number; q: string; value: number };
+    const parsed: Parsed[] = [];
+    let maxYr = 0;
+    for (let n = 1; n < lines.length; n++) {
+      const line = lines[n].trim();
+      if (!line) continue;
+      const c = parseCsvLine(line);
+      if (c[iType] !== 'traditional' || c[iFlavor] !== 'all-transactions' || c[iFreq] !== 'quarterly') continue;
+      const level = c[iLevel];
+      if (level !== 'MSA' && level !== 'State') continue;
+      const value = Number(c[iNsa]);
+      if (!Number.isFinite(value)) continue;
+      const yr = Number(c[iYr]);
+      parsed.push({ level, placeId: c[iId], placeName: c[iName], yr, q: c[iPeriod], value });
+      if (yr > maxYr) maxYr = yr;
+    }
+    if (parsed.length === 0) throw new Error('HPI parse produced 0 rows — format drift?');
+
+    // keep last 12 quarters: quarter index yr*4 + q
+    const latestQ = Math.max(...parsed.filter(p => p.yr === maxYr).map(p => Number(p.q)));
+    const latestIdx = maxYr * 4 + latestQ;
+    const cutoffIdx = latestIdx - (QUARTERS_KEPT - 1);
+
+    const maps = await loadRegionMaps();
+    const overrides = loadOverrides(SOURCE);
+    const matchMetro = buildMetroMatcher(maps);
+    const unmatched = new UnmatchedCollector();
+    // regions covered by a DIRECT cbsa_code match — an MSAD fallback must never overwrite these
+    const directRegionIds = new Set<number>();
+    for (const p of parsed) {
+      if (p.level !== 'MSA') continue;
+      const direct = maps.byCbsa.get(p.placeId);
+      if (direct) directRegionIds.add(direct.id);
+    }
+    /** "Los Angeles-Long Beach-Glendale, CA (MSAD)" -> parent CBSA via first city × each state token. */
+    const matchMsad = (placeName: string) => {
+      const name = placeName.replace(/\s*\(MSAD\)$/, '');
+      const comma = name.lastIndexOf(',');
+      if (comma < 0) return null;
+      const firstCity = name.slice(0, comma).split(/[-/]/)[0].trim();
+      for (const st of name.slice(comma + 1).trim().split('-')) {
+        const m = matchMetro(`${firstCity}, ${st.trim()}`);
+        if (m) return m;
+      }
+      return null;
+    };
+    const rows: MetricRow[] = [];
+    const mapEntries: { source: string; sourceRegionId: string; regionId: number; matchMethod: string }[] = [];
+    const unmatchedIds = new Set<string>();
+
+    for (const p of parsed) {
+      if (p.yr * 4 + Number(p.q) < cutoffIdx) continue;
+      let region = p.level === 'MSA' ? maps.byCbsa.get(p.placeId) : maps.byStateCode.get(p.placeId);
+      let method = p.level === 'MSA' ? 'cbsa' : 'state';
+      if (!region && overrides[p.placeId]) {
+        region = maps.byCanonicalKey.get(overrides[p.placeId]);
+        method = 'override';
+      }
+      if (!region && p.level === 'MSA' && p.placeName.endsWith('(MSAD)')) {
+        // FHFA lists divisions INSTEAD of the parent CBSA for the largest metros.
+        // The PRIMARY division's first-named city equals the parent CBSA's first city
+        // ("Los Angeles-Long Beach-Glendale, CA" -> CBSA 31080); secondary divisions
+        // (Anaheim, Camden, Cambridge...) correctly fail the prefix match and stay skipped.
+        // Never applied to a region already covered by a direct cbsa_code match.
+        const m = matchMsad(p.placeName);
+        if (m && !directRegionIds.has(m.region.id)) { region = m.region; method = 'msad_primary_city'; }
+      }
+      if (!region) {
+        if (!unmatchedIds.has(p.placeId)) {
+          unmatchedIds.add(p.placeId);
+          unmatched.add(SOURCE, { level: p.level, place_id: p.placeId, place_name: p.placeName });
+        }
+        continue;
+      }
+      rows.push({
+        regionId: region.id, source: SOURCE, metric: 'hpi',
+        period: `${p.yr}-${QUARTER_END[p.q]}`, value: p.value,
+      });
+      mapEntries.push({ source: SOURCE, sourceRegionId: p.placeId, regionId: region.id, matchMethod: method });
+    }
+    if (rows.length === 0) throw new Error('HPI matched 0 regions — crosswalk drift?');
+
+    const upserted = await upsertMetricRows(rows, runId);
+    await upsertSourceRegionMap(mapEntries);
+    unmatched.flush();
+    await closeRun(runId, 'ok', {
+      upserted, skipped: unmatchedIds.size, fileHash: sha256,
+      notes: `flavor=all-transactions latest=${maxYr}Q${latestQ} quarters=${QUARTERS_KEPT} unmatched_places=${unmatchedIds.size}`,
+    });
+    console.log(`[fhfa] ok: ${upserted} rows (latest ${maxYr}Q${latestQ}), ${unmatchedIds.size} unmatched place_ids`);
+  } catch (e) {
+    await closeRun(runId, 'failed', { notes: String(e) });
+    console.error('[fhfa] FAILED:', e);
+    process.exitCode = 1;
+  } finally {
+    await pool.end();
+  }
+}
+
+main();
diff --git a/src/server/index.ts b/src/server/index.ts
index ff3e097..5e2ef77 100644
--- a/src/server/index.ts
+++ b/src/server/index.ts
@@ -77,6 +77,102 @@ app.get('/api/choropleth', async (req, res) => {
   }
 });
 
+// market detail: full 36mo series (all sources) + latest per metric for one region
+app.get('/api/market', async (req, res) => {
+  try {
+    const key = String(req.query.key || '');
+    const rg = await query(
+      `SELECT id, region_type, canonical_key, name, state_code, fips, cbsa_code, lat, lng, population
+         FROM region WHERE canonical_key = $1`,
+      [key],
+    );
+    if (!rg.rows.length) return res.status(404).json({ error: 'region not found: ' + key });
+    const region = rg.rows[0];
+    const r = await query<{ source: string; metric: string; period: string; value: string }>(
+      `SELECT source, metric, to_char(period, 'YYYY-MM-DD') AS period, value::text AS value
+         FROM metric_series
+        WHERE region_id = $1
+          AND (period >= (CURRENT_DATE - INTERVAL '36 months') OR source = 'acs')
+        ORDER BY metric, period`,
+      [region.id],
+    );
+    const series: Record<string, [string, number][]> = {};
+    const latest: Record<string, number> = {};
+    for (const row of r.rows) {
+      (series[row.metric] ||= []).push([row.period, Number(row.value)]);
+      latest[row.metric] = Number(row.value); // rows are period-ASC per metric, so last write wins
+    }
+    res.json({ region, series, latest });
+  } catch (e: any) {
+    res.status(500).json({ error: String(e.message || e) });
+  }
+});
+
+const MARKETS_METRICS = [
+  'zhvi', 'zhvi_yoy', 'median_sale_price', 'median_sale_price_yoy', 'inventory', 'dom',
+  'months_of_supply', 'sale_to_list', 'median_hh_income', 'rent_yield', 'affordability',
+];
+
+// ranking dashboard: one row per region with latest score + latest key metrics
+app.get('/api/markets', async (req, res) => {
+  try {
+    const type = String(req.query.type || 'county');
+    if (type !== 'county' && type !== 'metro') return res.status(400).json({ error: 'type must be county|metro' });
+    const metricsQ = query<{ region_id: number; metric: string; value: string }>(
+      `SELECT DISTINCT ON (ms.region_id, ms.metric) ms.region_id, ms.metric, ms.value::text AS value
+         FROM metric_series ms
+         JOIN region rg ON rg.id = ms.region_id AND rg.region_type = $1
+        WHERE ms.metric = ANY($2)
+        ORDER BY ms.region_id, ms.metric, ms.period DESC`,
+      [type, MARKETS_METRICS],
+    );
+    const scoresQ = query<{ region_id: number; opportunity_score: string; rank: number; components: any }>(
+      `SELECT rs.region_id, rs.opportunity_score::text AS opportunity_score, rs.rank, rs.components
+         FROM region_scores rs
+         JOIN region rg ON rg.id = rs.region_id AND rg.region_type = $1
+        WHERE rs.score_date = (SELECT MAX(rs2.score_date) FROM region_scores rs2
+                                 JOIN region rg2 ON rg2.id = rs2.region_id AND rg2.region_type = $1)`,
+      [type],
+    );
+    const regionsQ = query(
+      `SELECT id, canonical_key, name, state_code, fips, cbsa_code, population
+         FROM region WHERE region_type = $1`,
+      [type],
+    );
+    const [metrics, scores, regions] = await Promise.all([metricsQ, scoresQ, regionsQ]);
+    const metricMap = new Map<number, Record<string, number>>();
+    for (const m of metrics.rows) {
+      let o = metricMap.get(m.region_id);
+      if (!o) { o = {}; metricMap.set(m.region_id, o); }
+      o[m.metric] = Number(m.value);
+    }
+    const scoreMap = new Map(scores.rows.map(s => [s.region_id, s]));
+    const rows = regions.rows.map((rg: any) => {
+      const m = metricMap.get(rg.id) || {};
+      const s = scoreMap.get(rg.id);
+      const sub = s?.components?.sub_scores || {};
+      return {
+        key: rg.canonical_key, name: rg.name, state: rg.state_code, population: rg.population,
+        opportunity_score: s ? Number(s.opportunity_score) : null,
+        rank: s?.rank ?? null,
+        momentum: sub.momentum ?? null, affordability_score: sub.affordability ?? null,
+        rent_yield_score: sub.rent_yield ?? null, inventory_trend: sub.inventory_trend ?? null,
+        velocity: sub.velocity ?? null,
+        data_completeness: s?.components?.data_completeness ?? null,
+        zhvi: m.zhvi ?? null, zhvi_yoy: m.zhvi_yoy ?? null,
+        median_sale_price: m.median_sale_price ?? null, median_sale_price_yoy: m.median_sale_price_yoy ?? null,
+        inventory: m.inventory ?? null, dom: m.dom ?? null,
+        months_of_supply: m.months_of_supply ?? null, sale_to_list: m.sale_to_list ?? null,
+        median_hh_income: m.median_hh_income ?? null, rent_yield: m.rent_yield ?? null,
+        affordability: m.affordability ?? null,
+      };
+    });
+    res.json({ type, count: rows.length, rows });
+  } catch (e: any) {
+    res.status(500).json({ error: String(e.message || e) });
+  }
+});
+
 app.use(express.static(join(ROOT, 'public')));
 
 app.listen(PORT, () => {

← 509b9f8 M2: Zillow ZHVI/ZORI + Redfin tracker ingests (1.19M rows),  ·  back to Nationalrealestate  ·  M4: deterministic opportunity scorer (5-component percentile effc2fd →