diff --git a/.gitattributes b/.gitattributes index a6344aac8c09253b3b630fb776ae94478aa0275b..d079320fc0089792fda7151a5caa51a08cb62721 100644 --- a/.gitattributes +++ b/.gitattributes @@ -33,3 +33,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text *.zip filter=lfs diff=lfs merge=lfs -text *.zst filter=lfs diff=lfs merge=lfs -text *tfevents* filter=lfs diff=lfs merge=lfs -text +trackio/assets/badge.png filter=lfs diff=lfs merge=lfs -text +trackio/assets/trackio_logo_old.png filter=lfs diff=lfs merge=lfs -text diff --git a/trackio/CHANGELOG.md b/trackio/CHANGELOG.md new file mode 100644 index 0000000000000000000000000000000000000000..553e69e52dab83ca6cc61d45344f6f918d2dd455 --- /dev/null +++ b/trackio/CHANGELOG.md @@ -0,0 +1,304 @@ +# trackio + +## 0.26.0 + +### Features + +- [#553](https://github.com/gradio-app/trackio/pull/553) [`06011ac`](https://github.com/gradio-app/trackio/commit/06011acc9c73341fd234f9cd8eaf96d5a34ad8ce) - fix: serve static-Space assets at /static/trackio. Thanks @abidlabs! +- [#563](https://github.com/gradio-app/trackio/pull/563) [`551569c`](https://github.com/gradio-app/trackio/commit/551569c16fb56ec63249ebdc28348d326ccf7126) - Fix Traces UI a bit. Thanks @abidlabs! +- [#550](https://github.com/gradio-app/trackio/pull/550) [`5690acd`](https://github.com/gradio-app/trackio/commit/5690acda5da303c63ad332451afeab3e9750fd1a) - fix: keep sparse metrics sparse through smoothing. Thanks @abidlabs! +- [#551](https://github.com/gradio-app/trackio/pull/551) [`0ef7266`](https://github.com/gradio-app/trackio/commit/0ef72660695cf932f3906ddbf33d41d087280a22) - add "group by" dropdown to sidebar. Thanks @Saba9! +- [#538](https://github.com/gradio-app/trackio/pull/538) [`a15c1a8`](https://github.com/gradio-app/trackio/commit/a15c1a8877c07514e0596630bb7c7299299994a9) - Subdue empty dashboard tabs. Thanks @abidlabs! +- [#559](https://github.com/gradio-app/trackio/pull/559) [`0b53a41`](https://github.com/gradio-app/trackio/commit/0b53a413909598f92138b6b6395a91c2d5034faf) - Store traces separately from metrics. Thanks @abidlabs! +- [#556](https://github.com/gradio-app/trackio/pull/556) [`d110001`](https://github.com/gradio-app/trackio/commit/d110001dbd9f6b262dfe41f2b702e3a71aa0cfc9) - fix: keep selected x-axis option in dropdown and dismiss dropdown on re-click. Thanks @Saba9! +- [#560](https://github.com/gradio-app/trackio/pull/560) [`aee2923`](https://github.com/gradio-app/trackio/commit/aee2923d3ada4f74d62d065c16f1f6a56a295e48) - Paginate Traces tab with step filter. Thanks @abidlabs! + +### Fixes + +- [#540](https://github.com/gradio-app/trackio/pull/540) [`0b674ac`](https://github.com/gradio-app/trackio/commit/0b674ac6438738de89bc5b3fb700ccfd8a39368c) - raise default metrics sampling cap from 1500 to 3000 so client-side smoothing on the Metrics tab runs over higher-resolution data. Thanks @edbeeching! + +## 0.25.1 + +### Features + +- [#535](https://github.com/gradio-app/trackio/pull/535) [`d7f1b27`](https://github.com/gradio-app/trackio/commit/d7f1b27a98f185d2d97ef54975d5865e0b5243c9) - Avoid HF token leaks in static snapshots. Thanks @abidlabs! + +## 0.25.0 + +### Features + +- [#533](https://github.com/gradio-app/trackio/pull/533) [`08bc5eb`](https://github.com/gradio-app/trackio/commit/08bc5eb090525d3ff5f7fa4233c30c42162aa74c) - Fix Windows-only emoji mojibake when uploading Space README. Thanks @tomaarsen! +- [#518](https://github.com/gradio-app/trackio/pull/518) [`e7ed176`](https://github.com/gradio-app/trackio/commit/e7ed176da53d8b49290fddd890b3d18c0b9b958f) - Traces in Trackio. Thanks @abidlabs! +- [#531](https://github.com/gradio-app/trackio/pull/531) [`27a50a3`](https://github.com/gradio-app/trackio/commit/27a50a37362020304b774344b4c774ff548985b6) - Add configurable custom frontends for Trackio. Thanks @abidlabs! + +## 0.24.2 + +### Features + +- [#527](https://github.com/gradio-app/trackio/pull/527) [`7d1c0b9`](https://github.com/gradio-app/trackio/commit/7d1c0b9c37ce9a9845e6bbe6c083da9d36084caf) - Fix dashboard UX issues: smoothing in share URL, run selection, and run filtering. Thanks @abidlabs! +- [#526](https://github.com/gradio-app/trackio/pull/526) [`643878a`](https://github.com/gradio-app/trackio/commit/643878a82985fab9e6675f769ff0107cb46e042a) - Add emoji to README and deploy README content. Thanks @qgallouedec! +- [#529](https://github.com/gradio-app/trackio/pull/529) [`a77972b`](https://github.com/gradio-app/trackio/commit/a77972b68541ebe9e056824e69c9bbca3979ece4) - Remove pydub dependency. Thanks @abidlabs! + +## 0.24.1 + +### Features + +- [#524](https://github.com/gradio-app/trackio/pull/524) [`65a6897`](https://github.com/gradio-app/trackio/commit/65a6897561b465fc8f05550562f8da1ba3c99060) - Fix `trackio skills add`. Thanks @abidlabs! +- [#522](https://github.com/gradio-app/trackio/pull/522) [`05aaca7`](https://github.com/gradio-app/trackio/commit/05aaca7f166bf7667b60b40656d677532a4bdd6e) - relax `starlette` dependency and fix import style. Thanks @abidlabs! +- [#525](https://github.com/gradio-app/trackio/pull/525) [`32c05c5`](https://github.com/gradio-app/trackio/commit/32c05c5d5e3aa84ca7099a6fa08a9093ccd4b95f) - Restore sidebar share and embed snippets, and fix query parameter regression. Thanks @abidlabs! + +## 0.24.0 + +### Features + +- [#502](https://github.com/gradio-app/trackio/pull/502) [`3b397df`](https://github.com/gradio-app/trackio/commit/3b397dfbaff9de137b088f3cad528117e14faab1) - Add docs on SQL & Parquet schema / format, as well as a new CLI command: `trackio query project --project PROJECT --sql SQL_QUERY`. Thanks @abidlabs! +- [#506](https://github.com/gradio-app/trackio/pull/506) [`498bbc4`](https://github.com/gradio-app/trackio/commit/498bbc47f66cc90cc5776f363d001a5571941c00) - Scope bucket sync to trackio/ subtree to avoid walking the HF cache. Thanks @abidlabs! +- [#505](https://github.com/gradio-app/trackio/pull/505) [`8e26ab9`](https://github.com/gradio-app/trackio/commit/8e26ab93b5d9caa2f81334f6fff42fb9cefbb232) - Add an `id` field to `Run` which is used internally, allowing users to have multiple runs with the same run name. Thanks @abidlabs! +- [#517](https://github.com/gradio-app/trackio/pull/517) [`29e1034`](https://github.com/gradio-app/trackio/commit/29e1034b795567ec5ed6d19c5a946915a6498e2a) - Fix static exports, Space bucket handling, and other misc issues. Thanks @abidlabs! +- [#489](https://github.com/gradio-app/trackio/pull/489) [`1b96db3`](https://github.com/gradio-app/trackio/commit/1b96db39c8fd4326e621ee2336b0fca4f263a18a) - Remove `gradio` dependency in `trackio` -- only `gradio_client` is needed locally anymore. Also lazily import `pandas` and remove it as a dependency. Thanks @abidlabs! +- [#513](https://github.com/gradio-app/trackio/pull/513) [`d54d290`](https://github.com/gradio-app/trackio/commit/d54d290fcb1bb08358b558a43a962f78abe990ea) - Reduce HF Spaces 429s: polling tuning and batched metric logs API. Thanks @abidlabs! +- [#516](https://github.com/gradio-app/trackio/pull/516) [`afe2959`](https://github.com/gradio-app/trackio/commit/afe295988928a3ea3ded38bdb5bb05cca85d3c74) - Fix run list order and legend overflow. Thanks @abidlabs! +- [#515](https://github.com/gradio-app/trackio/pull/515) [`0a242b8`](https://github.com/gradio-app/trackio/commit/0a242b85127b02f532b24c7fd2bb046580cc7641) - Add Gradio-compatible /gradio_api routes on Spaces. Thanks @abidlabs! +- [#510](https://github.com/gradio-app/trackio/pull/510) [`60bbc86`](https://github.com/gradio-app/trackio/commit/60bbc86b4e7f880de72075e5bf31b093709bb5a4) - Add server_url and TRACKIO_SERVER_URL for self-hosted servers; space_id and TRACKIO_SPACE_ID take precedence when both are set. Thanks @abidlabs! +- [#509](https://github.com/gradio-app/trackio/pull/509) [`21c099a`](https://github.com/gradio-app/trackio/commit/21c099aa830a278973fab4c7c58a0139f417caa4) - Fix: Open browser with write_token so trackio show allows mutations. Thanks @abidlabs! + +## 0.23.0 + +### Features + +- [#494](https://github.com/gradio-app/trackio/pull/494) [`e8a897d`](https://github.com/gradio-app/trackio/commit/e8a897d2266d9b2558f72d768b0b21f4d0a8781b) - Add a settings/CLI page to Trackio. Thanks @abidlabs! +- [#481](https://github.com/gradio-app/trackio/pull/481) [`882647e`](https://github.com/gradio-app/trackio/commit/882647ec1599cf04500d03b5ca75ddc2733682e2) - Add multi-GPU system metrics support. Thanks @Saba9! +- [#485](https://github.com/gradio-app/trackio/pull/485) [`46a3cc3`](https://github.com/gradio-app/trackio/commit/46a3cc3758719e171417612efee102a487e71ebd) - Fix/remove flaky E2E space tests. Thanks @abidlabs! +- [#501](https://github.com/gradio-app/trackio/pull/501) [`06ea885`](https://github.com/gradio-app/trackio/commit/06ea8852f5e40ab3f1cf629a0a01af5c17f847a1) - Fix SQLite corruption on bucket-mounted Spaces. Thanks @abidlabs! +- [#496](https://github.com/gradio-app/trackio/pull/496) [`af23d74`](https://github.com/gradio-app/trackio/commit/af23d74438b146c4a3512ace15ea984656e943ed) - Prevent trackio errors from crashing the user's training loop. Thanks @abidlabs! + +## 0.22.0 + +### Features + +- [#484](https://github.com/gradio-app/trackio/pull/484) [`cc05ada`](https://github.com/gradio-app/trackio/commit/cc05ada8e89773f3a894af99b801ef680f64418f) - Fix duplicate columns in parquet export. Thanks @abidlabs! +- [#487](https://github.com/gradio-app/trackio/pull/487) [`853f764`](https://github.com/gradio-app/trackio/commit/853f7646a70d12633afaa4f69db86425aa665413) - Relax `PIL` dependency and remove `plotly` as it's no longer used. Thanks @abidlabs! + +## 0.21.2 + +### Features + +- [#482](https://github.com/gradio-app/trackio/pull/482) [`f62180a`](https://github.com/gradio-app/trackio/commit/f62180a0218bc99a259d5ca110a0384a6cae11c8) - Use server-side bucket copy when freezing Spaces. Thanks @abidlabs! + +## 0.21.1 + +### Features + +- [#475](https://github.com/gradio-app/trackio/pull/475) [`fcb476c`](https://github.com/gradio-app/trackio/commit/fcb476cd37a40923e9679aaf966f41d582a878a8) - Tweaks. Thanks @abidlabs! +- [#477](https://github.com/gradio-app/trackio/pull/477) [`7d52dfd`](https://github.com/gradio-app/trackio/commit/7d52dfdce5b6eff6a34501a6d5a620220663cf09) - Fix `.sync()` and add `.freeze()` as a separate methods. Thanks @abidlabs! + +## 0.21.0 + +### Features + +- [#467](https://github.com/gradio-app/trackio/pull/467) [`f357deb`](https://github.com/gradio-app/trackio/commit/f357debf78957e4c1f2b901bee4f77cf397298b4) - Allow logged metrics as x-axis choices. Thanks @abidlabs! +- [#474](https://github.com/gradio-app/trackio/pull/474) [`655673d`](https://github.com/gradio-app/trackio/commit/655673d4c6b7c8b7ee8f87f2589f2dbbc3d2ef91) - Fix file descriptor leak from `sqlite3.connect`. Thanks @abidlabs! +- [#470](https://github.com/gradio-app/trackio/pull/470) [`bea8c9d`](https://github.com/gradio-app/trackio/commit/bea8c9dcae0b59d071b6c779c97ee525c9bbf6e7) - Restores tooltips to line plots and fixes the call to uses TTL instead of OAuth. Thanks @abidlabs! +- [#471](https://github.com/gradio-app/trackio/pull/471) [`246fce0`](https://github.com/gradio-app/trackio/commit/246fce0a01619e1c2c538c67b3e460883334d500) - Deprecate dataset backend in favor of buckets. Thanks @abidlabs! +- [#465](https://github.com/gradio-app/trackio/pull/465) [`3e11174`](https://github.com/gradio-app/trackio/commit/3e1117438bb8168b802245a33059affa558ae519) - Use HF buckets as backend. Thanks @abidlabs! +- [#469](https://github.com/gradio-app/trackio/pull/469) [`915d170`](https://github.com/gradio-app/trackio/commit/915d17045133172b59195acfdcc70709229668aa) - Make static Spaces work with Buckets and also allow conversion from Gradio SDK to Static Spaces. Thanks @abidlabs! + +## 0.20.2 + +### Features + +- [#464](https://github.com/gradio-app/trackio/pull/464) [`c89ebb3`](https://github.com/gradio-app/trackio/commit/c89ebb3b50f695bc7f16cbc6f46dce86f79a01e9) - Improve rendering of curves. Thanks @abidlabs! +- [#462](https://github.com/gradio-app/trackio/pull/462) [`9160b78`](https://github.com/gradio-app/trackio/commit/9160b78ff6f258f0b87a4f34a24e7d0b5dfbf2fb) - Refactor plot title to display only the metric name without the path. Thanks @qgallouedec! + +## 0.20.1 + +### Features + +- [#454](https://github.com/gradio-app/trackio/pull/454) [`22881db`](https://github.com/gradio-app/trackio/commit/22881dbbbb6b81197a00a19853771007093d61e4) - Bar chart single point. Thanks @abidlabs! +- [#455](https://github.com/gradio-app/trackio/pull/455) [`f8db51a`](https://github.com/gradio-app/trackio/commit/f8db51a20ca61ef703f3f2c2ee1ebd9c4f239cf2) - Adds a static Trackio mode via `trackio.sync(sdk="static")` and support for the `TRACKIO_SPACE_ID` environment variable. Thanks @abidlabs! + +## 0.20.0 + +### Features + +- [#450](https://github.com/gradio-app/trackio/pull/450) [`b0571ef`](https://github.com/gradio-app/trackio/commit/b0571ef6207a1ce346696f858ad2b7b584dd194f) - Use Svelte source for Gradio components directly in Trackio dashboard. Thanks @abidlabs! + +## 0.19.0 + +### Features + +- [#445](https://github.com/gradio-app/trackio/pull/445) [`cef4a58`](https://github.com/gradio-app/trackio/commit/cef4a583cb76f4091fc6c0e5783124ee84f8e243) - Add remote HF Space support to CLI. Thanks @abidlabs! +- [#444](https://github.com/gradio-app/trackio/pull/444) [`358f2a9`](https://github.com/gradio-app/trackio/commit/358f2a9ca238ee8b90b5a8c96220da287e0698fb) - Fix alerts placeholder flashing on reports page. Thanks @abidlabs! + +## 0.18.0 + +### Features + +- [#435](https://github.com/gradio-app/trackio/pull/435) [`4a47112`](https://github.com/gradio-app/trackio/commit/4a471128e18a39e45fad48a67fd711c5ae9e4aed) - feat: allow hiding section header accordions. Thanks @Saba9! +- [#439](https://github.com/gradio-app/trackio/pull/439) [`18e9650`](https://github.com/gradio-app/trackio/commit/18e96503d5a3a7cf926e92782d457e23c19942bd) - Add alerts with webhooks, CLI, and documentation. Thanks @abidlabs! +- [#438](https://github.com/gradio-app/trackio/pull/438) [`0875ccd`](https://github.com/gradio-app/trackio/commit/0875ccd3d8a41b1376f64030f21cfe8cdcc73b05) - Add "share this view" functionality. Thanks @qgallouedec! +- [#409](https://github.com/gradio-app/trackio/pull/409) [`9282403`](https://github.com/gradio-app/trackio/commit/9282403d8896d48679b0f888208a7ba5bdd4271a) - Add Apple Silicon GPU and system monitoring support. Thanks @znation! +- [#434](https://github.com/gradio-app/trackio/pull/434) [`4193223`](https://github.com/gradio-app/trackio/commit/41932230a3a2e1c16405dba08ecba5a42f11d1a8) - fix: table slider crash. Thanks @Saba9! + +### Fixes + +- [#441](https://github.com/gradio-app/trackio/pull/441) [`3a2d11d`](https://github.com/gradio-app/trackio/commit/3a2d11dab0b4b37c925abc30ef84b0e2910321ee) - preserve x-axis step when toggling run checkboxes. Thanks @Saba9! + +## 0.17.0 + +### Features + +- [#428](https://github.com/gradio-app/trackio/pull/428) [`f7dd1ce`](https://github.com/gradio-app/trackio/commit/f7dd1ce2dc8a1936f9983467fcbcf93bfef01e09) - feat: add ability to rename runs. Thanks @Saba9! +- [#437](https://github.com/gradio-app/trackio/pull/437) [`2727c0b`](https://github.com/gradio-app/trackio/commit/2727c0b0755f48f7f186162ea45185c98f6b5516) - Add markdown reports across Trackio. Thanks @abidlabs! +- [#427](https://github.com/gradio-app/trackio/pull/427) [`5aeb9ed`](https://github.com/gradio-app/trackio/commit/5aeb9edcfd2068d309d9d64f172dcbcc327be1ab) - Make Trackio logging much more robust. Thanks @abidlabs! + +## 0.16.1 + +### Features + +- [#431](https://github.com/gradio-app/trackio/pull/431) [`c7ce55b`](https://github.com/gradio-app/trackio/commit/c7ce55b14dd5eb0c2165fb15df17dd60721c9325) - Lazy load the UI when trackio is imported. Thanks @abidlabs! + +## 0.16.0 + +### Features + +- [#426](https://github.com/gradio-app/trackio/pull/426) [`ead4dc8`](https://github.com/gradio-app/trackio/commit/ead4dc8e74ee2d8e47d61bca0a7668456acf49be) - Fix redundant double rendering of group checkboxes. Thanks @abidlabs! +- [#413](https://github.com/gradio-app/trackio/pull/413) [`39c4750`](https://github.com/gradio-app/trackio/commit/39c4750951d554ba6eb4d58847c6bb444b2891a8) - Check `dist-packages` when checking for source installation. Thanks @sergiopaniego! +- [#423](https://github.com/gradio-app/trackio/pull/423) [`2e52ab3`](https://github.com/gradio-app/trackio/commit/2e52ab303e3041718a6a56fbf84d0848aca9ad67) - Fix legend outline visibility issue. Thanks @Raghunath-Balaji! +- [#407](https://github.com/gradio-app/trackio/pull/407) [`c8a384d`](https://github.com/gradio-app/trackio/commit/c8a384ddfe5a295cecf862a26178d40e48acb424) - Fix pytests that were failling locally on MacOS. Thanks @abidlabs! +- [#405](https://github.com/gradio-app/trackio/pull/405) [`35aae4e`](https://github.com/gradio-app/trackio/commit/35aae4e3aa3e2b2888887528478b9dc6a9808bda) - Add conditional padding for HF Space dashboard when not in iframe. Thanks @znation! + +## 0.15.0 + +### Features + +- [#397](https://github.com/gradio-app/trackio/pull/397) [`6b38ad0`](https://github.com/gradio-app/trackio/commit/6b38ad02e5d73a0df49c4eede7e91331282ece04) - Adds `--host` cli option support. Thanks @abidlabs! +- [#396](https://github.com/gradio-app/trackio/pull/396) [`4a4d1ab`](https://github.com/gradio-app/trackio/commit/4a4d1ab85e63d923132a3fa7afa5d90e16431bec) - Fix run selection issue. Thanks @abidlabs! +- [#394](https://github.com/gradio-app/trackio/pull/394) [`c47a3a3`](https://github.com/gradio-app/trackio/commit/c47a3a31f8c4b83bce1aa7fc22eeba3d9021ad3d) - Add wandb-compatible API for trackio. Thanks @abidlabs! +- [#378](https://github.com/gradio-app/trackio/pull/378) [`b02046a`](https://github.com/gradio-app/trackio/commit/b02046a5b0dad7c9854e099a87f884afba4aecb2) - Add JSON export button for line plots and upgrade gradio dependency. Thanks @JamshedAli18! + +## 0.14.2 + +### Features + +- [#386](https://github.com/gradio-app/trackio/pull/386) [`f9452cd`](https://github.com/gradio-app/trackio/commit/f9452cdb8f0819368f3610f7ac0ed08957305275) - Fixing some issues related to deployed Trackio Spaces. Thanks @abidlabs! + +## 0.14.1 + +### Features + +- [#382](https://github.com/gradio-app/trackio/pull/382) [`44fe9bb`](https://github.com/gradio-app/trackio/commit/44fe9bb264fb2aafb0ec302ff15227c045819a2c) - Fix app file path when Trackio is not installed from source. Thanks @abidlabs! +- [#380](https://github.com/gradio-app/trackio/pull/380) [`c3f4cff`](https://github.com/gradio-app/trackio/commit/c3f4cff74bc5676e812773d8571454894fcdc7cc) - Add CLI commands for querying projects, runs, and metrics. Thanks @abidlabs! + +## 0.14.0 + +### Features + +- [#377](https://github.com/gradio-app/trackio/pull/377) [`5c5015b`](https://github.com/gradio-app/trackio/commit/5c5015b68c85c5de51111dad983f735c27b9a05f) - fixed wrapping issue in Runs table. Thanks @gaganchapa! +- [#374](https://github.com/gradio-app/trackio/pull/374) [`388e26b`](https://github.com/gradio-app/trackio/commit/388e26b9e9f24cd7ad203affe9b709be885b3d24) - Save Optimized Parquet files. Thanks @lhoestq! +- [#371](https://github.com/gradio-app/trackio/pull/371) [`fbace9c`](https://github.com/gradio-app/trackio/commit/fbace9cd7732c166f34d268f54b05bb06846cc5d) - Add GPU metrics logging. Thanks @kashif! +- [#367](https://github.com/gradio-app/trackio/pull/367) [`862840c`](https://github.com/gradio-app/trackio/commit/862840c13e30fc960cbee5b9eac4d3c25beba9de) - Add option to only show latest run, and fix the double logo issue. Thanks @abidlabs! + +## 0.13.1 + +### Features + +- [#369](https://github.com/gradio-app/trackio/pull/369) [`767e9fe`](https://github.com/gradio-app/trackio/commit/767e9fe095d7c6ed102016caf927c1517fb8618c) - tiny pr removing unnecessary code. Thanks @abidlabs! + +## 0.13.0 + +### Features + +- [#358](https://github.com/gradio-app/trackio/pull/358) [`073715d`](https://github.com/gradio-app/trackio/commit/073715d1caf8282f68890117f09c3ac301205312) - Improvements to `trackio.sync()`. Thanks @abidlabs! + +## 0.12.0 + +### Features + +- [#357](https://github.com/gradio-app/trackio/pull/357) [`02ba815`](https://github.com/gradio-app/trackio/commit/02ba815358060f1966052de051a5bdb09702920e) - Redesign media and tables to show up on separate page. Thanks @abidlabs! +- [#359](https://github.com/gradio-app/trackio/pull/359) [`08fe9c9`](https://github.com/gradio-app/trackio/commit/08fe9c9ddd7fe99ee811555fdfb62df9ab88e939) - docs: Improve docstrings. Thanks @qgallouedec! + +## 0.11.0 + +### Features + +- [#355](https://github.com/gradio-app/trackio/pull/355) [`ea51f49`](https://github.com/gradio-app/trackio/commit/ea51f4954922f21be76ef828700420fe9a912c4b) - Color code run checkboxes and match with plot lines. Thanks @abidlabs! +- [#353](https://github.com/gradio-app/trackio/pull/353) [`8abe691`](https://github.com/gradio-app/trackio/commit/8abe6919aeefe21fc7a23af814883efbb037c21f) - Remove show_api from demo.launch. Thanks @sergiopaniego! +- [#351](https://github.com/gradio-app/trackio/pull/351) [`8a8957e`](https://github.com/gradio-app/trackio/commit/8a8957e530dd7908d1fef7f2df030303f808101f) - Add `trackio.save()`. Thanks @abidlabs! + +## 0.10.0 + +### Features + +- [#305](https://github.com/gradio-app/trackio/pull/305) [`e64883a`](https://github.com/gradio-app/trackio/commit/e64883a51f7b8b93f7d48b8afe55acdb62238b71) - bump to gradio 6.0, make `trackio` compatible, and fix related issues. Thanks @abidlabs! + +## 0.9.1 + +### Features + +- [#344](https://github.com/gradio-app/trackio/pull/344) [`7e01024`](https://github.com/gradio-app/trackio/commit/7e010241d9a34794e0ce0dc19c1a6f0cf94ba856) - Avoid redundant calls to /whoami-v2. Thanks @Wauplin! + +## 0.9.0 + +### Features + +- [#343](https://github.com/gradio-app/trackio/pull/343) [`51bea30`](https://github.com/gradio-app/trackio/commit/51bea30f2877adff8e6497466d3a799400a0a049) - Sync offline projects to Hugging Face spaces. Thanks @candemircan! +- [#341](https://github.com/gradio-app/trackio/pull/341) [`4fd841f`](https://github.com/gradio-app/trackio/commit/4fd841fa190e15071b02f6fba7683ef4f393a654) - Adds a basic UI test to `trackio`. Thanks @abidlabs! +- [#339](https://github.com/gradio-app/trackio/pull/339) [`011d91b`](https://github.com/gradio-app/trackio/commit/011d91bb6ae266516fd250a349285670a8049d05) - Allow customzing the trackio color palette. Thanks @abidlabs! + +## 0.8.1 + +### Features + +- [#336](https://github.com/gradio-app/trackio/pull/336) [`5f9f51d`](https://github.com/gradio-app/trackio/commit/5f9f51dac8677f240d7c42c3e3b2660a22aee138) - Support a list of `Trackio.Image` in a `trackio.Table` cell. Thanks @abidlabs! + +## 0.8.0 + +### Features + +- [#331](https://github.com/gradio-app/trackio/pull/331) [`2c02d0f`](https://github.com/gradio-app/trackio/commit/2c02d0fd0a5824160528782402bb0dd4083396d5) - Truncate table string values that are greater than 250 characters (configuirable via env variable). Thanks @abidlabs! +- [#324](https://github.com/gradio-app/trackio/pull/324) [`50b2122`](https://github.com/gradio-app/trackio/commit/50b2122e7965ac82a72e6cb3b7d048bc10a2a6b1) - Add log y-axis functionality to UI. Thanks @abidlabs! +- [#326](https://github.com/gradio-app/trackio/pull/326) [`61dc1f4`](https://github.com/gradio-app/trackio/commit/61dc1f40af2f545f8e70395ddf0dbb8aee6b60d5) - Fix: improve table rendering for metrics in Trackio Dashboard. Thanks @vigneshwaran! +- [#328](https://github.com/gradio-app/trackio/pull/328) [`6857cbb`](https://github.com/gradio-app/trackio/commit/6857cbbe557a59a4642f210ec42566d108294e63) - Support trackio.Table with trackio.Image columns. Thanks @abidlabs! +- [#323](https://github.com/gradio-app/trackio/pull/323) [`6857cbb`](https://github.com/gradio-app/trackio/commit/6857cbbe557a59a4642f210ec42566d108294e63) - add Trackio client implementations in Go, Rust, and JS. Thanks @vaibhav-research! + +## 0.7.0 + +### Features + +- [#277](https://github.com/gradio-app/trackio/pull/277) [`db35601`](https://github.com/gradio-app/trackio/commit/db35601b9c023423c4654c9909b8ab73e58737de) - fix: make grouped runs view reflect live updates. Thanks @Saba9! +- [#320](https://github.com/gradio-app/trackio/pull/320) [`24ae739`](https://github.com/gradio-app/trackio/commit/24ae73969b09fb3126acd2f91647cdfbf8cf72a1) - Add additional query parms for xmin, xmax, and smoothing. Thanks @abidlabs! +- [#270](https://github.com/gradio-app/trackio/pull/270) [`cd1dfc3`](https://github.com/gradio-app/trackio/commit/cd1dfc3dc641b4499ac6d4a1b066fa8e2b52c57b) - feature: add support for logging audio. Thanks @Saba9! + +## 0.6.0 + +### Features + +- [#309](https://github.com/gradio-app/trackio/pull/309) [`1df2353`](https://github.com/gradio-app/trackio/commit/1df23534d6c01938c8db9c0f584ffa23e8d6021d) - Add histogram support with wandb-compatible API. Thanks @abidlabs! +- [#315](https://github.com/gradio-app/trackio/pull/315) [`76ba060`](https://github.com/gradio-app/trackio/commit/76ba06055dc43ca8f03b79f3e72d761949bd19a8) - Add guards to avoid silent fails. Thanks @Xmaster6y! +- [#313](https://github.com/gradio-app/trackio/pull/313) [`a606b3e`](https://github.com/gradio-app/trackio/commit/a606b3e1c5edf3d4cf9f31bd50605226a5a1c5d0) - No longer prevent certain keys from being used. Instead, dunderify them to prevent collisions with internal usage. Thanks @abidlabs! +- [#317](https://github.com/gradio-app/trackio/pull/317) [`27370a5`](https://github.com/gradio-app/trackio/commit/27370a595d0dbdf7eebbe7159d2ba778f039da44) - quick fixes for trackio.histogram. Thanks @abidlabs! +- [#312](https://github.com/gradio-app/trackio/pull/312) [`aa0f3bf`](https://github.com/gradio-app/trackio/commit/aa0f3bf372e7a0dd592a38af699c998363830eeb) - Fix video logging by adding TRACKIO_DIR to allowed_paths. Thanks @abidlabs! + +## 0.5.3 + +### Features + +- [#300](https://github.com/gradio-app/trackio/pull/300) [`5e4cacf`](https://github.com/gradio-app/trackio/commit/5e4cacf2e7ce527b4ce60de3a5bc05d2c02c77fb) - Adds more environment variables to allow customization of Trackio dashboard. Thanks @abidlabs! + +## 0.5.2 + +### Features + +- [#293](https://github.com/gradio-app/trackio/pull/293) [`64afc28`](https://github.com/gradio-app/trackio/commit/64afc28d3ea1dfd821472dc6bf0b8ed35a9b74be) - Ensures that the TRACKIO_DIR environment variable is respected. Thanks @abidlabs! +- [#287](https://github.com/gradio-app/trackio/pull/287) [`cd3e929`](https://github.com/gradio-app/trackio/commit/cd3e9294320949e6b8b829239069a43d5d7ff4c1) - fix(sqlite): unify .sqlite extension, allow export when DBs exist, clean WAL sidecars on import. Thanks @vaibhav-research! + +### Fixes + +- [#291](https://github.com/gradio-app/trackio/pull/291) [`3b5adc3`](https://github.com/gradio-app/trackio/commit/3b5adc3d1f452dbab7a714d235f4974782f93730) - Fix the wheel build. Thanks @pngwn! + +## 0.5.1 + +### Fixes + +- [#278](https://github.com/gradio-app/trackio/pull/278) [`314c054`](https://github.com/gradio-app/trackio/commit/314c05438007ddfea3383e06fd19143e27468e2d) - Fix row orientation of metrics plots. Thanks @abidlabs! \ No newline at end of file diff --git a/trackio/__init__.py b/trackio/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..1068bd091345b20627dca9f3bc8dfa77581abc1c --- /dev/null +++ b/trackio/__init__.py @@ -0,0 +1,1165 @@ +import atexit +import glob +import json +import logging +import os +import shutil +import warnings +import webbrowser +from pathlib import Path +from typing import Any + +import huggingface_hub +from gradio_client import handle_file +from huggingface_hub import SpaceStorage +from huggingface_hub.errors import LocalTokenNotFoundError + +from trackio import context_vars, deploy, utils +from trackio.alerts import AlertLevel +from trackio.api import Api +from trackio.apple_gpu import apple_gpu_available +from trackio.apple_gpu import log_apple_gpu as _log_apple_gpu +from trackio.cpu import log_cpu as _log_cpu +from trackio.deploy import freeze, sync +from trackio.frontend_config import resolve_frontend_dir +from trackio.gpu import gpu_available +from trackio.gpu import log_gpu as _log_nvidia_gpu +from trackio.histogram import Histogram +from trackio.imports import import_csv, import_tf_events +from trackio.launch import launch_trackio_dashboard +from trackio.markdown import Markdown +from trackio.media import ( + TrackioAudio, + TrackioImage, + TrackioVideo, + get_project_media_path, +) +from trackio.remote_client import RemoteClient +from trackio.run import Run +from trackio.server import TrackioDashboardApp, build_starlette_app_only +from trackio.sqlite_storage import SQLiteStorage +from trackio.table import Table +from trackio.trace import Trace +from trackio.typehints import UploadEntry +from trackio.utils import TRACKIO_DIR, TRACKIO_LOGO_DIR, _emit_nonfatal_warning + +logging.getLogger("httpx").setLevel(logging.WARNING) + +__version__ = json.loads(Path(__file__).parent.joinpath("package.json").read_text())[ + "version" +] + + +class _TupleNoPrint(tuple): + def __repr__(self) -> str: + return "" + + +__all__ = [ + "init", + "log", + "log_system", + "log_gpu", + "log_cpu", + "finish", + "alert", + "AlertLevel", + "show", + "sync", + "freeze", + "delete_project", + "import_csv", + "import_tf_events", + "save", + "Image", + "Video", + "Audio", + "Table", + "Trace", + "Histogram", + "Markdown", + "Api", + "TRACKIO_LOGO_DIR", +] + +Audio = TrackioAudio +Image = TrackioImage +Video = TrackioVideo + + +config = {} + +_atexit_registered = False +_projects_notified_auto_log_hw: set[str] = set() + + +def _cleanup_current_run(): + run = context_vars.current_run.get() + if run is not None: + try: + run.finish() + except Exception: + pass + + +def _safe_get_runs_for_init( + project: str, + space_id: str | None, + server_base_url: str | None, + write_token: str | None, + resume: str, + remote_client: RemoteClient | None = None, + check_existing_for_never: bool = False, +) -> list[str]: + if space_id is not None: + if resume == "never" and not check_existing_for_never: + return [] + try: + client = remote_client or RemoteClient( + space_id, + hf_token=huggingface_hub.utils.get_token(), + verbose=False, + ) + runs = client.predict(project=project, api_name="/get_runs_for_project") + return runs if isinstance(runs, list) else [] + except Exception as e: + _emit_nonfatal_warning( + f"trackio.init() could not inspect existing runs for project '{project}' on Space '{space_id}': {e}. Continuing without resume metadata." + ) + return [] + if server_base_url is not None: + if resume == "never" and not check_existing_for_never: + return [] + try: + client = remote_client or RemoteClient( + server_base_url, + hf_token=None, + write_token=write_token, + verbose=False, + ) + runs = client.predict(project=project, api_name="/get_runs_for_project") + return runs if isinstance(runs, list) else [] + except Exception as e: + _emit_nonfatal_warning( + f"trackio.init() could not inspect existing runs for project '{project}' on self-hosted server '{server_base_url}': {e}. Continuing without resume metadata." + ) + return [] + try: + return SQLiteStorage.get_runs(project) + except Exception as e: + _emit_nonfatal_warning( + f"trackio.init() could not inspect existing runs for project '{project}': {e}. Continuing without resume metadata." + ) + return [] + + +def _safe_get_latest_run_for_init( + project: str, + name: str, + space_id: str | None = None, + server_base_url: str | None = None, + write_token: str | None = None, + remote_client: RemoteClient | None = None, +) -> dict | None: + if space_id is not None: + try: + client = remote_client or RemoteClient( + space_id, + hf_token=huggingface_hub.utils.get_token(), + verbose=False, + ) + runs = client.predict(project=project, api_name="/get_runs_for_project") + if not isinstance(runs, list): + return None + matches = [r for r in runs if isinstance(r, dict) and r.get("name") == name] + if not matches: + return None + matches.sort(key=lambda r: r.get("created_at") or "", reverse=True) + return matches[0] + except Exception as e: + _emit_nonfatal_warning( + f"trackio.init() could not inspect existing runs for project '{project}' on Space '{space_id}': {e}. Continuing without resume metadata." + ) + return None + if server_base_url is not None: + try: + client = remote_client or RemoteClient( + server_base_url, + hf_token=None, + write_token=write_token, + verbose=False, + ) + runs = client.predict(project=project, api_name="/get_runs_for_project") + if not isinstance(runs, list): + return None + matches = [r for r in runs if isinstance(r, dict) and r.get("name") == name] + if not matches: + return None + matches.sort(key=lambda r: r.get("created_at") or "", reverse=True) + return matches[0] + except Exception as e: + _emit_nonfatal_warning( + f"trackio.init() could not inspect existing runs for project '{project}' on self-hosted server '{server_base_url}': {e}. Continuing without resume metadata." + ) + return None + try: + return SQLiteStorage.get_latest_run_record_by_name(project, name) + except Exception as e: + _emit_nonfatal_warning( + f"trackio.init() could not inspect existing runs for project '{project}': {e}. Continuing without resume metadata." + ) + return None + + +def _safe_get_last_step_for_init( + project: str, + run_name: str, + space_id: str | None, + server_base_url: str | None, + write_token: str | None, + resumed: bool, + run_id: str | None = None, + remote_client: RemoteClient | None = None, +) -> int | None: + if not resumed: + return None + if space_id is not None: + try: + client = remote_client or RemoteClient( + space_id, + hf_token=huggingface_hub.utils.get_token(), + verbose=False, + ) + summary_kwargs: dict[str, Any] = { + "project": project, + "api_name": "/get_run_summary", + } + if run_id is not None: + summary_kwargs["run_id"] = run_id + else: + summary_kwargs["run"] = run_name + summary = client.predict(**summary_kwargs) + if isinstance(summary, dict): + last_step = summary.get("last_step") + return last_step if isinstance(last_step, int) else None + return None + except Exception as e: + _emit_nonfatal_warning( + f"trackio.init() could not recover the previous step for run '{run_name}' on Space '{space_id}': {e}. Continuing from step 0." + ) + return None + if server_base_url is not None: + try: + client = remote_client or RemoteClient( + server_base_url, + hf_token=None, + write_token=write_token, + verbose=False, + ) + summary_kwargs = { + "project": project, + "api_name": "/get_run_summary", + } + if run_id is not None: + summary_kwargs["run_id"] = run_id + else: + summary_kwargs["run"] = run_name + summary = client.predict(**summary_kwargs) + if isinstance(summary, dict): + last_step = summary.get("last_step") + return last_step if isinstance(last_step, int) else None + return None + except Exception as e: + _emit_nonfatal_warning( + f"trackio.init() could not recover the previous step for run '{run_name}' on self-hosted server '{server_base_url}': {e}. Continuing from step 0." + ) + return None + try: + return SQLiteStorage.get_max_step_for_run(project, run_name, run_id=run_id) + except Exception as e: + _emit_nonfatal_warning( + f"trackio.init() could not recover the previous step for run '{run_name}': {e}. Continuing from step 0." + ) + return None + + +def init( + project: str, + name: str | None = None, + group: str | None = None, + space_id: str | None = None, + server_url: str | None = None, + space_storage: SpaceStorage | None = None, + dataset_id: str | None = None, + bucket_id: str | None = None, + config: dict | None = None, + resume: str = "never", + settings: Any = None, + private: bool | None = None, + embed: bool = True, + auto_log_gpu: bool | None = None, + gpu_log_interval: float = 10.0, + auto_log_cpu: bool = False, + cpu_log_interval: float = 10.0, + webhook_url: str | None = None, + webhook_min_level: AlertLevel | str | None = None, +) -> Run: + """ + Creates a new Trackio project and returns a [`Run`] object. + + Args: + project (`str`): + The name of the project (can be an existing project to continue tracking or + a new project to start tracking from scratch). + name (`str`, *optional*): + The name of the run (if not provided, a default name will be generated). + group (`str`, *optional*): + The name of the group which this run belongs to in order to help organize + related runs together. You can toggle the entire group's visibility in the + dashboard. + space_id (`str`, *optional*): + If provided, the project will be logged to a Hugging Face Space instead of + a local directory. Should be a complete Space name like + `"username/reponame"` or `"orgname/reponame"`, or just `"reponame"` in which + case the Space will be created in the currently-logged-in Hugging Face + user's namespace. If the Space does not exist, it will be created. If the + Space already exists, the project will be logged to it. Can also be set + via the `TRACKIO_SPACE_ID` environment variable. You cannot log to a + Space that has been **frozen** (converted to the static SDK); use + ``trackio.sync(..., sdk="static")`` only after you are done logging. + Takes precedence over `server_url` and `TRACKIO_SERVER_URL` when more than + one is set. + server_url (`str`, *optional*): + Base URL of a self-hosted Trackio server (``http://`` or ``https://``), or the + write-access URL from ``trackio.show()`` which may include a ``write_token`` query + parameter. The client sends that token on each request (``X-Trackio-Write-Token``); + you can also set ``TRACKIO_WRITE_TOKEN`` instead of embedding the token in the URL. + When set, metrics are sent to that server over HTTP instead of creating or syncing + to a Hugging Face Space. Can also be set via the ``TRACKIO_SERVER_URL`` environment + variable. Ignored when ``space_id`` or ``TRACKIO_SPACE_ID`` is set. + space_storage ([`~huggingface_hub.SpaceStorage`], *optional*): + Choice of persistent storage tier. + dataset_id (`str`, *optional*): + Deprecated. Use `bucket_id` instead. + bucket_id (`str`, *optional*): + The ID of the Hugging Face Bucket to use for metric persistence. By default, + when a `space_id` is provided and `bucket_id` is not explicitly set, a + bucket is auto-generated from the space_id. Buckets provide + S3-like storage without git overhead - the SQLite database is stored directly + via `hf-mount` in the Space. Specify a Bucket with name like + `"username/bucketname"` or just `"bucketname"`. + config (`dict`, *optional*): + A dictionary of configuration options. Provided for compatibility with + `wandb.init()`. + resume (`str`, *optional*, defaults to `"never"`): + Controls how to handle resuming a run. Can be one of: + + - `"must"`: Must resume the run with the given name, raises error if run + doesn't exist + - `"allow"`: Resume the run if it exists, otherwise create a new run + - `"never"`: Never resume a run, always create a new one + private (`bool`, *optional*): + Whether to make the Space private. If None (default), the repo will be + public unless the organization's default is private. This value is ignored + if the repo already exists. + settings (`Any`, *optional*): + Not used. Provided for compatibility with `wandb.init()`. + embed (`bool`, *optional*, defaults to `True`): + If running inside a Jupyter/Colab notebook, whether the dashboard should + automatically be embedded in the cell when trackio.init() is called. For + local runs, this launches a local Trackio dashboard and embeds it. For Space runs, + this embeds the Space URL. In Colab, the local dashboard will be accessible + via a public share URL when `share=True`. + auto_log_gpu (`bool` or `None`, *optional*, defaults to `None`): + Controls automatic GPU metrics logging. If `None` (default), GPU logging + is automatically enabled when `nvidia-ml-py` is installed and an NVIDIA + GPU or Apple M series is detected. Set to `True` to force enable or + `False` to disable. + gpu_log_interval (`float`, *optional*, defaults to `10.0`): + The interval in seconds between automatic GPU metric logs. + Only used when `auto_log_gpu=True`. + auto_log_cpu (`bool`, *optional*, defaults to `False`): + Controls automatic CPU and RAM metrics logging (utilization, memory, + disk I/O, network I/O, and sensors). Requires `psutil`, which can be + installed with `pip install trackio[cpu]`. On Apple Silicon, CPU and + RAM metrics are already included in the Apple system metrics logged by + `auto_log_gpu`, so leave this disabled to avoid duplicate entries. + cpu_log_interval (`float`, *optional*, defaults to `10.0`): + The interval in seconds between automatic CPU metric logs. + Only used when `auto_log_cpu=True`. + webhook_url (`str`, *optional*): + A webhook URL to POST alert payloads to when `trackio.alert()` is + called. Supports Slack and Discord webhook URLs natively (payloads + are formatted automatically). Can also be set via the + `TRACKIO_WEBHOOK_URL` environment variable. Individual alerts can + override this URL by passing `webhook_url` to `trackio.alert()`. + webhook_min_level (`AlertLevel` or `str`, *optional*): + Minimum alert level that should trigger webhook delivery. + For example, `AlertLevel.WARN` sends only `WARN` and `ERROR` + alerts to the webhook destination. Can also be set via + `TRACKIO_WEBHOOK_MIN_LEVEL`. + Returns: + `Run`: A [`Run`] object that can be used to log metrics and finish the run. + """ + if settings is not None: + _emit_nonfatal_warning( + "* Warning: settings is not used. Provided for compatibility with wandb.init(). Please create an issue at: https://github.com/gradio-app/trackio/issues if you need a specific feature implemented." + ) + + previous_run = context_vars.current_run.get() + if previous_run is not None: + try: + previous_run.finish() + except Exception as e: + _emit_nonfatal_warning( + f"trackio.init() could not finish the previous run '{previous_run.name}': {e}. Continuing with new run." + ) + context_vars.current_run.set(None) + + bucket_id_was_explicit = bucket_id is not None + space_id, server_url = utils.resolve_space_id_and_server_url(space_id, server_url) + if bucket_id is None and utils.on_spaces(): + bucket_id = os.environ.get("TRACKIO_BUCKET_ID") + if server_url is not None and not server_url.startswith(("http://", "https://")): + raise ValueError( + f"`server_url` must be a full URL starting with http:// or https://, got: {server_url!r}" + ) + server_base_url: str | None = None + write_token_resolved: str | None = None + if server_url is not None: + server_base_url, tok = utils.parse_trackio_server_url(server_url) + write_token_resolved = tok or os.environ.get("TRACKIO_WRITE_TOKEN") + if not write_token_resolved: + raise ValueError( + "Self-hosted logging requires a write token: add write_token to the server URL, " + "or set the TRACKIO_WRITE_TOKEN environment variable." + ) + if server_url is not None and (dataset_id is not None or bucket_id is not None): + raise ValueError( + "`dataset_id` and `bucket_id` are Hugging Face Spaces concepts and are not " + "compatible with `server_url`. Configure storage on the self-hosted server." + ) + if space_id is None and dataset_id is not None: + raise ValueError("Must provide a `space_id` when `dataset_id` is provided.") + if dataset_id is not None and bucket_id is not None: + raise ValueError("Cannot provide both `dataset_id` and `bucket_id`.") + try: + space_id, dataset_id, bucket_id = utils.preprocess_space_and_dataset_ids( + space_id, dataset_id, bucket_id + ) + if ( + space_id is not None + and dataset_id is None + and bucket_id is not None + and not bucket_id_was_explicit + and not utils.on_spaces() + ): + bucket_id = deploy.resolve_auto_bucket_id(space_id, bucket_id) + except LocalTokenNotFoundError as e: + raise LocalTokenNotFoundError( + f"You must be logged in to Hugging Face locally when `space_id` is provided to deploy to a Space. {e}" + ) from e + + if space_id is None and bucket_id is not None: + _emit_nonfatal_warning( + "trackio.init() has `bucket_id` set but `space_id` is None: metrics will be logged " + "locally only. Pass `space_id` to create or use a Hugging Face Space, which will be " + "attached to the Hugging Face Bucket.", + UserWarning, + stacklevel=2, + ) + + if space_id is not None: + deploy.raise_if_space_is_frozen_for_logging(space_id) + + remote_source = space_id or server_base_url + + if remote_source is not None: + url = remote_source + context_vars.current_server.set(url) + if space_id is not None: + context_vars.current_space_id.set(space_id) + context_vars.current_server_write_token.set(None) + else: + context_vars.current_space_id.set(None) + context_vars.current_server_write_token.set(write_token_resolved) + else: + url = None + context_vars.current_server.set(None) + context_vars.current_space_id.set(None) + context_vars.current_server_write_token.set(None) + + _should_embed_local = False + + if ( + context_vars.current_project.get() is None + or context_vars.current_project.get() != project + ): + print(f"* Trackio project initialized: {project}") + + if bucket_id is not None: + if utils.on_spaces(): + os.environ["TRACKIO_BUCKET_ID"] = bucket_id + bucket_url = f"https://huggingface.co/buckets/{bucket_id}" + print( + f"* Trackio metrics will be synced to Hugging Face Bucket: {bucket_url}" + ) + elif dataset_id is not None: + if utils.on_spaces(): + os.environ["TRACKIO_DATASET_ID"] = dataset_id + print( + f"* Trackio metrics will be synced to Hugging Face Dataset: {dataset_id}" + ) + if remote_source is None: + print(f"* Trackio metrics logged to: {TRACKIO_DIR}") + _should_embed_local = embed and utils.is_in_notebook() + if not _should_embed_local: + utils.print_dashboard_instructions(project) + elif server_base_url is not None: + print( + f"* Trackio metrics will be sent to self-hosted server: {server_base_url}" + ) + if utils.is_in_notebook() and embed: + utils.embed_url_in_notebook(server_base_url) + else: + try: + deploy.create_space_if_not_exists( + space_id, + space_storage, + dataset_id, + bucket_id, + private, + ) + user_name, space_name = space_id.split("/") + space_url = deploy.SPACE_HOST_URL.format( + user_name=user_name, space_name=space_name + ) + if utils.is_in_notebook() and embed: + utils.embed_url_in_notebook(space_url) + except Exception as e: + _emit_nonfatal_warning( + f"trackio.init() could not prepare Space '{space_id}': {e}. Logging will continue in local fallback mode until the Space is reachable." + ) + context_vars.current_project.set(project) + + remote_client = None + if space_id is not None: + try: + remote_client = RemoteClient( + space_id, + hf_token=huggingface_hub.utils.get_token(), + verbose=False, + ) + except Exception as e: + _emit_nonfatal_warning( + f"trackio.init() could not create a remote client for Space '{space_id}': {e}. Continuing with local fallback metadata lookups." + ) + elif server_base_url is not None: + try: + remote_client = RemoteClient( + server_base_url, + hf_token=None, + write_token=write_token_resolved, + verbose=False, + ) + except Exception as e: + _emit_nonfatal_warning( + f"trackio.init() could not create a remote client for '{server_base_url}': {e}. Continuing with local fallback metadata lookups." + ) + + existing_run_records = _safe_get_runs_for_init( + project, + space_id, + server_base_url, + write_token_resolved, + resume, + remote_client=remote_client, + check_existing_for_never=name is not None, + ) + existing_runs = [ + r["name"] if isinstance(r, dict) else r for r in existing_run_records + ] + + existing_run = ( + _safe_get_latest_run_for_init( + project, + name, + space_id=space_id, + server_base_url=server_base_url, + write_token=write_token_resolved, + remote_client=remote_client, + ) + if name is not None + else None + ) + resolved_run_id = None + + if resume == "must": + if name is None: + raise ValueError("Must provide a run name when resume='must'") + if existing_run is None: + raise ValueError(f"Run '{name}' does not exist in project '{project}'") + resumed = True + resolved_run_id = existing_run["id"] + elif resume == "allow": + resumed = existing_run is not None + if resumed: + resolved_run_id = existing_run["id"] + elif resume == "never": + resumed = False + else: + raise ValueError("resume must be one of: 'must', 'allow', or 'never'") + + initial_last_step = ( + _safe_get_last_step_for_init( + project, + name, + space_id, + server_base_url, + write_token_resolved, + resumed, + run_id=resolved_run_id, + remote_client=remote_client, + ) + if name is not None + else None + ) + + if auto_log_gpu is None: + nvidia_available = gpu_available() + apple_available = apple_gpu_available() + auto_log_gpu = nvidia_available or apple_available + if project not in _projects_notified_auto_log_hw: + if nvidia_available: + print("* NVIDIA GPU detected, enabling automatic GPU metrics logging") + elif apple_available: + print( + "* Apple Silicon detected, enabling automatic system metrics logging" + ) + if nvidia_available or apple_available: + _projects_notified_auto_log_hw.add(project) + + run = Run( + url=url, + project=project, + client=None, + name=name, + run_id=resolved_run_id, + group=group, + config=config, + space_id=space_id, + server_base_url=server_base_url, + write_token=write_token_resolved, + existing_runs=existing_runs, + initial_last_step=initial_last_step, + auto_log_gpu=auto_log_gpu, + gpu_log_interval=gpu_log_interval, + auto_log_cpu=auto_log_cpu, + cpu_log_interval=cpu_log_interval, + webhook_url=webhook_url, + webhook_min_level=webhook_min_level, + ) + + if space_id is not None: + try: + SQLiteStorage.set_project_metadata(project, "space_id", space_id) + except Exception as e: + _emit_nonfatal_warning( + f"trackio.init() could not persist Space metadata for project '{project}': {e}. Logging will continue." + ) + try: + if SQLiteStorage.has_pending_data(project): + run._has_local_buffer = True + except Exception as e: + _emit_nonfatal_warning( + f"trackio.init() could not inspect pending buffered data for project '{project}': {e}. Logging will continue." + ) + + global _atexit_registered + if not _atexit_registered: + atexit.register(_cleanup_current_run) + _atexit_registered = True + + if resumed: + print(f"* Resumed existing run: {run.name}") + else: + print(f"* Created new run: {run.name}") + + context_vars.current_run.set(run) + globals()["config"] = run.config + + if _should_embed_local: + try: + show(project=project, open_browser=False, block_thread=False) + except Exception as e: + _emit_nonfatal_warning( + f"trackio.init() could not auto-launch the dashboard: {e}. Logging will continue." + ) + + return run + + +def log(metrics: dict, step: int | None = None) -> None: + """ + Logs metrics to the current run. + + Args: + metrics (`dict`): + A dictionary of metrics to log. + step (`int`, *optional*): + The step number. If not provided, the step will be incremented + automatically. + """ + run = context_vars.current_run.get() + if run is None: + raise RuntimeError("Call trackio.init() before trackio.log().") + run.log( + metrics=metrics, + step=step, + ) + + +def log_system(metrics: dict) -> None: + """ + Logs system metrics (GPU, etc.) to the current run using timestamps instead of steps. + + Args: + metrics (`dict`): + A dictionary of system metrics to log. + """ + run = context_vars.current_run.get() + if run is None: + raise RuntimeError("Call trackio.init() before trackio.log_system().") + run.log_system(metrics=metrics) + + +def log_gpu(run: Run | None = None, device: int | None = None) -> dict: + """ + Log GPU metrics to the current or specified run as system metrics. + Automatically detects whether an NVIDIA or Apple GPU is available and calls + the appropriate logging method. + + Args: + run: Optional Run instance. If None, uses current run from context. + device: CUDA device index to collect metrics from (NVIDIA GPUs only). + If None, collects from all GPUs visible to this process. + This parameter is ignored for Apple GPUs. + + Returns: + dict: The GPU metrics that were logged. + + Example: + ```python + import trackio + + run = trackio.init(project="my-project") + trackio.log({"loss": 0.5}) + trackio.log_gpu() + trackio.log_gpu(device=0) + ``` + """ + if run is None: + run = context_vars.current_run.get() + if run is None: + raise RuntimeError("Call trackio.init() before trackio.log_gpu().") + + if gpu_available(): + return _log_nvidia_gpu(run=run, device=device) + elif apple_gpu_available(): + return _log_apple_gpu(run=run) + else: + _emit_nonfatal_warning( + "No GPU detected. Install nvidia-ml-py for NVIDIA GPU support " + "or psutil for Apple Silicon support." + ) + return {} + + +def log_cpu(run: Run | None = None) -> dict: + """ + Log CPU, RAM, disk, network, and sensor metrics to the current or specified run + as system metrics. + + Args: + run: Optional Run instance. If None, uses current run from context. + + Returns: + dict: The CPU and system metrics that were logged. + + Example: + ```python + import trackio + + run = trackio.init(project="my-project") + trackio.log({"loss": 0.5}) + trackio.log_cpu() + ``` + """ + if run is None: + run = context_vars.current_run.get() + if run is None: + raise RuntimeError("Call trackio.init() before trackio.log_cpu().") + + return _log_cpu(run=run) + + +def finish(): + """ + Finishes the current run. + """ + run = context_vars.current_run.get() + if run is None: + raise RuntimeError("Call trackio.init() before trackio.finish().") + try: + run.finish() + finally: + context_vars.current_run.set(None) + + +def alert( + title: str, + text: str | None = None, + level: AlertLevel = AlertLevel.WARN, + webhook_url: str | None = None, +) -> None: + """ + Fires an alert immediately on the current run. The alert is printed to the + terminal, stored in the database, and displayed in the dashboard. If a + webhook URL is configured (via `trackio.init()`, the `TRACKIO_WEBHOOK_URL` + environment variable, or the `webhook_url` parameter here), the alert is + also POSTed to that URL. + + Args: + title (`str`): + A short title for the alert. + text (`str`, *optional*): + A longer description with details about the alert. + level (`AlertLevel`, *optional*, defaults to `AlertLevel.WARN`): + The severity level. One of `AlertLevel.INFO`, `AlertLevel.WARN`, + or `AlertLevel.ERROR`. + webhook_url (`str`, *optional*): + A webhook URL to send this specific alert to. Overrides any + URL set in `trackio.init()` or the `TRACKIO_WEBHOOK_URL` + environment variable. Supports Slack and Discord webhook + URLs natively. + """ + run = context_vars.current_run.get() + if run is None: + raise RuntimeError("Call trackio.init() before trackio.alert().") + run.alert(title=title, text=text, level=level, webhook_url=webhook_url) + + +def delete_project(project: str, force: bool = False) -> bool: + """ + Deletes a project by removing its local SQLite database. + + Args: + project (`str`): + The name of the project to delete. + force (`bool`, *optional*, defaults to `False`): + If `True`, deletes the project without prompting for confirmation. + If `False`, prompts the user to confirm before deleting. + + Returns: + `bool`: `True` if the project was deleted, `False` otherwise. + """ + db_path = SQLiteStorage.get_project_db_path(project) + + if not db_path.exists(): + print(f"* Project '{project}' does not exist.") + return False + + if not force: + response = input( + f"Are you sure you want to delete project '{project}'? " + f"This will permanently delete all runs and metrics. (y/N): " + ) + if response.lower() not in ["y", "yes"]: + print("* Deletion cancelled.") + return False + + try: + db_path.unlink() + + for suffix in ("-wal", "-shm"): + sidecar = Path(str(db_path) + suffix) + if sidecar.exists(): + sidecar.unlink() + + print(f"* Project '{project}' has been deleted.") + return True + except Exception as e: + print(f"* Error deleting project '{project}': {e}") + return False + + +def save( + glob_str: str | Path, + project: str | None = None, +) -> str: + """ + Saves files to a project (not linked to a specific run). If Trackio is running + locally, the file(s) will be copied to the project's files directory. If Trackio is + running in a Space, the file(s) will be uploaded to the Space's files directory. + + Args: + glob_str (`str` or `Path`): + The file path or glob pattern to save. Can be a single file or a pattern + matching multiple files (e.g., `"*.py"`, `"models/**/*.pth"`). + project (`str`, *optional*): + The name of the project to save files to. If not provided, uses the current + project from `trackio.init()`. If no project is initialized, raises an + error. + + Returns: + `str`: The path where the file(s) were saved (project's files directory). + + Example: + ```python + import trackio + + trackio.init(project="my-project") + trackio.save("config.yaml") + trackio.save("models/*.pth") + ``` + """ + if project is None: + project = context_vars.current_project.get() + if project is None: + raise RuntimeError( + "No project specified. Either call trackio.init() first or provide a " + "project parameter to trackio.save()." + ) + + glob_str = Path(glob_str) + base_path = Path.cwd().resolve() + + matched_files = [] + if glob_str.is_file(): + matched_files = [glob_str.resolve()] + else: + pattern = str(glob_str) + if not glob_str.is_absolute(): + pattern = str((Path.cwd() / glob_str).resolve()) + matched_files = [ + Path(f).resolve() + for f in glob.glob(pattern, recursive=True) + if Path(f).is_file() + ] + + if not matched_files: + raise ValueError(f"No files found matching pattern: {glob_str}") + + current_run = context_vars.current_run.get() + is_local = ( + current_run._is_local + if current_run is not None + else ( + context_vars.current_space_id.get() is None + and context_vars.current_server.get() is None + ) + ) + + if is_local: + for file_path in matched_files: + try: + relative_to_base = file_path.relative_to(base_path) + except ValueError: + relative_to_base = Path(file_path.name) + + if current_run is not None: + current_run._queue_upload( + file_path, + step=None, + relative_path=str(relative_to_base.parent), + use_run_name=False, + ) + else: + media_path = get_project_media_path( + project=project, + run=None, + step=None, + relative_path=str(relative_to_base), + ) + shutil.copy(str(file_path), str(media_path)) + else: + url = context_vars.current_server.get() + + upload_entries = [] + for file_path in matched_files: + try: + relative_to_base = file_path.relative_to(base_path) + except ValueError: + relative_to_base = Path(file_path.name) + + if current_run is not None: + current_run._queue_upload( + file_path, + step=None, + relative_path=str(relative_to_base.parent), + use_run_name=False, + ) + else: + upload_entry: UploadEntry = { + "project": project, + "run": None, + "step": None, + "relative_path": str(relative_to_base), + "uploaded_file": handle_file(file_path), + } + upload_entries.append(upload_entry) + + if upload_entries: + if url is None: + raise RuntimeError( + "No server available. Call trackio.init() before trackio.save() to start the server." + ) + + try: + wt = context_vars.current_server_write_token.get() + if wt is not None: + client = RemoteClient( + url, + hf_token=None, + write_token=wt, + httpx_kwargs={"timeout": 90}, + ) + else: + client = RemoteClient( + url, + hf_token=huggingface_hub.utils.get_token(), + httpx_kwargs={"timeout": 90}, + ) + client.predict( + api_name="/bulk_upload_media", + uploads=upload_entries, + hf_token=huggingface_hub.utils.get_token() if wt is None else None, + ) + except Exception as e: + _emit_nonfatal_warning( + f"Failed to upload files: {e}. " + "Files may not be available in the dashboard." + ) + + return str(utils.MEDIA_DIR / project / "files") + + +def show( + project: str | None = None, + *, + theme: Any = None, + mcp_server: bool | None = None, + footer: bool = True, + color_palette: list[str] | None = None, + open_browser: bool = True, + block_thread: bool | None = None, + host: str | None = None, + share: bool | None = None, + server_port: int | None = None, + frontend_dir: str | Path | None = None, +): + """ + Launches the Trackio dashboard. + + Args: + project (`str`, *optional*): + The name of the project whose runs to show. If not provided, all projects + will be shown and the user can select one. + theme (`Any`, *optional*): + Ignored. Kept for backward compatibility; Trackio no longer uses Gradio themes. + mcp_server (`bool`, *optional*): + If `True`, the dashboard exposes an MCP server at `/mcp` when the optional + `trackio[mcp]` dependency is installed. If `None` (default), the + `GRADIO_MCP_SERVER` environment variable is used (e.g. on Spaces). + footer (`bool`, *optional*, defaults to `True`): + Whether to include `footer=false` in the write-token URL when `False`. + This can also be controlled via the `footer` query parameter in the URL. + color_palette (`list[str]`, *optional*): + A list of hex color codes to use for plot lines. If not provided, the + `TRACKIO_COLOR_PALETTE` environment variable will be used (comma-separated + hex codes), or if that is not set, the default color palette will be used. + Example: `['#FF0000', '#00FF00', '#0000FF']` + open_browser (`bool`, *optional*, defaults to `True`): + If `True` and not in a notebook, a new browser tab will be opened with the + dashboard. If `False`, the browser will not be opened. + block_thread (`bool`, *optional*): + If `True`, the main thread will be blocked until the dashboard is closed. + If `None` (default behavior), then the main thread will not be blocked if the + dashboard is launched in a notebook, otherwise the main thread will be blocked. + host (`str`, *optional*): + The host to bind the server to. If not provided, defaults to `'127.0.0.1'` + (localhost only). Set to `'0.0.0.0'` to allow remote access. + share (`bool`, *optional*): + If `True`, creates a temporary public URL (Gradio-compatible tunnel). On Colab + or hosted notebooks, defaults to `True` unless overridden. + server_port (`int`, *optional*): + Port to bind. If not set, scans from `GRADIO_SERVER_PORT` (default 7860). + frontend_dir (`str | Path`, *optional*): + Directory containing a custom static frontend. Must contain `index.html`. + If not provided, Trackio checks `TRACKIO_FRONTEND_DIR`, then the persistent + Trackio config, then the bundled frontend. If an explicit `frontend_dir` + points to a missing or empty directory, Trackio copies in the starter + template and serves that directory. + + Returns: + `app`: The dashboard handle (`.close()` stops the server). + `url`: The local URL of the dashboard. + `share_url`: The public share URL, if any. + `full_url`: The full URL including the write token (share URL when sharing, else local). + """ + if theme is not None and theme != "default": + warnings.warn( + "The theme argument is ignored; Trackio no longer depends on Gradio themes.", + UserWarning, + stacklevel=2, + ) + + if color_palette is not None: + os.environ["TRACKIO_COLOR_PALETTE"] = ",".join(color_palette) + + _mcp_server = ( + mcp_server + if mcp_server is not None + else os.environ.get("GRADIO_MCP_SERVER", "False") == "True" + ) + + resolved_frontend = resolve_frontend_dir(frontend_dir, announce=True) + starlette_app, wt = build_starlette_app_only( + mcp_server=_mcp_server, + frontend_dir=str(resolved_frontend.path), + ) + local_url, share_url, _local_api_url, uv_server = launch_trackio_dashboard( + starlette_app, + server_name=host, + server_port=server_port, + share=share, + mcp_server=_mcp_server, + quiet=True, + ) + server = TrackioDashboardApp(starlette_app, uv_server, wt) + + base_root = (share_url or local_url).rstrip("/") + base_url = base_root + "/" + dashboard_url = base_url + if project: + dashboard_url += f"?project={project}" + full_url = utils.get_full_url( + base_root, + project=project, + write_token=wt, + footer=footer, + ) + + if not utils.is_in_notebook(): + print(f"\033[1m\033[38;5;208m* Trackio UI launched at: {dashboard_url}\033[0m") + utils.print_write_token_instructions(full_url) + if open_browser: + webbrowser.open(full_url) + block_thread = block_thread if block_thread is not None else True + else: + utils.embed_url_in_notebook(full_url) + block_thread = block_thread if block_thread is not None else False + + if block_thread: + utils.block_main_thread_until_keyboard_interrupt() + return _TupleNoPrint((server, local_url, share_url, full_url)) diff --git a/trackio/_vendor/__init__.py b/trackio/_vendor/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/trackio/_vendor/gradio_exceptions.py b/trackio/_vendor/gradio_exceptions.py new file mode 100644 index 0000000000000000000000000000000000000000..34696b9e534896b66557bab78a2d78709c07e351 --- /dev/null +++ b/trackio/_vendor/gradio_exceptions.py @@ -0,0 +1,6 @@ +class ChecksumMismatchError(Exception): + pass + + +class ShareCertificateWriteError(Exception): + pass diff --git a/trackio/_vendor/networking.py b/trackio/_vendor/networking.py new file mode 100644 index 0000000000000000000000000000000000000000..04ef35763f89eb813059ea6fc91a7316ecd2f2de --- /dev/null +++ b/trackio/_vendor/networking.py @@ -0,0 +1,81 @@ +from __future__ import annotations + +import os +import time +import warnings +from pathlib import Path +from urllib.parse import urlparse, urlunparse + +import httpx + +from trackio._vendor.gradio_exceptions import ShareCertificateWriteError +from trackio._vendor.tunneling import CERTIFICATE_PATH, Tunnel + +GRADIO_API_SERVER = "https://api.gradio.app/v3/tunnel-request" +GRADIO_SHARE_SERVER_ADDRESS = os.getenv("GRADIO_SHARE_SERVER_ADDRESS") + + +def setup_tunnel( + local_host: str, + local_port: int, + share_token: str, + share_server_address: str | None, + share_server_tls_certificate: str | None, +) -> str: + share_server_address = ( + GRADIO_SHARE_SERVER_ADDRESS + if share_server_address is None + else share_server_address + ) + if share_server_address is None: + try: + response = httpx.get(GRADIO_API_SERVER, timeout=30) + payload = response.json()[0] + remote_host, remote_port = payload["host"], int(payload["port"]) + certificate = payload["root_ca"] + except Exception as e: + raise RuntimeError( + "Could not get share link from Gradio API Server." + ) from e + try: + Path(CERTIFICATE_PATH).parent.mkdir(parents=True, exist_ok=True) + with open(CERTIFICATE_PATH, "w") as f: + f.write(certificate) + except Exception as e: + raise ShareCertificateWriteError( + f"{e}. This can happen if the current working directory is read-only." + ) from e + share_server_tls_certificate = CERTIFICATE_PATH + + else: + remote_host, remote_port = share_server_address.split(":") + remote_port = int(remote_port) + tunnel = Tunnel( + remote_host, + remote_port, + local_host, + local_port, + share_token, + share_server_tls_certificate, + ) + address = tunnel.start_tunnel() + return address + + +def url_ok(url: str) -> bool: + try: + for _ in range(5): + with warnings.catch_warnings(): + warnings.filterwarnings("ignore") + r = httpx.head(url, timeout=3, verify=False) + if r.status_code in (200, 401, 302, 303, 307): + return True + time.sleep(0.500) + except (ConnectionError, httpx.ConnectError, httpx.TimeoutException): + return False + return False + + +def normalize_share_url(share_url: str, share_server_protocol: str) -> str: + parsed_url = urlparse(share_url) + return urlunparse((share_server_protocol,) + parsed_url[1:]) diff --git a/trackio/_vendor/tunneling.py b/trackio/_vendor/tunneling.py new file mode 100644 index 0000000000000000000000000000000000000000..6bd6258ed043ba70b07bb1e928bf009864206000 --- /dev/null +++ b/trackio/_vendor/tunneling.py @@ -0,0 +1,191 @@ +import atexit +import hashlib +import os +import platform +import re +import stat +import subprocess +import sys +import time +from pathlib import Path + +import httpx +from huggingface_hub.constants import HF_HOME + +from trackio._vendor.gradio_exceptions import ChecksumMismatchError + +VERSION = "0.3" +CURRENT_TUNNELS: list["Tunnel"] = [] + +machine = platform.machine() +if machine == "x86_64": + machine = "amd64" +elif machine == "aarch64": + machine = "arm64" + +BINARY_REMOTE_NAME = f"frpc_{platform.system().lower()}_{machine.lower()}" +EXTENSION = ".exe" if os.name == "nt" else "" +BINARY_URL = f"https://cdn-media.huggingface.co/frpc-gradio-{VERSION}/{BINARY_REMOTE_NAME}{EXTENSION}" + +CHECKSUMS = { + "https://cdn-media.huggingface.co/frpc-gradio-0.3/frpc_windows_amd64.exe": "14bc0ea470be5d67d79a07412bd21de8a0a179c6ac1116d7764f68e942dc9ceb", + "https://cdn-media.huggingface.co/frpc-gradio-0.3/frpc_linux_amd64": "c791d1f047b41ff5885772fc4bf20b797c6059bbd82abb9e31de15e55d6a57c4", + "https://cdn-media.huggingface.co/frpc-gradio-0.3/frpc_linux_arm64": "823ced25104de6dc3c9f4798dbb43f20e681207279e6ab89c40e2176ccbf70cd", + "https://cdn-media.huggingface.co/frpc-gradio-0.3/frpc_darwin_amd64": "930f8face3365810ce16689da81b7d1941fda4466225a7bbcbced9a2916a6e15", + "https://cdn-media.huggingface.co/frpc-gradio-0.3/frpc_darwin_arm64": "dfac50c690aca459ed5158fad8bfbe99f9282baf4166cf7c410a6673fbc1f327", + "https://cdn-media.huggingface.co/frpc-gradio-0.3/frpc_linux_arm": "4b563beb2e36c448cc688174e20b53af38dc1ff2b5e362d4ddd1401f2affbfb7", + "https://cdn-media.huggingface.co/frpc-gradio-0.3/frpc_freebsd_386": "cb0a56c764ecf96dd54ed601d240c564f060ee4e58202d65ffca17c1a51ce19c", + "https://cdn-media.huggingface.co/frpc-gradio-0.3/frpc_freebsd_amd64": "516d9e6903513869a011ddcd1ec206167ad1eb5dd6640d21057acc258edecbbb", + "https://cdn-media.huggingface.co/frpc-gradio-0.3/frpc_linux_386": "4c2f2a48cd71571498c0ac8a4d42a055f22cb7f14b4b5a2b0d584220fd60a283", + "https://cdn-media.huggingface.co/frpc-gradio-0.3/frpc_linux_mips": "b309ecd594d4f0f7f33e556a80d4b67aef9319c00a8334648a618e56b23cb9e0", + "https://cdn-media.huggingface.co/frpc-gradio-0.3/frpc_linux_mips64": "0372ef5505baa6f3b64c6295a86541b24b7b0dbe4ef28b344992e21f47624b7b", + "https://cdn-media.huggingface.co/frpc-gradio-0.3/frpc_linux_riscv64": "1658eed7e8c14ea76e1d95749d58441ce24147c3d559381832c725c29cfc3df3", + "https://cdn-media.huggingface.co/frpc-gradio-0.3/frpc_linux_mipsle": "a2aaba16961d3372b79bd7a28976fcd0f0bbaebc2b50d5a7a71af2240747960f", + "https://cdn-media.huggingface.co/frpc-gradio-0.3/frpc_windows_386.exe": "721b90550195a83e15f2176d8f85a48d5a25822757cb872e9723d4bccc4e5bb6", + "https://cdn-media.huggingface.co/frpc-gradio-0.3/frpc_linux_mips64le": "796481edd609f31962b45cc0ab4c9798d040205ae3bf354ed1b72fb432d796b8", +} + +CHUNK_SIZE = 128 + +BINARY_FILENAME = f"{BINARY_REMOTE_NAME}_v{VERSION}" +BINARY_FOLDER = Path(HF_HOME) / "trackio" / "frpc" +BINARY_PATH = str(BINARY_FOLDER / BINARY_FILENAME) + +TUNNEL_TIMEOUT_SECONDS = 30 +TUNNEL_ERROR_MESSAGE = ( + "Could not create share URL. " + "Please check the appended log from frpc for more information:" +) + +CERTIFICATE_PATH = ".trackio/certificate.pem" + + +class Tunnel: + def __init__( + self, + remote_host: str, + remote_port: int, + local_host: str, + local_port: int, + share_token: str, + share_server_tls_certificate: str | None, + ): + self.proc = None + self.url = None + self.remote_host = remote_host + self.remote_port = remote_port + self.local_host = local_host + self.local_port = local_port + self.share_token = share_token + self.share_server_tls_certificate = share_server_tls_certificate + + @staticmethod + def download_binary(): + if not Path(BINARY_PATH).exists(): + Path(BINARY_FOLDER).mkdir(parents=True, exist_ok=True) + resp = httpx.get(BINARY_URL, timeout=30) + + if resp.status_code == 403: + raise OSError( + f"Cannot set up a share link as this platform is incompatible. Please " + f"create a GitHub issue with information about your platform: {platform.uname()}" + ) + + resp.raise_for_status() + + with open(BINARY_PATH, "wb") as file: + file.write(resp.content) + st = os.stat(BINARY_PATH) + os.chmod(BINARY_PATH, st.st_mode | stat.S_IEXEC) + + if BINARY_URL in CHECKSUMS: + sha = hashlib.sha256() + with open(BINARY_PATH, "rb") as f: + for chunk in iter(lambda: f.read(CHUNK_SIZE * sha.block_size), b""): + sha.update(chunk) + calculated_hash = sha.hexdigest() + + if calculated_hash != CHECKSUMS[BINARY_URL]: + raise ChecksumMismatchError() + + def start_tunnel(self) -> str: + self.download_binary() + self.url = self._start_tunnel(BINARY_PATH) + return self.url + + def kill(self): + if self.proc is not None: + print(f"Killing tunnel {self.local_host}:{self.local_port} <> {self.url}") + self.proc.terminate() + self.proc = None + + def _start_tunnel(self, binary: str) -> str: + CURRENT_TUNNELS.append(self) + command = [ + binary, + "http", + "-n", + self.share_token, + "-l", + str(self.local_port), + "-i", + self.local_host, + "--uc", + "--sd", + "random", + "--ue", + "--server_addr", + f"{self.remote_host}:{self.remote_port}", + "--disable_log_color", + ] + if self.share_server_tls_certificate is not None: + command.extend( + [ + "--tls_enable", + "--tls_trusted_ca_file", + self.share_server_tls_certificate, + ] + ) + self.proc = subprocess.Popen( + command, stdout=subprocess.PIPE, stderr=subprocess.PIPE + ) + atexit.register(self.kill) + return self._read_url_from_tunnel_stream() + + def _read_url_from_tunnel_stream(self) -> str: + start_timestamp = time.time() + + log = [] + url = "" + + def _raise_tunnel_error(): + log_text = "\n".join(log) + print(log_text, file=sys.stderr) + raise ValueError(f"{TUNNEL_ERROR_MESSAGE}\n{log_text}") + + while url == "": + if time.time() - start_timestamp >= TUNNEL_TIMEOUT_SECONDS: + _raise_tunnel_error() + + assert self.proc is not None # noqa: S101 + if self.proc.stdout is None: + continue + + line = self.proc.stdout.readline() + line = line.decode("utf-8") + + if line == "": + continue + + log.append(line.strip()) + + if "start proxy success" in line: + result = re.search("start proxy success: (.+)\n", line) + if result is None: + _raise_tunnel_error() + else: + url = result.group(1) + elif "login to server failed" in line: + _raise_tunnel_error() + + return url diff --git a/trackio/alerts.py b/trackio/alerts.py new file mode 100644 index 0000000000000000000000000000000000000000..646b9786eacb91fca5270189a78280293e045fc0 --- /dev/null +++ b/trackio/alerts.py @@ -0,0 +1,184 @@ +import json +import logging +import ssl +import urllib.request +from enum import Enum + +try: + import certifi + + _SSL_CONTEXT = ssl.create_default_context(cafile=certifi.where()) +except ImportError: + _SSL_CONTEXT = None + +logger = logging.getLogger(__name__) + + +class AlertLevel(str, Enum): + INFO = "info" + WARN = "warn" + ERROR = "error" + + +ALERT_LEVEL_ORDER = { + AlertLevel.INFO: 0, + AlertLevel.WARN: 1, + AlertLevel.ERROR: 2, +} + +ALERT_COLORS = { + AlertLevel.INFO: "\033[94m", + AlertLevel.WARN: "\033[93m", + AlertLevel.ERROR: "\033[91m", +} +RESET_COLOR = "\033[0m" + +LEVEL_EMOJI = { + AlertLevel.INFO: "ℹ️", + AlertLevel.WARN: "⚠️", + AlertLevel.ERROR: "🚨", +} + + +def format_alert_terminal( + level: AlertLevel, title: str, text: str | None, step: int | None +) -> str: + color = ALERT_COLORS.get(level, "") + step_str = f" (step {step})" if step is not None else "" + if text: + return f"{color}[TRACKIO {level.value.upper()}]{RESET_COLOR} {title}: {text}{step_str}" + return f"{color}[TRACKIO {level.value.upper()}]{RESET_COLOR} {title}{step_str}" + + +def _is_slack_url(url: str) -> bool: + return "hooks.slack.com" in url + + +def _is_discord_url(url: str) -> bool: + return "discord.com/api/webhooks" in url or "discordapp.com/api/webhooks" in url + + +def _build_slack_payload( + level: AlertLevel, + title: str, + text: str | None, + project: str, + run: str, + step: int | None, +) -> dict: + emoji = LEVEL_EMOJI.get(level, "") + step_str = f" • Step {step}" if step is not None else "" + header = f"{emoji} *[{level.value.upper()}] {title}*" + context = f"Project: {project} • Run: {run}{step_str}" + blocks = [ + {"type": "section", "text": {"type": "mrkdwn", "text": header}}, + ] + if text: + blocks.append({"type": "section", "text": {"type": "mrkdwn", "text": text}}) + blocks.append( + {"type": "context", "elements": [{"type": "mrkdwn", "text": context}]} + ) + return {"blocks": blocks} + + +def _build_discord_payload( + level: AlertLevel, + title: str, + text: str | None, + project: str, + run: str, + step: int | None, +) -> dict: + color_map = { + AlertLevel.INFO: 3447003, + AlertLevel.WARN: 16776960, + AlertLevel.ERROR: 15158332, + } + emoji = LEVEL_EMOJI.get(level, "") + step_str = f" • Step {step}" if step is not None else "" + embed = { + "title": f"{emoji} [{level.value.upper()}] {title}", + "color": color_map.get(level, 0), + "footer": {"text": f"Project: {project} • Run: {run}{step_str}"}, + } + if text: + embed["description"] = text + return {"embeds": [embed]} + + +def _build_generic_payload( + level: AlertLevel, + title: str, + text: str | None, + project: str, + run: str, + step: int | None, + timestamp: str | None, +) -> dict: + return { + "level": level.value, + "title": title, + "text": text, + "project": project, + "run": run, + "step": step, + "timestamp": timestamp, + } + + +def parse_alert_level(level: AlertLevel | str) -> AlertLevel: + if isinstance(level, AlertLevel): + return level + normalized = level.lower().strip() + try: + return AlertLevel(normalized) + except ValueError as e: + allowed = ", ".join(lvl.value for lvl in AlertLevel) + raise ValueError( + f"Invalid alert level '{level}'. Expected one of: {allowed}." + ) from e + + +def resolve_webhook_min_level( + webhook_min_level: AlertLevel | str | None, +) -> AlertLevel | None: + if webhook_min_level is None: + return None + return parse_alert_level(webhook_min_level) + + +def should_send_webhook( + level: AlertLevel, webhook_min_level: AlertLevel | None +) -> bool: + if webhook_min_level is None: + return True + return ALERT_LEVEL_ORDER[level] >= ALERT_LEVEL_ORDER[webhook_min_level] + + +def send_webhook( + url: str, + level: AlertLevel, + title: str, + text: str | None, + project: str, + run: str, + step: int | None, + timestamp: str | None = None, +) -> None: + if _is_slack_url(url): + payload = _build_slack_payload(level, title, text, project, run, step) + elif _is_discord_url(url): + payload = _build_discord_payload(level, title, text, project, run, step) + else: + payload = _build_generic_payload( + level, title, text, project, run, step, timestamp + ) + + data = json.dumps(payload).encode("utf-8") + req = urllib.request.Request( + url, data=data, headers={"Content-Type": "application/json"} + ) + try: + urllib.request.urlopen(req, timeout=10, context=_SSL_CONTEXT) + except Exception as e: + logger.warning(f"Failed to send webhook to {url}: {e}") diff --git a/trackio/api.py b/trackio/api.py new file mode 100644 index 0000000000000000000000000000000000000000..8ae640e5cb7c8be650e1bc92f31ac5975d7ca280 --- /dev/null +++ b/trackio/api.py @@ -0,0 +1,95 @@ +from typing import Iterator + +from trackio.sqlite_storage import SQLiteStorage + + +class Run: + def __init__(self, project: str, name: str, run_id: str | None = None): + self.project = project + self.name = name + self._id = run_id or name + self._config = None + + @property + def id(self) -> str: + return self._id + + @property + def config(self) -> dict | None: + if self._config is None: + self._config = SQLiteStorage.get_run_config( + self.project, self.name, run_id=self.id + ) + return self._config + + def alerts(self, level: str | None = None, since: str | None = None) -> list[dict]: + return SQLiteStorage.get_alerts( + self.project, run_name=self.name, run_id=self.id, level=level, since=since + ) + + def delete(self) -> bool: + return SQLiteStorage.delete_run(self.project, self.name, run_id=self.id) + + def move(self, new_project: str) -> bool: + success = SQLiteStorage.move_run( + self.project, self.name, new_project, run_id=self.id + ) + if success: + self.project = new_project + return success + + def rename(self, new_name: str) -> "Run": + SQLiteStorage.rename_run(self.project, self.name, new_name, run_id=self.id) + self.name = new_name + return self + + def __repr__(self) -> str: + return f"" + + +class Runs: + def __init__(self, project: str): + self.project = project + self._runs = None + + def _load_runs(self): + if self._runs is None: + records = SQLiteStorage.get_run_records(self.project) + self._runs = [ + Run(self.project, str(record["name"]), run_id=str(record["id"])) + for record in records + ] + + def __iter__(self) -> Iterator[Run]: + self._load_runs() + return iter(self._runs) + + def __getitem__(self, index: int) -> Run: + self._load_runs() + return self._runs[index] + + def __len__(self) -> int: + self._load_runs() + return len(self._runs) + + def __repr__(self) -> str: + self._load_runs() + return f"" + + +class Api: + def runs(self, project: str) -> Runs: + if not SQLiteStorage.get_project_db_path(project).exists(): + raise ValueError(f"Project '{project}' does not exist") + return Runs(project) + + def alerts( + self, + project: str, + run: str | None = None, + level: str | None = None, + since: str | None = None, + ) -> list[dict]: + if not SQLiteStorage.get_project_db_path(project).exists(): + raise ValueError(f"Project '{project}' does not exist") + return SQLiteStorage.get_alerts(project, run_name=run, level=level, since=since) diff --git a/trackio/apple_gpu.py b/trackio/apple_gpu.py new file mode 100644 index 0000000000000000000000000000000000000000..099ff36fd596507ff5013ae24c70985d4be3eb30 --- /dev/null +++ b/trackio/apple_gpu.py @@ -0,0 +1,198 @@ +import platform +import subprocess +import sys +import threading +import warnings +from typing import TYPE_CHECKING, Any + +if TYPE_CHECKING: + from trackio.run import Run + +psutil: Any = None +PSUTIL_AVAILABLE = False +_monitor_lock = threading.Lock() + + +def _ensure_psutil(): + global PSUTIL_AVAILABLE, psutil + if PSUTIL_AVAILABLE: + return psutil + try: + import psutil as _psutil + + psutil = _psutil + PSUTIL_AVAILABLE = True + return psutil + except ImportError: + raise ImportError( + "psutil is required for Apple Silicon monitoring. " + "Install it with: pip install psutil" + ) + + +def is_apple_silicon() -> bool: + """Check if running on Apple Silicon (M1/M2/M3/M4).""" + if platform.system() != "Darwin": + return False + + try: + result = subprocess.run( + ["sysctl", "-n", "machdep.cpu.brand_string"], + capture_output=True, + text=True, + timeout=1, + ) + cpu_brand = result.stdout.strip() + return "Apple" in cpu_brand + except Exception: + return False + + +def get_gpu_info() -> dict[str, Any]: + """Get Apple GPU information using ioreg.""" + try: + result = subprocess.run( + ["ioreg", "-r", "-d", "1", "-w", "0", "-c", "IOAccelerator"], + capture_output=True, + text=True, + timeout=2, + ) + + if result.returncode == 0 and result.stdout: + lines = result.stdout.strip().split("\n") + for line in lines: + if "IOAccelerator" in line and "class" in line: + return {"detected": True, "type": "Apple GPU"} + else: + print("Error collecting Apple GPU info. ioreg stdout was:", file=sys.stderr) + print(result.stdout, file=sys.stderr) + print("ioreg stderr was:", file=sys.stderr) + print(result.stderr, file=sys.stderr) + + result = subprocess.run( + ["system_profiler", "SPDisplaysDataType"], + capture_output=True, + text=True, + timeout=3, + ) + + if result.returncode == 0 and "Apple" in result.stdout: + for line in result.stdout.split("\n"): + if "Chipset Model:" in line: + model = line.split(":")[-1].strip() + return {"detected": True, "type": model} + + except Exception: + pass + + return {"detected": False} + + +def apple_gpu_available() -> bool: + """ + Check if Apple GPU monitoring is available. + + Returns True if running on Apple Silicon (M-series chips) and psutil is installed. + """ + try: + _ensure_psutil() + return is_apple_silicon() + except ImportError: + return False + except Exception: + return False + + +def collect_apple_metrics() -> dict: + """ + Collect system metrics for Apple Silicon. + + Returns: + Dictionary of system metrics including CPU, memory, and GPU info. + """ + from trackio.cpu import collect_cpu_metrics + + metrics = collect_cpu_metrics(include_static=False) + + gpu_info = get_gpu_info() + if gpu_info.get("detected"): + metrics["gpu/detected"] = 1 + + return metrics + + +class AppleGpuMonitor: + def __init__(self, run: "Run", interval: float = 10.0): + self._run = run + self._interval = interval + self._stop_flag = threading.Event() + self._thread: "threading.Thread | None" = None + + def start(self): + if not is_apple_silicon(): + warnings.warn( + "auto_log_gpu=True but not running on Apple Silicon. " + "Apple GPU logging disabled." + ) + return + + if not PSUTIL_AVAILABLE: + try: + _ensure_psutil() + except ImportError: + warnings.warn( + "auto_log_gpu=True but psutil not installed. " + "Install with: pip install psutil" + ) + return + + self._thread = threading.Thread(target=self._monitor_loop, daemon=True) + self._thread.start() + + def stop(self): + self._stop_flag.set() + if self._thread is not None: + self._thread.join(timeout=2.0) + + def _monitor_loop(self): + while not self._stop_flag.is_set(): + try: + metrics = collect_apple_metrics() + if metrics: + self._run.log_system(metrics) + except Exception: + pass + + self._stop_flag.wait(timeout=self._interval) + + +def log_apple_gpu(run: "Run | None" = None) -> dict: + """ + Log Apple Silicon system metrics to the current or specified run. + + Args: + run: Optional Run instance. If None, uses current run from context. + + Returns: + dict: The system metrics that were logged. + + Example: + ```python + import trackio + + run = trackio.init(project="my-project") + trackio.log({"loss": 0.5}) + trackio.log_apple_gpu() + ``` + """ + from trackio import context_vars + + if run is None: + run = context_vars.current_run.get() + if run is None: + raise RuntimeError("Call trackio.init() before trackio.log_apple_gpu().") + + metrics = collect_apple_metrics() + if metrics: + run.log_system(metrics) + return metrics diff --git a/trackio/asgi_app.py b/trackio/asgi_app.py new file mode 100644 index 0000000000000000000000000000000000000000..d3119d2a538da92ee86b5814e4dd5836178b406c --- /dev/null +++ b/trackio/asgi_app.py @@ -0,0 +1,507 @@ +from __future__ import annotations + +import inspect +import json +import logging +import math +import secrets +import tempfile +import threading +from collections.abc import Callable +from pathlib import Path +from typing import Any, get_args, get_origin +from urllib.parse import unquote + +from starlette.applications import Starlette +from starlette.requests import Request +from starlette.responses import FileResponse, JSONResponse, Response, StreamingResponse +from starlette.routing import Route + +from trackio.exceptions import TrackioAPIError +from trackio.remote_client import HTTP_API_VERSION +from trackio.utils import on_spaces + +logger = logging.getLogger("trackio.asgi_app") + +_PACKAGE_JSON_PATH = Path(__file__).parent / "package.json" +_TRACKIO_PACKAGE_VERSION = json.loads(_PACKAGE_JSON_PATH.read_text())["version"] + + +def _normalize_allowed_file_roots( + allowed_file_roots: list[str | Path] | None, +) -> tuple[Path, ...]: + roots = [] + for root in allowed_file_roots or []: + roots.append(Path(root).resolve()) + return tuple(roots) + + +def _is_allowed_file_path(path: Path, allowed_roots: tuple[Path, ...]) -> bool: + resolved_path = path.resolve(strict=False) + for root in allowed_roots: + try: + resolved_path.relative_to(root) + return True + except ValueError: + continue + return False + + +def _json_safe(data: Any) -> Any: + if data is None or isinstance(data, (str, bool, int)): + return data + if isinstance(data, float): + return data if math.isfinite(data) else None + if isinstance(data, dict): + return {k: _json_safe(v) for k, v in data.items()} + if isinstance(data, (list, tuple)): + return [_json_safe(v) for v in data] + if hasattr(data, "item"): + try: + return _json_safe(data.item()) + except Exception: + pass + return str(data) + + +def register_uploaded_temp_file(request: Request, file_path: str | Path) -> None: + resolved_path = Path(file_path).resolve(strict=False) + with request.app.state.uploaded_temp_files_lock: + request.app.state.uploaded_temp_files.add(resolved_path) + + +def consume_uploaded_temp_file(request: Request, file_data: Any) -> Path: + file_path = file_data.get("path") if isinstance(file_data, dict) else None + if not isinstance(file_path, str) or not file_path: + raise TrackioAPIError("Expected uploaded file metadata with a valid path.") + + resolved_path = Path(file_path).resolve(strict=False) + with request.app.state.uploaded_temp_files_lock: + if resolved_path not in request.app.state.uploaded_temp_files: + raise TrackioAPIError( + "Uploaded file was not created by this Trackio server." + ) + request.app.state.uploaded_temp_files.remove(resolved_path) + + if not resolved_path.is_file(): + raise TrackioAPIError("Uploaded file is missing.") + + return resolved_path + + +def cleanup_uploaded_temp_file(file_path: str | Path) -> None: + try: + Path(file_path).unlink(missing_ok=True) + except Exception: + pass + + +def _invoke_handler( + fn: Any, + request: Request, + args: list[Any] | None = None, + kwargs: dict[str, Any] | None = None, +) -> Any: + sig = inspect.signature(fn) + params = list(sig.parameters.values()) + positional_args: list[Any] = [] + keyword_args: dict[str, Any] = {} + args = list(args or []) + kwargs = dict(kwargs or {}) + data_index = 0 + + for param in params: + if param.name == "request": + keyword_args["request"] = request + elif param.kind == inspect.Parameter.VAR_POSITIONAL: + positional_args.extend(args[data_index:]) + data_index = len(args) + elif param.kind == inspect.Parameter.VAR_KEYWORD: + keyword_args.update(kwargs) + kwargs.clear() + elif param.name in kwargs: + keyword_args[param.name] = kwargs.pop(param.name) + elif param.kind in ( + inspect.Parameter.POSITIONAL_ONLY, + inspect.Parameter.POSITIONAL_OR_KEYWORD, + ) and data_index < len(args): + positional_args.append(args[data_index]) + data_index += 1 + elif param.default is inspect.Signature.empty and param.kind not in ( + inspect.Parameter.VAR_POSITIONAL, + inspect.Parameter.VAR_KEYWORD, + ): + raise TrackioAPIError(f"Missing required parameter: {param.name}") + + return fn(*positional_args, **keyword_args) + + +async def version_handler(request: Request) -> Response: + mcp_enabled = bool(getattr(request.app.state, "mcp_enabled", False)) + return JSONResponse( + { + "version": _TRACKIO_PACKAGE_VERSION, + "api_version": HTTP_API_VERSION, + "api_transport": "http", + "mcp_enabled": mcp_enabled, + "mcp_path": "/mcp" if mcp_enabled else None, + } + ) + + +def _json_schema_and_python_type(annotation: Any) -> tuple[dict[str, Any], str]: + if annotation is inspect.Parameter.empty: + return {"type": "object"}, "Any" + origin = get_origin(annotation) + args = get_args(annotation) + if origin is not None and args: + non_none = tuple(a for a in args if a is not type(None)) + if len(non_none) == 1 and len(args) > 1: + return _json_schema_and_python_type(non_none[0]) + if origin is list: + inner, py_inner = _json_schema_and_python_type( + args[0] if args else inspect.Parameter.empty + ) + return {"type": "array", "items": inner}, f"list[{py_inner}]" + if origin is dict: + return {"type": "object"}, "dict" + if annotation in (str, bytes): + return {"type": "string"}, "str" + if annotation is int: + return {"type": "integer"}, "int" + if annotation is float: + return {"type": "number"}, "float" + if annotation is bool: + return {"type": "boolean"}, "bool" + name = getattr(annotation, "__name__", None) + if name: + return {"type": "object"}, name + return {"type": "object"}, "Any" + + +def build_gradio_api_info(api_registry: dict[str, Any]) -> dict[str, Any]: + named_endpoints: dict[str, Any] = {} + for name in sorted(api_registry.keys()): + fn = api_registry[name] + if not callable(fn): + continue + sig = inspect.signature(fn) + parameters: list[dict[str, Any]] = [] + for pname, param in sig.parameters.items(): + if pname == "request": + continue + jtype, pytype = _json_schema_and_python_type(param.annotation) + has_default = param.default is not inspect.Parameter.empty + parameters.append( + { + "label": pname, + "parameter_name": pname, + "parameter_has_default": has_default, + "parameter_default": None if not has_default else param.default, + "type": jtype, + "python_type": {"type": pytype, "description": ""}, + "component": "Api", + "example_input": None, + } + ) + ret_ann = sig.return_annotation + if ret_ann is inspect.Signature.empty: + ret_ann = Any + rjtype, rpytype = _json_schema_and_python_type(ret_ann) + returns = [ + { + "label": "result", + "type": rjtype, + "python_type": {"type": rpytype, "description": ""}, + "component": "Api", + } + ] + named_endpoints[f"/{name}"] = { + "parameters": parameters, + "returns": returns, + "api_visibility": "public", + } + return {"named_endpoints": named_endpoints, "unnamed_endpoints": {}} + + +_MAX_GRADIO_CALL_EVENTS = 256 + + +def _hf_token_value_is_unset(value: Any) -> bool: + if value is None: + return True + if isinstance(value, str) and value.strip() == "": + return True + return False + + +def _authorization_bearer_token(request: Request) -> str | None: + auth = request.headers.get("authorization") or request.headers.get("Authorization") + if not auth: + return None + parts = auth.split() + if len(parts) != 2 or parts[0].lower() != "bearer": + return None + tok = parts[1].strip() + return tok or None + + +def _maybe_apply_hf_token_from_authorization( + request: Request, fn: Any, args: list[Any], kwargs: dict[str, Any] +) -> None: + if not on_spaces(): + return + token = _authorization_bearer_token(request) + if not token: + return + sig = inspect.signature(fn) + if "hf_token" not in sig.parameters: + return + params = [p for p in sig.parameters.values() if p.name != "request"] + names = [p.name for p in params] + if "hf_token" not in names: + return + idx = names.index("hf_token") + if "hf_token" in kwargs: + if _hf_token_value_is_unset(kwargs["hf_token"]): + kwargs["hf_token"] = token + return + if idx < len(args): + if _hf_token_value_is_unset(args[idx]): + args[idx] = token + return + kwargs["hf_token"] = token + + +def _store_gradio_call_result( + request: Request, event_id: str, api_name: str, data: Any +) -> None: + with request.app.state.gradio_call_events_lock: + d = request.app.state.gradio_call_events + while len(d) >= _MAX_GRADIO_CALL_EVENTS: + d.pop(next(iter(d))) + d[event_id] = {"api_name": api_name, "data": data} + + +async def run_api_request(request: Request, api_name: str) -> Response: + api_registry = request.app.state.api_registry + fn = api_registry.get(api_name) + if fn is None: + return JSONResponse({"error": f"Unknown API: {api_name}"}, status_code=404) + + try: + body = await request.json() + except Exception: + body = {} + + args: list[Any] = [] + kwargs: dict[str, Any] = {} + if isinstance(body, dict): + if "args" in body or "kwargs" in body: + args = body.get("args") or [] + kwargs = body.get("kwargs") or {} + elif "data" in body and isinstance(body["data"], list): + args = body["data"] + else: + kwargs = body + elif isinstance(body, list): + args = body + elif body is not None: + args = [body] + + if not isinstance(args, list): + args = [args] + if not isinstance(kwargs, dict): + kwargs = {} + + _maybe_apply_hf_token_from_authorization(request, fn, args, kwargs) + + try: + result = _invoke_handler(fn, request, args=args, kwargs=kwargs) + return JSONResponse({"data": _json_safe(result)}) + except TrackioAPIError as e: + return JSONResponse({"error": str(e)}, status_code=400) + except Exception as e: + return JSONResponse({"error": str(e)}, status_code=500) + + +async def api_handler(request: Request) -> Response: + return await run_api_request(request, request.path_params["api_name"]) + + +async def gradio_api_info_handler(request: Request) -> Response: + return JSONResponse( + build_gradio_api_info(request.app.state.api_registry), + headers={"Cache-Control": "no-store"}, + ) + + +async def gradio_call_post_handler(request: Request) -> Response: + api_name = request.path_params["api_name"] + resp = await run_api_request(request, api_name) + if resp.status_code != 200: + return resp + body = json.loads(bytes(resp.body).decode()) + event_id = secrets.token_urlsafe(16) + _store_gradio_call_result(request, event_id, api_name, body["data"]) + return JSONResponse({"event_id": event_id}) + + +async def gradio_call_poll_handler(request: Request) -> Response: + api_name = request.path_params["api_name"] + event_id = request.path_params["event_id"] + with request.app.state.gradio_call_events_lock: + event = request.app.state.gradio_call_events.pop(event_id, None) + if event is None: + logger.info("gradio_api poll: unknown or expired event_id") + return JSONResponse({"error": "Unknown or expired event_id"}, status_code=404) + if event.get("api_name") != api_name: + logger.info( + "gradio_api poll: api_name mismatch (path=%r, stored=%r)", + api_name, + event.get("api_name"), + ) + with request.app.state.gradio_call_events_lock: + d = request.app.state.gradio_call_events + while len(d) >= _MAX_GRADIO_CALL_EVENTS: + d.pop(next(iter(d))) + d[event_id] = event + return JSONResponse({"error": "Unknown or expired event_id"}, status_code=404) + + data = event["data"] + payload = json.dumps(_json_safe([data])) + + async def sse() -> Any: + yield f"event: complete\ndata: {payload}\n\n" + + return StreamingResponse( + sse(), + media_type="text/event-stream", + headers={ + "Cache-Control": "no-store", + "X-Accel-Buffering": "no", + }, + ) + + +async def upload_handler(request: Request) -> Response: + upload_authorizer = getattr(request.app.state, "upload_authorizer", None) + if callable(upload_authorizer): + try: + upload_authorizer(request) + except TrackioAPIError as e: + return JSONResponse({"error": str(e)}, status_code=400) + + form = await request.form() + uploads = form.getlist("files") + saved_paths = [] + for upload in uploads: + suffix = Path(getattr(upload, "filename", "") or "").suffix + with tempfile.NamedTemporaryFile( + delete=False, + prefix="trackio-upload-", + suffix=suffix, + ) as tmp: + tmp.write(await upload.read()) + register_uploaded_temp_file(request, tmp.name) + saved_paths.append(tmp.name) + return JSONResponse({"paths": saved_paths}) + + +async def gradio_upload_alias_handler(request: Request) -> Response: + return await upload_handler(request) + + +_DISALLOWED_FILE_SUFFIXES = frozenset( + {".db", ".db-journal", ".db-wal", ".db-shm", ".sqlite", ".sqlite3"} +) + + +async def file_handler(request: Request) -> Response: + fs_path = request.query_params.get("path") + if fs_path is None: + return Response("Missing path", status_code=400) + fp = Path(unquote(fs_path)).resolve(strict=False) + if fp.suffix.lower() in _DISALLOWED_FILE_SUFFIXES: + return Response("Not found", status_code=404) + allowed_roots = getattr(request.app.state, "allowed_file_roots", ()) + if fp.is_file() and _is_allowed_file_path(fp, allowed_roots): + return FileResponse(str(fp)) + return Response("Not found", status_code=404) + + +def create_trackio_starlette_app( + oauth_routes: list[Route], + api_registry: dict[str, Any], + extra_routes: list[Any] | None = None, + mcp_lifespan: Any = None, + mcp_enabled: bool = False, + allowed_file_roots: list[str | Path] | None = None, + upload_authorizer: Callable[[Request], None] | None = None, +) -> Starlette: + routes: list[Any] = list(oauth_routes) + routes.extend( + [ + Route("/version", endpoint=version_handler, methods=["GET"]), + Route("/api/upload", endpoint=upload_handler, methods=["POST"]), + Route("/api/{api_name:str}", endpoint=api_handler, methods=["POST"]), + Route("/file", endpoint=file_handler, methods=["GET"]), + ] + ) + if on_spaces(): + routes.extend( + [ + Route( + "/gradio_api/info", + endpoint=gradio_api_info_handler, + methods=["GET"], + ), + Route( + "/gradio_api/info/", + endpoint=gradio_api_info_handler, + methods=["GET"], + ), + Route( + "/gradio_api/upload", + endpoint=gradio_upload_alias_handler, + methods=["POST"], + ), + Route( + "/gradio_api/upload/", + endpoint=gradio_upload_alias_handler, + methods=["POST"], + ), + Route( + "/gradio_api/call/{api_name:str}", + endpoint=gradio_call_post_handler, + methods=["POST"], + ), + Route( + "/gradio_api/call/{api_name:str}/", + endpoint=gradio_call_post_handler, + methods=["POST"], + ), + Route( + "/gradio_api/call/{api_name:str}/{event_id:str}", + endpoint=gradio_call_poll_handler, + methods=["GET"], + ), + Route( + "/gradio_api/call/{api_name:str}/{event_id:str}/", + endpoint=gradio_call_poll_handler, + methods=["GET"], + ), + ] + ) + routes.extend(extra_routes or []) + app = Starlette(routes=routes, lifespan=mcp_lifespan) + app.state.api_registry = api_registry + app.state.mcp_enabled = mcp_enabled + app.state.allowed_file_roots = _normalize_allowed_file_roots(allowed_file_roots) + app.state.upload_authorizer = upload_authorizer + app.state.uploaded_temp_files = set() + app.state.uploaded_temp_files_lock = threading.Lock() + if on_spaces(): + app.state.gradio_call_events = {} + app.state.gradio_call_events_lock = threading.Lock() + return app diff --git a/trackio/assets/badge.png b/trackio/assets/badge.png new file mode 100644 index 0000000000000000000000000000000000000000..03e0340873223b3ecb45f3ebf09512f6d6746ec2 --- /dev/null +++ b/trackio/assets/badge.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:206b7847247e83279f498510a2760338a03116bb5141a658d71ec14429f9ea9e +size 169669 diff --git a/trackio/assets/trackio_logo_dark.png b/trackio/assets/trackio_logo_dark.png new file mode 100644 index 0000000000000000000000000000000000000000..e6ff7e0a3580bca040d9ec3ea8c91e8cca469e61 Binary files /dev/null and b/trackio/assets/trackio_logo_dark.png differ diff --git a/trackio/assets/trackio_logo_light.png b/trackio/assets/trackio_logo_light.png new file mode 100644 index 0000000000000000000000000000000000000000..b3438262c61989e6c6d16df4801a8935136115b3 Binary files /dev/null and b/trackio/assets/trackio_logo_light.png differ diff --git a/trackio/assets/trackio_logo_old.png b/trackio/assets/trackio_logo_old.png new file mode 100644 index 0000000000000000000000000000000000000000..48a07d40b83e23c9cc9dc0cb6544a3c6ad62b57f --- /dev/null +++ b/trackio/assets/trackio_logo_old.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3922c4d1e465270ad4d8abb12023f3beed5d9f7f338528a4c0ac21dcf358a1c8 +size 487101 diff --git a/trackio/assets/trackio_logo_type_dark.png b/trackio/assets/trackio_logo_type_dark.png new file mode 100644 index 0000000000000000000000000000000000000000..6f80a3191e514a8a0beaa6ab2011e5baf8df5eda Binary files /dev/null and b/trackio/assets/trackio_logo_type_dark.png differ diff --git a/trackio/assets/trackio_logo_type_dark_transparent.png b/trackio/assets/trackio_logo_type_dark_transparent.png new file mode 100644 index 0000000000000000000000000000000000000000..2495f610c975917290b57706133b38621a58cb8b Binary files /dev/null and b/trackio/assets/trackio_logo_type_dark_transparent.png differ diff --git a/trackio/assets/trackio_logo_type_light.png b/trackio/assets/trackio_logo_type_light.png new file mode 100644 index 0000000000000000000000000000000000000000..f07866d245ea897b9aba417b29403f7f91cc8bbd Binary files /dev/null and b/trackio/assets/trackio_logo_type_light.png differ diff --git a/trackio/assets/trackio_logo_type_light_transparent.png b/trackio/assets/trackio_logo_type_light_transparent.png new file mode 100644 index 0000000000000000000000000000000000000000..a20b4d5e64c61c91546577645310593fe3493508 Binary files /dev/null and b/trackio/assets/trackio_logo_type_light_transparent.png differ diff --git a/trackio/bucket_storage.py b/trackio/bucket_storage.py new file mode 100644 index 0000000000000000000000000000000000000000..4076e9d2733c5ae63b847e07f40442e07e16da5a --- /dev/null +++ b/trackio/bucket_storage.py @@ -0,0 +1,151 @@ +import shutil +import tempfile +from pathlib import Path + +import huggingface_hub + +from trackio.sqlite_storage import SQLiteStorage +from trackio.utils import MEDIA_DIR, TRACKIO_DIR + + +def create_bucket_if_not_exists(bucket_id: str, private: bool | None = None) -> None: + huggingface_hub.create_bucket(bucket_id, private=private, exist_ok=True) + + +def _list_bucket_file_paths(bucket_id: str, prefix: str | None = None) -> list[str]: + items = huggingface_hub.list_bucket_tree(bucket_id, prefix=prefix, recursive=True) + return [ + item.path + for item in items + if getattr(item, "type", None) == "file" and getattr(item, "path", None) + ] + + +def download_bucket_to_trackio_dir(bucket_id: str) -> None: + TRACKIO_DIR.mkdir(parents=True, exist_ok=True) + huggingface_hub.sync_bucket( + source=f"hf://buckets/{bucket_id}/trackio", + dest=str(TRACKIO_DIR), + quiet=True, + ) + + +def upload_project_to_bucket(project: str, bucket_id: str) -> None: + db_path = SQLiteStorage.get_project_db_path(project) + if not db_path.exists(): + raise FileNotFoundError(f"No database found for project '{project}'") + + with SQLiteStorage._get_connection( + db_path, configure_pragmas=False, row_factory=None + ) as conn: + conn.execute("PRAGMA wal_checkpoint(TRUNCATE)") + + files_to_add = [(str(db_path), f"trackio/{db_path.name}")] + + media_dir = MEDIA_DIR / project + if media_dir.exists(): + for media_file in media_dir.rglob("*"): + if media_file.is_file(): + rel = media_file.relative_to(TRACKIO_DIR) + files_to_add.append((str(media_file), f"trackio/{rel}")) + + huggingface_hub.batch_bucket_files(bucket_id, add=files_to_add) + + +def _download_db_from_bucket( + project: str, bucket_id: str, dest_path: Path | None = None +) -> bool: + db_filename = SQLiteStorage.get_project_db_filename(project) + remote_path = f"trackio/{db_filename}" + local_path = dest_path or SQLiteStorage.get_project_db_path(project) + local_path.parent.mkdir(parents=True, exist_ok=True) + try: + huggingface_hub.download_bucket_files( + bucket_id, + files=[(remote_path, str(local_path))], + token=huggingface_hub.utils.get_token(), + ) + return local_path.exists() + except Exception: + return False + + +def _local_db_has_data(project: str) -> bool: + db_path = SQLiteStorage.get_project_db_path(project) + if not db_path.exists() or db_path.stat().st_size == 0: + return False + try: + with SQLiteStorage._get_connection( + db_path, configure_pragmas=False, row_factory=None + ) as conn: + count = conn.execute("SELECT COUNT(*) FROM metrics").fetchone()[0] + return count > 0 + except Exception: + return False + + +def _export_and_upload_static( + project: str, + dest_bucket_id: str, + db_path: Path, + media_dir: Path | None = None, +) -> None: + with tempfile.TemporaryDirectory() as tmp_dir: + output_dir = Path(tmp_dir) + SQLiteStorage.export_for_static_space( + project, output_dir, db_path_override=db_path + ) + + if media_dir and media_dir.exists(): + shutil.copytree(media_dir, output_dir / "media") + + files_to_add = [] + for f in output_dir.rglob("*"): + if f.is_file(): + rel = f.relative_to(output_dir) + files_to_add.append((str(f), str(rel))) + + huggingface_hub.batch_bucket_files(dest_bucket_id, add=files_to_add) + + +def _copy_project_media_between_buckets( + source_bucket_id: str, dest_bucket_id: str, project: str +) -> None: + source_media_prefix = f"trackio/media/{project}/" + media_to_copy = _list_bucket_file_paths( + source_bucket_id, prefix=source_media_prefix + ) + if not media_to_copy: + return + + huggingface_hub.copy_files( + f"hf://buckets/{source_bucket_id}/{source_media_prefix}", + f"hf://buckets/{dest_bucket_id}/media/", + ) + + +def upload_project_to_bucket_for_static(project: str, bucket_id: str) -> None: + if not _local_db_has_data(project): + _download_db_from_bucket(project, bucket_id) + + db_path = SQLiteStorage.get_project_db_path(project) + _export_and_upload_static(project, bucket_id, db_path, MEDIA_DIR / project) + + +def export_from_bucket_for_static( + source_bucket_id: str, + dest_bucket_id: str, + project: str, +) -> None: + with tempfile.TemporaryDirectory() as work_dir: + work_path = Path(work_dir) + db_path = work_path / SQLiteStorage.get_project_db_filename(project) + + if not _download_db_from_bucket(project, source_bucket_id, dest_path=db_path): + raise FileNotFoundError( + f"Could not download database for project '{project}' " + f"from bucket '{source_bucket_id}'." + ) + + _export_and_upload_static(project, dest_bucket_id, db_path) + _copy_project_media_between_buckets(source_bucket_id, dest_bucket_id, project) diff --git a/trackio/cli.py b/trackio/cli.py new file mode 100644 index 0000000000000000000000000000000000000000..d9d062213407844d49b38e640f775c2c4953b527 --- /dev/null +++ b/trackio/cli.py @@ -0,0 +1,1419 @@ +import argparse +import os + +from trackio import freeze, show, sync +from trackio.cli_helpers import ( + error_exit, + format_alerts, + format_json, + format_list, + format_metric_values, + format_project_summary, + format_query_result, + format_run_summary, + format_snapshot, + format_system_metric_names, + format_system_metrics, +) +from trackio.frontend_config import ( + TRACKIO_CONFIG_PATH, + get_persisted_frontend_dir, + set_persisted_frontend_dir, + unset_persisted_frontend_dir, +) +from trackio.markdown import Markdown +from trackio.server import get_project_summary, get_run_summary +from trackio.sqlite_storage import SQLiteStorage + + +def _get_space(args): + return getattr(args, "space", None) + + +def _get_remote(args): + from trackio.remote_client import RemoteClient + + space = _get_space(args) + if not space: + return None + hf_token = getattr(args, "hf_token", None) + return RemoteClient(space, hf_token=hf_token) + + +def _handle_status(): + print("Reading local Trackio projects...\n") + projects = SQLiteStorage.get_projects() + if not projects: + print("No Trackio projects found.") + return + + local_projects = [] + synced_projects = [] + unsynced_projects = [] + + for project in projects: + space_id = SQLiteStorage.get_space_id(project) + if space_id is None: + local_projects.append(project) + elif SQLiteStorage.has_pending_data(project): + unsynced_projects.append(project) + else: + synced_projects.append(project) + + print("Finished reading Trackio projects") + if local_projects: + print(f" * {len(local_projects)} local trackio project(s) [OK]") + if synced_projects: + print(f" * {len(synced_projects)} trackio project(s) synced to Spaces [OK]") + if unsynced_projects: + print( + f" * {len(unsynced_projects)} trackio project(s) with unsynced changes [WARNING]:" + ) + for p in unsynced_projects: + print(f" - {p}") + + if unsynced_projects: + print( + f"\nRun `trackio sync --project {unsynced_projects[0]}` to sync. " + "Or run `trackio sync --all` to sync all unsynced changes." + ) + + +def _handle_sync(args): + from trackio.deploy import sync_incremental + + if args.sync_all and args.project: + error_exit("Cannot use --all and --project together.") + if not args.sync_all and not args.project: + error_exit("Must provide either --project or --all.") + + if args.sync_all: + projects = SQLiteStorage.get_projects() + synced_any = False + for project in projects: + space_id = SQLiteStorage.get_space_id(project) + if space_id and SQLiteStorage.has_pending_data(project): + sync_incremental( + project, + space_id, + private=args.private, + pending_only=True, + frontend_dir=args.frontend, + ) + synced_any = True + if not synced_any: + print("No projects with unsynced data found.") + else: + space_id = args.space_id + if space_id is None: + space_id = SQLiteStorage.get_space_id(args.project) + sync( + project=args.project, + space_id=space_id, + private=args.private, + force=args.force, + sdk=args.sdk, + frontend_dir=args.frontend, + ) + + +def _handle_config(args): + if args.config_command == "get": + frontend_dir = get_persisted_frontend_dir() + if frontend_dir is None: + print("No Trackio frontend config is set.") + print(f"Config file: {TRACKIO_CONFIG_PATH}") + return + print(f"frontend: {frontend_dir}") + print(f"config: {TRACKIO_CONFIG_PATH}") + return + + if args.config_command == "set": + try: + frontend_dir = set_persisted_frontend_dir(args.frontend) + except ValueError as e: + error_exit(str(e)) + print(f"Saved Trackio default frontend: {frontend_dir}") + print("Reset with `trackio config unset frontend`.") + return + + if args.config_command == "unset": + removed = unset_persisted_frontend_dir() + if removed: + print("Removed Trackio default frontend.") + else: + print("No Trackio default frontend was set.") + return + + +def _extract_reports( + run: str, logs: list[dict], report_name: str | None = None +) -> list[dict]: + reports = [] + for log in logs: + timestamp = log.get("timestamp") + step = log.get("step") + for key, value in log.items(): + if report_name is not None and key != report_name: + continue + if isinstance(value, dict) and value.get("_type") == Markdown.TYPE: + content = value.get("_value") + if isinstance(content, str): + reports.append( + { + "run": run, + "report": key, + "step": step, + "timestamp": timestamp, + "content": content, + } + ) + return reports + + +def _handle_query(args): + remote = _get_remote(args) + try: + if remote: + result = remote.predict(args.project, args.sql, api_name="/query_project") + else: + result = SQLiteStorage.query_project(args.project, args.sql) + except FileNotFoundError as e: + error_exit(str(e)) + except ValueError as e: + error_exit(str(e)) + + if args.json: + print(format_json(result)) + else: + print(format_query_result(result)) + + +def main(): + parser = argparse.ArgumentParser(description="Trackio CLI") + parser.add_argument( + "--space", + required=False, + help="HF Space ID (e.g. 'user/space') or Space URL to query remotely.", + ) + parser.add_argument( + "--hf-token", + required=False, + help="HF token for accessing private Spaces.", + ) + subparsers = parser.add_subparsers(dest="command") + + ui_parser = subparsers.add_parser( + "show", help="Show the Trackio dashboard UI for a project" + ) + ui_parser.add_argument( + "--project", required=False, help="Project name to show in the dashboard" + ) + ui_parser.add_argument( + "--theme", + required=False, + default="default", + help="A Gradio Theme to use for the dashboard instead of the default, can be a built-in theme (e.g. 'soft', 'citrus'), or a theme from the Hub (e.g. 'gstaff/xkcd').", + ) + ui_parser.add_argument( + "--mcp-server", + action="store_true", + help="Enable MCP server functionality. The Trackio dashboard will be set up as an MCP server and certain functions will be exposed as MCP tools.", + ) + ui_parser.add_argument( + "--footer", + action="store_true", + default=True, + help="Show the Gradio footer. Use --no-footer to hide it.", + ) + ui_parser.add_argument( + "--no-footer", + dest="footer", + action="store_false", + help="Hide the Gradio footer.", + ) + ui_parser.add_argument( + "--color-palette", + required=False, + help="Comma-separated list of hex color codes for plot lines (e.g. '#FF0000,#00FF00,#0000FF'). If not provided, the TRACKIO_COLOR_PALETTE environment variable will be used, or the default palette if not set.", + ) + ui_parser.add_argument( + "--host", + required=False, + help="Host to bind the server to (e.g. '0.0.0.0' for remote access). If not provided, defaults to '127.0.0.1' (localhost only).", + ) + ui_parser.add_argument( + "--frontend", + required=False, + help="Custom frontend directory to serve. Must contain index.html.", + ) + + subparsers.add_parser( + "status", + help="Show the status of all local Trackio projects, including sync status.", + ) + + sync_parser = subparsers.add_parser( + "sync", + help="Sync a local project's database to a Hugging Face Space. If the Space does not exist, it will be created.", + ) + sync_parser.add_argument( + "--project", + required=False, + help="The name of the local project.", + ) + sync_parser.add_argument( + "--space-id", + required=False, + help="The Hugging Face Space ID where the project will be synced (e.g. username/space_id). If not provided, uses the previously-configured Space.", + ) + sync_parser.add_argument( + "--all", + action="store_true", + dest="sync_all", + help="Sync all projects that have unsynced data to their configured Spaces.", + ) + sync_parser.add_argument( + "--private", + action="store_true", + help="Make the Hugging Face Space private if creating a new Space. By default, the repo will be public unless the organization's default is private. This value is ignored if the repo already exists.", + ) + sync_parser.add_argument( + "--force", + action="store_true", + help="Overwrite the existing database without prompting for confirmation.", + ) + sync_parser.add_argument( + "--sdk", + choices=["gradio", "static"], + default="gradio", + help="The type of Space to deploy. 'gradio' (default) deploys a live Gradio server. 'static' deploys a static Space that reads from an HF Bucket.", + ) + sync_parser.add_argument( + "--frontend", + required=False, + help="Custom frontend directory to deploy. Must contain index.html.", + ) + + freeze_parser = subparsers.add_parser( + "freeze", + help="Create a one-time static Space snapshot from a project's data.", + ) + freeze_parser.add_argument( + "--space-id", + required=True, + help="The source Gradio Space ID (e.g. username/space_id).", + ) + freeze_parser.add_argument( + "--project", + required=True, + help="The name of the project to freeze into a static snapshot.", + ) + freeze_parser.add_argument( + "--new-space-id", + required=False, + help="The Space ID for the new static Space. Defaults to {space_id}_static.", + ) + freeze_parser.add_argument( + "--private", + action="store_true", + help="Make the new static Space private.", + ) + freeze_parser.add_argument( + "--frontend", + required=False, + help="Custom frontend directory to deploy to the frozen static Space.", + ) + + config_parser = subparsers.add_parser( + "config", + help="Manage persistent Trackio configuration.", + ) + config_subparsers = config_parser.add_subparsers( + dest="config_command", + required=True, + ) + config_subparsers.add_parser("get", help="Show current Trackio config.") + config_set_parser = config_subparsers.add_parser( + "set", + help="Set a persistent Trackio config value.", + ) + config_set_parser.add_argument( + "key", + choices=["frontend"], + help="Config key to set.", + ) + config_set_parser.add_argument( + "frontend", + help="Frontend directory to persist.", + ) + config_unset_parser = config_subparsers.add_parser( + "unset", + help="Unset a persistent Trackio config value.", + ) + config_unset_parser.add_argument( + "key", + choices=["frontend"], + help="Config key to unset.", + ) + + list_parser = subparsers.add_parser( + "list", + help="List projects, runs, or metrics", + ) + list_subparsers = list_parser.add_subparsers(dest="list_type", required=True) + + list_projects_parser = list_subparsers.add_parser( + "projects", + help="List all projects", + ) + list_projects_parser.add_argument( + "--json", + action="store_true", + help="Output in JSON format", + ) + + list_runs_parser = list_subparsers.add_parser( + "runs", + help="List runs for a project", + ) + list_runs_parser.add_argument( + "--project", + required=True, + help="Project name", + ) + list_runs_parser.add_argument( + "--json", + action="store_true", + help="Output in JSON format", + ) + + list_metrics_parser = list_subparsers.add_parser( + "metrics", + help="List metrics for a run", + ) + list_metrics_parser.add_argument( + "--project", + required=True, + help="Project name", + ) + list_metrics_parser.add_argument( + "--run", + required=True, + help="Run name", + ) + list_metrics_parser.add_argument( + "--json", + action="store_true", + help="Output in JSON format", + ) + + list_system_metrics_parser = list_subparsers.add_parser( + "system-metrics", + help="List system metrics for a run", + ) + list_system_metrics_parser.add_argument( + "--project", + required=True, + help="Project name", + ) + list_system_metrics_parser.add_argument( + "--run", + required=True, + help="Run name", + ) + list_system_metrics_parser.add_argument( + "--json", + action="store_true", + help="Output in JSON format", + ) + + list_alerts_parser = list_subparsers.add_parser( + "alerts", + help="List alerts for a project or run", + ) + list_alerts_parser.add_argument( + "--project", + required=True, + help="Project name", + ) + list_alerts_parser.add_argument( + "--run", + required=False, + help="Run name (optional)", + ) + list_alerts_parser.add_argument( + "--level", + required=False, + help="Filter by alert level (info, warn, error)", + ) + list_alerts_parser.add_argument( + "--json", + action="store_true", + help="Output in JSON format", + ) + list_alerts_parser.add_argument( + "--since", + required=False, + help="Only show alerts after this ISO 8601 timestamp", + ) + + list_reports_parser = list_subparsers.add_parser( + "reports", + help="List markdown reports for a project or run", + ) + list_reports_parser.add_argument( + "--project", + required=True, + help="Project name", + ) + list_reports_parser.add_argument( + "--run", + required=False, + help="Run name (optional)", + ) + list_reports_parser.add_argument( + "--json", + action="store_true", + help="Output in JSON format", + ) + + get_parser = subparsers.add_parser( + "get", + help="Get project, run, or metric information", + ) + get_subparsers = get_parser.add_subparsers(dest="get_type", required=True) + + get_project_parser = get_subparsers.add_parser( + "project", + help="Get project summary", + ) + get_project_parser.add_argument( + "--project", + required=True, + help="Project name", + ) + get_project_parser.add_argument( + "--json", + action="store_true", + help="Output in JSON format", + ) + + get_run_parser = get_subparsers.add_parser( + "run", + help="Get run summary", + ) + get_run_parser.add_argument( + "--project", + required=True, + help="Project name", + ) + get_run_parser.add_argument( + "--run", + required=True, + help="Run name", + ) + get_run_parser.add_argument( + "--json", + action="store_true", + help="Output in JSON format", + ) + + get_metric_parser = get_subparsers.add_parser( + "metric", + help="Get metric values for a run", + ) + get_metric_parser.add_argument( + "--project", + required=True, + help="Project name", + ) + get_metric_parser.add_argument( + "--run", + required=True, + help="Run name", + ) + get_metric_parser.add_argument( + "--metric", + required=True, + help="Metric name", + ) + get_metric_parser.add_argument( + "--step", + type=int, + required=False, + help="Get metric at exactly this step", + ) + get_metric_parser.add_argument( + "--around", + type=int, + required=False, + help="Get metrics around this step (use with --window)", + ) + get_metric_parser.add_argument( + "--at-time", + required=False, + help="Get metrics around this ISO 8601 timestamp (use with --window)", + ) + get_metric_parser.add_argument( + "--window", + type=int, + required=False, + default=10, + help="Window size: ±steps for --around, ±seconds for --at-time (default: 10)", + ) + get_metric_parser.add_argument( + "--json", + action="store_true", + help="Output in JSON format", + ) + + get_snapshot_parser = get_subparsers.add_parser( + "snapshot", + help="Get all metrics at/around a step or timestamp", + ) + get_snapshot_parser.add_argument( + "--project", + required=True, + help="Project name", + ) + get_snapshot_parser.add_argument( + "--run", + required=True, + help="Run name", + ) + get_snapshot_parser.add_argument( + "--step", + type=int, + required=False, + help="Get all metrics at exactly this step", + ) + get_snapshot_parser.add_argument( + "--around", + type=int, + required=False, + help="Get all metrics around this step (use with --window)", + ) + get_snapshot_parser.add_argument( + "--at-time", + required=False, + help="Get all metrics around this ISO 8601 timestamp (use with --window)", + ) + get_snapshot_parser.add_argument( + "--window", + type=int, + required=False, + default=10, + help="Window size: ±steps for --around, ±seconds for --at-time (default: 10)", + ) + get_snapshot_parser.add_argument( + "--json", + action="store_true", + help="Output in JSON format", + ) + + get_system_metric_parser = get_subparsers.add_parser( + "system-metric", + help="Get system metric values for a run", + ) + get_system_metric_parser.add_argument( + "--project", + required=True, + help="Project name", + ) + get_system_metric_parser.add_argument( + "--run", + required=True, + help="Run name", + ) + get_system_metric_parser.add_argument( + "--metric", + required=False, + help="System metric name (optional, if not provided returns all system metrics)", + ) + get_system_metric_parser.add_argument( + "--json", + action="store_true", + help="Output in JSON format", + ) + + get_alerts_parser = get_subparsers.add_parser( + "alerts", + help="Get alerts for a project or run", + ) + get_alerts_parser.add_argument( + "--project", + required=True, + help="Project name", + ) + get_alerts_parser.add_argument( + "--run", + required=False, + help="Run name (optional)", + ) + get_alerts_parser.add_argument( + "--level", + required=False, + help="Filter by alert level (info, warn, error)", + ) + get_alerts_parser.add_argument( + "--json", + action="store_true", + help="Output in JSON format", + ) + get_alerts_parser.add_argument( + "--since", + required=False, + help="Only show alerts after this ISO 8601 timestamp", + ) + + get_report_parser = get_subparsers.add_parser( + "report", + help="Get markdown report entries for a run", + ) + get_report_parser.add_argument( + "--project", + required=True, + help="Project name", + ) + get_report_parser.add_argument( + "--run", + required=True, + help="Run name", + ) + get_report_parser.add_argument( + "--report", + required=True, + help="Report metric name", + ) + get_report_parser.add_argument( + "--json", + action="store_true", + help="Output in JSON format", + ) + + query_parser = subparsers.add_parser( + "query", + help="Run a read-only SQL query against a project database", + ) + query_subparsers = query_parser.add_subparsers(dest="query_type", required=True) + query_project_parser = query_subparsers.add_parser( + "project", + help="Run a read-only SQL query against a project's SQLite database", + ) + query_project_parser.add_argument( + "--project", + required=True, + help="Project name", + ) + query_project_parser.add_argument( + "--sql", + required=True, + help="Read-only SQL query to execute", + ) + query_project_parser.add_argument( + "--json", + action="store_true", + help="Output in JSON format", + ) + + skills_parser = subparsers.add_parser( + "skills", + help="Manage Trackio skills for AI coding assistants", + ) + skills_subparsers = skills_parser.add_subparsers( + dest="skills_action", required=True + ) + skills_add_parser = skills_subparsers.add_parser( + "add", + help="Download and install the Trackio skill for an AI assistant", + ) + skills_add_parser.add_argument( + "--cursor", + action="store_true", + help="Install for Cursor", + ) + skills_add_parser.add_argument( + "--claude", + action="store_true", + help="Install for Claude Code", + ) + skills_add_parser.add_argument( + "--codex", + action="store_true", + help="Install for Codex", + ) + skills_add_parser.add_argument( + "--opencode", + action="store_true", + help="Install for OpenCode", + ) + skills_add_parser.add_argument( + "--global", + dest="global_", + action="store_true", + help="Install globally (user-level) instead of in the current project directory", + ) + skills_add_parser.add_argument( + "--dest", + type=str, + required=False, + help="Install into a custom destination (path to skills directory)", + ) + skills_add_parser.add_argument( + "--force", + action="store_true", + help="Overwrite existing skill if it already exists", + ) + + args, unknown_args = parser.parse_known_args() + if unknown_args: + trailing_global_parser = argparse.ArgumentParser(add_help=False) + trailing_global_parser.add_argument("--space", required=False) + trailing_global_parser.add_argument("--hf-token", required=False) + trailing_globals, remaining_unknown = trailing_global_parser.parse_known_args( + unknown_args + ) + if remaining_unknown: + parser.error(f"unrecognized arguments: {' '.join(remaining_unknown)}") + if trailing_globals.space is not None: + args.space = trailing_globals.space + if trailing_globals.hf_token is not None: + args.hf_token = trailing_globals.hf_token + + if args.command in ("show", "status", "sync", "freeze", "skills") and _get_space( + args + ): + error_exit( + f"The '{args.command}' command does not support --space (remote mode)." + ) + + if args.command == "show": + color_palette = None + if args.color_palette: + color_palette = [color.strip() for color in args.color_palette.split(",")] + show( + project=args.project, + theme=args.theme, + mcp_server=args.mcp_server, + footer=args.footer, + color_palette=color_palette, + host=args.host, + frontend_dir=args.frontend, + ) + elif args.command == "status": + _handle_status() + elif args.command == "sync": + _handle_sync(args) + elif args.command == "freeze": + freeze( + space_id=args.space_id, + project=args.project, + new_space_id=args.new_space_id, + private=args.private, + frontend_dir=args.frontend, + ) + elif args.command == "config": + _handle_config(args) + elif args.command == "list": + remote = _get_remote(args) + if args.list_type == "projects": + if remote: + projects = remote.predict(api_name="/get_all_projects") + else: + projects = SQLiteStorage.get_projects() + if args.json: + print(format_json({"projects": projects})) + else: + print(format_list(projects, "Projects")) + elif args.list_type == "runs": + if remote: + run_records = remote.predict( + args.project, api_name="/get_runs_for_project" + ) + runs = [r["name"] if isinstance(r, dict) else r for r in run_records] + else: + db_path = SQLiteStorage.get_project_db_path(args.project) + if not db_path.exists(): + error_exit(f"Project '{args.project}' not found.") + runs = SQLiteStorage.get_runs(args.project) + if args.json: + print(format_json({"project": args.project, "runs": runs})) + else: + print(format_list(runs, f"Runs in '{args.project}'")) + elif args.list_type == "metrics": + if remote: + metrics = remote.predict( + args.project, args.run, api_name="/get_metrics_for_run" + ) + else: + db_path = SQLiteStorage.get_project_db_path(args.project) + if not db_path.exists(): + error_exit(f"Project '{args.project}' not found.") + runs = SQLiteStorage.get_runs(args.project) + if args.run not in runs: + error_exit( + f"Run '{args.run}' not found in project '{args.project}'." + ) + metrics = SQLiteStorage.get_all_metrics_for_run(args.project, args.run) + if args.json: + print( + format_json( + {"project": args.project, "run": args.run, "metrics": metrics} + ) + ) + else: + print( + format_list( + metrics, f"Metrics for '{args.run}' in '{args.project}'" + ) + ) + elif args.list_type == "system-metrics": + if remote: + system_metrics = remote.predict( + args.project, args.run, api_name="/get_system_metrics_for_run" + ) + else: + db_path = SQLiteStorage.get_project_db_path(args.project) + if not db_path.exists(): + error_exit(f"Project '{args.project}' not found.") + runs = SQLiteStorage.get_runs(args.project) + if args.run not in runs: + error_exit( + f"Run '{args.run}' not found in project '{args.project}'." + ) + system_metrics = SQLiteStorage.get_all_system_metrics_for_run( + args.project, args.run + ) + if args.json: + print( + format_json( + { + "project": args.project, + "run": args.run, + "system_metrics": system_metrics, + } + ) + ) + else: + print(format_system_metric_names(system_metrics)) + elif args.list_type == "alerts": + if remote: + alerts = remote.predict( + args.project, + args.run, + args.level, + args.since, + api_name="/get_alerts", + ) + else: + db_path = SQLiteStorage.get_project_db_path(args.project) + if not db_path.exists(): + error_exit(f"Project '{args.project}' not found.") + alerts = SQLiteStorage.get_alerts( + args.project, + run_name=args.run, + level=args.level, + since=args.since, + ) + if args.json: + print( + format_json( + { + "project": args.project, + "run": args.run, + "level": args.level, + "since": args.since, + "alerts": alerts, + } + ) + ) + else: + print(format_alerts(alerts)) + elif args.list_type == "reports": + if remote: + run_records = remote.predict( + args.project, api_name="/get_runs_for_project" + ) + runs = [r["name"] if isinstance(r, dict) else r for r in run_records] + else: + db_path = SQLiteStorage.get_project_db_path(args.project) + if not db_path.exists(): + error_exit(f"Project '{args.project}' not found.") + runs = SQLiteStorage.get_runs(args.project) + if args.run and args.run not in runs: + error_exit(f"Run '{args.run}' not found in project '{args.project}'.") + + target_runs = [args.run] if args.run else runs + all_reports = [] + for run_name in target_runs: + if remote: + logs = remote.predict(args.project, run_name, api_name="/get_logs") + else: + logs = SQLiteStorage.get_logs(args.project, run_name) + all_reports.extend(_extract_reports(run_name, logs)) + + if args.json: + print( + format_json( + { + "project": args.project, + "run": args.run, + "reports": all_reports, + } + ) + ) + else: + report_lines = [ + f"{entry['run']} | {entry['report']} | step={entry['step']} | {entry['timestamp']}" + for entry in all_reports + ] + if args.run: + print( + format_list( + report_lines, + f"Reports for '{args.run}' in '{args.project}'", + ) + ) + else: + print(format_list(report_lines, f"Reports in '{args.project}'")) + elif args.command == "get": + remote = _get_remote(args) + if args.get_type == "project": + if remote: + summary = remote.predict(args.project, api_name="/get_project_summary") + else: + db_path = SQLiteStorage.get_project_db_path(args.project) + if not db_path.exists(): + error_exit(f"Project '{args.project}' not found.") + summary = get_project_summary(args.project) + if args.json: + print(format_json(summary)) + else: + print(format_project_summary(summary)) + elif args.get_type == "run": + if remote: + summary = remote.predict( + args.project, args.run, api_name="/get_run_summary" + ) + else: + db_path = SQLiteStorage.get_project_db_path(args.project) + if not db_path.exists(): + error_exit(f"Project '{args.project}' not found.") + runs = SQLiteStorage.get_runs(args.project) + if args.run not in runs: + error_exit( + f"Run '{args.run}' not found in project '{args.project}'." + ) + summary = get_run_summary(args.project, args.run) + if args.json: + print(format_json(summary)) + else: + print(format_run_summary(summary)) + elif args.get_type == "metric": + at_time = getattr(args, "at_time", None) + if remote: + values = remote.predict( + args.project, + args.run, + args.metric, + args.step, + args.around, + at_time, + args.window, + api_name="/get_metric_values", + ) + else: + db_path = SQLiteStorage.get_project_db_path(args.project) + if not db_path.exists(): + error_exit(f"Project '{args.project}' not found.") + runs = SQLiteStorage.get_runs(args.project) + if args.run not in runs: + error_exit( + f"Run '{args.run}' not found in project '{args.project}'." + ) + metrics = SQLiteStorage.get_all_metrics_for_run(args.project, args.run) + if args.metric not in metrics: + error_exit( + f"Metric '{args.metric}' not found in run '{args.run}' of project '{args.project}'." + ) + values = SQLiteStorage.get_metric_values( + args.project, + args.run, + args.metric, + step=args.step, + around_step=args.around, + at_time=at_time, + window=args.window, + ) + if args.json: + print( + format_json( + { + "project": args.project, + "run": args.run, + "metric": args.metric, + "values": values, + } + ) + ) + else: + print(format_metric_values(values)) + elif args.get_type == "snapshot": + if not args.step and not args.around and not getattr(args, "at_time", None): + error_exit( + "Provide --step, --around (with --window), or --at-time (with --window)." + ) + at_time = getattr(args, "at_time", None) + if remote: + snapshot = remote.predict( + args.project, + args.run, + args.step, + args.around, + at_time, + args.window, + api_name="/get_snapshot", + ) + else: + db_path = SQLiteStorage.get_project_db_path(args.project) + if not db_path.exists(): + error_exit(f"Project '{args.project}' not found.") + runs = SQLiteStorage.get_runs(args.project) + if args.run not in runs: + error_exit( + f"Run '{args.run}' not found in project '{args.project}'." + ) + snapshot = SQLiteStorage.get_snapshot( + args.project, + args.run, + step=args.step, + around_step=args.around, + at_time=at_time, + window=args.window, + ) + if args.json: + result = { + "project": args.project, + "run": args.run, + "metrics": snapshot, + } + if args.step is not None: + result["step"] = args.step + if args.around is not None: + result["around"] = args.around + result["window"] = args.window + if at_time is not None: + result["at_time"] = at_time + result["window"] = args.window + print(format_json(result)) + else: + print(format_snapshot(snapshot)) + elif args.get_type == "system-metric": + if remote: + system_metrics = remote.predict( + args.project, args.run, api_name="/get_system_logs" + ) + if args.metric: + all_system_metric_names = remote.predict( + args.project, + args.run, + api_name="/get_system_metrics_for_run", + ) + if args.metric not in all_system_metric_names: + error_exit( + f"System metric '{args.metric}' not found in run '{args.run}' of project '{args.project}'." + ) + filtered_metrics = [ + { + k: v + for k, v in entry.items() + if k == "timestamp" or k == args.metric + } + for entry in system_metrics + if args.metric in entry + ] + if args.json: + print( + format_json( + { + "project": args.project, + "run": args.run, + "metric": args.metric, + "values": filtered_metrics, + } + ) + ) + else: + print(format_system_metrics(filtered_metrics)) + else: + if args.json: + print( + format_json( + { + "project": args.project, + "run": args.run, + "system_metrics": system_metrics, + } + ) + ) + else: + print(format_system_metrics(system_metrics)) + else: + db_path = SQLiteStorage.get_project_db_path(args.project) + if not db_path.exists(): + error_exit(f"Project '{args.project}' not found.") + runs = SQLiteStorage.get_runs(args.project) + if args.run not in runs: + error_exit( + f"Run '{args.run}' not found in project '{args.project}'." + ) + if args.metric: + system_metrics = SQLiteStorage.get_system_logs( + args.project, args.run + ) + all_system_metric_names = ( + SQLiteStorage.get_all_system_metrics_for_run( + args.project, args.run + ) + ) + if args.metric not in all_system_metric_names: + error_exit( + f"System metric '{args.metric}' not found in run '{args.run}' of project '{args.project}'." + ) + filtered_metrics = [ + { + k: v + for k, v in entry.items() + if k == "timestamp" or k == args.metric + } + for entry in system_metrics + if args.metric in entry + ] + if args.json: + print( + format_json( + { + "project": args.project, + "run": args.run, + "metric": args.metric, + "values": filtered_metrics, + } + ) + ) + else: + print(format_system_metrics(filtered_metrics)) + else: + system_metrics = SQLiteStorage.get_system_logs( + args.project, args.run + ) + if args.json: + print( + format_json( + { + "project": args.project, + "run": args.run, + "system_metrics": system_metrics, + } + ) + ) + else: + print(format_system_metrics(system_metrics)) + elif args.get_type == "alerts": + if remote: + alerts = remote.predict( + args.project, + args.run, + args.level, + args.since, + api_name="/get_alerts", + ) + else: + db_path = SQLiteStorage.get_project_db_path(args.project) + if not db_path.exists(): + error_exit(f"Project '{args.project}' not found.") + alerts = SQLiteStorage.get_alerts( + args.project, + run_name=args.run, + level=args.level, + since=args.since, + ) + if args.json: + print( + format_json( + { + "project": args.project, + "run": args.run, + "level": args.level, + "since": args.since, + "alerts": alerts, + } + ) + ) + else: + print(format_alerts(alerts)) + elif args.get_type == "report": + if remote: + logs = remote.predict(args.project, args.run, api_name="/get_logs") + else: + db_path = SQLiteStorage.get_project_db_path(args.project) + if not db_path.exists(): + error_exit(f"Project '{args.project}' not found.") + runs = SQLiteStorage.get_runs(args.project) + if args.run not in runs: + error_exit( + f"Run '{args.run}' not found in project '{args.project}'." + ) + logs = SQLiteStorage.get_logs(args.project, args.run) + + reports = _extract_reports(args.run, logs, report_name=args.report) + if not reports: + error_exit( + f"Report '{args.report}' not found in run '{args.run}' of project '{args.project}'." + ) + + if args.json: + print( + format_json( + { + "project": args.project, + "run": args.run, + "report": args.report, + "values": reports, + } + ) + ) + else: + output = [] + for idx, entry in enumerate(reports, start=1): + output.append( + f"Entry {idx} | step={entry['step']} | timestamp={entry['timestamp']}" + ) + output.append(entry["content"]) + if idx < len(reports): + output.append("-" * 80) + print("\n".join(output)) + elif args.command == "query": + if args.query_type == "project": + _handle_query(args) + elif args.command == "skills": + if args.skills_action == "add": + _handle_skills_add(args) + else: + parser.print_help() + + +def _handle_skills_add(args): + import shutil + from pathlib import Path + + CENTRAL_LOCAL = Path(".agents/skills") + CENTRAL_GLOBAL = Path("~/.agents/skills") + CLAUDE_LOCAL = Path(".claude/skills") + CLAUDE_GLOBAL = Path("~/.claude/skills") + + SKILL_ID = "trackio" + GITHUB_RAW = "https://raw.githubusercontent.com/gradio-app/trackio/main" + SKILL_PREFIX = ".agents/skills/trackio" + SKILL_FILES = [ + "SKILL.md", + "alerts.md", + "logging_metrics.md", + "retrieving_metrics.md", + "storage_schema.md", + ] + + if not (args.cursor or args.claude or args.codex or args.opencode or args.dest): + error_exit( + "Pick a destination via --cursor, --claude, --codex, --opencode, or --dest." + ) + + def download(url: str) -> str: + from huggingface_hub.utils import get_session + + try: + response = get_session().get(url) + response.raise_for_status() + except Exception as e: + error_exit( + f"Failed to download {url}\n{e}\n\n" + "Make sure you have internet access. The skill files are fetched from " + "the Trackio GitHub repository." + ) + return response.text + + def remove_existing(path: Path, force: bool): + if not (path.exists() or path.is_symlink()): + return + if not force: + error_exit( + f"Skill already exists at {path}.\nRe-run with --force to overwrite." + ) + if path.is_dir() and not path.is_symlink(): + shutil.rmtree(path) + else: + path.unlink() + + def install_to(skills_dir: Path, force: bool) -> Path: + skills_dir = skills_dir.expanduser().resolve() + skills_dir.mkdir(parents=True, exist_ok=True) + dest = skills_dir / SKILL_ID + remove_existing(dest, force) + dest.mkdir() + for fname in SKILL_FILES: + content = download(f"{GITHUB_RAW}/{SKILL_PREFIX}/{fname}") + (dest / fname).write_text(content, encoding="utf-8") + return dest + + def create_symlink( + agent_skills_dir: Path, central_skill_path: Path, force: bool + ) -> Path: + agent_skills_dir = agent_skills_dir.expanduser().resolve() + agent_skills_dir.mkdir(parents=True, exist_ok=True) + link_path = agent_skills_dir / SKILL_ID + remove_existing(link_path, force) + link_path.symlink_to(os.path.relpath(central_skill_path, agent_skills_dir)) + return link_path + + global_targets = { + "cursor": Path("~/.cursor/skills"), + "claude": CLAUDE_GLOBAL, + "codex": Path("~/.codex/skills"), + "opencode": Path("~/.opencode/skills"), + } + local_targets = { + "cursor": Path(".cursor/skills"), + "claude": CLAUDE_LOCAL, + "codex": Path(".codex/skills"), + "opencode": Path(".opencode/skills"), + } + targets_dict = global_targets if args.global_ else local_targets + + if args.dest: + if args.cursor or args.claude or args.codex or args.opencode or args.global_: + error_exit("--dest cannot be combined with agent flags or --global.") + skill_dest = install_to(Path(args.dest), args.force) + print(f"Installed '{SKILL_ID}' to {skill_dest}") + return + + agent_targets = [] + if args.cursor: + agent_targets.append(targets_dict["cursor"]) + if args.claude: + agent_targets.append(targets_dict["claude"]) + if args.codex: + agent_targets.append(targets_dict["codex"]) + if args.opencode: + agent_targets.append(targets_dict["opencode"]) + + central_path = CENTRAL_GLOBAL if args.global_ else CENTRAL_LOCAL + central_skill_path = install_to(central_path, args.force) + print(f"Installed '{SKILL_ID}' to central location: {central_skill_path}") + + for agent_target in agent_targets: + link_path = create_symlink(agent_target, central_skill_path, args.force) + print(f"Created symlink: {link_path}") + + +if __name__ == "__main__": + main() diff --git a/trackio/cli_helpers.py b/trackio/cli_helpers.py new file mode 100644 index 0000000000000000000000000000000000000000..13287d05a92a824a9a779142f56a74d445f25254 --- /dev/null +++ b/trackio/cli_helpers.py @@ -0,0 +1,204 @@ +import json +import sys +from typing import Any + + +def format_json(data: Any) -> str: + """Format data as JSON.""" + return json.dumps(data, indent=2) + + +def format_list(items: list[str], title: str | None = None) -> str: + """Format a list of items in human-readable format.""" + if not items: + return f"No {title.lower() if title else 'items'} found." + + output = [] + if title: + output.append(f"{title}:") + + for item in items: + output.append(f" - {item}") + + return "\n".join(output) + + +def format_project_summary(summary: dict) -> str: + """Format project summary in human-readable format.""" + output = [f"Project: {summary['project']}"] + output.append(f"Number of runs: {summary['num_runs']}") + + if summary["runs"]: + output.append("\nRuns:") + for run in summary["runs"]: + output.append(f" - {run}") + else: + output.append("\nNo runs found.") + + if summary.get("last_activity"): + output.append(f"\nLast activity (max step): {summary['last_activity']}") + + return "\n".join(output) + + +def format_run_summary(summary: dict) -> str: + """Format run summary in human-readable format.""" + output = [f"Project: {summary['project']}"] + output.append(f"Run: {summary['run']}") + output.append(f"Number of logs: {summary['num_logs']}") + + if summary.get("last_step") is not None: + output.append(f"Last step: {summary['last_step']}") + + if summary.get("metrics"): + output.append("\nMetrics:") + for metric in summary["metrics"]: + output.append(f" - {metric}") + else: + output.append("\nNo metrics found.") + + config = summary.get("config") + if config: + output.append("\nConfig:") + config_display = {k: v for k, v in config.items() if not k.startswith("_")} + if config_display: + for key, value in config_display.items(): + output.append(f" {key}: {value}") + else: + output.append(" (no config)") + else: + output.append("\nConfig: (no config)") + + return "\n".join(output) + + +def format_metric_values(values: list[dict]) -> str: + """Format metric values in human-readable format.""" + if not values: + return "No metric values found." + + output = [f"Found {len(values)} value(s):\n"] + output.append("Step | Timestamp | Value") + output.append("-" * 50) + + for value in values: + step = value.get("step", "N/A") + timestamp = value.get("timestamp", "N/A") + val = value.get("value", "N/A") + output.append(f"{step} | {timestamp} | {val}") + + return "\n".join(output) + + +def format_system_metrics(metrics: list[dict]) -> str: + """Format system metrics in human-readable format.""" + if not metrics: + return "No system metrics found." + + output = [f"Found {len(metrics)} system metric entry/entries:\n"] + + for i, entry in enumerate(metrics): + timestamp = entry.get("timestamp", "N/A") + output.append(f"\nEntry {i + 1} (Timestamp: {timestamp}):") + for key, value in entry.items(): + if key != "timestamp": + output.append(f" {key}: {value}") + + return "\n".join(output) + + +def format_system_metric_names(names: list[str]) -> str: + """Format system metric names in human-readable format.""" + return format_list(names, "System Metrics") + + +def format_snapshot(snapshot: dict[str, list[dict]]) -> str: + """Format a metrics snapshot in human-readable format.""" + if not snapshot: + return "No metrics found in the specified range." + + output = [] + for metric_name, values in sorted(snapshot.items()): + output.append(f"\n{metric_name}:") + output.append(" Step | Timestamp | Value") + output.append(" " + "-" * 48) + for v in values: + step = v.get("step", "N/A") + ts = v.get("timestamp", "N/A") + val = v.get("value", "N/A") + output.append(f" {step} | {ts} | {val}") + + return "\n".join(output) + + +def format_alerts(alerts: list[dict]) -> str: + """Format alerts in human-readable format.""" + if not alerts: + return "No alerts found." + + output = [f"Found {len(alerts)} alert(s):\n"] + output.append("Timestamp | Run | Level | Title | Text | Step") + output.append("-" * 80) + + for a in alerts: + ts = a.get("timestamp", "N/A") + run = a.get("run", "N/A") + level = a.get("level", "N/A").upper() + title = a.get("title", "") + text = a.get("text", "") or "" + step = a.get("step", "N/A") + output.append(f"{ts} | {run} | {level} | {title} | {text} | {step}") + + return "\n".join(output) + + +def format_query_result(result: dict[str, Any]) -> str: + """Format SQL query results in human-readable format.""" + columns = result.get("columns", []) + rows = result.get("rows", []) + row_count = result.get("row_count", 0) + + if not columns: + return f"Query returned {row_count} row(s)." + + rendered_rows = [] + for row in rows: + rendered_rows.append( + [ + "" if row.get(column) is None else str(row.get(column)) + for column in columns + ] + ) + + widths = [] + for idx, column in enumerate(columns): + cell_width = max( + (len(rendered_row[idx]) for rendered_row in rendered_rows), default=0 + ) + widths.append(max(len(column), cell_width)) + + header = " | ".join( + column.ljust(width) for column, width in zip(columns, widths, strict=False) + ) + separator = "-+-".join("-" * width for width in widths) + output = [f"Query returned {row_count} row(s).", header, separator] + + if not rendered_rows: + output.append("(no rows)") + return "\n".join(output) + + for rendered_row in rendered_rows: + output.append( + " | ".join( + value.ljust(width) + for value, width in zip(rendered_row, widths, strict=False) + ) + ) + + return "\n".join(output) + + +def error_exit(message: str, code: int = 1) -> None: + """Print error message and exit.""" + print(f"Error: {message}", file=sys.stderr) + sys.exit(code) diff --git a/trackio/commit_scheduler.py b/trackio/commit_scheduler.py new file mode 100644 index 0000000000000000000000000000000000000000..2e1cbabc2f9e576def2332cd4fbdc5788828ace6 --- /dev/null +++ b/trackio/commit_scheduler.py @@ -0,0 +1,310 @@ +# Originally copied from https://github.com/huggingface/huggingface_hub/blob/d0a948fc2a32ed6e557042a95ef3e4af97ec4a7c/src/huggingface_hub/_commit_scheduler.py + +import atexit +import logging +import time +from concurrent.futures import Future +from dataclasses import dataclass +from pathlib import Path +from threading import Lock, Thread +from typing import Callable, Dict, List, Union + +from huggingface_hub.hf_api import ( + DEFAULT_IGNORE_PATTERNS, + CommitInfo, + CommitOperationAdd, + HfApi, +) +from huggingface_hub.utils import filter_repo_objects + +logger = logging.getLogger(__name__) + + +@dataclass(frozen=True) +class _FileToUpload: + """Temporary dataclass to store info about files to upload. Not meant to be used directly.""" + + local_path: Path + path_in_repo: str + size_limit: int + last_modified: float + + +class CommitScheduler: + """ + Scheduler to upload a local folder to the Hub at regular intervals (e.g. push to hub every 5 minutes). + + The recommended way to use the scheduler is to use it as a context manager. This ensures that the scheduler is + properly stopped and the last commit is triggered when the script ends. The scheduler can also be stopped manually + with the `stop` method. Checkout the [upload guide](https://huggingface.co/docs/huggingface_hub/guides/upload#scheduled-uploads) + to learn more about how to use it. + + Args: + repo_id (`str`): + The id of the repo to commit to. + folder_path (`str` or `Path`): + Path to the local folder to upload regularly. + every (`int` or `float`, *optional*): + The number of minutes between each commit. Defaults to 5 minutes. + path_in_repo (`str`, *optional*): + Relative path of the directory in the repo, for example: `"checkpoints/"`. Defaults to the root folder + of the repository. + repo_type (`str`, *optional*): + The type of the repo to commit to. Defaults to `model`. + revision (`str`, *optional*): + The revision of the repo to commit to. Defaults to `main`. + private (`bool`, *optional*): + Whether to make the repo private. If `None` (default), the repo will be public unless the organization's default is private. This value is ignored if the repo already exists. + token (`str`, *optional*): + The token to use to commit to the repo. Defaults to the token saved on the machine. + allow_patterns (`List[str]` or `str`, *optional*): + If provided, only files matching at least one pattern are uploaded. + ignore_patterns (`List[str]` or `str`, *optional*): + If provided, files matching any of the patterns are not uploaded. + squash_history (`bool`, *optional*): + Whether to squash the history of the repo after each commit. Defaults to `False`. Squashing commits is + useful to avoid degraded performances on the repo when it grows too large. + hf_api (`HfApi`, *optional*): + The [`HfApi`] client to use to commit to the Hub. Can be set with custom settings (user agent, token,...). + on_before_commit (`Callable[[], None]`, *optional*): + If specified, a function that will be called before the CommitScheduler lists files to create a commit. + + Example: + ```py + >>> from pathlib import Path + >>> from huggingface_hub import CommitScheduler + + # Scheduler uploads every 10 minutes + >>> csv_path = Path("watched_folder/data.csv") + >>> CommitScheduler(repo_id="test_scheduler", repo_type="dataset", folder_path=csv_path.parent, every=10) + + >>> with csv_path.open("a") as f: + ... f.write("first line") + + # Some time later (...) + >>> with csv_path.open("a") as f: + ... f.write("second line") + ``` + + Example using a context manager: + ```py + >>> from pathlib import Path + >>> from huggingface_hub import CommitScheduler + + >>> with CommitScheduler(repo_id="test_scheduler", repo_type="dataset", folder_path="watched_folder", every=10) as scheduler: + ... csv_path = Path("watched_folder/data.csv") + ... with csv_path.open("a") as f: + ... f.write("first line") + ... (...) + ... with csv_path.open("a") as f: + ... f.write("second line") + + # Scheduler is now stopped and last commit have been triggered + ``` + """ + + def __init__( + self, + *, + repo_id: str, + folder_path: Union[str, Path], + every: Union[int, float] = 5, + path_in_repo: str | None = None, + repo_type: str | None = None, + revision: str | None = None, + private: bool | None = None, + token: str | None = None, + allow_patterns: list[str] | str | None = None, + ignore_patterns: list[str] | str | None = None, + squash_history: bool = False, + hf_api: HfApi | None = None, + on_before_commit: Callable[[], None] | None = None, + ) -> None: + self.api = hf_api or HfApi(token=token) + self.on_before_commit = on_before_commit + + # Folder + self.folder_path = Path(folder_path).expanduser().resolve() + self.path_in_repo = path_in_repo or "" + self.allow_patterns = allow_patterns + + if ignore_patterns is None: + ignore_patterns = [] + elif isinstance(ignore_patterns, str): + ignore_patterns = [ignore_patterns] + self.ignore_patterns = ignore_patterns + DEFAULT_IGNORE_PATTERNS + + if self.folder_path.is_file(): + raise ValueError( + f"'folder_path' must be a directory, not a file: '{self.folder_path}'." + ) + self.folder_path.mkdir(parents=True, exist_ok=True) + + # Repository + repo_url = self.api.create_repo( + repo_id=repo_id, private=private, repo_type=repo_type, exist_ok=True + ) + self.repo_id = repo_url.repo_id + self.repo_type = repo_type + self.revision = revision + self.token = token + + self.last_uploaded: Dict[Path, float] = {} + self.last_push_time: float | None = None + + if not every > 0: + raise ValueError(f"'every' must be a positive integer, not '{every}'.") + self.lock = Lock() + self.every = every + self.squash_history = squash_history + + logger.info( + f"Scheduled job to push '{self.folder_path}' to '{self.repo_id}' every {self.every} minutes." + ) + self._scheduler_thread = Thread(target=self._run_scheduler, daemon=True) + self._scheduler_thread.start() + atexit.register(self._push_to_hub) + + self.__stopped = False + + def stop(self) -> None: + """Stop the scheduler. + + A stopped scheduler cannot be restarted. Mostly for tests purposes. + """ + self.__stopped = True + + def __enter__(self) -> "CommitScheduler": + return self + + def __exit__(self, exc_type, exc_value, traceback) -> None: + # Upload last changes before exiting + self.trigger().result() + self.stop() + return + + def _run_scheduler(self) -> None: + """Dumb thread waiting between each scheduled push to Hub.""" + while True: + self.last_future = self.trigger() + time.sleep(self.every * 60) + if self.__stopped: + break + + def trigger(self) -> Future: + """Trigger a `push_to_hub` and return a future. + + This method is automatically called every `every` minutes. You can also call it manually to trigger a commit + immediately, without waiting for the next scheduled commit. + """ + return self.api.run_as_future(self._push_to_hub) + + def _push_to_hub(self) -> CommitInfo | None: + if self.__stopped: # If stopped, already scheduled commits are ignored + return None + + logger.info("(Background) scheduled commit triggered.") + try: + value = self.push_to_hub() + if self.squash_history: + logger.info("(Background) squashing repo history.") + self.api.super_squash_history( + repo_id=self.repo_id, repo_type=self.repo_type, branch=self.revision + ) + return value + except Exception as e: + logger.error( + f"Error while pushing to Hub: {e}" + ) # Depending on the setup, error might be silenced + raise + + def push_to_hub(self) -> CommitInfo | None: + """ + Push folder to the Hub and return the commit info. + + + + This method is not meant to be called directly. It is run in the background by the scheduler, respecting a + queue mechanism to avoid concurrent commits. Making a direct call to the method might lead to concurrency + issues. + + + + The default behavior of `push_to_hub` is to assume an append-only folder. It lists all files in the folder and + uploads only changed files. If no changes are found, the method returns without committing anything. If you want + to change this behavior, you can inherit from [`CommitScheduler`] and override this method. This can be useful + for example to compress data together in a single file before committing. For more details and examples, check + out our [integration guide](https://huggingface.co/docs/huggingface_hub/main/en/guides/upload#scheduled-uploads). + """ + # Check files to upload (with lock) + with self.lock: + if self.on_before_commit is not None: + self.on_before_commit() + + logger.debug("Listing files to upload for scheduled commit.") + + # List files from folder (taken from `_prepare_upload_folder_additions`) + relpath_to_abspath = { + path.relative_to(self.folder_path).as_posix(): path + for path in sorted( + self.folder_path.glob("**/*") + ) # sorted to be deterministic + if path.is_file() + } + prefix = f"{self.path_in_repo.strip('/')}/" if self.path_in_repo else "" + + # Filter with pattern + filter out unchanged files + retrieve current file size + files_to_upload: List[_FileToUpload] = [] + for relpath in filter_repo_objects( + relpath_to_abspath.keys(), + allow_patterns=self.allow_patterns, + ignore_patterns=self.ignore_patterns, + ): + local_path = relpath_to_abspath[relpath] + stat = local_path.stat() + if ( + self.last_uploaded.get(local_path) is None + or self.last_uploaded[local_path] != stat.st_mtime + ): + files_to_upload.append( + _FileToUpload( + local_path=local_path, + path_in_repo=prefix + relpath, + size_limit=stat.st_size, + last_modified=stat.st_mtime, + ) + ) + + # Return if nothing to upload + if len(files_to_upload) == 0: + logger.debug("Dropping schedule commit: no changed file to upload.") + return None + + # Convert `_FileToUpload` as `CommitOperationAdd` (=> compute file shas + limit to file size) + logger.debug("Removing unchanged files since previous scheduled commit.") + add_operations = [ + CommitOperationAdd( + # TODO: Cap the file to its current size, even if the user append data to it while a scheduled commit is happening + # (requires an upstream fix for XET-535: `hf_xet` should support `BinaryIO` for upload) + path_or_fileobj=file_to_upload.local_path, + path_in_repo=file_to_upload.path_in_repo, + ) + for file_to_upload in files_to_upload + ] + + # Upload files (append mode expected - no need for lock) + logger.debug("Uploading files for scheduled commit.") + commit_info = self.api.create_commit( + repo_id=self.repo_id, + repo_type=self.repo_type, + operations=add_operations, + commit_message="Scheduled Commit", + revision=self.revision, + ) + + for file in files_to_upload: + self.last_uploaded[file.local_path] = file.last_modified + + self.last_push_time = time.time() + + return commit_info diff --git a/trackio/context_vars.py b/trackio/context_vars.py new file mode 100644 index 0000000000000000000000000000000000000000..ef1404001b8856446ec2940eee81578d634a51fd --- /dev/null +++ b/trackio/context_vars.py @@ -0,0 +1,21 @@ +import contextvars +from typing import TYPE_CHECKING + +if TYPE_CHECKING: + from trackio.run import Run + +current_run: contextvars.ContextVar["Run | None"] = contextvars.ContextVar( + "current_run", default=None +) +current_project: contextvars.ContextVar[str | None] = contextvars.ContextVar( + "current_project", default=None +) +current_server: contextvars.ContextVar[str | None] = contextvars.ContextVar( + "current_server", default=None +) +current_space_id: contextvars.ContextVar[str | None] = contextvars.ContextVar( + "current_space_id", default=None +) +current_server_write_token: contextvars.ContextVar[str | None] = contextvars.ContextVar( + "current_server_write_token", default=None +) diff --git a/trackio/cpu.py b/trackio/cpu.py new file mode 100644 index 0000000000000000000000000000000000000000..ec7c989763ced081c5712f5cb20e826d272b86a5 --- /dev/null +++ b/trackio/cpu.py @@ -0,0 +1,294 @@ +import threading +import time +import warnings +from typing import TYPE_CHECKING, Any + +if TYPE_CHECKING: + from trackio.run import Run + +psutil: Any = None +PSUTIL_AVAILABLE = False +_psutil_lock = threading.Lock() + + +def _ensure_psutil(): + global PSUTIL_AVAILABLE, psutil + if PSUTIL_AVAILABLE: + return psutil + with _psutil_lock: + if PSUTIL_AVAILABLE: + return psutil + try: + import psutil as _psutil + + psutil = _psutil + PSUTIL_AVAILABLE = True + return psutil + except ImportError: + raise ImportError( + "psutil is required for CPU and RAM monitoring. " + "Install it with: pip install psutil" + ) + + +def cpu_available() -> bool: + """ + Check if CPU and RAM monitoring is available. + + Returns True if psutil is installed. + """ + try: + _ensure_psutil() + return True + except ImportError: + return False + except Exception: + return False + + +def collect_cpu_metrics( + prev_disk_counters: Any = None, + prev_net_counters: Any = None, + elapsed: float | None = None, + include_static: bool = True, +) -> dict: + """ + Collect CPU, RAM, disk, network, and sensor metrics using psutil. + + Args: + prev_disk_counters: Previous disk I/O counters for computing read/write rates. + If None, only cumulative values are reported. + prev_net_counters: Previous network I/O counters for computing send/recv rates. + If None, only cumulative values are reported. + elapsed: Seconds since prev_disk_counters and prev_net_counters were captured. + If None or non-positive, cumulative values are reported instead of rates. + include_static: Whether to include mostly static metrics such as CPU + frequency and core counts. + + Returns: + Dictionary of system metrics. + """ + if not PSUTIL_AVAILABLE: + try: + _ensure_psutil() + except ImportError: + return {} + + metrics = {} + + try: + per_core = psutil.cpu_percent(interval=0.1, percpu=True) + for i, pct in enumerate(per_core): + metrics[f"cpu/{i}/utilization"] = pct + if per_core: + metrics["cpu/utilization"] = sum(per_core) / len(per_core) + except Exception: + pass + + if include_static: + try: + cpu_freq = psutil.cpu_freq() + if cpu_freq: + metrics["cpu/frequency"] = cpu_freq.current + if cpu_freq.max > 0: + metrics["cpu/frequency_max"] = cpu_freq.max + except Exception: + pass + + try: + cpu_count_logical = psutil.cpu_count(logical=True) + if cpu_count_logical is not None: + metrics["cpu/count_logical"] = cpu_count_logical + cpu_count_physical = psutil.cpu_count(logical=False) + if cpu_count_physical is not None: + metrics["cpu/count_physical"] = cpu_count_physical + except Exception: + pass + + try: + mem = psutil.virtual_memory() + metrics["memory/used"] = mem.used / (1024**3) + metrics["memory/total"] = mem.total / (1024**3) + metrics["memory/available"] = mem.available / (1024**3) + metrics["memory/percent"] = mem.percent + except Exception: + pass + + try: + swap = psutil.swap_memory() + metrics["swap/used"] = swap.used / (1024**3) + metrics["swap/total"] = swap.total / (1024**3) + metrics["swap/percent"] = swap.percent + except Exception: + pass + + try: + disk = psutil.disk_io_counters() + if disk is not None: + if prev_disk_counters is not None and elapsed and elapsed > 0: + metrics["disk/read_mb_per_sec"] = ( + (disk.read_bytes - prev_disk_counters.read_bytes) + / elapsed + / (1024**2) + ) + metrics["disk/write_mb_per_sec"] = ( + (disk.write_bytes - prev_disk_counters.write_bytes) + / elapsed + / (1024**2) + ) + metrics["disk/read_iops"] = ( + disk.read_count - prev_disk_counters.read_count + ) / elapsed + metrics["disk/write_iops"] = ( + disk.write_count - prev_disk_counters.write_count + ) / elapsed + else: + metrics["disk/read_bytes"] = disk.read_bytes / (1024**3) + metrics["disk/write_bytes"] = disk.write_bytes / (1024**3) + except Exception: + pass + + try: + net = psutil.net_io_counters() + if net is not None: + if prev_net_counters is not None and elapsed and elapsed > 0: + metrics["network/sent_mb_per_sec"] = ( + (net.bytes_sent - prev_net_counters.bytes_sent) + / elapsed + / (1024**2) + ) + metrics["network/recv_mb_per_sec"] = ( + (net.bytes_recv - prev_net_counters.bytes_recv) + / elapsed + / (1024**2) + ) + else: + metrics["network/sent_bytes"] = net.bytes_sent / (1024**3) + metrics["network/recv_bytes"] = net.bytes_recv / (1024**3) + except Exception: + pass + + try: + sensors = psutil.sensors_temperatures() + if sensors: + for chip_name, entries in sensors.items(): + for i, entry in enumerate(entries): + label = ( + entry.label.strip() + if entry.label and entry.label.strip() + else f"{chip_name}_{i}" + ) + metrics[f"temp/{label}"] = entry.current + except Exception: + pass + + try: + battery = psutil.sensors_battery() + if battery is not None: + metrics["battery/percent"] = battery.percent + metrics["battery/power_plugged"] = int(battery.power_plugged) + except Exception: + pass + + return metrics + + +class CpuMonitor: + def __init__(self, run: "Run", interval: float = 10.0): + self._run = run + self._interval = interval + self._stop_flag = threading.Event() + self._thread: "threading.Thread | None" = None + self._last_disk_counters: Any = None + self._last_net_counters: Any = None + self._last_time: float | None = None + + def start(self): + if not PSUTIL_AVAILABLE: + try: + _ensure_psutil() + except ImportError: + warnings.warn( + "auto_log_cpu=True but psutil is not installed. " + "CPU and RAM logging disabled. Install with: pip install psutil" + ) + return + + self._thread = threading.Thread(target=self._monitor_loop, daemon=True) + self._thread.start() + + def stop(self): + self._stop_flag.set() + if self._thread is not None: + self._thread.join(timeout=2.0) + + def _monitor_loop(self): + try: + self._last_disk_counters = psutil.disk_io_counters() + except Exception: + pass + try: + self._last_net_counters = psutil.net_io_counters() + except Exception: + pass + self._last_time = time.monotonic() + + while not self._stop_flag.is_set(): + self._stop_flag.wait(timeout=self._interval) + if self._stop_flag.is_set(): + break + try: + now = time.monotonic() + elapsed = now - self._last_time if self._last_time is not None else None + metrics = collect_cpu_metrics( + prev_disk_counters=self._last_disk_counters, + prev_net_counters=self._last_net_counters, + elapsed=elapsed, + include_static=False, + ) + try: + self._last_disk_counters = psutil.disk_io_counters() + except Exception: + self._last_disk_counters = None + try: + self._last_net_counters = psutil.net_io_counters() + except Exception: + self._last_net_counters = None + self._last_time = now + if metrics: + self._run.log_system(metrics) + except Exception: + pass + + +def log_cpu(run: "Run | None" = None) -> dict: + """ + Log CPU, RAM, disk, network, and sensor metrics to the current or specified run + as system metrics. + + Args: + run: Optional Run instance. If None, uses current run from context. + + Returns: + dict: The system metrics that were logged. + + Example: + ```python + import trackio + + run = trackio.init(project="my-project") + trackio.log({"loss": 0.5}) + trackio.log_cpu() + ``` + """ + from trackio import context_vars + + if run is None: + run = context_vars.current_run.get() + if run is None: + raise RuntimeError("Call trackio.init() before trackio.log_cpu().") + + metrics = collect_cpu_metrics() + if metrics: + run.log_system(metrics) + return metrics diff --git a/trackio/deploy.py b/trackio/deploy.py new file mode 100644 index 0000000000000000000000000000000000000000..6b29983acb493d6b0184d85fb671e9b744c85028 --- /dev/null +++ b/trackio/deploy.py @@ -0,0 +1,1252 @@ +import importlib.metadata +import io +import json as json_mod +import os +import shutil +import sys +import tempfile +import threading +import time +import warnings +from collections import Counter +from importlib.resources import files +from pathlib import Path + +if sys.version_info >= (3, 11): + import tomllib +else: + import tomli as tomllib + +import httpx +import huggingface_hub +from gradio_client import handle_file +from httpx import ReadTimeout +from huggingface_hub import Volume +from huggingface_hub.errors import ( + BucketNotFoundError, + HfHubHTTPError, + RepositoryNotFoundError, +) + +import trackio +from trackio.bucket_storage import ( + create_bucket_if_not_exists, + export_from_bucket_for_static, + upload_project_to_bucket, + upload_project_to_bucket_for_static, +) +from trackio.frontend_config import resolve_frontend_dir +from trackio.remote_client import RemoteClient +from trackio.sqlite_storage import SQLiteStorage +from trackio.utils import ( + MEDIA_DIR, + get_or_create_project_hash, + on_spaces, + preprocess_space_and_dataset_ids, +) + +SPACE_HOST_URL = "https://{user_name}-{space_name}.hf.space/" +SPACE_URL = "https://huggingface.co/spaces/{space_id}" +_BOLD_ORANGE = "\033[1m\033[38;5;208m" +_RESET = "\033[0m" + + +def raise_if_space_is_frozen_for_logging(space_id: str) -> None: + try: + info = huggingface_hub.HfApi().space_info(space_id) + except RepositoryNotFoundError: + return + if getattr(info, "sdk", None) == "static": + raise RuntimeError( + f"Cannot log to Hugging Face Space '{space_id}' because it has been frozen " + f"(it uses the static SDK: a read-only dashboard with no live Trackio server).\n\n" + f"Use a different space_id for training, or create a new Gradio Trackio Space. " + f"Freezing converts a live Gradio Space to static after a run; a frozen Space " + f'cannot accept new logs. See trackio.sync(..., sdk="static") in the Trackio docs.' + ) + + +def _readme_linked_hub_yaml(dataset_id: str | None) -> str: + if dataset_id is not None: + return f"datasets:\n - {dataset_id}\n" + return "" + + +_CUSTOM_SPACE_FRONTEND_DIR = "trackio_custom_frontend" + + +def _space_app_py(frontend_dir: str | None = None) -> str: + if frontend_dir is None: + return "import trackio\ntrackio.show()\n" + return f'import trackio\ntrackio.show(frontend_dir="{frontend_dir}")\n' + + +def _upload_frontend_folder( + hf_api: huggingface_hub.HfApi, + *, + repo_id: str, + repo_type: str, + folder_path: str | Path, + path_in_repo: str | None = None, +) -> None: + kwargs = { + "repo_id": repo_id, + "repo_type": repo_type, + "folder_path": str(folder_path), + } + if path_in_repo is not None: + kwargs["path_in_repo"] = path_in_repo + hf_api.upload_folder(**kwargs) + + +def _retry_hf_write(op_name: str, fn, retries: int = 4, initial_delay: float = 1.5): + delay = initial_delay + for attempt in range(1, retries + 1): + try: + return fn() + except ReadTimeout: + if attempt == retries: + raise + print( + f"* {op_name} timed out (attempt {attempt}/{retries}). Retrying in {delay:.1f}s..." + ) + time.sleep(delay) + delay = min(delay * 2, 12) + except HfHubHTTPError as e: + status = e.response.status_code if e.response is not None else None + if status is None or status < 500 or attempt == retries: + raise + print( + f"* {op_name} failed with HTTP {status} (attempt {attempt}/{retries}). Retrying in {delay:.1f}s..." + ) + time.sleep(delay) + delay = min(delay * 2, 12) + + +def _get_space_volumes( + space_id: str, hf_api: huggingface_hub.HfApi | None = None +) -> list[Volume]: + """ + Return mounted volumes for a Space. + + `HfApi.get_space_runtime()` does not always populate `volumes`, even when the + mount exists. Fall back to `space_info().runtime.volumes`, which currently + carries the volume metadata for running Spaces. + """ + hf_api = hf_api or huggingface_hub.HfApi() + runtime = hf_api.get_space_runtime(space_id) + if runtime.volumes: + return list(runtime.volumes) + + info = hf_api.space_info(space_id) + if info.runtime and info.runtime.volumes: + return list(info.runtime.volumes) + + return [] + + +def _get_space_bucket_at_data_mount( + space_id: str, hf_api: huggingface_hub.HfApi | None = None +) -> str | None: + for volume in _get_space_volumes(space_id, hf_api=hf_api): + if volume.type == "bucket" and volume.mount_path == "/data": + return volume.source + return None + + +def _get_existing_space_bucket( + space_id: str, hf_api: huggingface_hub.HfApi | None = None +) -> str | None: + """Return the Trackio bucket for a Space, preferring the canonical /data mount.""" + bucket_at_data = _get_space_bucket_at_data_mount(space_id, hf_api=hf_api) + if bucket_at_data is not None: + return bucket_at_data + + for volume in _get_space_volumes(space_id, hf_api=hf_api): + if volume.type == "bucket": + return volume.source + return None + + +def _get_existing_static_space_bucket( + space_id: str, hf_api: huggingface_hub.HfApi | None = None +) -> str | None: + hf_api = hf_api or huggingface_hub.HfApi() + try: + config_path = hf_api.hf_hub_download( + repo_id=space_id, + repo_type="space", + filename="config.json", + ) + except (FileNotFoundError, HfHubHTTPError, OSError, ValueError): + return None + + try: + with open(config_path, encoding="utf-8") as config_file: + config = json_mod.load(config_file) + except (OSError, ValueError, TypeError): + return None + + bucket_id = config.get("bucket_id") + if isinstance(bucket_id, str) and bucket_id: + return bucket_id + return None + + +def _ensure_bucket_mounted_at_data( + space_id: str, + bucket_id: str, + hf_api: huggingface_hub.HfApi | None = None, +) -> None: + hf_api = hf_api or huggingface_hub.HfApi() + existing = _get_space_volumes(space_id, hf_api=hf_api) + already_mounted = any( + v.type == "bucket" and v.source == bucket_id and v.mount_path == "/data" + for v in existing + ) + if not already_mounted: + preserved = [ + v + for v in existing + if not ( + v.type == "bucket" + and (v.source == bucket_id or v.mount_path == "/data") + ) + ] + hf_api.set_space_volumes( + space_id, + preserved + [Volume(type="bucket", source=bucket_id, mount_path="/data")], + ) + print(f"* Attached bucket {bucket_id} at '/data'") + + existing_variables = hf_api.get_space_variables(space_id) + current_trackio_dir = getattr(existing_variables.get("TRACKIO_DIR"), "value", None) + if current_trackio_dir != "/data/trackio": + huggingface_hub.add_space_variable(space_id, "TRACKIO_DIR", "/data/trackio") + current_bucket_id = getattr( + existing_variables.get("TRACKIO_BUCKET_ID"), "value", None + ) + if current_bucket_id != bucket_id: + huggingface_hub.add_space_variable(space_id, "TRACKIO_BUCKET_ID", bucket_id) + + +def _bucket_exists(bucket_id: str, hf_api: huggingface_hub.HfApi | None = None) -> bool: + hf_api = hf_api or huggingface_hub.HfApi() + try: + hf_api.bucket_info(bucket_id) + return True + except BucketNotFoundError: + return False + + +def _find_available_bucket_id( + preferred_bucket_id: str, hf_api: huggingface_hub.HfApi | None = None +) -> str: + hf_api = hf_api or huggingface_hub.HfApi() + if not _bucket_exists(preferred_bucket_id, hf_api): + return preferred_bucket_id + + suffix = 2 + while True: + candidate = f"{preferred_bucket_id}-{suffix}" + if not _bucket_exists(candidate, hf_api): + return candidate + suffix += 1 + + +def resolve_auto_bucket_id( + space_id: str, + preferred_bucket_id: str, + hf_api: huggingface_hub.HfApi | None = None, +) -> str: + """ + Resolve the bucket to use for an auto-generated bucket ID. + + Rules: + - Existing Space with a bucket mounted at /data -> reuse that bucket. + - Existing static Space with a bucket_id in config.json -> reuse that bucket. + - Otherwise -> use the preferred auto bucket ID if free, or a suffixed variant. + """ + hf_api = hf_api or huggingface_hub.HfApi() + try: + info = hf_api.space_info(space_id) + except RepositoryNotFoundError: + pass + else: + existing_bucket_id = _get_existing_space_bucket(space_id, hf_api=hf_api) + if existing_bucket_id is None and getattr(info, "sdk", None) == "static": + existing_bucket_id = _get_existing_static_space_bucket( + space_id, hf_api=hf_api + ) + if existing_bucket_id is not None: + return existing_bucket_id + + bucket_id = _find_available_bucket_id(preferred_bucket_id, hf_api) + if bucket_id != preferred_bucket_id: + print( + f"* Auto-generated bucket {preferred_bucket_id} already exists; " + f"using {bucket_id} instead" + ) + return bucket_id + + +def _get_source_install_dependencies() -> str: + """Get trackio dependencies from pyproject.toml for source installs.""" + trackio_path = files("trackio") + pyproject_path = Path(trackio_path).parent / "pyproject.toml" + with open(pyproject_path, "rb") as f: + pyproject = tomllib.load(f) + deps = pyproject["project"]["dependencies"] + spaces_deps = ( + pyproject["project"].get("optional-dependencies", {}).get("spaces", []) + ) + mcp_deps = pyproject["project"].get("optional-dependencies", {}).get("mcp", []) + return "\n".join(deps + spaces_deps + mcp_deps) + + +def _get_space_install_requirement() -> str: + return f"trackio[spaces,mcp]=={trackio.__version__}" + + +def _is_trackio_installed_from_source() -> bool: + """Check if trackio is installed from source/editable install vs PyPI.""" + try: + trackio_file = trackio.__file__ + if "site-packages" not in trackio_file and "dist-packages" not in trackio_file: + return True + + dist = importlib.metadata.distribution("trackio") + if dist.files: + files = list(dist.files) + has_pth = any(".pth" in str(f) for f in files) + if has_pth: + return True + + return False + except ( + AttributeError, + importlib.metadata.PackageNotFoundError, + importlib.metadata.MetadataError, + ValueError, + TypeError, + ): + return True + + +def deploy_as_space( + space_id: str, + space_storage: huggingface_hub.SpaceStorage | None = None, + dataset_id: str | None = None, + bucket_id: str | None = None, + private: bool | None = None, + frontend_dir: str | Path | None = None, +): + if on_spaces(): # in case a repo with this function is uploaded to spaces + return + + if dataset_id is not None and bucket_id is not None: + raise ValueError( + "Cannot use bucket volume options together with dataset_id; use one persistence mode." + ) + + trackio_path = files("trackio") + + hf_api = huggingface_hub.HfApi() + + try: + huggingface_hub.create_repo( + space_id, + private=private, + space_sdk="gradio", + space_storage=space_storage, + repo_type="space", + exist_ok=True, + ) + except HfHubHTTPError as e: + if e.response.status_code in [401, 403]: # unauthorized or forbidden + print("Need 'write' access token to create a Spaces repo.") + huggingface_hub.login(add_to_git_credential=False) + huggingface_hub.create_repo( + space_id, + private=private, + space_sdk="gradio", + space_storage=space_storage, + repo_type="space", + exist_ok=True, + ) + else: + raise ValueError(f"Failed to create Space: {e}") + + # We can assume huggingface-hub is available; requirements.txt pins trackio. + # Make sure necessary dependencies are installed by creating a requirements.txt. + is_source_install = _is_trackio_installed_from_source() + resolved_frontend = resolve_frontend_dir(frontend_dir, announce=True) + + if bucket_id is not None: + create_bucket_if_not_exists(bucket_id, private=private) + + with open(Path(trackio_path, "README.md"), "r", encoding="utf-8") as f: + readme_content = f.read() + readme_content = readme_content.replace("sdk_version: {GRADIO_VERSION}\n", "") + readme_content = readme_content.replace("{APP_FILE}", "app.py") + readme_content = readme_content.replace( + "{LINKED_HUB_METADATA}", _readme_linked_hub_yaml(dataset_id) + ) + readme_buffer = io.BytesIO(readme_content.encode("utf-8")) + hf_api.upload_file( + path_or_fileobj=readme_buffer, + path_in_repo="README.md", + repo_id=space_id, + repo_type="space", + ) + + if is_source_install: + requirements_content = _get_source_install_dependencies() + else: + requirements_content = _get_space_install_requirement() + + requirements_buffer = io.BytesIO(requirements_content.encode("utf-8")) + hf_api.upload_file( + path_or_fileobj=requirements_buffer, + path_in_repo="requirements.txt", + repo_id=space_id, + repo_type="space", + ) + + huggingface_hub.utils.disable_progress_bars() + + if is_source_install: + dist_index = ( + Path(trackio.__file__).resolve().parent / "frontend" / "dist" / "index.html" + ) + if not dist_index.is_file() and not resolved_frontend.is_custom: + raise ValueError( + "The Trackio frontend build is missing. From the repository root run " + "`cd trackio/frontend && npm ci && npm run build`, then deploy again." + ) + hf_api.upload_folder( + repo_id=space_id, + repo_type="space", + folder_path=trackio_path, + path_in_repo="trackio", + ignore_patterns=[ + "README.md", + "frontend/node_modules/**", + "frontend/src/**", + "frontend/.gitignore", + "frontend/package.json", + "frontend/package-lock.json", + "frontend/vite.config.js", + "frontend/svelte.config.js", + "**/__pycache__/**", + "*.pyc", + ], + ) + + if resolved_frontend.is_custom: + _upload_frontend_folder( + hf_api, + repo_id=space_id, + repo_type="space", + folder_path=resolved_frontend.path, + path_in_repo=_CUSTOM_SPACE_FRONTEND_DIR, + ) + + app_file_content = _space_app_py( + _CUSTOM_SPACE_FRONTEND_DIR if resolved_frontend.is_custom else None + ) + app_file_buffer = io.BytesIO(app_file_content.encode("utf-8")) + hf_api.upload_file( + path_or_fileobj=app_file_buffer, + path_in_repo="app.py", + repo_id=space_id, + repo_type="space", + ) + + if hf_token := huggingface_hub.utils.get_token(): + huggingface_hub.add_space_secret(space_id, "HF_TOKEN", hf_token) + if bucket_id is not None: + _ensure_bucket_mounted_at_data(space_id, bucket_id, hf_api) + elif dataset_id is not None: + huggingface_hub.add_space_variable(space_id, "TRACKIO_DATASET_ID", dataset_id) + if logo_light_url := os.environ.get("TRACKIO_LOGO_LIGHT_URL"): + huggingface_hub.add_space_variable( + space_id, "TRACKIO_LOGO_LIGHT_URL", logo_light_url + ) + if logo_dark_url := os.environ.get("TRACKIO_LOGO_DARK_URL"): + huggingface_hub.add_space_variable( + space_id, "TRACKIO_LOGO_DARK_URL", logo_dark_url + ) + if plot_order := os.environ.get("TRACKIO_PLOT_ORDER"): + huggingface_hub.add_space_variable(space_id, "TRACKIO_PLOT_ORDER", plot_order) + if theme := os.environ.get("TRACKIO_THEME"): + huggingface_hub.add_space_variable(space_id, "TRACKIO_THEME", theme) + huggingface_hub.add_space_variable(space_id, "GRADIO_MCP_SERVER", "True") + + +def create_space_if_not_exists( + space_id: str, + space_storage: huggingface_hub.SpaceStorage | None = None, + dataset_id: str | None = None, + bucket_id: str | None = None, + private: bool | None = None, + frontend_dir: str | Path | None = None, +) -> None: + """ + Creates a new Hugging Face Space if it does not exist. + + Args: + space_id (`str`): + The ID of the Space to create. + space_storage ([`~huggingface_hub.SpaceStorage`], *optional*): + Choice of persistent storage tier for the Space. + dataset_id (`str`, *optional*): + Deprecated. Use `bucket_id` instead. + bucket_id (`str`, *optional*): + Full Hub bucket id (`namespace/name`) to attach via the Hub volumes API (platform mount). + Sets `TRACKIO_DIR` to the mount path. + private (`bool`, *optional*): + Whether to make the Space private. If `None` (default), the repo will be + public unless the organization's default is private. This value is ignored + if the repo already exists. + """ + if "/" not in space_id: + raise ValueError( + f"Invalid space ID: {space_id}. Must be in the format: username/reponame or orgname/reponame." + ) + if dataset_id is not None and "/" not in dataset_id: + raise ValueError( + f"Invalid dataset ID: {dataset_id}. Must be in the format: username/datasetname or orgname/datasetname." + ) + if bucket_id is not None and "/" not in bucket_id: + raise ValueError( + f"Invalid bucket ID: {bucket_id}. Must be in the format: username/bucketname or orgname/bucketname." + ) + try: + huggingface_hub.repo_info(space_id, repo_type="space") + print( + f"* Found existing space: {_BOLD_ORANGE}{SPACE_URL.format(space_id=space_id)}{_RESET}" + ) + if bucket_id is not None: + create_bucket_if_not_exists(bucket_id, private=private) + _ensure_bucket_mounted_at_data(space_id, bucket_id) + elif dataset_id is not None: + huggingface_hub.add_space_variable( + space_id, "TRACKIO_DATASET_ID", dataset_id + ) + resolved_frontend = resolve_frontend_dir(frontend_dir, announce=False) + if resolved_frontend.is_custom: + deploy_as_space( + space_id, + space_storage, + dataset_id, + bucket_id, + private, + frontend_dir=frontend_dir, + ) + return + except RepositoryNotFoundError: + pass + except HfHubHTTPError as e: + if e.response.status_code in [401, 403]: # unauthorized or forbidden + print("Need 'write' access token to create a Spaces repo.") + huggingface_hub.login(add_to_git_credential=False) + else: + raise ValueError(f"Failed to create Space: {e}") + + print( + f"* Creating new space: {_BOLD_ORANGE}{SPACE_URL.format(space_id=space_id)}{_RESET}" + ) + deploy_as_space( + space_id, + space_storage, + dataset_id, + bucket_id, + private, + frontend_dir=frontend_dir, + ) + print("* Waiting for Space to be ready...") + _wait_until_space_running(space_id) + + +def _wait_until_space_running(space_id: str, timeout: int = 300) -> None: + hf_api = huggingface_hub.HfApi() + start = time.time() + delay = 2 + request_timeout = 45.0 + failure_stages = frozenset( + ("NO_APP_FILE", "CONFIG_ERROR", "BUILD_ERROR", "RUNTIME_ERROR") + ) + while time.time() - start < timeout: + try: + info = hf_api.space_info(space_id, timeout=request_timeout) + if info.runtime: + stage = str(info.runtime.stage) + if stage in failure_stages: + raise RuntimeError( + f"Space {space_id} entered terminal stage {stage}. " + "Fix README.md or app files; see build logs on the Hub." + ) + if stage == "RUNNING": + return + except RuntimeError: + raise + except (huggingface_hub.utils.HfHubHTTPError, httpx.RequestError): + pass + time.sleep(delay) + delay = min(delay * 1.5, 15) + raise TimeoutError( + f"Space {space_id} did not reach RUNNING within {timeout}s. " + "Check status and build logs on the Hub." + ) + + +def wait_until_space_exists( + space_id: str, +) -> None: + """ + Blocks the current thread until the Space exists. + + Args: + space_id (`str`): + The ID of the Space to wait for. + + Raises: + `TimeoutError`: If waiting for the Space takes longer than expected. + """ + hf_api = huggingface_hub.HfApi() + delay = 1 + for _ in range(30): + try: + hf_api.space_info(space_id) + return + except (huggingface_hub.utils.HfHubHTTPError, httpx.RequestError): + time.sleep(delay) + delay = min(delay * 2, 60) + raise TimeoutError("Waiting for space to exist took longer than expected") + + +def upload_db_to_space(project: str, space_id: str, force: bool = False) -> None: + """ + Uploads the database of a local Trackio project to a Hugging Face Space. + + This uses the Trackio remote client so newer Trackio Spaces can speak the direct + HTTP API while older Gradio-based Spaces still work through `gradio_client`. + + Args: + project (`str`): + The name of the project to upload. + space_id (`str`): + The ID of the Space to upload to. + force (`bool`, *optional*, defaults to `False`): + If `True`, overwrites the existing database without prompting. If `False`, + prompts for confirmation. + """ + db_path = SQLiteStorage.get_project_db_path(project) + client = RemoteClient( + space_id, + hf_token=huggingface_hub.utils.get_token(), + httpx_kwargs={"timeout": 90}, + ) + + if not force: + try: + existing_projects = client.predict(api_name="/get_all_projects") + if project in existing_projects: + response = input( + f"Database for project '{project}' already exists on Space '{space_id}'. " + f"Overwrite it? (y/N): " + ) + if response.lower() not in ["y", "yes"]: + print("* Upload cancelled.") + return + except Exception as e: + print(f"* Warning: Could not check if project exists on Space: {e}") + print("* Proceeding with upload...") + + client.predict( + api_name="/upload_db_to_space", + project=project, + uploaded_db=handle_file(db_path), + hf_token=huggingface_hub.utils.get_token(), + ) + + +SYNC_BATCH_SIZE = 500 + + +def sync_incremental( + project: str, + space_id: str, + private: bool | None = None, + pending_only: bool = False, + frontend_dir: str | Path | None = None, +) -> None: + """ + Syncs a local Trackio project to a Space via the bulk_log API endpoints + instead of uploading the entire DB file. Supports incremental sync. + + Args: + project: The name of the project to sync. + space_id: The HF Space ID to sync to. + private: Whether to make the Space private if creating. + pending_only: If True, only sync rows tagged with space_id (pending data). + """ + print( + f"* Syncing project '{project}' to: {SPACE_URL.format(space_id=space_id)} (please wait...)" + ) + create_space_if_not_exists(space_id, private=private, frontend_dir=frontend_dir) + wait_until_space_exists(space_id) + hf_token = huggingface_hub.utils.get_token() + expected_run_counts: Counter[str] = Counter() + + client = RemoteClient( + space_id, + hf_token=hf_token, + httpx_kwargs={"timeout": 90}, + ) + + if pending_only: + pending_logs = SQLiteStorage.get_pending_logs(project) + if pending_logs: + logs = pending_logs["logs"] + expected_run_counts.update(log["run"] for log in logs) + for i in range(0, len(logs), SYNC_BATCH_SIZE): + batch = logs[i : i + SYNC_BATCH_SIZE] + print( + f" Syncing metrics: {min(i + SYNC_BATCH_SIZE, len(logs))}/{len(logs)}..." + ) + client.predict(api_name="/bulk_log", logs=batch, hf_token=hf_token) + SQLiteStorage.clear_pending_logs(project, pending_logs["ids"]) + + pending_sys = SQLiteStorage.get_pending_system_logs(project) + if pending_sys: + logs = pending_sys["logs"] + for i in range(0, len(logs), SYNC_BATCH_SIZE): + batch = logs[i : i + SYNC_BATCH_SIZE] + print( + f" Syncing system metrics: {min(i + SYNC_BATCH_SIZE, len(logs))}/{len(logs)}..." + ) + client.predict( + api_name="/bulk_log_system", logs=batch, hf_token=hf_token + ) + SQLiteStorage.clear_pending_system_logs(project, pending_sys["ids"]) + + pending_uploads = SQLiteStorage.get_pending_uploads(project) + if pending_uploads: + upload_entries = [] + for u in pending_uploads["uploads"]: + fp = u["file_path"] + if os.path.exists(fp): + upload_entries.append( + { + "project": u["project"], + "run": u["run"], + "step": u["step"], + "relative_path": u["relative_path"], + "uploaded_file": handle_file(fp), + } + ) + if upload_entries: + print(f" Syncing {len(upload_entries)} media files...") + client.predict( + api_name="/bulk_upload_media", + uploads=upload_entries, + hf_token=hf_token, + ) + SQLiteStorage.clear_pending_uploads(project, pending_uploads["ids"]) + else: + all_logs = SQLiteStorage.get_all_logs_for_sync(project) + if all_logs: + expected_run_counts.update(log["run"] for log in all_logs) + for i in range(0, len(all_logs), SYNC_BATCH_SIZE): + batch = all_logs[i : i + SYNC_BATCH_SIZE] + print( + f" Syncing metrics: {min(i + SYNC_BATCH_SIZE, len(all_logs))}/{len(all_logs)}..." + ) + client.predict(api_name="/bulk_log", logs=batch, hf_token=hf_token) + + all_sys_logs = SQLiteStorage.get_all_system_logs_for_sync(project) + if all_sys_logs: + for i in range(0, len(all_sys_logs), SYNC_BATCH_SIZE): + batch = all_sys_logs[i : i + SYNC_BATCH_SIZE] + print( + f" Syncing system metrics: {min(i + SYNC_BATCH_SIZE, len(all_sys_logs))}/{len(all_sys_logs)}..." + ) + client.predict( + api_name="/bulk_log_system", logs=batch, hf_token=hf_token + ) + + _wait_for_remote_sync(client, project, expected_run_counts) + SQLiteStorage.set_project_metadata(project, "space_id", space_id) + print( + f"* Synced successfully to space: {_BOLD_ORANGE}{SPACE_URL.format(space_id=space_id)}{_RESET}" + ) + + +def _build_remote_client_with_retry( + space_id: str, + timeout: int = 360, + verbose: bool = False, +) -> RemoteClient: + deadline = time.time() + timeout + delay = 2 + last_error: Exception | None = None + while time.time() < deadline: + try: + return RemoteClient(space_id, verbose=verbose, httpx_kwargs={"timeout": 90}) + except (ValueError, ConnectionError) as e: + last_error = e + time.sleep(delay) + delay = min(delay * 1.5, 15) + raise ConnectionError( + f"Could not connect to Space '{space_id}' within {timeout}s: {last_error}" + ) + + +def _wait_for_remote_sync( + client: RemoteClient, + project: str, + expected_run_counts: Counter[str], + timeout: int = 180, +) -> None: + if not expected_run_counts: + return + + deadline = time.time() + timeout + delay = 2 + last_error: Exception | None = None + pending = dict(expected_run_counts) + + while time.time() < deadline and pending: + completed = [] + for run_name, expected_num_logs in pending.items(): + try: + summary = client.predict( + project=project, run=run_name, api_name="/get_run_summary" + ) + if summary.get("num_logs") == expected_num_logs: + completed.append(run_name) + except Exception as e: + last_error = e + for run_name in completed: + pending.pop(run_name, None) + if pending: + time.sleep(delay) + delay = min(delay * 1.5, 15) + + if pending: + raise TimeoutError( + f"Remote sync for project '{project}' did not become visible for runs " + f"{sorted(pending.items())} within {timeout}s. " + f"Last error: {last_error!r}" + ) + + +def upload_dataset_for_static( + project: str, + dataset_id: str, + private: bool | None = None, +) -> None: + hf_api = huggingface_hub.HfApi() + + try: + huggingface_hub.create_repo( + dataset_id, + private=private, + repo_type="dataset", + exist_ok=True, + ) + except HfHubHTTPError as e: + if e.response.status_code in [401, 403]: + print("Need 'write' access token to create a Dataset repo.") + huggingface_hub.login(add_to_git_credential=False) + huggingface_hub.create_repo( + dataset_id, + private=private, + repo_type="dataset", + exist_ok=True, + ) + else: + raise ValueError(f"Failed to create Dataset: {e}") + + with tempfile.TemporaryDirectory() as tmp_dir: + output_dir = Path(tmp_dir) + SQLiteStorage.export_for_static_space(project, output_dir) + + media_dir = MEDIA_DIR / project + if media_dir.exists(): + dest = output_dir / "media" + shutil.copytree(media_dir, dest) + + _retry_hf_write( + "Dataset upload", + lambda: hf_api.upload_folder( + repo_id=dataset_id, + repo_type="dataset", + folder_path=str(output_dir), + ), + ) + + print(f"* Dataset uploaded: https://huggingface.co/datasets/{dataset_id}") + + +def deploy_as_static_space( + space_id: str, + dataset_id: str | None, + project: str, + bucket_id: str | None = None, + private: bool | None = None, + hf_token: str | None = None, + frontend_dir: str | Path | None = None, +) -> None: + if on_spaces(): + return + + if private is True: + raise ValueError( + "private=True is not supported for static Trackio Spaces. Static Spaces " + "run entirely in the browser, so their snapshot data must be public. " + "Use sdk='gradio' for a private dashboard." + ) + hf_api = huggingface_hub.HfApi() + + try: + huggingface_hub.create_repo( + space_id, + private=False, + space_sdk="static", + repo_type="space", + exist_ok=True, + ) + except HfHubHTTPError as e: + if e.response.status_code in [401, 403]: + print("Need 'write' access token to create a Spaces repo.") + huggingface_hub.login(add_to_git_credential=False) + huggingface_hub.create_repo( + space_id, + private=False, + space_sdk="static", + repo_type="space", + exist_ok=True, + ) + else: + raise ValueError(f"Failed to create Space: {e}") + + linked = _readme_linked_hub_yaml(dataset_id) + readme_content = ( + f"---\nemoji: 🎯\nsdk: static\npinned: false\ntags:\n - trackio\n{linked}---\n" + ) + _retry_hf_write( + "Static Space README upload", + lambda: hf_api.upload_file( + path_or_fileobj=io.BytesIO(readme_content.encode("utf-8")), + path_in_repo="README.md", + repo_id=space_id, + repo_type="space", + ), + ) + + resolved_frontend = resolve_frontend_dir(frontend_dir, announce=True) + + _retry_hf_write( + "Static Space frontend upload", + lambda: hf_api.upload_folder( + repo_id=space_id, + repo_type="space", + folder_path=str(resolved_frontend.path), + ), + ) + + config = { + "mode": "static", + "project": project, + "private": bool(private), + } + if bucket_id is not None: + config["bucket_id"] = bucket_id + if dataset_id is not None: + config["dataset_id"] = dataset_id + if hf_token is not None: + warnings.warn( + "`hf_token` is ignored by deploy_as_static_space() for static Space " + "deployment and will be removed in a future release.", + DeprecationWarning, + stacklevel=2, + ) + + _retry_hf_write( + "Static Space config upload", + lambda: hf_api.upload_file( + path_or_fileobj=io.BytesIO(json_mod.dumps(config).encode("utf-8")), + path_in_repo="config.json", + repo_id=space_id, + repo_type="space", + ), + ) + + assets_dir = Path(trackio.__file__).resolve().parent / "assets" + if assets_dir.is_dir(): + _retry_hf_write( + "Static Space assets upload", + lambda: hf_api.upload_folder( + repo_id=space_id, + repo_type="space", + folder_path=str(assets_dir), + path_in_repo="static/trackio", + ), + ) + + print( + f"* Static Space deployed: {_BOLD_ORANGE}{SPACE_URL.format(space_id=space_id)}{_RESET}" + ) + + +def sync( + project: str, + space_id: str | None = None, + private: bool | None = None, + force: bool = False, + run_in_background: bool = False, + sdk: str = "gradio", + dataset_id: str | None = None, + bucket_id: str | None = None, + frontend_dir: str | Path | None = None, +) -> str: + """ + Syncs a local Trackio project's database to a Hugging Face Space. + If the Space does not exist, it will be created. Local data is never deleted. + + **Freezing:** Passing ``sdk="static"`` deploys a static Space backed by an HF Bucket + (read-only dashboard, no Gradio server). You can sync the same project again later to + refresh that static Space. If you want a one-time snapshot of an existing Gradio Space, + use ``freeze()`` instead. + + Args: + project (`str`): The name of the project to upload. + space_id (`str`, *optional*): The ID of the Space to upload to (e.g., `"username/space_id"`). + If not provided, checks project metadata first, then generates a random space_id. + private (`bool`, *optional*): + Whether to make the Space private. If None (default), the repo will be + public unless the organization's default is private. This value is ignored + if the repo already exists. Not supported with ``sdk="static"`` because + static Trackio dashboards read snapshot data directly from the browser. + force (`bool`, *optional*, defaults to `False`): + If `True`, overwrite the existing database without prompting for confirmation. + If `False`, prompt the user before overwriting an existing database. + run_in_background (`bool`, *optional*, defaults to `False`): + If `True`, the Space creation and database upload will be run in a background thread. + If `False`, all the steps will be run synchronously. + sdk (`str`, *optional*, defaults to `"gradio"`): + The type of Space to deploy. `"gradio"` deploys a Gradio Space with a live + server. `"static"` freezes the Space: deploys a static Space that reads from an HF Bucket + (no server needed). + dataset_id (`str`, *optional*): + Deprecated. Use `bucket_id` instead. + bucket_id (`str`, *optional*): + The ID of the HF Bucket to sync to. By default, a bucket is auto-generated + from the space_id. + Returns: + `str`: The Space ID of the synced project. + """ + if sdk not in ("gradio", "static"): + raise ValueError(f"sdk must be 'gradio' or 'static', got '{sdk}'") + if sdk == "static" and private is True: + raise ValueError( + "private=True is not supported for static Trackio Spaces. Static Spaces " + "run entirely in the browser, so their snapshot data must be public. " + "Use sdk='gradio' for a private dashboard." + ) + bucket_id_was_explicit = bucket_id is not None + + if space_id is None: + space_id = SQLiteStorage.get_space_id(project) + if space_id is None: + space_id = f"{project}-{get_or_create_project_hash(project)}" + space_id, dataset_id, bucket_id = preprocess_space_and_dataset_ids( + space_id, dataset_id, bucket_id + ) + if dataset_id is None and bucket_id is not None and not bucket_id_was_explicit: + bucket_id = resolve_auto_bucket_id(space_id, bucket_id) + + def _do_sync(): + try: + info = huggingface_hub.HfApi().space_info(space_id) + existing_sdk = info.sdk + if existing_sdk and existing_sdk != sdk: + raise ValueError( + f"Space '{space_id}' is a '{existing_sdk}' Space but sdk='{sdk}' was requested. " + f"The sdk must match the existing Space type." + ) + except RepositoryNotFoundError: + pass + + if sdk == "static": + if dataset_id is not None: + upload_dataset_for_static(project, dataset_id, private=False) + deploy_as_static_space( + space_id, + dataset_id, + project, + private=False, + frontend_dir=frontend_dir, + ) + elif bucket_id is not None: + create_bucket_if_not_exists(bucket_id, private=False) + upload_project_to_bucket_for_static(project, bucket_id) + print( + f"* Project data uploaded to bucket: https://huggingface.co/buckets/{bucket_id}" + ) + deploy_as_static_space( + space_id, + None, + project, + bucket_id=bucket_id, + private=False, + frontend_dir=frontend_dir, + ) + else: + if bucket_id is not None: + create_bucket_if_not_exists(bucket_id, private=private) + upload_project_to_bucket(project, bucket_id) + print( + f"* Project data uploaded to bucket: https://huggingface.co/buckets/{bucket_id}" + ) + create_space_if_not_exists( + space_id, + bucket_id=bucket_id, + private=private, + frontend_dir=frontend_dir, + ) + _wait_until_space_running(space_id) + _wait_for_remote_sync( + _build_remote_client_with_retry(space_id), + project, + Counter( + log["run"] + for log in SQLiteStorage.get_all_logs_for_sync(project) + ), + ) + else: + sync_incremental( + project, + space_id, + private=private, + pending_only=False, + frontend_dir=frontend_dir, + ) + SQLiteStorage.set_project_metadata(project, "space_id", space_id) + + if run_in_background: + threading.Thread(target=_do_sync).start() + else: + _do_sync() + return space_id + + +def _get_source_bucket(space_id: str) -> str: + bucket_id = _get_existing_space_bucket(space_id) + if bucket_id is not None: + _ensure_bucket_mounted_at_data(space_id, bucket_id) + return bucket_id + raise ValueError( + f"Space '{space_id}' has no bucket mounted at '/data'. " + f"freeze() requires the source Space to use bucket storage." + ) + + +def freeze( + space_id: str, + project: str, + new_space_id: str | None = None, + private: bool | None = None, + bucket_id: str | None = None, + frontend_dir: str | Path | None = None, +) -> str: + """ + Creates a new static Hugging Face Space containing a read-only snapshot of + the data for the specified project from the source Gradio Space. The data is + read from the bucket attached to the source Space at freeze time. The original + Space is not modified, and the new static Space does not automatically reflect + metrics uploaded to the original Gradio Space after the freeze completes. + + Args: + space_id (`str`): + The ID of the source Gradio Space (e.g., `"username/my-space"` or a + short repo name with the logged-in namespace inferred, like `init()`). + Must be a Gradio Space with a bucket mounted at `/data`. + project (`str`): + The name of the project whose data to include in the frozen Space. + new_space_id (`str`, *optional*): + The ID for the new static Space. If not provided, defaults to + `"{space_id}_static"`. + private (`bool`, *optional*): + Not supported. Frozen static dashboards read snapshot data directly + from the browser, so the destination snapshot must be public. + bucket_id (`str`, *optional*): + The ID of the HF Bucket for the new static Space's data storage. + If not provided, one is auto-generated from the new Space ID. + + Returns: + `str`: The Space ID of the newly created static Space. + """ + if private is True: + raise ValueError( + "private=True is not supported for frozen static Trackio Spaces. Static " + "Spaces run entirely in the browser, so their snapshot data must be " + "public. Use a Gradio Space if the frozen dashboard must stay private." + ) + space_id, _, _ = preprocess_space_and_dataset_ids(space_id, None, None) + + try: + info = huggingface_hub.HfApi().space_info(space_id) + if info.sdk != "gradio": + raise ValueError( + f"Space '{space_id}' is not a Gradio Space (sdk='{info.sdk}'). " + f"freeze() requires a Gradio Space as the source." + ) + except RepositoryNotFoundError: + raise ValueError( + f"Space '{space_id}' not found. Provide an existing Gradio Space ID." + ) + + source_bucket_id = _get_source_bucket(space_id) + print(f"* Reading project data from bucket: {source_bucket_id}") + + bucket_id_was_explicit = bucket_id is not None + + if new_space_id is None: + new_space_id = f"{space_id}_static" + new_space_id, _dataset_id, bucket_id = preprocess_space_and_dataset_ids( + new_space_id, None, bucket_id + ) + if bucket_id is not None and not bucket_id_was_explicit: + bucket_id = resolve_auto_bucket_id(new_space_id, bucket_id) + + hf_api = huggingface_hub.HfApi() + try: + dest_info = hf_api.space_info(new_space_id) + tags = dest_info.tags or [] + if dest_info.sdk != "static" or "trackio" not in tags: + raise ValueError( + f"Space '{new_space_id}' already exists and is not a Trackio static Space " + f"(sdk='{dest_info.sdk}', tags={tags}). Choose a different new_space_id " + f"or delete the existing Space first." + ) + except RepositoryNotFoundError: + pass + + create_bucket_if_not_exists(bucket_id, private=False) + export_from_bucket_for_static(source_bucket_id, bucket_id, project) + print( + f"* Project data uploaded to bucket: https://huggingface.co/buckets/{bucket_id}" + ) + deploy_as_static_space( + new_space_id, + None, + project, + bucket_id=bucket_id, + private=False, + frontend_dir=frontend_dir, + ) + return new_space_id diff --git a/trackio/dummy_commit_scheduler.py b/trackio/dummy_commit_scheduler.py new file mode 100644 index 0000000000000000000000000000000000000000..6068fe8a36b8647ade92dd300af0855f4338826f --- /dev/null +++ b/trackio/dummy_commit_scheduler.py @@ -0,0 +1,19 @@ +from concurrent.futures import Future + + +class DummyCommitSchedulerLock: + def __enter__(self): + return None + + def __exit__(self, exception_type, exception_value, exception_traceback): + pass + + +class DummyCommitScheduler: + def __init__(self): + self.lock = DummyCommitSchedulerLock() + + def trigger(self) -> Future: + fut: Future = Future() + fut.set_result(None) + return fut diff --git a/trackio/exceptions.py b/trackio/exceptions.py new file mode 100644 index 0000000000000000000000000000000000000000..189f56d718245b65790ff43e14005b846aad2402 --- /dev/null +++ b/trackio/exceptions.py @@ -0,0 +1,2 @@ +class TrackioAPIError(Exception): + pass diff --git a/trackio/frontend/dist/assets/index-DsqR87ZT.js b/trackio/frontend/dist/assets/index-DsqR87ZT.js new file mode 100644 index 0000000000000000000000000000000000000000..756f6bd1270bb6e643a559630b0ef4ec7444acee --- /dev/null +++ b/trackio/frontend/dist/assets/index-DsqR87ZT.js @@ -0,0 +1,250 @@ +var yW=Object.defineProperty;var XF=e=>{throw TypeError(e)};var bW=(e,t,n)=>t in e?yW(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var Ys=(e,t,n)=>bW(e,typeof t!="symbol"?t+"":t,n),G2=(e,t,n)=>t.has(e)||XF("Cannot "+n);var re=(e,t,n)=>(G2(e,t,"read from private field"),n?n.call(e):t.get(e)),Nt=(e,t,n)=>t.has(e)?XF("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),$t=(e,t,n,r)=>(G2(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n),Wn=(e,t,n)=>(G2(e,t,"access private method"),n);(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const i of document.querySelectorAll('link[rel="modulepreload"]'))r(i);new MutationObserver(i=>{for(const s of i)if(s.type==="childList")for(const o of s.addedNodes)o.tagName==="LINK"&&o.rel==="modulepreload"&&r(o)}).observe(document,{childList:!0,subtree:!0});function n(i){const s={};return i.integrity&&(s.integrity=i.integrity),i.referrerPolicy&&(s.referrerPolicy=i.referrerPolicy),i.crossOrigin==="use-credentials"?s.credentials="include":i.crossOrigin==="anonymous"?s.credentials="omit":s.credentials="same-origin",s}function r(i){if(i.ep)return;i.ep=!0;const s=n(i);fetch(i.href,s)}})();const xW="5";var FT;typeof window<"u"&&((FT=window.__svelte??(window.__svelte={})).v??(FT.v=new Set)).add(xW);const _W=1,wW=2,RT=4,EW=8,AW=16,kW=1,SW=2,CW=4,$W=8,FW=16,DW=1,MW=2,_r=Symbol(),NT="http://www.w3.org/1999/xhtml",TW="http://www.w3.org/2000/svg",RW="http://www.w3.org/1998/Math/MathML",NW=!1;var GA=Array.isArray,OW=Array.prototype.indexOf,Ad=Array.prototype.includes,ky=Array.from,LW=Object.defineProperty,id=Object.getOwnPropertyDescriptor,OT=Object.getOwnPropertyDescriptors,IW=Object.prototype,PW=Array.prototype,YA=Object.getPrototypeOf,KF=Object.isExtensible;const LT=()=>{};function BW(e){return e()}function J_(e){for(var t=0;t{e=r,t=i});return{promise:n,resolve:e,reject:t}}function VA(e,t){if(Array.isArray(e))return e;if(!(Symbol.iterator in e))return Array.from(e);const n=[];for(const r of e)if(n.push(r),n.length===t)break;return n}const hr=2,kd=4,Xg=8,PT=1<<24,xu=16,po=32,Nc=64,Q_=128,Fs=512,sr=1024,Tr=2048,go=4096,as=8192,Ds=16384,ff=32768,ew=1<<25,Oc=65536,ZF=1<<17,zW=1<<18,fh=1<<19,BT=1<<20,Ko=1<<25,Lc=65536,tw=1<<21,XA=1<<22,Vl=1<<23,Za=Symbol("$state"),jW=Symbol("legacy props"),UW=Symbol(""),Ia=new class extends Error{constructor(){super(...arguments);Ys(this,"name","StaleReactionError");Ys(this,"message","The reaction that called `getAbortSignal()` was re-run or destroyed")}};var DT;const qW=!!((DT=globalThis.document)!=null&&DT.contentType)&&globalThis.document.contentType.includes("xml");function WW(e){throw new Error("https://svelte.dev/e/lifecycle_outside_component")}function HW(){throw new Error("https://svelte.dev/e/async_derived_orphan")}function GW(e,t,n){throw new Error("https://svelte.dev/e/each_key_duplicate")}function YW(e){throw new Error("https://svelte.dev/e/effect_in_teardown")}function VW(){throw new Error("https://svelte.dev/e/effect_in_unowned_derived")}function XW(e){throw new Error("https://svelte.dev/e/effect_orphan")}function KW(){throw new Error("https://svelte.dev/e/effect_update_depth_exceeded")}function ZW(e){throw new Error("https://svelte.dev/e/props_invalid_value")}function JW(){throw new Error("https://svelte.dev/e/state_descriptors_fixed")}function QW(){throw new Error("https://svelte.dev/e/state_prototype_fixed")}function eH(){throw new Error("https://svelte.dev/e/state_unsafe_mutation")}function tH(){throw new Error("https://svelte.dev/e/svelte_boundary_reset_onerror")}function nH(){console.warn("https://svelte.dev/e/select_multiple_invalid_value")}function rH(){console.warn("https://svelte.dev/e/svelte_boundary_reset_noop")}function zT(e){return e===this.v}function jT(e,t){return e!=e?t==t:e!==t||e!==null&&typeof e=="object"||typeof e=="function"}function UT(e){return!jT(e,this.v)}let dh=!1,iH=!1;function sH(){dh=!0}let Nn=null;function Sd(e){Nn=e}function En(e,t=!1,n){Nn={p:Nn,i:!1,c:null,e:null,s:e,x:null,r:Lt,l:dh&&!t?{s:null,u:null,$:[]}:null}}function An(e){var t=Nn,n=t.e;if(n!==null){t.e=null;for(var r of n)uR(r)}return t.i=!0,Nn=t.p,{}}function Kg(){return!dh||Nn!==null&&Nn.l===null}let cc=[];function qT(){var e=cc;cc=[],J_(e)}function Xl(e){if(cc.length===0&&!Wp){var t=cc;queueMicrotask(()=>{t===cc&&qT()})}cc.push(e)}function oH(){for(;cc.length>0;)qT()}function WT(e){var t=Lt;if(t===null)return Dt.f|=Vl,e;if((t.f&ff)===0&&(t.f&kd)===0)throw e;Pl(e,t)}function Pl(e,t){for(;t!==null;){if((t.f&Q_)!==0){if((t.f&ff)===0)throw e;try{t.b.error(e);return}catch(n){e=n}}t=t.parent}throw e}const aH=-7169;function zn(e,t){e.f=e.f&aH|t}function KA(e){(e.f&Fs)!==0||e.deps===null?zn(e,sr):zn(e,go)}function HT(e){if(e!==null)for(const t of e)(t.f&hr)===0||(t.f&Lc)===0||(t.f^=Lc,HT(t.deps))}function GT(e,t,n){(e.f&Tr)!==0?t.add(e):(e.f&go)!==0&&n.add(e),HT(e.deps),zn(e,sr)}let tm=!1;function lH(e){var t=tm;try{return tm=!1,[e(),tm]}finally{tm=t}}const qh=new Set;let _t=null,Er=null,nw=null,Wp=!1,Y2=!1,Kf=null,e1=null;var JF=0;let uH=1;var gd,md,vd,yd,Gg,xs,bd,Ll,Uo,xd,ti,rw,iw,sw,ow,YT;const wy=class wy{constructor(){Nt(this,ti);Ys(this,"id",uH++);Ys(this,"current",new Map);Ys(this,"previous",new Map);Nt(this,gd,new Set);Nt(this,md,new Set);Nt(this,vd,0);Nt(this,yd,0);Nt(this,Gg,null);Nt(this,xs,[]);Nt(this,bd,new Set);Nt(this,Ll,new Set);Nt(this,Uo,new Map);Ys(this,"is_fork",!1);Nt(this,xd,!1)}skip_effect(t){re(this,Uo).has(t)||re(this,Uo).set(t,{d:[],m:[]})}unskip_effect(t){var n=re(this,Uo).get(t);if(n){re(this,Uo).delete(t);for(var r of n.d)zn(r,Tr),this.schedule(r);for(r of n.m)zn(r,go),this.schedule(r)}}capture(t,n){n!==_r&&!this.previous.has(t)&&this.previous.set(t,n),(t.f&Vl)===0&&(this.current.set(t,t.v),Er==null||Er.set(t,t.v))}activate(){_t=this}deactivate(){_t=null,Er=null}flush(){try{if(Y2=!0,_t=this,!Wn(this,ti,rw).call(this)){for(const t of re(this,bd))re(this,Ll).delete(t),zn(t,Tr),this.schedule(t);for(const t of re(this,Ll))zn(t,go),this.schedule(t)}Wn(this,ti,iw).call(this)}finally{JF=0,nw=null,Kf=null,e1=null,Y2=!1,_t=null,Er=null,Kl.clear()}}discard(){for(const t of re(this,md))t(this);re(this,md).clear()}increment(t){$t(this,vd,re(this,vd)+1),t&&$t(this,yd,re(this,yd)+1)}decrement(t,n){$t(this,vd,re(this,vd)-1),t&&$t(this,yd,re(this,yd)-1),!(re(this,xd)||n)&&($t(this,xd,!0),Xl(()=>{$t(this,xd,!1),this.flush()}))}oncommit(t){re(this,gd).add(t)}ondiscard(t){re(this,md).add(t)}settled(){return(re(this,Gg)??$t(this,Gg,IT())).promise}static ensure(){if(_t===null){const t=_t=new wy;Y2||(qh.add(_t),Wp||Xl(()=>{_t===t&&t.flush()}))}return _t}apply(){}schedule(t){var i;if(nw=t,(i=t.b)!=null&&i.is_pending&&(t.f&(kd|Xg|PT))!==0&&(t.f&ff)===0){t.b.defer_effect(t);return}for(var n=t;n.parent!==null;){n=n.parent;var r=n.f;if(Kf!==null&&n===Lt&&(Dt===null||(Dt.f&hr)===0))return;if((r&(Nc|po))!==0){if((r&sr)===0)return;n.f^=sr}}re(this,xs).push(n)}};gd=new WeakMap,md=new WeakMap,vd=new WeakMap,yd=new WeakMap,Gg=new WeakMap,xs=new WeakMap,bd=new WeakMap,Ll=new WeakMap,Uo=new WeakMap,xd=new WeakMap,ti=new WeakSet,rw=function(){return this.is_fork||re(this,yd)>0},iw=function(){var a,l;JF++>1e3&&fH();const t=re(this,xs);$t(this,xs,[]),this.apply();var n=Kf=[],r=[],i=e1=[];for(const u of t)Wn(this,ti,sw).call(this,u,n,r);if(_t=null,i.length>0){var s=wy.ensure();for(const u of i)s.schedule(u)}if(Kf=null,e1=null,Wn(this,ti,rw).call(this)){Wn(this,ti,ow).call(this,r),Wn(this,ti,ow).call(this,n);for(const[u,c]of re(this,Uo))KT(u,c)}else{re(this,bd).clear(),re(this,Ll).clear();for(const u of re(this,gd))u(this);re(this,gd).clear(),QF(r),QF(n),re(this,vd)===0&&Wn(this,ti,YT).call(this),(a=re(this,Gg))==null||a.resolve()}var o=_t;if(re(this,xs).length>0){const u=o??(o=this);re(u,xs).push(...re(this,xs).filter(c=>!re(u,xs).includes(c)))}o!==null&&(qh.add(o),Wn(l=o,ti,iw).call(l))},sw=function(t,n,r){t.f^=sr;for(var i=t.first;i!==null;){var s=i.f,o=(s&(po|Nc))!==0,a=o&&(s&sr)!==0,l=a||(s&as)!==0||re(this,Uo).has(i);if(!l&&i.fn!==null){o?i.f^=sr:(s&kd)!==0?n.push(i):e0(i)&&((s&xu)!==0&&re(this,Ll).add(i),Fd(i));var u=i.first;if(u!==null){i=u;continue}}for(;i!==null;){var c=i.next;if(c!==null){i=c;break}i=i.parent}}},ow=function(t){for(var n=0;n1){this.previous.clear();var t=_t,n=Er,r=!0;for(const s of qh){if(s===this){r=!1;continue}const o=[];for(const[l,u]of this.current){if(s.current.has(l))if(r&&u!==s.current.get(l))s.current.set(l,u);else continue;o.push(l)}if(o.length===0)continue;const a=[...s.current.keys()].filter(l=>!this.current.has(l));if(a.length>0){s.activate();const l=new Set,u=new Map;for(const c of o)VT(c,a,l,u);if(re(s,xs).length>0){s.apply();for(const c of re(s,xs))Wn(i=s,ti,sw).call(i,c,[],[])}s.deactivate()}}_t=t,Er=n}re(this,Uo).clear(),qh.delete(this)};let Ic=wy;function cH(e){var t=Wp;Wp=!0;try{for(var n;;){if(oH(),_t===null)return n;_t.flush()}}finally{Wp=t}}function fH(){try{KW()}catch(e){Pl(e,nw)}}let Zs=null;function QF(e){var t=e.length;if(t!==0){for(var n=0;n0)){Kl.clear();for(const i of Zs){if((i.f&(Ds|as))!==0)continue;const s=[i];let o=i.parent;for(;o!==null;)Zs.has(o)&&(Zs.delete(o),s.push(o)),o=o.parent;for(let a=s.length-1;a>=0;a--){const l=s[a];(l.f&(Ds|as))===0&&Fd(l)}}Zs.clear()}}Zs=null}}function VT(e,t,n,r){if(!n.has(e)&&(n.add(e),e.reactions!==null))for(const i of e.reactions){const s=i.f;(s&hr)!==0?VT(i,t,n,r):(s&(XA|xu))!==0&&(s&Tr)===0&&XT(i,t,r)&&(zn(i,Tr),ZA(i))}}function XT(e,t,n){const r=n.get(e);if(r!==void 0)return r;if(e.deps!==null)for(const i of e.deps){if(Ad.call(t,i))return!0;if((i.f&hr)!==0&&XT(i,t,n))return n.set(i,!0),!0}return n.set(e,!1),!1}function ZA(e){_t.schedule(e)}function KT(e,t){if(!((e.f&po)!==0&&(e.f&sr)!==0)){(e.f&Tr)!==0?t.d.push(e):(e.f&go)!==0&&t.m.push(e),zn(e,sr);for(var n=e.first;n!==null;)KT(n,t),n=n.next}}function dH(e){let t=0,n=Pc(0),r;return()=>{tk()&&(y(n),Qg(()=>(t===0&&(r=_u(()=>e(()=>Hp(n)))),t+=1,()=>{Xl(()=>{t-=1,t===0&&(r==null||r(),r=void 0,Hp(n))})})))}}var hH=Oc|fh;function pH(e,t,n,r){new gH(e,t,n,r)}var _s,HA,qo,vc,Ci,Wo,Zi,Js,ja,yc,Il,_d,wd,Ed,Ua,Ey,er,mH,vH,yH,aw,t1,n1,lw;class gH{constructor(t,n,r,i){Nt(this,er);Ys(this,"parent");Ys(this,"is_pending",!1);Ys(this,"transform_error");Nt(this,_s);Nt(this,HA,null);Nt(this,qo);Nt(this,vc);Nt(this,Ci);Nt(this,Wo,null);Nt(this,Zi,null);Nt(this,Js,null);Nt(this,ja,null);Nt(this,yc,0);Nt(this,Il,0);Nt(this,_d,!1);Nt(this,wd,new Set);Nt(this,Ed,new Set);Nt(this,Ua,null);Nt(this,Ey,dH(()=>($t(this,Ua,Pc(re(this,yc))),()=>{$t(this,Ua,null)})));var s;$t(this,_s,t),$t(this,qo,n),$t(this,vc,o=>{var a=Lt;a.b=this,a.f|=Q_,r(o)}),this.parent=Lt.b,this.transform_error=i??((s=this.parent)==null?void 0:s.transform_error)??(o=>o),$t(this,Ci,Cy(()=>{Wn(this,er,aw).call(this)},hH))}defer_effect(t){GT(t,re(this,wd),re(this,Ed))}is_rendered(){return!this.is_pending&&(!this.parent||this.parent.is_rendered())}has_pending_snippet(){return!!re(this,qo).pending}update_pending_count(t,n){Wn(this,er,lw).call(this,t,n),$t(this,yc,re(this,yc)+t),!(!re(this,Ua)||re(this,_d))&&($t(this,_d,!0),Xl(()=>{$t(this,_d,!1),re(this,Ua)&&Cd(re(this,Ua),re(this,yc))}))}get_effect_pending(){return re(this,Ey).call(this),y(re(this,Ua))}error(t){var n=re(this,qo).onerror;let r=re(this,qo).failed;if(!n&&!r)throw t;re(this,Wo)&&(Ii(re(this,Wo)),$t(this,Wo,null)),re(this,Zi)&&(Ii(re(this,Zi)),$t(this,Zi,null)),re(this,Js)&&(Ii(re(this,Js)),$t(this,Js,null));var i=!1,s=!1;const o=()=>{if(i){rH();return}i=!0,s&&tH(),re(this,Js)!==null&&xc(re(this,Js),()=>{$t(this,Js,null)}),Wn(this,er,n1).call(this,()=>{Wn(this,er,aw).call(this)})},a=l=>{try{s=!0,n==null||n(l,o),s=!1}catch(u){Pl(u,re(this,Ci)&&re(this,Ci).parent)}r&&$t(this,Js,Wn(this,er,n1).call(this,()=>{try{return ws(()=>{var u=Lt;u.b=this,u.f|=Q_,r(re(this,_s),()=>l,()=>o)})}catch(u){return Pl(u,re(this,Ci).parent),null}}))};Xl(()=>{var l;try{l=this.transform_error(t)}catch(u){Pl(u,re(this,Ci)&&re(this,Ci).parent);return}l!==null&&typeof l=="object"&&typeof l.then=="function"?l.then(a,u=>Pl(u,re(this,Ci)&&re(this,Ci).parent)):a(l)})}}_s=new WeakMap,HA=new WeakMap,qo=new WeakMap,vc=new WeakMap,Ci=new WeakMap,Wo=new WeakMap,Zi=new WeakMap,Js=new WeakMap,ja=new WeakMap,yc=new WeakMap,Il=new WeakMap,_d=new WeakMap,wd=new WeakMap,Ed=new WeakMap,Ua=new WeakMap,Ey=new WeakMap,er=new WeakSet,mH=function(){try{$t(this,Wo,ws(()=>re(this,vc).call(this,re(this,_s))))}catch(t){this.error(t)}},vH=function(t){const n=re(this,qo).failed;n&&$t(this,Js,ws(()=>{n(re(this,_s),()=>t,()=>()=>{})}))},yH=function(){const t=re(this,qo).pending;if(t){this.is_pending=!0,$t(this,Zi,ws(()=>t(re(this,_s))));var n=_t;Xl(()=>{var r=$t(this,ja,document.createDocumentFragment()),i=Ja();r.append(i),$t(this,Wo,Wn(this,er,n1).call(this,()=>ws(()=>re(this,vc).call(this,i)))),re(this,Il)===0&&(re(this,_s).before(r),$t(this,ja,null),xc(re(this,Zi),()=>{$t(this,Zi,null)}),Wn(this,er,t1).call(this,n))})}},aw=function(){var t=_t;try{if(this.is_pending=this.has_pending_snippet(),$t(this,Il,0),$t(this,yc,0),$t(this,Wo,ws(()=>{re(this,vc).call(this,re(this,_s))})),re(this,Il)>0){var n=$t(this,ja,document.createDocumentFragment());ok(re(this,Wo),n);const r=re(this,qo).pending;$t(this,Zi,ws(()=>r(re(this,_s))))}else Wn(this,er,t1).call(this,t)}catch(r){this.error(r)}},t1=function(t){this.is_pending=!1;for(const n of re(this,wd))zn(n,Tr),t.schedule(n);for(const n of re(this,Ed))zn(n,go),t.schedule(n);re(this,wd).clear(),re(this,Ed).clear()},n1=function(t){var n=Lt,r=Dt,i=Nn;oa(re(this,Ci)),Ns(re(this,Ci)),Sd(re(this,Ci).ctx);try{return Ic.ensure(),t()}catch(s){return WT(s),null}finally{oa(n),Ns(r),Sd(i)}},lw=function(t,n){var r;if(!this.has_pending_snippet()){this.parent&&Wn(r=this.parent,er,lw).call(r,t,n);return}$t(this,Il,re(this,Il)+t),re(this,Il)===0&&(Wn(this,er,t1).call(this,n),re(this,Zi)&&xc(re(this,Zi),()=>{$t(this,Zi,null)}),re(this,ja)&&(re(this,_s).before(re(this,ja)),$t(this,ja,null)))};function bH(e,t,n,r){const i=Kg()?Zg:JA;var s=e.filter(d=>!d.settled);if(n.length===0&&s.length===0){r(t.map(i));return}var o=Lt,a=xH(),l=s.length===1?s[0].promise:s.length>1?Promise.all(s.map(d=>d.promise)):null;function u(d){a();try{r(d)}catch(h){(o.f&Ds)===0&&Pl(h,o)}O1()}if(n.length===0){l.then(()=>u(t.map(i)));return}var c=ZT();function f(){Promise.all(n.map(d=>_H(d))).then(d=>u([...t.map(i),...d])).catch(d=>Pl(d,o)).finally(()=>c())}l?l.then(()=>{a(),f(),O1()}):f()}function xH(){var e=Lt,t=Dt,n=Nn,r=_t;return function(s=!0){oa(e),Ns(t),Sd(n),s&&(e.f&Ds)===0&&(r==null||r.activate(),r==null||r.apply())}}function O1(e=!0){oa(null),Ns(null),Sd(null),e&&(_t==null||_t.deactivate())}function ZT(){var e=Lt.b,t=_t,n=e.is_rendered();return e.update_pending_count(1,t),t.increment(n),(r=!1)=>{e.update_pending_count(-1,t),t.decrement(n,r)}}function Zg(e){var t=hr|Tr,n=Dt!==null&&(Dt.f&hr)!==0?Dt:null;return Lt!==null&&(Lt.f|=fh),{ctx:Nn,deps:null,effects:null,equals:zT,f:t,fn:e,reactions:null,rv:0,v:_r,wv:0,parent:n??Lt,ac:null}}function _H(e,t,n){let r=Lt;r===null&&HW();var i=void 0,s=Pc(_r),o=!Dt,a=new Map;return NH(()=>{var h;var l=Lt,u=IT();i=u.promise;try{Promise.resolve(e()).then(u.resolve,u.reject).finally(O1)}catch(p){u.reject(p),O1()}var c=_t;if(o){if((l.f&ff)!==0)var f=ZT();if(r.b.is_rendered())(h=a.get(c))==null||h.reject(Ia),a.delete(c);else{for(const p of a.values())p.reject(Ia);a.clear()}a.set(c,u)}const d=(p,g=void 0)=>{if(f){var m=g===Ia;f(m)}if(!(g===Ia||(l.f&Ds)!==0)){if(c.activate(),g)s.f|=Vl,Cd(s,g);else{(s.f&Vl)!==0&&(s.f^=Vl),Cd(s,p);for(const[v,b]of a){if(a.delete(v),v===c)break;b.reject(Ia)}}c.deactivate()}};u.promise.then(d,p=>d(null,p||"unknown"))}),nk(()=>{for(const l of a.values())l.reject(Ia)}),new Promise(l=>{function u(c){function f(){c===i?l(s):u(i)}c.then(f,f)}u(i)})}function we(e){const t=Zg(e);return gR(t),t}function JA(e){const t=Zg(e);return t.equals=UT,t}function wH(e){var t=e.effects;if(t!==null){e.effects=null;for(var n=0;n0&&!eR&&SH()}return t}function SH(){eR=!1;for(const e of uw)(e.f&sr)!==0&&zn(e,go),e0(e)&&Fd(e);uw.clear()}function tR(e,t=1){var n=y(e),r=t===1?n++:n--;return D(e,n),r}function Hp(e){D(e,e.v+1)}function nR(e,t,n){var r=e.reactions;if(r!==null)for(var i=Kg(),s=r.length,o=0;o{if(_c===s)return a();var l=Dt,u=_c;Ns(null),r5(s);var c=a();return Ns(l),r5(u),c};return r&&n.set("length",se(e.length)),new Proxy(e,{defineProperty(a,l,u){(!("value"in u)||u.configurable===!1||u.enumerable===!1||u.writable===!1)&&JW();var c=n.get(l);return c===void 0?o(()=>{var f=se(u.value);return n.set(l,f),f}):D(c,u.value,!0),!0},deleteProperty(a,l){var u=n.get(l);if(u===void 0){if(l in a){const c=o(()=>se(_r));n.set(l,c),Hp(i)}}else D(u,_r),Hp(i);return!0},get(a,l,u){var h;if(l===Za)return e;var c=n.get(l),f=l in a;if(c===void 0&&(!f||(h=id(a,l))!=null&&h.writable)&&(c=o(()=>{var p=mt(f?a[l]:_r),g=se(p);return g}),n.set(l,c)),c!==void 0){var d=y(c);return d===_r?void 0:d}return Reflect.get(a,l,u)},getOwnPropertyDescriptor(a,l){var u=Reflect.getOwnPropertyDescriptor(a,l);if(u&&"value"in u){var c=n.get(l);c&&(u.value=y(c))}else if(u===void 0){var f=n.get(l),d=f==null?void 0:f.v;if(f!==void 0&&d!==_r)return{enumerable:!0,configurable:!0,value:d,writable:!0}}return u},has(a,l){var d;if(l===Za)return!0;var u=n.get(l),c=u!==void 0&&u.v!==_r||Reflect.has(a,l);if(u!==void 0||Lt!==null&&(!c||(d=id(a,l))!=null&&d.writable)){u===void 0&&(u=o(()=>{var h=c?mt(a[l]):_r,p=se(h);return p}),n.set(l,u));var f=y(u);if(f===_r)return!1}return c},set(a,l,u,c){var x;var f=n.get(l),d=l in a;if(r&&l==="length")for(var h=u;hse(_r)),n.set(h+"",p))}if(f===void 0)(!d||(x=id(a,l))!=null&&x.writable)&&(f=o(()=>se(void 0)),D(f,mt(u)),n.set(l,f));else{d=f.v!==_r;var g=o(()=>mt(u));D(f,g)}var m=Reflect.getOwnPropertyDescriptor(a,l);if(m!=null&&m.set&&m.set.call(c,u),!d){if(r&&typeof l=="string"){var v=n.get("length"),b=Number(l);Number.isInteger(b)&&b>=v.v&&D(v,b+1)}Hp(i)}return!0},ownKeys(a){y(i);var l=Reflect.ownKeys(a).filter(f=>{var d=n.get(f);return d===void 0||d.v!==_r});for(var[u,c]of n)c.v!==_r&&!(u in a)&&l.push(u);return l},setPrototypeOf(){QW()}})}function e5(e){try{if(e!==null&&typeof e=="object"&&Za in e)return e[Za]}catch{}return e}function CH(e,t){return Object.is(e5(e),e5(t))}var $d,rR,iR,sR;function $H(){if($d===void 0){$d=window,rR=/Firefox/.test(navigator.userAgent);var e=Element.prototype,t=Node.prototype,n=Text.prototype;iR=id(t,"firstChild").get,sR=id(t,"nextSibling").get,KF(e)&&(e.__click=void 0,e.__className=void 0,e.__attributes=null,e.__style=void 0,e.__e=void 0),KF(n)&&(n.__t=void 0)}}function Ja(e=""){return document.createTextNode(e)}function Zo(e){return iR.call(e)}function Jg(e){return sR.call(e)}function C(e,t){return Zo(e)}function Ot(e,t=!1){{var n=Zo(e);return n instanceof Comment&&n.data===""?Jg(n):n}}function N(e,t=1,n=!1){let r=e;for(;t--;)r=Jg(r);return r}function FH(e){e.textContent=""}function oR(){return!1}function aR(e,t,n){return document.createElementNS(t??NT,e,void 0)}let t5=!1;function DH(){t5||(t5=!0,document.addEventListener("reset",e=>{Promise.resolve().then(()=>{var t;if(!e.defaultPrevented)for(const n of e.target.elements)(t=n.__on_r)==null||t.call(n)})},{capture:!0}))}function Sy(e){var t=Dt,n=Lt;Ns(null),oa(null);try{return e()}finally{Ns(t),oa(n)}}function ek(e,t,n,r=n){e.addEventListener(t,()=>Sy(n));const i=e.__on_r;i?e.__on_r=()=>{i(),r(!0)}:e.__on_r=()=>r(!0),DH()}function lR(e){Lt===null&&(Dt===null&&XW(),VW()),ru&&YW()}function MH(e,t){var n=t.last;n===null?t.last=t.first=e:(n.next=e,e.prev=n,t.last=e)}function ma(e,t){var n=Lt;n!==null&&(n.f&as)!==0&&(e|=as);var r={ctx:Nn,deps:null,nodes:null,f:e|Tr|Fs,first:null,fn:t,last:null,next:null,parent:n,b:n&&n.b,prev:null,teardown:null,wv:0,ac:null},i=r;if((e&kd)!==0)Kf!==null?Kf.push(r):Ic.ensure().schedule(r);else if(t!==null){try{Fd(r)}catch(o){throw Ii(r),o}i.deps===null&&i.teardown===null&&i.nodes===null&&i.first===i.last&&(i.f&fh)===0&&(i=i.first,(e&xu)!==0&&(e&Oc)!==0&&i!==null&&(i.f|=Oc))}if(i!==null&&(i.parent=n,n!==null&&MH(i,n),Dt!==null&&(Dt.f&hr)!==0&&(e&Nc)===0)){var s=Dt;(s.effects??(s.effects=[])).push(i)}return r}function tk(){return Dt!==null&&!oo}function nk(e){const t=ma(Xg,null);return zn(t,sr),t.teardown=e,t}function Bt(e){lR();var t=Lt.f,n=!Dt&&(t&po)!==0&&(t&ff)===0;if(n){var r=Nn;(r.e??(r.e=[])).push(e)}else return uR(e)}function uR(e){return ma(kd|BT,e)}function TH(e){return lR(),ma(Xg|BT,e)}function RH(e){Ic.ensure();const t=ma(Nc|fh,e);return(n={})=>new Promise(r=>{n.outro?xc(t,()=>{Ii(t),r(void 0)}):(Ii(t),r(void 0))})}function rk(e){return ma(kd,e)}function NH(e){return ma(XA|fh,e)}function Qg(e,t=0){return ma(Xg|t,e)}function xe(e,t=[],n=[],r=[]){bH(r,t,n,i=>{ma(Xg,()=>e(...i.map(y)))})}function Cy(e,t=0){var n=ma(xu|t,e);return n}function ws(e){return ma(po|fh,e)}function cR(e){var t=e.teardown;if(t!==null){const n=ru,r=Dt;n5(!0),Ns(null);try{t.call(null)}finally{n5(n),Ns(r)}}}function ik(e,t=!1){var n=e.first;for(e.first=e.last=null;n!==null;){const i=n.ac;i!==null&&Sy(()=>{i.abort(Ia)});var r=n.next;(n.f&Nc)!==0?n.parent=null:Ii(n,t),n=r}}function OH(e){for(var t=e.first;t!==null;){var n=t.next;(t.f&po)===0&&Ii(t),t=n}}function Ii(e,t=!0){var n=!1;(t||(e.f&zW)!==0)&&e.nodes!==null&&e.nodes.end!==null&&(fR(e.nodes.start,e.nodes.end),n=!0),zn(e,ew),ik(e,t&&!n),cg(e,0);var r=e.nodes&&e.nodes.t;if(r!==null)for(const s of r)s.stop();cR(e),e.f^=ew,e.f|=Ds;var i=e.parent;i!==null&&i.first!==null&&dR(e),e.next=e.prev=e.teardown=e.ctx=e.deps=e.fn=e.nodes=e.ac=null}function fR(e,t){for(;e!==null;){var n=e===t?null:Jg(e);e.remove(),e=n}}function dR(e){var t=e.parent,n=e.prev,r=e.next;n!==null&&(n.next=r),r!==null&&(r.prev=n),t!==null&&(t.first===e&&(t.first=r),t.last===e&&(t.last=n))}function xc(e,t,n=!0){var r=[];hR(e,r,!0);var i=()=>{n&&Ii(e),t&&t()},s=r.length;if(s>0){var o=()=>--s||i();for(var a of r)a.out(o)}else i()}function hR(e,t,n){if((e.f&as)===0){e.f^=as;var r=e.nodes&&e.nodes.t;if(r!==null)for(const a of r)(a.is_global||n)&&t.push(a);for(var i=e.first;i!==null;){var s=i.next,o=(i.f&Oc)!==0||(i.f&po)!==0&&(e.f&xu)!==0;hR(i,t,o?n:!1),i=s}}}function sk(e){pR(e,!0)}function pR(e,t){if((e.f&as)!==0){e.f^=as,(e.f&sr)===0&&(zn(e,Tr),Ic.ensure().schedule(e));for(var n=e.first;n!==null;){var r=n.next,i=(n.f&Oc)!==0||(n.f&po)!==0;pR(n,i?t:!1),n=r}var s=e.nodes&&e.nodes.t;if(s!==null)for(const o of s)(o.is_global||t)&&o.in()}}function ok(e,t){if(e.nodes)for(var n=e.nodes.start,r=e.nodes.end;n!==null;){var i=n===r?null:Jg(n);t.append(n),n=i}}let r1=!1,ru=!1;function n5(e){ru=e}let Dt=null,oo=!1;function Ns(e){Dt=e}let Lt=null;function oa(e){Lt=e}let Ms=null;function gR(e){Dt!==null&&(Ms===null?Ms=[e]:Ms.push(e))}let Fi=null,Xi=0,bs=null;function LH(e){bs=e}let mR=1,fc=0,_c=fc;function r5(e){_c=e}function vR(){return++mR}function e0(e){var t=e.f;if((t&Tr)!==0)return!0;if(t&hr&&(e.f&=~Lc),(t&go)!==0){for(var n=e.deps,r=n.length,i=0;ie.wv)return!0}(t&Fs)!==0&&Er===null&&zn(e,sr)}return!1}function yR(e,t,n=!0){var r=e.reactions;if(r!==null&&!(Ms!==null&&Ad.call(Ms,e)))for(var i=0;i{e.ac.abort(Ia)}),e.ac=null);try{e.f|=tw;var c=e.fn,f=c();e.f|=ff;var d=e.deps,h=_t==null?void 0:_t.is_fork;if(Fi!==null){var p;if(h||cg(e,Xi),d!==null&&Xi>0)for(d.length=Xi+Fi.length,p=0;pn==null?void 0:n.call(this,s))}return e.startsWith("pointer")||e.startsWith("touch")||e==="wheel"?Xl(()=>{t.addEventListener(e,i,r)}):t.addEventListener(e,i,r),i}function fn(e,t,n,r,i){var s={capture:r,passive:i},o=PH(e,t,n,s);(t===document.body||t===window||t===document||t instanceof HTMLMediaElement)&&nk(()=>{t.removeEventListener(e,o,s)})}function Ue(e,t,n){(t[dc]??(t[dc]={}))[e]=n}function ni(e){for(var t=0;t{throw b});throw d}}finally{e[dc]=t,delete e.currentTarget,Ns(c),oa(f)}}}var MT;const V2=((MT=globalThis==null?void 0:globalThis.window)==null?void 0:MT.trustedTypes)&&globalThis.window.trustedTypes.createPolicy("svelte-trusted-html",{createHTML:e=>e});function BH(e){return(V2==null?void 0:V2.createHTML(e))??e}function AR(e){var t=aR("template");return t.innerHTML=BH(e.replaceAll("","")),t.content}function Bc(e,t){var n=Lt;n.nodes===null&&(n.nodes={start:e,end:t,a:null,t:null})}function U(e,t){var n=(t&DW)!==0,r=(t&MW)!==0,i,s=!e.startsWith("");return()=>{i===void 0&&(i=AR(s?e:""+e),n||(i=Zo(i)));var o=r||rR?document.importNode(i,!0):i.cloneNode(!0);if(n){var a=Zo(o),l=o.lastChild;Bc(a,l)}else Bc(o,o);return o}}function zH(e,t,n="svg"){var r=!e.startsWith(""),i=`<${n}>${r?e:""+e}`,s;return()=>{if(!s){var o=AR(i),a=Zo(o);s=Zo(a)}var l=s.cloneNode(!0);return Bc(l,l),l}}function _i(e,t){return zH(e,t,"svg")}function hw(e=""){{var t=Ja(e+"");return Bc(t,t),t}}function Ri(){var e=document.createDocumentFragment(),t=document.createComment(""),n=Ja();return e.append(t,n),Bc(t,n),e}function I(e,t){e!==null&&e.before(t)}const jH=["touchstart","touchmove"];function UH(e){return jH.includes(e)}function be(e,t){var n=t==null?"":typeof t=="object"?`${t}`:t;n!==(e.__t??(e.__t=e.nodeValue))&&(e.__t=n,e.nodeValue=`${n}`)}function qH(e,t){return WH(e,t)}const nm=new Map;function WH(e,{target:t,anchor:n,props:r={},events:i,context:s,intro:o=!0,transformError:a}){$H();var l=void 0,u=RH(()=>{var c=n??t.appendChild(Ja());pH(c,{pending:()=>{}},h=>{En({});var p=Nn;s&&(p.c=s),i&&(r.$$events=i),l=e(h,r)||{},An()},a);var f=new Set,d=h=>{for(var p=0;p{var m;for(var h of f)for(const v of[t,document]){var p=nm.get(v),g=p.get(h);--g==0?(v.removeEventListener(h,dw),p.delete(h),p.size===0&&nm.delete(v)):p.set(h,g)}fw.delete(d),c!==n&&((m=c.parentNode)==null||m.removeChild(c))}});return HH.set(l,u),l}let HH=new WeakMap;var Qs,Ho,Ji,bc,Yg,Vg,Ay;class kR{constructor(t,n=!0){Ys(this,"anchor");Nt(this,Qs,new Map);Nt(this,Ho,new Map);Nt(this,Ji,new Map);Nt(this,bc,new Set);Nt(this,Yg,!0);Nt(this,Vg,t=>{if(re(this,Qs).has(t)){var n=re(this,Qs).get(t),r=re(this,Ho).get(n);if(r)sk(r),re(this,bc).delete(n);else{var i=re(this,Ji).get(n);i&&(re(this,Ho).set(n,i.effect),re(this,Ji).delete(n),i.fragment.lastChild.remove(),this.anchor.before(i.fragment),r=i.effect)}for(const[s,o]of re(this,Qs)){if(re(this,Qs).delete(s),s===t)break;const a=re(this,Ji).get(o);a&&(Ii(a.effect),re(this,Ji).delete(o))}for(const[s,o]of re(this,Ho)){if(s===n||re(this,bc).has(s))continue;const a=()=>{if(Array.from(re(this,Qs).values()).includes(s)){var u=document.createDocumentFragment();ok(o,u),u.append(Ja()),re(this,Ji).set(s,{effect:o,fragment:u})}else Ii(o);re(this,bc).delete(s),re(this,Ho).delete(s)};re(this,Yg)||!r?(re(this,bc).add(s),xc(o,a,!1)):a()}}});Nt(this,Ay,t=>{re(this,Qs).delete(t);const n=Array.from(re(this,Qs).values());for(const[r,i]of re(this,Ji))n.includes(r)||(Ii(i.effect),re(this,Ji).delete(r))});this.anchor=t,$t(this,Yg,n)}ensure(t,n){var r=_t,i=oR();if(n&&!re(this,Ho).has(t)&&!re(this,Ji).has(t))if(i){var s=document.createDocumentFragment(),o=Ja();s.append(o),re(this,Ji).set(t,{effect:ws(()=>n(o)),fragment:s})}else re(this,Ho).set(t,ws(()=>n(this.anchor)));if(re(this,Qs).set(r,t),i){for(const[a,l]of re(this,Ho))a===t?r.unskip_effect(l):r.skip_effect(l);for(const[a,l]of re(this,Ji))a===t?r.unskip_effect(l.effect):r.skip_effect(l.effect);r.oncommit(re(this,Vg)),r.ondiscard(re(this,Ay))}else re(this,Vg).call(this,r)}}Qs=new WeakMap,Ho=new WeakMap,Ji=new WeakMap,bc=new WeakMap,Yg=new WeakMap,Vg=new WeakMap,Ay=new WeakMap;function s5(e,t,...n){var r=new kR(e);Cy(()=>{const i=t()??null;r.ensure(i,i&&(s=>i(s,...n)))},Oc)}function hh(e){Nn===null&&WW(),dh&&Nn.l!==null?GH(Nn).m.push(e):Bt(()=>{const t=_u(e);if(typeof t=="function")return t})}function GH(e){var t=e.l;return t.u??(t.u={a:[],b:[],m:[]})}function ge(e,t,n=!1){var r=new kR(e),i=n?Oc:0;function s(o,a){r.ensure(o,a)}Cy(()=>{var o=!1;t((a,l=0)=>{o=!0,s(l,a)}),o||s(-1,null)},i)}function At(e,t){return t}function YH(e,t,n){for(var r=[],i=t.length,s,o=t.length,a=0;a{if(s){if(s.pending.delete(f),s.done.add(f),s.pending.size===0){var d=e.outrogroups;pw(e,ky(s.done)),d.delete(s),d.size===0&&(e.outrogroups=null)}}else o-=1},!1)}if(o===0){var l=r.length===0&&n!==null;if(l){var u=n,c=u.parentNode;FH(c),c.append(u),e.items.clear()}pw(e,t,!l)}else s={pending:new Set(t),done:new Set},(e.outrogroups??(e.outrogroups=new Set)).add(s)}function pw(e,t,n=!0){var r;if(e.pending.size>0){r=new Set;for(const o of e.pending.values())for(const a of o)r.add(e.items.get(a).e)}for(var i=0;i{var x=n();return GA(x)?x:x==null?[]:ky(x)}),d,h=new Map,p=!0;function g(x){(b.effect.f&Ds)===0&&(b.pending.delete(x),b.fallback=c,VH(b,d,o,t,r),c!==null&&(d.length===0?(c.f&Ko)===0?sk(c):(c.f^=Ko,mp(c,null,o)):xc(c,()=>{c=null})))}function m(x){b.pending.delete(x)}var v=Cy(()=>{d=y(f);for(var x=d.length,_=new Set,w=_t,A=oR(),E=0;Es(o)):(c=ws(()=>s(o5??(o5=Ja()))),c.f|=Ko)),x>_.size&&GW(),!p)if(h.set(w,_),A){for(const[M,O]of a)_.has(M)||w.skip_effect(O.e);w.oncommit(g),w.ondiscard(m)}else g(w);y(f)}),b={effect:v,items:a,pending:h,outrogroups:null,fallback:c};p=!1}function Wh(e){for(;e!==null&&(e.f&po)===0;)e=e.next;return e}function VH(e,t,n,r,i){var $,M,O,P,T,F,R,z,j;var s=(r&EW)!==0,o=t.length,a=e.items,l=Wh(e.effect.first),u,c=null,f,d=[],h=[],p,g,m,v;if(s)for(v=0;v0){var S=(r&RT)!==0&&o===0?n:null;if(s){for(v=0;v{var q,te;if(f!==void 0)for(m of f)(te=(q=m.nodes)==null?void 0:q.a)==null||te.apply()})}function XH(e,t,n,r,i,s,o,a){var l=(o&_W)!==0?(o&AW)===0?kH(n,!1,!1):Pc(n):null,u=(o&wW)!==0?Pc(i):null;return{v:l,i:u,e:ws(()=>(s(t,l??n,u??i,a),()=>{e.delete(r)}))}}function mp(e,t,n){if(e.nodes)for(var r=e.nodes.start,i=e.nodes.end,s=t&&(t.f&Ko)===0?t.nodes.start:n;r!==null;){var o=Jg(r);if(s.before(r),r===i)return;r=o}}function kl(e,t,n){t===null?e.effect.first=n:t.next=n,n===null?e.effect.last=t:n.prev=t}function KH(e,t,n=!1,r=!1,i=!1,s=!1){var o=e,a="";if(n)var l=e;xe(()=>{var u=Lt;if(a!==(a=t()??"")){if(n){u.nodes=null,l.innerHTML=a,a!==""&&Bc(Zo(l),l.lastChild);return}if(u.nodes!==null&&(fR(u.nodes.start,u.nodes.end),u.nodes=null),a!==""){var c=r?TW:i?RW:void 0,f=aR(r?"svg":i?"math":"template",c);f.innerHTML=a;var d=r||i?f:f.content;if(Bc(Zo(d),d.lastChild),r||i)for(;Zo(d);)o.before(Zo(d));else o.before(d)}}})}function X2(e,t,n){rk(()=>{var r=_u(()=>t(e,n==null?void 0:n())||{});if(n&&(r!=null&&r.update)){var i=!1,s={};Qg(()=>{var o=n();wR(o),i&&jT(s,o)&&(s=o,r.update(o))}),i=!0}if(r!=null&&r.destroy)return()=>r.destroy()})}const a5=[...` +\r\f \v\uFEFF`];function ZH(e,t,n){var r=e==null?"":""+e;if(n){for(var i of Object.keys(n))if(n[i])r=r?r+" "+i:i;else if(r.length)for(var s=i.length,o=0;(o=r.indexOf(i,o))>=0;){var a=o+s;(o===0||a5.includes(r[o-1]))&&(a===r.length||a5.includes(r[a]))?r=(o===0?"":r.substring(0,o))+r.substring(a+1):o=a}}return r===""?null:r}function l5(e,t=!1){var n=t?" !important;":";",r="";for(var i of Object.keys(e)){var s=e[i];s!=null&&s!==""&&(r+=" "+i+": "+s+n)}return r}function K2(e){return e[0]!=="-"||e[1]!=="-"?e.toLowerCase():e}function JH(e,t){if(t){var n="",r,i;if(Array.isArray(t)?(r=t[0],i=t[1]):r=t,e){e=String(e).replaceAll(/\s*\/\*.*?\*\/\s*/g,"").trim();var s=!1,o=0,a=!1,l=[];r&&l.push(...Object.keys(r).map(K2)),i&&l.push(...Object.keys(i).map(K2));var u=0,c=-1;const g=e.length;for(var f=0;f{SR(e,e.__value)});t.observe(e,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["value"]}),nk(()=>{t.disconnect()})}function L1(e,t,n=t){var r=new WeakSet,i=!0;ek(e,"change",s=>{var o=s?"[selected]":":checked",a;if(e.multiple)a=[].map.call(e.querySelectorAll(o),Gp);else{var l=e.querySelector(o)??e.querySelector("option:not([disabled])");a=l&&Gp(l)}n(a),_t!==null&&r.add(_t)}),rk(()=>{var s=t();if(e===document.activeElement){var o=_t;if(r.has(o))return}if(SR(e,s,i),i&&s===void 0){var a=e.querySelector(":checked");a!==null&&(s=Gp(a),n(s))}e.__value=s,i=!1}),QH(e)}function Gp(e){return"__value"in e?e.__value:e.value}const eG=Symbol("is custom element"),tG=Symbol("is html"),nG=qW?"progress":"PROGRESS";function u5(e,t){var n=ak(e);n.value===(n.value=t??void 0)||e.value===t&&(t!==0||e.nodeName!==nG)||(e.value=t??"")}function Gf(e,t){var n=ak(e);n.checked!==(n.checked=t??void 0)&&(e.checked=t)}function xt(e,t,n,r){var i=ak(e);i[t]!==(i[t]=n)&&(t==="loading"&&(e[UW]=n),n==null?e.removeAttribute(t):typeof n!="string"&&rG(e).includes(t)?e[t]=n:e.setAttribute(t,n))}function ak(e){return e.__attributes??(e.__attributes={[eG]:e.nodeName.includes("-"),[tG]:e.namespaceURI===NT})}var c5=new Map;function rG(e){var t=e.getAttribute("is")||e.nodeName,n=c5.get(t);if(n)return n;c5.set(t,n=[]);for(var r,i=e,s=Element.prototype;s!==i;){r=OT(i);for(var o in r)r[o].set&&n.push(o);i=YA(i)}return n}function t0(e,t,n=t){var r=new WeakSet;ek(e,"input",async i=>{var s=i?e.defaultValue:e.value;if(s=J2(e)?Q2(s):s,n(s),_t!==null&&r.add(_t),await ts(),s!==(s=t())){var o=e.selectionStart,a=e.selectionEnd,l=e.value.length;if(e.value=s??"",a!==null){var u=e.value.length;o===a&&a===l&&u>l?(e.selectionStart=u,e.selectionEnd=u):(e.selectionStart=o,e.selectionEnd=Math.min(a,u))}}}),_u(t)==null&&e.value&&(n(J2(e)?Q2(e.value):e.value),_t!==null&&r.add(_t)),Qg(()=>{var i=t();if(e===document.activeElement){var s=_t;if(r.has(s))return}J2(e)&&i===Q2(e.value)||e.type==="date"&&!i&&!e.value||i!==e.value&&(e.value=i??"")})}function iG(e,t,n=t){ek(e,"change",r=>{var i=r?e.defaultChecked:e.checked;n(i)}),_u(t)==null&&n(e.checked),Qg(()=>{var r=t();e.checked=!!r})}function J2(e){var t=e.type;return t==="number"||t==="range"}function Q2(e){return e===""?null:+e}function f5(e,t){return e===t||(e==null?void 0:e[Za])===t}function rs(e={},t,n,r){var i=Nn.r,s=Lt;return rk(()=>{var o,a;return Qg(()=>{o=a,a=[],_u(()=>{e!==n(...a)&&(t(e,...a),o&&f5(n(...o),e)&&t(null,...o))})}),()=>{let l=s;for(;l!==i&&l.parent!==null&&l.parent.f&ew;)l=l.parent;const u=()=>{a&&f5(n(...a),e)&&t(null,...a)},c=l.teardown;l.teardown=()=>{u(),c==null||c()}}}),e}function sG(e=!1){const t=Nn,n=t.l.u;if(!n)return;let r=()=>wR(t.s);if(e){let i=0,s={};const o=Zg(()=>{let a=!1;const l=t.s;for(const u in l)l[u]!==s[u]&&(s[u]=l[u],a=!0);return a&&i++,i});r=()=>y(o)}n.b.length&&TH(()=>{d5(t,r),J_(n.b)}),Bt(()=>{const i=_u(()=>n.m.map(BW));return()=>{for(const s of i)typeof s=="function"&&s()}}),n.a.length&&Bt(()=>{d5(t,r),J_(n.a)})}function d5(e,t){if(e.l.s)for(const n of e.l.s)y(n);t()}function oe(e,t,n,r){var x;var i=!dh||(n&SW)!==0,s=(n&$W)!==0,o=(n&FW)!==0,a=r,l=!0,u=()=>(l&&(l=!1,a=o?_u(r):r),a);let c;if(s){var f=Za in e||jW in e;c=((x=id(e,t))==null?void 0:x.set)??(f&&t in e?_=>e[t]=_:void 0)}var d,h=!1;s?[d,h]=lH(()=>e[t]):d=e[t],d===void 0&&r!==void 0&&(d=u(),c&&(i&&ZW(),c(d)));var p;if(i?p=()=>{var _=e[t];return _===void 0?u():(l=!0,_)}:p=()=>{var _=e[t];return _!==void 0&&(a=void 0),_===void 0?a:_},i&&(n&CW)===0)return p;if(c){var g=e.$$legacy;return(function(_,w){return arguments.length>0?((!i||!w||g||h)&&c(w?p():_),_):p()})}var m=!1,v=((n&kW)!==0?Zg:JA)(()=>(m=!1,p()));s&&y(v);var b=Lt;return(function(_,w){if(arguments.length>0){const A=w?y(v):i&&s?mt(_):_;return D(v,A),m=!0,a!==void 0&&(a=A),_}return ru&&m||(b.f&Ds)!==0?v.v:y(v)})}var oG=U(""),aG=U('');function lG(e,t){En(t,!0);let n=oe(t,"currentPage",3,"metrics"),r=oe(t,"tabAvailability",19,()=>({})),i=oe(t,"optionalEmptyTabs",19,()=>new Set);const s=[{id:"metrics",label:"Metrics"},{id:"system",label:"System Metrics"},{id:"traces",label:"Traces"},{id:"media",label:"Media & Tables"},{id:"reports",label:"Alerts & Reports"},{id:"runs",label:"Runs"},{id:"files",label:"Files"}];function o(h){var p;(p=t.onNavigate)==null||p.call(t,h)}function a(h){return i().has(h)&&r()[h]===!1}var l=aG(),u=N(C(l),2),c=C(u);wt(c,17,()=>s,At,(h,p)=>{var g=oG();let m;var v=C(g);xe((b,x)=>{m=en(g,1,"nav-link svelte-d8j1hi",null,m,b),xt(g,"title",x),be(v,y(p).label)},[()=>({active:n()===y(p).id,empty:a(y(p).id)}),()=>a(y(p).id)?`${y(p).label} is empty for this project`:y(p).label]),Ue("click",g,()=>o(y(p).id)),I(h,g)});var f=N(c,2);let d;xe(()=>d=en(f,1,"nav-link settings-btn svelte-d8j1hi",null,d,{active:n()==="settings"})),Ue("click",f,()=>o("settings")),I(e,l),An()}ni(["click"]);var uG=U(''),cG=U('
');function h5(e,t){En(t,!0);let n=oe(t,"choices",19,()=>[]),r=oe(t,"selected",31,()=>mt([])),i=oe(t,"colors",19,()=>[]),s=oe(t,"ontoggle",3,null),o=oe(t,"getKey",3,c=>c),a=oe(t,"getLabel",3,c=>c);function l(c){var d;const f=o()(c);r().includes(f)?r(r().filter(h=>h!==f)):r([...r(),f]),(d=s())==null||d()}var u=cG();wt(u,21,n,At,(c,f,d)=>{var h=uG(),p=C(h),g=N(p,2),m=N(g,2),v=C(m);xe((b,x,_)=>{Gf(p,b),ll(g,`background: ${(i()[d]||"#999")??""}`),xt(m,"title",x),be(v,_)},[()=>r().includes(o()(y(f))),()=>a()(y(f)),()=>a()(y(f))]),Ue("change",p,()=>l(y(f))),I(c,h)}),I(e,u),An()}ni(["change"]);var fG=U(' '),dG=U(' '),hG=U('
  • '),pG=U('
      '),gG=U('');function ex(e,t){En(t,!0);let n=oe(t,"label",3,"Dropdown"),r=oe(t,"info",3,""),i=oe(t,"value",15,null),s=oe(t,"choices",19,()=>[]),o=oe(t,"filterable",3,!0),a=oe(t,"showLabel",3,!0),l,u=se(!1),c=se(""),f=se(null),d=se(mt([])),h=se(0),p=se(null),g=se(null),m=se(300),v=we(()=>s().map(Y=>typeof Y=="object"&&Y!==null?Y:{label:String(Y),value:Y})),b=we(()=>i()!==null?y(v).findIndex(Y=>Y.value===i()):-1);Bt(()=>{if(y(u))return;const Y=y(v).findIndex(ee=>ee.value===i());i()!==null&&Y>=0?D(c,y(v)[Y].label,!0):D(c,"")}),Bt(()=>{D(d,y(u)?x(y(c)):y(v).map((Y,ee)=>ee),!0)});function x(Y){if(!Y)return y(v).map((_e,Le)=>Le);const ee=Y.toLowerCase();return y(v).map((_e,Le)=>_e.label.toLowerCase().includes(ee)?Le:-1).filter(_e=>_e>=0)}function _(){var Y;if(D(c,""),D(d,y(v).map((ee,_e)=>_e),!0),D(u,!0),l){const ee=(Y=l.closest(".wrap"))==null?void 0:Y.getBoundingClientRect();if(ee){D(h,ee.width,!0);const _e=window.innerHeight-ee.bottom,Le=ee.top;_e>=200||_e>Le?(D(p,`${ee.bottom}px`),D(g,null),D(m,_e-16)):(D(g,`${window.innerHeight-ee.top}px`),D(p,null),D(m,Le-16))}}}function w(Y){y(u)&&(Y.preventDefault(),l==null||l.blur())}function A(){const Y=y(v).findIndex(ee=>ee.label===y(c));if(Y>=0)i(y(v)[Y].value);else if(i()!==null){const ee=y(v).findIndex(_e=>_e.value===i());D(c,ee>=0?y(v)[ee].label:"",!0)}else D(c,"");D(u,!1),D(f,null),D(d,y(v).map((ee,_e)=>_e),!0)}function E(Y){const ee=parseInt(Y);isNaN(ee)||(i(y(v)[ee].value),D(c,y(v)[ee].label,!0),D(u,!1),D(f,null),l==null||l.blur())}async function k(Y){if(await ts(),D(d,x(y(c)),!0),y(d).length>0&&y(f)===null&&D(f,y(d)[0],!0),Y.key==="ArrowDown")if(Y.preventDefault(),y(f)===null)D(f,y(d)[0]??null,!0);else{const ee=y(d).indexOf(y(f));ee0&&D(f,y(d)[ee-1],!0)}}else Y.key==="Enter"?y(f)!==null&&E(y(f)):Y.key==="Escape"&&(D(u,!1),l==null||l.blur())}var S=gG(),$=C(S);{var M=Y=>{var ee=fG(),_e=C(ee);xe(()=>be(_e,n())),I(Y,ee)};ge($,Y=>{a()&&Y(M)})}var O=N($,2);{var P=Y=>{var ee=dG(),_e=C(ee);xe(()=>be(_e,r())),I(Y,ee)};ge(O,Y=>{r()&&Y(P)})}var T=N(O,2);let F;var R=C(T),z=C(R),j=C(z);rs(j,Y=>l=Y,()=>l);var q=N(T,2);{var te=Y=>{var ee=pG(),_e=C(ee);let Le;wt(_e,21,()=>y(d),At,(Z,he)=>{var He=hG();let Ke;var de=C(He);let Re;var Q=N(de);xe(()=>{Ke=en(He,1,"item svelte-kgylqb",null,Ke,{selected:y(he)===y(b),active:y(he)===y(f)}),xt(He,"data-index",y(he)),xt(He,"aria-selected",y(he)===y(b)),Re=en(de,1,"check-mark svelte-kgylqb",null,Re,{hide:y(he)!==y(b)}),be(Q,` ${y(v)[y(he)].label??""}`)}),I(Z,He)}),xe(()=>Le=ll(_e,"",Le,{top:y(p),bottom:y(g),"max-height":`${y(m)??""}px`,width:`${y(h)??""}px`})),Ue("mousedown",_e,Z=>{var He;Z.preventDefault();const he=(He=Z.target.closest("li"))==null?void 0:He.dataset.index;he!==void 0&&E(he)}),I(Y,ee)};ge(q,Y=>{y(u)&&Y(te)})}xe(()=>{F=en(T,1,"wrap svelte-kgylqb",null,F,{focused:y(u)}),xt(j,"aria-label",n()),j.readOnly=!o(),xt(j,"placeholder",i()===null?"Select...":"")}),Ue("mousedown",j,w),Ue("keydown",j,k),fn("blur",j,A),fn("focus",j,_),t0(j,()=>y(c),Y=>D(c,Y)),I(e,S),An()}ni(["mousedown","keydown"]);var mG=U(' '),vG=U('');function rm(e,t){En(t,!0);let n=oe(t,"label",3,""),r=oe(t,"checked",15,!1),i=oe(t,"showLabel",3,!0);function s(c){r(c.currentTarget.checked)}var o=vG(),a=C(o),l=N(a,2);{var u=c=>{var f=mG(),d=C(f);xe(()=>be(d,n())),I(c,f)};ge(l,c=>{i()&&n()&&c(u)})}Ue("input",a,s),iG(a,r),I(e,o),An()}ni(["input"]);var yG=U(' '),bG=U(' '),xG=U('
      ');function _G(e,t){En(t,!0);let n=oe(t,"label",3,"Slider"),r=oe(t,"info",3,""),i=oe(t,"value",15,0),s=oe(t,"min",3,0),o=oe(t,"max",3,100),a=oe(t,"step",3,1),l=oe(t,"showLabel",3,!0),u,c=we(()=>i()>o()?100:i(){u&&u.style.setProperty("--range_progress",`${y(c)}%`)});var f=xG(),d=C(f),h=C(d);{var p=E=>{var k=yG(),S=C(k);xe(()=>be(S,n())),I(E,k)};ge(h,E=>{l()&&E(p)})}var g=N(d,2);{var m=E=>{var k=bG(),S=C(k);xe(()=>be(S,r())),I(E,k)};ge(g,E=>{r()&&E(m)})}var v=N(g,2),b=C(v),x=C(b),_=N(b,2);rs(_,E=>u=E,()=>u);var w=N(_,2),A=C(w);xe(()=>{be(x,s()),xt(_,"min",s()),xt(_,"max",o()),xt(_,"step",a()),be(A,o())}),t0(_,i),I(e,f),An()}var wG=U(' '),EG=U(' '),AG=U('
      ');function tx(e,t){En(t,!0);let n=oe(t,"label",3,""),r=oe(t,"info",3,""),i=oe(t,"value",15,""),s=oe(t,"placeholder",3,""),o=oe(t,"showLabel",3,!0);var a=AG(),l=C(a);{var u=p=>{var g=wG(),m=C(g);xe(()=>be(m,n())),I(p,g)};ge(l,p=>{o()&&n()&&p(u)})}var c=N(l,2);{var f=p=>{var g=EG(),m=C(g);xe(()=>be(m,r())),I(p,g)};ge(c,p=>{r()&&p(f)})}var d=N(c,2),h=C(d);xe(()=>xt(h,"placeholder",s())),t0(h,i),I(e,a),An()}const kG=["#A8769B","#E89957","#3B82F6","#10B981","#EF4444","#8B5CF6","#14B8A6","#F59E0B","#EC4899","#06B6D4"];let gw=kG;function SG(e){Array.isArray(e)&&e.length>0&&(gw=e)}function mw(e){return gw[e%gw.length]}function n0(e){const t={};return e.forEach((n,r)=>{const i=typeof n=="string"?n:(n==null?void 0:n.id)??(n==null?void 0:n.name)??String(r);t[i]=mw(r)}),t}function p5(e){return!e||e.length===0?[]:[e[0]]}function CG(e,t,n){const r=e??[],i=t??[],s=n??[],o=new Set(i),a=r.filter(u=>o.has(u));if(r.length===0||a.length===0)return[...i];if(s.length>0&&r.length===s.length){const u=new Set(a),c=i.filter(f=>!u.has(f));return[...a,...c]}return a}const CR=["project","run","timestamp","step","time","metrics"];function $G(e,t,n,r,i,s){if(!e||e.length===0)return null;let o=e.map(d=>({...d}));Object.hasOwn(o[0],"step")||o.forEach((d,h)=>d.step=h);let a="step";if(r==="time"&&Object.hasOwn(o[0],"timestamp")){const d=new Date(o[0].timestamp).getTime();o.forEach(h=>{h.time=(new Date(h.timestamp).getTime()-d)/1e3}),a="time"}else r!=="step"&&(a=r);i&&o.forEach(d=>{if(d[a]!=null){const h=d[a];d[a]=h<=0?Math.log10(Math.max(h,0)+1):Math.log10(h)}});const u=$R(o).filter(d=>!CR.includes(d)&&d!==a);s&&o.forEach(d=>{u.forEach(h=>{if(d[h]!=null&&typeof d[h]=="number"){const p=d[h];d[h]=p<=0?Math.log10(Math.max(p,0)+1):Math.log10(p)}})});const c=typeof t=="string"?t:(t==null?void 0:t.id)??(t==null?void 0:t.name),f=typeof t=="string"?t:(t==null?void 0:t.name)??(t==null?void 0:t.id);if(n>0){const d=o.map(p=>({...p,run:f,run_id:c,series_key:c,data_type:"original"})),h=FG(o,u,n).map(p=>({...p,run:f,run_id:c,series_key:c,data_type:"smoothed"}));return{rows:[...d,...h],xColumn:a}}return{rows:o.map(d=>({...d,run:f,run_id:c,series_key:c,data_type:"original"})),xColumn:a}}function FG(e,t,n){const r=Math.max(3,Math.min(n,e.length)),i=Math.floor(r/2);return e.map((s,o)=>{const a={...s};return t.forEach(l=>{if(s[l]==null||typeof s[l]!="number")return;const u=Math.max(0,o-i),c=Math.min(e.length,o+i+1);let f=0,d=0;for(let h=u;h0?f/d:s[l]}),a})}function $R(e){if(!e||e.length===0)return[];const t=new Set;return e.forEach(n=>{Object.keys(n).forEach(r=>{typeof n[r]=="number"&&isFinite(n[r])&&t.add(r)})}),Array.from(t)}function DG(e){return $R(e).filter(t=>!CR.includes(t))}function I1(e,t,n,r){let i=e.filter(a=>a[n]!=null&&a[n]!==void 0);if(r){const a=new Map;for(const u of i){const c=`${u.series_key||u.run||""}\0${u.data_type||"original"}`;a.has(c)||a.set(c,[]),a.get(c).push(u)}const l=[];for(const[,u]of a){u.sort((d,h)=>d[t]-h[t]);let c=0,f=u.length-1;for(;c=0&&u[f][t]>r[1];)f--;c=Math.max(0,c-1),f=Math.min(u.length-1,f+1),l.push(...u.slice(c,f+1))}i=l}const s=i.filter(a=>a.data_type==="original"||!a.data_type);let o;if(s.length>0){let a=1/0,l=-1/0;for(const u of s){const c=u[n];c!=null&&(cl&&(l=c))}a!==1/0&&(o=[a,l])}return{data:FR(i,t,n,"series_key",r,["run","series_key"]).data,yExtent:o}}function g5(e,t,n,r,i,s=[]){const o=[t,n];r&&Object.hasOwn(e[0],r)&&o.push(r),o.push(...s);let a=e.map(p=>{const g={};return[...new Set(o)].forEach(m=>g[m]=p[m]),p.data_type&&(g.data_type=p.data_type),p.run&&(g.run=p.run),g});const l=Math.min(...a.map(p=>p[t]).filter(p=>p!=null)),u=Math.max(...a.map(p=>p[t]).filter(p=>p!=null));let c=i;if(i){const[p,g]=[i[0]??l,i[1]??u];c=[p,g]}const f={};r?a.forEach(p=>{const g=p[r]||"__default";f[g]||(f[g]=[]),f[g].push(p)}):f.__default=a;const d=[],h=100;return Object.values(f).forEach(p=>{if(p.sort((x,_)=>(x[t]||0)-(_[t]||0)),p.length<500){d.push(...p);return}const g=c?c[0]:l,m=c?c[1]:u;if(g===m){d.push(...p);return}const v=(m-g)/h,b=new Map;p.forEach(x=>{const _=x[t];if(_==null)return;const w=Math.min(Math.floor((_-g)/v),h-1);b.has(w)||b.set(w,[]),b.get(w).push(x)}),b.forEach(x=>{if(x.length===0)return;let _=x[0],w=x[0];x.forEach(A=>{A[n]<_[n]&&(_=A),A[n]>w[n]&&(w=A)}),d.push(_),_!==w&&d.push(w)})}),d.sort((p,g)=>(p[t]||0)-(g[t]||0)),{data:d,xLim:c}}function FR(e,t,n,r,i,s=[]){if(!e||e.length===0)return{data:e,xLim:i};if(e.some(a=>a.data_type)&&r&&e[0]&&Object.hasOwn(e[0],r)){const a=new Map;for(const c of e){const f=`${c[r]??"__default"}\0${c.data_type??"original"}`;a.has(f)||a.set(f,[]),a.get(f).push(c)}const l=[];let u=i;for(const c of a.values()){const f=g5(c,t,n,r,i,s);l.push(...f.data),u=f.xLim}return l.sort((c,f)=>(c[t]||0)-(f[t]||0)),{data:l,xLim:u}}return g5(e,t,n,r,i,s)}function DR(e,t=[]){const n=[],r={};e.forEach(u=>{if(u.includes("/")){const c=u.split("/"),f=c[0];if(r[f]||(r[f]={direct:[],subgroups:{}}),c.length===2)r[f].direct.push(u);else{const d=c[1];r[f].subgroups[d]||(r[f].subgroups[d]=[]),r[f].subgroups[d].push(u)}}else n.push(u)});function i(u){if(!t||t.length===0)return u.sort();const c=[],f=[...u];for(const d of t)for(let h=f.length-1;h>=0;h--)s(f[h],d)&&(c.push(f[h]),f.splice(h,1));return f.sort(),[...c,...f]}function s(u,c){return c===u||c.endsWith("/*")&&u.startsWith(c.slice(0,-1))?!0:c.includes("*")?new RegExp("^"+c.replace(/\*/g,".*")+"$").test(u):!1}function o(u){if(!t||t.length===0)return 1/0;for(let c=0;c0&&(a.charts={direct:i(n),subgroups:{}});const l=Object.keys(r);if(l.sort((u,c)=>{const f=o(u),d=o(c);return f!==d?f-d:u.localeCompare(c)}),l.forEach(u=>{const c=r[u];c.direct=i(c.direct),Object.keys(c.subgroups).forEach(f=>{c.subgroups[f]=i(c.subgroups[f])}),a[u]=c}),"charts"in a){const u=o("charts");if(u<1/0){const c=Object.entries(a);c.sort(([d],[h])=>{const p=d==="charts"?u:o(d),g=h==="charts"?u:o(h);return p!==g?p-g:d.localeCompare(h)});const f={};return c.forEach(([d,h])=>{f[d]=h}),f}}return a}function MR(e,t,n){if(!t||!e||e.length===0)return"";const r=new Set,i=[];for(const s of e){const o=s[t];o&&!r.has(o)&&(r.add(o),i.push(`${o}:${n[o]??"#999"}`))}return i.sort(),i.join("|")}function m5(e){if(!e)return null;const t=typeof e.step=="number"?e.step:null,n=e.timestamp??null;return{step:t,ts:n}}function TR(e,t){if(!e||!t)return!!t;if(t.length!==e.length)return!0;if(t.length===0)return!1;const n=m5(e[e.length-1]),r=m5(t[t.length-1]);return!n||!r?!0:n.step!==r.step||n.ts!==r.ts}function lk(e,t){if(!t||!t.trim())return e;try{const n=new RegExp(t,"i");return e.filter(r=>n.test(r))}catch{return e.filter(n=>n.toLowerCase().includes(t.toLowerCase()))}}const P1=Object.freeze({_Group:"Group",_Username:"Username"});function MG(e){return e.startsWith("_")&&!Object.hasOwn(P1,e)}function TG(e){return P1[e]??e}function RG(e,t){const n=new Set;for(const r of Object.values(e??{})){if(!r||typeof r!="object")continue;const i=r[t],s=i==null?"(unset)":String(i);if(n.add(s),n.size>=2)return!0}return!1}function NG(e){const t=Object.keys(P1).filter(o=>RG(e,o)).map(o=>({label:TG(o),value:o})),n=new Set(t.map(o=>o.label)),r=new Set,i=new Set;for(const o of Object.values(e??{}))if(!(!o||typeof o!="object"))for(const a of Object.keys(o))o[a]===null||o[a]===void 0||MG(a)||Object.hasOwn(P1,a)||n.has(a)||(typeof o[a]=="object"?i.add(a):r.add(a));for(const o of i)r.delete(o);const s=[...r].sort().map(o=>({label:o,value:o}));return[{label:"None",value:null},...t,...s]}function OG(e,t,n){if(!n)return null;const r=new Map;for(const i of e){const o=((t??{})[i.id]??(t??{})[i.name]??{})[n],a=o==null?"(unset)":String(o);r.has(a)||r.set(a,[]),r.get(a).push(i)}return r}var LG=_i(''),IG=_i(''),PG=U('
      ',1),BG=U('
      '),zG=_i(''),jG=U(''),UG=U(''),qG=U(''),WG=_i(''),HG=U(''),GG=U(''),YG=U(''),VG=U('
      '),XG=U('
      '),KG=U('
      '),ZG=U('
      '),JG=U(''),QG=U('
      '),eY=U('
      ',1),tY=U('
      ',1),nY=U(''),rY=U('

      Signed in, but this account does not have write access to this Space.

      '),iY=U('

      Required to delete or rename runs (Space owner or collaborator with write access).

      ',1),sY=U(''),oY=U(''),aY=U(''),lY=U('
      ');function uY(e,t){En(t,!0);let n=oe(t,"open",15,!0),r=oe(t,"variant",3,"full"),i=oe(t,"currentPage",3,"metrics"),s=oe(t,"projects",19,()=>[]),o=oe(t,"selectedProject",15,null),a=oe(t,"runs",19,()=>[]),l=oe(t,"selectedRuns",31,()=>mt([])),u=oe(t,"availableSystemDevices",19,()=>[]),c=oe(t,"selectedSystemDevices",31,()=>mt([])),f=oe(t,"smoothing",15,10),d=oe(t,"xAxis",15,"step"),h=oe(t,"logScaleX",15,!1),p=oe(t,"logScaleY",15,!1),g=oe(t,"metricFilter",15,""),m=oe(t,"realtimeEnabled",15,!0),v=oe(t,"showHeaders",15,!0),b=oe(t,"filterText",15,""),x=oe(t,"runConfigs",19,()=>({})),_=oe(t,"metricColumns",19,()=>[]),w=oe(t,"spacesMode",3,!1),A=oe(t,"runMutationAllowed",3,!0),E=oe(t,"mutationAuth",3,"local"),k=oe(t,"readOnlySource",3,null),S=oe(t,"projectLocked",3,!1),$=oe(t,"spaceId",3,null),M=oe(t,"logoUrls",19,()=>({light:"/static/trackio/trackio_logo_type_light_transparent.png",dark:"/static/trackio/trackio_logo_type_dark_transparent.png"})),O=oe(t,"darkMode",3,!1),P=se(0),T=null;hh(()=>{const X=()=>{tR(P)};return window.addEventListener("popstate",X),()=>{window.removeEventListener("popstate",X),T&&(clearTimeout(T),T=null)}});let F=we(()=>(y(P),`${window.location.origin}/oauth/hf/start`)),R=we(()=>["step","time",..._()]);function z(){n(!n())}function j(X,ke){return X.indeterminate=ke,{update(Fe){X.indeterminate=Fe}}}let q=we(()=>{if(!b()||!b().trim())return a();const X=new Set(lk(a().map(ke=>ke.name),b()));return a().filter(ke=>X.has(ke.name))}),te=we(()=>n0(a())),Y=we(()=>y(q).map(X=>X.id??X.name)),ee=se(null);Bt(()=>{o(),D(ee,null)}),Bt(()=>{y(_e).some(X=>X.value===y(ee))||D(ee,null)});let _e=we(()=>NG(x())),Le=we(()=>OG(y(q),x(),y(ee))),Z=se(!1),he=se("share"),He=se(null);function Ke(){D(Z,!y(Z)),y(Z)&&y(q).length>0?l(p5(y(Y))):y(Z)||l([...y(Y)])}Bt(()=>{if(!y(Z)||y(Y).length===0)return;const X=p5(y(Y));(l().length!==X.length||l()[0]!==X[0])&&l(X)});function de(X){c().includes(X)?c(c().filter(ke=>ke!==X)):c([...c(),X])}function Re(X){if(!X||!X.includes("/"))return"";const[ke,Fe]=X.split("/",2);return!ke||!Fe?"":`${ke}-${Fe}.hf.space`}function Q(){const X=Re($());if(X)return`https://${X}`;const ke=window.__trackio_base||"/",Fe=new URL(ke,window.location.origin);let Ie=Fe.href;return Ie.endsWith("/")&&(Ie=Ie.slice(0,-1)),Ie||Fe.origin}function W(X,ke){const Fe=new Set(ke.map(Ie=>Ie.id??Ie.name));return X.filter(Ie=>Fe.has(Ie))}let L=we(()=>{var ft;if(y(P),i()!=="metrics"||!w()||!o())return"";const X=new URLSearchParams;X.set("project",o()),(ft=g())!=null&&ft.trim()&&X.set("metric_filter",g().trim());const ke=W(l(),a());ke.length&&X.set("run_ids",ke.join(",")),f()!=null&&f()!==10&&X.set("smoothing",f().toString()),v()||X.set("accordion","hidden"),X.set("sidebar","hidden"),X.set("navbar","hidden");const Fe=Q(),Ie=X.toString();return Ie?`${Fe}/?${Ie}`:`${Fe}/`}),H=we(()=>y(L)?``:"");async function ve(X,ke){if(X){try{await navigator.clipboard.writeText(X)}catch{const Fe=document.createElement("textarea");Fe.value=X,Fe.style.position="fixed",Fe.style.opacity="0",document.body.appendChild(Fe),Fe.focus(),Fe.select(),document.execCommand("copy"),document.body.removeChild(Fe)}D(He,ke,!0),T&&clearTimeout(T),T=setTimeout(()=>{D(He,null),T=null},2e3)}}var G=lY();let B;var ie=C(G),qe=C(ie);{var K=X=>{var ke=LG();I(X,ke)},V=X=>{var ke=IG();I(X,ke)};ge(qe,X=>{n()?X(K):X(V,-1)})}var J=N(ie,2);{var ye=X=>{var ke=aY(),Fe=C(ke),Ie=C(Fe),ft=C(Ie),Oe=N(Ie,2),Me=C(Oe);{var Ge=Ve=>{var Xe=PG(),dt=N(Ot(Xe),2),pt=C(dt);xe(()=>be(pt,o()??"—")),I(Ve,Xe)},lt=Ve=>{ex(Ve,{label:"Project",get choices(){return s()},filterable:!0,get value(){return o()},set value(Xe){o(Xe)}})};ge(Me,Ve=>{S()?Ve(Ge):Ve(lt,-1)})}var yt=N(Oe,2);{var Et=Ve=>{var Xe=BG(),dt=C(Xe);tx(dt,{label:"Run Filter",info:"Filter runs using regex patterns. Leave empty to show all runs.",placeholder:"e.g., baseline|exp-.*|v2",get value(){return b()},set value(pt){b(pt)}}),I(Ve,Xe)};ge(yt,Ve=>{r()==="compact"&&i()==="runs"&&Ve(Et)})}var ct=N(yt,2);{var Ut=Ve=>{var Xe=tY(),dt=Ot(Xe);{var pt=Zt=>{var Fn=VG(),Ir=C(Fn),hn=C(Ir);let pn;var Ai=N(hn,2);let ii;var Yn=N(Ir,2);{var Vn=rr=>{var ki=qG(),si=N(C(ki),2);{var gn=yr=>{var br=jG(),bn=C(br),Pr=N(bn,2),Ln=C(Pr);{var kn=xr=>{var Gs=zG();I(xr,Gs)},Ma=xr=>{var Gs=hw("Copy");I(xr,Gs)};ge(Ln,xr=>{y(He)==="share"?xr(kn):xr(Ma,-1)})}xe(()=>{u5(bn,y(L)),xt(Pr,"aria-label",y(He)==="share"?"Copied":"Copy share link")}),Ue("click",Pr,()=>ve(y(L),"share")),I(yr,br)},zu=yr=>{var br=UG();I(yr,br)};ge(si,yr=>{y(L)?yr(gn):yr(zu,-1)})}I(rr,ki)},ms=rr=>{var ki=YG(),si=N(C(ki),2);{var gn=yr=>{var br=HG(),bn=C(br),Pr=N(bn,2),Ln=C(Pr);{var kn=xr=>{var Gs=WG();I(xr,Gs)},Ma=xr=>{var Gs=hw("Copy");I(xr,Gs)};ge(Ln,xr=>{y(He)==="embed"?xr(kn):xr(Ma,-1)})}xe(()=>{u5(bn,y(H)),xt(Pr,"aria-label",y(He)==="embed"?"Copied":"Copy embed code")}),Ue("click",Pr,()=>ve(y(H),"embed")),I(yr,br)},zu=yr=>{var br=GG();I(yr,br)};ge(si,yr=>{y(H)?yr(gn):yr(zu,-1)})}I(rr,ki)};ge(Yn,rr=>{y(he)==="share"?rr(Vn):rr(ms,-1)})}xe(()=>{pn=en(hn,1,"share-tab-btn svelte-181dlmc",null,pn,{active:y(he)==="share"}),ii=en(Ai,1,"share-tab-btn svelte-181dlmc",null,ii,{active:y(he)==="embed"})}),Ue("click",hn,()=>{D(he,"share")}),Ue("click",Ai,()=>{D(he,"embed")}),I(Zt,Fn)};ge(dt,Zt=>{i()==="metrics"&&w()&&Zt(pt)})}var Ct=N(dt,2),le=C(Ct),pe=C(le),et=C(pe);X2(et,(Zt,Fn)=>j==null?void 0:j(Zt,Fn),()=>l().length>0&&l().length{var Fn=KG();wt(Fn,21,()=>[...y(Le).entries()],At,(Ir,hn)=>{var pn=we(()=>VA(y(hn),2));let Ai=()=>y(pn)[0],ii=()=>y(pn)[1];const Yn=we(()=>ii().map(Ln=>Ln.id??Ln.name)),Vn=we(()=>y(Yn).filter(Ln=>l().includes(Ln)));var ms=XG(),rr=C(ms),ki=C(rr),si=C(ki);X2(si,(Ln,kn)=>j==null?void 0:j(Ln,kn),()=>y(Vn).length>0&&y(Vn).lengthii().map(kn=>y(te)[kn.id??kn.name]??mw(Math.max(0,a().indexOf(kn)))));h5(Pr,{get choices(){return ii()},getKey:kn=>kn.id??kn.name,getLabel:kn=>kn.name,get colors(){return y(Ln)},ontoggle:()=>{D(Z,!1)},get selected(){return l()},set selected(kn){l(kn)}})}xe(()=>{Gf(si,y(Vn).length===y(Yn).length&&y(Yn).length>0),xt(gn,"title",Ai()),be(zu,Ai()),be(br,`(${ii().length??""})`)}),Ue("change",si,()=>{if(y(Vn).length===y(Yn).length)l(l().filter(Ln=>!y(Yn).includes(Ln)));else{const Ln=y(Yn).filter(kn=>!l().includes(kn));l([...l(),...Ln])}D(Z,!1)}),I(Ir,ms)}),I(Zt,Fn)},Or=Zt=>{var Fn=ZG(),Ir=C(Fn);{let hn=we(()=>y(q).map(pn=>y(te)[pn.id??pn.name]??mw(Math.max(0,a().indexOf(pn)))));h5(Ir,{get choices(){return y(q)},getKey:pn=>pn.id??pn.name,getLabel:pn=>pn.name,get colors(){return y(hn)},ontoggle:()=>{D(Z,!1)},get selected(){return l()},set selected(pn){l(pn)}})}I(Zt,Fn)};ge(Rt,Zt=>{y(Le)?Zt(bt):Zt(Or,-1)})}var ri=N(Rt,2);{var Lr=Zt=>{var Fn=QG(),Ir=C(Fn),hn=C(Ir);X2(hn,(Yn,Vn)=>j==null?void 0:j(Yn,Vn),()=>c().length>0&&c().length{var ms=JG(),rr=C(ms),ki=N(rr,2),si=C(ki);xe(gn=>{Gf(rr,gn),xt(ki,"title",y(Vn)),be(si,y(Vn))},[()=>c().includes(y(Vn))]),Ue("change",rr,()=>de(y(Vn))),I(Yn,ms)}),xe(()=>{Gf(hn,c().length===u().length&&u().length>0),be(Ai,`Devices (${u().length??""})`)}),Ue("change",hn,()=>{c().length===u().length?c([]):c([...u()])}),I(Zt,Fn)};ge(ri,Zt=>{i()==="system"&&u().length>0&&Zt(Lr)})}var Vi=N(Ct,2);{var Hs=Zt=>{var Fn=eY(),Ir=N(Ot(Fn),2),hn=C(Ir);rm(hn,{label:"Refresh metrics realtime",get checked(){return m()},set checked(gn){m(gn)}});var pn=N(hn,2);rm(pn,{label:"Show section headers",get checked(){return v()},set checked(gn){v(gn)}});var Ai=N(Ir,2),ii=C(Ai);_G(ii,{label:"Smoothing Factor (0 = no smoothing)",min:0,max:20,step:1,get value(){return f()},set value(gn){f(gn)}});var Yn=N(Ai,2),Vn=C(Yn);ex(Vn,{label:"X-axis",get choices(){return y(R)},filterable:!1,get value(){return d()},set value(gn){d(gn)}});var ms=N(Vn,2);rm(ms,{label:"Log scale X-axis",get checked(){return h()},set checked(gn){h(gn)}});var rr=N(ms,2);rm(rr,{label:"Log scale Y-axis",get checked(){return p()},set checked(gn){p(gn)}});var ki=N(Yn,2),si=C(ki);tx(si,{label:"Metric Filter",info:"Filter metrics using regex patterns. Leave empty to show all metrics.",placeholder:"e.g., loss|ndcg@10|gpu",get value(){return g()},set value(gn){g(gn)}}),I(Zt,Fn)};ge(Vi,Zt=>{(i()==="metrics"||i()==="system")&&Zt(Hs)})}xe(()=>{Gf(et,l().length===y(Y).length&&y(Y).length>0),be(nt,`Runs (${y(Y).length??""})`),Gf(Xt,y(Z))}),Ue("change",et,()=>{l().length===y(Y).length?l([]):l([...y(Y)]),D(Z,!1)}),Ue("change",Xt,Ke),I(Ve,Xe)};ge(ct,Ve=>{r()==="full"&&Ve(Ut)})}var me=N(Fe,2);{var Ee=Ve=>{var Xe=nY(),dt=N(C(Xe),2),pt=C(dt);xe(()=>{xt(dt,"href",k().url),be(pt,k().url)}),I(Ve,Xe)},Ye=Ve=>{var Xe=sY(),dt=C(Xe);{var pt=le=>{var pe=rY();I(le,pe)},Ct=le=>{var pe=iY(),et=Ot(pe);xe(()=>xt(et,"href",y(F))),I(le,pe)};ge(dt,le=>{E()==="oauth_insufficient"?le(pt):le(Ct,-1)})}I(Ve,Xe)},ht=Ve=>{var Xe=oY(),dt=N(C(Xe),2);Ue("click",dt,()=>{sessionStorage.removeItem("trackio_oauth_session")}),I(Ve,Xe)};ge(me,Ve=>{k()?Ve(Ee):w()&&!A()?Ve(Ye,1):w()&&A()&&E()==="oauth"&&Ve(ht,2)})}xe(()=>xt(ft,"src",O()?M().dark:M().light)),I(X,ke)};ge(J,X=>{n()&&X(ye)})}xe(()=>B=en(G,1,"sidebar svelte-181dlmc",null,B,{collapsed:!n()})),Ue("click",ie,z),I(e,G),An()}ni(["click","change"]);var cY=U('
      '),fY=U('
      '),dY=U('
      '),hY=U('
      '),pY=U('
      ');function gY(e,t){En(t,!0);let n=oe(t,"alerts",19,()=>[]);const r={info:"🔵",warn:"🟡",error:"🔴"};let i=se(mt({})),s=se(null),o=se(!1),a=we(()=>y(s)?n().filter(d=>d.level===y(s)):n());function l(d){D(i,{...y(i),[d]:!y(i)[d]},!0)}var u=Ri(),c=Ot(u);{var f=d=>{var h=pY();let p;var g=C(h),m=C(g),v=C(m),b=N(m,2);{var x=k=>{var S=cY(),$=C(S);let M;var O=N($,2);let P;var T=N(O,2);let F;var R=N(T,2);let z;xe(()=>{M=en($,1,"pill svelte-x5aqew",null,M,{active:y(s)===null}),P=en(O,1,"pill svelte-x5aqew",null,P,{active:y(s)==="info"}),F=en(T,1,"pill svelte-x5aqew",null,F,{active:y(s)==="warn"}),z=en(R,1,"pill svelte-x5aqew",null,z,{active:y(s)==="error"})}),Ue("click",$,j=>{j.stopPropagation(),D(s,null)}),Ue("click",O,j=>{j.stopPropagation(),D(s,"info")}),Ue("click",T,j=>{j.stopPropagation(),D(s,"warn")}),Ue("click",R,j=>{j.stopPropagation(),D(s,"error")}),I(k,S)};ge(b,k=>{y(o)||k(x)})}var _=N(b,2);let w;var A=N(g,2);{var E=k=>{var S=hY();wt(S,21,()=>y(a),At,($,M,O)=>{var P=dY();let T;var F=C(P),R=C(F),z=C(R),j=N(R,2),q=C(j),te=N(j,2),Y=C(te),ee=N(F,2);{var _e=Le=>{var Z=fY(),he=C(Z);xe(()=>be(he,y(M).text)),I(Le,Z)};ge(ee,Le=>{y(i)[O]&&y(M).text&&Le(_e)})}xe(()=>{T=en(P,1,"alert-item svelte-x5aqew",null,T,{expanded:y(i)[O]}),be(z,r[y(M).level]||""),be(q,y(M).title),be(Y,y(M).meta||"")}),Ue("click",F,()=>l(O)),I($,P)}),I(k,S)};ge(A,k=>{y(o)||k(E)})}xe(()=>{p=en(h,1,"alert-panel svelte-x5aqew",null,p,{collapsed:y(o)}),be(v,`Alerts (${n().length??""})`),w=en(_,0,"collapse-icon svelte-x5aqew",null,w,{rotated:y(o)})}),Ue("click",g,()=>D(o,!y(o))),Ue("keydown",g,k=>k.key==="Enter"&&D(o,!y(o))),I(d,h)};ge(c,d=>{n().length>0&&d(f)})}I(e,u),An()}ni(["click","keydown"]);function v5(){const e=window.location.pathname.replace(/\/+$/,"")||"/";switch(e==="/"?"":e.replace(/^\//,"").split("/")[0]){case"":case"metrics":return"metrics";case"system":return"system";case"traces":return"traces";case"media":return"media";case"reports":return"reports";case"runs":return"runs";case"run":return"run-detail";case"files":return"files";case"settings":return"settings";default:return"metrics"}}function vw(e){const t=new URLSearchParams(window.location.search),r={metrics:"/",traces:"/traces",system:"/system",media:"/media",reports:"/reports",runs:"/runs","run-detail":"/run",files:"/files",settings:"/settings"}[e]||"/",i=t.toString(),s=i?`${r}?${i}`:r;window.history.pushState({},"",s),window.dispatchEvent(new PopStateEvent("popstate"))}function $i(e){return new URLSearchParams(window.location.search).get(e)}function y5(e,t){const n=new URLSearchParams(window.location.search);t!=null&&t!==""?n.set(e,t):n.delete(e);const r=n.toString(),i=r?`${window.location.pathname}?${r}`:window.location.pathname;window.history.replaceState({},"",i)}const mY=/("(?:[^\\"]|\\.)*")|[:,]/g;function nx(e,t={}){const n=JSON.stringify([1],void 0,t.indent===void 0?2:t.indent).slice(2,-3),r=n===""?1/0:t.maxLength===void 0?80:t.maxLength;let{replacer:i}=t;return(function s(o,a,l){o&&typeof o.toJSON=="function"&&(o=o.toJSON());const u=JSON.stringify(o,i);if(u===void 0)return u;const c=r-a.length-l;if(u.length<=c){const f=u.replace(mY,(d,h)=>h||`${d} `);if(f.length<=c)return f}if(i!=null&&(o=JSON.parse(u),i=void 0),typeof o=="object"&&o!==null){const f=a+n,d=[];let h=0,p,g;if(Array.isArray(o)){p="[",g="]";const{length:m}=o;for(;h0)return[p,n+d.join(`, +${f}`),g].join(` +${a}`)}return u})(e,"",0)}function Gi(e,t,n){return e.fields=t||[],e.fname=n,e}function On(e){return e==null?null:e.fname}function Yr(e){return e==null?null:e.fields}function RR(e){return e.length===1?vY(e[0]):yY(e)}const vY=e=>function(t){return t[e]},yY=e=>{const t=e.length;return function(n){for(let r=0;ro?u():o=a+1:l==="["?(a>o&&u(),i=o=a+1):l==="]"&&(i||ae("Access path missing open bracket: "+e),i>0&&u(),i=0,o=a+1)}return i&&ae("Access path missing closing bracket: "+e),r&&ae("Access path missing closing quote: "+e),a>o&&(a++,u()),t}function Os(e,t,n){const r=va(e);return e=r.length===1?r[0]:e,Gi((n&&n.get||RR)(r),[e],t||e)}const r0=Os("id"),Qr=Gi(e=>e,[],"identity"),Ol=Gi(()=>0,[],"zero"),ph=Gi(()=>1,[],"one"),fs=Gi(()=>!0,[],"true"),Cl=Gi(()=>!1,[],"false"),uk=new Set(Object.getOwnPropertyNames(Object.prototype));function bY(e,t,n){const r=[t].concat([].slice.call(n));console[e].apply(console,r)}const NR=0,ck=1,fk=2,OR=3,LR=4;function dk(e,t){let n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:bY,r=e||NR;return{level(i){return arguments.length?(r=+i,this):r},error(){return r>=ck&&n(t||"error","ERROR",arguments),this},warn(){return r>=fk&&n(t||"warn","WARN",arguments),this},info(){return r>=OR&&n(t||"log","INFO",arguments),this},debug(){return r>=LR&&n(t||"log","DEBUG",arguments),this}}}var fe=Array.isArray;function Pe(e){return e===Object(e)}const b5=e=>e!=="__proto__";function gh(){for(var e=arguments.length,t=new Array(e),n=0;n{for(const s in i)if(s==="signals")r.signals=xY(r.signals,i.signals);else{const o=s==="legend"?{layout:1}:s==="style"?!0:null;mh(r,s,i[s],o)}return r},{})}function mh(e,t,n,r){if(!b5(t))return;let i,s;if(Pe(n)&&!fe(n)){s=Pe(e[t])?e[t]:e[t]={};for(i in n)r&&(r===!0||r[i])?mh(s,i,n[i]):b5(i)&&(s[i]=n[i])}else e[t]=n}function xY(e,t){if(e==null)return t;const n={},r=[];function i(s){n[s.name]||(n[s.name]=1,r.push(s))}return t.forEach(i),e.forEach(i),r}function jt(e){return e[e.length-1]}function Hr(e){return e==null||e===""?null:+e}const IR=e=>t=>e*Math.exp(t),PR=e=>t=>Math.log(e*t),BR=e=>t=>Math.sign(t)*Math.log1p(Math.abs(t/e)),zR=e=>t=>Math.sign(t)*Math.expm1(Math.abs(t))*e,B1=e=>t=>t<0?-Math.pow(-t,e):Math.pow(t,e);function $y(e,t,n,r){const i=n(e[0]),s=n(jt(e)),o=(s-i)*t;return[r(i-o),r(s-o)]}function jR(e,t){return $y(e,t,Hr,Qr)}function UR(e,t){var n=Math.sign(e[0]);return $y(e,t,PR(n),IR(n))}function qR(e,t,n){return $y(e,t,B1(n),B1(1/n))}function WR(e,t,n){return $y(e,t,BR(n),zR(n))}function Fy(e,t,n,r,i){const s=r(e[0]),o=r(jt(e)),a=t!=null?r(t):(s+o)/2;return[i(a+(s-a)*n),i(a+(o-a)*n)]}function hk(e,t,n){return Fy(e,t,n,Hr,Qr)}function pk(e,t,n){const r=Math.sign(e[0]);return Fy(e,t,n,PR(r),IR(r))}function z1(e,t,n,r){return Fy(e,t,n,B1(r),B1(1/r))}function gk(e,t,n,r){return Fy(e,t,n,BR(r),zR(r))}function HR(e){return 1+~~(new Date(e).getMonth()/3)}function GR(e){return 1+~~(new Date(e).getUTCMonth()/3)}function je(e){return e!=null?fe(e)?e:[e]:[]}function YR(e,t,n){let r=e[0],i=e[1],s;return i=n-t?[t,n]:[r=Math.min(Math.max(r,t),n-s),r+s]}function St(e){return typeof e=="function"}const _Y="descending";function mk(e,t,n){n=n||{},t=je(t)||[];const r=[],i=[],s={},o=n.comparator||wY;return je(e).forEach((a,l)=>{a!=null&&(r.push(t[l]===_Y?-1:1),i.push(a=St(a)?a:Os(a,null,n)),(Yr(a)||[]).forEach(u=>s[u]=1))}),i.length===0?null:Gi(o(i,r),Object.keys(s))}const vh=(e,t)=>(et||t==null)&&e!=null?1:(t=t instanceof Date?+t:t,(e=e instanceof Date?+e:e)!==e&&t===t?-1:t!==t&&e===e?1:0),wY=(e,t)=>e.length===1?EY(e[0],t[0]):AY(e,t,e.length),EY=(e,t)=>function(n,r){return vh(e(n),e(r))*t},AY=(e,t,n)=>(t.push(0),function(r,i){let s,o=0,a=-1;for(;o===0&&++ae}function vk(e,t){let n;return r=>{n&&clearTimeout(n),n=setTimeout(()=>(t(r),n=null),e)}}function kt(e){for(let t,n,r=1,i=arguments.length;ro&&(o=i))}else{for(i=t(e[n]);no&&(o=i))}return[s,o]}function VR(e,t){const n=e.length;let r=-1,i,s,o,a,l;if(t==null){for(;++r=s){i=o=s;break}if(r===n)return[-1,-1];for(a=l=r;++rs&&(i=s,a=r),o=s){i=o=s;break}if(r===n)return[-1,-1];for(a=l=r;++rs&&(i=s,a=r),o{i.set(s,e[s])}),i}function XR(e,t,n,r,i,s){if(!n&&n!==0)return s;const o=+n;let a=e[0],l=jt(e),u;ls&&(o=i,i=s,s=o),n=n===void 0||n,r=r===void 0||r,(n?i<=e:ia.replace(/\\(.)/g,"$1")):je(e));const r=e&&e.length,i=n&&n.get||RR,s=a=>i(t?[a]:va(a));let o;if(!r)o=function(){return""};else if(r===1){const a=s(e[0]);o=function(l){return""+a(l)}}else{const a=e.map(s);o=function(l){let u=""+a[0](l),c=0;for(;++c{t={},n={},r=0},s=(o,a)=>(++r>e&&(n=t,t={},r=1),t[o]=a);return i(),{clear:i,has:o=>We(t,o)||We(n,o),get:o=>We(t,o)?t[o]:We(n,o)?s(o,n[o]):void 0,set:(o,a)=>We(t,o)?t[o]=a:s(o,a)}}function QR(e,t,n,r){const i=t.length,s=n.length;if(!s)return t;if(!i)return n;const o=r||new t.constructor(i+s);let a=0,l=0,u=0;for(;a0?n[l++]:t[a++];for(;a=0;)n+=e;return n}function eN(e,t,n,r){const i=n||" ",s=e+"",o=t-s.length;return o<=0?s:r==="left"?vp(i,o)+s:r==="center"?vp(i,~~(o/2))+s+vp(i,Math.ceil(o/2)):s+vp(i,o)}function i0(e){return e&&jt(e)-e[0]||0}function De(e){return fe(e)?"["+e.map(De)+"]":Pe(e)||ze(e)?JSON.stringify(e).replace("\u2028","\\u2028").replace("\u2029","\\u2029"):e}function xk(e){return e==null||e===""?null:!e||e==="false"||e==="0"?!1:!!e}const SY=e=>Gt(e)||Zl(e)?e:Date.parse(e);function _k(e,t){return t=t||SY,e==null||e===""?null:t(e)}function wk(e){return e==null||e===""?null:e+""}function mo(e){const t={},n=e.length;for(let r=0;r9999?"+"+Si(e,6):Si(e,4)}function FY(e){var t=e.getUTCHours(),n=e.getUTCMinutes(),r=e.getUTCSeconds(),i=e.getUTCMilliseconds();return isNaN(e)?"Invalid Date":$Y(e.getUTCFullYear())+"-"+Si(e.getUTCMonth()+1,2)+"-"+Si(e.getUTCDate(),2)+(i?"T"+Si(t,2)+":"+Si(n,2)+":"+Si(r,2)+"."+Si(i,3)+"Z":r?"T"+Si(t,2)+":"+Si(n,2)+":"+Si(r,2)+"Z":n||t?"T"+Si(t,2)+":"+Si(n,2)+"Z":"")}function DY(e){var t=new RegExp('["'+e+` +\r]`),n=e.charCodeAt(0);function r(f,d){var h,p,g=i(f,function(m,v){if(h)return h(m,v-1);p=m,h=d?CY(m,d):nN(m)});return g.columns=p||[],g}function i(f,d){var h=[],p=f.length,g=0,m=0,v,b=p<=0,x=!1;f.charCodeAt(p-1)===Hh&&--p,f.charCodeAt(p-1)===sx&&--p;function _(){if(b)return rx;if(x)return x=!1,x5;var A,E=g,k;if(f.charCodeAt(E)===ix){for(;g++=p?b=!0:(k=f.charCodeAt(g++))===Hh?x=!0:k===sx&&(x=!0,f.charCodeAt(g)===Hh&&++g),f.slice(E+1,A-1).replace(/""/g,'"')}for(;g1)r=PY(e,t,n);else for(i=0,r=new Array(s=e.arcs.length);it?1:e>=t?0:NaN}function BY(e,t){return e==null||t==null?NaN:te?1:t>=e?0:NaN}function bh(e){let t,n,r;e.length!==2?(t=Qa,n=(a,l)=>Qa(e(a),l),r=(a,l)=>e(a)-l):(t=e===Qa||e===BY?e:zY,n=e,r=e);function i(a,l,u=0,c=a.length){if(u>>1;n(a[f],l)<0?u=f+1:c=f}while(u>>1;n(a[f],l)<=0?u=f+1:c=f}while(uu&&r(a[f-1],l)>-r(a[f],l)?f-1:f}return{left:i,center:o,right:s}}function zY(){return 0}function iN(e){return e===null?NaN:+e}function*jY(e,t){if(t===void 0)for(let n of e)n!=null&&(n=+n)>=n&&(yield n);else{let n=-1;for(let r of e)(r=t(r,++n,e))!=null&&(r=+r)>=r&&(yield r)}}const sN=bh(Qa),iu=sN.right,UY=sN.left;bh(iN).center;function qY(e,t){let n=0,r,i=0,s=0;if(t===void 0)for(let o of e)o!=null&&(o=+o)>=o&&(r=o-i,i+=r/++n,s+=r*(o-i));else{let o=-1;for(let a of e)(a=t(a,++o,e))!=null&&(a=+a)>=a&&(r=a-i,i+=r/++n,s+=r*(a-i))}if(n>1)return s/(n-1)}function WY(e,t){const n=qY(e,t);return n&&Math.sqrt(n)}class mi{constructor(){this._partials=new Float64Array(32),this._n=0}add(t){const n=this._partials;let r=0;for(let i=0;i0){for(o=t[--n];n>0&&(r=o,i=t[--n],o=r+i,s=i-(o-r),!s););n>0&&(s<0&&t[n-1]<0||s>0&&t[n-1]>0)&&(i=s*2,r=o+i,i==r-o&&(o=r))}return o}}class E5 extends Map{constructor(t,n=lN){if(super(),Object.defineProperties(this,{_intern:{value:new Map},_key:{value:n}}),t!=null)for(const[r,i]of t)this.set(r,i)}get(t){return super.get(yw(this,t))}has(t){return super.has(yw(this,t))}set(t,n){return super.set(oN(this,t),n)}delete(t){return super.delete(aN(this,t))}}class j1 extends Set{constructor(t,n=lN){if(super(),Object.defineProperties(this,{_intern:{value:new Map},_key:{value:n}}),t!=null)for(const r of t)this.add(r)}has(t){return super.has(yw(this,t))}add(t){return super.add(oN(this,t))}delete(t){return super.delete(aN(this,t))}}function yw({_intern:e,_key:t},n){const r=t(n);return e.has(r)?e.get(r):n}function oN({_intern:e,_key:t},n){const r=t(n);return e.has(r)?e.get(r):(e.set(r,n),n)}function aN({_intern:e,_key:t},n){const r=t(n);return e.has(r)&&(n=e.get(r),e.delete(r)),n}function lN(e){return e!==null&&typeof e=="object"?e.valueOf():e}function HY(e,t){return Array.from(t,n=>e[n])}function GY(e=Qa){if(e===Qa)return uN;if(typeof e!="function")throw new TypeError("compare is not a function");return(t,n)=>{const r=e(t,n);return r||r===0?r:(e(n,n)===0)-(e(t,t)===0)}}function uN(e,t){return(e==null||!(e>=e))-(t==null||!(t>=t))||(et?1:0)}const YY=Math.sqrt(50),VY=Math.sqrt(10),XY=Math.sqrt(2);function U1(e,t,n){const r=(t-e)/Math.max(0,n),i=Math.floor(Math.log10(r)),s=r/Math.pow(10,i),o=s>=YY?10:s>=VY?5:s>=XY?2:1;let a,l,u;return i<0?(u=Math.pow(10,-i)/o,a=Math.round(e*u),l=Math.round(t*u),a/ut&&--l,u=-u):(u=Math.pow(10,i)*o,a=Math.round(e/u),l=Math.round(t/u),a*ut&&--l),l0))return[];if(e===t)return[e];const r=t=i))return[];const a=s-i+1,l=new Array(a);if(r)if(o<0)for(let u=0;u=r)&&(n=r);else{let r=-1;for(let i of e)(i=t(i,++r,e))!=null&&(n=i)&&(n=i)}return n}function _w(e,t){let n;if(t===void 0)for(const r of e)r!=null&&(n>r||n===void 0&&r>=r)&&(n=r);else{let r=-1;for(let i of e)(i=t(i,++r,e))!=null&&(n>i||n===void 0&&i>=i)&&(n=i)}return n}function cN(e,t,n=0,r=1/0,i){if(t=Math.floor(t),n=Math.floor(Math.max(0,n)),r=Math.floor(Math.min(e.length-1,r)),!(n<=t&&t<=r))return e;for(i=i===void 0?uN:GY(i);r>n;){if(r-n>600){const l=r-n+1,u=t-n+1,c=Math.log(l),f=.5*Math.exp(2*c/3),d=.5*Math.sqrt(c*f*(l-f)/l)*(u-l/2<0?-1:1),h=Math.max(n,Math.floor(t-u*f/l+d)),p=Math.min(r,Math.floor(t+(l-u)*f/l+d));cN(e,t,h,p,i)}const s=e[t];let o=n,a=r;for(Gh(e,n,t),i(e[r],s)>0&&Gh(e,n,r);o0;)--a}i(e[n],s)===0?Gh(e,n,a):(++a,Gh(e,a,r)),a<=t&&(n=a+1),t<=a&&(r=a-1)}return e}function Gh(e,t,n){const r=e[t];e[t]=e[n],e[n]=r}function ww(e,t,n){if(e=Float64Array.from(jY(e,n)),!(!(r=e.length)||isNaN(t=+t))){if(t<=0||r<2)return _w(e);if(t>=1)return wc(e);var r,i=(r-1)*t,s=Math.floor(i),o=wc(cN(e,s).subarray(0,s+1)),a=_w(e.subarray(s+1));return o+(a-o)*(i-s)}}function fN(e,t,n=iN){if(!(!(r=e.length)||isNaN(t=+t))){if(t<=0||r<2)return+n(e[0],0,e);if(t>=1)return+n(e[r-1],r-1,e);var r,i=(r-1)*t,s=Math.floor(i),o=+n(e[s],s,e),a=+n(e[s+1],s+1,e);return o+(a-o)*(i-s)}}function KY(e,t){let n=0,r=0;if(t===void 0)for(let i of e)i!=null&&(i=+i)>=i&&(++n,r+=i);else{let i=-1;for(let s of e)(s=t(s,++i,e))!=null&&(s=+s)>=s&&(++n,r+=s)}if(n)return r/n}function dN(e,t){return ww(e,.5,t)}function*ZY(e){for(const t of e)yield*t}function hN(e){return Array.from(ZY(e))}function is(e,t,n){e=+e,t=+t,n=(i=arguments.length)<2?(t=e,e=0,1):i<3?1:+n;for(var r=-1,i=Math.max(0,Math.ceil((t-e)/n))|0,s=new Array(i);++r=1e21?e.toLocaleString("en").replace(/,/g,""):e.toString(10)}function q1(e,t){if(!isFinite(e)||e===0)return null;var n=(e=t?e.toExponential(t-1):e.toExponential()).indexOf("e"),r=e.slice(0,n);return[r.length>1?r[0]+r.slice(2):r,+e.slice(n+1)]}function Dd(e){return e=q1(Math.abs(e)),e?e[1]:NaN}function nV(e,t){return function(n,r){for(var i=n.length,s=[],o=0,a=e[0],l=0;i>0&&a>0&&(l+a+1>r&&(a=Math.max(1,r-l)),s.push(n.substring(i-=a,i+a)),!((l+=a+1)>r));)a=e[o=(o+1)%e.length];return s.reverse().join(t)}}function rV(e){return function(t){return t.replace(/[0-9]/g,function(n){return e[+n]})}}var iV=/^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;function zc(e){if(!(t=iV.exec(e)))throw new Error("invalid format: "+e);var t;return new Ek({fill:t[1],align:t[2],sign:t[3],symbol:t[4],zero:t[5],width:t[6],comma:t[7],precision:t[8]&&t[8].slice(1),trim:t[9],type:t[10]})}zc.prototype=Ek.prototype;function Ek(e){this.fill=e.fill===void 0?" ":e.fill+"",this.align=e.align===void 0?">":e.align+"",this.sign=e.sign===void 0?"-":e.sign+"",this.symbol=e.symbol===void 0?"":e.symbol+"",this.zero=!!e.zero,this.width=e.width===void 0?void 0:+e.width,this.comma=!!e.comma,this.precision=e.precision===void 0?void 0:+e.precision,this.trim=!!e.trim,this.type=e.type===void 0?"":e.type+""}Ek.prototype.toString=function(){return this.fill+this.align+this.sign+this.symbol+(this.zero?"0":"")+(this.width===void 0?"":Math.max(1,this.width|0))+(this.comma?",":"")+(this.precision===void 0?"":"."+Math.max(0,this.precision|0))+(this.trim?"~":"")+this.type};function sV(e){e:for(var t=e.length,n=1,r=-1,i;n0&&(r=0);break}return r>0?e.slice(0,r)+e.slice(i+1):e}var W1;function oV(e,t){var n=q1(e,t);if(!n)return W1=void 0,e.toPrecision(t);var r=n[0],i=n[1],s=i-(W1=Math.max(-8,Math.min(8,Math.floor(i/3)))*3)+1,o=r.length;return s===o?r:s>o?r+new Array(s-o+1).join("0"):s>0?r.slice(0,s)+"."+r.slice(s):"0."+new Array(1-s).join("0")+q1(e,Math.max(0,t+s-1))[0]}function A5(e,t){var n=q1(e,t);if(!n)return e+"";var r=n[0],i=n[1];return i<0?"0."+new Array(-i).join("0")+r:r.length>i+1?r.slice(0,i+1)+"."+r.slice(i+1):r+new Array(i-r.length+2).join("0")}const k5={"%":(e,t)=>(e*100).toFixed(t),b:e=>Math.round(e).toString(2),c:e=>e+"",d:tV,e:(e,t)=>e.toExponential(t),f:(e,t)=>e.toFixed(t),g:(e,t)=>e.toPrecision(t),o:e=>Math.round(e).toString(8),p:(e,t)=>A5(e*100,t),r:A5,s:oV,X:e=>Math.round(e).toString(16).toUpperCase(),x:e=>Math.round(e).toString(16)};function S5(e){return e}var C5=Array.prototype.map,$5=["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"];function gN(e){var t=e.grouping===void 0||e.thousands===void 0?S5:nV(C5.call(e.grouping,Number),e.thousands+""),n=e.currency===void 0?"":e.currency[0]+"",r=e.currency===void 0?"":e.currency[1]+"",i=e.decimal===void 0?".":e.decimal+"",s=e.numerals===void 0?S5:rV(C5.call(e.numerals,String)),o=e.percent===void 0?"%":e.percent+"",a=e.minus===void 0?"−":e.minus+"",l=e.nan===void 0?"NaN":e.nan+"";function u(f,d){f=zc(f);var h=f.fill,p=f.align,g=f.sign,m=f.symbol,v=f.zero,b=f.width,x=f.comma,_=f.precision,w=f.trim,A=f.type;A==="n"?(x=!0,A="g"):k5[A]||(_===void 0&&(_=12),w=!0,A="g"),(v||h==="0"&&p==="=")&&(v=!0,h="0",p="=");var E=(d&&d.prefix!==void 0?d.prefix:"")+(m==="$"?n:m==="#"&&/[boxX]/.test(A)?"0"+A.toLowerCase():""),k=(m==="$"?r:/[%p]/.test(A)?o:"")+(d&&d.suffix!==void 0?d.suffix:""),S=k5[A],$=/[defgprs%]/.test(A);_=_===void 0?6:/[gprs]/.test(A)?Math.max(1,Math.min(21,_)):Math.max(0,Math.min(20,_));function M(O){var P=E,T=k,F,R,z;if(A==="c")T=S(O)+T,O="";else{O=+O;var j=O<0||1/O<0;if(O=isNaN(O)?l:S(Math.abs(O),_),w&&(O=sV(O)),j&&+O==0&&g!=="+"&&(j=!1),P=(j?g==="("?g:a:g==="-"||g==="("?"":g)+P,T=(A==="s"&&!isNaN(O)&&W1!==void 0?$5[8+W1/3]:"")+T+(j&&g==="("?")":""),$){for(F=-1,R=O.length;++Fz||z>57){T=(z===46?i+O.slice(F+1):O.slice(F))+T,O=O.slice(0,F);break}}}x&&!v&&(O=t(O,1/0));var q=P.length+O.length+T.length,te=q>1)+P+O+T+te.slice(q);break;default:O=te+P+O+T;break}return s(O)}return M.toString=function(){return f+""},M}function c(f,d){var h=Math.max(-8,Math.min(8,Math.floor(Dd(d)/3)))*3,p=Math.pow(10,-h),g=u((f=zc(f),f.type="f",f),{suffix:$5[8+h/3]});return function(m){return g(p*m)}}return{format:u,formatPrefix:c}}var sm,Dy,Ak;aV({thousands:",",grouping:[3],currency:["$",""]});function aV(e){return sm=gN(e),Dy=sm.format,Ak=sm.formatPrefix,sm}function mN(e){return Math.max(0,-Dd(Math.abs(e)))}function vN(e,t){return Math.max(0,Math.max(-8,Math.min(8,Math.floor(Dd(t)/3)))*3-Dd(Math.abs(e)))}function yN(e,t){return e=Math.abs(e),t=Math.abs(t)-e,Math.max(0,Dd(t)-Dd(e))+1}const ox=new Date,ax=new Date;function tr(e,t,n,r){function i(s){return e(s=arguments.length===0?new Date:new Date(+s)),s}return i.floor=s=>(e(s=new Date(+s)),s),i.ceil=s=>(e(s=new Date(s-1)),t(s,1),e(s),s),i.round=s=>{const o=i(s),a=i.ceil(s);return s-o(t(s=new Date(+s),o==null?1:Math.floor(o)),s),i.range=(s,o,a)=>{const l=[];if(s=i.ceil(s),a=a==null?1:Math.floor(a),!(s0))return l;let u;do l.push(u=new Date(+s)),t(s,a),e(s);while(utr(o=>{if(o>=o)for(;e(o),!s(o);)o.setTime(o-1)},(o,a)=>{if(o>=o)if(a<0)for(;++a<=0;)for(;t(o,-1),!s(o););else for(;--a>=0;)for(;t(o,1),!s(o););}),n&&(i.count=(s,o)=>(ox.setTime(+s),ax.setTime(+o),e(ox),e(ax),Math.floor(n(ox,ax))),i.every=s=>(s=Math.floor(s),!isFinite(s)||!(s>0)?null:s>1?i.filter(r?o=>r(o)%s===0:o=>i.count(0,o)%s===0):i)),i}const Md=tr(()=>{},(e,t)=>{e.setTime(+e+t)},(e,t)=>t-e);Md.every=e=>(e=Math.floor(e),!isFinite(e)||!(e>0)?null:e>1?tr(t=>{t.setTime(Math.floor(t/e)*e)},(t,n)=>{t.setTime(+t+n*e)},(t,n)=>(n-t)/e):Md);Md.range;const Ha=1e3,ks=Ha*60,Ga=ks*60,ul=Ga*24,kk=ul*7,F5=ul*30,lx=ul*365,Ya=tr(e=>{e.setTime(e-e.getMilliseconds())},(e,t)=>{e.setTime(+e+t*Ha)},(e,t)=>(t-e)/Ha,e=>e.getUTCSeconds());Ya.range;const My=tr(e=>{e.setTime(e-e.getMilliseconds()-e.getSeconds()*Ha)},(e,t)=>{e.setTime(+e+t*ks)},(e,t)=>(t-e)/ks,e=>e.getMinutes());My.range;const Ty=tr(e=>{e.setUTCSeconds(0,0)},(e,t)=>{e.setTime(+e+t*ks)},(e,t)=>(t-e)/ks,e=>e.getUTCMinutes());Ty.range;const Ry=tr(e=>{e.setTime(e-e.getMilliseconds()-e.getSeconds()*Ha-e.getMinutes()*ks)},(e,t)=>{e.setTime(+e+t*Ga)},(e,t)=>(t-e)/Ga,e=>e.getHours());Ry.range;const Ny=tr(e=>{e.setUTCMinutes(0,0,0)},(e,t)=>{e.setTime(+e+t*Ga)},(e,t)=>(t-e)/Ga,e=>e.getUTCHours());Ny.range;const el=tr(e=>e.setHours(0,0,0,0),(e,t)=>e.setDate(e.getDate()+t),(e,t)=>(t-e-(t.getTimezoneOffset()-e.getTimezoneOffset())*ks)/ul,e=>e.getDate()-1);el.range;const Jl=tr(e=>{e.setUTCHours(0,0,0,0)},(e,t)=>{e.setUTCDate(e.getUTCDate()+t)},(e,t)=>(t-e)/ul,e=>e.getUTCDate()-1);Jl.range;const bN=tr(e=>{e.setUTCHours(0,0,0,0)},(e,t)=>{e.setUTCDate(e.getUTCDate()+t)},(e,t)=>(t-e)/ul,e=>Math.floor(e/ul));bN.range;function df(e){return tr(t=>{t.setDate(t.getDate()-(t.getDay()+7-e)%7),t.setHours(0,0,0,0)},(t,n)=>{t.setDate(t.getDate()+n*7)},(t,n)=>(n-t-(n.getTimezoneOffset()-t.getTimezoneOffset())*ks)/kk)}const xh=df(0),H1=df(1),lV=df(2),uV=df(3),Td=df(4),cV=df(5),fV=df(6);xh.range;H1.range;lV.range;uV.range;Td.range;cV.range;fV.range;function hf(e){return tr(t=>{t.setUTCDate(t.getUTCDate()-(t.getUTCDay()+7-e)%7),t.setUTCHours(0,0,0,0)},(t,n)=>{t.setUTCDate(t.getUTCDate()+n*7)},(t,n)=>(n-t)/kk)}const _h=hf(0),G1=hf(1),dV=hf(2),hV=hf(3),Rd=hf(4),pV=hf(5),gV=hf(6);_h.range;G1.range;dV.range;hV.range;Rd.range;pV.range;gV.range;const fg=tr(e=>{e.setDate(1),e.setHours(0,0,0,0)},(e,t)=>{e.setMonth(e.getMonth()+t)},(e,t)=>t.getMonth()-e.getMonth()+(t.getFullYear()-e.getFullYear())*12,e=>e.getMonth());fg.range;const dg=tr(e=>{e.setUTCDate(1),e.setUTCHours(0,0,0,0)},(e,t)=>{e.setUTCMonth(e.getUTCMonth()+t)},(e,t)=>t.getUTCMonth()-e.getUTCMonth()+(t.getUTCFullYear()-e.getUTCFullYear())*12,e=>e.getUTCMonth());dg.range;const la=tr(e=>{e.setMonth(0,1),e.setHours(0,0,0,0)},(e,t)=>{e.setFullYear(e.getFullYear()+t)},(e,t)=>t.getFullYear()-e.getFullYear(),e=>e.getFullYear());la.every=e=>!isFinite(e=Math.floor(e))||!(e>0)?null:tr(t=>{t.setFullYear(Math.floor(t.getFullYear()/e)*e),t.setMonth(0,1),t.setHours(0,0,0,0)},(t,n)=>{t.setFullYear(t.getFullYear()+n*e)});la.range;const ua=tr(e=>{e.setUTCMonth(0,1),e.setUTCHours(0,0,0,0)},(e,t)=>{e.setUTCFullYear(e.getUTCFullYear()+t)},(e,t)=>t.getUTCFullYear()-e.getUTCFullYear(),e=>e.getUTCFullYear());ua.every=e=>!isFinite(e=Math.floor(e))||!(e>0)?null:tr(t=>{t.setUTCFullYear(Math.floor(t.getUTCFullYear()/e)*e),t.setUTCMonth(0,1),t.setUTCHours(0,0,0,0)},(t,n)=>{t.setUTCFullYear(t.getUTCFullYear()+n*e)});ua.range;function xN(e,t,n,r,i,s){const o=[[Ya,1,Ha],[Ya,5,5*Ha],[Ya,15,15*Ha],[Ya,30,30*Ha],[s,1,ks],[s,5,5*ks],[s,15,15*ks],[s,30,30*ks],[i,1,Ga],[i,3,3*Ga],[i,6,6*Ga],[i,12,12*Ga],[r,1,ul],[r,2,2*ul],[n,1,kk],[t,1,F5],[t,3,3*F5],[e,1,lx]];function a(u,c,f){const d=cm).right(o,d);if(h===o.length)return e.every(su(u/lx,c/lx,f));if(h===0)return Md.every(Math.max(su(u,c,f),1));const[p,g]=o[d/o[h-1][2](e[t]=1+n,e),{});function Ck(e){const t=je(e).slice(),n={};return t.length||ae("Missing time unit."),t.forEach(i=>{We(ux,i)?n[i]=1:ae(`Invalid time unit: ${i}.`)}),(n[Zn]||n[Wr]?1:0)+(n[zi]||n[Vr]||n[ji]?1:0)+(n[ca]?1:0)>1&&ae(`Incompatible time units: ${e}`),t.sort((i,s)=>ux[i]-ux[s]),t}const xV={[Dr]:"%Y ",[zi]:"Q%q ",[Vr]:"%b ",[ji]:"%d ",[Zn]:"W%U ",[Wr]:"%a ",[ca]:"%j ",[ds]:"%H:00",[hs]:"00:%M",[Ls]:":%S",[vo]:".%L",[`${Dr}-${Vr}`]:"%Y-%m ",[`${Dr}-${Vr}-${ji}`]:"%Y-%m-%d ",[`${ds}-${hs}`]:"%H:%M"};function _N(e,t){const n=kt({},xV,t),r=Ck(e),i=r.length;let s="",o=0,a,l;for(o=0;oo;--a)if(l=r.slice(o,a).join("-"),n[l]!=null){s+=n[l],o=a;break}return s.trim()}const ic=new Date;function $k(e){return ic.setFullYear(e),ic.setMonth(0),ic.setDate(1),ic.setHours(0,0,0,0),ic}function wN(e){return AN(new Date(e))}function EN(e){return Ew(new Date(e))}function AN(e){return el.count($k(e.getFullYear())-1,e)}function Ew(e){return xh.count($k(e.getFullYear())-1,e)}function Aw(e){return $k(e).getDay()}function _V(e,t,n,r,i,s,o){if(0<=e&&e<100){const a=new Date(-1,t,n,r,i,s,o);return a.setFullYear(e),a}return new Date(e,t,n,r,i,s,o)}function kN(e){return CN(new Date(e))}function SN(e){return kw(new Date(e))}function CN(e){const t=Date.UTC(e.getUTCFullYear(),0,1);return Jl.count(t-1,e)}function kw(e){const t=Date.UTC(e.getUTCFullYear(),0,1);return _h.count(t-1,e)}function Sw(e){return ic.setTime(Date.UTC(e,0,1)),ic.getUTCDay()}function wV(e,t,n,r,i,s,o){if(0<=e&&e<100){const a=new Date(Date.UTC(-1,t,n,r,i,s,o));return a.setUTCFullYear(n.y),a}return new Date(Date.UTC(e,t,n,r,i,s,o))}function $N(e,t,n,r,i){const s=t||1,o=jt(e),a=(v,b,x)=>(x=x||v,EV(n[x],r[x],v===o&&s,b)),l=new Date,u=mo(e),c=u[Dr]?a(Dr):ei(2012),f=u[Vr]?a(Vr):u[zi]?a(zi):Ol,d=u[Zn]&&u[Wr]?a(Wr,1,Zn+Wr):u[Zn]?a(Zn,1):u[Wr]?a(Wr,1):u[ji]?a(ji,1):u[ca]?a(ca,1):ph,h=u[ds]?a(ds):Ol,p=u[hs]?a(hs):Ol,g=u[Ls]?a(Ls):Ol,m=u[vo]?a(vo):Ol;return function(v){l.setTime(+v);const b=c(l);return i(b,f(l),d(l,b),h(l),p(l),g(l),m(l))}}function EV(e,t,n,r){const i=n<=1?e:r?(s,o)=>r+n*Math.floor((e(s,o)-r)/n):(s,o)=>n*Math.floor(e(s,o)/n);return t?(s,o)=>t(i(s,o),o):i}function Nd(e,t,n){return t+e*7-(n+6)%7}const AV={[Dr]:e=>e.getFullYear(),[zi]:e=>Math.floor(e.getMonth()/3),[Vr]:e=>e.getMonth(),[ji]:e=>e.getDate(),[ds]:e=>e.getHours(),[hs]:e=>e.getMinutes(),[Ls]:e=>e.getSeconds(),[vo]:e=>e.getMilliseconds(),[ca]:e=>AN(e),[Zn]:e=>Ew(e),[Zn+Wr]:(e,t)=>Nd(Ew(e),e.getDay(),Aw(t)),[Wr]:(e,t)=>Nd(1,e.getDay(),Aw(t))},kV={[zi]:e=>3*e,[Zn]:(e,t)=>Nd(e,0,Aw(t))};function FN(e,t){return $N(e,t||1,AV,kV,_V)}const SV={[Dr]:e=>e.getUTCFullYear(),[zi]:e=>Math.floor(e.getUTCMonth()/3),[Vr]:e=>e.getUTCMonth(),[ji]:e=>e.getUTCDate(),[ds]:e=>e.getUTCHours(),[hs]:e=>e.getUTCMinutes(),[Ls]:e=>e.getUTCSeconds(),[vo]:e=>e.getUTCMilliseconds(),[ca]:e=>CN(e),[Zn]:e=>kw(e),[Wr]:(e,t)=>Nd(1,e.getUTCDay(),Sw(t)),[Zn+Wr]:(e,t)=>Nd(kw(e),e.getUTCDay(),Sw(t))},CV={[zi]:e=>3*e,[Zn]:(e,t)=>Nd(e,0,Sw(t))};function DN(e,t){return $N(e,t||1,SV,CV,wV)}const $V={[Dr]:la,[zi]:fg.every(3),[Vr]:fg,[Zn]:xh,[ji]:el,[Wr]:el,[ca]:el,[ds]:Ry,[hs]:My,[Ls]:Ya,[vo]:Md},FV={[Dr]:ua,[zi]:dg.every(3),[Vr]:dg,[Zn]:_h,[ji]:Jl,[Wr]:Jl,[ca]:Jl,[ds]:Ny,[hs]:Ty,[Ls]:Ya,[vo]:Md};function wh(e){return $V[e]}function Eh(e){return FV[e]}function MN(e,t,n){return e?e.offset(t,n):void 0}function TN(e,t,n){return MN(wh(e),t,n)}function RN(e,t,n){return MN(Eh(e),t,n)}function NN(e,t,n,r){return e?e.range(t,n,r):void 0}function ON(e,t,n,r){return NN(wh(e),t,n,r)}function LN(e,t,n,r){return NN(Eh(e),t,n,r)}const yp=1e3,bp=yp*60,xp=bp*60,Oy=xp*24,DV=Oy*7,D5=Oy*30,Cw=Oy*365,IN=[Dr,Vr,ji,ds,hs,Ls,vo],_p=IN.slice(0,-1),wp=_p.slice(0,-1),Ep=wp.slice(0,-1),MV=Ep.slice(0,-1),TV=[Dr,Zn],M5=[Dr,Vr],PN=[Dr],Yh=[[_p,1,yp],[_p,5,5*yp],[_p,15,15*yp],[_p,30,30*yp],[wp,1,bp],[wp,5,5*bp],[wp,15,15*bp],[wp,30,30*bp],[Ep,1,xp],[Ep,3,3*xp],[Ep,6,6*xp],[Ep,12,12*xp],[MV,1,Oy],[TV,1,DV],[M5,1,D5],[M5,3,3*D5],[PN,1,Cw]];function BN(e){const t=e.extent,n=e.maxbins||40,r=Math.abs(i0(t))/n;let i=bh(a=>a[2]).right(Yh,r),s,o;return i===Yh.length?(s=PN,o=su(t[0]/Cw,t[1]/Cw,n)):i?(i=Yh[r/Yh[i-1][2]53)return null;"w"in W||(W.w=1),"Z"in W?(H=fx(Vh(W.y,0,1)),ve=H.getUTCDay(),H=ve>4||ve===0?G1.ceil(H):G1(H),H=Jl.offset(H,(W.V-1)*7),W.y=H.getUTCFullYear(),W.m=H.getUTCMonth(),W.d=H.getUTCDate()+(W.w+6)%7):(H=cx(Vh(W.y,0,1)),ve=H.getDay(),H=ve>4||ve===0?H1.ceil(H):H1(H),H=el.offset(H,(W.V-1)*7),W.y=H.getFullYear(),W.m=H.getMonth(),W.d=H.getDate()+(W.w+6)%7)}else("W"in W||"U"in W)&&("w"in W||(W.w="u"in W?W.u%7:"W"in W?1:0),ve="Z"in W?fx(Vh(W.y,0,1)).getUTCDay():cx(Vh(W.y,0,1)).getDay(),W.m=0,W.d="W"in W?(W.w+6)%7+W.W*7-(ve+5)%7:W.w+W.U*7-(ve+6)%7);return"Z"in W?(W.H+=W.Z/100|0,W.M+=W.Z%100,fx(W)):cx(W)}}function k(de,Re,Q,W){for(var L=0,H=Re.length,ve=Q.length,G,B;L=ve)return-1;if(G=Re.charCodeAt(L++),G===37){if(G=Re.charAt(L++),B=w[G in T5?Re.charAt(L++):G],!B||(W=B(de,Q,W))<0)return-1}else if(G!=Q.charCodeAt(W++))return-1}return W}function S(de,Re,Q){var W=u.exec(Re.slice(Q));return W?(de.p=c.get(W[0].toLowerCase()),Q+W[0].length):-1}function $(de,Re,Q){var W=h.exec(Re.slice(Q));return W?(de.w=p.get(W[0].toLowerCase()),Q+W[0].length):-1}function M(de,Re,Q){var W=f.exec(Re.slice(Q));return W?(de.w=d.get(W[0].toLowerCase()),Q+W[0].length):-1}function O(de,Re,Q){var W=v.exec(Re.slice(Q));return W?(de.m=b.get(W[0].toLowerCase()),Q+W[0].length):-1}function P(de,Re,Q){var W=g.exec(Re.slice(Q));return W?(de.m=m.get(W[0].toLowerCase()),Q+W[0].length):-1}function T(de,Re,Q){return k(de,t,Re,Q)}function F(de,Re,Q){return k(de,n,Re,Q)}function R(de,Re,Q){return k(de,r,Re,Q)}function z(de){return o[de.getDay()]}function j(de){return s[de.getDay()]}function q(de){return l[de.getMonth()]}function te(de){return a[de.getMonth()]}function Y(de){return i[+(de.getHours()>=12)]}function ee(de){return 1+~~(de.getMonth()/3)}function _e(de){return o[de.getUTCDay()]}function Le(de){return s[de.getUTCDay()]}function Z(de){return l[de.getUTCMonth()]}function he(de){return a[de.getUTCMonth()]}function He(de){return i[+(de.getUTCHours()>=12)]}function Ke(de){return 1+~~(de.getUTCMonth()/3)}return{format:function(de){var Re=A(de+="",x);return Re.toString=function(){return de},Re},parse:function(de){var Re=E(de+="",!1);return Re.toString=function(){return de},Re},utcFormat:function(de){var Re=A(de+="",_);return Re.toString=function(){return de},Re},utcParse:function(de){var Re=E(de+="",!0);return Re.toString=function(){return de},Re}}}var T5={"-":"",_:" ",0:"0"},gr=/^\s*\d+/,RV=/^%/,NV=/[\\^$*+?|[\]().{}]/g;function Yt(e,t,n){var r=e<0?"-":"",i=(r?-e:e)+"",s=i.length;return r+(s[t.toLowerCase(),n]))}function LV(e,t,n){var r=gr.exec(t.slice(n,n+1));return r?(e.w=+r[0],n+r[0].length):-1}function IV(e,t,n){var r=gr.exec(t.slice(n,n+1));return r?(e.u=+r[0],n+r[0].length):-1}function PV(e,t,n){var r=gr.exec(t.slice(n,n+2));return r?(e.U=+r[0],n+r[0].length):-1}function BV(e,t,n){var r=gr.exec(t.slice(n,n+2));return r?(e.V=+r[0],n+r[0].length):-1}function zV(e,t,n){var r=gr.exec(t.slice(n,n+2));return r?(e.W=+r[0],n+r[0].length):-1}function R5(e,t,n){var r=gr.exec(t.slice(n,n+4));return r?(e.y=+r[0],n+r[0].length):-1}function N5(e,t,n){var r=gr.exec(t.slice(n,n+2));return r?(e.y=+r[0]+(+r[0]>68?1900:2e3),n+r[0].length):-1}function jV(e,t,n){var r=/^(Z)|([+-]\d\d)(?::?(\d\d))?/.exec(t.slice(n,n+6));return r?(e.Z=r[1]?0:-(r[2]+(r[3]||"00")),n+r[0].length):-1}function UV(e,t,n){var r=gr.exec(t.slice(n,n+1));return r?(e.q=r[0]*3-3,n+r[0].length):-1}function qV(e,t,n){var r=gr.exec(t.slice(n,n+2));return r?(e.m=r[0]-1,n+r[0].length):-1}function O5(e,t,n){var r=gr.exec(t.slice(n,n+2));return r?(e.d=+r[0],n+r[0].length):-1}function WV(e,t,n){var r=gr.exec(t.slice(n,n+3));return r?(e.m=0,e.d=+r[0],n+r[0].length):-1}function L5(e,t,n){var r=gr.exec(t.slice(n,n+2));return r?(e.H=+r[0],n+r[0].length):-1}function HV(e,t,n){var r=gr.exec(t.slice(n,n+2));return r?(e.M=+r[0],n+r[0].length):-1}function GV(e,t,n){var r=gr.exec(t.slice(n,n+2));return r?(e.S=+r[0],n+r[0].length):-1}function YV(e,t,n){var r=gr.exec(t.slice(n,n+3));return r?(e.L=+r[0],n+r[0].length):-1}function VV(e,t,n){var r=gr.exec(t.slice(n,n+6));return r?(e.L=Math.floor(r[0]/1e3),n+r[0].length):-1}function XV(e,t,n){var r=RV.exec(t.slice(n,n+1));return r?n+r[0].length:-1}function KV(e,t,n){var r=gr.exec(t.slice(n));return r?(e.Q=+r[0],n+r[0].length):-1}function ZV(e,t,n){var r=gr.exec(t.slice(n));return r?(e.s=+r[0],n+r[0].length):-1}function I5(e,t){return Yt(e.getDate(),t,2)}function JV(e,t){return Yt(e.getHours(),t,2)}function QV(e,t){return Yt(e.getHours()%12||12,t,2)}function eX(e,t){return Yt(1+el.count(la(e),e),t,3)}function jN(e,t){return Yt(e.getMilliseconds(),t,3)}function tX(e,t){return jN(e,t)+"000"}function nX(e,t){return Yt(e.getMonth()+1,t,2)}function rX(e,t){return Yt(e.getMinutes(),t,2)}function iX(e,t){return Yt(e.getSeconds(),t,2)}function sX(e){var t=e.getDay();return t===0?7:t}function oX(e,t){return Yt(xh.count(la(e)-1,e),t,2)}function UN(e){var t=e.getDay();return t>=4||t===0?Td(e):Td.ceil(e)}function aX(e,t){return e=UN(e),Yt(Td.count(la(e),e)+(la(e).getDay()===4),t,2)}function lX(e){return e.getDay()}function uX(e,t){return Yt(H1.count(la(e)-1,e),t,2)}function cX(e,t){return Yt(e.getFullYear()%100,t,2)}function fX(e,t){return e=UN(e),Yt(e.getFullYear()%100,t,2)}function dX(e,t){return Yt(e.getFullYear()%1e4,t,4)}function hX(e,t){var n=e.getDay();return e=n>=4||n===0?Td(e):Td.ceil(e),Yt(e.getFullYear()%1e4,t,4)}function pX(e){var t=e.getTimezoneOffset();return(t>0?"-":(t*=-1,"+"))+Yt(t/60|0,"0",2)+Yt(t%60,"0",2)}function P5(e,t){return Yt(e.getUTCDate(),t,2)}function gX(e,t){return Yt(e.getUTCHours(),t,2)}function mX(e,t){return Yt(e.getUTCHours()%12||12,t,2)}function vX(e,t){return Yt(1+Jl.count(ua(e),e),t,3)}function qN(e,t){return Yt(e.getUTCMilliseconds(),t,3)}function yX(e,t){return qN(e,t)+"000"}function bX(e,t){return Yt(e.getUTCMonth()+1,t,2)}function xX(e,t){return Yt(e.getUTCMinutes(),t,2)}function _X(e,t){return Yt(e.getUTCSeconds(),t,2)}function wX(e){var t=e.getUTCDay();return t===0?7:t}function EX(e,t){return Yt(_h.count(ua(e)-1,e),t,2)}function WN(e){var t=e.getUTCDay();return t>=4||t===0?Rd(e):Rd.ceil(e)}function AX(e,t){return e=WN(e),Yt(Rd.count(ua(e),e)+(ua(e).getUTCDay()===4),t,2)}function kX(e){return e.getUTCDay()}function SX(e,t){return Yt(G1.count(ua(e)-1,e),t,2)}function CX(e,t){return Yt(e.getUTCFullYear()%100,t,2)}function $X(e,t){return e=WN(e),Yt(e.getUTCFullYear()%100,t,2)}function FX(e,t){return Yt(e.getUTCFullYear()%1e4,t,4)}function DX(e,t){var n=e.getUTCDay();return e=n>=4||n===0?Rd(e):Rd.ceil(e),Yt(e.getUTCFullYear()%1e4,t,4)}function MX(){return"+0000"}function B5(){return"%"}function z5(e){return+e}function j5(e){return Math.floor(+e/1e3)}var Tf,Fk,HN,Dk,GN;TX({dateTime:"%x, %X",date:"%-m/%-d/%Y",time:"%-I:%M:%S %p",periods:["AM","PM"],days:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],shortDays:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],months:["January","February","March","April","May","June","July","August","September","October","November","December"],shortMonths:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]});function TX(e){return Tf=zN(e),Fk=Tf.format,HN=Tf.parse,Dk=Tf.utcFormat,GN=Tf.utcParse,Tf}function Ap(e){const t={};return n=>t[n]||(t[n]=e(n))}function RX(e,t){return n=>{const r=e(n),i=r.indexOf(t);if(i<0)return r;let s=NX(r,i);const o=si;)if(r[s]!=="0"){++s;break}return r.slice(0,s)+o}}function NX(e,t){let n=e.lastIndexOf("e"),r;if(n>0)return n;for(n=e.length;--n>t;)if(r=e.charCodeAt(n),r>=48&&r<=57)return n+1}function YN(e){const t=Ap(e.format),n=e.formatPrefix;return{format:t,formatPrefix:n,formatFloat(r){const i=zc(r||",");if(i.precision==null){switch(i.precision=12,i.type){case"%":i.precision-=2;break;case"e":i.precision-=1;break}return RX(t(i),t(".1f")(1)[1])}else return t(i)},formatSpan(r,i,s,o){o=zc(o??",f");const a=su(r,i,s),l=Math.max(Math.abs(r),Math.abs(i));let u;if(o.precision==null)switch(o.type){case"s":return isNaN(u=vN(a,l))||(o.precision=u),n(o,l);case"":case"e":case"g":case"p":case"r":{isNaN(u=yN(a,l))||(o.precision=u-(o.type==="e"));break}case"f":case"%":{isNaN(u=mN(a))||(o.precision=u-(o.type==="%")*2);break}}return t(o)}}}let $w;VN();function VN(){return $w=YN({format:Dy,formatPrefix:Ak})}function XN(e){return YN(gN(e))}function Y1(e){return arguments.length?$w=XN(e):$w}function U5(e,t,n){n=n||{},Pe(n)||ae(`Invalid time multi-format specifier: ${n}`);const r=t(Ls),i=t(hs),s=t(ds),o=t(ji),a=t(Zn),l=t(Vr),u=t(zi),c=t(Dr),f=e(n[vo]||".%L"),d=e(n[Ls]||":%S"),h=e(n[hs]||"%I:%M"),p=e(n[ds]||"%I %p"),g=e(n[ji]||n[Wr]||"%a %d"),m=e(n[Zn]||"%b %d"),v=e(n[Vr]||"%B"),b=e(n[zi]||"%B"),x=e(n[Dr]||"%Y");return _=>(r(_)<_?f:i(_)<_?d:s(_)<_?h:o(_)<_?p:l(_)<_?a(_)<_?g:m:c(_)<_?u(_)<_?v:b:x)(_)}function KN(e){const t=Ap(e.format),n=Ap(e.utcFormat);return{timeFormat:r=>ze(r)?t(r):U5(t,wh,r),utcFormat:r=>ze(r)?n(r):U5(n,Eh,r),timeParse:Ap(e.parse),utcParse:Ap(e.utcParse)}}let Fw;ZN();function ZN(){return Fw=KN({format:Fk,parse:HN,utcFormat:Dk,utcParse:GN})}function JN(e){return KN(zN(e))}function hg(e){return arguments.length?Fw=JN(e):Fw}const Dw=(e,t)=>kt({},e,t);function QN(e,t){const n=e?XN(e):Y1(),r=t?JN(t):hg();return Dw(n,r)}function Mk(e,t){const n=arguments.length;return n&&n!==2&&ae("defaultLocale expects either zero or two arguments."),n?Dw(Y1(e),hg(t)):Dw(Y1(),hg())}function OX(){return VN(),ZN(),Mk()}const LX=/^(data:|([A-Za-z]+:)?\/\/)/,IX=/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|cid|xmpp|file|data):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i,PX=/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205f\u3000]/g,q5="file://";function BX(e,t){return n=>({options:n||{},sanitize:jX,load:zX,fileAccess:!1,file:UX(),http:WX(e)})}async function zX(e,t){const n=await this.sanitize(e,t),r=n.href;return n.localFile?this.file(r):this.http(r,t)}async function jX(e,t){t=kt({},this.options,t);const n=this.fileAccess,r={href:null};let i,s,o;const a=IX.test(e.replace(PX,""));(e==null||typeof e!="string"||!a)&&ae("Sanitize failure, invalid URI: "+De(e));const l=LX.test(e);return(o=t.baseURL)&&!l&&(!e.startsWith("/")&&!o.endsWith("/")&&(e="/"+e),e=o+e),s=(i=e.startsWith(q5))||t.mode==="file"||t.mode!=="http"&&!l&&n,i?e=e.slice(q5.length):e.startsWith("//")&&(t.defaultProtocol==="file"?(e=e.slice(2),s=!0):e=(t.defaultProtocol||"http")+":"+e),Object.defineProperty(r,"localFile",{value:!!s}),r.href=e,t.target&&(r.target=t.target+""),t.rel&&(r.rel=t.rel+""),t.context==="image"&&t.crossOrigin&&(r.crossOrigin=t.crossOrigin+""),r}function UX(e){return qX}async function qX(){ae("No file system access.")}function WX(e){return e?async function(t,n){const r=kt({},this.options.http,n),i=n&&n.response,s=await e(t,r);return s.ok?St(s[i])?s[i]():s.text():ae(s.status+""+s.statusText)}:HX}async function HX(){ae("No HTTP fetch method available.")}const GX=e=>e!=null&&e===e,YX=e=>e==="true"||e==="false"||e===!0||e===!1,VX=e=>!Number.isNaN(Date.parse(e)),eO=e=>!Number.isNaN(+e)&&!(e instanceof Date),XX=e=>eO(e)&&Number.isInteger(+e),Mw={boolean:xk,integer:Hr,number:Hr,date:_k,string:wk,unknown:Qr},om=[YX,XX,eO,VX],KX=["boolean","integer","number","date"];function tO(e,t){if(!e||!e.length)return"unknown";const n=e.length,r=om.length,i=om.map((s,o)=>o+1);for(let s=0,o=0,a,l;ss===0?o:s,0)-1]}function nO(e,t){return t.reduce((n,r)=>(n[r]=tO(e,r),n),{})}function W5(e){const t=function(n,r){const i={delimiter:e};return Tk(n,r?kt(r,i):i)};return t.responseType="text",t}function Tk(e,t){return t.header&&(e=t.header.map(De).join(t.delimiter)+` +`+e),DY(t.delimiter).parse(e+"")}Tk.responseType="text";function ZX(e){return typeof Buffer=="function"&&St(Buffer.isBuffer)?Buffer.isBuffer(e):!1}function Rk(e,t){const n=t&&t.property?Os(t.property):Qr;return Pe(e)&&!ZX(e)?JX(n(e),t):n(JSON.parse(e))}Rk.responseType="json";function JX(e,t){return!fe(e)&&KR(e)&&(e=[...e]),t&&t.copy?JSON.parse(JSON.stringify(e)):e}const QX={interior:(e,t)=>e!==t,exterior:(e,t)=>e===t};function rO(e,t){let n,r,i,s;return e=Rk(e,t),t&&t.feature?(n=NY,i=t.feature):t&&t.mesh?(n=LY,i=t.mesh,s=QX[t.filter]):ae("Missing TopoJSON feature or mesh parameter."),r=(r=e.objects[i])?n(e,r,s):ae("Invalid TopoJSON object: "+i),r&&r.features||[r]}rO.responseType="json";const i1={dsv:Tk,csv:W5(","),tsv:W5(" "),json:Rk,topojson:rO};function Nk(e,t){return arguments.length>1?(i1[e]=t,this):We(i1,e)?i1[e]:null}function iO(e){const t=Nk(e);return t&&t.responseType||"text"}function sO(e,t,n,r){t=t||{};const i=Nk(t.type||"json");return i||ae("Unknown data format type: "+t.type),e=i(e,t),t.parse&&eK(e,t.parse,n,r),We(e,"columns")&&delete e.columns,e}function eK(e,t,n,r){if(!e.length)return;const i=hg();n=n||i.timeParse,r=r||i.utcParse;let s=e.columns||Object.keys(e[0]),o,a,l,u,c,f;t==="auto"&&(t=nO(e,s)),s=Object.keys(t);const d=s.map(h=>{const p=t[h];let g,m;if(p&&(p.startsWith("date:")||p.startsWith("utc:")))return g=p.split(/:(.+)?/,2),m=g[1],(m[0]==="'"&&m[m.length-1]==="'"||m[0]==='"'&&m[m.length-1]==='"')&&(m=m.slice(1,-1)),(g[0]==="utc"?r:n)(m);if(!Mw[p])throw Error("Illegal format pattern: "+h+":"+p);return Mw[p]});for(l=0,c=e.length,f=s.length;l{const s=t(i);return r[s]||(r[s]=1,n.push(i)),n},n.remove=i=>{const s=t(i);if(r[s]){r[s]=0;const o=n.indexOf(i);o>=0&&n.splice(o,1)}return n},n}async function s1(e,t){try{await t(e)}catch(n){e.error(n)}}const oO=Symbol("vega_id");let tK=1;function Py(e){return!!(e&&it(e))}function it(e){return e[oO]}function aO(e,t){return e[oO]=t,e}function Kt(e){const t=e===Object(e)?e:{data:e};return it(t)?t:aO(t,tK++)}function Ok(e){return By(e,Kt({}))}function By(e,t){for(const n in e)t[n]=e[n];return t}function lO(e,t){return aO(t,it(e))}function pf(e,t){return e?t?(n,r)=>e(n,r)||it(t(n))-it(t(r)):(n,r)=>e(n,r)||it(n)-it(r):null}function uO(e){return e&&e.constructor===Eu}function Eu(){const e=[],t=[],n=[],r=[],i=[];let s=null,o=!1;return{constructor:Eu,insert(a){const l=je(a),u=l.length;for(let c=0;c{p(b)&&(u[it(b)]=-1)});for(f=0,d=e.length;f0&&(v(g,p,h.value),a.modifies(p));for(f=0,d=i.length;f{p(b)&&u[it(b)]>0&&v(b,h.field,h.value)}),a.modifies(h.field);if(o)a.mod=t.length||r.length?l.filter(b=>u[it(b)]>0):l.slice();else for(m in c)a.mod.push(c[m]);return(s||s==null&&(t.length||r.length))&&a.clean(!0),a}}}const o1="_:mod:_";function zy(){Object.defineProperty(this,o1,{writable:!0,value:{}})}zy.prototype={set(e,t,n,r){const i=this,s=i[e],o=i[o1];return t!=null&&t>=0?(s[t]!==n||r)&&(s[t]=n,o[t+":"+e]=-1,o[e]=-1):(s!==n||r)&&(i[e]=n,o[e]=fe(n)?1+n.length:-1),i},modified(e,t){const n=this[o1];if(arguments.length){if(fe(e)){for(let r=0;r=0?t+1{h instanceof cn?(h!==this&&(t&&h.targets().add(this),s.push(h)),i.push({op:h,name:f,index:d})):r.set(f,d,h)};for(o in e)if(a=e[o],o===rK)je(a).forEach(f=>{f instanceof cn?f!==this&&(f.targets().add(this),s.push(f)):ae("Pulse parameters must be operator instances.")}),this.source=a;else if(fe(a))for(r.set(o,-1,Array(l=a.length)),u=0;u{const n=Date.now();return n-t>e?(t=n,1):0})},debounce(e){const t=$l();return this.targets().add($l(null,null,vk(e,n=>{const r=n.dataflow;t.receive(n),r&&r.run&&r.run()}))),t},between(e,t){let n=!1;return e.targets().add($l(null,null,()=>n=!0)),t.targets().add($l(null,null,()=>n=!1)),this.filter(()=>n)},detach(){this._filter=fs,this._targets=null}};function cK(e,t,n,r){const i=this,s=$l(n,r),o=function(u){u.dataflow=i;try{s.receive(u)}catch(c){i.error(c)}finally{i.run()}};let a;typeof e=="string"&&typeof document<"u"?a=document.querySelectorAll(e):a=je(e);const l=a.length;for(let u=0;ut=r);return n.requests=0,n.done=()=>{--n.requests===0&&(e._pending=null,t(e))},e._pending=n}const mK={skip:!0};function vK(e,t,n,r,i){return(e instanceof cn?bK:yK)(this,e,t,n,r,i),this}function yK(e,t,n,r,i,s){const o=kt({},s,mK);let a,l;St(n)||(n=ei(n)),r===void 0?a=u=>e.touch(n(u)):St(r)?(l=new cn(null,r,i,!1),a=u=>{l.evaluate(u);const c=n(u),f=l.value;uO(f)?e.pulse(c,f,s):e.update(c,f,o)}):a=u=>e.update(n(u),r,o),t.apply(a)}function bK(e,t,n,r,i,s){if(r===void 0)t.targets().add(n);else{const o=s||{},a=new cn(null,xK(n,r),i,!1);a.modified(o.force),a.rank=t.rank,t.targets().add(a),n&&(a.skip(!0),a.value=n.value,a.targets().add(n),e.connect(n,[a]))}}function xK(e,t){return t=St(t)?t:ei(t),e?function(n,r){const i=t(n,r);return e.skip()||(e.skip(i!==this.value).value=i),i}:t}function _K(e){e.rank=++this._rank}function wK(e){const t=[e];let n,r,i;for(;t.length;)if(this.rank(n=t.pop()),r=n._targets)for(i=r.length;--i>=0;)t.push(n=r[i]),n===e&&ae("Cycle detected in dataflow graph.")}const V1={},zo=1,Ml=2,La=4,EK=zo|Ml,G5=zo|La,Rf=zo|Ml|La,Y5=8,Zh=16,V5=32,X5=64;function Ql(e,t,n){this.dataflow=e,this.stamp=t??-1,this.add=[],this.rem=[],this.mod=[],this.fields=null,this.encode=n||null}function dx(e,t){const n=[];return Dl(e,t,r=>n.push(r)),n}function K5(e,t){const n={};return e.visit(t,r=>{n[it(r)]=1}),r=>n[it(r)]?null:r}function am(e,t){return e?(n,r)=>e(n,r)&&t(n,r):t}Ql.prototype={StopPropagation:V1,ADD:zo,REM:Ml,MOD:La,ADD_REM:EK,ADD_MOD:G5,ALL:Rf,REFLOW:Y5,SOURCE:Zh,NO_SOURCE:V5,NO_FIELDS:X5,fork(e){return new Ql(this.dataflow).init(this,e)},clone(){const e=this.fork(Rf);return e.add=e.add.slice(),e.rem=e.rem.slice(),e.mod=e.mod.slice(),e.source&&(e.source=e.source.slice()),e.materialize(Rf|Zh)},addAll(){let e=this;return!e.source||e.add===e.rem||!e.rem.length&&e.source.length===e.add.length||(e=new Ql(this.dataflow).init(this),e.add=e.source,e.rem=[]),e},init(e,t){const n=this;return n.stamp=e.stamp,n.encode=e.encode,e.fields&&!(t&X5)&&(n.fields=e.fields),t&zo?(n.addF=e.addF,n.add=e.add):(n.addF=null,n.add=[]),t&Ml?(n.remF=e.remF,n.rem=e.rem):(n.remF=null,n.rem=[]),t&La?(n.modF=e.modF,n.mod=e.mod):(n.modF=null,n.mod=[]),t&V5?(n.srcF=null,n.source=null):(n.srcF=e.srcF,n.source=e.source,e.cleans&&(n.cleans=e.cleans)),n},runAfter(e){this.dataflow.runAfter(e)},changed(e){const t=e||Rf;return t&zo&&this.add.length||t&Ml&&this.rem.length||t&La&&this.mod.length},reflow(e){if(e)return this.fork(Rf).reflow();const t=this.add.length,n=this.source&&this.source.length;return n&&n!==t&&(this.mod=this.source,t&&this.filter(La,K5(this,zo))),this},clean(e){return arguments.length?(this.cleans=!!e,this):this.cleans},modifies(e){const t=this.fields||(this.fields={});return fe(e)?e.forEach(n=>t[n]=!0):t[e]=!0,this},modified(e,t){const n=this.fields;return(t||this.mod.length)&&n?arguments.length?fe(e)?e.some(r=>n[r]):n[e]:!!n:!1},filter(e,t){const n=this;return e&zo&&(n.addF=am(n.addF,t)),e&Ml&&(n.remF=am(n.remF,t)),e&La&&(n.modF=am(n.modF,t)),e&Zh&&(n.srcF=am(n.srcF,t)),n},materialize(e){e=e||Rf;const t=this;return e&zo&&t.addF&&(t.add=dx(t.add,t.addF),t.addF=null),e&Ml&&t.remF&&(t.rem=dx(t.rem,t.remF),t.remF=null),e&La&&t.modF&&(t.mod=dx(t.mod,t.modF),t.modF=null),e&Zh&&t.srcF&&(t.source=t.source.filter(t.srcF),t.srcF=null),t},visit(e,t){const n=this,r=t;if(e&Zh)return Dl(n.source,n.srcF,r),n;e&zo&&Dl(n.add,n.addF,r),e&Ml&&Dl(n.rem,n.remF,r),e&La&&Dl(n.mod,n.modF,r);const i=n.source;if(e&Y5&&i){const s=n.add.length+n.mod.length;s===i.length||(s?Dl(i,K5(n,G5),r):Dl(i,n.srcF,r))}return n}};function Lk(e,t,n,r){const i=this;let s=0;this.dataflow=e,this.stamp=t,this.fields=null,this.encode=r||null,this.pulses=n;for(const o of n)if(o.stamp===t){if(o.fields){const a=i.fields||(i.fields={});for(const l in o.fields)a[l]=1}o.changed(i.ADD)&&(s|=i.ADD),o.changed(i.REM)&&(s|=i.REM),o.changed(i.MOD)&&(s|=i.MOD)}this.changes=s}Te(Lk,Ql,{fork(e){const t=new Ql(this.dataflow).init(this,e&this.NO_FIELDS);return e!==void 0&&(e&t.ADD&&this.visit(t.ADD,n=>t.add.push(n)),e&t.REM&&this.visit(t.REM,n=>t.rem.push(n)),e&t.MOD&&this.visit(t.MOD,n=>t.mod.push(n))),t},changed(e){return this.changes&e},modified(e){const t=this,n=t.fields;return n&&t.changes&t.MOD?fe(e)?e.some(r=>n[r]):n[e]:0},filter(){ae("MultiPulse does not support filtering.")},materialize(){ae("MultiPulse does not support materialization.")},visit(e,t){const n=this,r=n.pulses,i=r.length;let s=0;if(e&n.SOURCE)for(;sr._enqueue(c,!0)),r._touched=Iy(r0);let o=0,a,l,u;try{for(;r._heap.size()>0;){if(a=r._heap.pop(),a.rank!==a.qrank){r._enqueue(a,!0);continue}l=a.run(r._getPulse(a,e)),l.then?l=await l:l.async&&(i.push(l.async),l=V1),l!==V1&&a._targets&&a._targets.forEach(c=>r._enqueue(c)),++o}}catch(c){r._heap.clear(),u=c}if(r._input={},r._pulse=null,r.debug(`Pulse ${s}: ${o} operators`),u&&(r._postrun=[],r.error(u)),r._postrun.length){const c=r._postrun.sort((f,d)=>d.priority-f.priority);r._postrun=[];for(let f=0;fr.runAsync(null,()=>{c.forEach(f=>{try{f(r)}catch(d){r.error(d)}})})),r}async function kK(e,t,n){for(;this._running;)await this._running;const r=()=>this._running=null;return(this._running=this.evaluate(e,t,n)).then(r,r),this._running}function SK(e,t,n){return this._pulse?cO(this):(this.evaluate(e,t,n),this)}function CK(e,t,n){if(this._pulse||t)this._postrun.push({priority:n||0,callback:e});else try{e(this)}catch(r){this.error(r)}}function cO(e){return e.error("Dataflow already running. Use runAsync() to chain invocations."),e}function $K(e,t){const n=e.stampi.pulse),t):this._input[e.id]||DK(this._pulse,n&&n.pulse)}function DK(e,t){return t&&t.stamp===e.stamp?t:(e=e.fork(),t&&t!==V1&&(e.source=t.source),e)}const Ik={skip:!1,force:!1};function MK(e,t){const n=t||Ik;return this._pulse?this._enqueue(e):this._touched.add(e),n.skip&&e.skip(!0),this}function TK(e,t,n){const r=n||Ik;return(e.set(t)||r.force)&&this.touch(e,r),this}function RK(e,t,n){this.touch(e,n||Ik);const r=new Ql(this,this._clock+(this._pulse?0:1)),i=e.pulse&&e.pulse.source||[];return r.target=e,this._input[e.id]=t.pulse(r,i),this}function NK(e){let t=[];return{clear:()=>t=[],size:()=>t.length,peek:()=>t[0],push:n=>(t.push(n),fO(t,0,t.length-1,e)),pop:()=>{const n=t.pop();let r;return t.length?(r=t[0],t[0]=n,OK(t,0,e)):r=n,r}}}function fO(e,t,n,r){let i,s;const o=e[n];for(;n>t;){if(s=n-1>>1,i=e[s],r(o,i)<0){e[n]=i,n=s;continue}break}return e[n]=o}function OK(e,t,n){const r=t,i=e.length,s=e[t];let o=(t<<1)+1,a;for(;o=0&&(o=a),e[t]=e[o],t=o,o=(t<<1)+1;return e[t]=s,fO(e,r,t,n)}function sd(){this.logger(dk()),this.logLevel(ck),this._clock=0,this._rank=0,this._locale=Mk();try{this._loader=Ly()}catch{}this._touched=Iy(r0),this._input={},this._pulse=null,this._heap=NK((e,t)=>e.qrank-t.qrank),this._postrun=[]}function Jh(e){return function(){return this._log[e].apply(this,arguments)}}sd.prototype={stamp(){return this._clock},loader(e){return arguments.length?(this._loader=e,this):this._loader},locale(e){return arguments.length?(this._locale=e,this):this._locale},logger(e){return arguments.length?(this._log=e,this):this._log},error:Jh("error"),warn:Jh("warn"),info:Jh("info"),debug:Jh("debug"),logLevel:Jh("level"),cleanThreshold:1e4,add:aK,connect:lK,rank:_K,rerank:wK,pulse:RK,touch:MK,update:TK,changeset:Eu,ingest:dK,parse:fK,preload:pK,request:hK,events:cK,on:vK,evaluate:AK,run:SK,runAsync:kK,runAfter:CK,_enqueue:$K,_getPulse:FK};function ne(e,t){cn.call(this,e,null,t)}Te(ne,cn,{run(e){if(e.stampthis.pulse=n):t!==e.StopPropagation&&(this.pulse=t),t},evaluate(e){const t=this.marshall(e.stamp),n=this.transform(t,e);return t.clear(),n},transform(){}});const Od={};function dO(e){const t=hO(e);return t&&t.Definition||null}function hO(e){return e=e&&e.toLowerCase(),We(Od,e)?Od[e]:null}function*pO(e,t){if(t==null)for(let n of e)n!=null&&n!==""&&(n=+n)>=n&&(yield n);else{let n=-1;for(let r of e)r=t(r,++n,e),r!=null&&r!==""&&(r=+r)>=r&&(yield r)}}function Pk(e,t,n){const r=Float64Array.from(pO(e,n));return r.sort(Qa),t.map(i=>fN(r,i))}function Bk(e,t){return Pk(e,[.25,.5,.75],t)}function zk(e,t){const n=e.length,r=WY(e,t),i=Bk(e,t),s=(i[2]-i[0])/1.34;return 1.06*(Math.min(r,s)||r||Math.abs(i[0])||1)*Math.pow(n,-.2)}function gO(e){const t=e.maxbins||20,n=e.base||10,r=Math.log(n),i=e.divide||[5,2];let s=e.extent[0],o=e.extent[1],a,l,u,c,f,d;const h=e.span||o-s||Math.abs(s)||1;if(e.step)a=e.step;else if(e.steps){for(c=h/t,f=0,d=e.steps.length;ft;)a*=n;for(f=0,d=i.length;f=u&&h/c<=t&&(a=c)}c=Math.log(a);const p=c>=0?0:~~(-c/r)+1,g=Math.pow(n,-p-1);return(e.nice||e.nice===void 0)&&(c=Math.floor(s/a+g)*a,s=sd);const i=e.length,s=new Float64Array(i);let o=0,a=1,l=r(e[0]),u=l,c=l+t,f;for(;a=c){for(u=(l+u)/2;o>1);oi;)e[o--]=e[r]}r=i,i=s}return e}function PK(e){return function(){return e=(1103515245*e+12345)%2147483647,e/2147483647}}function BK(e,t){t==null&&(t=e,e=0);let n,r,i;const s={min(o){return arguments.length?(n=o||0,i=r-n,s):n},max(o){return arguments.length?(r=o||0,i=r-n,s):r},sample(){return n+Math.floor(i*Is())},pdf(o){return o===Math.floor(o)&&o>=n&&o=r?1:(a-n+1)/i},icdf(o){return o>=0&&o<=1?n-1+Math.floor(o*i):NaN}};return s.min(e).max(t)}const yO=Math.sqrt(2*Math.PI),zK=Math.SQRT2;let Qh=NaN;function Uy(e,t){e=e||0,t=t??1;let n=0,r=0,i,s;if(Qh===Qh)n=Qh,Qh=NaN;else{do n=Is()*2-1,r=Is()*2-1,i=n*n+r*r;while(i===0||i>1);s=Math.sqrt(-2*Math.log(i)/i),n*=s,Qh=r*s}return e+n*t}function jk(e,t,n){n=n??1;const r=(e-(t||0))/n;return Math.exp(-.5*r*r)/(n*yO)}function qy(e,t,n){t=t||0,n=n??1;const r=(e-t)/n,i=Math.abs(r);let s;if(i>37)s=0;else{const o=Math.exp(-i*i/2);let a;i<7.07106781186547?(a=.0352624965998911*i+.700383064443688,a=a*i+6.37396220353165,a=a*i+33.912866078383,a=a*i+112.079291497871,a=a*i+221.213596169931,a=a*i+220.206867912376,s=o*a,a=.0883883476483184*i+1.75566716318264,a=a*i+16.064177579207,a=a*i+86.7807322029461,a=a*i+296.564248779674,a=a*i+637.333633378831,a=a*i+793.826512519948,a=a*i+440.413735824752,s=s/a):(a=i+.65,a=i+4/a,a=i+3/a,a=i+2/a,a=i+1/a,s=o/a/2.506628274631)}return r>0?1-s:s}function Wy(e,t,n){return e<0||e>1?NaN:(t||0)+(n??1)*zK*jK(2*e-1)}function jK(e){let t=-Math.log((1-e)*(1+e)),n;return t<6.25?(t-=3.125,n=-364441206401782e-35,n=-16850591381820166e-35+n*t,n=128584807152564e-32+n*t,n=11157877678025181e-33+n*t,n=-1333171662854621e-31+n*t,n=20972767875968562e-33+n*t,n=6637638134358324e-30+n*t,n=-4054566272975207e-29+n*t,n=-8151934197605472e-29+n*t,n=26335093153082323e-28+n*t,n=-12975133253453532e-27+n*t,n=-5415412054294628e-26+n*t,n=10512122733215323e-25+n*t,n=-4112633980346984e-24+n*t,n=-29070369957882005e-24+n*t,n=42347877827932404e-23+n*t,n=-13654692000834679e-22+n*t,n=-13882523362786469e-21+n*t,n=.00018673420803405714+n*t,n=-.000740702534166267+n*t,n=-.006033670871430149+n*t,n=.24015818242558962+n*t,n=1.6536545626831027+n*t):t<16?(t=Math.sqrt(t)-3.25,n=22137376921775787e-25,n=9075656193888539e-23+n*t,n=-27517406297064545e-23+n*t,n=18239629214389228e-24+n*t,n=15027403968909828e-22+n*t,n=-4013867526981546e-21+n*t,n=29234449089955446e-22+n*t,n=12475304481671779e-21+n*t,n=-47318229009055734e-21+n*t,n=6828485145957318e-20+n*t,n=24031110387097894e-21+n*t,n=-.0003550375203628475+n*t,n=.0009532893797373805+n*t,n=-.0016882755560235047+n*t,n=.002491442096107851+n*t,n=-.003751208507569241+n*t,n=.005370914553590064+n*t,n=1.0052589676941592+n*t,n=3.0838856104922208+n*t):Number.isFinite(t)?(t=Math.sqrt(t)-5,n=-27109920616438573e-27,n=-2555641816996525e-25+n*t,n=15076572693500548e-25+n*t,n=-3789465440126737e-24+n*t,n=761570120807834e-23+n*t,n=-1496002662714924e-23+n*t,n=2914795345090108e-23+n*t,n=-6771199775845234e-23+n*t,n=22900482228026655e-23+n*t,n=-99298272942317e-20+n*t,n=4526062597223154e-21+n*t,n=-1968177810553167e-20+n*t,n=7599527703001776e-20+n*t,n=-.00021503011930044477+n*t,n=-.00013871931833623122+n*t,n=1.0103004648645344+n*t,n=4.849906401408584+n*t):n=1/0,n*e}function Uk(e,t){let n,r;const i={mean(s){return arguments.length?(n=s||0,i):n},stdev(s){return arguments.length?(r=s??1,i):r},sample:()=>Uy(n,r),pdf:s=>jk(s,n,r),cdf:s=>qy(s,n,r),icdf:s=>Wy(s,n,r)};return i.mean(e).stdev(t)}function qk(e,t){const n=Uk();let r=0;const i={data(s){return arguments.length?(e=s,r=s?s.length:0,i.bandwidth(t)):e},bandwidth(s){return arguments.length?(t=s,!t&&e&&(t=zk(e)),i):t},sample(){return e[~~(Is()*r)]+t*n.sample()},pdf(s){let o=0,a=0;for(;aWk(n,r),pdf:s=>Hk(s,n,r),cdf:s=>Gk(s,n,r),icdf:s=>Yk(s,n,r)};return i.mean(e).stdev(t)}function xO(e,t){let n=0,r;function i(o){const a=[];let l=0,u;for(u=0;u=t&&e<=n?1/(n-t):0}function Kk(e,t,n){return n==null&&(n=t??1,t=0),en?1:(e-t)/(n-t)}function Zk(e,t,n){return n==null&&(n=t??1,t=0),e>=0&&e<=1?t+e*(n-t):NaN}function _O(e,t){let n,r;const i={min(s){return arguments.length?(n=s||0,i):n},max(s){return arguments.length?(r=s??1,i):r},sample:()=>Vk(n,r),pdf:s=>Xk(s,n,r),cdf:s=>Kk(s,n,r),icdf:s=>Zk(s,n,r)};return t==null&&(t=e??1,e=0),i.min(e).max(t)}function Jk(e,t,n){let r=0,i=0;for(const s of e){const o=n(s);t(s)==null||o==null||isNaN(o)||(r+=(o-r)/++i)}return{coef:[r],predict:()=>r,rSquared:0}}function s0(e,t,n,r){const i=r-e*e,s=Math.abs(i)<1e-24?0:(n-e*t)/i;return[t-s*e,s]}function Hy(e,t,n,r){e=e.filter(h=>{let p=t(h),g=n(h);return p!=null&&(p=+p)>=p&&g!=null&&(g=+g)>=g}),r&&e.sort((h,p)=>t(h)-t(p));const i=e.length,s=new Float64Array(i),o=new Float64Array(i);let a=0,l=0,u=0,c,f,d;for(d of e)s[a]=c=+t(d),o[a]=f=+n(d),++a,l+=(c-l)/a,u+=(f-u)/a;for(a=0;a=s&&o!=null&&(o=+o)>=o&&r(s,o,++i)}function Ah(e,t,n,r,i){let s=0,o=0;return o0(e,t,n,(a,l)=>{const u=l-i(a),c=l-r;s+=u*u,o+=c*c}),1-s/o}function Qk(e,t,n){let r=0,i=0,s=0,o=0,a=0;o0(e,t,n,(c,f)=>{++a,r+=(c-r)/a,i+=(f-i)/a,s+=(c*f-s)/a,o+=(c*c-o)/a});const l=s0(r,i,s,o),u=c=>l[0]+l[1]*c;return{coef:l,predict:u,rSquared:Ah(e,t,n,i,u)}}function wO(e,t,n){let r=0,i=0,s=0,o=0,a=0;o0(e,t,n,(c,f)=>{++a,c=Math.log(c),r+=(c-r)/a,i+=(f-i)/a,s+=(c*f-s)/a,o+=(c*c-o)/a});const l=s0(r,i,s,o),u=c=>l[0]+l[1]*Math.log(c);return{coef:l,predict:u,rSquared:Ah(e,t,n,i,u)}}function EO(e,t,n){const[r,i,s,o]=Hy(e,t,n);let a=0,l=0,u=0,c=0,f=0,d,h,p;o0(e,t,n,(b,x)=>{d=r[f++],h=Math.log(x),p=d*x,a+=(x*h-a)/f,l+=(p-l)/f,u+=(p*h-u)/f,c+=(d*p-c)/f});const[g,m]=s0(l/o,a/o,u/o,c/o),v=b=>Math.exp(g+m*(b-s));return{coef:[Math.exp(g-m*s),m],predict:v,rSquared:Ah(e,t,n,o,v)}}function AO(e,t,n){let r=0,i=0,s=0,o=0,a=0,l=0;o0(e,t,n,(f,d)=>{const h=Math.log(f),p=Math.log(d);++l,r+=(h-r)/l,i+=(p-i)/l,s+=(h*p-s)/l,o+=(h*h-o)/l,a+=(d-a)/l});const u=s0(r,i,s,o),c=f=>u[0]*Math.pow(f,u[1]);return u[0]=Math.exp(u[0]),{coef:u,predict:c,rSquared:Ah(e,t,n,a,c)}}function eS(e,t,n){const[r,i,s,o]=Hy(e,t,n),a=r.length;let l=0,u=0,c=0,f=0,d=0,h,p,g,m;for(h=0;h(E=E-s,x*E*E+_*E+w+o);return{coef:[w-_*s+x*s*s+o,_-2*x*s,x],predict:A,rSquared:Ah(e,t,n,o,A)}}function kO(e,t,n,r){if(r===0)return Jk(e,t,n);if(r===1)return Qk(e,t,n);if(r===2)return eS(e,t,n);const[i,s,o,a]=Hy(e,t,n),l=i.length,u=[],c=[],f=r+1;let d,h,p,g,m;for(d=0;d{x-=o;let _=a+v[0]+v[1]*x+v[2]*x*x;for(d=3;d=0;--s)for(a=t[s],l=1,i[s]+=a,o=1;o<=s;++o)l*=(s+1-o)/o,i[s-o]+=a*Math.pow(n,o)*l;return i[0]+=r,i}function qK(e){const t=e.length-1,n=[];let r,i,s,o,a;for(r=0;rMath.abs(e[r][o])&&(o=i);for(s=r;s=r;s--)e[s][i]-=e[s][r]*e[r][i]/e[r][r]}for(i=t-1;i>=0;--i){for(a=0,s=i+1;si[x]-v?b:x;let w=0,A=0,E=0,k=0,S=0;const $=1/Math.abs(i[_]-v||1);for(let P=b;P<=x;++P){const T=i[P],F=s[P],R=WK(Math.abs(v-T)*$)*d[P],z=T*R;w+=R,A+=z,E+=F*R,k+=F*z,S+=T*z}const[M,O]=s0(A/w,E/w,k/w,S/w);c[m]=M+O*v,f[m]=Math.abs(s[m]-c[m]),HK(i,m+1,p)}if(h===Z5)break;const g=dN(f);if(Math.abs(g)=1?J5:(b=1-v*v)*b}return GK(i,c,o,a)}function WK(e){return(e=1-e*e*e)*e*e}function HK(e,t,n){const r=e[t];let i=n[0],s=n[1]+1;if(!(s>=e.length))for(;t>i&&e[s]-r<=r-e[i];)n[0]=++i,n[1]=s,++s}function GK(e,t,n,r){const i=e.length,s=[];let o=0,a=0,l=[],u;for(;o[g,e(g)],s=t[0],o=t[1],a=o-s,l=a/r,u=[i(s)],c=[];if(n===r){for(let g=1;g0;)c.push(i(s+g/n*a))}let f=u[0],d=c[c.length-1];const h=1/a,p=VK(f[1],c);for(;d;){const g=i((f[0]+d[0])/2);g[0]-f[0]>=l&&XK(f,g,d,h,p)>YK?c.push(g):(f=d,u.push(d),c.pop()),d=c[c.length-1]}return u}function VK(e,t){let n=e,r=e;const i=t.length;for(let s=0;sr&&(r=o)}return 1/(r-n)}function XK(e,t,n,r,i){const s=Math.atan2(i*(n[1]-e[1]),r*(n[0]-e[0])),o=Math.atan2(i*(t[1]-e[1]),r*(t[0]-e[0]));return Math.abs(s-o)}function KK(e){return t=>{const n=e.length;let r=1,i=String(e[0](t));for(;r{},ZK={init:hx,add:hx,rem:hx,idx:0},pg={values:{init:e=>e.cell.store=!0,value:e=>e.cell.data.values(),idx:-1},count:{value:e=>e.cell.num},__count__:{value:e=>e.missing+e.valid},missing:{value:e=>e.missing},valid:{value:e=>e.valid},sum:{init:e=>e.sum=0,value:e=>e.valid?e.sum:void 0,add:(e,t)=>e.sum+=+t,rem:(e,t)=>e.sum-=t},product:{init:e=>e.product=1,value:e=>e.valid?e.product:void 0,add:(e,t)=>e.product*=t,rem:(e,t)=>e.product/=t},mean:{init:e=>e.mean=0,value:e=>e.valid?e.mean:void 0,add:(e,t)=>(e.mean_d=t-e.mean,e.mean+=e.mean_d/e.valid),rem:(e,t)=>(e.mean_d=t-e.mean,e.mean-=e.valid?e.mean_d/e.valid:e.mean)},average:{value:e=>e.valid?e.mean:void 0,req:["mean"],idx:1},variance:{init:e=>e.dev=0,value:e=>e.valid>1?e.dev/(e.valid-1):void 0,add:(e,t)=>e.dev+=e.mean_d*(t-e.mean),rem:(e,t)=>e.dev-=e.mean_d*(t-e.mean),req:["mean"],idx:1},variancep:{value:e=>e.valid>1?e.dev/e.valid:void 0,req:["variance"],idx:2},stdev:{value:e=>e.valid>1?Math.sqrt(e.dev/(e.valid-1)):void 0,req:["variance"],idx:2},stdevp:{value:e=>e.valid>1?Math.sqrt(e.dev/e.valid):void 0,req:["variance"],idx:2},stderr:{value:e=>e.valid>1?Math.sqrt(e.dev/(e.valid*(e.valid-1))):void 0,req:["variance"],idx:2},distinct:{value:e=>e.cell.data.distinct(e.get),req:["values"],idx:3},ci0:{value:e=>e.cell.data.ci0(e.get),req:["values"],idx:3},ci1:{value:e=>e.cell.data.ci1(e.get),req:["values"],idx:3},median:{value:e=>e.cell.data.q2(e.get),req:["values"],idx:3},q1:{value:e=>e.cell.data.q1(e.get),req:["values"],idx:3},q3:{value:e=>e.cell.data.q3(e.get),req:["values"],idx:3},min:{init:e=>e.min=void 0,value:e=>e.min=Number.isNaN(e.min)?e.cell.data.min(e.get):e.min,add:(e,t)=>{(t{t<=e.min&&(e.min=NaN)},req:["values"],idx:4},max:{init:e=>e.max=void 0,value:e=>e.max=Number.isNaN(e.max)?e.cell.data.max(e.get):e.max,add:(e,t)=>{(t>e.max||e.max===void 0)&&(e.max=t)},rem:(e,t)=>{t>=e.max&&(e.max=NaN)},req:["values"],idx:4},argmin:{init:e=>e.argmin=void 0,value:e=>e.argmin||e.cell.data.argmin(e.get),add:(e,t,n)=>{t{t<=e.min&&(e.argmin=void 0)},req:["min","values"],idx:3},argmax:{init:e=>e.argmax=void 0,value:e=>e.argmax||e.cell.data.argmax(e.get),add:(e,t,n)=>{t>e.max&&(e.argmax=n)},rem:(e,t)=>{t>=e.max&&(e.argmax=void 0)},req:["max","values"],idx:3},exponential:{init:(e,t)=>{e.exp=0,e.exp_r=t},value:e=>e.valid?e.exp*(1-e.exp_r)/(1-e.exp_r**e.valid):void 0,add:(e,t)=>e.exp=e.exp_r*e.exp+t,rem:(e,t)=>e.exp=(e.exp-t/e.exp_r**(e.valid-1))/e.exp_r},exponentialb:{value:e=>e.valid?e.exp*(1-e.exp_r):void 0,req:["exponential"],idx:1}},a0=Object.keys(pg).filter(e=>e!=="__count__");function JK(e,t){return(n,r)=>kt({name:e,aggregate_param:r,out:n||e},ZK,t)}[...a0,"__count__"].forEach(e=>{pg[e]=JK(e,pg[e])});function $O(e,t,n){return pg[e](n,t)}function FO(e,t){return e.idx-t.idx}function QK(e){const t={};e.forEach(r=>t[r.name]=r);const n=r=>{r.req&&r.req.forEach(i=>{t[i]||n(t[i]=pg[i]())})};return e.forEach(n),Object.values(t).sort(FO)}function eZ(){this.valid=0,this.missing=0,this._ops.forEach(e=>e.aggregate_param==null?e.init(this):e.init(this,e.aggregate_param))}function tZ(e,t){if(e==null||e===""){++this.missing;return}e===e&&(++this.valid,this._ops.forEach(n=>n.add(this,e,t)))}function nZ(e,t){if(e==null||e===""){--this.missing;return}e===e&&(--this.valid,this._ops.forEach(n=>n.rem(this,e,t)))}function rZ(e){return this._out.forEach(t=>e[t.out]=t.value(this)),e}function DO(e,t){const n=t||Qr,r=QK(e),i=e.slice().sort(FO);function s(o){this._ops=r,this._out=i,this.cell=o,this.init()}return s.prototype.init=eZ,s.prototype.add=tZ,s.prototype.rem=nZ,s.prototype.set=rZ,s.prototype.get=n,s.fields=e.map(o=>o.out),s}function tS(e){this._key=e?Os(e):it,this.reset()}const Nr=tS.prototype;Nr.reset=function(){this._add=[],this._rem=[],this._ext=null,this._get=null,this._q=null};Nr.add=function(e){this._add.push(e)};Nr.rem=function(e){this._rem.push(e)};Nr.values=function(){if(this._get=null,this._rem.length===0)return this._add;const e=this._add,t=this._rem,n=this._key,r=e.length,i=t.length,s=Array(r-i),o={};let a,l,u;for(a=0;a=0;)s=e(t[r])+"",We(n,s)||(n[s]=1,++i);return i};Nr.extent=function(e){if(this._get!==e||!this._ext){const t=this.values(),n=VR(t,e);this._ext=[t[n[0]],t[n[1]]],this._get=e}return this._ext};Nr.argmin=function(e){return this.extent(e)[0]||{}};Nr.argmax=function(e){return this.extent(e)[1]||{}};Nr.min=function(e){const t=this.extent(e)[0];return t!=null?e(t):void 0};Nr.max=function(e){const t=this.extent(e)[1];return t!=null?e(t):void 0};Nr.quartile=function(e){return(this._get!==e||!this._q)&&(this._q=Bk(this.values(),e),this._get=e),this._q};Nr.q1=function(e){return this.quartile(e)[0]};Nr.q2=function(e){return this.quartile(e)[1]};Nr.q3=function(e){return this.quartile(e)[2]};Nr.ci=function(e){return(this._get!==e||!this._ci)&&(this._ci=mO(this.values(),1e3,.05,e),this._get=e),this._ci};Nr.ci0=function(e){return this.ci(e)[0]};Nr.ci1=function(e){return this.ci(e)[1]};function ou(e){ne.call(this,null,e),this._adds=[],this._mods=[],this._alen=0,this._mlen=0,this._drop=!0,this._cross=!1,this._dims=[],this._dnames=[],this._measures=[],this._countOnly=!1,this._counts=null,this._prev=null,this._inputs=null,this._outputs=null}ou.Definition={type:"Aggregate",metadata:{generates:!0,changes:!0},params:[{name:"groupby",type:"field",array:!0},{name:"ops",type:"enum",array:!0,values:a0},{name:"aggregate_params",type:"number",null:!0,array:!0},{name:"fields",type:"field",null:!0,array:!0},{name:"as",type:"string",null:!0,array:!0},{name:"drop",type:"boolean",default:!0},{name:"cross",type:"boolean",default:!1},{name:"key",type:"field"}]};Te(ou,ne,{transform(e,t){const n=this,r=t.fork(t.NO_SOURCE|t.NO_FIELDS),i=e.modified();return n.stamp=r.stamp,n.value&&(i||t.modified(n._inputs,!0))?(n._prev=n.value,n.value=i?n.init(e):Object.create(null),t.visit(t.SOURCE,s=>n.add(s))):(n.value=n.value||n.init(e),t.visit(t.REM,s=>n.rem(s)),t.visit(t.ADD,s=>n.add(s))),r.modifies(n._outputs),n._drop=e.drop!==!1,e.cross&&n._dims.length>1&&(n._drop=!1,n.cross()),t.clean()&&n._drop&&r.clean(!0).runAfter(()=>this.clean()),n.changes(r)},cross(){const e=this,t=e.value,n=e._dnames,r=n.map(()=>({})),i=n.length;function s(a){let l,u,c,f;for(l in a)for(c=a[l].tuple,u=0;u{const x=On(b);return i(b),n.push(x),x}),this.cellkey=e.key?e.key:Tw(this._dims),this._countOnly=!0,this._counts=[],this._measures=[];const s=e.fields||[null],o=e.ops||["count"],a=e.aggregate_params||[null],l=e.as||[],u=s.length,c={};let f,d,h,p,g,m,v;for(u!==o.length&&ae("Unmatched number of fields and aggregate ops."),v=0;vDO(b,b.field)),Object.create(null)},cellkey:Tw(),cell(e,t){let n=this.value[e];return n?n.num===0&&this._drop&&n.stamp{const f=r(c);c[a]=f,c[l]=f==null?null:i+s*(1+(f-i)/s)}:c=>c[a]=r(c)),t.modifies(n?o:a)},_bins(e){if(this.value&&!e.modified())return this.value;const t=e.field,n=gO(e),r=n.step;let i=n.start,s=i+Math.ceil((n.stop-i)/r)*r,o,a;(o=e.anchor)!=null&&(a=o-(i+r*Math.floor((o-i)/r)),i+=a,s+=a);const l=function(u){let c=Hr(t(u));return c==null?null:cs?1/0:(c=Math.max(i,Math.min(c,s-r)),i+r*Math.floor(iZ+(c-i)/r))};return l.start=i,l.stop=n.stop,l.step=r,this.value=Gi(l,Yr(t),e.name||"bin_"+On(t))}});function MO(e,t,n){const r=e;let i=t||[],s=n||[],o={},a=0;return{add:l=>s.push(l),remove:l=>o[r(l)]=++a,size:()=>i.length,data:(l,u)=>(a&&(i=i.filter(c=>!o[r(c)]),o={},a=0),u&&l&&i.sort(l),s.length&&(i=l?QR(l,i,s.sort(l)):i.concat(s),s=[]),i)}}function rS(e){ne.call(this,[],e)}rS.Definition={type:"Collect",metadata:{source:!0},params:[{name:"sort",type:"compare"}]};Te(rS,ne,{transform(e,t){const n=t.fork(t.ALL),r=MO(it,this.value,n.materialize(n.ADD).add),i=e.sort,s=t.changed()||i&&(e.modified("sort")||t.modified(i.fields));return n.visit(n.REM,r.remove),this.modified(s),this.value=n.source=r.data(pf(i),s),t.source&&t.source.root&&(this.value.root=t.source.root),n}});function TO(e){cn.call(this,null,sZ,e)}Te(TO,cn);function sZ(e){return this.value&&!e.modified()?this.value:mk(e.fields,e.orders)}function iS(e){ne.call(this,null,e)}iS.Definition={type:"CountPattern",metadata:{generates:!0,changes:!0},params:[{name:"field",type:"field",required:!0},{name:"case",type:"enum",values:["upper","lower","mixed"],default:"mixed"},{name:"pattern",type:"string",default:'[\\w"]+'},{name:"stopwords",type:"string",default:""},{name:"as",type:"string",array:!0,length:2,default:["text","count"]}]};function oZ(e,t,n){switch(t){case"upper":e=e.toUpperCase();break;case"lower":e=e.toLowerCase();break}return e.match(n)}Te(iS,ne,{transform(e,t){const n=f=>d=>{for(var h=oZ(a(d),e.case,s)||[],p,g=0,m=h.length;gi[f]=1+(i[f]||0)),c=n(f=>i[f]-=1);return r?t.visit(t.SOURCE,u):(t.visit(t.ADD,u),t.visit(t.REM,c)),this._finish(t,l)},_parameterCheck(e,t){let n=!1;return(e.modified("stopwords")||!this._stop)&&(this._stop=new RegExp("^"+(e.stopwords||"")+"$","i"),n=!0),(e.modified("pattern")||!this._match)&&(this._match=new RegExp(e.pattern||"[\\w']+","g"),n=!0),(e.modified("field")||t.modified(e.field.fields))&&(n=!0),n&&(this._counts={}),n},_finish(e,t){const n=this._counts,r=this._tuples||(this._tuples={}),i=t[0],s=t[1],o=e.fork(e.NO_SOURCE|e.NO_FIELDS);let a,l,u;for(a in n)l=r[a],u=n[a]||0,!l&&u?(r[a]=l=Kt({}),l[i]=a,l[s]=u,o.add.push(l)):u===0?(l&&o.rem.push(l),n[a]=null,r[a]=null):l[s]!==u&&(l[s]=u,o.mod.push(l));return o.modifies(t)}});function sS(e){ne.call(this,null,e)}sS.Definition={type:"Cross",metadata:{generates:!0},params:[{name:"filter",type:"expr"},{name:"as",type:"string",array:!0,length:2,default:["a","b"]}]};Te(sS,ne,{transform(e,t){const n=t.fork(t.NO_SOURCE),r=e.as||["a","b"],i=r[0],s=r[1],o=!this.value||t.changed(t.ADD_REM)||e.modified("as")||e.modified("filter");let a=this.value;return o?(a&&(n.rem=a),a=t.materialize(t.SOURCE).source,n.add=this.value=aZ(a,i,s,e.filter||fs)):n.mod=a,n.source=this.value,n.modifies(r)}});function aZ(e,t,n,r){for(var i=[],s={},o=e.length,a=0,l,u;aRO(s,t))):typeof r[i]===eD&&r[i](e[i]);return r}function oS(e){ne.call(this,null,e)}const NO=[{key:{function:"normal"},params:[{name:"mean",type:"number",default:0},{name:"stdev",type:"number",default:1}]},{key:{function:"lognormal"},params:[{name:"mean",type:"number",default:0},{name:"stdev",type:"number",default:1}]},{key:{function:"uniform"},params:[{name:"min",type:"number",default:0},{name:"max",type:"number",default:1}]},{key:{function:"kde"},params:[{name:"field",type:"field",required:!0},{name:"from",type:"data"},{name:"bandwidth",type:"number",default:0}]}],cZ={key:{function:"mixture"},params:[{name:"distributions",type:"param",array:!0,params:NO},{name:"weights",type:"number",array:!0}]};oS.Definition={type:"Density",metadata:{generates:!0},params:[{name:"extent",type:"number",array:!0,length:2},{name:"steps",type:"number"},{name:"minsteps",type:"number",default:25},{name:"maxsteps",type:"number",default:200},{name:"method",type:"string",default:"pdf",values:["pdf","cdf"]},{name:"distribution",type:"param",params:NO.concat(cZ)},{name:"as",type:"string",array:!0,default:["value","density"]}]};Te(oS,ne,{transform(e,t){const n=t.fork(t.NO_SOURCE|t.NO_FIELDS);if(!this.value||t.changed()||e.modified()){const r=RO(e.distribution,fZ(t)),i=e.steps||e.minsteps||25,s=e.steps||e.maxsteps||200;let o=e.method||"pdf";o!=="pdf"&&o!=="cdf"&&ae("Invalid density method: "+o),!e.extent&&!r.data&&ae("Missing density extent parameter."),o=r[o];const a=e.as||["value","density"],l=e.extent||aa(r.data()),u=Gy(o,l,i,s).map(c=>{const f={};return f[a[0]]=c[0],f[a[1]]=c[1],Kt(f)});this.value&&(n.rem=this.value),this.value=n.add=n.source=u}return n}});function fZ(e){return()=>e.materialize(e.SOURCE).source}function OO(e,t){return e?e.map((n,r)=>t[r]||On(n)):null}function aS(e,t,n){const r=[],i=f=>f(l);let s,o,a,l,u,c;if(t==null)r.push(e.map(n));else for(s={},o=0,a=e.length;oi0(aa(e,t))/30;Te(lS,ne,{transform(e,t){if(this.value&&!(e.modified()||t.changed()))return t;const n=t.materialize(t.SOURCE).source,r=aS(t.source,e.groupby,Qr),i=e.smooth||!1,s=e.field,o=e.step||dZ(n,s),a=pf((p,g)=>s(p)-s(g)),l=e.as||LO,u=r.length;let c=1/0,f=-1/0,d=0,h;for(;df&&(f=g),p[++h][l]=g}return this.value={start:c,stop:f,step:o},t.reflow(!0).modifies(l)}});function IO(e){cn.call(this,null,hZ,e),this.modified(!0)}Te(IO,cn);function hZ(e){const t=e.expr;return this.value&&!e.modified("expr")?this.value:Gi(n=>t(n,e),Yr(t),On(t))}function uS(e){ne.call(this,[void 0,void 0],e)}uS.Definition={type:"Extent",metadata:{},params:[{name:"field",type:"field",required:!0}]};Te(uS,ne,{transform(e,t){const n=this.value,r=e.field,i=t.changed()||t.modified(r.fields)||e.modified("field");let s=n[0],o=n[1];if((i||s==null)&&(s=1/0,o=-1/0),t.visit(i?t.SOURCE:t.ADD,a=>{const l=Hr(r(a));l!=null&&(lo&&(o=l))}),!Number.isFinite(s)||!Number.isFinite(o)){let a=On(r);a&&(a=` for field "${a}"`),t.dataflow.warn(`Infinite extent${a}: [${s}, ${o}]`),s=o=void 0}this.value=[s,o]}});function cS(e,t){cn.call(this,e),this.parent=t,this.count=0}Te(cS,cn,{connect(e){return this.detachSubflow=e.detachSubflow,this.targets().add(e),e.source=this},add(e){this.count+=1,this.value.add.push(e)},rem(e){this.count-=1,this.value.rem.push(e)},mod(e){this.value.mod.push(e)},init(e){this.value.init(e,e.NO_SOURCE)},evaluate(){return this.value}});function Yy(e){ne.call(this,{},e),this._keys=yh();const t=this._targets=[];t.active=0,t.forEach=n=>{for(let r=0,i=t.active;rr&&r.count>0);this.initTargets(n)}},initTargets(e){const t=this._targets,n=t.length,r=e?e.length:0;let i=0;for(;ithis.subflow(l,i,t);return this._group=e.group||{},this.initTargets(),t.visit(t.REM,l=>{const u=it(l),c=s.get(u);c!==void 0&&(s.delete(u),a(c).rem(l))}),t.visit(t.ADD,l=>{const u=r(l);s.set(it(l),u),a(u).add(l)}),o||t.modified(r.fields)?t.visit(t.MOD,l=>{const u=it(l),c=s.get(u),f=r(l);c===f?a(f).mod(l):(s.set(u,f),a(c).rem(l),a(f).add(l))}):t.changed(t.MOD)&&t.visit(t.MOD,l=>{a(s.get(it(l))).mod(l)}),o&&t.visit(t.REFLOW,l=>{const u=it(l),c=s.get(u),f=r(l);c!==f&&(s.set(u,f),a(c).rem(l),a(f).add(l))}),t.clean()?n.runAfter(()=>{this.clean(),s.clean()}):s.empty>n.cleanThreshold&&n.runAfter(s.clean),t}});function PO(e){cn.call(this,null,pZ,e)}Te(PO,cn);function pZ(e){return this.value&&!e.modified()?this.value:fe(e.name)?je(e.name).map(t=>Os(t)):Os(e.name,e.as)}function fS(e){ne.call(this,yh(),e)}fS.Definition={type:"Filter",metadata:{changes:!0},params:[{name:"expr",type:"expr",required:!0}]};Te(fS,ne,{transform(e,t){const n=t.dataflow,r=this.value,i=t.fork(),s=i.add,o=i.rem,a=i.mod,l=e.expr;let u=!0;t.visit(t.REM,f=>{const d=it(f);r.has(d)?r.delete(d):o.push(f)}),t.visit(t.ADD,f=>{l(f,e)?s.push(f):r.set(it(f),1)});function c(f){const d=it(f),h=l(f,e),p=r.get(d);h&&p?(r.delete(d),s.push(f)):!h&&!p?(r.set(d,1),o.push(f)):u&&h&&!p&&a.push(f)}return t.visit(t.MOD,c),e.modified()&&(u=!1,t.visit(t.REFLOW,c)),r.empty>n.cleanThreshold&&n.runAfter(r.clean),i}});function dS(e){ne.call(this,[],e)}dS.Definition={type:"Flatten",metadata:{generates:!0},params:[{name:"fields",type:"field",array:!0,required:!0},{name:"index",type:"string"},{name:"as",type:"string",array:!0}]};Te(dS,ne,{transform(e,t){const n=t.fork(t.NO_SOURCE),r=e.fields,i=OO(r,e.as||[]),s=e.index||null,o=i.length;return n.rem=this.value,t.visit(t.SOURCE,a=>{const l=r.map(p=>p(a)),u=l.reduce((p,g)=>Math.max(p,g.length),0);let c=0,f,d,h;for(;c{for(let c=0,f;co[r]=n(o,e))}});function BO(e){ne.call(this,[],e)}Te(BO,ne,{transform(e,t){const n=t.fork(t.ALL),r=e.generator;let i=this.value,s=e.size-i.length,o,a,l;if(s>0){for(o=[];--s>=0;)o.push(l=Kt(r(e))),i.push(l);n.add=n.add.length?n.materialize(n.ADD).add.concat(o):o}else a=i.slice(0,-s),n.rem=n.rem.length?n.materialize(n.REM).rem.concat(a):a,i=i.slice(-s);return n.source=this.value=i,n}});const lm={value:"value",median:dN,mean:KY,min:_w,max:wc},gZ=[];function gS(e){ne.call(this,[],e)}gS.Definition={type:"Impute",metadata:{changes:!0},params:[{name:"field",type:"field",required:!0},{name:"key",type:"field",required:!0},{name:"keyvals",array:!0},{name:"groupby",type:"field",array:!0},{name:"method",type:"enum",default:"value",values:["value","mean","median","max","min"]},{name:"value",default:0}]};function mZ(e){var t=e.method||lm.value,n;if(lm[t]==null)ae("Unrecognized imputation method: "+t);else return t===lm.value?(n=e.value!==void 0?e.value:0,()=>n):lm[t]}function vZ(e){const t=e.field;return n=>n?t(n):NaN}Te(gS,ne,{transform(e,t){var n=t.fork(t.ALL),r=mZ(e),i=vZ(e),s=On(e.field),o=On(e.key),a=(e.groupby||[]).map(On),l=yZ(t.source,e.groupby,e.key,e.keyvals),u=[],c=this.value,f=l.domain.length,d,h,p,g,m,v,b,x,_,w;for(m=0,x=l.length;mv(m),s=[],o=r?r.slice():[],a={},l={},u,c,f,d,h,p,g,m;for(o.forEach((v,b)=>a[v]=b+1),d=0,g=e.length;dn.add(s))):(i=n.value=n.value||this.init(e),t.visit(t.REM,s=>n.rem(s)),t.visit(t.ADD,s=>n.add(s))),n.changes(),t.visit(t.SOURCE,s=>{kt(s,i[n.cellkey(s)].tuple)}),t.reflow(r).modifies(this._outputs)},changes(){const e=this._adds,t=this._mods;let n,r;for(n=0,r=this._alen;n{const p=qk(h,o)[a],g=e.counts?h.length:1,m=c||aa(h);Gy(p,m,f,d).forEach(v=>{const b={};for(let x=0;x(this._pending=je(i.data),s=>s.touch(this)))}:n.request(e.url,e.format).then(r=>px(this,t,je(r.data)))}});function xZ(e){return e.modified("async")&&!(e.modified("values")||e.modified("url")||e.modified("format"))}function px(e,t,n){n.forEach(Kt);const r=t.fork(t.NO_FIELDS&t.NO_SOURCE);return r.rem=e.value,e.value=r.source=r.add=n,e._pending=null,r.rem.length&&r.clean(!0),r}function yS(e){ne.call(this,{},e)}yS.Definition={type:"Lookup",metadata:{modifies:!0},params:[{name:"index",type:"index",params:[{name:"from",type:"data",required:!0},{name:"key",type:"field",required:!0}]},{name:"values",type:"field",array:!0},{name:"fields",type:"field",array:!0,required:!0},{name:"as",type:"string",array:!0},{name:"default",default:null}]};Te(yS,ne,{transform(e,t){const n=e.fields,r=e.index,i=e.values,s=e.default==null?null:e.default,o=e.modified(),a=n.length;let l=o?t.SOURCE:t.ADD,u=t,c=e.as,f,d,h;return i?(d=i.length,a>1&&!c&&ae('Multi-field lookup requires explicit "as" parameter.'),c&&c.length!==a*d&&ae('The "as" parameter has too few output field names.'),c=c||i.map(On),f=function(p){for(var g=0,m=0,v,b;gt.modified(p.fields)),l|=h?t.MOD:0),t.visit(l,f),u.modifies(c)}});function UO(e){cn.call(this,null,_Z,e)}Te(UO,cn);function _Z(e){if(this.value&&!e.modified())return this.value;const t=e.extents,n=t.length;let r=1/0,i=-1/0,s,o;for(s=0;si&&(i=o[1]);return[r,i]}function qO(e){cn.call(this,null,wZ,e)}Te(qO,cn);function wZ(e){return this.value&&!e.modified()?this.value:e.values.reduce((t,n)=>t.concat(n),[])}function WO(e){ne.call(this,null,e)}Te(WO,ne,{transform(e,t){return this.modified(e.modified()),this.value=e,t.fork(t.NO_SOURCE|t.NO_FIELDS)}});function bS(e){ou.call(this,e)}bS.Definition={type:"Pivot",metadata:{generates:!0,changes:!0},params:[{name:"groupby",type:"field",array:!0},{name:"field",type:"field",required:!0},{name:"value",type:"field",required:!0},{name:"op",type:"enum",values:a0,default:"sum"},{name:"limit",type:"number",default:0},{name:"key",type:"field"}]};Te(bS,ou,{_transform:ou.prototype.transform,transform(e,t){return this._transform(EZ(e,t),t)}});function EZ(e,t){const n=e.field,r=e.value,i=(e.op==="count"?"__count__":e.op)||"sum",s=Yr(n).concat(Yr(r)),o=kZ(n,e.limit||0,t);return t.changed()&&e.set("__pivot__",null,null,!0),{key:e.key,groupby:e.groupby,ops:o.map(()=>i),fields:o.map(a=>AZ(a,n,r,s)),as:o.map(a=>a+""),modified:e.modified.bind(e)}}function AZ(e,t,n,r){return Gi(i=>t(i)===e?n(i):NaN,r,e+"")}function kZ(e,t,n){const r={},i=[];return n.visit(n.SOURCE,s=>{const o=e(s);r[o]||(r[o]=1,i.push(o))}),i.sort(vh),t?i.slice(0,t):i}function HO(e){Yy.call(this,e)}Te(HO,Yy,{transform(e,t){const n=e.subflow,r=e.field,i=s=>this.subflow(it(s),n,t,s);return(e.modified("field")||r&&t.modified(Yr(r)))&&ae("PreFacet does not support field modification."),this.initTargets(),r?(t.visit(t.MOD,s=>{const o=i(s);r(s).forEach(a=>o.mod(a))}),t.visit(t.ADD,s=>{const o=i(s);r(s).forEach(a=>o.add(Kt(a)))}),t.visit(t.REM,s=>{const o=i(s);r(s).forEach(a=>o.rem(a))})):(t.visit(t.MOD,s=>i(s).mod(s)),t.visit(t.ADD,s=>i(s).add(s)),t.visit(t.REM,s=>i(s).rem(s))),t.clean()&&t.runAfter(()=>this.clean()),t}});function xS(e){ne.call(this,null,e)}xS.Definition={type:"Project",metadata:{generates:!0,changes:!0},params:[{name:"fields",type:"field",array:!0},{name:"as",type:"string",null:!0,array:!0}]};Te(xS,ne,{transform(e,t){const n=t.fork(t.NO_SOURCE),r=e.fields,i=OO(e.fields,e.as||[]),s=r?(a,l)=>SZ(a,l,r,i):By;let o;return this.value?o=this.value:(t=t.addAll(),o=this.value={}),t.visit(t.REM,a=>{const l=it(a);n.rem.push(o[l]),o[l]=null}),t.visit(t.ADD,a=>{const l=s(a,Kt({}));o[it(a)]=l,n.add.push(l)}),t.visit(t.MOD,a=>{n.mod.push(s(a,o[it(a)]))}),n}});function SZ(e,t,n,r){for(let i=0,s=n.length;i{const d=Pk(f,u);for(let h=0;h{const s=it(i);n.rem.push(r[s]),r[s]=null}),t.visit(t.ADD,i=>{const s=Ok(i);r[it(i)]=s,n.add.push(s)}),t.visit(t.MOD,i=>{const s=r[it(i)];for(const o in i)s[o]=i[o],n.modifies(o);n.mod.push(s)})),n}});function wS(e){ne.call(this,[],e),this.count=0}wS.Definition={type:"Sample",metadata:{},params:[{name:"size",type:"number",default:1e3}]};Te(wS,ne,{transform(e,t){const n=t.fork(t.NO_SOURCE),r=e.modified("size"),i=e.size,s=this.value.reduce((c,f)=>(c[it(f)]=1,c),{});let o=this.value,a=this.count,l=0;function u(c){let f,d;o.length=l&&(f=o[d],s[it(f)]&&n.rem.push(f),o[d]=c)),++a}if(t.rem.length&&(t.visit(t.REM,c=>{const f=it(c);s[f]&&(s[f]=-1,n.rem.push(c)),--a}),o=o.filter(c=>s[it(c)]!==-1)),(t.rem.length||r)&&o.length{s[it(c)]||u(c)}),l=-1),r&&o.length>i){const c=o.length-i;for(let f=0;f{s[it(c)]&&n.mod.push(c)}),t.add.length&&t.visit(t.ADD,u),(t.add.length||l<0)&&(n.add=o.filter(c=>!s[it(c)])),this.count=a,this.value=n.source=o,n}});function ES(e){ne.call(this,null,e)}ES.Definition={type:"Sequence",metadata:{generates:!0,changes:!0},params:[{name:"start",type:"number",required:!0},{name:"stop",type:"number",required:!0},{name:"step",type:"number",default:1},{name:"as",type:"string",default:"data"}]};Te(ES,ne,{transform(e,t){if(this.value&&!e.modified())return;const n=t.materialize().fork(t.MOD),r=e.as||"data";return n.rem=this.value?t.rem.concat(this.value):t.rem,this.value=is(e.start,e.stop,e.step||1).map(i=>{const s={};return s[r]=i,Kt(s)}),n.add=t.add.concat(this.value),n}});function VO(e){ne.call(this,null,e),this.modified(!0)}Te(VO,ne,{transform(e,t){return this.value=t.source,t.changed()?t.fork(t.NO_SOURCE|t.NO_FIELDS):t.StopPropagation}});function AS(e){ne.call(this,null,e)}const XO=["unit0","unit1"];AS.Definition={type:"TimeUnit",metadata:{modifies:!0},params:[{name:"field",type:"field",required:!0},{name:"interval",type:"boolean",default:!0},{name:"units",type:"enum",values:Sk,array:!0},{name:"step",type:"number",default:1},{name:"maxbins",type:"number",default:40},{name:"extent",type:"date",array:!0},{name:"timezone",type:"enum",default:"local",values:["local","utc"]},{name:"as",type:"string",array:!0,length:2,default:XO}]};Te(AS,ne,{transform(e,t){const n=e.field,r=e.interval!==!1,i=e.timezone==="utc",s=this._floor(e,t),o=(i?Eh:wh)(s.unit).offset,a=e.as||XO,l=a[0],u=a[1],c=s.step;let f=s.start||1/0,d=s.stop||-1/0,h=t.ADD;return(e.modified()||t.changed(t.REM)||t.modified(Yr(n)))&&(t=t.reflow(!0),h=t.SOURCE,f=1/0,d=-1/0),t.visit(h,p=>{const g=n(p);let m,v;g==null?(p[l]=null,r&&(p[u]=null)):(p[l]=m=v=s(g),r&&(p[u]=v=o(m,c)),md&&(d=v))}),s.start=f,s.stop=d,t.modifies(r?a:l)},_floor(e,t){const n=e.timezone==="utc",{units:r,step:i}=e.units?{units:e.units,step:e.step||1}:BN({extent:e.extent||aa(t.materialize(t.SOURCE).source,e.field),maxbins:e.maxbins}),s=Ck(r),o=this.value||{},a=(n?DN:FN)(s,i);return a.unit=jt(s),a.units=s,a.step=i,a.start=o.start,a.stop=o.stop,this.value=a}});function KO(e){ne.call(this,yh(),e)}Te(KO,ne,{transform(e,t){const n=t.dataflow,r=e.field,i=this.value,s=a=>i.set(r(a),a);let o=!0;return e.modified("field")||t.modified(r.fields)?(i.clear(),t.visit(t.SOURCE,s)):t.changed()?(t.visit(t.REM,a=>i.delete(r(a))),t.visit(t.ADD,s)):o=!1,this.modified(o),i.empty>n.cleanThreshold&&n.runAfter(i.clean),t.fork()}});function ZO(e){ne.call(this,null,e)}Te(ZO,ne,{transform(e,t){(!this.value||e.modified("field")||e.modified("sort")||t.changed()||e.sort&&t.modified(e.sort.fields))&&(this.value=(e.sort?t.source.slice().sort(pf(e.sort)):t.source).map(e.field))}});function $Z(e,t,n,r){const i=gg[e](t,n);return{init:i.init||Ol,update:function(s,o){o[r]=i.next(s)}}}const gg={row_number:function(){return{next:e=>e.index+1}},rank:function(){let e;return{init:()=>e=1,next:t=>{const n=t.index,r=t.data;return n&&t.compare(r[n-1],r[n])?e=n+1:e}}},dense_rank:function(){let e;return{init:()=>e=1,next:t=>{const n=t.index,r=t.data;return n&&t.compare(r[n-1],r[n])?++e:e}}},percent_rank:function(){const e=gg.rank(),t=e.next;return{init:e.init,next:n=>(t(n)-1)/(n.data.length-1)}},cume_dist:function(){let e;return{init:()=>e=0,next:t=>{const n=t.data,r=t.compare;let i=t.index;if(e0||ae("ntile num must be greater than zero.");const n=gg.cume_dist(),r=n.next;return{init:n.init,next:i=>Math.ceil(t*r(i))}},lag:function(e,t){return t=+t||1,{next:n=>{const r=n.index-t;return r>=0?e(n.data[r]):null}}},lead:function(e,t){return t=+t||1,{next:n=>{const r=n.index+t,i=n.data;return re(t.data[t.i0])}},last_value:function(e){return{next:t=>e(t.data[t.i1-1])}},nth_value:function(e,t){return t=+t,t>0||ae("nth_value nth must be greater than zero."),{next:n=>{const r=n.i0+(t-1);return rt=null,next:n=>{const r=e(n.data[n.index]);return r!=null?t=r:t}}},next_value:function(e){let t,n;return{init:()=>(t=null,n=-1),next:r=>{const i=r.data;return r.index<=n?t:(n=FZ(e,i,r.index))<0?(n=i.length,t=null):t=e(i[n])}}}};function FZ(e,t,n){for(let r=t.length;nl[g]=1)}h(e.sort),t.forEach((p,g)=>{const m=n[g],v=r[g],b=i[g]||null,x=On(m),_=CO(p,x,s[g]);if(h(m),o.push(_),We(gg,p))a.push($Z(p,m,v,_));else{if(m==null&&p!=="count"&&ae("Null aggregate field specified."),p==="count"){c.push(_);return}d=!1;let w=u[x];w||(w=u[x]=[],w.field=m,f.push(w)),w.push($O(p,b,_))}}),(c.length||f.length)&&(this.cell=MZ(f,c,d)),this.inputs=Object.keys(l)}const QO=JO.prototype;QO.init=function(){this.windows.forEach(e=>e.init()),this.cell&&this.cell.init()};QO.update=function(e,t){const n=this.cell,r=this.windows,i=e.data,s=r&&r.length;let o;if(n){for(o=e.p0;oDO(l,l.field));const r={num:0,agg:null,store:!1,count:t};if(!n)for(var i=e.length,s=r.agg=Array(i),o=0;othis.group(i(a));let o=this.state;(!o||n)&&(o=this.state=new JO(e)),n||t.modified(o.inputs)?(this.value={},t.visit(t.SOURCE,a=>s(a).add(a))):(t.visit(t.REM,a=>s(a).remove(a)),t.visit(t.ADD,a=>s(a).add(a)));for(let a=0,l=this._mlen;a0&&!i(s[n],s[n-1])&&(e.i0=t.left(s,s[n])),r1?0:e<-1?Ld:Math.acos(e)}function nD(e){return e>=1?X1:e<=-1?-X1:Math.asin(e)}const Rw=Math.PI,Nw=2*Rw,tc=1e-6,PZ=Nw-tc;function t7(e){this._+=e[0];for(let t=1,n=e.length;t=0))throw new Error(`invalid digits: ${e}`);if(t>15)return t7;const n=10**t;return function(r){this._+=r[0];for(let i=1,s=r.length;itc)if(!(Math.abs(f*l-u*c)>tc)||!s)this._append`L${this._x1=t},${this._y1=n}`;else{let h=r-o,p=i-a,g=l*l+u*u,m=h*h+p*p,v=Math.sqrt(g),b=Math.sqrt(d),x=s*Math.tan((Rw-Math.acos((g+d-m)/(2*v*b)))/2),_=x/b,w=x/v;Math.abs(_-1)>tc&&this._append`L${t+_*c},${n+_*f}`,this._append`A${s},${s},0,0,${+(f*h>c*p)},${this._x1=t+w*l},${this._y1=n+w*u}`}}arc(t,n,r,i,s,o){if(t=+t,n=+n,r=+r,o=!!o,r<0)throw new Error(`negative radius: ${r}`);let a=r*Math.cos(i),l=r*Math.sin(i),u=t+a,c=n+l,f=1^o,d=o?i-s:s-i;this._x1===null?this._append`M${u},${c}`:(Math.abs(this._x1-u)>tc||Math.abs(this._y1-c)>tc)&&this._append`L${u},${c}`,r&&(d<0&&(d=d%Nw+Nw),d>PZ?this._append`A${r},${r},0,1,${f},${t-a},${n-l}A${r},${r},0,1,${f},${this._x1=u},${this._y1=c}`:d>tc&&this._append`A${r},${r},0,${+(d>=Rw)},${f},${this._x1=t+r*Math.cos(s)},${this._y1=n+r*Math.sin(s)}`)}rect(t,n,r,i){this._append`M${this._x0=this._x1=+t},${this._y0=this._y1=+n}h${r=+r}v${+i}h${-r}Z`}toString(){return this._}};function Vy(){return new SS}Vy.prototype=SS.prototype;function Xy(e){let t=3;return e.digits=function(n){if(!arguments.length)return t;if(n==null)t=null;else{const r=Math.floor(n);if(!(r>=0))throw new RangeError(`invalid digits: ${n}`);t=r}return e},()=>new SS(t)}function zZ(e){return e.innerRadius}function jZ(e){return e.outerRadius}function UZ(e){return e.startAngle}function qZ(e){return e.endAngle}function WZ(e){return e&&e.padAngle}function HZ(e,t,n,r,i,s,o,a){var l=n-e,u=r-t,c=o-i,f=a-s,d=f*l-c*u;if(!(d*dT*T+F*F&&(k=$,S=M),{cx:k,cy:S,x01:-c,y01:-f,x11:k*(i/w-1),y11:S*(i/w-1)}}function GZ(){var e=zZ,t=jZ,n=Jt(0),r=null,i=UZ,s=qZ,o=WZ,a=null,l=Xy(u);function u(){var c,f,d=+e.apply(this,arguments),h=+t.apply(this,arguments),p=i.apply(this,arguments)-X1,g=s.apply(this,arguments)-X1,m=tD(g-p),v=g>p;if(a||(a=c=l()),hjr))a.moveTo(0,0);else if(m>e7-jr)a.moveTo(h*Wu(p),h*No(p)),a.arc(0,0,h,p,g,!v),d>jr&&(a.moveTo(d*Wu(g),d*No(g)),a.arc(0,0,d,g,p,v));else{var b=p,x=g,_=p,w=g,A=m,E=m,k=o.apply(this,arguments)/2,S=k>jr&&(r?+r.apply(this,arguments):hc(d*d+h*h)),$=gx(tD(h-d)/2,+n.apply(this,arguments)),M=$,O=$,P,T;if(S>jr){var F=nD(S/d*No(k)),R=nD(S/h*No(k));(A-=F*2)>jr?(F*=v?1:-1,_+=F,w-=F):(A=0,_=w=(p+g)/2),(E-=R*2)>jr?(R*=v?1:-1,b+=R,x-=R):(E=0,b=x=(p+g)/2)}var z=h*Wu(b),j=h*No(b),q=d*Wu(w),te=d*No(w);if($>jr){var Y=h*Wu(x),ee=h*No(x),_e=d*Wu(_),Le=d*No(_),Z;if(mjr?O>jr?(P=um(_e,Le,z,j,h,O,v),T=um(Y,ee,q,te,h,O,v),a.moveTo(P.cx+P.x01,P.cy+P.y01),O<$?a.arc(P.cx,P.cy,O,Br(P.y01,P.x01),Br(T.y01,T.x01),!v):(a.arc(P.cx,P.cy,O,Br(P.y01,P.x01),Br(P.y11,P.x11),!v),a.arc(0,0,h,Br(P.cy+P.y11,P.cx+P.x11),Br(T.cy+T.y11,T.cx+T.x11),!v),a.arc(T.cx,T.cy,O,Br(T.y11,T.x11),Br(T.y01,T.x01),!v))):(a.moveTo(z,j),a.arc(0,0,h,b,x,!v)):a.moveTo(z,j),!(d>jr)||!(A>jr)?a.lineTo(q,te):M>jr?(P=um(q,te,Y,ee,d,-M,v),T=um(z,j,_e,Le,d,-M,v),a.lineTo(P.cx+P.x01,P.cy+P.y01),M<$?a.arc(P.cx,P.cy,M,Br(P.y01,P.x01),Br(T.y01,T.x01),!v):(a.arc(P.cx,P.cy,M,Br(P.y01,P.x01),Br(P.y11,P.x11),!v),a.arc(0,0,d,Br(P.cy+P.y11,P.cx+P.x11),Br(T.cy+T.y11,T.cx+T.x11),v),a.arc(T.cx,T.cy,M,Br(T.y11,T.x11),Br(T.y01,T.x01),!v))):a.arc(0,0,d,w,_,v)}if(a.closePath(),c)return a=null,c+""||null}return u.centroid=function(){var c=(+e.apply(this,arguments)+ +t.apply(this,arguments))/2,f=(+i.apply(this,arguments)+ +s.apply(this,arguments))/2-Ld/2;return[Wu(f)*c,No(f)*c]},u.innerRadius=function(c){return arguments.length?(e=typeof c=="function"?c:Jt(+c),u):e},u.outerRadius=function(c){return arguments.length?(t=typeof c=="function"?c:Jt(+c),u):t},u.cornerRadius=function(c){return arguments.length?(n=typeof c=="function"?c:Jt(+c),u):n},u.padRadius=function(c){return arguments.length?(r=c==null?null:typeof c=="function"?c:Jt(+c),u):r},u.startAngle=function(c){return arguments.length?(i=typeof c=="function"?c:Jt(+c),u):i},u.endAngle=function(c){return arguments.length?(s=typeof c=="function"?c:Jt(+c),u):s},u.padAngle=function(c){return arguments.length?(o=typeof c=="function"?c:Jt(+c),u):o},u.context=function(c){return arguments.length?(a=c??null,u):a},u}function n7(e){return typeof e=="object"&&"length"in e?e:Array.from(e)}function r7(e){this._context=e}r7.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._point=0},lineEnd:function(){(this._line||this._line!==0&&this._point===1)&&this._context.closePath(),this._line=1-this._line},point:function(e,t){switch(e=+e,t=+t,this._point){case 0:this._point=1,this._line?this._context.lineTo(e,t):this._context.moveTo(e,t);break;case 1:this._point=2;default:this._context.lineTo(e,t);break}}};function CS(e){return new r7(e)}function i7(e){return e[0]}function s7(e){return e[1]}function o7(e,t){var n=Jt(!0),r=null,i=CS,s=null,o=Xy(a);e=typeof e=="function"?e:e===void 0?i7:Jt(e),t=typeof t=="function"?t:t===void 0?s7:Jt(t);function a(l){var u,c=(l=n7(l)).length,f,d=!1,h;for(r==null&&(s=i(h=o())),u=0;u<=c;++u)!(u=h;--p)a.point(x[p],_[p]);a.lineEnd(),a.areaEnd()}v&&(x[d]=+e(m,d,f),_[d]=+t(m,d,f),a.point(r?+r(m,d,f):x[d],n?+n(m,d,f):_[d]))}if(b)return a=null,b+""||null}function c(){return o7().defined(i).curve(o).context(s)}return u.x=function(f){return arguments.length?(e=typeof f=="function"?f:Jt(+f),r=null,u):e},u.x0=function(f){return arguments.length?(e=typeof f=="function"?f:Jt(+f),u):e},u.x1=function(f){return arguments.length?(r=f==null?null:typeof f=="function"?f:Jt(+f),u):r},u.y=function(f){return arguments.length?(t=typeof f=="function"?f:Jt(+f),n=null,u):t},u.y0=function(f){return arguments.length?(t=typeof f=="function"?f:Jt(+f),u):t},u.y1=function(f){return arguments.length?(n=f==null?null:typeof f=="function"?f:Jt(+f),u):n},u.lineX0=u.lineY0=function(){return c().x(e).y(t)},u.lineY1=function(){return c().x(e).y(n)},u.lineX1=function(){return c().x(r).y(t)},u.defined=function(f){return arguments.length?(i=typeof f=="function"?f:Jt(!!f),u):i},u.curve=function(f){return arguments.length?(o=f,s!=null&&(a=o(s)),u):o},u.context=function(f){return arguments.length?(f==null?s=a=null:a=o(s=f),u):s},u}const YZ={draw(e,t){const n=hc(t/Ld);e.moveTo(n,0),e.arc(0,0,n,0,e7)}};function VZ(e,t){let n=null,r=Xy(i);e=typeof e=="function"?e:Jt(e||YZ),t=typeof t=="function"?t:Jt(t===void 0?64:+t);function i(){let s;if(n||(n=s=r()),e.apply(this,arguments).draw(n,+t.apply(this,arguments)),s)return n=null,s+""||null}return i.type=function(s){return arguments.length?(e=typeof s=="function"?s:Jt(s),i):e},i.size=function(s){return arguments.length?(t=typeof s=="function"?s:Jt(+s),i):t},i.context=function(s){return arguments.length?(n=s??null,i):n},i}function au(){}function K1(e,t,n){e._context.bezierCurveTo((2*e._x0+e._x1)/3,(2*e._y0+e._y1)/3,(e._x0+2*e._x1)/3,(e._y0+2*e._y1)/3,(e._x0+4*e._x1+t)/6,(e._y0+4*e._y1+n)/6)}function Ky(e){this._context=e}Ky.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._y0=this._y1=NaN,this._point=0},lineEnd:function(){switch(this._point){case 3:K1(this,this._x1,this._y1);case 2:this._context.lineTo(this._x1,this._y1);break}(this._line||this._line!==0&&this._point===1)&&this._context.closePath(),this._line=1-this._line},point:function(e,t){switch(e=+e,t=+t,this._point){case 0:this._point=1,this._line?this._context.lineTo(e,t):this._context.moveTo(e,t);break;case 1:this._point=2;break;case 2:this._point=3,this._context.lineTo((5*this._x0+this._x1)/6,(5*this._y0+this._y1)/6);default:K1(this,e,t);break}this._x0=this._x1,this._x1=e,this._y0=this._y1,this._y1=t}};function XZ(e){return new Ky(e)}function l7(e){this._context=e}l7.prototype={areaStart:au,areaEnd:au,lineStart:function(){this._x0=this._x1=this._x2=this._x3=this._x4=this._y0=this._y1=this._y2=this._y3=this._y4=NaN,this._point=0},lineEnd:function(){switch(this._point){case 1:{this._context.moveTo(this._x2,this._y2),this._context.closePath();break}case 2:{this._context.moveTo((this._x2+2*this._x3)/3,(this._y2+2*this._y3)/3),this._context.lineTo((this._x3+2*this._x2)/3,(this._y3+2*this._y2)/3),this._context.closePath();break}case 3:{this.point(this._x2,this._y2),this.point(this._x3,this._y3),this.point(this._x4,this._y4);break}}},point:function(e,t){switch(e=+e,t=+t,this._point){case 0:this._point=1,this._x2=e,this._y2=t;break;case 1:this._point=2,this._x3=e,this._y3=t;break;case 2:this._point=3,this._x4=e,this._y4=t,this._context.moveTo((this._x0+4*this._x1+e)/6,(this._y0+4*this._y1+t)/6);break;default:K1(this,e,t);break}this._x0=this._x1,this._x1=e,this._y0=this._y1,this._y1=t}};function KZ(e){return new l7(e)}function u7(e){this._context=e}u7.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._y0=this._y1=NaN,this._point=0},lineEnd:function(){(this._line||this._line!==0&&this._point===3)&&this._context.closePath(),this._line=1-this._line},point:function(e,t){switch(e=+e,t=+t,this._point){case 0:this._point=1;break;case 1:this._point=2;break;case 2:this._point=3;var n=(this._x0+4*this._x1+e)/6,r=(this._y0+4*this._y1+t)/6;this._line?this._context.lineTo(n,r):this._context.moveTo(n,r);break;case 3:this._point=4;default:K1(this,e,t);break}this._x0=this._x1,this._x1=e,this._y0=this._y1,this._y1=t}};function ZZ(e){return new u7(e)}function c7(e,t){this._basis=new Ky(e),this._beta=t}c7.prototype={lineStart:function(){this._x=[],this._y=[],this._basis.lineStart()},lineEnd:function(){var e=this._x,t=this._y,n=e.length-1;if(n>0)for(var r=e[0],i=t[0],s=e[n]-r,o=t[n]-i,a=-1,l;++a<=n;)l=a/n,this._basis.point(this._beta*e[a]+(1-this._beta)*(r+l*s),this._beta*t[a]+(1-this._beta)*(i+l*o));this._x=this._y=null,this._basis.lineEnd()},point:function(e,t){this._x.push(+e),this._y.push(+t)}};const JZ=(function e(t){function n(r){return t===1?new Ky(r):new c7(r,t)}return n.beta=function(r){return e(+r)},n})(.85);function Z1(e,t,n){e._context.bezierCurveTo(e._x1+e._k*(e._x2-e._x0),e._y1+e._k*(e._y2-e._y0),e._x2+e._k*(e._x1-t),e._y2+e._k*(e._y1-n),e._x2,e._y2)}function $S(e,t){this._context=e,this._k=(1-t)/6}$S.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._x2=this._y0=this._y1=this._y2=NaN,this._point=0},lineEnd:function(){switch(this._point){case 2:this._context.lineTo(this._x2,this._y2);break;case 3:Z1(this,this._x1,this._y1);break}(this._line||this._line!==0&&this._point===1)&&this._context.closePath(),this._line=1-this._line},point:function(e,t){switch(e=+e,t=+t,this._point){case 0:this._point=1,this._line?this._context.lineTo(e,t):this._context.moveTo(e,t);break;case 1:this._point=2,this._x1=e,this._y1=t;break;case 2:this._point=3;default:Z1(this,e,t);break}this._x0=this._x1,this._x1=this._x2,this._x2=e,this._y0=this._y1,this._y1=this._y2,this._y2=t}};const QZ=(function e(t){function n(r){return new $S(r,t)}return n.tension=function(r){return e(+r)},n})(0);function FS(e,t){this._context=e,this._k=(1-t)/6}FS.prototype={areaStart:au,areaEnd:au,lineStart:function(){this._x0=this._x1=this._x2=this._x3=this._x4=this._x5=this._y0=this._y1=this._y2=this._y3=this._y4=this._y5=NaN,this._point=0},lineEnd:function(){switch(this._point){case 1:{this._context.moveTo(this._x3,this._y3),this._context.closePath();break}case 2:{this._context.lineTo(this._x3,this._y3),this._context.closePath();break}case 3:{this.point(this._x3,this._y3),this.point(this._x4,this._y4),this.point(this._x5,this._y5);break}}},point:function(e,t){switch(e=+e,t=+t,this._point){case 0:this._point=1,this._x3=e,this._y3=t;break;case 1:this._point=2,this._context.moveTo(this._x4=e,this._y4=t);break;case 2:this._point=3,this._x5=e,this._y5=t;break;default:Z1(this,e,t);break}this._x0=this._x1,this._x1=this._x2,this._x2=e,this._y0=this._y1,this._y1=this._y2,this._y2=t}};const eJ=(function e(t){function n(r){return new FS(r,t)}return n.tension=function(r){return e(+r)},n})(0);function DS(e,t){this._context=e,this._k=(1-t)/6}DS.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._x2=this._y0=this._y1=this._y2=NaN,this._point=0},lineEnd:function(){(this._line||this._line!==0&&this._point===3)&&this._context.closePath(),this._line=1-this._line},point:function(e,t){switch(e=+e,t=+t,this._point){case 0:this._point=1;break;case 1:this._point=2;break;case 2:this._point=3,this._line?this._context.lineTo(this._x2,this._y2):this._context.moveTo(this._x2,this._y2);break;case 3:this._point=4;default:Z1(this,e,t);break}this._x0=this._x1,this._x1=this._x2,this._x2=e,this._y0=this._y1,this._y1=this._y2,this._y2=t}};const tJ=(function e(t){function n(r){return new DS(r,t)}return n.tension=function(r){return e(+r)},n})(0);function MS(e,t,n){var r=e._x1,i=e._y1,s=e._x2,o=e._y2;if(e._l01_a>jr){var a=2*e._l01_2a+3*e._l01_a*e._l12_a+e._l12_2a,l=3*e._l01_a*(e._l01_a+e._l12_a);r=(r*a-e._x0*e._l12_2a+e._x2*e._l01_2a)/l,i=(i*a-e._y0*e._l12_2a+e._y2*e._l01_2a)/l}if(e._l23_a>jr){var u=2*e._l23_2a+3*e._l23_a*e._l12_a+e._l12_2a,c=3*e._l23_a*(e._l23_a+e._l12_a);s=(s*u+e._x1*e._l23_2a-t*e._l12_2a)/c,o=(o*u+e._y1*e._l23_2a-n*e._l12_2a)/c}e._context.bezierCurveTo(r,i,s,o,e._x2,e._y2)}function f7(e,t){this._context=e,this._alpha=t}f7.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._x2=this._y0=this._y1=this._y2=NaN,this._l01_a=this._l12_a=this._l23_a=this._l01_2a=this._l12_2a=this._l23_2a=this._point=0},lineEnd:function(){switch(this._point){case 2:this._context.lineTo(this._x2,this._y2);break;case 3:this.point(this._x2,this._y2);break}(this._line||this._line!==0&&this._point===1)&&this._context.closePath(),this._line=1-this._line},point:function(e,t){if(e=+e,t=+t,this._point){var n=this._x2-e,r=this._y2-t;this._l23_a=Math.sqrt(this._l23_2a=Math.pow(n*n+r*r,this._alpha))}switch(this._point){case 0:this._point=1,this._line?this._context.lineTo(e,t):this._context.moveTo(e,t);break;case 1:this._point=2;break;case 2:this._point=3;default:MS(this,e,t);break}this._l01_a=this._l12_a,this._l12_a=this._l23_a,this._l01_2a=this._l12_2a,this._l12_2a=this._l23_2a,this._x0=this._x1,this._x1=this._x2,this._x2=e,this._y0=this._y1,this._y1=this._y2,this._y2=t}};const nJ=(function e(t){function n(r){return t?new f7(r,t):new $S(r,0)}return n.alpha=function(r){return e(+r)},n})(.5);function d7(e,t){this._context=e,this._alpha=t}d7.prototype={areaStart:au,areaEnd:au,lineStart:function(){this._x0=this._x1=this._x2=this._x3=this._x4=this._x5=this._y0=this._y1=this._y2=this._y3=this._y4=this._y5=NaN,this._l01_a=this._l12_a=this._l23_a=this._l01_2a=this._l12_2a=this._l23_2a=this._point=0},lineEnd:function(){switch(this._point){case 1:{this._context.moveTo(this._x3,this._y3),this._context.closePath();break}case 2:{this._context.lineTo(this._x3,this._y3),this._context.closePath();break}case 3:{this.point(this._x3,this._y3),this.point(this._x4,this._y4),this.point(this._x5,this._y5);break}}},point:function(e,t){if(e=+e,t=+t,this._point){var n=this._x2-e,r=this._y2-t;this._l23_a=Math.sqrt(this._l23_2a=Math.pow(n*n+r*r,this._alpha))}switch(this._point){case 0:this._point=1,this._x3=e,this._y3=t;break;case 1:this._point=2,this._context.moveTo(this._x4=e,this._y4=t);break;case 2:this._point=3,this._x5=e,this._y5=t;break;default:MS(this,e,t);break}this._l01_a=this._l12_a,this._l12_a=this._l23_a,this._l01_2a=this._l12_2a,this._l12_2a=this._l23_2a,this._x0=this._x1,this._x1=this._x2,this._x2=e,this._y0=this._y1,this._y1=this._y2,this._y2=t}};const rJ=(function e(t){function n(r){return t?new d7(r,t):new FS(r,0)}return n.alpha=function(r){return e(+r)},n})(.5);function h7(e,t){this._context=e,this._alpha=t}h7.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._x2=this._y0=this._y1=this._y2=NaN,this._l01_a=this._l12_a=this._l23_a=this._l01_2a=this._l12_2a=this._l23_2a=this._point=0},lineEnd:function(){(this._line||this._line!==0&&this._point===3)&&this._context.closePath(),this._line=1-this._line},point:function(e,t){if(e=+e,t=+t,this._point){var n=this._x2-e,r=this._y2-t;this._l23_a=Math.sqrt(this._l23_2a=Math.pow(n*n+r*r,this._alpha))}switch(this._point){case 0:this._point=1;break;case 1:this._point=2;break;case 2:this._point=3,this._line?this._context.lineTo(this._x2,this._y2):this._context.moveTo(this._x2,this._y2);break;case 3:this._point=4;default:MS(this,e,t);break}this._l01_a=this._l12_a,this._l12_a=this._l23_a,this._l01_2a=this._l12_2a,this._l12_2a=this._l23_2a,this._x0=this._x1,this._x1=this._x2,this._x2=e,this._y0=this._y1,this._y1=this._y2,this._y2=t}};const iJ=(function e(t){function n(r){return t?new h7(r,t):new DS(r,0)}return n.alpha=function(r){return e(+r)},n})(.5);function p7(e){this._context=e}p7.prototype={areaStart:au,areaEnd:au,lineStart:function(){this._point=0},lineEnd:function(){this._point&&this._context.closePath()},point:function(e,t){e=+e,t=+t,this._point?this._context.lineTo(e,t):(this._point=1,this._context.moveTo(e,t))}};function sJ(e){return new p7(e)}function rD(e){return e<0?-1:1}function iD(e,t,n){var r=e._x1-e._x0,i=t-e._x1,s=(e._y1-e._y0)/(r||i<0&&-0),o=(n-e._y1)/(i||r<0&&-0),a=(s*i+o*r)/(r+i);return(rD(s)+rD(o))*Math.min(Math.abs(s),Math.abs(o),.5*Math.abs(a))||0}function sD(e,t){var n=e._x1-e._x0;return n?(3*(e._y1-e._y0)/n-t)/2:t}function mx(e,t,n){var r=e._x0,i=e._y0,s=e._x1,o=e._y1,a=(s-r)/3;e._context.bezierCurveTo(r+a,i+a*t,s-a,o-a*n,s,o)}function J1(e){this._context=e}J1.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._y0=this._y1=this._t0=NaN,this._point=0},lineEnd:function(){switch(this._point){case 2:this._context.lineTo(this._x1,this._y1);break;case 3:mx(this,this._t0,sD(this,this._t0));break}(this._line||this._line!==0&&this._point===1)&&this._context.closePath(),this._line=1-this._line},point:function(e,t){var n=NaN;if(e=+e,t=+t,!(e===this._x1&&t===this._y1)){switch(this._point){case 0:this._point=1,this._line?this._context.lineTo(e,t):this._context.moveTo(e,t);break;case 1:this._point=2;break;case 2:this._point=3,mx(this,sD(this,n=iD(this,e,t)),n);break;default:mx(this,this._t0,n=iD(this,e,t));break}this._x0=this._x1,this._x1=e,this._y0=this._y1,this._y1=t,this._t0=n}}};function g7(e){this._context=new m7(e)}(g7.prototype=Object.create(J1.prototype)).point=function(e,t){J1.prototype.point.call(this,t,e)};function m7(e){this._context=e}m7.prototype={moveTo:function(e,t){this._context.moveTo(t,e)},closePath:function(){this._context.closePath()},lineTo:function(e,t){this._context.lineTo(t,e)},bezierCurveTo:function(e,t,n,r,i,s){this._context.bezierCurveTo(t,e,r,n,s,i)}};function oJ(e){return new J1(e)}function aJ(e){return new g7(e)}function v7(e){this._context=e}v7.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x=[],this._y=[]},lineEnd:function(){var e=this._x,t=this._y,n=e.length;if(n)if(this._line?this._context.lineTo(e[0],t[0]):this._context.moveTo(e[0],t[0]),n===2)this._context.lineTo(e[1],t[1]);else for(var r=oD(e),i=oD(t),s=0,o=1;o=0;--t)i[t]=(o[t]-i[t+1])/s[t];for(s[n-1]=(e[n]+i[n-1])/2,t=0;t=0&&(this._t=1-this._t,this._line=1-this._line)},point:function(e,t){switch(e=+e,t=+t,this._point){case 0:this._point=1,this._line?this._context.lineTo(e,t):this._context.moveTo(e,t);break;case 1:this._point=2;default:{if(this._t<=0)this._context.lineTo(this._x,t),this._context.lineTo(e,t);else{var n=this._x*(1-this._t)+e*this._t;this._context.lineTo(n,this._y),this._context.lineTo(n,t)}break}}this._x=e,this._y=t}};function uJ(e){return new Zy(e,.5)}function cJ(e){return new Zy(e,0)}function fJ(e){return new Zy(e,1)}function eu(e,t){if(typeof document<"u"&&document.createElement){const n=document.createElement("canvas");if(n&&n.getContext)return n.width=e,n.height=t,n}return null}const dJ=()=>typeof Image<"u"?Image:null;function ya(e,t){switch(arguments.length){case 0:break;case 1:this.range(e);break;default:this.range(t).domain(e);break}return this}function Au(e,t){switch(arguments.length){case 0:break;case 1:{typeof e=="function"?this.interpolator(e):this.range(e);break}default:{this.domain(e),typeof t=="function"?this.interpolator(t):this.range(t);break}}return this}const Ow=Symbol("implicit");function TS(){var e=new E5,t=[],n=[],r=Ow;function i(s){let o=e.get(s);if(o===void 0){if(r!==Ow)return r;e.set(s,o=t.push(s)-1)}return n[o%n.length]}return i.domain=function(s){if(!arguments.length)return t.slice();t=[],e=new E5;for(const o of s)e.has(o)||e.set(o,t.push(o)-1);return i},i.range=function(s){return arguments.length?(n=Array.from(s),i):n.slice()},i.unknown=function(s){return arguments.length?(r=s,i):r},i.copy=function(){return TS(t,n).unknown(r)},ya.apply(i,arguments),i}function kh(e,t,n){e.prototype=t.prototype=n,n.constructor=e}function l0(e,t){var n=Object.create(e.prototype);for(var r in t)n[r]=t[r];return n}function ku(){}var jc=.7,Id=1/jc,od="\\s*([+-]?\\d+)\\s*",mg="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",ea="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",hJ=/^#([0-9a-f]{3,8})$/,pJ=new RegExp(`^rgb\\(${od},${od},${od}\\)$`),gJ=new RegExp(`^rgb\\(${ea},${ea},${ea}\\)$`),mJ=new RegExp(`^rgba\\(${od},${od},${od},${mg}\\)$`),vJ=new RegExp(`^rgba\\(${ea},${ea},${ea},${mg}\\)$`),yJ=new RegExp(`^hsl\\(${mg},${ea},${ea}\\)$`),bJ=new RegExp(`^hsla\\(${mg},${ea},${ea},${mg}\\)$`),aD={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074};kh(ku,vg,{copy(e){return Object.assign(new this.constructor,this,e)},displayable(){return this.rgb().displayable()},hex:lD,formatHex:lD,formatHex8:xJ,formatHsl:_J,formatRgb:uD,toString:uD});function lD(){return this.rgb().formatHex()}function xJ(){return this.rgb().formatHex8()}function _J(){return y7(this).formatHsl()}function uD(){return this.rgb().formatRgb()}function vg(e){var t,n;return e=(e+"").trim().toLowerCase(),(t=hJ.exec(e))?(n=t[1].length,t=parseInt(t[1],16),n===6?cD(t):n===3?new or(t>>8&15|t>>4&240,t>>4&15|t&240,(t&15)<<4|t&15,1):n===8?cm(t>>24&255,t>>16&255,t>>8&255,(t&255)/255):n===4?cm(t>>12&15|t>>8&240,t>>8&15|t>>4&240,t>>4&15|t&240,((t&15)<<4|t&15)/255):null):(t=pJ.exec(e))?new or(t[1],t[2],t[3],1):(t=gJ.exec(e))?new or(t[1]*255/100,t[2]*255/100,t[3]*255/100,1):(t=mJ.exec(e))?cm(t[1],t[2],t[3],t[4]):(t=vJ.exec(e))?cm(t[1]*255/100,t[2]*255/100,t[3]*255/100,t[4]):(t=yJ.exec(e))?hD(t[1],t[2]/100,t[3]/100,1):(t=bJ.exec(e))?hD(t[1],t[2]/100,t[3]/100,t[4]):aD.hasOwnProperty(e)?cD(aD[e]):e==="transparent"?new or(NaN,NaN,NaN,0):null}function cD(e){return new or(e>>16&255,e>>8&255,e&255,1)}function cm(e,t,n,r){return r<=0&&(e=t=n=NaN),new or(e,t,n,r)}function RS(e){return e instanceof ku||(e=vg(e)),e?(e=e.rgb(),new or(e.r,e.g,e.b,e.opacity)):new or}function lu(e,t,n,r){return arguments.length===1?RS(e):new or(e,t,n,r??1)}function or(e,t,n,r){this.r=+e,this.g=+t,this.b=+n,this.opacity=+r}kh(or,lu,l0(ku,{brighter(e){return e=e==null?Id:Math.pow(Id,e),new or(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=e==null?jc:Math.pow(jc,e),new or(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new or(Ec(this.r),Ec(this.g),Ec(this.b),Q1(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:fD,formatHex:fD,formatHex8:wJ,formatRgb:dD,toString:dD}));function fD(){return`#${pc(this.r)}${pc(this.g)}${pc(this.b)}`}function wJ(){return`#${pc(this.r)}${pc(this.g)}${pc(this.b)}${pc((isNaN(this.opacity)?1:this.opacity)*255)}`}function dD(){const e=Q1(this.opacity);return`${e===1?"rgb(":"rgba("}${Ec(this.r)}, ${Ec(this.g)}, ${Ec(this.b)}${e===1?")":`, ${e})`}`}function Q1(e){return isNaN(e)?1:Math.max(0,Math.min(1,e))}function Ec(e){return Math.max(0,Math.min(255,Math.round(e)||0))}function pc(e){return e=Ec(e),(e<16?"0":"")+e.toString(16)}function hD(e,t,n,r){return r<=0?e=t=n=NaN:n<=0||n>=1?e=t=NaN:t<=0&&(e=NaN),new io(e,t,n,r)}function y7(e){if(e instanceof io)return new io(e.h,e.s,e.l,e.opacity);if(e instanceof ku||(e=vg(e)),!e)return new io;if(e instanceof io)return e;e=e.rgb();var t=e.r/255,n=e.g/255,r=e.b/255,i=Math.min(t,n,r),s=Math.max(t,n,r),o=NaN,a=s-i,l=(s+i)/2;return a?(t===s?o=(n-r)/a+(n0&&l<1?0:o,new io(o,a,l,e.opacity)}function ev(e,t,n,r){return arguments.length===1?y7(e):new io(e,t,n,r??1)}function io(e,t,n,r){this.h=+e,this.s=+t,this.l=+n,this.opacity=+r}kh(io,ev,l0(ku,{brighter(e){return e=e==null?Id:Math.pow(Id,e),new io(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?jc:Math.pow(jc,e),new io(this.h,this.s,this.l*e,this.opacity)},rgb(){var e=this.h%360+(this.h<0)*360,t=isNaN(e)||isNaN(this.s)?0:this.s,n=this.l,r=n+(n<.5?n:1-n)*t,i=2*n-r;return new or(vx(e>=240?e-240:e+120,i,r),vx(e,i,r),vx(e<120?e+240:e-120,i,r),this.opacity)},clamp(){return new io(pD(this.h),fm(this.s),fm(this.l),Q1(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){const e=Q1(this.opacity);return`${e===1?"hsl(":"hsla("}${pD(this.h)}, ${fm(this.s)*100}%, ${fm(this.l)*100}%${e===1?")":`, ${e})`}`}}));function pD(e){return e=(e||0)%360,e<0?e+360:e}function fm(e){return Math.max(0,Math.min(1,e||0))}function vx(e,t,n){return(e<60?t+(n-t)*e/60:e<180?n:e<240?t+(n-t)*(240-e)/60:t)*255}const b7=Math.PI/180,x7=180/Math.PI,tv=18,_7=.96422,w7=1,E7=.82521,A7=4/29,ad=6/29,k7=3*ad*ad,EJ=ad*ad*ad;function S7(e){if(e instanceof ta)return new ta(e.l,e.a,e.b,e.opacity);if(e instanceof Va)return C7(e);e instanceof or||(e=RS(e));var t=_x(e.r),n=_x(e.g),r=_x(e.b),i=yx((.2225045*t+.7168786*n+.0606169*r)/w7),s,o;return t===n&&n===r?s=o=i:(s=yx((.4360747*t+.3850649*n+.1430804*r)/_7),o=yx((.0139322*t+.0971045*n+.7141733*r)/E7)),new ta(116*i-16,500*(s-i),200*(i-o),e.opacity)}function nv(e,t,n,r){return arguments.length===1?S7(e):new ta(e,t,n,r??1)}function ta(e,t,n,r){this.l=+e,this.a=+t,this.b=+n,this.opacity=+r}kh(ta,nv,l0(ku,{brighter(e){return new ta(this.l+tv*(e??1),this.a,this.b,this.opacity)},darker(e){return new ta(this.l-tv*(e??1),this.a,this.b,this.opacity)},rgb(){var e=(this.l+16)/116,t=isNaN(this.a)?e:e+this.a/500,n=isNaN(this.b)?e:e-this.b/200;return t=_7*bx(t),e=w7*bx(e),n=E7*bx(n),new or(xx(3.1338561*t-1.6168667*e-.4906146*n),xx(-.9787684*t+1.9161415*e+.033454*n),xx(.0719453*t-.2289914*e+1.4052427*n),this.opacity)}}));function yx(e){return e>EJ?Math.pow(e,1/3):e/k7+A7}function bx(e){return e>ad?e*e*e:k7*(e-A7)}function xx(e){return 255*(e<=.0031308?12.92*e:1.055*Math.pow(e,1/2.4)-.055)}function _x(e){return(e/=255)<=.04045?e/12.92:Math.pow((e+.055)/1.055,2.4)}function AJ(e){if(e instanceof Va)return new Va(e.h,e.c,e.l,e.opacity);if(e instanceof ta||(e=S7(e)),e.a===0&&e.b===0)return new Va(NaN,0=1?(n=1,t-1):Math.floor(n*t),i=e[r],s=e[r+1],o=r>0?e[r-1]:2*i-s,a=r()=>e;function T7(e,t){return function(n){return e+n*t}}function SJ(e,t,n){return e=Math.pow(e,n),t=Math.pow(t,n)-e,n=1/n,function(r){return Math.pow(e+r*t,n)}}function eb(e,t){var n=t-e;return n?T7(e,n>180||n<-180?n-360*Math.round(n/360):n):Qy(isNaN(e)?t:e)}function CJ(e){return(e=+e)==1?ar:function(t,n){return n-t?SJ(t,n,e):Qy(isNaN(t)?n:t)}}function ar(e,t){var n=t-e;return n?T7(e,n):Qy(isNaN(e)?t:e)}const Iw=(function e(t){var n=CJ(t);function r(i,s){var o=n((i=lu(i)).r,(s=lu(s)).r),a=n(i.g,s.g),l=n(i.b,s.b),u=ar(i.opacity,s.opacity);return function(c){return i.r=o(c),i.g=a(c),i.b=l(c),i.opacity=u(c),i+""}}return r.gamma=e,r})(1);function R7(e){return function(t){var n=t.length,r=new Array(n),i=new Array(n),s=new Array(n),o,a;for(o=0;on&&(s=t.slice(n,s),a[o]?a[o]+=s:a[++o]=s),(r=r[0])===(i=i[0])?a[o]?a[o]+=i:a[++o]=i:(a[++o]=null,l.push({i:o,x:no(r,i)})),n=wx.lastIndex;return n180?c+=360:c-u>180&&(u+=360),d.push({i:f.push(i(f)+"rotate(",null,r)-2,x:no(u,c)})):c&&f.push(i(f)+"rotate("+c+r)}function a(u,c,f,d){u!==c?d.push({i:f.push(i(f)+"skewX(",null,r)-2,x:no(u,c)}):c&&f.push(i(f)+"skewX("+c+r)}function l(u,c,f,d,h,p){if(u!==f||c!==d){var g=h.push(i(h)+"scale(",null,",",null,")");p.push({i:g-4,x:no(u,f)},{i:g-2,x:no(c,d)})}else(f!==1||d!==1)&&h.push(i(h)+"scale("+f+","+d+")")}return function(u,c){var f=[],d=[];return u=e(u),c=e(c),s(u.translateX,u.translateY,c.translateX,c.translateY,f,d),o(u.rotate,c.rotate,f,d),a(u.skewX,c.skewX,f,d),l(u.scaleX,u.scaleY,c.scaleX,c.scaleY,f,d),u=c=null,function(h){for(var p=-1,g=d.length,m;++pt&&(n=e,e=t,t=n),function(r){return Math.max(e,Math.min(t,r))}}function eQ(e,t,n){var r=e[0],i=e[1],s=t[0],o=t[1];return i2?tQ:eQ,l=u=null,f}function f(d){return d==null||isNaN(d=+d)?s:(l||(l=a(e.map(r),t,n)))(r(o(d)))}return f.invert=function(d){return o(i((u||(u=a(t,e.map(r),no)))(d)))},f.domain=function(d){return arguments.length?(e=Array.from(d,zw),c()):e.slice()},f.range=function(d){return arguments.length?(t=Array.from(d),c()):t.slice()},f.rangeRound=function(d){return t=Array.from(d),n=u0,c()},f.clamp=function(d){return arguments.length?(o=d?!0:Li,c()):o!==Li},f.interpolate=function(d){return arguments.length?(n=d,c()):n},f.unknown=function(d){return arguments.length?(s=d,f):s},function(d,h){return r=d,i=h,c()}}function W7(){return tb()(Li,Li)}function H7(e,t,n,r){var i=su(e,t,n),s;switch(r=zc(r??",f"),r.type){case"s":{var o=Math.max(Math.abs(e),Math.abs(t));return r.precision==null&&!isNaN(s=vN(i,o))&&(r.precision=s),Ak(r,o)}case"":case"e":case"g":case"p":case"r":{r.precision==null&&!isNaN(s=yN(i,Math.max(Math.abs(e),Math.abs(t))))&&(r.precision=s-(r.type==="e"));break}case"f":case"%":{r.precision==null&&!isNaN(s=mN(i))&&(r.precision=s-(r.type==="%")*2);break}}return Dy(r)}function gf(e){var t=e.domain;return e.ticks=function(n){var r=t();return bw(r[0],r[r.length-1],n??10)},e.tickFormat=function(n,r){var i=t();return H7(i[0],i[i.length-1],n??10,r)},e.nice=function(n){n==null&&(n=10);var r=t(),i=0,s=r.length-1,o=r[i],a=r[s],l,u,c=10;for(a0;){if(u=xw(o,a,n),u===l)return r[i]=o,r[s]=a,t(r);if(u>0)o=Math.floor(o/u)*u,a=Math.ceil(a/u)*u;else if(u<0)o=Math.ceil(o*u)/u,a=Math.floor(a*u)/u;else break;l=u}return e},e}function G7(){var e=W7();return e.copy=function(){return c0(e,G7())},ya.apply(e,arguments),gf(e)}function Y7(e){var t;function n(r){return r==null||isNaN(r=+r)?t:r}return n.invert=n,n.domain=n.range=function(r){return arguments.length?(e=Array.from(r,zw),n):e.slice()},n.unknown=function(r){return arguments.length?(t=r,n):t},n.copy=function(){return Y7(e).unknown(t)},e=arguments.length?Array.from(e,zw):[0,1],gf(n)}function V7(e,t){e=e.slice();var n=0,r=e.length-1,i=e[n],s=e[r],o;return sMath.pow(e,t)}function oQ(e){return e===Math.E?Math.log:e===10&&Math.log10||e===2&&Math.log2||(e=Math.log(e),t=>Math.log(t)/e)}function ED(e){return(t,n)=>-e(-t,n)}function PS(e){const t=e(_D,wD),n=t.domain;let r=10,i,s;function o(){return i=oQ(r),s=sQ(r),n()[0]<0?(i=ED(i),s=ED(s),e(nQ,rQ)):e(_D,wD),t}return t.base=function(a){return arguments.length?(r=+a,o()):r},t.domain=function(a){return arguments.length?(n(a),o()):n()},t.ticks=a=>{const l=n();let u=l[0],c=l[l.length-1];const f=c0){for(;d<=h;++d)for(p=1;pc)break;v.push(g)}}else for(;d<=h;++d)for(p=r-1;p>=1;--p)if(g=d>0?p/s(-d):p*s(d),!(gc)break;v.push(g)}v.length*2{if(a==null&&(a=10),l==null&&(l=r===10?"s":","),typeof l!="function"&&(!(r%1)&&(l=zc(l)).precision==null&&(l.trim=!0),l=Dy(l)),a===1/0)return l;const u=Math.max(1,r*a/t.ticks().length);return c=>{let f=c/s(Math.round(i(c)));return f*rn(V7(n(),{floor:a=>s(Math.floor(i(a))),ceil:a=>s(Math.ceil(i(a)))})),t}function X7(){const e=PS(tb()).domain([1,10]);return e.copy=()=>c0(e,X7()).base(e.base()),ya.apply(e,arguments),e}function AD(e){return function(t){return Math.sign(t)*Math.log1p(Math.abs(t/e))}}function kD(e){return function(t){return Math.sign(t)*Math.expm1(Math.abs(t))*e}}function BS(e){var t=1,n=e(AD(t),kD(t));return n.constant=function(r){return arguments.length?e(AD(t=+r),kD(t)):t},gf(n)}function K7(){var e=BS(tb());return e.copy=function(){return c0(e,K7()).constant(e.constant())},ya.apply(e,arguments)}function SD(e){return function(t){return t<0?-Math.pow(-t,e):Math.pow(t,e)}}function aQ(e){return e<0?-Math.sqrt(-e):Math.sqrt(e)}function lQ(e){return e<0?-e*e:e*e}function zS(e){var t=e(Li,Li),n=1;function r(){return n===1?e(Li,Li):n===.5?e(aQ,lQ):e(SD(n),SD(1/n))}return t.exponent=function(i){return arguments.length?(n=+i,r()):n},gf(t)}function jS(){var e=zS(tb());return e.copy=function(){return c0(e,jS()).exponent(e.exponent())},ya.apply(e,arguments),e}function uQ(){return jS.apply(null,arguments).exponent(.5)}function Z7(){var e=[],t=[],n=[],r;function i(){var o=0,a=Math.max(1,t.length);for(n=new Array(a-1);++o0?n[a-1]:e[0],a=n?[r[n-1],t]:[r[u-1],r[u]]},o.unknown=function(l){return arguments.length&&(s=l),o},o.thresholds=function(){return r.slice()},o.copy=function(){return J7().domain([e,t]).range(i).unknown(s)},ya.apply(gf(o),arguments)}function Q7(){var e=[.5],t=[0,1],n,r=1;function i(s){return s!=null&&s<=s?t[iu(e,s,0,r)]:n}return i.domain=function(s){return arguments.length?(e=Array.from(s),r=Math.min(e.length,t.length-1),i):e.slice()},i.range=function(s){return arguments.length?(t=Array.from(s),r=Math.min(e.length,t.length-1),i):t.slice()},i.invertExtent=function(s){var o=t.indexOf(s);return[e[o-1],e[o]]},i.unknown=function(s){return arguments.length?(n=s,i):n},i.copy=function(){return Q7().domain(e).range(t).unknown(n)},ya.apply(i,arguments)}function cQ(e){return new Date(e)}function fQ(e){return e instanceof Date?+e:+new Date(+e)}function US(e,t,n,r,i,s,o,a,l,u){var c=W7(),f=c.invert,d=c.domain,h=u(".%L"),p=u(":%S"),g=u("%I:%M"),m=u("%I %p"),v=u("%a %d"),b=u("%b %d"),x=u("%B"),_=u("%Y");function w(A){return(l(A)0?r:1:0}const SQ="identity",Pd="linear",cl="log",f0="pow",d0="sqrt",ib="symlog",Uc="time",qc="utc",na="sequential",Sh="diverging",Bd="quantile",sb="quantize",ob="threshold",YS="ordinal",Uw="point",s9="band",VS="bin-ordinal",nr="continuous",h0="discrete",p0="discretizing",Us="interpolating",XS="temporal";function CQ(e){return function(t){let n=t[0],r=t[1],i;return r=r&&n[l]<=i&&(s<0&&(s=l),o=l);if(!(s<0))return r=e.invertExtent(n[s]),i=e.invertExtent(n[o]),[r[0]===void 0?r[1]:r[0],i[1]===void 0?i[0]:i[1]]}}function KS(){const e=TS().unknown(void 0),t=e.domain,n=e.range;let r=[0,1],i,s,o=!1,a=0,l=0,u=.5;delete e.unknown;function c(){const f=t().length,d=r[1]g+i*v);return n(d?m.reverse():m)}return e.domain=function(f){return arguments.length?(t(f),c()):t()},e.range=function(f){return arguments.length?(r=[+f[0],+f[1]],c()):r.slice()},e.rangeRound=function(f){return r=[+f[0],+f[1]],o=!0,c()},e.bandwidth=function(){return s},e.step=function(){return i},e.round=function(f){return arguments.length?(o=!!f,c()):o},e.padding=function(f){return arguments.length?(l=Math.max(0,Math.min(1,f)),a=l,c()):a},e.paddingInner=function(f){return arguments.length?(a=Math.max(0,Math.min(1,f)),c()):a},e.paddingOuter=function(f){return arguments.length?(l=Math.max(0,Math.min(1,f)),c()):l},e.align=function(f){return arguments.length?(u=Math.max(0,Math.min(1,f)),c()):u},e.invertRange=function(f){if(f[0]==null||f[1]==null)return;const d=r[1]r[1-d])))return v=Math.max(0,iu(h,g)-1),b=g===m?v:iu(h,m)-1,g-h[v]>s+1e-10&&++v,d&&(x=v,v=p-b,b=p-x),v>b?void 0:t().slice(v,b+1)},e.invert=function(f){const d=e.invertRange([f,f]);return d&&d[0]},e.copy=function(){return KS().domain(t()).range(r).round(o).paddingInner(a).paddingOuter(l).align(u)},c()}function o9(e){const t=e.copy;return e.padding=e.paddingOuter,delete e.paddingInner,e.copy=function(){return o9(t())},e}function FQ(){return o9(KS().paddingInner(1))}var DQ=Array.prototype.map;function MQ(e){return DQ.call(e,Hr)}const TQ=Array.prototype.slice;function a9(){let e=[],t=[];function n(r){return r==null||r!==r?void 0:t[(iu(e,r)-1)%t.length]}return n.domain=function(r){return arguments.length?(e=MQ(r),n):e.slice()},n.range=function(r){return arguments.length?(t=TQ.call(r),n):t.slice()},n.tickFormat=function(r,i){return H7(e[0],jt(e),r??10,i)},n.copy=function(){return a9().domain(n.domain()).range(n.range())},n}const iv=new Map,l9=Symbol("vega_scale");function u9(e){return e[l9]=!0,e}function CD(e){return e&&e[l9]===!0}function RQ(e,t,n){const r=function(){const s=t();return s.invertRange||(s.invertRange=s.invert?CQ(s):s.invertExtent?$Q(s):void 0),s.type=e,u9(s)};return r.metadata=mo(je(n)),r}function Vt(e,t,n){return arguments.length>1?(iv.set(e,RQ(e,t,n)),this):c9(e)?iv.get(e):void 0}Vt(SQ,Y7);Vt(Pd,G7,nr);Vt(cl,X7,[nr,cl]);Vt(f0,jS,nr);Vt(d0,uQ,nr);Vt(ib,K7,nr);Vt(Uc,dQ,[nr,XS]);Vt(qc,hQ,[nr,XS]);Vt(na,qS,[nr,Us]);Vt(`${na}-${Pd}`,qS,[nr,Us]);Vt(`${na}-${cl}`,e9,[nr,Us,cl]);Vt(`${na}-${f0}`,WS,[nr,Us]);Vt(`${na}-${d0}`,pQ,[nr,Us]);Vt(`${na}-${ib}`,t9,[nr,Us]);Vt(`${Sh}-${Pd}`,n9,[nr,Us]);Vt(`${Sh}-${cl}`,r9,[nr,Us,cl]);Vt(`${Sh}-${f0}`,HS,[nr,Us]);Vt(`${Sh}-${d0}`,gQ,[nr,Us]);Vt(`${Sh}-${ib}`,i9,[nr,Us]);Vt(Bd,Z7,[p0,Bd]);Vt(sb,J7,p0);Vt(ob,Q7,p0);Vt(VS,a9,[h0,p0]);Vt(YS,TS,h0);Vt(s9,KS,h0);Vt(Uw,FQ,h0);function c9(e){return iv.has(e)}function mf(e,t){const n=iv.get(e);return n&&n.metadata[t]}function ZS(e){return mf(e,nr)}function zd(e){return mf(e,h0)}function qw(e){return mf(e,p0)}function f9(e){return mf(e,cl)}function NQ(e){return mf(e,XS)}function d9(e){return mf(e,Us)}function h9(e){return mf(e,Bd)}const OQ=["clamp","base","constant","exponent"];function p9(e,t){const n=t[0],r=jt(t)-n;return function(i){return e(n+i*r)}}function ab(e,t,n){return IS(JS(t||"rgb",n),e)}function g9(e,t){const n=new Array(t),r=t+1;for(let i=0;ie[a]?o[a](e[a]()):0),o)}function JS(e,t){const n=ZJ[LQ(e)];return t!=null&&n&&n.gamma?n.gamma(t):n}function LQ(e){return"interpolate"+e.toLowerCase().split("-").map(t=>t[0].toUpperCase()+t.slice(1)).join("")}const IQ={blues:"cfe1f2bed8eca8cee58fc1de74b2d75ba3cf4592c63181bd206fb2125ca40a4a90",greens:"d3eecdc0e6baabdda594d3917bc77d60ba6c46ab5e329a512089430e7735036429",greys:"e2e2e2d4d4d4c4c4c4b1b1b19d9d9d8888887575756262624d4d4d3535351e1e1e",oranges:"fdd8b3fdc998fdb87bfda55efc9244f87f2cf06b18e4580bd14904b93d029f3303",purples:"e2e1efd4d4e8c4c5e0b4b3d6a3a0cc928ec3827cb97566ae684ea25c3696501f8c",reds:"fdc9b4fcb49afc9e80fc8767fa7051f6573fec3f2fdc2a25c81b1db21218970b13",blueGreen:"d5efedc1e8e0a7ddd18bd2be70c6a958ba9144ad77319c5d2089460e7736036429",bluePurple:"ccddecbad0e4a8c2dd9ab0d4919cc98d85be8b6db28a55a6873c99822287730f71",greenBlue:"d3eecec5e8c3b1e1bb9bd8bb82cec269c2ca51b2cd3c9fc7288abd1675b10b60a1",orangeRed:"fddcaffdcf9bfdc18afdad77fb9562f67d53ee6545e24932d32d1ebf130da70403",purpleBlue:"dbdaebc8cee4b1c3de97b7d87bacd15b9fc93a90c01e7fb70b70ab056199045281",purpleBlueGreen:"dbd8eac8cee4b0c3de93b7d872acd1549fc83892bb1c88a3097f8702736b016353",purpleRed:"dcc9e2d3b3d7ce9eccd186c0da6bb2e14da0e23189d91e6fc61159ab07498f023a",redPurple:"fccfccfcbec0faa9b8f98faff571a5ec539ddb3695c41b8aa908808d0179700174",yellowGreen:"e4f4acd1eca0b9e2949ed68880c97c62bb6e47aa5e3297502083440e723b036034",yellowOrangeBrown:"feeaa1fedd84fecc63feb746fca031f68921eb7215db5e0bc54c05ab3d038f3204",yellowOrangeRed:"fee087fed16ffebd59fea849fd903efc7335f9522bee3423de1b20ca0b22af0225",blueOrange:"134b852f78b35da2cb9dcae1d2e5eff2f0ebfce0bafbbf74e8932fc5690d994a07",brownBlueGreen:"704108a0651ac79548e3c78af3e6c6eef1eac9e9e48ed1c74da79e187a72025147",purpleGreen:"5b1667834792a67fb6c9aed3e6d6e8eff0efd9efd5aedda971bb75368e490e5e29",purpleOrange:"4114696647968f83b7b9b4d6dadbebf3eeeafce0bafbbf74e8932fc5690d994a07",redBlue:"8c0d25bf363adf745ef4ae91fbdbc9f2efeed2e5ef9dcae15da2cb2f78b3134b85",redGrey:"8c0d25bf363adf745ef4ae91fcdccbfaf4f1e2e2e2c0c0c0969696646464343434",yellowGreenBlue:"eff9bddbf1b4bde5b594d5b969c5be45b4c22c9ec02182b82163aa23479c1c3185",redYellowBlue:"a50026d4322cf16e43fcac64fedd90faf8c1dcf1ecabd6e875abd04a74b4313695",redYellowGreen:"a50026d4322cf16e43fcac63fedd8df9f7aed7ee8ea4d86e64bc6122964f006837",pinkYellowGreen:"8e0152c0267edd72adf0b3d6faddedf5f3efe1f2cab6de8780bb474f9125276419",spectral:"9e0142d13c4bf0704afcac63fedd8dfbf8b0e0f3a1a9dda269bda94288b55e4fa2",viridis:"440154470e61481a6c482575472f7d443a834144873d4e8a39568c35608d31688e2d708e2a788e27818e23888e21918d1f988b1fa08822a8842ab07f35b77943bf7154c56866cc5d7ad1518fd744a5db36bcdf27d2e21be9e51afde725",magma:"0000040404130b0924150e3720114b2c11603b0f704a107957157e651a80721f817f24828c29819a2e80a8327db6377ac43c75d1426fde4968e95462f1605df76f5cfa7f5efc8f65fe9f6dfeaf78febf84fece91fddea0fcedaffcfdbf",inferno:"0000040403130c0826170c3b240c4f330a5f420a68500d6c5d126e6b176e781c6d86216b932667a12b62ae305cbb3755c73e4cd24644dd513ae65c30ed6925f3771af8850ffb9506fca50afcb519fac62df6d645f2e661f3f484fcffa4",plasma:"0d088723069033059742039d5002a25d01a66a00a87801a88405a7900da49c179ea72198b12a90ba3488c33d80cb4779d35171da5a69e16462e76e5bed7953f2834cf68f44fa9a3dfca636fdb32ffec029fcce25f9dc24f5ea27f0f921",cividis:"00205100235800265d002961012b65042e670831690d346b11366c16396d1c3c6e213f6e26426e2c456e31476e374a6e3c4d6e42506e47536d4c566d51586e555b6e5a5e6e5e616e62646f66676f6a6a706e6d717270717573727976737c79747f7c75827f758682768985778c8877908b78938e789691789a94789e9778a19b78a59e77a9a177aea575b2a874b6ab73bbaf71c0b26fc5b66dc9b96acebd68d3c065d8c462ddc85fe2cb5ce7cf58ebd355f0d652f3da4ff7de4cfae249fce647",rainbow:"6e40aa883eb1a43db3bf3cafd83fa4ee4395fe4b83ff576eff6659ff7847ff8c38f3a130e2b72fcfcc36bee044aff05b8ff4576ff65b52f6673af27828ea8d1ddfa319d0b81cbecb23abd82f96e03d82e14c6edb5a5dd0664dbf6e40aa",sinebow:"ff4040fc582af47218e78d0bd5a703bfbf00a7d5038de70b72f41858fc2a40ff402afc5818f4720be78d03d5a700bfbf03a7d50b8de71872f42a58fc4040ff582afc7218f48d0be7a703d5bf00bfd503a7e70b8df41872fc2a58ff4040",turbo:"23171b32204a3e2a71453493493eae4b49c54a53d7485ee44569ee4074f53c7ff8378af93295f72e9ff42ba9ef28b3e926bce125c5d925cdcf27d5c629dcbc2de3b232e9a738ee9d3ff39347f68950f9805afc7765fd6e70fe667cfd5e88fc5795fb51a1f84badf545b9f140c5ec3cd0e637dae034e4d931ecd12ef4c92bfac029ffb626ffad24ffa223ff9821ff8d1fff821dff771cfd6c1af76118f05616e84b14df4111d5380fcb2f0dc0260ab61f07ac1805a313029b0f00950c00910b00",browns:"eedbbdecca96e9b97ae4a865dc9856d18954c7784cc0673fb85536ad44339f3632",tealBlues:"bce4d89dd3d181c3cb65b3c245a2b9368fae347da0306a932c5985",teals:"bbdfdfa2d4d58ac9c975bcbb61b0af4da5a43799982b8b8c1e7f7f127273006667",warmGreys:"dcd4d0cec5c1c0b8b4b3aaa7a59c9998908c8b827f7e7673726866665c5a59504e",goldGreen:"f4d166d5ca60b6c35c98bb597cb25760a6564b9c533f8f4f33834a257740146c36",goldOrange:"f4d166f8be5cf8aa4cf5983bf3852aef701be2621fd65322c54923b142239e3a26",goldRed:"f4d166f6be59f9aa51fc964ef6834bee734ae56249db5247cf4244c43141b71d3e",lightGreyRed:"efe9e6e1dad7d5cbc8c8bdb9bbaea9cd967ddc7b43e15f19df4011dc000b",lightGreyTeal:"e4eaead6dcddc8ced2b7c2c7a6b4bc64b0bf22a6c32295c11f85be1876bc",lightMulti:"e0f1f2c4e9d0b0de9fd0e181f6e072f6c053f3993ef77440ef4a3c",lightOrange:"f2e7daf7d5baf9c499fab184fa9c73f68967ef7860e8645bde515bd43d5b",lightTealBlue:"e3e9e0c0dccf9aceca7abfc859afc0389fb9328dad2f7ca0276b95255988",darkBlue:"3232322d46681a5c930074af008cbf05a7ce25c0dd38daed50f3faffffff",darkGold:"3c3c3c584b37725e348c7631ae8b2bcfa424ecc31ef9de30fff184ffffff",darkGreen:"3a3a3a215748006f4d048942489e4276b340a6c63dd2d836ffeb2cffffaa",darkMulti:"3737371f5287197d8c29a86995ce3fffe800ffffff",darkRed:"3434347036339e3c38cc4037e75d1eec8620eeab29f0ce32ffeb2c"},PQ={accent:vQ,category10:mQ,category20:"1f77b4aec7e8ff7f0effbb782ca02c98df8ad62728ff98969467bdc5b0d58c564bc49c94e377c2f7b6d27f7f7fc7c7c7bcbd22dbdb8d17becf9edae5",category20b:"393b795254a36b6ecf9c9ede6379398ca252b5cf6bcedb9c8c6d31bd9e39e7ba52e7cb94843c39ad494ad6616be7969c7b4173a55194ce6dbdde9ed6",category20c:"3182bd6baed69ecae1c6dbefe6550dfd8d3cfdae6bfdd0a231a35474c476a1d99bc7e9c0756bb19e9ac8bcbddcdadaeb636363969696bdbdbdd9d9d9",dark2:yQ,observable10:bQ,paired:xQ,pastel1:_Q,pastel2:wQ,set1:EQ,set2:AQ,set3:kQ,tableau10:"4c78a8f58518e4575672b7b254a24beeca3bb279a2ff9da69d755dbab0ac",tableau20:"4c78a89ecae9f58518ffbf7954a24b88d27ab79a20f2cf5b43989483bcb6e45756ff9d9879706ebab0acd67195fcbfd2b279a2d6a5c99e765fd8b5a5"};function v9(e){if(fe(e))return e;const t=e.length/6|0,n=new Array(t);for(let r=0;rab(v9(e)));function QS(e,t){return e=e&&e.toLowerCase(),arguments.length>1?($D[e]=t,this):$D[e]}const a1="symbol",BQ="discrete",zQ="gradient",jQ=e=>fe(e)?e.map(t=>String(t)):String(e),UQ=(e,t)=>e[1]-t[1],qQ=(e,t)=>t[1]-e[1];function e3(e,t,n){let r;return Gt(t)&&(e.bins&&(t=Math.max(t,e.bins.length)),n!=null&&(t=Math.min(t,Math.floor(i0(e.domain())/n||1)+1))),Pe(t)&&(r=t.step,t=t.interval),ze(t)&&(t=e.type===Uc?wh(t):e.type==qc?Eh(t):ae("Only time and utc scales accept interval strings."),r&&(t=t.every(r))),t}function b9(e,t,n){let r=e.range(),i=r[0],s=jt(r),o=UQ;if(i>s&&(r=s,s=i,i=r,o=qQ),i=Math.floor(i),s=Math.ceil(s),t=t.map(a=>[a,e(a)]).filter(a=>i<=a[1]&&a[1]<=s).sort(o).map(a=>a[0]),n>0&&t.length>1){const a=[t[0],jt(t)];for(;t.length>n&&t.length>=3;)t=t.filter((l,u)=>!(u%2));t.length<3&&(t=a)}return t}function t3(e,t){return e.bins?b9(e,e.bins,t):e.ticks?e.ticks(t):e.domain()}function x9(e,t,n,r,i,s){const o=t.type;let a=jQ;if(o===Uc||i===Uc)a=e.timeFormat(r);else if(o===qc||i===qc)a=e.utcFormat(r);else if(f9(o)){const l=e.formatFloat(r);if(s||t.bins)a=l;else{const u=_9(t,n,!1);a=c=>u(c)?l(c):""}}else if(t.tickFormat){const l=t.domain();a=e.formatSpan(l[0],l[l.length-1],n,r)}else r&&(a=e.format(r));return a}function _9(e,t,n){const r=t3(e,t),i=e.base(),s=Math.log(i),o=Math.max(1,i*t/r.length),a=l=>{let u=l/Math.pow(i,Math.round(Math.log(l)/s));return u*i1?r[1]-r[0]:r[0],o;for(o=1;oWw[e.type]||e.bins;function A9(e,t,n,r,i,s,o){const a=w9[t.type]&&s!==Uc&&s!==qc?WQ(e,t,i):x9(e,t,n,i,s,o);return r===a1&&YQ(t)?VQ(a):r===BQ?XQ(a):KQ(a)}const VQ=e=>(t,n,r)=>{const i=FD(r[n+1],FD(r.max,1/0)),s=DD(t,e),o=DD(i,e);return s&&o?s+" – "+o:o?"< "+o:"≥ "+s},FD=(e,t)=>e??t,XQ=e=>(t,n)=>n?e(t):null,KQ=e=>t=>e(t),DD=(e,t)=>Number.isFinite(e)?t(e):null;function ZQ(e){const t=e.domain(),n=t.length-1;let r=+t[0],i=+jt(t),s=i-r;if(e.type===ob){const o=n?s/n:.1;r-=o,i+=o,s=i-r}return o=>(o-r)/s}function JQ(e,t,n,r){const i=r||t.type;return ze(n)&&NQ(i)&&(n=n.replace(/%a/g,"%A").replace(/%b/g,"%B")),!n&&i===Uc?e.timeFormat("%A, %d %B %Y, %X"):!n&&i===qc?e.utcFormat("%A, %d %B %Y, %X UTC"):A9(e,t,5,null,n,r,!0)}function k9(e,t,n){n=n||{};const r=Math.max(3,n.maxlen||7),i=JQ(e,t,n.format,n.formatType);if(qw(t.type)){const s=E9(t).slice(1).map(i),o=s.length;return`${o} boundar${o===1?"y":"ies"}: ${s.join(", ")}`}else if(zd(t.type)){const s=t.domain(),o=s.length,a=o>r?s.slice(0,r-2).map(i).join(", ")+", ending with "+s.slice(-1).map(i):s.map(i).join(", ");return`${o} value${o===1?"":"s"}: ${a}`}else{const s=t.domain();return`values from ${i(s[0])} to ${i(jt(s))}`}}let S9=0;function QQ(){S9=0}const sv="p_";function n3(e){return e&&e.gradient}function C9(e,t,n){const r=e.gradient;let i=e.id,s=r==="radial"?sv:"";return i||(i=e.id="gradient_"+S9++,r==="radial"?(e.x1=Oo(e.x1,.5),e.y1=Oo(e.y1,.5),e.r1=Oo(e.r1,0),e.x2=Oo(e.x2,.5),e.y2=Oo(e.y2,.5),e.r2=Oo(e.r2,.5),s=sv):(e.x1=Oo(e.x1,0),e.y1=Oo(e.y1,0),e.x2=Oo(e.x2,1),e.y2=Oo(e.y2,0))),t[i]=e,"url("+(n||"")+"#"+s+i+")"}function Oo(e,t){return e??t}function $9(e,t){var n=[],r;return r={gradient:"linear",x1:e?e[0]:0,y1:e?e[1]:0,x2:t?t[0]:1,y2:t?t[1]:0,stops:n,stop:function(i,s){return n.push({offset:i,color:s}),r}}}const MD={basis:{curve:XZ},"basis-closed":{curve:KZ},"basis-open":{curve:ZZ},bundle:{curve:JZ,tension:"beta",value:.85},cardinal:{curve:QZ,tension:"tension",value:0},"cardinal-open":{curve:tJ,tension:"tension",value:0},"cardinal-closed":{curve:eJ,tension:"tension",value:0},"catmull-rom":{curve:nJ,tension:"alpha",value:.5},"catmull-rom-closed":{curve:rJ,tension:"alpha",value:.5},"catmull-rom-open":{curve:iJ,tension:"alpha",value:.5},linear:{curve:CS},"linear-closed":{curve:sJ},monotone:{horizontal:aJ,vertical:oJ},natural:{curve:lJ},step:{curve:uJ},"step-after":{curve:fJ},"step-before":{curve:cJ}};function r3(e,t,n){var r=We(MD,e)&&MD[e],i=null;return r&&(i=r.curve||r[t||"vertical"],r.tension&&n!=null&&(i=i[r.tension](n))),i}const eee={m:2,l:2,h:1,v:1,z:0,c:6,s:4,q:4,t:2,a:7},tee=/[mlhvzcsqta]([^mlhvzcsqta]+|$)/gi,nee=/^[+-]?(([0-9]*\.[0-9]+)|([0-9]+\.)|([0-9]+))([eE][+-]?[0-9]+)?/,ree=/^((\s+,?\s*)|(,\s*))/,iee=/^[01]/;function jd(e){const t=[];return(e.match(tee)||[]).forEach(r=>{let i=r[0];const s=i.toLowerCase(),o=eee[s],a=see(s,o,r.slice(1).trim()),l=a.length;if(l1&&(g=Math.sqrt(g),n*=g,r*=g);const m=d/n,v=f/n,b=-f/r,x=d/r,_=m*a+v*l,w=b*a+x*l,A=m*e+v*t,E=b*e+x*t;let S=1/((A-_)*(A-_)+(E-w)*(E-w))-.25;S<0&&(S=0);let $=Math.sqrt(S);s==i&&($=-$);const M=.5*(_+A)-$*(E-w),O=.5*(w+E)+$*(A-_),P=Math.atan2(w-O,_-M);let F=Math.atan2(E-O,A-M)-P;F<0&&s===1?F+=Yo:F>0&&s===0&&(F-=Yo);const R=Math.ceil(Math.abs(F/(sc+.001))),z=[];for(let j=0;j+e}function hm(e,t,n){return Math.max(t,Math.min(e,n))}function M9(){var e=fee,t=dee,n=hee,r=pee,i=Ta(0),s=i,o=i,a=i,l=null;function u(c,f,d){var h,p=f??+e.call(this,c),g=d??+t.call(this,c),m=+n.call(this,c),v=+r.call(this,c),b=Math.min(m,v)/2,x=hm(+i.call(this,c),0,b),_=hm(+s.call(this,c),0,b),w=hm(+o.call(this,c),0,b),A=hm(+a.call(this,c),0,b);if(l||(l=h=Vy()),x<=0&&_<=0&&w<=0&&A<=0)l.rect(p,g,m,v);else{var E=p+m,k=g+v;l.moveTo(p+x,g),l.lineTo(E-_,g),l.bezierCurveTo(E-Sl*_,g,E,g+Sl*_,E,g+_),l.lineTo(E,k-A),l.bezierCurveTo(E,k-Sl*A,E-Sl*A,k,E-A,k),l.lineTo(p+w,k),l.bezierCurveTo(p+Sl*w,k,p,k-Sl*w,p,k-w),l.lineTo(p,g+x),l.bezierCurveTo(p,g+Sl*x,p+Sl*x,g,p+x,g),l.closePath()}if(h)return l=null,h+""||null}return u.x=function(c){return arguments.length?(e=Ta(c),u):e},u.y=function(c){return arguments.length?(t=Ta(c),u):t},u.width=function(c){return arguments.length?(n=Ta(c),u):n},u.height=function(c){return arguments.length?(r=Ta(c),u):r},u.cornerRadius=function(c,f,d,h){return arguments.length?(i=Ta(c),s=f!=null?Ta(f):i,a=d!=null?Ta(d):i,o=h!=null?Ta(h):s,u):i},u.context=function(c){return arguments.length?(l=c??null,u):l},u}function T9(){var e,t,n,r,i=null,s,o,a,l;function u(f,d,h){const p=h/2;if(s){var g=a-d,m=f-o;if(g||m){var v=Math.hypot(g,m),b=(g/=v)*l,x=(m/=v)*l,_=Math.atan2(m,g);i.moveTo(o-b,a-x),i.lineTo(f-g*p,d-m*p),i.arc(f,d,p,_-Math.PI,_),i.lineTo(o+b,a+x),i.arc(o,a,l,_,_+Math.PI)}else i.arc(f,d,p,0,Yo);i.closePath()}else s=1;o=f,a=d,l=p}function c(f){var d,h=f.length,p,g=!1,m;for(i==null&&(i=m=Vy()),d=0;d<=h;++d)!(de.x||0,v0=e=>e.y||0,gee=e=>e.width||0,mee=e=>e.height||0,vee=e=>(e.x||0)+(e.width||0),yee=e=>(e.y||0)+(e.height||0),bee=e=>e.startAngle||0,xee=e=>e.endAngle||0,_ee=e=>e.padAngle||0,wee=e=>e.innerRadius||0,Eee=e=>e.outerRadius||0,Aee=e=>e.cornerRadius||0,kee=e=>g0(e.cornerRadiusTopLeft,e.cornerRadius)||0,See=e=>g0(e.cornerRadiusTopRight,e.cornerRadius)||0,Cee=e=>g0(e.cornerRadiusBottomRight,e.cornerRadius)||0,$ee=e=>g0(e.cornerRadiusBottomLeft,e.cornerRadius)||0,Fee=e=>g0(e.size,64),Dee=e=>e.size||1,lb=e=>e.defined!==!1,Mee=e=>D9(e.shape||"circle"),Tee=GZ().startAngle(bee).endAngle(xee).padAngle(_ee).innerRadius(wee).outerRadius(Eee).cornerRadius(Aee),Ree=a7().x(m0).y1(v0).y0(yee).defined(lb),Nee=a7().y(v0).x1(m0).x0(vee).defined(lb),Oee=o7().x(m0).y(v0).defined(lb),Lee=M9().x(m0).y(v0).width(gee).height(mee).cornerRadius(kee,See,Cee,$ee),Iee=VZ().type(Mee).size(Fee),Pee=T9().x(m0).y(v0).defined(lb).size(Dee);function i3(e){return e.cornerRadius||e.cornerRadiusTopLeft||e.cornerRadiusTopRight||e.cornerRadiusBottomRight||e.cornerRadiusBottomLeft}function Bee(e,t){return Tee.context(e)(t)}function zee(e,t){const n=t[0],r=n.interpolate||"linear";return(n.orient==="horizontal"?Nee:Ree).curve(r3(r,n.orient,n.tension)).context(e)(t)}function jee(e,t){const n=t[0],r=n.interpolate||"linear";return Oee.curve(r3(r,n.orient,n.tension)).context(e)(t)}function Ch(e,t,n,r){return Lee.context(e)(t,n,r)}function Uee(e,t){return(t.mark.shape||t.shape).context(e)(t)}function qee(e,t){return Iee.context(e)(t)}function Wee(e,t){return Pee.context(e)(t)}var R9=1;function N9(){R9=1}function s3(e,t,n){var r=t.clip,i=e._defs,s=t.clip_id||(t.clip_id="clip"+R9++),o=i.clipping[s]||(i.clipping[s]={id:s});return St(r)?o.path=r(null):i3(n)?o.path=Ch(null,n,0,0):(o.width=n.width||0,o.height=n.height||0),"url(#"+s+")"}function Hn(e){this.clear(),e&&this.union(e)}Hn.prototype={clone(){return new Hn(this)},clear(){return this.x1=+Number.MAX_VALUE,this.y1=+Number.MAX_VALUE,this.x2=-Number.MAX_VALUE,this.y2=-Number.MAX_VALUE,this},empty(){return this.x1===+Number.MAX_VALUE&&this.y1===+Number.MAX_VALUE&&this.x2===-Number.MAX_VALUE&&this.y2===-Number.MAX_VALUE},equals(e){return this.x1===e.x1&&this.y1===e.y1&&this.x2===e.x2&&this.y2===e.y2},set(e,t,n,r){return nthis.x2&&(this.x2=e),t>this.y2&&(this.y2=t),this},expand(e){return this.x1-=e,this.y1-=e,this.x2+=e,this.y2+=e,this},round(){return this.x1=Math.floor(this.x1),this.y1=Math.floor(this.y1),this.x2=Math.ceil(this.x2),this.y2=Math.ceil(this.y2),this},scale(e){return this.x1*=e,this.y1*=e,this.x2*=e,this.y2*=e,this},translate(e,t){return this.x1+=e,this.x2+=e,this.y1+=t,this.y2+=t,this},rotate(e,t,n){const r=this.rotatedPoints(e,t,n);return this.clear().add(r[0],r[1]).add(r[2],r[3]).add(r[4],r[5]).add(r[6],r[7])},rotatedPoints(e,t,n){var{x1:r,y1:i,x2:s,y2:o}=this,a=Math.cos(e),l=Math.sin(e),u=t-t*a+n*l,c=n-t*l-n*a;return[a*r-l*i+u,l*r+a*i+c,a*r-l*o+u,l*r+a*o+c,a*s-l*i+u,l*s+a*i+c,a*s-l*o+u,l*s+a*o+c]},union(e){return e.x1this.x2&&(this.x2=e.x2),e.y2>this.y2&&(this.y2=e.y2),this},intersect(e){return e.x1>this.x1&&(this.x1=e.x1),e.y1>this.y1&&(this.y1=e.y1),e.x2=e.x2&&this.y1<=e.y1&&this.y2>=e.y2},alignsWith(e){return e&&(this.x1==e.x1||this.x2==e.x2||this.y1==e.y1||this.y2==e.y2)},intersects(e){return e&&!(this.x2e.x2||this.y2e.y2)},contains(e,t){return!(ethis.x2||tthis.y2)},width(){return this.x2-this.x1},height(){return this.y2-this.y1}};function ub(e){this.mark=e,this.bounds=this.bounds||new Hn}function cb(e){ub.call(this,e),this.items=this.items||[]}Te(cb,ub);class O9{constructor(t){this._pending=0,this._loader=t||Ly()}pending(){return this._pending}sanitizeURL(t){const n=this;return OD(n),n._loader.sanitize(t,{context:"href"}).then(r=>(ep(n),r)).catch(()=>(ep(n),null))}loadImage(t){const n=this,r=dJ();return OD(n),n._loader.sanitize(t,{context:"image"}).then(i=>{const s=i.href;if(!s||!r)throw{url:s};const o=new r,a=We(i,"crossOrigin")?i.crossOrigin:"anonymous";return a!=null&&(o.crossOrigin=a),o.onload=()=>ep(n),o.onerror=()=>ep(n),o.src=s,o}).catch(i=>(ep(n),{complete:!1,width:0,height:0,src:i&&i.url||""}))}ready(){const t=this;return new Promise(n=>{function r(i){t.pending()?setTimeout(()=>{r(!0)},10):n(i)}r(!1)})}}function OD(e){e._pending+=1}function ep(e){e._pending-=1}function gl(e,t,n){if(t.stroke&&t.opacity!==0&&t.strokeOpacity!==0){const r=t.strokeWidth!=null?+t.strokeWidth:1;e.expand(r+(n?Hee(t,r):0))}return e}function Hee(e,t){return e.strokeJoin&&e.strokeJoin!=="miter"?0:t}const Gee=Yo-1e-8;let fb,l1,u1,gc,Hw,c1,Gw,Yw;const Bl=(e,t)=>fb.add(e,t),f1=(e,t)=>Bl(l1=e,u1=t),LD=e=>Bl(e,fb.y1),ID=e=>Bl(fb.x1,e),oc=(e,t)=>Hw*e+Gw*t,ac=(e,t)=>c1*e+Yw*t,Sx=(e,t)=>Bl(oc(e,t),ac(e,t)),Cx=(e,t)=>f1(oc(e,t),ac(e,t));function y0(e,t){return fb=e,t?(gc=t*uu,Hw=Yw=Math.cos(gc),c1=Math.sin(gc),Gw=-c1):(Hw=Yw=1,gc=c1=Gw=0),Yee}const Yee={beginPath(){},closePath(){},moveTo:Cx,lineTo:Cx,rect(e,t,n,r){gc?(Sx(e+n,t),Sx(e+n,t+r),Sx(e,t+r),Cx(e,t)):(Bl(e+n,t+r),f1(e,t))},quadraticCurveTo(e,t,n,r){const i=oc(e,t),s=ac(e,t),o=oc(n,r),a=ac(n,r);PD(l1,i,o,LD),PD(u1,s,a,ID),f1(o,a)},bezierCurveTo(e,t,n,r,i,s){const o=oc(e,t),a=ac(e,t),l=oc(n,r),u=ac(n,r),c=oc(i,s),f=ac(i,s);BD(l1,o,l,c,LD),BD(u1,a,u,f,ID),f1(c,f)},arc(e,t,n,r,i,s){if(r+=gc,i+=gc,l1=n*Math.cos(i)+e,u1=n*Math.sin(i)+t,Math.abs(i-r)>Gee)Bl(e-n,t-n),Bl(e+n,t+n);else{const o=u=>Bl(n*Math.cos(u)+e,n*Math.sin(u)+t);let a,l;if(o(r),o(i),i!==r)if(r=r%Yo,r<0&&(r+=Yo),i=i%Yo,i<0&&(i+=Yo),ii;++l,a-=sc)o(a);else for(a=r-r%sc+sc,l=0;l<4&&aoee?(c=o*o+a*s,c>=0&&(c=Math.sqrt(c),l=(-o+c)/s,u=(-o-c)/s)):l=.5*a/o,0d)return!1;g>f&&(f=g)}else if(h>0){if(g0?(e.globalAlpha=n,e.fillStyle=P9(e,t,t.fill),!0):!1}var Xee=[];function qd(e,t,n){var r=(r=t.strokeWidth)!=null?r:1;return r<=0?!1:(n*=t.strokeOpacity==null?1:t.strokeOpacity,n>0?(e.globalAlpha=n,e.strokeStyle=P9(e,t,t.stroke),e.lineWidth=r,e.lineCap=t.strokeCap||"butt",e.lineJoin=t.strokeJoin||"miter",e.miterLimit=t.strokeMiterLimit||10,e.setLineDash&&(e.setLineDash(t.strokeDash||Xee),e.lineDashOffset=t.strokeDashOffset||0),!0):!1)}function Kee(e,t){return e.zindex-t.zindex||e.index-t.index}function l3(e){if(!e.zdirty)return e.zitems;var t=e.items,n=[],r,i,s;for(i=0,s=t.length;i=0;)if(r=t(n[i]))return r;if(n===s){for(n=e.items,i=n.length;--i>=0;)if(!n[i].zindex&&(r=t(n[i])))return r}return null}function u3(e){return function(t,n,r){yo(n,i=>{(!r||r.intersects(i.bounds))&&B9(e,t,i,i)})}}function Zee(e){return function(t,n,r){n.items.length&&(!r||r.intersects(n.bounds))&&B9(e,t,n.items[0],n.items)}}function B9(e,t,n,r){var i=n.opacity==null?1:n.opacity;i!==0&&(e(t,r)||(Ud(t,n),n.fill&&ov(t,n,i)&&t.fill(),n.stroke&&qd(t,n,i)&&t.stroke()))}function db(e){return e=e||fs,function(t,n,r,i,s,o){return r*=t.pixelRatio,i*=t.pixelRatio,av(n,a=>{const l=a.bounds;if(!(l&&!l.contains(s,o)||!l)&&e(t,a,r,i,s,o))return a})}}function b0(e,t){return function(n,r,i,s){var o=Array.isArray(r)?r[0]:r,a=t??o.fill,l=o.stroke&&n.isPointInStroke,u,c;return l&&(u=o.strokeWidth,c=o.strokeCap,n.lineWidth=u??1,n.lineCap=c??"butt"),e(n,r)?!1:a&&n.isPointInPath(i,s)||l&&n.isPointInStroke(i,s)}}function c3(e){return db(b0(e))}function kc(e,t){return"translate("+e+","+t+")"}function f3(e){return"rotate("+e+")"}function Jee(e,t){return"scale("+e+","+t+")"}function z9(e){return kc(e.x||0,e.y||0)}function Qee(e){return kc(e.x||0,e.y||0)+(e.angle?" "+f3(e.angle):"")}function ete(e){return kc(e.x||0,e.y||0)+(e.angle?" "+f3(e.angle):"")+(e.scaleX||e.scaleY?" "+Jee(e.scaleX||1,e.scaleY||1):"")}function d3(e,t,n){function r(o,a){o("transform",Qee(a)),o("d",t(null,a))}function i(o,a){return t(y0(o,a.angle),a),gl(o,a).translate(a.x||0,a.y||0)}function s(o,a){var l=a.x||0,u=a.y||0,c=a.angle||0;o.translate(l,u),c&&o.rotate(c*=uu),o.beginPath(),t(o,a),c&&o.rotate(-c),o.translate(-l,-u)}return{type:e,tag:"path",nested:!1,attr:r,bound:i,draw:u3(s),pick:c3(s),isect:n||o3(s)}}var tte=d3("arc",Bee);function nte(e,t){for(var n=e[0].orient==="horizontal"?t[1]:t[0],r=e[0].orient==="horizontal"?"y":"x",i=e.length,s=1/0,o,a;--i>=0;)e[i].defined!==!1&&(a=Math.abs(e[i][r]-n),a=0;)if(e[r].defined!==!1&&(i=e[r].x-t[0],s=e[r].y-t[1],o=i*i+s*s,o=0;)if(e[n].defined!==!1&&(r=e[n].x-t[0],i=e[n].y-t[1],s=r*r+i*i,r=e[n].size||1,s.5&&t<1.5?.5-Math.abs(t-1):0}function ate(e,t){e("transform",z9(t))}function q9(e,t){const n=U9(t);e("d",Ch(null,t,n,n))}function lte(e,t){e("class","background"),e("aria-hidden",!0),q9(e,t)}function ute(e,t){e("class","foreground"),e("aria-hidden",!0),t.strokeForeground?q9(e,t):e("d","")}function cte(e,t,n){const r=t.clip?s3(n,t,t):null;e("clip-path",r)}function fte(e,t){if(!t.clip&&t.items){const n=t.items,r=n.length;for(let i=0;i{const s=i.x||0,o=i.y||0,a=i.strokeForeground,l=i.opacity==null?1:i.opacity;(i.stroke||i.fill)&&l&&(xg(e,i,s,o),Ud(e,i),i.fill&&ov(e,i,l)&&e.fill(),i.stroke&&!a&&qd(e,i,l)&&e.stroke()),e.save(),e.translate(s,o),i.clip&&j9(e,i),n&&n.translate(-s,-o),yo(i,u=>{(u.marktype==="group"||r==null||r.includes(u.marktype))&&this.draw(e,u,n,r)}),n&&n.translate(s,o),e.restore(),a&&i.stroke&&l&&(xg(e,i,s,o),Ud(e,i),qd(e,i,l)&&e.stroke())})}function mte(e,t,n,r,i,s){if(t.bounds&&!t.bounds.contains(i,s)||!t.items)return null;const o=n*e.pixelRatio,a=r*e.pixelRatio;return av(t,l=>{let u,c,f;const d=l.bounds;if(d&&!d.contains(i,s))return;c=l.x||0,f=l.y||0;const h=c+(l.width||0),p=f+(l.height||0),g=l.clip;if(g&&(ih||sp))return;if(e.save(),e.translate(c,f),c=i-c,f=s-f,g&&i3(l)&&!pte(e,l,o,a))return e.restore(),null;const m=l.strokeForeground,v=t.interactive!==!1;return v&&m&&l.stroke&&hte(e,l,o,a)?(e.restore(),l):(u=av(l,b=>vte(b,c,f)?this.pick(b,n,r,c,f):null),!u&&v&&(l.fill||!m&&l.stroke)&&dte(e,l,o,a)&&(u=l),e.restore(),u||null)})}function vte(e,t,n){return(e.interactive!==!1||e.marktype==="group")&&e.bounds&&e.bounds.contains(t,n)}var yte={type:"group",tag:"g",nested:!1,attr:ate,bound:fte,draw:gte,pick:mte,isect:L9,content:cte,background:lte,foreground:ute},_g={xmlns:"http://www.w3.org/2000/svg","xmlns:xlink":"http://www.w3.org/1999/xlink",version:"1.1"};function p3(e,t){var n=e.image;return(!n||e.url&&e.url!==n.url)&&(n={complete:!1,width:0,height:0},t.loadImage(e.url).then(r=>{e.image=r,e.image.url=e.url})),n}function g3(e,t){return e.width!=null?e.width:!t||!t.width?0:e.aspect!==!1&&e.height?e.height*t.width/t.height:t.width}function m3(e,t){return e.height!=null?e.height:!t||!t.height?0:e.aspect!==!1&&e.width?e.width*t.height/t.width:t.height}function hb(e,t){return e==="center"?t/2:e==="right"?t:0}function pb(e,t){return e==="middle"?t/2:e==="bottom"?t:0}function bte(e,t,n){const r=p3(t,n),i=g3(t,r),s=m3(t,r),o=(t.x||0)-hb(t.align,i),a=(t.y||0)-pb(t.baseline,s),l=!r.src&&r.toDataURL?r.toDataURL():r.src||"";e("href",l,_g["xmlns:xlink"],"xlink:href"),e("transform",kc(o,a)),e("width",i),e("height",s),e("preserveAspectRatio",t.aspect===!1?"none":"xMidYMid")}function xte(e,t){const n=t.image,r=g3(t,n),i=m3(t,n),s=(t.x||0)-hb(t.align,r),o=(t.y||0)-pb(t.baseline,i);return e.set(s,o,s+r,o+i)}function _te(e,t,n){yo(t,r=>{if(n&&!n.intersects(r.bounds))return;const i=p3(r,this);let s=g3(r,i),o=m3(r,i);if(s===0||o===0)return;let a=(r.x||0)-hb(r.align,s),l=(r.y||0)-pb(r.baseline,o),u,c,f,d;r.aspect!==!1&&(c=i.width/i.height,f=r.width/r.height,c===c&&f===f&&c!==f&&(f{if(!(n&&!n.intersects(r.bounds))){var i=r.opacity==null?1:r.opacity;i&&W9(e,r,i)&&(Ud(e,r),e.stroke())}})}function Rte(e,t,n,r){return e.isPointInStroke?W9(e,t,1)&&e.isPointInStroke(n,r):!1}var Nte={type:"rule",tag:"line",nested:!1,attr:Dte,bound:Mte,draw:Tte,pick:db(Rte),isect:I9},Ote=d3("shape",Uee),Lte=d3("symbol",qee,a3);const qD=JR();var ls={height:xa,measureWidth:v3,estimateWidth:lv,width:lv,canvas:H9};H9(!0);function H9(e){ls.width=e&&tu?v3:lv}function lv(e,t){return G9(fu(e,t),xa(e))}function G9(e,t){return~~(.8*e.length*t)}function v3(e,t){return xa(e)<=0||!(t=fu(e,t))?0:Y9(t,gb(e))}function Y9(e,t){const n=`(${t}) ${e}`;let r=qD.get(n);return r===void 0&&(tu.font=t,r=tu.measureText(e).width,qD.set(n,r)),r}function xa(e){return e.fontSize!=null?+e.fontSize||0:11}function cu(e){return e.lineHeight!=null?e.lineHeight:xa(e)+2}function Ite(e){return fe(e)?e.length>1?e:e[0]:e}function x0(e){return Ite(e.lineBreak&&e.text&&!fe(e.text)?e.text.split(e.lineBreak):e.text)}function y3(e){const t=x0(e);return(fe(t)?t.length-1:0)*cu(e)}function fu(e,t){const n=t==null?"":(t+"").trim();return e.limit>0&&n.length?Bte(e,n):n}function Pte(e){if(ls.width===v3){const t=gb(e);return n=>Y9(n,t)}else if(ls.width===lv){const t=xa(e);return n=>G9(n,t)}else return t=>ls.width(e,t)}function Bte(e,t){var n=+e.limit,r=Pte(e);if(r(t)>>1,r(t.slice(l))>n?o=l+1:a=l;return i+t.slice(o)}else{for(;o>>1),r(t.slice(0,l))Math.max(d,ls.width(t,h)),0)):f=ls.width(t,c),i==="center"?l-=f/2:i==="right"&&(l-=f),e.set(l+=o,u+=a,l+f,u+r),t.angle&&!n)e.rotate(t.angle*uu,o,a);else if(n===2)return e.rotatedPoints(t.angle*uu,o,a);return e}function Ute(e,t,n){yo(t,r=>{var i=r.opacity==null?1:r.opacity,s,o,a,l,u,c,f;if(!(n&&!n.intersects(r.bounds)||i===0||r.fontSize<=0||r.text==null||r.text.length===0)){if(e.font=gb(r),e.textAlign=r.align||"left",s=mb(r),o=s.x1,a=s.y1,r.angle&&(e.save(),e.translate(o,a),e.rotate(r.angle*uu),o=a=0),o+=r.dx||0,a+=(r.dy||0)+b3(r),c=x0(r),Ud(e,r),fe(c))for(u=cu(r),l=0;lt;)e.removeChild(n[--r]);return e}function Q9(e){return"mark-"+e.marktype+(e.role?" role-"+e.role:"")+(e.name?" "+e.name:"")}function vb(e,t){const n=t.getBoundingClientRect();return[e.clientX-n.left-(t.clientLeft||0),e.clientY-n.top-(t.clientTop||0)]}function Vte(e,t,n,r){var i=e&&e.mark,s,o;if(i&&(s=ps[i.marktype]).tip){for(o=vb(t,n),o[0]-=r[0],o[1]-=r[1];e=e.mark.group;)o[0]-=e.x||0,o[1]-=e.y||0;e=s.tip(i.items,o)}return e}let w3=class{constructor(t,n){this._active=null,this._handlers={},this._loader=t||Ly(),this._tooltip=n||Xte}initialize(t,n,r){return this._el=t,this._obj=r||null,this.origin(n)}element(){return this._el}canvas(){return this._el&&this._el.firstChild}origin(t){return arguments.length?(this._origin=t||[0,0],this):this._origin.slice()}scene(t){return arguments.length?(this._scene=t,this):this._scene}on(){}off(){}_handlerIndex(t,n,r){for(let i=t?t.length:0;--i>=0;)if(t[i].type===n&&(!r||t[i].handler===r))return i;return-1}handlers(t){const n=this._handlers,r=[];if(t)r.push(...n[this.eventName(t)]);else for(const i in n)r.push(...n[i]);return r}eventName(t){const n=t.indexOf(".");return n<0?t:t.slice(0,n)}handleHref(t,n,r){this._loader.sanitize(r,{context:"href"}).then(i=>{const s=new MouseEvent(t.type,t),o=zl(null,"a");for(const a in i)o.setAttribute(a,i[a]);o.dispatchEvent(s)}).catch(()=>{})}handleTooltip(t,n,r){if(n&&n.tooltip!=null){n=Vte(n,t,this.canvas(),this._origin);const i=r&&n&&n.tooltip||null;this._tooltip.call(this._obj,this,t,n,i)}}getItemBoundingClientRect(t){const n=this.canvas();if(!n)return;const r=n.getBoundingClientRect(),i=this._origin,s=t.bounds,o=s.width(),a=s.height();let l=s.x1+i[0]+r.left,u=s.y1+i[1]+r.top;for(;t.mark&&(t=t.mark.group);)l+=t.x||0,u+=t.y||0;return{x:l,y:u,width:o,height:a,left:l,top:u,right:l+o,bottom:u+a}}};function Xte(e,t,n,r){e.element().setAttribute("title",r||"")}class w0{constructor(t){this._el=null,this._bgcolor=null,this._loader=new O9(t)}initialize(t,n,r,i,s){return this._el=t,this.resize(n,r,i,s)}element(){return this._el}canvas(){return this._el&&this._el.firstChild}background(t){return arguments.length===0?this._bgcolor:(this._bgcolor=t,this)}resize(t,n,r,i){return this._width=t,this._height=n,this._origin=r||[0,0],this._scale=i||1,this}dirty(){}render(t,n){const r=this;return r._call=function(){r._render(t,n)},r._call(),r._call=null,r}_render(){}renderAsync(t,n){const r=this.render(t,n);return this._ready?this._ready.then(()=>r):Promise.resolve(r)}_load(t,n){var r=this,i=r._loader[t](n);if(!r._ready){const s=r._call;r._ready=r._loader.ready().then(o=>{o&&s(),r._ready=null})}return i}sanitizeURL(t){return this._load("sanitizeURL",t)}loadImage(t){return this._load("loadImage",t)}}const Kte="keydown",Zte="keypress",Jte="keyup",eL="dragenter",h1="dragleave",tL="dragover",Kw="pointerdown",Qte="pointerup",uv="pointermove",p1="pointerout",nL="pointerover",Zw="mousedown",ene="mouseup",rL="mousemove",cv="mouseout",iL="mouseover",fv="click",tne="dblclick",nne="wheel",sL="mousewheel",dv="touchstart",hv="touchmove",pv="touchend",rne=[Kte,Zte,Jte,eL,h1,tL,Kw,Qte,uv,p1,nL,Zw,ene,rL,cv,iL,fv,tne,nne,sL,dv,hv,pv],Jw=uv,Vp=cv,Qw=fv;class E0 extends w3{constructor(t,n){super(t,n),this._down=null,this._touch=null,this._first=!0,this._events={},this.events=rne,this.pointermove=YD([uv,rL],[nL,iL],[p1,cv]),this.dragover=YD([tL],[eL],[h1]),this.pointerout=VD([p1,cv]),this.dragleave=VD([h1])}initialize(t,n,r){return this._canvas=t&&_3(t,"canvas"),[fv,Zw,Kw,uv,p1,h1].forEach(i=>GD(this,i)),super.initialize(t,n,r)}canvas(){return this._canvas}context(){return this._canvas.getContext("2d")}DOMMouseScroll(t){this.fire(sL,t)}pointerdown(t){this._down=this._active,this.fire(Kw,t)}mousedown(t){this._down=this._active,this.fire(Zw,t)}click(t){this._down===this._active&&(this.fire(fv,t),this._down=null)}touchstart(t){this._touch=this.pickEvent(t.changedTouches[0]),this._first&&(this._active=this._touch,this._first=!1),this.fire(dv,t,!0)}touchmove(t){this.fire(hv,t,!0)}touchend(t){this.fire(pv,t,!0),this._touch=null}fire(t,n,r){const i=r?this._touch:this._active,s=this._handlers[t];if(n.vegaType=t,t===Qw&&i&&i.href?this.handleHref(n,i,i.href):(t===Jw||t===Vp)&&this.handleTooltip(n,i,t!==Vp),s)for(let o=0,a=s.length;o=0&&i.splice(s,1),this}pickEvent(t){const n=vb(t,this._canvas),r=this._origin;return this.pick(this._scene,n[0],n[1],n[0]-r[0],n[1]-r[1])}pick(t,n,r,i,s){const o=this.context();return ps[t.marktype].pick.call(this,o,t,n,r,i,s)}}const ine=e=>e===dv||e===hv||e===pv?[dv,hv,pv]:[e];function GD(e,t){ine(t).forEach(n=>sne(e,n))}function sne(e,t){const n=e.canvas();n&&!e._events[t]&&(e._events[t]=1,n.addEventListener(t,e[t]?r=>e[t](r):r=>e.fire(t,r)))}function kp(e,t,n){t.forEach(r=>e.fire(r,n))}function YD(e,t,n){return function(r){const i=this._active,s=this.pickEvent(r);s===i?kp(this,e,r):((!i||!i.exit)&&kp(this,n,r),this._active=s,kp(this,t,r),kp(this,e,r))}}function VD(e){return function(t){kp(this,e,t),this._active=null}}function one(){return typeof window<"u"&&window.devicePixelRatio||1}function ane(e,t,n,r,i,s){const o=typeof HTMLElement<"u"&&e instanceof HTMLElement&&e.parentNode!=null,a=e.getContext("2d"),l=o?one():i;e.width=t*l,e.height=n*l;for(const u in s)a[u]=s[u];return o&&l!==1&&(e.style.width=t+"px",e.style.height=n+"px"),a.pixelRatio=l,a.setTransform(l,0,0,l,l*r[0],l*r[1]),e}class gv extends w0{constructor(t){super(t),this._options={},this._redraw=!1,this._dirty=new Hn,this._tempb=new Hn}initialize(t,n,r,i,s,o){return this._options=o||{},this._canvas=this._options.externalContext?null:eu(1,1,this._options.type),t&&this._canvas&&(Es(t,0).appendChild(this._canvas),this._canvas.setAttribute("class","marks")),super.initialize(t,n,r,i,s)}resize(t,n,r,i){if(super.resize(t,n,r,i),this._canvas)ane(this._canvas,this._width,this._height,this._origin,this._scale,this._options.context);else{const s=this._options.externalContext;s||ae("CanvasRenderer is missing a valid canvas or context"),s.scale(this._scale,this._scale),s.translate(this._origin[0],this._origin[1])}return this._redraw=!0,this}canvas(){return this._canvas}context(){return this._options.externalContext||(this._canvas?this._canvas.getContext("2d"):null)}dirty(t){const n=this._tempb.clear().union(t.bounds);let r=t.mark.group;for(;r;)n.translate(r.x||0,r.y||0),r=r.mark.group;this._dirty.union(n)}_render(t,n){const r=this.context(),i=this._origin,s=this._width,o=this._height,a=this._dirty,l=lne(i,s,o);r.save();const u=this._redraw||a.empty()?(this._redraw=!1,l.expand(1)):une(r,l.intersect(a),i);return this.clear(-i[0],-i[1],s,o),this.draw(r,t,u,n),r.restore(),a.clear(),this}draw(t,n,r,i){if(n.marktype!=="group"&&i!=null&&!i.includes(n.marktype))return;const s=ps[n.marktype];n.clip&&ote(t,n),s.draw.call(this,t,n,r,i),n.clip&&t.restore()}clear(t,n,r,i){const s=this._options,o=this.context();s.type!=="pdf"&&!s.externalContext&&o.clearRect(t,n,r,i),this._bgcolor!=null&&(o.fillStyle=this._bgcolor,o.fillRect(t,n,r,i))}}const lne=(e,t,n)=>new Hn().set(0,0,t,n).translate(-e[0],-e[1]);function une(e,t,n){return t.expand(1).round(),e.pixelRatio%1&&t.scale(e.pixelRatio).round().scale(1/e.pixelRatio),t.translate(-(n[0]%1),-(n[1]%1)),e.beginPath(),e.rect(t.x1,t.y1,t.width(),t.height()),e.clip(),t}class oL extends w3{constructor(t,n){super(t,n);const r=this;r._hrefHandler=$x(r,(i,s)=>{s&&s.href&&r.handleHref(i,s,s.href)}),r._tooltipHandler=$x(r,(i,s)=>{r.handleTooltip(i,s,i.type!==Vp)})}initialize(t,n,r){let i=this._svg;return i&&(i.removeEventListener(Qw,this._hrefHandler),i.removeEventListener(Jw,this._tooltipHandler),i.removeEventListener(Vp,this._tooltipHandler)),this._svg=i=t&&_3(t,"svg"),i&&(i.addEventListener(Qw,this._hrefHandler),i.addEventListener(Jw,this._tooltipHandler),i.addEventListener(Vp,this._tooltipHandler)),super.initialize(t,n,r)}canvas(){return this._svg}on(t,n){const r=this.eventName(t),i=this._handlers;if(this._handlerIndex(i[r],t,n)<0){const o={type:t,handler:n,listener:$x(this,n)};(i[r]||(i[r]=[])).push(o),this._svg&&this._svg.addEventListener(r,o.listener)}return this}off(t,n){const r=this.eventName(t),i=this._handlers[r],s=this._handlerIndex(i,t,n);return s>=0&&(this._svg&&this._svg.removeEventListener(r,i[s].listener),i.splice(s,1)),this}}const $x=(e,t)=>n=>{let r=n.target.__data__;r=Array.isArray(r)?r[0]:r,n.vegaType=n.type,t.call(e._obj,n,r)},aL="aria-hidden",E3="aria-label",A3="role",k3="aria-roledescription",lL="graphics-object",S3="graphics-symbol",uL=(e,t,n)=>({[A3]:e,[k3]:t,[E3]:n||void 0}),cne=mo(["axis-domain","axis-grid","axis-label","axis-tick","axis-title","legend-band","legend-entry","legend-gradient","legend-label","legend-title","legend-symbol","title"]),XD={axis:{desc:"axis",caption:hne},legend:{desc:"legend",caption:pne},"title-text":{desc:"title",caption:e=>`Title text '${ZD(e)}'`},"title-subtitle":{desc:"subtitle",caption:e=>`Subtitle text '${ZD(e)}'`}},KD={ariaRole:A3,ariaRoleDescription:k3,description:E3};function cL(e,t){const n=t.aria===!1;if(e(aL,n||void 0),n||t.description==null)for(const r in KD)e(KD[r],void 0);else{const r=t.mark.marktype;e(E3,t.description),e(A3,t.ariaRole||(r==="group"?lL:S3)),e(k3,t.ariaRoleDescription||`${r} mark`)}}function fL(e){return e.aria===!1?{[aL]:!0}:cne[e.role]?null:XD[e.role]?dne(e,XD[e.role]):fne(e)}function fne(e){const t=e.marktype,n=t==="group"||t==="text"||e.items.some(r=>r.description!=null&&r.aria!==!1);return uL(n?lL:S3,`${t} mark container`,e.description)}function dne(e,t){try{const n=e.items[0],r=t.caption||(()=>"");return uL(t.role||S3,t.desc,n.description||r(n))}catch{return null}}function ZD(e){return je(e.text).join(" ")}function hne(e){const t=e.datum,n=e.orient,r=t.title?dL(e):null,i=e.context,s=i.scales[t.scale].value,o=i.dataflow.locale(),a=s.type;return`${n==="left"||n==="right"?"Y":"X"}-axis`+(r?` titled '${r}'`:"")+` for a ${zd(a)?"discrete":a} scale with ${k9(o,s,e)}`}function pne(e){const t=e.datum,n=t.title?dL(e):null,r=`${t.type||""} legend`.trim(),i=t.scales,s=Object.keys(i),o=e.context,a=o.scales[i[s[0]]].value,l=o.dataflow.locale();return mne(r)+(n?` titled '${n}'`:"")+` for ${gne(s)} with ${k9(l,a,e)}`}function dL(e){try{return je(jt(e.items).items[0].text).join(" ")}catch{return null}}function gne(e){return e=e.map(t=>t+(t==="fill"||t==="stroke"?" color":"")),e.length<2?e[0]:e.slice(0,-1).join(", ")+" and "+jt(e)}function mne(e){return e.length?e[0].toUpperCase()+e.slice(1):e}const hL=e=>(e+"").replace(/&/g,"&").replace(//g,">"),vne=e=>hL(e).replace(/"/g,""").replace(/\t/g," ").replace(/\n/g," ").replace(/\r/g," ");function C3(){let e="",t="",n="";const r=[],i=()=>t=n="",s=l=>{t&&(e+=`${t}>${n}`,i()),r.push(l)},o=(l,u)=>(u!=null&&(t+=` ${l}="${vne(u)}"`),a),a={open(l){s(l),t="<"+l;for(var u=arguments.length,c=new Array(u>1?u-1:0),f=1;f${n}`:"/>"):e+=``,i(),a},attr:o,text:l=>(n+=hL(l),a),toString:()=>e};return a}const pL=e=>gL(C3(),e)+"";function gL(e,t){if(e.open(t.tagName),t.hasAttributes()){const n=t.attributes,r=n.length;for(let i=0;i{c.dirty=n})),!i.zdirty){if(r.exit){o.nested&&i.items.length?(u=i.items[0],u._svg&&this._update(o,u._svg,u)):r._svg&&(u=r._svg.parentNode,u&&u.removeChild(r._svg)),r._svg=null;continue}r=o.nested?i.items[0]:r,r._update!==n&&(!r._svg||!r._svg.ownerSVGElement?(this._dirtyAll=!1,QD(r,n)):this._update(o,r._svg,r),r._update=n)}return!this._dirtyAll}mark(t,n,r,i){if(!this.isDirty(n))return n._svg;const s=this._svg,o=n.marktype,a=ps[o],l=n.interactive===!1?"none":null,u=a.tag==="g",c=e4(n,t,r,"g",s);if(o!=="group"&&i!=null&&!i.includes(o))return Es(c,0),n._svg;c.setAttribute("class",Q9(n));const f=fL(n);for(const g in f)li(c,g,f[g]);u||li(c,"pointer-events",l),li(c,"clip-path",n.clip?s3(this,n,n.group):null);let d=null,h=0;const p=g=>{const m=this.isDirty(g),v=e4(g,c,d,a.tag,s);m&&(this._update(a,v,g),u&&xne(this,v,g,i)),d=v,++h};return a.nested?n.items.length&&p(n.items[0]):yo(n,p),Es(c,h),c}_update(t,n,r){Xa=n,qr=n.__values__,cL(Xp,r),t.attr(Xp,r,this);const i=wne[t.type];i&&i.call(this,t,n,r),Xa&&this.style(Xa,r)}style(t,n){if(n!=null){for(const r in mv){let i=r==="font"?_0(n):n[r];if(i===qr[r])continue;const s=mv[r];i==null?t.removeAttribute(s):(n3(i)&&(i=C9(i,this._defs.gradient,vL())),t.setAttribute(s,i+"")),qr[r]=i}for(const r in vv)g1(t,vv[r],n[r])}}defs(){const t=this._svg,n=this._defs;let r=n.el,i=0;for(const s in n.gradient)r||(n.el=r=Kn(t,tp+1,"defs",Xn)),i=yne(r,n.gradient[s],i);for(const s in n.clipping)r||(n.el=r=Kn(t,tp+1,"defs",Xn)),i=bne(r,n.clipping[s],i);r&&(i===0?(t.removeChild(r),n.el=null):Es(r,i))}_clearDefs(){const t=this._defs;t.gradient={},t.clipping={}}}function QD(e,t){for(;e&&e.dirty!==t;e=e.mark.group)if(e.dirty=t,e.mark&&e.mark.dirty!==t)e.mark.dirty=t;else return}function yne(e,t,n){let r,i,s;if(t.gradient==="radial"){let o=Kn(e,n++,"pattern",Xn);jl(o,{id:sv+t.id,viewBox:"0,0,1,1",width:"100%",height:"100%",preserveAspectRatio:"xMidYMid slice"}),o=Kn(o,0,"rect",Xn),jl(o,{width:1,height:1,fill:`url(${vL()}#${t.id})`}),e=Kn(e,n++,"radialGradient",Xn),jl(e,{id:t.id,fx:t.x1,fy:t.y1,fr:t.r1,cx:t.x2,cy:t.y2,r:t.r2})}else e=Kn(e,n++,"linearGradient",Xn),jl(e,{id:t.id,x1:t.x1,x2:t.x2,y1:t.y1,y2:t.y2});for(r=0,i=t.stops.length;r{i=e.mark(t,o,i,r),++s}),Es(t,1+s)}function e4(e,t,n,r,i){let s=e._svg,o;if(!s&&(o=t.ownerDocument,s=zl(o,r,Xn),e._svg=s,e.mark&&(s.__data__=e,s.__values__={fill:"default"},r==="g"))){const a=zl(o,"path",Xn);s.appendChild(a),a.__data__=e;const l=zl(o,"g",Xn);s.appendChild(l),l.__data__=e;const u=zl(o,"path",Xn);s.appendChild(u),u.__data__=e,u.__values__={fill:"default"}}return(s.ownerSVGElement!==i||_ne(s,n))&&t.insertBefore(s,n?n.nextSibling:t.firstChild),s}function _ne(e,t){return e.parentNode&&e.parentNode.childNodes.length>1&&e.previousSibling!=t}let Xa=null,qr=null;const wne={group(e,t,n){const r=Xa=t.childNodes[2];qr=r.__values__,e.foreground(Xp,n,this),qr=t.__values__,Xa=t.childNodes[1],e.content(Xp,n,this);const i=Xa=t.childNodes[0];e.background(Xp,n,this);const s=n.mark.interactive===!1?"none":null;if(s!==qr.events&&(li(r,"pointer-events",s),li(i,"pointer-events",s),qr.events=s),n.strokeForeground&&n.stroke){const o=n.fill;li(r,"display",null),this.style(i,n),li(i,"stroke",null),o&&(n.fill=null),qr=r.__values__,this.style(r,n),o&&(n.fill=o),Xa=null}else li(r,"display","none")},image(e,t,n){n.smooth===!1?(g1(t,"image-rendering","optimizeSpeed"),g1(t,"image-rendering","pixelated")):g1(t,"image-rendering",null)},text(e,t,n){const r=x0(n);let i,s,o,a;fe(r)?(s=r.map(l=>fu(n,l)),i=s.join(` +`),i!==qr.text&&(Es(t,0),o=t.ownerDocument,a=cu(n),s.forEach((l,u)=>{const c=zl(o,"tspan",Xn);c.__data__=n,c.textContent=l,u&&(c.setAttribute("x",0),c.setAttribute("dy",a)),t.appendChild(c)}),qr.text=i)):(s=fu(n,r),s!==qr.text&&(t.textContent=s,qr.text=s)),li(t,"font-family",_0(n)),li(t,"font-size",xa(n)+"px"),li(t,"font-style",n.fontStyle),li(t,"font-variant",n.fontVariant),li(t,"font-weight",n.fontWeight)}};function Xp(e,t,n){t!==qr[e]&&(n?Ene(Xa,e,t,n):li(Xa,e,t),qr[e]=t)}function g1(e,t,n){n!==qr[t]&&(n==null?e.style.removeProperty(t):e.style.setProperty(t,n+""),qr[t]=n)}function jl(e,t){for(const n in t)li(e,n,t[n])}function li(e,t,n){n!=null?e.setAttribute(t,n):e.removeAttribute(t)}function Ene(e,t,n,r){n!=null?e.setAttributeNS(r,t,n):e.removeAttributeNS(r,t)}function vL(){let e;return typeof window>"u"?"":(e=window.location).hash?e.href.slice(0,-e.hash.length):e.href}class yL extends w0{constructor(t){super(t),this._text=null,this._defs={gradient:{},clipping:{}}}svg(){return this._text}_render(t){const n=C3();n.open("svg",kt({},_g,{class:"marks",width:this._width*this._scale,height:this._height*this._scale,viewBox:`0 0 ${this._width} ${this._height}`}));const r=this._bgcolor;return r&&r!=="transparent"&&r!=="none"&&n.open("rect",{width:this._width,height:this._height,fill:r}).close(),n.open("g",mL,{transform:"translate("+this._origin+")"}),this.mark(n,t),n.close(),this.defs(n),this._text=n.close()+"",this}mark(t,n){const r=ps[n.marktype],i=r.tag,s=[cL,r.attr];t.open("g",{class:Q9(n),"clip-path":n.clip?s3(this,n,n.group):null},fL(n),{"pointer-events":i!=="g"&&n.interactive===!1?"none":null});const o=a=>{const l=this.href(a);if(l&&t.open("a",l),t.open(i,this.attr(n,a,s,i!=="g"?i:null)),i==="text"){const u=x0(a);if(fe(u)){const c={x:0,dy:cu(a)};for(let f=0;fthis.mark(t,d)),t.close(),u&&f?(c&&(a.fill=null),a.stroke=f,t.open("path",this.attr(n,a,r.foreground,"bgrect")).close(),c&&(a.fill=c)):t.open("path",this.attr(n,a,r.foreground,"bgfore")).close()}t.close(),l&&t.close()};return r.nested?n.items&&n.items.length&&o(n.items[0]):yo(n,o),t.close()}href(t){const n=t.href;let r;if(n){if(r=this._hrefs&&this._hrefs[n])return r;this.sanitizeURL(n).then(i=>{i["xlink:href"]=i.href,i.href=null,(this._hrefs||(this._hrefs={}))[n]=i})}return null}attr(t,n,r,i){const s={},o=(a,l,u,c)=>{s[c||a]=l};return Array.isArray(r)?r.forEach(a=>a(o,n,this)):r(o,n,this),i&&Ane(s,n,t,i,this._defs),s}defs(t){const n=this._defs.gradient,r=this._defs.clipping;if(Object.keys(n).length+Object.keys(r).length!==0){t.open("defs");for(const s in n){const o=n[s],a=o.stops;o.gradient==="radial"?(t.open("pattern",{id:sv+s,viewBox:"0,0,1,1",width:"100%",height:"100%",preserveAspectRatio:"xMidYMid slice"}),t.open("rect",{width:"1",height:"1",fill:"url(#"+s+")"}).close(),t.close(),t.open("radialGradient",{id:s,fx:o.x1,fy:o.y1,fr:o.r1,cx:o.x2,cy:o.y2,r:o.r2})):t.open("linearGradient",{id:s,x1:o.x1,x2:o.x2,y1:o.y1,y2:o.y2});for(let l=0;l!eo.svgMarkTypes.includes(s));this._svgRenderer.render(t,eo.svgMarkTypes),this._canvasRenderer.render(t,i)}resize(t,n,r,i){return super.resize(t,n,r,i),this._svgRenderer.resize(t,n,r,i),this._canvasRenderer.resize(t,n,r,i),this}background(t){return eo.svgOnTop?this._canvasRenderer.background(t):this._svgRenderer.background(t),this}}class bL extends E0{constructor(t,n){super(t,n)}initialize(t,n,r){const i=Kn(Kn(t,0,"div"),eo.svgOnTop?0:1,"div");return super.initialize(i,n,r)}}const xL="canvas",_L="hybrid",wL="png",EL="svg",AL="none",Ul={Canvas:xL,PNG:wL,SVG:EL,Hybrid:_L,None:AL},Wc={};Wc[xL]=Wc[wL]={renderer:gv,headless:gv,handler:E0};Wc[EL]={renderer:$3,headless:yL,handler:oL};Wc[_L]={renderer:eE,headless:eE,handler:bL};Wc[AL]={};function yb(e,t){return e=String(e||"").toLowerCase(),arguments.length>1?(Wc[e]=t,this):Wc[e]}function kL(e,t,n){const r=[],i=new Hn().union(t),s=e.marktype;return s?SL(e,i,n,r):s==="group"?CL(e,i,n,r):ae("Intersect scene must be mark node or group item.")}function SL(e,t,n,r){if(Sne(e,t,n)){const i=e.items,s=e.marktype,o=i.length;let a=0;if(s==="group")for(;a=0;s--)if(n[s]!=r[s])return!1;for(s=n.length-1;s>=0;s--)if(i=n[s],!F3(e[i],t[i],i))return!1;return typeof e==typeof t}function Fne(){N9(),QQ()}const Wd="top",so="left",ao="right",du="bottom",Dne="top-left",Mne="top-right",Tne="bottom-left",Rne="bottom-right",D3="start",tE="middle",ui="end",Nne="x",One="y",bb="group",M3="axis",T3="title",Lne="frame",Ine="scope",R3="legend",ML="row-header",TL="row-footer",RL="row-title",NL="column-header",OL="column-footer",LL="column-title",Pne="padding",Bne="symbol",IL="fit",PL="fit-x",BL="fit-y",zne="pad",N3="none",pm="all",nE="each",O3="flush",ql="column",Wl="row";function zL(e){ne.call(this,null,e)}Te(zL,ne,{transform(e,t){const n=t.dataflow,r=e.mark,i=r.marktype,s=ps[i],o=s.bound;let a=r.bounds,l;if(s.nested)r.items.length&&n.dirty(r.items[0]),a=gm(r,o),r.items.forEach(u=>{u.bounds.clear().union(a)});else if(i===bb||e.modified())switch(t.visit(t.MOD,u=>n.dirty(u)),a.clear(),r.items.forEach(u=>a.union(gm(u,o))),r.role){case M3:case R3:case T3:t.reflow()}else l=t.changed(t.REM),t.visit(t.ADD,u=>{a.union(gm(u,o))}),t.visit(t.MOD,u=>{l=l||a.alignsWith(u.bounds),n.dirty(u),a.union(gm(u,o))}),l&&(a.clear(),r.items.forEach(u=>a.union(u.bounds)));return FL(r),t.modifies("bounds")}});function gm(e,t,n){return t(e.bounds.clear(),e,n)}const t4=":vega_identifier:";function L3(e){ne.call(this,0,e)}L3.Definition={type:"Identifier",metadata:{modifies:!0},params:[{name:"as",type:"string",required:!0}]};Te(L3,ne,{transform(e,t){const n=jne(t.dataflow),r=e.as;let i=n.value;return t.visit(t.ADD,s=>s[r]=s[r]||++i),n.set(this.value=i),t}});function jne(e){return e._signals[t4]||(e._signals[t4]=e.add(0))}function jL(e){ne.call(this,null,e)}Te(jL,ne,{transform(e,t){let n=this.value;n||(n=t.dataflow.scenegraph().mark(e.markdef,Une(e),e.index),n.group.context=e.context,e.context.group||(e.context.group=n.group),n.source=this.source,n.clip=e.clip,n.interactive=e.interactive,this.value=n);const r=n.marktype===bb?cb:ub;return t.visit(t.ADD,i=>r.call(i,n)),(e.modified("clip")||e.modified("interactive"))&&(n.clip=e.clip,n.interactive=!!e.interactive,n.zdirty=!0,t.reflow()),n.items=t.source,t}});function Une(e){const t=e.groups,n=e.parent;return t&&t.size===1?t.get(Object.keys(t.object)[0]):t&&n?t.lookup(n):null}function UL(e){ne.call(this,null,e)}const n4={parity:e=>e.filter((t,n)=>n%2?t.opacity=0:1),greedy:(e,t)=>{let n;return e.filter((r,i)=>!i||!qL(n.bounds,r.bounds,t)?(n=r,1):r.opacity=0)}},qL=(e,t,n)=>n>Math.max(t.x1-e.x2,e.x1-t.x2,t.y1-e.y2,e.y1-t.y2),r4=(e,t)=>{for(var n=1,r=e.length,i=e[0].bounds,s;n{const t=e.bounds;return t.width()>1&&t.height()>1},Wne=(e,t,n)=>{var r=e.range(),i=new Hn;return t===Wd||t===du?i.set(r[0],-1/0,r[1],1/0):i.set(-1/0,r[0],1/0,r[1]),i.expand(n||1),s=>i.encloses(s.bounds)},i4=e=>(e.forEach(t=>t.opacity=1),e),s4=(e,t)=>e.reflow(t.modified()).modifies("opacity");Te(UL,ne,{transform(e,t){const n=n4[e.method]||n4.parity,r=e.separation||0;let i=t.materialize(t.SOURCE).source,s,o;if(!i||!i.length)return;if(!e.method)return e.modified("method")&&(i4(i),t=s4(t,e)),t;if(i=i.filter(qne),!i.length)return;if(e.sort&&(i=i.slice().sort(e.sort)),s=i4(i),t=s4(t,e),s.length>=3&&r4(s,r)){do s=n(s,r);while(s.length>=3&&r4(s,r));s.length<3&&!jt(i).opacity&&(s.length>1&&(jt(s).opacity=0),jt(i).opacity=1)}e.boundScale&&e.boundTolerance>=0&&(o=Wne(e.boundScale,e.boundOrient,+e.boundTolerance),i.forEach(l=>{o(l)||(l.opacity=0)}));const a=s[0].mark.bounds.clear();return i.forEach(l=>{l.opacity&&a.union(l.bounds)}),t}});function WL(e){ne.call(this,null,e)}Te(WL,ne,{transform(e,t){const n=t.dataflow;if(t.visit(t.ALL,r=>n.dirty(r)),t.fields&&t.fields.zindex){const r=t.source&&t.source[0];r&&(r.mark.zdirty=!0)}}});const Ur=new Hn;function Qf(e,t,n){return e[t]===n?0:(e[t]=n,1)}function Hne(e){var t=e.items[0].orient;return t===so||t===ao}function Gne(e){let t=+e.grid;return[e.ticks?t++:-1,e.labels?t++:-1,t+ +e.domain]}function Yne(e,t,n,r){var i=t.items[0],s=i.datum,o=i.translate!=null?i.translate:.5,a=i.orient,l=Gne(s),u=i.range,c=i.offset,f=i.position,d=i.minExtent,h=i.maxExtent,p=s.title&&i.items[l[2]].items[0],g=i.titlePadding,m=i.bounds,v=p&&y3(p),b=0,x=0,_,w;switch(Ur.clear().union(m),m.clear(),(_=l[0])>-1&&m.union(i.items[_].bounds),(_=l[1])>-1&&m.union(i.items[_].bounds),a){case Wd:b=f||0,x=-c,w=Math.max(d,Math.min(h,-m.y1)),m.add(0,-w).add(u,0),p&&mm(e,p,w,g,v,0,-1,m);break;case so:b=-c,x=f||0,w=Math.max(d,Math.min(h,-m.x1)),m.add(-w,0).add(0,u),p&&mm(e,p,w,g,v,1,-1,m);break;case ao:b=n+c,x=f||0,w=Math.max(d,Math.min(h,m.x2)),m.add(0,0).add(w,u),p&&mm(e,p,w,g,v,1,1,m);break;case du:b=f||0,x=r+c,w=Math.max(d,Math.min(h,m.y2)),m.add(0,0).add(u,w),p&&mm(e,p,w,g,0,0,1,m);break;default:b=i.x,x=i.y}return gl(m.translate(b,x),i),Qf(i,"x",b+o)|Qf(i,"y",x+o)&&(i.bounds=Ur,e.dirty(i),i.bounds=m,e.dirty(i)),i.mark.bounds.clear().union(m)}function mm(e,t,n,r,i,s,o,a){const l=t.bounds;if(t.auto){const u=o*(n+i+r);let c=0,f=0;e.dirty(t),s?c=(t.x||0)-(t.x=u):f=(t.y||0)-(t.y=u),t.mark.bounds.clear().union(l.translate(-c,-f)),e.dirty(t)}a.union(l)}const o4=(e,t)=>Math.floor(Math.min(e,t)),a4=(e,t)=>Math.ceil(Math.max(e,t));function Vne(e){var t=e.items,n=t.length,r=0,i,s;const o={marks:[],rowheaders:[],rowfooters:[],colheaders:[],colfooters:[],rowtitle:null,coltitle:null};for(;r1)for(E=0;E0&&(x[E]+=T/2);if(a&&xn(n.center,Wl)&&c!==1)for(E=0;E0&&(_[E]+=F/2);for(E=0;Ei&&(e.warn("Grid headers exceed limit: "+i),t=t.slice(0,i)),g+=s,b=0,_=t.length;b<_;++b)e.dirty(t[b]),t[b].mark.bounds.clear();for(v=c,b=0,_=t.length;b<_;++b,v+=f){for(A=t[b],w=A.mark.bounds,x=v;x>=0&&(E=n[x])==null;x-=d);a?(k=h==null?E.x:Math.round(E.bounds.x1+h*E.bounds.width()),S=g):(k=g,S=h==null?E.y:Math.round(E.bounds.y1+h*E.bounds.height())),w.union(A.bounds.translate(k-(A.x||0),S-(A.y||0))),A.x=k,A.y=S,e.dirty(A),m=o(m,w[u])}return m}function u4(e,t,n,r,i,s){if(t){e.dirty(t);var o=n,a=n;r?o=Math.round(i.x1+s*i.width()):a=Math.round(i.y1+s*i.height()),t.bounds.translate(o-(t.x||0),a-(t.y||0)),t.mark.bounds.clear().union(t.bounds),t.x=o,t.y=a,e.dirty(t)}}function ere(e,t){const n=e[t]||{};return(r,i)=>n[r]!=null?n[r]:e[r]!=null?e[r]:i}function tre(e,t){let n=-1/0;return e.forEach(r=>{r.offset!=null&&(n=Math.max(n,r.offset))}),n>-1/0?n:t}function nre(e,t,n,r,i,s,o){const a=ere(n,t),l=tre(e,a("offset",0)),u=a("anchor",D3),c=u===ui?1:u===tE?.5:0,f={align:nE,bounds:a("bounds",O3),columns:a("direction")==="vertical"?1:e.length,padding:a("margin",8),center:a("center"),nodirty:!0};switch(t){case so:f.anchor={x:Math.floor(r.x1)-l,column:ui,y:c*(o||r.height()+2*r.y1),row:u};break;case ao:f.anchor={x:Math.ceil(r.x2)+l,y:c*(o||r.height()+2*r.y1),row:u};break;case Wd:f.anchor={y:Math.floor(i.y1)-l,row:ui,x:c*(s||i.width()+2*i.x1),column:u};break;case du:f.anchor={y:Math.ceil(i.y2)+l,x:c*(s||i.width()+2*i.x1),column:u};break;case Dne:f.anchor={x:l,y:l};break;case Mne:f.anchor={x:s-l,y:l,column:ui};break;case Tne:f.anchor={x:l,y:o-l,row:ui};break;case Rne:f.anchor={x:s-l,y:o-l,column:ui,row:ui};break}return f}function rre(e,t){var n=t.items[0],r=n.datum,i=n.orient,s=n.bounds,o=n.x,a=n.y,l,u;return n._bounds?n._bounds.clear().union(s):n._bounds=s.clone(),s.clear(),sre(e,n,n.items[0].items[0]),s=ire(n,s),l=2*n.padding,u=2*n.padding,s.empty()||(l=Math.ceil(s.width()+l),u=Math.ceil(s.height()+u)),r.type===Bne&&ore(n.items[0].items[0].items[0].items),i!==N3&&(n.x=o=0,n.y=a=0),n.width=l,n.height=u,gl(s.set(o,a,o+l,a+u),n),n.mark.bounds.clear().union(s),n}function ire(e,t){return e.items.forEach(n=>t.union(n.bounds)),t.x1=e.padding,t.y1=e.padding,t}function sre(e,t,n){var r=t.padding,i=r-n.x,s=r-n.y;if(!t.datum.title)(i||s)&&np(e,n,i,s);else{var o=t.items[1].items[0],a=o.anchor,l=t.titlePadding||0,u=r-o.x,c=r-o.y;switch(o.orient){case so:i+=Math.ceil(o.bounds.width())+l;break;case ao:case du:break;default:s+=o.bounds.height()+l}switch((i||s)&&np(e,n,i,s),o.orient){case so:c+=Of(t,n,o,a,1,1);break;case ao:u+=Of(t,n,o,ui,0,0)+l,c+=Of(t,n,o,a,1,1);break;case du:u+=Of(t,n,o,a,0,0),c+=Of(t,n,o,ui,-1,0,1)+l;break;default:u+=Of(t,n,o,a,0,0)}(u||c)&&np(e,o,u,c),(u=Math.round(o.bounds.x1-r))<0&&(np(e,n,-u,0),np(e,o,-u,0))}}function Of(e,t,n,r,i,s,o){const a=e.datum.type!=="symbol",l=n.datum.vgrad,u=a&&(s||!l)&&!o?t.items[0]:t,c=u.bounds[i?"y2":"x2"]-e.padding,f=l&&s?c:0,d=l&&s?0:c,h=i<=0?0:y3(n);return Math.round(r===D3?f:r===ui?d-h:.5*(c-h))}function np(e,t,n,r){t.x+=n,t.y+=r,t.bounds.translate(n,r),t.mark.bounds.translate(n,r),e.dirty(t)}function ore(e){const t=e.reduce((n,r)=>(n[r.column]=Math.max(r.bounds.x2-r.x,n[r.column]||0),n),{});e.forEach(n=>{n.width=t[n.column],n.height=n.bounds.y2-n.y})}function are(e,t,n,r,i){var s=t.items[0],o=s.frame,a=s.orient,l=s.anchor,u=s.offset,c=s.padding,f=s.items[0].items[0],d=s.items[1]&&s.items[1].items[0],h=a===so||a===ao?r:n,p=0,g=0,m=0,v=0,b=0,x;if(o!==bb?a===so?(p=i.y2,h=i.y1):a===ao?(p=i.y1,h=i.y2):(p=i.x1,h=i.x2):a===so&&(p=r,h=0),x=l===D3?p:l===ui?h:(p+h)/2,d&&d.text){switch(a){case Wd:case du:b=f.bounds.height()+c;break;case so:v=f.bounds.width()+c;break;case ao:v=-f.bounds.width()-c;break}Ur.clear().union(d.bounds),Ur.translate(v-(d.x||0),b-(d.y||0)),Qf(d,"x",v)|Qf(d,"y",b)&&(e.dirty(d),d.bounds.clear().union(Ur),d.mark.bounds.clear().union(Ur),e.dirty(d)),Ur.clear().union(d.bounds)}else Ur.clear();switch(Ur.union(f.bounds),a){case Wd:g=x,m=i.y1-Ur.height()-u;break;case so:g=i.x1-Ur.width()-u,m=x;break;case ao:g=i.x2+Ur.width()+u,m=x;break;case du:g=x,m=i.y2+u;break;default:g=s.x,m=s.y}return Qf(s,"x",g)|Qf(s,"y",m)&&(Ur.translate(g,m),e.dirty(s),s.bounds.clear().union(Ur),t.bounds.clear().union(Ur),e.dirty(s)),s.bounds}function GL(e){ne.call(this,null,e)}Te(GL,ne,{transform(e,t){const n=t.dataflow;return e.mark.items.forEach(r=>{e.layout&&Zne(n,r,e.layout),ure(n,r,e)}),lre(e.mark.group)?t.reflow():t}});function lre(e){return e&&e.mark.role!=="legend-entry"}function ure(e,t,n){var r=t.items,i=Math.max(0,t.width||0),s=Math.max(0,t.height||0),o=new Hn().set(0,0,i,s),a=o.clone(),l=o.clone(),u=[],c,f,d,h,p,g;for(p=0,g=r.length;p{d=v.orient||ao,d!==N3&&(m[d]||(m[d]=[])).push(v)});for(const v in m){const b=m[v];HL(e,b,nre(b,v,n.legends,a,l,i,s))}u.forEach(v=>{const b=v.bounds;if(b.equals(v._bounds)||(v.bounds=v._bounds,e.dirty(v),v.bounds=b,e.dirty(v)),n.autosize&&(n.autosize.type===IL||n.autosize.type===PL||n.autosize.type===BL))switch(v.orient){case so:case ao:o.add(b.x1,0).add(b.x2,0);break;case Wd:case du:o.add(0,b.y1).add(0,b.y2)}else o.union(b)})}o.union(a).union(l),c&&o.union(are(e,c,i,s,o)),t.clip&&o.set(0,0,t.width||0,t.height||0),cre(e,t,o,n)}function cre(e,t,n,r){const i=r.autosize||{},s=i.type;if(e._autosize<1||!s)return;let o=e._width,a=e._height,l=Math.max(0,t.width||0),u=Math.max(0,Math.ceil(-n.x1)),c=Math.max(0,t.height||0),f=Math.max(0,Math.ceil(-n.y1));const d=Math.max(0,Math.ceil(n.x2-l)),h=Math.max(0,Math.ceil(n.y2-c));if(i.contains===Pne){const p=e.padding();o-=p.left+p.right,a-=p.top+p.bottom}s===N3?(u=0,f=0,l=o,c=a):s===IL?(l=Math.max(0,o-u-d),c=Math.max(0,a-f-h)):s===PL?(l=Math.max(0,o-u-d),a=c+f+h):s===BL?(o=l+u+d,c=Math.max(0,a-f-h)):s===zne&&(o=l+u+d,a=c+f+h),e._resizeView(o,a,l,c,[u,f],i.resize)}const fre=Object.freeze(Object.defineProperty({__proto__:null,bound:zL,identifier:L3,mark:jL,overlap:UL,render:WL,viewlayout:GL},Symbol.toStringTag,{value:"Module"}));function YL(e){ne.call(this,null,e)}Te(YL,ne,{transform(e,t){if(this.value&&!e.modified())return t.StopPropagation;var n=t.dataflow.locale(),r=t.fork(t.NO_SOURCE|t.NO_FIELDS),i=this.value,s=e.scale,o=e.count==null?e.values?e.values.length:10:e.count,a=e3(s,o,e.minstep),l=e.format||x9(n,s,a,e.formatSpecifier,e.formatType,!!e.values),u=e.values?b9(s,e.values,a):t3(s,a);return i&&(r.rem=i),i=u.map((c,f)=>Kt({index:f/(u.length-1||1),value:c,label:l(c)})),e.extra&&i.length&&i.push(Kt({index:-1,extra:{value:i[0].value},label:""})),r.source=i,r.add=i,this.value=i,r}});function VL(e){ne.call(this,null,e)}function dre(){return Kt({})}function hre(e){const t=yh().test(n=>n.exit);return t.lookup=n=>t.get(e(n)),t}Te(VL,ne,{transform(e,t){var n=t.dataflow,r=t.fork(t.NO_SOURCE|t.NO_FIELDS),i=e.item||dre,s=e.key||it,o=this.value;return fe(r.encode)&&(r.encode=null),o&&(e.modified("key")||t.modified(s))&&ae("DataJoin does not support modified key function or fields."),o||(t=t.addAll(),this.value=o=hre(s)),t.visit(t.ADD,a=>{const l=s(a);let u=o.get(l);u?u.exit?(o.empty--,r.add.push(u)):r.mod.push(u):(u=i(a),o.set(l,u),r.add.push(u)),u.datum=a,u.exit=!1}),t.visit(t.MOD,a=>{const l=s(a),u=o.get(l);u&&(u.datum=a,r.mod.push(u))}),t.visit(t.REM,a=>{const l=s(a),u=o.get(l);a===u.datum&&!u.exit&&(r.rem.push(u),u.exit=!0,++o.empty)}),t.changed(t.ADD_MOD)&&r.modifies("datum"),(t.clean()||e.clean&&o.empty>n.cleanThreshold)&&n.runAfter(o.clean),r}});function XL(e){ne.call(this,null,e)}Te(XL,ne,{transform(e,t){var n=t.fork(t.ADD_REM),r=e.mod||!1,i=e.encoders,s=t.encode;if(fe(s))if(n.changed()||s.every(f=>i[f]))s=s[0],n.encode=null;else return t.StopPropagation;var o=s==="enter",a=i.update||Cl,l=i.enter||Cl,u=i.exit||Cl,c=(s&&!o?i[s]:a)||Cl;if(t.changed(t.ADD)&&(t.visit(t.ADD,f=>{l(f,e),a(f,e)}),n.modifies(l.output),n.modifies(a.output),c!==Cl&&c!==a&&(t.visit(t.ADD,f=>{c(f,e)}),n.modifies(c.output))),t.changed(t.REM)&&u!==Cl&&(t.visit(t.REM,f=>{u(f,e)}),n.modifies(u.output)),o||c!==Cl){const f=t.MOD|(e.modified()?t.REFLOW:0);o?(t.visit(f,d=>{const h=l(d,e)||r;(c(d,e)||h)&&n.mod.push(d)}),n.mod.length&&n.modifies(l.output)):t.visit(f,d=>{(c(d,e)||r)&&n.mod.push(d)}),n.mod.length&&n.modifies(c.output)}return n.changed()?n:t.StopPropagation}});function KL(e){ne.call(this,[],e)}Te(KL,ne,{transform(e,t){if(this.value!=null&&!e.modified())return t.StopPropagation;var n=t.dataflow.locale(),r=t.fork(t.NO_SOURCE|t.NO_FIELDS),i=this.value,s=e.type||a1,o=e.scale,a=+e.limit,l=e3(o,e.count==null?5:e.count,e.minstep),u=!!e.values||s===a1,c=e.format||A9(n,o,l,s,e.formatSpecifier,e.formatType,u),f=e.values||E9(o,l),d,h,p,g,m;return i&&(r.rem=i),s===a1?(a&&f.length>a?(t.dataflow.warn("Symbol legend count exceeds limit, filtering items."),i=f.slice(0,a-1),m=!0):i=f,St(p=e.size)?(!e.values&&o(i[0])===0&&(i=i.slice(1)),g=i.reduce((v,b)=>Math.max(v,p(b,e)),0)):p=ei(g=p||8),i=i.map((v,b)=>Kt({index:b,label:c(v,b,i),value:v,offset:g,size:p(v,e)})),m&&(m=f[i.length],i.push(Kt({index:i.length,label:`…${f.length-i.length} entries`,value:m,offset:g,size:p(m,e)})))):s===zQ?(d=o.domain(),h=m9(o,d[0],jt(d)),f.length<3&&!e.values&&d[0]!==jt(d)&&(f=[d[0],jt(d)]),i=f.map((v,b)=>Kt({index:b,label:c(v,b,f),value:v,perc:h(v)}))):(p=f.length-1,h=ZQ(o),i=f.map((v,b)=>Kt({index:b,label:c(v,b,f),value:v,perc:b?h(v):0,perc2:b===p?1:h(f[b+1])}))),r.source=i,r.add=i,this.value=i,r}});const pre=e=>e.source.x,gre=e=>e.source.y,mre=e=>e.target.x,vre=e=>e.target.y;function I3(e){ne.call(this,{},e)}I3.Definition={type:"LinkPath",metadata:{modifies:!0},params:[{name:"sourceX",type:"field",default:"source.x"},{name:"sourceY",type:"field",default:"source.y"},{name:"targetX",type:"field",default:"target.x"},{name:"targetY",type:"field",default:"target.y"},{name:"orient",type:"enum",default:"vertical",values:["horizontal","vertical","radial"]},{name:"shape",type:"enum",default:"line",values:["line","arc","curve","diagonal","orthogonal"]},{name:"require",type:"signal"},{name:"as",type:"string",default:"path"}]};Te(I3,ne,{transform(e,t){var n=e.sourceX||pre,r=e.sourceY||gre,i=e.targetX||mre,s=e.targetY||vre,o=e.as||"path",a=e.orient||"vertical",l=e.shape||"line",u=c4.get(l+"-"+a)||c4.get(l);return u||ae("LinkPath unsupported type: "+e.shape+(e.orient?"-"+e.orient:"")),t.visit(t.SOURCE,c=>{c[o]=u(n(c),r(c),i(c),s(c))}),t.reflow(e.modified()).modifies(o)}});const ZL=(e,t,n,r)=>"M"+e+","+t+"L"+n+","+r,yre=(e,t,n,r)=>ZL(t*Math.cos(e),t*Math.sin(e),r*Math.cos(n),r*Math.sin(n)),JL=(e,t,n,r)=>{var i=n-e,s=r-t,o=Math.hypot(i,s)/2,a=180*Math.atan2(s,i)/Math.PI;return"M"+e+","+t+"A"+o+","+o+" "+a+" 0 1 "+n+","+r},bre=(e,t,n,r)=>JL(t*Math.cos(e),t*Math.sin(e),r*Math.cos(n),r*Math.sin(n)),QL=(e,t,n,r)=>{const i=n-e,s=r-t,o=.2*(i+s),a=.2*(s-i);return"M"+e+","+t+"C"+(e+o)+","+(t+a)+" "+(n+a)+","+(r-o)+" "+n+","+r},xre=(e,t,n,r)=>QL(t*Math.cos(e),t*Math.sin(e),r*Math.cos(n),r*Math.sin(n)),_re=(e,t,n,r)=>"M"+e+","+t+"V"+r+"H"+n,wre=(e,t,n,r)=>"M"+e+","+t+"H"+n+"V"+r,Ere=(e,t,n,r)=>{const i=Math.cos(e),s=Math.sin(e),o=Math.cos(n),a=Math.sin(n),l=Math.abs(n-e)>Math.PI?n<=e:n>e;return"M"+t*i+","+t*s+"A"+t+","+t+" 0 0,"+(l?1:0)+" "+t*o+","+t*a+"L"+r*o+","+r*a},Are=(e,t,n,r)=>{const i=(e+n)/2;return"M"+e+","+t+"C"+i+","+t+" "+i+","+r+" "+n+","+r},kre=(e,t,n,r)=>{const i=(t+r)/2;return"M"+e+","+t+"C"+e+","+i+" "+n+","+i+" "+n+","+r},Sre=(e,t,n,r)=>{const i=Math.cos(e),s=Math.sin(e),o=Math.cos(n),a=Math.sin(n),l=(t+r)/2;return"M"+t*i+","+t*s+"C"+l*i+","+l*s+" "+l*o+","+l*a+" "+r*o+","+r*a},c4=yh({line:ZL,"line-radial":yre,arc:JL,"arc-radial":bre,curve:QL,"curve-radial":xre,"orthogonal-horizontal":_re,"orthogonal-vertical":wre,"orthogonal-radial":Ere,"diagonal-horizontal":Are,"diagonal-vertical":kre,"diagonal-radial":Sre});function P3(e){ne.call(this,null,e)}P3.Definition={type:"Pie",metadata:{modifies:!0},params:[{name:"field",type:"field"},{name:"startAngle",type:"number",default:0},{name:"endAngle",type:"number",default:6.283185307179586},{name:"sort",type:"boolean",default:!1},{name:"as",type:"string",array:!0,length:2,default:["startAngle","endAngle"]}]};Te(P3,ne,{transform(e,t){var n=e.as||["startAngle","endAngle"],r=n[0],i=n[1],s=e.field||ph,o=e.startAngle||0,a=e.endAngle!=null?e.endAngle:2*Math.PI,l=t.source,u=l.map(s),c=u.length,f=o,d=(a-o)/pN(u),h=is(c),p,g,m;for(e.sort&&h.sort((v,b)=>u[v]-u[b]),p=0;p-1)return r;var i=t.domain,s=e.type,o=t.zero||t.zero===void 0&&$re(e),a,l;if(!i)return 0;if((o||t.domainMin!=null||t.domainMax!=null||t.domainMid!=null)&&(a=(i=i.slice()).length-1||1,o&&(i[0]>0&&(i[0]=0),i[a]<0&&(i[a]=0)),t.domainMin!=null&&(i[0]=t.domainMin),t.domainMax!=null&&(i[a]=t.domainMax),t.domainMid!=null)){l=t.domainMid;const u=l>i[a]?a+1:li+(s<0?-1:s>0?1:0),0));r!==t.length&&n.warn("Log scale domain includes zero: "+De(t))}return t}function Ore(e,t,n){let r=t.bins;if(r&&!fe(r)){const i=e.domain(),s=i[0],o=jt(i),a=r.step;let l=r.start==null?s:r.start,u=r.stop==null?o:r.stop;a||ae("Scale bins parameter missing step property."),lo&&(u=a*Math.floor(o/a)),r=is(l,u+a/2,a)}return r?e.bins=r:e.bins&&delete e.bins,e.type===VS&&(r?!t.domain&&!t.domainRaw&&(e.domain(r),n=r.length):e.bins=e.domain()),n}function Lre(e,t,n){var r=e.type,i=t.round||!1,s=t.range;if(t.rangeStep!=null)s=Ire(r,t,n);else if(t.scheme&&(s=Pre(r,t,n),St(s))){if(e.interpolator)return e.interpolator(s);ae(`Scale type ${r} does not support interpolating color schemes.`)}if(s&&d9(r))return e.interpolator(ab(rE(s,t.reverse),t.interpolate,t.interpolateGamma));s&&t.interpolate&&e.interpolate?e.interpolate(JS(t.interpolate,t.interpolateGamma)):St(e.round)?e.round(i):St(e.rangeRound)&&e.interpolate(i?u0:Su),s&&e.range(rE(s,t.reverse))}function Ire(e,t,n){e!==s9&&e!==Uw&&ae("Only band and point scales support rangeStep.");var r=(t.paddingOuter!=null?t.paddingOuter:t.padding)||0,i=e===Uw?1:(t.paddingInner!=null?t.paddingInner:t.padding)||0;return[0,t.rangeStep*GS(n,i,r)]}function Pre(e,t,n){var r=t.schemeExtent,i,s;return fe(t.scheme)?s=ab(t.scheme,t.interpolate,t.interpolateGamma):(i=t.scheme.toLowerCase(),s=QS(i),s||ae(`Unrecognized scheme name: ${t.scheme}`)),n=e===ob?n+1:e===VS?n-1:e===Bd||e===sb?+t.schemeCount||Cre:n,d9(e)?f4(s,r,t.reverse):St(s)?g9(f4(s,r),n):e===YS?s:s.slice(0,n)}function f4(e,t,n){return St(e)&&(t||n)?p9(e,rE(t||[0,1],n)):e}function rE(e,t){return t?e.slice().reverse():e}function rI(e){ne.call(this,null,e)}Te(rI,ne,{transform(e,t){const n=e.modified("sort")||t.changed(t.ADD)||t.modified(e.sort.fields)||t.modified("datum");return n&&t.source.sort(pf(e.sort)),this.modified(n),t}});const d4="zero",iI="center",sI="normalize",oI=["y0","y1"];function B3(e){ne.call(this,null,e)}B3.Definition={type:"Stack",metadata:{modifies:!0},params:[{name:"field",type:"field"},{name:"groupby",type:"field",array:!0},{name:"sort",type:"compare"},{name:"offset",type:"enum",default:d4,values:[d4,iI,sI]},{name:"as",type:"string",array:!0,length:2,default:oI}]};Te(B3,ne,{transform(e,t){var n=e.as||oI,r=n[0],i=n[1],s=pf(e.sort),o=e.field||ph,a=e.offset===iI?Bre:e.offset===sI?zre:jre,l,u,c,f;for(l=Ure(t.source,e.groupby,s,o),u=0,c=l.length,f=l.max;ug(c),o,a,l,u,c,f,d,h,p;if(t==null)i.push(e.slice());else for(o={},a=0,l=e.length;ap&&(p=h),n&&d.sort(n)}return i.max=p,i}const qre=Object.freeze(Object.defineProperty({__proto__:null,axisticks:YL,datajoin:VL,encode:XL,legendentries:KL,linkpath:I3,pie:P3,scale:tI,sortitems:rI,stack:B3},Symbol.toStringTag,{value:"Module"}));var at=1e-6,yv=1e-12,Mt=Math.PI,Rn=Mt/2,bv=Mt/4,yi=Mt*2,Pn=180/Mt,Ft=Mt/180,zt=Math.abs,$h=Math.atan,Ps=Math.atan2,ut=Math.cos,ym=Math.ceil,aI=Math.exp,iE=Math.hypot,xv=Math.log,Dx=Math.pow,st=Math.sin,Ss=Math.sign||function(e){return e>0?1:e<0?-1:0},bi=Math.sqrt,z3=Math.tan;function lI(e){return e>1?0:e<-1?Mt:Math.acos(e)}function Ui(e){return e>1?Rn:e<-1?-Rn:Math.asin(e)}function Cr(){}function _v(e,t){e&&p4.hasOwnProperty(e.type)&&p4[e.type](e,t)}var h4={Feature:function(e,t){_v(e.geometry,t)},FeatureCollection:function(e,t){for(var n=e.features,r=-1,i=n.length;++r=0?1:-1,i=r*n,s=ut(t),o=st(t),a=lE*o,l=aE*s+a*ut(i),u=a*r*st(i);wv.add(Ps(u,l)),oE=e,aE=s,lE=o}function Yre(e){return Ev=new mi,qa(e,fa),Ev*2}function Av(e){return[Ps(e[1],e[0]),Ui(e[2])]}function Hc(e){var t=e[0],n=e[1],r=ut(n);return[r*ut(t),r*st(t),st(n)]}function bm(e,t){return e[0]*t[0]+e[1]*t[1]+e[2]*t[2]}function Hd(e,t){return[e[1]*t[2]-e[2]*t[1],e[2]*t[0]-e[0]*t[2],e[0]*t[1]-e[1]*t[0]]}function Mx(e,t){e[0]+=t[0],e[1]+=t[1],e[2]+=t[2]}function xm(e,t){return[e[0]*t,e[1]*t,e[2]*t]}function kv(e){var t=bi(e[0]*e[0]+e[1]*e[1]+e[2]*e[2]);e[0]/=t,e[1]/=t,e[2]/=t}var Sn,Ti,Mn,es,nc,dI,hI,ld,Kp,Tl,fl,Pa={point:uE,lineStart:m4,lineEnd:v4,polygonStart:function(){Pa.point=gI,Pa.lineStart=Vre,Pa.lineEnd=Xre,Kp=new mi,fa.polygonStart()},polygonEnd:function(){fa.polygonEnd(),Pa.point=uE,Pa.lineStart=m4,Pa.lineEnd=v4,wv<0?(Sn=-(Mn=180),Ti=-(es=90)):Kp>at?es=90:Kp<-at&&(Ti=-90),fl[0]=Sn,fl[1]=Mn},sphere:function(){Sn=-(Mn=180),Ti=-(es=90)}};function uE(e,t){Tl.push(fl=[Sn=e,Mn=e]),tes&&(es=t)}function pI(e,t){var n=Hc([e*Ft,t*Ft]);if(ld){var r=Hd(ld,n),i=[r[1],-r[0],0],s=Hd(i,r);kv(s),s=Av(s);var o=e-nc,a=o>0?1:-1,l=s[0]*Pn*a,u,c=zt(o)>180;c^(a*nces&&(es=u)):(l=(l+360)%360-180,c^(a*nces&&(es=t))),c?eQi(Sn,Mn)&&(Mn=e):Qi(e,Mn)>Qi(Sn,Mn)&&(Sn=e):Mn>=Sn?(eMn&&(Mn=e)):e>nc?Qi(Sn,e)>Qi(Sn,Mn)&&(Mn=e):Qi(e,Mn)>Qi(Sn,Mn)&&(Sn=e)}else Tl.push(fl=[Sn=e,Mn=e]);tes&&(es=t),ld=n,nc=e}function m4(){Pa.point=pI}function v4(){fl[0]=Sn,fl[1]=Mn,Pa.point=uE,ld=null}function gI(e,t){if(ld){var n=e-nc;Kp.add(zt(n)>180?n+(n>0?360:-360):n)}else dI=e,hI=t;fa.point(e,t),pI(e,t)}function Vre(){fa.lineStart()}function Xre(){gI(dI,hI),fa.lineEnd(),zt(Kp)>at&&(Sn=-(Mn=180)),fl[0]=Sn,fl[1]=Mn,ld=null}function Qi(e,t){return(t-=e)<0?t+360:t}function Kre(e,t){return e[0]-t[0]}function y4(e,t){return e[0]<=e[1]?e[0]<=t&&t<=e[1]:tQi(r[0],r[1])&&(r[1]=i[1]),Qi(i[0],r[1])>Qi(r[0],r[1])&&(r[0]=i[0])):s.push(r=i);for(o=-1/0,n=s.length-1,t=0,r=s[n];t<=n;r=i,++t)i=s[t],(a=Qi(r[1],i[0]))>o&&(o=a,Sn=i[0],Mn=r[1])}return Tl=fl=null,Sn===1/0||Ti===1/0?[[NaN,NaN],[NaN,NaN]]:[[Sn,Ti],[Mn,es]]}var Sp,Sv,Cv,$v,Fv,Dv,Mv,Tv,cE,fE,dE,mI,vI,ci,fi,di,lo={sphere:Cr,point:j3,lineStart:b4,lineEnd:x4,polygonStart:function(){lo.lineStart=eie,lo.lineEnd=tie},polygonEnd:function(){lo.lineStart=b4,lo.lineEnd=x4}};function j3(e,t){e*=Ft,t*=Ft;var n=ut(t);A0(n*ut(e),n*st(e),st(t))}function A0(e,t,n){++Sp,Cv+=(e-Cv)/Sp,$v+=(t-$v)/Sp,Fv+=(n-Fv)/Sp}function b4(){lo.point=Jre}function Jre(e,t){e*=Ft,t*=Ft;var n=ut(t);ci=n*ut(e),fi=n*st(e),di=st(t),lo.point=Qre,A0(ci,fi,di)}function Qre(e,t){e*=Ft,t*=Ft;var n=ut(t),r=n*ut(e),i=n*st(e),s=st(t),o=Ps(bi((o=fi*s-di*i)*o+(o=di*r-ci*s)*o+(o=ci*i-fi*r)*o),ci*r+fi*i+di*s);Sv+=o,Dv+=o*(ci+(ci=r)),Mv+=o*(fi+(fi=i)),Tv+=o*(di+(di=s)),A0(ci,fi,di)}function x4(){lo.point=j3}function eie(){lo.point=nie}function tie(){yI(mI,vI),lo.point=j3}function nie(e,t){mI=e,vI=t,e*=Ft,t*=Ft,lo.point=yI;var n=ut(t);ci=n*ut(e),fi=n*st(e),di=st(t),A0(ci,fi,di)}function yI(e,t){e*=Ft,t*=Ft;var n=ut(t),r=n*ut(e),i=n*st(e),s=st(t),o=fi*s-di*i,a=di*r-ci*s,l=ci*i-fi*r,u=iE(o,a,l),c=Ui(u),f=u&&-c/u;cE.add(f*o),fE.add(f*a),dE.add(f*l),Sv+=c,Dv+=c*(ci+(ci=r)),Mv+=c*(fi+(fi=i)),Tv+=c*(di+(di=s)),A0(ci,fi,di)}function rie(e){Sp=Sv=Cv=$v=Fv=Dv=Mv=Tv=0,cE=new mi,fE=new mi,dE=new mi,qa(e,lo);var t=+cE,n=+fE,r=+dE,i=iE(t,n,r);return iMt&&(e-=Math.round(e/yi)*yi),[e,t]}pE.invert=pE;function bI(e,t,n){return(e%=yi)?t||n?hE(w4(e),E4(t,n)):w4(e):t||n?E4(t,n):pE}function _4(e){return function(t,n){return t+=e,zt(t)>Mt&&(t-=Math.round(t/yi)*yi),[t,n]}}function w4(e){var t=_4(e);return t.invert=_4(-e),t}function E4(e,t){var n=ut(e),r=st(e),i=ut(t),s=st(t);function o(a,l){var u=ut(l),c=ut(a)*u,f=st(a)*u,d=st(l),h=d*n+c*r;return[Ps(f*i-h*s,c*n-d*r),Ui(h*i+f*s)]}return o.invert=function(a,l){var u=ut(l),c=ut(a)*u,f=st(a)*u,d=st(l),h=d*i-f*s;return[Ps(f*i+d*s,c*n+h*r),Ui(h*n-c*r)]},o}function iie(e){e=bI(e[0]*Ft,e[1]*Ft,e.length>2?e[2]*Ft:0);function t(n){return n=e(n[0]*Ft,n[1]*Ft),n[0]*=Pn,n[1]*=Pn,n}return t.invert=function(n){return n=e.invert(n[0]*Ft,n[1]*Ft),n[0]*=Pn,n[1]*=Pn,n},t}function sie(e,t,n,r,i,s){if(n){var o=ut(t),a=st(t),l=r*n;i==null?(i=t+r*yi,s=t-l/2):(i=A4(o,i),s=A4(o,s),(r>0?is)&&(i+=r*yi));for(var u,c=i;r>0?c>s:c1&&e.push(e.pop().concat(e.shift()))},result:function(){var n=e;return e=[],t=null,n}}}function m1(e,t){return zt(e[0]-t[0])=0;--a)i.point((f=c[a])[0],f[1]);else r(d.x,d.p.x,-1,i);d=d.p}d=d.o,c=d.z,h=!h}while(!d.v);i.lineEnd()}}}function k4(e){if(t=e.length){for(var t,n=0,r=e[0],i;++n=0?1:-1,$=S*k,M=$>Mt,O=m*A;if(l.add(Ps(O*S*st($),v*E+O*ut($))),o+=M?k+S*yi:k,M^p>=n^_>=n){var P=Hd(Hc(h),Hc(x));kv(P);var T=Hd(s,P);kv(T);var F=(M^k>=0?-1:1)*Ui(T[2]);(r>F||r===F&&(P[0]||P[1]))&&(a+=M^k>=0?1:-1)}}return(o<-at||o0){for(l||(i.polygonStart(),l=!0),i.lineStart(),A=0;A1&&_&2&&w.push(w.pop().concat(w.shift())),c.push(w.filter(aie))}}return d}}function aie(e){return e.length>1}function lie(e,t){return((e=e.x)[0]<0?e[1]-Rn-at:Rn-e[1])-((t=t.x)[0]<0?t[1]-Rn-at:Rn-t[1])}const S4=wI(function(){return!0},uie,fie,[-Mt,-Rn]);function uie(e){var t=NaN,n=NaN,r=NaN,i;return{lineStart:function(){e.lineStart(),i=1},point:function(s,o){var a=s>0?Mt:-Mt,l=zt(s-t);zt(l-Mt)0?Rn:-Rn),e.point(r,n),e.lineEnd(),e.lineStart(),e.point(a,n),e.point(s,n),i=0):r!==a&&l>=Mt&&(zt(t-r)at?$h((st(t)*(s=ut(r))*st(n)-st(r)*(i=ut(t))*st(e))/(i*s*o)):(t+r)/2}function fie(e,t,n,r){var i;if(e==null)i=n*Rn,r.point(-Mt,i),r.point(0,i),r.point(Mt,i),r.point(Mt,0),r.point(Mt,-i),r.point(0,-i),r.point(-Mt,-i),r.point(-Mt,0),r.point(-Mt,i);else if(zt(e[0]-t[0])>at){var s=e[0]0,i=zt(t)>at;function s(c,f,d,h){sie(h,e,n,d,c,f)}function o(c,f){return ut(c)*ut(f)>t}function a(c){var f,d,h,p,g;return{lineStart:function(){p=h=!1,g=1},point:function(m,v){var b=[m,v],x,_=o(m,v),w=r?_?0:u(m,v):_?u(m+(m<0?Mt:-Mt),v):0;if(!f&&(p=h=_)&&c.lineStart(),_!==h&&(x=l(f,b),(!x||m1(f,x)||m1(b,x))&&(b[2]=1)),_!==h)g=0,_?(c.lineStart(),x=l(b,f),c.point(x[0],x[1])):(x=l(f,b),c.point(x[0],x[1],2),c.lineEnd()),f=x;else if(i&&f&&r^_){var A;!(w&d)&&(A=l(b,f,!0))&&(g=0,r?(c.lineStart(),c.point(A[0][0],A[0][1]),c.point(A[1][0],A[1][1]),c.lineEnd()):(c.point(A[1][0],A[1][1]),c.lineEnd(),c.lineStart(),c.point(A[0][0],A[0][1],3)))}_&&(!f||!m1(f,b))&&c.point(b[0],b[1]),f=b,h=_,d=w},lineEnd:function(){h&&c.lineEnd(),f=null},clean:function(){return g|(p&&h)<<1}}}function l(c,f,d){var h=Hc(c),p=Hc(f),g=[1,0,0],m=Hd(h,p),v=bm(m,m),b=m[0],x=v-b*b;if(!x)return!d&&c;var _=t*v/x,w=-t*b/x,A=Hd(g,m),E=xm(g,_),k=xm(m,w);Mx(E,k);var S=A,$=bm(E,S),M=bm(S,S),O=$*$-M*(bm(E,E)-1);if(!(O<0)){var P=bi(O),T=xm(S,(-$-P)/M);if(Mx(T,E),T=Av(T),!d)return T;var F=c[0],R=f[0],z=c[1],j=f[1],q;R0^T[1]<(zt(T[0]-F)Mt^(F<=T[0]&&T[0]<=R)){var _e=xm(S,(-$+P)/M);return Mx(_e,E),[T,Av(_e)]}}}function u(c,f){var d=r?e:Mt-e,h=0;return c<-d?h|=1:c>d&&(h|=2),f<-d?h|=4:f>d&&(h|=8),h}return wI(o,a,s,r?[0,-e]:[-Mt,e-Mt])}function hie(e,t,n,r,i,s){var o=e[0],a=e[1],l=t[0],u=t[1],c=0,f=1,d=l-o,h=u-a,p;if(p=n-o,!(!d&&p>0)){if(p/=d,d<0){if(p0){if(p>f)return;p>c&&(c=p)}if(p=i-o,!(!d&&p<0)){if(p/=d,d<0){if(p>f)return;p>c&&(c=p)}else if(d>0){if(p0)){if(p/=h,h<0){if(p0){if(p>f)return;p>c&&(c=p)}if(p=s-a,!(!h&&p<0)){if(p/=h,h<0){if(p>f)return;p>c&&(c=p)}else if(h>0){if(p0&&(e[0]=o+c*d,e[1]=a+c*h),f<1&&(t[0]=o+f*d,t[1]=a+f*h),!0}}}}}var Cp=1e9,wm=-Cp;function EI(e,t,n,r){function i(u,c){return e<=u&&u<=n&&t<=c&&c<=r}function s(u,c,f,d){var h=0,p=0;if(u==null||(h=o(u,f))!==(p=o(c,f))||l(u,c)<0^f>0)do d.point(h===0||h===3?e:n,h>1?r:t);while((h=(h+f+4)%4)!==p);else d.point(c[0],c[1])}function o(u,c){return zt(u[0]-e)0?0:3:zt(u[0]-n)0?2:1:zt(u[1]-t)0?1:0:c>0?3:2}function a(u,c){return l(u.x,c.x)}function l(u,c){var f=o(u,1),d=o(c,1);return f!==d?f-d:f===0?c[1]-u[1]:f===1?u[0]-c[0]:f===2?u[1]-c[1]:c[0]-u[0]}return function(u){var c=u,f=xI(),d,h,p,g,m,v,b,x,_,w,A,E={point:k,lineStart:O,lineEnd:P,polygonStart:$,polygonEnd:M};function k(F,R){i(F,R)&&c.point(F,R)}function S(){for(var F=0,R=0,z=h.length;Rr&&(Le-ee)*(r-_e)>(Z-_e)*(e-ee)&&++F:Z<=r&&(Le-ee)*(r-_e)<(Z-_e)*(e-ee)&&--F;return F}function $(){c=f,d=[],h=[],A=!0}function M(){var F=S(),R=A&&F,z=(d=hN(d)).length;(R||z)&&(u.polygonStart(),R&&(u.lineStart(),s(null,null,1,u),u.lineEnd()),z&&_I(d,a,F,s,u),u.polygonEnd()),c=u,d=h=p=null}function O(){E.point=T,h&&h.push(p=[]),w=!0,_=!1,b=x=NaN}function P(){d&&(T(g,m),v&&_&&f.rejoin(),d.push(f.result())),E.point=k,_&&c.lineEnd()}function T(F,R){var z=i(F,R);if(h&&p.push([F,R]),w)g=F,m=R,v=z,w=!1,z&&(c.lineStart(),c.point(F,R));else if(z&&_)c.point(F,R);else{var j=[b=Math.max(wm,Math.min(Cp,b)),x=Math.max(wm,Math.min(Cp,x))],q=[F=Math.max(wm,Math.min(Cp,F)),R=Math.max(wm,Math.min(Cp,R))];hie(j,q,e,t,n,r)?(_||(c.lineStart(),c.point(j[0],j[1])),c.point(q[0],q[1]),z||c.lineEnd(),A=!1):z&&(c.lineStart(),c.point(F,R),A=!1)}b=F,x=R,_=z}return E}}function C4(e,t,n){var r=is(e,t-at,n).concat(t);return function(i){return r.map(function(s){return[i,s]})}}function $4(e,t,n){var r=is(e,t-at,n).concat(t);return function(i){return r.map(function(s){return[s,i]})}}function pie(){var e,t,n,r,i,s,o,a,l=10,u=l,c=90,f=360,d,h,p,g,m=2.5;function v(){return{type:"MultiLineString",coordinates:b()}}function b(){return is(ym(r/c)*c,n,c).map(p).concat(is(ym(a/f)*f,o,f).map(g)).concat(is(ym(t/l)*l,e,l).filter(function(x){return zt(x%c)>at}).map(d)).concat(is(ym(s/u)*u,i,u).filter(function(x){return zt(x%f)>at}).map(h))}return v.lines=function(){return b().map(function(x){return{type:"LineString",coordinates:x}})},v.outline=function(){return{type:"Polygon",coordinates:[p(r).concat(g(o).slice(1),p(n).reverse().slice(1),g(a).reverse().slice(1))]}},v.extent=function(x){return arguments.length?v.extentMajor(x).extentMinor(x):v.extentMinor()},v.extentMajor=function(x){return arguments.length?(r=+x[0][0],n=+x[1][0],a=+x[0][1],o=+x[1][1],r>n&&(x=r,r=n,n=x),a>o&&(x=a,a=o,o=x),v.precision(m)):[[r,a],[n,o]]},v.extentMinor=function(x){return arguments.length?(t=+x[0][0],e=+x[1][0],s=+x[0][1],i=+x[1][1],t>e&&(x=t,t=e,e=x),s>i&&(x=s,s=i,i=x),v.precision(m)):[[t,s],[e,i]]},v.step=function(x){return arguments.length?v.stepMajor(x).stepMinor(x):v.stepMinor()},v.stepMajor=function(x){return arguments.length?(c=+x[0],f=+x[1],v):[c,f]},v.stepMinor=function(x){return arguments.length?(l=+x[0],u=+x[1],v):[l,u]},v.precision=function(x){return arguments.length?(m=+x,d=C4(s,i,90),h=$4(t,e,m),p=C4(a,o,90),g=$4(r,n,m),v):m},v.extentMajor([[-180,-90+at],[180,90-at]]).extentMinor([[-180,-80-at],[180,80+at]])}const wg=e=>e;var Rx=new mi,gE=new mi,AI,kI,mE,vE,Wa={point:Cr,lineStart:Cr,lineEnd:Cr,polygonStart:function(){Wa.lineStart=gie,Wa.lineEnd=vie},polygonEnd:function(){Wa.lineStart=Wa.lineEnd=Wa.point=Cr,Rx.add(zt(gE)),gE=new mi},result:function(){var e=Rx/2;return Rx=new mi,e}};function gie(){Wa.point=mie}function mie(e,t){Wa.point=SI,AI=mE=e,kI=vE=t}function SI(e,t){gE.add(vE*e-mE*t),mE=e,vE=t}function vie(){SI(AI,kI)}var Gd=1/0,Rv=Gd,Eg=-Gd,Nv=Eg,Ov={point:yie,lineStart:Cr,lineEnd:Cr,polygonStart:Cr,polygonEnd:Cr,result:function(){var e=[[Gd,Rv],[Eg,Nv]];return Eg=Nv=-(Rv=Gd=1/0),e}};function yie(e,t){eEg&&(Eg=e),tNv&&(Nv=t)}var yE=0,bE=0,$p=0,Lv=0,Iv=0,ed=0,xE=0,_E=0,Fp=0,CI,$I,Vo,Xo,As={point:Gc,lineStart:F4,lineEnd:D4,polygonStart:function(){As.lineStart=_ie,As.lineEnd=wie},polygonEnd:function(){As.point=Gc,As.lineStart=F4,As.lineEnd=D4},result:function(){var e=Fp?[xE/Fp,_E/Fp]:ed?[Lv/ed,Iv/ed]:$p?[yE/$p,bE/$p]:[NaN,NaN];return yE=bE=$p=Lv=Iv=ed=xE=_E=Fp=0,e}};function Gc(e,t){yE+=e,bE+=t,++$p}function F4(){As.point=bie}function bie(e,t){As.point=xie,Gc(Vo=e,Xo=t)}function xie(e,t){var n=e-Vo,r=t-Xo,i=bi(n*n+r*r);Lv+=i*(Vo+e)/2,Iv+=i*(Xo+t)/2,ed+=i,Gc(Vo=e,Xo=t)}function D4(){As.point=Gc}function _ie(){As.point=Eie}function wie(){FI(CI,$I)}function Eie(e,t){As.point=FI,Gc(CI=Vo=e,$I=Xo=t)}function FI(e,t){var n=e-Vo,r=t-Xo,i=bi(n*n+r*r);Lv+=i*(Vo+e)/2,Iv+=i*(Xo+t)/2,ed+=i,i=Xo*e-Vo*t,xE+=i*(Vo+e),_E+=i*(Xo+t),Fp+=i*3,Gc(Vo=e,Xo=t)}function DI(e){this._context=e}DI.prototype={_radius:4.5,pointRadius:function(e){return this._radius=e,this},polygonStart:function(){this._line=0},polygonEnd:function(){this._line=NaN},lineStart:function(){this._point=0},lineEnd:function(){this._line===0&&this._context.closePath(),this._point=NaN},point:function(e,t){switch(this._point){case 0:{this._context.moveTo(e,t),this._point=1;break}case 1:{this._context.lineTo(e,t);break}default:{this._context.moveTo(e+this._radius,t),this._context.arc(e,t,this._radius,0,yi);break}}},result:Cr};var wE=new mi,Nx,MI,TI,Dp,Mp,Ag={point:Cr,lineStart:function(){Ag.point=Aie},lineEnd:function(){Nx&&RI(MI,TI),Ag.point=Cr},polygonStart:function(){Nx=!0},polygonEnd:function(){Nx=null},result:function(){var e=+wE;return wE=new mi,e}};function Aie(e,t){Ag.point=RI,MI=Dp=e,TI=Mp=t}function RI(e,t){Dp-=e,Mp-=t,wE.add(bi(Dp*Dp+Mp*Mp)),Dp=e,Mp=t}let M4,Pv,T4,R4;class N4{constructor(t){this._append=t==null?NI:kie(t),this._radius=4.5,this._=""}pointRadius(t){return this._radius=+t,this}polygonStart(){this._line=0}polygonEnd(){this._line=NaN}lineStart(){this._point=0}lineEnd(){this._line===0&&(this._+="Z"),this._point=NaN}point(t,n){switch(this._point){case 0:{this._append`M${t},${n}`,this._point=1;break}case 1:{this._append`L${t},${n}`;break}default:{if(this._append`M${t},${n}`,this._radius!==T4||this._append!==Pv){const r=this._radius,i=this._;this._="",this._append`m0,${r}a${r},${r} 0 1,1 0,${-2*r}a${r},${r} 0 1,1 0,${2*r}z`,T4=r,Pv=this._append,R4=this._,this._=i}this._+=R4;break}}}result(){const t=this._;return this._="",t.length?t:null}}function NI(e){let t=1;this._+=e[0];for(const n=e.length;t=0))throw new RangeError(`invalid digits: ${e}`);if(t>15)return NI;if(t!==M4){const n=10**t;M4=t,Pv=function(i){let s=1;this._+=i[0];for(const o=i.length;s=0))throw new RangeError(`invalid digits: ${a}`);n=l}return t===null&&(s=new N4(n)),o},o.projection(e).digits(n).context(t)}function xb(e){return function(t){var n=new EE;for(var r in e)n[r]=e[r];return n.stream=t,n}}function EE(){}EE.prototype={constructor:EE,point:function(e,t){this.stream.point(e,t)},sphere:function(){this.stream.sphere()},lineStart:function(){this.stream.lineStart()},lineEnd:function(){this.stream.lineEnd()},polygonStart:function(){this.stream.polygonStart()},polygonEnd:function(){this.stream.polygonEnd()}};function U3(e,t,n){var r=e.clipExtent&&e.clipExtent();return e.scale(150).translate([0,0]),r!=null&&e.clipExtent(null),qa(n,e.stream(Ov)),t(Ov.result()),r!=null&&e.clipExtent(r),e}function _b(e,t,n){return U3(e,function(r){var i=t[1][0]-t[0][0],s=t[1][1]-t[0][1],o=Math.min(i/(r[1][0]-r[0][0]),s/(r[1][1]-r[0][1])),a=+t[0][0]+(i-o*(r[1][0]+r[0][0]))/2,l=+t[0][1]+(s-o*(r[1][1]+r[0][1]))/2;e.scale(150*o).translate([a,l])},n)}function q3(e,t,n){return _b(e,[[0,0],t],n)}function W3(e,t,n){return U3(e,function(r){var i=+t,s=i/(r[1][0]-r[0][0]),o=(i-s*(r[1][0]+r[0][0]))/2,a=-s*r[0][1];e.scale(150*s).translate([o,a])},n)}function H3(e,t,n){return U3(e,function(r){var i=+t,s=i/(r[1][1]-r[0][1]),o=-s*r[0][0],a=(i-s*(r[1][1]+r[0][1]))/2;e.scale(150*s).translate([o,a])},n)}var O4=16,Sie=ut(30*Ft);function L4(e,t){return+t?$ie(e,t):Cie(e)}function Cie(e){return xb({point:function(t,n){t=e(t,n),this.stream.point(t[0],t[1])}})}function $ie(e,t){function n(r,i,s,o,a,l,u,c,f,d,h,p,g,m){var v=u-r,b=c-i,x=v*v+b*b;if(x>4*t&&g--){var _=o+d,w=a+h,A=l+p,E=bi(_*_+w*w+A*A),k=Ui(A/=E),S=zt(zt(A)-1)t||zt((v*P+b*T)/x-.5)>.3||o*d+a*h+l*p2?F[2]%360*Ft:0,P()):[a*Pn,l*Pn,u*Pn]},M.angle=function(F){return arguments.length?(f=F%360*Ft,P()):f*Pn},M.reflectX=function(F){return arguments.length?(d=F?-1:1,P()):d<0},M.reflectY=function(F){return arguments.length?(h=F?-1:1,P()):h<0},M.precision=function(F){return arguments.length?(A=L4(E,w=F*F),T()):bi(w)},M.fitExtent=function(F,R){return _b(M,F,R)},M.fitSize=function(F,R){return q3(M,F,R)},M.fitWidth=function(F,R){return W3(M,F,R)},M.fitHeight=function(F,R){return H3(M,F,R)};function P(){var F=I4(n,0,0,d,h,f).apply(null,t(s,o)),R=I4(n,r-F[0],i-F[1],d,h,f);return c=bI(a,l,u),E=hE(t,R),k=hE(c,E),A=L4(E,w),T()}function T(){return S=$=null,M}return function(){return t=e.apply(this,arguments),M.invert=t.invert&&O,P()}}function G3(e){var t=0,n=Mt/3,r=LI(e),i=r(t,n);return i.parallels=function(s){return arguments.length?r(t=s[0]*Ft,n=s[1]*Ft):[t*Pn,n*Pn]},i}function Tie(e){var t=ut(e);function n(r,i){return[r*t,st(i)/t]}return n.invert=function(r,i){return[r/t,Ui(i*t)]},n}function Rie(e,t){var n=st(e),r=(n+st(t))/2;if(zt(r)=.12&&m<.234&&g>=-.425&&g<-.214?i:m>=.166&&m<.234&&g>=-.214&&g<-.115?o:n).invert(d)},c.stream=function(d){return e&&t===d?e:e=Nie([n.stream(t=d),i.stream(d),o.stream(d)])},c.precision=function(d){return arguments.length?(n.precision(d),i.precision(d),o.precision(d),f()):n.precision()},c.scale=function(d){return arguments.length?(n.scale(d),i.scale(d*.35),o.scale(d),c.translate(n.translate())):n.scale()},c.translate=function(d){if(!arguments.length)return n.translate();var h=n.scale(),p=+d[0],g=+d[1];return r=n.translate(d).clipExtent([[p-.455*h,g-.238*h],[p+.455*h,g+.238*h]]).stream(u),s=i.translate([p-.307*h,g+.201*h]).clipExtent([[p-.425*h+at,g+.12*h+at],[p-.214*h-at,g+.234*h-at]]).stream(u),a=o.translate([p-.205*h,g+.212*h]).clipExtent([[p-.214*h+at,g+.166*h+at],[p-.115*h-at,g+.234*h-at]]).stream(u),f()},c.fitExtent=function(d,h){return _b(c,d,h)},c.fitSize=function(d,h){return q3(c,d,h)},c.fitWidth=function(d,h){return W3(c,d,h)},c.fitHeight=function(d,h){return H3(c,d,h)};function f(){return e=t=null,c}return c.scale(1070)}function PI(e){return function(t,n){var r=ut(t),i=ut(n),s=e(r*i);return s===1/0?[2,0]:[s*i*st(t),s*st(n)]}}function k0(e){return function(t,n){var r=bi(t*t+n*n),i=e(r),s=st(i),o=ut(i);return[Ps(t*s,r*o),Ui(r&&n*s/r)]}}var BI=PI(function(e){return bi(2/(1+e))});BI.invert=k0(function(e){return 2*Ui(e/2)});function Lie(){return _a(BI).scale(124.75).clipAngle(180-.001)}var zI=PI(function(e){return(e=lI(e))&&e/st(e)});zI.invert=k0(function(e){return e});function Iie(){return _a(zI).scale(79.4188).clipAngle(180-.001)}function wb(e,t){return[e,xv(z3((Rn+t)/2))]}wb.invert=function(e,t){return[e,2*$h(aI(t))-Rn]};function Pie(){return jI(wb).scale(961/yi)}function jI(e){var t=_a(e),n=t.center,r=t.scale,i=t.translate,s=t.clipExtent,o=null,a,l,u;t.scale=function(f){return arguments.length?(r(f),c()):r()},t.translate=function(f){return arguments.length?(i(f),c()):i()},t.center=function(f){return arguments.length?(n(f),c()):n()},t.clipExtent=function(f){return arguments.length?(f==null?o=a=l=u=null:(o=+f[0][0],a=+f[0][1],l=+f[1][0],u=+f[1][1]),c()):o==null?null:[[o,a],[l,u]]};function c(){var f=Mt*r(),d=t(iie(t.rotate()).invert([0,0]));return s(o==null?[[d[0]-f,d[1]-f],[d[0]+f,d[1]+f]]:e===wb?[[Math.max(d[0]-f,o),a],[Math.min(d[0]+f,l),u]]:[[o,Math.max(d[1]-f,a)],[l,Math.min(d[1]+f,u)]])}return c()}function Em(e){return z3((Rn+e)/2)}function Bie(e,t){var n=ut(e),r=e===t?st(e):xv(n/ut(t))/xv(Em(t)/Em(e)),i=n*Dx(Em(e),r)/r;if(!r)return wb;function s(o,a){i>0?a<-Rn+at&&(a=-Rn+at):a>Rn-at&&(a=Rn-at);var l=i/Dx(Em(a),r);return[l*st(r*o),i-l*ut(r*o)]}return s.invert=function(o,a){var l=i-a,u=Ss(r)*bi(o*o+l*l),c=Ps(o,zt(l))*Ss(l);return l*r<0&&(c-=Mt*Ss(o)*Ss(l)),[c/r,2*$h(Dx(i/u,1/r))-Rn]},s}function zie(){return G3(Bie).scale(109.5).parallels([30,30])}function zv(e,t){return[e,t]}zv.invert=zv;function jie(){return _a(zv).scale(152.63)}function Uie(e,t){var n=ut(e),r=e===t?st(e):(n-ut(t))/(t-e),i=n/r+e;if(zt(r)at&&--r>0);return[e/(.8707+(s=n*n)*(-.131979+s*(-.013791+s*s*s*(.003971-.001529*s)))),n]};function Vie(){return _a(WI).scale(175.295)}function HI(e,t){return[ut(t)*st(e),st(t)]}HI.invert=k0(Ui);function Xie(){return _a(HI).scale(249.5).clipAngle(90+at)}function GI(e,t){var n=ut(t),r=1+ut(e)*n;return[n*st(e)/r,st(t)/r]}GI.invert=k0(function(e){return 2*$h(e)});function Kie(){return _a(GI).scale(250).clipAngle(142)}function YI(e,t){return[xv(z3((Rn+t)/2)),-e]}YI.invert=function(e,t){return[-t,2*$h(aI(e))-Rn]};function Zie(){var e=jI(YI),t=e.center,n=e.rotate;return e.center=function(r){return arguments.length?t([-r[1],r[0]]):(r=t(),[r[1],-r[0]])},e.rotate=function(r){return arguments.length?n([r[0],r[1],r.length>2?r[2]+90:90]):(r=n(),[r[0],r[1],r[2]-90])},n([0,0,90]).scale(159.155)}var Jie=Math.abs,AE=Math.cos,Uv=Math.sin,Qie=1e-6,VI=Math.PI,kE=VI/2,P4=ese(2);function B4(e){return e>1?kE:e<-1?-kE:Math.asin(e)}function ese(e){return e>0?Math.sqrt(e):0}function tse(e,t){var n=e*Uv(t),r=30,i;do t-=i=(t+Uv(t)-n)/(1+AE(t));while(Jie(i)>Qie&&--r>0);return t/2}function nse(e,t,n){function r(i,s){return[e*i*AE(s=tse(n,s)),t*Uv(s)]}return r.invert=function(i,s){return s=B4(s/t),[i/(e*AE(s)),B4((2*s+Uv(2*s))/n)]},r}var rse=nse(P4/kE,P4,VI);function ise(){return _a(rse).scale(169.529)}const sse=OI(),SE=["clipAngle","clipExtent","scale","translate","center","rotate","parallels","precision","reflectX","reflectY","coefficient","distance","fraction","lobes","parallel","radius","ratio","spacing","tilt"];function ose(e,t){return function n(){const r=t();return r.type=e,r.path=OI().projection(r),r.copy=r.copy||function(){const i=n();return SE.forEach(s=>{r[s]&&i[s](r[s]())}),i.path.pointRadius(r.path.pointRadius()),i},u9(r)}}function Y3(e,t){if(!e||typeof e!="string")throw new Error("Projection type must be a name string.");return e=e.toLowerCase(),arguments.length>1?(qv[e]=ose(e,t),this):qv[e]||null}function XI(e){return e&&e.path||sse}const qv={albers:II,albersusa:Oie,azimuthalequalarea:Lie,azimuthalequidistant:Iie,conicconformal:zie,conicequalarea:Bv,conicequidistant:qie,equalEarth:Hie,equirectangular:jie,gnomonic:Gie,identity:Yie,mercator:Pie,mollweide:ise,naturalEarth1:Vie,orthographic:Xie,stereographic:Kie,transversemercator:Zie};for(const e in qv)Y3(e,qv[e]);function ase(){}const Ra=[[],[[[1,1.5],[.5,1]]],[[[1.5,1],[1,1.5]]],[[[1.5,1],[.5,1]]],[[[1,.5],[1.5,1]]],[[[1,1.5],[.5,1]],[[1,.5],[1.5,1]]],[[[1,.5],[1,1.5]]],[[[1,.5],[.5,1]]],[[[.5,1],[1,.5]]],[[[1,1.5],[1,.5]]],[[[.5,1],[1,.5]],[[1.5,1],[1,1.5]]],[[[1.5,1],[1,.5]]],[[[.5,1],[1.5,1]]],[[[1,1.5],[1.5,1]]],[[[.5,1],[1,1.5]]],[]];function KI(){var e=1,t=1,n=a;function r(l,u){return u.map(c=>i(l,c))}function i(l,u){var c=[],f=[];return s(l,u,d=>{n(d,l,u),lse(d)>0?c.push([d]):f.push(d)}),f.forEach(d=>{for(var h=0,p=c.length,g;h=u,Ra[m<<1].forEach(x);++h=u,Ra[g|m<<1].forEach(x);for(Ra[m<<0].forEach(x);++p=u,v=l[p*e]>=u,Ra[m<<1|v<<2].forEach(x);++h=u,b=v,v=l[p*e+h+1]>=u,Ra[g|m<<1|v<<2|b<<3].forEach(x);Ra[m|v<<3].forEach(x)}for(h=-1,v=l[p*e]>=u,Ra[v<<2].forEach(x);++h=u,Ra[v<<2|b<<3].forEach(x);Ra[v<<3].forEach(x);function x(_){var w=[_[0][0]+h,_[0][1]+p],A=[_[1][0]+h,_[1][1]+p],E=o(w),k=o(A),S,$;(S=d[E])?($=f[k])?(delete d[S.end],delete f[$.start],S===$?(S.ring.push(A),c(S.ring)):f[S.start]=d[$.end]={start:S.start,end:$.end,ring:S.ring.concat($.ring)}):(delete d[S.end],S.ring.push(A),d[S.end=k]=S):(S=f[k])?($=d[E])?(delete f[S.start],delete d[$.end],S===$?(S.ring.push(A),c(S.ring)):f[$.start]=d[S.end]={start:$.start,end:S.end,ring:$.ring.concat(S.ring)}):(delete f[S.start],S.ring.unshift(w),f[S.start=E]=S):f[E]=d[k]={start:E,end:k,ring:[w,A]}}}function o(l){return l[0]*2+l[1]*(e+1)*4}function a(l,u,c){l.forEach(f=>{var d=f[0],h=f[1],p=d|0,g=h|0,m,v=u[g*e+p];d>0&&d0&&h=0&&c>=0||ae("invalid size"),e=u,t=c,r},r.smooth=function(l){return arguments.length?(n=l?a:ase,r):n===a},r}function lse(e){for(var t=0,n=e.length,r=e[n-1][1]*e[0][0]-e[n-1][0]*e[0][1];++tr!=h>r&&n<(d-u)*(r-c)/(h-c)+u&&(i=-i)}return i}function fse(e,t,n){var r;return dse(e,t,n)&&hse(e[r=+(e[0]===t[0])],n[r],t[r])}function dse(e,t,n){return(t[0]-e[0])*(n[1]-e[1])===(n[0]-e[0])*(t[1]-e[1])}function hse(e,t,n){return e<=t&&t<=n||n<=t&&t<=e}function ZI(e,t,n){return function(r){var i=aa(r),s=n?Math.min(i[0],0):i[0],o=i[1],a=o-s,l=t?su(s,o,e):a/(e+1);return is(s+l,o,l)}}function V3(e){ne.call(this,null,e)}V3.Definition={type:"Isocontour",metadata:{generates:!0},params:[{name:"field",type:"field"},{name:"thresholds",type:"number",array:!0},{name:"levels",type:"number"},{name:"nice",type:"boolean",default:!1},{name:"resolve",type:"enum",values:["shared","independent"],default:"independent"},{name:"zero",type:"boolean",default:!0},{name:"smooth",type:"boolean",default:!0},{name:"scale",type:"number",expr:!0},{name:"translate",type:"number",array:!0,expr:!0},{name:"as",type:"string",null:!0,default:"contour"}]};Te(V3,ne,{transform(e,t){if(this.value&&!t.changed()&&!e.modified())return t.StopPropagation;var n=t.fork(t.NO_SOURCE|t.NO_FIELDS),r=t.materialize(t.SOURCE).source,i=e.field||Qr,s=KI().smooth(e.smooth!==!1),o=e.thresholds||pse(r,i,e),a=e.as===null?null:e.as||"contour",l=[];return r.forEach(u=>{const c=i(u),f=s.size([c.width,c.height])(c.values,fe(o)?o:o(c.values));gse(f,c,u,e),f.forEach(d=>{l.push(By(u,Kt(a!=null?{[a]:d}:d)))})}),this.value&&(n.rem=this.value),this.value=n.source=n.add=l,n}});function pse(e,t,n){const r=ZI(n.levels||10,n.nice,n.zero!==!1);return n.resolve!=="shared"?r:r(e.map(i=>wc(t(i).values)))}function gse(e,t,n,r){let i=r.scale||t.scale,s=r.translate||t.translate;if(St(i)&&(i=i(n,r)),St(s)&&(s=s(n,r)),(i===1||i==null)&&!s)return;const o=(Gt(i)?i:i[0])||1,a=(Gt(i)?i:i[1])||1,l=s&&s[0]||0,u=s&&s[1]||0;e.forEach(JI(t,o,a,l,u))}function JI(e,t,n,r,i){const s=e.x1||0,o=e.y1||0,a=t*n<0;function l(f){f.forEach(u)}function u(f){a&&f.reverse(),f.forEach(c)}function c(f){f[0]=(f[0]-s)*t+r,f[1]=(f[1]-o)*n+i}return function(f){return f.coordinates.forEach(l),f}}function z4(e,t,n){const r=e>=0?e:zk(t,n);return Math.round((Math.sqrt(4*r*r+1)-1)/2)}function Ox(e){return St(e)?e:ei(+e)}function QI(){var e=l=>l[0],t=l=>l[1],n=ph,r=[-1,-1],i=960,s=500,o=2;function a(l,u){const c=z4(r[0],l,e)>>o,f=z4(r[1],l,t)>>o,d=c?c+2:0,h=f?f+2:0,p=2*d+(i>>o),g=2*h+(s>>o),m=new Float32Array(p*g),v=new Float32Array(p*g);let b=m;l.forEach(_=>{const w=d+(+e(_)>>o),A=h+(+t(_)>>o);w>=0&&w=0&&A0&&f>0?(Lf(p,g,m,v,c),If(p,g,v,m,f),Lf(p,g,m,v,c),If(p,g,v,m,f),Lf(p,g,m,v,c),If(p,g,v,m,f)):c>0?(Lf(p,g,m,v,c),Lf(p,g,v,m,c),Lf(p,g,m,v,c),b=v):f>0&&(If(p,g,m,v,f),If(p,g,v,m,f),If(p,g,m,v,f),b=v);const x=u?Math.pow(2,-2*o):1/pN(b);for(let _=0,w=p*g;_>o),y2:h+(s>>o)}}return a.x=function(l){return arguments.length?(e=Ox(l),a):e},a.y=function(l){return arguments.length?(t=Ox(l),a):t},a.weight=function(l){return arguments.length?(n=Ox(l),a):n},a.size=function(l){if(!arguments.length)return[i,s];var u=+l[0],c=+l[1];return u>=0&&c>=0||ae("invalid size"),i=u,s=c,a},a.cellSize=function(l){return arguments.length?((l=+l)>=1||ae("invalid cell size"),o=Math.floor(Math.log(l)/Math.LN2),a):1<=i&&(a>=s&&(l-=n[a-s+o*e]),r[a-i+o*e]=l/Math.min(a+1,e-1+s-a,s))}function If(e,t,n,r,i){const s=(i<<1)+1;for(let o=0;o=i&&(a>=s&&(l-=n[o+(a-s)*e]),r[o+(a-i)*e]=l/Math.min(a+1,t-1+s-a,s))}function X3(e){ne.call(this,null,e)}X3.Definition={type:"KDE2D",metadata:{generates:!0},params:[{name:"size",type:"number",array:!0,length:2,required:!0},{name:"x",type:"field",required:!0},{name:"y",type:"field",required:!0},{name:"weight",type:"field"},{name:"groupby",type:"field",array:!0},{name:"cellSize",type:"number"},{name:"bandwidth",type:"number",array:!0,length:2},{name:"counts",type:"boolean",default:!1},{name:"as",type:"string",default:"grid"}]};const mse=["x","y","weight","size","cellSize","bandwidth"];function eP(e,t){return mse.forEach(n=>t[n]!=null?e[n](t[n]):0),e}Te(X3,ne,{transform(e,t){if(this.value&&!t.changed()&&!e.modified())return t.StopPropagation;var n=t.fork(t.NO_SOURCE|t.NO_FIELDS),r=t.materialize(t.SOURCE).source,i=vse(r,e.groupby),s=(e.groupby||[]).map(On),o=eP(QI(),e),a=e.as||"grid",l=[];function u(c,f){for(let d=0;dKt(u({[a]:o(c,e.counts)},c.dims))),this.value&&(n.rem=this.value),this.value=n.source=n.add=l,n}});function vse(e,t){var n=[],r=c=>c(a),i,s,o,a,l,u;if(t==null)n.push(e);else for(i={},s=0,o=e.length;sn.push(a(c))),s&&o&&(t.visit(l,c=>{var f=s(c),d=o(c);f!=null&&d!=null&&(f=+f)===f&&(d=+d)===d&&r.push([f,d])}),n=n.concat({type:CE,geometry:{type:yse,coordinates:r}})),this.value={type:Z3,features:n}}});function Q3(e){ne.call(this,null,e)}Q3.Definition={type:"GeoPath",metadata:{modifies:!0},params:[{name:"projection",type:"projection"},{name:"field",type:"field"},{name:"pointRadius",type:"number",expr:!0},{name:"as",type:"string",default:"path"}]};Te(Q3,ne,{transform(e,t){var n=t.fork(t.ALL),r=this.value,i=e.field||Qr,s=e.as||"path",o=n.SOURCE;!r||e.modified()?(this.value=r=XI(e.projection),n.materialize().reflow()):o=i===Qr||t.modified(i.fields)?n.ADD_MOD:n.ADD;const a=bse(r,e.pointRadius);return n.visit(o,l=>l[s]=r(i(l))),r.pointRadius(a),n.modifies(s)}});function bse(e,t){const n=e.pointRadius();return e.context(null),t!=null&&e.pointRadius(t),n}function eC(e){ne.call(this,null,e)}eC.Definition={type:"GeoPoint",metadata:{modifies:!0},params:[{name:"projection",type:"projection",required:!0},{name:"fields",type:"field",array:!0,required:!0,length:2},{name:"as",type:"string",array:!0,length:2,default:["x","y"]}]};Te(eC,ne,{transform(e,t){var n=e.projection,r=e.fields[0],i=e.fields[1],s=e.as||["x","y"],o=s[0],a=s[1],l;function u(c){const f=n([r(c),i(c)]);f?(c[o]=f[0],c[a]=f[1]):(c[o]=void 0,c[a]=void 0)}return e.modified()?t=t.materialize().reflow(!0).visit(t.SOURCE,u):(l=t.modified(r.fields)||t.modified(i.fields),t.visit(l?t.ADD_MOD:t.ADD,u)),t.modifies(s)}});function tC(e){ne.call(this,null,e)}tC.Definition={type:"GeoShape",metadata:{modifies:!0,nomod:!0},params:[{name:"projection",type:"projection"},{name:"field",type:"field",default:"datum"},{name:"pointRadius",type:"number",expr:!0},{name:"as",type:"string",default:"shape"}]};Te(tC,ne,{transform(e,t){var n=t.fork(t.ALL),r=this.value,i=e.as||"shape",s=n.ADD;return(!r||e.modified())&&(this.value=r=xse(XI(e.projection),e.field||Os("datum"),e.pointRadius),n.materialize().reflow(),s=n.SOURCE),n.visit(s,o=>o[i]=r),n.modifies(i)}});function xse(e,t,n){const r=n==null?i=>e(t(i)):i=>{var s=e.pointRadius(),o=e.pointRadius(n)(t(i));return e.pointRadius(s),o};return r.context=i=>(e.context(i),r),r}function nC(e){ne.call(this,[],e),this.generator=pie()}nC.Definition={type:"Graticule",metadata:{changes:!0,generates:!0},params:[{name:"extent",type:"array",array:!0,length:2,content:{type:"number",array:!0,length:2}},{name:"extentMajor",type:"array",array:!0,length:2,content:{type:"number",array:!0,length:2}},{name:"extentMinor",type:"array",array:!0,length:2,content:{type:"number",array:!0,length:2}},{name:"step",type:"number",array:!0,length:2},{name:"stepMajor",type:"number",array:!0,length:2,default:[90,360]},{name:"stepMinor",type:"number",array:!0,length:2,default:[10,10]},{name:"precision",type:"number",default:2.5}]};Te(nC,ne,{transform(e,t){var n=this.value,r=this.generator,i;if(!n.length||e.modified())for(const s in e)St(r[s])&&r[s](e[s]);return i=r(),n.length?t.mod.push(lO(n[0],i)):t.add.push(Kt(i)),n[0]=i,t}});function rC(e){ne.call(this,null,e)}rC.Definition={type:"heatmap",metadata:{modifies:!0},params:[{name:"field",type:"field"},{name:"color",type:"string",expr:!0},{name:"opacity",type:"number",expr:!0},{name:"resolve",type:"enum",values:["shared","independent"],default:"independent"},{name:"as",type:"string",default:"image"}]};Te(rC,ne,{transform(e,t){if(!t.changed()&&!e.modified())return t.StopPropagation;var n=t.materialize(t.SOURCE).source,r=e.resolve==="shared",i=e.field||Qr,s=wse(e.opacity,e),o=_se(e.color,e),a=e.as||"image",l={$x:0,$y:0,$value:0,$max:r?wc(n.map(u=>wc(i(u).values))):0};return n.forEach(u=>{const c=i(u),f=kt({},u,l);r||(f.$max=wc(c.values||[])),u[a]=Ese(c,f,o.dep?o:ei(o(f)),s.dep?s:ei(s(f)))}),t.reflow(!0).modifies(a)}});function _se(e,t){let n;return St(e)?(n=r=>lu(e(r,t)),n.dep=tP(e)):n=ei(lu(e||"#888")),n}function wse(e,t){let n;return St(e)?(n=r=>e(r,t),n.dep=tP(e)):e?n=ei(e):(n=r=>r.$value/r.$max||0,n.dep=!0),n}function tP(e){if(!St(e))return!1;const t=mo(Yr(e));return t.$x||t.$y||t.$value||t.$max}function Ese(e,t,n,r){const i=e.width,s=e.height,o=e.x1||0,a=e.y1||0,l=e.x2||i,u=e.y2||s,c=e.values,f=c?m=>c[m]:Ol,d=eu(l-o,u-a),h=d.getContext("2d"),p=h.getImageData(0,0,l-o,u-a),g=p.data;for(let m=a,v=0;m{e[r]!=null&&j4(n,r,e[r])})):SE.forEach(r=>{e.modified(r)&&j4(n,r,e[r])}),e.pointRadius!=null&&n.path.pointRadius(e.pointRadius),e.fit&&Ase(n,e),t.fork(t.NO_SOURCE|t.NO_FIELDS)}});function Ase(e,t){const n=Sse(t.fit);t.extent?e.fitExtent(t.extent,n):t.size&&e.fitSize(t.size,n)}function kse(e){const t=Y3((e||"mercator").toLowerCase());return t||ae("Unrecognized projection type: "+e),t()}function j4(e,t,n){St(e[t])&&e[t](n)}function Sse(e){return e=je(e),e.length===1?e[0]:{type:Z3,features:e.reduce((t,n)=>t.concat(Cse(n)),[])}}function Cse(e){return e.type===Z3?e.features:je(e).filter(t=>t!=null).map(t=>t.type===CE?t:{type:CE,geometry:t})}const $se=Object.freeze(Object.defineProperty({__proto__:null,contour:K3,geojson:J3,geopath:Q3,geopoint:eC,geoshape:tC,graticule:nC,heatmap:rC,isocontour:V3,kde2d:X3,projection:nP},Symbol.toStringTag,{value:"Module"}));function Fse(e,t){var n,r=1;e==null&&(e=0),t==null&&(t=0);function i(){var s,o=n.length,a,l=0,u=0;for(s=0;s=(f=(a+u)/2))?a=f:u=f,(m=n>=(d=(l+c)/2))?l=d:c=d,i=s,!(s=s[v=m<<1|g]))return i[v]=o,e;if(h=+e._x.call(null,s.data),p=+e._y.call(null,s.data),t===h&&n===p)return o.next=s,i?i[v]=o:e._root=o,e;do i=i?i[v]=new Array(4):e._root=new Array(4),(g=t>=(f=(a+u)/2))?a=f:u=f,(m=n>=(d=(l+c)/2))?l=d:c=d;while((v=m<<1|g)===(b=(p>=d)<<1|h>=f));return i[b]=s,i[v]=o,e}function Mse(e){var t,n,r=e.length,i,s,o=new Array(r),a=new Array(r),l=1/0,u=1/0,c=-1/0,f=-1/0;for(n=0;nc&&(c=i),sf&&(f=s));if(l>c||u>f)return this;for(this.cover(l,u).cover(c,f),n=0;ne||e>=i||r>t||t>=s;)switch(u=(tc||(a=p.y0)>f||(l=p.x1)=v)<<1|e>=m)&&(p=d[d.length-1],d[d.length-1]=d[d.length-1-g],d[d.length-1-g]=p)}else{var b=e-+this._x.call(null,h.data),x=t-+this._y.call(null,h.data),_=b*b+x*x;if(_=(d=(o+l)/2))?o=d:l=d,(g=f>=(h=(a+u)/2))?a=h:u=h,t=n,!(n=n[m=g<<1|p]))return this;if(!n.length)break;(t[m+1&3]||t[m+2&3]||t[m+3&3])&&(r=t,v=m)}for(;n.data!==e;)if(i=n,!(n=n.next))return this;return(s=n.next)&&delete n.next,i?(s?i.next=s:delete i.next,this):t?(s?t[m]=s:delete t[m],(n=t[0]||t[1]||t[2]||t[3])&&n===(t[3]||t[2]||t[1]||t[0])&&!n.length&&(r?r[v]=n:this._root=n),this):(this._root=s,this)}function Ise(e){for(var t=0,n=e.length;td.index){var M=h-k.x-k.vx,O=p-k.y-k.vy,P=M*M+O*O;P<$*$&&(M===0&&(M=Hl(r),P+=M*M),O===0&&(O=Hl(r),P+=O*O),P=($-(P=Math.sqrt(P)))/P*i,d.vx+=(M*=P)*($=(S*=S)/(m+S)),d.vy+=(O*=P)*$,k.vx-=M*($=1-$),k.vy-=O*$)}return}return _>h+$||Ap+$||Eu.r&&(u.r=u[c].r)}function l(){if(t){var u,c=t.length,f;for(n=new Array(c),u=0;u[t(w,A,o),w])),_;for(m=0,a=new Array(v);m{}};function iP(){for(var e=0,t=arguments.length,n={},r;e=0&&(r=n.slice(i+1),n=n.slice(0,i)),n&&!t.hasOwnProperty(n))throw new Error("unknown type: "+n);return{type:n,name:r}})}v1.prototype=iP.prototype={constructor:v1,on:function(e,t){var n=this._,r=Jse(e+"",n),i,s=-1,o=r.length;if(arguments.length<2){for(;++s0)for(var n=new Array(i),r=0,i,s;r=0&&e._call.call(void 0,t),e=e._next;--Yd}function H4(){Yc=(Hv=kg.now())+Eb,Yd=Tp=0;try{toe()}finally{Yd=0,roe(),Yc=0}}function noe(){var e=kg.now(),t=e-Hv;t>sP&&(Eb-=t,Hv=e)}function roe(){for(var e,t=Wv,n,r=1/0;t;)t._call?(r>t._time&&(r=t._time),e=t,t=t._next):(n=t._next,t._next=null,t=e?e._next=n:Wv=n);Rp=e,$E(r)}function $E(e){if(!Yd){Tp&&(Tp=clearTimeout(Tp));var t=e-Yc;t>24?(e<1/0&&(Tp=setTimeout(H4,e-kg.now()-Eb)),rp&&(rp=clearInterval(rp))):(rp||(Hv=kg.now(),rp=setInterval(noe,sP)),Yd=1,oP(H4))}}function ioe(e,t,n){var r=new Gv,i=t;return t==null?(r.restart(e,t,n),r):(r._restart=r.restart,r.restart=function(s,o,a){o=+o,a=a==null?oC():+a,r._restart(function l(u){u+=i,r._restart(l,i+=o,a),s(u)},o,a)},r.restart(e,t,n),r)}const soe=1664525,ooe=1013904223,G4=4294967296;function aoe(){let e=1;return()=>(e=(soe*e+ooe)%G4)/G4}function loe(e){return e.x}function uoe(e){return e.y}var coe=10,foe=Math.PI*(3-Math.sqrt(5));function doe(e){var t,n=1,r=.001,i=1-Math.pow(r,1/300),s=0,o=.6,a=new Map,l=aP(f),u=iP("tick","end"),c=aoe();e==null&&(e=[]);function f(){d(),u.call("tick",t),n1?(m==null?a.delete(g):a.set(g,p(m)),t):a.get(g)},find:function(g,m,v){var b=0,x=e.length,_,w,A,E,k;for(v==null?v=1/0:v*=v,b=0;b1?(u.on(g,m),t):u.on(g)}}}function hoe(){var e,t,n,r,i=pi(-30),s,o=1,a=1/0,l=.81;function u(h){var p,g=e.length,m=iC(e,loe,uoe).visitAfter(f);for(r=h,p=0;p=a)return;(h.data!==t||h.next)&&(v===0&&(v=Hl(n),_+=v*v),b===0&&(b=Hl(n),_+=b*b),_=0;)n.tick();else if(n.stopped()&&n.restart(),!r)return t.StopPropagation}return this.finish(e,t)},finish(e,t){const n=t.dataflow;for(let a=this._argops,l=0,u=a.length,c;le.touch(t).run()}function yoe(e,t){const n=doe(e),r=n.stop,i=n.restart;let s=!1;return n.stopped=()=>s,n.restart=()=>(s=!1,i()),n.stop=()=>(s=!0,r()),uP(n,t,!0).on("end",()=>s=!0)}function uP(e,t,n,r){var i=je(t.forces),s,o,a,l;for(s=0,o=FE.length;st(r,n):t)}const woe=Object.freeze(Object.defineProperty({__proto__:null,force:aC},Symbol.toStringTag,{value:"Module"}));function Eoe(e,t){return e.parent===t.parent?1:2}function Aoe(e){return e.reduce(koe,0)/e.length}function koe(e,t){return e+t.x}function Soe(e){return 1+e.reduce(Coe,0)}function Coe(e,t){return Math.max(e,t.y)}function $oe(e){for(var t;t=e.children;)e=t[0];return e}function Foe(e){for(var t;t=e.children;)e=t[t.length-1];return e}function Doe(){var e=Eoe,t=1,n=1,r=!1;function i(s){var o,a=0;s.eachAfter(function(d){var h=d.children;h?(d.x=Aoe(h),d.y=Soe(h)):(d.x=o?a+=e(d,o):0,d.y=0,o=d)});var l=$oe(s),u=Foe(s),c=l.x-e(l,u)/2,f=u.x+e(u,l)/2;return s.eachAfter(r?function(d){d.x=(d.x-s.x)*t,d.y=(s.y-d.y)*n}:function(d){d.x=(d.x-c)/(f-c)*t,d.y=(1-(s.y?d.y/s.y:1))*n})}return i.separation=function(s){return arguments.length?(e=s,i):e},i.size=function(s){return arguments.length?(r=!1,t=+s[0],n=+s[1],i):r?null:[t,n]},i.nodeSize=function(s){return arguments.length?(r=!0,t=+s[0],n=+s[1],i):r?[t,n]:null},i}function Moe(e){var t=0,n=e.children,r=n&&n.length;if(!r)t=1;else for(;--r>=0;)t+=n[r].value;e.value=t}function Toe(){return this.eachAfter(Moe)}function Roe(e,t){let n=-1;for(const r of this)e.call(t,r,++n,this);return this}function Noe(e,t){for(var n=this,r=[n],i,s,o=-1;n=r.pop();)if(e.call(t,n,++o,this),i=n.children)for(s=i.length-1;s>=0;--s)r.push(i[s]);return this}function Ooe(e,t){for(var n=this,r=[n],i=[],s,o,a,l=-1;n=r.pop();)if(i.push(n),s=n.children)for(o=0,a=s.length;o=0;)n+=r[i].value;t.value=n})}function Poe(e){return this.eachBefore(function(t){t.children&&t.children.sort(e)})}function Boe(e){for(var t=this,n=zoe(t,e),r=[t];t!==n;)t=t.parent,r.push(t);for(var i=r.length;e!==n;)r.splice(i,0,e),e=e.parent;return r}function zoe(e,t){if(e===t)return e;var n=e.ancestors(),r=t.ancestors(),i=null;for(e=n.pop(),t=r.pop();e===t;)i=e,e=n.pop(),t=r.pop();return i}function joe(){for(var e=this,t=[e];e=e.parent;)t.push(e);return t}function Uoe(){return Array.from(this)}function qoe(){var e=[];return this.eachBefore(function(t){t.children||e.push(t)}),e}function Woe(){var e=this,t=[];return e.each(function(n){n!==e&&t.push({source:n.parent,target:n})}),t}function*Hoe(){var e=this,t,n=[e],r,i,s;do for(t=n.reverse(),n=[];e=t.pop();)if(yield e,r=e.children)for(i=0,s=r.length;i=0;--a)i.push(s=o[a]=new Vd(o[a])),s.parent=r,s.depth=r.depth+1;return n.eachBefore(cP)}function Goe(){return lC(this).eachBefore(Xoe)}function Yoe(e){return e.children}function Voe(e){return Array.isArray(e)?e[1]:null}function Xoe(e){e.data.value!==void 0&&(e.value=e.data.value),e.data=e.data.data}function cP(e){var t=0;do e.height=t;while((e=e.parent)&&e.height<++t)}function Vd(e){this.data=e,this.depth=this.height=0,this.parent=null}Vd.prototype=lC.prototype={constructor:Vd,count:Toe,each:Roe,eachAfter:Ooe,eachBefore:Noe,find:Loe,sum:Ioe,sort:Poe,path:Boe,ancestors:joe,descendants:Uoe,leaves:qoe,links:Woe,copy:Goe,[Symbol.iterator]:Hoe};function y1(e){return e==null?null:fP(e)}function fP(e){if(typeof e!="function")throw new Error;return e}function lc(){return 0}function Yf(e){return function(){return e}}const Koe=1664525,Zoe=1013904223,V4=4294967296;function Joe(){let e=1;return()=>(e=(Koe*e+Zoe)%V4)/V4}function Qoe(e){return typeof e=="object"&&"length"in e?e:Array.from(e)}function eae(e,t){let n=e.length,r,i;for(;n;)i=t()*n--|0,r=e[n],e[n]=e[i],e[i]=r;return e}function tae(e,t){for(var n=0,r=(e=eae(Array.from(e),t)).length,i=[],s,o;n0&&n*n>r*r+i*i}function Lx(e,t){for(var n=0;n1e-6?(M+Math.sqrt(M*M-4*$*O))/(2*$):O/M);return{x:r+A+E*P,y:i+k+S*P,r:P}}function X4(e,t,n){var r=e.x-t.x,i,s,o=e.y-t.y,a,l,u=r*r+o*o;u?(s=t.r+n.r,s*=s,l=e.r+n.r,l*=l,s>l?(i=(u+l-s)/(2*u),a=Math.sqrt(Math.max(0,l/u-i*i)),n.x=e.x-i*r-a*o,n.y=e.y-i*o+a*r):(i=(u+s-l)/(2*u),a=Math.sqrt(Math.max(0,s/u-i*i)),n.x=t.x+i*r-a*o,n.y=t.y+i*o+a*r)):(n.x=t.x+n.r,n.y=t.y)}function K4(e,t){var n=e.r+t.r-1e-6,r=t.x-e.x,i=t.y-e.y;return n>0&&n*n>r*r+i*i}function Z4(e){var t=e._,n=e.next._,r=t.r+n.r,i=(t.x*n.r+n.x*t.r)/r,s=(t.y*n.r+n.y*t.r)/r;return i*i+s*s}function km(e){this._=e,this.next=null,this.previous=null}function sae(e,t){if(!(s=(e=Qoe(e)).length))return 0;var n,r,i,s,o,a,l,u,c,f,d;if(n=e[0],n.x=0,n.y=0,!(s>1))return n.r;if(r=e[1],n.x=-r.r,r.x=n.r,r.y=0,!(s>2))return n.r+r.r;X4(r,n,i=e[2]),n=new km(n),r=new km(r),i=new km(i),n.next=i.previous=r,r.next=n.previous=i,i.next=r.previous=n;e:for(l=3;ldae(n(_,w,i))),b=v.map(nM),x=new Set(v).add("");for(const _ of b)x.has(_)||(x.add(_),v.push(_),b.push(nM(_)),s.push(Px));o=(_,w)=>v[w],a=(_,w)=>b[w]}for(c=0,l=s.length;c=0&&(h=s[v],h.data===Px);--v)h.data=null}if(f.parent=uae,f.eachBefore(function(v){v.depth=v.parent.depth+1,--l}).eachBefore(cP),f.parent=null,l>0)throw new Error("cycle");return f}return r.id=function(i){return arguments.length?(e=y1(i),r):e},r.parentId=function(i){return arguments.length?(t=y1(i),r):t},r.path=function(i){return arguments.length?(n=y1(i),r):n},r}function dae(e){e=`${e}`;let t=e.length;return DE(e,t-1)&&!DE(e,t-2)&&(e=e.slice(0,-1)),e[0]==="/"?e:`/${e}`}function nM(e){let t=e.length;if(t<2)return"";for(;--t>1&&!DE(e,t););return e.slice(0,t)}function DE(e,t){if(e[t]==="/"){let n=0;for(;t>0&&e[--t]==="\\";)++n;if((n&1)===0)return!0}return!1}function hae(e,t){return e.parent===t.parent?1:2}function Bx(e){var t=e.children;return t?t[0]:e.t}function zx(e){var t=e.children;return t?t[t.length-1]:e.t}function pae(e,t,n){var r=n/(t.i-e.i);t.c-=r,t.s+=n,e.c+=r,t.z+=n,t.m+=n}function gae(e){for(var t=0,n=0,r=e.children,i=r.length,s;--i>=0;)s=r[i],s.z+=t,s.m+=t,t+=s.s+(n+=s.c)}function mae(e,t,n){return e.a.parent===t.parent?e.a:n}function b1(e,t){this._=e,this.parent=null,this.children=null,this.A=null,this.a=this,this.z=0,this.m=0,this.c=0,this.s=0,this.t=null,this.i=t}b1.prototype=Object.create(Vd.prototype);function vae(e){for(var t=new b1(e,0),n,r=[t],i,s,o,a;n=r.pop();)if(s=n._.children)for(n.children=new Array(a=s.length),o=a-1;o>=0;--o)r.push(i=n.children[o]=new b1(s[o],o)),i.parent=n;return(t.parent=new b1(null,0)).children=[t],t}function yae(){var e=hae,t=1,n=1,r=null;function i(u){var c=vae(u);if(c.eachAfter(s),c.parent.m=-c.z,c.eachBefore(o),r)u.eachBefore(l);else{var f=u,d=u,h=u;u.eachBefore(function(b){b.xd.x&&(d=b),b.depth>h.depth&&(h=b)});var p=f===d?1:e(f,d)/2,g=p-f.x,m=t/(d.x+p+g),v=n/(h.depth||1);u.eachBefore(function(b){b.x=(b.x+g)*m,b.y=b.depth*v})}return u}function s(u){var c=u.children,f=u.parent.children,d=u.i?f[u.i-1]:null;if(c){gae(u);var h=(c[0].z+c[c.length-1].z)/2;d?(u.z=d.z+e(u._,d._),u.m=u.z-h):u.z=h}else d&&(u.z=d.z+e(u._,d._));u.parent.A=a(u,d,u.parent.A||f[0])}function o(u){u._.x=u.z+u.parent.m,u.m+=u.parent.m}function a(u,c,f){if(c){for(var d=u,h=u,p=c,g=d.parent.children[0],m=d.m,v=h.m,b=p.m,x=g.m,_;p=zx(p),d=Bx(d),p&&d;)g=Bx(g),h=zx(h),h.a=u,_=p.z+b-d.z-m+e(p._,d._),_>0&&(pae(mae(p,u,f),u,_),m+=_,v+=_),b+=p.m,m+=d.m,x+=g.m,v+=h.m;p&&!zx(h)&&(h.t=p,h.m+=b-v),d&&!Bx(g)&&(g.t=d,g.m+=m-x,f=u)}return f}function l(u){u.x*=t,u.y=u.depth*n}return i.separation=function(u){return arguments.length?(e=u,i):e},i.size=function(u){return arguments.length?(r=!1,t=+u[0],n=+u[1],i):r?null:[t,n]},i.nodeSize=function(u){return arguments.length?(r=!0,t=+u[0],n=+u[1],i):r?[t,n]:null},i}function Ab(e,t,n,r,i){for(var s=e.children,o,a=-1,l=s.length,u=e.value&&(i-n)/e.value;++ab&&(b=u),A=m*m*w,x=Math.max(b/A,A/v),x>_){m-=u;break}_=x}o.push(l={value:m,dice:h1?r:1)},n})(gP);function bae(){var e=vP,t=!1,n=1,r=1,i=[0],s=lc,o=lc,a=lc,l=lc,u=lc;function c(d){return d.x0=d.y0=0,d.x1=n,d.y1=r,d.eachBefore(f),i=[0],t&&d.eachBefore(pP),d}function f(d){var h=i[d.depth],p=d.x0+h,g=d.y0+h,m=d.x1-h,v=d.y1-h;m=d-1){var b=s[f];b.x0=p,b.y0=g,b.x1=m,b.y1=v;return}for(var x=u[f],_=h/2+x,w=f+1,A=d-1;w>>1;u[E]<_?w=E+1:A=E}_-u[w-1]v-g){var $=h?(p*S+m*k)/h:m;c(f,w,k,p,g,$,v),c(w,d,S,$,g,m,v)}else{var M=h?(g*S+v*k)/h:v;c(f,w,k,p,g,m,M),c(w,d,S,p,M,m,v)}}}function _ae(e,t,n,r,i){(e.depth&1?Ab:S0)(e,t,n,r,i)}const wae=(function e(t){function n(r,i,s,o,a){if((l=r._squarify)&&l.ratio===t)for(var l,u,c,f,d=-1,h,p=l.length,g=r.value;++d1?r:1)},n})(gP);function ME(e,t,n){const r={};return e.each(i=>{const s=i.data;n(s)&&(r[t(s)]=i)}),e.lookup=r,e}function uC(e){ne.call(this,null,e)}uC.Definition={type:"Nest",metadata:{treesource:!0,changes:!0},params:[{name:"keys",type:"field",array:!0},{name:"generate",type:"boolean"}]};const Eae=e=>e.values;Te(uC,ne,{transform(e,t){t.source||ae("Nest transform requires an upstream data source.");var n=e.generate,r=e.modified(),i=t.clone(),s=this.value;return(!s||r||t.changed())&&(s&&s.each(o=>{o.children&&Py(o.data)&&i.rem.push(o.data)}),this.value=s=lC({values:je(e.keys).reduce((o,a)=>(o.key(a),o),Aae()).entries(i.source)},Eae),n&&s.each(o=>{o.children&&(o=Kt(o.data),i.add.push(o),i.source.push(o))}),ME(s,it,it)),i.source.root=s,i}});function Aae(){const e=[],t={entries:i=>r(n(i,0),0),key:i=>(e.push(i),t)};function n(i,s){if(s>=e.length)return i;const o=i.length,a=e[s++],l={},u={};let c=-1,f,d,h;for(;++ce.length)return i;const o=[];for(const a in i)o.push({key:a,values:r(i[a],s)});return o}return t}function ml(e){ne.call(this,null,e)}const kae=(e,t)=>e.parent===t.parent?1:2;Te(ml,ne,{transform(e,t){(!t.source||!t.source.root)&&ae(this.constructor.name+" transform requires a backing tree data source.");const n=this.layout(e.method),r=this.fields,i=t.source.root,s=e.as||r;e.field?i.sum(e.field):i.count(),e.sort&&i.sort(pf(e.sort,o=>o.data)),Sae(n,this.params,e),n.separation&&n.separation(e.separation!==!1?kae:ph);try{this.value=n(i)}catch(o){ae(o)}return i.each(o=>Cae(o,r,s)),t.reflow(e.modified()).modifies(s).modifies("leaf")}});function Sae(e,t,n){for(let r,i=0,s=t.length;is[it(o)]=1),r.each(o=>{const a=o.data,l=o.parent&&o.parent.data;l&&s[it(a)]&&s[it(l)]&&i.add.push(Kt({source:l,target:a}))}),this.value=i.add):t.changed(t.MOD)&&(t.visit(t.MOD,o=>s[it(o)]=1),n.forEach(o=>{(s[it(o.source)]||s[it(o.target)])&&i.mod.push(o)})),i}});const iM={binary:xae,dice:S0,slice:Ab,slicedice:_ae,squarify:vP,resquarify:wae},OE=["x0","y0","x1","y1","depth","children"];function gC(e){ml.call(this,e)}gC.Definition={type:"Treemap",metadata:{tree:!0,modifies:!0},params:[{name:"field",type:"field"},{name:"sort",type:"compare"},{name:"method",type:"enum",default:"squarify",values:["squarify","resquarify","binary","dice","slice","slicedice"]},{name:"padding",type:"number",default:0},{name:"paddingInner",type:"number",default:0},{name:"paddingOuter",type:"number",default:0},{name:"paddingTop",type:"number",default:0},{name:"paddingRight",type:"number",default:0},{name:"paddingBottom",type:"number",default:0},{name:"paddingLeft",type:"number",default:0},{name:"ratio",type:"number",default:1.618033988749895},{name:"round",type:"boolean",default:!1},{name:"size",type:"number",array:!0,length:2},{name:"as",type:"string",array:!0,length:OE.length,default:OE}]};Te(gC,ml,{layout(){const e=bae();return e.ratio=t=>{const n=e.tile();n.ratio&&e.tile(n.ratio(t))},e.method=t=>{We(iM,t)?e.tile(iM[t]):ae("Unrecognized Treemap layout method: "+t)},e},params:["method","ratio","size","round","padding","paddingInner","paddingOuter","paddingTop","paddingRight","paddingBottom","paddingLeft"],fields:OE});const $ae=Object.freeze(Object.defineProperty({__proto__:null,nest:uC,pack:cC,partition:fC,stratify:dC,tree:hC,treelinks:pC,treemap:gC},Symbol.toStringTag,{value:"Module"})),jx=4278190080;function Fae(e,t){const n=e.bitmap();return(t||[]).forEach(r=>n.set(e(r.boundary[0]),e(r.boundary[3]))),[n,void 0]}function Dae(e,t,n,r,i){const s=e.width,o=e.height,a=r||i,l=eu(s,o).getContext("2d"),u=eu(s,o).getContext("2d"),c=a&&eu(s,o).getContext("2d");n.forEach(k=>x1(l,k,!1)),x1(u,t,!1),a&&x1(c,t,!0);const f=Ux(l,s,o),d=Ux(u,s,o),h=a&&Ux(c,s,o),p=e.bitmap(),g=a&&e.bitmap();let m,v,b,x,_,w,A,E;for(v=0;v{i.items.forEach(s=>x1(e,s.items,n))}):ps[r].draw(e,{items:n?t.map(Mae):t})}function Mae(e){const t=By(e,{});return t.stroke&&t.strokeOpacity!==0||t.fill&&t.fillOpacity!==0?{...t,strokeOpacity:1,stroke:"#000",fillOpacity:0}:t}const Na=5,oi=31,Sg=32,Rl=new Uint32Array(Sg+1),ro=new Uint32Array(Sg+1);ro[0]=0;Rl[0]=~ro[0];for(let e=1;e<=Sg;++e)ro[e]=ro[e-1]<<1|1,Rl[e]=~ro[e];function Tae(e,t){const n=new Uint32Array(~~((e*t+Sg)/Sg));function r(s,o){n[s]|=o}function i(s,o){n[s]&=o}return{array:n,get:(s,o)=>{const a=o*e+s;return n[a>>>Na]&1<<(a&oi)},set:(s,o)=>{const a=o*e+s;r(a>>>Na,1<<(a&oi))},clear:(s,o)=>{const a=o*e+s;i(a>>>Na,~(1<<(a&oi)))},getRange:(s,o,a,l)=>{let u=l,c,f,d,h;for(;u>=o;--u)if(c=u*e+s,f=u*e+a,d=c>>>Na,h=f>>>Na,d===h){if(n[d]&Rl[c&oi]&ro[(f&oi)+1])return!0}else{if(n[d]&Rl[c&oi]||n[h]&ro[(f&oi)+1])return!0;for(let p=d+1;p{let u,c,f,d,h;for(;o<=l;++o)if(u=o*e+s,c=o*e+a,f=u>>>Na,d=c>>>Na,f===d)r(f,Rl[u&oi]&ro[(c&oi)+1]);else for(r(f,Rl[u&oi]),r(d,ro[(c&oi)+1]),h=f+1;h{let u,c,f,d,h;for(;o<=l;++o)if(u=o*e+s,c=o*e+a,f=u>>>Na,d=c>>>Na,f===d)i(f,ro[u&oi]|Rl[(c&oi)+1]);else for(i(f,ro[u&oi]),i(d,Rl[(c&oi)+1]),h=f+1;hs<0||o<0||l>=t||a>=e}}function Rae(e,t,n){const r=Math.max(1,Math.sqrt(e*t/1e6)),i=~~((e+2*n+r)/r),s=~~((t+2*n+r)/r),o=a=>~~((a+n)/r);return o.invert=a=>a*r-n,o.bitmap=()=>Tae(i,s),o.ratio=r,o.padding=n,o.width=e,o.height=t,o}function Nae(e,t,n,r){const i=e.width,s=e.height;return function(o){const a=o.datum.datum.items[r].items,l=a.length,u=o.datum.fontSize,c=ls.width(o.datum,o.datum.text);let f=0,d,h,p,g,m,v,b;for(let x=0;x=f&&(f=b,o.x=m,o.y=v);return m=c/2,v=u/2,d=o.x-m,h=o.x+m,p=o.y-v,g=o.y+v,o.align="center",d<0&&h<=i?o.align="left":0<=d&&ii||t-(o=r/2)<0||t+o>s}function Gl(e,t,n,r,i,s,o,a){const l=i*s/(r*2),u=e(t-l),c=e(t+l),f=e(n-(s=s/2)),d=e(n+s);return o.outOfBounds(u,f,c,d)||o.getRange(u,f,c,d)||a&&a.getRange(u,f,c,d)}function Oae(e,t,n,r){const i=e.width,s=e.height,o=t[0],a=t[1];function l(u,c,f,d,h){const p=e.invert(u),g=e.invert(c);let m=f,v=s,b;if(!Yv(p,g,d,h,i,s)&&!Gl(e,p,g,h,d,m,o,a)&&!Gl(e,p,g,h,d,h,o,null)){for(;v-m>=1;)b=(m+v)/2,Gl(e,p,g,h,d,b,o,a)?v=b:m=b;if(m>f)return[p,g,m,!0]}}return function(u){const c=u.datum.datum.items[r].items,f=c.length,d=u.datum.fontSize,h=ls.width(u.datum,u.datum.text);let p=n?d:0,g=!1,m=!1,v=0,b,x,_,w,A,E,k,S,$,M,O,P,T,F,R,z,j;for(let q=0;qx&&(j=b,b=x,x=j),_>w&&(j=_,_=w,w=j),$=e(b),O=e(x),M=~~(($+O)/2),P=e(_),F=e(w),T=~~((P+F)/2),k=M;k>=$;--k)for(S=T;S>=P;--S)z=l(k,S,p,h,d),z&&([u.x,u.y,p,g]=z);for(k=M;k<=O;++k)for(S=T;S<=F;++S)z=l(k,S,p,h,d),z&&([u.x,u.y,p,g]=z);!g&&!n&&(R=Math.abs(x-b+w-_),A=(b+x)/2,E=(_+w)/2,R>=v&&!Yv(A,E,h,d,i,s)&&!Gl(e,A,E,d,h,d,o,null)&&(v=R,u.x=A,u.y=E,m=!0))}return g||m?(A=h/2,E=d/2,o.setRange(e(u.x-A),e(u.y-E),e(u.x+A),e(u.y+E)),u.align="center",u.baseline="middle",!0):!1}}const Lae=[-1,-1,1,1],Iae=[-1,1,-1,1];function Pae(e,t,n,r){const i=e.width,s=e.height,o=t[0],a=t[1],l=e.bitmap();return function(u){const c=u.datum.datum.items[r].items,f=c.length,d=u.datum.fontSize,h=ls.width(u.datum,u.datum.text),p=[];let g=n?d:0,m=!1,v=!1,b=0,x,_,w,A,E,k,S,$,M,O,P,T;for(let F=0;F=1;)P=(M+O)/2,Gl(e,E,k,d,h,P,o,a)?O=P:M=P;M>g&&(u.x=E,u.y=k,g=M,m=!0)}}!m&&!n&&(T=Math.abs(_-x+A-w),E=(x+_)/2,k=(w+A)/2,T>=b&&!Yv(E,k,h,d,i,s)&&!Gl(e,E,k,d,h,d,o,null)&&(b=T,u.x=E,u.y=k,v=!0))}return m||v?(E=h/2,k=d/2,o.setRange(e(u.x-E),e(u.y-k),e(u.x+E),e(u.y+k)),u.align="center",u.baseline="middle",!0):!1}}const Bae=["right","center","left"],zae=["bottom","middle","top"];function jae(e,t,n,r){const i=e.width,s=e.height,o=t[0],a=t[1],l=r.length;return function(u){const c=u.boundary,f=u.datum.fontSize;if(c[2]<0||c[5]<0||c[0]>i||c[3]>s)return!1;let d=u.textWidth??0,h,p,g,m,v,b,x,_,w,A,E,k,S,$,M;for(let O=0;O>>2&3)-1,g=h===0&&p===0||r[O]<0,m=h&&p?Math.SQRT1_2:1,v=r[O]<0?-1:1,b=c[1+h]+r[O]*h*m,E=c[4+p]+v*f*p/2+r[O]*p*m,_=E-f/2,w=E+f/2,k=e(b),$=e(_),M=e(w),!d)if(sM(k,k,$,M,o,a,b,b,_,w,c,g))d=ls.width(u.datum,u.datum.text);else continue;if(A=b+v*d*h/2,b=A-d/2,x=A+d/2,k=e(b),S=e(x),sM(k,S,$,M,o,a,b,x,_,w,c,g))return u.x=h?h*v<0?x:b:A,u.y=p?p*v<0?w:_:E,u.align=Bae[h*v+1],u.baseline=zae[p*v+1],o.setRange(k,$,S,M),!0}return!1}}function sM(e,t,n,r,i,s,o,a,l,u,c,f){return!(i.outOfBounds(e,n,t,r)||(f&&s||i).getRange(e,n,t,r))}const qx=0,Wx=4,Hx=8,Gx=0,Yx=1,Vx=2,Uae={"top-left":qx+Gx,top:qx+Yx,"top-right":qx+Vx,left:Wx+Gx,middle:Wx+Yx,right:Wx+Vx,"bottom-left":Hx+Gx,bottom:Hx+Yx,"bottom-right":Hx+Vx},qae={naive:Nae,"reduced-search":Oae,floodfill:Pae};function Wae(e,t,n,r,i,s,o,a,l,u,c){if(!e.length)return e;const f=Math.max(r.length,i.length),d=Hae(r,f),h=Gae(i,f),p=Yae(e[0].datum),g=p==="group"&&e[0].datum.items[l].marktype,m=g==="area",v=Vae(p,g,a,l),b=u===null||u===1/0,x=m&&c==="naive";let _=-1,w=-1;const A=e.map($=>{const M=b?ls.width($,$.text):void 0;return _=Math.max(_,M),w=Math.max(w,$.fontSize),{datum:$,opacity:0,x:void 0,y:void 0,align:void 0,baseline:void 0,boundary:v($),textWidth:M}});u=u===null||u===1/0?Math.max(_,w)+Math.max(...r):u;const E=Rae(t[0],t[1],u);let k;if(!x){n&&A.sort((O,P)=>n(O.datum,P.datum));let $=!1;for(let O=0;OO.datum);k=s.length||M?Dae(E,M||[],s,$,m):Fae(E,o&&A)}const S=m?qae[c](E,k,o,l):jae(E,k,h,d);return A.forEach($=>$.opacity=+S($)),A}function Hae(e,t){const n=new Float64Array(t),r=e.length;for(let i=0;i[s.x,s.x,s.x,s.y,s.y,s.y];return e?e==="line"||e==="area"?s=>i(s.datum):t==="line"?s=>{const o=s.datum.items[r].items;return i(o.length?o[n==="start"?0:o.length-1]:{x:NaN,y:NaN})}:s=>{const o=s.datum.bounds;return[o.x1,(o.x1+o.x2)/2,o.x2,o.y1,(o.y1+o.y2)/2,o.y2]}:i}const LE=["x","y","opacity","align","baseline"],yP=["top-left","left","bottom-left","top","bottom","top-right","right","bottom-right"];function mC(e){ne.call(this,null,e)}mC.Definition={type:"Label",metadata:{modifies:!0},params:[{name:"size",type:"number",array:!0,length:2,required:!0},{name:"sort",type:"compare"},{name:"anchor",type:"string",array:!0,default:yP},{name:"offset",type:"number",array:!0,default:[1]},{name:"padding",type:"number",default:0,null:!0},{name:"lineAnchor",type:"string",values:["start","end"],default:"end"},{name:"markIndex",type:"number",default:0},{name:"avoidBaseMark",type:"boolean",default:!0},{name:"avoidMarks",type:"data",array:!0},{name:"method",type:"string",default:"naive"},{name:"as",type:"string",array:!0,length:LE.length,default:LE}]};Te(mC,ne,{transform(e,t){function n(s){const o=e[s];return St(o)&&t.modified(o.fields)}const r=e.modified();if(!(r||t.changed(t.ADD_REM)||n("sort")))return;(!e.size||e.size.length!==2)&&ae("Size parameter should be specified as a [width, height] array.");const i=e.as||LE;return Wae(t.materialize(t.SOURCE).source||[],e.size,e.sort,je(e.offset==null?1:e.offset),je(e.anchor||yP),e.avoidMarks||[],e.avoidBaseMark!==!1,e.lineAnchor||"end",e.markIndex||0,e.padding===void 0?0:e.padding,e.method||"naive").forEach(s=>{const o=s.datum;o[i[0]]=s.x,o[i[1]]=s.y,o[i[2]]=s.opacity,o[i[3]]=s.align,o[i[4]]=s.baseline}),t.reflow(r).modifies(i)}});const Xae=Object.freeze(Object.defineProperty({__proto__:null,label:mC},Symbol.toStringTag,{value:"Module"}));function bP(e,t){var n=[],r=function(c){return c(a)},i,s,o,a,l,u;if(t==null)n.push(e);else for(i={},s=0,o=e.length;s{SO(u,e.x,e.y,e.bandwidth||.3).forEach(c=>{const f={};for(let d=0;de==="poly"?t:e==="quad"?2:1;function yC(e){ne.call(this,null,e)}yC.Definition={type:"Regression",metadata:{generates:!0},params:[{name:"x",type:"field",required:!0},{name:"y",type:"field",required:!0},{name:"groupby",type:"field",array:!0},{name:"method",type:"string",default:"linear",values:Object.keys(IE)},{name:"order",type:"number",default:3},{name:"extent",type:"number",array:!0,length:2},{name:"params",type:"boolean",default:!1},{name:"as",type:"string",array:!0}]};Te(yC,ne,{transform(e,t){const n=t.fork(t.NO_SOURCE|t.NO_FIELDS);if(!this.value||t.changed()||e.modified()){const r=t.materialize(t.SOURCE).source,i=bP(r,e.groupby),s=(e.groupby||[]).map(On),o=e.method||"linear",a=e.order==null?3:e.order,l=Kae(o,a),u=e.as||[On(e.x),On(e.y)],c=IE[o],f=[];let d=e.extent;We(IE,o)||ae("Invalid regression method: "+o),d!=null&&o==="log"&&d[0]<=0&&(t.dataflow.warn("Ignoring extent with values <= 0 for log regression."),d=null),i.forEach(h=>{if(h.length<=l){t.dataflow.warn("Skipping regression with more parameters than data points.");return}const g=c(h,e.x,e.y,a);if(e.params){f.push(Kt({keys:h.dims,coef:g.coef,rSquared:g.rSquared}));return}const m=d||aa(h,e.x),v=b=>{const x={};for(let _=0;_v([b,g.predict(b)])):Gy(g.predict,m,25,200).forEach(v)}),this.value&&(n.rem=this.value),this.value=n.add=n.source=f}return n}});const Zae=Object.freeze(Object.defineProperty({__proto__:null,loess:vC,regression:yC},Symbol.toStringTag,{value:"Module"})),tl=11102230246251565e-32,zr=134217729,Jae=(3+8*tl)*tl;function Xx(e,t,n,r,i){let s,o,a,l,u=t[0],c=r[0],f=0,d=0;c>u==c>-u?(s=u,u=t[++f]):(s=c,c=r[++d]);let h=0;if(fu==c>-u?(o=u+s,a=s-(o-u),u=t[++f]):(o=c+s,a=s-(o-c),c=r[++d]),s=o,a!==0&&(i[h++]=a);fu==c>-u?(o=s+u,l=o-s,a=s-(o-l)+(u-l),u=t[++f]):(o=s+c,l=o-s,a=s-(o-l)+(c-l),c=r[++d]),s=o,a!==0&&(i[h++]=a);for(;f=T||-P>=T||(f=e-S,a=e-(S+f)+(f-i),f=n-$,u=n-($+f)+(f-i),f=t-M,l=t-(M+f)+(f-s),f=r-O,c=r-(O+f)+(f-s),a===0&&l===0&&u===0&&c===0)||(T=nle*o+Jae*Math.abs(P),P+=S*c+O*a-(M*u+$*l),P>=T||-P>=T))return P;_=a*O,d=zr*a,h=d-(d-a),p=a-h,d=zr*O,g=d-(d-O),m=O-g,w=p*m-(_-h*g-p*g-h*m),A=l*$,d=zr*l,h=d-(d-l),p=l-h,d=zr*$,g=d-(d-$),m=$-g,E=p*m-(A-h*g-p*g-h*m),v=w-E,f=w-v,ai[0]=w-(v+f)+(f-E),b=_+v,f=b-_,x=_-(b-f)+(v-f),v=x-A,f=x-v,ai[1]=x-(v+f)+(f-A),k=b+v,f=k-b,ai[2]=b-(k-f)+(v-f),ai[3]=k;const F=Xx(4,Pf,4,ai,oM);_=S*c,d=zr*S,h=d-(d-S),p=S-h,d=zr*c,g=d-(d-c),m=c-g,w=p*m-(_-h*g-p*g-h*m),A=M*u,d=zr*M,h=d-(d-M),p=M-h,d=zr*u,g=d-(d-u),m=u-g,E=p*m-(A-h*g-p*g-h*m),v=w-E,f=w-v,ai[0]=w-(v+f)+(f-E),b=_+v,f=b-_,x=_-(b-f)+(v-f),v=x-A,f=x-v,ai[1]=x-(v+f)+(f-A),k=b+v,f=k-b,ai[2]=b-(k-f)+(v-f),ai[3]=k;const R=Xx(F,oM,4,ai,aM);_=a*c,d=zr*a,h=d-(d-a),p=a-h,d=zr*c,g=d-(d-c),m=c-g,w=p*m-(_-h*g-p*g-h*m),A=l*u,d=zr*l,h=d-(d-l),p=l-h,d=zr*u,g=d-(d-u),m=u-g,E=p*m-(A-h*g-p*g-h*m),v=w-E,f=w-v,ai[0]=w-(v+f)+(f-E),b=_+v,f=b-_,x=_-(b-f)+(v-f),v=x-A,f=x-v,ai[1]=x-(v+f)+(f-A),k=b+v,f=k-b,ai[2]=b-(k-f)+(v-f),ai[3]=k;const z=Xx(R,aM,4,ai,lM);return lM[z-1]}function Sm(e,t,n,r,i,s){const o=(t-s)*(n-i),a=(e-i)*(r-s),l=o-a,u=Math.abs(o+a);return Math.abs(l)>=ele*u?l:-rle(e,t,n,r,i,s,u)}const uM=Math.pow(2,-52),Cm=new Uint32Array(512);class Vv{static from(t,n=lle,r=ule){const i=t.length,s=new Float64Array(i*2);for(let o=0;o>1;if(n>0&&typeof t[0]!="number")throw new Error("Expected coords to contain numbers.");this.coords=t;const r=Math.max(2*n-5,0);this._triangles=new Uint32Array(r*3),this._halfedges=new Int32Array(r*3),this._hashSize=Math.ceil(Math.sqrt(n)),this._hullPrev=new Uint32Array(n),this._hullNext=new Uint32Array(n),this._hullTri=new Uint32Array(n),this._hullHash=new Int32Array(this._hashSize),this._ids=new Uint32Array(n),this._dists=new Float64Array(n),this.update()}update(){const{coords:t,_hullPrev:n,_hullNext:r,_hullTri:i,_hullHash:s}=this,o=t.length>>1;let a=1/0,l=1/0,u=-1/0,c=-1/0;for(let S=0;Su&&(u=$),M>c&&(c=M),this._ids[S]=S}const f=(a+u)/2,d=(l+c)/2;let h,p,g;for(let S=0,$=1/0;S0&&(p=S,$=M)}let b=t[2*p],x=t[2*p+1],_=1/0;for(let S=0;SO&&(S[$++]=P,O=T)}this.hull=S.subarray(0,$),this.triangles=new Uint32Array(0),this.halfedges=new Uint32Array(0);return}if(Sm(m,v,b,x,w,A)<0){const S=p,$=b,M=x;p=g,b=w,x=A,g=S,w=$,A=M}const E=ale(m,v,b,x,w,A);this._cx=E.x,this._cy=E.y;for(let S=0;S0&&Math.abs(P-$)<=uM&&Math.abs(T-M)<=uM||($=P,M=T,O===h||O===p||O===g))continue;let F=0;for(let te=0,Y=this._hashKey(P,T);te=0;)if(R=z,R===F){R=-1;break}if(R===-1)continue;let j=this._addTriangle(R,O,r[R],-1,-1,i[R]);i[O]=this._legalize(j+2),i[R]=j,k++;let q=r[R];for(;z=r[q],Sm(P,T,t[2*q],t[2*q+1],t[2*z],t[2*z+1])<0;)j=this._addTriangle(q,O,z,i[O],-1,i[q]),i[O]=this._legalize(j+2),r[q]=q,k--,q=z;if(R===F)for(;z=n[R],Sm(P,T,t[2*z],t[2*z+1],t[2*R],t[2*R+1])<0;)j=this._addTriangle(z,O,R,-1,i[R],i[z]),this._legalize(j+2),i[z]=j,r[R]=R,k--,R=z;this._hullStart=n[O]=R,r[R]=n[q]=O,r[O]=q,s[this._hashKey(P,T)]=O,s[this._hashKey(t[2*R],t[2*R+1])]=R}this.hull=new Uint32Array(k);for(let S=0,$=this._hullStart;S0?3-n:1+n)/4}function Kx(e,t,n,r){const i=e-n,s=t-r;return i*i+s*s}function sle(e,t,n,r,i,s,o,a){const l=e-o,u=t-a,c=n-o,f=r-a,d=i-o,h=s-a,p=l*l+u*u,g=c*c+f*f,m=d*d+h*h;return l*(f*m-g*h)-u*(c*m-g*d)+p*(c*h-f*d)<0}function ole(e,t,n,r,i,s){const o=n-e,a=r-t,l=i-e,u=s-t,c=o*o+a*a,f=l*l+u*u,d=.5/(o*u-a*l),h=(u*c-a*f)*d,p=(o*f-l*c)*d;return h*h+p*p}function ale(e,t,n,r,i,s){const o=n-e,a=r-t,l=i-e,u=s-t,c=o*o+a*a,f=l*l+u*u,d=.5/(o*u-a*l),h=e+(u*c-a*f)*d,p=t+(o*f-l*c)*d;return{x:h,y:p}}function td(e,t,n,r){if(r-n<=20)for(let i=n+1;i<=r;i++){const s=e[i],o=t[s];let a=i-1;for(;a>=n&&t[e[a]]>o;)e[a+1]=e[a--];e[a+1]=s}else{const i=n+r>>1;let s=n+1,o=r;ip(e,i,s),t[e[n]]>t[e[r]]&&ip(e,n,r),t[e[s]]>t[e[r]]&&ip(e,s,r),t[e[n]]>t[e[s]]&&ip(e,n,s);const a=e[s],l=t[a];for(;;){do s++;while(t[e[s]]l);if(o=o-n?(td(e,t,s,r),td(e,t,n,o-1)):(td(e,t,n,o-1),td(e,t,s,r))}}function ip(e,t,n){const r=e[t];e[t]=e[n],e[n]=r}function lle(e){return e[0]}function ule(e){return e[1]}const cM=1e-6;class mc{constructor(){this._x0=this._y0=this._x1=this._y1=null,this._=""}moveTo(t,n){this._+=`M${this._x0=this._x1=+t},${this._y0=this._y1=+n}`}closePath(){this._x1!==null&&(this._x1=this._x0,this._y1=this._y0,this._+="Z")}lineTo(t,n){this._+=`L${this._x1=+t},${this._y1=+n}`}arc(t,n,r){t=+t,n=+n,r=+r;const i=t+r,s=n;if(r<0)throw new Error("negative radius");this._x1===null?this._+=`M${i},${s}`:(Math.abs(this._x1-i)>cM||Math.abs(this._y1-s)>cM)&&(this._+="L"+i+","+s),r&&(this._+=`A${r},${r},0,1,1,${t-r},${n}A${r},${r},0,1,1,${this._x1=i},${this._y1=s}`)}rect(t,n,r,i){this._+=`M${this._x0=this._x1=+t},${this._y0=this._y1=+n}h${+r}v${+i}h${-r}Z`}value(){return this._||null}}class PE{constructor(){this._=[]}moveTo(t,n){this._.push([t,n])}closePath(){this._.push(this._[0].slice())}lineTo(t,n){this._.push([t,n])}value(){return this._.length?this._:null}}let cle=class{constructor(t,[n,r,i,s]=[0,0,960,500]){if(!((i=+i)>=(n=+n))||!((s=+s)>=(r=+r)))throw new Error("invalid bounds");this.delaunay=t,this._circumcenters=new Float64Array(t.points.length*2),this.vectors=new Float64Array(t.points.length*2),this.xmax=i,this.xmin=n,this.ymax=s,this.ymin=r,this._init()}update(){return this.delaunay.update(),this._init(),this}_init(){const{delaunay:{points:t,hull:n,triangles:r},vectors:i}=this;let s,o;const a=this.circumcenters=this._circumcenters.subarray(0,r.length/3*2);for(let g=0,m=0,v=r.length,b,x;g1;)s-=2;for(let o=2;o0){if(n>=this.ymax)return null;(o=(this.ymax-n)/i)0){if(t>=this.xmax)return null;(o=(this.xmax-t)/r)this.xmax?2:0)|(nthis.ymax?8:0)}_simplify(t){if(t&&t.length>4){for(let n=0;n1e-10)return!1}return!0}function gle(e,t,n){return[e+Math.sin(e+t)*n,t+Math.cos(e-t)*n]}class bC{static from(t,n=dle,r=hle,i){return new bC("length"in t?mle(t,n,r,i):Float64Array.from(vle(t,n,r,i)))}constructor(t){this._delaunator=new Vv(t),this.inedges=new Int32Array(t.length/2),this._hullIndex=new Int32Array(t.length/2),this.points=this._delaunator.coords,this._init()}update(){return this._delaunator.update(),this._init(),this}_init(){const t=this._delaunator,n=this.points;if(t.hull&&t.hull.length>2&&ple(t)){this.collinear=Int32Array.from({length:n.length/2},(d,h)=>h).sort((d,h)=>n[2*d]-n[2*h]||n[2*d+1]-n[2*h+1]);const l=this.collinear[0],u=this.collinear[this.collinear.length-1],c=[n[2*l],n[2*l+1],n[2*u],n[2*u+1]],f=1e-8*Math.hypot(c[3]-c[1],c[2]-c[0]);for(let d=0,h=n.length/2;d0&&(this.triangles=new Int32Array(3).fill(-1),this.halfedges=new Int32Array(3).fill(-1),this.triangles[0]=i[0],o[i[0]]=1,i.length===2&&(o[i[1]]=0,this.triangles[1]=i[1],this.triangles[2]=i[1]))}voronoi(t){return new cle(this,t)}*neighbors(t){const{inedges:n,hull:r,_hullIndex:i,halfedges:s,triangles:o,collinear:a}=this;if(a){const f=a.indexOf(t);f>0&&(yield a[f-1]),f=0&&s!==r&&s!==i;)r=s;return s}_step(t,n,r){const{inedges:i,hull:s,_hullIndex:o,halfedges:a,triangles:l,points:u}=this;if(i[t]===-1||!u.length)return(t+1)%(u.length>>1);let c=t,f=Bf(n-u[t*2],2)+Bf(r-u[t*2+1],2);const d=i[t];let h=d;do{let p=l[h];const g=Bf(n-u[p*2],2)+Bf(r-u[p*2+1],2);if(g>5)*e[1]),m=null,v=u.length,b=-1,x=[],_=u.map(A=>({text:t(A),font:n(A),style:i(A),weight:s(A),rotate:o(A),size:~~(r(A)+1e-14),padding:a(A),xoff:0,yoff:0,x1:0,y1:0,x0:0,y0:0,hasText:!1,sprite:null,datum:A})).sort((A,E)=>E.size-A.size);++b>1,w.y=e[1]*(c()+.5)>>1,Ele(p,w,_,b),w.hasText&&h(g,w,m)&&(x.push(w),m?kle(m,w):m=[{x:w.x+w.x0,y:w.y+w.y0},{x:w.x+w.x1,y:w.y+w.y1}],w.x-=e[0]>>1,w.y-=e[1]>>1)}return x};function d(p){p.width=p.height=1;var g=Math.sqrt(p.getContext("2d").getImageData(0,0,1,1).data.length>>2);p.width=(Lp<<5)/g,p.height=_1/g;var m=p.getContext("2d");return m.fillStyle=m.strokeStyle="red",m.textAlign="center",{context:m,ratio:g}}function h(p,g,m){for(var v=g.x,b=g.y,x=Math.hypot(e[0],e[1]),_=l(e),w=c()<.5?1:-1,A=-w,E,k,S;(E=_(A+=w))&&(k=~~E[0],S=~~E[1],!(Math.min(Math.abs(k),Math.abs(S))>=x));)if(g.x=v+k,g.y=b+S,!(g.x+g.x0<0||g.y+g.y0<0||g.x+g.x1>e[0]||g.y+g.y1>e[1])&&(!m||!Ale(g,p,e[0]))&&(!m||Sle(g,m))){for(var $=g.sprite,M=g.width>>5,O=e[0]>>5,P=g.x-(M<<4),T=P&127,F=32-T,R=g.y1-g.y0,z=(g.y+g.y0)*O+(P>>5),j,q=0;q>>T:0);z+=O}return g.sprite=null,!0}return!1}return f.words=function(p){return arguments.length?(u=p,f):u},f.size=function(p){return arguments.length?(e=[+p[0],+p[1]],f):e},f.font=function(p){return arguments.length?(n=Hu(p),f):n},f.fontStyle=function(p){return arguments.length?(i=Hu(p),f):i},f.fontWeight=function(p){return arguments.length?(s=Hu(p),f):s},f.rotate=function(p){return arguments.length?(o=Hu(p),f):o},f.text=function(p){return arguments.length?(t=Hu(p),f):t},f.spiral=function(p){return arguments.length?(l=Fle[p]||p,f):l},f.fontSize=function(p){return arguments.length?(r=Hu(p),f):r},f.padding=function(p){return arguments.length?(a=Hu(p),f):a},f.random=function(p){return arguments.length?(c=p,f):c},f}function Ele(e,t,n,r){if(!t.sprite){var i=e.context,s=e.ratio;i.clearRect(0,0,(Lp<<5)/s,_1/s);var o=0,a=0,l=0,u=n.length,c,f,d,h,p;for(--r;++r>5<<5,d=~~Math.max(Math.abs(b+x),Math.abs(b-x))}else c=c+31>>5<<5;if(d>l&&(l=d),o+c>=Lp<<5&&(o=0,a+=l,l=0),a+d>=_1)break;i.translate((o+(c>>1))/s,(a+(d>>1))/s),t.rotate&&i.rotate(t.rotate*Zx),i.fillText(t.text,0,0),t.padding&&(i.lineWidth=2*t.padding,i.strokeText(t.text,0,0)),i.restore(),t.width=c,t.height=d,t.xoff=o,t.yoff=a,t.x1=c>>1,t.y1=d>>1,t.x0=-t.x1,t.y0=-t.y1,t.hasText=!0,o+=c}for(var w=i.getImageData(0,0,(Lp<<5)/s,_1/s).data,A=[];--r>=0;)if(t=n[r],!!t.hasText){for(c=t.width,f=c>>5,d=t.y1-t.y0,h=0;h>5),$=w[(a+p)*(Lp<<5)+(o+h)<<2]?1<<31-h%32:0;A[S]|=$,E|=$}E?k=p:(t.y0++,d--,p--,a++)}t.y1=t.y0+k,t.sprite=A.slice(0,(t.y1-t.y0)*f)}}}function Ale(e,t,n){n>>=5;for(var r=e.sprite,i=e.width>>5,s=e.x-(i<<4),o=s&127,a=32-o,l=e.y1-e.y0,u=(e.y+e.y0)*n+(s>>5),c,f=0;f>>o:0))&t[u+d])return!0;u+=n}return!1}function kle(e,t){var n=e[0],r=e[1];t.x+t.x0r.x&&(r.x=t.x+t.x1),t.y+t.y1>r.y&&(r.y=t.y+t.y1)}function Sle(e,t){return e.x+e.x1>t[0].x&&e.x+e.x0t[0].y&&e.y+e.y0g(p(m))}i.forEach(p=>{p[o[0]]=NaN,p[o[1]]=NaN,p[o[3]]=0});const u=s.words(i).text(e.text).size(e.size||[500,500]).padding(e.padding||1).spiral(e.spiral||"archimedean").rotate(e.rotate||0).font(e.font||"sans-serif").fontStyle(e.fontStyle||"normal").fontWeight(e.fontWeight||"normal").fontSize(a).random(Is).layout(),c=s.size(),f=c[0]>>1,d=c[1]>>1,h=u.length;for(let p=0,g,m;pnew Uint8Array(e),Rle=e=>new Uint16Array(e),tg=e=>new Uint32Array(e);function Nle(){let e=8,t=[],n=tg(0),r=$m(0,e),i=$m(0,e);return{data:()=>t,seen:()=>n=Ole(n,t.length),add(s){for(let o=0,a=t.length,l=s.length,u;ot.length,curr:()=>r,prev:()=>i,reset:s=>i[s]=r[s],all:()=>e<257?255:e<65537?65535:4294967295,set(s,o){r[s]|=o},clear(s,o){r[s]&=~o},resize(s,o){const a=r.length;(s>a||o>e)&&(e=Math.max(o,e),r=$m(s,e,r),i=$m(s,e))}}}function Ole(e,t,n){return e.length>=t?e:(n=n||new e.constructor(t),n.set(e),n)}function $m(e,t,n){const r=(t<257?Tle:t<65537?Rle:tg)(e);return n&&r.set(n),r}function fM(e,t,n){const r=1<0)for(m=0;me,size:()=>n}}function Lle(e,t){return e.sort.call(t,(n,r)=>{const i=e[n],s=e[r];return is?1:0}),HY(e,t)}function Ile(e,t,n,r,i,s,o,a,l){let u=0,c=0,f;for(f=0;ut.modified(r.fields));return n?this.reinit(e,t):this.eval(e,t)}else return this.init(e,t)},init(e,t){const n=e.fields,r=e.query,i=this._indices={},s=this._dims=[],o=r.length;let a=0,l,u;for(;a{const s=i.remove(t,n);for(const o in r)r[o].reindex(s)})},update(e,t,n){const r=this._dims,i=e.query,s=t.stamp,o=r.length;let a=0,l,u;for(n.filters=0,u=0;uh)for(m=h,v=Math.min(f,p);mp)for(m=Math.max(f,p),v=d;mf)for(p=f,g=Math.min(u,d);pd)for(p=Math.max(u,d),g=c;pa[c]&n?null:o[c];return s.filter(s.MOD,u),i&i-1?(s.filter(s.ADD,c=>{const f=a[c]&n;return!f&&f^l[c]&n?o[c]:null}),s.filter(s.REM,c=>{const f=a[c]&n;return f&&!(f^(f^l[c]&n))?o[c]:null})):(s.filter(s.ADD,u),s.filter(s.REM,c=>(a[c]&n)===i?o[c]:null)),s.filter(s.SOURCE,c=>u(c._index))}});const Ple=Object.freeze(Object.defineProperty({__proto__:null,crossfilter:wC,resolvefilter:EC},Symbol.toStringTag,{value:"Module"})),Ble="RawCode",Vc="Literal",zle="Property",jle="Identifier",Ule="ArrayExpression",qle="BinaryExpression",wP="CallExpression",Wle="ConditionalExpression",Hle="LogicalExpression",Gle="MemberExpression",Yle="ObjectExpression",Vle="UnaryExpression";function Eo(e){this.type=e}Eo.prototype.visit=function(e){let t,n,r;if(e(this))return 1;for(t=Xle(this),n=0,r=t.length;n";wa[Xc]="Identifier";wa[$u]="Keyword";wa[Sb]="Null";wa[vf]="Numeric";wa[Di]="Punctuator";wa[F0]="String";wa[Kle]="RegularExpression";var Zle="ArrayExpression",Jle="BinaryExpression",Qle="CallExpression",eue="ConditionalExpression",EP="Identifier",tue="Literal",nue="LogicalExpression",rue="MemberExpression",iue="ObjectExpression",sue="Property",oue="UnaryExpression",lr="Unexpected token %0",aue="Unexpected number",lue="Unexpected string",uue="Unexpected identifier",cue="Unexpected reserved word",fue="Unexpected end of input",BE="Invalid regular expression",Jx="Invalid regular expression: missing /",AP="Octal literals are not allowed in strict mode.",due="Duplicate data property in object literal not allowed in strict mode",$r="ILLEGAL",Cg="Disabled.",hue=new RegExp("[\\xAA\\xB5\\xBA\\xC0-\\xD6\\xD8-\\xF6\\xF8-\\u02C1\\u02C6-\\u02D1\\u02E0-\\u02E4\\u02EC\\u02EE\\u0370-\\u0374\\u0376\\u0377\\u037A-\\u037D\\u037F\\u0386\\u0388-\\u038A\\u038C\\u038E-\\u03A1\\u03A3-\\u03F5\\u03F7-\\u0481\\u048A-\\u052F\\u0531-\\u0556\\u0559\\u0561-\\u0587\\u05D0-\\u05EA\\u05F0-\\u05F2\\u0620-\\u064A\\u066E\\u066F\\u0671-\\u06D3\\u06D5\\u06E5\\u06E6\\u06EE\\u06EF\\u06FA-\\u06FC\\u06FF\\u0710\\u0712-\\u072F\\u074D-\\u07A5\\u07B1\\u07CA-\\u07EA\\u07F4\\u07F5\\u07FA\\u0800-\\u0815\\u081A\\u0824\\u0828\\u0840-\\u0858\\u08A0-\\u08B2\\u0904-\\u0939\\u093D\\u0950\\u0958-\\u0961\\u0971-\\u0980\\u0985-\\u098C\\u098F\\u0990\\u0993-\\u09A8\\u09AA-\\u09B0\\u09B2\\u09B6-\\u09B9\\u09BD\\u09CE\\u09DC\\u09DD\\u09DF-\\u09E1\\u09F0\\u09F1\\u0A05-\\u0A0A\\u0A0F\\u0A10\\u0A13-\\u0A28\\u0A2A-\\u0A30\\u0A32\\u0A33\\u0A35\\u0A36\\u0A38\\u0A39\\u0A59-\\u0A5C\\u0A5E\\u0A72-\\u0A74\\u0A85-\\u0A8D\\u0A8F-\\u0A91\\u0A93-\\u0AA8\\u0AAA-\\u0AB0\\u0AB2\\u0AB3\\u0AB5-\\u0AB9\\u0ABD\\u0AD0\\u0AE0\\u0AE1\\u0B05-\\u0B0C\\u0B0F\\u0B10\\u0B13-\\u0B28\\u0B2A-\\u0B30\\u0B32\\u0B33\\u0B35-\\u0B39\\u0B3D\\u0B5C\\u0B5D\\u0B5F-\\u0B61\\u0B71\\u0B83\\u0B85-\\u0B8A\\u0B8E-\\u0B90\\u0B92-\\u0B95\\u0B99\\u0B9A\\u0B9C\\u0B9E\\u0B9F\\u0BA3\\u0BA4\\u0BA8-\\u0BAA\\u0BAE-\\u0BB9\\u0BD0\\u0C05-\\u0C0C\\u0C0E-\\u0C10\\u0C12-\\u0C28\\u0C2A-\\u0C39\\u0C3D\\u0C58\\u0C59\\u0C60\\u0C61\\u0C85-\\u0C8C\\u0C8E-\\u0C90\\u0C92-\\u0CA8\\u0CAA-\\u0CB3\\u0CB5-\\u0CB9\\u0CBD\\u0CDE\\u0CE0\\u0CE1\\u0CF1\\u0CF2\\u0D05-\\u0D0C\\u0D0E-\\u0D10\\u0D12-\\u0D3A\\u0D3D\\u0D4E\\u0D60\\u0D61\\u0D7A-\\u0D7F\\u0D85-\\u0D96\\u0D9A-\\u0DB1\\u0DB3-\\u0DBB\\u0DBD\\u0DC0-\\u0DC6\\u0E01-\\u0E30\\u0E32\\u0E33\\u0E40-\\u0E46\\u0E81\\u0E82\\u0E84\\u0E87\\u0E88\\u0E8A\\u0E8D\\u0E94-\\u0E97\\u0E99-\\u0E9F\\u0EA1-\\u0EA3\\u0EA5\\u0EA7\\u0EAA\\u0EAB\\u0EAD-\\u0EB0\\u0EB2\\u0EB3\\u0EBD\\u0EC0-\\u0EC4\\u0EC6\\u0EDC-\\u0EDF\\u0F00\\u0F40-\\u0F47\\u0F49-\\u0F6C\\u0F88-\\u0F8C\\u1000-\\u102A\\u103F\\u1050-\\u1055\\u105A-\\u105D\\u1061\\u1065\\u1066\\u106E-\\u1070\\u1075-\\u1081\\u108E\\u10A0-\\u10C5\\u10C7\\u10CD\\u10D0-\\u10FA\\u10FC-\\u1248\\u124A-\\u124D\\u1250-\\u1256\\u1258\\u125A-\\u125D\\u1260-\\u1288\\u128A-\\u128D\\u1290-\\u12B0\\u12B2-\\u12B5\\u12B8-\\u12BE\\u12C0\\u12C2-\\u12C5\\u12C8-\\u12D6\\u12D8-\\u1310\\u1312-\\u1315\\u1318-\\u135A\\u1380-\\u138F\\u13A0-\\u13F4\\u1401-\\u166C\\u166F-\\u167F\\u1681-\\u169A\\u16A0-\\u16EA\\u16EE-\\u16F8\\u1700-\\u170C\\u170E-\\u1711\\u1720-\\u1731\\u1740-\\u1751\\u1760-\\u176C\\u176E-\\u1770\\u1780-\\u17B3\\u17D7\\u17DC\\u1820-\\u1877\\u1880-\\u18A8\\u18AA\\u18B0-\\u18F5\\u1900-\\u191E\\u1950-\\u196D\\u1970-\\u1974\\u1980-\\u19AB\\u19C1-\\u19C7\\u1A00-\\u1A16\\u1A20-\\u1A54\\u1AA7\\u1B05-\\u1B33\\u1B45-\\u1B4B\\u1B83-\\u1BA0\\u1BAE\\u1BAF\\u1BBA-\\u1BE5\\u1C00-\\u1C23\\u1C4D-\\u1C4F\\u1C5A-\\u1C7D\\u1CE9-\\u1CEC\\u1CEE-\\u1CF1\\u1CF5\\u1CF6\\u1D00-\\u1DBF\\u1E00-\\u1F15\\u1F18-\\u1F1D\\u1F20-\\u1F45\\u1F48-\\u1F4D\\u1F50-\\u1F57\\u1F59\\u1F5B\\u1F5D\\u1F5F-\\u1F7D\\u1F80-\\u1FB4\\u1FB6-\\u1FBC\\u1FBE\\u1FC2-\\u1FC4\\u1FC6-\\u1FCC\\u1FD0-\\u1FD3\\u1FD6-\\u1FDB\\u1FE0-\\u1FEC\\u1FF2-\\u1FF4\\u1FF6-\\u1FFC\\u2071\\u207F\\u2090-\\u209C\\u2102\\u2107\\u210A-\\u2113\\u2115\\u2119-\\u211D\\u2124\\u2126\\u2128\\u212A-\\u212D\\u212F-\\u2139\\u213C-\\u213F\\u2145-\\u2149\\u214E\\u2160-\\u2188\\u2C00-\\u2C2E\\u2C30-\\u2C5E\\u2C60-\\u2CE4\\u2CEB-\\u2CEE\\u2CF2\\u2CF3\\u2D00-\\u2D25\\u2D27\\u2D2D\\u2D30-\\u2D67\\u2D6F\\u2D80-\\u2D96\\u2DA0-\\u2DA6\\u2DA8-\\u2DAE\\u2DB0-\\u2DB6\\u2DB8-\\u2DBE\\u2DC0-\\u2DC6\\u2DC8-\\u2DCE\\u2DD0-\\u2DD6\\u2DD8-\\u2DDE\\u2E2F\\u3005-\\u3007\\u3021-\\u3029\\u3031-\\u3035\\u3038-\\u303C\\u3041-\\u3096\\u309D-\\u309F\\u30A1-\\u30FA\\u30FC-\\u30FF\\u3105-\\u312D\\u3131-\\u318E\\u31A0-\\u31BA\\u31F0-\\u31FF\\u3400-\\u4DB5\\u4E00-\\u9FCC\\uA000-\\uA48C\\uA4D0-\\uA4FD\\uA500-\\uA60C\\uA610-\\uA61F\\uA62A\\uA62B\\uA640-\\uA66E\\uA67F-\\uA69D\\uA6A0-\\uA6EF\\uA717-\\uA71F\\uA722-\\uA788\\uA78B-\\uA78E\\uA790-\\uA7AD\\uA7B0\\uA7B1\\uA7F7-\\uA801\\uA803-\\uA805\\uA807-\\uA80A\\uA80C-\\uA822\\uA840-\\uA873\\uA882-\\uA8B3\\uA8F2-\\uA8F7\\uA8FB\\uA90A-\\uA925\\uA930-\\uA946\\uA960-\\uA97C\\uA984-\\uA9B2\\uA9CF\\uA9E0-\\uA9E4\\uA9E6-\\uA9EF\\uA9FA-\\uA9FE\\uAA00-\\uAA28\\uAA40-\\uAA42\\uAA44-\\uAA4B\\uAA60-\\uAA76\\uAA7A\\uAA7E-\\uAAAF\\uAAB1\\uAAB5\\uAAB6\\uAAB9-\\uAABD\\uAAC0\\uAAC2\\uAADB-\\uAADD\\uAAE0-\\uAAEA\\uAAF2-\\uAAF4\\uAB01-\\uAB06\\uAB09-\\uAB0E\\uAB11-\\uAB16\\uAB20-\\uAB26\\uAB28-\\uAB2E\\uAB30-\\uAB5A\\uAB5C-\\uAB5F\\uAB64\\uAB65\\uABC0-\\uABE2\\uAC00-\\uD7A3\\uD7B0-\\uD7C6\\uD7CB-\\uD7FB\\uF900-\\uFA6D\\uFA70-\\uFAD9\\uFB00-\\uFB06\\uFB13-\\uFB17\\uFB1D\\uFB1F-\\uFB28\\uFB2A-\\uFB36\\uFB38-\\uFB3C\\uFB3E\\uFB40\\uFB41\\uFB43\\uFB44\\uFB46-\\uFBB1\\uFBD3-\\uFD3D\\uFD50-\\uFD8F\\uFD92-\\uFDC7\\uFDF0-\\uFDFB\\uFE70-\\uFE74\\uFE76-\\uFEFC\\uFF21-\\uFF3A\\uFF41-\\uFF5A\\uFF66-\\uFFBE\\uFFC2-\\uFFC7\\uFFCA-\\uFFCF\\uFFD2-\\uFFD7\\uFFDA-\\uFFDC]"),pue=new RegExp("[\\xAA\\xB5\\xBA\\xC0-\\xD6\\xD8-\\xF6\\xF8-\\u02C1\\u02C6-\\u02D1\\u02E0-\\u02E4\\u02EC\\u02EE\\u0300-\\u0374\\u0376\\u0377\\u037A-\\u037D\\u037F\\u0386\\u0388-\\u038A\\u038C\\u038E-\\u03A1\\u03A3-\\u03F5\\u03F7-\\u0481\\u0483-\\u0487\\u048A-\\u052F\\u0531-\\u0556\\u0559\\u0561-\\u0587\\u0591-\\u05BD\\u05BF\\u05C1\\u05C2\\u05C4\\u05C5\\u05C7\\u05D0-\\u05EA\\u05F0-\\u05F2\\u0610-\\u061A\\u0620-\\u0669\\u066E-\\u06D3\\u06D5-\\u06DC\\u06DF-\\u06E8\\u06EA-\\u06FC\\u06FF\\u0710-\\u074A\\u074D-\\u07B1\\u07C0-\\u07F5\\u07FA\\u0800-\\u082D\\u0840-\\u085B\\u08A0-\\u08B2\\u08E4-\\u0963\\u0966-\\u096F\\u0971-\\u0983\\u0985-\\u098C\\u098F\\u0990\\u0993-\\u09A8\\u09AA-\\u09B0\\u09B2\\u09B6-\\u09B9\\u09BC-\\u09C4\\u09C7\\u09C8\\u09CB-\\u09CE\\u09D7\\u09DC\\u09DD\\u09DF-\\u09E3\\u09E6-\\u09F1\\u0A01-\\u0A03\\u0A05-\\u0A0A\\u0A0F\\u0A10\\u0A13-\\u0A28\\u0A2A-\\u0A30\\u0A32\\u0A33\\u0A35\\u0A36\\u0A38\\u0A39\\u0A3C\\u0A3E-\\u0A42\\u0A47\\u0A48\\u0A4B-\\u0A4D\\u0A51\\u0A59-\\u0A5C\\u0A5E\\u0A66-\\u0A75\\u0A81-\\u0A83\\u0A85-\\u0A8D\\u0A8F-\\u0A91\\u0A93-\\u0AA8\\u0AAA-\\u0AB0\\u0AB2\\u0AB3\\u0AB5-\\u0AB9\\u0ABC-\\u0AC5\\u0AC7-\\u0AC9\\u0ACB-\\u0ACD\\u0AD0\\u0AE0-\\u0AE3\\u0AE6-\\u0AEF\\u0B01-\\u0B03\\u0B05-\\u0B0C\\u0B0F\\u0B10\\u0B13-\\u0B28\\u0B2A-\\u0B30\\u0B32\\u0B33\\u0B35-\\u0B39\\u0B3C-\\u0B44\\u0B47\\u0B48\\u0B4B-\\u0B4D\\u0B56\\u0B57\\u0B5C\\u0B5D\\u0B5F-\\u0B63\\u0B66-\\u0B6F\\u0B71\\u0B82\\u0B83\\u0B85-\\u0B8A\\u0B8E-\\u0B90\\u0B92-\\u0B95\\u0B99\\u0B9A\\u0B9C\\u0B9E\\u0B9F\\u0BA3\\u0BA4\\u0BA8-\\u0BAA\\u0BAE-\\u0BB9\\u0BBE-\\u0BC2\\u0BC6-\\u0BC8\\u0BCA-\\u0BCD\\u0BD0\\u0BD7\\u0BE6-\\u0BEF\\u0C00-\\u0C03\\u0C05-\\u0C0C\\u0C0E-\\u0C10\\u0C12-\\u0C28\\u0C2A-\\u0C39\\u0C3D-\\u0C44\\u0C46-\\u0C48\\u0C4A-\\u0C4D\\u0C55\\u0C56\\u0C58\\u0C59\\u0C60-\\u0C63\\u0C66-\\u0C6F\\u0C81-\\u0C83\\u0C85-\\u0C8C\\u0C8E-\\u0C90\\u0C92-\\u0CA8\\u0CAA-\\u0CB3\\u0CB5-\\u0CB9\\u0CBC-\\u0CC4\\u0CC6-\\u0CC8\\u0CCA-\\u0CCD\\u0CD5\\u0CD6\\u0CDE\\u0CE0-\\u0CE3\\u0CE6-\\u0CEF\\u0CF1\\u0CF2\\u0D01-\\u0D03\\u0D05-\\u0D0C\\u0D0E-\\u0D10\\u0D12-\\u0D3A\\u0D3D-\\u0D44\\u0D46-\\u0D48\\u0D4A-\\u0D4E\\u0D57\\u0D60-\\u0D63\\u0D66-\\u0D6F\\u0D7A-\\u0D7F\\u0D82\\u0D83\\u0D85-\\u0D96\\u0D9A-\\u0DB1\\u0DB3-\\u0DBB\\u0DBD\\u0DC0-\\u0DC6\\u0DCA\\u0DCF-\\u0DD4\\u0DD6\\u0DD8-\\u0DDF\\u0DE6-\\u0DEF\\u0DF2\\u0DF3\\u0E01-\\u0E3A\\u0E40-\\u0E4E\\u0E50-\\u0E59\\u0E81\\u0E82\\u0E84\\u0E87\\u0E88\\u0E8A\\u0E8D\\u0E94-\\u0E97\\u0E99-\\u0E9F\\u0EA1-\\u0EA3\\u0EA5\\u0EA7\\u0EAA\\u0EAB\\u0EAD-\\u0EB9\\u0EBB-\\u0EBD\\u0EC0-\\u0EC4\\u0EC6\\u0EC8-\\u0ECD\\u0ED0-\\u0ED9\\u0EDC-\\u0EDF\\u0F00\\u0F18\\u0F19\\u0F20-\\u0F29\\u0F35\\u0F37\\u0F39\\u0F3E-\\u0F47\\u0F49-\\u0F6C\\u0F71-\\u0F84\\u0F86-\\u0F97\\u0F99-\\u0FBC\\u0FC6\\u1000-\\u1049\\u1050-\\u109D\\u10A0-\\u10C5\\u10C7\\u10CD\\u10D0-\\u10FA\\u10FC-\\u1248\\u124A-\\u124D\\u1250-\\u1256\\u1258\\u125A-\\u125D\\u1260-\\u1288\\u128A-\\u128D\\u1290-\\u12B0\\u12B2-\\u12B5\\u12B8-\\u12BE\\u12C0\\u12C2-\\u12C5\\u12C8-\\u12D6\\u12D8-\\u1310\\u1312-\\u1315\\u1318-\\u135A\\u135D-\\u135F\\u1380-\\u138F\\u13A0-\\u13F4\\u1401-\\u166C\\u166F-\\u167F\\u1681-\\u169A\\u16A0-\\u16EA\\u16EE-\\u16F8\\u1700-\\u170C\\u170E-\\u1714\\u1720-\\u1734\\u1740-\\u1753\\u1760-\\u176C\\u176E-\\u1770\\u1772\\u1773\\u1780-\\u17D3\\u17D7\\u17DC\\u17DD\\u17E0-\\u17E9\\u180B-\\u180D\\u1810-\\u1819\\u1820-\\u1877\\u1880-\\u18AA\\u18B0-\\u18F5\\u1900-\\u191E\\u1920-\\u192B\\u1930-\\u193B\\u1946-\\u196D\\u1970-\\u1974\\u1980-\\u19AB\\u19B0-\\u19C9\\u19D0-\\u19D9\\u1A00-\\u1A1B\\u1A20-\\u1A5E\\u1A60-\\u1A7C\\u1A7F-\\u1A89\\u1A90-\\u1A99\\u1AA7\\u1AB0-\\u1ABD\\u1B00-\\u1B4B\\u1B50-\\u1B59\\u1B6B-\\u1B73\\u1B80-\\u1BF3\\u1C00-\\u1C37\\u1C40-\\u1C49\\u1C4D-\\u1C7D\\u1CD0-\\u1CD2\\u1CD4-\\u1CF6\\u1CF8\\u1CF9\\u1D00-\\u1DF5\\u1DFC-\\u1F15\\u1F18-\\u1F1D\\u1F20-\\u1F45\\u1F48-\\u1F4D\\u1F50-\\u1F57\\u1F59\\u1F5B\\u1F5D\\u1F5F-\\u1F7D\\u1F80-\\u1FB4\\u1FB6-\\u1FBC\\u1FBE\\u1FC2-\\u1FC4\\u1FC6-\\u1FCC\\u1FD0-\\u1FD3\\u1FD6-\\u1FDB\\u1FE0-\\u1FEC\\u1FF2-\\u1FF4\\u1FF6-\\u1FFC\\u200C\\u200D\\u203F\\u2040\\u2054\\u2071\\u207F\\u2090-\\u209C\\u20D0-\\u20DC\\u20E1\\u20E5-\\u20F0\\u2102\\u2107\\u210A-\\u2113\\u2115\\u2119-\\u211D\\u2124\\u2126\\u2128\\u212A-\\u212D\\u212F-\\u2139\\u213C-\\u213F\\u2145-\\u2149\\u214E\\u2160-\\u2188\\u2C00-\\u2C2E\\u2C30-\\u2C5E\\u2C60-\\u2CE4\\u2CEB-\\u2CF3\\u2D00-\\u2D25\\u2D27\\u2D2D\\u2D30-\\u2D67\\u2D6F\\u2D7F-\\u2D96\\u2DA0-\\u2DA6\\u2DA8-\\u2DAE\\u2DB0-\\u2DB6\\u2DB8-\\u2DBE\\u2DC0-\\u2DC6\\u2DC8-\\u2DCE\\u2DD0-\\u2DD6\\u2DD8-\\u2DDE\\u2DE0-\\u2DFF\\u2E2F\\u3005-\\u3007\\u3021-\\u302F\\u3031-\\u3035\\u3038-\\u303C\\u3041-\\u3096\\u3099\\u309A\\u309D-\\u309F\\u30A1-\\u30FA\\u30FC-\\u30FF\\u3105-\\u312D\\u3131-\\u318E\\u31A0-\\u31BA\\u31F0-\\u31FF\\u3400-\\u4DB5\\u4E00-\\u9FCC\\uA000-\\uA48C\\uA4D0-\\uA4FD\\uA500-\\uA60C\\uA610-\\uA62B\\uA640-\\uA66F\\uA674-\\uA67D\\uA67F-\\uA69D\\uA69F-\\uA6F1\\uA717-\\uA71F\\uA722-\\uA788\\uA78B-\\uA78E\\uA790-\\uA7AD\\uA7B0\\uA7B1\\uA7F7-\\uA827\\uA840-\\uA873\\uA880-\\uA8C4\\uA8D0-\\uA8D9\\uA8E0-\\uA8F7\\uA8FB\\uA900-\\uA92D\\uA930-\\uA953\\uA960-\\uA97C\\uA980-\\uA9C0\\uA9CF-\\uA9D9\\uA9E0-\\uA9FE\\uAA00-\\uAA36\\uAA40-\\uAA4D\\uAA50-\\uAA59\\uAA60-\\uAA76\\uAA7A-\\uAAC2\\uAADB-\\uAADD\\uAAE0-\\uAAEF\\uAAF2-\\uAAF6\\uAB01-\\uAB06\\uAB09-\\uAB0E\\uAB11-\\uAB16\\uAB20-\\uAB26\\uAB28-\\uAB2E\\uAB30-\\uAB5A\\uAB5C-\\uAB5F\\uAB64\\uAB65\\uABC0-\\uABEA\\uABEC\\uABED\\uABF0-\\uABF9\\uAC00-\\uD7A3\\uD7B0-\\uD7C6\\uD7CB-\\uD7FB\\uF900-\\uFA6D\\uFA70-\\uFAD9\\uFB00-\\uFB06\\uFB13-\\uFB17\\uFB1D-\\uFB28\\uFB2A-\\uFB36\\uFB38-\\uFB3C\\uFB3E\\uFB40\\uFB41\\uFB43\\uFB44\\uFB46-\\uFBB1\\uFBD3-\\uFD3D\\uFD50-\\uFD8F\\uFD92-\\uFDC7\\uFDF0-\\uFDFB\\uFE00-\\uFE0F\\uFE20-\\uFE2D\\uFE33\\uFE34\\uFE4D-\\uFE4F\\uFE70-\\uFE74\\uFE76-\\uFEFC\\uFF10-\\uFF19\\uFF21-\\uFF3A\\uFF3F\\uFF41-\\uFF5A\\uFF66-\\uFFBE\\uFFC2-\\uFFC7\\uFFCA-\\uFFCF\\uFFD2-\\uFFD7\\uFFDA-\\uFFDC]");function Cb(e,t){if(!e)throw new Error("ASSERT: "+t)}function Ba(e){return e>=48&&e<=57}function AC(e){return"0123456789abcdefABCDEF".includes(e)}function ng(e){return"01234567".includes(e)}function gue(e){return e===32||e===9||e===11||e===12||e===160||e>=5760&&[5760,6158,8192,8193,8194,8195,8196,8197,8198,8199,8200,8201,8202,8239,8287,12288,65279].includes(e)}function $g(e){return e===10||e===13||e===8232||e===8233}function D0(e){return e===36||e===95||e>=65&&e<=90||e>=97&&e<=122||e===92||e>=128&&hue.test(String.fromCharCode(e))}function Xv(e){return e===36||e===95||e>=65&&e<=90||e>=97&&e<=122||e>=48&&e<=57||e===92||e>=128&&pue.test(String.fromCharCode(e))}const mue={if:1,in:1,do:1,var:1,for:1,new:1,try:1,let:1,this:1,else:1,case:1,void:1,with:1,enum:1,while:1,break:1,catch:1,throw:1,const:1,yield:1,class:1,super:1,return:1,typeof:1,delete:1,switch:1,export:1,import:1,public:1,static:1,default:1,finally:1,extends:1,package:1,private:1,function:1,continue:1,debugger:1,interface:1,protected:1,instanceof:1,implements:1};function kP(){for(;ue1114111||e!=="}")&&Wt({},lr,$r),t<=65535?String.fromCharCode(t):(n=(t-65536>>10)+55296,r=(t-65536&1023)+56320,String.fromCharCode(n,r))}function SP(){var e,t;for(e=Je.charCodeAt(ue++),t=String.fromCharCode(e),e===92&&(Je.charCodeAt(ue)!==117&&Wt({},lr,$r),++ue,e=zE("u"),(!e||e==="\\"||!D0(e.charCodeAt(0)))&&Wt({},lr,$r),t=e);ue>>=")return ue+=4,{type:Di,value:o,start:e,end:ue};if(s=o.substr(0,3),s===">>>"||s==="<<="||s===">>=")return ue+=3,{type:Di,value:s,start:e,end:ue};if(i=s.substr(0,2),r===i[1]&&"+-<>&|".includes(r)||i==="=>")return ue+=2,{type:Di,value:i,start:e,end:ue};if(i==="//"&&Wt({},lr,$r),"<>=!+-*%&|^/".includes(r))return++ue,{type:Di,value:r,start:e,end:ue};Wt({},lr,$r)}function xue(e){let t="";for(;ue{if(parseInt(i,16)<=1114111)return"x";Wt({},BE)}).replace(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g,"x"));try{new RegExp(n)}catch{Wt({},BE)}try{return new RegExp(e,t)}catch{return null}}function Aue(){var e,t,n,r,i;for(e=Je[ue],Cb(e==="/","Regular expression literal must start with a slash"),t=Je[ue++],n=!1,r=!1;ue=0&&Wt({},BE,n),{value:n,literal:t}}function Sue(){var e,t,n,r;return tn=null,kP(),e=ue,t=Aue(),n=kue(),r=Eue(t.value,n.value),{literal:t.literal+n.literal,value:r,regex:{pattern:t.value,flags:n.value},start:e,end:ue}}function Cue(e){return e.type===Xc||e.type===$u||e.type===kb||e.type===Sb}function CP(){if(kP(),ue>=Xr)return{type:$0,start:ue,end:ue};const e=Je.charCodeAt(ue);return D0(e)?bue():e===40||e===41||e===59?Qx():e===39||e===34?wue():e===46?Ba(Je.charCodeAt(ue+1))?hM():Qx():Ba(e)?hM():Qx()}function Ni(){const e=tn;return ue=e.end,tn=CP(),ue=e.end,e}function $P(){const e=ue;tn=CP(),ue=e}function $ue(e){const t=new Eo(Zle);return t.elements=e,t}function pM(e,t,n){const r=new Eo(e==="||"||e==="&&"?nue:Jle);return r.operator=e,r.left=t,r.right=n,r}function Fue(e,t){const n=new Eo(Qle);return n.callee=e,n.arguments=t,n}function Due(e,t,n){const r=new Eo(eue);return r.test=e,r.consequent=t,r.alternate=n,r}function kC(e){const t=new Eo(EP);return t.name=e,t}function Ip(e){const t=new Eo(tue);return t.value=e.value,t.raw=Je.slice(e.start,e.end),e.regex&&(t.raw==="//"&&(t.raw="/(?:)/"),t.regex=e.regex),t}function gM(e,t,n){const r=new Eo(rue);return r.computed=e==="[",r.object=t,r.property=n,r.computed||(n.member=!0),r}function Mue(e){const t=new Eo(iue);return t.properties=e,t}function mM(e,t,n){const r=new Eo(sue);return r.key=t,r.value=n,r.kind=e,r}function Tue(e,t){const n=new Eo(oue);return n.operator=e,n.argument=t,n.prefix=!0,n}function Wt(e,t){var n,r=Array.prototype.slice.call(arguments,2),i=t.replace(/%(\d)/g,(s,o)=>(Cb(o":case"<=":case">=":case"instanceof":case"in":t=7;break;case"<<":case">>":case">>>":t=8;break;case"+":case"-":t=9;break;case"*":case"/":case"%":t=11;break}return t}function Wue(){var e,t,n,r,i,s,o,a,l,u;if(e=tn,l=w1(),r=tn,i=bM(r),i===0)return l;for(r.prec=i,Ni(),t=[e,tn],o=w1(),s=[l,r,o];(i=bM(tn))>0;){for(;s.length>2&&i<=s[s.length-2].prec;)o=s.pop(),a=s.pop().value,l=s.pop(),t.pop(),n=pM(a,l,o),s.push(n);r=Ni(),r.prec=i,s.push(r),t.push(tn),n=w1(),s.push(n)}for(u=s.length-1,n=s[u],t.pop();u>1;)t.pop(),n=pM(s[u-1].value,s[u-2],n),u-=2;return n}function Kc(){var e,t,n;return e=Wue(),mn("?")&&(Ni(),t=Kc(),Kr(":"),n=Kc(),e=Due(e,t,n)),e}function SC(){const e=Kc();if(mn(","))throw new Error(Cg);return e}function FP(e){Je=e,ue=0,Xr=Je.length,tn=null,$P();const t=SC();if(tn.type!==$0)throw new Error("Unexpect token after expression.");return t}var DP={NaN:"NaN",E:"Math.E",LN2:"Math.LN2",LN10:"Math.LN10",LOG2E:"Math.LOG2E",LOG10E:"Math.LOG10E",PI:"Math.PI",SQRT1_2:"Math.SQRT1_2",SQRT2:"Math.SQRT2",MIN_VALUE:"Number.MIN_VALUE",MAX_VALUE:"Number.MAX_VALUE"};function MP(e){function t(o,a,l,u){let c=e(a[0]);return l&&(c=l+"("+c+")",l.lastIndexOf("new ",0)===0&&(c="("+c+")")),c+"."+o+(u<0?"":u===0?"()":"("+a.slice(1).map(e).join(",")+")")}function n(o,a,l){return u=>t(o,u,a,l)}const r="new Date",i="String",s="RegExp";return{isNaN:"Number.isNaN",isFinite:"Number.isFinite",abs:"Math.abs",acos:"Math.acos",asin:"Math.asin",atan:"Math.atan",atan2:"Math.atan2",ceil:"Math.ceil",cos:"Math.cos",exp:"Math.exp",floor:"Math.floor",hypot:"Math.hypot",log:"Math.log",max:"Math.max",min:"Math.min",pow:"Math.pow",random:"Math.random",round:"Math.round",sin:"Math.sin",sqrt:"Math.sqrt",tan:"Math.tan",clamp:function(o){o.length<3&&ae("Missing arguments to clamp function."),o.length>3&&ae("Too many arguments to clamp function.");const a=o.map(e);return"Math.max("+a[1]+", Math.min("+a[2]+","+a[0]+"))"},now:"Date.now",utc:"Date.UTC",datetime:r,date:n("getDate",r,0),day:n("getDay",r,0),year:n("getFullYear",r,0),month:n("getMonth",r,0),hours:n("getHours",r,0),minutes:n("getMinutes",r,0),seconds:n("getSeconds",r,0),milliseconds:n("getMilliseconds",r,0),time:n("getTime",r,0),timezoneoffset:n("getTimezoneOffset",r,0),utcdate:n("getUTCDate",r,0),utcday:n("getUTCDay",r,0),utcyear:n("getUTCFullYear",r,0),utcmonth:n("getUTCMonth",r,0),utchours:n("getUTCHours",r,0),utcminutes:n("getUTCMinutes",r,0),utcseconds:n("getUTCSeconds",r,0),utcmilliseconds:n("getUTCMilliseconds",r,0),length:n("length",null,-1),parseFloat:"parseFloat",parseInt:"parseInt",upper:n("toUpperCase",i,0),lower:n("toLowerCase",i,0),substring:n("substring",i),split:n("split",i),trim:n("trim",i,0),btoa:"btoa",atob:"atob",regexp:s,test:n("test",s),if:function(o){o.length<3&&ae("Missing arguments to if function."),o.length>3&&ae("Too many arguments to if function.");const a=o.map(e);return"("+a[0]+"?"+a[1]+":"+a[2]+")"}}}function Hue(e){const t=e&&e.length-1;return t&&(e[0]==='"'&&e[t]==='"'||e[0]==="'"&&e[t]==="'")?e.slice(1,-1):e}function TP(e){e=e||{};const t=e.allowed?mo(e.allowed):{},n=e.forbidden?mo(e.forbidden):{},r=e.constants||DP,i=(e.functions||MP)(f),s=e.globalvar,o=e.fieldvar,a=St(s)?s:p=>`${s}["${p}"]`;let l={},u={},c=0;function f(p){if(ze(p))return p;const g=d[p.type];return g==null&&ae("Unsupported type: "+p.type),g(p)}const d={Literal:p=>p.raw,Identifier:p=>{const g=p.name;return c>0?g:We(n,g)?ae("Illegal identifier: "+g):We(r,g)?r[g]:We(t,g)?g:(l[g]=1,a(g))},MemberExpression:p=>{const g=!p.computed,m=f(p.object);g&&(c+=1);const v=f(p.property);return m===o&&(u[Hue(v)]=1),g&&(c-=1),m+(g?"."+v:"["+v+"]")},CallExpression:p=>{p.callee.type!=="Identifier"&&ae("Illegal callee type: "+p.callee.type);const g=p.callee.name,m=p.arguments,v=We(i,g)&&i[g];return v||ae("Unrecognized function: "+g),St(v)?v(m):v+"("+m.map(f).join(",")+")"},ArrayExpression:p=>"["+p.elements.map(f).join(",")+"]",BinaryExpression:p=>"("+f(p.left)+" "+p.operator+" "+f(p.right)+")",UnaryExpression:p=>"("+p.operator+f(p.argument)+")",ConditionalExpression:p=>"("+f(p.test)+"?"+f(p.consequent)+":"+f(p.alternate)+")",LogicalExpression:p=>"("+f(p.left)+p.operator+f(p.right)+")",ObjectExpression:p=>{for(const g of p.properties){const m=g.key.name;uk.has(m)&&ae("Illegal property: "+m)}return"{"+p.properties.map(f).join(",")+"}"},Property:p=>{c+=1;const g=f(p.key);return c-=1,g+":"+f(p.value)}};function h(p){const g={code:f(p),globals:Object.keys(l),fields:Object.keys(u)};return l={},u={},g}return h.functions=i,h.constants=r,h}const xM=Symbol("vega_selection_getter");function RP(e){return(!e.getter||!e.getter[xM])&&(e.getter=Os(e.field),e.getter[xM]=!0),e.getter}const CC="intersect",_M="union",Gue="vlMulti",Yue="vlPoint",wM="or",Vue="and",Go="_vgsid_",Fg=Os(Go),Xue="E",Kue="R",Zue="R-E",Jue="R-LE",Que="R-RE",ece="E-LT",tce="E-LTE",nce="E-GT",rce="E-GTE",ice="E-VALID",sce="E-ONE",Kv="index:unit";function EM(e,t){for(var n=t.fields,r=t.values,i=n.length,s=0,o,a;s=r[s])return!1}else if(a.type===tce){if(o>r[s])return!1}else if(a.type===nce){if(o<=r[s])return!1}else if(a.type===rce){if(okt(t.fields?{values:t.fields.map(r=>RP(r)(n.datum))}:{[Go]:Fg(n.datum)},t))}function fce(e,t,n,r){for(var i=this.context.data[e],s=i?i.values.value:[],o={},a={},l={},u,c,f,d,h,p,g,m,v,b,x=s.length,_=0,w,A;_(E[c[S].field]=k,E),{})))}else h=Go,p=Fg(u),g=o[h]||(o[h]={}),m=g[d]||(g[d]=[]),m.push(p),n&&(m=a[d]||(a[d]=[]),m.push({[Go]:p}));if(t=t||_M,o[Go]?o[Go]=t_[`${Go}_${t}`](...Object.values(o[Go])):Object.keys(o).forEach(E=>{o[E]=Object.keys(o[E]).map(k=>o[E][k]).reduce((k,S)=>k===void 0?S:t_[`${l[E]}_${t}`](k,S))}),s=Object.keys(a),n&&s.length){const E=r?Yue:Gue;o[E]=t===_M?{[wM]:s.reduce((k,S)=>(k.push(...a[S]),k),[])}:{[Vue]:s.map(k=>({[wM]:a[k]}))}}return o}var t_={[`${Go}_union`]:eV,[`${Go}_intersect`]:JY,E_union:function(e,t){if(!e.length)return t;for(var n=0,r=t.length;nt.includes(n)):t},R_union:function(e,t){var n=Hr(t[0]),r=Hr(t[1]);return n>r&&(n=t[1],r=t[0]),e.length?(e[0]>n&&(e[0]=n),e[1]r&&(n=t[1],r=t[0]),e.length?rr&&(e[1]=r),e):[n,r]}};const dce=":",hce="@";function $C(e,t,n,r){t[0].type!==Vc&&ae("First argument to selection functions must be a string literal.");const i=t[0].value,s=t.length>=2&&jt(t).value,o="unit",a=hce+o,l=dce+i;s===CC&&!We(r,a)&&(r[a]=n.getData(i).indataRef(n,o)),We(r,l)||(r[l]=n.getData(i).tuplesRef())}function OP(e){const t=this.context.data[e];return t?t.values.value:[]}function pce(e,t,n){const r=this.context.data[e]["index:"+t],i=r?r.value.get(n):void 0;return i&&i.count}function gce(e,t){const n=this.context.dataflow,r=this.context.data[e],i=r.input;return n.pulse(i,n.changeset().remove(fs).insert(t)),1}function mce(e,t,n){if(e){const r=this.context.dataflow,i=e.mark.source;r.pulse(i,r.changeset().encode(e,t))}return n!==void 0?n:e}const M0=e=>function(t,n){const r=this.context.dataflow.locale();return t===null?"null":r[e](n)(t)},vce=M0("format"),LP=M0("timeFormat"),yce=M0("utcFormat"),bce=M0("timeParse"),xce=M0("utcParse"),Fm=new Date(2e3,0,1);function Fb(e,t,n){return!Number.isInteger(e)||!Number.isInteger(t)?"":(Fm.setYear(2e3),Fm.setMonth(e),Fm.setDate(t),LP.call(this,Fm,n))}function _ce(e){return Fb.call(this,e,1,"%B")}function wce(e){return Fb.call(this,e,1,"%b")}function Ece(e){return Fb.call(this,0,2+e,"%A")}function Ace(e){return Fb.call(this,0,2+e,"%a")}const kce=":",Sce="@",jE="%",IP="$";function FC(e,t,n,r){t[0].type!==Vc&&ae("First argument to data functions must be a string literal.");const i=t[0].value,s=kce+i;if(!We(s,r))try{r[s]=n.getData(i).tuplesRef()}catch{}}function Cce(e,t,n,r){t[0].type!==Vc&&ae("First argument to indata must be a string literal."),t[1].type!==Vc&&ae("Second argument to indata must be a string literal.");const i=t[0].value,s=t[1].value,o=Sce+s;We(o,r)||(r[o]=n.getData(i).indataRef(n,s))}function vi(e,t,n,r){if(t[0].type===Vc)AM(n,r,t[0].value);else for(e in n.scales)AM(n,r,e)}function AM(e,t,n){const r=jE+n;if(!We(t,r))try{t[r]=e.scaleRef(n)}catch{}}function Ea(e,t){if(ze(e)){const n=t.scales[e];return n&&CD(n.value)?n.value:void 0}else if(St(e))return CD(e)?e:void 0}function $ce(e,t,n){t.__bandwidth=i=>i&&i.bandwidth?i.bandwidth():0,n._bandwidth=vi,n._range=vi,n._scale=vi;const r=i=>"_["+(i.type===Vc?De(jE+i.value):De(jE)+"+"+e(i))+"]";return{_bandwidth:i=>`this.__bandwidth(${r(i[0])})`,_range:i=>`${r(i[0])}.range()`,_scale:i=>`${r(i[0])}(${e(i[1])})`}}function DC(e,t){return function(n,r,i){if(n){const s=Ea(n,(i||this).context);return s&&s.path[e](r)}else return t(r)}}const Fce=DC("area",Yre),Dce=DC("bounds",Zre),Mce=DC("centroid",rie);function Tce(e,t){const n=Ea(e,(t||this).context);return n&&n.scale()}function Rce(e){const t=this.context.group;let n=!1;if(t)for(;e;){if(e===t){n=!0;break}e=e.mark.group}return n}function MC(e,t,n){try{e[t].apply(e,["EXPRESSION"].concat([].slice.call(n)))}catch(r){e.warn(r)}return n[n.length-1]}function Nce(){return MC(this.context.dataflow,"warn",arguments)}function Oce(){return MC(this.context.dataflow,"info",arguments)}function Lce(){return MC(this.context.dataflow,"debug",arguments)}function n_(e){const t=e/255;return t<=.03928?t/12.92:Math.pow((t+.055)/1.055,2.4)}function UE(e){const t=lu(e),n=n_(t.r),r=n_(t.g),i=n_(t.b);return .2126*n+.7152*r+.0722*i}function Ice(e,t){const n=UE(e),r=UE(t),i=Math.max(n,r),s=Math.min(n,r);return(i+.05)/(s+.05)}function Pce(){const e=[].slice.call(arguments);return e.unshift({}),kt(...e)}function PP(e,t){return e===t||e!==e&&t!==t?!0:fe(e)?fe(t)&&e.length===t.length?Bce(e,t):!1:Pe(e)&&Pe(t)?BP(e,t):!1}function Bce(e,t){for(let n=0,r=e.length;nBP(e,t)}function zce(e,t,n,r,i,s){const o=this.context.dataflow,a=this.context.data[e],l=a.input,u=o.stamp();let c=a.changes,f,d;if(o._trigger===!1||!(l.value.length||t||r))return 0;if((!c||c.stamp{a.modified=!0,o.pulse(l,c).run()},!0,1)),n&&(f=n===!0?fs:fe(n)||Py(n)?n:kM(n),c.remove(f)),t&&c.insert(t),r&&(f=kM(r),l.value.some(f)?c.remove(f):c.insert(r)),i)for(d in s)c.modify(i,d,s[d]);return 1}function jce(e){const t=e.touches,n=t[0].clientX-t[1].clientX,r=t[0].clientY-t[1].clientY;return Math.hypot(n,r)}function Uce(e){const t=e.touches;return Math.atan2(t[0].clientY-t[1].clientY,t[0].clientX-t[1].clientX)}const SM={};function qce(e,t){const n=SM[t]||(SM[t]=Os(t));return fe(e)?e.map(n):n(e)}function Db(e){return fe(e)||ArrayBuffer.isView(e)?e:null}function TC(e){return Db(e)||(ze(e)?e:null)}function Wce(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r1?t-1:0),r=1;r1?t-1:0),r=1;r1?t-1:0),r=1;rs.stop(u(c),e(c))),s}function sfe(e,t,n){const r=Ea(e,(n||this).context);return function(i){return r?r.path.context(i)(t):""}}function ofe(e){let t=null;return function(n){return n?bg(n,t=t||jd(e)):e}}const zP=e=>e.data;function jP(e,t){const n=OP.call(t,e);return n.root&&n.root.lookup||{}}function afe(e,t,n){const r=jP(e,this),i=r[t],s=r[n];return i&&s?i.path(s).map(zP):void 0}function lfe(e,t){const n=jP(e,this)[t];return n?n.ancestors().map(zP):void 0}const UP=()=>typeof window<"u"&&window||null;function ufe(){const e=UP();return e?e.screen:{}}function cfe(){const e=UP();return e?[e.innerWidth,e.innerHeight]:[void 0,void 0]}function ffe(){const e=this.context.dataflow,t=e.container&&e.container();return t?[t.clientWidth,t.clientHeight]:[void 0,void 0]}function qP(e,t,n){if(!e)return[];const[r,i]=e,s=new Hn().set(r[0],r[1],i[0],i[1]),o=n||this.context.dataflow.scenegraph().root;return kL(o,s,dfe(t))}function dfe(e){let t=null;if(e){const n=je(e.marktype),r=je(e.markname);t=i=>(!n.length||n.some(s=>i.marktype===s))&&(!r.length||r.some(s=>i.name===s))}return t}function hfe(e,t,n){let r=arguments.length>3&&arguments[3]!==void 0?arguments[3]:5;e=je(e);const i=e[e.length-1];return i===void 0||Math.hypot(i[0]-t,i[1]-n)>r?[...e,[t,n]]:e}function pfe(e){return je(e).reduce((t,n,r)=>{let[i,s]=n;return t+=r==0?`M ${i},${s} `:r===e.length-1?" Z":`L ${i},${s} `},"")}function gfe(e,t,n){const{x:r,y:i,mark:s}=n,o=new Hn().set(Number.MAX_SAFE_INTEGER,Number.MAX_SAFE_INTEGER,Number.MIN_SAFE_INTEGER,Number.MIN_SAFE_INTEGER);for(const[l,u]of t)lo.x2&&(o.x2=l),uo.y2&&(o.y2=u);return o.translate(r,i),qP([[o.x1,o.y1],[o.x2,o.y2]],e,s).filter(l=>mfe(l.x,l.y,t))}function mfe(e,t,n){let r=0;for(let i=0,s=n.length-1;it!=a>t&&e<(o-l)*(t-u)/(a-u)+l&&r++}return r&1}const Dg={random(){return Is()},cumulativeNormal:qy,cumulativeLogNormal:Gk,cumulativeUniform:Kk,densityNormal:jk,densityLogNormal:Hk,densityUniform:Xk,quantileNormal:Wy,quantileLogNormal:Yk,quantileUniform:Zk,sampleNormal:Uy,sampleLogNormal:Wk,sampleUniform:Vk,isArray:fe,isBoolean:wu,isDate:Zl,isDefined(e){return e!==void 0},isNumber:Gt,isObject:Pe,isRegExp:yk,isString:ze,isTuple:Py,isValid(e){return e!=null&&e===e},toBoolean:xk,toDate(e){return _k(e)},toNumber:Hr,toString:wk,indexof:Hce,join:Wce,lastindexof:Gce,replace:Vce,reverse:Xce,sort:Kce,slice:Yce,flush:XR,lerp:ZR,merge:Pce,pad:eN,peek:jt,pluck:qce,span:i0,inrange:Zf,truncate:tN,rgb:lu,lab:nv,hcl:rv,hsl:ev,luminance:UE,contrast:Ice,sequence:is,format:vce,utcFormat:yce,utcParse:xce,utcOffset:RN,utcSequence:LN,timeFormat:LP,timeParse:bce,timeOffset:TN,timeSequence:ON,timeUnitSpecifier:_N,monthFormat:_ce,monthAbbrevFormat:wce,dayFormat:Ece,dayAbbrevFormat:Ace,quarter:HR,utcquarter:GR,week:EN,utcweek:SN,dayofyear:wN,utcdayofyear:kN,warn:Nce,info:Oce,debug:Lce,extent(e){return aa(e)},inScope:Rce,intersect:qP,clampRange:YR,pinchDistance:jce,pinchAngle:Uce,screen:ufe,containerSize:ffe,windowSize:cfe,bandspace:Zce,setdata:gce,pathShape:ofe,panLinear:jR,panLog:UR,panPow:qR,panSymlog:WR,zoomLinear:hk,zoomLog:pk,zoomPow:z1,zoomSymlog:gk,encode:mce,modify:zce,lassoAppend:hfe,lassoPath:pfe,intersectLasso:gfe},vfe=["view","item","group","xy","x","y"],yfe="event.vega.",WP="this.",RC={},HP={forbidden:["_"],allowed:["datum","event","item"],fieldvar:"datum",globalvar:e=>`_[${De(IP+e)}]`,functions:bfe,constants:DP,visitors:RC},qE=TP(HP);function bfe(e){const t=MP(e);vfe.forEach(n=>t[n]=yfe+n);for(const n in Dg)t[n]=WP+n;return kt(t,$ce(e,Dg,RC)),t}function qn(e,t,n){return arguments.length===1?Dg[e]:(Dg[e]=t,n&&(RC[e]=n),qE&&(qE.functions[e]=WP+e),this)}qn("bandwidth",Jce,vi);qn("copy",Qce,vi);qn("domain",efe,vi);qn("range",nfe,vi);qn("invert",tfe,vi);qn("scale",rfe,vi);qn("gradient",ife,vi);qn("geoArea",Fce,vi);qn("geoBounds",Dce,vi);qn("geoCentroid",Mce,vi);qn("geoShape",sfe,vi);qn("geoScale",Tce,vi);qn("indata",pce,Cce);qn("data",OP,FC);qn("treePath",afe,FC);qn("treeAncestors",lfe,FC);qn("vlSelectionTest",oce,$C);qn("vlSelectionIdTest",uce,$C);qn("vlSelectionResolve",fce,$C);qn("vlSelectionTuples",cce);function da(e,t){const n={};let r;try{e=ze(e)?e:De(e)+"",r=FP(e)}catch{ae("Expression parse error: "+e)}r.visit(s=>{if(s.type!==wP)return;const o=s.callee.name,a=HP.visitors[o];a&&a(o,s.arguments,t,n)});const i=qE(r);return i.globals.forEach(s=>{const o=IP+s;!We(n,o)&&t.getSignal(s)&&(n[o]=t.signalRef(s))}),{$expr:kt({code:i.code},t.options.ast?{ast:r}:null),$fields:i.fields,$params:n}}function xfe(e){const t=this,n=e.operators||[];return e.background&&(t.background=e.background),e.eventConfig&&(t.eventConfig=e.eventConfig),e.locale&&(t.locale=e.locale),n.forEach(r=>t.parseOperator(r)),n.forEach(r=>t.parseOperatorParameters(r)),(e.streams||[]).forEach(r=>t.parseStream(r)),(e.updates||[]).forEach(r=>t.parseUpdate(r)),t.resolve()}const _fe=mo(["rule"]),CM=mo(["group","image","rect"]);function wfe(e,t){let n="";return _fe[t]||(e.x2&&(e.x?(CM[t]&&(n+="if(o.x>o.x2)$=o.x,o.x=o.x2,o.x2=$;"),n+="o.width=o.x2-o.x;"):n+="o.x=o.x2-(o.width||0);"),e.xc&&(n+="o.x=o.xc-(o.width||0)/2;"),e.y2&&(e.y?(CM[t]&&(n+="if(o.y>o.y2)$=o.y,o.y=o.y2,o.y2=$;"),n+="o.height=o.y2-o.y;"):n+="o.y=o.y2-(o.height||0);"),e.yc&&(n+="o.y=o.yc-(o.height||0)/2;")),n}function NC(e){return(e+"").toLowerCase()}function Efe(e){return NC(e)==="operator"}function Afe(e){return NC(e)==="collect"}function sp(e,t,n){n.endsWith(";")||(n="return("+n+");");const r=Function(...t.concat(n));return e&&e.functions?r.bind(e.functions):r}function kfe(e,t,n,r){return`((u = ${e}) < (v = ${t}) || u == null) && v != null ? ${n} + : (u > v || v == null) && u != null ? ${r} + : ((v = v instanceof Date ? +v : v), (u = u instanceof Date ? +u : u)) !== u && v === v ? ${n} + : v !== v && u === u ? ${r} : `}var Sfe={operator:(e,t)=>sp(e,["_"],t.code),parameter:(e,t)=>sp(e,["datum","_"],t.code),event:(e,t)=>sp(e,["event"],t.code),handler:(e,t)=>{const n=`var datum=event.item&&event.item.datum;return ${t.code};`;return sp(e,["_","event"],n)},encode:(e,t)=>{const{marktype:n,channels:r}=t;let i="var o=item,datum=o.datum,m=0,$;";for(const s in r){const o="o["+De(s)+"]";i+=`$=${r[s].code};if(${o}!==$)${o}=$,m=1;`}return i+=wfe(r,n),i+="return m;",sp(e,["item","_"],i)},codegen:{get(e){const t=`[${e.map(De).join("][")}]`,n=Function("_",`return _${t};`);return n.path=t,n},comparator(e,t){let n;const r=(s,o)=>{const a=t[o];let l,u;return s.path?(l=`a${s.path}`,u=`b${s.path}`):((n=n||{})["f"+o]=s,l=`this.f${o}(a)`,u=`this.f${o}(b)`),kfe(l,u,-a,a)},i=Function("a","b","var u, v; return "+e.map(r).join("")+"0;");return n?i.bind(n):i}}};function Cfe(e){const t=this;Efe(e.type)||!e.type?t.operator(e,e.update?t.operatorExpression(e.update):null):t.transform(e,e.type)}function $fe(e){const t=this;if(e.params){const n=t.get(e.id);n||ae("Invalid operator id: "+e.id),t.dataflow.connect(n,n.parameters(t.parseParameters(e.params),e.react,e.initonly))}}function Ffe(e,t){t=t||{};const n=this;for(const r in e){const i=e[r];t[r]=fe(i)?i.map(s=>$M(s,n,t)):$M(i,n,t)}return t}function $M(e,t,n){if(!e||!Pe(e))return e;for(let r=0,i=FM.length,s;ri&&i.$tupleid?it:i);return t.fn[n]||(t.fn[n]=mk(r,e.$order,t.expr.codegen))}function Ofe(e,t){const n=e.$encode,r={};for(const i in n){const s=n[i];r[i]=Gi(t.encodeExpression(s.$expr),s.$fields),r[i].output=s.$output}return r}function Lfe(e,t){return t}function Ife(e,t){const n=e.$subflow;return function(r,i,s){const o=t.fork().parse(n),a=o.get(n.operators[0].id),l=o.signals.parent;return l&&l.set(s),a.detachSubflow=()=>t.detach(o),a}}function Pfe(){return it}function Bfe(e){var t=this,n=e.filter!=null?t.eventExpression(e.filter):void 0,r=e.stream!=null?t.get(e.stream):void 0,i;e.source?r=t.events(e.source,e.type,n):e.merge&&(i=e.merge.map(s=>t.get(s)),r=i[0].merge.apply(i[0],i.slice(1))),e.between&&(i=e.between.map(s=>t.get(s)),r=r.between(i[0],i[1])),e.filter&&(r=r.filter(n)),e.throttle!=null&&(r=r.throttle(+e.throttle)),e.debounce!=null&&(r=r.debounce(+e.debounce)),r==null&&ae("Invalid stream definition: "+JSON.stringify(e)),e.consume&&r.consume(!0),t.stream(e,r)}function zfe(e){var t=this,n=Pe(n=e.source)?n.$ref:n,r=t.get(n),i=null,s=e.update,o=void 0;r||ae("Source not defined: "+e.source),i=e.target&&e.target.$expr?t.eventExpression(e.target.$expr):t.get(e.target),s&&s.$expr&&(s.$params&&(o=t.parseParameters(s.$params)),s=t.handlerExpression(s.$expr)),t.update(e,r,i,s,o)}const jfe={skip:!0};function Ufe(e){var t=this,n={};if(e.signals){var r=n.signals={};Object.keys(t.signals).forEach(s=>{const o=t.signals[s];e.signals(s,o)&&(r[s]=o.value)})}if(e.data){var i=n.data={};Object.keys(t.data).forEach(s=>{const o=t.data[s];e.data(s,o)&&(i[s]=o.input.value)})}return t.subcontext&&e.recurse!==!1&&(n.subcontext=t.subcontext.map(s=>s.getState(e))),n}function qfe(e){var t=this,n=t.dataflow,r=e.data,i=e.signals;Object.keys(i||{}).forEach(s=>{n.update(t.signals[s],i[s],jfe)}),Object.keys(r||{}).forEach(s=>{n.pulse(t.data[s].input,n.changeset().remove(fs).insert(r[s]))}),(e.subcontext||[]).forEach((s,o)=>{const a=t.subcontext[o];a&&a.setState(s)})}function GP(e,t,n,r){return new YP(e,t,n,r)}function YP(e,t,n,r){this.dataflow=e,this.transforms=t,this.events=e.events.bind(e),this.expr=r||Sfe,this.signals={},this.scales={},this.nodes={},this.data={},this.fn={},n&&(this.functions=Object.create(n),this.functions.context=this)}function DM(e){this.dataflow=e.dataflow,this.transforms=e.transforms,this.events=e.events,this.expr=e.expr,this.signals=Object.create(e.signals),this.scales=Object.create(e.scales),this.nodes=Object.create(e.nodes),this.data=Object.create(e.data),this.fn=Object.create(e.fn),e.functions&&(this.functions=Object.create(e.functions),this.functions.context=this)}YP.prototype=DM.prototype={fork(){const e=new DM(this);return(this.subcontext||(this.subcontext=[])).push(e),e},detach(e){this.subcontext=this.subcontext.filter(n=>n!==e);const t=Object.keys(e.nodes);for(const n of t)e.nodes[n]._targets=null;for(const n of t)e.nodes[n].detach();e.nodes=null},get(e){return this.nodes[e]},set(e,t){return this.nodes[e]=t},add(e,t){const n=this,r=n.dataflow,i=e.value;if(n.set(e.id,t),Afe(e.type)&&i&&(i.$ingest?r.ingest(t,i.$ingest,i.$format):i.$request?r.preload(t,i.$request,i.$format):r.pulse(t,r.changeset().insert(i))),e.root&&(n.root=t),e.parent){let s=n.get(e.parent.$ref);s?(r.connect(s,[t]),t.targets().add(s)):(n.unresolved=n.unresolved||[]).push(()=>{s=n.get(e.parent.$ref),r.connect(s,[t]),t.targets().add(s)})}if(e.signal&&(n.signals[e.signal]=t),e.scale&&(n.scales[e.scale]=t),e.data)for(const s in e.data){const o=n.data[s]||(n.data[s]={});e.data[s].forEach(a=>o[a]=t)}},resolve(){return(this.unresolved||[]).forEach(e=>e()),delete this.unresolved,this},operator(e,t){this.add(e,this.dataflow.add(e.value,t))},transform(e,t){this.add(e,this.dataflow.add(this.transforms[NC(t)]))},stream(e,t){this.set(e.id,t)},update(e,t,n,r,i){this.dataflow.on(t,n,r,i,e.options)},operatorExpression(e){return this.expr.operator(this,e)},parameterExpression(e){return this.expr.parameter(this,e)},eventExpression(e){return this.expr.event(this,e)},handlerExpression(e){return this.expr.handler(this,e)},encodeExpression(e){return this.expr.encode(this,e)},parse:xfe,parseOperator:Cfe,parseOperatorParameters:$fe,parseParameters:Ffe,parseStream:Bfe,parseUpdate:zfe,getState:Ufe,setState:qfe};function Wfe(e){const t=e.container();t&&(t.setAttribute("role","graphics-document"),t.setAttribute("aria-roleDescription","visualization"),VP(t,e.description()))}function VP(e,t){e&&(t==null?e.removeAttribute("aria-label"):e.setAttribute("aria-label",t))}function Hfe(e){e.add(null,t=>(e._background=t.bg,e._resize=1,t.bg),{bg:e._signals.background})}const r_="default";function Gfe(e){const t=e._signals.cursor||(e._signals.cursor=e.add({user:r_,item:null}));e.on(e.events("view","pointermove"),t,(n,r)=>{const i=t.value,s=i?ze(i)?i:i.user:r_,o=r.item&&r.item.cursor||null;return i&&s===i.user&&o==i.item?i:{user:s,item:o}}),e.add(null,function(n){let r=n.cursor,i=this.value;return ze(r)||(i=r.item,r=r.user),WE(e,r&&r!==r_?r:i||r),i},{cursor:t})}function WE(e,t){const n=e.globalCursor()?typeof document<"u"&&document.body:e.container();if(n)return t==null?n.style.removeProperty("cursor"):n.style.cursor=t}function Zv(e,t){var n=e._runtime.data;return We(n,t)||ae("Unrecognized data set: "+t),n[t]}function Yfe(e,t){return arguments.length<2?Zv(this,e).values.value:Mb.call(this,e,Eu().remove(fs).insert(t))}function Mb(e,t){uO(t)||ae("Second argument to changes must be a changeset.");const n=Zv(this,e);return n.modified=!0,this.pulse(n.input,t)}function Vfe(e,t){return Mb.call(this,e,Eu().insert(t))}function Xfe(e,t){return Mb.call(this,e,Eu().remove(t))}function XP(e){var t=e.padding();return Math.max(0,e._viewWidth+t.left+t.right)}function KP(e){var t=e.padding();return Math.max(0,e._viewHeight+t.top+t.bottom)}function Tb(e){var t=e.padding(),n=e._origin;return[t.left+n[0],t.top+n[1]]}function Kfe(e){var t=Tb(e),n=XP(e),r=KP(e);e._renderer.background(e.background()),e._renderer.resize(n,r,t),e._handler.origin(t),e._resizeListeners.forEach(i=>{try{i(n,r)}catch(s){e.error(s)}})}function Zfe(e,t,n){var r=e._renderer,i=r&&r.canvas(),s,o,a;return i&&(a=Tb(e),o=t.changedTouches?t.changedTouches[0]:t,s=vb(o,i),s[0]-=a[0],s[1]-=a[1]),t.dataflow=e,t.item=n,t.vega=Jfe(e,n,s),t}function Jfe(e,t,n){const r=t?t.mark.marktype==="group"?t:t.mark.group:null;function i(o){var a=r,l;if(o){for(l=t;l;l=l.mark.group)if(l.mark.name===o){a=l;break}}return a&&a.mark&&a.mark.interactive?a:{}}function s(o){if(!o)return n;ze(o)&&(o=i(o));const a=n.slice();for(;o;)a[0]-=o.x||0,a[1]-=o.y||0,o=o.mark&&o.mark.group;return a}return{view:ei(e),item:ei(t||{}),group:i,xy:s,x:o=>s(o)[0],y:o=>s(o)[1]}}const MM="view",Qfe="timer",ede="window",tde={trap:!1};function nde(e){const t=kt({defaults:{}},e),n=(r,i)=>{i.forEach(s=>{fe(r[s])&&(r[s]=mo(r[s]))})};return n(t.defaults,["prevent","allow"]),n(t,["view","window","selector"]),t}function ZP(e,t,n,r){e._eventListeners.push({type:n,sources:je(t),handler:r})}function rde(e,t){var n=e._eventConfig.defaults,r=n.prevent,i=n.allow;return r===!1||i===!0?!1:r===!0||i===!1?!0:r?r[t]:i?!i[t]:e.preventDefault()}function Dm(e,t,n){const r=e._eventConfig&&e._eventConfig[t];return r===!1||Pe(r)&&!r[n]?(e.warn(`Blocked ${t} ${n} event listener.`),!1):!0}function ide(e,t,n){var r=this,i=new jy(n),s=function(u,c){r.runAsync(null,()=>{e===MM&&rde(r,t)&&u.preventDefault(),i.receive(Zfe(r,u,c))})},o;if(e===Qfe)Dm(r,"timer",t)&&r.timer(s,t);else if(e===MM)Dm(r,"view",t)&&r.addEventListener(t,s,tde);else if(e===ede?Dm(r,"window",t)&&typeof window<"u"&&(o=[window]):typeof document<"u"&&Dm(r,"selector",t)&&(o=Array.from(document.querySelectorAll(e))),!o)r.warn("Can not resolve event source: "+e);else{for(var a=0,l=o.length;a=0;)t[i].stop();for(i=r.length;--i>=0;)for(o=r[i],s=o.sources.length;--s>=0;)o.sources[s].removeEventListener(o.type,o.handler);for(e&&e.call(this,this._handler,null,null,null),i=n.length;--i>=0;)l=n[i].type,a=n[i].handler,this._handler.off(l,a);return this}function us(e,t,n){const r=document.createElement(e);for(const i in t)r.setAttribute(i,t[i]);return n!=null&&(r.textContent=n),r}const ade="vega-bind",lde="vega-bind-name",ude="vega-bind-radio";function cde(e,t,n){if(!t)return;const r=n.param;let i=n.state;return i||(i=n.state={elements:null,active:!1,set:null,update:o=>{o!=e.signal(r.signal)&&e.runAsync(null,()=>{i.source=!0,e.signal(r.signal,o)})}},r.debounce&&(i.update=vk(r.debounce,i.update))),(r.input==null&&r.element?fde:hde)(i,t,r,e),i.active||(e.on(e._signals[r.signal],null,()=>{i.source?i.source=!1:i.set(e.signal(r.signal))}),i.active=!0),i}function fde(e,t,n,r){const i=n.event||"input",s=()=>e.update(t.value);r.signal(n.signal,t.value),t.addEventListener(i,s),ZP(r,t,i,s),e.set=o=>{t.value=o,t.dispatchEvent(dde(i))}}function dde(e){return typeof Event<"u"?new Event(e):{type:e}}function hde(e,t,n,r){const i=r.signal(n.signal),s=us("div",{class:ade}),o=n.input==="radio"?s:s.appendChild(us("label"));o.appendChild(us("span",{class:lde},n.name||n.signal)),t.appendChild(s);let a=pde;switch(n.input){case"checkbox":a=gde;break;case"select":a=mde;break;case"radio":a=vde;break;case"range":a=yde;break}a(e,o,n,i)}function pde(e,t,n,r){const i=us("input");for(const s in n)s!=="signal"&&s!=="element"&&i.setAttribute(s==="input"?"type":s,n[s]);i.setAttribute("name",n.signal),i.value=r,t.appendChild(i),i.addEventListener("input",()=>e.update(i.value)),e.elements=[i],e.set=s=>i.value=s}function gde(e,t,n,r){const i={type:"checkbox",name:n.signal};r&&(i.checked=!0);const s=us("input",i);t.appendChild(s),s.addEventListener("change",()=>e.update(s.checked)),e.elements=[s],e.set=o=>s.checked=!!o||null}function mde(e,t,n,r){const i=us("select",{name:n.signal}),s=n.labels||[];n.options.forEach((o,a)=>{const l={value:o};Jv(o,r)&&(l.selected=!0),i.appendChild(us("option",l,(s[a]||o)+""))}),t.appendChild(i),i.addEventListener("change",()=>{e.update(n.options[i.selectedIndex])}),e.elements=[i],e.set=o=>{for(let a=0,l=n.options.length;a{const l={type:"radio",name:n.signal,value:o};Jv(o,r)&&(l.checked=!0);const u=us("input",l);u.addEventListener("change",()=>e.update(o));const c=us("label",{},(s[a]||o)+"");return c.prepend(u),i.appendChild(c),u}),e.set=o=>{const a=e.elements,l=a.length;for(let u=0;u{l.textContent=a.value,e.update(+a.value)};a.addEventListener("input",u),a.addEventListener("change",u),e.elements=[a],e.set=c=>{a.value=c,l.textContent=c}}function Jv(e,t){return e===t||e+""==t+""}function JP(e,t,n,r,i,s){return t=t||new r(e.loader()),t.initialize(n,XP(e),KP(e),Tb(e),i,s).background(e.background())}function OC(e,t){return t?function(){try{t.apply(this,arguments)}catch(n){e.error(n)}}:null}function bde(e,t,n,r){const i=new r(e.loader(),OC(e,e.tooltip())).scene(e.scenegraph().root).initialize(n,Tb(e),e);return t&&t.handlers().forEach(s=>{i.on(s.type,s.handler)}),i}function xde(e,t){const n=this,r=n._renderType,i=n._eventConfig.bind,s=yb(r);e=n._el=e?i_(n,e,!0):null,Wfe(n),s||n.error("Unrecognized renderer type: "+r);const o=s.handler||E0,a=e?s.renderer:s.headless;return n._renderer=a?JP(n,n._renderer,e,a):null,n._handler=bde(n,n._handler,e,o),n._redraw=!0,e&&i!=="none"&&(t=t?n._elBind=i_(n,t,!0):e.appendChild(us("form",{class:"vega-bindings"})),n._bind.forEach(l=>{l.param.element&&i!=="container"&&(l.element=i_(n,l.param.element,!!l.param.input))}),n._bind.forEach(l=>{cde(n,l.element||t,l)})),n}function i_(e,t,n){if(typeof t=="string")if(typeof document<"u"){if(t=document.querySelector(t),!t)return e.error("Signal bind element not found: "+t),null}else return e.error("DOM document instance not found."),null;if(t&&n)try{t.textContent=""}catch(r){t=null,e.error(r)}return t}const op=e=>+e||0,_de=e=>({top:e,bottom:e,left:e,right:e});function OM(e){return Pe(e)?{top:op(e.top),bottom:op(e.bottom),left:op(e.left),right:op(e.right)}:_de(op(e))}async function LC(e,t,n,r){const i=yb(t),s=i&&i.headless;return s||ae("Unrecognized renderer type: "+t),await e.runAsync(),JP(e,null,null,s,n,r).renderAsync(e._scenegraph.root)}async function wde(e,t){e!==Ul.Canvas&&e!==Ul.SVG&&e!==Ul.PNG&&ae("Unrecognized image type: "+e);const n=await LC(this,e,t);return e===Ul.SVG?Ede(n.svg(),"image/svg+xml"):n.canvas().toDataURL("image/png")}function Ede(e,t){const n=new Blob([e],{type:t});return window.URL.createObjectURL(n)}async function Ade(e,t){return(await LC(this,Ul.Canvas,e,t)).canvas()}async function kde(e){return(await LC(this,Ul.SVG,e)).svg()}function Sde(e,t,n){return GP(e,Od,Dg,n).parse(t)}function Cde(e){var t=this._runtime.scales;return We(t,e)||ae("Unrecognized scale or projection: "+e),t[e].value}var QP="width",eB="height",IC="padding",LM={skip:!0};function tB(e,t){var n=e.autosize(),r=e.padding();return t-(n&&n.contains===IC?r.left+r.right:0)}function nB(e,t){var n=e.autosize(),r=e.padding();return t-(n&&n.contains===IC?r.top+r.bottom:0)}function $de(e){var t=e._signals,n=t[QP],r=t[eB],i=t[IC];function s(){e._autosize=e._resize=1}e._resizeWidth=e.add(null,a=>{e._width=a.size,e._viewWidth=tB(e,a.size),s()},{size:n}),e._resizeHeight=e.add(null,a=>{e._height=a.size,e._viewHeight=nB(e,a.size),s()},{size:r});const o=e.add(null,s,{pad:i});e._resizeWidth.rank=n.rank+1,e._resizeHeight.rank=r.rank+1,o.rank=i.rank+1}function Fde(e,t,n,r,i,s){this.runAfter(o=>{let a=0;o._autosize=0,o.width()!==n&&(a=1,o.signal(QP,n,LM),o._resizeWidth.skip(!0)),o.height()!==r&&(a=1,o.signal(eB,r,LM),o._resizeHeight.skip(!0)),o._viewWidth!==e&&(o._resize=1,o._viewWidth=e),o._viewHeight!==t&&(o._resize=1,o._viewHeight=t),(o._origin[0]!==i[0]||o._origin[1]!==i[1])&&(o._resize=1,o._origin=i),a&&o.run("enter"),s&&o.runAfter(l=>l.resize())},!1,1)}function Dde(e){return this._runtime.getState(e||{data:Mde,signals:Tde,recurse:!0})}function Mde(e,t){return t.modified&&fe(t.input.value)&&!e.startsWith("_:vega:_")}function Tde(e,t){return!(e==="parent"||t instanceof Od.proxy)}function Rde(e){return this.runAsync(null,t=>{t._trigger=!1,t._runtime.setState(e)},t=>{t._trigger=!0}),this}function Nde(e,t){function n(r){e({timestamp:Date.now(),elapsed:r})}this._timers.push(ioe(n,t))}function Ode(e,t,n,r){const i=e.element();i&&i.setAttribute("title",Lde(r))}function Lde(e){return e==null?"":fe(e)?rB(e):Pe(e)&&!Zl(e)?Ide(e):e+""}function Ide(e){return Object.keys(e).map(t=>{const n=e[t];return t+": "+(fe(n)?rB(n):iB(n))}).join(` +`)}function rB(e){return"["+e.map(iB).join(", ")+"]"}function iB(e){return fe(e)?"[…]":Pe(e)&&!Zl(e)?"{…}":e}function Pde(){if(this.renderer()==="canvas"&&this._renderer._canvas){let e=null;const t=()=>{e!=null&&e();const n=matchMedia(`(resolution: ${window.devicePixelRatio}dppx)`);n.addEventListener("change",t),e=()=>{n.removeEventListener("change",t)},this._renderer._canvas.getContext("2d").pixelRatio=window.devicePixelRatio||1,this._redraw=!0,this._resize=1,this.resize().runAsync()};t()}}function sB(e,t){const n=this;if(t=t||{},sd.call(n),t.loader&&n.loader(t.loader),t.logger&&n.logger(t.logger),t.logLevel!=null&&n.logLevel(t.logLevel),t.locale||e.locale){const s=kt({},e.locale,t.locale);n.locale(QN(s.number,s.time))}n._el=null,n._elBind=null,n._renderType=t.renderer||Ul.Canvas,n._scenegraph=new J9;const r=n._scenegraph.root;n._renderer=null,n._tooltip=t.tooltip||Ode,n._redraw=!0,n._handler=new E0().scene(r),n._globalCursor=!1,n._preventDefault=!1,n._timers=[],n._eventListeners=[],n._resizeListeners=[],n._eventConfig=nde(e.eventConfig),n.globalCursor(n._eventConfig.globalCursor);const i=Sde(n,e,t.expr);n._runtime=i,n._signals=i.signals,n._bind=(e.bindings||[]).map(s=>({state:null,param:kt({},s)})),i.root&&i.root.set(r),r.source=i.data.root.input,n.pulse(i.data.root.input,n.changeset().insert(r.items)),n._width=n.width(),n._height=n.height(),n._viewWidth=tB(n,n._width),n._viewHeight=nB(n,n._height),n._origin=[0,0],n._resize=0,n._autosize=1,$de(n),Hfe(n),Gfe(n),n.description(e.description),t.hover&&n.hover(),t.container&&n.initialize(t.container,t.bind),t.watchPixelRatio&&n._watchPixelRatio()}function Mm(e,t){return We(e._signals,t)?e._signals[t]:ae("Unrecognized signal name: "+De(t))}function oB(e,t){const n=(e._targets||[]).filter(r=>r._update&&r._update.handler===t);return n.length?n[0]:null}function IM(e,t,n,r){let i=oB(n,r);return i||(i=OC(e,()=>r(t,n.value)),i.handler=r,e.on(n,null,i)),e}function PM(e,t,n){const r=oB(t,n);return r&&t._targets.remove(r),e}Te(sB,sd,{async evaluate(e,t,n){if(await sd.prototype.evaluate.call(this,e,t),this._redraw||this._resize)try{this._renderer&&(this._resize&&(this._resize=0,Kfe(this)),await this._renderer.renderAsync(this._scenegraph.root)),this._redraw=!1}catch(r){this.error(r)}return n&&s1(this,n),this},dirty(e){this._redraw=!0,this._renderer&&this._renderer.dirty(e)},description(e){if(arguments.length){const t=e!=null?e+"":null;return t!==this._desc&&VP(this._el,this._desc=t),this}return this._desc},container(){return this._el},scenegraph(){return this._scenegraph},origin(){return this._origin.slice()},signal(e,t,n){const r=Mm(this,e);return arguments.length===1?r.value:this.update(r,t,n)},width(e){return arguments.length?this.signal("width",e):this.signal("width")},height(e){return arguments.length?this.signal("height",e):this.signal("height")},padding(e){return arguments.length?this.signal("padding",OM(e)):OM(this.signal("padding"))},autosize(e){return arguments.length?this.signal("autosize",e):this.signal("autosize")},background(e){return arguments.length?this.signal("background",e):this.signal("background")},renderer(e){return arguments.length?(yb(e)||ae("Unrecognized renderer type: "+e),e!==this._renderType&&(this._renderType=e,this._resetRenderer()),this):this._renderType},tooltip(e){return arguments.length?(e!==this._tooltip&&(this._tooltip=e,this._resetRenderer()),this):this._tooltip},loader(e){return arguments.length?(e!==this._loader&&(sd.prototype.loader.call(this,e),this._resetRenderer()),this):this._loader},resize(){return this._autosize=1,this.touch(Mm(this,"autosize"))},_resetRenderer(){this._renderer&&(this._renderer=null,this.initialize(this._el,this._elBind))},_resizeView:Fde,addEventListener(e,t,n){let r=t;return n&&n.trap===!1||(r=OC(this,t),r.raw=t),this._handler.on(e,r),this},removeEventListener(e,t){for(var n=this._handler.handlers(e),r=n.length,i,s;--r>=0;)if(s=n[r].type,i=n[r].handler,e===s&&(t===i||t===i.raw)){this._handler.off(s,i);break}return this},addResizeListener(e){const t=this._resizeListeners;return t.includes(e)||t.push(e),this},removeResizeListener(e){var t=this._resizeListeners,n=t.indexOf(e);return n>=0&&t.splice(n,1),this},addSignalListener(e,t){return IM(this,e,Mm(this,e),t)},removeSignalListener(e,t){return PM(this,Mm(this,e),t)},addDataListener(e,t){return IM(this,e,Zv(this,e).values,t)},removeDataListener(e,t){return PM(this,Zv(this,e).values,t)},globalCursor(e){if(arguments.length){if(this._globalCursor!==!!e){const t=WE(this,null);this._globalCursor=!!e,t&&WE(this,t)}return this}else return this._globalCursor},preventDefault(e){return arguments.length?(this._preventDefault=e,this):this._preventDefault},timer:Nde,events:ide,finalize:ode,hover:sde,data:Yfe,change:Mb,insert:Vfe,remove:Xfe,scale:Cde,initialize:xde,toImageURL:wde,toCanvas:Ade,toSVG:kde,getState:Dde,setState:Rde,_watchPixelRatio:Pde});const Bde="view",Qv="[",ey="]",aB="{",lB="}",zde=":",uB=",",jde="@",Ude=">",qde=/[[\]{}]/,Wde={"*":1,arc:1,area:1,group:1,image:1,line:1,path:1,rect:1,rule:1,shape:1,symbol:1,text:1,trail:1};let cB,fB;function Fu(e,t,n){return cB=t||Bde,fB=n||Wde,dB(e.trim()).map(HE)}function Hde(e){return fB[e]}function rg(e,t,n,r,i){const s=e.length;let o=0,a;for(;t=0?--o:r&&r.indexOf(a)>=0&&++o}return t}function dB(e){const t=[],n=e.length;let r=0,i=0;for(;i' after between selector: "+e;r=r.map(HE);const i=HE(e.slice(1).trim());return i.between?{between:r,stream:i}:(i.between=r,i)}function Yde(e){const t={source:cB},n=[];let r=[0,0],i=0,s=0,o=e.length,a=0,l,u;if(e[o-1]===lB){if(a=e.lastIndexOf(aB),a>=0){try{r=Vde(e.substring(a+1,o-1))}catch{throw"Invalid throttle specification: "+e}e=e.slice(0,a).trim(),o=e.length}else throw"Unmatched right brace: "+e;a=0}if(!o)throw e;if(e[0]===jde&&(i=++a),l=rg(e,a,zde),l1?(t.type=n[1],i?t.markname=n[0].slice(1):Hde(n[0])?t.marktype=n[0]:t.source=n[0]):t.type=n[0],t.type.slice(-1)==="!"&&(t.consume=!0,t.type=t.type.slice(0,-1)),u!=null&&(t.filter=u),r[0]&&(t.throttle=r[0]),r[1]&&(t.debounce=r[1]),t}function Vde(e){const t=e.split(uB);if(!e.length||t.length>2)throw e;return t.map(n=>{const r=+n;if(r!==r)throw e;return r})}function Xde(e){return Pe(e)?e:{type:e||"pad"}}const ap=e=>+e||0,Kde=e=>({top:e,bottom:e,left:e,right:e});function Zde(e){return Pe(e)?e.signal?e:{top:ap(e.top),bottom:ap(e.bottom),left:ap(e.left),right:ap(e.right)}:Kde(ap(e))}const ur=e=>Pe(e)&&!fe(e)?kt({},e):{value:e};function BM(e,t,n,r){return n!=null?(Pe(n)&&!fe(n)||fe(n)&&n.length&&Pe(n[0])?e.update[t]=n:e[r||"enter"][t]={value:n},1):0}function Rr(e,t,n){for(const r in t)BM(e,r,t[r]);for(const r in n)BM(e,r,n[r],"update")}function Fh(e,t,n){for(const r in t)n&&We(n,r)||(e[r]=kt(e[r]||{},t[r]));return e}function Vf(e,t){return t&&(t.enter&&t.enter[e]||t.update&&t.update[e])}const PC="mark",BC="frame",zC="scope",Jde="axis",Qde="axis-domain",ehe="axis-grid",the="axis-label",nhe="axis-tick",rhe="axis-title",ihe="legend",she="legend-band",ohe="legend-entry",ahe="legend-gradient",hB="legend-label",lhe="legend-symbol",uhe="legend-title",che="title",fhe="title-text",dhe="title-subtitle";function hhe(e,t,n,r,i){const s={},o={};let a,l,u,c;l="lineBreak",t==="text"&&i[l]!=null&&!Vf(l,e)&&s_(s,l,i[l]),(n=="legend"||String(n).startsWith("axis"))&&(n=null),c=n===BC?i.group:n===PC?kt({},i.mark,i[t]):null;for(l in c)u=Vf(l,e)||(l==="fill"||l==="stroke")&&(Vf("fill",e)||Vf("stroke",e)),u||s_(s,l,c[l]);je(r).forEach(f=>{const d=i.style&&i.style[f];for(const h in d)Vf(h,e)||s_(s,h,d[h])}),e=kt({},e);for(l in s)c=s[l],c.signal?(a=a||{})[l]=c:o[l]=c;return e.enter=kt(o,e.enter),a&&(e.update=kt(a,e.update)),e}function s_(e,t,n){e[t]=n&&n.signal?{signal:n.signal}:{value:n}}const pB=e=>ze(e)?De(e):e.signal?`(${e.signal})`:gB(e);function Rb(e){if(e.gradient!=null)return ghe(e);let t=e.signal?`(${e.signal})`:e.color?phe(e.color):e.field!=null?gB(e.field):e.value!==void 0?De(e.value):void 0;return e.scale!=null&&(t=mhe(e,t)),t===void 0&&(t=null),e.exponent!=null&&(t=`pow(${t},${E1(e.exponent)})`),e.mult!=null&&(t+=`*${E1(e.mult)}`),e.offset!=null&&(t+=`+${E1(e.offset)}`),e.round&&(t=`round(${t})`),t}const Tm=(e,t,n,r)=>`(${e}(${[t,n,r].map(Rb).join(",")})+'')`;function phe(e){return e.c?Tm("hcl",e.h,e.c,e.l):e.h||e.s?Tm("hsl",e.h,e.s,e.l):e.l||e.a?Tm("lab",e.l,e.a,e.b):e.r||e.g||e.b?Tm("rgb",e.r,e.g,e.b):null}function ghe(e){const t=[e.start,e.stop,e.count].map(n=>n==null?null:De(n));for(;t.length&&jt(t)==null;)t.pop();return t.unshift(pB(e.gradient)),`gradient(${t.join(",")})`}function E1(e){return Pe(e)?"("+Rb(e)+")":e}function gB(e){return mB(Pe(e)?e:{datum:e})}function mB(e){let t,n,r;if(e.signal)t="datum",r=e.signal;else if(e.group||e.parent){for(n=Math.max(1,e.level||1),t="item";n-- >0;)t+=".mark.group";e.parent?(r=e.parent,t+=".datum"):r=e.group}else e.datum?(t="datum",r=e.datum):ae("Invalid field reference: "+De(e));return e.signal||(r=ze(r)?va(r).map(De).join("]["):mB(r)),t+"["+r+"]"}function mhe(e,t){const n=pB(e.scale);return e.range!=null?t=`lerp(_range(${n}), ${+e.range})`:(t!==void 0&&(t=`_scale(${n}, ${t})`),e.band&&(t=(t?t+"+":"")+`_bandwidth(${n})`+(+e.band==1?"":"*"+E1(e.band)),e.extra&&(t=`(datum.extra ? _scale(${n}, datum.extra.value) : ${t})`)),t==null&&(t="0")),t}function vhe(e){let t="";return e.forEach(n=>{const r=Rb(n);t+=n.test?`(${n.test})?${r}:`:r}),jt(t)===":"&&(t+="null"),t}function vB(e,t,n,r,i,s){const o={};s=s||{},s.encoders={$encode:o},e=hhe(e,t,n,r,i.config);for(const a in e)o[a]=yhe(e[a],t,s,i);return s}function yhe(e,t,n,r){const i={},s={};for(const o in e)e[o]!=null&&(i[o]=xhe(bhe(e[o]),r,n,s));return{$expr:{marktype:t,channels:i},$fields:Object.keys(s),$output:Object.keys(e)}}function bhe(e){return fe(e)?vhe(e):Rb(e)}function xhe(e,t,n,r){const i=da(e,t);return i.$fields.forEach(s=>r[s]=1),kt(n,i.$params),i.$expr}const _he="outer",whe=["value","update","init","react","bind"];function zM(e,t){ae(e+' for "outer" push: '+De(t))}function yB(e,t){const n=e.name;if(e.push===_he)t.signals[n]||zM("No prior signal definition",n),whe.forEach(r=>{e[r]!==void 0&&zM("Invalid property ",r)});else{const r=t.addSignal(n,e.value);e.react===!1&&(r.react=!1),e.bind&&t.addBinding(n,e.bind)}}function GE(e,t,n,r){this.id=-1,this.type=e,this.value=t,this.params=n,r&&(this.parent=r)}function Nb(e,t,n,r){return new GE(e,t,n,r)}function ty(e,t){return Nb("operator",e,t)}function rt(e){const t={$ref:e.id};return e.id<0&&(e.refs=e.refs||[]).push(t),t}function Mg(e,t){return t?{$field:e,$name:t}:{$field:e}}const YE=Mg("key");function jM(e,t){return{$compare:e,$order:t}}function Ehe(e,t){const n={$key:e};return t&&(n.$flat=!0),n}const Ahe="ascending",khe="descending";function She(e){return Pe(e)?(e.order===khe?"-":"+")+Ob(e.op,e.field):""}function Ob(e,t){return(e&&e.signal?"$"+e.signal:e||"")+(e&&t?"_":"")+(t&&t.signal?"$"+t.signal:t||"")}const jC="scope",VE="view";function Qn(e){return e&&e.signal}function Che(e){return e&&e.expr}function A1(e){if(Qn(e))return!0;if(Pe(e)){for(const t in e)if(A1(e[t]))return!0}return!1}function to(e,t){return e??t}function Sc(e){return e&&e.signal||e}const UM="timer";function Tg(e,t){return(e.merge?Fhe:e.stream?Dhe:e.type?Mhe:ae("Invalid stream specification: "+De(e)))(e,t)}function $he(e){return e===jC?VE:e||VE}function Fhe(e,t){const n=e.merge.map(i=>Tg(i,t)),r=UC({merge:n},e,t);return t.addStream(r).id}function Dhe(e,t){const n=Tg(e.stream,t),r=UC({stream:n},e,t);return t.addStream(r).id}function Mhe(e,t){let n;e.type===UM?(n=t.event(UM,e.throttle),e={between:e.between,filter:e.filter}):n=t.event($he(e.source),e.type);const r=UC({stream:n},e,t);return Object.keys(r).length===1?n:t.addStream(r).id}function UC(e,t,n){let r=t.between;return r&&(r.length!==2&&ae('Stream "between" parameter must have 2 entries: '+De(t)),e.between=[Tg(r[0],n),Tg(r[1],n)]),r=t.filter?[].concat(t.filter):[],(t.marktype||t.markname||t.markrole)&&r.push(The(t.marktype,t.markname,t.markrole)),t.source===jC&&r.push("inScope(event.item)"),r.length&&(e.filter=da("("+r.join(")&&(")+")",n).$expr),(r=t.throttle)!=null&&(e.throttle=+r),(r=t.debounce)!=null&&(e.debounce=+r),t.consume&&(e.consume=!0),e}function The(e,t,n){const r="event.item";return r+(e&&e!=="*"?"&&"+r+".mark.marktype==='"+e+"'":"")+(n?"&&"+r+".mark.role==='"+n+"'":"")+(t?"&&"+r+".mark.name==='"+t+"'":"")}const Rhe={code:"_.$value",ast:{type:"Identifier",value:"value"}};function Nhe(e,t,n){const r=e.encode,i={target:n};let s=e.events,o=e.update,a=[];s||ae("Signal update missing events specification."),ze(s)&&(s=Fu(s,t.isSubscope()?jC:VE)),s=je(s).filter(l=>l.signal||l.scale?(a.push(l),0):1),a.length>1&&(a=[Lhe(a)]),s.length&&a.push(s.length>1?{merge:s}:s[0]),r!=null&&(o&&ae("Signal encode and update are mutually exclusive."),o="encode(item(),"+De(r)+")"),i.update=ze(o)?da(o,t):o.expr!=null?da(o.expr,t):o.value!=null?o.value:o.signal!=null?{$expr:Rhe,$params:{$value:t.signalRef(o.signal)}}:ae("Invalid signal update specification."),e.force&&(i.options={force:!0}),a.forEach(l=>t.addUpdate(kt(Ohe(l,t),i)))}function Ohe(e,t){return{source:e.signal?t.signalRef(e.signal):e.scale?t.scaleRef(e.scale):Tg(e,t)}}function Lhe(e){return{signal:"["+e.map(t=>t.scale?'scale("'+t.scale+'")':t.signal)+"]"}}function Ihe(e,t){const n=t.getSignal(e.name);let r=e.update;e.init&&(r?ae("Signals can not include both init and update expressions."):(r=e.init,n.initonly=!0)),r&&(r=da(r,t),n.update=r.$expr,n.params=r.$params),e.on&&e.on.forEach(i=>Nhe(i,t,n.id))}const un=e=>(t,n,r)=>Nb(e,n,t||void 0,r),bB=un("aggregate"),Phe=un("axisticks"),xB=un("bound"),Ao=un("collect"),qM=un("compare"),Bhe=un("datajoin"),_B=un("encode"),zhe=un("expression"),jhe=un("facet"),Uhe=un("field"),qhe=un("key"),Whe=un("legendentries"),Hhe=un("load"),Ghe=un("mark"),Yhe=un("multiextent"),Vhe=un("multivalues"),Xhe=un("overlap"),Khe=un("params"),wB=un("prefacet"),Zhe=un("projection"),Jhe=un("proxy"),Qhe=un("relay"),EB=un("render"),epe=un("scale"),yf=un("sieve"),tpe=un("sortitems"),AB=un("viewlayout"),npe=un("values");let rpe=0;const kB={min:"min",max:"max",count:"sum"};function ipe(e,t){const n=e.type||"linear";c9(n)||ae("Unrecognized scale type: "+De(n)),t.addScale(e.name,{type:n,domain:void 0})}function spe(e,t){const n=t.getScale(e.name).params;let r;n.domain=SB(e.domain,e,t),e.range!=null&&(n.range=$B(e,t,n)),e.interpolate!=null&&gpe(e.interpolate,n),e.nice!=null&&(n.nice=ppe(e.nice,t)),e.bins!=null&&(n.bins=hpe(e.bins,t));for(r in e)We(n,r)||r==="name"||(n[r]=Cs(e[r],t))}function Cs(e,t){return Pe(e)?e.signal?t.signalRef(e.signal):ae("Unsupported object: "+De(e)):e}function k1(e,t){return e.signal?t.signalRef(e.signal):e.map(n=>Cs(n,t))}function Lb(e){ae("Can not find data set: "+De(e))}function SB(e,t,n){if(!e){(t.domainMin!=null||t.domainMax!=null)&&ae("No scale domain defined for domainMin/domainMax to override.");return}return e.signal?n.signalRef(e.signal):(fe(e)?ope:e.fields?lpe:ape)(e,t,n)}function ope(e,t,n){return e.map(r=>Cs(r,n))}function ape(e,t,n){const r=n.getData(e.data);return r||Lb(e.data),zd(t.type)?r.valuesRef(n,e.field,CB(e.sort,!1)):h9(t.type)?r.domainRef(n,e.field):r.extentRef(n,e.field)}function lpe(e,t,n){const r=e.data,i=e.fields.reduce((s,o)=>(o=ze(o)?{data:r,field:o}:fe(o)||o.signal?upe(o,n):o,s.push(o),s),[]);return(zd(t.type)?cpe:h9(t.type)?fpe:dpe)(e,n,i)}function upe(e,t){const n="_:vega:_"+rpe++,r=Ao({});if(fe(e))r.value={$ingest:e};else if(e.signal){const i="setdata("+De(n)+","+e.signal+")";r.params.input=t.signalRef(i)}return t.addDataPipeline(n,[r,yf({})]),{data:n,field:"data"}}function cpe(e,t,n){const r=CB(e.sort,!0);let i,s;const o=n.map(u=>{const c=t.getData(u.data);return c||Lb(u.data),c.countsRef(t,u.field,r)}),a={groupby:YE,pulse:o};r&&(i=r.op||"count",s=r.field?Ob(i,r.field):"count",a.ops=[kB[i]],a.fields=[t.fieldRef(s)],a.as=[s]),i=t.add(bB(a));const l=t.add(Ao({pulse:rt(i)}));return s=t.add(npe({field:YE,sort:t.sortRef(r),pulse:rt(l)})),rt(s)}function CB(e,t){return e&&(!e.field&&!e.op?Pe(e)?e.field="key":e={field:"key"}:!e.field&&e.op!=="count"?ae("No field provided for sort aggregate op: "+e.op):t&&e.field&&e.op&&!kB[e.op]&&ae("Multiple domain scales can not be sorted using "+e.op)),e}function fpe(e,t,n){const r=n.map(i=>{const s=t.getData(i.data);return s||Lb(i.data),s.domainRef(t,i.field)});return rt(t.add(Vhe({values:r})))}function dpe(e,t,n){const r=n.map(i=>{const s=t.getData(i.data);return s||Lb(i.data),s.extentRef(t,i.field)});return rt(t.add(Yhe({extents:r})))}function hpe(e,t){return e.signal||fe(e)?k1(e,t):t.objectProperty(e)}function ppe(e,t){return e.signal?t.signalRef(e.signal):Pe(e)?{interval:Cs(e.interval),step:Cs(e.step)}:Cs(e)}function gpe(e,t){t.interpolate=Cs(e.type||e),e.gamma!=null&&(t.interpolateGamma=Cs(e.gamma))}function $B(e,t,n){const r=t.config.range;let i=e.range;if(i.signal)return t.signalRef(i.signal);if(ze(i)){if(r&&We(r,i))return e=kt({},e,{range:r[i]}),$B(e,t,n);i==="width"?i=[0,{signal:"width"}]:i==="height"?i=zd(e.type)?[0,{signal:"height"}]:[{signal:"height"},0]:ae("Unrecognized scale range value: "+De(i))}else if(i.scheme){n.scheme=fe(i.scheme)?k1(i.scheme,t):Cs(i.scheme,t),i.extent&&(n.schemeExtent=k1(i.extent,t)),i.count&&(n.schemeCount=Cs(i.count,t));return}else if(i.step){n.rangeStep=Cs(i.step,t);return}else{if(zd(e.type)&&!fe(i))return SB(i,e,t);fe(i)||ae("Unsupported range type: "+De(i))}return i.map(s=>(fe(s)?k1:Cs)(s,t))}function mpe(e,t){const n=t.config.projection||{},r={};for(const i in e)i!=="name"&&(r[i]=XE(e[i],i,t));for(const i in n)r[i]==null&&(r[i]=XE(n[i],i,t));t.addProjection(e.name,r)}function XE(e,t,n){return fe(e)?e.map(r=>XE(r,t,n)):Pe(e)?e.signal?n.signalRef(e.signal):t==="fit"?e:ae("Unsupported parameter object: "+De(e)):e}const ko="top",Dh="left",Mh="right",hu="bottom",FB="center",vpe="vertical",ype="start",bpe="middle",xpe="end",KE="index",qC="label",_pe="offset",Xd="perc",wpe="perc2",Ts="value",T0="guide-label",WC="guide-title",Epe="group-title",Ape="group-subtitle",WM="symbol",S1="gradient",ZE="discrete",JE="size",kpe="shape",Spe="fill",Cpe="stroke",$pe="strokeWidth",Fpe="strokeDash",Dpe="opacity",HC=[JE,kpe,Spe,Cpe,$pe,Fpe,Dpe],R0={name:1,style:1,interactive:1},qt={value:0},Rs={value:1},Ib="group",DB="rect",GC="rule",Mpe="symbol",bf="text";function Rg(e){return e.type=Ib,e.interactive=e.interactive||!1,e}function Yi(e,t){const n=(r,i)=>to(e[r],to(t[r],i));return n.isVertical=r=>vpe===to(e.direction,t.direction||(r?t.symbolDirection:t.gradientDirection)),n.gradientLength=()=>to(e.gradientLength,t.gradientLength||t.gradientWidth),n.gradientThickness=()=>to(e.gradientThickness,t.gradientThickness||t.gradientHeight),n.entryColumns=()=>to(e.columns,to(t.columns,+n.isVertical(!0))),n}function MB(e,t){const n=t&&(t.update&&t.update[e]||t.enter&&t.enter[e]);return n&&n.signal?n:n?n.value:null}function Tpe(e,t,n){const r=t.config.style[n];return r&&r[e]}function Pb(e,t,n){return`item.anchor === '${ype}' ? ${e} : item.anchor === '${xpe}' ? ${t} : ${n}`}const YC=Pb(De(Dh),De(Mh),De(FB));function Rpe(e){const t=e("tickBand");let n=e("tickOffset"),r,i;return t?t.signal?(r={signal:`(${t.signal}) === 'extent' ? 1 : 0.5`},i={signal:`(${t.signal}) === 'extent'`},Pe(n)||(n={signal:`(${t.signal}) === 'extent' ? 0 : ${n}`})):t==="extent"?(r=1,i=!0,n=0):(r=.5,i=!1):(r=e("bandPosition"),i=e("tickExtra")),{extra:i,band:r,offset:n}}function TB(e,t){return t?e?Pe(e)?Object.assign({},e,{offset:TB(e.offset,t)}):{value:e,offset:t}:t:e}function gs(e,t){return t?(e.name=t.name,e.style=t.style||e.style,e.interactive=!!t.interactive,e.encode=Fh(e.encode,t,R0)):e.interactive=!1,e}function Npe(e,t,n,r){const i=Yi(e,n),s=i.isVertical(),o=i.gradientThickness(),a=i.gradientLength();let l,u,c,f,d;s?(u=[0,1],c=[0,0],f=o,d=a):(u=[0,0],c=[1,0],f=a,d=o);const h={enter:l={opacity:qt,x:qt,y:qt,width:ur(f),height:ur(d)},update:kt({},l,{opacity:Rs,fill:{gradient:t,start:u,stop:c}}),exit:{opacity:qt}};return Rr(h,{stroke:i("gradientStrokeColor"),strokeWidth:i("gradientStrokeWidth")},{opacity:i("gradientOpacity")}),gs({type:DB,role:ahe,encode:h},r)}function Ope(e,t,n,r,i){const s=Yi(e,n),o=s.isVertical(),a=s.gradientThickness(),l=s.gradientLength();let u,c,f,d,h="";o?(u="y",f="y2",c="x",d="width",h="1-"):(u="x",f="x2",c="y",d="height");const p={opacity:qt,fill:{scale:t,field:Ts}};p[u]={signal:h+"datum."+Xd,mult:l},p[c]=qt,p[f]={signal:h+"datum."+wpe,mult:l},p[d]=ur(a);const g={enter:p,update:kt({},p,{opacity:Rs}),exit:{opacity:qt}};return Rr(g,{stroke:s("gradientStrokeColor"),strokeWidth:s("gradientStrokeWidth")},{opacity:s("gradientOpacity")}),gs({type:DB,role:she,key:Ts,from:i,encode:g},r)}const Lpe=`datum.${Xd}<=0?"${Dh}":datum.${Xd}>=1?"${Mh}":"${FB}"`,Ipe=`datum.${Xd}<=0?"${hu}":datum.${Xd}>=1?"${ko}":"${bpe}"`;function HM(e,t,n,r){const i=Yi(e,t),s=i.isVertical(),o=ur(i.gradientThickness()),a=i.gradientLength();let l=i("labelOverlap"),u,c,f,d,h="";const p={enter:u={opacity:qt},update:c={opacity:Rs,text:{field:qC}},exit:{opacity:qt}};return Rr(p,{fill:i("labelColor"),fillOpacity:i("labelOpacity"),font:i("labelFont"),fontSize:i("labelFontSize"),fontStyle:i("labelFontStyle"),fontWeight:i("labelFontWeight"),limit:to(e.labelLimit,t.gradientLabelLimit)}),s?(u.align={value:"left"},u.baseline=c.baseline={signal:Ipe},f="y",d="x",h="1-"):(u.align=c.align={signal:Lpe},u.baseline={value:"top"},f="x",d="y"),u[f]=c[f]={signal:h+"datum."+Xd,mult:a},u[d]=c[d]=o,o.offset=to(e.labelOffset,t.gradientLabelOffset)||0,l=l?{separation:i("labelSeparation"),method:l,order:"datum."+KE}:void 0,gs({type:bf,role:hB,style:T0,key:Ts,from:r,encode:p,overlap:l},n)}function Ppe(e,t,n,r,i){const s=Yi(e,t),o=n.entries,a=!!(o&&o.interactive),l=o?o.name:void 0,u=s("clipHeight"),c=s("symbolOffset"),f={data:"value"},d=`(${i}) ? datum.${_pe} : datum.${JE}`,h=u?ur(u):{field:JE},p=`datum.${KE}`,g=`max(1, ${i})`;let m,v,b,x,_;h.mult=.5,m={enter:v={opacity:qt,x:{signal:d,mult:.5,offset:c},y:h},update:b={opacity:Rs,x:v.x,y:v.y},exit:{opacity:qt}};let w=null,A=null;e.fill||(w=t.symbolBaseFillColor,A=t.symbolBaseStrokeColor),Rr(m,{fill:s("symbolFillColor",w),shape:s("symbolType"),size:s("symbolSize"),stroke:s("symbolStrokeColor",A),strokeDash:s("symbolDash"),strokeDashOffset:s("symbolDashOffset"),strokeWidth:s("symbolStrokeWidth")},{opacity:s("symbolOpacity")}),HC.forEach($=>{e[$]&&(b[$]=v[$]={scale:e[$],field:Ts})});const E=gs({type:Mpe,role:lhe,key:Ts,from:f,clip:u?!0:void 0,encode:m},n.symbols),k=ur(c);k.offset=s("labelOffset"),m={enter:v={opacity:qt,x:{signal:d,offset:k},y:h},update:b={opacity:Rs,text:{field:qC},x:v.x,y:v.y},exit:{opacity:qt}},Rr(m,{align:s("labelAlign"),baseline:s("labelBaseline"),fill:s("labelColor"),fillOpacity:s("labelOpacity"),font:s("labelFont"),fontSize:s("labelFontSize"),fontStyle:s("labelFontStyle"),fontWeight:s("labelFontWeight"),limit:s("labelLimit")});const S=gs({type:bf,role:hB,style:T0,key:Ts,from:f,encode:m},n.labels);return m={enter:{noBound:{value:!u},width:qt,height:u?ur(u):qt,opacity:qt},exit:{opacity:qt},update:b={opacity:Rs,row:{signal:null},column:{signal:null}}},s.isVertical(!0)?(x=`ceil(item.mark.items.length / ${g})`,b.row.signal=`${p}%${x}`,b.column.signal=`floor(${p} / ${x})`,_={field:["row",p]}):(b.row.signal=`floor(${p} / ${g})`,b.column.signal=`${p} % ${g}`,_={field:p}),b.column.signal=`(${i})?${b.column.signal}:${p}`,r={facet:{data:r,name:"value",groupby:KE}},Rg({role:zC,from:r,encode:Fh(m,o,R0),marks:[E,S],name:l,interactive:a,sort:_})}function Bpe(e,t){const n=Yi(e,t);return{align:n("gridAlign"),columns:n.entryColumns(),center:{row:!0,column:!1},padding:{row:n("rowPadding"),column:n("columnPadding")}}}const VC='item.orient === "left"',XC='item.orient === "right"',Bb=`(${VC} || ${XC})`,zpe=`datum.vgrad && ${Bb}`,jpe=Pb('"top"','"bottom"','"middle"'),Upe=Pb('"right"','"left"','"center"'),qpe=`datum.vgrad && ${XC} ? (${Upe}) : (${Bb} && !(datum.vgrad && ${VC})) ? "left" : ${YC}`,Wpe=`item._anchor || (${Bb} ? "middle" : "start")`,Hpe=`${zpe} ? (${VC} ? -90 : 90) : 0`,Gpe=`${Bb} ? (datum.vgrad ? (${XC} ? "bottom" : "top") : ${jpe}) : "top"`;function Ype(e,t,n,r){const i=Yi(e,t),s={enter:{opacity:qt},update:{opacity:Rs,x:{field:{group:"padding"}},y:{field:{group:"padding"}}},exit:{opacity:qt}};return Rr(s,{orient:i("titleOrient"),_anchor:i("titleAnchor"),anchor:{signal:Wpe},angle:{signal:Hpe},align:{signal:qpe},baseline:{signal:Gpe},text:e.title,fill:i("titleColor"),fillOpacity:i("titleOpacity"),font:i("titleFont"),fontSize:i("titleFontSize"),fontStyle:i("titleFontStyle"),fontWeight:i("titleFontWeight"),limit:i("titleLimit"),lineHeight:i("titleLineHeight")},{align:i("titleAlign"),baseline:i("titleBaseline")}),gs({type:bf,role:uhe,style:WC,from:r,encode:s},n)}function Vpe(e,t){let n;return Pe(e)&&(e.signal?n=e.signal:e.path?n="pathShape("+GM(e.path)+")":e.sphere&&(n="geoShape("+GM(e.sphere)+', {type: "Sphere"})')),n?t.signalRef(n):!!e}function GM(e){return Pe(e)&&e.signal?e.signal:De(e)}function RB(e){const t=e.role||"";return t.startsWith("axis")||t.startsWith("legend")||t.startsWith("title")?t:e.type===Ib?zC:t||PC}function Xpe(e){return{marktype:e.type,name:e.name||void 0,role:e.role||RB(e),zindex:+e.zindex||void 0,aria:e.aria,description:e.description}}function Kpe(e,t){return e&&e.signal?t.signalRef(e.signal):e!==!1}function KC(e,t){const n=dO(e.type);n||ae("Unrecognized transform type: "+De(e.type));const r=Nb(n.type.toLowerCase(),null,NB(n,e,t));return e.signal&&t.addSignal(e.signal,t.proxy(r)),r.metadata=n.metadata||{},r}function NB(e,t,n){const r={},i=e.params.length;for(let s=0;sYM(e,s,n)):YM(e,i,n)}function YM(e,t,n){const r=e.type;if(Qn(t))return XM(r)?ae("Expression references can not be signals."):o_(r)?n.fieldRef(t):KM(r)?n.compareRef(t):n.signalRef(t.signal);{const i=e.expr||o_(r);return i&&ege(t)?n.exprRef(t.expr,t.as):i&&tge(t)?Mg(t.field,t.as):XM(r)?da(t,n):nge(r)?rt(n.getData(t).values):o_(r)?Mg(t):KM(r)?n.compareRef(t):t}}function Jpe(e,t,n){return ze(t.from)||ae('Lookup "from" parameter must be a string literal.'),n.getData(t.from).lookupRef(n,t.key)}function Qpe(e,t,n){const r=t[e.name];return e.array?(fe(r)||ae("Expected an array of sub-parameters. Instead: "+De(r)),r.map(i=>VM(e,i,n))):VM(e,r,n)}function VM(e,t,n){const r=e.params.length;let i;for(let o=0;oe&&e.expr,tge=e=>e&&e.field,nge=e=>e==="data",XM=e=>e==="expr",o_=e=>e==="field",KM=e=>e==="compare";function rge(e,t,n){let r,i,s,o,a;return e?(r=e.facet)&&(t||ae("Only group marks can be faceted."),r.field!=null?o=a=C1(r,n):(e.data?a=rt(n.getData(e.data).aggregate):(s=KC(kt({type:"aggregate",groupby:je(r.groupby)},r.aggregate),n),s.params.key=n.keyRef(r.groupby),s.params.pulse=C1(r,n),o=a=rt(n.add(s))),i=n.keyRef(r.groupby,!0))):o=rt(n.add(Ao(null,[{}]))),o||(o=C1(e,n)),{key:i,pulse:o,parent:a}}function C1(e,t){return e.$ref?e:e.data&&e.data.$ref?e.data:rt(t.getData(e.data).output)}function Zc(e,t,n,r,i){this.scope=e,this.input=t,this.output=n,this.values=r,this.aggregate=i,this.index={}}Zc.fromEntries=function(e,t){const n=t.length,r=t[n-1],i=t[n-2];let s=t[0],o=null,a=1;for(s&&s.type==="load"&&(s=t[1]),e.add(t[0]);af??"null").join(",")+"),0)",c=da(u,t);l.update=c.$expr,l.params=c.$params}function zb(e,t){const n=RB(e),r=e.type===Ib,i=e.from&&e.from.facet,s=e.overlap;let o=e.layout||n===zC||n===BC,a,l,u,c,f,d,h;const p=n===PC||o||i,g=rge(e.from,r,t);l=t.add(Bhe({key:g.key||(e.key?Mg(e.key):void 0),pulse:g.pulse,clean:!r}));const m=rt(l);l=u=t.add(Ao({pulse:m})),l=t.add(Ghe({markdef:Xpe(e),interactive:Kpe(e.interactive,t),clip:Vpe(e.clip,t),context:{$context:!0},groups:t.lookup(),parent:t.signals.parent?t.signalRef("parent"):null,index:t.markpath(),pulse:rt(l)}));const v=rt(l);l=c=t.add(_B(vB(e.encode,e.type,n,e.style,t,{mod:!1,pulse:v}))),l.params.parent=t.encode(),e.transform&&e.transform.forEach(A=>{const E=KC(A,t),k=E.metadata;(k.generates||k.changes)&&ae("Mark transforms should not generate new data."),k.nomod||(c.params.mod=!0),E.params.pulse=rt(l),t.add(l=E)}),e.sort&&(l=t.add(tpe({sort:t.compareRef(e.sort),pulse:rt(l)})));const b=rt(l);(i||o)&&(o=t.add(AB({layout:t.objectProperty(e.layout),legends:t.legends,mark:v,pulse:b})),d=rt(o));const x=t.add(xB({mark:v,pulse:d||b}));h=rt(x),r&&(p&&(a=t.operators,a.pop(),o&&a.pop()),t.pushState(b,d||h,m),i?ige(e,t,g):p?sge(e,t,g):t.parse(e),t.popState(),p&&(o&&a.push(o),a.push(x))),s&&(h=oge(s,h,t));const _=t.add(EB({pulse:h})),w=t.add(yf({pulse:rt(_)},void 0,t.parent()));e.name!=null&&(f=e.name,t.addData(f,new Zc(t,u,_,w)),e.on&&e.on.forEach(A=>{(A.insert||A.remove||A.toggle)&&ae("Marks only support modify triggers."),LB(A,t,f)}))}function oge(e,t,n){const r=e.method,i=e.bound,s=e.separation,o={separation:Qn(s)?n.signalRef(s.signal):s,method:Qn(r)?n.signalRef(r.signal):r,pulse:t};if(e.order&&(o.sort=n.compareRef({field:e.order})),i){const a=i.tolerance;o.boundTolerance=Qn(a)?n.signalRef(a.signal):+a,o.boundScale=n.scaleRef(i.scale),o.boundOrient=i.orient}return rt(n.add(Xhe(o)))}function age(e,t){const n=t.config.legend,r=e.encode||{},i=Yi(e,n),s=r.legend||{},o=s.name||void 0,a=s.interactive,l=s.style,u={};let c=0,f,d,h;HC.forEach(x=>e[x]?(u[x]=e[x],c=c||e[x]):0),c||ae("Missing valid scale for legend.");const p=lge(e,t.scaleType(c)),g={title:e.title!=null,scales:u,type:p,vgrad:p!=="symbol"&&i.isVertical()},m=rt(t.add(Ao(null,[g]))),v={enter:{x:{value:0},y:{value:0}}},b=rt(t.add(Whe(d={type:p,scale:t.scaleRef(c),count:t.objectProperty(i("tickCount")),limit:t.property(i("symbolLimit")),values:t.objectProperty(e.values),minstep:t.property(e.tickMinStep),formatType:t.property(e.formatType),formatSpecifier:t.property(e.format)})));return p===S1?(h=[Npe(e,c,n,r.gradient),HM(e,n,r.labels,b)],d.count=d.count||t.signalRef(`max(2,2*floor((${Sc(i.gradientLength())})/100))`)):p===ZE?h=[Ope(e,c,n,r.gradient,b),HM(e,n,r.labels,b)]:(f=Bpe(e,n),h=[Ppe(e,n,r,b,Sc(f.columns))],d.size=fge(e,t,h[0].marks)),h=[Rg({role:ohe,from:m,encode:v,marks:h,layout:f,interactive:a})],g.title&&h.push(Ype(e,n,r.title,m)),zb(Rg({role:ihe,from:m,encode:Fh(cge(i,e,n),s,R0),marks:h,aria:i("aria"),description:i("description"),zindex:i("zindex"),name:o,interactive:a,style:l}),t)}function lge(e,t){let n=e.type||WM;return!e.type&&uge(e)===1&&(e.fill||e.stroke)&&(n=ZS(t)?S1:qw(t)?ZE:WM),n!==S1?n:qw(t)?ZE:S1}function uge(e){return HC.reduce((t,n)=>t+(e[n]?1:0),0)}function cge(e,t,n){const r={enter:{},update:{}};return Rr(r,{orient:e("orient"),offset:e("offset"),padding:e("padding"),titlePadding:e("titlePadding"),cornerRadius:e("cornerRadius"),fill:e("fillColor"),stroke:e("strokeColor"),strokeWidth:n.strokeWidth,strokeDash:n.strokeDash,x:e("legendX"),y:e("legendY"),format:t.format,formatType:t.formatType}),r}function fge(e,t,n){const r=Sc(JM("size",e,n)),i=Sc(JM("strokeWidth",e,n)),s=Sc(dge(n[1].encode,t,T0));return da(`max(ceil(sqrt(${r})+${i}),${s})`,t)}function JM(e,t,n){return t[e]?`scale("${t[e]}",datum)`:MB(e,n[0].encode)}function dge(e,t,n){return MB("fontSize",e)||Tpe("fontSize",t,n)}const hge=`item.orient==="${Dh}"?-90:item.orient==="${Mh}"?90:0`;function pge(e,t){e=ze(e)?{text:e}:e;const n=Yi(e,t.config.title),r=e.encode||{},i=r.group||{},s=i.name||void 0,o=i.interactive,a=i.style,l=[],u={},c=rt(t.add(Ao(null,[u])));return l.push(vge(e,n,gge(e),c)),e.subtitle&&l.push(yge(e,n,r.subtitle,c)),zb(Rg({role:che,from:c,encode:mge(n,i),marks:l,aria:n("aria"),description:n("description"),zindex:n("zindex"),name:s,interactive:o,style:a}),t)}function gge(e){const t=e.encode;return t&&t.title||kt({name:e.name,interactive:e.interactive,style:e.style},t)}function mge(e,t){const n={enter:{},update:{}};return Rr(n,{orient:e("orient"),anchor:e("anchor"),align:{signal:YC},angle:{signal:hge},limit:e("limit"),frame:e("frame"),offset:e("offset")||0,padding:e("subtitlePadding")}),Fh(n,t,R0)}function vge(e,t,n,r){const i={value:0},s=e.text,o={enter:{opacity:i},update:{opacity:{value:1}},exit:{opacity:i}};return Rr(o,{text:s,align:{signal:"item.mark.group.align"},angle:{signal:"item.mark.group.angle"},limit:{signal:"item.mark.group.limit"},baseline:"top",dx:t("dx"),dy:t("dy"),fill:t("color"),font:t("font"),fontSize:t("fontSize"),fontStyle:t("fontStyle"),fontWeight:t("fontWeight"),lineHeight:t("lineHeight")},{align:t("align"),angle:t("angle"),baseline:t("baseline")}),gs({type:bf,role:fhe,style:Epe,from:r,encode:o},n)}function yge(e,t,n,r){const i={value:0},s=e.subtitle,o={enter:{opacity:i},update:{opacity:{value:1}},exit:{opacity:i}};return Rr(o,{text:s,align:{signal:"item.mark.group.align"},angle:{signal:"item.mark.group.angle"},limit:{signal:"item.mark.group.limit"},baseline:"top",dx:t("dx"),dy:t("dy"),fill:t("subtitleColor"),font:t("subtitleFont"),fontSize:t("subtitleFontSize"),fontStyle:t("subtitleFontStyle"),fontWeight:t("subtitleFontWeight"),lineHeight:t("subtitleLineHeight")},{align:t("align"),angle:t("angle"),baseline:t("baseline")}),gs({type:bf,role:dhe,style:Ape,from:r,encode:o},n)}function bge(e,t){const n=[];e.transform&&e.transform.forEach(r=>{n.push(KC(r,t))}),e.on&&e.on.forEach(r=>{LB(r,t,e.name)}),t.addDataPipeline(e.name,xge(e,t,n))}function xge(e,t,n){const r=[];let i=null,s=!1,o=!1,a,l,u,c,f;for(e.values?Qn(e.values)||A1(e.format)?(r.push(QM(t,e)),r.push(i=Gu())):r.push(i=Gu({$ingest:e.values,$format:e.format})):e.url?A1(e.url)||A1(e.format)?(r.push(QM(t,e)),r.push(i=Gu())):r.push(i=Gu({$request:e.url,$format:e.format})):e.source&&(i=a=je(e.source).map(d=>rt(t.getData(d).output)),r.push(null)),l=0,u=n.length;le===hu||e===ko,jb=(e,t,n)=>Qn(e)?Age(e.signal,t,n):e===Dh||e===ko?t:n,cr=(e,t,n)=>Qn(e)?wge(e.signal,t,n):IB(e)?t:n,fo=(e,t,n)=>Qn(e)?Ege(e.signal,t,n):IB(e)?n:t,PB=(e,t,n)=>Qn(e)?kge(e.signal,t,n):e===ko?{value:t}:{value:n},_ge=(e,t,n)=>Qn(e)?Sge(e.signal,t,n):e===Mh?{value:t}:{value:n},wge=(e,t,n)=>BB(`${e} === '${ko}' || ${e} === '${hu}'`,t,n),Ege=(e,t,n)=>BB(`${e} !== '${ko}' && ${e} !== '${hu}'`,t,n),Age=(e,t,n)=>ZC(`${e} === '${Dh}' || ${e} === '${ko}'`,t,n),kge=(e,t,n)=>ZC(`${e} === '${ko}'`,t,n),Sge=(e,t,n)=>ZC(`${e} === '${Mh}'`,t,n),BB=(e,t,n)=>(t=t!=null?ur(t):t,n=n!=null?ur(n):n,e6(t)&&e6(n)?(t=t?t.signal||De(t.value):null,n=n?n.signal||De(n.value):null,{signal:`${e} ? (${t}) : (${n})`}):[kt({test:e},t)].concat(n||[])),e6=e=>e==null||Object.keys(e).length===1,ZC=(e,t,n)=>({signal:`${e} ? (${nd(t)}) : (${nd(n)})`}),Cge=(e,t,n,r,i)=>({signal:(r!=null?`${e} === '${Dh}' ? (${nd(r)}) : `:"")+(n!=null?`${e} === '${hu}' ? (${nd(n)}) : `:"")+(i!=null?`${e} === '${Mh}' ? (${nd(i)}) : `:"")+(t!=null?`${e} === '${ko}' ? (${nd(t)}) : `:"")+"(null)"}),nd=e=>Qn(e)?e.signal:e==null?null:De(e),$ge=(e,t)=>t===0?0:Qn(e)?{signal:`(${e.signal}) * ${t}`}:{value:e*t},ud=(e,t)=>{const n=e.signal;return n&&n.endsWith("(null)")?{signal:n.slice(0,-6)+t.signal}:e};function zf(e,t,n,r){let i;if(t&&We(t,e))return t[e];if(We(n,e))return n[e];if(e.startsWith("title")){switch(e){case"titleColor":i="fill";break;case"titleFont":case"titleFontSize":case"titleFontWeight":i=e[5].toLowerCase()+e.slice(6)}return r[WC][i]}else if(e.startsWith("label")){switch(e){case"labelColor":i="fill";break;case"labelFont":case"labelFontSize":i=e[5].toLowerCase()+e.slice(6)}return r[T0][i]}return null}function t6(e){const t={};for(const n of e)if(n)for(const r in n)t[r]=1;return Object.keys(t)}function Fge(e,t){var n=t.config,r=n.style,i=n.axis,s=t.scaleType(e.scale)==="band"&&n.axisBand,o=e.orient,a,l,u;if(Qn(o)){const f=t6([n.axisX,n.axisY]),d=t6([n.axisTop,n.axisBottom,n.axisLeft,n.axisRight]);a={};for(u of f)a[u]=cr(o,zf(u,n.axisX,i,r),zf(u,n.axisY,i,r));l={};for(u of d)l[u]=Cge(o.signal,zf(u,n.axisTop,i,r),zf(u,n.axisBottom,i,r),zf(u,n.axisLeft,i,r),zf(u,n.axisRight,i,r))}else a=o===ko||o===hu?n.axisX:n.axisY,l=n["axis"+o[0].toUpperCase()+o.slice(1)];return a||l||s?kt({},i,a,l,s):i}function Dge(e,t,n,r){const i=Yi(e,t),s=e.orient;let o,a;const l={enter:o={opacity:qt},update:a={opacity:Rs},exit:{opacity:qt}};Rr(l,{stroke:i("domainColor"),strokeCap:i("domainCap"),strokeDash:i("domainDash"),strokeDashOffset:i("domainDashOffset"),strokeWidth:i("domainWidth"),strokeOpacity:i("domainOpacity")});const u=n6(e,0),c=n6(e,1);return o.x=a.x=cr(s,u,qt),o.x2=a.x2=cr(s,c),o.y=a.y=fo(s,u,qt),o.y2=a.y2=fo(s,c),gs({type:GC,role:Qde,from:r,encode:l},n)}function n6(e,t){return{scale:e.scale,range:t}}function Mge(e,t,n,r,i){const s=Yi(e,t),o=e.orient,a=e.gridScale,l=jb(o,1,-1),u=Tge(e.offset,l);let c,f,d;const h={enter:c={opacity:qt},update:d={opacity:Rs},exit:f={opacity:qt}};Rr(h,{stroke:s("gridColor"),strokeCap:s("gridCap"),strokeDash:s("gridDash"),strokeDashOffset:s("gridDashOffset"),strokeOpacity:s("gridOpacity"),strokeWidth:s("gridWidth")});const p={scale:e.scale,field:Ts,band:i.band,extra:i.extra,offset:i.offset,round:s("tickRound")},g=cr(o,{signal:"height"},{signal:"width"}),m=a?{scale:a,range:0,mult:l,offset:u}:{value:0,offset:u},v=a?{scale:a,range:1,mult:l,offset:u}:kt(g,{mult:l,offset:u});return c.x=d.x=cr(o,p,m),c.y=d.y=fo(o,p,m),c.x2=d.x2=fo(o,v),c.y2=d.y2=cr(o,v),f.x=cr(o,p),f.y=fo(o,p),gs({type:GC,role:ehe,key:Ts,from:r,encode:h},n)}function Tge(e,t){if(t!==1)if(!Pe(e))e=Qn(t)?{signal:`(${t.signal}) * (${e||0})`}:t*(e||0);else{let n=e=kt({},e);for(;n.mult!=null;)if(Pe(n.mult))n=n.mult=kt({},n.mult);else return n.mult=Qn(t)?{signal:`(${n.mult}) * (${t.signal})`}:n.mult*t,e;n.mult=t}return e}function Rge(e,t,n,r,i,s){const o=Yi(e,t),a=e.orient,l=jb(a,-1,1);let u,c,f;const d={enter:u={opacity:qt},update:f={opacity:Rs},exit:c={opacity:qt}};Rr(d,{stroke:o("tickColor"),strokeCap:o("tickCap"),strokeDash:o("tickDash"),strokeDashOffset:o("tickDashOffset"),strokeOpacity:o("tickOpacity"),strokeWidth:o("tickWidth")});const h=ur(i);h.mult=l;const p={scale:e.scale,field:Ts,band:s.band,extra:s.extra,offset:s.offset,round:o("tickRound")};return f.y=u.y=cr(a,qt,p),f.y2=u.y2=cr(a,h),c.x=cr(a,p),f.x=u.x=fo(a,qt,p),f.x2=u.x2=fo(a,h),c.y=fo(a,p),gs({type:GC,role:nhe,key:Ts,from:r,encode:d},n)}function a_(e,t,n,r,i){return{signal:'flush(range("'+e+'"), scale("'+e+'", datum.value), '+t+","+n+","+r+","+i+")"}}function Nge(e,t,n,r,i,s){const o=Yi(e,t),a=e.orient,l=e.scale,u=jb(a,-1,1),c=Sc(o("labelFlush")),f=Sc(o("labelFlushOffset")),d=o("labelAlign"),h=o("labelBaseline");let p=c===0||!!c,g;const m=ur(i);m.mult=u,m.offset=ur(o("labelPadding")||0),m.offset.mult=u;const v={scale:l,field:Ts,band:.5,offset:TB(s.offset,o("labelOffset"))},b=cr(a,p?a_(l,c,'"left"','"right"','"center"'):{value:"center"},_ge(a,"left","right")),x=cr(a,PB(a,"bottom","top"),p?a_(l,c,'"top"','"bottom"','"middle"'):{value:"middle"}),_=a_(l,c,`-(${f})`,f,0);p=p&&f;const w={opacity:qt,x:cr(a,v,m),y:fo(a,v,m)},A={enter:w,update:g={opacity:Rs,text:{field:qC},x:w.x,y:w.y,align:b,baseline:x},exit:{opacity:qt,x:w.x,y:w.y}};Rr(A,{dx:!d&&p?cr(a,_):null,dy:!h&&p?fo(a,_):null}),Rr(A,{angle:o("labelAngle"),fill:o("labelColor"),fillOpacity:o("labelOpacity"),font:o("labelFont"),fontSize:o("labelFontSize"),fontWeight:o("labelFontWeight"),fontStyle:o("labelFontStyle"),limit:o("labelLimit"),lineHeight:o("labelLineHeight")},{align:d,baseline:h});const E=o("labelBound");let k=o("labelOverlap");return k=k||E?{separation:o("labelSeparation"),method:k,order:"datum.index",bound:E?{scale:l,orient:a,tolerance:E}:null}:void 0,g.align!==b&&(g.align=ud(g.align,b)),g.baseline!==x&&(g.baseline=ud(g.baseline,x)),gs({type:bf,role:the,style:T0,key:Ts,from:r,encode:A,overlap:k},n)}function Oge(e,t,n,r){const i=Yi(e,t),s=e.orient,o=jb(s,-1,1);let a,l;const u={enter:a={opacity:qt,anchor:ur(i("titleAnchor",null)),align:{signal:YC}},update:l=kt({},a,{opacity:Rs,text:ur(e.title)}),exit:{opacity:qt}},c={signal:`lerp(range("${e.scale}"), ${Pb(0,1,.5)})`};return l.x=cr(s,c),l.y=fo(s,c),a.angle=cr(s,qt,$ge(o,90)),a.baseline=cr(s,PB(s,hu,ko),{value:hu}),l.angle=a.angle,l.baseline=a.baseline,Rr(u,{fill:i("titleColor"),fillOpacity:i("titleOpacity"),font:i("titleFont"),fontSize:i("titleFontSize"),fontStyle:i("titleFontStyle"),fontWeight:i("titleFontWeight"),limit:i("titleLimit"),lineHeight:i("titleLineHeight")},{align:i("titleAlign"),angle:i("titleAngle"),baseline:i("titleBaseline")}),Lge(i,s,u,n),u.update.align=ud(u.update.align,a.align),u.update.angle=ud(u.update.angle,a.angle),u.update.baseline=ud(u.update.baseline,a.baseline),gs({type:bf,role:rhe,style:WC,from:r,encode:u},n)}function Lge(e,t,n,r){const i=(a,l)=>a!=null?(n.update[l]=ud(ur(a),n.update[l]),!1):!Vf(l,r),s=i(e("titleX"),"x"),o=i(e("titleY"),"y");n.enter.auto=o===s?ur(o):cr(t,ur(o),ur(s))}function Ige(e,t){const n=Fge(e,t),r=e.encode||{},i=r.axis||{},s=i.name||void 0,o=i.interactive,a=i.style,l=Yi(e,n),u=Rpe(l),c={scale:e.scale,ticks:!!l("ticks"),labels:!!l("labels"),grid:!!l("grid"),domain:!!l("domain"),title:e.title!=null},f=rt(t.add(Ao({},[c]))),d=rt(t.add(Phe({scale:t.scaleRef(e.scale),extra:t.property(u.extra),count:t.objectProperty(e.tickCount),values:t.objectProperty(e.values),minstep:t.property(e.tickMinStep),formatType:t.property(e.formatType),formatSpecifier:t.property(e.format)}))),h=[];let p;return c.grid&&h.push(Mge(e,n,r.grid,d,u)),c.ticks&&(p=l("tickSize"),h.push(Rge(e,n,r.ticks,d,p,u))),c.labels&&(p=c.ticks?p:0,h.push(Nge(e,n,r.labels,d,p,u))),c.domain&&h.push(Dge(e,n,r.domain,f)),c.title&&h.push(Oge(e,n,r.title,f)),zb(Rg({role:Jde,from:f,encode:Fh(Pge(l,e),i,R0),marks:h,aria:l("aria"),description:l("description"),zindex:l("zindex"),name:s,interactive:o,style:a}),t)}function Pge(e,t){const n={enter:{},update:{}};return Rr(n,{orient:e("orient"),offset:e("offset")||0,position:to(t.position,0),titlePadding:e("titlePadding"),minExtent:e("minExtent"),maxExtent:e("maxExtent"),range:{signal:`abs(span(range("${t.scale}")))`},translate:e("translate"),format:t.format,formatType:t.formatType}),n}function zB(e,t,n){const r=je(e.signals),i=je(e.scales);return n||r.forEach(s=>yB(s,t)),je(e.projections).forEach(s=>mpe(s,t)),i.forEach(s=>ipe(s,t)),je(e.data).forEach(s=>bge(s,t)),i.forEach(s=>spe(s,t)),(n||r).forEach(s=>Ihe(s,t)),je(e.axes).forEach(s=>Ige(s,t)),je(e.marks).forEach(s=>zb(s,t)),je(e.legends).forEach(s=>age(s,t)),e.title&&pge(e.title,t),t.parseLambdas(),t}const Bge=e=>Fh({enter:{x:{value:0},y:{value:0}},update:{width:{signal:"width"},height:{signal:"height"}}},e);function zge(e,t){const n=t.config,r=rt(t.root=t.add(ty())),i=jge(e,n);i.forEach(u=>yB(u,t)),t.description=e.description||n.description,t.eventConfig=n.events,t.legends=t.objectProperty(n.legend&&n.legend.layout),t.locale=n.locale;const s=t.add(Ao()),o=t.add(_B(vB(Bge(e.encode),Ib,BC,e.style,t,{pulse:rt(s)}))),a=t.add(AB({layout:t.objectProperty(e.layout),legends:t.legends,autosize:t.signalRef("autosize"),mark:r,pulse:rt(o)}));t.operators.pop(),t.pushState(rt(o),rt(a),null),zB(e,t,i),t.operators.push(a);let l=t.add(xB({mark:r,pulse:rt(a)}));return l=t.add(EB({pulse:rt(l)})),l=t.add(yf({pulse:rt(l)})),t.addData("root",new Zc(t,s,s,l)),t}function up(e,t){return t&&t.signal?{name:e,update:t.signal}:{name:e,value:t}}function jge(e,t){const n=o=>to(e[o],t[o]),r=[up("background",n("background")),up("autosize",Xde(n("autosize"))),up("padding",Zde(n("padding"))),up("width",n("width")||0),up("height",n("height")||0)],i=r.reduce((o,a)=>(o[a.name]=a,o),{}),s={};return je(e.signals).forEach(o=>{We(i,o.name)?o=kt(i[o.name],o):r.push(o),s[o.name]=o}),je(t.signals).forEach(o=>{!We(s,o.name)&&!We(i,o.name)&&r.push(o)}),r}function jB(e,t){this.config=e||{},this.options=t||{},this.bindings=[],this.field={},this.signals={},this.lambdas={},this.scales={},this.events={},this.data={},this.streams=[],this.updates=[],this.operators=[],this.eventConfig=null,this.locale=null,this._id=0,this._subid=0,this._nextsub=[0],this._parent=[],this._encode=[],this._lookup=[],this._markpath=[]}function r6(e){this.config=e.config,this.options=e.options,this.legends=e.legends,this.field=Object.create(e.field),this.signals=Object.create(e.signals),this.lambdas=Object.create(e.lambdas),this.scales=Object.create(e.scales),this.events=Object.create(e.events),this.data=Object.create(e.data),this.streams=[],this.updates=[],this.operators=[],this._id=0,this._subid=++e._nextsub[0],this._nextsub=e._nextsub,this._parent=e._parent.slice(),this._encode=e._encode.slice(),this._lookup=e._lookup.slice(),this._markpath=e._markpath}jB.prototype=r6.prototype={parse(e){return zB(e,this)},fork(){return new r6(this)},isSubscope(){return this._subid>0},toRuntime(){return this.finish(),{description:this.description,operators:this.operators,streams:this.streams,updates:this.updates,bindings:this.bindings,eventConfig:this.eventConfig,locale:this.locale}},id(){return(this._subid?this._subid+":":0)+this._id++},add(e){return this.operators.push(e),e.id=this.id(),e.refs&&(e.refs.forEach(t=>{t.$ref=e.id}),e.refs=null),e},proxy(e){const t=e instanceof GE?rt(e):e;return this.add(Jhe({value:t}))},addStream(e){return this.streams.push(e),e.id=this.id(),e},addUpdate(e){return this.updates.push(e),e},finish(){let e,t;this.root&&(this.root.root=!0);for(e in this.signals)this.signals[e].signal=e;for(e in this.scales)this.scales[e].scale=e;function n(r,i,s){let o,a;r&&(o=r.data||(r.data={}),a=o[i]||(o[i]=[]),a.push(s))}for(e in this.data){t=this.data[e],n(t.input,e,"input"),n(t.output,e,"output"),n(t.values,e,"values");for(const r in t.index)n(t.index[r],e,"index:"+r)}return this},pushState(e,t,n){this._encode.push(rt(this.add(yf({pulse:e})))),this._parent.push(t),this._lookup.push(n?rt(this.proxy(n)):null),this._markpath.push(-1)},popState(){this._encode.pop(),this._parent.pop(),this._lookup.pop(),this._markpath.pop()},parent(){return jt(this._parent)},encode(){return jt(this._encode)},lookup(){return jt(this._lookup)},markpath(){const e=this._markpath;return++e[e.length-1]},fieldRef(e,t){if(ze(e))return Mg(e,t);e.signal||ae("Unsupported field reference: "+De(e));const n=e.signal;let r=this.field[n];if(!r){const i={name:this.signalRef(n)};t&&(i.as=t),this.field[n]=r=rt(this.add(Uhe(i)))}return r},compareRef(e){let t=!1;const n=s=>Qn(s)?(t=!0,this.signalRef(s.signal)):Che(s)?(t=!0,this.exprRef(s.expr)):s,r=je(e.field).map(n),i=je(e.order).map(n);return t?rt(this.add(qM({fields:r,orders:i}))):jM(r,i)},keyRef(e,t){let n=!1;const r=s=>Qn(s)?(n=!0,rt(i[s.signal])):s,i=this.signals;return e=je(e).map(r),n?rt(this.add(qhe({fields:e,flat:t}))):Ehe(e,t)},sortRef(e){if(!e)return e;const t=Ob(e.op,e.field),n=e.order||Ahe;return n.signal?rt(this.add(qM({fields:t,orders:this.signalRef(n.signal)}))):jM(t,n)},event(e,t){const n=e+":"+t;if(!this.events[n]){const r=this.id();this.streams.push({id:r,source:e,type:t}),this.events[n]=r}return this.events[n]},hasOwnSignal(e){return We(this.signals,e)},addSignal(e,t){this.hasOwnSignal(e)&&ae("Duplicate signal name: "+De(e));const n=t instanceof GE?t:this.add(ty(t));return this.signals[e]=n},getSignal(e){return this.signals[e]||ae("Unrecognized signal name: "+De(e)),this.signals[e]},signalRef(e){return this.signals[e]?rt(this.signals[e]):(We(this.lambdas,e)||(this.lambdas[e]=this.add(ty(null))),rt(this.lambdas[e]))},parseLambdas(){const e=Object.keys(this.lambdas);for(let t=0,n=e.length;t0?",":"")+(Pe(i)?i.signal||JC(i):De(i))}return n+"]"}function qge(e){let t="{",n=0,r,i;for(r in e)i=e[r],t+=(++n>1?",":"")+De(r)+":"+(Pe(i)?i.signal||JC(i):De(i));return t+"}"}function Wge(){const e="sans-serif",r="#4c78a8",i="#000",s="#888",o="#ddd";return{description:"Vega visualization",padding:0,autosize:"pad",background:null,events:{defaults:{allow:["wheel"]}},group:null,mark:null,arc:{fill:r},area:{fill:r},image:null,line:{stroke:r,strokeWidth:2},path:{stroke:r},rect:{fill:r},rule:{stroke:i},shape:{stroke:r},symbol:{fill:r,size:64},text:{fill:i,font:e,fontSize:11},trail:{fill:r,size:2},style:{"guide-label":{fill:i,font:e,fontSize:10},"guide-title":{fill:i,font:e,fontSize:11,fontWeight:"bold"},"group-title":{fill:i,font:e,fontSize:13,fontWeight:"bold"},"group-subtitle":{fill:i,font:e,fontSize:12},point:{size:30,strokeWidth:2,shape:"circle"},circle:{size:30,strokeWidth:2},square:{size:30,strokeWidth:2,shape:"square"},cell:{fill:"transparent",stroke:o},view:{fill:"transparent"}},title:{orient:"top",anchor:"middle",offset:4,subtitlePadding:3},axis:{minExtent:0,maxExtent:200,bandPosition:.5,domain:!0,domainWidth:1,domainColor:s,grid:!1,gridWidth:1,gridColor:o,labels:!0,labelAngle:0,labelLimit:180,labelOffset:0,labelPadding:2,ticks:!0,tickColor:s,tickOffset:0,tickRound:!0,tickSize:5,tickWidth:1,titlePadding:4},axisBand:{tickOffset:-.5},projection:{type:"mercator"},legend:{orient:"right",padding:0,gridAlign:"each",columnPadding:10,rowPadding:2,symbolDirection:"vertical",gradientDirection:"vertical",gradientLength:200,gradientThickness:16,gradientStrokeColor:o,gradientStrokeWidth:0,gradientLabelOffset:2,labelAlign:"left",labelBaseline:"middle",labelLimit:160,labelOffset:4,labelOverlap:!0,symbolLimit:30,symbolType:"circle",symbolSize:100,symbolOffset:0,symbolStrokeWidth:1.5,symbolBaseFillColor:"transparent",symbolBaseStrokeColor:s,titleLimit:180,titleOrient:"top",titlePadding:5,layout:{offset:18,direction:"horizontal",left:{direction:"vertical"},right:{direction:"vertical"}}},range:{category:{scheme:"tableau10"},ordinal:{scheme:"blues"},heatmap:{scheme:"yellowgreenblue"},ramp:{scheme:"blues"},diverging:{scheme:"blueorange",extent:[1,0]},symbol:["circle","square","triangle-up","cross","diamond","triangle-right","triangle-down","triangle-left"]}}}function Hge(e,t,n){return Pe(e)||ae("Input Vega specification must be an object."),t=gh(Wge(),t,e.config),zge(e,new jB(t,n)).toRuntime()}var Gge="5.33.1";kt(Od,OZ,fre,qre,$se,woe,Xae,$ae,Zae,_le,Mle,Ple);const Yge=Object.freeze(Object.defineProperty({__proto__:null,Bounds:Hn,CanvasHandler:E0,CanvasRenderer:gv,DATE:ji,DAY:Wr,DAYOFYEAR:ca,Dataflow:sd,Debug:LR,DisallowedObjectProperties:uk,Error:ck,EventStream:jy,Gradient:$9,GroupItem:cb,HOURS:ds,Handler:w3,HybridHandler:bL,HybridRenderer:eE,Info:OR,Item:ub,MILLISECONDS:vo,MINUTES:hs,MONTH:Vr,Marks:ps,MultiPulse:Lk,None:NR,Operator:cn,Parameters:zy,Pulse:Ql,QUARTER:zi,RenderType:Ul,Renderer:w0,ResourceLoader:O9,SECONDS:Ls,SVGHandler:oL,SVGRenderer:$3,SVGStringRenderer:yL,Scenegraph:J9,TIME_UNITS:Sk,Transform:ne,View:sB,WEEK:Zn,Warn:fk,YEAR:Dr,accessor:Gi,accessorFields:Yr,accessorName:On,array:je,ascending:vh,bandwidthNRD:zk,bin:gO,bootstrapCI:mO,boundClip:FL,boundContext:y0,boundItem:Xw,boundMark:V9,boundStroke:gl,changeset:Eu,clampRange:YR,codegenExpression:TP,compare:mk,constant:ei,cumulativeLogNormal:Gk,cumulativeNormal:qy,cumulativeUniform:Kk,dayofyear:wN,debounce:vk,defaultLocale:Mk,definition:dO,densityLogNormal:Hk,densityNormal:jk,densityUniform:Xk,domChild:Kn,domClear:Es,domCreate:zl,domFind:_3,dotbin:vO,error:ae,expressionFunction:qn,extend:kt,extent:aa,extentIndex:VR,falsy:Cl,fastmap:yh,field:Os,flush:XR,font:gb,fontFamily:_0,fontSize:xa,format:i1,formatLocale:Y1,formats:Nk,hasOwnProperty:We,id:r0,identity:Qr,inferType:tO,inferTypes:nO,ingest:Kt,inherits:Te,inrange:Zf,interpolate:JS,interpolateColors:ab,interpolateRange:p9,intersect:kL,intersectBoxLine:Jf,intersectPath:o3,intersectPoint:a3,intersectRule:I9,isArray:fe,isBoolean:wu,isDate:Zl,isFunction:St,isIterable:KR,isNumber:Gt,isObject:Pe,isRegExp:yk,isString:ze,isTuple:Py,key:bk,lerp:ZR,lineHeight:cu,loader:Ly,locale:QN,logger:dk,lruCache:JR,markup:C3,merge:QR,mergeConfig:gh,multiLineOffset:y3,one:ph,pad:eN,panLinear:jR,panLog:UR,panPow:qR,panSymlog:WR,parse:Hge,parseExpression:FP,parseSelector:Fu,path:Vy,pathCurves:r3,pathEqual:DL,pathParse:jd,pathRectangle:M9,pathRender:bg,pathSymbols:D9,pathTrail:T9,peek:jt,point:vb,projection:Y3,quantileLogNormal:Yk,quantileNormal:Wy,quantileUniform:Zk,quantiles:Pk,quantizeInterpolator:g9,quarter:HR,quartiles:Bk,get random(){return Is},randomInteger:BK,randomKDE:qk,randomLCG:PK,randomLogNormal:bO,randomMixture:xO,randomNormal:Uk,randomUniform:_O,read:sO,regressionConstant:Jk,regressionExp:EO,regressionLinear:Qk,regressionLoess:SO,regressionLog:wO,regressionPoly:kO,regressionPow:AO,regressionQuad:eS,renderModule:yb,repeat:vp,resetDefaultLocale:OX,resetSVGClipId:N9,resetSVGDefIds:Fne,responseType:iO,runtimeContext:GP,sampleCurve:Gy,sampleLogNormal:Wk,sampleNormal:Uy,sampleUniform:Vk,scale:Vt,sceneEqual:F3,sceneFromJSON:K9,scenePickVisit:av,sceneToJSON:X9,sceneVisit:yo,sceneZOrder:l3,scheme:QS,serializeXML:pL,setHybridRendererOptions:kne,setRandom:LK,span:i0,splitAccessPath:va,stringValue:De,textMetrics:ls,timeBin:BN,timeFloor:FN,timeFormatLocale:hg,timeInterval:wh,timeOffset:TN,timeSequence:ON,timeUnitSpecifier:_N,timeUnits:Ck,toBoolean:xk,toDate:_k,toNumber:Hr,toSet:mo,toString:wk,transform:hO,transforms:Od,truncate:tN,truthy:fs,tupleid:it,typeParsers:Mw,utcFloor:DN,utcInterval:Eh,utcOffset:RN,utcSequence:LN,utcdayofyear:kN,utcquarter:GR,utcweek:SN,version:Gge,visitArray:Dl,week:EN,writeConfig:mh,zero:Ol,zoomLinear:hk,zoomLog:pk,zoomPow:z1,zoomSymlog:gk},Symbol.toStringTag,{value:"Module"}));function Vge(e,t,n){let r;t.x2&&(t.x?(n&&e.x>e.x2&&(r=e.x,e.x=e.x2,e.x2=r),e.width=e.x2-e.x):e.x=e.x2-(e.width||0)),t.xc&&(e.x=e.xc-(e.width||0)/2),t.y2&&(t.y?(n&&e.y>e.y2&&(r=e.y,e.y=e.y2,e.y2=r),e.height=e.y2-e.y):e.y=e.y2-(e.height||0)),t.yc&&(e.y=e.yc-(e.height||0)/2)}var Xge={NaN:NaN,E:Math.E,LN2:Math.LN2,LN10:Math.LN10,LOG2E:Math.LOG2E,LOG10E:Math.LOG10E,PI:Math.PI,SQRT1_2:Math.SQRT1_2,SQRT2:Math.SQRT2,MIN_VALUE:Number.MIN_VALUE,MAX_VALUE:Number.MAX_VALUE},Kge={"*":(e,t)=>e*t,"+":(e,t)=>e+t,"-":(e,t)=>e-t,"/":(e,t)=>e/t,"%":(e,t)=>e%t,">":(e,t)=>e>t,"<":(e,t)=>ee<=t,">=":(e,t)=>e>=t,"==":(e,t)=>e==t,"!=":(e,t)=>e!=t,"===":(e,t)=>e===t,"!==":(e,t)=>e!==t,"&":(e,t)=>e&t,"|":(e,t)=>e|t,"^":(e,t)=>e^t,"<<":(e,t)=>e<>":(e,t)=>e>>t,">>>":(e,t)=>e>>>t},Zge={"+":e=>+e,"-":e=>-e,"~":e=>~e,"!":e=>!e};const Jge=Array.prototype.slice,Yu=(e,t,n)=>{const r=n?n(t[0]):t[0];return r[e].apply(r,Jge.call(t,1))},Qge=(e,t,n,r,i,s,o)=>new Date(e,t||0,n??1,r||0,i||0,s||0,o||0);var e0e={isNaN:Number.isNaN,isFinite:Number.isFinite,abs:Math.abs,acos:Math.acos,asin:Math.asin,atan:Math.atan,atan2:Math.atan2,ceil:Math.ceil,cos:Math.cos,exp:Math.exp,floor:Math.floor,log:Math.log,max:Math.max,min:Math.min,pow:Math.pow,random:Math.random,round:Math.round,sin:Math.sin,sqrt:Math.sqrt,tan:Math.tan,clamp:(e,t,n)=>Math.max(t,Math.min(n,e)),now:Date.now,utc:Date.UTC,datetime:Qge,date:e=>new Date(e).getDate(),day:e=>new Date(e).getDay(),year:e=>new Date(e).getFullYear(),month:e=>new Date(e).getMonth(),hours:e=>new Date(e).getHours(),minutes:e=>new Date(e).getMinutes(),seconds:e=>new Date(e).getSeconds(),milliseconds:e=>new Date(e).getMilliseconds(),time:e=>new Date(e).getTime(),timezoneoffset:e=>new Date(e).getTimezoneOffset(),utcdate:e=>new Date(e).getUTCDate(),utcday:e=>new Date(e).getUTCDay(),utcyear:e=>new Date(e).getUTCFullYear(),utcmonth:e=>new Date(e).getUTCMonth(),utchours:e=>new Date(e).getUTCHours(),utcminutes:e=>new Date(e).getUTCMinutes(),utcseconds:e=>new Date(e).getUTCSeconds(),utcmilliseconds:e=>new Date(e).getUTCMilliseconds(),length:e=>e.length,join:function(){return Yu("join",arguments)},indexof:function(){return Yu("indexOf",arguments)},lastindexof:function(){return Yu("lastIndexOf",arguments)},slice:function(){return Yu("slice",arguments)},reverse:e=>e.slice().reverse(),sort:e=>e.slice().sort(vh),parseFloat,parseInt,upper:e=>String(e).toUpperCase(),lower:e=>String(e).toLowerCase(),substring:function(){return Yu("substring",arguments,String)},split:function(){return Yu("split",arguments,String)},replace:function(){return Yu("replace",arguments,String)},trim:e=>String(e).trim(),btoa:e=>btoa(e),atob:e=>atob(e),regexp:RegExp,test:(e,t)=>RegExp(e).test(t)};const t0e=["view","item","group","xy","x","y"],QE=new Set([Function,eval,setTimeout,setInterval]);typeof setImmediate=="function"&&QE.add(setImmediate);const n0e={Literal:(e,t)=>t.value,Identifier:(e,t)=>{const n=t.name;return e.memberDepth>0?n:n==="datum"?e.datum:n==="event"?e.event:n==="item"?e.item:Xge[n]||e.params["$"+n]},MemberExpression:(e,t)=>{const n=!t.computed,r=e(t.object);n&&(e.memberDepth+=1);const i=e(t.property);if(n&&(e.memberDepth-=1),QE.has(r[i])){console.error(`Prevented interpretation of member "${i}" which could lead to insecure code execution`);return}return r[i]},CallExpression:(e,t)=>{const n=t.arguments;let r=t.callee.name;return r.startsWith("_")&&(r=r.slice(1)),r==="if"?e(n[0])?e(n[1]):e(n[2]):(e.fn[r]||e0e[r]).apply(e.fn,n.map(e))},ArrayExpression:(e,t)=>t.elements.map(e),BinaryExpression:(e,t)=>Kge[t.operator](e(t.left),e(t.right)),UnaryExpression:(e,t)=>Zge[t.operator](e(t.argument)),ConditionalExpression:(e,t)=>e(t.test)?e(t.consequent):e(t.alternate),LogicalExpression:(e,t)=>t.operator==="&&"?e(t.left)&&e(t.right):e(t.left)||e(t.right),ObjectExpression:(e,t)=>t.properties.reduce((n,r)=>{e.memberDepth+=1;const i=e(r.key);e.memberDepth-=1;const s=e(r.value);return uk.has(i)?console.error(`Prevented interpretation of property "${i}" which could lead to insecure code execution`):QE.has(s)?console.error(`Prevented interpretation of method "${s}" which could lead to insecure code execution`):n[i]=s,n},{})};function cp(e,t,n,r,i,s){const o=a=>n0e[a.type](o,a);return o.memberDepth=0,o.fn=Object.create(t),o.params=n,o.datum=r,o.event=i,o.item=s,t0e.forEach(a=>o.fn[a]=function(){return i.vega[a](...arguments)}),o(e)}var r0e={operator(e,t){const n=t.ast,r=e.functions;return i=>cp(n,r,i)},parameter(e,t){const n=t.ast,r=e.functions;return(i,s)=>cp(n,r,s,i)},event(e,t){const n=t.ast,r=e.functions;return i=>cp(n,r,void 0,void 0,i)},handler(e,t){const n=t.ast,r=e.functions;return(i,s)=>{const o=s.item&&s.item.datum;return cp(n,r,i,o,s)}},encode(e,t){const{marktype:n,channels:r}=t,i=e.functions,s=n==="group"||n==="image"||n==="rect";return(o,a)=>{const l=o.datum;let u=0,c;for(const f in r)c=cp(r[f].ast,i,a,l,void 0,o),o[f]!==c&&(o[f]=c,u=1);return n!=="rule"&&Vge(o,r,s),u}}};const i0e="5.23.0",s0e={version:i0e};function QC(e){return Se(e,"or")}function e$(e){return Se(e,"and")}function t$(e){return Se(e,"not")}function $1(e,t){if(t$(e))$1(e.not,t);else if(e$(e))for(const n of e.and)$1(n,t);else if(QC(e))for(const n of e.or)$1(n,t);else t(e)}function cd(e,t){return t$(e)?{not:cd(e.not,t)}:e$(e)?{and:e.and.map(n=>cd(n,t))}:QC(e)?{or:e.or.map(n=>cd(n,t))}:t(e)}const gt=structuredClone;function UB(e){throw new Error(e)}function Kd(e,t){const n={};for(const r of t)We(e,r)&&(n[r]=e[r]);return n}function Pi(e,t){const n={...e};for(const r of t)delete n[r];return n}Set.prototype.toJSON=function(){return`Set(${[...this].map(e=>ln(e)).join(",")})`};function It(e){if(Gt(e))return e;const t=ze(e)?e:ln(e);if(t.length<250)return t;let n=0;for(let r=0;ra===0?o:`[${o}]`),s=i.map((o,a)=>i.slice(0,a+1).join(""));for(const o of s)t.add(o)}return t}function i$(e,t){return e===void 0||t===void 0?!0:r$(tA(e),tA(t))}function an(e){return Ae(e).length===0}const Ae=Object.keys,Mr=Object.values,pu=Object.entries;function Ng(e){return e===!0||e===!1}function _n(e){const t=e.replace(/\W/g,"_");return(e.match(/^\d+/)?"_":"")+t}function ig(e,t){return t$(e)?`!(${ig(e.not,t)})`:e$(e)?`(${e.and.map(n=>ig(n,t)).join(") && (")})`:QC(e)?`(${e.or.map(n=>ig(n,t)).join(") || (")})`:t(e)}function ny(e,t){if(t.length===0)return!0;const n=t.shift();return n in e&&ny(e[n],t)&&delete e[n],an(e)}function N0(e){return e.charAt(0).toUpperCase()+e.substr(1)}function s$(e,t="datum"){const n=va(e),r=[];for(let i=1;i<=n.length;i++){const s=`[${n.slice(0,i).map(De).join("][")}]`;r.push(`${t}${s}`)}return r.join(" && ")}function HB(e,t="datum"){return`${t}[${De(va(e).join("."))}]`}function Qt(e){return`datum['${e.replaceAll("'","\\'")}']`}function l0e(e){return e.replace(/(\[|\]|\.|'|")/g,"\\$1")}function Bs(e){return`${va(e).map(l0e).join("\\.")}`}function Jc(e,t,n){return e.replace(new RegExp(t.replace(/[-/\\^$*+?.()|[\]{}]/g,"\\$&"),"g"),n)}function Th(e){return`${va(e).join(".")}`}function Jd(e){return e?va(e).length:0}function jn(...e){return e.find(t=>t!==void 0)}let GB=42;function YB(e){const t=++GB;return e?String(e)+t:t}function u0e(){GB=42}function VB(e){return XB(e)?e:`__${e}`}function XB(e){return e.startsWith("__")}function Og(e){if(e!==void 0)return(e%360+360)%360}function Ub(e){return Gt(e)?!0:!isNaN(e)&&!isNaN(parseFloat(e))}const i6=Object.getPrototypeOf(structuredClone({}));function ss(e,t){if(e===t)return!0;if(e&&t&&typeof e=="object"&&typeof t=="object"){if(e.constructor.name!==t.constructor.name)return!1;let n,r;if(Array.isArray(e)){if(n=e.length,n!=t.length)return!1;for(r=n;r--!==0;)if(!ss(e[r],t[r]))return!1;return!0}if(e instanceof Map&&t instanceof Map){if(e.size!==t.size)return!1;for(const s of e.entries())if(!t.has(s[0]))return!1;for(const s of e.entries())if(!ss(s[1],t.get(s[0])))return!1;return!0}if(e instanceof Set&&t instanceof Set){if(e.size!==t.size)return!1;for(const s of e.entries())if(!t.has(s[0]))return!1;return!0}if(ArrayBuffer.isView(e)&&ArrayBuffer.isView(t)){if(n=e.length,n!=t.length)return!1;for(r=n;r--!==0;)if(e[r]!==t[r])return!1;return!0}if(e.constructor===RegExp)return e.source===t.source&&e.flags===t.flags;if(e.valueOf!==Object.prototype.valueOf&&e.valueOf!==i6.valueOf)return e.valueOf()===t.valueOf();if(e.toString!==Object.prototype.toString&&e.toString!==i6.toString)return e.toString()===t.toString();const i=Object.keys(e);if(n=i.length,n!==Object.keys(t).length)return!1;for(r=n;r--!==0;)if(!Object.prototype.hasOwnProperty.call(t,i[r]))return!1;for(r=n;r--!==0;){const s=i[r];if(!ss(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function ln(e){const t=[];return(function n(r){if(r&&r.toJSON&&typeof r.toJSON=="function"&&(r=r.toJSON()),r===void 0)return;if(typeof r=="number")return isFinite(r)?""+r:"null";if(typeof r!="object")return JSON.stringify(r);let i,s;if(Array.isArray(r)){for(s="[",i=0;iKb(e[t])?_n(`_${t}_${pu(e[t])}`):_n(`_${t}_${e[t]}`)).join("")}function dn(e){return e===!0||wf(e)&&!e.binned}function wr(e){return e==="binned"||wf(e)&&e.binned===!0}function wf(e){return Pe(e)}function Kb(e){return Se(e,"param")}function s6(e){switch(e){case nl:case rl:case bl:case qi:case ka:case Sa:case Nu:case xl:case Tu:case Ru:case Wi:return 6;case Ou:return 4;default:return 10}}function P0(e){return Se(e,"expr")}function Ar(e,{level:t}={level:0}){const n=Ae(e||{}),r={};for(const i of n)r[i]=t===0?ns(e[i]):Ar(e[i],{level:t-1});return r}function uz(e){const{anchor:t,frame:n,offset:r,orient:i,angle:s,limit:o,color:a,subtitleColor:l,subtitleFont:u,subtitleFontSize:c,subtitleFontStyle:f,subtitleFontWeight:d,subtitleLineHeight:h,subtitlePadding:p,...g}=e,m={...g,...a?{fill:a}:{}},v={...t?{anchor:t}:{},...n?{frame:n}:{},...r?{offset:r}:{},...i?{orient:i}:{},...s!==void 0?{angle:s}:{},...o!==void 0?{limit:o}:{}},b={...l?{subtitleColor:l}:{},...u?{subtitleFont:u}:{},...c?{subtitleFontSize:c}:{},...f?{subtitleFontStyle:f}:{},...d?{subtitleFontWeight:d}:{},...h?{subtitleLineHeight:h}:{},...p?{subtitlePadding:p}:{}},x=Kd(e,["align","baseline","dx","dy","limit"]);return{titleMarkConfig:m,subtitleMarkConfig:x,nonMarkTitleProperties:v,subtitle:b}}function Nl(e){return ze(e)||fe(e)&&ze(e[0])}function tt(e){return Se(e,"signal")}function Ef(e){return Se(e,"step")}function N0e(e){return fe(e)?!1:Se(e,"fields")&&!Se(e,"data")}function O0e(e){return fe(e)?!1:Se(e,"fields")&&Se(e,"data")}function Ka(e){return fe(e)?!1:Se(e,"field")&&Se(e,"data")}const L0e={aria:1,description:1,ariaRole:1,ariaRoleDescription:1,blend:1,opacity:1,fill:1,fillOpacity:1,stroke:1,strokeCap:1,strokeWidth:1,strokeOpacity:1,strokeDash:1,strokeDashOffset:1,strokeJoin:1,strokeOffset:1,strokeMiterLimit:1,startAngle:1,endAngle:1,padAngle:1,innerRadius:1,outerRadius:1,size:1,shape:1,interpolate:1,tension:1,orient:1,align:1,baseline:1,text:1,dir:1,dx:1,dy:1,ellipsis:1,limit:1,radius:1,theta:1,angle:1,font:1,fontSize:1,fontWeight:1,fontStyle:1,lineBreak:1,lineHeight:1,cursor:1,href:1,tooltip:1,cornerRadius:1,cornerRadiusTopLeft:1,cornerRadiusTopRight:1,cornerRadiusBottomLeft:1,cornerRadiusBottomRight:1,aspect:1,width:1,height:1,url:1,smooth:1},I0e=Ae(L0e),P0e={arc:1,area:1,group:1,image:1,line:1,path:1,rect:1,rule:1,shape:1,symbol:1,text:1,trail:1},nA=["cornerRadius","cornerRadiusTopLeft","cornerRadiusTopRight","cornerRadiusBottomLeft","cornerRadiusBottomRight"];function cz(e){const t=fe(e.condition)?e.condition.map(o6):o6(e.condition);return{...ns(e),condition:t}}function ns(e){if(P0(e)){const{expr:t,...n}=e;return{signal:t,...n}}return e}function o6(e){if(P0(e)){const{expr:t,...n}=e;return{signal:t,...n}}return e}function vn(e){if(P0(e)){const{expr:t,...n}=e;return{signal:t,...n}}return tt(e)?e:e!==void 0?{value:e}:void 0}function B0e(e){return tt(e)?e.signal:De(e)}function a6(e){return tt(e)?e.signal:De(e.value)}function uo(e){return tt(e)?e.signal:e==null?null:De(e)}function z0e(e,t,n){for(const r of n){const i=ha(r,t.markDef,t.config);i!==void 0&&(e[r]=vn(i))}return e}function fz(e){return[].concat(e.type,e.style??[])}function on(e,t,n,r={}){const{vgChannel:i,ignoreVgConfig:s}=r;return i&&Se(t,i)?t[i]:t[e]!==void 0?t[e]:s&&(!i||i===e)?void 0:ha(e,t,n,r)}function ha(e,t,n,{vgChannel:r}={}){const i=rA(e,t,n.style);return jn(r?i:void 0,i,r?n[t.type][r]:void 0,n[t.type][e],r?n.mark[r]:n.mark[e])}function rA(e,t,n){return dz(e,fz(t),n)}function dz(e,t,n){t=je(t);let r;for(const i of t){const s=n[i];Se(s,e)&&(r=s[e])}return r}function hz(e,t){return je(e).reduce((n,r)=>(n.field.push(Ne(r,t)),n.order.push(r.sort??"ascending"),n),{field:[],order:[]})}function pz(e,t){const n=[...e];return t.forEach(r=>{for(const i of n)if(ss(i,r))return;n.push(r)}),n}function gz(e,t){return ss(e,t)||!t?e:e?[...je(e),...je(t)].join(", "):t}function mz(e,t){const n=e.value,r=t.value;if(n==null||r===null)return{explicit:e.explicit,value:null};if((Nl(n)||tt(n))&&(Nl(r)||tt(r)))return{explicit:e.explicit,value:gz(n,r)};if(Nl(n)||tt(n))return{explicit:e.explicit,value:n};if(Nl(r)||tt(r))return{explicit:e.explicit,value:r};if(!Nl(n)&&!tt(n)&&!Nl(r)&&!tt(r))return{explicit:e.explicit,value:pz(n,r)};throw new Error("It should never reach here")}function g$(e){return`Invalid specification ${ln(e)}. Make sure the specification includes at least one of the following properties: "mark", "layer", "facet", "hconcat", "vconcat", "concat", or "repeat".`}const j0e='Autosize "fit" only works for single views and layered views.';function l6(e){return`${e=="width"?"Width":"Height"} "container" only works for single views and layered views.`}function u6(e){const t=e=="width"?"Width":"Height",n=e=="width"?"x":"y";return`${t} "container" only works well with autosize "fit" or "fit-${n}".`}function c6(e){return e?`Dropping "fit-${e}" because spec has discrete ${Hi(e)}.`:'Dropping "fit" because spec has discrete size.'}function m$(e){return`Unknown field for ${e}. Cannot calculate view size.`}function f6(e){return`Cannot project a selection on encoding channel "${e}", which has no field.`}function U0e(e,t){return`Cannot project a selection on encoding channel "${e}" as it uses an aggregate function ("${t}").`}function q0e(e){return`The "nearest" transform is not supported for ${e} marks.`}function vz(e){return`Selection not supported for ${e} yet.`}function W0e(e){return`Cannot find a selection named "${e}".`}const H0e="Scale bindings are currently only supported for scales with unbinned, continuous domains.",G0e="Sequntial scales are deprecated. The available quantitative scale type values are linear, log, pow, sqrt, symlog, time and utc",Y0e="Legend bindings are only supported for selections over an individual field or encoding channel.";function V0e(e){return`Lookups can only be performed on selection parameters. "${e}" is a variable parameter.`}function X0e(e){return`Cannot define and lookup the "${e}" selection in the same view. Try moving the lookup into a second, layered view?`}const K0e="The same selection must be used to override scale domains in a layered view.",Z0e='Interval selections should be initialized using "x", "y", "longitude", or "latitude" keys.';function J0e(e){return`Unknown repeated value "${e}".`}function d6(e){return`The "columns" property cannot be used when "${e}" has nested row/column.`}const Q0e="Multiple timer selections in one unit spec are not supported. Ignoring all but the first.",v$="Animation involving facet, layer, or concat is currently unsupported.";function eme(e){return`A "field" or "encoding" must be specified when using a selection as a scale domain. Using "field": ${De(e)}.`}function tme(e,t,n,r){return(e.length?"Multiple ":"No ")+`matching ${De(t)} encoding found for selection ${De(n.param)}. Using "field": ${De(r)}.`}const nme="Axes cannot be shared in concatenated or repeated views yet (https://github.com/vega/vega-lite/issues/2415).";function rme(e){return`Unrecognized parse "${e}".`}function h6(e,t,n){return`An ancestor parsed field "${e}" as ${n} but a child wants to parse the field as ${t}.`}const ime="Attempt to add the same child twice.";function sme(e){return`Ignoring an invalid transform: ${ln(e)}.`}const ome='If "from.fields" is not specified, "as" has to be a string that specifies the key to be used for the data from the secondary source.';function p6(e){return`Config.customFormatTypes is not true, thus custom format type and format for channel ${e} are dropped.`}function ame(e){const{parentProjection:t,projection:n}=e;return`Layer's shared projection ${ln(t)} is overridden by a child projection ${ln(n)}.`}const lme="Arc marks uses theta channel rather than angle, replacing angle with theta.";function ume(e){return`${e}Offset dropped because ${e} is continuous`}function cme(e,t,n){return`Channel ${e} is a ${t}. Converted to {value: ${ln(n)}}.`}function yz(e){return`Invalid field type "${e}".`}function fme(e,t){return`Invalid field type "${e}" for aggregate: "${t}", using "quantitative" instead.`}function dme(e){return`Invalid aggregation operator "${e}".`}function bz(e,t){const{fill:n,stroke:r}=t;return`Dropping color ${e} as the plot also has ${n&&r?"fill and stroke":n?"fill":"stroke"}.`}function hme(e){return`Position range does not support relative band size for ${e}.`}function iA(e,t){return`Dropping ${ln(e)} from channel "${t}" since it does not contain any data field, datum, value, or signal.`}const pme="Line marks cannot encode size with a non-groupby field. You may want to use trail marks instead.";function Zb(e,t,n){return`${e} dropped as it is incompatible with "${t}".`}function gme(e){return`${e}-encoding is dropped as ${e} is not a valid encoding channel.`}function mme(e){return`${e} encoding should be discrete (ordinal / nominal / binned).`}function vme(e){return`${e} encoding should be discrete (ordinal / nominal / binned) or use a discretizing scale (e.g. threshold).`}function yme(e){return`Facet encoding dropped as ${e.join(" and ")} ${e.length>1?"are":"is"} also specified.`}function c_(e,t){return`Using discrete channel "${e}" to encode "${t}" field can be misleading as it does not encode ${t==="ordinal"?"order":"magnitude"}.`}function bme(e){return`The ${e} for range marks cannot be an expression`}function xme(e,t){return`Line mark is for continuous lines and thus cannot be used with ${e&&t?"x2 and y2":e?"x2":"y2"}. We will use the rule mark (line segments) instead.`}function _me(e,t){return`Specified orient "${e}" overridden with "${t}".`}function wme(e){return`Cannot use the scale property "${e}" with non-color channel.`}function Eme(e){return`Cannot use the relative band size with ${e} scale.`}function Ame(e){return`Using unaggregated domain with raw field has no effect (${ln(e)}).`}function kme(e){return`Unaggregated domain not applicable for "${e}" since it produces values outside the origin domain of the source data.`}function Sme(e){return`Unaggregated domain is currently unsupported for log scale (${ln(e)}).`}function Cme(e){return`Cannot apply size to non-oriented mark "${e}".`}function $me(e,t,n){return`Channel "${e}" does not work with "${t}" scale. We are using "${n}" scale instead.`}function Fme(e,t){return`FieldDef does not work with "${e}" scale. We are using "${t}" scale instead.`}function xz(e,t,n){return`${n}-scale's "${t}" is dropped as it does not work with ${e} scale.`}function _z(e){return`The step for "${e}" is dropped because the ${e==="width"?"x":"y"} is continuous.`}function Dme(e,t,n,r){return`Conflicting ${t.toString()} property "${e.toString()}" (${ln(n)} and ${ln(r)}). Using ${ln(n)}.`}function Mme(e,t,n,r){return`Conflicting ${t.toString()} property "${e.toString()}" (${ln(n)} and ${ln(r)}). Using the union of the two domains.`}function Tme(e){return`Setting the scale to be independent for "${e}" means we also have to set the guide (axis or legend) to be independent.`}function Rme(e){return`Dropping sort property ${ln(e)} as unioned domains only support boolean or op "count", "min", and "max".`}const g6="Domains that should be unioned has conflicting sort properties. Sort will be set to true.",Nme="Detected faceted independent scales that union domain of multiple fields from different data sources. We will use the first field. The result view size may be incorrect.",Ome="Detected faceted independent scales that union domain of the same fields from different source. We will assume that this is the same field from a different fork of the same data source. However, if this is not the case, the result view size may be incorrect.",Lme="Detected faceted independent scales that union domain of multiple fields from the same data source. We will use the first field. The result view size may be incorrect.";function Ime(e){return`Cannot stack "${e}" if there is already "${e}2".`}function Pme(e){return`Stack is applied to a non-linear scale (${e}).`}function Bme(e){return`Stacking is applied even though the aggregate function is non-summative ("${e}").`}function ry(e,t){return`Invalid ${e}: ${ln(t)}.`}function zme(e){return`Dropping day from datetime ${ln(e)} as day cannot be combined with other units.`}function jme(e,t){return`${t?"extent ":""}${t&&e?"and ":""}${e?"center ":""}${t&&e?"are ":"is "}not needed when data are aggregated.`}function Ume(e,t,n){return`${e} is not usually used with ${t} for ${n}.`}function qme(e,t){return`Continuous axis should not have customized aggregation function ${e}; ${t} already agregates the axis.`}function m6(e){return`1D error band does not support ${e}.`}function wz(e){return`Channel ${e} is required for "binned" bin.`}function Wme(e){return`Channel ${e} should not be used with "binned" bin.`}function Hme(e){return`Domain for ${e} is required for threshold scale.`}const Ez=dk(fk);let ef=Ez;function Gme(e){return ef=e,ef}function Yme(){return ef=Ez,ef}function y$(...e){ef.error(...e)}function Ce(...e){ef.warn(...e)}function Vme(...e){ef.debug(...e)}function Af(e){if(e&&Pe(e)){for(const t of x$)if(Se(e,t))return!0}return!1}const Az=["january","february","march","april","may","june","july","august","september","october","november","december"],Xme=Az.map(e=>e.substr(0,3)),kz=["sunday","monday","tuesday","wednesday","thursday","friday","saturday"],Kme=kz.map(e=>e.substr(0,3));function Zme(e){if(Ub(e)&&(e=+e),Gt(e))return e>4&&Ce(ry("quarter",e)),e-1;throw new Error(ry("quarter",e))}function Jme(e){if(Ub(e)&&(e=+e),Gt(e))return e-1;{const t=e.toLowerCase(),n=Az.indexOf(t);if(n!==-1)return n;const r=t.substr(0,3),i=Xme.indexOf(r);if(i!==-1)return i;throw new Error(ry("month",e))}}function Qme(e){if(Ub(e)&&(e=+e),Gt(e))return e%7;{const t=e.toLowerCase(),n=kz.indexOf(t);if(n!==-1)return n;const r=t.substr(0,3),i=Kme.indexOf(r);if(i!==-1)return i;throw new Error(ry("day",e))}}function b$(e,t){const n=[];if(t&&e.day!==void 0&&Ae(e).length>1&&(Ce(zme(e)),e=gt(e),delete e.day),e.year!==void 0?n.push(e.year):n.push(2012),e.month!==void 0){const r=t?Jme(e.month):e.month;n.push(r)}else if(e.quarter!==void 0){const r=t?Zme(e.quarter):e.quarter;n.push(Gt(r)?r*3:`${r}*3`)}else n.push(0);if(e.date!==void 0)n.push(e.date);else if(e.day!==void 0){const r=t?Qme(e.day):e.day;n.push(Gt(r)?r+1:`${r}+1`)}else n.push(1);for(const r of["hours","minutes","seconds","milliseconds"]){const i=e[r];n.push(typeof i>"u"?0:i)}return n}function tf(e){const n=b$(e,!0).join(", ");return e.utc?`utc(${n})`:`datetime(${n})`}function e1e(e){const n=b$(e,!1).join(", ");return e.utc?`utc(${n})`:`datetime(${n})`}function t1e(e){const t=b$(e,!0);return e.utc?+new Date(Date.UTC(...t)):+new Date(...t)}const Sz={year:1,quarter:1,month:1,week:1,day:1,dayofyear:1,date:1,hours:1,minutes:1,seconds:1,milliseconds:1},x$=Ae(Sz);function n1e(e){return We(Sz,e)}function kf(e){return Pe(e)?e.binned:Cz(e)}function Cz(e){return e&&e.startsWith("binned")}function _$(e){return e.startsWith("utc")}function r1e(e){return e.substring(3)}const i1e={"year-month":"%b %Y ","year-month-date":"%b %d, %Y "};function Jb(e){return x$.filter(t=>Fz(e,t))}function $z(e){const t=Jb(e);return t[t.length-1]}function Fz(e,t){const n=e.indexOf(t);return!(n<0||n>0&&t==="seconds"&&e.charAt(n-1)==="i"||e.length>n+3&&t==="day"&&e.charAt(n+3)==="o"||n>0&&t==="year"&&e.charAt(n-1)==="f")}function s1e(e,t,{end:n}={end:!1}){const r=s$(t),i=_$(e)?"utc":"";function s(l){return l==="quarter"?`(${i}quarter(${r})-1)`:`${i}${l}(${r})`}let o;const a={};for(const l of x$)Fz(e,l)&&(a[l]=s(l),o=l);return n&&(a[o]+="+1"),e1e(a)}function Dz(e){if(!e)return;const t=Jb(e);return`timeUnitSpecifier(${ln(t)}, ${ln(i1e)})`}function o1e(e,t,n){if(!e)return;const r=Dz(e);return`${n||_$(e)?"utc":"time"}Format(${t}, ${r})`}function dr(e){if(!e)return;let t;return ze(e)?Cz(e)?t={unit:e.substring(6),binned:!0}:t={unit:e}:Pe(e)&&(t={...e,...e.unit?{unit:e.unit}:{}}),_$(t.unit)&&(t.utc=!0,t.unit=r1e(t.unit)),t}function a1e(e){const{utc:t,...n}=dr(e);return n.unit?(t?"utc":"")+Ae(n).map(r=>_n(`${r==="unit"?"":`_${r}_`}${n[r]}`)).join(""):(t?"utc":"")+"timeunit"+Ae(n).map(r=>_n(`_${r}_${n[r]}`)).join("")}function Mz(e,t=n=>n){const n=dr(e),r=$z(n.unit);if(r&&r!=="day"){const i={year:2001,month:1,date:1,hours:0,minutes:0,seconds:0,milliseconds:0},{step:s,part:o}=Tz(r,n.step),a={...i,[o]:+i[o]+s};return`${t(tf(a))} - ${t(tf(i))}`}}const l1e={year:1,month:1,date:1,hours:1,minutes:1,seconds:1,milliseconds:1};function u1e(e){return We(l1e,e)}function Tz(e,t=1){if(u1e(e))return{part:e,step:t};switch(e){case"day":case"dayofyear":return{part:"date",step:t};case"quarter":return{part:"month",step:t*3};case"week":return{part:"date",step:t*7}}}function c1e(e){return Se(e,"param")}function w$(e){return!!(e!=null&&e.field)&&e.equal!==void 0}function E$(e){return!!(e!=null&&e.field)&&e.lt!==void 0}function A$(e){return!!(e!=null&&e.field)&&e.lte!==void 0}function k$(e){return!!(e!=null&&e.field)&&e.gt!==void 0}function S$(e){return!!(e!=null&&e.field)&&e.gte!==void 0}function C$(e){if(e!=null&&e.field){if(fe(e.range)&&e.range.length===2)return!0;if(tt(e.range))return!0}return!1}function $$(e){return!!(e!=null&&e.field)&&(fe(e.oneOf)||fe(e.in))}function f1e(e){return!!(e!=null&&e.field)&&e.valid!==void 0}function Rz(e){return $$(e)||w$(e)||C$(e)||E$(e)||k$(e)||A$(e)||S$(e)}function Io(e,t){return l2(e,{timeUnit:t,wrapTime:!0})}function d1e(e,t){return e.map(n=>Io(n,t))}function Nz(e,t=!0){const{field:n}=e,r=dr(e.timeUnit),{unit:i,binned:s}=r||{},o=Ne(e,{expr:"datum"}),a=i?`time(${s?o:s1e(i,n)})`:o;if(w$(e))return`${a}===${Io(e.equal,i)}`;if(E$(e)){const l=e.lt;return`${a}<${Io(l,i)}`}else if(k$(e)){const l=e.gt;return`${a}>${Io(l,i)}`}else if(A$(e)){const l=e.lte;return`${a}<=${Io(l,i)}`}else if(S$(e)){const l=e.gte;return`${a}>=${Io(l,i)}`}else{if($$(e))return`indexof([${d1e(e.oneOf,i).join(",")}], ${a}) !== -1`;if(f1e(e))return Qb(a,e.valid);if(C$(e)){const{range:l}=Ar(e),u=tt(l)?{signal:`${l.signal}[0]`}:l[0],c=tt(l)?{signal:`${l.signal}[1]`}:l[1];if(u!==null&&c!==null&&t)return"inrange("+a+", ["+Io(u,i)+", "+Io(c,i)+"])";const f=[];return u!==null&&f.push(`${a} >= ${Io(u,i)}`),c!==null&&f.push(`${a} <= ${Io(c,i)}`),f.length>0?f.join(" && "):"true"}}throw new Error(`Invalid field predicate: ${ln(e)}`)}function Qb(e,t=!0){return t?`isValid(${e}) && isFinite(+${e})`:`!isValid(${e}) || !isFinite(+${e})`}function h1e(e){return Rz(e)&&e.timeUnit?{...e,timeUnit:dr(e.timeUnit)}:e}const B0={quantitative:"quantitative",ordinal:"ordinal",temporal:"temporal",nominal:"nominal",geojson:"geojson"};function p1e(e){return e==="quantitative"||e==="temporal"}function Oz(e){return e==="ordinal"||e==="nominal"}const nf=B0.quantitative,F$=B0.ordinal,eh=B0.temporal,D$=B0.nominal,Nh=B0.geojson;function g1e(e){if(e)switch(e=e.toLowerCase(),e){case"q":case nf:return"quantitative";case"t":case eh:return"temporal";case"o":case F$:return"ordinal";case"n":case D$:return"nominal";case Nh:return"geojson"}}const kr={LINEAR:"linear",LOG:"log",POW:"pow",SQRT:"sqrt",TIME:"time",UTC:"utc",POINT:"point",BAND:"band"},sA={linear:"numeric",log:"numeric",pow:"numeric",sqrt:"numeric",symlog:"numeric",identity:"numeric",sequential:"numeric",time:"time",utc:"time",ordinal:"ordinal","bin-ordinal":"bin-ordinal",point:"ordinal-position",band:"ordinal-position",quantile:"discretizing",quantize:"discretizing",threshold:"discretizing"};function m1e(e,t){const n=sA[e],r=sA[t];return n===r||n==="ordinal-position"&&r==="time"||r==="ordinal-position"&&n==="time"}const v1e={linear:0,log:1,pow:1,sqrt:1,symlog:1,identity:1,sequential:1,time:0,utc:0,point:10,band:11,ordinal:0,"bin-ordinal":0,quantile:0,quantize:0,threshold:0};function v6(e){return v1e[e]}const Lz=new Set(["linear","log","pow","sqrt","symlog"]),Iz=new Set([...Lz,"time","utc"]);function Pz(e){return Lz.has(e)}const Bz=new Set(["quantile","quantize","threshold"]),y1e=new Set([...Iz,...Bz,"sequential","identity"]),b1e=new Set(["ordinal","bin-ordinal","point","band"]);function pr(e){return b1e.has(e)}function bo(e){return y1e.has(e)}function Qo(e){return Iz.has(e)}function th(e){return Bz.has(e)}const x1e={pointPadding:.5,barBandPaddingInner:.1,rectBandPaddingInner:0,tickBandPaddingInner:.25,bandWithNestedOffsetPaddingInner:.2,bandWithNestedOffsetPaddingOuter:.2,minBandSize:2,minFontSize:8,maxFontSize:40,minOpacity:.3,maxOpacity:.8,minSize:4,minStrokeWidth:1,maxStrokeWidth:4,quantileCount:4,quantizeCount:4,zero:!0,framesPerSecond:2,animationDuration:5};function _1e(e){return!ze(e)&&Se(e,"name")}function zz(e){return Se(e,"param")}function w1e(e){return Se(e,"unionWith")}function E1e(e){return Pe(e)&&"field"in e}const A1e={type:1,domain:1,domainMax:1,domainMin:1,domainMid:1,domainRaw:1,align:1,range:1,rangeMax:1,rangeMin:1,scheme:1,bins:1,reverse:1,round:1,clamp:1,nice:1,base:1,exponent:1,constant:1,interpolate:1,zero:1,padding:1,paddingInner:1,paddingOuter:1},{type:oFe,domain:aFe,range:lFe,rangeMax:uFe,rangeMin:cFe,scheme:fFe,...k1e}=A1e,S1e=Ae(k1e);function oA(e,t){switch(t){case"type":case"domain":case"reverse":case"range":return!0;case"scheme":case"interpolate":return!["point","band","identity"].includes(e);case"bins":return!["point","band","identity","ordinal"].includes(e);case"round":return Qo(e)||e==="band"||e==="point";case"padding":case"rangeMin":case"rangeMax":return Qo(e)||["point","band"].includes(e);case"paddingOuter":case"align":return["point","band"].includes(e);case"paddingInner":return e==="band";case"domainMax":case"domainMid":case"domainMin":case"domainRaw":case"clamp":return Qo(e);case"nice":return Qo(e)||e==="quantize"||e==="threshold";case"exponent":return e==="pow";case"base":return e==="log";case"constant":return e==="symlog";case"zero":return bo(e)&&!Tt(["log","time","utc","threshold","quantile"],e)}}function jz(e,t){switch(t){case"interpolate":case"scheme":case"domainMid":return fd(e)?void 0:wme(t);case"align":case"type":case"bins":case"domain":case"domainMax":case"domainMin":case"domainRaw":case"range":case"base":case"exponent":case"constant":case"nice":case"padding":case"paddingInner":case"paddingOuter":case"rangeMax":case"rangeMin":case"reverse":case"round":case"clamp":case"zero":return}}function C1e(e,t){return Tt([F$,D$],t)?e===void 0||pr(e):t===eh?Tt([kr.TIME,kr.UTC,void 0],e):t===nf?Pz(e)||th(e)||e===void 0:!0}function $1e(e,t,n=!1){if(!$a(e))return!1;switch(e){case wn:case mr:case Du:case Rh:case qs:case Co:return Qo(t)||t==="band"?!0:t==="point"?!n:!1;case Mu:return Tt(["linear","band"],t);case bl:case Nu:case xl:case Tu:case Ru:case xf:return Qo(t)||th(t)||Tt(["band","point","ordinal"],t);case qi:case ka:case Sa:return t!=="band";case Ou:case Wi:return t==="ordinal"||th(t)}}function F1e(e){return Pe(e)&&"value"in e}const Ei={arc:"arc",area:"area",bar:"bar",image:"image",line:"line",point:"point",rect:"rect",rule:"rule",text:"text",tick:"tick",trail:"trail",circle:"circle",square:"square",geoshape:"geoshape"},Uz=Ei.arc,e2=Ei.area,t2=Ei.bar,D1e=Ei.image,n2=Ei.line,r2=Ei.point,M1e=Ei.rect,iy=Ei.rule,qz=Ei.text,M$=Ei.tick,T1e=Ei.trail,T$=Ei.circle,R$=Ei.square,Wz=Ei.geoshape;function Iu(e){return["line","area","trail"].includes(e)}function Lg(e){return["rect","bar","image","arc","tick"].includes(e)}const R1e=new Set(Ae(Ei));function pa(e){return Se(e,"type")}const N1e=["stroke","strokeWidth","strokeDash","strokeDashOffset","strokeOpacity","strokeJoin","strokeMiterLimit"],O1e=["fill","fillOpacity"],L1e=[...N1e,...O1e],I1e={color:1,filled:1,invalid:1,order:1,radius2:1,theta2:1,timeUnitBandSize:1,timeUnitBandPosition:1},y6=Ae(I1e),f_=["binSpacing","continuousBandSize","discreteBandSize","minBandSize"],P1e={area:["line","point"],bar:f_,rect:f_,line:["point"],tick:["bandSize","thickness",...f_]},B1e={color:"#4c78a8",invalid:"break-paths-show-path-domains",timeUnitBandSize:1},z1e={mark:1,arc:1,area:1,bar:1,circle:1,image:1,line:1,point:1,rect:1,rule:1,square:1,text:1,tick:1,trail:1,geoshape:1},Hz=Ae(z1e);function rf(e){return Se(e,"band")}const j1e={horizontal:["cornerRadiusTopRight","cornerRadiusBottomRight"],vertical:["cornerRadiusTopLeft","cornerRadiusTopRight"]},U1e=5,N$={binSpacing:0,continuousBandSize:U1e,minBandSize:.25,timeUnitBandPosition:.5},q1e={...N$,binSpacing:1},W1e={...N$,thickness:1};function H1e(e){return pa(e)?e.type:e}function Gz(e,{isPath:t}){return e===void 0||e==="break-paths-show-path-domains"?t?"break-paths-show-domains":"filter":e===null?"show":e}function O$({markDef:e,config:t,scaleChannel:n,scaleType:r,isCountAggregate:i}){var a,l;if(!r||!bo(r)||i)return"always-valid";const s=Gz(on("invalid",e,t),{isPath:Iu(e.type)});return((l=(a=t.scale)==null?void 0:a.invalid)==null?void 0:l[n])!==void 0?"show":s}function G1e(e){return e==="break-paths-filter-domains"||e==="break-paths-show-domains"}function Yz({scaleName:e,scale:t,mode:n}){const r=`domain('${e}')`;if(!t||!e)return;const i=`${r}[0]`,s=`peek(${r})`,o=t.domainHasZero();return o==="definitely"?{scale:e,value:0}:o==="maybe"?{signal:`scale('${e}', inrange(0, ${r}) ? 0 : ${n==="zeroOrMin"?i:s})`}:{signal:`scale('${e}', ${n==="zeroOrMin"?i:s})`}}function Vz({scaleChannel:e,channelDef:t,scale:n,scaleName:r,markDef:i,config:s}){var c;const o=n==null?void 0:n.get("type"),a=_o(t),l=Xb(a==null?void 0:a.aggregate),u=O$({scaleChannel:e,markDef:i,config:s,scaleType:o,isCountAggregate:l});if(a&&u==="show"){const f=((c=s.scale.invalid)==null?void 0:c[e])??"zero-or-min";return{test:Qb(Ne(a,{expr:"datum"}),!1),...Y1e(f,n,r)}}}function Y1e(e,t,n){if(F1e(e)){const{value:r}=e;return tt(r)?{signal:r.signal}:{value:r}}return Yz({scale:t,scaleName:n,mode:"zeroOrMin"})}function L$(e){const{channel:t,channelDef:n,markDef:r,scale:i,scaleName:s,config:o}=e,a=_f(t),l=I$(e),u=Vz({scaleChannel:a,channelDef:n,scale:i,scaleName:s,markDef:r,config:o});return u!==void 0?[u,l]:l}function V1e(e){const{datum:t}=e;return Af(t)?tf(t):`${ln(t)}`}function Cc(e,t,n,r){const i={};if(t&&(i.scale=t),Fa(e)){const{datum:s}=e;Af(s)?i.signal=tf(s):tt(s)?i.signal=s.signal:P0(s)?i.signal=s.expr:i.value=s}else i.field=Ne(e,n);if(r){const{offset:s,band:o}=r;s&&(i.offset=s),o&&(i.band=o)}return i}function sy({scaleName:e,fieldOrDatumDef:t,fieldOrDatumDef2:n,offset:r,startSuffix:i,endSuffix:s="end",bandPosition:o=.5}){const a=!tt(o)&&0{switch(t.fieldTitle){case"plain":return e.field;case"functional":return uve(e);default:return lve(e,t)}};let aj=oj;function lj(e){aj=e}function cve(){lj(oj)}function dd(e,t,{allowDisabling:n,includeDefault:r=!0}){var a;const i=(a=j$(e))==null?void 0:a.title;if(!$e(e))return i??e.title;const s=e,o=r?U$(s,t):void 0;return n?jn(i,s.title,o):i??s.title??o}function j$(e){if(rh(e)&&e.axis)return e.axis;if(ij(e)&&e.legend)return e.legend;if(B$(e)&&e.header)return e.header}function U$(e,t){return aj(e,t)}function ly(e){if(sj(e)){const{format:t,formatType:n}=e;return{format:t,formatType:n}}else{const t=j$(e)??{},{format:n,formatType:r}=t;return{format:n,formatType:r}}}function fve(e,t){var s;switch(t){case"latitude":case"longitude":return"quantitative";case"row":case"column":case"facet":case"shape":case"strokeDash":return"nominal";case"order":return"ordinal"}if(z$(e)&&fe(e.sort))return"ordinal";const{aggregate:n,bin:r,timeUnit:i}=e;if(i)return"temporal";if(r||n&&!Lu(n)&&!dl(n))return"quantitative";if(Sf(e)&&((s=e.scale)!=null&&s.type))switch(sA[e.scale.type]){case"numeric":case"discretizing":return"quantitative";case"time":return"temporal"}return"nominal"}function _o(e){if($e(e))return e;if(o2(e))return e.condition}function Jn(e){if(vt(e))return e;if(q0(e))return e.condition}function uj(e,t,n,r={}){if(ze(e)||Gt(e)||wu(e)){const i=ze(e)?"string":Gt(e)?"number":"boolean";return Ce(cme(t,i,e)),{value:e}}return vt(e)?uy(e,t,n,r):q0(e)?{...e,condition:uy(e.condition,t,n,r)}:e}function uy(e,t,n,r){if(sj(e)){const{format:i,formatType:s,...o}=e;if(sf(s)&&!n.customFormatTypes)return Ce(p6(t)),uy(o,t,n,r)}else{const i=rh(e)?"axis":ij(e)?"legend":B$(e)?"header":null;if(i&&e[i]){const{format:s,formatType:o,...a}=e[i];if(sf(o)&&!n.customFormatTypes)return Ce(p6(t)),uy({...e,[i]:a},t,n,r)}}return $e(e)?q$(e,t,r):dve(e)}function dve(e){let t=e.type;if(t)return e;const{datum:n}=e;return t=Gt(n)?"quantitative":ze(n)?"nominal":Af(n)?"temporal":void 0,{...e,type:t}}function q$(e,t,{compositeMark:n=!1}={}){const{aggregate:r,timeUnit:i,bin:s,field:o}=e,a={...e};if(!n&&r&&!p$(r)&&!Lu(r)&&!dl(r)&&(Ce(dme(r)),delete a.aggregate),i&&(a.timeUnit=dr(i)),o&&(a.field=`${o}`),dn(s)&&(a.bin=a2(s,t)),wr(s)&&!Un(t)&&Ce(Wme(t)),xi(a)){const{type:l}=a,u=g1e(l);l!==u&&(a.type=u),l!=="quantitative"&&Xb(r)&&(Ce(fme(l,r)),a.type="quantitative")}else if(!nz(t)){const l=fve(a,t);a.type=l}if(xi(a)){const{compatible:l,warning:u}=hve(a,t)||{};l===!1&&Ce(u)}if(z$(a)&&ze(a.sort)){const{sort:l}=a;if(x6(l))return{...a,sort:{encoding:l}};const u=l.substring(1);if(l.charAt(0)==="-"&&x6(u))return{...a,sort:{encoding:u,order:"descending"}}}if(B$(a)){const{header:l}=a;if(l){const{orient:u,...c}=l;if(u)return{...a,header:{...c,labelOrient:l.labelOrient||u,titleOrient:l.titleOrient||u}}}}return a}function a2(e,t){return wu(e)?{maxbins:s6(t)}:e==="binned"?{binned:!0}:!e.maxbins&&!e.step?{...e,maxbins:s6(t)}:e}const jf={compatible:!0};function hve(e,t){const n=e.type;if(n==="geojson"&&t!=="shape")return{compatible:!1,warning:`Channel ${t} should not be used with a geojson data.`};switch(t){case nl:case rl:case qb:return ay(e)?jf:{compatible:!1,warning:mme(t)};case wn:case mr:case Du:case Rh:case qi:case ka:case Sa:case O0:case L0:case Wb:case Qc:case Hb:case Gb:case xf:case qs:case Co:case Yb:return jf;case Fo:case zs:case $o:case Do:return n!==nf?{compatible:!1,warning:`Channel ${t} should be used with a quantitative field only, not ${e.type} field.`}:jf;case xl:case Tu:case Ru:case Nu:case bl:case yl:case vl:case So:case Aa:case Mu:return n==="nominal"&&!e.sort?{compatible:!1,warning:`Channel ${t} should not be used with an unsorted discrete field.`}:jf;case Wi:case Ou:return!ay(e)&&!ove(e)?{compatible:!1,warning:vme(t)}:jf;case Qd:return e.type==="nominal"&&!("sort"in e)?{compatible:!1,warning:"Channel order is inappropriate for nominal field, which has no inherent order."}:jf}}function ih(e){const{formatType:t}=ly(e);return t==="time"||!t&&pve(e)}function pve(e){return e&&(e.type==="temporal"||$e(e)&&!!e.timeUnit)}function l2(e,{timeUnit:t,type:n,wrapTime:r,undefinedIfExprNotRequired:i}){var l;const s=t&&((l=dr(t))==null?void 0:l.unit);let o=s||n==="temporal",a;return P0(e)?a=e.expr:tt(e)?a=e.signal:Af(e)?(o=!0,a=tf(e)):(ze(e)||Gt(e))&&o&&(a=`datetime(${ln(e)})`,n1e(s)&&(Gt(e)&&e<1e4||ze(e)&&isNaN(Date.parse(e)))&&(a=tf({[s]:e}))),a?r&&o?`time(${a})`:a:i?void 0:ln(e)}function cj(e,t){const{type:n}=e;return t.map(r=>{const i=$e(e)&&!kf(e.timeUnit)?e.timeUnit:void 0,s=l2(r,{timeUnit:i,type:n,undefinedIfExprNotRequired:!0});return s!==void 0?{signal:s}:r})}function W0(e,t){return dn(e.bin)?$a(t)&&["ordinal","nominal"].includes(e.type):(console.warn("Only call this method for binned field defs."),!1)}const E6={labelAlign:{part:"labels",vgProp:"align"},labelBaseline:{part:"labels",vgProp:"baseline"},labelColor:{part:"labels",vgProp:"fill"},labelFont:{part:"labels",vgProp:"font"},labelFontSize:{part:"labels",vgProp:"fontSize"},labelFontStyle:{part:"labels",vgProp:"fontStyle"},labelFontWeight:{part:"labels",vgProp:"fontWeight"},labelOpacity:{part:"labels",vgProp:"opacity"},labelOffset:null,labelPadding:null,gridColor:{part:"grid",vgProp:"stroke"},gridDash:{part:"grid",vgProp:"strokeDash"},gridDashOffset:{part:"grid",vgProp:"strokeDashOffset"},gridOpacity:{part:"grid",vgProp:"opacity"},gridWidth:{part:"grid",vgProp:"strokeWidth"},tickColor:{part:"ticks",vgProp:"stroke"},tickDash:{part:"ticks",vgProp:"strokeDash"},tickDashOffset:{part:"ticks",vgProp:"strokeDashOffset"},tickOpacity:{part:"ticks",vgProp:"opacity"},tickSize:null,tickWidth:{part:"ticks",vgProp:"strokeWidth"}};function H0(e){return e==null?void 0:e.condition}const fj=["domain","grid","labels","ticks","title"],gve={grid:"grid",gridCap:"grid",gridColor:"grid",gridDash:"grid",gridDashOffset:"grid",gridOpacity:"grid",gridScale:"grid",gridWidth:"grid",orient:"main",bandPosition:"both",aria:"main",description:"main",domain:"main",domainCap:"main",domainColor:"main",domainDash:"main",domainDashOffset:"main",domainOpacity:"main",domainWidth:"main",format:"main",formatType:"main",labelAlign:"main",labelAngle:"main",labelBaseline:"main",labelBound:"main",labelColor:"main",labelFlush:"main",labelFlushOffset:"main",labelFont:"main",labelFontSize:"main",labelFontStyle:"main",labelFontWeight:"main",labelLimit:"main",labelLineHeight:"main",labelOffset:"main",labelOpacity:"main",labelOverlap:"main",labelPadding:"main",labels:"main",labelSeparation:"main",maxExtent:"main",minExtent:"main",offset:"both",position:"main",tickCap:"main",tickColor:"main",tickDash:"main",tickDashOffset:"main",tickMinStep:"both",tickOffset:"both",tickOpacity:"main",tickRound:"both",ticks:"main",tickSize:"main",tickWidth:"both",title:"main",titleAlign:"main",titleAnchor:"main",titleAngle:"main",titleBaseline:"main",titleColor:"main",titleFont:"main",titleFontSize:"main",titleFontStyle:"main",titleFontWeight:"main",titleLimit:"main",titleLineHeight:"main",titleOpacity:"main",titlePadding:"main",titleX:"main",titleY:"main",encode:"both",scale:"both",tickBand:"both",tickCount:"both",tickExtra:"both",translate:"both",values:"both",zindex:"both"},dj={orient:1,aria:1,bandPosition:1,description:1,domain:1,domainCap:1,domainColor:1,domainDash:1,domainDashOffset:1,domainOpacity:1,domainWidth:1,format:1,formatType:1,grid:1,gridCap:1,gridColor:1,gridDash:1,gridDashOffset:1,gridOpacity:1,gridWidth:1,labelAlign:1,labelAngle:1,labelBaseline:1,labelBound:1,labelColor:1,labelFlush:1,labelFlushOffset:1,labelFont:1,labelFontSize:1,labelFontStyle:1,labelFontWeight:1,labelLimit:1,labelLineHeight:1,labelOffset:1,labelOpacity:1,labelOverlap:1,labelPadding:1,labels:1,labelSeparation:1,maxExtent:1,minExtent:1,offset:1,position:1,tickBand:1,tickCap:1,tickColor:1,tickCount:1,tickDash:1,tickDashOffset:1,tickExtra:1,tickMinStep:1,tickOffset:1,tickOpacity:1,tickRound:1,ticks:1,tickSize:1,tickWidth:1,title:1,titleAlign:1,titleAnchor:1,titleAngle:1,titleBaseline:1,titleColor:1,titleFont:1,titleFontSize:1,titleFontStyle:1,titleFontWeight:1,titleLimit:1,titleLineHeight:1,titleOpacity:1,titlePadding:1,titleX:1,titleY:1,translate:1,values:1,zindex:1},mve={...dj,style:1,labelExpr:1,encoding:1};function A6(e){return We(mve,e)}const vve={axis:1,axisBand:1,axisBottom:1,axisDiscrete:1,axisLeft:1,axisPoint:1,axisQuantitative:1,axisRight:1,axisTemporal:1,axisTop:1,axisX:1,axisXBand:1,axisXDiscrete:1,axisXPoint:1,axisXQuantitative:1,axisXTemporal:1,axisY:1,axisYBand:1,axisYDiscrete:1,axisYPoint:1,axisYQuantitative:1,axisYTemporal:1},hj=Ae(vve);function wl(e){return Se(e,"mark")}class u2{constructor(t,n){this.name=t,this.run=n}hasMatchingType(t){return wl(t)?H1e(t.mark)===this.name:!1}}function $c(e,t){const n=e&&e[t];return n?fe(n)?Zd(n,r=>!!r.field):$e(n)||o2(n):!1}function pj(e,t){const n=e&&e[t];return n?fe(n)?Zd(n,r=>!!r.field):$e(n)||Fa(n)||q0(n):!1}function gj(e,t){if(Un(t)){const n=e[t];if(($e(n)||Fa(n))&&(Oz(n.type)||$e(n)&&n.timeUnit)){const r=u$(t);return pj(e,r)}}return!1}function mj(e){return Zd(d0e,t=>{if($c(e,t)){const n=e[t];if(fe(n))return Zd(n,r=>!!r.aggregate);{const r=_o(n);return r&&!!r.aggregate}}return!1})}function vj(e,t){const n=[],r=[],i=[],s=[],o={};return W$(e,(a,l)=>{if($e(a)){const{field:u,aggregate:c,bin:f,timeUnit:d,...h}=a;if(c||d||f){const p=j$(a),g=p==null?void 0:p.title;let m=Ne(a,{forAs:!0});const v={...g?[]:{title:dd(a,t,{allowDisabling:!0})},...h,field:m};if(c){let b;if(Lu(c)?(b="argmax",m=Ne({op:"argmax",field:c.argmax},{forAs:!0}),v.field=`${m}.${u}`):dl(c)?(b="argmin",m=Ne({op:"argmin",field:c.argmin},{forAs:!0}),v.field=`${m}.${u}`):c!=="boxplot"&&c!=="errorbar"&&c!=="errorband"&&(b=c),b){const x={op:b,as:m};u&&(x.field=u),s.push(x)}}else if(n.push(m),xi(a)&&dn(f)){if(r.push({bin:f,field:u,as:m}),n.push(Ne(a,{binSuffix:"end"})),W0(a,l)&&n.push(Ne(a,{binSuffix:"range"})),Un(l)){const b={field:`${m}_end`};o[`${l}2`]=b}v.bin="binned",nz(l)||(v.type=nf)}else if(d&&!kf(d)){i.push({timeUnit:d,field:u,as:m});const b=xi(a)&&a.type!==eh&&"time";b&&(l===O0||l===Qc?v.formatType=b:E0e(l)?v.legend={formatType:b,...v.legend}:Un(l)&&(v.axis={formatType:b,...v.axis}))}o[l]=v}else n.push(u),o[l]=e[l]}else o[l]=e[l]}),{bins:r,timeUnits:i,aggregate:s,groupby:n,encoding:o}}function yve(e,t,n){const r=k0e(t,n);if(r){if(r==="binned"){const i=e[t===So?wn:mr];return!!($e(i)&&$e(e[t])&&wr(i.bin))}}else return!1;return!0}function bve(e,t,n,r){const i={};for(const s of Ae(e))tz(s)||Ce(gme(s));for(let s of y0e){if(!e[s])continue;const o=e[s];if(I0(s)){const a=v0e(s),l=i[a];if($e(l)&&p1e(l.type)&&$e(o)&&!l.timeUnit){Ce(ume(a));continue}}if(s==="angle"&&t==="arc"&&!e.theta&&(Ce(lme),s=qs),!yve(e,s,t)){Ce(Zb(s,t));continue}if(s===bl&&t==="line"){const a=_o(e[s]);if(a!=null&&a.aggregate){Ce(pme);continue}}if(s===qi&&(n?"fill"in e:"stroke"in e)){Ce(bz("encoding",{fill:"fill"in e,stroke:"stroke"in e}));continue}if(s===L0||s===Qd&&!fe(o)&&!xo(o)||s===Qc&&fe(o)){if(o){if(s===Qd){const a=e[s];if(rj(a)){i[s]=a;continue}}i[s]=je(o).reduce((a,l)=>($e(l)?a.push(q$(l,s)):Ce(iA(l,s)),a),[])}}else{if(s===Qc&&o===null)i[s]=null;else if(!$e(o)&&!Fa(o)&&!xo(o)&&!U0(o)&&!tt(o)){Ce(iA(o,s));continue}i[s]=uj(o,s,r)}}return i}function c2(e,t){const n={};for(const r of Ae(e)){const i=uj(e[r],r,t,{compositeMark:!0});n[r]=i}return n}function xve(e){const t=[];for(const n of Ae(e))if($c(e,n)){const r=e[n],i=je(r);for(const s of i)$e(s)?t.push(s):o2(s)&&t.push(s.condition)}return t}function W$(e,t,n){if(e)for(const r of Ae(e)){const i=e[r];if(fe(i))for(const s of i)t.call(n,s,r);else t.call(n,i,r)}}function _ve(e,t,n,r){return e?Ae(e).reduce((i,s)=>{const o=e[s];return fe(o)?o.reduce((a,l)=>t.call(r,a,l,s),i):t.call(r,i,o,s)},n):n}function yj(e,t){return Ae(t).reduce((n,r)=>{switch(r){case wn:case mr:case Hb:case Yb:case Gb:case So:case Aa:case Du:case Rh:case qs:case yl:case Co:case vl:case Mu:case $o:case Fo:case Do:case zs:case O0:case Wi:case xf:case Qc:return n;case Qd:if(e==="line"||e==="trail")return n;case L0:case Wb:{const i=t[r];if(fe(i)||$e(i))for(const s of je(i))s.aggregate||n.push(Ne(s,{}));return n}case bl:if(e==="trail")return n;case qi:case ka:case Sa:case xl:case Tu:case Ru:case Ou:case Nu:{const i=_o(t[r]);return i&&!i.aggregate&&n.push(Ne(i,{})),n}}},[])}function wve(e){const{tooltip:t,...n}=e;if(!t)return{filteredEncoding:n};let r,i;if(fe(t)){for(const s of t)s.aggregate?(r||(r=[]),r.push(s)):(i||(i=[]),i.push(s));r&&(n.tooltip=r)}else t.aggregate?n.tooltip=t:i=t;return fe(i)&&i.length===1&&(i=i[0]),{customTooltipWithoutAggregatedField:i,filteredEncoding:n}}function lA(e,t,n,r=!0){if("tooltip"in n)return{tooltip:n.tooltip};const i=e.map(({fieldPrefix:o,titlePrefix:a})=>{const l=r?` of ${H$(t)}`:"";return{field:o+t.field,type:t.type,title:tt(a)?{signal:`${a}"${escape(l)}"`}:a+l}}),s=xve(n).map(ive);return{tooltip:[...i,...Jo(s,It)]}}function H$(e){const{title:t,field:n}=e;return jn(t,n)}function G$(e,t,n,r,i){const{scale:s,axis:o}=n;return({partName:a,mark:l,positionPrefix:u,endPositionPrefix:c=void 0,extraEncoding:f={}})=>{const d=H$(n);return bj(e,a,i,{mark:l,encoding:{[t]:{field:`${u}_${n.field}`,type:n.type,...d!==void 0?{title:d}:{},...s!==void 0?{scale:s}:{},...o!==void 0?{axis:o}:{}},...ze(c)?{[`${t}2`]:{field:`${c}_${n.field}`}}:{},...r,...f}})}}function bj(e,t,n,r){const{clip:i,color:s,opacity:o}=e,a=e.type;return e[t]||e[t]===void 0&&n[t]?[{...r,mark:{...n[t],...i?{clip:i}:{},...s?{color:s}:{},...o?{opacity:o}:{},...pa(r.mark)?r.mark:{type:r.mark},style:`${a}-${String(t)}`,...wu(e[t])?{}:e[t]}}]:[]}function xj(e,t,n){const{encoding:r}=e,i=t==="vertical"?"y":"x",s=r[i],o=r[`${i}2`],a=r[`${i}Error`],l=r[`${i}Error2`];return{continuousAxisChannelDef:Rm(s,n),continuousAxisChannelDef2:Rm(o,n),continuousAxisChannelDefError:Rm(a,n),continuousAxisChannelDefError2:Rm(l,n),continuousAxis:i}}function Rm(e,t){if(e!=null&&e.aggregate){const{aggregate:n,...r}=e;return n!==t&&Ce(qme(n,t)),r}else return e}function _j(e,t){const{mark:n,encoding:r}=e,{x:i,y:s}=r;if(pa(n)&&n.orient)return n.orient;if(Yl(i)){if(Yl(s)){const o=$e(i)&&i.aggregate,a=$e(s)&&s.aggregate;if(!o&&a===t)return"vertical";if(!a&&o===t)return"horizontal";if(o===t&&a===t)throw new Error("Both x and y cannot have aggregate");return ih(s)&&!ih(i)?"horizontal":"vertical"}return"horizontal"}else{if(Yl(s))return"vertical";throw new Error(`Need a valid continuous axis for ${t}s`)}}const cy="boxplot",Eve=["box","median","outliers","rule","ticks"],Ave=new u2(cy,Ej);function wj(e){return Gt(e)?"tukey":e}function Ej(e,{config:t}){e={...e,encoding:c2(e.encoding,t)};const{mark:n,encoding:r,params:i,projection:s,...o}=e,a=pa(n)?n:{type:n};i&&Ce(vz("boxplot"));const l=a.extent??t.boxplot.extent,u=on("size",a,t),c=a.invalid,f=wj(l),{bins:d,timeUnits:h,transform:p,continuousAxisChannelDef:g,continuousAxis:m,groupby:v,aggregate:b,encodingWithoutContinuousAxis:x,ticksOrient:_,boxOrient:w,customTooltipWithoutAggregatedField:A}=kve(e,l,t),E=Th(g.field),{color:k,size:S,...$}=x,M=ie=>G$(a,m,g,ie,t.boxplot),O=M($),P=M(x),T=(Pe(t.boxplot.box)?t.boxplot.box.color:t.mark.color)||"#4c78a8",F=M({...$,...S?{size:S}:{},color:{condition:{test:`${Qt(`lower_box_${g.field}`)} >= ${Qt(`upper_box_${g.field}`)}`,...k||{value:T}}}}),R=lA([{fieldPrefix:f==="min-max"?"upper_whisker_":"max_",titlePrefix:"Max"},{fieldPrefix:"upper_box_",titlePrefix:"Q3"},{fieldPrefix:"mid_box_",titlePrefix:"Median"},{fieldPrefix:"lower_box_",titlePrefix:"Q1"},{fieldPrefix:f==="min-max"?"lower_whisker_":"min_",titlePrefix:"Min"}],g,x),z={type:"tick",color:"black",opacity:1,orient:_,invalid:c,aria:!1},j=f==="min-max"?R:lA([{fieldPrefix:"upper_whisker_",titlePrefix:"Upper Whisker"},{fieldPrefix:"lower_whisker_",titlePrefix:"Lower Whisker"}],g,x),q=[...O({partName:"rule",mark:{type:"rule",invalid:c,aria:!1},positionPrefix:"lower_whisker",endPositionPrefix:"lower_box",extraEncoding:j}),...O({partName:"rule",mark:{type:"rule",invalid:c,aria:!1},positionPrefix:"upper_box",endPositionPrefix:"upper_whisker",extraEncoding:j}),...O({partName:"ticks",mark:z,positionPrefix:"lower_whisker",extraEncoding:j}),...O({partName:"ticks",mark:z,positionPrefix:"upper_whisker",extraEncoding:j})],te=[...f!=="tukey"?q:[],...P({partName:"box",mark:{type:"bar",...u?{size:u}:{},orient:w,invalid:c,ariaRoleDescription:"box"},positionPrefix:"lower_box",endPositionPrefix:"upper_box",extraEncoding:R}),...F({partName:"median",mark:{type:"tick",invalid:c,...Pe(t.boxplot.median)&&t.boxplot.median.color?{color:t.boxplot.median.color}:{},...u?{size:u}:{},orient:_,aria:!1},positionPrefix:"mid_box",extraEncoding:R})];if(f==="min-max")return{...o,transform:(o.transform??[]).concat(p),layer:te};const Y=Qt(`lower_box_${g.field}`),ee=Qt(`upper_box_${g.field}`),_e=`(${ee} - ${Y})`,Le=`${Y} - ${l} * ${_e}`,Z=`${ee} + ${l} * ${_e}`,he=Qt(g.field),He={joinaggregate:Aj(g.field),groupby:v},Ke={transform:[{filter:`(${Le} <= ${he}) && (${he} <= ${Z})`},{aggregate:[{op:"min",field:g.field,as:`lower_whisker_${E}`},{op:"max",field:g.field,as:`upper_whisker_${E}`},{op:"min",field:`lower_box_${g.field}`,as:`lower_box_${E}`},{op:"max",field:`upper_box_${g.field}`,as:`upper_box_${E}`},...b],groupby:v}],layer:q},{tooltip:de,...Re}=$,{scale:Q,axis:W}=g,L=H$(g),H=Pi(W,["title"]),ve=bj(a,"outliers",t.boxplot,{transform:[{filter:`(${he} < ${Le}) || (${he} > ${Z})`}],mark:"point",encoding:{[m]:{field:g.field,type:g.type,...L!==void 0?{title:L}:{},...Q!==void 0?{scale:Q}:{},...an(H)?{}:{axis:H}},...Re,...k?{color:k}:{},...A?{tooltip:A}:{}}})[0];let G;const B=[...d,...h,He];return ve?G={transform:B,layer:[ve,Ke]}:(G=Ke,G.transform.unshift(...B)),{...o,layer:[G,{transform:p,layer:te}]}}function Aj(e){const t=Th(e);return[{op:"q1",field:e,as:`lower_box_${t}`},{op:"q3",field:e,as:`upper_box_${t}`}]}function kve(e,t,n){const r=_j(e,cy),{continuousAxisChannelDef:i,continuousAxis:s}=xj(e,r,cy),o=i.field,a=Th(o),l=wj(t),u=[...Aj(o),{op:"median",field:o,as:`mid_box_${a}`},{op:"min",field:o,as:(l==="min-max"?"lower_whisker_":"min_")+a},{op:"max",field:o,as:(l==="min-max"?"upper_whisker_":"max_")+a}],c=l==="min-max"||l==="tukey"?[]:[{calculate:`${Qt(`upper_box_${a}`)} - ${Qt(`lower_box_${a}`)}`,as:`iqr_${a}`},{calculate:`min(${Qt(`upper_box_${a}`)} + ${Qt(`iqr_${a}`)} * ${t}, ${Qt(`max_${a}`)})`,as:`upper_whisker_${a}`},{calculate:`max(${Qt(`lower_box_${a}`)} - ${Qt(`iqr_${a}`)} * ${t}, ${Qt(`min_${a}`)})`,as:`lower_whisker_${a}`}],{[s]:f,...d}=e.encoding,{customTooltipWithoutAggregatedField:h,filteredEncoding:p}=wve(d),{bins:g,timeUnits:m,aggregate:v,groupby:b,encoding:x}=vj(p,n),_=r==="vertical"?"horizontal":"vertical",w=r,A=[...g,...m,{aggregate:[...v,...u],groupby:b},...c];return{bins:g,timeUnits:m,transform:A,groupby:b,aggregate:v,continuousAxisChannelDef:i,continuousAxis:s,encodingWithoutContinuousAxis:x,ticksOrient:_,boxOrient:w,customTooltipWithoutAggregatedField:h}}const Y$="errorbar",Sve=["ticks","rule"],Cve=new u2(Y$,kj);function kj(e,{config:t}){e={...e,encoding:c2(e.encoding,t)};const{transform:n,continuousAxisChannelDef:r,continuousAxis:i,encodingWithoutContinuousAxis:s,ticksOrient:o,markDef:a,outerSpec:l,tooltipEncoding:u}=Sj(e,Y$,t);delete s.size;const c=G$(a,i,r,s,t.errorbar),f=a.thickness,d=a.size,h={type:"tick",orient:o,aria:!1,...f!==void 0?{thickness:f}:{},...d!==void 0?{size:d}:{}},p=[...c({partName:"ticks",mark:h,positionPrefix:"lower",extraEncoding:u}),...c({partName:"ticks",mark:h,positionPrefix:"upper",extraEncoding:u}),...c({partName:"rule",mark:{type:"rule",ariaRoleDescription:"errorbar",...f!==void 0?{size:f}:{}},positionPrefix:"lower",endPositionPrefix:"upper",extraEncoding:u})];return{...l,transform:n,...p.length>1?{layer:p}:{...p[0]}}}function $ve(e,t){const{encoding:n}=e;if(Fve(n))return{orient:_j(e,t),inputType:"raw"};const r=Dve(n),i=Mve(n),s=n.x,o=n.y;if(r){if(i)throw new Error(`${t} cannot be both type aggregated-upper-lower and aggregated-error`);const a=n.x2,l=n.y2;if(vt(a)&&vt(l))throw new Error(`${t} cannot have both x2 and y2`);if(vt(a)){if(Yl(s))return{orient:"horizontal",inputType:"aggregated-upper-lower"};throw new Error(`Both x and x2 have to be quantitative in ${t}`)}else if(vt(l)){if(Yl(o))return{orient:"vertical",inputType:"aggregated-upper-lower"};throw new Error(`Both y and y2 have to be quantitative in ${t}`)}throw new Error("No ranged axis")}else{const a=n.xError,l=n.xError2,u=n.yError,c=n.yError2;if(vt(l)&&!vt(a))throw new Error(`${t} cannot have xError2 without xError`);if(vt(c)&&!vt(u))throw new Error(`${t} cannot have yError2 without yError`);if(vt(a)&&vt(u))throw new Error(`${t} cannot have both xError and yError with both are quantiative`);if(vt(a)){if(Yl(s))return{orient:"horizontal",inputType:"aggregated-error"};throw new Error("All x, xError, and xError2 (if exist) have to be quantitative")}else if(vt(u)){if(Yl(o))return{orient:"vertical",inputType:"aggregated-error"};throw new Error("All y, yError, and yError2 (if exist) have to be quantitative")}throw new Error("No ranged axis")}}function Fve(e){return(vt(e.x)||vt(e.y))&&!vt(e.x2)&&!vt(e.y2)&&!vt(e.xError)&&!vt(e.xError2)&&!vt(e.yError)&&!vt(e.yError2)}function Dve(e){return vt(e.x2)||vt(e.y2)}function Mve(e){return vt(e.xError)||vt(e.xError2)||vt(e.yError)||vt(e.yError2)}function Sj(e,t,n){const{mark:r,encoding:i,params:s,projection:o,...a}=e,l=pa(r)?r:{type:r};s&&Ce(vz(t));const{orient:u,inputType:c}=$ve(e,t),{continuousAxisChannelDef:f,continuousAxisChannelDef2:d,continuousAxisChannelDefError:h,continuousAxisChannelDefError2:p,continuousAxis:g}=xj(e,u,t),{errorBarSpecificAggregate:m,postAggregateCalculates:v,tooltipSummary:b,tooltipTitleWithFieldName:x}=Tve(l,f,d,h,p,c,t,n),{[g]:_,[g==="x"?"x2":"y2"]:w,[g==="x"?"xError":"yError"]:A,[g==="x"?"xError2":"yError2"]:E,...k}=i,{bins:S,timeUnits:$,aggregate:M,groupby:O,encoding:P}=vj(k,n),T=[...M,...m],F=c!=="raw"?[]:O,R=lA(b,f,P,x);return{transform:[...a.transform??[],...S,...$,...T.length===0?[]:[{aggregate:T,groupby:F}],...v],groupby:F,continuousAxisChannelDef:f,continuousAxis:g,encodingWithoutContinuousAxis:P,ticksOrient:u==="vertical"?"horizontal":"vertical",markDef:l,outerSpec:a,tooltipEncoding:R}}function Tve(e,t,n,r,i,s,o,a){let l=[],u=[];const c=t.field;let f,d=!1;if(s==="raw"){const h=e.center?e.center:e.extent?e.extent==="iqr"?"median":"mean":a.errorbar.center,p=e.extent?e.extent:h==="mean"?"stderr":"iqr";if(h==="median"!=(p==="iqr")&&Ce(Ume(h,p,o)),p==="stderr"||p==="stdev")l=[{op:p,field:c,as:`extent_${c}`},{op:h,field:c,as:`center_${c}`}],u=[{calculate:`${Qt(`center_${c}`)} + ${Qt(`extent_${c}`)}`,as:`upper_${c}`},{calculate:`${Qt(`center_${c}`)} - ${Qt(`extent_${c}`)}`,as:`lower_${c}`}],f=[{fieldPrefix:"center_",titlePrefix:N0(h)},{fieldPrefix:"upper_",titlePrefix:k6(h,p,"+")},{fieldPrefix:"lower_",titlePrefix:k6(h,p,"-")}],d=!0;else{let g,m,v;p==="ci"?(g="mean",m="ci0",v="ci1"):(g="median",m="q1",v="q3"),l=[{op:m,field:c,as:`lower_${c}`},{op:v,field:c,as:`upper_${c}`},{op:g,field:c,as:`center_${c}`}],f=[{fieldPrefix:"upper_",titlePrefix:dd({field:c,aggregate:v,type:"quantitative"},a,{allowDisabling:!1})},{fieldPrefix:"lower_",titlePrefix:dd({field:c,aggregate:m,type:"quantitative"},a,{allowDisabling:!1})},{fieldPrefix:"center_",titlePrefix:dd({field:c,aggregate:g,type:"quantitative"},a,{allowDisabling:!1})}]}}else{(e.center||e.extent)&&Ce(jme(e.center,e.extent)),s==="aggregated-upper-lower"?(f=[],u=[{calculate:Qt(n.field),as:`upper_${c}`},{calculate:Qt(c),as:`lower_${c}`}]):s==="aggregated-error"&&(f=[{fieldPrefix:"",titlePrefix:c}],u=[{calculate:`${Qt(c)} + ${Qt(r.field)}`,as:`upper_${c}`}],i?u.push({calculate:`${Qt(c)} + ${Qt(i.field)}`,as:`lower_${c}`}):u.push({calculate:`${Qt(c)} - ${Qt(r.field)}`,as:`lower_${c}`}));for(const h of u)f.push({fieldPrefix:h.as.substring(0,6),titlePrefix:Jc(Jc(h.calculate,"datum['",""),"']","")})}return{postAggregateCalculates:u,errorBarSpecificAggregate:l,tooltipSummary:f,tooltipTitleWithFieldName:d}}function k6(e,t,n){return`${N0(e)} ${n} ${t}`}const V$="errorband",Rve=["band","borders"],Nve=new u2(V$,Cj);function Cj(e,{config:t}){e={...e,encoding:c2(e.encoding,t)};const{transform:n,continuousAxisChannelDef:r,continuousAxis:i,encodingWithoutContinuousAxis:s,markDef:o,outerSpec:a,tooltipEncoding:l}=Sj(e,V$,t),u=o,c=G$(u,i,r,s,t.errorband),f=e.encoding.x!==void 0&&e.encoding.y!==void 0;let d={type:f?"area":"rect"},h={type:f?"line":"rule"};const p={...u.interpolate?{interpolate:u.interpolate}:{},...u.tension&&u.interpolate?{tension:u.tension}:{}};return f?(d={...d,...p,ariaRoleDescription:"errorband"},h={...h,...p,aria:!1}):u.interpolate?Ce(m6("interpolate")):u.tension&&Ce(m6("tension")),{...a,transform:n,layer:[...c({partName:"band",mark:d,positionPrefix:"lower",endPositionPrefix:"upper",extraEncoding:l}),...c({partName:"borders",mark:h,positionPrefix:"lower",extraEncoding:l}),...c({partName:"borders",mark:h,positionPrefix:"upper",extraEncoding:l})]}}const $j={};function X$(e,t,n){const r=new u2(e,t);$j[e]={normalizer:r,parts:n}}function Ove(){return Ae($j)}X$(cy,Ej,Eve);X$(Y$,kj,Sve);X$(V$,Cj,Rve);const Lve=["gradientHorizontalMaxLength","gradientHorizontalMinLength","gradientVerticalMaxLength","gradientVerticalMinLength","unselectedOpacity"],Fj={titleAlign:"align",titleAnchor:"anchor",titleAngle:"angle",titleBaseline:"baseline",titleColor:"color",titleFont:"font",titleFontSize:"fontSize",titleFontStyle:"fontStyle",titleFontWeight:"fontWeight",titleLimit:"limit",titleLineHeight:"lineHeight",titleOrient:"orient",titlePadding:"offset"},Dj={labelAlign:"align",labelAnchor:"anchor",labelAngle:"angle",labelBaseline:"baseline",labelColor:"color",labelFont:"font",labelFontSize:"fontSize",labelFontStyle:"fontStyle",labelFontWeight:"fontWeight",labelLimit:"limit",labelLineHeight:"lineHeight",labelOrient:"orient",labelPadding:"offset"},Ive=Ae(Fj),Pve=Ae(Dj),Bve={header:1,headerRow:1,headerColumn:1,headerFacet:1},Mj=Ae(Bve),Tj=["size","shape","fill","stroke","strokeDash","strokeWidth","opacity"],zve={gradientHorizontalMaxLength:200,gradientHorizontalMinLength:100,gradientVerticalMaxLength:200,gradientVerticalMinLength:64,unselectedOpacity:.35},jve={aria:1,clipHeight:1,columnPadding:1,columns:1,cornerRadius:1,description:1,direction:1,fillColor:1,format:1,formatType:1,gradientLength:1,gradientOpacity:1,gradientStrokeColor:1,gradientStrokeWidth:1,gradientThickness:1,gridAlign:1,labelAlign:1,labelBaseline:1,labelColor:1,labelFont:1,labelFontSize:1,labelFontStyle:1,labelFontWeight:1,labelLimit:1,labelOffset:1,labelOpacity:1,labelOverlap:1,labelPadding:1,labelSeparation:1,legendX:1,legendY:1,offset:1,orient:1,padding:1,rowPadding:1,strokeColor:1,symbolDash:1,symbolDashOffset:1,symbolFillColor:1,symbolLimit:1,symbolOffset:1,symbolOpacity:1,symbolSize:1,symbolStrokeColor:1,symbolStrokeWidth:1,symbolType:1,tickCount:1,tickMinStep:1,title:1,titleAlign:1,titleAnchor:1,titleBaseline:1,titleColor:1,titleFont:1,titleFontSize:1,titleFontStyle:1,titleFontWeight:1,titleLimit:1,titleLineHeight:1,titleOpacity:1,titleOrient:1,titlePadding:1,type:1,values:1,zindex:1},wo="_vgsid_",Uve={point:{on:"click",fields:[wo],toggle:"event.shiftKey",resolve:"global",clear:"dblclick"},interval:{on:"[pointerdown, window:pointerup] > window:pointermove!",encodings:["x","y"],translate:"[pointerdown, window:pointerup] > window:pointermove!",zoom:"wheel!",mark:{fill:"#333",fillOpacity:.125,stroke:"white"},resolve:"global",clear:"dblclick"}};function K$(e){return e==="legend"||!!(e!=null&&e.legend)}function d_(e){return K$(e)&&Pe(e)}function Z$(e){return!!(e!=null&&e.select)}function Rj(e){const t=[];for(const n of e||[]){if(Z$(n))continue;const{expr:r,bind:i,...s}=n;if(i&&r){const o={...s,bind:i,init:r};t.push(o)}else{const o={...s,...r?{update:r}:{},...i?{bind:i}:{}};t.push(o)}}return t}function qve(e){return f2(e)||Q$(e)||J$(e)}function J$(e){return Se(e,"concat")}function f2(e){return Se(e,"vconcat")}function Q$(e){return Se(e,"hconcat")}function Nj({step:e,offsetIsDiscrete:t}){return t?e.for??"offset":"position"}function ga(e){return Se(e,"step")}function S6(e){return Se(e,"view")||Se(e,"width")||Se(e,"height")}const C6=20,Wve={align:1,bounds:1,center:1,columns:1,spacing:1},Hve=Ae(Wve);function Gve(e,t,n){const r=n[t],i={},{spacing:s,columns:o}=r;s!==void 0&&(i.spacing=s),o!==void 0&&(s2(e)&&!j0(e.facet)||J$(e))&&(i.columns=o),f2(e)&&(i.columns=1);for(const a of Hve)if(e[a]!==void 0)if(a==="spacing"){const l=e[a];i[a]=Gt(l)?l:{row:l.row??s,column:l.column??s}}else i[a]=e[a];return i}function uA(e,t){return e[t]??e[t==="width"?"continuousWidth":"continuousHeight"]}function cA(e,t){const n=fy(e,t);return ga(n)?n.step:Oj}function fy(e,t){const n=e[t]??e[t==="width"?"discreteWidth":"discreteHeight"];return jn(n,{step:e.step})}const Oj=20,Yve={continuousWidth:200,continuousHeight:200,step:Oj},Vve={background:"white",padding:5,timeFormat:"%b %d, %Y",countTitle:"Count of Records",view:Yve,mark:B1e,arc:{},area:{},bar:q1e,circle:{},geoshape:{},image:{},line:{},point:{},rect:N$,rule:{color:"black"},square:{},text:{color:"black"},tick:W1e,trail:{},boxplot:{size:14,extent:1.5,box:{},median:{color:"white"},outliers:{},rule:{},ticks:null},errorbar:{center:"mean",rule:!0,ticks:!1},errorband:{band:{opacity:.3},borders:!1},scale:x1e,projection:{},legend:zve,header:{titlePadding:10,labelPadding:10},headerColumn:{},headerRow:{},headerFacet:{},selection:Uve,style:{},title:{},facet:{spacing:C6},concat:{spacing:C6},normalizedNumberFormat:".0%"},Oa=["#4c78a8","#f58518","#e45756","#72b7b2","#54a24b","#eeca3b","#b279a2","#ff9da6","#9d755d","#bab0ac"],$6={text:11,guideLabel:10,guideTitle:11,groupTitle:13,groupSubtitle:12},F6={blue:Oa[0],orange:Oa[1],red:Oa[2],teal:Oa[3],green:Oa[4],yellow:Oa[5],purple:Oa[6],pink:Oa[7],brown:Oa[8],gray0:"#000",gray1:"#111",gray2:"#222",gray3:"#333",gray4:"#444",gray5:"#555",gray6:"#666",gray7:"#777",gray8:"#888",gray9:"#999",gray10:"#aaa",gray11:"#bbb",gray12:"#ccc",gray13:"#ddd",gray14:"#eee",gray15:"#fff"};function Xve(e={}){return{signals:[{name:"color",value:Pe(e)?{...F6,...e}:F6}],mark:{color:{signal:"color.blue"}},rule:{color:{signal:"color.gray0"}},text:{color:{signal:"color.gray0"}},style:{"guide-label":{fill:{signal:"color.gray0"}},"guide-title":{fill:{signal:"color.gray0"}},"group-title":{fill:{signal:"color.gray0"}},"group-subtitle":{fill:{signal:"color.gray0"}},cell:{stroke:{signal:"color.gray8"}}},axis:{domainColor:{signal:"color.gray13"},gridColor:{signal:"color.gray8"},tickColor:{signal:"color.gray13"}},range:{category:[{signal:"color.blue"},{signal:"color.orange"},{signal:"color.red"},{signal:"color.teal"},{signal:"color.green"},{signal:"color.yellow"},{signal:"color.purple"},{signal:"color.pink"},{signal:"color.brown"},{signal:"color.grey8"}]}}}function Kve(e){return{signals:[{name:"fontSize",value:Pe(e)?{...$6,...e}:$6}],text:{fontSize:{signal:"fontSize.text"}},style:{"guide-label":{fontSize:{signal:"fontSize.guideLabel"}},"guide-title":{fontSize:{signal:"fontSize.guideTitle"}},"group-title":{fontSize:{signal:"fontSize.groupTitle"}},"group-subtitle":{fontSize:{signal:"fontSize.groupSubtitle"}}}}}function Zve(e){return{text:{font:e},style:{"guide-label":{font:e},"guide-title":{font:e},"group-title":{font:e},"group-subtitle":{font:e}}}}function Lj(e){const t=Ae(e||{}),n={};for(const r of t){const i=e[r];n[r]=H0(i)?cz(i):ns(i)}return n}function Jve(e){const t=Ae(e),n={};for(const r of t)n[r]=Lj(e[r]);return n}const Qve=[...Hz,...hj,...Mj,"background","padding","legend","lineBreak","scale","style","title","view"];function Ij(e={}){const{color:t,font:n,fontSize:r,selection:i,...s}=e,o=gh({},gt(Vve),n?Zve(n):{},t?Xve(t):{},r?Kve(r):{},s||{});i&&mh(o,"selection",i,!0);const a=Pi(o,Qve);for(const l of["background","lineBreak","padding"])o[l]&&(a[l]=ns(o[l]));for(const l of Hz)o[l]&&(a[l]=Ar(o[l]));for(const l of hj)o[l]&&(a[l]=Lj(o[l]));for(const l of Mj)o[l]&&(a[l]=Ar(o[l]));if(o.legend&&(a.legend=Ar(o.legend)),o.scale){const{invalid:l,...u}=o.scale,c=Ar(l,{level:1});a.scale={...Ar(u),...Ae(c).length>0?{invalid:c}:{}}}return o.style&&(a.style=Jve(o.style)),o.title&&(a.title=Ar(o.title)),o.view&&(a.view=Ar(o.view)),a}const eye=new Set(["view",...R1e]),tye=["color","fontSize","background","padding","facet","concat","numberFormat","numberFormatType","normalizedNumberFormat","normalizedNumberFormatType","timeFormat","countTitle","header","axisQuantitative","axisTemporal","axisDiscrete","axisPoint","axisXBand","axisXPoint","axisXDiscrete","axisXQuantitative","axisXTemporal","axisYBand","axisYPoint","axisYDiscrete","axisYQuantitative","axisYTemporal","scale","selection","overlay"],nye={view:["continuousWidth","continuousHeight","discreteWidth","discreteHeight","step"],...P1e};function rye(e){e=gt(e);for(const t of tye)delete e[t];if(e.axis)for(const t in e.axis)H0(e.axis[t])&&delete e.axis[t];if(e.legend)for(const t of Lve)delete e.legend[t];if(e.mark){for(const t of y6)delete e.mark[t];e.mark.tooltip&&Pe(e.mark.tooltip)&&delete e.mark.tooltip}e.params&&(e.signals=(e.signals||[]).concat(Rj(e.params)),delete e.params);for(const t of eye){for(const r of y6)delete e[t][r];const n=nye[t];if(n)for(const r of n)delete e[t][r];sye(e,t)}for(const t of Ove())delete e[t];iye(e);for(const t in e)Pe(e[t])&&an(e[t])&&delete e[t];return an(e)?void 0:e}function iye(e){const{titleMarkConfig:t,subtitleMarkConfig:n,subtitle:r}=uz(e.title);an(t)||(e.style["group-title"]={...e.style["group-title"],...t}),an(n)||(e.style["group-subtitle"]={...e.style["group-subtitle"],...n}),an(r)?delete e.title:e.title=r}function sye(e,t,n,r){const i=e[t];t==="view"&&(n="cell");const s={...i,...e.style[n??t]};an(s)||(e.style[n??t]=s),delete e[t]}function d2(e){return Se(e,"layer")}function oye(e){return Se(e,"repeat")}function aye(e){return!fe(e.repeat)&&Se(e.repeat,"layer")}class eF{map(t,n){return s2(t)?this.mapFacet(t,n):oye(t)?this.mapRepeat(t,n):Q$(t)?this.mapHConcat(t,n):f2(t)?this.mapVConcat(t,n):J$(t)?this.mapConcat(t,n):this.mapLayerOrUnit(t,n)}mapLayerOrUnit(t,n){if(d2(t))return this.mapLayer(t,n);if(wl(t))return this.mapUnit(t,n);throw new Error(g$(t))}mapLayer(t,n){return{...t,layer:t.layer.map(r=>this.mapLayerOrUnit(r,n))}}mapHConcat(t,n){return{...t,hconcat:t.hconcat.map(r=>this.map(r,n))}}mapVConcat(t,n){return{...t,vconcat:t.vconcat.map(r=>this.map(r,n))}}mapConcat(t,n){const{concat:r,...i}=t;return{...i,concat:r.map(s=>this.map(s,n))}}mapFacet(t,n){return{...t,spec:this.map(t.spec,n)}}mapRepeat(t,n){return{...t,spec:this.map(t.spec,n)}}}const lye={zero:1,center:1,normalize:1};function uye(e){return We(lye,e)}const cye=new Set([Uz,t2,e2,iy,r2,T$,R$,n2,qz,M$]),fye=new Set([t2,e2,Uz]);function Uf(e){return $e(e)&&nh(e)==="quantitative"&&!e.bin}function D6(e,t,{orient:n,type:r}){const i=t==="x"?"y":"radius",s=t==="x"&&["bar","area"].includes(r),o=e[t],a=e[i];if($e(o)&&$e(a))if(Uf(o)&&Uf(a)){if(o.stack)return t;if(a.stack)return i;const l=$e(o)&&!!o.aggregate,u=$e(a)&&!!a.aggregate;if(l!==u)return l?t:i;if(s){if(n==="vertical")return i;if(n==="horizontal")return t}}else{if(Uf(o))return t;if(Uf(a))return i}else{if(Uf(o))return s&&n==="vertical"?void 0:t;if(Uf(a))return s&&n==="horizontal"?void 0:i}}function dye(e){switch(e){case"x":return"y";case"y":return"x";case"theta":return"radius";case"radius":return"theta"}}function Pj(e,t){var g,m;const n=pa(e)?e:{type:e},r=n.type;if(!cye.has(r))return null;const i=D6(t,"x",n)||D6(t,"theta",n);if(!i)return null;const s=t[i],o=$e(s)?Ne(s,{}):void 0,a=dye(i),l=[],u=new Set;if(t[a]){const v=t[a],b=$e(v)?Ne(v,{}):void 0;b&&b!==o&&(l.push(a),u.add(b))}const c=a==="x"?"xOffset":"yOffset",f=t[c],d=$e(f)?Ne(f,{}):void 0;d&&d!==o&&(l.push(c),u.add(d));const h=b0e.reduce((v,b)=>{if(b!=="tooltip"&&$c(t,b)){const x=t[b];for(const _ of je(x)){const w=_o(_);if(w.aggregate)continue;const A=Ne(w,{});(!A||!u.has(A))&&v.push({channel:b,fieldDef:w})}}return v},[]);let p;return s.stack!==void 0?wu(s.stack)?p=s.stack?"zero":null:p=s.stack:fye.has(r)&&(p="zero"),!p||!uye(p)||mj(t)&&h.length===0?null:((g=s==null?void 0:s.scale)!=null&&g.type&&((m=s==null?void 0:s.scale)==null?void 0:m.type)!==kr.LINEAR&&s!=null&&s.stack&&Ce(Pme(s.scale.type)),vt(t[Ca(i)])?(s.stack!==void 0&&Ce(Ime(i)),null):($e(s)&&s.aggregate&&!T0e.has(s.aggregate)&&Ce(Bme(s.aggregate)),{groupbyChannels:l,groupbyFields:u,fieldChannel:i,impute:s.impute===null?!1:Iu(r),stackBy:h,offset:p}))}function Bj(e,t,n){const r=Ar(e),i=on("orient",r,n);if(r.orient=mye(r.type,t,i),i!==void 0&&i!==r.orient&&Ce(_me(r.orient,i)),r.type==="bar"&&r.orient){const l=on("cornerRadiusEnd",r,n);if(l!==void 0){const u=r.orient==="horizontal"&&t.x2||r.orient==="vertical"&&t.y2?["cornerRadius"]:j1e[r.orient];for(const c of u)r[c]=l;r.cornerRadiusEnd!==void 0&&delete r.cornerRadiusEnd}}const s=on("opacity",r,n),o=on("fillOpacity",r,n);return s===void 0&&o===void 0&&(r.opacity=pye(r.type,t)),on("cursor",r,n)===void 0&&(r.cursor=hye(r,t,n)),r}function hye(e,t,n){return t.href||e.href||on("href",e,n)?"pointer":e.cursor}function pye(e,t){if(Tt([r2,M$,T$,R$],e)&&!mj(t))return .7}function gye(e,t,{graticule:n}){if(n)return!1;const r=ha("filled",e,t),i=e.type;return jn(r,i!==r2&&i!==n2&&i!==iy)}function mye(e,t,n){switch(e){case r2:case T$:case R$:case qz:case M1e:case D1e:return}const{x:r,y:i,x2:s,y2:o}=t;switch(e){case t2:if($e(r)&&(wr(r.bin)||$e(i)&&i.aggregate&&!r.aggregate))return"vertical";if($e(i)&&(wr(i.bin)||$e(r)&&r.aggregate&&!i.aggregate))return"horizontal";if(o||s){if(n)return n;if(!s)return($e(r)&&r.type===nf&&!dn(r.bin)||oy(r))&&$e(i)&&wr(i.bin)?"horizontal":"vertical";if(!o)return($e(i)&&i.type===nf&&!dn(i.bin)||oy(i))&&$e(r)&&wr(r.bin)?"vertical":"horizontal"}case iy:if(s&&!($e(r)&&wr(r.bin))&&o&&!($e(i)&&wr(i.bin)))return;case e2:if(o)return $e(i)&&wr(i.bin)?"horizontal":"vertical";if(s)return $e(r)&&wr(r.bin)?"vertical":"horizontal";if(e===iy){if(r&&!i)return"vertical";if(i&&!r)return"horizontal"}case n2:case M$:{const a=w6(r),l=w6(i);if(n)return n;if(a&&!l)return e!=="tick"?"horizontal":"vertical";if(!a&&l)return e!=="tick"?"vertical":"horizontal";if(a&&l)return"vertical";{const u=xi(r)&&r.type===eh,c=xi(i)&&i.type===eh;if(u&&!c)return"vertical";if(!u&&c)return"horizontal"}return}}return"vertical"}function vye(e){const{point:t,line:n,...r}=e;return Ae(r).length>1?r:r.type}function yye(e){for(const t of["line","area","rule","trail"])e[t]&&(e={...e,[t]:Pi(e[t],["point","line"])});return e}function h_(e,t={},n){return e.point==="transparent"?{opacity:0}:e.point?Pe(e.point)?e.point:{}:e.point!==void 0?null:t.point||n.shape?Pe(t.point)?t.point:{}:void 0}function M6(e,t={}){return e.line?e.line===!0?{}:e.line:e.line!==void 0?null:t.line?t.line===!0?{}:t.line:void 0}class bye{constructor(){this.name="path-overlay"}hasMatchingType(t,n){if(wl(t)){const{mark:r,encoding:i}=t,s=pa(r)?r:{type:r};switch(s.type){case"line":case"rule":case"trail":return!!h_(s,n[s.type],i);case"area":return!!h_(s,n[s.type],i)||!!M6(s,n[s.type])}}return!1}run(t,n,r){const{config:i}=n,{params:s,projection:o,mark:a,name:l,encoding:u,...c}=t,f=c2(u,i),d=pa(a)?a:{type:a},h=h_(d,i[d.type],f),p=d.type==="area"&&M6(d,i[d.type]),g=[{name:l,...s?{params:s}:{},mark:vye({...d.type==="area"&&d.opacity===void 0&&d.fillOpacity===void 0?{opacity:.7}:{},...d}),encoding:Pi(f,["shape"])}],m=Pj(Bj(d,f,i),f);let v=f;if(m){const{fieldChannel:b,offset:x}=m;v={...f,[b]:{...f[b],...x?{stack:x}:{}}}}return v=Pi(v,["y2","x2"]),p&&g.push({...o?{projection:o}:{},mark:{type:"line",...Kd(d,["clip","interpolate","tension","tooltip"]),...p},encoding:v}),h&&g.push({...o?{projection:o}:{},mark:{type:"point",opacity:1,filled:!0,...Kd(d,["clip","tooltip"]),...h},encoding:v}),r({...c,layer:g},{...n,config:yye(i)})}}function xye(e,t){return t?j0(e)?jj(e,t):zj(e,t):e}function p_(e,t){return t?jj(e,t):e}function fA(e,t,n){const r=t[e];if(nve(r)){if(r.repeat in n)return{...t,[e]:n[r.repeat]};Ce(J0e(r.repeat));return}return t}function zj(e,t){if(e=fA("field",e,t),e!==void 0){if(e===null)return null;if(z$(e)&&il(e.sort)){const n=fA("field",e.sort,t);e={...e,...n?{sort:n}:{}}}return e}}function T6(e,t){if($e(e))return zj(e,t);{const n=fA("datum",e,t);return n!==e&&!n.type&&(n.type="nominal"),n}}function R6(e,t){if(vt(e)){const n=T6(e,t);if(n)return n;if(U0(e))return{condition:e.condition}}else{if(q0(e)){const n=T6(e.condition,t);if(n)return{...e,condition:n};{const{condition:r,...i}=e;return i}}return e}}function jj(e,t){const n={};for(const r in e)if(Se(e,r)){const i=e[r];if(fe(i))n[r]=i.map(s=>R6(s,t)).filter(s=>s);else{const s=R6(i,t);s!==void 0&&(n[r]=s)}}return n}class _ye{constructor(){this.name="RuleForRangedLine"}hasMatchingType(t){if(wl(t)){const{encoding:n,mark:r}=t;if(r==="line"||pa(r)&&r.type==="line")for(const i of m0e){const s=_f(i),o=n[s];if(n[i]&&($e(o)&&!wr(o.bin)||Fa(o)))return!0}}return!1}run(t,n,r){const{encoding:i,mark:s}=t;return Ce(xme(!!i.x2,!!i.y2)),r({...t,mark:Pe(s)?{...s,type:"rule"}:"rule"},n)}}class wye extends eF{constructor(){super(...arguments),this.nonFacetUnitNormalizers=[Ave,Cve,Nve,new bye,new _ye]}map(t,n){if(wl(t)){const r=$c(t.encoding,nl),i=$c(t.encoding,rl),s=$c(t.encoding,qb);if(r||i||s)return this.mapFacetedUnit(t,n)}return super.map(t,n)}mapUnit(t,n){const{parentEncoding:r,parentProjection:i}=n,s=p_(t.encoding,n.repeater),o={...t,...t.name?{name:[n.repeaterPrefix,t.name].filter(l=>l).join("_")}:{},...s?{encoding:s}:{}};if(r||i)return this.mapUnitWithParentEncodingOrProjection(o,n);const a=this.mapLayerOrUnit.bind(this);for(const l of this.nonFacetUnitNormalizers)if(l.hasMatchingType(o,n.config))return l.run(o,n,a);return o}mapRepeat(t,n){return aye(t)?this.mapLayerRepeat(t,n):this.mapNonLayerRepeat(t,n)}mapLayerRepeat(t,n){const{repeat:r,spec:i,...s}=t,{row:o,column:a,layer:l}=r,{repeater:u={},repeaterPrefix:c=""}=n;return o||a?this.mapRepeat({...t,repeat:{...o?{row:o}:{},...a?{column:a}:{}},spec:{repeat:{layer:l},spec:i}},n):{...s,layer:l.map(f=>{const d={...u,layer:f},h=`${(i.name?`${i.name}_`:"")+c}child__layer_${_n(f)}`,p=this.mapLayerOrUnit(i,{...n,repeater:d,repeaterPrefix:h});return p.name=h,p})}}mapNonLayerRepeat(t,n){const{repeat:r,spec:i,data:s,...o}=t;!fe(r)&&t.columns&&(t=Pi(t,["columns"]),Ce(d6("repeat")));const a=[],{repeater:l={},repeaterPrefix:u=""}=n,c=!fe(r)&&r.row||[l?l.row:null],f=!fe(r)&&r.column||[l?l.column:null],d=fe(r)&&r||[l?l.repeat:null];for(const p of d)for(const g of c)for(const m of f){const v={repeat:p,row:g,column:m,layer:l.layer},b=(i.name?`${i.name}_`:"")+u+"child__"+(fe(r)?`${_n(p)}`:(r.row?`row_${_n(g)}`:"")+(r.column?`column_${_n(m)}`:"")),x=this.map(i,{...n,repeater:v,repeaterPrefix:b});x.name=b,a.push(Pi(x,["data"]))}const h=fe(r)?t.columns:r.column?r.column.length:1;return{data:i.data??s,align:"all",...o,columns:h,concat:a}}mapFacet(t,n){const{facet:r}=t;return j0(r)&&t.columns&&(t=Pi(t,["columns"]),Ce(d6("facet"))),super.mapFacet(t,n)}mapUnitWithParentEncodingOrProjection(t,n){const{encoding:r,projection:i}=t,{parentEncoding:s,parentProjection:o,config:a}=n,l=O6({parentProjection:o,projection:i}),u=N6({parentEncoding:s,encoding:p_(r,n.repeater)});return this.mapUnit({...t,...l?{projection:l}:{},...u?{encoding:u}:{}},{config:a})}mapFacetedUnit(t,n){const{row:r,column:i,facet:s,...o}=t.encoding,{mark:a,width:l,projection:u,height:c,view:f,params:d,encoding:h,...p}=t,{facetMapping:g,layout:m}=this.getFacetMappingAndLayout({row:r,column:i,facet:s},n),v=p_(o,n.repeater);return this.mapFacet({...p,...m,facet:g,spec:{...l?{width:l}:{},...c?{height:c}:{},...f?{view:f}:{},...u?{projection:u}:{},mark:a,encoding:v,...d?{params:d}:{}}},n)}getFacetMappingAndLayout(t,n){const{row:r,column:i,facet:s}=t;if(r||i){s&&Ce(yme([...r?[nl]:[],...i?[rl]:[]]));const o={},a={};for(const l of[nl,rl]){const u=t[l];if(u){const{align:c,center:f,spacing:d,columns:h,...p}=u;o[l]=p;for(const g of["align","center","spacing"])u[g]!==void 0&&(a[g]??(a[g]={}),a[g][l]=u[g])}}return{facetMapping:o,layout:a}}else{const{align:o,center:a,spacing:l,columns:u,...c}=s;return{facetMapping:xye(c,n.repeater),layout:{...o?{align:o}:{},...a?{center:a}:{},...l?{spacing:l}:{},...u?{columns:u}:{}}}}}mapLayer(t,{parentEncoding:n,parentProjection:r,...i}){const{encoding:s,projection:o,...a}=t,l={...i,parentEncoding:N6({parentEncoding:n,encoding:s,layer:!0}),parentProjection:O6({parentProjection:r,projection:o})};return super.mapLayer({...a,...t.name?{name:[l.repeaterPrefix,t.name].filter(u=>u).join("_")}:{}},l)}}function N6({parentEncoding:e,encoding:t={},layer:n}){let r={};if(e){const i=new Set([...Ae(e),...Ae(t)]);for(const s of i){const o=t[s],a=e[s];if(vt(o)){const l={...a,...o};r[s]=l}else q0(o)?r[s]={...o,condition:{...a,...o.condition}}:o||o===null?r[s]=o:(n||xo(a)||tt(a)||vt(a)||fe(a))&&(r[s]=a)}}else r=t;return!r||an(r)?void 0:r}function O6(e){const{parentProjection:t,projection:n}=e;return t&&n&&Ce(ame({parentProjection:t,projection:n})),n??t}function tF(e){return Se(e,"filter")}function Eye(e){return Se(e,"stop")}function Uj(e){return Se(e,"lookup")}function Aye(e){return Se(e,"data")}function kye(e){return Se(e,"param")}function Sye(e){return Se(e,"pivot")}function Cye(e){return Se(e,"density")}function $ye(e){return Se(e,"quantile")}function Fye(e){return Se(e,"regression")}function Dye(e){return Se(e,"loess")}function Mye(e){return Se(e,"sample")}function Tye(e){return Se(e,"window")}function Rye(e){return Se(e,"joinaggregate")}function Nye(e){return Se(e,"flatten")}function Oye(e){return Se(e,"calculate")}function qj(e){return Se(e,"bin")}function Lye(e){return Se(e,"impute")}function Iye(e){return Se(e,"timeUnit")}function Pye(e){return Se(e,"aggregate")}function Bye(e){return Se(e,"stack")}function zye(e){return Se(e,"fold")}function jye(e){return Se(e,"extent")&&!Se(e,"density")&&!Se(e,"regression")}function Uye(e){return e.map(t=>tF(t)?{filter:cd(t.filter,h1e)}:t)}class qye extends eF{map(t,n){return n.emptySelections??(n.emptySelections={}),n.selectionPredicates??(n.selectionPredicates={}),t=L6(t,n),super.map(t,n)}mapLayerOrUnit(t,n){if(t=L6(t,n),t.encoding){const r={};for(const[i,s]of pu(t.encoding))r[i]=Wj(s,n);t={...t,encoding:r}}return super.mapLayerOrUnit(t,n)}mapUnit(t,n){const{selection:r,...i}=t;return r?{...i,params:pu(r).map(([s,o])=>{const{init:a,bind:l,empty:u,...c}=o;c.type==="single"?(c.type="point",c.toggle=!1):c.type==="multi"&&(c.type="point"),n.emptySelections[s]=u!=="none";for(const f of Mr(n.selectionPredicates[s]??{}))f.empty=u!=="none";return{name:s,value:a,select:c,bind:l}})}:t}}function L6(e,t){const{transform:n,...r}=e;if(n){const i=n.map(s=>{if(tF(s))return{filter:dA(s,t)};if(qj(s)&&wf(s.bin))return{...s,bin:Hj(s.bin)};if(Uj(s)){const{selection:o,...a}=s.from;return o?{...s,from:{param:o,...a}}:s}return s});return{...r,transform:i}}return e}function Wj(e,t){var r,i;const n=gt(e);if($e(n)&&wf(n.bin)&&(n.bin=Hj(n.bin)),Sf(n)&&((i=(r=n.scale)==null?void 0:r.domain)!=null&&i.selection)){const{selection:s,...o}=n.scale.domain;n.scale.domain={...o,...s?{param:s}:{}}}if(U0(n))if(fe(n.condition))n.condition=n.condition.map(s=>{const{selection:o,param:a,test:l,...u}=s;return a?s:{...u,test:dA(s,t)}});else{const{selection:s,param:o,test:a,...l}=Wj(n.condition,t);n.condition=o?n.condition:{...l,test:dA(n.condition,t)}}return n}function Hj(e){const t=e.extent;if(t!=null&&t.selection){const{selection:n,...r}=t;return{...e,extent:{...r,param:n}}}return e}function dA(e,t){const n=r=>cd(r,i=>{var s;const o=t.emptySelections[i]??!0,a={param:i,empty:o};return(s=t.selectionPredicates)[i]??(s[i]=[]),t.selectionPredicates[i].push(a),a});return e.selection?n(e.selection):cd(e.test||e.filter,r=>r.selection?n(r.selection):r)}class hA extends eF{map(t,n){const r=n.selections??[];if(t.params&&!wl(t)){const i=[];for(const s of t.params)Z$(s)?r.push(s):i.push(s);t.params=i}return n.selections=r,super.map(t,n)}mapUnit(t,n){const r=n.selections;if(!r||!r.length)return t;const i=(n.path??[]).concat(t.name),s=[];for(const o of r)if(!o.views||!o.views.length)s.push(o);else for(const a of o.views)(ze(a)&&(a===t.name||i.includes(a))||fe(a)&&a.map(l=>i.indexOf(l)).every((l,u,c)=>l!==-1&&(u===0||l>c[u-1])))&&s.push(o);return s.length&&(t.params=s),t}}for(const e of["mapFacet","mapRepeat","mapHConcat","mapVConcat","mapLayer"]){const t=hA.prototype[e];hA.prototype[e]=function(n,r){return t.call(this,n,Wye(n,r))}}function Wye(e,t){return e.name?{...t,path:(t.path??[]).concat(e.name)}:t}function Gj(e,t){t===void 0&&(t=Ij(e.config));const n=Vye(e,t),{width:r,height:i}=e,s=Xye(n,{width:r,height:i,autosize:e.autosize},t);return{...n,...s?{autosize:s}:{}}}const Hye=new wye,Gye=new qye,Yye=new hA;function Vye(e,t={}){const n={config:t};return Yye.map(Hye.map(Gye.map(e,n),n),n)}function I6(e){return ze(e)?{type:e}:e??{}}function Xye(e,t,n){let{width:r,height:i}=t;const s=wl(e)||d2(e),o={};s?r=="container"&&i=="container"?(o.type="fit",o.contains="padding"):r=="container"?(o.type="fit-x",o.contains="padding"):i=="container"&&(o.type="fit-y",o.contains="padding"):(r=="container"&&(Ce(l6("width")),r=void 0),i=="container"&&(Ce(l6("height")),i=void 0));const a={type:"pad",...o,...n?I6(n.autosize):{},...I6(e.autosize)};if(a.type==="fit"&&!s&&(Ce(j0e),a.type="pad"),r=="container"&&!(a.type=="fit"||a.type=="fit-x")&&Ce(u6("width")),i=="container"&&!(a.type=="fit"||a.type=="fit-y")&&Ce(u6("height")),!ss(a,{type:"pad"}))return a}function Kye(e){return["fit","fit-x","fit-y"].includes(e)}function Zye(e){return e?`fit-${Vb(e)}`:"fit"}const Jye=["background","padding"];function P6(e,t){const n={};for(const r of Jye)e&&e[r]!==void 0&&(n[r]=ns(e[r]));return t&&(n.params=e.params),n}class El{constructor(t={},n={}){this.explicit=t,this.implicit=n}clone(){return new El(gt(this.explicit),gt(this.implicit))}combine(){return{...this.explicit,...this.implicit}}get(t){return jn(this.explicit[t],this.implicit[t])}getWithExplicit(t){return this.explicit[t]!==void 0?{explicit:!0,value:this.explicit[t]}:this.implicit[t]!==void 0?{explicit:!1,value:this.implicit[t]}:{explicit:!1,value:void 0}}setWithExplicit(t,{value:n,explicit:r}){n!==void 0&&this.set(t,n,r)}set(t,n,r){return delete this[r?"implicit":"explicit"][t],this[r?"explicit":"implicit"][t]=n,this}copyKeyFromSplit(t,{explicit:n,implicit:r}){n[t]!==void 0?this.set(t,n[t],!0):r[t]!==void 0&&this.set(t,r[t],!1)}copyKeyFromObject(t,n){n[t]!==void 0&&this.set(t,n[t],!0)}copyAll(t){for(const n of Ae(t.combine())){const r=t.getWithExplicit(n);this.setWithExplicit(n,r)}}}function jo(e){return{explicit:!0,value:e}}function Ki(e){return{explicit:!1,value:e}}function Yj(e){return(t,n,r,i)=>{const s=e(t.value,n.value);return s>0?t:s<0?n:h2(t,n,r,i)}}function h2(e,t,n,r){return e.explicit&&t.explicit&&Ce(Dme(n,r,e.value,t.value)),e}function vu(e,t,n,r,i=h2){return e===void 0||e.value===void 0?t:e.explicit&&!t.explicit?e:t.explicit&&!e.explicit?t:ss(e.value,t.value)?e:i(e,t,n,r)}class Qye extends El{constructor(t={},n={},r=!1){super(t,n),this.explicit=t,this.implicit=n,this.parseNothing=r}clone(){const t=super.clone();return t.parseNothing=this.parseNothing,t}}function sh(e){return Se(e,"url")}function Ig(e){return Se(e,"values")}function Vj(e){return Se(e,"name")&&!sh(e)&&!Ig(e)&&!nu(e)}function nu(e){return e&&(Xj(e)||Kj(e)||nF(e))}function Xj(e){return Se(e,"sequence")}function Kj(e){return Se(e,"sphere")}function nF(e){return Se(e,"graticule")}var $n;(function(e){e[e.Raw=0]="Raw",e[e.Main=1]="Main",e[e.Row=2]="Row",e[e.Column=3]="Column",e[e.Lookup=4]="Lookup",e[e.PreFilterInvalid=5]="PreFilterInvalid",e[e.PostFilterInvalid=6]="PostFilterInvalid"})($n||($n={}));function Zj({invalid:e,isPath:t}){switch(Gz(e,{isPath:t})){case"filter":return{marks:"exclude-invalid-values",scales:"exclude-invalid-values"};case"break-paths-show-domains":return{marks:t?"include-invalid-values":"exclude-invalid-values",scales:"include-invalid-values"};case"break-paths-filter-domains":return{marks:t?"include-invalid-values":"exclude-invalid-values",scales:"exclude-invalid-values"};case"show":return{marks:"include-invalid-values",scales:"include-invalid-values"}}}function ebe(e){const{marks:t,scales:n}=Zj(e);return t===n?$n.Main:n==="include-invalid-values"?$n.PreFilterInvalid:$n.PostFilterInvalid}class rn{constructor(t,n){this.debugName=n,this._children=[],this._parent=null,t&&(this.parent=t)}clone(){throw new Error("Cannot clone node")}get parent(){return this._parent}set parent(t){this._parent=t,t&&t.addChild(this)}get children(){return this._children}numChildren(){return this._children.length}addChild(t,n){if(this._children.includes(t)){Ce(ime);return}n!==void 0?this._children.splice(n,0,t):this._children.push(t)}removeChild(t){const n=this._children.indexOf(t);return this._children.splice(n,1),n}remove(){let t=this._parent.removeChild(this);for(const n of this._children)n._parent=this._parent,this._parent.addChild(n,t++)}insertAsParentOf(t){const n=t.parent;n.removeChild(this),this.parent=n,t.parent=this}swapWithParent(){const t=this._parent,n=t.parent;for(const i of this._children)i.parent=t;this._children=[],t.removeChild(this);const r=t.parent.removeChild(t);this._parent=n,n.addChild(this,r),t.parent=this}}class Bi extends rn{clone(){const t=new this.constructor;return t.debugName=`clone_${this.debugName}`,t._source=this._source,t._name=`clone_${this._name}`,t.type=this.type,t.refCounts=this.refCounts,t.refCounts[t._name]=0,t}constructor(t,n,r,i){super(t,n),this.type=r,this.refCounts=i,this._source=this._name=n,this.refCounts&&!(this._name in this.refCounts)&&(this.refCounts[this._name]=0)}dependentFields(){return new Set}producedFields(){return new Set}hash(){return this._hash===void 0&&(this._hash=`Output ${YB()}`),this._hash}getSource(){return this.refCounts[this._name]++,this._source}isRequired(){return!!this.refCounts[this._name]}setSource(t){this._source=t}}function g_(e){return e.as!==void 0}function B6(e){return`${e}_end`}class ra extends rn{clone(){return new ra(null,gt(this.timeUnits))}constructor(t,n){super(t),this.timeUnits=n}static makeFromEncoding(t,n){const r=n.reduceFieldDef((i,s,o)=>{const{field:a,timeUnit:l}=s;if(l){let u;if(kf(l)){if(Cn(n)){const{mark:c,markDef:f,config:d}=n,h=mu({fieldDef:s,markDef:f,config:d});(Lg(c)||h)&&(u={timeUnit:dr(l),field:a})}}else u={as:Ne(s,{forAs:!0}),field:a,timeUnit:l};if(Cn(n)){const{mark:c,markDef:f,config:d}=n,h=mu({fieldDef:s,markDef:f,config:d});Lg(c)&&Un(o)&&h!==.5&&(u.rectBandPosition=h)}u&&(i[It(u)]=u)}return i},{});return an(r)?null:new ra(t,r)}static makeFromTransform(t,n){const{timeUnit:r,...i}={...n},s=dr(r),o={...i,timeUnit:s};return new ra(t,{[It(o)]:o})}merge(t){this.timeUnits={...this.timeUnits};for(const n in t.timeUnits)this.timeUnits[n]||(this.timeUnits[n]=t.timeUnits[n]);for(const n of t.children)t.removeChild(n),n.parent=this;t.remove()}removeFormulas(t){const n={};for(const[r,i]of pu(this.timeUnits)){const s=g_(i)?i.as:`${i.field}_end`;t.has(s)||(n[r]=i)}this.timeUnits=n}producedFields(){return new Set(Mr(this.timeUnits).map(t=>g_(t)?t.as:B6(t.field)))}dependentFields(){return new Set(Mr(this.timeUnits).map(t=>t.field))}hash(){return`TimeUnit ${It(this.timeUnits)}`}assemble(){const t=[];for(const n of Mr(this.timeUnits)){const{rectBandPosition:r}=n,i=dr(n.timeUnit);if(g_(n)){const{field:s,as:o}=n,{unit:a,utc:l,...u}=i,c=[o,`${o}_end`];t.push({field:Bs(s),type:"timeunit",...a?{units:Jb(a)}:{},...l?{timezone:"utc"}:{},...u,as:c}),t.push(...z6(c,r,i))}else if(n){const{field:s}=n,o=s.replaceAll("\\.","."),a=Jj({timeUnit:i,field:o}),l=B6(o);t.push({type:"formula",expr:a,as:l}),t.push(...z6([o,l],r,i))}}return t}}const p2="offsetted_rect_start",g2="offsetted_rect_end";function Jj({timeUnit:e,field:t,reverse:n}){const{unit:r,utc:i}=e,s=$z(r),{part:o,step:a}=Tz(s,e.step);return`${i?"utcOffset":"timeOffset"}('${o}', ${Qt(t)}, ${n?-a:a})`}function z6([e,t],n,r){if(n!==void 0&&n!==.5){const i=Qt(e),s=Qt(t);return[{type:"formula",expr:j6([Jj({timeUnit:r,field:e,reverse:!0}),i],n+.5),as:`${e}_${p2}`},{type:"formula",expr:j6([i,s],n+.5),as:`${e}_${g2}`}]}return[]}function j6([e,t],n){return`${1-n} * ${e} + ${n} * ${t}`}const G0="_tuple_fields";class tbe{constructor(...t){this.items=t,this.hasChannel={},this.hasField={},this.hasSelectionId=!1}}const nbe={defined:()=>!0,parse:(e,t,n)=>{const r=t.name,i=t.project??(t.project=new tbe),s={},o={},a=new Set,l=(p,g)=>{const m=g==="visual"?p.channel:p.field;let v=_n(`${r}_${m}`);for(let b=1;a.has(v);b++)v=_n(`${r}_${m}_${b}`);return a.add(v),{[g]:v}},u=t.type,c=e.config.selection[u],f=n.value!==void 0?je(n.value):null;let{fields:d,encodings:h}=Pe(n.select)?n.select:{};if(!d&&!h&&f){for(const p of f)if(Pe(p))for(const g of Ae(p))g0e(g)?(h||(h=[])).push(g):u==="interval"?(Ce(Z0e),h=c.encodings):(d??(d=[])).push(g)}!d&&!h&&(h=c.encodings,"fields"in c&&(d=c.fields));for(const p of h??[]){const g=e.fieldDef(p);if(g){let m=g.field;if(g.aggregate){Ce(U0e(p,g.aggregate));continue}else if(!m){Ce(f6(p));continue}if(g.timeUnit&&!kf(g.timeUnit)){m=e.vgField(p);const v={timeUnit:g.timeUnit,as:m,field:g.field};o[It(v)]=v}if(!s[m]){const v=u==="interval"&&$a(p)&&bo(e.getScaleComponent(p).get("type"))?"R":g.bin?"R-RE":"E",b={field:m,channel:p,type:v,index:i.items.length};b.signals={...l(b,"data"),...l(b,"visual")},i.items.push(s[m]=b),i.hasField[m]=s[m],i.hasSelectionId=i.hasSelectionId||m===wo,QB(p)?(b.geoChannel=p,b.channel=JB(p),i.hasChannel[b.channel]=s[m]):i.hasChannel[p]=s[m]}}else Ce(f6(p))}for(const p of d??[]){if(i.hasField[p])continue;const g={type:"E",field:p,index:i.items.length};g.signals={...l(g,"data")},i.items.push(g),i.hasField[p]=g,i.hasSelectionId=i.hasSelectionId||p===wo}f&&(t.init=f.map(p=>i.items.map(g=>Pe(p)?p[g.geoChannel||g.channel]!==void 0?p[g.geoChannel||g.channel]:p[g.field]:p))),an(o)||(i.timeUnit=new ra(null,o))},signals:(e,t,n)=>{const r=t.name+G0;return n.filter(s=>s.name===r).length>0||t.project.hasSelectionId?n:n.concat({name:r,value:t.project.items.map(nU)})}},Qj="_curr",F1="anim_value",Xf="anim_clock",pA="eased_anim_clock",eU="min_extent",tU="max_range_extent",m_="last_tick_at",v_="is_playing",rbe=1/60*1e3,ibe=(e,t)=>[{name:pA,update:Xf},{name:`${e}_domain`,init:`domain('${t}')`},{name:eU,init:`extent(${e}_domain)[0]`},{name:tU,init:`extent(range('${t}'))[1]`},{name:F1,update:`invert('${t}', ${pA})`}],sbe={defined:e=>e.type==="point",topLevelSignals:(e,t,n)=>(ia(t)&&(n=n.concat([{name:Xf,init:"0",on:[{events:{type:"timer",throttle:rbe},update:`${v_} ? (${Xf} + (now() - ${m_}) > ${tU} ? 0 : ${Xf} + (now() - ${m_})) : ${Xf}`}]},{name:m_,init:"now()",on:[{events:[{signal:Xf},{signal:v_}],update:"now()"}]},{name:v_,init:"true"}])),n),signals:(e,t,n)=>{const r=t.name,i=r+G0,s=t.project,o="(item().isVoronoi ? datum.datum : datum)",a=Mr(e.component.selection??{}).reduce((c,f)=>f.type==="interval"?c.concat(f.name+hd):c,[]).map(c=>`indexof(item().mark.name, '${c}') < 0`).join(" && "),l=`datum && item().mark.marktype !== 'group' && indexof(item().mark.role, 'legend') < 0${a?` && ${a}`:""}`;let u=`unit: ${Fc(e)}, `;if(t.project.hasSelectionId)u+=`${wo}: ${o}[${De(wo)}]`;else if(ia(t))u+=`fields: ${i}, values: [${F1} ? ${F1} : ${eU}]`;else{const c=s.items.map(f=>{const d=e.fieldDef(f.channel);return d!=null&&d.bin?`[${o}[${De(e.vgField(f.channel,{}))}], ${o}[${De(e.vgField(f.channel,{binSuffix:"end"}))}]]`:`${o}[${De(f.field)}]`}).join(", ");u+=`fields: ${i}, values: [${c}]`}if(ia(t))return n.concat(ibe(t.name,e.scaleName(Mu)),[{name:r+pl,on:[{events:[{signal:pA},{signal:F1}],update:`{${u}}`,force:!0}]}]);{const c=t.events;return n.concat([{name:r+pl,on:c?[{events:c,update:`${l} ? {${u}} : null`,force:!0}]:[]}])}}};function nU(e){const{signals:t,hasLegend:n,index:r,...i}=e;return i.field=Bs(i.field),i}function of(e,t=!0,n=Qr){if(fe(e)){const r=e.map(i=>of(i,t,n));return t?`[${r.join(", ")}]`:r}else if(Af(e))return n(t?tf(e):t1e(e));return t?n(ln(e)):e}function obe(e,t){for(const n of Mr(e.component.selection??{})){const r=n.name;let i=`${r}${pl}, ${n.resolve==="global"?"true":`{unit: ${Fc(e)}}`}`;for(const s of v2)s.defined(n)&&(s.signals&&(t=s.signals(e,n,t)),s.modifyExpr&&(i=s.modifyExpr(e,n,i)));t.push({name:r+Rbe,on:[{events:{signal:n.name+pl},update:`modify(${De(n.name+af)}, ${i})`}]})}return rF(t)}function abe(e,t){if(e.component.selection&&Ae(e.component.selection).length){const n=De(e.getName("cell"));t.unshift({name:"facet",value:{},on:[{events:Fu("pointermove","scope"),update:`isTuple(facet) ? facet : group(${n}).datum`}]})}return rF(t)}function lbe(e,t){let n=!1;for(const r of Mr(e.component.selection??{})){const i=r.name,s=De(i+af);if(t.filter(a=>a.name===i).length===0){const a=r.resolve==="global"?"union":r.resolve,l=r.type==="point"?", true, true)":")";t.push({name:r.name,update:`${bU}(${s}, ${De(a)}${l}`})}n=!0;for(const a of v2)a.defined(r)&&a.topLevelSignals&&(t=a.topLevelSignals(e,r,t))}return n&&t.filter(i=>i.name==="unit").length===0&&t.unshift({name:"unit",value:{},on:[{events:"pointermove",update:"isTuple(group()) ? group() : unit"}]}),rF(t)}function ube(e,t){const n=[],r=[],i=Fc(e,{escape:!1});for(const s of Mr(e.component.selection??{})){const o={name:s.name+af};if(s.project.hasSelectionId&&(o.transform=[{type:"collect",sort:{field:wo}}]),s.init){const l=s.project.items.map(nU);o.values=s.project.hasSelectionId?s.init.map(u=>({unit:i,[wo]:of(u,!1)[0]})):s.init.map(u=>({unit:i,fields:l,values:of(u,!1)}))}if([...n,...t].filter(l=>l.name===s.name+af).length||n.push(o),ia(s)&&t.length){const l=e.lookupDataSource(e.getDataName($n.Main)),u=t.find(f=>f.name===l),c=u.transform.find(f=>f.type==="filter"&&f.expr.includes("vlSelectionTest"));if(c){u.transform=u.transform.filter(d=>d!==c);const f={name:u.name+Qj,source:u.name,transform:[c]};r.push(f)}}}return n.concat(t,r)}function rU(e,t){for(const n of Mr(e.component.selection??{}))for(const r of v2)r.defined(n)&&r.marks&&(t=r.marks(e,n,t));return t}function cbe(e,t){for(const n of e.children)Cn(n)&&(t=rU(n,t));return t}function fbe(e,t,n,r){const i=DU(e,t.param,t);return{signal:bo(n.get("type"))&&fe(r)&&r[0]>r[1]?`isValid(${i}) && reverse(${i})`:i}}function rF(e){return e.map(t=>(t.on&&!t.on.length&&delete t.on,t))}const sl={defined:e=>e.type==="interval"&&e.resolve==="global"&&e.bind&&e.bind==="scales",parse:(e,t)=>{const n=t.scales=[];for(const r of t.project.items){const i=r.channel;if(!$a(i))continue;const s=e.getScaleComponent(i),o=s?s.get("type"):void 0;if(o=="sequential"&&Ce(G0e),!s||!bo(o)){Ce(H0e);continue}s.set("selectionExtent",{param:t.name,field:r.field},!0),n.push(r)}},topLevelSignals:(e,t,n)=>{const r=t.scales.filter(o=>n.filter(a=>a.name===o.signals.data).length===0);if(!e.parent||mA(e)||r.length===0)return n;const i=n.find(o=>o.name===t.name);let s=i.update;if(s.includes(bU))i.update=`{${r.map(o=>`${De(Bs(o.field))}: ${o.signals.data}`).join(", ")}}`;else{for(const o of r){const a=`${De(Bs(o.field))}: ${o.signals.data}`;s.includes(a)||(s=`${s.substring(0,s.length-1)}, ${a}}`)}i.update=s}return n.concat(r.map(o=>({name:o.signals.data})))},signals:(e,t,n)=>{if(e.parent&&!mA(e))for(const r of t.scales){const i=n.find(s=>s.name===r.signals.data);i.push="outer",delete i.value,delete i.update}return n}};function gA(e,t){return`domain(${De(e.scaleName(t))})`}function mA(e){return e.parent&&Bh(e.parent)&&(!e.parent.parent||mA(e.parent.parent))}const hd="_brush",iU="_scale_trigger",fp="geo_interval_init_tick",sU="_init",dbe="_center",hbe={defined:e=>e.type==="interval",parse:(e,t,n)=>{var r;if(e.hasProjection){const i={...Pe(n.select)?n.select:{}};i.fields=[wo],i.encodings||(i.encodings=n.value?Ae(n.value):[Fo,$o]),n.select={type:"interval",...i}}if(t.translate&&!sl.defined(t)){const i=`!event.item || event.item.mark.name !== ${De(t.name+hd)}`;for(const s of t.events){if(!s.between){Ce(`${s} is not an ordered event stream for interval selections.`);continue}const o=je((r=s.between[0]).filter??(r.filter=[]));o.includes(i)||o.push(i)}}},signals:(e,t,n)=>{const r=t.name,i=r+pl,s=Mr(t.project.hasChannel).filter(a=>a.channel===wn||a.channel===mr),o=t.init?t.init[0]:null;if(n.push(...s.reduce((a,l)=>a.concat(pbe(e,t,l,o&&o[l.index])),[])),e.hasProjection){const a=De(e.projectionName()),l=e.projectionName()+dbe,{x:u,y:c}=t.project.hasChannel,f=u&&u.signals.visual,d=c&&c.signals.visual,h=u?o&&o[u.index]:`${l}[0]`,p=c?o&&o[c.index]:`${l}[1]`,g=w=>e.getSizeSignalRef(w).signal,m=`[[${f?f+"[0]":"0"}, ${d?d+"[0]":"0"}],[${f?f+"[1]":g("width")}, ${d?d+"[1]":g("height")}]]`;o&&(n.unshift({name:r+sU,init:`[scale(${a}, [${u?h[0]:h}, ${c?p[0]:p}]), scale(${a}, [${u?h[1]:h}, ${c?p[1]:p}])]`}),(!u||!c)&&(n.find(A=>A.name===l)||n.unshift({name:l,update:`invert(${a}, [${g("width")}/2, ${g("height")}/2])`})));const v=`intersect(${m}, {markname: ${De(e.getName("marks"))}}, unit.mark)`,b=`{unit: ${Fc(e)}}`,x=`vlSelectionTuples(${v}, ${b})`,_=s.map(w=>w.signals.visual);return n.concat({name:i,on:[{events:[..._.length?[{signal:_.join(" || ")}]:[],...o?[{signal:fp}]:[]],update:x}]})}else{if(!sl.defined(t)){const u=r+iU,c=s.map(f=>{const d=f.channel,{data:h,visual:p}=f.signals,g=De(e.scaleName(d)),m=e.getScaleComponent(d).get("type"),v=bo(m)?"+":"";return`(!isArray(${h}) || (${v}invert(${g}, ${p})[0] === ${v}${h}[0] && ${v}invert(${g}, ${p})[1] === ${v}${h}[1]))`});c.length&&n.push({name:u,value:{},on:[{events:s.map(f=>({scale:e.scaleName(f.channel)})),update:c.join(" && ")+` ? ${u} : {}`}]})}const a=s.map(u=>u.signals.data),l=`unit: ${Fc(e)}, fields: ${r+G0}, values`;return n.concat({name:i,...o?{init:`{${l}: ${of(o)}}`}:{},...a.length?{on:[{events:[{signal:a.join(" || ")}],update:`${a.join(" && ")} ? {${l}: [${a}]} : null`}]}:{}})}},topLevelSignals:(e,t,n)=>(Cn(e)&&e.hasProjection&&t.init&&(n.filter(i=>i.name===fp).length||n.unshift({name:fp,value:null,on:[{events:"timer{1}",update:`${fp} === null ? {} : ${fp}`}]})),n),marks:(e,t,n)=>{const r=t.name,{x:i,y:s}=t.project.hasChannel,o=i==null?void 0:i.signals.visual,a=s==null?void 0:s.signals.visual,l=`data(${De(t.name+af)})`;if(sl.defined(t)||!i&&!s)return n;const u={x:i!==void 0?{signal:`${o}[0]`}:{value:0},y:s!==void 0?{signal:`${a}[0]`}:{value:0},x2:i!==void 0?{signal:`${o}[1]`}:{field:{group:"width"}},y2:s!==void 0?{signal:`${a}[1]`}:{field:{group:"height"}}};if(t.resolve==="global")for(const m of Ae(u))u[m]=[{test:`${l}.length && ${l}[0].unit === ${Fc(e)}`,...u[m]},{value:0}];const{fill:c,fillOpacity:f,cursor:d,...h}=t.mark,p=Ae(h).reduce((m,v)=>(m[v]=[{test:[i!==void 0&&`${o}[0] !== ${o}[1]`,s!==void 0&&`${a}[0] !== ${a}[1]`].filter(b=>b).join(" && "),value:h[v]},{value:null}],m),{}),g=d??(t.translate?"move":null);return[{name:`${r+hd}_bg`,type:"rect",clip:!0,encode:{enter:{fill:{value:c},fillOpacity:{value:f}},update:u}},...n,{name:r+hd,type:"rect",clip:!0,encode:{enter:{...g?{cursor:{value:g}}:{},fill:{value:"transparent"}},update:{...u,...p}}}]}};function pbe(e,t,n,r){const i=!e.hasProjection,s=n.channel,o=n.signals.visual,a=De(i?e.scaleName(s):e.projectionName()),l=d=>`scale(${a}, ${d})`,u=e.getSizeSignalRef(s===wn?"width":"height").signal,c=`${s}(unit)`,f=t.events.reduce((d,h)=>[...d,{events:h.between[0],update:`[${c}, ${c}]`},{events:h,update:`[${o}[0], clamp(${c}, 0, ${u})]`}],[]);if(i){const d=n.signals.data,h=sl.defined(t),p=e.getScaleComponent(s),g=p?p.get("type"):void 0,m=r?{init:of(r,!0,l)}:{value:[]};return f.push({events:{signal:t.name+iU},update:bo(g)?`[${l(`${d}[0]`)}, ${l(`${d}[1]`)}]`:"[0, 0]"}),h?[{name:d,on:[]}]:[{name:o,...m,on:f},{name:d,...r?{init:of(r)}:{},on:[{events:{signal:o},update:`${o}[0] === ${o}[1] ? null : invert(${a}, ${o})`}]}]}else{const d=s===wn?0:1,h=t.name+sU,p=r?{init:`[${h}[0][${d}], ${h}[1][${d}]]`}:{value:[]};return[{name:o,...p,on:f}]}}function Oh({model:e,channelDef:t,vgChannel:n,invalidValueRef:r,mainRefFn:i}){const s=U0(t)&&t.condition;let o=[];s&&(o=je(s).map(u=>{const c=i(u);if(tve(u)){const{param:f,empty:d}=u;return{test:FU(e,{param:f,empty:d}),...c}}else return{test:gy(e,u.test),...c}})),r!==void 0&&o.push(r);const a=i(t);return a!==void 0&&o.push(a),o.length>1||o.length===1&&o[0].test?{[n]:o}:o.length===1?{[n]:o[0]}:{}}function iF(e,t="text"){const n=e.encoding[t];return Oh({model:e,channelDef:n,vgChannel:t,mainRefFn:r=>m2(r,e.config),invalidValueRef:void 0})}function m2(e,t,n="datum"){if(e){if(xo(e))return vn(e.value);if(vt(e)){const{format:r,formatType:i}=ly(e);return P$({fieldOrDatumDef:e,format:r,formatType:i,expr:n,config:t})}}}function oU(e,t={}){const{encoding:n,markDef:r,config:i,stack:s}=e,o=n.tooltip;if(fe(o))return{tooltip:U6({tooltip:o},s,i,t)};{const a=t.reactiveGeom?"datum.datum":"datum";return Oh({model:e,channelDef:o,vgChannel:"tooltip",mainRefFn:u=>{const c=m2(u,i,a);if(c)return c;if(u===null)return;let f=on("tooltip",r,i);if(f===!0&&(f={content:"encoding"}),ze(f))return{value:f};if(Pe(f))return tt(f)?f:f.content==="encoding"?U6(n,s,i,t):{signal:a}},invalidValueRef:void 0})}}function aU(e,t,n,{reactiveGeom:r}={}){const i={...n,...n.tooltipFormat},s=new Set,o=r?"datum.datum":"datum",a=[];function l(c,f){const d=_f(f),h=xi(c)?c:{...c,type:e[d].type},p=h.title||U$(h,i),g=je(p).join(", ").replaceAll(/"/g,'\\"');let m;if(Un(f)){const v=f==="x"?"x2":"y2",b=_o(e[v]);if(wr(h.bin)&&b){const x=Ne(h,{expr:o}),_=Ne(b,{expr:o}),{format:w,formatType:A}=ly(h);m=z0(x,_,w,A,i),s.add(v)}}if((Un(f)||f===qs||f===Co)&&t&&t.fieldChannel===f&&t.offset==="normalize"){const{format:v,formatType:b}=ly(h);m=P$({fieldOrDatumDef:h,format:v,formatType:b,expr:o,config:i,normalizeStack:!0}).signal}m??(m=m2(h,i,o).signal),a.push({channel:f,key:g,value:m})}W$(e,(c,f)=>{$e(c)?l(c,f):o2(c)&&l(c.condition,f)});const u={};for(const{channel:c,key:f,value:d}of a)!s.has(c)&&!u[f]&&(u[f]=d);return u}function U6(e,t,n,{reactiveGeom:r}={}){const i=aU(e,t,n,{reactiveGeom:r}),s=pu(i).map(([o,a])=>`"${o}": ${a}`);return s.length>0?{signal:`{${s.join(", ")}}`}:void 0}function gbe(e){const{markDef:t,config:n}=e,r=on("aria",t,n);return r===!1?{}:{...r?{aria:r}:{},...mbe(e),...vbe(e)}}function mbe(e){const{mark:t,markDef:n,config:r}=e;if(r.aria===!1)return{};const i=on("ariaRoleDescription",n,r);return i!=null?{ariaRoleDescription:{value:i}}:We(P0e,t)?{}:{ariaRoleDescription:{value:t}}}function vbe(e){const{encoding:t,markDef:n,config:r,stack:i}=e,s=t.description;if(s)return Oh({model:e,channelDef:s,vgChannel:"description",mainRefFn:l=>m2(l,e.config),invalidValueRef:void 0});const o=on("description",n,r);if(o!=null)return{description:vn(o)};if(r.aria===!1)return{};const a=aU(t,i,r);if(!an(a))return{description:{signal:pu(a).map(([l,u],c)=>`"${c>0?"; ":""}${l}: " + (${u})`).join(" + ")}}}function Sr(e,t,n={}){const{markDef:r,encoding:i,config:s}=t,{vgChannel:o}=n;let{defaultRef:a,defaultValue:l}=n;const u=i[e];a===void 0&&(l??(l=on(e,r,s,{vgChannel:o,ignoreVgConfig:!U0(u)})),l!==void 0&&(a=vn(l)));const c={markDef:r,config:s,scaleName:t.scaleName(e),scale:t.getScaleComponent(e)},f=Vz({...c,scaleChannel:e,channelDef:u});return Oh({model:t,channelDef:u,vgChannel:o??e,invalidValueRef:f,mainRefFn:h=>I$({...c,channel:e,channelDef:h,stack:null,defaultRef:a})})}function lU(e,t={filled:void 0}){const{markDef:n,encoding:r,config:i}=e,{type:s}=n,o=t.filled??on("filled",n,i),a=Tt(["bar","point","circle","square","geoshape"],s)?"transparent":void 0,l=on(o===!0?"color":void 0,n,i,{vgChannel:"fill"})??i.mark[o===!0&&"color"]??a,u=on(o===!1?"color":void 0,n,i,{vgChannel:"stroke"})??i.mark[o===!1&&"color"],c=o?"fill":"stroke",f={...l?{fill:vn(l)}:{},...u?{stroke:vn(u)}:{}};return n.color&&(o?n.fill:n.stroke)&&Ce(bz("property",{fill:"fill"in n,stroke:"stroke"in n})),{...f,...Sr("color",e,{vgChannel:c,defaultValue:o?l:u}),...Sr("fill",e,{defaultValue:r.fill?l:void 0}),...Sr("stroke",e,{defaultValue:r.stroke?u:void 0})}}function ybe(e){const{encoding:t,mark:n}=e,r=t.order;return!Iu(n)&&xo(r)?Oh({model:e,channelDef:r,vgChannel:"zindex",mainRefFn:i=>vn(i.value),invalidValueRef:void 0}):{}}function oh({channel:e,markDef:t,encoding:n={},model:r,bandPosition:i}){const s=`${e}Offset`,o=t[s],a=n[s];if((s==="xOffset"||s==="yOffset")&&a)return{offsetType:"encoding",offset:I$({channel:s,channelDef:a,markDef:t,config:r==null?void 0:r.config,scaleName:r.scaleName(s),scale:r.getScaleComponent(s),stack:null,defaultRef:vn(o),bandPosition:i})};const l=t[s];return l?{offsetType:"visual",offset:l}:{}}function gi(e,t,{defaultPos:n,vgChannel:r}){const{encoding:i,markDef:s,config:o,stack:a}=t,l=i[e],u=i[Ca(e)],c=t.scaleName(e),f=t.getScaleComponent(e),{offset:d,offsetType:h}=oh({channel:e,markDef:s,encoding:i,model:t,bandPosition:.5}),p=sF({model:t,defaultPos:n,channel:e,scaleName:c,scale:f}),g=!l&&Un(e)&&(i.latitude||i.longitude)?{field:t.getName(e)}:bbe({channel:e,channelDef:l,channel2Def:u,markDef:s,config:o,scaleName:c,scale:f,stack:a,offset:d,defaultRef:p,bandPosition:h==="encoding"?0:void 0});return g?{[r||e]:g}:void 0}function bbe(e){const{channel:t,channelDef:n,scaleName:r,stack:i,offset:s,markDef:o}=e;if(vt(n)&&i&&t===i.fieldChannel){if($e(n)){let a=n.bandPosition;if(a===void 0&&o.type==="text"&&(t==="radius"||t==="theta")&&(a=.5),a!==void 0)return sy({scaleName:r,fieldOrDatumDef:n,startSuffix:"start",bandPosition:a,offset:s})}return Cc(n,r,{suffix:"end"},{offset:s})}return L$(e)}function sF({model:e,defaultPos:t,channel:n,scaleName:r,scale:i}){const{markDef:s,config:o}=e;return()=>{const a=_f(n),l=gu(n),u=on(n,s,o,{vgChannel:l});if(u!==void 0)return sg(n,u);switch(t){case"zeroOrMin":return q6({scaleName:r,scale:i,mode:"zeroOrMin",mainChannel:a,config:o});case"zeroOrMax":return q6({scaleName:r,scale:i,mode:{zeroOrMax:{widthSignal:e.width.signal,heightSignal:e.height.signal}},mainChannel:a,config:o});case"mid":return{...e[Hi(n)],mult:.5}}}}function q6({mainChannel:e,config:t,...n}){const r=Yz(n),{mode:i}=n;if(r)return r;switch(e){case"radius":{if(i==="zeroOrMin")return{value:0};const{widthSignal:s,heightSignal:o}=i.zeroOrMax;return{signal:`min(${s},${o})/2`}}case"theta":return i==="zeroOrMin"?{value:0}:{signal:"2*PI"};case"x":return i==="zeroOrMin"?{value:0}:{field:{group:"width"}};case"y":return i==="zeroOrMin"?{field:{group:"height"}}:{value:0}}}const xbe={left:"x",center:"xc",right:"x2"},_be={top:"y",middle:"yc",bottom:"y2"};function uU(e,t,n,r="middle"){if(e==="radius"||e==="theta")return gu(e);const i=e==="x"?"align":"baseline",s=on(i,t,n);let o;return tt(s)?(Ce(bme(i)),o=void 0):o=s,e==="x"?xbe[o||(r==="top"?"left":"center")]:_be[o||r]}function dy(e,t,{defaultPos:n,defaultPos2:r,range:i}){return i?cU(e,t,{defaultPos:n,defaultPos2:r}):gi(e,t,{defaultPos:n})}function cU(e,t,{defaultPos:n,defaultPos2:r}){const{markDef:i,config:s}=t,o=Ca(e),a=Hi(e),l=wbe(t,r,o),u=l[a]?uU(e,i,s):gu(e);return{...gi(e,t,{defaultPos:n,vgChannel:u}),...l}}function wbe(e,t,n){const{encoding:r,mark:i,markDef:s,stack:o,config:a}=e,l=_f(n),u=Hi(n),c=gu(n),f=r[l],d=e.scaleName(l),h=e.getScaleComponent(l),{offset:p}=n in r||n in s?oh({channel:n,markDef:s,encoding:r,model:e}):oh({channel:l,markDef:s,encoding:r,model:e});if(!f&&(n==="x2"||n==="y2")&&(r.latitude||r.longitude)){const m=Hi(n),v=e.markDef[m];return v!=null?{[m]:{value:v}}:{[c]:{field:e.getName(n)}}}const g=Ebe({channel:n,channelDef:f,channel2Def:r[n],markDef:s,config:a,scaleName:d,scale:h,stack:o,offset:p,defaultRef:void 0});return g!==void 0?{[c]:g}:Nm(n,s)||Nm(n,{[n]:rA(n,s,a.style),[u]:rA(u,s,a.style)})||Nm(n,a[i])||Nm(n,a.mark)||{[c]:sF({model:e,defaultPos:t,channel:n,scaleName:d,scale:h})()}}function Ebe({channel:e,channelDef:t,channel2Def:n,markDef:r,config:i,scaleName:s,scale:o,stack:a,offset:l,defaultRef:u}){return vt(t)&&a&&e.charAt(0)===a.fieldChannel.charAt(0)?Cc(t,s,{suffix:"start"},{offset:l}):L$({channel:e,channelDef:n,scaleName:s,scale:o,stack:a,markDef:r,config:i,offset:l,defaultRef:u})}function Nm(e,t){const n=Hi(e),r=gu(e);if(t[r]!==void 0)return{[r]:sg(e,t[r])};if(t[e]!==void 0)return{[r]:sg(e,t[e])};if(t[n]){const i=t[n];if(rf(i))Ce(hme(n));else return{[n]:sg(e,i)}}}function hl(e,t){const{config:n,encoding:r,markDef:i}=e,s=i.type,o=Ca(t),a=Hi(t),l=r[t],u=r[o],c=e.getScaleComponent(t),f=c?c.get("type"):void 0,d=i.orient,h=r[a]??r.size??on("size",i,n,{vgChannel:a}),p=rz(t),g=s==="bar"&&(t==="x"?d==="vertical":d==="horizontal")||s==="tick"&&(t==="y"?d==="vertical":d==="horizontal");return $e(l)&&(dn(l.bin)||wr(l.bin)||l.timeUnit&&!u)&&!(h&&!rf(h))&&!r[p]&&!pr(f)?Sbe({fieldDef:l,fieldDef2:u,channel:t,model:e}):(vt(l)&&pr(f)||g)&&!u?kbe(l,t,e):cU(t,e,{defaultPos:"zeroOrMax",defaultPos2:"zeroOrMin"})}function Abe(e,t,n,r,i,s,o){if(rf(i))if(n){const l=n.get("type");if(l==="band"){let u=`bandwidth('${t}')`;i.band!==1&&(u=`${i.band} * ${u}`);const c=ha("minBandSize",{type:o},r);return{signal:c?`max(${uo(c)}, ${u})`:u}}else i.band!==1&&(Ce(Eme(l)),i=void 0)}else return{mult:i.band,field:{group:e}};else{if(tt(i))return i;if(i)return{value:i}}if(n){const l=n.get("range");if(Ef(l)&&Gt(l.step))return{value:l.step-2}}if(!s){const{bandPaddingInner:l,barBandPaddingInner:u,rectBandPaddingInner:c,tickBandPaddingInner:f}=r.scale,d=jn(l,o==="tick"?f:o==="bar"?u:c);if(tt(d))return{signal:`(1 - (${d.signal})) * ${e}`};if(Gt(d))return{signal:`${1-d} * ${e}`}}return{value:cA(r.view,e)-2}}function kbe(e,t,n){var S,$;const{markDef:r,encoding:i,config:s,stack:o}=n,a=r.orient,l=n.scaleName(t),u=n.getScaleComponent(t),c=Hi(t),f=Ca(t),d=rz(t),h=n.scaleName(d),p=n.getScaleComponent(u$(t)),g=r.type==="tick"||a==="horizontal"&&t==="y"||a==="vertical"&&t==="x";let m;(i.size||r.size)&&(g?m=Sr("size",n,{vgChannel:c,defaultRef:vn(r.size)}):Ce(Cme(r.type)));const v=!!m,b=tj({channel:t,fieldDef:e,markDef:r,config:s,scaleType:(S=u||p)==null?void 0:S.get("type"),useVlSizeChannel:g});m=m||{[c]:Abe(c,h||l,p||u,s,b,!!e,r.type)};const x=(($=u||p)==null?void 0:$.get("type"))==="band"&&rf(b)&&!v?"top":"middle",_=uU(t,r,s,x),w=_==="xc"||_==="yc",{offset:A,offsetType:E}=oh({channel:t,markDef:r,encoding:i,model:n,bandPosition:w?.5:0}),k=L$({channel:t,channelDef:e,markDef:r,config:s,scaleName:l,scale:u,stack:o,offset:A,defaultRef:sF({model:n,defaultPos:"mid",channel:t,scaleName:l,scale:u}),bandPosition:w?E==="encoding"?0:.5:tt(b)?{signal:`(1-${b})/2`}:rf(b)?(1-b.band)/2:0});if(c)return{[_]:k,...m};{const M=gu(f),O=m[c],P=A?{...O,offset:A}:O;return{[_]:k,[M]:fe(k)?[k[0],{...k[1],offset:P}]:{...k,offset:P}}}}function W6(e,t,n,r,i,s,o){if(ZB(e))return 0;const a=e==="x"||e==="y2",l=a?-t/2:t/2;if(tt(n)||tt(i)||tt(r)||s){const u=uo(n),c=uo(i),f=uo(r),d=uo(s),p=s?`(${o} < ${d} ? ${a?"":"-"}0.5 * (${d} - (${o})) : ${l})`:l,g=f?`${f} + `:"",m=u?`(${u} ? -1 : 1) * `:"",v=c?`(${c} + ${p})`:p;return{signal:g+m+v}}else return i=i||0,r+(n?-i-l:+i+l)}function Sbe({fieldDef:e,fieldDef2:t,channel:n,model:r}){var $;const{config:i,markDef:s,encoding:o}=r,a=r.getScaleComponent(n),l=r.scaleName(n),u=a?a.get("type"):void 0,c=a.get("reverse"),f=tj({channel:n,fieldDef:e,markDef:s,config:i,scaleType:u}),d=($=r.component.axes[n])==null?void 0:$[0],h=(d==null?void 0:d.get("translate"))??.5,p=Un(n)?on("binSpacing",s,i)??0:0,g=Ca(n),m=gu(n),v=gu(g),b=ha("minBandSize",s,i),{offset:x}=oh({channel:n,markDef:s,encoding:o,model:r,bandPosition:0}),{offset:_}=oh({channel:g,markDef:s,encoding:o,model:r,bandPosition:0}),w=X1e({fieldDef:e,scaleName:l}),A=W6(n,p,c,h,x,b,w),E=W6(g,p,c,h,_??x,b,w),k=tt(f)?{signal:`(1-${f.signal})/2`}:rf(f)?(1-f.band)/2:.5,S=mu({fieldDef:e,fieldDef2:t,markDef:s,config:i});if(dn(e.bin)||e.timeUnit){const M=e.timeUnit&&S!==.5;return{[v]:H6({fieldDef:e,scaleName:l,bandPosition:k,offset:E,useRectOffsetField:M}),[m]:H6({fieldDef:e,scaleName:l,bandPosition:tt(k)?{signal:`1-${k.signal}`}:1-k,offset:A,useRectOffsetField:M})}}else if(wr(e.bin)){const M=Cc(e,l,{},{offset:E});if($e(t))return{[v]:M,[m]:Cc(t,l,{},{offset:A})};if(wf(e.bin)&&e.bin.step)return{[v]:M,[m]:{signal:`scale("${l}", ${Ne(e,{expr:"datum"})} + ${e.bin.step})`,offset:A}}}Ce(wz(g))}function H6({fieldDef:e,scaleName:t,bandPosition:n,offset:r,useRectOffsetField:i}){return sy({scaleName:t,fieldOrDatumDef:e,bandPosition:n,offset:r,...i?{startSuffix:p2,endSuffix:g2}:{}})}const Cbe=new Set(["aria","width","height"]);function Ws(e,t){const{fill:n=void 0,stroke:r=void 0}=t.color==="include"?lU(e):{};return{...$be(e.markDef,t),...G6("fill",n),...G6("stroke",r),...Sr("opacity",e),...Sr("fillOpacity",e),...Sr("strokeOpacity",e),...Sr("strokeWidth",e),...Sr("strokeDash",e),...ybe(e),...oU(e),...iF(e,"href"),...gbe(e)}}function G6(e,t){return t?{[e]:t}:{}}function $be(e,t){return I0e.reduce((n,r)=>(!Cbe.has(r)&&Se(e,r)&&t[r]!=="ignore"&&(n[r]=vn(e[r])),n),{})}function oF(e){const{config:t,markDef:n}=e,r=new Set;if(e.forEachFieldDef((i,s)=>{var u;let o;if(!$a(s)||!(o=e.getScaleType(s)))return;const a=Xb(i.aggregate),l=O$({scaleChannel:s,markDef:n,config:t,scaleType:o,isCountAggregate:a});if(G1e(l)){const c=e.vgField(s,{expr:"datum",binSuffix:(u=e.stack)!=null&&u.impute?"mid":void 0});c&&r.add(c)}}),r.size>0)return{defined:{signal:[...r].map(s=>Qb(s,!0)).join(" && ")}}}function Y6(e,t){if(t!==void 0)return{[e]:vn(t)}}const y_="voronoi",fU={defined:e=>e.type==="point"&&e.nearest,parse:(e,t)=>{if(t.events)for(const n of t.events)n.markname=e.getName(y_)},marks:(e,t,n)=>{const{x:r,y:i}=t.project.hasChannel,s=e.mark;if(Iu(s))return Ce(q0e(s)),n;const o={name:e.getName(y_),type:"path",interactive:!0,from:{data:e.getName("marks")},encode:{update:{fill:{value:"transparent"},strokeWidth:{value:.35},stroke:{value:"transparent"},isVoronoi:{value:!0},...oU(e,{reactiveGeom:!0})}},transform:[{type:"voronoi",x:{expr:r||!i?"datum.datum.x || 0":"0"},y:{expr:i||!r?"datum.datum.y || 0":"0"},size:[e.getSizeSignalRef("width"),e.getSizeSignalRef("height")]}]};let a=0,l=!1;return n.forEach((u,c)=>{const f=u.name??"";f===e.component.mark[0].name?a=c:f.includes(y_)&&(l=!0)}),l||n.splice(a+1,0,o),n}},dU={defined:e=>e.type==="point"&&e.resolve==="global"&&e.bind&&e.bind!=="scales"&&!K$(e.bind),parse:(e,t,n)=>xU(t,n),topLevelSignals:(e,t,n)=>{const r=t.name,i=t.project,s=t.bind,o=t.init&&t.init[0],a=fU.defined(t)?"(item().isVoronoi ? datum.datum : datum)":"datum";return i.items.forEach((l,u)=>{const c=_n(`${r}_${l.field}`);n.filter(d=>d.name===c).length||n.unshift({name:c,...o?{init:of(o[u])}:{value:null},on:t.events?[{events:t.events,update:`datum && item().mark.marktype !== 'group' ? ${a}[${De(l.field)}] : null`}]:[],bind:s[l.field]??s[l.channel]??s})}),n},signals:(e,t,n)=>{const r=t.name,i=t.project,s=n.find(u=>u.name===r+pl),o=r+G0,a=i.items.map(u=>_n(`${r}_${u.field}`)),l=a.map(u=>`${u} !== null`).join(" && ");return a.length&&(s.update=`${l} ? {fields: ${o}, values: [${a.join(", ")}]} : null`),delete s.value,delete s.on,n}},hy="_toggle",hU={defined:e=>e.type==="point"&&!ia(e)&&!!e.toggle,signals:(e,t,n)=>n.concat({name:t.name+hy,value:!1,on:[{events:t.events,update:t.toggle}]}),modifyExpr:(e,t)=>{const n=t.name+pl,r=t.name+hy;return`${r} ? null : ${n}, `+(t.resolve==="global"?`${r} ? null : true, `:`${r} ? null : {unit: ${Fc(e)}}, `)+`${r} ? ${n} : null`}},Fbe={defined:e=>e.clear!==void 0&&e.clear!==!1&&!ia(e),parse:(e,t)=>{t.clear&&(t.clear=ze(t.clear)?Fu(t.clear,"view"):t.clear)},topLevelSignals:(e,t,n)=>{if(dU.defined(t))for(const r of t.project.items){const i=n.findIndex(s=>s.name===_n(`${t.name}_${r.field}`));i!==-1&&n[i].on.push({events:t.clear,update:"null"})}return n},signals:(e,t,n)=>{function r(i,s){i!==-1&&n[i].on&&n[i].on.push({events:t.clear,update:s})}if(t.type==="interval")for(const i of t.project.items){const s=n.findIndex(o=>o.name===i.signals.visual);if(r(s,"[0, 0]"),s===-1){const o=n.findIndex(a=>a.name===i.signals.data);r(o,"null")}}else{let i=n.findIndex(s=>s.name===t.name+pl);r(i,"null"),hU.defined(t)&&(i=n.findIndex(s=>s.name===t.name+hy),r(i,"false"))}return n}},pU={defined:e=>{const t=e.resolve==="global"&&e.bind&&K$(e.bind),n=e.project.items.length===1&&e.project.items[0].field!==wo;return t&&!n&&Ce(Y0e),t&&n},parse:(e,t,n)=>{const r=gt(n);if(r.select=ze(r.select)?{type:r.select,toggle:t.toggle}:{...r.select,toggle:t.toggle},xU(t,r),Pe(n.select)&&(n.select.on||n.select.clear)){const o='event.item && indexof(event.item.mark.role, "legend") < 0';for(const a of t.events)a.filter=je(a.filter??[]),a.filter.includes(o)||a.filter.push(o)}const i=d_(t.bind)?t.bind.legend:"click",s=ze(i)?Fu(i,"view"):je(i);t.bind={legend:{merge:s}}},topLevelSignals:(e,t,n)=>{const r=t.name,i=d_(t.bind)&&t.bind.legend,s=o=>a=>{const l=gt(a);return l.markname=o,l};for(const o of t.project.items){if(!o.hasLegend)continue;const a=`${_n(o.field)}_legend`,l=`${r}_${a}`;if(n.filter(c=>c.name===l).length===0){const c=i.merge.map(s(`${a}_symbols`)).concat(i.merge.map(s(`${a}_labels`))).concat(i.merge.map(s(`${a}_entries`)));n.unshift({name:l,...t.init?{}:{value:null},on:[{events:c,update:"isDefined(datum.value) ? datum.value : item().items[0].items[0].datum.value",force:!0},{events:i.merge,update:`!event.item || !datum ? null : ${l}`,force:!0}]})}}return n},signals:(e,t,n)=>{const r=t.name,i=t.project,s=n.find(d=>d.name===r+pl),o=r+G0,a=i.items.filter(d=>d.hasLegend).map(d=>_n(`${r}_${_n(d.field)}_legend`)),u=`${a.map(d=>`${d} !== null`).join(" && ")} ? {fields: ${o}, values: [${a.join(", ")}]} : null`;t.events&&a.length>0?s.on.push({events:a.map(d=>({signal:d})),update:u}):a.length>0&&(s.update=u,delete s.value,delete s.on);const c=n.find(d=>d.name===r+hy),f=d_(t.bind)&&t.bind.legend;return c&&(t.events?c.on.push({...c.on[0],events:f}):c.on[0].events=f),n}};function Dbe(e,t,n){var i;const r=(i=e.fieldDef(t))==null?void 0:i.field;for(const s of Mr(e.component.selection??{})){const o=s.project.hasField[r]??s.project.hasChannel[t];if(o&&pU.defined(s)){const a=n.get("selections")??[];a.push(s.name),n.set("selections",a,!1),o.hasLegend=!0}}}const gU="_translate_anchor",mU="_translate_delta",Mbe={defined:e=>e.type==="interval"&&e.translate,signals:(e,t,n)=>{const r=t.name,i=sl.defined(t),s=r+gU,{x:o,y:a}=t.project.hasChannel;let l=Fu(t.translate,"scope");return i||(l=l.map(u=>(u.between[0].markname=r+hd,u))),n.push({name:s,value:{},on:[{events:l.map(u=>u.between[0]),update:"{x: x(unit), y: y(unit)"+(o!==void 0?`, extent_x: ${i?gA(e,wn):`slice(${o.signals.visual})`}`:"")+(a!==void 0?`, extent_y: ${i?gA(e,mr):`slice(${a.signals.visual})`}`:"")+"}"}]},{name:r+mU,value:{},on:[{events:l,update:`{x: ${s}.x - x(unit), y: ${s}.y - y(unit)}`}]}),o!==void 0&&V6(e,t,o,"width",n),a!==void 0&&V6(e,t,a,"height",n),n}};function V6(e,t,n,r,i){const s=t.name,o=s+gU,a=s+mU,l=n.channel,u=sl.defined(t),c=i.find(w=>w.name===n.signals[u?"data":"visual"]),f=e.getSizeSignalRef(r).signal,d=e.getScaleComponent(l),h=d&&d.get("type"),p=d&&d.get("reverse"),g=u?l===wn?p?"":"-":p?"-":"":"",m=`${o}.extent_${l}`,v=`${g}${a}.${l} / ${u?`${f}`:`span(${m})`}`,b=!u||!d?"panLinear":h==="log"?"panLog":h==="symlog"?"panSymlog":h==="pow"?"panPow":"panLinear",x=u?h==="pow"?`, ${d.get("exponent")??1}`:h==="symlog"?`, ${d.get("constant")??1}`:"":"",_=`${b}(${m}, ${v}${x})`;c.on.push({events:{signal:a},update:u?_:`clampRange(${_}, 0, ${f})`})}const vU="_zoom_anchor",yU="_zoom_delta",Tbe={defined:e=>e.type==="interval"&&e.zoom,signals:(e,t,n)=>{const r=t.name,i=sl.defined(t),s=r+yU,{x:o,y:a}=t.project.hasChannel,l=De(e.scaleName(wn)),u=De(e.scaleName(mr));let c=Fu(t.zoom,"scope");return i||(c=c.map(f=>(f.markname=r+hd,f))),n.push({name:r+vU,on:[{events:c,update:i?"{"+[l?`x: invert(${l}, x(unit))`:"",u?`y: invert(${u}, y(unit))`:""].filter(f=>f).join(", ")+"}":"{x: x(unit), y: y(unit)}"}]},{name:s,on:[{events:c,force:!0,update:"pow(1.001, event.deltaY * pow(16, event.deltaMode))"}]}),o!==void 0&&X6(e,t,o,"width",n),a!==void 0&&X6(e,t,a,"height",n),n}};function X6(e,t,n,r,i){const s=t.name,o=n.channel,a=sl.defined(t),l=i.find(b=>b.name===n.signals[a?"data":"visual"]),u=e.getSizeSignalRef(r).signal,c=e.getScaleComponent(o),f=c&&c.get("type"),d=a?gA(e,o):l.name,h=s+yU,p=`${s}${vU}.${o}`,g=!a||!c?"zoomLinear":f==="log"?"zoomLog":f==="symlog"?"zoomSymlog":f==="pow"?"zoomPow":"zoomLinear",m=a?f==="pow"?`, ${c.get("exponent")??1}`:f==="symlog"?`, ${c.get("constant")??1}`:"":"",v=`${g}(${d}, ${p}, ${h}${m})`;l.on.push({events:{signal:h},update:a?v:`clampRange(${v}, 0, ${u})`})}const af="_store",pl="_tuple",Rbe="_modify",bU="vlSelectionResolve",v2=[sbe,hbe,nbe,hU,dU,sl,pU,Fbe,Mbe,Tbe,fU];function Nbe(e){let t=e.parent;for(;t&&!cs(t);)t=t.parent;return t}function Fc(e,{escape:t}={escape:!0}){let n=t?De(e.name):e.name;const r=Nbe(e);if(r){const{facet:i}=r;for(const s of $s)i[s]&&(n+=` + '__facet_${s}_' + (facet[${De(r.vgField(s))}])`)}return n}function aF(e){return Mr(e.component.selection??{}).reduce((t,n)=>t||n.project.hasSelectionId,!1)}function xU(e,t){(ze(t.select)||!t.select.on)&&delete e.events,(ze(t.select)||!t.select.clear)&&delete e.clear,(ze(t.select)||!t.select.toggle)&&delete e.toggle}function ia(e){var t;return(t=e.events)==null?void 0:t.find(n=>"type"in n&&n.type==="timer")}const Obe="RawCode",Lbe="Literal",Ibe="Property",Pbe="Identifier",Bbe="ArrayExpression",zbe="BinaryExpression",jbe="CallExpression",Ube="ConditionalExpression",qbe="LogicalExpression",Wbe="MemberExpression",Hbe="ObjectExpression",Gbe="UnaryExpression";function Mo(e){this.type=e}Mo.prototype.visit=function(e){let t,n,r;if(e(this))return 1;for(t=Ybe(this),n=0,r=t.length;n";Da[lf]="Identifier";Da[Pu]="Keyword";Da[b2]="Null";Da[Cf]="Numeric";Da[Mi]="Punctuator";Da[V0]="String";Da[Vbe]="RegularExpression";var Xbe="ArrayExpression",Kbe="BinaryExpression",Zbe="CallExpression",Jbe="ConditionalExpression",_U="Identifier",Qbe="Literal",e2e="LogicalExpression",t2e="MemberExpression",n2e="ObjectExpression",r2e="Property",i2e="UnaryExpression",fr="Unexpected token %0",s2e="Unexpected number",o2e="Unexpected string",a2e="Unexpected identifier",l2e="Unexpected reserved word",u2e="Unexpected end of input",vA="Invalid regular expression",b_="Invalid regular expression: missing /",wU="Octal literals are not allowed in strict mode.",c2e="Duplicate data property in object literal not allowed in strict mode",Fr="ILLEGAL",Pg="Disabled.",f2e=new RegExp("[\\xAA\\xB5\\xBA\\xC0-\\xD6\\xD8-\\xF6\\xF8-\\u02C1\\u02C6-\\u02D1\\u02E0-\\u02E4\\u02EC\\u02EE\\u0370-\\u0374\\u0376\\u0377\\u037A-\\u037D\\u037F\\u0386\\u0388-\\u038A\\u038C\\u038E-\\u03A1\\u03A3-\\u03F5\\u03F7-\\u0481\\u048A-\\u052F\\u0531-\\u0556\\u0559\\u0561-\\u0587\\u05D0-\\u05EA\\u05F0-\\u05F2\\u0620-\\u064A\\u066E\\u066F\\u0671-\\u06D3\\u06D5\\u06E5\\u06E6\\u06EE\\u06EF\\u06FA-\\u06FC\\u06FF\\u0710\\u0712-\\u072F\\u074D-\\u07A5\\u07B1\\u07CA-\\u07EA\\u07F4\\u07F5\\u07FA\\u0800-\\u0815\\u081A\\u0824\\u0828\\u0840-\\u0858\\u08A0-\\u08B2\\u0904-\\u0939\\u093D\\u0950\\u0958-\\u0961\\u0971-\\u0980\\u0985-\\u098C\\u098F\\u0990\\u0993-\\u09A8\\u09AA-\\u09B0\\u09B2\\u09B6-\\u09B9\\u09BD\\u09CE\\u09DC\\u09DD\\u09DF-\\u09E1\\u09F0\\u09F1\\u0A05-\\u0A0A\\u0A0F\\u0A10\\u0A13-\\u0A28\\u0A2A-\\u0A30\\u0A32\\u0A33\\u0A35\\u0A36\\u0A38\\u0A39\\u0A59-\\u0A5C\\u0A5E\\u0A72-\\u0A74\\u0A85-\\u0A8D\\u0A8F-\\u0A91\\u0A93-\\u0AA8\\u0AAA-\\u0AB0\\u0AB2\\u0AB3\\u0AB5-\\u0AB9\\u0ABD\\u0AD0\\u0AE0\\u0AE1\\u0B05-\\u0B0C\\u0B0F\\u0B10\\u0B13-\\u0B28\\u0B2A-\\u0B30\\u0B32\\u0B33\\u0B35-\\u0B39\\u0B3D\\u0B5C\\u0B5D\\u0B5F-\\u0B61\\u0B71\\u0B83\\u0B85-\\u0B8A\\u0B8E-\\u0B90\\u0B92-\\u0B95\\u0B99\\u0B9A\\u0B9C\\u0B9E\\u0B9F\\u0BA3\\u0BA4\\u0BA8-\\u0BAA\\u0BAE-\\u0BB9\\u0BD0\\u0C05-\\u0C0C\\u0C0E-\\u0C10\\u0C12-\\u0C28\\u0C2A-\\u0C39\\u0C3D\\u0C58\\u0C59\\u0C60\\u0C61\\u0C85-\\u0C8C\\u0C8E-\\u0C90\\u0C92-\\u0CA8\\u0CAA-\\u0CB3\\u0CB5-\\u0CB9\\u0CBD\\u0CDE\\u0CE0\\u0CE1\\u0CF1\\u0CF2\\u0D05-\\u0D0C\\u0D0E-\\u0D10\\u0D12-\\u0D3A\\u0D3D\\u0D4E\\u0D60\\u0D61\\u0D7A-\\u0D7F\\u0D85-\\u0D96\\u0D9A-\\u0DB1\\u0DB3-\\u0DBB\\u0DBD\\u0DC0-\\u0DC6\\u0E01-\\u0E30\\u0E32\\u0E33\\u0E40-\\u0E46\\u0E81\\u0E82\\u0E84\\u0E87\\u0E88\\u0E8A\\u0E8D\\u0E94-\\u0E97\\u0E99-\\u0E9F\\u0EA1-\\u0EA3\\u0EA5\\u0EA7\\u0EAA\\u0EAB\\u0EAD-\\u0EB0\\u0EB2\\u0EB3\\u0EBD\\u0EC0-\\u0EC4\\u0EC6\\u0EDC-\\u0EDF\\u0F00\\u0F40-\\u0F47\\u0F49-\\u0F6C\\u0F88-\\u0F8C\\u1000-\\u102A\\u103F\\u1050-\\u1055\\u105A-\\u105D\\u1061\\u1065\\u1066\\u106E-\\u1070\\u1075-\\u1081\\u108E\\u10A0-\\u10C5\\u10C7\\u10CD\\u10D0-\\u10FA\\u10FC-\\u1248\\u124A-\\u124D\\u1250-\\u1256\\u1258\\u125A-\\u125D\\u1260-\\u1288\\u128A-\\u128D\\u1290-\\u12B0\\u12B2-\\u12B5\\u12B8-\\u12BE\\u12C0\\u12C2-\\u12C5\\u12C8-\\u12D6\\u12D8-\\u1310\\u1312-\\u1315\\u1318-\\u135A\\u1380-\\u138F\\u13A0-\\u13F4\\u1401-\\u166C\\u166F-\\u167F\\u1681-\\u169A\\u16A0-\\u16EA\\u16EE-\\u16F8\\u1700-\\u170C\\u170E-\\u1711\\u1720-\\u1731\\u1740-\\u1751\\u1760-\\u176C\\u176E-\\u1770\\u1780-\\u17B3\\u17D7\\u17DC\\u1820-\\u1877\\u1880-\\u18A8\\u18AA\\u18B0-\\u18F5\\u1900-\\u191E\\u1950-\\u196D\\u1970-\\u1974\\u1980-\\u19AB\\u19C1-\\u19C7\\u1A00-\\u1A16\\u1A20-\\u1A54\\u1AA7\\u1B05-\\u1B33\\u1B45-\\u1B4B\\u1B83-\\u1BA0\\u1BAE\\u1BAF\\u1BBA-\\u1BE5\\u1C00-\\u1C23\\u1C4D-\\u1C4F\\u1C5A-\\u1C7D\\u1CE9-\\u1CEC\\u1CEE-\\u1CF1\\u1CF5\\u1CF6\\u1D00-\\u1DBF\\u1E00-\\u1F15\\u1F18-\\u1F1D\\u1F20-\\u1F45\\u1F48-\\u1F4D\\u1F50-\\u1F57\\u1F59\\u1F5B\\u1F5D\\u1F5F-\\u1F7D\\u1F80-\\u1FB4\\u1FB6-\\u1FBC\\u1FBE\\u1FC2-\\u1FC4\\u1FC6-\\u1FCC\\u1FD0-\\u1FD3\\u1FD6-\\u1FDB\\u1FE0-\\u1FEC\\u1FF2-\\u1FF4\\u1FF6-\\u1FFC\\u2071\\u207F\\u2090-\\u209C\\u2102\\u2107\\u210A-\\u2113\\u2115\\u2119-\\u211D\\u2124\\u2126\\u2128\\u212A-\\u212D\\u212F-\\u2139\\u213C-\\u213F\\u2145-\\u2149\\u214E\\u2160-\\u2188\\u2C00-\\u2C2E\\u2C30-\\u2C5E\\u2C60-\\u2CE4\\u2CEB-\\u2CEE\\u2CF2\\u2CF3\\u2D00-\\u2D25\\u2D27\\u2D2D\\u2D30-\\u2D67\\u2D6F\\u2D80-\\u2D96\\u2DA0-\\u2DA6\\u2DA8-\\u2DAE\\u2DB0-\\u2DB6\\u2DB8-\\u2DBE\\u2DC0-\\u2DC6\\u2DC8-\\u2DCE\\u2DD0-\\u2DD6\\u2DD8-\\u2DDE\\u2E2F\\u3005-\\u3007\\u3021-\\u3029\\u3031-\\u3035\\u3038-\\u303C\\u3041-\\u3096\\u309D-\\u309F\\u30A1-\\u30FA\\u30FC-\\u30FF\\u3105-\\u312D\\u3131-\\u318E\\u31A0-\\u31BA\\u31F0-\\u31FF\\u3400-\\u4DB5\\u4E00-\\u9FCC\\uA000-\\uA48C\\uA4D0-\\uA4FD\\uA500-\\uA60C\\uA610-\\uA61F\\uA62A\\uA62B\\uA640-\\uA66E\\uA67F-\\uA69D\\uA6A0-\\uA6EF\\uA717-\\uA71F\\uA722-\\uA788\\uA78B-\\uA78E\\uA790-\\uA7AD\\uA7B0\\uA7B1\\uA7F7-\\uA801\\uA803-\\uA805\\uA807-\\uA80A\\uA80C-\\uA822\\uA840-\\uA873\\uA882-\\uA8B3\\uA8F2-\\uA8F7\\uA8FB\\uA90A-\\uA925\\uA930-\\uA946\\uA960-\\uA97C\\uA984-\\uA9B2\\uA9CF\\uA9E0-\\uA9E4\\uA9E6-\\uA9EF\\uA9FA-\\uA9FE\\uAA00-\\uAA28\\uAA40-\\uAA42\\uAA44-\\uAA4B\\uAA60-\\uAA76\\uAA7A\\uAA7E-\\uAAAF\\uAAB1\\uAAB5\\uAAB6\\uAAB9-\\uAABD\\uAAC0\\uAAC2\\uAADB-\\uAADD\\uAAE0-\\uAAEA\\uAAF2-\\uAAF4\\uAB01-\\uAB06\\uAB09-\\uAB0E\\uAB11-\\uAB16\\uAB20-\\uAB26\\uAB28-\\uAB2E\\uAB30-\\uAB5A\\uAB5C-\\uAB5F\\uAB64\\uAB65\\uABC0-\\uABE2\\uAC00-\\uD7A3\\uD7B0-\\uD7C6\\uD7CB-\\uD7FB\\uF900-\\uFA6D\\uFA70-\\uFAD9\\uFB00-\\uFB06\\uFB13-\\uFB17\\uFB1D\\uFB1F-\\uFB28\\uFB2A-\\uFB36\\uFB38-\\uFB3C\\uFB3E\\uFB40\\uFB41\\uFB43\\uFB44\\uFB46-\\uFBB1\\uFBD3-\\uFD3D\\uFD50-\\uFD8F\\uFD92-\\uFDC7\\uFDF0-\\uFDFB\\uFE70-\\uFE74\\uFE76-\\uFEFC\\uFF21-\\uFF3A\\uFF41-\\uFF5A\\uFF66-\\uFFBE\\uFFC2-\\uFFC7\\uFFCA-\\uFFCF\\uFFD2-\\uFFD7\\uFFDA-\\uFFDC]"),d2e=new RegExp("[\\xAA\\xB5\\xBA\\xC0-\\xD6\\xD8-\\xF6\\xF8-\\u02C1\\u02C6-\\u02D1\\u02E0-\\u02E4\\u02EC\\u02EE\\u0300-\\u0374\\u0376\\u0377\\u037A-\\u037D\\u037F\\u0386\\u0388-\\u038A\\u038C\\u038E-\\u03A1\\u03A3-\\u03F5\\u03F7-\\u0481\\u0483-\\u0487\\u048A-\\u052F\\u0531-\\u0556\\u0559\\u0561-\\u0587\\u0591-\\u05BD\\u05BF\\u05C1\\u05C2\\u05C4\\u05C5\\u05C7\\u05D0-\\u05EA\\u05F0-\\u05F2\\u0610-\\u061A\\u0620-\\u0669\\u066E-\\u06D3\\u06D5-\\u06DC\\u06DF-\\u06E8\\u06EA-\\u06FC\\u06FF\\u0710-\\u074A\\u074D-\\u07B1\\u07C0-\\u07F5\\u07FA\\u0800-\\u082D\\u0840-\\u085B\\u08A0-\\u08B2\\u08E4-\\u0963\\u0966-\\u096F\\u0971-\\u0983\\u0985-\\u098C\\u098F\\u0990\\u0993-\\u09A8\\u09AA-\\u09B0\\u09B2\\u09B6-\\u09B9\\u09BC-\\u09C4\\u09C7\\u09C8\\u09CB-\\u09CE\\u09D7\\u09DC\\u09DD\\u09DF-\\u09E3\\u09E6-\\u09F1\\u0A01-\\u0A03\\u0A05-\\u0A0A\\u0A0F\\u0A10\\u0A13-\\u0A28\\u0A2A-\\u0A30\\u0A32\\u0A33\\u0A35\\u0A36\\u0A38\\u0A39\\u0A3C\\u0A3E-\\u0A42\\u0A47\\u0A48\\u0A4B-\\u0A4D\\u0A51\\u0A59-\\u0A5C\\u0A5E\\u0A66-\\u0A75\\u0A81-\\u0A83\\u0A85-\\u0A8D\\u0A8F-\\u0A91\\u0A93-\\u0AA8\\u0AAA-\\u0AB0\\u0AB2\\u0AB3\\u0AB5-\\u0AB9\\u0ABC-\\u0AC5\\u0AC7-\\u0AC9\\u0ACB-\\u0ACD\\u0AD0\\u0AE0-\\u0AE3\\u0AE6-\\u0AEF\\u0B01-\\u0B03\\u0B05-\\u0B0C\\u0B0F\\u0B10\\u0B13-\\u0B28\\u0B2A-\\u0B30\\u0B32\\u0B33\\u0B35-\\u0B39\\u0B3C-\\u0B44\\u0B47\\u0B48\\u0B4B-\\u0B4D\\u0B56\\u0B57\\u0B5C\\u0B5D\\u0B5F-\\u0B63\\u0B66-\\u0B6F\\u0B71\\u0B82\\u0B83\\u0B85-\\u0B8A\\u0B8E-\\u0B90\\u0B92-\\u0B95\\u0B99\\u0B9A\\u0B9C\\u0B9E\\u0B9F\\u0BA3\\u0BA4\\u0BA8-\\u0BAA\\u0BAE-\\u0BB9\\u0BBE-\\u0BC2\\u0BC6-\\u0BC8\\u0BCA-\\u0BCD\\u0BD0\\u0BD7\\u0BE6-\\u0BEF\\u0C00-\\u0C03\\u0C05-\\u0C0C\\u0C0E-\\u0C10\\u0C12-\\u0C28\\u0C2A-\\u0C39\\u0C3D-\\u0C44\\u0C46-\\u0C48\\u0C4A-\\u0C4D\\u0C55\\u0C56\\u0C58\\u0C59\\u0C60-\\u0C63\\u0C66-\\u0C6F\\u0C81-\\u0C83\\u0C85-\\u0C8C\\u0C8E-\\u0C90\\u0C92-\\u0CA8\\u0CAA-\\u0CB3\\u0CB5-\\u0CB9\\u0CBC-\\u0CC4\\u0CC6-\\u0CC8\\u0CCA-\\u0CCD\\u0CD5\\u0CD6\\u0CDE\\u0CE0-\\u0CE3\\u0CE6-\\u0CEF\\u0CF1\\u0CF2\\u0D01-\\u0D03\\u0D05-\\u0D0C\\u0D0E-\\u0D10\\u0D12-\\u0D3A\\u0D3D-\\u0D44\\u0D46-\\u0D48\\u0D4A-\\u0D4E\\u0D57\\u0D60-\\u0D63\\u0D66-\\u0D6F\\u0D7A-\\u0D7F\\u0D82\\u0D83\\u0D85-\\u0D96\\u0D9A-\\u0DB1\\u0DB3-\\u0DBB\\u0DBD\\u0DC0-\\u0DC6\\u0DCA\\u0DCF-\\u0DD4\\u0DD6\\u0DD8-\\u0DDF\\u0DE6-\\u0DEF\\u0DF2\\u0DF3\\u0E01-\\u0E3A\\u0E40-\\u0E4E\\u0E50-\\u0E59\\u0E81\\u0E82\\u0E84\\u0E87\\u0E88\\u0E8A\\u0E8D\\u0E94-\\u0E97\\u0E99-\\u0E9F\\u0EA1-\\u0EA3\\u0EA5\\u0EA7\\u0EAA\\u0EAB\\u0EAD-\\u0EB9\\u0EBB-\\u0EBD\\u0EC0-\\u0EC4\\u0EC6\\u0EC8-\\u0ECD\\u0ED0-\\u0ED9\\u0EDC-\\u0EDF\\u0F00\\u0F18\\u0F19\\u0F20-\\u0F29\\u0F35\\u0F37\\u0F39\\u0F3E-\\u0F47\\u0F49-\\u0F6C\\u0F71-\\u0F84\\u0F86-\\u0F97\\u0F99-\\u0FBC\\u0FC6\\u1000-\\u1049\\u1050-\\u109D\\u10A0-\\u10C5\\u10C7\\u10CD\\u10D0-\\u10FA\\u10FC-\\u1248\\u124A-\\u124D\\u1250-\\u1256\\u1258\\u125A-\\u125D\\u1260-\\u1288\\u128A-\\u128D\\u1290-\\u12B0\\u12B2-\\u12B5\\u12B8-\\u12BE\\u12C0\\u12C2-\\u12C5\\u12C8-\\u12D6\\u12D8-\\u1310\\u1312-\\u1315\\u1318-\\u135A\\u135D-\\u135F\\u1380-\\u138F\\u13A0-\\u13F4\\u1401-\\u166C\\u166F-\\u167F\\u1681-\\u169A\\u16A0-\\u16EA\\u16EE-\\u16F8\\u1700-\\u170C\\u170E-\\u1714\\u1720-\\u1734\\u1740-\\u1753\\u1760-\\u176C\\u176E-\\u1770\\u1772\\u1773\\u1780-\\u17D3\\u17D7\\u17DC\\u17DD\\u17E0-\\u17E9\\u180B-\\u180D\\u1810-\\u1819\\u1820-\\u1877\\u1880-\\u18AA\\u18B0-\\u18F5\\u1900-\\u191E\\u1920-\\u192B\\u1930-\\u193B\\u1946-\\u196D\\u1970-\\u1974\\u1980-\\u19AB\\u19B0-\\u19C9\\u19D0-\\u19D9\\u1A00-\\u1A1B\\u1A20-\\u1A5E\\u1A60-\\u1A7C\\u1A7F-\\u1A89\\u1A90-\\u1A99\\u1AA7\\u1AB0-\\u1ABD\\u1B00-\\u1B4B\\u1B50-\\u1B59\\u1B6B-\\u1B73\\u1B80-\\u1BF3\\u1C00-\\u1C37\\u1C40-\\u1C49\\u1C4D-\\u1C7D\\u1CD0-\\u1CD2\\u1CD4-\\u1CF6\\u1CF8\\u1CF9\\u1D00-\\u1DF5\\u1DFC-\\u1F15\\u1F18-\\u1F1D\\u1F20-\\u1F45\\u1F48-\\u1F4D\\u1F50-\\u1F57\\u1F59\\u1F5B\\u1F5D\\u1F5F-\\u1F7D\\u1F80-\\u1FB4\\u1FB6-\\u1FBC\\u1FBE\\u1FC2-\\u1FC4\\u1FC6-\\u1FCC\\u1FD0-\\u1FD3\\u1FD6-\\u1FDB\\u1FE0-\\u1FEC\\u1FF2-\\u1FF4\\u1FF6-\\u1FFC\\u200C\\u200D\\u203F\\u2040\\u2054\\u2071\\u207F\\u2090-\\u209C\\u20D0-\\u20DC\\u20E1\\u20E5-\\u20F0\\u2102\\u2107\\u210A-\\u2113\\u2115\\u2119-\\u211D\\u2124\\u2126\\u2128\\u212A-\\u212D\\u212F-\\u2139\\u213C-\\u213F\\u2145-\\u2149\\u214E\\u2160-\\u2188\\u2C00-\\u2C2E\\u2C30-\\u2C5E\\u2C60-\\u2CE4\\u2CEB-\\u2CF3\\u2D00-\\u2D25\\u2D27\\u2D2D\\u2D30-\\u2D67\\u2D6F\\u2D7F-\\u2D96\\u2DA0-\\u2DA6\\u2DA8-\\u2DAE\\u2DB0-\\u2DB6\\u2DB8-\\u2DBE\\u2DC0-\\u2DC6\\u2DC8-\\u2DCE\\u2DD0-\\u2DD6\\u2DD8-\\u2DDE\\u2DE0-\\u2DFF\\u2E2F\\u3005-\\u3007\\u3021-\\u302F\\u3031-\\u3035\\u3038-\\u303C\\u3041-\\u3096\\u3099\\u309A\\u309D-\\u309F\\u30A1-\\u30FA\\u30FC-\\u30FF\\u3105-\\u312D\\u3131-\\u318E\\u31A0-\\u31BA\\u31F0-\\u31FF\\u3400-\\u4DB5\\u4E00-\\u9FCC\\uA000-\\uA48C\\uA4D0-\\uA4FD\\uA500-\\uA60C\\uA610-\\uA62B\\uA640-\\uA66F\\uA674-\\uA67D\\uA67F-\\uA69D\\uA69F-\\uA6F1\\uA717-\\uA71F\\uA722-\\uA788\\uA78B-\\uA78E\\uA790-\\uA7AD\\uA7B0\\uA7B1\\uA7F7-\\uA827\\uA840-\\uA873\\uA880-\\uA8C4\\uA8D0-\\uA8D9\\uA8E0-\\uA8F7\\uA8FB\\uA900-\\uA92D\\uA930-\\uA953\\uA960-\\uA97C\\uA980-\\uA9C0\\uA9CF-\\uA9D9\\uA9E0-\\uA9FE\\uAA00-\\uAA36\\uAA40-\\uAA4D\\uAA50-\\uAA59\\uAA60-\\uAA76\\uAA7A-\\uAAC2\\uAADB-\\uAADD\\uAAE0-\\uAAEF\\uAAF2-\\uAAF6\\uAB01-\\uAB06\\uAB09-\\uAB0E\\uAB11-\\uAB16\\uAB20-\\uAB26\\uAB28-\\uAB2E\\uAB30-\\uAB5A\\uAB5C-\\uAB5F\\uAB64\\uAB65\\uABC0-\\uABEA\\uABEC\\uABED\\uABF0-\\uABF9\\uAC00-\\uD7A3\\uD7B0-\\uD7C6\\uD7CB-\\uD7FB\\uF900-\\uFA6D\\uFA70-\\uFAD9\\uFB00-\\uFB06\\uFB13-\\uFB17\\uFB1D-\\uFB28\\uFB2A-\\uFB36\\uFB38-\\uFB3C\\uFB3E\\uFB40\\uFB41\\uFB43\\uFB44\\uFB46-\\uFBB1\\uFBD3-\\uFD3D\\uFD50-\\uFD8F\\uFD92-\\uFDC7\\uFDF0-\\uFDFB\\uFE00-\\uFE0F\\uFE20-\\uFE2D\\uFE33\\uFE34\\uFE4D-\\uFE4F\\uFE70-\\uFE74\\uFE76-\\uFEFC\\uFF10-\\uFF19\\uFF21-\\uFF3A\\uFF3F\\uFF41-\\uFF5A\\uFF66-\\uFFBE\\uFFC2-\\uFFC7\\uFFCA-\\uFFCF\\uFFD2-\\uFFD7\\uFFDA-\\uFFDC]");function x2(e,t){if(!e)throw new Error("ASSERT: "+t)}function za(e){return e>=48&&e<=57}function lF(e){return"0123456789abcdefABCDEF".includes(e)}function og(e){return"01234567".includes(e)}function h2e(e){return e===32||e===9||e===11||e===12||e===160||e>=5760&&[5760,6158,8192,8193,8194,8195,8196,8197,8198,8199,8200,8201,8202,8239,8287,12288,65279].includes(e)}function Bg(e){return e===10||e===13||e===8232||e===8233}function X0(e){return e===36||e===95||e>=65&&e<=90||e>=97&&e<=122||e===92||e>=128&&f2e.test(String.fromCharCode(e))}function py(e){return e===36||e===95||e>=65&&e<=90||e>=97&&e<=122||e>=48&&e<=57||e===92||e>=128&&d2e.test(String.fromCharCode(e))}const p2e={if:1,in:1,do:1,var:1,for:1,new:1,try:1,let:1,this:1,else:1,case:1,void:1,with:1,enum:1,while:1,break:1,catch:1,throw:1,const:1,yield:1,class:1,super:1,return:1,typeof:1,delete:1,switch:1,export:1,import:1,public:1,static:1,default:1,finally:1,extends:1,package:1,private:1,function:1,continue:1,debugger:1,interface:1,protected:1,instanceof:1,implements:1};function EU(){for(;ce1114111||e!=="}")&&Ht({},fr,Fr),t<=65535?String.fromCharCode(t):(n=(t-65536>>10)+55296,r=(t-65536&1023)+56320,String.fromCharCode(n,r))}function AU(){var e,t;for(e=Qe.charCodeAt(ce++),t=String.fromCharCode(e),e===92&&(Qe.charCodeAt(ce)!==117&&Ht({},fr,Fr),++ce,e=yA("u"),(!e||e==="\\"||!X0(e.charCodeAt(0)))&&Ht({},fr,Fr),t=e);ce>>=")return ce+=4,{type:Mi,value:o,start:e,end:ce};if(s=o.substr(0,3),s===">>>"||s==="<<="||s===">>=")return ce+=3,{type:Mi,value:s,start:e,end:ce};if(i=s.substr(0,2),r===i[1]&&"+-<>&|".includes(r)||i==="=>")return ce+=2,{type:Mi,value:i,start:e,end:ce};if(i==="//"&&Ht({},fr,Fr),"<>=!+-*%&|^/".includes(r))return++ce,{type:Mi,value:r,start:e,end:ce};Ht({},fr,Fr)}function y2e(e){let t="";for(;ce{if(parseInt(i,16)<=1114111)return"x";Ht({},vA)}).replace(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g,"x"));try{new RegExp(n)}catch{Ht({},vA)}try{return new RegExp(e,t)}catch{return null}}function w2e(){var e,t,n,r,i;for(e=Qe[ce],x2(e==="/","Regular expression literal must start with a slash"),t=Qe[ce++],n=!1,r=!1;ce=0&&Ht({},vA,n),{value:n,literal:t}}function A2e(){var e,t,n,r;return nn=null,EU(),e=ce,t=w2e(),n=E2e(),r=_2e(t.value,n.value),{literal:t.literal+n.literal,value:r,regex:{pattern:t.value,flags:n.value},start:e,end:ce}}function k2e(e){return e.type===lf||e.type===Pu||e.type===y2||e.type===b2}function kU(){if(EU(),ce>=Zr)return{type:Y0,start:ce,end:ce};const e=Qe.charCodeAt(ce);return X0(e)?v2e():e===40||e===41||e===59?x_():e===39||e===34?x2e():e===46?za(Qe.charCodeAt(ce+1))?K6():x_():za(e)?K6():x_()}function Oi(){const e=nn;return ce=e.end,nn=kU(),ce=e.end,e}function SU(){const e=ce;nn=kU(),ce=e}function S2e(e){const t=new Mo(Xbe);return t.elements=e,t}function Z6(e,t,n){const r=new Mo(e==="||"||e==="&&"?e2e:Kbe);return r.operator=e,r.left=t,r.right=n,r}function C2e(e,t){const n=new Mo(Zbe);return n.callee=e,n.arguments=t,n}function $2e(e,t,n){const r=new Mo(Jbe);return r.test=e,r.consequent=t,r.alternate=n,r}function uF(e){const t=new Mo(_U);return t.name=e,t}function Pp(e){const t=new Mo(Qbe);return t.value=e.value,t.raw=Qe.slice(e.start,e.end),e.regex&&(t.raw==="//"&&(t.raw="/(?:)/"),t.regex=e.regex),t}function J6(e,t,n){const r=new Mo(t2e);return r.computed=e==="[",r.object=t,r.property=n,r.computed||(n.member=!0),r}function F2e(e){const t=new Mo(n2e);return t.properties=e,t}function Q6(e,t,n){const r=new Mo(r2e);return r.key=t,r.value=n,r.kind=e,r}function D2e(e,t){const n=new Mo(i2e);return n.operator=e,n.argument=t,n.prefix=!0,n}function Ht(e,t){var n,r=Array.prototype.slice.call(arguments,2),i=t.replace(/%(\d)/g,(s,o)=>(x2(o":case"<=":case">=":case"instanceof":case"in":t=7;break;case"<<":case">>":case">>>":t=8;break;case"+":case"-":t=9;break;case"*":case"/":case"%":t=11;break}return t}function U2e(){var e,t,n,r,i,s,o,a,l,u;if(e=nn,l=D1(),r=nn,i=n8(r),i===0)return l;for(r.prec=i,Oi(),t=[e,nn],o=D1(),s=[l,r,o];(i=n8(nn))>0;){for(;s.length>2&&i<=s[s.length-2].prec;)o=s.pop(),a=s.pop().value,l=s.pop(),t.pop(),n=Z6(a,l,o),s.push(n);r=Oi(),r.prec=i,s.push(r),t.push(nn),n=D1(),s.push(n)}for(u=s.length-1,n=s[u],t.pop();u>1;)t.pop(),n=Z6(s[u-1].value,s[u-2],n),u-=2;return n}function uf(){var e,t,n;return e=U2e(),yn("?")&&(Oi(),t=uf(),Jr(":"),n=uf(),e=$2e(e,t,n)),e}function cF(){const e=uf();if(yn(","))throw new Error(Pg);return e}function q2e(e){Qe=e,ce=0,Zr=Qe.length,nn=null,SU();const t=cF();if(nn.type!==Y0)throw new Error("Unexpect token after expression.");return t}function bA(e){const t=[];return e.type==="Identifier"?[e.name]:e.type==="Literal"?[e.value]:(e.type==="MemberExpression"&&(t.push(...bA(e.object)),t.push(...bA(e.property))),t)}function CU(e){return e.object.type==="MemberExpression"?CU(e.object):e.object.name==="datum"}function $U(e){const t=q2e(e),n=new Set;return t.visit(r=>{r.type==="MemberExpression"&&CU(r)&&n.add(bA(r).slice(1).join("."))}),n}class Lh extends rn{clone(){return new Lh(null,this.model,gt(this.filter))}constructor(t,n,r){super(t),this.model=n,this.filter=r,this.expr=gy(this.model,this.filter,this),this._dependentFields=$U(this.expr)}dependentFields(){return this._dependentFields}producedFields(){return new Set}assemble(){return{type:"filter",expr:this.expr}}hash(){return`Filter ${this.expr}`}}function W2e(e,t){const n={},r=e.config.selection;if(!t||!t.length)return n;let i=0;for(const s of t){const o=_n(s.name),a=s.select,l=ze(a)?a:a.type,u=Pe(a)?gt(a):{type:l},c=r[l];for(const h in c)h==="fields"||h==="encodings"||(h==="mark"&&(u.mark={...c.mark,...u.mark}),(u[h]===void 0||u[h]===!0)&&(u[h]=gt(c[h]??u[h])));const f=n[o]={...u,name:o,type:l,init:s.value,bind:s.bind,events:ze(u.on)?Fu(u.on,"scope"):je(gt(u.on))};if(ia(f)&&(i++,i>1)){delete n[o];continue}const d=gt(s);for(const h of v2)h.defined(f)&&h.parse&&h.parse(e,f,d)}return i>1&&Ce(Q0e),n}function FU(e,t,n,r="datum"){const i=ze(t)?t:t.param,s=_n(i),o=De(s+af);let a;try{a=e.getSelectionComponent(s,i)}catch{return`!!${s}`}if(a.project.timeUnit){const d=n??e.component.data.raw,h=a.project.timeUnit.clone();d.parent?h.insertAsParentOf(d):d.parent=h}const l=a.project.hasSelectionId?"vlSelectionIdTest(":"vlSelectionTest(",u=a.resolve==="global"?")":`, ${De(a.resolve)})`,c=`${l}${o}, ${r}${u}`,f=`length(data(${o}))`;return t.empty===!1?`${f} && ${c}`:`!${f} || ${c}`}function DU(e,t,n){const r=_n(t),i=n.encoding;let s=n.field,o;try{o=e.getSelectionComponent(r,t)}catch{return r}if(!i&&!s)s=o.project.items[0].field,o.project.items.length>1&&Ce(eme(s));else if(i&&!s){const a=o.project.items.filter(l=>l.channel===i);!a.length||a.length>1?(s=o.project.items[0].field,Ce(tme(a,i,n,s))):s=a[0].field}return`${o.name}[${De(Bs(s))}]`}function H2e(e,t){for(const[n,r]of pu(e.component.selection??{})){const i=e.getName(`lookup_${n}`);e.component.data.outputNodes[i]=r.materialized=new Bi(new Lh(t,e,{param:n}),i,$n.Lookup,e.component.data.outputNodeRefCounts)}}function gy(e,t,n){return ig(t,r=>ze(r)?r:c1e(r)?FU(e,r,n):Nz(r))}function G2e(e,t){if(e)return fe(e)&&!Nl(e)?e.map(n=>U$(n,t)).join(", "):e}function w_(e,t,n,r){var i,s;e.encode??(e.encode={}),(i=e.encode)[t]??(i[t]={}),(s=e.encode[t]).update??(s.update={}),e.encode[t].update[n]=r}function Bp(e,t,n,r={header:!1}){var f,d;const{disable:i,orient:s,scale:o,labelExpr:a,title:l,zindex:u,...c}=e.combine();if(!i){for(const h in c){const p=h,g=gve[p],m=c[p];if(g&&g!==t&&g!=="both")delete c[p];else if(H0(m)){const{condition:v,...b}=m,x=je(v),_=E6[p];if(_){const{vgProp:w,part:A}=_,E=[...x.map(k=>{const{test:S,...$}=k;return{test:gy(null,S),...$}}),b];w_(c,A,w,E),delete c[p]}else if(_===null){const w={signal:x.map(A=>{const{test:E,...k}=A;return`${gy(null,E)} ? ${a6(k)} : `}).join("")+a6(b)};c[p]=w}}else if(tt(m)){const v=E6[p];if(v){const{vgProp:b,part:x}=v;w_(c,x,b,m),delete c[p]}}Tt(["labelAlign","labelBaseline"],p)&&c[p]===null&&delete c[p]}if(t==="grid"){if(!c.grid)return;if(c.encode){const{grid:h}=c.encode;c.encode={...h?{grid:h}:{}},an(c.encode)&&delete c.encode}return{scale:o,orient:s,...c,domain:!1,labels:!1,aria:!1,maxExtent:0,minExtent:0,ticks:!1,zindex:jn(u,0)}}else{if(!r.header&&e.mainExtracted)return;if(a!==void 0){let p=a;(d=(f=c.encode)==null?void 0:f.labels)!=null&&d.update&&tt(c.encode.labels.update.text)&&(p=Jc(a,"datum.label",c.encode.labels.update.text.signal)),w_(c,"labels","text",{signal:p})}if(c.labelAlign===null&&delete c.labelAlign,c.encode){for(const p of fj)e.hasAxisPart(p)||delete c.encode[p];an(c.encode)&&delete c.encode}const h=G2e(l,n);return{scale:o,orient:s,grid:!1,...h?{title:h}:{},...c,...n.aria===!1?{aria:!1}:{},zindex:jn(u,0)}}}}function MU(e){const{axes:t}=e.component,n=[];for(const r of _l)if(t[r]){for(const i of t[r])if(!i.get("disable")&&!i.get("gridScale")){const s=r==="x"?"height":"width",o=e.getSizeSignalRef(s).signal;s!==o&&n.push({name:s,update:o})}}return n}function Y2e(e,t){const{x:n=[],y:r=[]}=e;return[...n.map(i=>Bp(i,"grid",t)),...r.map(i=>Bp(i,"grid",t)),...n.map(i=>Bp(i,"main",t)),...r.map(i=>Bp(i,"main",t))].filter(i=>i)}function r8(e,t,n,r){return Object.assign.apply(null,[{},...e.map(i=>{if(i==="axisOrient"){const s=n==="x"?"bottom":"left",o=t[n==="x"?"axisBottom":"axisLeft"]||{},a=t[n==="x"?"axisTop":"axisRight"]||{},l=new Set([...Ae(o),...Ae(a)]),u={};for(const c of l.values())u[c]={signal:`${r.signal} === "${s}" ? ${uo(o[c])} : ${uo(a[c])}`};return u}return t[i]})])}function V2e(e,t,n,r){const i=t==="band"?["axisDiscrete","axisBand"]:t==="point"?["axisDiscrete","axisPoint"]:Pz(t)?["axisQuantitative"]:t==="time"||t==="utc"?["axisTemporal"]:[],s=e==="x"?"axisX":"axisY",o=tt(n)?"axisOrient":`axis${N0(n)}`,a=[...i,...i.map(u=>s+u.substr(4))],l=["axis",o,s];return{vlOnlyAxisConfig:r8(a,r,e,n),vgAxisConfig:r8(l,r,e,n),axisConfigStyle:X2e([...l,...a],r)}}function X2e(e,t){var r;const n=[{}];for(const i of e){let s=(r=t[i])==null?void 0:r.style;if(s){s=je(s);for(const o of s)n.push(t.style[o])}}return Object.assign.apply(null,n)}function xA(e,t,n,r={}){var s;const i=dz(e,n,t);if(i!==void 0)return{configFrom:"style",configValue:i};for(const o of["vlOnlyAxisConfig","vgAxisConfig","axisConfigStyle"])if(((s=r[o])==null?void 0:s[e])!==void 0)return{configFrom:o,configValue:r[o][e]};return{}}const i8={scale:({model:e,channel:t})=>e.scaleName(t),format:({format:e})=>e,formatType:({formatType:e})=>e,grid:({fieldOrDatumDef:e,axis:t,scaleType:n})=>t.grid??K2e(n,e),gridScale:({model:e,channel:t})=>Z2e(e,t),labelAlign:({axis:e,labelAngle:t,orient:n,channel:r})=>e.labelAlign||RU(t,n,r),labelAngle:({labelAngle:e})=>e,labelBaseline:({axis:e,labelAngle:t,orient:n,channel:r})=>e.labelBaseline||TU(t,n,r),labelFlush:({axis:e,fieldOrDatumDef:t,channel:n})=>e.labelFlush??Q2e(t.type,n),labelOverlap:({axis:e,fieldOrDatumDef:t,scaleType:n})=>e.labelOverlap??exe(t.type,n,$e(t)&&!!t.timeUnit,$e(t)?t.sort:void 0),orient:({orient:e})=>e,tickCount:({channel:e,model:t,axis:n,fieldOrDatumDef:r,scaleType:i})=>{const s=e==="x"?"width":e==="y"?"height":void 0,o=s?t.getSizeSignalRef(s):void 0;return n.tickCount??nxe({fieldOrDatumDef:r,scaleType:i,size:o,values:n.values})},tickMinStep:rxe,title:({axis:e,model:t,channel:n})=>{if(e.title!==void 0)return e.title;const r=NU(t,n);if(r!==void 0)return r;const i=t.typedFieldDef(n),s=n==="x"?"x2":"y2",o=t.fieldDef(s);return pz(i?[_6(i)]:[],$e(o)?[_6(o)]:[])},values:({axis:e,fieldOrDatumDef:t})=>ixe(e,t),zindex:({axis:e,fieldOrDatumDef:t,mark:n})=>e.zindex??sxe(n,t)};function K2e(e,t){return!pr(e)&&$e(t)&&!dn(t==null?void 0:t.bin)&&!wr(t==null?void 0:t.bin)}function Z2e(e,t){const n=t==="x"?"y":"x";if(e.getScaleComponent(n))return e.scaleName(n)}function J2e(e,t,n,r,i){const s=t==null?void 0:t.labelAngle;if(s!==void 0)return tt(s)?s:Og(s);{const{configValue:o}=xA("labelAngle",r,t==null?void 0:t.style,i);return o!==void 0?Og(o):n===wn&&Tt([D$,F$],e.type)&&!($e(e)&&e.timeUnit)?270:void 0}}function _A(e){return`(((${e.signal} % 360) + 360) % 360)`}function TU(e,t,n,r){if(e!==void 0)if(n==="x"){if(tt(e)){const i=_A(e),s=tt(t)?`(${t.signal} === "top")`:t==="top";return{signal:`(45 < ${i} && ${i} < 135) || (225 < ${i} && ${i} < 315) ? "middle" :(${i} <= 45 || 315 <= ${i}) === ${s} ? "bottom" : "top"`}}if(45{if(Sf(r)&&ej(r.sort)){const{field:s,timeUnit:o}=r,a=r.sort,l=a.map((u,c)=>`${Nz({field:s,timeUnit:o,equal:u})} ? ${c} : `).join("")+a.length;t=new ah(t,{calculate:l,as:lh(r,i,{forAs:!0})})}}),t}producedFields(){return new Set([this.transform.as])}dependentFields(){return this._dependentFields}assemble(){return{type:"formula",expr:this.transform.calculate,as:this.transform.as}}hash(){return`Calculate ${It(this.transform)}`}}function lh(e,t,n){return Ne(e,{prefix:t,suffix:"sort_index",...n})}function w2(e,t){return Tt(["top","bottom"],t)?"column":Tt(["left","right"],t)||e==="row"?"row":"column"}function uh(e,t,n,r){const i=r==="row"?n.headerRow:r==="column"?n.headerColumn:n.headerFacet;return jn((t||{})[e],i[e],n.header[e])}function E2(e,t,n,r){const i={};for(const s of e){const o=uh(s,t||{},n,r);o!==void 0&&(i[s]=o)}return i}const fF=["row","column"],dF=["header","footer"];function oxe(e,t){const n=e.component.layoutHeaders[t].title,r=e.config?e.config:void 0,i=e.component.layoutHeaders[t].facetFieldDef?e.component.layoutHeaders[t].facetFieldDef:void 0,{titleAnchor:s,titleAngle:o,titleOrient:a}=E2(["titleAnchor","titleAngle","titleOrient"],i.header,r,t),l=w2(t,a),u=Og(o);return{name:`${t}-title`,type:"group",role:`${l}-title`,title:{text:n,...t==="row"?{orient:"left"}:{},style:"guide-title",...LU(u,l),...OU(l,u,s),...IU(r,i,t,Ive,Fj)}}}function OU(e,t,n="middle"){switch(n){case"start":return{align:"left"};case"end":return{align:"right"}}const r=RU(t,e==="row"?"left":"top",e==="row"?"y":"x");return r?{align:r}:{}}function LU(e,t){const n=TU(e,t==="row"?"left":"top",t==="row"?"y":"x",!0);return n?{baseline:n}:{}}function axe(e,t){const n=e.component.layoutHeaders[t],r=[];for(const i of dF)if(n[i])for(const s of n[i]){const o=uxe(e,t,i,n,s);o!=null&&r.push(o)}return r}function lxe(e,t){const{sort:n}=e;return il(n)?{field:Ne(n,{expr:"datum"}),order:n.order??"ascending"}:fe(n)?{field:lh(e,t,{expr:"datum"}),order:"ascending"}:{field:Ne(e,{expr:"datum"}),order:n??"ascending"}}function wA(e,t,n){const{format:r,formatType:i,labelAngle:s,labelAnchor:o,labelOrient:a,labelExpr:l}=E2(["format","formatType","labelAngle","labelAnchor","labelOrient","labelExpr"],e.header,n,t),u=P$({fieldOrDatumDef:e,format:r,formatType:i,expr:"parent",config:n}).signal,c=w2(t,a);return{text:{signal:l?Jc(Jc(l,"datum.label",u),"datum.value",Ne(e,{expr:"parent"})):u},...t==="row"?{orient:"left"}:{},style:"guide-label",frame:"group",...LU(s,c),...OU(c,s,o),...IU(n,e,t,Pve,Dj)}}function uxe(e,t,n,r,i){if(i){let s=null;const{facetFieldDef:o}=r,a=e.config?e.config:void 0;if(o&&i.labels){const{labelOrient:f}=E2(["labelOrient"],o.header,a,t);(t==="row"&&!Tt(["top","bottom"],f)||t==="column"&&!Tt(["left","right"],f))&&(s=wA(o,t,a))}const l=cs(e)&&!j0(e.facet),u=i.axes,c=(u==null?void 0:u.length)>0;if(s||c){const f=t==="row"?"height":"width";return{name:e.getName(`${t}_${n}`),type:"group",role:`${t}-${n}`,...r.facetFieldDef?{from:{data:e.getName(`${t}_domain`)},sort:lxe(o,t)}:{},...c&&l?{from:{data:e.getName(`facet_domain_${t}`)}}:{},...s?{title:s}:{},...i.sizeSignal?{encode:{update:{[f]:i.sizeSignal}}}:{},...c?{axes:u}:{}}}}return null}const cxe={column:{start:0,end:1},row:{start:1,end:0}};function fxe(e,t){return cxe[t][e]}function dxe(e,t){const n={};for(const r of $s){const i=e[r];if(i!=null&&i.facetFieldDef){const{titleAnchor:s,titleOrient:o}=E2(["titleAnchor","titleOrient"],i.facetFieldDef.header,t,r),a=w2(r,o),l=fxe(s,a);l!==void 0&&(n[a]=l)}}return an(n)?void 0:n}function IU(e,t,n,r,i){const s={};for(const o of r){if(!i[o])continue;const a=uh(o,t==null?void 0:t.header,e,n);a!==void 0&&(s[i[o]]=a)}return s}function hF(e){return[...Om(e,"width"),...Om(e,"height"),...Om(e,"childWidth"),...Om(e,"childHeight")]}function Om(e,t){const n=t==="width"?"x":"y",r=e.component.layoutSize.get(t);if(!r||r==="merged")return[];const i=e.getSizeSignalRef(t).signal;if(r==="step"){const s=e.getScaleComponent(n);if(s){const o=s.get("type"),a=s.get("range");if(pr(o)&&Ef(a)){const l=e.scaleName(n);return cs(e.parent)&&e.parent.component.resolve.scale[n]==="independent"?[s8(l,a)]:[s8(l,a),{name:i,update:PU(l,s,`domain('${l}').length`)}]}}throw new Error("layout size is step although width/height is not step.")}else if(r=="container"){const s=i.endsWith("width"),o=s?"containerSize()[0]":"containerSize()[1]",a=uA(e.config.view,s?"width":"height"),l=`isFinite(${o}) ? ${o} : ${a}`;return[{name:i,init:l,on:[{update:l,events:"window:resize"}]}]}else return[{name:i,value:r}]}function s8(e,t){const n=`${e}_step`;return tt(t.step)?{name:n,update:t.step.signal}:{name:n,value:t.step}}function PU(e,t,n){const r=t.get("type"),i=t.get("padding"),s=jn(t.get("paddingOuter"),i);let o=t.get("paddingInner");return o=r==="band"?o!==void 0?o:i:1,`bandspace(${n}, ${uo(o)}, ${uo(s)}) * ${e}_step`}function BU(e){return e==="childWidth"?"width":e==="childHeight"?"height":e}function zU(e,t){return Ae(e).reduce((n,r)=>({...n,...Oh({model:t,channelDef:e[r],vgChannel:r,mainRefFn:i=>vn(i.value),invalidValueRef:void 0})}),{})}function jU(e,t){if(cs(t))return e==="theta"?"independent":"shared";if(Bh(t))return"shared";if(xF(t))return Un(e)||e==="theta"||e==="radius"?"independent":"shared";throw new Error("invalid model type for resolve")}function pF(e,t){const n=e.scale[t],r=Un(t)?"axis":"legend";return n==="independent"?(e[r][t]==="shared"&&Ce(Tme(t)),"independent"):e[r][t]||"shared"}const hxe={...jve,disable:1,labelExpr:1,selections:1,opacity:1,shape:1,stroke:1,fill:1,size:1,strokeWidth:1,strokeDash:1,encode:1},UU=Ae(hxe);class pxe extends El{}const o8={symbols:gxe,gradient:mxe,labels:vxe,entries:yxe};function gxe(e,{fieldOrDatumDef:t,model:n,channel:r,legendCmpt:i,legendType:s}){if(s!=="symbol")return;const{markDef:o,encoding:a,config:l,mark:u}=n,c=o.filled&&u!=="trail";let f={...z0e({},n,L1e),...lU(n,{filled:c})};const d=i.get("symbolOpacity")??l.legend.symbolOpacity,h=i.get("symbolFillColor")??l.legend.symbolFillColor,p=i.get("symbolStrokeColor")??l.legend.symbolStrokeColor,g=d===void 0?qU(a.opacity)??o.opacity:void 0;if(f.fill){if(r==="fill"||c&&r===qi)delete f.fill;else if(Se(f.fill,"field"))h?delete f.fill:(f.fill=vn(l.legend.symbolBaseFillColor??"black"),f.fillOpacity=vn(g??1));else if(fe(f.fill)){const m=EA(a.fill??a.color)??o.fill??(c&&o.color);m&&(f.fill=vn(m))}}if(f.stroke){if(r==="stroke"||!c&&r===qi)delete f.stroke;else if(Se(f.stroke,"field")||p)delete f.stroke;else if(fe(f.stroke)){const m=jn(EA(a.stroke||a.color),o.stroke,c?o.color:void 0);m&&(f.stroke={value:m})}}if(r!==xl){const m=$e(t)&&HU(n,i,t);m?f.opacity=[{test:m,...vn(g??1)},vn(l.legend.unselectedOpacity)]:g&&(f.opacity=vn(g))}return f={...f,...e},an(f)?void 0:f}function mxe(e,{model:t,legendType:n,legendCmpt:r}){if(n!=="gradient")return;const{config:i,markDef:s,encoding:o}=t;let a={};const u=(r.get("gradientOpacity")??i.legend.gradientOpacity)===void 0?qU(o.opacity)||s.opacity:void 0;return u&&(a.opacity=vn(u)),a={...a,...e},an(a)?void 0:a}function vxe(e,{fieldOrDatumDef:t,model:n,channel:r,legendCmpt:i}){const s=n.legend(r)||{},o=n.config,a=$e(t)?HU(n,i,t):void 0,l=a?[{test:a,value:1},{value:o.legend.unselectedOpacity}]:void 0,{format:u,formatType:c}=s;let f;sf(c)?f=co({fieldOrDatumDef:t,field:"datum.value",format:u,formatType:c,config:o}):u===void 0&&c===void 0&&o.customFormatTypes&&(t.type==="quantitative"&&o.numberFormatType?f=co({fieldOrDatumDef:t,field:"datum.value",format:o.numberFormat,formatType:o.numberFormatType,config:o}):t.type==="temporal"&&o.timeFormatType&&$e(t)&&t.timeUnit===void 0&&(f=co({fieldOrDatumDef:t,field:"datum.value",format:o.timeFormat,formatType:o.timeFormatType,config:o})));const d={...l?{opacity:l}:{},...f?{text:f}:{},...e};return an(d)?void 0:d}function yxe(e,{legendCmpt:t}){const n=t.get("selections");return n!=null&&n.length?{...e,fill:{value:"transparent"}}:e}function qU(e){return WU(e,(t,n)=>Math.max(t,n.value))}function EA(e){return WU(e,(t,n)=>jn(t,n.value))}function WU(e,t){if(rve(e))return je(e.condition).reduce(t,e.value);if(xo(e))return e.value}function HU(e,t,n){const r=t.get("selections");if(!(r!=null&&r.length))return;const i=De(n.field);return r.map(s=>`(!length(data(${De(_n(s)+af)})) || (${s}[${i}] && indexof(${s}[${i}], datum.value) >= 0))`).join(" || ")}const a8={direction:({direction:e})=>e,format:({fieldOrDatumDef:e,legend:t,config:n})=>{const{format:r,formatType:i}=t;return Zz(e,e.type,r,i,n,!1)},formatType:({legend:e,fieldOrDatumDef:t,scaleType:n})=>{const{formatType:r}=e;return Jz(r,t,n)},gradientLength:e=>{const{legend:t,legendConfig:n}=e;return t.gradientLength??n.gradientLength??kxe(e)},labelOverlap:({legend:e,legendConfig:t,scaleType:n})=>e.labelOverlap??t.labelOverlap??Sxe(n),symbolType:({legend:e,markDef:t,channel:n,encoding:r})=>e.symbolType??xxe(t.type,n,r.shape,t.shape),title:({fieldOrDatumDef:e,config:t})=>dd(e,t,{allowDisabling:!0}),type:({legendType:e,scaleType:t,channel:n})=>{if(fd(n)&&Qo(t)){if(e==="gradient")return}else if(e==="symbol")return;return e},values:({fieldOrDatumDef:e,legend:t})=>bxe(t,e)};function bxe(e,t){const n=e.values;if(fe(n))return cj(t,n);if(tt(n))return n}function xxe(e,t,n,r){if(t!=="shape"){const i=EA(n)??r;if(i)return i}switch(e){case"bar":case"rect":case"image":case"square":return"square";case"line":case"trail":case"rule":return"stroke";case"arc":case"point":case"circle":case"tick":case"geoshape":case"area":case"text":return"circle"}}function _xe(e){const{legend:t}=e;return jn(t.type,wxe(e))}function wxe({channel:e,timeUnit:t,scaleType:n}){if(fd(e)){if(Tt(["quarter","month","day"],t))return"symbol";if(Qo(n))return"gradient"}return"symbol"}function Exe({legendConfig:e,legendType:t,orient:n,legend:r}){return r.direction??e[t?"gradientDirection":"symbolDirection"]??Axe(n,t)}function Axe(e,t){switch(e){case"top":case"bottom":return"horizontal";case"left":case"right":case"none":case void 0:return;default:return t==="gradient"?"horizontal":void 0}}function kxe({legendConfig:e,model:t,direction:n,orient:r,scaleType:i}){const{gradientHorizontalMaxLength:s,gradientHorizontalMinLength:o,gradientVerticalMaxLength:a,gradientVerticalMinLength:l}=e;if(Qo(i))return n==="horizontal"?r==="top"||r==="bottom"?l8(t,"width",o,s):o:l8(t,"height",l,a)}function l8(e,t,n,r){return{signal:`clamp(${e.getSizeSignalRef(t).signal}, ${n}, ${r})`}}function Sxe(e){if(Tt(["quantile","threshold","log","symlog"],e))return"greedy"}function GU(e){const t=Cn(e)?Cxe(e):Mxe(e);return e.component.legends=t,t}function Cxe(e){const{encoding:t}=e,n={};for(const r of[qi,...Tj]){const i=Jn(t[r]);!i||!e.getScaleComponent(r)||r===Wi&&$e(i)&&i.type===Nh||(n[r]=Dxe(e,r))}return n}function $xe(e,t){const n=e.scaleName(t);if(e.mark==="trail"){if(t==="color")return{stroke:n};if(t==="size")return{strokeWidth:n}}return t==="color"?e.markDef.filled?{fill:n}:{stroke:n}:{[t]:n}}function Fxe(e,t,n,r){switch(t){case"disable":return n!==void 0;case"values":return!!(n!=null&&n.values);case"title":if(t==="title"&&e===(r==null?void 0:r.title))return!0}return e===(n||{})[t]}function Dxe(e,t){var _;let n=e.legend(t);const{markDef:r,encoding:i,config:s}=e,o=s.legend,a=new pxe({},$xe(e,t));Dbe(e,t,a);const l=n!==void 0?!n:o.disable;if(a.set("disable",l,n!==void 0),l)return a;n=n||{};const u=e.getScaleComponent(t).get("type"),c=Jn(i[t]),f=$e(c)?(_=dr(c.timeUnit))==null?void 0:_.unit:void 0,d=n.orient||s.legend.orient||"right",h=_xe({legend:n,channel:t,timeUnit:f,scaleType:u}),p=Exe({legend:n,legendType:h,orient:d,legendConfig:o}),g={legend:n,channel:t,model:e,markDef:r,encoding:i,fieldOrDatumDef:c,legendConfig:o,config:s,scaleType:u,orient:d,legendType:h,direction:p};for(const w of UU){if(h==="gradient"&&w.startsWith("symbol")||h==="symbol"&&w.startsWith("gradient"))continue;const A=w in a8?a8[w](g):n[w];if(A!==void 0){const E=Fxe(A,w,n,e.fieldDef(t));(E||s.legend[w]===void 0)&&a.set(w,A,E)}}const m=(n==null?void 0:n.encoding)??{},v=a.get("selections"),b={},x={fieldOrDatumDef:c,model:e,channel:t,legendCmpt:a,legendType:h};for(const w of["labels","legend","title","symbols","gradient","entries"]){const A=zU(m[w]??{},e),E=w in o8?o8[w](A,x):A;E!==void 0&&!an(E)&&(b[w]={...v!=null&&v.length&&$e(c)?{name:`${_n(c.field)}_legend_${w}`}:{},...v!=null&&v.length?{interactive:!!v}:{},update:E})}return an(b)||a.set("encode",b,!!(n!=null&&n.encoding)),a}function Mxe(e){const{legends:t,resolve:n}=e.component;for(const r of e.children){GU(r);for(const i of Ae(r.component.legends))n.legend[i]=pF(e.component.resolve,i),n.legend[i]==="shared"&&(t[i]=YU(t[i],r.component.legends[i]),t[i]||(n.legend[i]="independent",delete t[i]))}for(const r of Ae(t))for(const i of e.children)i.component.legends[r]&&n.legend[r]==="shared"&&delete i.component.legends[r];return t}function YU(e,t){var s,o,a,l;if(!e)return t.clone();const n=e.getWithExplicit("orient"),r=t.getWithExplicit("orient");if(n.explicit&&r.explicit&&n.value!==r.value)return;let i=!1;for(const u of UU){const c=vu(e.getWithExplicit(u),t.getWithExplicit(u),u,"legend",(f,d)=>{switch(u){case"symbolType":return Txe(f,d);case"title":return mz(f,d);case"type":return i=!0,Ki("symbol")}return h2(f,d,u,"legend")});e.setWithExplicit(u,c)}return i&&((o=(s=e.implicit)==null?void 0:s.encode)!=null&&o.gradient&&ny(e.implicit,["encode","gradient"]),(l=(a=e.explicit)==null?void 0:a.encode)!=null&&l.gradient&&ny(e.explicit,["encode","gradient"])),e}function Txe(e,t){return t.value==="circle"?t:e}function Rxe(e,t,n,r){var i,s;e.encode??(e.encode={}),(i=e.encode)[t]??(i[t]={}),(s=e.encode[t]).update??(s.update={}),e.encode[t].update[n]=r}function VU(e){const t=e.component.legends,n={};for(const i of Ae(t)){const s=e.getScaleComponent(i),o=ln(s.get("domains"));if(n[o])for(const a of n[o])YU(a,t[i])||n[o].push(t[i]);else n[o]=[t[i].clone()]}return Mr(n).flat().map(i=>Nxe(i,e.config)).filter(i=>i!==void 0)}function Nxe(e,t){var o,a,l;const{disable:n,labelExpr:r,selections:i,...s}=e.combine();if(!n){if(t.aria===!1&&s.aria==null&&(s.aria=!1),(o=s.encode)!=null&&o.symbols){const u=s.encode.symbols.update;u.fill&&u.fill.value!=="transparent"&&!u.stroke&&!s.stroke&&(u.stroke={value:"transparent"});for(const c of Tj)s[c]&&delete u[c]}if(s.title||delete s.title,r!==void 0){let u=r;(l=(a=s.encode)==null?void 0:a.labels)!=null&&l.update&&tt(s.encode.labels.update.text)&&(u=Jc(r,"datum.label",s.encode.labels.update.text.signal)),Rxe(s,"labels","text",{signal:u})}return s}}function Oxe(e){return Bh(e)||xF(e)?Lxe(e):XU(e)}function Lxe(e){return e.children.reduce((t,n)=>t.concat(n.assembleProjections()),XU(e))}function XU(e){const t=e.component.projection;if(!t||t.merged)return[];const n=t.combine(),{name:r}=n;if(t.data){const i={signal:`[${t.size.map(o=>o.signal).join(", ")}]`},s=t.data.reduce((o,a)=>{const l=tt(a)?a.signal:`data('${e.lookupDataSource(a)}')`;return Tt(o,l)||o.push(l),o},[]);if(s.length<=0)throw new Error("Projection's fit didn't find any data sources");return[{name:r,size:i,fit:{signal:s.length>1?`[${s.join(", ")}]`:s[0]},...n}]}else return[{name:r,translate:{signal:"[width / 2, height / 2]"},...n}]}const Ixe=["type","clipAngle","clipExtent","center","rotate","precision","reflectX","reflectY","coefficient","distance","fraction","lobes","parallel","radius","ratio","spacing","tilt"];class KU extends El{constructor(t,n,r,i){super({...n},{name:t}),this.specifiedProjection=n,this.size=r,this.data=i,this.merged=!1}get isFit(){return!!this.data}}function ZU(e){e.component.projection=Cn(e)?Pxe(e):jxe(e)}function Pxe(e){if(e.hasProjection){const t=Ar(e.specifiedProjection),n=!(t&&(t.scale!=null||t.translate!=null)),r=n?[e.getSizeSignalRef("width"),e.getSizeSignalRef("height")]:void 0,i=n?Bxe(e):void 0,s=new KU(e.projectionName(!0),{...Ar(e.config.projection),...t},r,i);return s.get("type")||s.set("type","equalEarth",!1),s}}function Bxe(e){const t=[],{encoding:n}=e;for(const r of[[Fo,$o],[zs,Do]])(Jn(n[r[0]])||Jn(n[r[1]]))&&t.push({signal:e.getName(`geojson_${t.length}`)});return e.channelHasField(Wi)&&e.typedFieldDef(Wi).type===Nh&&t.push({signal:e.getName(`geojson_${t.length}`)}),t.length===0&&t.push(e.requestDataName($n.Main)),t}function zxe(e,t){const n=n$(Ixe,i=>!!(!We(e.explicit,i)&&!We(t.explicit,i)||We(e.explicit,i)&&We(t.explicit,i)&&ss(e.get(i),t.get(i))));if(ss(e.size,t.size)){if(n)return e;if(ss(e.explicit,{}))return t;if(ss(t.explicit,{}))return e}return null}function jxe(e){if(e.children.length===0)return;let t;for(const r of e.children)ZU(r);const n=n$(e.children,r=>{const i=r.component.projection;if(i)if(t){const s=zxe(t,i);return s&&(t=s),!!s}else return t=i,!0;else return!0});if(t&&n){const r=e.projectionName(!0),i=new KU(r,t.specifiedProjection,t.size,gt(t.data));for(const s of e.children){const o=s.component.projection;o&&(o.isFit&&i.data.push(...s.component.projection.data),s.renameProjection(o.get("name"),r),o.merged=!0)}return i}}function Uxe(e,t,n,r){if(W0(t,n)){const i=Cn(e)?e.axis(n)??e.legend(n)??{}:{},s=Ne(t,{expr:"datum"}),o=Ne(t,{expr:"datum",binSuffix:"end"});return{formulaAs:Ne(t,{binSuffix:"range",forAs:!0}),formula:z0(s,o,i.format,i.formatType,r)}}return{}}function JU(e,t){return`${lz(e)}_${t}`}function qxe(e,t){return{signal:e.getName(`${t}_bins`),extentSignal:e.getName(`${t}_extent`)}}function gF(e,t,n){const r=a2(n,void 0)??{},i=JU(r,t);return e.getName(`${i}_bins`)}function Wxe(e){return"as"in e}function u8(e,t,n){let r,i;Wxe(e)?r=ze(e.as)?[e.as,`${e.as}_end`]:[e.as[0],e.as[1]]:r=[Ne(e,{forAs:!0}),Ne(e,{binSuffix:"end",forAs:!0})];const s={...a2(t,void 0)},o=JU(s,e.field),{signal:a,extentSignal:l}=qxe(n,o);if(Kb(s.extent)){const c=s.extent;i=DU(n,c.param,c),delete s.extent}const u={bin:s,field:e.field,as:[r],...a?{signal:a}:{},...l?{extentSignal:l}:{},...i?{span:i}:{}};return{key:o,binComponent:u}}class sa extends rn{clone(){return new sa(null,gt(this.bins))}constructor(t,n){super(t),this.bins=n}static makeFromEncoding(t,n){const r=n.reduceFieldDef((i,s,o)=>{if(xi(s)&&dn(s.bin)){const{key:a,binComponent:l}=u8(s,s.bin,n);i[a]={...l,...i[a],...Uxe(n,s,o,n.config)}}return i},{});return an(r)?null:new sa(t,r)}static makeFromTransform(t,n,r){const{key:i,binComponent:s}=u8(n,n.bin,r);return new sa(t,{[i]:s})}merge(t,n){for(const r of Ae(t.bins))r in this.bins?(n(t.bins[r].signal,this.bins[r].signal),this.bins[r].as=Jo([...this.bins[r].as,...t.bins[r].as],It)):this.bins[r]=t.bins[r];for(const r of t.children)t.removeChild(r),r.parent=this;t.remove()}producedFields(){return new Set(Mr(this.bins).map(t=>t.as).flat(2))}dependentFields(){return new Set(Mr(this.bins).map(t=>t.field))}hash(){return`Bin ${It(this.bins)}`}assemble(){return Mr(this.bins).flatMap(t=>{const n=[],[r,...i]=t.as,{extent:s,...o}=t.bin,a={type:"bin",field:Bs(t.field),as:r,signal:t.signal,...Kb(s)?{extent:null}:{extent:s},...t.span?{span:{signal:`span(${t.span})`}}:{},...o};!s&&t.extentSignal&&(n.push({type:"extent",field:Bs(t.field),signal:t.extentSignal}),a.extent={signal:t.extentSignal}),n.push(a);for(const l of i)for(let u=0;u<2;u++)n.push({type:"formula",expr:Ne({field:r[u]},{expr:"datum"}),as:l[u]});return t.formula&&n.push({type:"formula",expr:t.formula,as:t.formulaAs}),n})}}function Hxe(e,t,n,r){var s;const i=Cn(r)?r.encoding[Ca(t)]:void 0;if(xi(n)&&Cn(r)&&nj(n,i,r.markDef,r.config)){e.add(Ne(n,{})),e.add(Ne(n,{suffix:"end"}));const{mark:o,markDef:a,config:l}=r,u=mu({fieldDef:n,markDef:a,config:l});Lg(o)&&u!==.5&&Un(t)&&(e.add(Ne(n,{suffix:p2})),e.add(Ne(n,{suffix:g2}))),n.bin&&W0(n,t)&&e.add(Ne(n,{binSuffix:"range"}))}else if(QB(t)){const o=JB(t);e.add(r.getName(o))}else e.add(Ne(n));return Sf(n)&&E1e((s=n.scale)==null?void 0:s.range)&&e.add(n.scale.range.field),e}function Gxe(e,t){for(const n of Ae(t)){const r=t[n];for(const i of Ae(r))n in e?e[n][i]=new Set([...e[n][i]??[],...r[i]]):e[n]={[i]:r[i]}}}class ho extends rn{clone(){return new ho(null,new Set(this.dimensions),gt(this.measures))}constructor(t,n,r){super(t),this.dimensions=n,this.measures=r}get groupBy(){return this.dimensions}static makeFromEncoding(t,n){let r=!1;n.forEachFieldDef(o=>{o.aggregate&&(r=!0)});const i={},s=new Set;return!r||(n.forEachFieldDef((o,a)=>{const{aggregate:l,field:u}=o;if(l)if(l==="count")i["*"]??(i["*"]={}),i["*"].count=new Set([Ne(o,{forAs:!0})]);else{if(dl(l)||Lu(l)){const c=dl(l)?"argmin":"argmax",f=l[c];i[f]??(i[f]={}),i[f][c]=new Set([Ne({op:c,field:f},{forAs:!0})])}else i[u]??(i[u]={}),i[u][l]=new Set([Ne(o,{forAs:!0})]);$a(a)&&n.scaleDomain(a)==="unaggregated"&&(i[u]??(i[u]={}),i[u].min=new Set([Ne({field:u,aggregate:"min"},{forAs:!0})]),i[u].max=new Set([Ne({field:u,aggregate:"max"},{forAs:!0})]))}else Hxe(s,a,o,n)}),s.size+Ae(i).length===0)?null:new ho(t,s,i)}static makeFromTransform(t,n){var r;const i=new Set,s={};for(const o of n.aggregate){const{op:a,field:l,as:u}=o;a&&(a==="count"?(s["*"]??(s["*"]={}),s["*"].count=new Set([u||Ne(o,{forAs:!0})])):(s[l]??(s[l]={}),(r=s[l])[a]??(r[a]=new Set),s[l][a].add(u||Ne(o,{forAs:!0}))))}for(const o of n.groupby??[])i.add(o);return i.size+Ae(s).length===0?null:new ho(t,i,s)}merge(t){return WB(this.dimensions,t.dimensions)?(Gxe(this.measures,t.measures),!0):(Vme("different dimensions, cannot merge"),!1)}addDimensions(t){t.forEach(this.dimensions.add,this.dimensions)}dependentFields(){return new Set([...this.dimensions,...Ae(this.measures)])}producedFields(){const t=new Set;for(const n of Ae(this.measures))for(const r of Ae(this.measures[n])){const i=this.measures[n][r];i.size===0?t.add(`${r}_${n}`):i.forEach(t.add,t)}return t}hash(){return`Aggregate ${It({dimensions:this.dimensions,measures:this.measures})}`}assemble(){const t=[],n=[],r=[];for(const s of Ae(this.measures))for(const o of Ae(this.measures[s]))for(const a of this.measures[s][o])r.push(a),t.push(o),n.push(s==="*"?null:Bs(s));return{type:"aggregate",groupby:[...this.dimensions].map(Bs),ops:t,fields:n,as:r}}}class Ih extends rn{constructor(t,n,r,i){super(t),this.model=n,this.name=r,this.data=i;for(const s of $s){const o=n.facet[s];if(o){const{bin:a,sort:l}=o;this[s]={name:n.getName(`${s}_domain`),fields:[Ne(o),...dn(a)?[Ne(o,{binSuffix:"end"})]:[]],...il(l)?{sortField:l}:fe(l)?{sortIndexField:lh(o,s)}:{}}}}this.childModel=n.child}hash(){let t="Facet";for(const n of $s)this[n]&&(t+=` ${n.charAt(0)}:${It(this[n])}`);return t}get fields(){var n;const t=[];for(const r of $s)(n=this[r])!=null&&n.fields&&t.push(...this[r].fields);return t}dependentFields(){const t=new Set(this.fields);for(const n of $s)this[n]&&(this[n].sortField&&t.add(this[n].sortField.field),this[n].sortIndexField&&t.add(this[n].sortIndexField));return t}producedFields(){return new Set}getSource(){return this.name}getChildIndependentFieldsWithStep(){const t={};for(const n of _l){const r=this.childModel.component.scales[n];if(r&&!r.merged){const i=r.get("type"),s=r.get("range");if(pr(i)&&Ef(s)){const o=A2(this.childModel,n),a=bF(o);a?t[n]=a:Ce(m$(n))}}}return t}assembleRowColumnHeaderData(t,n,r){const i={row:"y",column:"x",facet:void 0}[t],s=[],o=[],a=[];i&&r&&r[i]&&(n?(s.push(`distinct_${r[i]}`),o.push("max")):(s.push(r[i]),o.push("distinct")),a.push(`distinct_${r[i]}`));const{sortField:l,sortIndexField:u}=this[t];if(l){const{op:c=i2,field:f}=l;s.push(f),o.push(c),a.push(Ne(l,{forAs:!0}))}else u&&(s.push(u),o.push("max"),a.push(u));return{name:this[t].name,source:n??this.data,transform:[{type:"aggregate",groupby:this[t].fields,...s.length?{fields:s,ops:o,as:a}:{}}]}}assembleFacetHeaderData(t){var l;const{columns:n}=this.model.layout,{layoutHeaders:r}=this.model.component,i=[],s={};for(const u of fF){for(const c of dF){const f=(r[u]&&r[u][c])??[];for(const d of f)if(((l=d.axes)==null?void 0:l.length)>0){s[u]=!0;break}}if(s[u]){const c=`length(data("${this.facet.name}"))`,f=u==="row"?n?{signal:`ceil(${c} / ${n})`}:1:n?{signal:`min(${c}, ${n})`}:{signal:c};i.push({name:`${this.facet.name}_${u}`,transform:[{type:"sequence",start:0,stop:f}]})}}const{row:o,column:a}=s;return(o||a)&&i.unshift(this.assembleRowColumnHeaderData("facet",null,t)),i}assemble(){const t=[];let n=null;const r=this.getChildIndependentFieldsWithStep(),{column:i,row:s,facet:o}=this;if(i&&s&&(r.x||r.y)){n=`cross_${this.column.name}_${this.row.name}`;const a=[].concat(r.x??[],r.y??[]),l=a.map(()=>"distinct");t.push({name:n,source:this.data,transform:[{type:"aggregate",groupby:this.fields,fields:a,ops:l}]})}for(const a of[rl,nl])this[a]&&t.push(this.assembleRowColumnHeaderData(a,n,r));if(o){const a=this.assembleFacetHeaderData(r);a&&t.push(...a)}return t}}function c8(e){return e.startsWith("'")&&e.endsWith("'")||e.startsWith('"')&&e.endsWith('"')?e.slice(1,-1):e}function Yxe(e,t){const n=s$(e);if(t==="number")return`toNumber(${n})`;if(t==="boolean")return`toBoolean(${n})`;if(t==="string")return`toString(${n})`;if(t==="date")return`toDate(${n})`;if(t==="flatten")return n;if(t.startsWith("date:")){const r=c8(t.slice(5,t.length));return`timeParse(${n},'${r}')`}else if(t.startsWith("utc:")){const r=c8(t.slice(4,t.length));return`utcParse(${n},'${r}')`}else return Ce(rme(t)),null}function Vxe(e){const t={};return $1(e.filter,n=>{if(Rz(n)){let r=null;w$(n)?r=ns(n.equal):A$(n)?r=ns(n.lte):E$(n)?r=ns(n.lt):k$(n)?r=ns(n.gt):S$(n)?r=ns(n.gte):C$(n)?r=n.range[0]:$$(n)&&(r=(n.oneOf??n.in)[0]),r&&(Af(r)?t[n.field]="date":Gt(r)?t[n.field]="number":ze(r)&&(t[n.field]="string")),n.timeUnit&&(t[n.field]="date")}}),t}function Xxe(e){const t={};function n(r){ih(r)?t[r.field]="date":r.type==="quantitative"&&M0e(r.aggregate)?t[r.field]="number":Jd(r.field)>1?r.field in t||(t[r.field]="flatten"):Sf(r)&&il(r.sort)&&Jd(r.sort.field)>1&&(r.sort.field in t||(t[r.sort.field]="flatten"))}if((Cn(e)||cs(e))&&e.forEachFieldDef((r,i)=>{if(xi(r))n(r);else{const s=_f(i),o=e.fieldDef(s);n({...r,type:o.type})}}),Cn(e)){const{mark:r,markDef:i,encoding:s}=e;if(Iu(r)&&!e.encoding.order){const o=i.orient==="horizontal"?"y":"x",a=s[o];$e(a)&&a.type==="quantitative"&&!(a.field in t)&&(t[a.field]="number")}}return t}function Kxe(e){const t={};if(Cn(e)&&e.component.selection)for(const n of Ae(e.component.selection)){const r=e.component.selection[n];for(const i of r.project.items)!i.channel&&Jd(i.field)>1&&(t[i.field]="flatten")}return t}class Gr extends rn{clone(){return new Gr(null,gt(this._parse))}constructor(t,n){super(t),this._parse=n}hash(){return`Parse ${It(this._parse)}`}static makeExplicit(t,n,r){var o;let i={};const s=n.data;return!nu(s)&&((o=s==null?void 0:s.format)!=null&&o.parse)&&(i=s.format.parse),this.makeWithAncestors(t,i,{},r)}static makeWithAncestors(t,n,r,i){for(const a of Ae(r)){const l=i.getWithExplicit(a);l.value!==void 0&&(l.explicit||l.value===r[a]||l.value==="derived"||r[a]==="flatten"?delete r[a]:Ce(h6(a,r[a],l.value)))}for(const a of Ae(n)){const l=i.get(a);l!==void 0&&(l===n[a]?delete n[a]:Ce(h6(a,n[a],l)))}const s=new El(n,r);i.copyAll(s);const o={};for(const a of Ae(s.combine())){const l=s.get(a);l!==null&&(o[a]=l)}return Ae(o).length===0||i.parseNothing?null:new Gr(t,o)}get parse(){return this._parse}merge(t){this._parse={...this._parse,...t.parse},t.remove()}assembleFormatParse(){const t={};for(const n of Ae(this._parse)){const r=this._parse[n];Jd(n)===1&&(t[n]=r)}return t}producedFields(){return new Set(Ae(this._parse))}dependentFields(){return new Set(Ae(this._parse))}assembleTransforms(t=!1){return Ae(this._parse).filter(n=>t?Jd(n)>1:!0).map(n=>{const r=Yxe(n,this._parse[n]);return r?{type:"formula",expr:r,as:Th(n)}:null}).filter(n=>n!==null)}}class yu extends rn{clone(){return new yu(null)}constructor(t){super(t)}dependentFields(){return new Set}producedFields(){return new Set([wo])}hash(){return"Identifier"}assemble(){return{type:"identifier",as:wo}}}class K0 extends rn{clone(){return new K0(null,this.params)}constructor(t,n){super(t),this.params=n}dependentFields(){return new Set}producedFields(){}hash(){return`Graticule ${It(this.params)}`}assemble(){return{type:"graticule",...this.params===!0?{}:this.params}}}class Z0 extends rn{clone(){return new Z0(null,this.params)}constructor(t,n){super(t),this.params=n}dependentFields(){return new Set}producedFields(){return new Set([this.params.as??"data"])}hash(){return`Hash ${It(this.params)}`}assemble(){return{type:"sequence",...this.params}}}class cf extends rn{constructor(t){super(null),t??(t={name:"source"});let n;if(nu(t)||(n=t.format?{...Pi(t.format,["parse"])}:{}),Ig(t))this._data={values:t.values};else if(sh(t)){if(this._data={url:t.url},!n.type){let r=/(?:\.([^.]+))?$/.exec(t.url)[1];Tt(["json","csv","tsv","dsv","topojson"],r)||(r="json"),n.type=r}}else Kj(t)?this._data={values:[{type:"Sphere"}]}:(Vj(t)||nu(t))&&(this._data={});this._generator=nu(t),t.name&&(this._name=t.name),n&&!an(n)&&(this._data.format=n)}dependentFields(){return new Set}producedFields(){}get data(){return this._data}hasName(){return!!this._name}get isGenerator(){return this._generator}get dataName(){return this._name}set dataName(t){this._name=t}set parent(t){throw new Error("Source nodes have to be roots.")}remove(){throw new Error("Source nodes are roots and cannot be removed.")}hash(){throw new Error("Cannot hash sources")}assemble(){return{name:this._name,...this._data,transform:[]}}}var f8=function(e,t,n,r,i){if(r==="m")throw new TypeError("Private method is not writable");if(r==="a"&&!i)throw new TypeError("Private accessor was defined without a setter");if(typeof t=="function"?e!==t||!i:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return r==="a"?i.call(e,n):i?i.value=n:t.set(e,n),n},Zxe=function(e,t,n,r){if(n==="a"&&!r)throw new TypeError("Private accessor was defined without a getter");if(typeof t=="function"?e!==t||!r:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return n==="m"?r:n==="a"?r.call(e):r?r.value:t.get(e)},zp;function mF(e){return e instanceof cf||e instanceof K0||e instanceof Z0}class vF{constructor(){zp.set(this,void 0),f8(this,zp,!1,"f")}setModified(){f8(this,zp,!0,"f")}get modifiedFlag(){return Zxe(this,zp,"f")}}zp=new WeakMap;class $f extends vF{getNodeDepths(t,n,r){r.set(t,n);for(const i of t.children)this.getNodeDepths(i,n+1,r);return r}optimize(t){const r=[...this.getNodeDepths(t,0,new Map).entries()].sort((i,s)=>s[1]-i[1]);for(const i of r)this.run(i[0]);return this.modifiedFlag}}class yF extends vF{optimize(t){this.run(t);for(const n of t.children)this.optimize(n);return this.modifiedFlag}}class Jxe extends yF{mergeNodes(t,n){const r=n.shift();for(const i of n)t.removeChild(i),i.parent=r,i.remove()}run(t){const n=t.children.map(i=>i.hash()),r={};for(let i=0;i1&&(this.setModified(),this.mergeNodes(t,r[i]))}}class Qxe extends yF{constructor(t){super(),this.requiresSelectionId=t&&aF(t)}run(t){t instanceof yu&&(this.requiresSelectionId&&(mF(t.parent)||t.parent instanceof ho||t.parent instanceof Gr)||(this.setModified(),t.remove()))}}class e_e extends vF{optimize(t){return this.run(t,new Set),this.modifiedFlag}run(t,n){let r=new Set;t instanceof ra&&(r=t.producedFields(),r$(r,n)&&(this.setModified(),t.removeFormulas(n),t.producedFields.length===0&&t.remove()));for(const i of t.children)this.run(i,new Set([...n,...r]))}}class t_e extends yF{constructor(){super()}run(t){t instanceof Bi&&!t.isRequired()&&(this.setModified(),t.remove())}}class n_e extends $f{run(t){if(!mF(t)&&!(t.numChildren()>1)){for(const n of t.children)if(n instanceof Gr)if(t instanceof Gr)this.setModified(),t.merge(n);else{if(i$(t.producedFields(),n.dependentFields()))continue;this.setModified(),n.swapWithParent()}}}}class r_e extends $f{run(t){const n=[...t.children],r=t.children.filter(i=>i instanceof Gr);if(t.numChildren()>1&&r.length>=1){const i={},s=new Set;for(const o of r){const a=o.parse;for(const l of Ae(a))l in i?i[l]!==a[l]&&s.add(l):i[l]=a[l]}for(const o of s)delete i[o];if(!an(i)){this.setModified();const o=new Gr(t,i);for(const a of n){if(a instanceof Gr)for(const l of Ae(i))delete a.parse[l];t.removeChild(a),a.parent=o,a instanceof Gr&&Ae(a.parse).length===0&&a.remove()}}}}}class i_e extends $f{run(t){t instanceof Bi||t.numChildren()>0||t instanceof Ih||t instanceof cf||(this.setModified(),t.remove())}}class s_e extends $f{run(t){const n=t.children.filter(i=>i instanceof ra),r=n.pop();for(const i of n)this.setModified(),r.merge(i)}}class o_e extends $f{run(t){const n=t.children.filter(i=>i instanceof ho),r={};for(const i of n){const s=It(i.groupBy);s in r||(r[s]=[]),r[s].push(i)}for(const i of Ae(r)){const s=r[i];if(s.length>1){const o=s.pop();for(const a of s)o.merge(a)&&(t.removeChild(a),a.parent=o,a.remove(),this.setModified())}}}}class a_e extends $f{constructor(t){super(),this.model=t}run(t){const n=!(mF(t)||t instanceof Lh||t instanceof Gr||t instanceof yu),r=[],i=[];for(const s of t.children)s instanceof sa&&(n&&!i$(t.producedFields(),s.dependentFields())?r.push(s):i.push(s));if(r.length>0){const s=r.pop();for(const o of r)s.merge(o,this.model.renameSignal.bind(this.model));this.setModified(),t instanceof sa?t.merge(s,this.model.renameSignal.bind(this.model)):s.swapWithParent()}if(i.length>1){const s=i.pop();for(const o of i)s.merge(o,this.model.renameSignal.bind(this.model));this.setModified()}}}class l_e extends $f{run(t){const n=[...t.children];if(!Zd(n,o=>o instanceof Bi)||t.numChildren()<=1)return;const i=[];let s;for(const o of n)if(o instanceof Bi){let a=o;for(;a.numChildren()===1;){const[l]=a.children;if(l instanceof Bi)a=l;else break}i.push(...a.children),s?(t.removeChild(o),o.parent=s.parent,s.parent.removeChild(s),s.parent=a,this.setModified()):s=a}else i.push(o);if(i.length){this.setModified();for(const o of i)o.parent.removeChild(o),o.parent=s}}}class Ff extends rn{clone(){return new Ff(null,gt(this.transform))}constructor(t,n){super(t),this.transform=n}addDimensions(t){this.transform.groupby=Jo(this.transform.groupby.concat(t),n=>n)}dependentFields(){const t=new Set;return this.transform.groupby&&this.transform.groupby.forEach(t.add,t),this.transform.joinaggregate.map(n=>n.field).filter(n=>n!==void 0).forEach(t.add,t),t}producedFields(){return new Set(this.transform.joinaggregate.map(this.getDefaultName))}getDefaultName(t){return t.as??Ne(t)}hash(){return`JoinAggregateTransform ${It(this.transform)}`}assemble(){const t=[],n=[],r=[];for(const s of this.transform.joinaggregate)n.push(s.op),r.push(this.getDefaultName(s)),t.push(s.field===void 0?null:s.field);const i=this.transform.groupby;return{type:"joinaggregate",as:r,ops:n,fields:t,...i!==void 0?{groupby:i}:{}}}}class ch extends rn{clone(){return new ch(null,{...this.filter})}constructor(t,n){super(t),this.filter=n}static make(t,n,r){const{config:i,markDef:s}=n,{marks:o,scales:a}=r;if(o==="include-invalid-values"&&a==="include-invalid-values")return null;const l=n.reduceFieldDef((u,c,f)=>{const d=$a(f)&&n.getScaleComponent(f);if(d){const h=d.get("type"),{aggregate:p}=c,g=O$({scaleChannel:f,markDef:s,config:i,scaleType:h,isCountAggregate:Xb(p)});g!=="show"&&g!=="always-valid"&&(u[c.field]=c)}return u},{});return Ae(l).length?new ch(t,l):null}dependentFields(){return new Set(Ae(this.filter))}producedFields(){return new Set}hash(){return`FilterInvalid ${It(this.filter)}`}assemble(){const t=Ae(this.filter).reduce((n,r)=>{const i=this.filter[r],s=Ne(i,{expr:"datum"});return i!==null&&(i.type==="temporal"?n.push(`(isDate(${s}) || (${AA(s)}))`):i.type==="quantitative"&&n.push(AA(s))),n},[]);return t.length>0?{type:"filter",expr:t.join(" && ")}:null}}function AA(e){return`isValid(${e}) && isFinite(+${e})`}function u_e(e){return e.stack.stackBy.reduce((t,n)=>{const r=n.fieldDef,i=Ne(r);return i&&t.push(i),t},[])}function c_e(e){return fe(e)&&e.every(t=>ze(t))&&e.length>1}class ol extends rn{clone(){return new ol(null,gt(this._stack))}constructor(t,n){super(t),this._stack=n}static makeFromTransform(t,n){const{stack:r,groupby:i,as:s,offset:o="zero"}=n,a=[],l=[];if(n.sort!==void 0)for(const f of n.sort)a.push(f.field),l.push(jn(f.order,"ascending"));const u={field:a,order:l};let c;return c_e(s)?c=s:ze(s)?c=[s,`${s}_end`]:c=[`${n.stack}_start`,`${n.stack}_end`],new ol(t,{dimensionFieldDefs:[],stackField:r,groupby:i,offset:o,sort:u,facetby:[],as:c})}static makeFromEncoding(t,n){const r=n.stack,{encoding:i}=n;if(!r)return null;const{groupbyChannels:s,fieldChannel:o,offset:a,impute:l}=r,u=s.map(h=>{const p=i[h];return _o(p)}).filter(h=>!!h),c=u_e(n),f=n.encoding.order;let d;if(fe(f)||$e(f))d=hz(f);else{const h=rj(f)?f.sort:o==="y"?"descending":"ascending";d=c.reduce((p,g)=>(p.field.includes(g)||(p.field.push(g),p.order.push(h)),p),{field:[],order:[]})}return new ol(t,{dimensionFieldDefs:u,stackField:n.vgField(o),facetby:[],stackby:c,sort:d,offset:a,impute:l,as:[n.vgField(o,{suffix:"start",forAs:!0}),n.vgField(o,{suffix:"end",forAs:!0})]})}get stack(){return this._stack}addDimensions(t){this._stack.facetby.push(...t)}dependentFields(){const t=new Set;return t.add(this._stack.stackField),this.getGroupbyFields().forEach(t.add,t),this._stack.facetby.forEach(t.add,t),this._stack.sort.field.forEach(t.add,t),t}producedFields(){return new Set(this._stack.as)}hash(){return`Stack ${It(this._stack)}`}getGroupbyFields(){const{dimensionFieldDefs:t,impute:n,groupby:r}=this._stack;return t.length>0?t.map(i=>i.bin?n?[Ne(i,{binSuffix:"mid"})]:[Ne(i,{}),Ne(i,{binSuffix:"end"})]:[Ne(i)]).flat():r??[]}assemble(){const t=[],{facetby:n,dimensionFieldDefs:r,stackField:i,stackby:s,sort:o,offset:a,impute:l,as:u}=this._stack;if(l)for(const c of r){const{bandPosition:f=.5,bin:d}=c;if(d){const h=Ne(c,{expr:"datum"}),p=Ne(c,{expr:"datum",binSuffix:"end"});t.push({type:"formula",expr:`${AA(h)} ? ${f}*${h}+${1-f}*${p} : ${h}`,as:Ne(c,{binSuffix:"mid",forAs:!0})})}t.push({type:"impute",field:i,groupby:[...s,...n],key:Ne(c,{binSuffix:"mid"}),method:"value",value:0})}return t.push({type:"stack",groupby:[...this.getGroupbyFields(),...n],field:i,sort:o,as:u,offset:a}),t}}class Ph extends rn{clone(){return new Ph(null,gt(this.transform))}constructor(t,n){super(t),this.transform=n}addDimensions(t){this.transform.groupby=Jo(this.transform.groupby.concat(t),n=>n)}dependentFields(){const t=new Set;return(this.transform.groupby??[]).forEach(t.add,t),(this.transform.sort??[]).forEach(n=>t.add(n.field)),this.transform.window.map(n=>n.field).filter(n=>n!==void 0).forEach(t.add,t),t}producedFields(){return new Set(this.transform.window.map(this.getDefaultName))}getDefaultName(t){return t.as??Ne(t)}hash(){return`WindowTransform ${It(this.transform)}`}assemble(){const t=[],n=[],r=[],i=[];for(const f of this.transform.window)n.push(f.op),r.push(this.getDefaultName(f)),i.push(f.param===void 0?null:f.param),t.push(f.field===void 0?null:f.field);const s=this.transform.frame,o=this.transform.groupby;if(s&&s[0]===null&&s[1]===null&&n.every(f=>p$(f)))return{type:"joinaggregate",as:r,ops:n,fields:t,...o!==void 0?{groupby:o}:{}};const a=[],l=[];if(this.transform.sort!==void 0)for(const f of this.transform.sort)a.push(f.field),l.push(f.order??"ascending");const u={field:a,order:l},c=this.transform.ignorePeers;return{type:"window",params:i,as:r,ops:n,fields:t,sort:u,...c!==void 0?{ignorePeers:c}:{},...o!==void 0?{groupby:o}:{},...s!==void 0?{frame:s}:{}}}}function f_e(e){function t(n){if(!(n instanceof Ih)){const r=n.clone();if(r instanceof Bi){const i=SA+r.getSource();r.setSource(i),e.model.component.data.outputNodes[i]=r}else(r instanceof ho||r instanceof ol||r instanceof Ph||r instanceof Ff)&&r.addDimensions(e.fields);for(const i of n.children.flatMap(t))i.parent=r;return[r]}return n.children.flatMap(t)}return t}function kA(e){if(e instanceof Ih)if(e.numChildren()===1&&!(e.children[0]instanceof Bi)){const t=e.children[0];(t instanceof ho||t instanceof ol||t instanceof Ph||t instanceof Ff)&&t.addDimensions(e.fields),t.swapWithParent(),kA(e)}else{const t=e.model.component.data.main;QU(t);const n=f_e(e),r=e.children.map(n).flat();for(const i of r)i.parent=t}else e.children.map(kA)}function QU(e){if(e instanceof Bi&&e.type===$n.Main&&e.numChildren()===1){const t=e.children[0];t instanceof Ih||(t.swapWithParent(),QU(e))}}const SA="scale_",Lm=5;function CA(e){for(const t of e){for(const n of t.children)if(n.parent!==t)return!1;if(!CA(t.children))return!1}return!0}function Vs(e,t){let n=!1;for(const r of t)n=e.optimize(r)||n;return n}function d8(e,t,n){let r=e.sources,i=!1;return i=Vs(new t_e,r)||i,i=Vs(new Qxe(t),r)||i,r=r.filter(s=>s.numChildren()>0),i=Vs(new i_e,r)||i,r=r.filter(s=>s.numChildren()>0),n||(i=Vs(new n_e,r)||i,i=Vs(new a_e(t),r)||i,i=Vs(new e_e,r)||i,i=Vs(new r_e,r)||i,i=Vs(new o_e,r)||i,i=Vs(new s_e,r)||i,i=Vs(new Jxe,r)||i,i=Vs(new l_e,r)||i),e.sources=r,i}function d_e(e,t){CA(e.sources);let n=0,r=0;for(let i=0;it(n))}}function eq(e){Cn(e)?h_e(e):p_e(e)}function h_e(e){const t=e.component.scales;for(const n of Ae(t)){const r=m_e(e,n);if(t[n].setWithExplicit("domains",r),y_e(e,n),e.component.data.isFaceted){let s=e;for(;!cs(s)&&s.parent;)s=s.parent;if(s.component.resolve.scale[n]==="shared")for(const a of r.value)Ka(a)&&(a.data=SA+a.data.replace(SA,""))}}}function p_e(e){for(const n of e.children)eq(n);const t=e.component.scales;for(const n of Ae(t)){let r,i=null;for(const s of e.children){const o=s.component.scales[n];if(o){r===void 0?r=o.getWithExplicit("domains"):r=vu(r,o.getWithExplicit("domains"),"domains","scale",$A);const a=o.get("selectionExtent");i&&a&&i.param!==a.param&&Ce(K0e),i=a}}t[n].setWithExplicit("domains",r),i&&t[n].set("selectionExtent",i,!0)}}function g_e(e,t,n,r){if(e==="unaggregated"){const{valid:i,reason:s}=h8(t,n);if(!i){Ce(s);return}}else if(e===void 0&&r.useUnaggregatedDomain){const{valid:i}=h8(t,n);if(i)return"unaggregated"}return e}function m_e(e,t){const n=e.getScaleComponent(t).get("type"),{encoding:r}=e,i=g_e(e.scaleDomain(t),e.typedFieldDef(t),n,e.config.scale);return i!==e.scaleDomain(t)&&(e.specifiedScales[t]={...e.specifiedScales[t],domain:i}),t==="x"&&Jn(r.x2)?Jn(r.x)?vu(Fl(n,i,e,"x"),Fl(n,i,e,"x2"),"domain","scale",$A):Fl(n,i,e,"x2"):t==="y"&&Jn(r.y2)?Jn(r.y)?vu(Fl(n,i,e,"y"),Fl(n,i,e,"y2"),"domain","scale",$A):Fl(n,i,e,"y2"):Fl(n,i,e,t)}function v_e(e,t,n){return e.map(r=>({signal:`{data: ${l2(r,{timeUnit:n,type:t})}}`}))}function E_(e,t,n){var i;const r=(i=dr(n))==null?void 0:i.unit;return t==="temporal"||r?v_e(e,t,r):[e]}function Fl(e,t,n,r){const{encoding:i,markDef:s,mark:o,config:a,stack:l}=n,u=Jn(i[r]),{type:c}=u,f=u.timeUnit,d=ebe({invalid:ha("invalid",s,a),isPath:Iu(o)});if(w1e(t)){const g=Fl(e,void 0,n,r),m=E_(t.unionWith,c,f);return jo([...m,...g.value])}else{if(tt(t))return jo([t]);if(t&&t!=="unaggregated"&&!zz(t))return jo(E_(t,c,f))}if(l&&r===l.fieldChannel){if(l.offset==="normalize")return Ki([[0,1]]);const g=n.requestDataName(d);return Ki([{data:g,field:n.vgField(r,{suffix:"start"})},{data:g,field:n.vgField(r,{suffix:"end"})}])}const h=$a(r)&&$e(u)?b_e(n,r,e):void 0;if(Fa(u)){const g=E_([u.datum],c,f);return Ki(g)}const p=u;if(t==="unaggregated"){const{field:g}=u;return Ki([{data:n.requestDataName(d),field:Ne({field:g,aggregate:"min"})},{data:n.requestDataName(d),field:Ne({field:g,aggregate:"max"})}])}else if(dn(p.bin)){if(pr(e))return Ki(e==="bin-ordinal"?[]:[{data:Ng(h)?n.requestDataName(d):n.requestDataName($n.Raw),field:n.vgField(r,W0(p,r)?{binSuffix:"range"}:{}),sort:h===!0||!Pe(h)?{field:n.vgField(r,{}),op:"min"}:h}]);{const{bin:g}=p;if(dn(g)){const m=gF(n,p.field,g);return Ki([new ir(()=>{const v=n.getSignalName(m);return`[${v}.start, ${v}.stop]`})])}else return Ki([{data:n.requestDataName(d),field:n.vgField(r,{})}])}}else if(p.timeUnit&&Tt(["time","utc"],e)){const g=i[Ca(r)];if(nj(p,g,s,a)){const m=n.requestDataName(d),v=mu({fieldDef:p,fieldDef2:g,markDef:s,config:a}),b=Lg(o)&&v!==.5&&Un(r);return Ki([{data:m,field:n.vgField(r,b?{suffix:p2}:{})},{data:m,field:n.vgField(r,{suffix:b?g2:"end"})}])}}return Ki(h?[{data:Ng(h)?n.requestDataName(d):n.requestDataName($n.Raw),field:n.vgField(r),sort:h}]:[{data:n.requestDataName(d),field:n.vgField(r)}])}function A_(e,t){const{op:n,field:r,order:i}=e;return{op:n??(t?"sum":i2),...r?{field:Bs(r)}:{},...i?{order:i}:{}}}function y_e(e,t){var a;const n=e.component.scales[t],r=e.specifiedScales[t].domain,i=(a=e.fieldDef(t))==null?void 0:a.bin,s=zz(r)?r:void 0,o=wf(i)&&Kb(i.extent)?i.extent:void 0;(s||o)&&n.set("selectionExtent",s??o,!0)}function b_e(e,t,n){if(!pr(n))return;const r=e.fieldDef(t),i=r.sort;if(ej(i))return{op:"min",field:lh(r,t),order:"ascending"};const{stack:s}=e,o=s?new Set([...s.groupbyFields,...s.stackBy.map(a=>a.fieldDef.field)]):void 0;if(il(i)){const a=s&&!o.has(i.field);return A_(i,a)}else if(eve(i)){const{encoding:a,order:l}=i,u=e.fieldDef(a),{aggregate:c,field:f}=u,d=s&&!o.has(f);if(dl(c)||Lu(c))return A_({field:Ne(u),order:l},d);if(p$(c)||!c)return A_({op:c,field:f,order:l},d)}else{if(i==="descending")return{op:"min",field:e.vgField(t),order:"descending"};if(Tt(["ascending",void 0],i))return!0}}function h8(e,t){const{aggregate:n,type:r}=e;return n?ze(n)&&!R0e.has(n)?{valid:!1,reason:kme(n)}:r==="quantitative"&&t==="log"?{valid:!1,reason:Sme(e)}:{valid:!0}:{valid:!1,reason:Ame(e)}}function $A(e,t,n,r){return e.explicit&&t.explicit&&Ce(Mme(n,r,e.value,t.value)),{explicit:e.explicit,value:[...e.value,...t.value]}}function x_e(e){const t=Jo(e.map(o=>{if(Ka(o)){const{sort:a,...l}=o;return l}return o}),It),n=Jo(e.map(o=>{if(Ka(o)){const a=o.sort;return a!==void 0&&!Ng(a)&&("op"in a&&a.op==="count"&&delete a.field,a.order==="ascending"&&delete a.order),a}}).filter(o=>o!==void 0),It);if(t.length===0)return;if(t.length===1){const o=e[0];if(Ka(o)&&n.length>0){let a=n[0];if(n.length>1){Ce(g6);const l=n.filter(u=>Pe(u)&&"op"in u&&u.op!=="min");n.every(u=>Pe(u)&&"op"in u)&&l.length===1?a=l[0]:a=!0}else if(Pe(a)&&"field"in a){const l=a.field;o.field===l&&(a=a.order?{order:a.order}:!0)}return{...o,sort:a}}return o}const r=Jo(n.map(o=>Ng(o)||!("op"in o)||ze(o.op)&&We(F0e,o.op)?o:(Ce(Rme(o)),!0)),It);let i;r.length===1?i=r[0]:r.length>1&&(Ce(g6),i=!0);const s=Jo(e.map(o=>Ka(o)?o.data:null),o=>o);return s.length===1&&s[0]!==null?{data:s[0],fields:t.map(a=>a.field),...i?{sort:i}:{}}:{fields:t,...i?{sort:i}:{}}}function bF(e){if(Ka(e)&&ze(e.field))return e.field;if(N0e(e)){let t;for(const n of e.fields)if(Ka(n)&&ze(n.field)){if(!t)t=n.field;else if(t!==n.field)return Ce(Nme),t}return Ce(Ome),t}else if(O0e(e)){Ce(Lme);const t=e.fields[0];return ze(t)?t:void 0}}function A2(e,t){const r=e.component.scales[t].get("domains").map(i=>(Ka(i)&&(i.data=e.lookupDataSource(i.data)),i));return x_e(r)}function tq(e){return Bh(e)||xF(e)?e.children.reduce((t,n)=>t.concat(tq(n)),p8(e)):p8(e)}function p8(e){return Ae(e.component.scales).reduce((t,n)=>{const r=e.component.scales[n];if(r.merged)return t;const i=r.combine(),{name:s,type:o,selectionExtent:a,domains:l,range:u,reverse:c,...f}=i,d=__e(i.range,s,n,e),h=A2(e,n),p=a?fbe(e,a,r,h):null;return t.push({name:s,type:o,...h?{domain:h}:{},...p?{domainRaw:p}:{},range:d,...c!==void 0?{reverse:c}:{},...f}),t},[])}function __e(e,t,n,r){if(Un(n)){if(Ef(e))return{step:{signal:`${t}_step`}}}else if(Pe(e)&&Ka(e))return{...e,data:r.lookupDataSource(e.data)};return e}class nq extends El{constructor(t,n){super({},{name:t}),this.merged=!1,this.setWithExplicit("type",n)}domainHasZero(){const t=this.get("type");if(Tt([kr.LOG,kr.TIME,kr.UTC],t))return"definitely-not";const n=this.get("zero");if(n===!0||n===void 0&&Tt([kr.LINEAR,kr.SQRT,kr.POW],t))return"definitely";const r=this.get("domains");if(r.length>0){let i=!1,s=!1,o=!1;for(const a of r){if(fe(a)){const l=a[0],u=a[a.length-1];if(Gt(l)&&Gt(u))if(l<=0&&u>=0){i=!0;continue}else{s=!0;continue}}o=!0}if(i)return"definitely";if(s&&!o)return"definitely-not"}return"maybe"}}const w_e=["range","scheme"];function E_e(e){const t=e.component.scales;for(const n of h$){const r=t[n];if(!r)continue;const i=A_e(n,e);r.setWithExplicit("range",i)}}function g8(e,t){const n=e.fieldDef(t);if(n!=null&&n.bin){const{bin:r,field:i}=n,s=Hi(t),o=e.getName(s);if(Pe(r)&&r.binned&&r.step!==void 0)return new ir(()=>{const a=e.scaleName(t),l=`(domain("${a}")[1] - domain("${a}")[0]) / ${r.step}`;return`${e.getSignalName(o)} / (${l})`});if(dn(r)){const a=gF(e,i,r);return new ir(()=>{const l=e.getSignalName(a),u=`(${l}.stop - ${l}.start) / ${l}.step`;return`${e.getSignalName(o)} / (${u})`})}}}function A_e(e,t){const n=t.specifiedScales[e],{size:r}=t,s=t.getScaleComponent(e).get("type");for(const f of w_e)if(n[f]!==void 0){const d=oA(s,f),h=jz(e,f);if(!d)Ce(xz(s,f,e));else if(h)Ce(h);else switch(f){case"range":{const p=n.range;if(fe(p)){if(Un(e))return jo(p.map(g=>{if(g==="width"||g==="height"){const m=t.getName(g),v=t.getSignalName.bind(t);return ir.fromName(v,m)}return g}))}else if(Pe(p))return jo({data:t.requestDataName($n.Main),field:p.field,sort:{op:"min",field:t.vgField(e)}});return jo(p)}case"scheme":return jo(k_e(n[f]))}}const o=e===wn||e==="xOffset"?"width":"height",a=r[o];if(ga(a)){if(Un(e))if(pr(s)){const f=iq(a,t,e);if(f)return jo({step:f})}else Ce(_z(o));else if(I0(e)){const f=e===Du?"x":"y";if(t.getScaleComponent(f).get("type")==="band"){const p=sq(a,s);if(p)return jo(p)}}}const{rangeMin:l,rangeMax:u}=n,c=S_e(e,t);return(l!==void 0||u!==void 0)&&oA(s,"rangeMin")&&fe(c)&&c.length===2?jo([l??c[0],u??c[1]]):Ki(c)}function k_e(e){return _1e(e)?{scheme:e.name,...Pi(e,["name"])}:{scheme:e}}function rq(e,t,n,{center:r}={}){const i=Hi(e),s=t.getName(i),o=t.getSignalName.bind(t);return e===mr&&bo(n)?r?[ir.fromName(a=>`${o(a)}/2`,s),ir.fromName(a=>`-${o(a)}/2`,s)]:[ir.fromName(o,s),0]:r?[ir.fromName(a=>`-${o(a)}/2`,s),ir.fromName(a=>`${o(a)}/2`,s)]:[0,ir.fromName(o,s)]}function S_e(e,t){const{size:n,config:r,mark:i,encoding:s}=t,{type:o}=Jn(s[e]),l=t.getScaleComponent(e).get("type"),{domain:u,domainMid:c}=t.specifiedScales[e];switch(e){case wn:case mr:{if(Tt(["point","band"],l)){const f=oq(e,n,r.view);if(ga(f))return{step:iq(f,t,e)}}return rq(e,t,l)}case Du:case Rh:return C_e(e,t,l);case bl:{const f=D_e(i,r),d=M_e(i,n,t,r);return th(l)?F_e(f,d,$_e(l,r,u,e)):[f,d]}case qs:return[0,Math.PI*2];case xf:return[0,360];case Co:return[0,new ir(()=>{const f=t.getSignalName(cs(t.parent)?"child_width":"width"),d=t.getSignalName(cs(t.parent)?"child_height":"height");return`min(${f},${d})/2`})];case Mu:return{step:1e3/r.scale.framesPerSecond};case Nu:return[r.scale.minStrokeWidth,r.scale.maxStrokeWidth];case Ou:return[[1,0],[4,2],[2,1],[1,1],[1,2,4,2]];case Wi:return"symbol";case qi:case ka:case Sa:return l==="ordinal"?o==="nominal"?"category":"ordinal":c!==void 0?"diverging":i==="rect"||i==="geoshape"?"heatmap":"ramp";case xl:case Tu:case Ru:return[r.scale.minOpacity,r.scale.maxOpacity]}}function iq(e,t,n){const{encoding:r}=t,i=t.getScaleComponent(n),s=u$(n),o=r[s];if(Nj({step:e,offsetIsDiscrete:vt(o)&&Oz(o.type)})==="offset"&&pj(r,s)){const l=t.getScaleComponent(s);let c=`domain('${t.scaleName(s)}').length`;if(l.get("type")==="band"){const d=l.get("paddingInner")??l.get("padding")??0,h=l.get("paddingOuter")??l.get("padding")??0;c=`bandspace(${c}, ${d}, ${h})`}const f=i.get("paddingInner")??i.get("padding");return{signal:`${e.step} * ${c} / (1-${B0e(f)})`}}else return e.step}function sq(e,t){if(Nj({step:e,offsetIsDiscrete:pr(t)})==="offset")return{step:e.step}}function C_e(e,t,n){const r=e===Du?"x":"y",i=t.getScaleComponent(r);if(!i)return rq(r,t,n,{center:!0});const s=i.get("type"),o=t.scaleName(r),{markDef:a,config:l}=t;if(s==="band"){const u=oq(r,t.size,t.config.view);if(ga(u)){const c=sq(u,n);if(c)return c}return[0,{signal:`bandwidth('${o}')`}]}else{const u=t.encoding[r];if($e(u)&&u.timeUnit){const c=Mz(u.timeUnit,p=>`scale('${o}', ${p})`),f=t.config.scale.bandWithNestedOffsetPaddingInner,d=mu({fieldDef:u,markDef:a,config:l})-.5,h=d!==0?` + ${d}`:"";if(f){const p=tt(f)?`${f.signal}/2`+h:`${f/2+d}`,g=tt(f)?`(1 - ${f.signal}/2)`+h:`${1-f/2+d}`;return[{signal:`${p} * (${c})`},{signal:`${g} * (${c})`}]}return[0,{signal:c}]}return UB(`Cannot use ${e} scale if ${r} scale is not discrete.`)}}function oq(e,t,n){const r=e===wn?"width":"height",i=t[r];return i||fy(n,r)}function $_e(e,t,n,r){switch(e){case"quantile":return t.scale.quantileCount;case"quantize":return t.scale.quantizeCount;case"threshold":return n!==void 0&&fe(n)?n.length+1:(Ce(Hme(r)),3)}}function F_e(e,t,n){const r=()=>{const i=uo(t),s=uo(e),o=`(${i} - ${s}) / (${n} - 1)`;return`sequence(${s}, ${i} + ${o}, ${o})`};return tt(t)?new ir(r):{signal:r()}}function D_e(e,t){switch(e){case"bar":case"tick":return t.scale.minBandSize;case"line":case"trail":case"rule":return t.scale.minStrokeWidth;case"text":return t.scale.minFontSize;case"point":case"square":case"circle":return t.scale.minSize}throw new Error(Zb("size",e))}const m8=.95;function M_e(e,t,n,r){const i={x:g8(n,"x"),y:g8(n,"y")};switch(e){case"bar":case"tick":{if(r.scale.maxBandSize!==void 0)return r.scale.maxBandSize;const s=v8(t,i,r.view);return Gt(s)?s-1:new ir(()=>`${s.signal} - 1`)}case"line":case"trail":case"rule":return r.scale.maxStrokeWidth;case"text":return r.scale.maxFontSize;case"point":case"square":case"circle":{if(r.scale.maxSize)return r.scale.maxSize;const s=v8(t,i,r.view);return Gt(s)?Math.pow(m8*s,2):new ir(()=>`pow(${m8} * ${s.signal}, 2)`)}}throw new Error(Zb("size",e))}function v8(e,t,n){const r=ga(e.width)?e.width.step:cA(n,"width"),i=ga(e.height)?e.height.step:cA(n,"height");return t.x||t.y?new ir(()=>`min(${[t.x?t.x.signal:r,t.y?t.y.signal:i].join(", ")})`):Math.min(r,i)}function aq(e,t){Cn(e)?T_e(e,t):uq(e,t)}function T_e(e,t){const n=e.component.scales,{config:r,encoding:i,markDef:s,specifiedScales:o}=e;for(const a of Ae(n)){const l=o[a],u=n[a],c=e.getScaleComponent(a),f=Jn(i[a]),d=l[t],h=c.get("type"),p=c.get("padding"),g=c.get("paddingInner"),m=oA(h,t),v=jz(a,t);if(d!==void 0&&(m?v&&Ce(v):Ce(xz(h,t,a))),m&&v===void 0)if(d!==void 0){const b=f.timeUnit,x=f.type;switch(t){case"domainMax":case"domainMin":Af(l[t])||x==="temporal"||b?u.set(t,{signal:l2(l[t],{type:x,timeUnit:b})},!0):u.set(t,l[t],!0);break;default:u.copyKeyFromObject(t,l)}}else{const b=Se(y8,t)?y8[t]({model:e,channel:a,fieldOrDatumDef:f,scaleType:h,scalePadding:p,scalePaddingInner:g,domain:l.domain,domainMin:l.domainMin,domainMax:l.domainMax,markDef:s,config:r,hasNestedOffsetScale:gj(i,a),hasSecondaryRangeChannel:!!i[Ca(a)]}):r.scale[t];b!==void 0&&u.set(t,b,!1)}}}const y8={bins:({model:e,fieldOrDatumDef:t})=>$e(t)?R_e(e,t):void 0,interpolate:({channel:e,fieldOrDatumDef:t})=>N_e(e,t.type),nice:({scaleType:e,channel:t,domain:n,domainMin:r,domainMax:i,fieldOrDatumDef:s})=>O_e(e,t,n,r,i,s),padding:({channel:e,scaleType:t,fieldOrDatumDef:n,markDef:r,config:i})=>L_e(e,t,i.scale,n,r,i.bar),paddingInner:({scalePadding:e,channel:t,markDef:n,scaleType:r,config:i,hasNestedOffsetScale:s})=>I_e(e,t,n.type,r,i.scale,s),paddingOuter:({scalePadding:e,channel:t,scaleType:n,scalePaddingInner:r,config:i,hasNestedOffsetScale:s})=>P_e(e,t,n,r,i.scale,s),reverse:({fieldOrDatumDef:e,scaleType:t,channel:n,config:r})=>{const i=$e(e)?e.sort:void 0;return B_e(t,i,n,r.scale)},zero:({channel:e,fieldOrDatumDef:t,domain:n,markDef:r,scaleType:i,config:s,hasSecondaryRangeChannel:o})=>z_e(e,t,n,r,i,s.scale,o)};function lq(e){Cn(e)?E_e(e):uq(e,"range")}function uq(e,t){const n=e.component.scales;for(const r of e.children)t==="range"?lq(r):aq(r,t);for(const r of Ae(n)){let i;for(const s of e.children){const o=s.component.scales[r];if(o){const a=o.getWithExplicit(t);i=vu(i,a,t,"scale",Yj((l,u)=>{switch(t){case"range":return l.step&&u.step?l.step-u.step:0}return 0}))}}n[r].setWithExplicit(t,i)}}function R_e(e,t){const n=t.bin;if(dn(n)){const r=gF(e,t.field,n);return new ir(()=>e.getSignalName(r))}else if(wr(n)&&wf(n)&&n.step!==void 0)return{step:n.step}}function N_e(e,t){if(Tt([qi,ka,Sa],e)&&t!=="nominal")return"hcl"}function O_e(e,t,n,r,i,s){var o;if(!((o=_o(s))!=null&&o.bin||fe(n)||i!=null||r!=null||Tt([kr.TIME,kr.UTC],e)))return Un(t)?!0:void 0}function L_e(e,t,n,r,i,s){if(Un(e)){if(Qo(t)){if(n.continuousPadding!==void 0)return n.continuousPadding;const{type:o,orient:a}=i;if(o==="bar"&&!($e(r)&&(r.bin||r.timeUnit))&&(a==="vertical"&&e==="x"||a==="horizontal"&&e==="y"))return s.continuousBandSize}if(t===kr.POINT)return n.pointPadding}}function I_e(e,t,n,r,i,s=!1){if(e===void 0){if(Un(t)){const{bandPaddingInner:o,barBandPaddingInner:a,rectBandPaddingInner:l,tickBandPaddingInner:u,bandWithNestedOffsetPaddingInner:c}=i;return s?c:jn(o,n==="bar"?a:n==="tick"?u:l)}else if(I0(t)&&r===kr.BAND)return i.offsetBandPaddingInner}}function P_e(e,t,n,r,i,s=!1){if(e===void 0){if(Un(t)){const{bandPaddingOuter:o,bandWithNestedOffsetPaddingOuter:a}=i;if(s)return a;if(n===kr.BAND)return jn(o,tt(r)?{signal:`${r.signal}/2`}:r/2)}else if(I0(t)){if(n===kr.POINT)return .5;if(n===kr.BAND)return i.offsetBandPaddingOuter}}}function B_e(e,t,n,r){if(n==="x"&&r.xReverse!==void 0)return bo(e)&&t==="descending"?tt(r.xReverse)?{signal:`!${r.xReverse.signal}`}:!r.xReverse:r.xReverse;if(bo(e)&&t==="descending")return!0}function z_e(e,t,n,r,i,s,o){if(!!n&&n!=="unaggregated"&&bo(i)){if(fe(n)){const l=n[0],u=n[n.length-1];if(Gt(l)&&l<=0&&Gt(u)&&u>=0)return!0}return!1}if(e==="size"&&t.type==="quantitative"&&!th(i))return!0;if(!($e(t)&&t.bin)&&Tt([..._l,...x0e],e)){const{orient:l,type:u}=r;return Tt(["bar","area","line","trail"],u)&&(l==="horizontal"&&e==="y"||l==="vertical"&&e==="x")?!1:Tt(["bar","area"],u)&&!o?!0:s==null?void 0:s.zero}return!1}function j_e(e,t,n,r,i=!1){const s=U_e(t,n,r,i),{type:o}=e;return $a(t)?o!==void 0?$1e(t,o)?$e(n)&&!C1e(o,n.type)?(Ce(Fme(o,s)),s):o:(Ce($me(t,o,s)),s):s:null}function U_e(e,t,n,r){var i;switch(t.type){case"nominal":case"ordinal":{if(fd(e)||u_(e)==="discrete")return e==="shape"&&t.type==="ordinal"&&Ce(c_(e,"ordinal")),"ordinal";if(l_(e))return"band";if(Un(e)||I0(e)){if(Tt(["rect","bar","image","rule","tick"],n.type)||r)return"band"}else if(n.type==="arc"&&e in d$)return"band";const s=n[Hi(e)];return rf(s)||rh(t)&&((i=t.axis)!=null&&i.tickBand)?"band":"point"}case"temporal":return fd(e)?"time":u_(e)==="discrete"?(Ce(c_(e,"temporal")),"ordinal"):$e(t)&&t.timeUnit&&dr(t.timeUnit).utc?"utc":l_(e)?"band":"time";case"quantitative":return fd(e)?$e(t)&&dn(t.bin)?"bin-ordinal":"linear":u_(e)==="discrete"?(Ce(c_(e,"quantitative")),"ordinal"):l_(e)?"band":"linear";case"geojson":return}throw new Error(yz(t.type))}function q_e(e,{ignoreRange:t}={}){cq(e),eq(e);for(const n of S1e)aq(e,n);t||lq(e)}function cq(e){Cn(e)?e.component.scales=W_e(e):e.component.scales=G_e(e)}function W_e(e){const{encoding:t,mark:n,markDef:r}=e,i={};for(const s of h$){const o=Jn(t[s]);if(o&&n===Wz&&s===Wi&&o.type===Nh)continue;let a=o&&o.scale;if(o&&a!==null&&a!==!1){a??(a={});const l=gj(t,s),u=j_e(a,s,o,r,l);i[s]=new nq(e.scaleName(`${s}`,!0),{value:u,explicit:a.type===u})}}return i}const H_e=Yj((e,t)=>v6(e)-v6(t));function G_e(e){var t;const n=e.component.scales={},r={},i=e.component.resolve;for(const s of e.children){cq(s);for(const o of Ae(s.component.scales))if((t=i.scale)[o]??(t[o]=jU(o,e)),i.scale[o]==="shared"){const a=r[o],l=s.component.scales[o].getWithExplicit("type");a?m1e(a.value,l.value)?r[o]=vu(a,l,"type","scale",H_e):(i.scale[o]="independent",delete r[o]):r[o]=l}}for(const s of Ae(r)){const o=e.scaleName(s,!0),a=r[s];n[s]=new nq(o,a);for(const l of e.children){const u=l.component.scales[s];u&&(l.renameScale(u.get("name"),o),u.merged=!0)}}return n}class k_{constructor(){this.nameMap={}}rename(t,n){this.nameMap[t]=n}has(t){return this.nameMap[t]!==void 0}get(t){for(;this.nameMap[t]&&t!==this.nameMap[t];)t=this.nameMap[t];return t}}function Cn(e){return(e==null?void 0:e.type)==="unit"}function cs(e){return(e==null?void 0:e.type)==="facet"}function xF(e){return(e==null?void 0:e.type)==="concat"}function Bh(e){return(e==null?void 0:e.type)==="layer"}class _F{constructor(t,n,r,i,s,o,a){this.type=n,this.parent=r,this.config=s,this.parent=r,this.config=s,this.view=Ar(a),this.name=t.name??i,this.title=Nl(t.title)?{text:t.title}:t.title?Ar(t.title):void 0,this.scaleNameMap=r?r.scaleNameMap:new k_,this.projectionNameMap=r?r.projectionNameMap:new k_,this.signalNameMap=r?r.signalNameMap:new k_,this.data=t.data,this.description=t.description,this.transforms=Uye(t.transform??[]),this.layout=n==="layer"||n==="unit"?{}:Gve(t,n,s),this.component={data:{sources:r?r.component.data.sources:[],outputNodes:r?r.component.data.outputNodes:{},outputNodeRefCounts:r?r.component.data.outputNodeRefCounts:{},isFaceted:s2(t)||(r==null?void 0:r.component.data.isFaceted)&&t.data===void 0},layoutSize:new El,layoutHeaders:{row:{},column:{},facet:{}},mark:null,resolve:{scale:{},axis:{},legend:{},...o?gt(o):{}},selection:null,scales:null,projection:null,axes:{},legends:{}}}get width(){return this.getSizeSignalRef("width")}get height(){return this.getSizeSignalRef("height")}parse(){this.parseScale(),this.parseLayoutSize(),this.renameTopLevelLayoutSizeSignal(),this.parseSelections(),this.parseProjection(),this.parseData(),this.parseAxesAndHeaders(),this.parseLegends(),this.parseMarkGroup()}parseScale(){q_e(this)}parseProjection(){ZU(this)}renameTopLevelLayoutSizeSignal(){this.getName("width")!=="width"&&this.renameSignal(this.getName("width"),"width"),this.getName("height")!=="height"&&this.renameSignal(this.getName("height"),"height")}parseLegends(){GU(this)}assembleEncodeFromView(t){const{style:n,...r}=t,i={};for(const s of Ae(r)){const o=r[s];o!==void 0&&(i[s]=vn(o))}return i}assembleGroupEncodeEntry(t){let n={};return this.view&&(n=this.assembleEncodeFromView(this.view)),!t&&(this.description&&(n.description=vn(this.description)),this.type==="unit"||this.type==="layer")?{width:this.getSizeSignalRef("width"),height:this.getSizeSignalRef("height"),...n}:an(n)?void 0:n}assembleLayout(){if(!this.layout)return;const{spacing:t,...n}=this.layout,{component:r,config:i}=this,s=dxe(r.layoutHeaders,i);return{padding:t,...this.assembleDefaultLayout(),...n,...s?{titleBand:s}:{}}}assembleDefaultLayout(){return{}}assembleHeaderMarks(){const{layoutHeaders:t}=this.component;let n=[];for(const r of $s)t[r].title&&n.push(oxe(this,r));for(const r of fF)n=n.concat(axe(this,r));return n}assembleAxes(){return Y2e(this.component.axes,this.config)}assembleLegends(){return VU(this)}assembleProjections(){return Oxe(this)}assembleTitle(){const{encoding:t,...n}=this.title??{},r={...uz(this.config.title).nonMarkTitleProperties,...n,...t?{encode:{update:t}}:{}};if(r.text)return Tt(["unit","layer"],this.type)?Tt(["middle",void 0],r.anchor)&&(r.frame??(r.frame="group")):r.anchor??(r.anchor="start"),an(r)?void 0:r}assembleGroup(t=[]){const n={};t=t.concat(this.assembleSignals()),t.length>0&&(n.signals=t);const r=this.assembleLayout();r&&(n.layout=r),n.marks=[].concat(this.assembleHeaderMarks(),this.assembleMarks());const i=!this.parent||cs(this.parent)?tq(this):[];i.length>0&&(n.scales=i);const s=this.assembleAxes();s.length>0&&(n.axes=s);const o=this.assembleLegends();return o.length>0&&(n.legends=o),n}getName(t){return _n((this.name?`${this.name}_`:"")+t)}getDataName(t){return this.getName($n[t].toLowerCase())}requestDataName(t){const n=this.getDataName(t),r=this.component.data.outputNodeRefCounts;return r[n]=(r[n]||0)+1,n}getSizeSignalRef(t){if(cs(this.parent)){const n=BU(t),r=Vb(n),i=this.component.scales[r];if(i&&!i.merged){const s=i.get("type"),o=i.get("range");if(pr(s)&&Ef(o)){const a=i.get("name"),l=A2(this,r),u=bF(l);if(u){const c=Ne({aggregate:"distinct",field:u},{expr:"datum"});return{signal:PU(a,i,c)}}else return Ce(m$(r)),null}}}return{signal:this.signalNameMap.get(this.getName(t))}}lookupDataSource(t){const n=this.component.data.outputNodes[t];return n?n.getSource():t}getSignalName(t){return this.signalNameMap.get(t)}renameSignal(t,n){this.signalNameMap.rename(t,n)}renameScale(t,n){this.scaleNameMap.rename(t,n)}renameProjection(t,n){this.projectionNameMap.rename(t,n)}scaleName(t,n){if(n)return this.getName(t);if(tz(t)&&$a(t)&&this.component.scales[t]||this.scaleNameMap.has(this.getName(t)))return this.scaleNameMap.get(this.getName(t))}projectionName(t){if(t)return this.getName("projection");if(this.component.projection&&!this.component.projection.merged||this.projectionNameMap.has(this.getName("projection")))return this.projectionNameMap.get(this.getName("projection"))}getScaleComponent(t){if(!this.component.scales)throw new Error("getScaleComponent cannot be called before parseScale(). Make sure you have called parseScale or use parseUnitModelWithScale().");const n=this.component.scales[t];return n&&!n.merged?n:this.parent?this.parent.getScaleComponent(t):void 0}getScaleType(t){const n=this.getScaleComponent(t);return n?n.get("type"):void 0}getSelectionComponent(t,n){let r=this.component.selection[t];if(!r&&this.parent&&(r=this.parent.getSelectionComponent(t,n)),!r)throw new Error(W0e(n));return r}hasAxisOrientSignalRef(){var t,n;return((t=this.component.axes.x)==null?void 0:t.some(r=>r.hasOrientSignalRef()))||((n=this.component.axes.y)==null?void 0:n.some(r=>r.hasOrientSignalRef()))}}class fq extends _F{vgField(t,n={}){const r=this.fieldDef(t);if(r)return Ne(r,n)}reduceFieldDef(t,n){return _ve(this.getMapping(),(r,i,s)=>{const o=_o(i);return o?t(r,o,s):r},n)}forEachFieldDef(t,n){W$(this.getMapping(),(r,i)=>{const s=_o(r);s&&t(s,i)},n)}}class k2 extends rn{clone(){return new k2(null,gt(this.transform))}constructor(t,n){super(t),this.transform=n,this.transform=gt(n);const r=this.transform.as??[void 0,void 0];this.transform.as=[r[0]??"value",r[1]??"density"];const i=this.transform.resolve??"shared";this.transform.resolve=i}dependentFields(){return new Set([this.transform.density,...this.transform.groupby??[]])}producedFields(){return new Set(this.transform.as)}hash(){return`DensityTransform ${It(this.transform)}`}assemble(){const{density:t,...n}=this.transform,r={type:"kde",field:t,...n};return r.resolve=this.transform.resolve,r}}class S2 extends rn{clone(){return new S2(null,gt(this.transform))}constructor(t,n){super(t),this.transform=n,this.transform=gt(n)}dependentFields(){return new Set([this.transform.extent])}producedFields(){return new Set([])}hash(){return`ExtentTransform ${It(this.transform)}`}assemble(){const{extent:t,param:n}=this.transform;return{type:"extent",field:t,signal:n}}}class C2 extends rn{clone(){return new C2(this.parent,gt(this.transform))}constructor(t,n){super(t),this.transform=n,this.transform=gt(n);const{flatten:r,as:i=[]}=this.transform;this.transform.as=r.map((s,o)=>i[o]??s)}dependentFields(){return new Set(this.transform.flatten)}producedFields(){return new Set(this.transform.as)}hash(){return`FlattenTransform ${It(this.transform)}`}assemble(){const{flatten:t,as:n}=this.transform;return{type:"flatten",fields:t,as:n}}}class $2 extends rn{clone(){return new $2(null,gt(this.transform))}constructor(t,n){super(t),this.transform=n,this.transform=gt(n);const r=this.transform.as??[void 0,void 0];this.transform.as=[r[0]??"key",r[1]??"value"]}dependentFields(){return new Set(this.transform.fold)}producedFields(){return new Set(this.transform.as)}hash(){return`FoldTransform ${It(this.transform)}`}assemble(){const{fold:t,as:n}=this.transform;return{type:"fold",fields:t,as:n}}}class pd extends rn{clone(){return new pd(null,gt(this.fields),this.geojson,this.signal)}static parseAll(t,n){if(n.component.projection&&!n.component.projection.isFit)return t;let r=0;for(const i of[[Fo,$o],[zs,Do]]){const s=i.map(o=>{const a=Jn(n.encoding[o]);return $e(a)?a.field:Fa(a)?{expr:`${a.datum}`}:xo(a)?{expr:`${a.value}`}:void 0});(s[0]||s[1])&&(t=new pd(t,s,null,n.getName(`geojson_${r++}`)))}if(n.channelHasField(Wi)){const i=n.typedFieldDef(Wi);i.type===Nh&&(t=new pd(t,null,i.field,n.getName(`geojson_${r++}`)))}return t}constructor(t,n,r,i){super(t),this.fields=n,this.geojson=r,this.signal=i}dependentFields(){const t=(this.fields??[]).filter(ze);return new Set([...this.geojson?[this.geojson]:[],...t])}producedFields(){return new Set}hash(){return`GeoJSON ${this.geojson} ${this.signal} ${It(this.fields)}`}assemble(){return[...this.geojson?[{type:"filter",expr:`isValid(datum["${this.geojson}"])`}]:[],{type:"geojson",...this.fields?{fields:this.fields}:{},...this.geojson?{geojson:this.geojson}:{},signal:this.signal}]}}class zg extends rn{clone(){return new zg(null,this.projection,gt(this.fields),gt(this.as))}constructor(t,n,r,i){super(t),this.projection=n,this.fields=r,this.as=i}static parseAll(t,n){if(!n.projectionName())return t;for(const r of[[Fo,$o],[zs,Do]]){const i=r.map(o=>{const a=Jn(n.encoding[o]);return $e(a)?a.field:Fa(a)?{expr:`${a.datum}`}:xo(a)?{expr:`${a.value}`}:void 0}),s=r[0]===zs?"2":"";(i[0]||i[1])&&(t=new zg(t,n.projectionName(),i,[n.getName(`x${s}`),n.getName(`y${s}`)]))}return t}dependentFields(){return new Set(this.fields.filter(ze))}producedFields(){return new Set(this.as)}hash(){return`Geopoint ${this.projection} ${It(this.fields)} ${It(this.as)}`}assemble(){return{type:"geopoint",projection:this.projection,fields:this.fields,as:this.as}}}class Dc extends rn{clone(){return new Dc(null,gt(this.transform))}constructor(t,n){super(t),this.transform=n}dependentFields(){return new Set([this.transform.impute,this.transform.key,...this.transform.groupby??[]])}producedFields(){return new Set([this.transform.impute])}processSequence(t){const{start:n=0,stop:r,step:i}=t;return{signal:`sequence(${[n,r,...i?[i]:[]].join(",")})`}}static makeFromTransform(t,n){return new Dc(t,n)}static makeFromEncoding(t,n){const r=n.encoding,i=r.x,s=r.y;if($e(i)&&$e(s)){const o=i.impute?i:s.impute?s:void 0;if(o===void 0)return;const a=i.impute?s:s.impute?i:void 0,{method:l,value:u,frame:c,keyvals:f}=o.impute,d=yj(n.mark,r);return new Dc(t,{impute:o.field,key:a.field,...l?{method:l}:{},...u!==void 0?{value:u}:{},...c?{frame:c}:{},...f!==void 0?{keyvals:f}:{},...d.length?{groupby:d}:{}})}return null}hash(){return`Impute ${It(this.transform)}`}assemble(){const{impute:t,key:n,keyvals:r,method:i,groupby:s,value:o,frame:a=[null,null]}=this.transform,l={type:"impute",field:t,key:n,...r?{keyvals:Eye(r)?this.processSequence(r):r}:{},method:"value",...s?{groupby:s}:{},value:!i||i==="value"?o:null};if(i&&i!=="value"){const u={type:"window",as:[`imputed_${t}_value`],ops:[i],fields:[t],frame:a,ignorePeers:!1,...s?{groupby:s}:{}},c={type:"formula",expr:`datum.${t} === null ? datum.imputed_${t}_value : datum.${t}`,as:t};return[l,u,c]}else return[l]}}class F2 extends rn{clone(){return new F2(null,gt(this.transform))}constructor(t,n){super(t),this.transform=n,this.transform=gt(n);const r=this.transform.as??[void 0,void 0];this.transform.as=[r[0]??n.on,r[1]??n.loess]}dependentFields(){return new Set([this.transform.loess,this.transform.on,...this.transform.groupby??[]])}producedFields(){return new Set(this.transform.as)}hash(){return`LoessTransform ${It(this.transform)}`}assemble(){const{loess:t,on:n,...r}=this.transform;return{type:"loess",x:n,y:t,...r}}}class jg extends rn{clone(){return new jg(null,gt(this.transform),this.secondary)}constructor(t,n,r){super(t),this.transform=n,this.secondary=r}static make(t,n,r,i){const s=n.component.data.sources,{from:o}=r;let a=null;if(Aye(o)){let l=pq(o.data,s);l||(l=new cf(o.data),s.push(l));const u=n.getName(`lookup_${i}`);a=new Bi(l,u,$n.Lookup,n.component.data.outputNodeRefCounts),n.component.data.outputNodes[u]=a}else if(kye(o)){const l=o.param;r={as:l,...r};let u;try{u=n.getSelectionComponent(_n(l),l)}catch{throw new Error(V0e(l))}if(a=u.materialized,!a)throw new Error(X0e(l))}return new jg(t,r,a.getSource())}dependentFields(){return new Set([this.transform.lookup])}producedFields(){return new Set(this.transform.as?je(this.transform.as):this.transform.from.fields)}hash(){return`Lookup ${It({transform:this.transform,secondary:this.secondary})}`}assemble(){let t;if(this.transform.from.fields)t={values:this.transform.from.fields,...this.transform.as?{as:je(this.transform.as)}:{}};else{let n=this.transform.as;ze(n)||(Ce(ome),n="_lookup"),t={as:[n]}}return{type:"lookup",from:this.secondary,key:this.transform.from.key,fields:[this.transform.lookup],...t,...this.transform.default?{default:this.transform.default}:{}}}}class D2 extends rn{clone(){return new D2(null,gt(this.transform))}constructor(t,n){super(t),this.transform=n,this.transform=gt(n);const r=this.transform.as??[void 0,void 0];this.transform.as=[r[0]??"prob",r[1]??"value"]}dependentFields(){return new Set([this.transform.quantile,...this.transform.groupby??[]])}producedFields(){return new Set(this.transform.as)}hash(){return`QuantileTransform ${It(this.transform)}`}assemble(){const{quantile:t,...n}=this.transform;return{type:"quantile",field:t,...n}}}class M2 extends rn{clone(){return new M2(null,gt(this.transform))}constructor(t,n){super(t),this.transform=n,this.transform=gt(n);const r=this.transform.as??[void 0,void 0];this.transform.as=[r[0]??n.on,r[1]??n.regression]}dependentFields(){return new Set([this.transform.regression,this.transform.on,...this.transform.groupby??[]])}producedFields(){return new Set(this.transform.as)}hash(){return`RegressionTransform ${It(this.transform)}`}assemble(){const{regression:t,on:n,...r}=this.transform;return{type:"regression",x:n,y:t,...r}}}class T2 extends rn{clone(){return new T2(null,gt(this.transform))}constructor(t,n){super(t),this.transform=n}addDimensions(t){this.transform.groupby=Jo((this.transform.groupby??[]).concat(t),n=>n)}producedFields(){}dependentFields(){return new Set([this.transform.pivot,this.transform.value,...this.transform.groupby??[]])}hash(){return`PivotTransform ${It(this.transform)}`}assemble(){const{pivot:t,value:n,groupby:r,limit:i,op:s}=this.transform;return{type:"pivot",field:t,value:n,...i!==void 0?{limit:i}:{},...s!==void 0?{op:s}:{},...r!==void 0?{groupby:r}:{}}}}class R2 extends rn{clone(){return new R2(null,gt(this.transform))}constructor(t,n){super(t),this.transform=n}dependentFields(){return new Set}producedFields(){return new Set}hash(){return`SampleTransform ${It(this.transform)}`}assemble(){return{type:"sample",size:this.transform.sample}}}function dq(e){let t=0;function n(r,i){if(r instanceof cf&&!r.isGenerator&&!sh(r.data)&&(e.push(i),i={name:null,source:i.name,transform:[]}),r instanceof Gr&&(r.parent instanceof cf&&!i.source?(i.format={...i.format,parse:r.assembleFormatParse()},i.transform.push(...r.assembleTransforms(!0))):i.transform.push(...r.assembleTransforms())),r instanceof Ih){i.name||(i.name=`data_${t++}`),!i.source||i.transform.length>0?(e.push(i),r.data=i.name):r.data=i.source,e.push(...r.assemble());return}switch((r instanceof K0||r instanceof Z0||r instanceof ch||r instanceof Lh||r instanceof ah||r instanceof zg||r instanceof ho||r instanceof jg||r instanceof Ph||r instanceof Ff||r instanceof $2||r instanceof C2||r instanceof k2||r instanceof F2||r instanceof D2||r instanceof M2||r instanceof yu||r instanceof R2||r instanceof T2||r instanceof S2)&&i.transform.push(r.assemble()),(r instanceof sa||r instanceof ra||r instanceof Dc||r instanceof ol||r instanceof pd)&&i.transform.push(...r.assemble()),r instanceof Bi&&(i.source&&i.transform.length===0?r.setSource(i.source):r.parent instanceof Bi?r.setSource(i.name):(i.name||(i.name=`data_${t++}`),r.setSource(i.name),r.numChildren()===1&&(e.push(i),i={name:null,source:i.name,transform:[]}))),r.numChildren()){case 0:r instanceof Bi&&(!i.source||i.transform.length>0)&&e.push(i);break;case 1:n(r.children[0],i);break;default:{i.name||(i.name=`data_${t++}`);let s=i.name;!i.source||i.transform.length>0?e.push(i):s=i.source;for(const o of r.children)n(o,{name:null,source:s,transform:[]});break}}}return n}function Y_e(e){const t=[],n=dq(t);for(const r of e.children)n(r,{source:e.name,name:null,transform:[]});return t}function V_e(e,t){const n=[],r=dq(n);let i=0;for(const o of e.sources){o.hasName()||(o.dataName=`source_${i++}`);const a=o.assemble();r(o,a)}for(const o of n)o.transform.length===0&&delete o.transform;let s=0;for(const[o,a]of n.entries())(a.transform??[]).length===0&&!a.source&&n.splice(s++,0,n.splice(o,1)[0]);for(const o of n)for(const a of o.transform??[])a.type==="lookup"&&(a.from=e.outputNodes[a.from].getSource());for(const o of n)o.name in t&&(o.values=t[o.name]);return n}function X_e(e){return e==="top"||e==="left"||tt(e)?"header":"footer"}function K_e(e){for(const t of $s)Z_e(e,t);b8(e,"x"),b8(e,"y")}function Z_e(e,t){var o;const{facet:n,config:r,child:i,component:s}=e;if(e.channelHasField(t)){const a=n[t],l=uh("title",null,r,t);let u=dd(a,r,{allowDisabling:!0,includeDefault:l===void 0||!!l});i.component.layoutHeaders[t].title&&(u=fe(u)?u.join(", "):u,u+=` / ${i.component.layoutHeaders[t].title}`,i.component.layoutHeaders[t].title=null);const c=uh("labelOrient",a.header,r,t),f=a.header!==null?jn((o=a.header)==null?void 0:o.labels,r.header.labels,!0):!1,d=Tt(["bottom","right"],c)?"footer":"header";s.layoutHeaders[t]={title:a.header!==null?u:null,facetFieldDef:a,[d]:t==="facet"?[]:[hq(e,t,f)]}}}function hq(e,t,n){const r=t==="row"?"height":"width";return{labels:n,sizeSignal:e.child.component.layoutSize.get(r)?e.child.getSizeSignalRef(r):void 0,axes:[]}}function b8(e,t){const{child:n}=e;if(n.component.axes[t]){const{layoutHeaders:r,resolve:i}=e.component;if(i.axis[t]=pF(i,t),i.axis[t]==="shared"){const s=t==="x"?"column":"row",o=r[s];for(const a of n.component.axes[t]){const l=X_e(a.get("orient"));o[l]??(o[l]=[hq(e,s,!1)]);const u=Bp(a,"main",e.config,{header:!0});u&&o[l][0].axes.push(u),a.mainExtracted=!0}}}}function J_e(e){wF(e),my(e,"width"),my(e,"height")}function Q_e(e){wF(e);const t=e.layout.columns===1?"width":"childWidth",n=e.layout.columns===void 0?"height":"childHeight";my(e,t),my(e,n)}function wF(e){for(const t of e.children)t.parseLayoutSize()}function my(e,t){const n=BU(t),r=Vb(n),i=e.component.resolve,s=e.component.layoutSize;let o;for(const a of e.children){const l=a.component.layoutSize.getWithExplicit(n),u=i.scale[r]??jU(r,e);if(u==="independent"&&l.value==="step"){o=void 0;break}if(o){if(u==="independent"&&o.value!==l.value){o=void 0;break}o=vu(o,l,n,"")}else o=l}if(o){for(const a of e.children)e.renameSignal(a.getName(n),e.getName(t)),a.component.layoutSize.set(n,"merged",!1);s.setWithExplicit(t,o)}else s.setWithExplicit(t,{explicit:!1,value:void 0})}function ewe(e){const{size:t,component:n}=e;for(const r of _l){const i=Hi(r);if(t[i]){const s=t[i];n.layoutSize.set(i,ga(s)?"step":s,!0)}else{const s=twe(e,i);n.layoutSize.set(i,s,!1)}}}function twe(e,t){const n=t==="width"?"x":"y",r=e.config,i=e.getScaleComponent(n);if(i){const s=i.get("type"),o=i.get("range");if(pr(s)){const a=fy(r.view,t);return Ef(o)||ga(a)?"step":a}else return uA(r.view,t)}else{if(e.hasProjection||e.mark==="arc")return uA(r.view,t);{const s=fy(r.view,t);return ga(s)?s.step:s}}}function FA(e,t,n){return Ne(t,{suffix:`by_${Ne(e)}`,...n})}class ag extends fq{constructor(t,n,r,i){super(t,"facet",n,r,i,t.resolve),this.child=CF(t.spec,this,this.getName("child"),void 0,i),this.children=[this.child],this.facet=this.initFacet(t.facet)}initFacet(t){if(!j0(t))return{facet:this.initFacetFieldDef(t,"facet")};const n=Ae(t),r={};for(const i of n){if(![nl,rl].includes(i)){Ce(Zb(i,"facet"));break}const s=t[i];if(s.field===void 0){Ce(iA(s,i));break}r[i]=this.initFacetFieldDef(s,i)}return r}initFacetFieldDef(t,n){const r=q$(t,n);return r.header?r.header=Ar(r.header):r.header===null&&(r.header=null),r}channelHasField(t){return Se(this.facet,t)}fieldDef(t){return this.facet[t]}parseData(){this.component.data=N2(this),this.child.parseData()}parseLayoutSize(){wF(this)}parseSelections(){this.child.parseSelections(),this.component.selection=this.child.component.selection,Object.values(this.component.selection).some(t=>ia(t))&&y$(v$)}parseMarkGroup(){this.child.parseMarkGroup()}parseAxesAndHeaders(){this.child.parseAxesAndHeaders(),K_e(this)}assembleSelectionTopLevelSignals(t){return this.child.assembleSelectionTopLevelSignals(t)}assembleSignals(){return this.child.assembleSignals(),[]}assembleSelectionData(t){return this.child.assembleSelectionData(t)}getHeaderLayoutMixins(){const t={};for(const n of $s)for(const r of dF){const i=this.component.layoutHeaders[n],s=i[r],{facetFieldDef:o}=i;if(o){const a=uh("titleOrient",o.header,this.config,n);if(["right","bottom"].includes(a)){const l=w2(n,a);t.titleAnchor??(t.titleAnchor={}),t.titleAnchor[l]="end"}}if(s!=null&&s[0]){const a=n==="row"?"height":"width",l=r==="header"?"headerBand":"footerBand";n!=="facet"&&!this.child.component.layoutSize.get(a)&&(t[l]??(t[l]={}),t[l][n]=.5),i.title&&(t.offset??(t.offset={}),t.offset[n==="row"?"rowTitle":"columnTitle"]=10)}}return t}assembleDefaultLayout(){const{column:t,row:n}=this.facet,r=t?this.columnDistinctSignal():n?1:void 0;let i="all";return(!n&&this.component.resolve.scale.x==="independent"||!t&&this.component.resolve.scale.y==="independent")&&(i="none"),{...this.getHeaderLayoutMixins(),...r?{columns:r}:{},bounds:"full",align:i}}assembleLayoutSignals(){return this.child.assembleLayoutSignals()}columnDistinctSignal(){if(!(this.parent&&this.parent instanceof ag))return{signal:`length(data('${this.getName("column_domain")}'))`}}assembleGroupStyle(){}assembleGroup(t){return this.parent&&this.parent instanceof ag?{...this.channelHasField("column")?{encode:{update:{columns:{field:Ne(this.facet.column,{prefix:"distinct"})}}}}:{},...super.assembleGroup(t)}:super.assembleGroup(t)}getCardinalityAggregateForChild(){const t=[],n=[],r=[];if(this.child instanceof ag){if(this.child.channelHasField("column")){const i=Ne(this.child.facet.column);t.push(i),n.push("distinct"),r.push(`distinct_${i}`)}}else for(const i of _l){const s=this.child.component.scales[i];if(s&&!s.merged){const o=s.get("type"),a=s.get("range");if(pr(o)&&Ef(a)){const l=A2(this.child,i),u=bF(l);u?(t.push(u),n.push("distinct"),r.push(`distinct_${u}`)):Ce(m$(i))}}}return{fields:t,ops:n,as:r}}assembleFacet(){const{name:t,data:n}=this.component.data.facetRoot,{row:r,column:i}=this.facet,{fields:s,ops:o,as:a}=this.getCardinalityAggregateForChild(),l=[];for(const c of $s){const f=this.facet[c];if(f){l.push(Ne(f));const{bin:d,sort:h}=f;if(dn(d)&&l.push(Ne(f,{binSuffix:"end"})),il(h)){const{field:p,op:g=i2}=h,m=FA(f,h);r&&i?(s.push(m),o.push("max"),a.push(m)):(s.push(p),o.push(g),a.push(m))}else if(fe(h)){const p=lh(f,c);s.push(p),o.push("max"),a.push(p)}}}const u=!!r&&!!i;return{name:t,data:n,groupby:l,...u||s.length>0?{aggregate:{...u?{cross:u}:{},...s.length?{fields:s,ops:o,as:a}:{}}}:{}}}facetSortFields(t){const{facet:n}=this,r=n[t];return r?il(r.sort)?[FA(r,r.sort,{expr:"datum"})]:fe(r.sort)?[lh(r,t,{expr:"datum"})]:[Ne(r,{expr:"datum"})]:[]}facetSortOrder(t){const{facet:n}=this,r=n[t];if(r){const{sort:i}=r;return[(il(i)?i.order:!fe(i)&&i)||"ascending"]}return[]}assembleLabelTitle(){var i;const{facet:t,config:n}=this;if(t.facet)return wA(t.facet,"facet",n);const r={row:["top","bottom"],column:["left","right"]};for(const s of fF)if(t[s]){const o=uh("labelOrient",(i=t[s])==null?void 0:i.header,n,s);if(r[s].includes(o))return wA(t[s],s,n)}}assembleMarks(){const{child:t}=this,n=this.component.data.facetRoot,r=Y_e(n),i=t.assembleGroupEncodeEntry(!1),s=this.assembleLabelTitle()||t.assembleTitle(),o=t.assembleGroupStyle();return[{name:this.getName("cell"),type:"group",...s?{title:s}:{},...o?{style:o}:{},from:{facet:this.assembleFacet()},sort:{field:$s.map(l=>this.facetSortFields(l)).flat(),order:$s.map(l=>this.facetSortOrder(l)).flat()},...r.length>0?{data:r}:{},...i?{encode:{update:i}}:{},...t.assembleGroup(abe(this,[]))}]}getMapping(){return this.facet}}function nwe(e,t){const{row:n,column:r}=t;if(n&&r){let i=null;for(const s of[n,r])if(il(s.sort)){const{field:o,op:a=i2}=s.sort;e=i=new Ff(e,{joinaggregate:[{op:a,field:o,as:FA(s,s.sort,{forAs:!0})}],groupby:[Ne(s)]})}return i}return null}function pq(e,t){var n,r,i,s;for(const o of t){const a=o.data;if(e.name&&o.hasName()&&e.name!==o.dataName)continue;const l=(n=e.format)==null?void 0:n.mesh,u=(r=a.format)==null?void 0:r.feature;if(l&&u)continue;const c=(i=e.format)==null?void 0:i.feature;if((c||u)&&c!==u)continue;const f=(s=a.format)==null?void 0:s.mesh;if(!((l||f)&&l!==f)){if(Ig(e)&&Ig(a)){if(ss(e.values,a.values))return o}else if(sh(e)&&sh(a)){if(e.url===a.url)return o}else if(Vj(e)&&e.name===o.dataName)return o}}return null}function rwe(e,t){if(e.data||!e.parent){if(e.data===null){const r=new cf({values:[]});return t.push(r),r}const n=pq(e.data,t);if(n)return nu(e.data)||(n.data.format=qB({},e.data.format,n.data.format)),!n.hasName()&&e.data.name&&(n.dataName=e.data.name),n;{const r=new cf(e.data);return t.push(r),r}}else return e.parent.component.data.facetRoot?e.parent.component.data.facetRoot:e.parent.component.data.main}function iwe(e,t,n){let r=0;for(const i of t.transforms){let s,o;if(Oye(i))o=e=new ah(e,i),s="derived";else if(tF(i)){const a=Vxe(i);o=e=Gr.makeWithAncestors(e,{},a,n)??e,e=new Lh(e,t,i.filter)}else if(qj(i))o=e=sa.makeFromTransform(e,i,t),s="number";else if(Iye(i))s="date",n.getWithExplicit(i.field).value===void 0&&(e=new Gr(e,{[i.field]:s}),n.set(i.field,s,!1)),o=e=ra.makeFromTransform(e,i);else if(Pye(i))o=e=ho.makeFromTransform(e,i),s="number",aF(t)&&(e=new yu(e));else if(Uj(i))o=e=jg.make(e,t,i,r++),s="derived";else if(Tye(i))o=e=new Ph(e,i),s="number";else if(Rye(i))o=e=new Ff(e,i),s="number";else if(Bye(i))o=e=ol.makeFromTransform(e,i),s="derived";else if(zye(i))o=e=new $2(e,i),s="derived";else if(jye(i))o=e=new S2(e,i),s="derived";else if(Nye(i))o=e=new C2(e,i),s="derived";else if(Sye(i))o=e=new T2(e,i),s="derived";else if(Mye(i))e=new R2(e,i);else if(Lye(i))o=e=Dc.makeFromTransform(e,i),s="derived";else if(Cye(i))o=e=new k2(e,i),s="derived";else if($ye(i))o=e=new D2(e,i),s="derived";else if(Fye(i))o=e=new M2(e,i),s="derived";else if(Dye(i))o=e=new F2(e,i),s="derived";else{Ce(sme(i));continue}if(o&&s!==void 0)for(const a of o.producedFields()??[])n.set(a,s,!1)}return e}function N2(e){var m;let t=rwe(e,e.component.data.sources);const{outputNodes:n,outputNodeRefCounts:r}=e.component.data,i=e.data,o=!(i&&(nu(i)||sh(i)||Ig(i)))&&e.parent?e.parent.component.data.ancestorParse.clone():new Qye;nu(i)?(Xj(i)?t=new Z0(t,i.sequence):nF(i)&&(t=new K0(t,i.graticule)),o.parseNothing=!0):((m=i==null?void 0:i.format)==null?void 0:m.parse)===null&&(o.parseNothing=!0),t=Gr.makeExplicit(t,e,o)??t,t=new yu(t);const a=e.parent&&Bh(e.parent);(Cn(e)||cs(e))&&a&&(t=sa.makeFromEncoding(t,e)??t),e.transforms.length>0&&(t=iwe(t,e,o));const l=Kxe(e),u=Xxe(e);t=Gr.makeWithAncestors(t,{},{...l,...u},o)??t,Cn(e)&&(t=pd.parseAll(t,e),t=zg.parseAll(t,e)),(Cn(e)||cs(e))&&(a||(t=sa.makeFromEncoding(t,e)??t),t=ra.makeFromEncoding(t,e)??t,t=ah.parseAllForSortIndex(t,e));const c=t=Im($n.Raw,e,t);if(Cn(e)){const v=ho.makeFromEncoding(t,e);v&&(t=v,aF(e)&&(t=new yu(t))),t=Dc.makeFromEncoding(t,e)??t,t=ol.makeFromEncoding(t,e)??t}let f,d;if(Cn(e)){const{markDef:v,mark:b,config:x}=e,_=on("invalid",v,x),{marks:w,scales:A}=d=Zj({invalid:_,isPath:Iu(b)});w!==A&&A==="include-invalid-values"&&(f=t=Im($n.PreFilterInvalid,e,t)),w==="exclude-invalid-values"&&(t=ch.make(t,e,d)??t)}const h=t=Im($n.Main,e,t);let p;if(Cn(e)&&d){const{marks:v,scales:b}=d;v==="include-invalid-values"&&b==="exclude-invalid-values"&&(t=ch.make(t,e,d)??t,p=t=Im($n.PostFilterInvalid,e,t))}Cn(e)&&H2e(e,h);let g=null;if(cs(e)){const v=e.getName("facet");t=nwe(t,e.facet)??t,g=new Ih(t,e,v,h.getSource()),n[v]=g}return{...e.component.data,outputNodes:n,outputNodeRefCounts:r,raw:c,main:h,facetRoot:g,ancestorParse:o,preFilterInvalid:f,postFilterInvalid:p}}function Im(e,t,n){const{outputNodes:r,outputNodeRefCounts:i}=t.component.data,s=t.getDataName(e),o=new Bi(n,s,e,i);return r[s]=o,o}class swe extends _F{constructor(t,n,r,i){var s,o,a,l;super(t,"concat",n,r,i,t.resolve),(((o=(s=t.resolve)==null?void 0:s.axis)==null?void 0:o.x)==="shared"||((l=(a=t.resolve)==null?void 0:a.axis)==null?void 0:l.y)==="shared")&&Ce(nme),this.children=this.getChildren(t).map((u,c)=>CF(u,this,this.getName(`concat_${c}`),void 0,i))}parseData(){this.component.data=N2(this);for(const t of this.children)t.parseData()}parseSelections(){this.component.selection={};for(const t of this.children){t.parseSelections();for(const n of Ae(t.component.selection))this.component.selection[n]=t.component.selection[n]}Object.values(this.component.selection).some(t=>ia(t))&&y$(v$)}parseMarkGroup(){for(const t of this.children)t.parseMarkGroup()}parseAxesAndHeaders(){for(const t of this.children)t.parseAxesAndHeaders()}getChildren(t){return f2(t)?t.vconcat:Q$(t)?t.hconcat:t.concat}parseLayoutSize(){Q_e(this)}parseAxisGroup(){return null}assembleSelectionTopLevelSignals(t){return this.children.reduce((n,r)=>r.assembleSelectionTopLevelSignals(n),t)}assembleSignals(){return this.children.forEach(t=>t.assembleSignals()),[]}assembleLayoutSignals(){const t=hF(this);for(const n of this.children)t.push(...n.assembleLayoutSignals());return t}assembleSelectionData(t){return this.children.reduce((n,r)=>r.assembleSelectionData(n),t)}assembleMarks(){return this.children.map(t=>{const n=t.assembleTitle(),r=t.assembleGroupStyle(),i=t.assembleGroupEncodeEntry(!1);return{type:"group",name:t.getName("group"),...n?{title:n}:{},...r?{style:r}:{},...i?{encode:{update:i}}:{},...t.assembleGroup()}})}assembleGroupStyle(){}assembleDefaultLayout(){const t=this.layout.columns;return{...t!=null?{columns:t}:{},bounds:"full",align:"each"}}}function owe(e){return e===!1||e===null}const awe={disable:1,gridScale:1,scale:1,...dj,labelExpr:1,encode:1},gq=Ae(awe);class EF extends El{constructor(t={},n={},r=!1){super(),this.explicit=t,this.implicit=n,this.mainExtracted=r}clone(){return new EF(gt(this.explicit),gt(this.implicit),this.mainExtracted)}hasAxisPart(t){return t==="axis"?!0:t==="grid"||t==="title"?!!this.get(t):!owe(this.get(t))}hasOrientSignalRef(){return tt(this.explicit.orient)}}function lwe(e,t,n){const{encoding:r,config:i}=e,s=Jn(r[t])??Jn(r[Ca(t)]),o=e.axis(t)||{},{format:a,formatType:l}=o;if(sf(l))return{text:co({fieldOrDatumDef:s,field:"datum.value",format:a,formatType:l,config:i}),...n};if(a===void 0&&l===void 0&&i.customFormatTypes){if(nh(s)==="quantitative"){if(rh(s)&&s.stack==="normalize"&&i.normalizedNumberFormatType)return{text:co({fieldOrDatumDef:s,field:"datum.value",format:i.normalizedNumberFormat,formatType:i.normalizedNumberFormatType,config:i}),...n};if(i.numberFormatType)return{text:co({fieldOrDatumDef:s,field:"datum.value",format:i.numberFormat,formatType:i.numberFormatType,config:i}),...n}}if(nh(s)==="temporal"&&i.timeFormatType&&$e(s)&&!s.timeUnit)return{text:co({fieldOrDatumDef:s,field:"datum.value",format:i.timeFormat,formatType:i.timeFormatType,config:i}),...n}}return n}function uwe(e){return _l.reduce((t,n)=>(e.component.scales[n]&&(t[n]=[mwe(n,e)]),t),{})}const cwe={bottom:"top",top:"bottom",left:"right",right:"left"};function fwe(e){const{axes:t,resolve:n}=e.component,r={top:0,bottom:0,right:0,left:0};for(const i of e.children){i.parseAxesAndHeaders();for(const s of Ae(i.component.axes))n.axis[s]=pF(e.component.resolve,s),n.axis[s]==="shared"&&(t[s]=dwe(t[s],i.component.axes[s]),t[s]||(n.axis[s]="independent",delete t[s]))}for(const i of _l){for(const s of e.children)if(s.component.axes[i]){if(n.axis[i]==="independent"){t[i]=(t[i]??[]).concat(s.component.axes[i]);for(const o of s.component.axes[i]){const{value:a,explicit:l}=o.getWithExplicit("orient");if(!tt(a)){if(r[a]>0&&!l){const u=cwe[a];r[a]>r[u]&&o.set("orient",u,!1)}r[a]++}}}delete s.component.axes[i]}if(n.axis[i]==="independent"&&t[i]&&t[i].length>1)for(const[s,o]of(t[i]||[]).entries())s>0&&o.get("grid")&&!o.explicit.grid&&(o.implicit.grid=!1)}}function dwe(e,t){if(e){if(e.length!==t.length)return;const n=e.length;for(let r=0;rn.clone());return e}function hwe(e,t){for(const n of gq){const r=vu(e.getWithExplicit(n),t.getWithExplicit(n),n,"axis",(i,s)=>{switch(n){case"title":return mz(i,s);case"gridScale":return{explicit:i.explicit,value:jn(i.value,s.value)}}return h2(i,s,n,"axis")});e.setWithExplicit(n,r)}return e}function pwe(e,t,n,r,i){if(t==="disable")return n!==void 0;switch(n=n||{},t){case"titleAngle":case"labelAngle":return e===(tt(n.labelAngle)?n.labelAngle:Og(n.labelAngle));case"values":return!!n.values;case"encode":return!!n.encoding||!!n.labelAngle;case"title":if(e===NU(r,i))return!0}return e===n[t]}const gwe=new Set(["grid","translate","format","formatType","orient","labelExpr","tickCount","position","tickMinStep"]);function mwe(e,t){var v,b;let n=t.axis(e);const r=new EF,i=Jn(t.encoding[e]),{mark:s,config:o}=t,a=(n==null?void 0:n.orient)||((v=o[e==="x"?"axisX":"axisY"])==null?void 0:v.orient)||((b=o.axis)==null?void 0:b.orient)||txe(e),l=t.getScaleComponent(e).get("type"),u=V2e(e,l,a,t.config),c=n!==void 0?!n:xA("disable",o.style,n==null?void 0:n.style,u).configValue;if(r.set("disable",c,n!==void 0),c)return r;n=n||{};const f=J2e(i,n,e,o.style,u),d=Jz(n.formatType,i,l),h=Zz(i,i.type,n.format,n.formatType,o,!0),p={fieldOrDatumDef:i,axis:n,channel:e,model:t,scaleType:l,orient:a,labelAngle:f,format:h,formatType:d,mark:s,config:o};for(const x of gq){const _=x in i8?i8[x](p):A6(x)?n[x]:void 0,w=_!==void 0,A=pwe(_,x,n,t,e);if(w&&A)r.set(x,_,A);else{const{configValue:E=void 0,configFrom:k=void 0}=A6(x)&&x!=="values"?xA(x,o.style,n.style,u):{},S=E!==void 0;w&&!S?r.set(x,_,A):(k!=="vgAxisConfig"||gwe.has(x)&&S||H0(E)||tt(E))&&r.set(x,E,!1)}}const g=n.encoding??{},m=fj.reduce((x,_)=>{if(!r.hasAxisPart(_))return x;const w=zU(g[_]??{},t),A=_==="labels"?lwe(t,e,w):w;return A!==void 0&&!an(A)&&(x[_]={update:A}),x},{});return an(m)||r.set("encode",m,!!n.encoding||n.labelAngle!==void 0),r}function vwe({encoding:e,size:t}){for(const n of _l){const r=Hi(n);ga(t[r])&&Yl(e[n])&&(delete t[r],Ce(_z(r)))}return t}const ywe={vgMark:"arc",encodeEntry:e=>({...Ws(e,{align:"ignore",baseline:"ignore",color:"include",size:"ignore",orient:"ignore",theta:"ignore"}),...gi("x",e,{defaultPos:"mid"}),...gi("y",e,{defaultPos:"mid"}),...hl(e,"radius"),...hl(e,"theta")})},bwe={vgMark:"area",encodeEntry:e=>({...Ws(e,{align:"ignore",baseline:"ignore",color:"include",orient:"include",size:"ignore",theta:"ignore"}),...dy("x",e,{defaultPos:"zeroOrMin",defaultPos2:"zeroOrMin",range:e.markDef.orient==="horizontal"}),...dy("y",e,{defaultPos:"zeroOrMin",defaultPos2:"zeroOrMin",range:e.markDef.orient==="vertical"}),...oF(e)})},xwe={vgMark:"rect",encodeEntry:e=>({...Ws(e,{align:"ignore",baseline:"ignore",color:"include",orient:"ignore",size:"ignore",theta:"ignore"}),...hl(e,"x"),...hl(e,"y")})},_we={vgMark:"shape",encodeEntry:e=>({...Ws(e,{align:"ignore",baseline:"ignore",color:"include",size:"ignore",orient:"ignore",theta:"ignore"})}),postEncodingTransform:e=>{const{encoding:t}=e,n=t.shape;return[{type:"geoshape",projection:e.projectionName(),...n&&$e(n)&&n.type===Nh?{field:Ne(n,{expr:"datum"})}:{}}]}},wwe={vgMark:"image",encodeEntry:e=>({...Ws(e,{align:"ignore",baseline:"ignore",color:"ignore",orient:"ignore",size:"ignore",theta:"ignore"}),...hl(e,"x"),...hl(e,"y"),...iF(e,"url")})},Ewe={vgMark:"line",encodeEntry:e=>({...Ws(e,{align:"ignore",baseline:"ignore",color:"include",size:"ignore",orient:"ignore",theta:"ignore"}),...gi("x",e,{defaultPos:"mid"}),...gi("y",e,{defaultPos:"mid"}),...Sr("size",e,{vgChannel:"strokeWidth"}),...oF(e)})},Awe={vgMark:"trail",encodeEntry:e=>({...Ws(e,{align:"ignore",baseline:"ignore",color:"include",size:"include",orient:"ignore",theta:"ignore"}),...gi("x",e,{defaultPos:"mid"}),...gi("y",e,{defaultPos:"mid"}),...Sr("size",e),...oF(e)})};function AF(e,t){const{config:n}=e;return{...Ws(e,{align:"ignore",baseline:"ignore",color:"include",size:"include",orient:"ignore",theta:"ignore"}),...gi("x",e,{defaultPos:"mid"}),...gi("y",e,{defaultPos:"mid"}),...Sr("size",e),...Sr("angle",e),...kwe(e,n,t)}}function kwe(e,t,n){return n?{shape:{value:n}}:Sr("shape",e)}const Swe={vgMark:"symbol",encodeEntry:e=>AF(e)},Cwe={vgMark:"symbol",encodeEntry:e=>AF(e,"circle")},$we={vgMark:"symbol",encodeEntry:e=>AF(e,"square")},Fwe={vgMark:"rect",encodeEntry:e=>({...Ws(e,{align:"ignore",baseline:"ignore",color:"include",orient:"ignore",size:"ignore",theta:"ignore"}),...hl(e,"x"),...hl(e,"y")})},Dwe={vgMark:"rule",encodeEntry:e=>{const{markDef:t}=e,n=t.orient;return!e.encoding.x&&!e.encoding.y&&!e.encoding.latitude&&!e.encoding.longitude?{}:{...Ws(e,{align:"ignore",baseline:"ignore",color:"include",orient:"ignore",size:"ignore",theta:"ignore"}),...dy("x",e,{defaultPos:n==="horizontal"?"zeroOrMax":"mid",defaultPos2:"zeroOrMin",range:n!=="vertical"}),...dy("y",e,{defaultPos:n==="vertical"?"zeroOrMax":"mid",defaultPos2:"zeroOrMin",range:n!=="horizontal"}),...Sr("size",e,{vgChannel:"strokeWidth"})}}},Mwe={vgMark:"text",encodeEntry:e=>{const{config:t,encoding:n}=e;return{...Ws(e,{align:"include",baseline:"include",color:"include",size:"ignore",orient:"ignore",theta:"include"}),...gi("x",e,{defaultPos:"mid"}),...gi("y",e,{defaultPos:"mid"}),...iF(e),...Sr("size",e,{vgChannel:"fontSize"}),...Sr("angle",e),...Y6("align",Twe(e.markDef,n,t)),...Y6("baseline",Rwe(e.markDef,n,t)),...gi("radius",e,{defaultPos:null}),...gi("theta",e,{defaultPos:null})}}};function Twe(e,t,n){if(on("align",e,n)===void 0)return"center"}function Rwe(e,t,n){if(on("baseline",e,n)===void 0)return"middle"}const Nwe={vgMark:"rect",encodeEntry:e=>{const{config:t,markDef:n}=e,r=n.orient,i=r==="horizontal"?"x":"y",s=r==="horizontal"?"y":"x",o=r==="horizontal"?"height":"width";return{...Ws(e,{align:"ignore",baseline:"ignore",color:"include",orient:"ignore",size:"ignore",theta:"ignore"}),...hl(e,i),...gi(s,e,{defaultPos:"mid",vgChannel:s==="y"?"yc":"xc"}),[o]:vn(on("thickness",n,t))}}},Pm={arc:ywe,area:bwe,bar:xwe,circle:Cwe,geoshape:_we,image:wwe,line:Ewe,point:Swe,rect:Fwe,rule:Dwe,square:$we,text:Mwe,tick:Nwe,trail:Awe};function Owe(e){if(Tt([n2,e2,T1e],e.mark)){const t=yj(e.mark,e.encoding);if(t.length>0)return Lwe(e,t)}else if(e.mark===t2){const t=nA.some(n=>on(n,e.markDef,e.config));if(e.stack&&!e.fieldDef("size")&&t)return Iwe(e)}return kF(e)}const x8="faceted_path_";function Lwe(e,t){return[{name:e.getName("pathgroup"),type:"group",from:{facet:{name:x8+e.requestDataName($n.Main),data:e.requestDataName($n.Main),groupby:t}},encode:{update:{width:{field:{group:"width"}},height:{field:{group:"height"}}}},marks:kF(e,{fromPrefix:x8})}]}const _8="stack_group_";function Iwe(e){var u;const[t]=kF(e,{fromPrefix:_8}),n=e.scaleName(e.stack.fieldChannel),r=(c={})=>e.vgField(e.stack.fieldChannel,c),i=(c,f)=>{const d=[r({prefix:"min",suffix:"start",expr:f}),r({prefix:"max",suffix:"start",expr:f}),r({prefix:"min",suffix:"end",expr:f}),r({prefix:"max",suffix:"end",expr:f})];return`${c}(${d.map(h=>`scale('${n}',${h})`).join(",")})`};let s,o;e.stack.fieldChannel==="x"?(s={...Kd(t.encode.update,["y","yc","y2","height",...nA]),x:{signal:i("min","datum")},x2:{signal:i("max","datum")},clip:{value:!0}},o={x:{field:{group:"x"},mult:-1},height:{field:{group:"height"}}},t.encode.update={...Pi(t.encode.update,["y","yc","y2"]),height:{field:{group:"height"}}}):(s={...Kd(t.encode.update,["x","xc","x2","width"]),y:{signal:i("min","datum")},y2:{signal:i("max","datum")},clip:{value:!0}},o={y:{field:{group:"y"},mult:-1},width:{field:{group:"width"}}},t.encode.update={...Pi(t.encode.update,["x","xc","x2"]),width:{field:{group:"width"}}});for(const c of nA){const f=ha(c,e.markDef,e.config);t.encode.update[c]?(s[c]=t.encode.update[c],delete t.encode.update[c]):f&&(s[c]=vn(f)),f&&(t.encode.update[c]={value:0})}const a=[];if(((u=e.stack.groupbyChannels)==null?void 0:u.length)>0)for(const c of e.stack.groupbyChannels){const f=e.fieldDef(c),d=Ne(f);d&&a.push(d),(f!=null&&f.bin||f!=null&&f.timeUnit)&&a.push(Ne(f,{binSuffix:"end"}))}return s=["stroke","strokeWidth","strokeJoin","strokeCap","strokeDash","strokeDashOffset","strokeMiterLimit","strokeOpacity"].reduce((c,f)=>{if(t.encode.update[f])return{...c,[f]:t.encode.update[f]};{const d=ha(f,e.markDef,e.config);return d!==void 0?{...c,[f]:vn(d)}:c}},s),s.stroke&&(s.strokeForeground={value:!0},s.strokeOffset={value:0}),[{type:"group",from:{facet:{data:e.requestDataName($n.Main),name:_8+e.requestDataName($n.Main),groupby:a,aggregate:{fields:[r({suffix:"start"}),r({suffix:"start"}),r({suffix:"end"}),r({suffix:"end"})],ops:["min","max","min","max"]}}},encode:{update:s},marks:[{type:"group",encode:{update:o},marks:[t]}]}]}function Pwe(e){const{encoding:t,stack:n,mark:r,markDef:i,config:s}=e,o=t.order;if(!(!fe(o)&&xo(o)&&eA(o.value)||!o&&eA(on("order",i,s)))){if((fe(o)||$e(o))&&!n)return hz(o,{expr:"datum"});if(Iu(r)){const a=i.orient==="horizontal"?"y":"x",l=t[a];if($e(l))return{field:a}}}}function kF(e,t={fromPrefix:""}){const{mark:n,markDef:r,encoding:i,config:s}=e,o=jn(r.clip,Bwe(e),zwe(e)),a=fz(r),l=i.key,u=Pwe(e),c=jwe(e),f=on("aria",r,s),d=Pm[n].postEncodingTransform?Pm[n].postEncodingTransform(e):null;return[{name:e.getName("marks"),type:Pm[n].vgMark,...o?{clip:o}:{},...a?{style:a}:{},...l?{key:l.field}:{},...u?{sort:u}:{},...c||{},...f===!1?{aria:f}:{},from:{data:t.fromPrefix+e.requestDataName($n.Main)},encode:{update:Pm[n].encodeEntry(e)},...d?{transform:d}:{}}]}function Bwe(e){const t=e.getScaleComponent("x"),n=e.getScaleComponent("y");return t!=null&&t.get("selectionExtent")||n!=null&&n.get("selectionExtent")?!0:void 0}function zwe(e){const t=e.component.projection;return t&&!t.isFit?!0:void 0}function jwe(e){if(!e.component.selection)return null;const t=Ae(e.component.selection).length;let n=t,r=e.parent;for(;r&&n===0;)n=Ae(r.component.selection).length,r=r.parent;return n?{interactive:t>0||e.mark==="geoshape"||!!e.encoding.tooltip||!!e.markDef.tooltip}:null}class mq extends fq{constructor(t,n,r,i={},s){super(t,"unit",n,r,s,void 0,S6(t)?t.view:void 0),this.specifiedScales={},this.specifiedAxes={},this.specifiedLegends={},this.specifiedProjection={},this.selection=[],this.children=[],this.correctDataNames=u=>{var c,f,d;return(c=u.from)!=null&&c.data&&(u.from.data=this.lookupDataSource(u.from.data),"time"in this.encoding&&(u.from.data=u.from.data+Qj)),(d=(f=u.from)==null?void 0:f.facet)!=null&&d.data&&(u.from.facet.data=this.lookupDataSource(u.from.facet.data)),u};const o=pa(t.mark)?{...t.mark}:{type:t.mark},a=o.type;o.filled===void 0&&(o.filled=gye(o,s,{graticule:t.data&&nF(t.data)}));const l=this.encoding=bve(t.encoding||{},a,o.filled,s);this.markDef=Bj(o,l,s),this.size=vwe({encoding:l,size:S6(t)?{...i,...t.width?{width:t.width}:{},...t.height?{height:t.height}:{}}:i}),this.stack=Pj(this.markDef,l),this.specifiedScales=this.initScales(a,l),this.specifiedAxes=this.initAxes(l),this.specifiedLegends=this.initLegends(l),this.specifiedProjection=t.projection,this.selection=(t.params??[]).filter(u=>Z$(u))}get hasProjection(){const{encoding:t}=this,n=this.mark===Wz,r=t&&f0e.some(i=>vt(t[i]));return n||r}scaleDomain(t){const n=this.specifiedScales[t];return n?n.domain:void 0}axis(t){return this.specifiedAxes[t]}legend(t){return this.specifiedLegends[t]}initScales(t,n){return h$.reduce((r,i)=>{const s=Jn(n[i]);return s&&(r[i]=this.initScale(s.scale??{})),r},{})}initScale(t){const{domain:n,range:r}=t,i=Ar(t);return fe(n)&&(i.domain=n.map(ns)),fe(r)&&(i.range=r.map(ns)),i}initAxes(t){return _l.reduce((n,r)=>{const i=t[r];if(vt(i)||r===wn&&vt(t.x2)||r===mr&&vt(t.y2)){const s=vt(i)?i.axis:void 0;n[r]=s&&this.initAxis({...s})}return n},{})}initAxis(t){const n=Ae(t),r={};for(const i of n){const s=t[i];r[i]=H0(s)?cz(s):ns(s)}return r}initLegends(t){return w0e.reduce((n,r)=>{const i=Jn(t[r]);if(i&&A0e(r)){const s=i.legend;n[r]=s&&Ar(s)}return n},{})}parseData(){this.component.data=N2(this)}parseLayoutSize(){ewe(this)}parseSelections(){this.component.selection=W2e(this,this.selection)}parseMarkGroup(){this.component.mark=Owe(this)}parseAxesAndHeaders(){this.component.axes=uwe(this)}assembleSelectionTopLevelSignals(t){return lbe(this,t)}assembleSignals(){return[...MU(this),...obe(this,[])]}assembleSelectionData(t){return ube(this,t)}assembleLayout(){return null}assembleLayoutSignals(){return hF(this)}assembleMarks(){let t=this.component.mark??[];return(!this.parent||!Bh(this.parent))&&(t=rU(this,t)),t.map(this.correctDataNames)}assembleGroupStyle(){const{style:t}=this.view||{};return t!==void 0?t:this.encoding.x||this.encoding.y?"cell":"view"}getMapping(){return this.encoding}get mark(){return this.markDef.type}channelHasField(t){return $c(this.encoding,t)}fieldDef(t){const n=this.encoding[t];return _o(n)}typedFieldDef(t){const n=this.fieldDef(t);return xi(n)?n:null}}class SF extends _F{constructor(t,n,r,i,s){super(t,"layer",n,r,s,t.resolve,t.view);const o={...i,...t.width?{width:t.width}:{},...t.height?{height:t.height}:{}};this.children=t.layer.map((a,l)=>{if(d2(a))return new SF(a,this,this.getName(`layer_${l}`),o,s);if(wl(a))return new mq(a,this,this.getName(`layer_${l}`),o,s);throw new Error(g$(a))})}parseData(){this.component.data=N2(this);for(const t of this.children)t.parseData()}parseLayoutSize(){J_e(this)}parseSelections(){this.component.selection={};for(const t of this.children){t.parseSelections();for(const n of Ae(t.component.selection))this.component.selection[n]=t.component.selection[n]}Object.values(this.component.selection).some(t=>ia(t))&&y$(v$)}parseMarkGroup(){for(const t of this.children)t.parseMarkGroup()}parseAxesAndHeaders(){fwe(this)}assembleSelectionTopLevelSignals(t){return this.children.reduce((n,r)=>r.assembleSelectionTopLevelSignals(n),t)}assembleSignals(){return this.children.reduce((t,n)=>t.concat(n.assembleSignals()),MU(this))}assembleLayoutSignals(){return this.children.reduce((t,n)=>t.concat(n.assembleLayoutSignals()),hF(this))}assembleSelectionData(t){return this.children.reduce((n,r)=>r.assembleSelectionData(n),t)}assembleGroupStyle(){const t=new Set;for(const r of this.children)for(const i of je(r.assembleGroupStyle()))t.add(i);const n=Array.from(t);return n.length>1?n:n.length===1?n[0]:void 0}assembleTitle(){let t=super.assembleTitle();if(t)return t;for(const n of this.children)if(t=n.assembleTitle(),t)return t}assembleLayout(){return null}assembleMarks(){return cbe(this,this.children.flatMap(t=>t.assembleMarks()))}assembleLegends(){return this.children.reduce((t,n)=>t.concat(n.assembleLegends()),VU(this))}}function CF(e,t,n,r,i){if(s2(e))return new ag(e,t,n,i);if(d2(e))return new SF(e,t,n,r,i);if(wl(e))return new mq(e,t,n,r,i);if(qve(e))return new swe(e,t,n,i);throw new Error(g$(e))}function Uwe(e,t={}){t.logger&&Gme(t.logger),t.fieldTitle&&lj(t.fieldTitle);try{const n=Ij(gh(t.config,e.config)),r=Gj(e,n),i=CF(r,null,"",void 0,n);return i.parse(),d_e(i.component.data,i),{spec:Wwe(i,qwe(e,r.autosize,n,i),e.datasets,e.usermeta),normalized:r}}finally{t.logger&&Yme(),t.fieldTitle&&cve()}}function qwe(e,t,n,r){const i=r.component.layoutSize.get("width"),s=r.component.layoutSize.get("height");if(t===void 0?(t={type:"pad"},r.hasAxisOrientSignalRef()&&(t.resize=!0)):ze(t)&&(t={type:t}),i&&s&&Kye(t.type)){if(i==="step"&&s==="step")Ce(c6()),t.type="pad";else if(i==="step"||s==="step"){const o=i==="step"?"width":"height";Ce(c6(Vb(o)));const a=o==="width"?"height":"width";t.type=Zye(a)}}return{...Ae(t).length===1&&t.type?t.type==="pad"?{}:{autosize:t.type}:{autosize:t},...P6(n,!1),...P6(e,!0)}}function Wwe(e,t,n={},r){const i=e.config?rye(e.config):void 0,s=V_e(e.component.data,n),o=e.assembleSelectionData(s),a=e.assembleProjections(),l=e.assembleTitle(),u=e.assembleGroupStyle(),c=e.assembleGroupEncodeEntry(!0);let f=e.assembleLayoutSignals();f=f.filter(p=>(p.name==="width"||p.name==="height")&&p.value!==void 0?(t[p.name]=+p.value,!1):!0);const{params:d,...h}=t;return{$schema:"https://vega.github.io/schema/vega/v5.json",...e.description?{description:e.description}:{},...h,...l?{title:l}:{},...u?{style:u}:{},...c?{encode:{update:c}}:{},data:o,...a.length>0?{projections:a}:{},...e.assembleGroup([...f,...e.assembleSelectionTopLevelSignals([]),...Rj(d)]),...i?{config:i}:{},...r?{usermeta:r}:{}}}const Hwe=s0e.version,Gwe=Object.freeze(Object.defineProperty({__proto__:null,accessPathDepth:Jd,accessPathWithDatum:s$,accessWithDatumToUnescapedPath:Qt,compile:Uwe,contains:Tt,deepEqual:ss,deleteNestedProperty:ny,duplicate:gt,entries:pu,every:n$,fieldIntersection:i$,flatAccessWithDatum:HB,getFirstDefined:jn,hasIntersection:r$,hasProperty:Se,hash:It,internalField:VB,isBoolean:Ng,isEmpty:an,isEqual:a0e,isInternalField:XB,isNullOrFalse:eA,isNumeric:Ub,keys:Ae,logicalExpr:ig,mergeDeep:qB,never:UB,normalize:Gj,normalizeAngle:Og,omit:Pi,pick:Kd,prefixGenerator:tA,removePathFromField:Th,replaceAll:Jc,replacePathInField:Bs,resetIdCounter:u0e,setEqual:WB,some:Zd,stringify:ln,titleCase:N0,unique:Jo,uniqueId:YB,vals:Mr,varName:_n,version:Hwe},Symbol.toStringTag,{value:"Module"}));function vq(e){const[t,n]=/schema\/([\w-]+)\/([\w\.\-]+)\.json$/g.exec(e).slice(1,3);return{library:t,version:n}}var Ywe="2.15.0",Vwe={version:Ywe};const qf="#fff",w8="#888",Xwe={background:"#333",view:{stroke:w8},title:{color:qf,subtitleColor:qf},style:{"guide-label":{fill:qf},"guide-title":{fill:qf}},axis:{domainColor:qf,gridColor:w8,tickColor:qf}},Vu="#4572a7",Kwe={background:"#fff",arc:{fill:Vu},area:{fill:Vu},line:{stroke:Vu,strokeWidth:2},path:{stroke:Vu},rect:{fill:Vu},shape:{stroke:Vu},symbol:{fill:Vu,strokeWidth:1.5,size:50},axis:{bandPosition:.5,grid:!0,gridColor:"#000000",gridOpacity:1,gridWidth:.5,labelPadding:10,tickSize:5,tickWidth:.5},axisBand:{grid:!1,tickExtra:!0},legend:{labelBaseline:"middle",labelFontSize:11,symbolSize:50,symbolType:"square"},range:{category:["#4572a7","#aa4643","#8aa453","#71598e","#4598ae","#d98445","#94aace","#d09393","#b9cc98","#a99cbc"]}},Xu="#30a2da",S_="#cbcbcb",Zwe="#999",Jwe="#333",E8="#f0f0f0",A8="#333",Qwe={arc:{fill:Xu},area:{fill:Xu},axis:{domainColor:S_,grid:!0,gridColor:S_,gridWidth:1,labelColor:Zwe,labelFontSize:10,titleColor:Jwe,tickColor:S_,tickSize:10,titleFontSize:14,titlePadding:10,labelPadding:4},axisBand:{grid:!1},background:E8,group:{fill:E8},legend:{labelColor:A8,labelFontSize:11,padding:1,symbolSize:30,symbolType:"square",titleColor:A8,titleFontSize:14,titlePadding:10},line:{stroke:Xu,strokeWidth:2},path:{stroke:Xu,strokeWidth:.5},rect:{fill:Xu},range:{category:["#30a2da","#fc4f30","#e5ae38","#6d904f","#8b8b8b","#b96db8","#ff9e27","#56cc60","#52d2ca","#52689e","#545454","#9fe4f8"],diverging:["#cc0020","#e77866","#f6e7e1","#d6e8ed","#91bfd9","#1d78b5"],heatmap:["#d6e8ed","#cee0e5","#91bfd9","#549cc6","#1d78b5"]},point:{filled:!0,shape:"circle"},shape:{stroke:Xu},bar:{binSpacing:2,fill:Xu,stroke:null},title:{anchor:"start",fontSize:24,fontWeight:600,offset:20}},Ku="#000",eEe={group:{fill:"#e5e5e5"},arc:{fill:Ku},area:{fill:Ku},line:{stroke:Ku},path:{stroke:Ku},rect:{fill:Ku},shape:{stroke:Ku},symbol:{fill:Ku,size:40},axis:{domain:!1,grid:!0,gridColor:"#FFFFFF",gridOpacity:1,labelColor:"#7F7F7F",labelPadding:4,tickColor:"#7F7F7F",tickSize:5.67,titleFontSize:16,titleFontWeight:"normal"},legend:{labelBaseline:"middle",labelFontSize:11,symbolSize:40},range:{category:["#000000","#7F7F7F","#1A1A1A","#999999","#333333","#B0B0B0","#4D4D4D","#C9C9C9","#666666","#DCDCDC"]}},tEe=22,nEe="normal",k8="Benton Gothic, sans-serif",S8=11.5,rEe="normal",Zu="#82c6df",C_="Benton Gothic Bold, sans-serif",C8="normal",$8=13,dp={"category-6":["#ec8431","#829eb1","#c89d29","#3580b1","#adc839","#ab7fb4"],"fire-7":["#fbf2c7","#f9e39c","#f8d36e","#f4bb6a","#e68a4f","#d15a40","#ab4232"],"fireandice-6":["#e68a4f","#f4bb6a","#f9e39c","#dadfe2","#a6b7c6","#849eae"]},iEe={background:"#ffffff",title:{anchor:"start",color:"#000000",font:C_,fontSize:tEe,fontWeight:nEe},arc:{fill:Zu},area:{fill:Zu},line:{stroke:Zu,strokeWidth:2},path:{stroke:Zu},rect:{fill:Zu},shape:{stroke:Zu},symbol:{fill:Zu,size:30},axis:{labelFont:k8,labelFontSize:S8,labelFontWeight:rEe,titleFont:C_,titleFontSize:$8,titleFontWeight:C8},axisX:{labelAngle:0,labelPadding:4,tickSize:3},axisY:{labelBaseline:"middle",maxExtent:45,minExtent:45,tickSize:2,titleAlign:"left",titleAngle:0,titleX:-45,titleY:-11},legend:{labelFont:k8,labelFontSize:S8,symbolType:"square",titleFont:C_,titleFontSize:$8,titleFontWeight:C8},range:{category:dp["category-6"],diverging:dp["fireandice-6"],heatmap:dp["fire-7"],ordinal:dp["fire-7"],ramp:dp["fire-7"]}},Ju="#ab5787",Bm="#979797",sEe={background:"#f9f9f9",arc:{fill:Ju},area:{fill:Ju},line:{stroke:Ju},path:{stroke:Ju},rect:{fill:Ju},shape:{stroke:Ju},symbol:{fill:Ju,size:30},axis:{domainColor:Bm,domainWidth:.5,gridWidth:.2,labelColor:Bm,tickColor:Bm,tickWidth:.2,titleColor:Bm},axisBand:{grid:!1},axisX:{grid:!0,tickSize:10},axisY:{domain:!1,grid:!0,tickSize:0},legend:{labelFontSize:11,padding:1,symbolSize:30,symbolType:"square"},range:{category:["#ab5787","#51b2e5","#703c5c","#168dd9","#d190b6","#00609f","#d365ba","#154866","#666666","#c4c4c4"]}},Qu="#3e5c69",oEe={background:"#fff",arc:{fill:Qu},area:{fill:Qu},line:{stroke:Qu},path:{stroke:Qu},rect:{fill:Qu},shape:{stroke:Qu},symbol:{fill:Qu},axis:{domainWidth:.5,grid:!0,labelPadding:2,tickSize:5,tickWidth:.5,titleFontWeight:"normal"},axisBand:{grid:!1},axisX:{gridWidth:.2},axisY:{gridDash:[3],gridWidth:.4},legend:{labelFontSize:11,padding:1,symbolType:"square"},range:{category:["#3e5c69","#6793a6","#182429","#0570b0","#3690c0","#74a9cf","#a6bddb","#e2ddf2"]}},ys="#1696d2",F8="#000000",aEe="#FFFFFF",zm="Lato",$_="Lato",lEe="Lato",uEe="#DEDDDD",cEe=18,hp={"shades-blue":["#CFE8F3","#A2D4EC","#73BFE2","#46ABDB","#1696D2","#12719E","#0A4C6A","#062635"],"six-groups-cat-1":["#1696d2","#ec008b","#fdbf11","#000000","#d2d2d2","#55b748"],"six-groups-seq":["#cfe8f3","#a2d4ec","#73bfe2","#46abdb","#1696d2","#12719e"],"diverging-colors":["#ca5800","#fdbf11","#fdd870","#fff2cf","#cfe8f3","#73bfe2","#1696d2","#0a4c6a"]},fEe={background:aEe,title:{anchor:"start",fontSize:cEe,font:zm},axisX:{domain:!0,domainColor:F8,domainWidth:1,grid:!1,labelFontSize:12,labelFont:$_,labelAngle:0,tickColor:F8,tickSize:5,titleFontSize:12,titlePadding:10,titleFont:zm},axisY:{domain:!1,domainWidth:1,grid:!0,gridColor:uEe,gridWidth:1,labelFontSize:12,labelFont:$_,labelPadding:8,ticks:!1,titleFontSize:12,titlePadding:10,titleFont:zm,titleAngle:0,titleY:-10,titleX:18},legend:{labelFontSize:12,labelFont:$_,symbolSize:100,titleFontSize:12,titlePadding:10,titleFont:zm,orient:"right",offset:10},view:{stroke:"transparent"},range:{category:hp["six-groups-cat-1"],diverging:hp["diverging-colors"],heatmap:hp["diverging-colors"],ordinal:hp["six-groups-seq"],ramp:hp["shades-blue"]},area:{fill:ys},rect:{fill:ys},line:{color:ys,stroke:ys,strokeWidth:5},trail:{color:ys,stroke:ys,strokeWidth:0,size:1},path:{stroke:ys,strokeWidth:.5},point:{filled:!0},text:{font:lEe,color:ys,fontSize:11,align:"center",fontWeight:400,size:11},style:{bar:{fill:ys,stroke:null}},arc:{fill:ys},shape:{stroke:ys},symbol:{fill:ys,size:30}},ec="#3366CC",D8="#ccc",jm="Arial, sans-serif",dEe={arc:{fill:ec},area:{fill:ec},path:{stroke:ec},rect:{fill:ec},shape:{stroke:ec},symbol:{stroke:ec},circle:{fill:ec},background:"#fff",padding:{top:10,right:10,bottom:10,left:10},style:{"guide-label":{font:jm,fontSize:12},"guide-title":{font:jm,fontSize:12},"group-title":{font:jm,fontSize:12}},title:{font:jm,fontSize:14,fontWeight:"bold",dy:-3,anchor:"start"},axis:{gridColor:D8,tickColor:D8,domain:!1,grid:!0},range:{category:["#4285F4","#DB4437","#F4B400","#0F9D58","#AB47BC","#00ACC1","#FF7043","#9E9D24","#5C6BC0","#F06292","#00796B","#C2185B"],heatmap:["#c6dafc","#5e97f6","#2a56c6"]}},$F=e=>e*(1/3+1),M8=$F(9),T8=$F(10),R8=$F(12),pp="Segoe UI",N8="wf_standard-font, helvetica, arial, sans-serif",O8="#252423",gp="#605E5C",L8="transparent",hEe="#C8C6C4",Ks="#118DFF",pEe="#12239E",gEe="#E66C37",mEe="#6B007B",vEe="#E044A7",yEe="#744EC2",bEe="#D9B300",xEe="#D64550",yq=Ks,bq="#DEEFFF",I8=[bq,yq],_Ee=[bq,"#c7e4ff","#b0d9ff","#9aceff","#83c3ff","#6cb9ff","#55aeff","#3fa3ff","#2898ff",yq],wEe={view:{stroke:L8},background:L8,font:pp,header:{titleFont:N8,titleFontSize:R8,titleColor:O8,labelFont:pp,labelFontSize:T8,labelColor:gp},axis:{ticks:!1,grid:!1,domain:!1,labelColor:gp,labelFontSize:M8,titleFont:N8,titleColor:O8,titleFontSize:R8,titleFontWeight:"normal"},axisQuantitative:{tickCount:3,grid:!0,gridColor:hEe,gridDash:[1,5],labelFlush:!1},axisBand:{tickExtra:!0},axisX:{labelPadding:5},axisY:{labelPadding:10},bar:{fill:Ks},line:{stroke:Ks,strokeWidth:3,strokeCap:"round",strokeJoin:"round"},text:{font:pp,fontSize:M8,fill:gp},arc:{fill:Ks},area:{fill:Ks,line:!0,opacity:.6},path:{stroke:Ks},rect:{fill:Ks},point:{fill:Ks,filled:!0,size:75},shape:{stroke:Ks},symbol:{fill:Ks,strokeWidth:1.5,size:50},legend:{titleFont:pp,titleFontWeight:"bold",titleColor:gp,labelFont:pp,labelFontSize:T8,labelColor:gp,symbolType:"circle",symbolSize:75},range:{category:[Ks,pEe,gEe,mEe,vEe,yEe,bEe,xEe],diverging:I8,heatmap:I8,ordinal:_Ee}},F_='IBM Plex Sans,system-ui,-apple-system,BlinkMacSystemFont,".sfnstext-regular",sans-serif',EEe='IBM Plex Sans Condensed, system-ui, -apple-system, BlinkMacSystemFont, ".SFNSText-Regular", sans-serif',D_=400,Um={textPrimary:{g90:"#f4f4f4",g100:"#f4f4f4",white:"#161616",g10:"#161616"},textSecondary:{g90:"#c6c6c6",g100:"#c6c6c6",white:"#525252",g10:"#525252"},layerAccent01:{white:"#e0e0e0",g10:"#e0e0e0",g90:"#525252",g100:"#393939"},gridBg:{white:"#ffffff",g10:"#ffffff",g90:"#161616",g100:"#161616"}},AEe=["#8a3ffc","#33b1ff","#007d79","#ff7eb6","#fa4d56","#fff1f1","#6fdc8c","#4589ff","#d12771","#d2a106","#08bdba","#bae6ff","#ba4e00","#d4bbff"],kEe=["#6929c4","#1192e8","#005d5d","#9f1853","#fa4d56","#570408","#198038","#002d9c","#ee538b","#b28600","#009d9a","#012749","#8a3800","#a56eff"];function O2({theme:e,background:t}){const n=["white","g10"].includes(e)?"light":"dark",r=Um.gridBg[e],i=Um.textPrimary[e],s=Um.textSecondary[e],o=n==="dark"?AEe:kEe,a=n==="dark"?"#d4bbff":"#6929c4";return{background:t,arc:{fill:a},area:{fill:a},path:{stroke:a},rect:{fill:a},shape:{stroke:a},symbol:{stroke:a},circle:{fill:a},view:{fill:r,stroke:r},group:{fill:r},title:{color:i,anchor:"start",dy:-15,fontSize:16,font:F_,fontWeight:600},axis:{labelColor:s,labelFontSize:12,labelFont:EEe,labelFontWeight:D_,titleColor:i,titleFontWeight:600,titleFontSize:12,grid:!0,gridColor:Um.layerAccent01[e],labelAngle:0},axisX:{titlePadding:10},axisY:{titlePadding:2.5},style:{"guide-label":{font:F_,fill:s,fontWeight:D_},"guide-title":{font:F_,fill:s,fontWeight:D_}},range:{category:o,diverging:["#750e13","#a2191f","#da1e28","#fa4d56","#ff8389","#ffb3b8","#ffd7d9","#fff1f1","#e5f6ff","#bae6ff","#82cfff","#33b1ff","#1192e8","#0072c3","#00539a","#003a6d"],heatmap:["#f6f2ff","#e8daff","#d4bbff","#be95ff","#a56eff","#8a3ffc","#6929c4","#491d8b","#31135e","#1c0f30"]}}}const SEe=O2({theme:"white",background:"#ffffff"}),CEe=O2({theme:"g10",background:"#f4f4f4"}),$Ee=O2({theme:"g90",background:"#262626"}),FEe=O2({theme:"g100",background:"#161616"}),DEe=Vwe.version,MEe=Object.freeze(Object.defineProperty({__proto__:null,carbong10:CEe,carbong100:FEe,carbong90:$Ee,carbonwhite:SEe,dark:Xwe,excel:Kwe,fivethirtyeight:Qwe,ggplot2:eEe,googlecharts:dEe,latimes:iEe,powerbi:wEe,quartz:sEe,urbaninstitute:fEe,version:DEe,vox:oEe},Symbol.toStringTag,{value:"Module"}));function TEe(e,t,n,r){if(fe(e))return`[${e.map(i=>t(ze(i)?i:P8(i,n))).join(", ")}]`;if(Pe(e)){let i="";const{title:s,image:o,...a}=e;s&&(i+=`

      ${t(s)}

      `),o&&(i+=``);const l=Object.keys(a);if(l.length>0){i+="";for(const u of l){let c=a[u];c!==void 0&&(Pe(c)&&(c=P8(c,n)),i+=``)}i+="
      ${t(u)}${t(c)}
      "}return i||"{}"}return t(e)}function REe(e){const t=[];return function(n,r){if(typeof r!="object"||r===null)return r;const i=t.indexOf(this)+1;return t.length=i,t.length>e?"[Object]":t.indexOf(r)>=0?"[Circular]":(t.push(r),r)}}function P8(e,t){return JSON.stringify(e,REe(t))}var NEe=`#vg-tooltip-element { + visibility: hidden; + padding: 8px; + position: fixed; + z-index: 1000; + font-family: sans-serif; + font-size: 11px; + border-radius: 3px; + box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1); + /* The default theme is the light theme. */ + background-color: rgba(255, 255, 255, 0.95); + border: 1px solid #d9d9d9; + color: black; +} +#vg-tooltip-element.visible { + visibility: visible; +} +#vg-tooltip-element h2 { + margin-top: 0; + margin-bottom: 10px; + font-size: 13px; +} +#vg-tooltip-element table { + border-spacing: 0; +} +#vg-tooltip-element table tr { + border: none; +} +#vg-tooltip-element table tr td { + overflow: hidden; + text-overflow: ellipsis; + padding-top: 2px; + padding-bottom: 2px; +} +#vg-tooltip-element table tr td.key { + color: #808080; + max-width: 150px; + text-align: right; + padding-right: 4px; +} +#vg-tooltip-element table tr td.value { + display: block; + max-width: 300px; + max-height: 7em; + text-align: left; +} +#vg-tooltip-element.dark-theme { + background-color: rgba(32, 32, 32, 0.9); + border: 1px solid #f5f5f5; + color: white; +} +#vg-tooltip-element.dark-theme td.key { + color: #bfbfbf; +} +`;const xq="vg-tooltip-element",OEe={offsetX:10,offsetY:10,id:xq,styleId:"vega-tooltip-style",theme:"light",disableDefaultStyle:!1,sanitize:LEe,maxDepth:2,formatTooltip:TEe,baseURL:"",anchor:"cursor",position:["top","bottom","left","right","top-left","top-right","bottom-left","bottom-right"]};function LEe(e){return String(e).replace(/&/g,"&").replace(/=0&&e.y>=0&&e.x+t.width<=window.innerWidth&&e.y+t.height<=window.innerHeight}function zEe(e,t,n){return e.clientX>=t.x&&e.clientX<=t.x+n.width&&e.clientY>=t.y&&e.clientY<=t.y+n.height}class jEe{constructor(t){this.options={...OEe,...t};const n=this.options.id;if(this.el=null,this.call=this.tooltipHandler.bind(this),!this.options.disableDefaultStyle&&!document.getElementById(this.options.styleId)){const r=document.createElement("style");r.setAttribute("id",this.options.styleId),r.innerHTML=IEe(n);const i=document.head;i.childNodes.length>0?i.insertBefore(r,i.childNodes[0]):i.appendChild(r)}}tooltipHandler(t,n,r,i){if(this.el=document.getElementById(this.options.id),this.el||(this.el=document.createElement("div"),this.el.setAttribute("id",this.options.id),this.el.classList.add("vg-tooltip"),(document.fullscreenElement??document.body).appendChild(this.el)),i==null||i===""){this.el.classList.remove("visible",`${this.options.theme}-theme`);return}this.el.innerHTML=this.options.formatTooltip(i,this.options.sanitize,this.options.maxDepth,this.options.baseURL),this.el.classList.add("visible",`${this.options.theme}-theme`);const{x:s,y:o}=this.options.anchor==="mark"?PEe(t,n,r,this.el.getBoundingClientRect(),this.options):_q(n,this.el.getBoundingClientRect(),this.options);this.el.style.top=`${o}px`,this.el.style.left=`${s}px`}}var M_={};/*! + * https://github.com/Starcounter-Jack/JSON-Patch + * (c) 2017-2022 Joachim Wester + * MIT licensed + */var UEe=(function(){var e=function(t,n){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,i){r.__proto__=i}||function(r,i){for(var s in i)i.hasOwnProperty(s)&&(r[s]=i[s])},e(t,n)};return function(t,n){e(t,n);function r(){this.constructor=t}t.prototype=n===null?Object.create(n):(r.prototype=n.prototype,new r)}})(),qEe=Object.prototype.hasOwnProperty;function DA(e,t){return qEe.call(e,t)}function MA(e){if(Array.isArray(e)){for(var t=new Array(e.length),n=0;n=48&&r<=57){t++;continue}return!1}return!0}function rc(e){return e.indexOf("/")===-1&&e.indexOf("~")===-1?e:e.replace(/~/g,"~0").replace(/\//g,"~1")}function Aq(e){return e.replace(/~1/g,"/").replace(/~0/g,"~")}function RA(e){if(e===void 0)return!0;if(e){if(Array.isArray(e)){for(var t=0,n=e.length;t0&&l[c-1]=="constructor"))throw new TypeError("JSON-Patch: modifying `__proto__` or `constructor/prototype` prop is banned for security reasons, if this was on purpose, please set `banPrototypeModifications` flag false and pass it to this function. More info in fast-json-patch README");if(n&&d===void 0&&(u[h]===void 0?d=l.slice(0,c).join("/"):c==f-1&&(d=t.path),d!==void 0&&p(t,0,e,d)),c++,Array.isArray(u)){if(h==="-")h=u.length;else{if(n&&!TA(h))throw new Tn("Expected an unsigned base-10 integer value, making the new referenced value the array element with the zero-based index","OPERATION_PATH_ILLEGAL_ARRAY_INDEX",s,t,e);TA(h)&&(h=~~h)}if(c>=f){if(n&&t.op==="add"&&h>u.length)throw new Tn("The specified index MUST NOT be greater than the number of elements in the array","OPERATION_VALUE_OUT_OF_BOUNDS",s,t,e);var o=HEe[t.op].call(t,u,h,e);if(o.test===!1)throw new Tn("Test operation failed","TEST_OPERATION_FAILED",s,t,e);return o}}else if(c>=f){var o=rd[t.op].call(t,u,h,e);if(o.test===!1)throw new Tn("Test operation failed","TEST_OPERATION_FAILED",s,t,e);return o}if(u=u[h],n&&c0)throw new Tn('Operation `path` property must start with "/"',"OPERATION_PATH_INVALID",t,e,n);if((e.op==="move"||e.op==="copy")&&typeof e.from!="string")throw new Tn("Operation `from` property is not present (applicable in `move` and `copy` operations)","OPERATION_FROM_REQUIRED",t,e,n);if((e.op==="add"||e.op==="replace"||e.op==="test")&&e.value===void 0)throw new Tn("Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)","OPERATION_VALUE_REQUIRED",t,e,n);if((e.op==="add"||e.op==="replace"||e.op==="test")&&RA(e.value))throw new Tn("Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)","OPERATION_VALUE_CANNOT_CONTAIN_UNDEFINED",t,e,n);if(n){if(e.op=="add"){var i=e.path.split("/").length,s=r.split("/").length;if(i!==s+1&&i!==s)throw new Tn("Cannot perform an `add` operation at the desired path","OPERATION_PATH_CANNOT_ADD",t,e,n)}else if(e.op==="replace"||e.op==="remove"||e.op==="_get"){if(e.path!==r)throw new Tn("Cannot perform the operation at a path that does not exist","OPERATION_PATH_UNRESOLVABLE",t,e,n)}else if(e.op==="move"||e.op==="copy"){var o={op:"_get",path:e.from,value:void 0},a=Sq([o],n);if(a&&a.name==="OPERATION_PATH_UNRESOLVABLE")throw new Tn("Cannot perform the operation from a path that does not exist","OPERATION_FROM_UNRESOLVABLE",t,e,n)}}}else throw new Tn("Operation `op` property is not one of operations defined in RFC-6902","OPERATION_OP_INVALID",t,e,n)}function Sq(e,t,n){try{if(!Array.isArray(e))throw new Tn("Patch sequence must be an array","SEQUENCE_NOT_AN_ARRAY");if(t)L2(os(t),os(e),n||!0);else{n=n||yy;for(var r=0;r0&&(e.patches=[],e.callback&&e.callback(r)),r}function DF(e,t,n,r,i){if(t!==e){typeof t.toJSON=="function"&&(t=t.toJSON());for(var s=MA(t),o=MA(e),a=!1,l=o.length-1;l>=0;l--){var u=o[l],c=e[u];if(DA(t,u)&&!(t[u]===void 0&&c!==void 0&&Array.isArray(t)===!1)){var f=t[u];typeof c=="object"&&c!=null&&typeof f=="object"&&f!=null&&Array.isArray(c)===Array.isArray(f)?DF(c,f,n,r+"/"+rc(u),i):c!==f&&(i&&n.push({op:"test",path:r+"/"+rc(u),value:os(c)}),n.push({op:"replace",path:r+"/"+rc(u),value:os(f)}))}else Array.isArray(e)===Array.isArray(t)?(i&&n.push({op:"test",path:r+"/"+rc(u),value:os(c)}),n.push({op:"remove",path:r+"/"+rc(u)}),a=!0):(i&&n.push({op:"test",path:r,value:e}),n.push({op:"replace",path:r,value:t}))}if(!(!a&&s.length==o.length))for(var l=0;l=this.max){const s=this.map.keys().next().value;this.delete(s)}this.map.set(n,r)}return this}}return T_=e,T_}var R_,j8;function MF(){if(j8)return R_;j8=1;const e=Object.freeze({loose:!0}),t=Object.freeze({});return R_=r=>r?typeof r!="object"?e:r:t,R_}var qm={exports:{}},N_,U8;function TF(){if(U8)return N_;U8=1;const e="2.0.0",t=256,n=Number.MAX_SAFE_INTEGER||9007199254740991,r=16,i=t-6;return N_={MAX_LENGTH:t,MAX_SAFE_COMPONENT_LENGTH:r,MAX_SAFE_BUILD_LENGTH:i,MAX_SAFE_INTEGER:n,RELEASE_TYPES:["major","premajor","minor","preminor","patch","prepatch","prerelease"],SEMVER_SPEC_VERSION:e,FLAG_INCLUDE_PRERELEASE:1,FLAG_LOOSE:2},N_}var O_,q8;function I2(){return q8||(q8=1,O_=typeof process=="object"&&M_&&M_.NODE_DEBUG&&/\bsemver\b/i.test(M_.NODE_DEBUG)?(...t)=>console.error("SEMVER",...t):()=>{}),O_}var W8;function RF(){return W8||(W8=1,(function(e,t){const{MAX_SAFE_COMPONENT_LENGTH:n,MAX_SAFE_BUILD_LENGTH:r,MAX_LENGTH:i}=TF(),s=I2();t=e.exports={};const o=t.re=[],a=t.safeRe=[],l=t.src=[],u=t.t={};let c=0;const f="[a-zA-Z0-9-]",d=[["\\s",1],["\\d",i],[f,r]],h=g=>{for(const[m,v]of d)g=g.split(`${m}*`).join(`${m}{0,${v}}`).split(`${m}+`).join(`${m}{1,${v}}`);return g},p=(g,m,v)=>{const b=h(m),x=c++;s(g,x,m),u[g]=x,l[x]=m,o[x]=new RegExp(m,v?"g":void 0),a[x]=new RegExp(b,v?"g":void 0)};p("NUMERICIDENTIFIER","0|[1-9]\\d*"),p("NUMERICIDENTIFIERLOOSE","\\d+"),p("NONNUMERICIDENTIFIER",`\\d*[a-zA-Z-]${f}*`),p("MAINVERSION",`(${l[u.NUMERICIDENTIFIER]})\\.(${l[u.NUMERICIDENTIFIER]})\\.(${l[u.NUMERICIDENTIFIER]})`),p("MAINVERSIONLOOSE",`(${l[u.NUMERICIDENTIFIERLOOSE]})\\.(${l[u.NUMERICIDENTIFIERLOOSE]})\\.(${l[u.NUMERICIDENTIFIERLOOSE]})`),p("PRERELEASEIDENTIFIER",`(?:${l[u.NUMERICIDENTIFIER]}|${l[u.NONNUMERICIDENTIFIER]})`),p("PRERELEASEIDENTIFIERLOOSE",`(?:${l[u.NUMERICIDENTIFIERLOOSE]}|${l[u.NONNUMERICIDENTIFIER]})`),p("PRERELEASE",`(?:-(${l[u.PRERELEASEIDENTIFIER]}(?:\\.${l[u.PRERELEASEIDENTIFIER]})*))`),p("PRERELEASELOOSE",`(?:-?(${l[u.PRERELEASEIDENTIFIERLOOSE]}(?:\\.${l[u.PRERELEASEIDENTIFIERLOOSE]})*))`),p("BUILDIDENTIFIER",`${f}+`),p("BUILD",`(?:\\+(${l[u.BUILDIDENTIFIER]}(?:\\.${l[u.BUILDIDENTIFIER]})*))`),p("FULLPLAIN",`v?${l[u.MAINVERSION]}${l[u.PRERELEASE]}?${l[u.BUILD]}?`),p("FULL",`^${l[u.FULLPLAIN]}$`),p("LOOSEPLAIN",`[v=\\s]*${l[u.MAINVERSIONLOOSE]}${l[u.PRERELEASELOOSE]}?${l[u.BUILD]}?`),p("LOOSE",`^${l[u.LOOSEPLAIN]}$`),p("GTLT","((?:<|>)?=?)"),p("XRANGEIDENTIFIERLOOSE",`${l[u.NUMERICIDENTIFIERLOOSE]}|x|X|\\*`),p("XRANGEIDENTIFIER",`${l[u.NUMERICIDENTIFIER]}|x|X|\\*`),p("XRANGEPLAIN",`[v=\\s]*(${l[u.XRANGEIDENTIFIER]})(?:\\.(${l[u.XRANGEIDENTIFIER]})(?:\\.(${l[u.XRANGEIDENTIFIER]})(?:${l[u.PRERELEASE]})?${l[u.BUILD]}?)?)?`),p("XRANGEPLAINLOOSE",`[v=\\s]*(${l[u.XRANGEIDENTIFIERLOOSE]})(?:\\.(${l[u.XRANGEIDENTIFIERLOOSE]})(?:\\.(${l[u.XRANGEIDENTIFIERLOOSE]})(?:${l[u.PRERELEASELOOSE]})?${l[u.BUILD]}?)?)?`),p("XRANGE",`^${l[u.GTLT]}\\s*${l[u.XRANGEPLAIN]}$`),p("XRANGELOOSE",`^${l[u.GTLT]}\\s*${l[u.XRANGEPLAINLOOSE]}$`),p("COERCEPLAIN",`(^|[^\\d])(\\d{1,${n}})(?:\\.(\\d{1,${n}}))?(?:\\.(\\d{1,${n}}))?`),p("COERCE",`${l[u.COERCEPLAIN]}(?:$|[^\\d])`),p("COERCEFULL",l[u.COERCEPLAIN]+`(?:${l[u.PRERELEASE]})?(?:${l[u.BUILD]})?(?:$|[^\\d])`),p("COERCERTL",l[u.COERCE],!0),p("COERCERTLFULL",l[u.COERCEFULL],!0),p("LONETILDE","(?:~>?)"),p("TILDETRIM",`(\\s*)${l[u.LONETILDE]}\\s+`,!0),t.tildeTrimReplace="$1~",p("TILDE",`^${l[u.LONETILDE]}${l[u.XRANGEPLAIN]}$`),p("TILDELOOSE",`^${l[u.LONETILDE]}${l[u.XRANGEPLAINLOOSE]}$`),p("LONECARET","(?:\\^)"),p("CARETTRIM",`(\\s*)${l[u.LONECARET]}\\s+`,!0),t.caretTrimReplace="$1^",p("CARET",`^${l[u.LONECARET]}${l[u.XRANGEPLAIN]}$`),p("CARETLOOSE",`^${l[u.LONECARET]}${l[u.XRANGEPLAINLOOSE]}$`),p("COMPARATORLOOSE",`^${l[u.GTLT]}\\s*(${l[u.LOOSEPLAIN]})$|^$`),p("COMPARATOR",`^${l[u.GTLT]}\\s*(${l[u.FULLPLAIN]})$|^$`),p("COMPARATORTRIM",`(\\s*)${l[u.GTLT]}\\s*(${l[u.LOOSEPLAIN]}|${l[u.XRANGEPLAIN]})`,!0),t.comparatorTrimReplace="$1$2$3",p("HYPHENRANGE",`^\\s*(${l[u.XRANGEPLAIN]})\\s+-\\s+(${l[u.XRANGEPLAIN]})\\s*$`),p("HYPHENRANGELOOSE",`^\\s*(${l[u.XRANGEPLAINLOOSE]})\\s+-\\s+(${l[u.XRANGEPLAINLOOSE]})\\s*$`),p("STAR","(<|>)?=?\\s*\\*"),p("GTE0","^\\s*>=\\s*0\\.0\\.0\\s*$"),p("GTE0PRE","^\\s*>=\\s*0\\.0\\.0-0\\s*$")})(qm,qm.exports)),qm.exports}var L_,H8;function sAe(){if(H8)return L_;H8=1;const e=/^[0-9]+$/,t=(r,i)=>{const s=e.test(r),o=e.test(i);return s&&o&&(r=+r,i=+i),r===i?0:s&&!o?-1:o&&!s?1:rt(i,r)},L_}var I_,G8;function NF(){if(G8)return I_;G8=1;const e=I2(),{MAX_LENGTH:t,MAX_SAFE_INTEGER:n}=TF(),{safeRe:r,t:i}=RF(),s=MF(),{compareIdentifiers:o}=sAe();class a{constructor(u,c){if(c=s(c),u instanceof a){if(u.loose===!!c.loose&&u.includePrerelease===!!c.includePrerelease)return u;u=u.version}else if(typeof u!="string")throw new TypeError(`Invalid version. Must be a string. Got type "${typeof u}".`);if(u.length>t)throw new TypeError(`version is longer than ${t} characters`);e("SemVer",u,c),this.options=c,this.loose=!!c.loose,this.includePrerelease=!!c.includePrerelease;const f=u.trim().match(c.loose?r[i.LOOSE]:r[i.FULL]);if(!f)throw new TypeError(`Invalid Version: ${u}`);if(this.raw=u,this.major=+f[1],this.minor=+f[2],this.patch=+f[3],this.major>n||this.major<0)throw new TypeError("Invalid major version");if(this.minor>n||this.minor<0)throw new TypeError("Invalid minor version");if(this.patch>n||this.patch<0)throw new TypeError("Invalid patch version");f[4]?this.prerelease=f[4].split(".").map(d=>{if(/^[0-9]+$/.test(d)){const h=+d;if(h>=0&&h=0;)typeof this.prerelease[h]=="number"&&(this.prerelease[h]++,h=-2);if(h===-1){if(c===this.prerelease.join(".")&&f===!1)throw new Error("invalid increment argument: identifier already exists");this.prerelease.push(d)}}if(c){let h=[c,d];f===!1&&(h=[c]),o(this.prerelease[0],c)===0?isNaN(this.prerelease[1])&&(this.prerelease=h):this.prerelease=h}break}default:throw new Error(`invalid increment argument: ${u}`)}return this.raw=this.format(),this.build.length&&(this.raw+=`+${this.build.join(".")}`),this}}return I_=a,I_}var P_,Y8;function zh(){if(Y8)return P_;Y8=1;const e=NF();return P_=(n,r,i)=>new e(n,i).compare(new e(r,i)),P_}var B_,V8;function oAe(){if(V8)return B_;V8=1;const e=zh();return B_=(n,r,i)=>e(n,r,i)===0,B_}var z_,X8;function aAe(){if(X8)return z_;X8=1;const e=zh();return z_=(n,r,i)=>e(n,r,i)!==0,z_}var j_,K8;function lAe(){if(K8)return j_;K8=1;const e=zh();return j_=(n,r,i)=>e(n,r,i)>0,j_}var U_,Z8;function uAe(){if(Z8)return U_;Z8=1;const e=zh();return U_=(n,r,i)=>e(n,r,i)>=0,U_}var q_,J8;function cAe(){if(J8)return q_;J8=1;const e=zh();return q_=(n,r,i)=>e(n,r,i)<0,q_}var W_,Q8;function fAe(){if(Q8)return W_;Q8=1;const e=zh();return W_=(n,r,i)=>e(n,r,i)<=0,W_}var H_,eT;function dAe(){if(eT)return H_;eT=1;const e=oAe(),t=aAe(),n=lAe(),r=uAe(),i=cAe(),s=fAe();return H_=(a,l,u,c)=>{switch(l){case"===":return typeof a=="object"&&(a=a.version),typeof u=="object"&&(u=u.version),a===u;case"!==":return typeof a=="object"&&(a=a.version),typeof u=="object"&&(u=u.version),a!==u;case"":case"=":case"==":return e(a,u,c);case"!=":return t(a,u,c);case">":return n(a,u,c);case">=":return r(a,u,c);case"<":return i(a,u,c);case"<=":return s(a,u,c);default:throw new TypeError(`Invalid operator: ${l}`)}},H_}var G_,tT;function hAe(){if(tT)return G_;tT=1;const e=Symbol("SemVer ANY");class t{static get ANY(){return e}constructor(c,f){if(f=n(f),c instanceof t){if(c.loose===!!f.loose)return c;c=c.value}c=c.trim().split(/\s+/).join(" "),o("comparator",c,f),this.options=f,this.loose=!!f.loose,this.parse(c),this.semver===e?this.value="":this.value=this.operator+this.semver.version,o("comp",this)}parse(c){const f=this.options.loose?r[i.COMPARATORLOOSE]:r[i.COMPARATOR],d=c.match(f);if(!d)throw new TypeError(`Invalid comparator: ${c}`);this.operator=d[1]!==void 0?d[1]:"",this.operator==="="&&(this.operator=""),d[2]?this.semver=new a(d[2],this.options.loose):this.semver=e}toString(){return this.value}test(c){if(o("Comparator.test",c,this.options.loose),this.semver===e||c===e)return!0;if(typeof c=="string")try{c=new a(c,this.options)}catch{return!1}return s(c,this.operator,this.semver,this.options)}intersects(c,f){if(!(c instanceof t))throw new TypeError("a Comparator is required");return this.operator===""?this.value===""?!0:new l(c.value,f).test(this.value):c.operator===""?c.value===""?!0:new l(this.value,f).test(c.semver):(f=n(f),f.includePrerelease&&(this.value==="<0.0.0-0"||c.value==="<0.0.0-0")||!f.includePrerelease&&(this.value.startsWith("<0.0.0")||c.value.startsWith("<0.0.0"))?!1:!!(this.operator.startsWith(">")&&c.operator.startsWith(">")||this.operator.startsWith("<")&&c.operator.startsWith("<")||this.semver.version===c.semver.version&&this.operator.includes("=")&&c.operator.includes("=")||s(this.semver,"<",c.semver,f)&&this.operator.startsWith(">")&&c.operator.startsWith("<")||s(this.semver,">",c.semver,f)&&this.operator.startsWith("<")&&c.operator.startsWith(">")))}}G_=t;const n=MF(),{safeRe:r,t:i}=RF(),s=dAe(),o=I2(),a=NF(),l=Cq();return G_}var Y_,nT;function Cq(){if(nT)return Y_;nT=1;const e=/\s+/g;class t{constructor(F,R){if(R=i(R),F instanceof t)return F.loose===!!R.loose&&F.includePrerelease===!!R.includePrerelease?F:new t(F.raw,R);if(F instanceof s)return this.raw=F.value,this.set=[[F]],this.formatted=void 0,this;if(this.options=R,this.loose=!!R.loose,this.includePrerelease=!!R.includePrerelease,this.raw=F.trim().replace(e," "),this.set=this.raw.split("||").map(z=>this.parseRange(z.trim())).filter(z=>z.length),!this.set.length)throw new TypeError(`Invalid SemVer Range: ${this.raw}`);if(this.set.length>1){const z=this.set[0];if(this.set=this.set.filter(j=>!g(j[0])),this.set.length===0)this.set=[z];else if(this.set.length>1){for(const j of this.set)if(j.length===1&&m(j[0])){this.set=[j];break}}}this.formatted=void 0}get range(){if(this.formatted===void 0){this.formatted="";for(let F=0;F0&&(this.formatted+="||");const R=this.set[F];for(let z=0;z0&&(this.formatted+=" "),this.formatted+=R[z].toString().trim()}}return this.formatted}format(){return this.range}toString(){return this.range}parseRange(F){const z=((this.options.includePrerelease&&h)|(this.options.loose&&p))+":"+F,j=r.get(z);if(j)return j;const q=this.options.loose,te=q?l[u.HYPHENRANGELOOSE]:l[u.HYPHENRANGE];F=F.replace(te,O(this.options.includePrerelease)),o("hyphen replace",F),F=F.replace(l[u.COMPARATORTRIM],c),o("comparator trim",F),F=F.replace(l[u.TILDETRIM],f),o("tilde trim",F),F=F.replace(l[u.CARETTRIM],d),o("caret trim",F);let Y=F.split(" ").map(Z=>b(Z,this.options)).join(" ").split(/\s+/).map(Z=>M(Z,this.options));q&&(Y=Y.filter(Z=>(o("loose invalid filter",Z,this.options),!!Z.match(l[u.COMPARATORLOOSE])))),o("range list",Y);const ee=new Map,_e=Y.map(Z=>new s(Z,this.options));for(const Z of _e){if(g(Z))return[Z];ee.set(Z.value,Z)}ee.size>1&&ee.has("")&&ee.delete("");const Le=[...ee.values()];return r.set(z,Le),Le}intersects(F,R){if(!(F instanceof t))throw new TypeError("a Range is required");return this.set.some(z=>v(z,R)&&F.set.some(j=>v(j,R)&&z.every(q=>j.every(te=>q.intersects(te,R)))))}test(F){if(!F)return!1;if(typeof F=="string")try{F=new a(F,this.options)}catch{return!1}for(let R=0;RT.value==="<0.0.0-0",m=T=>T.value==="",v=(T,F)=>{let R=!0;const z=T.slice();let j=z.pop();for(;R&&z.length;)R=z.every(q=>j.intersects(q,F)),j=z.pop();return R},b=(T,F)=>(o("comp",T,F),T=A(T,F),o("caret",T),T=_(T,F),o("tildes",T),T=k(T,F),o("xrange",T),T=$(T,F),o("stars",T),T),x=T=>!T||T.toLowerCase()==="x"||T==="*",_=(T,F)=>T.trim().split(/\s+/).map(R=>w(R,F)).join(" "),w=(T,F)=>{const R=F.loose?l[u.TILDELOOSE]:l[u.TILDE];return T.replace(R,(z,j,q,te,Y)=>{o("tilde",T,z,j,q,te,Y);let ee;return x(j)?ee="":x(q)?ee=`>=${j}.0.0 <${+j+1}.0.0-0`:x(te)?ee=`>=${j}.${q}.0 <${j}.${+q+1}.0-0`:Y?(o("replaceTilde pr",Y),ee=`>=${j}.${q}.${te}-${Y} <${j}.${+q+1}.0-0`):ee=`>=${j}.${q}.${te} <${j}.${+q+1}.0-0`,o("tilde return",ee),ee})},A=(T,F)=>T.trim().split(/\s+/).map(R=>E(R,F)).join(" "),E=(T,F)=>{o("caret",T,F);const R=F.loose?l[u.CARETLOOSE]:l[u.CARET],z=F.includePrerelease?"-0":"";return T.replace(R,(j,q,te,Y,ee)=>{o("caret",T,j,q,te,Y,ee);let _e;return x(q)?_e="":x(te)?_e=`>=${q}.0.0${z} <${+q+1}.0.0-0`:x(Y)?q==="0"?_e=`>=${q}.${te}.0${z} <${q}.${+te+1}.0-0`:_e=`>=${q}.${te}.0${z} <${+q+1}.0.0-0`:ee?(o("replaceCaret pr",ee),q==="0"?te==="0"?_e=`>=${q}.${te}.${Y}-${ee} <${q}.${te}.${+Y+1}-0`:_e=`>=${q}.${te}.${Y}-${ee} <${q}.${+te+1}.0-0`:_e=`>=${q}.${te}.${Y}-${ee} <${+q+1}.0.0-0`):(o("no pr"),q==="0"?te==="0"?_e=`>=${q}.${te}.${Y}${z} <${q}.${te}.${+Y+1}-0`:_e=`>=${q}.${te}.${Y}${z} <${q}.${+te+1}.0-0`:_e=`>=${q}.${te}.${Y} <${+q+1}.0.0-0`),o("caret return",_e),_e})},k=(T,F)=>(o("replaceXRanges",T,F),T.split(/\s+/).map(R=>S(R,F)).join(" ")),S=(T,F)=>{T=T.trim();const R=F.loose?l[u.XRANGELOOSE]:l[u.XRANGE];return T.replace(R,(z,j,q,te,Y,ee)=>{o("xRange",T,z,j,q,te,Y,ee);const _e=x(q),Le=_e||x(te),Z=Le||x(Y),he=Z;return j==="="&&he&&(j=""),ee=F.includePrerelease?"-0":"",_e?j===">"||j==="<"?z="<0.0.0-0":z="*":j&&he?(Le&&(te=0),Y=0,j===">"?(j=">=",Le?(q=+q+1,te=0,Y=0):(te=+te+1,Y=0)):j==="<="&&(j="<",Le?q=+q+1:te=+te+1),j==="<"&&(ee="-0"),z=`${j+q}.${te}.${Y}${ee}`):Le?z=`>=${q}.0.0${ee} <${+q+1}.0.0-0`:Z&&(z=`>=${q}.${te}.0${ee} <${q}.${+te+1}.0-0`),o("xRange return",z),z})},$=(T,F)=>(o("replaceStars",T,F),T.trim().replace(l[u.STAR],"")),M=(T,F)=>(o("replaceGTE0",T,F),T.trim().replace(l[F.includePrerelease?u.GTE0PRE:u.GTE0],"")),O=T=>(F,R,z,j,q,te,Y,ee,_e,Le,Z,he)=>(x(z)?R="":x(j)?R=`>=${z}.0.0${T?"-0":""}`:x(q)?R=`>=${z}.${j}.0${T?"-0":""}`:te?R=`>=${R}`:R=`>=${R}${T?"-0":""}`,x(_e)?ee="":x(Le)?ee=`<${+_e+1}.0.0-0`:x(Z)?ee=`<${_e}.${+Le+1}.0-0`:he?ee=`<=${_e}.${Le}.${Z}-${he}`:T?ee=`<${_e}.${Le}.${+Z+1}-0`:ee=`<=${ee}`,`${R} ${ee}`.trim()),P=(T,F,R)=>{for(let z=0;z0){const j=T[z].semver;if(j.major===F.major&&j.minor===F.minor&&j.patch===F.patch)return!0}return!1}return!0};return Y_}var V_,rT;function pAe(){if(rT)return V_;rT=1;const e=Cq();return V_=(n,r,i)=>{try{r=new e(r,i)}catch{return!1}return r.test(n)},V_}var gAe=pAe(),$q=rAe(gAe);function mAe(e,t,n){const r=e.open(t),i=250,{origin:s}=new URL(t);let o=40;function a(u){u.source===r&&(o=0,e.removeEventListener("message",a,!1))}e.addEventListener("message",a,!1);function l(){o<=0||(r.postMessage(n,s),setTimeout(l,i),o-=1)}setTimeout(l,i)}var vAe=`.vega-embed { + position: relative; + display: inline-block; + box-sizing: border-box; +} +.vega-embed.has-actions { + padding-right: 38px; +} +.vega-embed details:not([open]) > :not(summary) { + display: none !important; +} +.vega-embed summary { + list-style: none; + position: absolute; + top: 0; + right: 0; + padding: 6px; + z-index: 1000; + background: white; + box-shadow: 1px 1px 3px rgba(0, 0, 0, 0.1); + color: #1b1e23; + border: 1px solid #aaa; + border-radius: 999px; + opacity: 0.2; + transition: opacity 0.4s ease-in; + cursor: pointer; + line-height: 0px; +} +.vega-embed summary::-webkit-details-marker { + display: none; +} +.vega-embed summary:active { + box-shadow: #aaa 0px 0px 0px 1px inset; +} +.vega-embed summary svg { + width: 14px; + height: 14px; +} +.vega-embed details[open] summary { + opacity: 0.7; +} +.vega-embed:hover summary, .vega-embed:focus-within summary { + opacity: 1 !important; + transition: opacity 0.2s ease; +} +.vega-embed .vega-actions { + position: absolute; + z-index: 1001; + top: 35px; + right: -9px; + display: flex; + flex-direction: column; + padding-bottom: 8px; + padding-top: 8px; + border-radius: 4px; + box-shadow: 0 2px 8px 0 rgba(0, 0, 0, 0.2); + border: 1px solid #d9d9d9; + background: white; + animation-duration: 0.15s; + animation-name: scale-in; + animation-timing-function: cubic-bezier(0.2, 0, 0.13, 1.5); + text-align: left; +} +.vega-embed .vega-actions a { + padding: 8px 16px; + font-family: sans-serif; + font-size: 14px; + font-weight: 600; + white-space: nowrap; + color: #434a56; + text-decoration: none; +} +.vega-embed .vega-actions a:hover, .vega-embed .vega-actions a:focus { + background-color: #f7f7f9; + color: black; +} +.vega-embed .vega-actions::before, .vega-embed .vega-actions::after { + content: ""; + display: inline-block; + position: absolute; +} +.vega-embed .vega-actions::before { + left: auto; + right: 14px; + top: -16px; + border: 8px solid rgba(0, 0, 0, 0); + border-bottom-color: #d9d9d9; +} +.vega-embed .vega-actions::after { + left: auto; + right: 15px; + top: -14px; + border: 7px solid rgba(0, 0, 0, 0); + border-bottom-color: #fff; +} +.vega-embed .chart-wrapper.fit-x { + width: 100%; +} +.vega-embed .chart-wrapper.fit-y { + height: 100%; +} + +.vega-embed-wrapper { + max-width: 100%; + overflow: auto; + padding-right: 14px; +} + +@keyframes scale-in { + from { + opacity: 0; + transform: scale(0.6); + } + to { + opacity: 1; + transform: scale(1); + } +} +`;function Fq(e,...t){for(const n of t)yAe(e,n);return e}function yAe(e,t){for(const n of Object.keys(t))mh(e,n,t[n],!0)}const Po=Yge;let qg=Gwe;const Wm=typeof window<"u"?window:void 0;var TT;qg===void 0&&((TT=Wm==null?void 0:Wm.vl)!=null&&TT.compile)&&(qg=Wm.vl);const bAe={export:{svg:!0,png:!0},source:!0,compiled:!0,editor:!0},xAe={CLICK_TO_VIEW_ACTIONS:"Click to view actions",COMPILED_ACTION:"View Compiled Vega",EDITOR_ACTION:"Open in Vega Editor",PNG_ACTION:"Save as PNG",SOURCE_ACTION:"View Source",SVG_ACTION:"Save as SVG"},jp={vega:"Vega","vega-lite":"Vega-Lite"},by={vega:Po.version,"vega-lite":qg?qg.version:"not available"},_Ae={vega:e=>e,"vega-lite":(e,t)=>qg.compile(e,{config:t}).spec},wAe=` + + + + +`,EAe="chart-wrapper";function AAe(e){return typeof e=="function"}function iT(e,t,n,r){const i=`${t}
      `,s=`
      ${n}`,o=window.open("");o.document.write(i+e+s),o.document.title=`${jp[r]} JSON Source`}function kAe(e,t){if(e.$schema){const n=vq(e.$schema);t&&t!==n.library&&console.warn(`The given visualization spec is written in ${jp[n.library]}, but mode argument sets ${jp[t]??t}.`);const r=n.library;return $q(by[r],`^${n.version.slice(1)}`)||console.warn(`The input spec uses ${jp[r]} ${n.version}, but the current version of ${jp[r]} is v${by[r]}.`),r}return"mark"in e||"encoding"in e||"layer"in e||"hconcat"in e||"vconcat"in e||"facet"in e||"repeat"in e?"vega-lite":"marks"in e||"signals"in e||"scales"in e||"axes"in e?"vega":t??"vega"}function Dq(e){return!!(e&&"load"in e)}function sT(e){return Dq(e)?e:Po.loader(e)}function SAe(e){var n;const t=((n=e.usermeta)==null?void 0:n.embedOptions)??{};return ze(t.defaultStyle)&&(t.defaultStyle=!1),t}async function Mq(e,t,n={}){let r,i;ze(t)?(i=sT(n.loader),r=JSON.parse(await i.load(t))):r=t;const s=SAe(r),o=s.loader;(!i||o)&&(i=sT(n.loader??o));const a=await oT(s,i),l=await oT(n,i),u={...Fq(l,a),config:gh(l.config??{},a.config??{})};return await $Ae(e,r,u,i)}async function oT(e,t){const n=ze(e.config)?JSON.parse(await t.load(e.config)):e.config??{},r=ze(e.patch)?JSON.parse(await t.load(e.patch)):e.patch;return{...e,...r?{patch:r}:{},...n?{config:n}:{}}}function CAe(e){const t=e.getRootNode?e.getRootNode():document;return t instanceof ShadowRoot?{root:t,rootContainer:t}:{root:document,rootContainer:document.head??document.body}}async function $Ae(e,t,n={},r){const i=n.theme?gh(MEe[n.theme],n.config??{}):n.config,s=wu(n.actions)?n.actions:Fq({},bAe,n.actions??{}),o={...xAe,...n.i18n},a=n.renderer??"canvas",l=n.logLevel??Po.Warn,u=n.downloadFileName??"visualization",c=typeof e=="string"?document.querySelector(e):e;if(!c)throw new Error(`${e} does not exist`);if(n.defaultStyle!==!1){const w="vega-embed-style",{root:A,rootContainer:E}=CAe(c);if(!A.getElementById(w)){const k=document.createElement("style");k.id=w,k.innerHTML=n.defaultStyle===void 0||n.defaultStyle===!0?vAe.toString():n.defaultStyle,E.appendChild(k)}}const f=kAe(t,n.mode);let d=_Ae[f](t,i);if(f==="vega-lite"&&d.$schema){const w=vq(d.$schema);$q(by.vega,`^${w.version.slice(1)}`)||console.warn(`The compiled spec uses Vega ${w.version}, but current version is v${by.vega}.`)}c.classList.add("vega-embed"),s&&c.classList.add("has-actions"),c.innerHTML="";let h=c;if(s){const w=document.createElement("div");w.classList.add(EAe),c.appendChild(w),h=w}const p=n.patch;if(p&&(d=p instanceof Function?p(d):L2(d,p,!0,!1).newDocument),n.formatLocale&&Po.formatLocale(n.formatLocale),n.timeFormatLocale&&Po.timeFormatLocale(n.timeFormatLocale),n.expressionFunctions)for(const w in n.expressionFunctions){const A=n.expressionFunctions[w];"fn"in A?Po.expressionFunction(w,A.fn,A.visitor):A instanceof Function&&Po.expressionFunction(w,A)}const{ast:g}=n,m=Po.parse(d,f==="vega-lite"?{}:i,{ast:g}),v=new(n.viewClass||Po.View)(m,{loader:r,logLevel:l,renderer:a,...g?{expr:Po.expressionInterpreter??n.expr??r0e}:{}});if(v.addSignalListener("autosize",(w,A)=>{const{type:E}=A;E=="fit-x"?(h.classList.add("fit-x"),h.classList.remove("fit-y")):E=="fit-y"?(h.classList.remove("fit-x"),h.classList.add("fit-y")):E=="fit"?h.classList.add("fit-x","fit-y"):h.classList.remove("fit-x","fit-y")}),n.tooltip!==!1){const{loader:w,tooltip:A}=n,E=w&&!Dq(w)?w==null?void 0:w.baseURL:void 0,k=AAe(A)?A:new jEe({baseURL:E,...A===!0?{}:A}).call;v.tooltip(k)}let{hover:b}=n;if(b===void 0&&(b=f==="vega"),b){const{hoverSet:w,updateSet:A}=typeof b=="boolean"?{}:b;v.hover(w,A)}n&&(n.width!=null&&v.width(n.width),n.height!=null&&v.height(n.height),n.padding!=null&&v.padding(n.padding)),await v.initialize(h,n.bind).runAsync();let x;if(s!==!1){let w=c;if(n.defaultStyle!==!1||n.forceActionsMenu){const E=document.createElement("details");E.title=o.CLICK_TO_VIEW_ACTIONS,c.append(E),w=E;const k=document.createElement("summary");k.innerHTML=wAe,E.append(k),x=S=>{E.contains(S.target)||E.removeAttribute("open")},document.addEventListener("click",x)}const A=document.createElement("div");if(w.append(A),A.classList.add("vega-actions"),s===!0||s.export!==!1){for(const E of["svg","png"])if(s===!0||s.export===!0||s.export[E]){const k=o[`${E.toUpperCase()}_ACTION`],S=document.createElement("a"),$=Pe(n.scaleFactor)?n.scaleFactor[E]:n.scaleFactor;S.text=k,S.href="#",S.target="_blank",S.download=`${u}.${E}`,S.addEventListener("mousedown",async function(M){M.preventDefault();const O=await v.toImageURL(E,$);this.href=O}),A.append(S)}}if(s===!0||s.source!==!1){const E=document.createElement("a");E.text=o.SOURCE_ACTION,E.href="#",E.addEventListener("click",function(k){iT(nx(t),n.sourceHeader??"",n.sourceFooter??"",f),k.preventDefault()}),A.append(E)}if(f==="vega-lite"&&(s===!0||s.compiled!==!1)){const E=document.createElement("a");E.text=o.COMPILED_ACTION,E.href="#",E.addEventListener("click",function(k){iT(nx(d),n.sourceHeader??"",n.sourceFooter??"","vega"),k.preventDefault()}),A.append(E)}if(s===!0||s.editor!==!1){const E=n.editorUrl??"https://vega.github.io/editor/",k=document.createElement("a");k.text=o.EDITOR_ACTION,k.href="#",k.addEventListener("click",function(S){mAe(window,E,{config:i,mode:p?"vega":f,renderer:a,spec:nx(p?d:t)}),S.preventDefault()}),A.append(k)}}function _(){x&&document.removeEventListener("click",x),v.finalize()}return{view:v,spec:t,vgSpec:d,finalize:_,embedOptions:n}}function aT(e,t,n){return!e||e.length===0?[]:t||e.length<=n?e:e.slice(0,n)}var FAe=U('
      '),DAe=U('
      '),MAe=U(''),TAe=U(' '),RAe=U(''),NAe=U('
      '),OAe=U(' '),LAe=U('
      '),IAe=U('
      ',1),PAe=U('
      '),BAe=U(''),zAe=U(' '),jAe=U(''),UAe=U('
      '),qAe=U(' '),WAe=U('
      '),HAe=U('
      '),GAe=U('
      ',1);function xy(e,t){En(t,!0);let n=oe(t,"data",19,()=>[]),r=oe(t,"x",3,"step"),i=oe(t,"y",3,""),s=oe(t,"colorField",3,"run"),o=oe(t,"colorDisplayField",3,""),a=oe(t,"colorLabel",3,""),l=oe(t,"dashField",3,""),u=oe(t,"dashLabel",3,""),c=oe(t,"yLabel",3,""),f=oe(t,"colorMap",19,()=>({})),d=oe(t,"title",3,""),h=oe(t,"xLim",3,null),p=oe(t,"yExtent",3,void 0),g=oe(t,"onSelect",3,null),m=oe(t,"onResetZoom",3,null),v=oe(t,"draggable",3,!1),b=oe(t,"ondragstart",3,null),x=oe(t,"ondragover",3,null),_=oe(t,"ondrop",3,null),w=se(null),A=se(null),E=se(null),k=se(null),S=se(!1),$=null,M=!1,O=we(()=>a()||s()),P=we(()=>u()||l()),T=we(()=>c()||(i().includes("/")?i().split("/").pop():i())),F=we(()=>{if(!s()||!n()||n().length===0)return[];const me=new Set,Ee=[];for(const Ye of n()){const ht=Ye[s()];ht&&!me.has(ht)&&(me.add(ht),Ee.push({key:ht,name:Ye[o()]||ht,color:f()[ht]||"#999"}))}return Ee}),R=we(()=>MR(n(),s(),f()));const z=6;let j=se(!1),q=se(!1),te=we(()=>aT(y(F),y(j),z)),Y=we(()=>aT(y(F),y(q),z)),ee=we(()=>{if(!l()||!n()||n().length===0)return[];const me=new Set,Ee=[],Ye=[[1,0],[12,4],[3,2],[10,3,2,3],[2,2],[14,4,2,4],[6,4,1,4],[16,5],[4,2,1,2],[2,1]];for(const ht of n()){const Ve=ht[l()];Ve&&!me.has(Ve)&&(me.add(Ve),Ee.push({name:Ve,pattern:Ye[Ee.length%Ye.length]}))}return Ee}),_e=we(()=>{if(!l()||!n()||n().length===0)return"";const me=y(ee).map(Ee=>`${Ee.name}:${Ee.pattern.join(",")}`);return me.sort(),me.join("|")});function Le(me,Ee){return getComputedStyle(document.documentElement).getPropertyValue(me).trim()||Ee}function Z(){const me=n().filter(Ye=>Ye.data_type==="original"||!Ye.data_type),Ee=n().filter(Ye=>Ye.data_type==="smoothed");return{originalData:me,smoothedData:Ee,hasSmoothed:Ee.length>0}}function he(me){const Ee=me.map(Ye=>Ye[r()]).filter(Ye=>Ye!=null);if(h())return[h()[0],h()[1]];if(Ee.length>0)return[Math.min(...Ee),Math.max(...Ee)]}function He(){const me=s()&&n().length>0&&Object.hasOwn(n()[0],s()),Ee=l()&&n().length>0&&Object.hasOwn(n()[0],l()),Ye=me?[...new Set(n().map(bt=>bt[s()]))]:[],ht=[...new Set(Ye)],Ve=ht,Xe=ht.map(bt=>f()[bt]||"#999"),{originalData:dt,smoothedData:pt,hasSmoothed:Ct}=Z();M=Ct;const le=he(dt),pe={field:r(),type:"quantitative",scale:{zero:!1,...le?{domain:le}:{}}},et={field:i(),type:"quantitative",...p()?{scale:{domain:p()}}:{}},Ze=me?{color:{field:s(),type:"nominal",scale:{domain:Ve,range:Xe},legend:null}}:{},nt=Ee?{strokeDash:{field:l(),type:"nominal",scale:{domain:y(ee).map(bt=>bt.name),range:y(ee).map(bt=>bt.pattern)},legend:null}}:{},Be=[],Xt=(bt={})=>({type:"line",clip:!0,strokeWidth:2.25,...bt}),sn=y(T),ot=[];me&&ot.push({field:o()||s(),type:"nominal",title:y(O)}),Ee&&ot.push({field:l(),type:"nominal",title:y(P)}),ot.push({field:r(),type:"quantitative",title:r()},{field:i(),type:"quantitative",title:sn});const Pt=[{name:"hover",select:{type:"point",on:"pointerover",nearest:!0,clear:"pointerout"}}],Rt=(bt,Or)=>({...bt,mark:{type:"circle",clip:!0,size:60,opacity:0},encoding:{x:pe,y:et,...Ze,tooltip:ot,opacity:{condition:{param:"hover",empty:!1,value:1},value:0}},params:Pt,name:Or});return Ct?(Be.push({data:{name:"data_original",values:dt},mark:Xt({strokeWidth:1,opacity:.3}),encoding:{x:pe,y:et,...Ze,...nt},name:"original"}),Be.push({data:{name:"data_smoothed",values:pt},mark:Xt(),encoding:{x:pe,y:et,...Ze,...nt},name:"plot"}),Be.push(Rt({data:{name:"data_smoothed",values:pt}},"hover_points"))):(Be.push({data:{name:"data_plot",values:n()},mark:Xt(),encoding:{x:pe,y:et,...Ze,...nt},name:"plot"}),Be.push(Rt({data:{name:"data_plot",values:n()}},"hover_points"))),{$schema:"https://vega.github.io/schema/vega-lite/v5.json",width:"container",height:y(S)?"container":250,autosize:{type:"fit",contains:"padding"},layer:Be,...g()?{params:[{name:"brush",select:{type:"interval",encodings:["x"],mark:{fill:"gray",fillOpacity:.3,stroke:"none"}},views:["plot"]}]}:{},config:{background:"transparent",axis:{labelColor:Le("--body-text-color-subdued","#6b7280"),titleColor:Le("--body-text-color","#374151"),gridColor:Le("--border-color-primary","#f3f4f6")},view:{stroke:"transparent"},mark:{cursor:g()?"crosshair":void 0}},encoding:{y:{title:sn}}}}function Ke(){const{originalData:me}=Z(),Ee=he(me),Ye=Ee?`${Ee[0]},${Ee[1]}`:"auto",ht=p()?`${p()[0]},${p()[1]}`:"auto";return`${i()}\0${r()}\0${y(R)}\0${y(_e)}\0${d()}\0${y(S)}\0${!!g()}\0${Ye}\0${ht}`}function de(me,Ee,Ye){const ht=Eu().remove(fs).insert(Ye);me.change(Ee,ht)}function Re(){if(!y(k))return!1;const{originalData:me,smoothedData:Ee,hasSmoothed:Ye}=Z();if(Ye!==M)return!1;try{return Ye?(de(y(k),"data_original",me),de(y(k),"data_smoothed",Ee)):de(y(k),"data_plot",n()),y(k).run(),M=Ye,!0}catch{return!1}}async function Q(){if(await ts(),!y(w)||!n()||n().length===0||!i())return;const me=He();try{y(k)&&(y(k).finalize(),D(k,null));const Ee=await Mq(y(w),me,{actions:!1,renderer:"canvas"});if(D(k,Ee.view,!0),$=Ke(),requestAnimationFrame(()=>{Ee.view.resize()}),g()){let Ye=0,ht=null;Ee.view.addSignalListener("brush",(Ve,Xe)=>{if(Date.now()-Ye<1e3||!Xe||Object.keys(Xe).length===0)return;clearTimeout(ht);const dt=Xe[Object.keys(Xe)[0]];!dt||dt.length!==2||(ht=setTimeout(()=>{Ye=Date.now(),g()(dt)},250))})}}catch(Ee){console.error("Vega render error:",Ee)}}async function W(){if(!y(w)||!n()||n().length===0||!i())return;const me=Ke();y(k)&&me===$&&Re()||await Q()}function L(){if(!n()||n().length===0)return;const me=n().filter(Ct=>Ct.data_type==="original"||!Ct.data_type);if(me.length===0)return;const Ee=Object.keys(me[0]).filter(Ct=>Ct!=="data_type"),Ye=Ee.map(Ct=>/[,"]/.test(Ct)?`"${Ct.replace(/"/g,'""')}"`:Ct).join(","),ht=me.map(Ct=>Ee.map(le=>{const pe=Ct[le];return pe==null?"":typeof pe=="string"&&(pe.includes(",")||pe.includes('"'))?`"${pe.replace(/"/g,'""')}"`:pe}).join(",")),Ve=[Ye,...ht].join(` +`),Xe=new Blob([Ve],{type:"text/csv"}),dt=URL.createObjectURL(Xe),pt=document.createElement("a");pt.href=dt,pt.download=`${(i()||"data").replace(/\//g,"_")}.csv`,document.body.appendChild(pt),pt.click(),document.body.removeChild(pt),URL.revokeObjectURL(dt)}async function H(){if(y(k))try{const me=await y(k).toImageURL("png",4),Ee=document.createElement("a");Ee.href=me,Ee.download=`${(i()||"chart").replace(/\//g,"_")}.png`,document.body.appendChild(Ee),Ee.click(),document.body.removeChild(Ee)}catch(me){console.error("Failed to export image:",me)}}function ve(me){if(!me)return Promise.reject(new Error("no element"));const Ee=me.requestFullscreen||me.webkitRequestFullscreen||me.mozRequestFullScreen||me.msRequestFullscreen;return Ee?Ee.call(me):Promise.reject(new Error("no fullscreen"))}function G(){const me=document.exitFullscreen||document.webkitExitFullscreen||document.mozCancelFullScreen||document.msExitFullscreen;return me?me.call(document):Promise.resolve()}function B(me){const Ee=document.getElementById("vg-tooltip-element");Ee&&me&&Ee.parentElement!==me&&me.appendChild(Ee)}async function ie(){var me;D(S,!0),document.body.style.overflow="hidden",await ts(),await ts();try{await ve(y(E)),await ts(),B(y(E)),(me=y(k))==null||me.resize()}catch{document.body.style.overflow="",D(S,!1)}}async function qe(){try{await G()}catch{}document.body.style.overflow="",D(S,!1),B(document.body)}async function K(){y(S)?await qe():await ie()}function V(){const me=document.fullscreenElement||document.webkitFullscreenElement||document.mozFullScreenElement||document.msFullscreenElement;!me&&y(S)&&(document.body.style.overflow="",D(S,!1),B(document.body)),me&&y(S)&&ts().then(()=>{var Ee;return(Ee=y(k))==null?void 0:Ee.resize()})}function J(me){me.key==="Escape"&&y(S)&&qe()}Bt(()=>{n(),i(),r(),y(R),y(_e),h(),p(),d(),y(S),y(w),W()}),Bt(()=>{if(!y(w))return;const me=new ResizeObserver(()=>{queueMicrotask(()=>{var Ee;(Ee=y(k))==null||Ee.resize()})});return me.observe(y(w)),()=>me.disconnect()}),hh(()=>(document.addEventListener("fullscreenchange",V),document.addEventListener("webkitfullscreenchange",V),document.addEventListener("mozfullscreenchange",V),document.addEventListener("MSFullscreenChange",V),()=>{document.removeEventListener("fullscreenchange",V),document.removeEventListener("webkitfullscreenchange",V),document.removeEventListener("mozfullscreenchange",V),document.removeEventListener("MSFullscreenChange",V),y(k)&&y(k).finalize(),document.body.style.overflow=""}));function ye(me){b()&&b()(me)}var X=GAe();fn("keydown",$d,J);var ke=Ot(X);let Fe;var Ie=C(ke),ft=C(Ie),Oe=N(ft,2),Me=N(Oe,2),Ge=N(Ie,2);{var lt=me=>{var Ee=FAe();I(me,Ee)};ge(Ge,me=>{v()&&me(lt)})}var yt=N(Ge,2);{var Et=me=>{var Ee=IAe(),Ye=Ot(Ee);{var ht=Ze=>{var nt=DAe(),Be=C(nt);xe(()=>be(Be,d())),I(Ze,nt)};ge(Ye,Ze=>{d()&&Ze(ht)})}var Ve=N(Ye,2),Xe=C(Ve);rs(Xe,Ze=>D(w,Ze),()=>y(w));var dt=N(Xe,2);{var pt=Ze=>{var nt=MAe();Ue("click",nt,Be=>{Be.stopPropagation(),m()()}),I(Ze,nt)};ge(dt,Ze=>{h()&&m()&&Ze(pt)})}var Ct=N(Ve,2);{var le=Ze=>{var nt=NAe(),Be=C(nt);wt(Be,17,()=>y(te),At,(ot,Pt)=>{var Rt=TAe(),bt=C(Rt),Or=N(bt,2),ri=C(Or);xe(()=>{ll(bt,`background: ${y(Pt).color??""}`),be(ri,y(Pt).name)}),I(ot,Rt)});var Xt=N(Be,2);{var sn=ot=>{var Pt=RAe(),Rt=C(Pt);xe(()=>be(Rt,y(j)?"Show less":`+${y(F).length-z} more`)),Ue("click",Pt,bt=>{bt.stopPropagation(),D(j,!y(j))}),I(ot,Pt)};ge(Xt,ot=>{y(F).length>z&&ot(sn)})}I(Ze,nt)};ge(Ct,Ze=>{y(F).length>0&&Ze(le)})}var pe=N(Ct,2);{var et=Ze=>{var nt=LAe(),Be=C(nt),Xt=C(Be),sn=N(Be,2);wt(sn,17,()=>y(ee),At,(ot,Pt)=>{var Rt=OAe(),bt=C(Rt),Or=C(bt),ri=N(bt,2),Lr=C(ri);xe(Vi=>{xt(Or,"stroke-dasharray",Vi),be(Lr,y(Pt).name)},[()=>y(Pt).pattern.join(" ")]),I(ot,Rt)}),xe(()=>be(Xt,y(P))),I(Ze,nt)};ge(pe,Ze=>{y(ee).length>0&&Ze(et)})}I(me,Ee)};ge(yt,me=>{y(S)||me(Et)})}rs(ke,me=>D(A,me),()=>y(A));var ct=N(ke,2);{var Ut=me=>{var Ee=HAe(),Ye=C(Ee),ht=C(Ye),Ve=N(ht,2),Xe=N(Ve,2),dt=N(Ye,2);{var pt=ot=>{var Pt=PAe(),Rt=C(Pt);xe(()=>be(Rt,d())),I(ot,Pt)};ge(dt,ot=>{d()&&ot(pt)})}var Ct=N(dt,2),le=C(Ct),pe=C(le);rs(pe,ot=>D(w,ot),()=>y(w));var et=N(pe,2);{var Ze=ot=>{var Pt=BAe();Ue("click",Pt,Rt=>{Rt.stopPropagation(),m()()}),I(ot,Pt)};ge(et,ot=>{h()&&m()&&ot(Ze)})}var nt=N(Ct,2);{var Be=ot=>{var Pt=UAe(),Rt=C(Pt);wt(Rt,17,()=>y(Y),At,(ri,Lr)=>{var Vi=zAe(),Hs=C(Vi),Zt=N(Hs,2),Fn=C(Zt);xe(()=>{ll(Hs,`background: ${y(Lr).color??""}`),be(Fn,y(Lr).name)}),I(ri,Vi)});var bt=N(Rt,2);{var Or=ri=>{var Lr=jAe(),Vi=C(Lr);xe(()=>be(Vi,y(q)?"Show less":`+${y(F).length-z} more`)),Ue("click",Lr,Hs=>{Hs.stopPropagation(),D(q,!y(q))}),I(ri,Lr)};ge(bt,ri=>{y(F).length>z&&ri(Or)})}I(ot,Pt)};ge(nt,ot=>{y(F).length>0&&ot(Be)})}var Xt=N(nt,2);{var sn=ot=>{var Pt=WAe(),Rt=C(Pt),bt=C(Rt),Or=N(Rt,2);wt(Or,17,()=>y(ee),At,(ri,Lr)=>{var Vi=qAe(),Hs=C(Vi),Zt=C(Hs),Fn=N(Hs,2),Ir=C(Fn);xe(hn=>{xt(Zt,"stroke-dasharray",hn),be(Ir,y(Lr).name)},[()=>y(Lr).pattern.join(" ")]),I(ri,Vi)}),xe(()=>be(bt,y(P))),I(ot,Pt)};ge(Xt,ot=>{y(ee).length>0&&ot(sn)})}rs(Ee,ot=>D(E,ot),()=>y(E)),Ue("click",ht,L),Ue("click",Ve,H),Ue("click",Xe,()=>qe()),I(me,Ee)};ge(ct,me=>{y(S)&&me(Ut)})}xe(()=>{Fe=en(ke,1,"plot-container svelte-9thu1j",null,Fe,{"hidden-plot":y(S)}),xt(ke,"draggable",v()?"true":void 0)}),fn("dragstart",ke,function(...me){var Ee;(Ee=v()?ye:void 0)==null||Ee.apply(this,me)}),fn("dragover",ke,function(...me){var Ee;(Ee=v()?x():void 0)==null||Ee.apply(this,me)}),fn("drop",ke,function(...me){var Ee;(Ee=v()?_():void 0)==null||Ee.apply(this,me)}),Ue("click",ft,L),Ue("click",Oe,H),Ue("click",Me,K),I(e,X),An()}ni(["click"]);var YAe=U('
      '),VAe=U('
      '),XAe=U(' '),KAe=U(''),ZAe=U('
      '),JAe=U('
      ',1),QAe=U('
      '),eke=U(' '),tke=U(''),nke=U('
      '),rke=U(`
      `),ike=U(`
      `,1);function lT(e,t){En(t,!0);let n=oe(t,"data",19,()=>[]),r=oe(t,"y",3,""),i=oe(t,"colorField",3,"run"),s=oe(t,"colorDisplayField",3,""),o=oe(t,"colorMap",19,()=>({})),a=oe(t,"title",3,""),l=oe(t,"draggable",3,!1),u=oe(t,"ondragstart",3,null),c=oe(t,"ondragover",3,null),f=oe(t,"ondrop",3,null),d=se(null),h=se(null),p=se(null),g=se(null),m=se(!1),v=we(()=>{if(!i()||!n()||n().length===0)return[];const G=new Set,B=[];for(const ie of n()){const qe=ie[i()];qe&&!G.has(qe)&&(G.add(qe),B.push({key:qe,name:ie[s()]||qe,color:o()[qe]||"#999"}))}return B}),b=we(()=>MR(n(),i(),o()));const x=6;let _=se(!1),w=se(!1),A=we(()=>y(_)||y(v).length<=x?y(v):y(v).slice(0,x)),E=we(()=>y(w)||y(v).length<=x?y(v):y(v).slice(0,x));function k(){const G=new Map;for(const B of n()){if(B.data_type==="smoothed")continue;const ie=B[i()];ie&&B[r()]!=null&&G.set(ie,{run:ie,label:B[s()]||ie,value:B[r()]})}return Array.from(G.values())}function S(G,B){return getComputedStyle(document.documentElement).getPropertyValue(G).trim()||B}function $(G){const B=G.map(K=>K.run),ie=B.map(K=>o()[K]||"#999"),qe=r().includes("/")?r().split("/").pop():r();return{$schema:"https://vega.github.io/schema/vega-lite/v5.json",width:"container",height:y(m)?"container":250,autosize:{type:"fit",contains:"padding"},data:{values:G},mark:{type:"bar",cornerRadiusTopLeft:3,cornerRadiusTopRight:3},encoding:{x:{field:"run",type:"nominal",sort:B,axis:{labelExpr:"datum.label",labelAngle:B.length>4?-45:0,labelLimit:120},title:null},y:{field:"value",type:"quantitative",title:qe,scale:{zero:!0}},color:{field:"run",type:"nominal",scale:{domain:B,range:ie},legend:null},tooltip:[{field:s()||"label",type:"nominal",title:"Run"},{field:"value",type:"quantitative",title:qe}]},config:{background:"transparent",axis:{labelColor:S("--body-text-color-subdued","#6b7280"),titleColor:S("--body-text-color","#374151"),gridColor:S("--border-color-primary","#f3f4f6")},view:{stroke:"transparent"}}}}async function M(){if(await ts(),!y(d)||!n()||n().length===0||!r())return;const G=k();if(G.length===0)return;const B=$(G);try{y(g)&&(y(g).finalize(),D(g,null));const ie=await Mq(y(d),B,{actions:!1,renderer:"canvas"});D(g,ie.view,!0),requestAnimationFrame(()=>{ie.view.resize()})}catch(ie){console.error("Vega render error:",ie)}}function O(){const G=k();if(G.length===0)return;const ie="run,"+(/[,"]/.test(r())?`"${r().replace(/"/g,'""')}"`:r()),qe=G.map(X=>`${typeof X.label=="string"&&(X.label.includes(",")||X.label.includes('"'))?`"${X.label.replace(/"/g,'""')}"`:X.label},${X.value}`),K=[ie,...qe].join(` +`),V=new Blob([K],{type:"text/csv"}),J=URL.createObjectURL(V),ye=document.createElement("a");ye.href=J,ye.download=`${(r()||"data").replace(/\//g,"_")}.csv`,document.body.appendChild(ye),ye.click(),document.body.removeChild(ye),URL.revokeObjectURL(J)}async function P(){if(y(g))try{const G=await y(g).toImageURL("png",4),B=document.createElement("a");B.href=G,B.download=`${(r()||"chart").replace(/\//g,"_")}.png`,document.body.appendChild(B),B.click(),document.body.removeChild(B)}catch(G){console.error("Failed to export image:",G)}}function T(G){if(!G)return Promise.reject(new Error("no element"));const B=G.requestFullscreen||G.webkitRequestFullscreen||G.mozRequestFullScreen||G.msRequestFullscreen;return B?B.call(G):Promise.reject(new Error("no fullscreen"))}function F(){const G=document.exitFullscreen||document.webkitExitFullscreen||document.mozCancelFullScreen||document.msExitFullscreen;return G?G.call(document):Promise.resolve()}function R(G){const B=document.getElementById("vg-tooltip-element");B&&G&&B.parentElement!==G&&G.appendChild(B)}async function z(){var G;D(m,!0),document.body.style.overflow="hidden",await ts(),await ts();try{await T(y(p)),await ts(),R(y(p)),(G=y(g))==null||G.resize()}catch{document.body.style.overflow="",D(m,!1)}}async function j(){try{await F()}catch{}document.body.style.overflow="",D(m,!1),R(document.body)}async function q(){y(m)?await j():await z()}function te(){const G=document.fullscreenElement||document.webkitFullscreenElement||document.mozFullScreenElement||document.msFullscreenElement;!G&&y(m)&&(document.body.style.overflow="",D(m,!1),R(document.body)),G&&y(m)&&ts().then(()=>{var B;return(B=y(g))==null?void 0:B.resize()})}function Y(G){G.key==="Escape"&&y(m)&&j()}Bt(()=>{n(),r(),y(b),a(),y(m),y(d),M()}),Bt(()=>{if(!y(d))return;const G=new ResizeObserver(()=>{queueMicrotask(()=>{var B;(B=y(g))==null||B.resize()})});return G.observe(y(d)),()=>G.disconnect()}),hh(()=>(document.addEventListener("fullscreenchange",te),document.addEventListener("webkitfullscreenchange",te),document.addEventListener("mozfullscreenchange",te),document.addEventListener("MSFullscreenChange",te),()=>{document.removeEventListener("fullscreenchange",te),document.removeEventListener("webkitfullscreenchange",te),document.removeEventListener("mozfullscreenchange",te),document.removeEventListener("MSFullscreenChange",te),y(g)&&y(g).finalize(),document.body.style.overflow=""}));function ee(G){u()&&u()(G)}var _e=ike();fn("keydown",$d,Y);var Le=Ot(_e);let Z;var he=C(Le),He=C(he),Ke=N(He,2),de=N(Ke,2),Re=N(he,2);{var Q=G=>{var B=YAe();I(G,B)};ge(Re,G=>{l()&&G(Q)})}var W=N(Re,2);{var L=G=>{var B=JAe(),ie=Ot(B);{var qe=X=>{var ke=VAe(),Fe=C(ke);xe(()=>be(Fe,a())),I(X,ke)};ge(ie,X=>{a()&&X(qe)})}var K=N(ie,2),V=C(K);rs(V,X=>D(d,X),()=>y(d));var J=N(K,2);{var ye=X=>{var ke=ZAe(),Fe=C(ke);wt(Fe,17,()=>y(A),At,(Oe,Me)=>{var Ge=XAe(),lt=C(Ge),yt=N(lt,2),Et=C(yt);xe(()=>{ll(lt,`background: ${y(Me).color??""}`),be(Et,y(Me).name)}),I(Oe,Ge)});var Ie=N(Fe,2);{var ft=Oe=>{var Me=KAe(),Ge=C(Me);xe(()=>be(Ge,y(_)?"Show less":`+${y(v).length-x} more`)),Ue("click",Me,lt=>{lt.stopPropagation(),D(_,!y(_))}),I(Oe,Me)};ge(Ie,Oe=>{y(v).length>x&&Oe(ft)})}I(X,ke)};ge(J,X=>{y(v).length>0&&X(ye)})}I(G,B)};ge(W,G=>{y(m)||G(L)})}rs(Le,G=>D(h,G),()=>y(h));var H=N(Le,2);{var ve=G=>{var B=rke(),ie=C(B),qe=C(ie),K=N(qe,2),V=N(K,2),J=N(ie,2);{var ye=Oe=>{var Me=QAe(),Ge=C(Me);xe(()=>be(Ge,a())),I(Oe,Me)};ge(J,Oe=>{a()&&Oe(ye)})}var X=N(J,2),ke=C(X),Fe=C(ke);rs(Fe,Oe=>D(d,Oe),()=>y(d));var Ie=N(X,2);{var ft=Oe=>{var Me=nke(),Ge=C(Me);wt(Ge,17,()=>y(E),At,(Et,ct)=>{var Ut=eke(),me=C(Ut),Ee=N(me,2),Ye=C(Ee);xe(()=>{ll(me,`background: ${y(ct).color??""}`),be(Ye,y(ct).name)}),I(Et,Ut)});var lt=N(Ge,2);{var yt=Et=>{var ct=tke(),Ut=C(ct);xe(()=>be(Ut,y(w)?"Show less":`+${y(v).length-x} more`)),Ue("click",ct,me=>{me.stopPropagation(),D(w,!y(w))}),I(Et,ct)};ge(lt,Et=>{y(v).length>x&&Et(yt)})}I(Oe,Me)};ge(Ie,Oe=>{y(v).length>0&&Oe(ft)})}rs(B,Oe=>D(p,Oe),()=>y(p)),Ue("click",qe,O),Ue("click",K,P),Ue("click",V,()=>j()),I(G,B)};ge(H,G=>{y(m)&&G(ve)})}xe(()=>{Z=en(Le,1,"plot-container bar-plot svelte-1swghqy",null,Z,{"hidden-plot":y(m)}),xt(Le,"draggable",l()?"true":void 0)}),fn("dragstart",Le,function(...G){var B;(B=l()?ee:void 0)==null||B.apply(this,G)}),fn("dragover",Le,function(...G){var B;(B=l()?c():void 0)==null||B.apply(this,G)}),fn("drop",Le,function(...G){var B;(B=l()?f():void 0)==null||B.apply(this,G)}),Ue("click",He,O),Ue("click",Ke,P),Ue("click",de,q),I(e,_e),An()}ni(["click"]);var ske=U('
      '),oke=U('
      '),ake=U('
      ');function OA(e,t){En(t,!0);let n=oe(t,"label",3,""),r=oe(t,"open",15,!0),i=oe(t,"hidden",3,!1);function s(){r(!r())}var o=Ri(),a=Ot(o);{var l=c=>{var f=ske(),d=C(f);{var h=p=>{var g=Ri(),m=Ot(g);s5(m,()=>t.children),I(p,g)};ge(d,p=>{t.children&&p(h)})}I(c,f)},u=c=>{var f=ake(),d=C(f),h=C(d);let p;var g=N(h,2),m=C(g),v=N(d,2);{var b=x=>{var _=oke(),w=C(_);{var A=E=>{var k=Ri(),S=Ot(k);s5(S,()=>t.children),I(E,k)};ge(w,E=>{t.children&&E(A)})}I(x,_)};ge(v,x=>{r()&&x(b)})}xe(()=>{p=en(h,1,"arrow svelte-1jep0a",null,p,{rotated:r()}),be(m,n())}),Ue("click",d,s),I(c,f)};ge(a,c=>{i()?c(l):c(u,-1)})}I(e,o),An()}ni(["click"]);sH();const Tq="trackio_theme_preference";let M1=[];function lke(e){return M1.push(e),()=>{M1=M1.filter(t=>t!==e)}}function uke(){const e=OF();M1.forEach(t=>t(e))}const uT={"--neutral-50":"#fafafa","--neutral-100":"#f4f4f5","--neutral-200":"#e4e4e7","--neutral-300":"#d4d4d8","--neutral-400":"#bbbbc2","--neutral-500":"#71717a","--neutral-600":"#52525b","--neutral-700":"#3f3f46","--neutral-800":"#27272a","--neutral-900":"#18181b","--neutral-950":"#0f0f11","--background-fill-primary":"#0f0f11","--background-fill-secondary":"#18181b","--body-text-color":"#f4f4f5","--body-text-color-subdued":"#bbbbc2","--border-color-primary":"#3f3f46","--color-accent":"#f97316","--color-accent-soft":"#3f3f46","--input-background-fill":"#27272a","--input-background-fill-focus":"#f97316","--input-border-color":"#3f3f46","--input-border-color-focus":"#3f3f46","--input-placeholder-color":"#71717a","--input-shadow":"none","--input-shadow-focus":"none","--checkbox-background-color":"#27272a","--checkbox-background-color-focus":"#27272a","--checkbox-background-color-hover":"#27272a","--checkbox-background-color-selected":"#f97316","--checkbox-border-color":"#3f3f46","--checkbox-border-color-focus":"#f97316","--checkbox-border-color-hover":"#52525b","--checkbox-border-color-selected":"#f97316","--table-even-background-fill":"#0f0f11","--table-odd-background-fill":"#18181b","--slider-color":"#f97316","--shadow-drop":"rgba(0,0,0,0.15) 0px 1px 2px 0px","--shadow-drop-lg":"0 1px 3px 0 rgb(0 0 0 / 0.3), 0 1px 2px -1px rgb(0 0 0 / 0.2)","--shadow-inset":"rgba(0,0,0,0.15) 0px 2px 4px 0px inset","--block-title-text-color":"#bbbbc2","--block-info-text-color":"#71717a","--primary-50":"#3f3f46"};function lg(e){const t=document.documentElement;e==="dark"?(t.dataset.theme="dark",Object.entries(uT).forEach(([n,r])=>{t.style.setProperty(n,r)})):(delete t.dataset.theme,Object.keys(uT).forEach(n=>{t.style.removeProperty(n)})),uke()}function OF(){return document.documentElement.dataset.theme==="dark"}function LF(){return window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"default"}function IF(){return localStorage.getItem(Tq)||"system"}function cke(e){localStorage.setItem(Tq,e),Rq(e),Nq(e==="system")}function Rq(e){lg(e==="system"?LF():e==="dark"?"dark":"default")}let Hm=!1;function cT(){IF()==="system"&&lg(LF())}function Nq(e){const t=window.matchMedia("(prefers-color-scheme: dark)");e&&!Hm?(t.addEventListener("change",cT),Hm=!0):!e&&Hm&&(t.removeEventListener("change",cT),Hm=!1)}function fke(){const e=new URLSearchParams(window.location.search).get("__theme");if(e){lg(e);return}const t=IF();Rq(t),Nq(t==="system")}var dke=U('
      Loading
      ');function Bu(e,t){En(t,!1);const r=OF()||new URLSearchParams(window.location.search).get("__theme")==="dark"||LF()==="dark"?"/static/trackio/trackio_logo_dark.png":"/static/trackio/trackio_logo_light.png";sG();var i=dke(),s=C(i),o=C(s),a=C(o),l=N(o,2),u=C(l);xe(()=>{xt(a,"src",r),xt(u,"src",r)}),I(e,i),An()}const fT=["BOOLEAN","INT32","INT64","INT96","FLOAT","DOUBLE","BYTE_ARRAY","FIXED_LEN_BYTE_ARRAY"],uc=["PLAIN","GROUP_VAR_INT","PLAIN_DICTIONARY","RLE","BIT_PACKED","DELTA_BINARY_PACKED","DELTA_LENGTH_BYTE_ARRAY","DELTA_BYTE_ARRAY","RLE_DICTIONARY","BYTE_STREAM_SPLIT"],hke=["REQUIRED","OPTIONAL","REPEATED"],pke=["UTF8","MAP","MAP_KEY_VALUE","LIST","ENUM","DECIMAL","DATE","TIME_MILLIS","TIME_MICROS","TIMESTAMP_MILLIS","TIMESTAMP_MICROS","UINT_8","UINT_16","UINT_32","UINT_64","INT_8","INT_16","INT_32","INT_64","JSON","BSON","INTERVAL"],gke=["UNCOMPRESSED","SNAPPY","GZIP","LZO","BROTLI","LZ4","ZSTD","LZ4_RAW"],Oq=["DATA_PAGE","INDEX_PAGE","DICTIONARY_PAGE","DATA_PAGE_V2"],mke=["SPHERICAL","VINCENTY","THOMAS","ANDOYER","KARNEY"];function LA(e){const t=Gm(e);if(t.type===1)return{type:"Point",coordinates:IA(e,t)};if(t.type===2)return{type:"LineString",coordinates:PA(e,t)};if(t.type===3)return{type:"Polygon",coordinates:dT(e,t)};if(t.type===4){const n=[];for(let r=0;r1&&i<=7&&(o=t.getUint32(e.offset,n),e.offset+=4);let a=2;return s&&a++,s===3&&a++,{littleEndian:n,type:i,dim:a,count:o}}function IA(e,t){const n=[];for(let r=0;r{var d;return((d=f.element.logical_type)==null?void 0:d.type)==="VARIANT"}))&&o==="BYTE_ARRAY"&&a!=="UTF8"&&(l==null?void 0:l.type)!=="STRING")return e;if(a==="DECIMAL"){const d=10**-(n.scale||0),h=new Array(e.length);for(let p=0;pr.timestampFromNanoseconds(vke(f)));if(a==="DATE")return Array.from(e).map(f=>r.dateFromDays(f));if(a==="TIMESTAMP_MILLIS")return Array.from(e).map(f=>r.timestampFromMilliseconds(f));if(a==="TIMESTAMP_MICROS")return Array.from(e).map(f=>r.timestampFromMicroseconds(f));if(a==="JSON")return e.map(f=>JSON.parse(Lq.decode(f)));if(a==="BSON")throw new Error("parquet bson not supported");if(a==="INTERVAL")throw new Error("parquet interval not supported");if((l==null?void 0:l.type)==="GEOMETRY")return e.map(f=>r.geometryFromBytes(f));if((l==null?void 0:l.type)==="GEOGRAPHY")return e.map(f=>r.geographyFromBytes(f));if(a==="UTF8"||(l==null?void 0:l.type)==="STRING"||i&&o==="BYTE_ARRAY")return e.map(f=>r.stringFromBytes(f));if(a==="UINT_64"||(l==null?void 0:l.type)==="INTEGER"&&l.bitWidth===64&&!l.isSigned){if(e instanceof BigInt64Array)return new BigUint64Array(e.buffer,e.byteOffset,e.length);const f=u?new Array(e.length):new BigUint64Array(e.length);for(let d=0;d=2n**BigInt(n-1)&&(t-=2n**BigInt(n)),Number(t)}function vke(e){const t=(e>>64n)-2440588n,n=e&0xffffffffffffffffn;return t*86400000000000n+n}function Bq(e){if(!e)return;const t=e[1]<<8|e[0],n=t>>15?-1:1,r=t>>10&31,i=t&1023;return r===0?n*2**-14*(i/1024):r===31?i?NaN:n*(1/0):n*2**(r-15)*(1+i/1024)}function zq(e,t,n){const r=e[t],i=[];let s=1;if(r.num_children)for(;i.lengtho.element.name===i);if(!s)throw new Error(`parquet schema element not found: ${t}`);r.push(s),n=s}return r}function yke(e){const t=[];function n(r){if(r.children.length)for(const i of r.children)n(i);else t.push(r.path.join("."))}return n(e),t}function Uq(e){let t=0;for(const{element:n}of e)n.repetition_type==="REPEATED"&&t++;return t}function PF(e){let t=0;for(const{element:n}of e.slice(1))n.repetition_type!=="REQUIRED"&&t++;return t}function bke(e){if(!e||e.element.converted_type!=="LIST"||e.children.length>1)return!1;const t=e.children[0];return!(t.children.length>1||t.element.repetition_type!=="REPEATED")}function xke(e){if(!e||e.element.converted_type!=="MAP"||e.children.length>1)return!1;const t=e.children[0];if(t.children.length!==2||t.element.repetition_type!=="REPEATED")return!1;const n=t.children.find(i=>i.element.name==="key");if((n==null?void 0:n.element.repetition_type)==="REPEATED")return!1;const r=t.children.find(i=>i.element.name==="value");return(r==null?void 0:r.element.repetition_type)!=="REPEATED"}function qq(e){if(e.length!==2)return!1;const[,t]=e;return!(t.element.repetition_type==="REPEATED"||t.children.length)}const _ke=0,pT=1,gT=2,mT=3,wke=4,Eke=5,Ake=6,kke=7,Ske=8,Cke=9,$ke=12;function B2(e){const t={};let n=0;for(;e.offset>4;n=s?n+s:Wq(e),t[`field_${n}`]=BA(e,i)}return t}function BA(e,t){switch(t){case pT:return!0;case gT:return!1;case mT:return e.view.getInt8(e.offset++);case wke:case Eke:return Wq(e);case Ake:return zA(e);case kke:{const n=e.view.getFloat64(e.offset,!0);return e.offset+=8,n}case Ske:{const n=Tc(e),r=new Uint8Array(e.view.buffer,e.view.byteOffset+e.offset,n);return e.offset+=n,r}case Cke:{const n=e.view.getUint8(e.offset++),r=n&15;let i=n>>4;i===15&&(i=Tc(e));const s=r===pT||r===gT,o=new Array(i);for(let a=0;a>>1^-(t&1)}function zA(e){const t=Fke(e);return t>>1n^-(t&1n)}function Dke(e,t){var s,o,a,l,u;const n=new Map,r=(s=t==null?void 0:t.find(({key:c})=>c==="geo"))==null?void 0:s.value,i=(r&&((o=JSON.parse(r))==null?void 0:o.columns))??{};for(const[c,f]of Object.entries(i)){if(f.encoding!=="WKB")continue;const d=f.edges==="spherical"?"GEOGRAPHY":"GEOMETRY",h=((a=f.crs)==null?void 0:a.id)??((u=(l=f.crs)==null?void 0:l.ids)==null?void 0:u[0]),p=h?`${h.authority}:${h.code.toString()}`:void 0;n.set(c,{type:d,crs:p})}for(let c=1;c=0))throw new Error("parquet expected AsyncBuffer");const i=Math.max(0,e.byteLength-n),s=await e.slice(i,e.byteLength),o=new DataView(s);if(o.getUint32(s.byteLength-4,!0)!==827474256)throw new Error("parquet file invalid (footer != PAR1)");const a=o.getUint32(s.byteLength-8,!0);if(a>e.byteLength-8)throw new Error(`parquet metadata length ${a} exceeds available buffer ${e.byteLength-8}`);if(a+8>n){const l=e.byteLength-a-8,u=await e.slice(l,i),c=new ArrayBuffer(a+8),f=new Uint8Array(c);return f.set(new Uint8Array(u)),f.set(new Uint8Array(s),i-l),vT(c,{parsers:t,geoparquet:r})}else return vT(s,{parsers:t,geoparquet:r})}function vT(e,{parsers:t,geoparquet:n=!0}={}){var m;if(!(e instanceof ArrayBuffer))throw new Error("parquet expected ArrayBuffer");const r=new DataView(e);if(t={...P2,...t},r.byteLength<8)throw new Error("parquet file is too short");if(r.getUint32(r.byteLength-4,!0)!==827474256)throw new Error("parquet file invalid (footer != PAR1)");const i=r.byteLength-8,s=r.getUint32(i,!0);if(s>r.byteLength-8)throw new Error(`parquet metadata length ${s} exceeds available buffer ${r.byteLength-8}`);const o=i-s,l=B2({view:r,offset:o}),u=l.field_1,c=l.field_2.map(v=>({type:fT[v.field_1],type_length:v.field_2,repetition_type:hke[v.field_3],name:Bo(v.field_4),num_children:v.field_5,converted_type:pke[v.field_6],scale:v.field_7,precision:v.field_8,field_id:v.field_9,logical_type:Nke(v.field_10)})),f=c.filter(v=>v.type),d=l.field_3,h=l.field_4.map(v=>{var b;return{columns:v.field_1.map((x,_)=>{var w,A,E;return{file_path:Bo(x.field_1),file_offset:x.field_2,meta_data:x.field_3&&{type:fT[x.field_3.field_1],encodings:(w=x.field_3.field_2)==null?void 0:w.map(k=>uc[k]),path_in_schema:x.field_3.field_3.map(Bo),codec:gke[x.field_3.field_4],num_values:x.field_3.field_5,total_uncompressed_size:x.field_3.field_6,total_compressed_size:x.field_3.field_7,key_value_metadata:(A=x.field_3.field_8)==null?void 0:A.map(k=>({key:Bo(k.field_1),value:Bo(k.field_2)})),data_page_offset:x.field_3.field_9,index_page_offset:x.field_3.field_10,dictionary_page_offset:x.field_3.field_11,statistics:Oke(x.field_3.field_12,f[_],t),encoding_stats:(E=x.field_3.field_13)==null?void 0:E.map(k=>({page_type:Oq[k.field_1],encoding:uc[k.field_2],count:k.field_3})),bloom_filter_offset:x.field_3.field_14,bloom_filter_length:x.field_3.field_15,size_statistics:x.field_3.field_16&&{unencoded_byte_array_data_bytes:x.field_3.field_16.field_1,repetition_level_histogram:x.field_3.field_16.field_2,definition_level_histogram:x.field_3.field_16.field_3},geospatial_statistics:x.field_3.field_17&&{bbox:x.field_3.field_17.field_1&&{xmin:x.field_3.field_17.field_1.field_1,xmax:x.field_3.field_17.field_1.field_2,ymin:x.field_3.field_17.field_1.field_3,ymax:x.field_3.field_17.field_1.field_4,zmin:x.field_3.field_17.field_1.field_5,zmax:x.field_3.field_17.field_1.field_6,mmin:x.field_3.field_17.field_1.field_7,mmax:x.field_3.field_17.field_1.field_8},geospatial_types:x.field_3.field_17.field_2}},offset_index_offset:x.field_4,offset_index_length:x.field_5,column_index_offset:x.field_6,column_index_length:x.field_7,crypto_metadata:x.field_8,encrypted_column_metadata:x.field_9}}),total_byte_size:v.field_2,num_rows:v.field_3,sorting_columns:(b=v.field_4)==null?void 0:b.map(x=>({column_idx:x.field_1,descending:x.field_2,nulls_first:x.field_3})),file_offset:v.field_5,total_compressed_size:v.field_6,ordinal:v.field_7}}),p=(m=l.field_5)==null?void 0:m.map(v=>({key:Bo(v.field_1),value:Bo(v.field_2)})),g=Bo(l.field_6);return n&&Dke(c,p),{version:u,schema:c,num_rows:d,row_groups:h,key_value_metadata:p,created_by:g,metadata_length:s}}function jA({schema:e}){return jq(e,[])[0]}function Nke(e){return e!=null&&e.field_1?{type:"STRING"}:e!=null&&e.field_2?{type:"MAP"}:e!=null&&e.field_3?{type:"LIST"}:e!=null&&e.field_4?{type:"ENUM"}:e!=null&&e.field_5?{type:"DECIMAL",scale:e.field_5.field_1,precision:e.field_5.field_2}:e!=null&&e.field_6?{type:"DATE"}:e!=null&&e.field_7?{type:"TIME",isAdjustedToUTC:e.field_7.field_1,unit:yT(e.field_7.field_2)}:e!=null&&e.field_8?{type:"TIMESTAMP",isAdjustedToUTC:e.field_8.field_1,unit:yT(e.field_8.field_2)}:e!=null&&e.field_10?{type:"INTEGER",bitWidth:e.field_10.field_1,isSigned:e.field_10.field_2}:e!=null&&e.field_11?{type:"NULL"}:e!=null&&e.field_12?{type:"JSON"}:e!=null&&e.field_13?{type:"BSON"}:e!=null&&e.field_14?{type:"UUID"}:e!=null&&e.field_15?{type:"FLOAT16"}:e!=null&&e.field_16?{type:"VARIANT",specification_version:e.field_16.field_1}:e!=null&&e.field_17?{type:"GEOMETRY",crs:Bo(e.field_17.field_1)}:e!=null&&e.field_18?{type:"GEOGRAPHY",crs:Bo(e.field_18.field_1),algorithm:mke[e.field_18.field_2]}:e}function yT(e){if(e.field_1)return"MILLIS";if(e.field_2)return"MICROS";if(e.field_3)return"NANOS";throw new Error("parquet time unit required")}function Oke(e,t,n){return e&&{max:Ym(e.field_1,t,n),min:Ym(e.field_2,t,n),null_count:e.field_3,distinct_count:e.field_4,max_value:Ym(e.field_5,t,n),min_value:Ym(e.field_6,t,n),is_max_value_exact:e.field_7,is_min_value_exact:e.field_8}}function Ym(e,t,n){const{type:r,converted_type:i,logical_type:s}=t;if(e===void 0)return e;if(r==="BOOLEAN")return e[0]===1;if(r==="BYTE_ARRAY")return n.stringFromBytes(e);const o=new DataView(e.buffer,e.byteOffset,e.byteLength);return r==="FLOAT"&&o.byteLength===4?o.getFloat32(0,!0):r==="DOUBLE"&&o.byteLength===8?o.getFloat64(0,!0):r==="INT32"&&i==="DATE"?n.dateFromDays(o.getInt32(0,!0)):r==="INT64"&&i==="TIMESTAMP_MILLIS"?n.timestampFromMilliseconds(o.getBigInt64(0,!0)):r==="INT64"&&i==="TIMESTAMP_MICROS"?n.timestampFromMicroseconds(o.getBigInt64(0,!0)):r==="INT64"&&(s==null?void 0:s.type)==="TIMESTAMP"&&(s==null?void 0:s.unit)==="NANOS"?n.timestampFromNanoseconds(o.getBigInt64(0,!0)):r==="INT64"&&(s==null?void 0:s.type)==="TIMESTAMP"&&(s==null?void 0:s.unit)==="MICROS"?n.timestampFromMicroseconds(o.getBigInt64(0,!0)):r==="INT64"&&(s==null?void 0:s.type)==="TIMESTAMP"?n.timestampFromMilliseconds(o.getBigInt64(0,!0)):r==="INT32"&&o.byteLength===4?o.getInt32(0,!0):r==="INT64"&&o.byteLength===8?o.getBigInt64(0,!0):i==="DECIMAL"?Pq(e)*10**-(t.scale||0):(s==null?void 0:s.type)==="FLOAT16"?Bq(e):e}function Lke(e){const t=B2(e);return{page_locations:t.field_1.map(Ike),unencoded_byte_array_data_bytes:t.field_2}}function Ike(e){return{offset:e.field_1,compressed_page_size:e.field_2,first_row_index:e.field_3}}function Hq(e,t){for(let r=0;rn.split(".")[0])),[...new Set(t)]}function Up(e,t,n=!0){return"$and"in t&&Array.isArray(t.$and)?t.$and.every(r=>Up(e,r,n)):"$or"in t&&Array.isArray(t.$or)?t.$or.some(r=>Up(e,r,n)):"$nor"in t&&Array.isArray(t.$nor)?!t.$nor.some(r=>Up(e,r,n)):Object.entries(t).every(([r,i])=>{const s=Pke(e,r);return typeof i!="object"||i===null||Array.isArray(i)?al(s,i,n):Object.entries(i||{}).every(([o,a])=>o==="$gt"?s>a:o==="$gte"?s>=a:o==="$lt"?sUA({rowGroup:e,physicalColumns:t,filter:s,strict:r}));if("$or"in n&&Array.isArray(n.$or))return n.$or.every(s=>UA({rowGroup:e,physicalColumns:t,filter:s,strict:r}));if("$nor"in n&&Array.isArray(n.$nor))return!1;for(const[s,o]of Object.entries(n)){const a=t.indexOf(s);if(a===-1)continue;const l=(i=e.columns[a].meta_data)==null?void 0:i.statistics;if(!l)continue;const{min:u,max:c,min_value:f,max_value:d}=l,h=f!==void 0?f:u,p=d!==void 0?d:c;if(!(h===void 0||p===void 0)){for(const[g,m]of Object.entries(o||{}))if(g==="$gt"&&p<=m||g==="$gte"&&p=m||g==="$lte"&&h>m||g==="$eq"&&(mp)||g==="$ne"&&al(h,p,r)&&al(h,m,r)||g==="$in"&&Array.isArray(m)&&m.every(v=>vp)||g==="$nin"&&Array.isArray(m)&&al(h,p,r)&&m.includes(h))return!0}}return!1}function Pke(e,t){let n=e;for(const r of t.split("."))n=n==null?void 0:n[r];return n}const Bke=1<<21;function zke({metadata:e,rowStart:t=0,rowEnd:n=1/0,columns:r,filter:i,filterStrict:s=!0,useOffsetIndex:o=!1}){if(!e)throw new Error("parquetPlan requires metadata");const a=[],l=[],u=[],c=yke(jA(e));let f=0;for(const d of e.row_groups){const h=Number(d.num_rows),p=f+h;if(h>0&&p>t&&fe.slice(r,i));return{byteLength:e.byteLength,slice(r,i=e.byteLength){const s=t.findIndex(({startByte:o,endByte:a})=>o<=r&&i<=a);if(s<0)return e.slice(r,i);if(t[s].startByte!==r||t[s].endByte!==i){const o=r-t[s].startByte,a=i-t[s].startByte;return n[s]instanceof Promise?n[s].then(l=>l.slice(o,a)):n[s].slice(o,a)}else return n[s]}}}const BF=new TextDecoder,bT=new WeakMap;function Yq(e,t=P2){if(Array.isArray(e))return e.map(n=>Yq(n,t));if(typeof e!="object")return e;if("metadata"in e){const n=Uke(e.metadata),r=e.typed_value&&R1(e.typed_value,n,t),i=e.value&&Wg(_y(e.value),n,t);return r&&i?{...i,...r}:r??i}return e}function R1(e,t,n){if(e&&typeof e=="object"&&!Array.isArray(e)&&!(e instanceof Uint8Array)){if("typed_value"in e)return R1(e.typed_value,t,n);if("value"in e&&e.value instanceof Uint8Array)return Wg(_y(e.value),t,n);const r={};for(const[i,s]of Object.entries(e))r[i]=R1(s,t,n);return r}return e instanceof Uint8Array?Wg(_y(e),t,n):Array.isArray(e)?e.map(r=>R1(r,t,n)):e}function _y(e){return{view:new DataView(e.buffer,e.byteOffset,e.byteLength),offset:0}}function Uke(e){let t=bT.get(e.buffer);t||(t=new Map,bT.set(e.buffer,t));const n=`${e.byteOffset}:${e.byteLength}`,r=t.get(n);if(r)return r;const i=_y(e),s=i.view.getUint8(i.offset++),o=s&15;if(o!==1)throw new Error(`parquet unsupported variant metadata version: ${o}`);const a=(s>>4&1)===1,l=(s>>6&3)+1,u=Rc(i,l),c=new Array(u+1);for(let p=0;p>2;if(i===0)return qke(e,s,n);if(i===2)return Wke(e,s,t,n);if(i===3)return Hke(e,s,t,n);const o=new Uint8Array(e.view.buffer,e.view.byteOffset+e.offset,s);return e.offset+=s,BF.decode(o)}function qke(e,t,n){switch(t){case 0:return null;case 1:return!0;case 2:return!1;case 3:{const r=e.view.getInt8(e.offset);return e.offset+=1,r}case 4:{const r=e.view.getInt16(e.offset,!0);return e.offset+=2,r}case 5:{const r=e.view.getInt32(e.offset,!0);return e.offset+=4,r}case 6:{const r=e.view.getBigInt64(e.offset,!0);return e.offset+=8,r}case 7:{const r=e.view.getFloat64(e.offset,!0);return e.offset+=8,r}case 8:return X_(e,4);case 9:return X_(e,8);case 10:return X_(e,16);case 11:{const r=e.view.getInt32(e.offset,!0);return e.offset+=4,n.dateFromDays(r)}case 12:case 13:{const r=e.view.getBigInt64(e.offset,!0);return e.offset+=8,n.timestampFromMicroseconds(r)}case 14:{const r=e.view.getFloat32(e.offset,!0);return e.offset+=4,r}case 15:return xT(e);case 16:{const r=xT(e);return BF.decode(r)}case 17:{const r=e.view.getBigInt64(e.offset,!0);return e.offset+=8,r}case 18:case 19:{const r=e.view.getBigInt64(e.offset,!0);return e.offset+=8,n.timestampFromNanoseconds(r)}case 20:{const r=new Uint8Array(e.view.buffer,e.view.byteOffset+e.offset,16);e.offset+=16;const i=Array.from(r,s=>s.toString(16).padStart(2,"0")).join("");return`${i.slice(0,8)}-${i.slice(8,12)}-${i.slice(12,16)}-${i.slice(16,20)}-${i.slice(20)}`}default:throw new Error(`parquet unsupported variant primitive type: ${t}`)}}function Wke(e,t,n,r){const i=(t&3)+1,s=(t>>2&3)+1,a=t>>4&1?Rc(e,4):e.view.getUint8(e.offset++),l=new Array(a);for(let f=0;f>2&1,o=i+1,a=Rc(e,s?4:1),l=new Array(a+1);for(let f=0;fp.repetition_type);let l=0;const u=[e];let c=e,f=0,d=0,h=0;if(n[0])for(;f>h&g;for(h+=d;h>=8;)h-=8n,e.offset++,h&&(m|=BigInt(e.view.getUint8(e.offset))<>>1;Yke(e,a,t,n,s),s+=a}}e.offset=i+r}function Yke(e,t,n,r,i){const s=n+7>>3;let o=0;for(let a=0;a>1<<3;const o=(1<8?(u-=8,l-=8,a>>>=8):l-u>u&o),s--,u+=n);return i}function Zq(e,t,n,r){const i=Xke(n,r),s=new Uint8Array(t*i);for(let o=0;o=n)throw new Error("invalid snappy length header");for(;i=n)throw new Error("missing eof marker");if((o&3)===0){let l=(o>>>2)+1;if(l>60){if(i+3>=n)throw new Error("snappy error literal pos + 3 >= inputLength");const u=l-60;l=e[i]+(e[i+1]<<8)+(e[i+2]<<16)+(e[i+3]<<24),l=(l&iSe[u])+1,i+=u}if(i+l>n)throw new Error("snappy error literal exceeds input length");wT(e,i,t,s,l),i+=l,s+=l}else{let l=0;switch(o&3){case 1:a=(o>>>2&7)+4,l=e[i]+(o>>>5<<8),i++;break;case 2:if(n<=i+1)throw new Error("snappy error end of input");a=(o>>>2)+1,l=e[i]+(e[i+1]<<8),i+=2;break;case 3:if(n<=i+3)throw new Error("snappy error end of input");a=(o>>>2)+1,l=e[i]+(e[i+1]<<8)+(e[i+2]<<16)+(e[i+3]<<24),i+=4;break}if(l===0||isNaN(l))throw new Error(`invalid offset ${l} pos ${i} inputLength ${n}`);if(l>s)throw new Error("cannot copy from before start of buffer");wT(t,s-l,t,s,a),s+=a}}if(s!==r)throw new Error("premature end of input")}function oSe(e,t,{type:n,element:r,schemaPath:i}){const s=new DataView(e.buffer,e.byteOffset,e.byteLength),o={view:s,offset:0};let a;const l=aSe(o,t,i),{definitionLevels:u,numNulls:c}=lSe(o,t,i),f=t.num_values-c;if(t.encoding==="PLAIN")a=zF(o,n,f,r.type_length);else if(t.encoding==="PLAIN_DICTIONARY"||t.encoding==="RLE_DICTIONARY"||t.encoding==="RLE"){const d=n==="BOOLEAN"?1:s.getUint8(o.offset++);d?(a=new Array(f),n==="BOOLEAN"?(bu(o,d,a),a=a.map(h=>!!h)):bu(o,d,a,s.byteLength-o.offset)):a=new Uint8Array(f)}else if(t.encoding==="BYTE_STREAM_SPLIT")a=Zq(o,f,n,r.type_length);else if(t.encoding==="DELTA_BINARY_PACKED")a=n==="INT32"?new Int32Array(f):new BigInt64Array(f),Hg(o,f,a);else if(t.encoding==="DELTA_LENGTH_BYTE_ARRAY")a=new Array(f),Kq(o,f,a);else throw new Error(`parquet unsupported encoding: ${t.encoding}`);return{definitionLevels:u,repetitionLevels:l,dataPage:a}}function aSe(e,t,n){if(n.length>1){const r=Uq(n);if(r){const i=new Array(t.num_values);return bu(e,z2(r),i),i}}return[]}function lSe(e,t,n){const r=PF(n);if(!r)return{definitionLevels:[],numNulls:0};const i=new Array(t.num_values);bu(e,z2(r),i);let s=t.num_values;for(const o of i)o===r&&s--;return s===0&&(i.length=0),{definitionLevels:i,numNulls:s}}function qA(e,t,n,r){let i;const s=r==null?void 0:r[n];if(n==="UNCOMPRESSED")i=e;else if(s)i=s(e,t);else if(n==="SNAPPY")i=new Uint8Array(t),sSe(e,i);else throw new Error(`parquet unsupported compression codec: ${n}`);if((i==null?void 0:i.length)!==t)throw new Error(`parquet decompressed page length ${i==null?void 0:i.length} does not match header ${t}`);return i}function uSe(e,t,n){const i={view:new DataView(e.buffer,e.byteOffset,e.byteLength),offset:0},{type:s,element:o,schemaPath:a,codec:l,compressors:u}=n,c=t.data_page_header_v2;if(!c)throw new Error("parquet data page header v2 is undefined");const f=cSe(i,c,a);i.offset=c.repetition_levels_byte_length;const d=fSe(i,c,a),h=t.uncompressed_page_size-c.definition_levels_byte_length-c.repetition_levels_byte_length;let p=e.subarray(i.offset);c.is_compressed!==!1&&(p=qA(p,h,l,u));const g=new DataView(p.buffer,p.byteOffset,p.byteLength),m={view:g,offset:0};let v;const b=c.num_values-c.num_nulls;if(c.encoding==="PLAIN")v=zF(m,s,b,o.type_length);else if(c.encoding==="RLE")v=new Array(b),bu(m,1,v),v=v.map(x=>!!x);else if(c.encoding==="PLAIN_DICTIONARY"||c.encoding==="RLE_DICTIONARY"){const x=g.getUint8(m.offset++);v=new Array(b),bu(m,x,v,h-1)}else if(c.encoding==="DELTA_BINARY_PACKED")v=s==="INT32"?new Int32Array(b):new BigInt64Array(b),Hg(m,b,v);else if(c.encoding==="DELTA_LENGTH_BYTE_ARRAY")v=new Array(b),Kq(m,b,v);else if(c.encoding==="DELTA_BYTE_ARRAY")v=new Array(b),Gke(m,b,v);else if(c.encoding==="BYTE_STREAM_SPLIT")v=Zq(m,b,s,o.type_length);else throw new Error(`parquet unsupported encoding: ${c.encoding}`);return{definitionLevels:d,repetitionLevels:f,dataPage:v}}function cSe(e,t,n){const r=Uq(n);if(!r)return[];const i=new Array(t.num_values);return bu(e,z2(r),i,t.repetition_levels_byte_length),i}function fSe(e,t,n){const r=PF(n);if(r){const i=new Array(t.num_values);return bu(e,z2(r),i,t.definition_levels_byte_length),i}}function ET(e,{groupStart:t,selectStart:n,selectEnd:r},i,s){const{pathInSchema:o,schemaPath:a}=i,l=qq(a),u=[];let c,f,d=0,h=0;const p=s&&(()=>{f&&s({pathInSchema:o,columnData:f,rowStart:t+d-f.length,rowEnd:t+d})});for(;(l?d=e.view.byteLength-1);){const g=dSe(e);if(g.type==="DICTIONARY_PAGE"){const{data:m}=AT(e,g,i,c,void 0,0);m&&(c=Iq(m,i))}else{const m=(f==null?void 0:f.length)||0,v=AT(e,g,i,c,f,n-d);v.skipped?(u.length||(h+=v.skipped),d+=v.skipped):v.data&&f===v.data?d+=v.data.length-m:v.data&&v.data.length&&(p==null||p(),u.push(v.data),d+=v.data.length,f=v.data)}}return p==null||p(),{data:u,skipped:h}}function AT(e,t,n,r,i,s){const{type:o,element:a,schemaPath:l,codec:u,compressors:c}=n,f=new Uint8Array(e.view.buffer,e.view.byteOffset+e.offset,t.compressed_page_size);if(e.offset+=t.compressed_page_size,t.type==="DATA_PAGE"){const d=t.data_page_header;if(!d)throw new Error("parquet data page header is undefined");if(s>d.num_values&&qq(l))return{skipped:d.num_values};const h=qA(f,Number(t.uncompressed_page_size),u,c),{definitionLevels:p,repetitionLevels:g,dataPage:m}=oSe(h,d,n),v=hT(m,r,d.encoding,n),b=Array.isArray(i)?i:[];return{skipped:0,data:_T(b,p,g,v,l)}}else if(t.type==="DATA_PAGE_V2"){const d=t.data_page_header_v2;if(!d)throw new Error("parquet data page header v2 is undefined");if(s>d.num_rows)return{skipped:d.num_values};const{definitionLevels:h,repetitionLevels:p,dataPage:g}=uSe(f,t,n),m=hT(g,r,d.encoding,n),v=Array.isArray(i)?i:[];return{skipped:0,data:_T(v,h,p,m,l)}}else if(t.type==="DICTIONARY_PAGE"){const d=t.dictionary_page_header;if(!d)throw new Error("parquet dictionary page header is undefined");const h=qA(f,Number(t.uncompressed_page_size),u,c),p={view:new DataView(h.buffer,h.byteOffset,h.byteLength),offset:0};return{skipped:0,data:zF(p,o,d.num_values,a.type_length)}}else throw new Error(`parquet unsupported page type: ${t.type}`)}function dSe(e){const t=B2(e),n=Oq[t.field_1],r=t.field_2,i=t.field_3,s=t.field_4,o=t.field_5&&{num_values:t.field_5.field_1,encoding:uc[t.field_5.field_2],definition_level_encoding:uc[t.field_5.field_3],repetition_level_encoding:uc[t.field_5.field_4],statistics:t.field_5.field_5&&{max:t.field_5.field_5.field_1,min:t.field_5.field_5.field_2,null_count:t.field_5.field_5.field_3,distinct_count:t.field_5.field_5.field_4,max_value:t.field_5.field_5.field_5,min_value:t.field_5.field_5.field_6}},a=t.field_6,l=t.field_7&&{num_values:t.field_7.field_1,encoding:uc[t.field_7.field_2],is_sorted:t.field_7.field_3},u=t.field_8&&{num_values:t.field_8.field_1,num_nulls:t.field_8.field_2,num_rows:t.field_8.field_3,encoding:uc[t.field_8.field_4],definition_levels_byte_length:t.field_8.field_5,repetition_levels_byte_length:t.field_8.field_6,is_compressed:t.field_8.field_7===void 0?!0:t.field_8.field_7,statistics:t.field_8.field_8};return{type:n,uncompressed_page_size:r,compressed_page_size:i,crc:s,data_page_header:o,index_page_header:a,dictionary_page_header:l,data_page_header_v2:u}}function hSe(e,{metadata:t},n){const{file:r,compressors:i,utf8:s}=e,o=[],a={...P2,...e.parsers};for(const l of n.chunks){const{columnMetadata:u}=l,c=jq(t.schema,u.path_in_schema),f={pathInSchema:u.path_in_schema,type:u.type,element:c[c.length-1].element,schemaPath:c,codec:u.codec,parsers:a,compressors:i,utf8:s};if(!("offsetIndex"in l)){o.push({pathInSchema:u.path_in_schema,data:Promise.resolve(r.slice(l.range.startByte,l.range.endByte)).then(d=>{const h={view:new DataView(d),offset:0};return ET(h,n,f,e.onPage)})});continue}o.push({pathInSchema:u.path_in_schema,data:Promise.resolve(r.slice(l.offsetIndex.startByte,l.offsetIndex.endByte)).then(async d=>{const h=Lke({view:new DataView(d),offset:0}),{selectStart:p,selectEnd:g}=n,m=h.page_locations;let v=NaN,b=NaN,x=0;for(let S=0;Sp&&(Number.isNaN(v)&&(v=Number($.offset),x=M),b=Number($.offset)+$.compressed_page_size)}const _=await r.slice(v,b),w={view:new DataView(_),offset:0},A=x?{...n,groupStart:n.groupStart+x,selectStart:n.selectStart-x,selectEnd:n.selectEnd-x}:n,{data:E,skipped:k}=ET(w,A,f,e.onPage);return{data:E,skipped:x+k}})})}return{groupStart:n.groupStart,groupRows:n.groupRows,asyncColumns:o}}async function kT({asyncColumns:e},t,n,r,i){const s=await Promise.all(e.map(async({data:f})=>{const d=await f;return{...d,data:Gq(d.data)}})),o=e.map(f=>f.pathInSchema[0]).filter(f=>!r||r.includes(f)),a=r??o,l=a.map(f=>e.findIndex(d=>d.pathInSchema[0]===f)),u=n-t;if(i==="object"){const f=Array(u);for(let d=0;d=0){const{data:m,skipped:v}=s[g];h[p]=m[d-v]}}c[f]=h}return c}function pSe(e,t,n){const{asyncColumns:r}=e;n={...P2,...n};const i=[];for(const s of t.children)if(s.children.length){const o=r.filter(u=>u.pathInSchema[0]===s.element.name);if(!o.length)continue;const a=new Map,l=Promise.all(o.map(u=>u.data.then(({data:c})=>{a.set(u.pathInSchema.join("."),Gq(c))}))).then(()=>{qp(a,s,n);const u=a.get(s.path.join("."));if(!u)throw new Error("parquet column data not assembled");return{data:[u],skipped:0}});i.push({pathInSchema:s.path,data:l})}else{const o=r.find(a=>a.pathInSchema[0]===s.element.name);o&&i.push(o)}return{...e,asyncColumns:i}}async function gSe(e){e.metadata??(e.metadata=await Rke(e.file,e));const{rowStart:t=0,rowEnd:n,columns:r,onChunk:i,onComplete:s,rowFormat:o,filter:a,filterStrict:l=!0}=e;if(a&&o!=="object")throw new Error('parquet filter requires rowFormat: "object"');const u=T1(a);if(u.length){const m=jA(e.metadata).children.map(b=>b.element.name),v=u.filter(b=>!m.includes(b));if(v.length)throw new Error(`parquet filter columns not found: ${v.join(", ")}`)}let c=r,f=!1;if(r&&a){const m=u.filter(v=>!r.includes(v));m.length&&(c=[...r,...m],f=!0)}const d=c!==r?{...e,columns:c}:e,h=mSe(d);if(!s&&!i){for(const{asyncColumns:m}of h)for(const{data:v}of m)await v;return}const p=jA(e.metadata),g=h.map(m=>pSe(m,p,e.parsers));if(i)for(const m of g)for(const v of m.asyncColumns)v.data.then(({data:b,skipped:x})=>{let _=m.groupStart+x;for(const w of b)i({columnName:v.pathInSchema[0],columnData:w,rowStart:_,rowEnd:_+w.length}),_+=w.length});if(s){const m=[];for(const v of g){const b=Math.max(t-v.groupStart,0),x=Math.min((n??1/0)-v.groupStart,v.groupRows),_=o==="object"?await kT(v,b,x,c,"object"):await kT(v,b,x,r,"array");if(a){for(const w of _)if(Up(w,a,l)){if(f&&r)for(const A of u)r.includes(A)||delete w[A];m.push(w)}}else Hq(m,_)}s(m)}else for(const{asyncColumns:m}of g)for(const{data:v}of m)await v}function mSe(e){if(!e.metadata)throw new Error("parquet requires metadata");const t=zke(e);return e.file=jke(e.file,t),t.groups.map(n=>hSe(e,t,n))}const Vm=new Map;function vSe(e){const t={};for(const n in e){const r=e[n];t[n]=typeof r=="bigint"?Number(r):r}return t}async function U2(e,t={}){if(Vm.has(e))return Vm.get(e);const n=await fetch(e,{headers:t});if(!n.ok){if(n.status===404)return Vm.set(e,[]),[];throw new Error(`Failed to fetch ${e}: ${n.status}`)}const r=await n.arrayBuffer();let i=[];return await gSe({file:r,rowFormat:"object",onComplete:s=>{i=s.map(vSe)}}),Vm.set(e,i),i}let Bn=null,Xm=null,Km=null,Zm=null,Jm=null,Wf=null,Hf=null,Lo=null;function Df(e){return Bn.bucket_id?`https://huggingface.co/buckets/${Bn.bucket_id}/resolve/${e}`:`https://huggingface.co/datasets/${Bn.dataset_id}/resolve/main/${e}`}async function ySe(e){Bn=e}function bSe(){return!Bn||Bn.mode!=="static"?null:Bn.bucket_id?{url:`https://huggingface.co/buckets/${Bn.bucket_id}`}:Bn.dataset_id?{url:`https://huggingface.co/datasets/${Bn.dataset_id}`}:null}async function jF(){return Xm||(Xm=await U2(Df("metrics.parquet")),Xm)}async function Jq(){return Km||(Km=await U2(Df("aux/system_metrics.parquet")),Km)}async function Qq(){return Zm||(Zm=await U2(Df("aux/configs.parquet")),Zm)}async function UF(){return Jm||(Jm=await U2(Df("aux/traces.parquet")),Jm)}async function qF(){if(Wf)return Wf;const e=await fetch(Df("runs.json"));return e.ok?(Wf=await e.json(),Wf):(Wf=[],Wf)}async function xSe(){if(Hf)return Hf;const e=await fetch(Df("settings.json"));return e.ok?(Hf=await e.json(),Hf):(Hf={},Hf)}const J0=new Set(["id","run_id","run_name","timestamp","step","log_id","space_id","created_at"]);function Q0(e){return!e||e.length===0?{rows:[],columns:[]}:{rows:e,columns:Object.keys(e[0])}}function WF(e){return e==null?{name:null,id:null}:typeof e=="string"?{name:e,id:null}:{name:e.name??null,id:e.id??null}}function em(e,t){const n=WF(t);return n.id!=null&&e.run_id!=null?e.run_id===n.id:n.name==null?!0:e.run_name===n.name}async function _Se(){return[Bn.project]}async function wSe(){return(await qF()).map(t=>({id:t.id??t.run_id??t.name,name:t.name,created_at:t.created_at??null,last_step:t.last_step??null,log_count:t.log_count??0}))}async function ESe(e,t){const n=await jF(),{rows:r,columns:i}=Q0(n),s=i.filter(l=>!J0.has(l)),o=r.filter(l=>em(l,t)),a=new Set;for(const l of o)for(const u of s)l[u]!==null&&l[u]!==void 0&&a.add(u);return[...a]}async function eW(e,t){const n=await jF(),{rows:r}=Q0(n);return r.filter(s=>em(s,t)).map(s=>{const o={};for(const[a,l]of Object.entries(s))if(!J0.has(a)&&l!=null)if(typeof l=="string"&&l.startsWith("{")&&l.includes("_type"))try{o[a]=JSON.parse(l)}catch{o[a]=l}else o[a]=l;return o.timestamp=s.timestamp,o.step=s.step,o})}function ASe(e){const t=[];function n(r){if(r!=null){if(Array.isArray(r)){r.forEach(n);return}if(typeof r=="object"){Object.values(r).forEach(n);return}t.push(String(r))}}return n(e.messages||[]),n(e.metadata||{}),t.join(" ").toLowerCase()}function kSe(e,t){switch(t){case"step_asc":return[...e].sort((n,r)=>(n.step??0)-(r.step??0));case"step_desc":return[...e].sort((n,r)=>(r.step??0)-(n.step??0));case"request_time_asc":return[...e].sort((n,r)=>String(n.timestamp||"").localeCompare(String(r.timestamp||"")));case"request_time_desc":default:return[...e].sort((n,r)=>String(r.timestamp||"").localeCompare(String(n.timestamp||"")))}}function ST(e,t){if(e==null)return t;if(typeof e=="string"){if(!e)return t;try{return JSON.parse(e)}catch{return t}}if(typeof e=="object"&&!ArrayBuffer.isView(e)&&!(e instanceof ArrayBuffer))return e;let n;try{const r=e instanceof ArrayBuffer?new Uint8Array(e):new Uint8Array(e.buffer||e);n=new TextDecoder("utf-8").decode(r)}catch{return t}if(!n)return t;try{return JSON.parse(n)}catch{return t}}async function SSe(e,t){const n=await UF(),r=new Map;for(const o of n){if(!em(o,t))continue;const a=o.step;r.set(a,(r.get(a)||0)+1)}const i=[...r.entries()].map(([o,a])=>({step:o,count:a})).sort((o,a)=>(o.step??0)-(a.step??0));return{total:i.reduce((o,a)=>o+a.count,0),steps:i}}async function CSe(e,t,n={}){const r=WF(t);let o=(await UF()).filter(a=>em(a,t)).map(a=>{const l={id:a.id,key:a.key,index:a.trace_index,run:a.run_name||r.name,run_id:a.run_id||r.id,step:a.step,timestamp:a.timestamp,messages:ST(a.messages,[]),metadata:ST(a.metadata,{})};return l._search_text=(a.search_text||`${l.id} ${l.key} ${ASe(l)}`).toLowerCase(),l});if(n.step!=null&&(o=o.filter(a=>a.step===n.step)),n.search&&n.search.trim()){const a=n.search.trim().toLowerCase();o=o.filter(l=>l._search_text.includes(a))}return o=kSe(o,n.sort||"request_time_desc"),n.offset&&(o=o.slice(n.offset)),n.limit!=null&&(o=o.slice(0,n.limit)),o.map(({_search_text:a,...l})=>l)}async function $Se(){const e=await qF(),t=e.map(n=>n.last_step||0);return{project:Bn.project,num_runs:e.length,runs:e.map(n=>({id:n.id??n.run_id??n.name,name:n.name,created_at:n.created_at??null,last_step:n.last_step??null,log_count:n.log_count??0})),last_activity:t.length?Math.max(...t):null}}async function FSe(e,t){const n=await qF(),r=WF(t),i=n.find(c=>r.id!=null&&(c.id??c.run_id??c.name)!=null?(c.id??c.run_id??c.name)===r.id:c.name===r.name);if(!i)return{project:Bn.project,run:r.name,run_id:r.id,num_logs:0,metrics:[],config:null,last_step:null};const s=await ESe(Bn.project,t);let o=null;const a=await Qq(),{rows:l}=Q0(a),u=l.find(c=>r.id!=null&&c.run_id!=null?c.run_id===r.id:c.run_name===r.name);if(u){o={};for(const[c,f]of Object.entries(u))c!=="id"&&c!=="run_name"&&c!=="created_at"&&(o[c]=f)}return{project:Bn.project,run:i.name,run_id:i.id??i.run_id??i.name,num_logs:i.log_count||0,metrics:s,config:o,last_step:i.last_step}}async function DSe(){return[]}async function tW(e,t){const n=await Jq(),{rows:r}=Q0(n);return r.filter(s=>em(s,t)).map(s=>{const o={};for(const[a,l]of Object.entries(s))J0.has(a)||l!=null&&(o[a]=l);return o.timestamp=s.timestamp,o})}async function MSe(){const e=await xSe();return{logo_urls:{light:"/static/trackio/trackio_logo_type_light_transparent.png",dark:"/static/trackio/trackio_logo_type_dark_transparent.png"},color_palette:e.color_palette||[],plot_order:e.plot_order||[],table_truncate_length:250}}let Qm=null;const TSe=new Set(["trackio.image","trackio.video","trackio.audio","trackio.table"]),RSe=new Set(["trackio.markdown"]);function NSe(e){for(const[t,n]of Object.entries(e))if(!J0.has(t)&&n!=null&&typeof n=="number"&&Number.isFinite(n))return!0;return!1}function CT(e,t){for(const[n,r]of Object.entries(e)){if(J0.has(n)||r==null)continue;let i=r;if(typeof i=="string"&&i.startsWith("{")&&i.includes("_type"))try{i=JSON.parse(i)}catch{continue}if(i&&typeof i=="object"&&t.has(i._type))return!0}return!1}async function OSe(){if(Qm)return Qm;const[e,t,n,r]=await Promise.all([jF().catch(()=>[]),Jq().catch(()=>[]),UF().catch(()=>[]),nW().catch(()=>[])]),i=e||[];let s=!1,o=!1,a=!1;for(const l of i)if(!s&&NSe(l)&&(s=!0),!o&&CT(l,TSe)&&(o=!0),!a&&CT(l,RSe)&&(a=!0),s&&o&&a)break;return Qm={metrics:s,media:o,reports:a,system:(t||[]).length>0,traces:(n||[]).length>0,files:(r||[]).length>0},Qm}async function nW(){if(Lo)return Lo;if(Bn.bucket_id){const r=await fetch(`https://huggingface.co/api/buckets/${Bn.bucket_id}/tree?prefix=media/files/&recursive=true`);if(!r.ok)return Lo=[],Lo;const i=await r.json();return Lo=(Array.isArray(i)?i:[]).filter(s=>s.type==="file").map(s=>({name:s.path.split("/").at(-1)??s.path,path:s.path.slice(6)})),Lo}const e=await fetch(`https://huggingface.co/api/datasets/${Bn.dataset_id}`);if(!e.ok)return Lo=[],Lo;const t=await e.json();return Lo=(Array.isArray(t==null?void 0:t.siblings)?t.siblings:[]).map(r=>r==null?void 0:r.rfilename).filter(r=>typeof r=="string"&&r.startsWith("media/files/")).map(r=>({name:r.split("/").at(-1)??r,path:r.slice(6)})),Lo}async function LSe(){const e=new Set(["id","run_id","run_name","created_at"]),t=await Qq().catch(()=>null);if(!t)return{};const{rows:n}=Q0(t),r={};for(const i of n){const s=i.run_name;if(!s)continue;const o={};for(const[a,l]of Object.entries(i))e.has(a)||l!=null&&(o[a]=l);r[i.run_id??s]=o}return r}async function ISe(){return{allowed:!1}}async function PSe(){throw new Error("Not supported in static mode")}async function BSe(){throw new Error("Not supported in static mode")}function zSe(e){return Bn.project&&e.startsWith(Bn.project+"/")?e.slice(Bn.project.length+1):e}function rW(e){const t=zSe(e);return Df(`media/${t}`)}let WA=0;function iW(){return typeof window>"u"?!1:(window.location.hostname||"").toLowerCase().endsWith(".hf.space")}function jSe(){const e=Date.now()+12e3;WA=Math.max(WA,e)}function HF(){return Date.now()(ug=e,e))),K_)}function WSe(){const e=sessionStorage.getItem("trackio_oauth_session");return e?{"x-trackio-oauth-session":e}:{}}async function vr(e,t={}){const n=e.startsWith("/")?e.slice(1):e,r=`${q2}/api/${n}`,i=await fetch(r,{method:"POST",credentials:"include",headers:{"Content-Type":"application/json",...WSe()},body:JSON.stringify(t)});if(i.status===429&&jSe(),!i.ok)throw new Error(`API call ${e} failed: ${i.status}`);const s=await i.json();if(s.error)throw new Error(s.error);return s.data}async function HSe(){return await Gn()?_Se():await vr("/get_all_projects")}async function GSe(e){return await Gn()?wSe():await vr("/get_runs_for_project",{project:e})}async function YSe(e){return await Gn()?LSe():await vr("/get_run_configs",{project:e})}function js(e){return e==null?{run:null,run_id:null}:typeof e=="string"?{run:e,run_id:null}:{run:e.name??null,run_id:e.id??null}}async function aW(e,t){const n={project:e,...js(t)};return await Gn()?eW(e,t):await vr("/get_logs",n)}async function VSe(e,t){if(await Gn()){const r=[];for(const i of t){const s=await eW(e,i);r.push({...js(i),logs:s})}return r}const n={project:e,runs:t.map(r=>js(r))};return await vr("/get_logs_batch",n)}async function XSe(e,t,n={}){const r={project:e,...js(t),...n};return await Gn()?CSe(e,t,n):await vr("/get_traces",r)}async function KSe(e,t){const n={project:e,...js(t)};return await Gn()?SSe(e,t):await vr("/get_trace_steps",n)}async function ZSe(e){return await Gn()?$Se():await vr("/get_project_summary",{project:e})}async function lW(e,t){const n={project:e,...js(t)};return await Gn()?FSe(e,t):await vr("/get_run_summary",n)}async function uW(e,t,n,r){const i={project:e,...js(t),level:n,since:r};return await Gn()?DSe():await vr("/get_alerts",i)}async function JSe(e,t){const n={project:e,...js(t)};return await Gn()?tW(e,t):await vr("/get_system_logs",n)}async function $T(e,t){if(await Gn()){const n=[];for(const r of t){const i=await tW(e,r);n.push({...js(r),logs:i})}return n}return await vr("/get_system_logs_batch",{project:e,runs:t.map(n=>js(n))})}async function QSe(){return await Gn()?MSe():await vr("/get_settings")}async function e3e(e){return await Gn()?nW():await vr("/get_project_files",{project:e})}async function t3e(e){return await Gn()?OSe():await vr("/get_tab_availability",{project:e})}async function n3e(){return await Gn()?ISe():await vr("/get_run_mutation_status",{})}async function r3e(e,t){const n={project:e,...js(t)};return await Gn()?PSe():await vr("/delete_run",n)}async function i3e(e,t,n){const r=js(t);return await Gn()?BSe():await vr("/rename_run",{project:e,old_name:r.run,run_id:r.run_id,new_name:n})}function s3e(e){oW=e?e+"/":""}function cW(e){return ug?rW(e):`${q2}/file?path=${encodeURIComponent(`${oW}${e}`)}`}function Z_(e){return ug?rW(e):`${q2}/file?path=${encodeURIComponent(e)}`}async function o3e(){return await Gn()?bSe():null}var a3e=U('

      No projects

      Create a project by calling trackio.init(project="…") in your training script.

      '),l3e=U('

      No run selected

      Select one or more runs in the sidebar.

      '),u3e=U('

      Start logging with Trackio

      You can create a new project by calling trackio.init():

      Then call trackio.log() to log metrics:

      Finally, call trackio.finish() to finish the run:

      '),c3e=U('
      '),f3e=U('
      '),d3e=U('
      ',1),h3e=U('
      ');function p3e(e,t){En(t,!0);let n=oe(t,"project",3,null),r=oe(t,"selectedRuns",19,()=>[]),i=oe(t,"allRuns",19,()=>[]),s=oe(t,"smoothing",3,10),o=oe(t,"xAxis",3,"step"),a=oe(t,"logScaleX",3,!1),l=oe(t,"logScaleY",3,!1),u=oe(t,"metricFilter",3,""),c=oe(t,"showHeaders",3,!0),f=oe(t,"appBootstrapReady",3,!1),d=oe(t,"plotOrder",19,()=>[]),h=oe(t,"realtimeEnabled",3,!0),p=oe(t,"metricColumns",31,()=>mt([])),g=se(mt([])),m=se("step"),v=se(mt([])),b=se(mt(new Set)),x=se(null),_=se(!1),w=se(mt({})),A=se(mt({group:null,index:-1})),E=new Map,k=null;const S=64;let $=we(()=>n0(i())),M=we(()=>{let Q=u()?lk(y(v),u()):y(v);return DR(Q,d())}),O=we(()=>Object.keys(y(M))),P=we(()=>{const Q=new Map,W=y(g),L=y(m),H=y(x);for(const ve of Object.values(y(M))){for(const G of ve.direct)Q.has(G)||Q.set(G,I1(W,L,G,H));for(const G of Object.values(ve.subgroups))for(const B of G)Q.has(B)||Q.set(B,I1(W,L,B,H))}return Q});function T(Q,W){const L=y(w)[Q];if(!L)return W;const H=[];for(const ve of L)W.includes(ve)&&H.push(ve);for(const ve of W)H.includes(ve)||H.push(ve);return H}function F(Q,W,L){D(A,{group:Q,index:W},!0),L.dataTransfer.effectAllowed="move",L.dataTransfer.setData("text/plain","")}function R(Q,W,L){y(A).group===Q&&(L.preventDefault(),L.dataTransfer.dropEffect="move")}function z(Q,W,L,H){if(H.preventDefault(),y(A).group!==Q||y(A).index===W){D(A,{group:null,index:-1},!0);return}const ve=[...L],[G]=ve.splice(y(A).index,1);ve.splice(W,0,G),D(w,{...y(w),[Q]:ve},!0),D(A,{group:null,index:-1},!0)}function j(){if(!n()||r().length===0){D(g,[],!0),D(v,[],!0);return}const Q=[];for(const B of r()){const ie=E.get(B.id??B.name);if(!ie)continue;const qe=$G(ie,B,s(),o(),a(),l());qe&&(Q.push(...qe.rows),D(m,qe.xColumn,!0))}D(g,Q,!0);const W=Q.filter(B=>B.data_type==="original"||!B.data_type),L=DG(W).filter(B=>B!=="run"&&B!=="data_type"&&B!=="x_axis"),H=L.filter(B=>B!==y(m));D(v,H,!0),p(L);const ve=new Map;for(const B of W){const ie=B.series_key;for(const qe of H){if(B[qe]==null)continue;const K=`${qe}\0${ie}`;ve.set(K,(ve.get(K)||0)+1)}}const G=new Set(H);for(const[B,ie]of ve)ie>1&&G.delete(B.split("\0")[0]);D(b,G,!0)}async function q(Q){const W=[];for(let L=0;L{const H=L.id??L.name;return!E.has(H)});let W=!1;if(Q.length>0)try{const L=await q(Q);for(const H of L){const ve=H.run_id??H.run;E.set(ve,H.logs),W=!0}}catch(L){console.error("Failed to load metric logs:",L)}(W||!y(_))&&j(),D(_,!0)}async function Y(){if(h()&&!(!n()||r().length===0)&&!GF()&&!HF())try{const Q=await q(r());let W=!1;for(const L of Q){const H=L.run_id??L.run,ve=L.logs,G=E.get(H);(!G||TR(G,ve))&&(E.set(H,ve),W=!0)}W&&j()}catch(Q){console.error("Failed to refresh metric logs:",Q)}}Bt(()=>{n(),r(),f(),E=n()?E:new Map,te()}),Bt(()=>{s(),o(),a(),l(),y(_)&&j()}),hh(()=>{const Q=$i("xmin"),W=$i("xmax");if(Q!=null&&Q!==""&&W!=null&&W!==""){const L=parseFloat(Q),H=parseFloat(W);!Number.isNaN(L)&&!Number.isNaN(H)&&L{k&&clearInterval(k)}});function ee(Q){Q&&Q.length===2&&D(x,Q,!0)}function _e(){D(x,null)}var Le=h3e(),Z=C(Le);{var he=Q=>{Bu(Q,{})},He=Q=>{var W=a3e();I(Q,W)},Ke=Q=>{var W=l3e();I(Q,W)},de=Q=>{var W=u3e(),L=N(C(W),4),H=C(L);H.textContent=`import trackio +trackio.init(project="my-project")`;var ve=N(L,4),G=C(ve);G.textContent=`for i in range(10): + trackio.log({"loss": 1/(i+1)})`;var B=N(ve,4),ie=C(B);ie.textContent="trackio.finish()",I(Q,W)},Re=Q=>{var W=Ri(),L=Ot(W);wt(L,17,()=>y(O),At,(H,ve)=>{const G=we(()=>y(M)[y(ve)]),B=we(()=>`${y(ve)}:direct`),ie=we(()=>T(y(B),y(G).direct)),qe=we(()=>y(G).direct.length),K=we(()=>Object.values(y(G).subgroups).reduce((J,ye)=>J+ye.length,0)),V=we(()=>y(qe)+y(K));{let J=we(()=>!c());OA(H,{get label(){return`${y(ve)??""} (${y(V)??""})`},open:!0,get hidden(){return y(J)},children:(ye,X)=>{var ke=d3e(),Fe=Ot(ke);{var Ie=Oe=>{var Me=c3e();wt(Me,21,()=>y(ie),At,(Ge,lt,yt)=>{const Et=we(()=>y(P).get(y(lt))??{data:[],yExtent:void 0}),ct=we(()=>y(Et).data),Ut=we(()=>y(Et).yExtent),me=we(()=>y(b).has(y(lt))),Ee=we(()=>c()&&y(lt).split("/").slice(1).join("/")||y(lt));var Ye=Ri(),ht=Ot(Ye);{var Ve=Xe=>{var dt=Ri(),pt=Ot(dt);{var Ct=pe=>{lT(pe,{get data(){return y(ct)},get y(){return y(lt)},get title(){return y(Ee)},colorField:"series_key",colorDisplayField:"run",get colorMap(){return y($)},draggable:!0,ondragstart:et=>F(y(B),yt,et),ondragover:et=>R(y(B),yt,et),ondrop:et=>z(y(B),yt,y(ie),et)})},le=pe=>{xy(pe,{get data(){return y(ct)},get x(){return y(m)},get y(){return y(lt)},get title(){return y(Ee)},colorField:"series_key",colorDisplayField:"run",get colorMap(){return y($)},get xLim(){return y(x)},get yExtent(){return y(Ut)},onSelect:ee,onResetZoom:_e,draggable:!0,ondragstart:et=>F(y(B),yt,et),ondragover:et=>R(y(B),yt,et),ondrop:et=>z(y(B),yt,y(ie),et)})};ge(pt,pe=>{y(me)?pe(Ct):pe(le,-1)})}I(Xe,dt)};ge(ht,Xe=>{y(ct).length>0&&Xe(Ve)})}I(Ge,Ye)}),I(Oe,Me)};ge(Fe,Oe=>{y(ie).length>0&&Oe(Ie)})}var ft=N(Fe,2);wt(ft,21,()=>Object.entries(y(G).subgroups),At,(Oe,Me)=>{var Ge=we(()=>VA(y(Me),2));let lt=()=>y(Ge)[0],yt=()=>y(Ge)[1];const Et=we(()=>`${y(ve)}:${lt()}`),ct=we(()=>T(y(Et),yt()));{let Ut=we(()=>!c());OA(Oe,{get label(){return`${lt()??""} (${yt().length??""})`},open:!0,get hidden(){return y(Ut)},children:(me,Ee)=>{var Ye=f3e();wt(Ye,21,()=>y(ct),At,(ht,Ve,Xe)=>{const dt=we(()=>y(P).get(y(Ve))??{data:[],yExtent:void 0}),pt=we(()=>y(dt).data),Ct=we(()=>y(dt).yExtent),le=we(()=>y(b).has(y(Ve))),pe=we(()=>c()&&y(Ve).split("/").slice(2).join("/")||y(Ve));var et=Ri(),Ze=Ot(et);{var nt=Be=>{var Xt=Ri(),sn=Ot(Xt);{var ot=Rt=>{lT(Rt,{get data(){return y(pt)},get y(){return y(Ve)},get title(){return y(pe)},colorField:"series_key",colorDisplayField:"run",get colorMap(){return y($)},draggable:!0,ondragstart:bt=>F(y(Et),Xe,bt),ondragover:bt=>R(y(Et),Xe,bt),ondrop:bt=>z(y(Et),Xe,y(ct),bt)})},Pt=Rt=>{xy(Rt,{get data(){return y(pt)},get x(){return y(m)},get y(){return y(Ve)},get title(){return y(pe)},colorField:"series_key",colorDisplayField:"run",get colorMap(){return y($)},get xLim(){return y(x)},get yExtent(){return y(Ct)},onSelect:ee,onResetZoom:_e,draggable:!0,ondragstart:bt=>F(y(Et),Xe,bt),ondragover:bt=>R(y(Et),Xe,bt),ondrop:bt=>z(y(Et),Xe,y(ct),bt)})};ge(sn,Rt=>{y(le)?Rt(ot):Rt(Pt,-1)})}I(Be,Xt)};ge(Ze,Be=>{y(pt).length>0&&Be(nt)})}I(ht,et)}),I(me,Ye)},$$slots:{default:!0}})}}),I(ye,ke)},$$slots:{default:!0}})}}),I(Q,W)};ge(Z,Q=>{!f()||!y(_)?Q(he):n()?r().length===0?Q(Ke,2):y(g).length===0?Q(de,3):Q(Re,-1):Q(He,1)})}I(e,Le),An()}var g3e=U('

      Select a project

      Pick a project to browse trace logs.

      '),m3e=U('

      No runs selected

      Select one or more runs in the sidebar to browse traces.

      '),v3e=U(""),y3e=U('

      No traces match the current filters

      Try a different search query, step, or run selection.

      '),b3e=U(" "),x3e=U('tool calls'),_3e=U('function call'),w3e=U('
      Expand content
       
      '),E3e=U('
       
      '),A3e=U(''),k3e=U('
       
      '),S3e=U('
      '),C3e=U('
       
      '),$3e=U('
      '),F3e=U('
       
      '),D3e=U('
      '),M3e=U('
      '),T3e=U('
      ',1),R3e=U('
      Trace IDRequestRunStepRequest time
      ',1),N3e=U('
      ',1),O3e=U('
      ');function L3e(e,t){En(t,!0);let n=oe(t,"project",3,null),r=oe(t,"selectedRuns",19,()=>[]);const i=50;let s=se(!1),o=se(""),a=se("request_time_desc"),l=se("all"),u=se(0),c=se(null),f=se(mt([])),d=se(mt([])),h=se(0),p=0,g=0;function m(L){return L.map(H=>`${H.id||""}:${H.name||""}`).join("|")}function v(L){return typeof L=="string"?L:Array.isArray(L)?L.map(H=>typeof H=="string"?H:typeof(H==null?void 0:H.text)=="string"?H.text:typeof(H==null?void 0:H.content)=="string"?H.content:(H==null?void 0:H._type)==="trackio.image"||(H==null?void 0:H.type)==="image"?"[image]":"").filter(Boolean).join(" "):typeof(L==null?void 0:L.text)=="string"?L.text:""}function b(L,H){const ve=Array.isArray(L.messages)?L.messages:[],G=ve.find(ie=>(ie==null?void 0:ie.role)==="user"),B=ve.find(ie=>(ie==null?void 0:ie.role)==="assistant");return{...L,run:L.run||H,request:v(G==null?void 0:G.content)||"(no user message)",preview:v(B==null?void 0:B.content)||"(no assistant response)"}}function x(L,H){return[...L].sort((ve,G)=>{switch(H){case"step_asc":return(ve.step??0)-(G.step??0);case"step_desc":return(G.step??0)-(ve.step??0);case"request_time_asc":return String(ve.timestamp||"").localeCompare(String(G.timestamp||""));case"request_time_desc":default:return String(G.timestamp||"").localeCompare(String(ve.timestamp||""))}})}async function _(){const L=++g;if(!n()||r().length===0){D(d,[],!0),D(h,0);return}try{const H=await Promise.all(r().map(B=>KSe(n(),B)));if(L!==g)return;const ve=new Map;let G=0;for(const B of H){G+=(B==null?void 0:B.total)||0;for(const ie of(B==null?void 0:B.steps)||[])ve.set(ie.step,(ve.get(ie.step)||0)+ie.count)}D(d,[...ve.entries()].map(([B,ie])=>({step:B,count:ie})).sort((B,ie)=>(B.step??0)-(ie.step??0)),!0),D(h,G,!0)}catch(H){if(L!==g)return;console.error("Failed to load trace summary:",H),D(d,[],!0),D(h,0)}}async function w(L,H,ve,G){const B=++p;if(!n()||r().length===0){D(f,[],!0),D(c,null);return}D(s,!0);try{const ie=ve==="all"?null:Number(ve),qe=G*i,K=r().length===1,V=K?i:qe+i,J=K?qe:0,ye=await Promise.all(r().map(async ke=>(await XSe(n(),ke,{search:L,sort:H,step:ie,limit:V,offset:J})).map(Ie=>b(Ie,ke.name))));if(B!==p)return;let X=x(ye.flat(),H);K||(X=X.slice(qe,qe+i)),D(f,X,!0),y(f).find(ke=>ke.id===y(c))||D(c,null)}catch(ie){if(B!==p)return;console.error("Failed to load traces:",ie),D(f,[],!0)}finally{B===p&&D(s,!1)}}let A="",E="",k="",S="all";Bt(()=>{const L=`${n()||""}::${m(r())}`;L!==A&&(A=L,D(u,0),D(l,"all"),D(c,null),D(f,[],!0),_())}),Bt(()=>{n(),m(r());const L=y(o).trim();(L!==E||y(a)!==k||y(l)!==S)&&((E!==""||L!==""||y(a)!==k||y(l)!==S)&&D(u,0),E=L,k=y(a),S=y(l));const H=setTimeout(()=>{w(L,y(a),y(l),y(u))},150);return()=>clearTimeout(H)});function $(L){D(c,y(c)===L?null:L,!0)}function M(L,H){(L.key==="Enter"||L.key===" ")&&(L.preventDefault(),$(H))}function O(L){if(!L)return"—";const H=new Date(L);if(Number.isNaN(H.getTime()))return L;const G=new Date().getTime()-H.getTime(),B=Math.max(0,Math.round(G/1e3));if(B<5)return"just now";if(B<60)return`${B} sec ago`;const ie=Math.round(B/60);if(ie<60)return`${ie} min ago`;const qe=Math.round(ie/60);if(qe<24)return`${qe} hr ago`;const K=Math.round(qe/24);if(K<7)return`${K} day${K===1?"":"s"} ago`;const V=Math.round(K/7);if(V<5)return`${V} wk ago`;const J=Math.round(K/30);return J<12?`${J} mo ago`:`${Math.round(K/365)} yr ago`}function P(L){const H=L==null?void 0:L.content;return typeof H=="string"||H==null?[]:Array.isArray(H)?H:[H]}function T(L){return P(L).length>0}function F(L){return(L==null?void 0:L._type)==="trackio.image"||(L==null?void 0:L.type)==="image"||(L==null?void 0:L.type)==="input_image"||(L==null?void 0:L.type)==="image_url"}function R(L){var H;return L!=null&&L.file_path?cW(L.file_path):(H=L==null?void 0:L.image_url)!=null&&H.url?L.image_url.url:typeof(L==null?void 0:L.url)=="string"?L.url:""}function z(L){return(L==null?void 0:L.caption)||(L==null?void 0:L.alt)||"Trace image"}function j(L){return typeof L=="string"&&L.length>500}function q(L){if(!L)return"";const H=String(L).split(":");if(H.length>=4){const ve=H[1],G=H[H.length-1];return G!==""&&!Number.isNaN(Number(G))?`${ve}:${G}`:ve}return String(L)}function te(L){if(!L)return"";const H=String(L).split(":"),ve=H.length>=4?H[1]||H[0]:String(L);return ve.replace(/[^a-zA-Z0-9]/g,"").slice(0,7)||ve.slice(0,7)}function Y(L){if(!L)return null;const H=String(L).split(":");if(H.length>=4){const ve=H[H.length-1];if(ve!==""&&!Number.isNaN(Number(ve)))return ve}return null}function ee(L){if(L==null)return"—";if(typeof L=="string")return L;if(typeof L=="number"||typeof L=="boolean")return String(L);try{return JSON.stringify(L)}catch{return String(L)}}function _e(L){return Object.entries(L.metadata||{})}let Le=we(()=>{if(y(l)==="all")return y(h);const L=Number(y(l)),H=y(d).find(ve=>ve.step===L);return H?H.count*Math.max(1,r().length):0}),Z=we(()=>Math.max(1,Math.ceil(y(Le)/i)));function he(){y(u)>0&&D(u,y(u)-1)}function He(){y(u){var H=g3e();I(L,H)},Q=L=>{var H=m3e();I(L,H)},W=L=>{var H=N3e(),ve=Ot(H),G=C(ve),B=C(G),ie=N(G,2),qe=N(C(ie),2),K=C(qe),V=C(K);K.value=K.__value="all";var J=N(K);wt(J,17,()=>y(d),At,(ct,Ut)=>{var me=v3e(),Ee=C(me),Ye={};xe(ht=>{be(Ee,`Step ${y(Ut).step??""} (${y(Ut).count??""})`),Ye!==(Ye=ht)&&(me.value=(me.__value=ht)??"")},[()=>String(y(Ut).step)]),I(ct,me)});var ye=N(ie,2),X=N(C(ye),2),ke=C(X);ke.value=ke.__value="request_time_desc";var Fe=N(ke);Fe.value=Fe.__value="request_time_asc";var Ie=N(Fe);Ie.value=Ie.__value="step_desc";var ft=N(Ie);ft.value=ft.__value="step_asc";var Oe=N(ye,2),Me=C(Oe),Ge=N(ve,2);{var lt=ct=>{Bu(ct,{})},yt=ct=>{var Ut=y3e();I(ct,Ut)},Et=ct=>{var Ut=R3e(),me=Ot(Ut);let Ee;var Ye=C(me),ht=N(C(Ye),2);wt(ht,21,()=>y(f),le=>le.id,(le,pe)=>{var et=T3e(),Ze=Ot(et),nt=C(Ze),Be=C(nt),Xt=C(Be),sn=N(nt),ot=C(sn),Pt=C(ot),Rt=N(ot,2),bt=C(Rt),Or=N(sn),ri=C(Or),Lr=N(Or),Vi=C(Lr),Hs=N(Lr),Zt=C(Hs),Fn=N(Ze,2);{var Ir=hn=>{var pn=M3e(),Ai=C(pn),ii=C(Ai),Yn=C(ii),Vn=C(Yn),ms=C(Vn),rr=N(Vn,2),ki=C(rr),si=N(rr,2),gn=C(si),zu=N(si,2);wt(zu,17,()=>_e(y(pe)),At,(br,bn)=>{var Pr=we(()=>VA(y(bn),2));let Ln=()=>y(Pr)[0],kn=()=>y(Pr)[1];var Ma=b3e(),xr=C(Ma);xe(Gs=>be(xr,`${Ln()??""}: ${Gs??""}`),[()=>ee(kn())]),I(br,Ma)});var yr=N(Yn,2);wt(yr,21,()=>y(pe).messages,At,(br,bn)=>{var Pr=D3e(),Ln=C(Pr),kn=C(Ln),Ma=N(kn);{var xr=Dn=>{var In=x3e();I(Dn,In)};ge(Ma,Dn=>{var In;(In=y(bn).tool_calls)!=null&&In.length&&Dn(xr)})}var Gs=N(Ma,2);{var fW=Dn=>{var In=_3e();I(Dn,In)};ge(Gs,Dn=>{y(bn).function_call&&Dn(fW)})}var YF=N(Ln,2);{var dW=Dn=>{var In=Ri(),ju=Ot(In);{var To=Ro=>{var qu=w3e(),Uh=N(C(qu),2),Al=C(Uh);xe(()=>be(Al,y(bn).content)),I(Ro,qu)},Uu=we(()=>j(y(bn).content)),jh=Ro=>{var qu=E3e(),Uh=C(qu);xe(()=>be(Uh,y(bn).content)),I(Ro,qu)};ge(ju,Ro=>{y(Uu)?Ro(To):Ro(jh,-1)})}I(Dn,In)},hW=Dn=>{var In=S3e();wt(In,21,()=>P(y(bn)),At,(ju,To)=>{var Uu=Ri(),jh=Ot(Uu);{var Ro=Al=>{var Mf=A3e();xe((W2,H2)=>{xt(Mf,"src",W2),xt(Mf,"alt",H2)},[()=>R(y(To)),()=>z(y(To))]),I(Al,Mf)},qu=we(()=>F(y(To))),Uh=Al=>{var Mf=k3e(),W2=C(Mf);xe(H2=>be(W2,H2),[()=>JSON.stringify(y(To),null,2)]),I(Al,Mf)};ge(jh,Al=>{y(qu)?Al(Ro):Al(Uh,-1)})}I(ju,Uu)}),I(Dn,In)},pW=we(()=>T(y(bn)));ge(YF,Dn=>{typeof y(bn).content=="string"?Dn(dW):y(pW)&&Dn(hW,1)})}var VF=N(YF,2);{var gW=Dn=>{var In=$3e();wt(In,21,()=>y(bn).tool_calls,At,(ju,To)=>{var Uu=C3e(),jh=C(Uu);xe(Ro=>be(jh,Ro),[()=>JSON.stringify(y(To),null,2)]),I(ju,Uu)}),I(Dn,In)};ge(VF,Dn=>{var In;(In=y(bn).tool_calls)!=null&&In.length&&Dn(gW)})}var mW=N(VF,2);{var vW=Dn=>{var In=F3e(),ju=C(In);xe(To=>be(ju,To),[()=>JSON.stringify(y(bn).function_call,null,2)]),I(Dn,In)};ge(mW,Dn=>{y(bn).function_call&&Dn(vW)})}xe(()=>{xt(Pr,"data-role",y(bn).role||"unknown"),be(kn,`${(y(bn).role||"message")??""} `)}),I(br,Pr)}),xe(br=>{be(ms,`Trace ID: ${br??""}`),be(ki,`Logged as: ${y(pe).key??""}`),be(gn,`Timestamp: ${(y(pe).timestamp||"—")??""}`)},[()=>q(y(pe).id)]),I(hn,pn)};ge(Fn,hn=>{y(c)===y(pe).id&&hn(Ir)})}xe((hn,pn,Ai,ii)=>{xt(Ze,"aria-expanded",y(c)===y(pe).id),xt(Be,"title",hn),be(Xt,`${pn??""}${Ai??""}`),be(Pt,y(pe).request),be(bt,y(pe).preview),be(ri,y(pe).run||"—"),be(Vi,y(pe).step??"—"),be(Zt,ii)},[()=>q(y(pe).id),()=>te(y(pe).id),()=>Y(y(pe).id)!==null?`:${Y(y(pe).id)}`:"",()=>O(y(pe).timestamp)]),Ue("click",Ze,()=>$(y(pe).id)),Ue("keydown",Ze,hn=>M(hn,y(pe).id)),I(le,et)});var Ve=N(me,2),Xe=C(Ve),dt=N(Xe,2),pt=C(dt),Ct=N(dt,2);xe(()=>{Ee=en(me,1,"traces-table-wrap svelte-1s32ifo",null,Ee,{dim:y(s)}),Xe.disabled=y(u)===0||y(s),be(pt,`Page ${y(u)+1} of ${y(Z)??""}`),Ct.disabled=y(u)>=y(Z)-1||y(s)}),Ue("click",Xe,he),Ue("click",Ct,He),I(ct,Ut)};ge(Ge,ct=>{y(s)&&y(f).length===0?ct(lt):y(f).length===0?ct(yt,1):ct(Et,-1)})}xe(()=>{be(V,`All steps (${y(h)??""})`),be(Me,`${y(Le)??""} trace${y(Le)===1?"":"s"}`)}),t0(B,()=>y(o),ct=>D(o,ct)),L1(qe,()=>y(l),ct=>D(l,ct)),L1(X,()=>y(a),ct=>D(a,ct)),I(L,H)};ge(de,L=>{n()?r().length===0?L(Q,1):L(W,-1):L(Re)})}I(e,Ke),An()}ni(["click","keydown"]);var I3e=U('

      Unable to load system metrics

      '),P3e=U('

      No projects

      Create a project by calling trackio.init(project="…") in your training script.

      '),B3e=U('

      No run selected

      Select one or more runs in the sidebar.

      '),z3e=U('

      No System Metrics Available

      System metrics will appear here once logged. To enable automatic logging:

      Setup:

      • CPU/system metrics: pip install trackio[cpu] (requires psutil)
      • NVIDIA GPU: pip install trackio[gpu] (requires nvidia-ml-py)
      • Apple Silicon: pip install trackio[apple-gpu] (requires psutil)
      '),j3e=U('
      '),U3e=U('
      '),q3e=U(" ",1),W3e=U('
      ');function H3e(e,t){En(t,!0);let n=oe(t,"project",3,null),r=oe(t,"selectedRuns",19,()=>[]),i=oe(t,"allRuns",19,()=>[]),s=oe(t,"smoothing",3,5),o=oe(t,"appBootstrapReady",3,!1),a=oe(t,"realtimeEnabled",3,!0),l=oe(t,"availableDevices",31,()=>mt([])),u=oe(t,"selectedDevices",31,()=>mt([])),c=se(mt([])),f=se(mt([])),d=se(null),h=se(!1),p=se(null),g=!0,m=se(mt({})),v=se(mt({group:null,index:-1}));const b=64;let x=new Map,_=null,w=we(()=>n0(i().length?i():r())),A=we(()=>DR(y(f))),E=we(()=>Object.keys(y(A))),k=we(()=>{const K=new Map,V=y(d);for(const J of Object.values(y(A))){for(const ye of J.direct)K.has(ye)||K.set(ye,I1(y(c),"time",ye,V));for(const ye of Object.values(J.subgroups))for(const X of ye)K.has(X)||K.set(X,I1(y(c),"time",X,V))}return K}),S=we(()=>{const K=[];for(const[V,J]of Object.entries(y(A)))for(const ye of R(Object.keys(J.subgroups)))K.push(Ke(V,ye));return[...new Set(K)]}),$=we(()=>{const K=new Map;for(const[V,J]of Object.entries(y(A)))K.set(V,Re(V,J.subgroups));return K}),M=we(()=>{const K=new Map,V=y(d);for(const[J,ye]of y($).entries())for(const[X,ke]of Object.entries(ye)){const Fe=`sys:${J}:compare:${X}`;K.set(Fe,Q(y(c),"time",ke,V))}return K});function O(K,V){const J=y(m)[K];if(!J)return V;const ye=[];for(const X of J)V.includes(X)&&ye.push(X);for(const X of V)ye.includes(X)||ye.push(X);return ye}function P(K,V,J){D(v,{group:K,index:V},!0),J.dataTransfer.effectAllowed="move",J.dataTransfer.setData("text/plain","")}function T(K,V,J){y(v).group===K&&(J.preventDefault(),J.dataTransfer.dropEffect="move")}function F(K,V,J,ye){if(ye.preventDefault(),y(v).group!==K||y(v).index===V){D(v,{group:null,index:-1},!0);return}const X=[...J],[ke]=X.splice(y(v).index,1);X.splice(V,0,ke),D(m,{...y(m),[K]:X},!0),D(v,{group:null,index:-1},!0)}function R(K){return[...K].sort((V,J)=>{const ye=Number(V),X=Number(J);return!Number.isNaN(ye)&&!Number.isNaN(X)?ye-X:V.localeCompare(J)})}function z(K,V){return K.length!==V.length?!1:K.every((J,ye)=>J===V[ye])}function j(){if(!n()||r().length===0){D(c,[],!0),D(f,[],!0);return}const K=[],V=new Set;for(const J of r()){const ye=J.id??J.name,X=x.get(ye);if(!X||X.length===0)continue;const ke=new Date(X[0].timestamp).getTime();X.forEach(Fe=>{const Ie=(new Date(Fe.timestamp).getTime()-ke)/1e3;Object.keys(Fe).forEach(ft=>{typeof Fe[ft]=="number"&&ft!=="step"&&ft!=="time"&&V.add(ft)}),K.push({...Fe,time:Ie,run:J.name,run_id:ye,series_key:ye,data_type:"original"})})}D(f,Array.from(V).sort(),!0),D(c,K,!0)}function q(K){const V=K&&K.message?String(K.message):"";return/\b(404|405|501)\b/.test(V)}async function te(K){if(g&&K.length<=b)try{return await $T(n(),K)}catch(J){if(!q(J))throw J;g=!1}if(g){const J=[];for(let ye=0;ye{const ye=J.id??J.name;return!x.has(ye)});let V=!1;if(K.length>0)try{const J=await te(K);for(const ye of J){const X=ye.run_id??ye.run;x.set(X,ye.logs),V=!0}D(p,null)}catch(J){if(console.error("Failed to load system metric logs:",J),!y(h)){D(p,J&&J.message?J.message:"Failed to load system metrics",!0);return}}(V||!y(h))&&j(),D(p,null),D(h,!0)}async function ee(){if(a()&&!(!n()||r().length===0)&&!GF()&&!HF())try{const K=await te(r());let V=!1;for(const J of K){const ye=J.run_id??J.run,X=J.logs,ke=x.get(ye);(!ke||TR(ke,X))&&(x.set(ye,X),V=!0)}V&&j()}catch(K){console.error("Failed to refresh system metric logs:",K)}}Bt(()=>{n(),r(),o(),x=n()?x:new Map,Y()}),Bt(()=>{s(),y(h)&&j()}),Bt(()=>{const K=l(),V=y(S),J=u().filter(ye=>V.includes(ye));if(z(l(),V)||l(V),V.length===0){u().length>0&&u([]);return}if(K.length===0&&u().length===0){z(u(),V)||u([...V]);return}if(u().length>0&&J.length!==u().length){const ye=J.length>0?J:[...V];z(u(),ye)||u(ye)}}),hh(()=>(_=setInterval(ee,sW()),()=>{_&&clearInterval(_)}));function _e(K){K&&K.length===2&&D(d,K,!0)}function Le(){D(d,null)}const Z={utilization:"%",mean_utilization:"%",allocated_memory:"GiB",total_allocated_memory:"GiB",power:"W",total_power:"W",temp:"°C",max_temp:"°C"};function he(K){const V=K.split("/").pop(),J=Z[V];return J?`${K} (${J})`:K}function He(K,V=1){const J=K.split("/").slice(V).join("/")||K;return he(J)}function Ke(K,V){return K==="gpu"?`GPU ${V}`:`${K.toUpperCase()} ${V}`}function de(K,V){return Ke(K,V)}function Re(K,V){const J={},ye=R(Object.keys(V)).filter(ke=>{const Fe=de(K,ke);return u().length===0||u().includes(Fe)});for(const ke of ye)for(const Fe of V[ke]??[]){const Ie=Fe.split("/").slice(2).join("/");Ie&&(J[Ie]||(J[Ie]=[]),J[Ie].push(Fe))}const X={};return Object.keys(J).sort().forEach(ke=>{X[ke]=J[ke]}),X}function Q(K,V,J,ye){if(!J||J.length===0)return{data:[],yExtent:void 0};let X=[];for(const Ie of J){const[ft,Oe]=Ie.split("/");for(const Me of K){const Ge=Me[Ie];Ge!=null&&X.push({[V]:Me[V],value:Ge,seriesKey:`${Me.series_key}\0${ft}\0${Oe}`,run:Me.run,series_key:Me.series_key,device:de(ft,Oe),data_type:Me.data_type})}}if(ye){const Ie=new Map;for(const Oe of X){const Me=`${Oe.seriesKey}\0${Oe.data_type||"original"}`;Ie.has(Me)||Ie.set(Me,[]),Ie.get(Me).push(Oe)}const ft=[];for(const Oe of Ie.values()){Oe.sort((lt,yt)=>lt[V]-yt[V]);let Me=0,Ge=Oe.length-1;for(;Me=0&&Oe[Ge][V]>ye[1];)Ge--;Me=Math.max(0,Me-1),Ge=Math.min(Oe.length-1,Ge+1),ft.push(...Oe.slice(Me,Ge+1))}X=ft}const ke=X.filter(Ie=>Ie.data_type==="original"||!Ie.data_type);let Fe;if(ke.length>0){let Ie=1/0,ft=-1/0;for(const Oe of ke)Oe.valueft&&(ft=Oe.value);Ie!==1/0&&(Fe=[Ie,ft])}return{data:FR(X,V,"value","seriesKey",ye,["seriesKey","run","series_key","device"]).data,yExtent:Fe}}var W=W3e(),L=C(W);{var H=K=>{Bu(K,{})},ve=K=>{var V=I3e(),J=N(C(V),2),ye=C(J);xe(()=>be(ye,y(p))),I(K,V)},G=K=>{var V=P3e();I(K,V)},B=K=>{var V=B3e();I(K,V)},ie=K=>{var V=z3e(),J=N(C(V),4),ye=C(J);ye.textContent=`import trackio + +# CPU/RAM/disk/network metrics: +run = trackio.init(project="my-project", auto_log_cpu=True) + +# GPU auto-enabled when NVIDIA or Apple Silicon is detected: +run = trackio.init(project="my-project", auto_log_gpu=True) + +# Manually log at any time: +trackio.log_cpu() +trackio.log_gpu()`,I(K,V)},qe=K=>{var V=Ri(),J=Ot(V);wt(J,17,()=>y(E),At,(ye,X)=>{const ke=we(()=>y(A)[y(X)]),Fe=we(()=>`sys:${y(X)}`),Ie=we(()=>`sys:${y(X)}:compare`),ft=we(()=>O(y(Fe),y(ke).direct)),Oe=we(()=>y($).get(y(X))??{}),Me=we(()=>O(y(Ie),Object.keys(y(Oe))));OA(ye,{get label(){return y(X)},open:!0,children:(Ge,lt)=>{var yt=q3e(),Et=Ot(yt);{var ct=Ee=>{var Ye=j3e();wt(Ye,21,()=>y(ft),At,(ht,Ve,Xe)=>{const dt=we(()=>y(k).get(y(Ve))??{data:[],yExtent:void 0}),pt=we(()=>y(dt).data),Ct=we(()=>y(dt).yExtent);var le=Ri(),pe=Ot(le);{var et=Ze=>{{let nt=we(()=>He(y(Ve),1));xy(Ze,{get data(){return y(pt)},x:"time",get y(){return y(Ve)},get title(){return y(nt)},get colorMap(){return y(w)},colorField:"series_key",colorDisplayField:"run",get xLim(){return y(d)},get yExtent(){return y(Ct)},onSelect:_e,onResetZoom:Le,draggable:!0,ondragstart:Be=>P(y(Fe),Xe,Be),ondragover:Be=>T(y(Fe),Xe,Be),ondrop:Be=>F(y(Fe),Xe,y(ft),Be)})}};ge(pe,Ze=>{y(pt).length>0&&Ze(et)})}I(ht,le)}),I(Ee,Ye)};ge(Et,Ee=>{y(ft).length>0&&Ee(ct)})}var Ut=N(Et,2);{var me=Ee=>{var Ye=U3e(),ht=C(Ye);wt(ht,21,()=>y(Me),At,(Ve,Xe,dt)=>{const pt=we(()=>`sys:${y(X)}:compare:${y(Xe)}`),Ct=we(()=>y(M).get(y(pt))??{data:[],yExtent:void 0}),le=we(()=>y(Ct).data),pe=we(()=>y(Ct).yExtent);var et=Ri(),Ze=Ot(et);{var nt=Be=>{{let Xt=we(()=>he(y(Xe))),sn=we(()=>he(y(Xe)));xy(Be,{get data(){return y(le)},x:"time",y:"value",get yLabel(){return y(Xt)},get title(){return y(sn)},colorField:"series_key",colorDisplayField:"run",colorLabel:"Run",get colorMap(){return y(w)},dashField:"device",dashLabel:"Device",get xLim(){return y(d)},get yExtent(){return y(pe)},onSelect:_e,onResetZoom:Le,draggable:!0,ondragstart:ot=>P(y(Ie),dt,ot),ondragover:ot=>T(y(Ie),dt,ot),ondrop:ot=>F(y(Ie),dt,y(Me),ot)})}};ge(Ze,Be=>{y(le).length>0&&Be(nt)})}I(Ve,et)}),I(Ee,Ye)};ge(Ut,Ee=>{y(Me).length>0&&Ee(me)})}I(Ge,yt)},$$slots:{default:!0}})}),I(K,V)};ge(L,K=>{!o()||!y(h)&&!y(p)?K(H):y(p)&&!y(h)?K(ve,1):n()?r().length===0?K(B,3):y(c).length===0?K(ie,4):K(qe,-1):K(G,2)})}I(e,W),An()}var G3e=_i(''),Y3e=_i(''),V3e=U('
      ');function X3e(e,t){En(t,!0);let n=oe(t,"src",3,"");const r=72;let i,s,o=se(mt([])),a=se(0),l=se(0),u=se(!1),c=se(!1);function f(S){if(!Number.isFinite(S)||S<0)return"0:00";const $=Math.floor(S/60),M=Math.floor(S%60);return`${$}:${M.toString().padStart(2,"0")}`}async function d(){var S;if(n()){D(c,!1);try{const M=await(await fetch(n())).arrayBuffer(),O=window.AudioContext||window.webkitAudioContext,P=new O,T=await P.decodeAudioData(M);D(a,T.duration,!0);const F=T.getChannelData(0),R=Math.max(1,Math.floor(F.length/r)),z=new Array(r);for(let q=0;qq/j),!0),(S=P.close)==null||S.call(P)}catch{D(c,!0)}}}function h(){if(!i||y(o).length===0)return;const S=window.devicePixelRatio||1,$=i.getBoundingClientRect();if($.width===0)return;i.width=$.width*S,i.height=$.height*S;const M=i.getContext("2d");M.setTransform(S,0,0,S,0,0),M.clearRect(0,0,$.width,$.height);const O=getComputedStyle(i),P=(O.getPropertyValue("--wave-played")||"#f97316").trim(),T=(O.getPropertyValue("--wave-base")||"#9ca3af").trim(),F=y(a)>0?y(l)/y(a):0,R=$.width/y(o).length,z=$.height/2;for(let j=0;j{}):s.pause())}function g(S){if(!s||!y(a))return;const $=i.getBoundingClientRect(),M=S.clientX-$.left,O=Math.max(0,Math.min(y(a),M/$.width*y(a)));s.currentTime=O,D(l,O,!0)}Bt(()=>{n(),D(o,[],!0),D(l,0),D(a,0),D(u,!1),d()}),Bt(()=>{y(o),y(l),y(a),h()});var m=V3e();fn("resize",$d,h);var v=C(m),b=C(v);{var x=S=>{var $=G3e();I(S,$)},_=S=>{var $=Y3e();I(S,$)};ge(b,S=>{y(u)?S(x):S(_,-1)})}var w=N(v,2);rs(w,S=>i=S,()=>i);var A=N(w,2),E=C(A),k=N(A,2);rs(k,S=>s=S,()=>s),xe((S,$)=>{xt(v,"aria-label",y(u)?"Pause":"Play"),v.disabled=y(c),be(E,`${S??""} / ${$??""}`),xt(k,"src",n())},[()=>f(y(l)),()=>f(y(a))]),Ue("click",v,p),Ue("click",w,g),fn("timeupdate",k,()=>D(l,s.currentTime,!0)),fn("loadedmetadata",k,()=>D(a,s.duration,!0)),fn("play",k,()=>D(u,!0)),fn("pause",k,()=>D(u,!1)),fn("ended",k,()=>{D(u,!1),D(l,0)}),I(e,m),An()}ni(["click"]);var K3e=U('

      Select a project

      Pick a project in the sidebar to browse media and tables for a run.

      ',1),Z3e=U('

      No runs selected

      Select runs in the sidebar to browse media and tables.

      ',1),J3e=U('

      No media or tables in this run

      Log images, video, audio, and tables by passing Trackio objects to trackio.log():

      Each type appears in its own section here once logged.

      ',1),Q3e=U('
      '),eCe=U('
      '),tCe=U('
      '),nCe=U(''),rCe=U('
      '),iCe=U('
      '),sCe=U('',2),oCe=U('
      '),aCe=U('
      '),lCe=U(''),uCe=U('
      '),cCe=U('
      '),fCe=U(' '),dCe=U(''),hCe=U(''),pCe=U('
      '),gCe=U(''),mCe=U(''),vCe=U('
      '),yCe=U('
      '),bCe=U('
      '),xCe=U('
      ',1),_Ce=U('
      '),wCe=U('
      '),ECe=U(''),ACe=U('
      ',1);function kCe(e,t){En(t,!0);let n=oe(t,"project",3,null),r=oe(t,"selectedRuns",19,()=>[]),i=oe(t,"allRuns",19,()=>[]),s=oe(t,"tableTruncateLength",3,250),o=we(()=>n0(i().length?i():r()));function a(Z){return y(o)[Z._runId]??y(o)[Z._run]??"#9ca3af"}const l=48,u={images:[],videos:[],audios:[],tables:[]};let c=se(mt(u)),f=se("newest"),d=se(mt(g())),h=se(null),p=se(!1);function g(){return{images:l,videos:l,audios:l,tables:l}}function m(){D(d,g(),!0)}function v(Z,he){const He=Number.isFinite(Z.step)?Z.step:0,Ke=Number.isFinite(he.step)?he.step:0,de=y(f)==="newest"?Ke-He:He-Ke;if(de!==0)return de;const Re=Number.isFinite(Z._index)?Z._index:0,Q=Number.isFinite(he._index)?he._index:0;return y(f)==="newest"?Q-Re:Re-Q}function b(Z){return[...Z].sort(v)}function x(Z){return Array.isArray(Z._value)&&Z._value.length>0}let _=we(()=>({images:b(y(c).images),videos:b(y(c).videos),audios:b(y(c).audios),tables:b(y(c).tables.filter(x))})),w=we(()=>({images:y(_).images.slice(0,y(d).images),videos:y(_).videos.slice(0,y(d).videos),audios:y(_).audios.slice(0,y(d).audios),tables:y(_).tables.slice(0,y(d).tables)})),A=we(()=>y(_).images.length>0||y(_).videos.length>0||y(_).audios.length>0||y(_).tables.length>0);function E(Z){y(d)[Z]+=l}Bt(()=>{y(f),y(c),m()});async function k(){if(!n()||r().length===0){D(c,u,!0);return}D(p,!0);try{const Z=r(),he=[];for(const L of Z){const H=await aW(n(),L);H&&he.push(...H.map(ve=>({...ve,_run:L.name,_runId:L.id??L.name})))}const He=he,Ke=[],de=[],Re=[],Q=[];let W=0;He&&He.forEach((L,H)=>{Object.entries(L).forEach(([ve,G])=>{if(G&&typeof G=="object"&&G._type){const B={key:ve,step:L.step??H,_index:W++,_run:L._run,_runId:L._runId,...G};switch(G._type){case"trackio.image":Ke.push(B);break;case"trackio.video":de.push(B);break;case"trackio.audio":Re.push(B);break;case"trackio.table":Q.push(B);break}}})}),D(c,{images:Ke,videos:de,audios:Re,tables:Q},!0)}catch(Z){console.error("Failed to load media:",Z)}finally{D(p,!1)}}Bt(()=>{n(),r(),k()});function S(Z){return Z._resolvedUrl?Z._resolvedUrl:Z.file_path?cW(Z.file_path):""}function $(Z){return Z&&typeof Z=="object"&&!Array.isArray(Z)&&Z._type==="trackio.image"}function M(Z){return Array.isArray(Z)&&Z.length>0&&Z.every(he=>he&&typeof he=="object"&&he._type==="trackio.image")}function O(Z){var he;(he=Z.currentTarget.parentElement)==null||he.classList.add("image-loaded")}function P(Z){var he;(he=Z.currentTarget.parentElement)==null||he.classList.add("image-failed")}function T(Z,he=null){D(h,{...Z,key:Z.key??(he==null?void 0:he.key),step:Z.step??(he==null?void 0:he.step),_run:Z._run??(he==null?void 0:he._run),_runId:Z._runId??(he==null?void 0:he._runId),caption:Z.caption??(he==null?void 0:he.caption)},!0)}function F(){D(h,null)}function R(Z){Z.key==="Escape"&&F()}var z=ACe();fn("keydown",$d,R);var j=Ot(z),q=C(j);{var te=Z=>{Bu(Z,{})},Y=Z=>{var he=Q3e(),He=C(he);{var Ke=Q=>{var W=K3e();I(Q,W)},de=Q=>{var W=Z3e(),L=N(Ot(W),4),H=C(L);H.textContent=`import trackio +trackio.init(project="my-project") +trackio.log({"loss": 0.5}) +trackio.finish()`,I(Q,W)},Re=Q=>{var W=J3e(),L=N(Ot(W),4),H=C(L);H.textContent=`import trackio + +trackio.init(project="my-project") +trackio.log({"plot": trackio.Image("figure.png")}) +trackio.log({"clip": trackio.Video("output.mp4")}) +trackio.log({"audio": trackio.Audio("speech.wav")}) + +import pandas as pd +df = pd.DataFrame({"epoch": [0, 1], "acc": [0.9, 0.95]}) +trackio.log({"samples": trackio.Table(dataframe=df)})`,I(Q,W)};ge(He,Q=>{n()?r().length===0?Q(de,1):Q(Re,-1):Q(Ke)})}I(Z,he)},ee=Z=>{const he=(V,J=LT)=>{var ye=eCe(),X=C(ye);let ke;var Fe=N(X,2),Ie=C(Fe);xe(ft=>{ke=ll(X,"",ke,ft),be(Ie,`Run: ${J()._run??""}, Step: ${J().step??""}`)},[()=>({background:a(J())})]),I(V,ye)};var He=xCe(),Ke=Ot(He),de=C(Ke),Re=N(C(de),2),Q=C(Re);Q.value=Q.__value="newest";var W=N(Q);W.value=W.__value="oldest";var L=N(Ke,2);{var H=V=>{var J=iCe(),ye=C(J),X=N(C(ye),2),ke=C(X),Fe=N(ye,2);wt(Fe,21,()=>y(w).images,At,(Oe,Me)=>{var Ge=nCe(),lt=C(Ge),yt=C(lt),Et=N(lt,2),ct=N(C(Et),2),Ut=N(Et,2);{var me=Ye=>{var ht=tCe(),Ve=C(ht);xe(()=>be(Ve,y(Me).caption)),I(Ye,ht)};ge(Ut,Ye=>{y(Me).caption&&Ye(me)})}var Ee=N(Ut,2);he(Ee,()=>y(Me)),xe(Ye=>{be(yt,y(Me).key),xt(Et,"aria-label",`Open ${y(Me).caption||y(Me).key}`),xt(ct,"src",Ye),xt(ct,"alt",y(Me).caption||y(Me).key)},[()=>S(y(Me))]),Ue("click",Et,()=>T(y(Me))),fn("load",ct,O),fn("error",ct,P),I(Oe,Ge)});var Ie=N(Fe,2);{var ft=Oe=>{var Me=rCe(),Ge=C(Me),lt=C(Ge),yt=N(Ge,2);xe(()=>be(lt,`Showing ${y(w).images.length??""} of ${y(_).images.length??""}`)),Ue("click",yt,()=>E("images")),I(Oe,Me)};ge(Ie,Oe=>{y(d).imagesbe(ke,`Images (${y(_).images.length??""})`)),I(V,J)};ge(L,V=>{y(_).images.length>0&&V(H)})}var ve=N(L,2);{var G=V=>{var J=aCe(),ye=C(J),X=N(C(ye),2),ke=C(X),Fe=N(ye,2);wt(Fe,21,()=>y(w).videos,At,(Oe,Me)=>{var Ge=sCe(),lt=C(Ge),yt=C(lt),Et=N(lt,2),ct=N(Et,2);he(ct,()=>y(Me)),xe(Ut=>{be(yt,y(Me).key),xt(Et,"src",Ut)},[()=>S(y(Me))]),I(Oe,Ge)});var Ie=N(Fe,2);{var ft=Oe=>{var Me=oCe(),Ge=C(Me),lt=C(Ge),yt=N(Ge,2);xe(()=>be(lt,`Showing ${y(w).videos.length??""} of ${y(_).videos.length??""}`)),Ue("click",yt,()=>E("videos")),I(Oe,Me)};ge(Ie,Oe=>{y(d).videosbe(ke,`Videos (${y(_).videos.length??""})`)),I(V,J)};ge(ve,V=>{y(_).videos.length>0&&V(G)})}var B=N(ve,2);{var ie=V=>{var J=cCe(),ye=C(J),X=N(C(ye),2),ke=C(X),Fe=N(ye,2);wt(Fe,21,()=>y(w).audios,At,(Oe,Me)=>{var Ge=lCe(),lt=C(Ge),yt=C(lt),Et=N(lt,2);{let Ut=we(()=>S(y(Me)));X3e(Et,{get src(){return y(Ut)}})}var ct=N(Et,2);he(ct,()=>y(Me)),xe(()=>be(yt,y(Me).key)),I(Oe,Ge)});var Ie=N(Fe,2);{var ft=Oe=>{var Me=uCe(),Ge=C(Me),lt=C(Ge),yt=N(Ge,2);xe(()=>be(lt,`Showing ${y(w).audios.length??""} of ${y(_).audios.length??""}`)),Ue("click",yt,()=>E("audios")),I(Oe,Me)};ge(Ie,Oe=>{y(d).audiosbe(ke,`Audio (${y(_).audios.length??""})`)),I(V,J)};ge(B,V=>{y(_).audios.length>0&&V(ie)})}var qe=N(B,2);{var K=V=>{var J=bCe(),ye=C(J),X=N(C(ye),2),ke=C(X),Fe=N(ye,2);wt(Fe,17,()=>y(w).tables,At,(Oe,Me)=>{var Ge=vCe(),lt=C(Ge),yt=C(lt),Et=C(yt),ct=N(yt,2);he(ct,()=>y(Me));var Ut=N(lt,2),me=C(Ut),Ee=C(me);wt(Ee,21,()=>Object.keys(y(Me)._value[0]),At,(ht,Ve)=>{var Xe=fCe(),dt=C(Xe);xe(()=>be(dt,y(Ve))),I(ht,Xe)});var Ye=N(me);wt(Ye,21,()=>y(Me)._value,At,(ht,Ve)=>{var Xe=mCe();wt(Xe,21,()=>Object.values(y(Ve)),At,(dt,pt)=>{var Ct=gCe(),le=C(Ct);{var pe=Xt=>{var sn=dCe(),ot=N(C(sn),2);xe(Pt=>{xt(ot,"src",Pt),xt(ot,"alt",y(pt).caption||"")},[()=>S(y(pt))]),Ue("click",sn,()=>T(y(pt),y(Me))),fn("load",ot,O),fn("error",ot,P),I(Xt,sn)},et=we(()=>$(y(pt))),Ze=Xt=>{var sn=pCe();wt(sn,21,()=>y(pt),At,(ot,Pt)=>{var Rt=hCe(),bt=N(C(Rt),2);xe(Or=>{xt(bt,"src",Or),xt(bt,"alt",y(Pt).caption||"")},[()=>S(y(Pt))]),Ue("click",Rt,()=>T(y(Pt),y(Me))),fn("load",bt,O),fn("error",bt,P),I(ot,Rt)}),I(Xt,sn)},nt=we(()=>M(y(pt))),Be=Xt=>{var sn=hw();xe(ot=>be(sn,ot),[()=>typeof y(pt)=="string"&&y(pt).length>s()?y(pt).slice(0,s())+"…":y(pt)??""]),I(Xt,sn)};ge(le,Xt=>{y(et)?Xt(pe):y(nt)?Xt(Ze,1):Xt(Be,-1)})}I(dt,Ct)}),I(ht,Xe)}),xe(()=>be(Et,y(Me).key)),I(Oe,Ge)});var Ie=N(Fe,2);{var ft=Oe=>{var Me=yCe(),Ge=C(Me),lt=C(Ge),yt=N(Ge,2);xe(()=>be(lt,`Showing ${y(w).tables.length??""} of ${y(_).tables.length??""}`)),Ue("click",yt,()=>E("tables")),I(Oe,Me)};ge(Ie,Oe=>{y(d).tablesbe(ke,`Tables (${y(_).tables.length??""})`)),I(V,J)};ge(qe,V=>{y(_).tables.length>0&&V(K)})}L1(Re,()=>y(f),V=>D(f,V)),I(Z,He)};ge(q,Z=>{y(p)?Z(te):y(A)?Z(ee,-1):Z(Y,1)})}var _e=N(j,2);{var Le=Z=>{var he=ECe(),He=C(he),Ke=C(He),de=N(Ke,2),Re=N(C(de),2),Q=N(de,2),W=C(Q);{var L=V=>{var J=_Ce(),ye=C(J);xe(()=>be(ye,y(h).key)),I(V,J)};ge(W,V=>{y(h).key&&V(L)})}var H=N(W,2);{var ve=V=>{var J=wCe(),ye=C(J);xe(()=>be(ye,y(h).caption)),I(V,J)};ge(H,V=>{y(h).caption&&V(ve)})}var G=N(H,2),B=C(G);let ie;var qe=N(B,2),K=C(qe);xe((V,J)=>{xt(Re,"src",V),xt(Re,"alt",y(h).caption||y(h).key||"Image preview"),ie=ll(B,"",ie,J),be(K,`Run: ${y(h)._run??""}, Step: ${y(h).step??""}`)},[()=>S(y(h)),()=>({background:a(y(h))})]),Ue("click",he,F),Ue("click",He,V=>V.stopPropagation()),Ue("keydown",He,V=>V.stopPropagation()),Ue("click",Ke,F),fn("load",Re,O),fn("error",Re,P),I(Z,he)};ge(_e,Z=>{y(h)&&Z(Le)})}I(e,z),An()}ni(["click","keydown"]);var SCe=U(`

      No alerts or reports yet

      Alerts are recorded when your training script calls trackio.alert(). + Reports are logged as Markdown via trackio.log().

      `),CCe=U('
      '),$Ce=U('

      '),FCe=U('

      No alerts for this level.

      '),DCe=U(' '),MCe=U(' '),TCe=U(''),RCe=U('
      '),NCe=U('

      '),OCe=U(" ",1),LCe=U('
      ');function ICe(e,t){En(t,!0);let n=oe(t,"project",3,null),r=oe(t,"selectedRuns",19,()=>[]),i=se(mt([])),s=se(mt([])),o=se(null),a=se(!1);const l={info:"🔵",warn:"🟡",error:"🔴"};function u(_){if(!_)return"";let w=_.replace(/&/g,"&").replace(//g,">");return w=w.replace(/^### (.+)$/gm,"

      $1

      "),w=w.replace(/^## (.+)$/gm,"

      $1

      "),w=w.replace(/^# (.+)$/gm,"

      $1

      "),w=w.replace(/\*\*(.+?)\*\*/g,"$1"),w=w.replace(/`([^`]+)`/g,"$1"),w=w.replace(/^- (.+)$/gm,"
    • $1
    • "),w=w.replace(/(
    • .*<\/li>\n?)+/gs,A=>`
        ${A}
      `),w=w.replace(/\n{2,}/g,"

      "),w=`

      ${w}

      `,w=w.replace(/

      \s*()/g,"$1"),w=w.replace(/(<\/h[234]>)\s*<\/p>/g,"$1"),w=w.replace(/

      \s*(

        )/g,"$1"),w=w.replace(/(<\/ul>)\s*<\/p>/g,"$1"),w=w.replace(/

        \s*<\/p>/g,""),w}let c=we(()=>y(o)?y(i).filter(_=>_.level===y(o)):y(i));async function f(){if(!n()){D(i,[],!0),D(s,[],!0);return}D(a,!0);try{const _=await uW(n(),null,null,null),w=new Set(r().map(k=>k.name));D(i,(_||[]).filter(k=>!k.run||w.has(k.run)),!0);const A=r(),E=[];for(const k of A)try{const S=await aW(n(),k);if(S)for(const $ of S)for(const[M,O]of Object.entries($))O&&typeof O=="object"&&O._type==="trackio.markdown"&&E.push({key:M,run:k.name,step:$.step,content:O._value||""})}catch{}D(s,E,!0)}catch(_){console.error("Failed to load alerts:",_),D(i,[],!0)}finally{D(a,!1)}}Bt(()=>{n(),r(),f()});function d(_){if(!_)return"";try{return new Date(_).toLocaleString()}catch{return _}}let h=["Level","Run","Title","Text","Step","Time"],p=we(()=>y(c).map(_=>[`${l[_.level]||""} ${_.level}`,_.run||"",_.title,_.text||"",_.step??"",d(_.timestamp)]));var g=LCe(),m=C(g);{var v=_=>{Bu(_,{})},b=_=>{var w=SCe(),A=N(C(w),4),E=C(A);E.textContent=`import trackio +from trackio import AlertLevel + +trackio.init(project="my-project") +trackio.alert("Low validation loss", text="Consider saving a checkpoint.", level=AlertLevel.INFO) +trackio.log({"reports/summary": trackio.Markdown("# My Report\\nResults look good.")})`,I(_,w)},x=_=>{var w=OCe(),A=Ot(w);{var E=$=>{var M=$Ce(),O=C(M),P=C(O),T=N(O,2);wt(T,17,()=>y(s),At,(F,R)=>{var z=CCe(),j=C(z),q=C(j),te=N(j,2);KH(te,()=>u(y(R).content),!0),xe(()=>be(q,`${y(R).key??""} · ${y(R).run??""} · step ${y(R).step??""}`)),I(F,z)}),xe(()=>be(P,`Reports (${y(s).length??""})`)),I($,M)};ge(A,$=>{y(s).length>0&&$(E)})}var k=N(A,2);{var S=$=>{var M=NCe(),O=C(M),P=C(O),T=N(O,2),F=C(T),R=C(F),z=C(R);let j;var q=N(z,2);let te;var Y=N(q,2);let ee;var _e=N(Y,2);let Le;var Z=N(T,2);{var he=Ke=>{var de=FCe();I(Ke,de)},He=Ke=>{var de=RCe(),Re=C(de),Q=C(Re);wt(Q,21,()=>h,At,(L,H)=>{var ve=DCe(),G=C(ve);xe(()=>be(G,y(H))),I(L,ve)});var W=N(Re);wt(W,21,()=>y(p),At,(L,H)=>{var ve=TCe();wt(ve,21,()=>y(H),At,(G,B)=>{var ie=MCe(),qe=C(ie);xe(()=>be(qe,y(B))),I(G,ie)}),I(L,ve)}),I(Ke,de)};ge(Z,Ke=>{y(c).length===0?Ke(he):Ke(He,-1)})}xe(()=>{be(P,`Alerts (${y(i).length??""})`),j=en(z,1,"pill svelte-iufsej",null,j,{active:y(o)===null}),te=en(q,1,"pill svelte-iufsej",null,te,{active:y(o)==="info"}),ee=en(Y,1,"pill svelte-iufsej",null,ee,{active:y(o)==="warn"}),Le=en(_e,1,"pill svelte-iufsej",null,Le,{active:y(o)==="error"})}),Ue("click",z,()=>D(o,null)),Ue("click",q,()=>D(o,"info")),Ue("click",Y,()=>D(o,"warn")),Ue("click",_e,()=>D(o,"error")),I($,M)};ge(k,$=>{y(i).length>0&&$(S)})}I(_,w)};ge(m,_=>{y(a)?_(v):y(i).length===0&&y(s).length===0?_(b,1):_(x,-1)})}I(e,g),An()}ni(["click"]);var PCe=U('

        No runs in this project

        Runs are created when you call trackio.init() and log at least one step. Example:

        Refresh this page or wait for the dashboard to poll; new runs appear in the table with step counts.

        '),BCe=U('
        '),zCe=U(''),jCe=U('
        '),UCe=U('
        '),qCe=U('
        ActionsRun NameStepsLast Step
        ',1),WCe=U('
        ');function HCe(e,t){En(t,!0);let n=oe(t,"project",3,null),r=oe(t,"runs",19,()=>[]),i=oe(t,"filterText",3,""),s=oe(t,"onRunsChanged",3,null),o=oe(t,"runMutationAllowed",3,!0),a=we(o),l=we(()=>n0(r())),u=se(mt([])),c=se(!1),f=se(-1),d=se(""),h=se(null),p=we(()=>{if(!i()||!i().trim())return y(u);const S=new Set(lk(y(u).map($=>$.name),i()));return y(u).filter($=>S.has($.name))});async function g(){if(!n()){D(u,[],!0);return}D(c,!0);try{const $=(await ZSe(n())).runs||[],O=(await Promise.all($.map(P=>lW(n(),P)))).map((P,T)=>({id:$[T].id??$[T].name,name:$[T].name,numSteps:P.num_logs||0,lastStep:P.last_step||0}));D(u,O,!0)}catch(S){console.error("Failed to load runs:",S)}finally{D(c,!1)}}Bt(()=>{n(),g()});async function m(S){if(y(a)&&confirm(`Delete run "${S.name}"? This cannot be undone.`))try{await r3e(n(),S),await g(),s()&&s()()}catch($){console.error("Failed to delete run:",$)}}async function v(S,$){var M,O;y(a)&&(D(f,S,!0),D(d,$,!0),await ts(),(M=y(h))==null||M.focus(),(O=y(h))==null||O.select())}async function b(S){if(!y(a))return;const $=y(d).trim();if(!$||$===S.name){D(f,-1);return}try{await i3e(n(),S,$),D(f,-1),await g(),s()&&s()()}catch(M){console.error("Failed to rename run:",M)}}function x(S,$){S.key==="Enter"&&b($),S.key==="Escape"&&D(f,-1)}var _=WCe(),w=C(_);{var A=S=>{Bu(S,{})},E=S=>{var $=PCe(),M=N(C($),4),O=C(M);O.textContent=`import trackio +trackio.init(project="my-project") +for i in range(10): + trackio.log({"loss": 1 / (i + 1)}) +trackio.finish()`,I(S,$)},k=S=>{var $=qCe(),M=Ot($);{var O=F=>{var R=BCe(),z=C(R),j=C(z);xe(()=>be(j,`${y(p).length??""} of ${y(u).length??""} runs`)),I(F,R)};ge(M,F=>{i()&&F(O)})}var P=N(M,2),T=N(C(P));wt(T,21,()=>y(p),At,(F,R,z)=>{var j=UCe(),q=C(j),te=C(q),Y=C(te),ee=N(Y,2),_e=N(q),Le=C(_e);{var Z=Q=>{var W=zCe();rs(W,L=>D(h,L),()=>y(h)),Ue("keydown",W,L=>x(L,y(R))),fn("blur",W,()=>b(y(R))),t0(W,()=>y(d),L=>D(d,L)),I(Q,W)},he=Q=>{var W=jCe(),L=C(W);let H;var ve=N(L,2),G=C(ve);xe(()=>{H=ll(L,"",H,{background:y(l)[y(R).id]??"#9ca3af"}),be(G,y(R).name)}),Ue("click",ve,()=>{y5("selected_run_id",y(R).id),y5("selected_run",y(R).name),vw("run-detail")}),I(Q,W)};ge(Le,Q=>{y(f)===z?Q(Z):Q(he,-1)})}var He=N(_e),Ke=C(He),de=N(He),Re=C(de);xe(()=>{xt(Y,"title",y(a)?"Rename":"Sign in with Hugging Face (write access) to rename runs"),Y.disabled=!y(a),xt(ee,"title",y(a)?"Delete":"Sign in with Hugging Face (write access) to delete runs"),ee.disabled=!y(a),be(Ke,y(R).numSteps),be(Re,y(R).lastStep)}),Ue("click",Y,()=>v(z,y(R).name)),Ue("click",ee,()=>m(y(R))),I(F,j)}),I(S,$)};ge(w,S=>{y(c)?S(A):y(u).length===0?S(E,1):S(k,-1)})}I(e,_),An()}ni(["click","keydown"]);var GCe=U(`

        Open a run

        Choose a run from the Runs page or follow a run name from the sidebar. This view shows the + project name, log count, last step, metric keys, and any logged config.

        Config passed to trackio.init() appears under Configuration when present.

        `),YCe=U('

        Configuration

         
        ',1),VCe=U('

        Project
        Total Logs
        Last Step
        Metrics
        '),XCe=U('
        ');function KCe(e,t){En(t,!0);let n=oe(t,"project",3,null),r=se(null),i=se(null),s=se(null),o=se(!1);Bt(()=>{D(i,$i("selected_run_id"),!0),D(r,$i("selected_run"),!0)});async function a(){if(!n()||!y(r)&&!y(i)){D(s,null);return}D(o,!0);try{const h=await lW(n(),y(i)?{id:y(i),name:y(r)}:y(r));D(s,h,!0),h!=null&&h.run&&D(r,h.run,!0)}catch(h){console.error("Failed to load run detail:",h)}finally{D(o,!1)}}Bt(()=>{n(),y(r),y(i),a()});var l=XCe(),u=C(l);{var c=h=>{Bu(h,{})},f=h=>{var p=GCe(),g=N(C(p),4),m=C(g);m.textContent=`import trackio +trackio.init(project="my-project", config={"lr": 1e-3}) +trackio.log({"loss": 0.5}) +trackio.finish()`,I(h,p)},d=h=>{var p=VCe(),g=C(p),m=C(g),v=N(g,2),b=C(v),x=N(C(b),2),_=C(x),w=N(b,2),A=N(C(w),2),E=C(A),k=N(w,2),S=N(C(k),2),$=C(S),M=N(k,2),O=N(C(M),2),P=C(O),T=N(v,2);{var F=R=>{var z=YCe(),j=N(Ot(z),2),q=C(j);xe(te=>be(q,te),[()=>JSON.stringify(y(s).config,null,2)]),I(R,z)};ge(T,R=>{y(s).config&&R(F)})}xe(R=>{be(m,y(s).run),be(_,y(s).project),be(E,y(s).num_logs),be($,y(s).last_step??"N/A"),be(P,R)},[()=>y(s).metrics?y(s).metrics.join(", "):"None"]),I(h,p)};ge(u,h=>{y(o)?h(c):y(s)?h(d,-1):h(f,1)})}I(e,l),An()}var ZCe=U('

        No project files yet

        Files are stored at the project level (not tied to a single run). After trackio.init(), copy artifacts into the project with trackio.save():

        Paths can be a single file or a glob. Saved files will list here for download.

        '),JCe=U(' '),QCe=U('
        Loading preview...
        '),e$e=U('
         
        '),t$e=U('
        Preview not available. Download the file instead.
        '),n$e=U('
        '),r$e=U('
        '),i$e=U('

        Files

        Showing files saved across all runs in this project.

        ',1),s$e=U('
        ');function o$e(e,t){En(t,!0);let n=oe(t,"project",3,null),r=se(mt([])),i=se(!1),s=se(null),o=se(null),a=se(!1);const l=new Set(["txt","md","json","yml","yaml","toml","ini","cfg","csv","tsv","xml","html","css","js","py","sh","log","conf","env","gitignore","dockerfile"]);function u(b){const x=b.split(".").pop().toLowerCase();return l.has(x)}function c(b){return b==null?"":b<1024?`${b} B`:b<1024*1024?`${(b/1024).toFixed(1)} KB`:`${(b/(1024*1024)).toFixed(1)} MB`}async function f(b){if(y(s)===b.name){D(s,null),D(o,null);return}if(D(s,b.name,!0),!u(b.name)){D(o,null);return}D(a,!0);try{const x=Z_(b.path),_=await fetch(x);if(!_.ok)throw new Error("fetch failed");const w=await _.text();D(o,w.length>5e4?w.slice(0,5e4)+` + +… (truncated)`:w,!0)}catch{D(o,null)}finally{D(a,!1)}}async function d(){if(!n()){D(r,[],!0);return}D(i,!0);try{D(r,await e3e(n()),!0)}catch{D(r,[],!0)}finally{D(i,!1)}}Bt(()=>{n(),d()});var h=s$e(),p=C(h);{var g=b=>{Bu(b,{})},m=b=>{var x=ZCe(),_=N(C(x),4),w=C(_);w.textContent=`import trackio + +trackio.init(project="my-project") +trackio.save("config.yaml") +trackio.save("checkpoints/*.pt")`,I(b,x)},v=b=>{var x=i$e(),_=N(Ot(x),4);wt(_,21,()=>y(r),At,(w,A)=>{var E=r$e();let k;var S=C(E),$=C(S),M=C($),O=C(M),P=N(M),T=N($,2),F=C(T);{var R=te=>{var Y=JCe(),ee=C(Y);xe(_e=>be(ee,_e),[()=>c(y(A).size)]),I(te,Y)};ge(F,te=>{y(A).size!=null&&te(R)})}var z=N(F,2),j=N(S,2);{var q=te=>{var Y=n$e(),ee=C(Y);{var _e=he=>{var He=QCe();I(he,He)},Le=he=>{var He=e$e(),Ke=C(He);xe(()=>be(Ke,y(o))),I(he,He)},Z=he=>{var He=t$e(),Ke=N(C(He));xe(de=>xt(Ke,"href",de),[()=>Z_(y(A).path)]),I(he,He)};ge(ee,he=>{y(a)?he(_e):y(o)!=null?he(Le,1):he(Z,-1)})}I(te,Y)};ge(j,te=>{y(s)===y(A).name&&te(q)})}xe((te,Y)=>{k=en(E,1,"file-item svelte-1xvfk9n",null,k,{expanded:y(s)===y(A).name}),be(O,te),be(P,` ${y(A).name??""}`),xt(z,"href",Y)},[()=>u(y(A).name)?"📄":"📦",()=>Z_(y(A).path)]),Ue("click",$,()=>f(y(A))),I(w,E)}),I(b,x)};ge(p,b=>{y(i)?b(g):y(r).length===0?b(m,1):b(v,-1)})}I(e,h),An()}ni(["click"]);var a$e=_i(''),l$e=_i(''),u$e=_i(''),c$e=U(""),f$e=U('Connected to — remote commands include --space automatically.',1),d$e=U(""),h$e=U('
        '),p$e=_i(''),g$e=_i(''),m$e=U('
        '),v$e=U(""),y$e=_i(''),b$e=_i(''),x$e=_i(''),_$e=_i(''),w$e=U('

        Settings

        Appearance

        Choose how the dashboard looks to you.

        CLI Reference

        Common Trackio CLI commands.

        Agent Skills

        Install Trackio as a skill in your AI coding agent to query experiments with natural language.

        Run in Terminal to Install:
        Example prompt

        ');function E$e(e,t){En(t,!0);let n=oe(t,"spaceId",3,null),r=oe(t,"selectedProject",3,null),i=oe(t,"projects",19,()=>[]),s=se(mt(IF())),o=se(null),a=se(null),l=se("claude"),u=se(!1),c=se(!1);const f=[{id:"claude",label:"Claude Code",flag:"--claude"},{id:"codex",label:"Codex",flag:"--codex"},{id:"cursor",label:"Cursor",flag:"--cursor"},{id:"opencode",label:"OpenCode",flag:"--opencode"}];let d=we(()=>{var B;return`trackio skills add ${(B=f.find(ie=>ie.id===y(l)))==null?void 0:B.flag}`}),h=we(()=>{const B=y(a)||"";return{claude:`Use the trackio skill to look at the runs in project "${B}" and find at which step the loss started diverging. Summarize what happened.`,codex:`Use the trackio skill to pull the latest metrics for project "${B}" and tell me which run has the best final eval accuracy.`,cursor:`Use the trackio skill to compare the last two runs in project "${B}" and explain why the learning rate change affected convergence.`,opencode:`Use the trackio skill to get a summary of project "${B}" and flag any runs where the loss spiked unexpectedly.`}[y(l)]});Bt(()=>{if(i(),r(),!(y(a)&&i().includes(y(a)))){if(r()&&i().includes(r())){D(a,r());return}D(a,i()[0]??r()??null,!0)}});function p(B){D(s,B,!0),cke(B)}function g(){return n()?` --space ${n()}`:""}let m=we(()=>{const B=g(),ie=y(a)||"";return[{title:"Launch dashboard",cmd:"trackio show"},{title:"Launch dashboard (project)",cmd:`trackio show --project "${ie}"`},{title:"List projects",cmd:`trackio${B} list projects`},{title:"List runs",cmd:`trackio${B} list runs --project "${ie}"`},{title:"List metrics",cmd:`trackio${B} list metrics --project "${ie}" --run `},{title:"Project summary",cmd:`trackio${B} get project --project "${ie}"`},{title:"Run summary",cmd:`trackio${B} get run --project "${ie}" --run `},{title:"Sync to HF Space",cmd:`trackio sync${B} --project "${ie}"`},{title:"Check sync status",cmd:"trackio status"}]});async function v(B,ie){try{await navigator.clipboard.writeText(B),D(o,ie,!0),setTimeout(()=>{y(o)===ie&&D(o,null)},1500)}catch{}}async function b(B,ie){try{await navigator.clipboard.writeText(B),ie==="agent"?(D(u,!0),setTimeout(()=>{D(u,!1)},1500)):(D(c,!0),setTimeout(()=>{D(c,!1)},1500))}catch{}}var x=w$e(),_=N(C(x),2),w=C(_),A=C(w),E=N(C(A),4);wt(E,20,()=>[{value:"system",label:"System"},{value:"light",label:"Light"},{value:"dark",label:"Dark"}],At,(B,ie)=>{var qe=c$e();let K;var V=C(qe);{var J=Fe=>{var Ie=a$e();I(Fe,Ie)},ye=Fe=>{var Ie=l$e();I(Fe,Ie)},X=Fe=>{var Ie=u$e();I(Fe,Ie)};ge(V,Fe=>{ie.value==="system"?Fe(J):ie.value==="light"?Fe(ye,1):Fe(X,-1)})}var ke=N(V);xe(()=>{K=en(qe,1,"theme-option svelte-1ozf5k3",null,K,{selected:y(s)===ie.value}),be(ke,` ${ie.label??""}`)}),Ue("click",qe,()=>p(ie.value)),I(B,qe)});var k=N(A,2),S=N(C(k),2),$=N(C(S));{var M=B=>{var ie=f$e(),qe=N(Ot(ie)),K=C(qe);xe(()=>be(K,n())),I(B,ie)};ge($,B=>{n()&&B(M)})}var O=N(S,2);{var P=B=>{var ie=h$e(),qe=N(C(ie),2);wt(qe,21,i,At,(K,V)=>{var J=d$e(),ye=C(J),X={};xe(()=>{be(ye,y(V)),X!==(X=y(V))&&(J.value=(J.__value=y(V))??"")}),I(K,J)}),L1(qe,()=>y(a),K=>D(a,K)),I(B,ie)};ge(O,B=>{i().length>0&&B(P)})}var T=N(O,2);wt(T,21,()=>y(m),At,(B,ie,qe)=>{var K=m$e(),V=C(K),J=C(V),ye=N(V,2),X=C(ye),ke=C(X),Fe=N(X,2);let Ie;var ft=C(Fe);{var Oe=Ge=>{var lt=p$e();I(Ge,lt)},Me=Ge=>{var lt=g$e();I(Ge,lt)};ge(ft,Ge=>{y(o)===qe?Ge(Oe):Ge(Me,-1)})}xe(()=>{be(J,y(ie).title),be(ke,y(ie).cmd),Ie=en(Fe,1,"copy-btn svelte-1ozf5k3",null,Ie,{copied:y(o)===qe})}),Ue("click",Fe,()=>v(y(ie).cmd,qe)),I(B,K)});var F=N(w,2),R=C(F),z=N(C(R),4);wt(z,21,()=>f,At,(B,ie)=>{var qe=v$e();let K;var V=C(qe);xe(()=>{K=en(qe,1,"agent-tab svelte-1ozf5k3",null,K,{active:y(l)===y(ie).id}),be(V,y(ie).label)}),Ue("click",qe,()=>{D(l,y(ie).id,!0)}),I(B,qe)});var j=N(z,2),q=C(j),te=N(C(q),2),Y=C(te),ee=C(Y),_e=N(Y,2);let Le;var Z=C(_e);{var he=B=>{var ie=y$e();I(B,ie)},He=B=>{var ie=b$e();I(B,ie)};ge(Z,B=>{y(u)?B(he):B(He,-1)})}var Ke=N(q,2),de=C(Ke),Re=N(C(de),2);let Q;var W=C(Re);{var L=B=>{var ie=x$e();I(B,ie)},H=B=>{var ie=_$e();I(B,ie)};ge(W,B=>{y(c)?B(L):B(H,-1)})}var ve=N(de,2),G=C(ve);xe(()=>{be(ee,y(d)),Le=en(_e,1,"copy-btn svelte-1ozf5k3",null,Le,{copied:y(u)}),Q=en(Re,1,"copy-btn svelte-1ozf5k3",null,Q,{copied:y(c)}),be(G,y(h))}),Ue("click",_e,()=>b(y(d),"agent")),Ue("click",Re,()=>b(y(h),"example")),I(e,x),An()}ni(["click"]);var A$e=U('
        ');function k$e(e,t){En(t,!0);function n(le){if(!le)return"";const pe=le.trim(),et=pe.split(",").map(nt=>nt.trim()).filter(Boolean);if(et.length===0)return"";const Ze=nt=>/^[\w./-]+$/.test(nt);return et.every(Ze)?et.map(nt=>`^${nt.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}$`).join("|"):pe}fke();let r=se(mt(OF()));lke(le=>{D(r,le,!0)});let i=se("metrics"),s=se(mt([])),o=se(null),a=se(mt([])),l=se(mt([])),u=se(10),c=se("step"),f=se(!1),d=se(!1),h=se(""),p=se(!0),g=se(!0),m=se(""),v=se(mt([])),b=se(!0),x=se(!1),_=se(!1),w=se(0),A=se(mt([])),E=se(null),k=se(mt({spaces:!1,allowed:!0,auth:"local"})),S=se(null),$=se(!1),M=se(mt({light:"/static/trackio/trackio_logo_type_light_transparent.png",dark:"/static/trackio/trackio_logo_type_dark_transparent.png"})),O=se(mt([])),P=se(250),T=se(null),F=se(null),R=se(mt([])),z=se(mt([])),j=se(mt({})),q=0,te=0,Y=!1,ee=!1;const _e=15e3,Le=new Set(["system","traces","media","reports","files"]),Z=["metrics","system","traces","media","reports","runs","files"];let he=se(mt({})),He=se(null);function Ke(le){return(le==null?void 0:le.id)??(le==null?void 0:le.name)}let de=we(()=>y(a).filter(le=>y(l).includes(Ke(le))));function Re(le){ee=!0,D(i,le,!0),vw(le)}function Q(){return(window.location.pathname.replace(/\/+$/,"")||"/")==="/"}function W(){return $i("project")||$i("selected_project")}function L(){const le=W();le&&y(s).includes(le)&&D(o,le,!0)}async function H(){try{const le=await HSe();if(D(s,le||[],!0),y(s).length>0&&!y(o)){const pe=W();D(o,pe&&y(s).includes(pe)?pe:y(s)[0],!0)}L()}catch(le){console.error("Failed to load projects:",le)}}async function ve(){await G(),await J()}async function G(){const le=y(o);if(!le){D(a,[],!0),D(l,[],!0),D(R,[],!0),D(z,[],!0),D(he,{},!0),D(He,null);return}le!==y(He)&&D(he,{},!0);try{const[pe,et]=await Promise.all([GSe(le),YSe(le).catch(()=>null)]);if(y(o)!==le)return;const Ze=[...pe||[]].reverse();if(JSON.stringify(y(a))!==JSON.stringify(Ze)){const nt=y(l),Be=y(a).map(Ke);D(a,Ze,!0),D(l,CG(nt,Ze.map(Ke),Be),!0)}et!=null&&(D(he,et,!0),D(He,le,!0))}catch(pe){console.error("Failed to load runs:",pe)}}async function B(){if(y(o))try{const le=await uW(y(o),null,null,null);D(A,(le||[]).slice(-20),!0)}catch{}}function ie(){return{metrics:!1,system:!1,traces:!1,media:!1,reports:!1,runs:!1,files:!1}}async function qe({force:le=!1}={}){const pe=Date.now();if(!le&&pe-te<_e)return;te=pe;const et=++q;if(!y(o)){D(j,ie(),!0);return}try{const Ze=await t3e(y(o));if(et!==q)return;const nt={...ie(),...Ze,runs:y(a).length>0};if(D(j,nt,!0),Y&&!ee&&Q()){const Be=Z.find(Xt=>nt[Xt]);Be&&Be!==y(i)&&(D(i,Be,!0),vw(Be)),ee=!0}}catch(Ze){if(et!==q)return;console.error("Failed to load tab availability:",Ze),D(j,ie(),!0)}}function K(){y(E)&&clearInterval(y(E)),D(E,setInterval(async()=>{y(p)&&(GF()||HF()||(await H(),await G(),await B(),await qe()))},USe()),!0)}function V(){const le=new URLSearchParams(window.location.search);let pe=!1;const et=le.get("write_token");et&&(document.cookie=`trackio_write_token=${encodeURIComponent(et)}; path=/; max-age=604800; SameSite=Lax`,le.delete("write_token"),pe=!0);const Ze=le.get("oauth_session");if(Ze&&(sessionStorage.setItem("trackio_oauth_session",Ze),le.delete("oauth_session"),pe=!0),pe){const nt=le.toString(),Be=window.location.pathname+(nt?`?${nt}`:"");window.history.replaceState({},"",Be)}}async function J(){try{const le=await n3e();D(k,{spaces:!!le.spaces,allowed:!!le.allowed,auth:le.auth??"none"},!0)}catch{D(k,{spaces:!1,allowed:!0,auth:"local"},!0)}}function ye(){y(S)&&clearInterval(y(S)),D(S,setInterval(()=>{J()},12e4),!0)}Bt(()=>{y(o),D(R,[],!0),D(z,[],!0),G()}),Bt(()=>{y(w),D(_,$i("navbar")==="hidden")}),hh(()=>{const le=$i("sidebar");le==="hidden"?(D(x,!0),D(b,!1)):le==="collapsed"?(D(x,!1),D(b,!1)):D(x,!1);const pe=$i("smoothing");if(pe){const nt=parseInt(pe,10);Number.isNaN(nt)||D(u,nt,!0)}const et=$i("metric_filter"),Ze=$i("metrics");return et?D(h,et,!0):Ze&&D(h,n(Ze),!0),$i("accordion")==="hidden"&&D(g,!1),Y=Q(),D(i,v5(),!0),window.addEventListener("popstate",()=>{D(i,v5(),!0),tR(w),L()}),V(),(async()=>{const nt=await Gn();nt?(D(p,!1),D(k,{spaces:!1,allowed:!1,auth:"static"},!0),D(T,await o3e(),!0)):(J(),ye(),window.addEventListener("focus",J));try{try{const Be=await QSe();Be&&(Be.logo_urls&&D(M,Be.logo_urls,!0),Be.color_palette&&SG(Be.color_palette),Be.plot_order&&D(O,Be.plot_order,!0),Be.table_truncate_length&&D(P,Be.table_truncate_length,!0),Be.media_dir&&s3e(Be.media_dir),Be.space_id&&D(F,Be.space_id,!0))}catch{}await H(),await G(),await B(),await qe({force:!0})}catch(Be){console.error("Failed to load projects:",Be)}finally{D($,!0)}nt||K()})(),()=>{y(E)&&clearInterval(y(E)),y(S)&&clearInterval(y(S)),window.removeEventListener("focus",J)}});let X=we(()=>{y(w);const le=W();return!!(le&&y(s).includes(le))});Bt(()=>{y(s),y(w),y(X)&&L()}),Bt(()=>{y(o),y(a),y($)&&qe({force:!0})});let ke=se(!1);Bt(()=>{if(y(ke)||!y($)||!y(o))return;const le=$i("run_ids"),pe=$i("runs");if(!le&&!pe){D(ke,!0);return}if(!y(a).length){D(ke,!0);return}let et;if(le){const Ze=le.split(",").map(Be=>Be.trim()).filter(Boolean),nt=new Set(y(a).map(Be=>Ke(Be)));et=Ze.filter(Be=>nt.has(Be))}else{const Ze=pe.split(",").map(Be=>Be.trim()).filter(Boolean),nt=new Set(Ze);et=y(a).filter(Be=>nt.has(Be.name)).map(Be=>Ke(Be))}et.length&&D(l,et,!0),D(ke,!0)});let Fe=we(()=>y(i)==="metrics"||y(i)==="traces"||y(i)==="system"||y(i)==="media"||y(i)==="reports"||y(i)==="runs"||y(i)==="run-detail"||y(i)==="files"),Ie=we(()=>y(i)==="runs"||y(i)==="files"?"compact":"full");var ft=A$e(),Oe=C(ft);{var Me=le=>{uY(le,{get variant(){return y(Ie)},get currentPage(){return y(i)},get spacesMode(){return y(k).spaces},get runMutationAllowed(){return y(k).allowed},get mutationAuth(){return y(k).auth},get readOnlySource(){return y(T)},get projects(){return y(s)},get projectLocked(){return y(X)},get runs(){return y(a)},get runConfigs(){return y(he)},get metricColumns(){return y(v)},get availableSystemDevices(){return y(R)},get spaceId(){return y(F)},get logoUrls(){return y(M)},get darkMode(){return y(r)},get open(){return y(b)},set open(pe){D(b,pe,!0)},get selectedProject(){return y(o)},set selectedProject(pe){D(o,pe,!0)},get selectedRuns(){return y(l)},set selectedRuns(pe){D(l,pe,!0)},get smoothing(){return y(u)},set smoothing(pe){D(u,pe,!0)},get xAxis(){return y(c)},set xAxis(pe){D(c,pe,!0)},get logScaleX(){return y(f)},set logScaleX(pe){D(f,pe,!0)},get logScaleY(){return y(d)},set logScaleY(pe){D(d,pe,!0)},get metricFilter(){return y(h)},set metricFilter(pe){D(h,pe,!0)},get realtimeEnabled(){return y(p)},set realtimeEnabled(pe){D(p,pe,!0)},get showHeaders(){return y(g)},set showHeaders(pe){D(g,pe,!0)},get filterText(){return y(m)},set filterText(pe){D(m,pe,!0)},get selectedSystemDevices(){return y(z)},set selectedSystemDevices(pe){D(z,pe,!0)}})};ge(Oe,le=>{y(Fe)&&!y(x)&&le(Me)})}var Ge=N(Oe,2),lt=C(Ge);{var yt=le=>{lG(le,{get currentPage(){return y(i)},get tabAvailability(){return y(j)},get optionalEmptyTabs(){return Le},onNavigate:Re})};ge(lt,le=>{y(_)||le(yt)})}var Et=N(lt,2),ct=C(Et);{var Ut=le=>{p3e(le,{get project(){return y(o)},get selectedRuns(){return y(de)},get allRuns(){return y(a)},get smoothing(){return y(u)},get xAxis(){return y(c)},get logScaleX(){return y(f)},get logScaleY(){return y(d)},get metricFilter(){return y(h)},get showHeaders(){return y(g)},get appBootstrapReady(){return y($)},get plotOrder(){return y(O)},get realtimeEnabled(){return y(p)},get metricColumns(){return y(v)},set metricColumns(pe){D(v,pe,!0)}})},me=le=>{L3e(le,{get project(){return y(o)},get selectedRuns(){return y(de)}})},Ee=le=>{H3e(le,{get project(){return y(o)},get selectedRuns(){return y(de)},get allRuns(){return y(a)},get smoothing(){return y(u)},get appBootstrapReady(){return y($)},get realtimeEnabled(){return y(p)},get availableDevices(){return y(R)},set availableDevices(pe){D(R,pe,!0)},get selectedDevices(){return y(z)},set selectedDevices(pe){D(z,pe,!0)}})},Ye=le=>{kCe(le,{get project(){return y(o)},get selectedRuns(){return y(de)},get allRuns(){return y(a)},get tableTruncateLength(){return y(P)}})},ht=le=>{ICe(le,{get project(){return y(o)},get selectedRuns(){return y(de)}})},Ve=le=>{HCe(le,{get project(){return y(o)},get runs(){return y(a)},get filterText(){return y(m)},onRunsChanged:ve,get runMutationAllowed(){return y(k).allowed}})},Xe=le=>{KCe(le,{get project(){return y(o)}})},dt=le=>{o$e(le,{get project(){return y(o)}})},pt=le=>{E$e(le,{get spaceId(){return y(F)},get selectedProject(){return y(o)},get projects(){return y(s)}})};ge(ct,le=>{y(i)==="metrics"?le(Ut):y(i)==="traces"?le(me,1):y(i)==="system"?le(Ee,2):y(i)==="media"?le(Ye,3):y(i)==="reports"?le(ht,4):y(i)==="runs"?le(Ve,5):y(i)==="run-detail"?le(Xe,6):y(i)==="files"?le(dt,7):y(i)==="settings"&&le(pt,8)})}var Ct=N(Ge,2);gY(Ct,{get alerts(){return y(A)}}),I(e,ft),An()}qH(k$e,{target:document.getElementById("app")}); diff --git a/trackio/frontend/dist/assets/index-PpAq14vL.css b/trackio/frontend/dist/assets/index-PpAq14vL.css new file mode 100644 index 0000000000000000000000000000000000000000..342286c938fad2c58820202a9d5a6eb33c50e185 --- /dev/null +++ b/trackio/frontend/dist/assets/index-PpAq14vL.css @@ -0,0 +1 @@ +:root{--primary-50: #fff7ed;--primary-100: #ffedd5;--primary-200: #fed7aa;--primary-300: #fdba74;--primary-400: #fb923c;--primary-500: #f97316;--primary-600: #ea580c;--primary-700: #c2410c;--primary-800: #9a3412;--primary-900: #7c2d12;--primary-950: #6c2e12;--secondary-50: #eff6ff;--secondary-100: #dbeafe;--secondary-200: #bfdbfe;--secondary-300: #93c5fd;--secondary-400: #60a5fa;--secondary-500: #3b82f6;--secondary-600: #2563eb;--secondary-700: #1d4ed8;--secondary-800: #1e40af;--secondary-900: #1e3a8a;--secondary-950: #1d3660;--neutral-50: #f9fafb;--neutral-100: #f3f4f6;--neutral-200: #e5e7eb;--neutral-300: #d1d5db;--neutral-400: #9ca3af;--neutral-500: #6b7280;--neutral-600: #4b5563;--neutral-700: #374151;--neutral-800: #1f2937;--neutral-900: #111827;--neutral-950: #0b0f19;--size-0-5: 2px;--size-1: 4px;--size-2: 8px;--size-3: 12px;--size-4: 16px;--size-5: 20px;--size-6: 24px;--size-8: 32px;--size-14: 56px;--size-16: 64px;--size-28: 112px;--size-full: 100%;--spacing-xxs: 1px;--spacing-xs: 2px;--spacing-sm: 4px;--spacing-md: 6px;--spacing-lg: 8px;--spacing-xl: 10px;--spacing-xxl: 16px;--radius-xxs: 1px;--radius-xs: 2px;--radius-sm: 3px;--radius-md: 4px;--radius-lg: 5px;--radius-xl: 8px;--radius-xxl: 12px;--text-xxs: 9px;--text-xs: 10px;--text-sm: 12px;--text-md: 14px;--text-lg: 16px;--text-xl: 22px;--text-xxl: 26px;--line-sm: 1.4;--background-fill-primary: white;--background-fill-secondary: var(--neutral-50);--body-text-color: var(--neutral-900);--body-text-color-subdued: var(--neutral-600);--border-color-primary: var(--neutral-200);--color-accent: var(--primary-500);--color-accent-soft: var(--primary-50);--shadow-drop: rgba(0, 0, 0, .05) 0px 1px 2px 0px;--shadow-drop-lg: 0 1px 3px 0 rgb(0 0 0 / .1), 0 1px 2px -1px rgb(0 0 0 / .1);--shadow-inset: rgba(0, 0, 0, .05) 0px 2px 4px 0px inset;--shadow-spread: 3px;--block-title-text-color: var(--neutral-500);--block-title-text-size: var(--text-md);--block-title-text-weight: 400;--block-info-text-color: var(--body-text-color-subdued);--block-info-text-size: var(--text-sm);--input-background-fill: white;--input-background-fill-focus: var(--primary-500);--input-border-color: var(--border-color-primary);--input-border-color-focus: var(--primary-300);--input-border-width: 1px;--input-padding: var(--spacing-xl);--input-placeholder-color: var(--neutral-400);--input-radius: var(--radius-lg);--input-shadow: 0 0 0 var(--shadow-spread) transparent, var(--shadow-inset);--input-shadow-focus: 0 0 0 var(--shadow-spread) var(--primary-50), var(--shadow-inset);--input-text-size: var(--text-md);--checkbox-background-color: var(--background-fill-primary);--checkbox-background-color-focus: var(--checkbox-background-color);--checkbox-background-color-hover: var(--checkbox-background-color);--checkbox-background-color-selected: var(--primary-600);--checkbox-border-color: var(--neutral-300);--checkbox-border-color-focus: var(--primary-500);--checkbox-border-color-hover: var(--neutral-300);--checkbox-border-color-selected: var(--primary-600);--checkbox-border-radius: var(--radius-sm);--checkbox-border-width: var(--input-border-width);--checkbox-label-gap: var(--spacing-lg);--checkbox-label-padding: var(--spacing-md) calc(2 * var(--spacing-md));--checkbox-label-text-size: var(--text-md);--checkbox-shadow: var(--input-shadow);--checkbox-check: url("data:image/svg+xml,%3csvg viewBox='0 0 16 16' fill='white' xmlns='http://www.w3.org/2000/svg'%3e%3cpath d='M12.207 4.793a1 1 0 010 1.414l-5 5a1 1 0 01-1.414 0l-2-2a1 1 0 011.414-1.414L6.5 9.086l4.293-4.293a1 1 0 011.414 0z'/%3e%3c/svg%3e");--slider-color: var(--primary-500);--container-radius: var(--radius-lg);--layer-top: 9999}.navbar.svelte-d8j1hi{display:flex;align-items:stretch;border-bottom:1px solid var(--border-color-primary, #e5e7eb);background:var(--background-fill-primary, white);padding:0;flex-shrink:0;min-height:44px}.nav-spacer.svelte-d8j1hi{flex:1 1 0;min-width:0}.nav-tabs.svelte-d8j1hi{display:flex;gap:0;flex-shrink:0;padding-right:8px}.nav-link.svelte-d8j1hi{padding:10px 16px;border:none;background:none;color:var(--body-text-color-subdued, #6b7280);font-size:var(--text-md, 14px);cursor:pointer;white-space:nowrap;border-bottom:2px solid transparent;transition:color .15s;font-weight:400}.nav-link.empty.svelte-d8j1hi:not(.active){color:var(--body-text-color-subdued, #9ca3af);opacity:.48}.nav-link.svelte-d8j1hi:hover{color:var(--body-text-color, #1f2937);opacity:1}.nav-link.active.svelte-d8j1hi{color:var(--body-text-color, #1f2937);border-bottom-color:var(--body-text-color, #1f2937);font-weight:500}.settings-btn.svelte-d8j1hi{display:flex;align-items:center;gap:6px}.settings-btn.svelte-d8j1hi svg:where(.svelte-d8j1hi){flex-shrink:0}.checkbox-group.svelte-17gmtkf{display:flex;flex-direction:column}.checkbox-item.svelte-17gmtkf{display:flex;align-items:center;gap:8px;padding:3px 0;cursor:pointer;font-size:13px}.checkbox-item.svelte-17gmtkf input[type=checkbox]:where(.svelte-17gmtkf){-moz-appearance:none;appearance:none;-webkit-appearance:none;width:16px;height:16px;margin:0;border:1px solid var(--checkbox-border-color, #d1d5db);border-radius:var(--checkbox-border-radius, 4px);background-color:var(--checkbox-background-color, white);box-shadow:var(--checkbox-shadow);cursor:pointer;flex-shrink:0;transition:background-color .15s,border-color .15s}.checkbox-item.svelte-17gmtkf input[type=checkbox]:where(.svelte-17gmtkf):checked{background-image:var(--checkbox-check);background-color:var(--checkbox-background-color-selected, #f97316);border-color:var(--checkbox-border-color-selected, #f97316)}.checkbox-item.svelte-17gmtkf input[type=checkbox]:where(.svelte-17gmtkf):hover{border-color:var(--checkbox-border-color-hover, #d1d5db)}.color-dot.svelte-17gmtkf{width:10px;height:10px;border-radius:50%;flex-shrink:0}.run-name.svelte-17gmtkf{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:var(--body-text-color, #1f2937)}.dropdown-container.svelte-kgylqb{width:100%;margin-bottom:4px}.label.svelte-kgylqb{display:block;font-size:13px;font-weight:500;color:var(--body-text-color-subdued, #6b7280);margin-bottom:6px}.info.svelte-kgylqb{display:block;font-size:12px;color:var(--body-text-color-subdued, #9ca3af);margin-bottom:4px}.wrap.svelte-kgylqb{position:relative;border-radius:var(--input-radius, 8px);background:var(--input-background-fill, white);border:1px solid var(--border-color-primary, #e5e7eb);transition:border-color .15s,box-shadow .15s}.wrap.focused.svelte-kgylqb{border-color:var(--input-border-color-focus, #fdba74);box-shadow:0 0 0 2px var(--primary-50, #fff7ed)}.wrap-inner.svelte-kgylqb{display:flex;position:relative;align-items:center;padding:0 10px}.secondary-wrap.svelte-kgylqb{display:flex;flex:1;align-items:center}input.svelte-kgylqb{margin:0;outline:none;border:none;background:inherit;width:100%;color:var(--body-text-color, #1f2937);font-size:13px;font-family:inherit;padding:7px 0}input.svelte-kgylqb::placeholder{color:var(--input-placeholder-color, #9ca3af)}input[readonly].svelte-kgylqb{cursor:pointer}.icon-wrap.svelte-kgylqb{color:var(--body-text-color-subdued, #9ca3af);width:16px;flex-shrink:0;pointer-events:none}.options.svelte-kgylqb{position:fixed;z-index:var(--layer-top, 9999);margin:0;padding:4px 0;box-shadow:0 4px 12px #0000001f;border-radius:var(--input-radius, 8px);border:1px solid var(--border-color-primary, #e5e7eb);background:var(--background-fill-primary, white);min-width:fit-content;overflow:auto;color:var(--body-text-color, #1f2937);list-style:none}.item.svelte-kgylqb{display:flex;cursor:pointer;padding:6px 10px;font-size:13px;word-break:break-word}.item.svelte-kgylqb:hover,.item.active.svelte-kgylqb{background:var(--background-fill-secondary, #f9fafb)}.item.selected.svelte-kgylqb{font-weight:500}.check-mark.svelte-kgylqb{padding-right:6px;min-width:16px;font-size:12px}.check-mark.hide.svelte-kgylqb{visibility:hidden}.checkbox-container.svelte-oj84db{display:flex;align-items:center;gap:8px;cursor:pointer;padding:3px 0}.label-text.svelte-oj84db{color:var(--body-text-color, #1f2937);font-size:13px;line-height:1.4}input[type=checkbox].svelte-oj84db{--ring-color: transparent;position:relative;-moz-appearance:none;appearance:none;-webkit-appearance:none;width:16px;height:16px;box-shadow:var(--checkbox-shadow);border:1px solid var(--checkbox-border-color, #d1d5db);border-radius:var(--checkbox-border-radius, 4px);background-color:var(--checkbox-background-color, white);flex-shrink:0;cursor:pointer;transition:background-color .15s,border-color .15s}input[type=checkbox].svelte-oj84db:checked,input[type=checkbox].svelte-oj84db:checked:hover,input[type=checkbox].svelte-oj84db:checked:focus{background-image:var(--checkbox-check);background-color:var(--checkbox-background-color-selected, #f97316);border-color:var(--checkbox-border-color-selected, #f97316)}input[type=checkbox].svelte-oj84db:hover{border-color:var(--checkbox-border-color-hover, #d1d5db);background-color:var(--checkbox-background-color-hover, white)}input[type=checkbox].svelte-oj84db:focus{border-color:var(--checkbox-border-color-focus, #f97316);background-color:var(--checkbox-background-color-focus, white);outline:none}.slider-wrap.svelte-wei6ev{display:flex;flex-direction:column;width:100%}.head.svelte-wei6ev{margin-bottom:4px;display:flex;justify-content:space-between;align-items:center;width:100%}.label.svelte-wei6ev{flex:1;font-size:13px;font-weight:500;color:var(--body-text-color-subdued, #6b7280)}.info.svelte-wei6ev{display:block;font-size:12px;color:var(--body-text-color-subdued, #9ca3af);margin-bottom:4px}.slider-input-container.svelte-wei6ev{display:flex;align-items:center;gap:6px}input[type=range].svelte-wei6ev{-webkit-appearance:none;-moz-appearance:none;appearance:none;width:100%;cursor:pointer;outline:none;border-radius:var(--radius-xl, 12px);min-width:var(--size-28, 112px);background:transparent}input[type=range].svelte-wei6ev::-webkit-slider-runnable-track{height:6px;border-radius:var(--radius-xl, 12px);background:linear-gradient(to right,var(--slider-color, #f97316) var(--range_progress, 50%),var(--neutral-200, #e5e7eb) var(--range_progress, 50%))}input[type=range].svelte-wei6ev::-webkit-slider-thumb{-webkit-appearance:none;-moz-appearance:none;appearance:none;height:16px;width:16px;background-color:var(--slider-color, #f97316);border:2px solid var(--background-fill-primary, white);border-radius:50%;margin-top:-5px;box-shadow:0 0 0 1px var(--border-color-primary, rgba(0, 0, 0, .08)),0 1px 3px #0003}input[type=range].svelte-wei6ev::-moz-range-track{height:6px;background:var(--neutral-200, #e5e7eb);border-radius:var(--radius-xl, 12px)}input[type=range].svelte-wei6ev::-moz-range-thumb{-webkit-appearance:none;-moz-appearance:none;appearance:none;height:16px;width:16px;background-color:var(--slider-color, #f97316);border:2px solid var(--background-fill-primary, white);border-radius:50%;box-shadow:0 0 0 1px var(--border-color-primary, rgba(0, 0, 0, .08)),0 1px 3px #0003}input[type=range].svelte-wei6ev::-moz-range-progress{height:6px;background-color:var(--slider-color, #f97316);border-radius:var(--radius-xl, 12px)}.bound.svelte-wei6ev{font-size:11px;color:var(--body-text-color-subdued, #9ca3af);min-width:12px;text-align:center}.textbox-container.svelte-6yncpg{width:100%}.label.svelte-6yncpg{display:block;font-size:13px;font-weight:500;color:var(--body-text-color-subdued, #6b7280);margin-bottom:6px}.info.svelte-6yncpg{display:block;font-size:12px;color:var(--body-text-color-subdued, #9ca3af);margin-bottom:4px}.input-wrap.svelte-6yncpg{border-radius:var(--input-radius, 8px);background:var(--input-background-fill, white);border:1px solid var(--border-color-primary, #e5e7eb);transition:border-color .15s,box-shadow .15s}.input-wrap.svelte-6yncpg:focus-within{border-color:var(--input-border-color-focus, #fdba74);box-shadow:0 0 0 2px var(--primary-50, #fff7ed)}input.svelte-6yncpg{width:100%;padding:7px 10px;outline:none;border:none;background:transparent;color:var(--body-text-color, #1f2937);font-size:13px;font-family:inherit;border-radius:var(--input-radius, 8px)}input.svelte-6yncpg::placeholder{color:var(--input-placeholder-color, #9ca3af)}.sidebar.svelte-181dlmc{width:290px;min-width:290px;background:var(--background-fill-primary, white);border-right:1px solid var(--border-color-primary, #e5e7eb);display:flex;flex-direction:column;position:relative;overflow:hidden;transition:width .2s,min-width .2s}.sidebar.collapsed.svelte-181dlmc{width:40px;min-width:40px}.toggle-btn.svelte-181dlmc{position:absolute;top:12px;right:8px;z-index:10;border:none;background:none;color:var(--body-text-color-subdued, #9ca3af);cursor:pointer;padding:4px;display:flex;align-items:center;justify-content:center;border-radius:var(--radius-sm, 4px);transition:color .15s,background-color .15s}.toggle-btn.svelte-181dlmc:hover{color:var(--body-text-color, #1f2937);background-color:var(--background-fill-secondary, #f9fafb)}.sidebar-content.svelte-181dlmc{padding:16px;flex:1;min-height:0;display:flex;flex-direction:column}.sidebar-scroll.svelte-181dlmc{overflow-y:auto;flex:1;min-height:0}.oauth-footer.svelte-181dlmc{flex-shrink:0;margin-top:12px;padding-top:12px;border-top:1px solid var(--border-color-primary, #e5e7eb)}.readonly-footer.svelte-181dlmc{flex-shrink:0;margin-top:12px;padding-top:12px;border-top:1px solid var(--border-color-primary, #e5e7eb);display:flex;align-items:center;gap:8px;flex-wrap:wrap}.readonly-badge.svelte-181dlmc{display:inline-flex;align-items:center;border:1px solid var(--border-color-primary, #e5e7eb);border-radius:999px;padding:2px 8px;font-size:10px;letter-spacing:.06em;font-weight:600;color:var(--body-text-color-subdued, #6b7280);background:var(--background-fill-secondary, #f9fafb)}.readonly-link.svelte-181dlmc{font-size:12px;color:var(--body-text-color-subdued, #6b7280);text-decoration:none;max-width:100%;overflow-wrap:anywhere}.readonly-link.svelte-181dlmc:hover{color:var(--body-text-color, #1f2937);text-decoration:underline}.oauth-line.svelte-181dlmc{margin:0;font-size:12px;line-height:1.4;color:var(--body-text-color-subdued, #6b7280)}.oauth-warn.svelte-181dlmc{color:var(--body-text-color, #92400e)}.hf-login-btn.svelte-181dlmc{display:inline-flex;align-items:center;justify-content:center;gap:8px;width:100%;padding:8px 12px;font-size:13px;font-weight:600;color:#fff;background:#141c2e;border-radius:var(--radius-lg, 8px);text-decoration:none;border:none;cursor:pointer;box-sizing:border-box}.hf-login-btn.svelte-181dlmc:hover{background:#283042}.hf-logo.svelte-181dlmc{width:20px;height:20px;flex-shrink:0}.oauth-hint.svelte-181dlmc{margin:8px 0 0;font-size:11px;line-height:1.35;color:var(--body-text-color-subdued, #9ca3af)}.oauth-signed-in.svelte-181dlmc{margin:0;font-size:12px;color:var(--body-text-color-subdued, #6b7280)}.oauth-logout.svelte-181dlmc{font-size:12px;color:var(--body-text-color-subdued, #9ca3af);text-decoration:none;cursor:pointer}.oauth-logout.svelte-181dlmc:hover{text-decoration:underline;color:var(--body-text-color, #1f2937)}.logo-section.svelte-181dlmc{margin-bottom:20px}.logo.svelte-181dlmc{width:80%;max-width:200px}.section.svelte-181dlmc{margin-top:2px;margin-bottom:18px}.share-tabs.svelte-181dlmc{display:flex;gap:6px;margin-bottom:8px}.share-tab-btn.svelte-181dlmc{border:1px solid var(--border-color-primary, #e5e7eb);border-radius:var(--radius-md, 6px);padding:4px 8px;font-size:12px;color:var(--body-text-color-subdued, #6b7280);background:var(--background-fill-primary, white);cursor:pointer}.share-tab-btn.active.svelte-181dlmc{color:var(--body-text-color, #1f2937);background:var(--background-fill-secondary, #f9fafb)}.share-field.svelte-181dlmc{display:flex;flex-direction:column;gap:6px}.share-input-row.svelte-181dlmc{display:flex;gap:6px;align-items:stretch}.share-input-row.svelte-181dlmc input:where(.svelte-181dlmc),.share-input-row.svelte-181dlmc textarea:where(.svelte-181dlmc){width:100%;min-width:0;border:1px solid var(--border-color-primary, #e5e7eb);border-radius:var(--radius-md, 6px);padding:6px 8px;font-size:12px;font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace;color:var(--body-text-color, #1f2937);background:var(--background-fill-secondary, #f9fafb);resize:vertical}.copy-btn.svelte-181dlmc{box-sizing:border-box;border:1px solid var(--border-color-primary, #e5e7eb);border-radius:var(--radius-md, 6px);padding:6px 10px;min-width:3.25rem;display:inline-flex;align-items:center;justify-content:center;font-size:12px;line-height:1;color:var(--body-text-color, #1f2937);background:var(--background-fill-primary, white);cursor:pointer;flex-shrink:0}.copy-btn-check.svelte-181dlmc{display:block;color:var(--color-accent, #f97316)}.share-hint.svelte-181dlmc{margin:0;font-size:12px;line-height:1.4;color:var(--body-text-color-subdued, #9ca3af)}.section-label.svelte-181dlmc{font-size:13px;font-weight:500;color:var(--body-text-color-subdued, #6b7280)}.locked-project.svelte-181dlmc{margin-top:4px;font-size:13px;font-weight:500;color:var(--body-text-color, #1f2937);padding:8px 10px;border:1px solid var(--border-color-primary, #e5e7eb);border-radius:var(--radius-md, 6px);background:var(--background-fill-secondary, #f9fafb)}.runs-header.svelte-181dlmc{display:flex;align-items:center;justify-content:space-between;margin-bottom:6px}.select-all-label.svelte-181dlmc{display:flex;align-items:center;gap:6px;cursor:pointer}.select-all-cb.svelte-181dlmc{-moz-appearance:none;appearance:none;-webkit-appearance:none;width:16px;height:16px;border:1px solid var(--checkbox-border-color, #d1d5db);border-radius:var(--checkbox-border-radius, 4px);background-color:var(--checkbox-background-color, white);cursor:pointer;flex-shrink:0;position:relative;transition:background-color .15s,border-color .15s}.select-all-cb.svelte-181dlmc:checked{background-color:var(--checkbox-background-color-selected, var(--color-accent, #f97316));border-color:var(--checkbox-background-color-selected, var(--color-accent, #f97316));background-image:var(--checkbox-check)}.select-all-cb.svelte-181dlmc:indeterminate{background-color:var(--checkbox-background-color-selected, var(--color-accent, #f97316));border-color:var(--checkbox-background-color-selected, var(--color-accent, #f97316));background-image:url("data:image/svg+xml,%3Csvg viewBox='0 0 16 16' fill='white' xmlns='http://www.w3.org/2000/svg'%3E%3Crect x='3' y='7' width='10' height='2' rx='1'/%3E%3C/svg%3E");background-size:12px;background-position:center;background-repeat:no-repeat}.latest-toggle.svelte-181dlmc{display:flex;align-items:center;gap:6px;font-size:12px;color:var(--body-text-color-subdued, #6b7280);cursor:pointer}.latest-toggle.svelte-181dlmc input[type=checkbox]:where(.svelte-181dlmc){-moz-appearance:none;appearance:none;-webkit-appearance:none;width:16px;height:16px;margin:0;border:1px solid var(--checkbox-border-color, #d1d5db);border-radius:var(--checkbox-border-radius, 4px);background-color:var(--checkbox-background-color, white);box-shadow:var(--checkbox-shadow);cursor:pointer;flex-shrink:0;transition:background-color .15s,border-color .15s}.latest-toggle.svelte-181dlmc input[type=checkbox]:where(.svelte-181dlmc):checked{background-image:var(--checkbox-check);background-color:var(--checkbox-background-color-selected, #f97316);border-color:var(--checkbox-border-color-selected, #f97316)}.checkbox-list.svelte-181dlmc{max-height:300px;overflow-y:auto;margin-top:8px}.device-group.svelte-181dlmc{margin-top:14px;padding-top:12px;border-top:1px solid var(--border-color-primary, #e5e7eb)}.section-sublabel.svelte-181dlmc{font-size:12px;font-weight:600;color:var(--body-text-color-subdued, #6b7280)}.checkbox-group.svelte-181dlmc{display:flex;flex-direction:column;margin-top:8px}.checkbox-item.svelte-181dlmc{display:flex;align-items:center;gap:8px;padding:3px 0;cursor:pointer;font-size:13px}.checkbox-item.svelte-181dlmc input[type=checkbox]:where(.svelte-181dlmc){-moz-appearance:none;appearance:none;-webkit-appearance:none;width:16px;height:16px;margin:0;border:1px solid var(--checkbox-border-color, #d1d5db);border-radius:var(--checkbox-border-radius, 4px);background-color:var(--checkbox-background-color, white);box-shadow:var(--checkbox-shadow);cursor:pointer;flex-shrink:0;transition:background-color .15s,border-color .15s}.checkbox-item.svelte-181dlmc input[type=checkbox]:where(.svelte-181dlmc):checked{background-image:var(--checkbox-check);background-color:var(--checkbox-background-color-selected, #f97316);border-color:var(--checkbox-border-color-selected, #f97316)}.checkbox-item.svelte-181dlmc input[type=checkbox]:where(.svelte-181dlmc):hover{border-color:var(--checkbox-border-color-hover, #d1d5db)}.run-name.svelte-181dlmc{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:var(--body-text-color, #1f2937)}.group-by-row.svelte-181dlmc{margin-top:8px}.grouped-runs.svelte-181dlmc{margin-top:8px;display:flex;flex-direction:column;gap:6px}.run-group-section.svelte-181dlmc{border:1px solid var(--border-color-primary, #e5e7eb);border-radius:var(--radius-md, 6px);overflow:hidden}.run-group-header.svelte-181dlmc{display:flex;align-items:center;padding:6px 10px;background:var(--background-fill-secondary, #f9fafb);border-bottom:1px solid var(--border-color-primary, #e5e7eb)}.run-group-label.svelte-181dlmc{font-size:12px;font-weight:600;color:var(--body-text-color, #1f2937);overflow:hidden;text-overflow:ellipsis;white-space:nowrap;max-width:160px}.run-group-count.svelte-181dlmc{font-size:11px;color:var(--body-text-color-subdued, #9ca3af);margin-left:4px;flex-shrink:0}.group-checkbox-list.svelte-181dlmc{padding:4px 10px;max-height:none}.alert-panel.svelte-x5aqew{position:fixed;bottom:16px;right:16px;width:380px;max-height:400px;background:var(--background-fill-primary, white);border:1px solid var(--border-color-primary, #e5e7eb);border-radius:var(--radius-lg, 8px);box-shadow:var(--shadow-drop-lg);z-index:1000;overflow:hidden;display:flex;flex-direction:column}.alert-panel.collapsed.svelte-x5aqew{max-height:none}.alert-header.svelte-x5aqew{padding:10px 12px;border:none;border-bottom:1px solid var(--border-color-primary, #e5e7eb);background:none;width:100%;display:flex;align-items:center;justify-content:space-between;cursor:pointer;gap:8px}.alert-panel.collapsed.svelte-x5aqew .alert-header:where(.svelte-x5aqew){border-bottom:none}.collapse-icon.svelte-x5aqew{color:var(--body-text-color-subdued, #9ca3af);flex-shrink:0;transition:transform .15s}.collapse-icon.rotated.svelte-x5aqew{transform:rotate(-90deg)}.alert-title.svelte-x5aqew{font-size:13px;font-weight:600;color:var(--body-text-color, #1f2937)}.filter-pills.svelte-x5aqew{display:flex;gap:4px}.pill.svelte-x5aqew{border:1px solid var(--border-color-primary, #e5e7eb);border-radius:var(--radius-xxl, 22px);padding:2px 8px;font-size:11px;background:var(--background-fill-secondary, #f9fafb);color:var(--body-text-color-subdued, #6b7280);cursor:pointer}.pill.active.svelte-x5aqew{background:var(--color-accent, #f97316);color:#fff;border-color:var(--color-accent, #f97316)}.alert-list.svelte-x5aqew{overflow-y:auto;flex:1}.alert-item.svelte-x5aqew{border-bottom:1px solid var(--neutral-100, #f3f4f6)}.alert-row.svelte-x5aqew{display:flex;align-items:center;gap:8px;width:100%;padding:8px 12px;border:none;background:none;text-align:left;cursor:pointer;font-size:var(--text-sm, 12px)}.alert-row.svelte-x5aqew:hover{background:var(--background-fill-secondary, #f9fafb)}.alert-text.svelte-x5aqew{flex:1;color:var(--body-text-color, #1f2937)}.alert-meta.svelte-x5aqew{font-size:var(--text-xs, 10px);color:var(--body-text-color-subdued, #9ca3af);white-space:nowrap}.alert-detail.svelte-x5aqew{padding:4px 12px 8px 32px;font-size:var(--text-sm, 12px);color:var(--body-text-color-subdued, #6b7280)}.plot-container.svelte-9thu1j{min-width:350px;flex:1;background:var(--background-fill-primary, white);border:1px solid var(--border-color-primary, #e5e7eb);border-radius:var(--radius-lg, 8px);padding:12px;overflow:hidden;position:relative}.plot-container[draggable=true].svelte-9thu1j{cursor:grab}.plot-container[draggable=true].svelte-9thu1j:active{cursor:grabbing}.hidden-plot.svelte-9thu1j{visibility:hidden;height:0;padding:0;margin:0;border:none;overflow:hidden;pointer-events:none}.drag-handle.svelte-9thu1j{position:absolute;top:8px;left:8px;color:var(--body-text-color-subdued, #9ca3af);opacity:0;transition:opacity .15s;z-index:5}.plot-container.svelte-9thu1j:hover .drag-handle:where(.svelte-9thu1j){opacity:.5}.drag-handle.svelte-9thu1j:hover{opacity:1!important}.plot-toolbar.svelte-9thu1j{position:absolute;top:8px;right:8px;display:flex;gap:4px;z-index:5;opacity:0;transition:opacity .15s}.plot-container.svelte-9thu1j:hover .plot-toolbar:where(.svelte-9thu1j){opacity:1}.toolbar-btn.svelte-9thu1j{border:1px solid var(--border-color-primary, #e5e7eb);background:var(--background-fill-primary, white);color:var(--body-text-color-subdued, #6b7280);cursor:pointer;padding:4px 6px;border-radius:var(--radius-sm, 4px);display:flex;align-items:center;justify-content:center}.toolbar-btn.svelte-9thu1j:hover{background:var(--neutral-100, #f3f4f6);color:var(--body-text-color, #1f2937)}.plot-chart-wrap.svelte-9thu1j{position:relative;width:100%}.plot-chart-wrap--fs.svelte-9thu1j{flex:1;min-height:0;display:flex;flex-direction:column}.reset-zoom-btn.svelte-9thu1j{position:absolute;bottom:1px;right:1px;z-index:6;display:inline-flex;align-items:center;justify-content:center;margin:0;min-width:52px;padding:5px 12px 5px 10px;border:none;border-radius:4px;background:transparent;color:var(--body-text-color-subdued, #334155);cursor:pointer;opacity:.92;transform:translateY(6px);transition:opacity .15s ease,color .15s ease,background .15s ease;box-shadow:none}.reset-zoom-btn.svelte-9thu1j:hover{opacity:1;color:var(--body-text-color, #0f172a);background:var(--background-fill-secondary, rgba(226, 232, 240, .85));transform:translateY(6px)}.reset-zoom-btn.svelte-9thu1j svg:where(.svelte-9thu1j){display:block;flex-shrink:0;filter:drop-shadow(0 0 .5px rgba(255,255,255,.95))}.plot-title.svelte-9thu1j{font-size:13px;font-weight:600;color:var(--body-text-color, #374151);text-align:center;padding:0 0 6px;word-break:break-word}.plot-title--fs.svelte-9thu1j{flex-shrink:0}.plot.svelte-9thu1j{width:100%}.plot.svelte-9thu1j .vega-embed{width:100%!important}.plot.svelte-9thu1j .vega-embed summary{display:none}.fullscreen-host.svelte-9thu1j{position:fixed;top:0;right:0;bottom:0;left:0;z-index:10000;box-sizing:border-box;display:flex;flex-direction:column;background:var(--background-fill-primary, white);padding:12px;gap:8px;pointer-events:auto}.fullscreen-host.svelte-9thu1j:fullscreen{width:100%;height:100%}.fullscreen-host.svelte-9thu1j:-webkit-full-screen{width:100%;height:100%}.fullscreen-toolbar.svelte-9thu1j{flex-shrink:0;display:flex;justify-content:flex-end;gap:4px;z-index:5}.fullscreen-chart-wrap.svelte-9thu1j{flex:1;min-height:0;display:flex;flex-direction:column}.fullscreen-legend.svelte-9thu1j{flex-shrink:0}.fullscreen-plot.svelte-9thu1j{flex:1;min-height:0;width:100%;overflow:hidden}.fullscreen-plot.svelte-9thu1j .vega-embed{width:100%!important;height:100%!important;min-height:0;display:flex;flex-direction:column}.fullscreen-plot.svelte-9thu1j .vega-embed .vega-view{flex:1;min-height:0}.fullscreen-plot.svelte-9thu1j .vega-embed summary{display:none}.custom-legend.svelte-9thu1j{display:flex;align-items:center;justify-content:center;gap:12px;padding:6px 0 0;flex-wrap:wrap}.legend-title.svelte-9thu1j{font-size:11px;color:var(--body-text-color-subdued, #6b7280);font-weight:600}.legend-item.svelte-9thu1j{display:flex;align-items:center;gap:4px}.legend-dot.svelte-9thu1j{width:10px;height:10px;border-radius:50%;flex-shrink:0}.legend-line-swatch.svelte-9thu1j{width:24px;height:10px;flex-shrink:0;color:var(--body-text-color, #1f2937)}.legend-label.svelte-9thu1j{font-size:11px;color:var(--body-text-color-subdued, #6b7280)}.legend-toggle.svelte-9thu1j{font-size:11px;color:var(--body-text-color-subdued, #6b7280);background:none;border:none;padding:0 4px;cursor:pointer;text-decoration:underline}.legend-toggle.svelte-9thu1j:hover{color:var(--body-text-color, #1f2937)}.plot-container.svelte-1swghqy{min-width:350px;flex:1;background:var(--background-fill-primary, white);border:1px solid var(--border-color-primary, #e5e7eb);border-radius:var(--radius-lg, 8px);padding:12px;overflow:hidden;position:relative}.plot-container[draggable=true].svelte-1swghqy{cursor:grab}.plot-container[draggable=true].svelte-1swghqy:active{cursor:grabbing}.hidden-plot.svelte-1swghqy{visibility:hidden;height:0;padding:0;margin:0;border:none;overflow:hidden;pointer-events:none}.drag-handle.svelte-1swghqy{position:absolute;top:8px;left:8px;color:var(--body-text-color-subdued, #9ca3af);opacity:0;transition:opacity .15s;z-index:5}.plot-container.svelte-1swghqy:hover .drag-handle:where(.svelte-1swghqy){opacity:.5}.drag-handle.svelte-1swghqy:hover{opacity:1!important}.plot-toolbar.svelte-1swghqy{position:absolute;top:8px;right:8px;display:flex;gap:4px;z-index:5;opacity:0;transition:opacity .15s}.plot-container.svelte-1swghqy:hover .plot-toolbar:where(.svelte-1swghqy){opacity:1}.toolbar-btn.svelte-1swghqy{border:1px solid var(--border-color-primary, #e5e7eb);background:var(--background-fill-primary, white);color:var(--body-text-color-subdued, #6b7280);cursor:pointer;padding:4px 6px;border-radius:var(--radius-sm, 4px);display:flex;align-items:center;justify-content:center}.toolbar-btn.svelte-1swghqy:hover{background:var(--neutral-100, #f3f4f6);color:var(--body-text-color, #1f2937)}.plot-chart-wrap.svelte-1swghqy{position:relative;width:100%}.plot-chart-wrap--fs.svelte-1swghqy{flex:1;min-height:0;display:flex;flex-direction:column}.plot-title.svelte-1swghqy{font-size:13px;font-weight:600;color:var(--body-text-color, #374151);text-align:center;padding:0 0 6px;word-break:break-word}.plot-title--fs.svelte-1swghqy{flex-shrink:0}.plot.svelte-1swghqy{width:100%}.plot.svelte-1swghqy .vega-embed{width:100%!important}.plot.svelte-1swghqy .vega-embed summary{display:none}.fullscreen-host.svelte-1swghqy{position:fixed;top:0;right:0;bottom:0;left:0;z-index:10000;box-sizing:border-box;display:flex;flex-direction:column;background:var(--background-fill-primary, white);padding:12px;gap:8px;pointer-events:auto}.fullscreen-host.svelte-1swghqy:fullscreen{width:100%;height:100%}.fullscreen-host.svelte-1swghqy:-webkit-full-screen{width:100%;height:100%}.fullscreen-toolbar.svelte-1swghqy{flex-shrink:0;display:flex;justify-content:flex-end;gap:4px;z-index:5}.fullscreen-chart-wrap.svelte-1swghqy{flex:1;min-height:0;display:flex;flex-direction:column}.fullscreen-legend.svelte-1swghqy{flex-shrink:0}.fullscreen-plot.svelte-1swghqy{flex:1;min-height:0;width:100%;overflow:hidden}.fullscreen-plot.svelte-1swghqy .vega-embed{width:100%!important;height:100%!important;min-height:0;display:flex;flex-direction:column}.fullscreen-plot.svelte-1swghqy .vega-embed .vega-view{flex:1;min-height:0}.fullscreen-plot.svelte-1swghqy .vega-embed summary{display:none}.custom-legend.svelte-1swghqy{display:flex;align-items:center;justify-content:center;gap:12px;padding:6px 0 0;flex-wrap:wrap}.legend-item.svelte-1swghqy{display:flex;align-items:center;gap:4px}.legend-dot.svelte-1swghqy{width:10px;height:10px;border-radius:50%;flex-shrink:0}.legend-label.svelte-1swghqy{font-size:11px;color:var(--body-text-color-subdued, #6b7280)}.legend-toggle.svelte-1swghqy{font-size:11px;color:var(--body-text-color-subdued, #6b7280);background:none;border:none;padding:0 4px;cursor:pointer;text-decoration:underline}.legend-toggle.svelte-1swghqy:hover{color:var(--body-text-color, #1f2937)}.accordion.svelte-1jep0a{margin-bottom:12px;border:1px solid var(--border-color-primary, #e5e7eb);border-radius:var(--radius-lg, 8px);background:var(--background-fill-primary, white);overflow:hidden}.accordion-hidden.svelte-1jep0a{margin-bottom:8px}.accordion-header.svelte-1jep0a{display:flex;align-items:center;gap:8px;width:100%;padding:10px 14px;border:none;background:var(--background-fill-primary, white);color:var(--body-text-color, #1f2937);font-size:var(--text-md, 14px);font-weight:600;cursor:pointer;text-align:left}.accordion-header.svelte-1jep0a:hover{background:var(--background-fill-secondary, #f9fafb)}.arrow.svelte-1jep0a{font-size:14px;transition:transform .15s;color:var(--body-text-color, #1f2937);display:inline-block}.arrow.svelte-1jep0a:not(.rotated){transform:rotate(-90deg)}.accordion-body.svelte-1jep0a{padding:0 14px 14px}.trackio-loading.svelte-1kc6b2l{display:flex;align-items:center;justify-content:center;width:100%;min-height:min(70vh,640px);padding:32px 24px;box-sizing:border-box;background:transparent}.logo-stack.svelte-1kc6b2l{position:relative;width:min(100%,200px);max-width:min(92vw,200px);line-height:0;background:transparent;isolation:isolate}.logo-base.svelte-1kc6b2l{display:block;background:transparent}.logo-img.svelte-1kc6b2l{width:100%;height:auto;display:block;background:transparent}.logo-overlay.svelte-1kc6b2l{position:absolute;left:0;top:0;width:100%;animation:svelte-1kc6b2l-trackio-logo-sweep 4s linear infinite;pointer-events:none;background:transparent}.logo-overlay.svelte-1kc6b2l .logo-img:where(.svelte-1kc6b2l){width:100%;height:auto;object-position:left center}.logo-img--gray.svelte-1kc6b2l{filter:grayscale(1)}@keyframes svelte-1kc6b2l-trackio-logo-sweep{0%{clip-path:inset(0 0 0 0)}50%{clip-path:inset(0 0 0 100%)}to{clip-path:inset(0 0 0 0)}}@media(prefers-reduced-motion:reduce){.logo-overlay.svelte-1kc6b2l{display:none}}.sr-only.svelte-1kc6b2l{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0}.metrics-page.svelte-2bul55{padding:20px 24px;overflow-y:auto;flex:1;min-height:0}.plot-grid.svelte-2bul55{display:flex;flex-wrap:wrap;gap:16px}.subgroup-list.svelte-2bul55{margin-top:16px}.empty-state.svelte-2bul55{max-width:640px;padding:40px 24px;color:var(--body-text-color, #1f2937)}.empty-state.svelte-2bul55 h2:where(.svelte-2bul55){margin:0 0 8px;font-size:20px;font-weight:700}.empty-state.svelte-2bul55 p:where(.svelte-2bul55){margin:12px 0 8px;color:var(--body-text-color-subdued, #6b7280)}.empty-state.svelte-2bul55 pre:where(.svelte-2bul55){background:var(--background-fill-secondary, #f9fafb);padding:16px;border-radius:var(--radius-lg, 8px);border:1px solid var(--border-color-primary, #e5e7eb);font-size:13px;overflow-x:auto}.empty-state.svelte-2bul55 code:where(.svelte-2bul55){background:var(--background-fill-secondary, #f0f0f0);padding:1px 5px;border-radius:var(--radius-sm, 4px);font-size:13px}.empty-state.svelte-2bul55 pre:where(.svelte-2bul55) code:where(.svelte-2bul55){background:none;padding:0}.traces-page.svelte-1s32ifo{padding:20px 24px;overflow-y:auto;flex:1;background:var(--background-fill-primary, white)}.toolbar.svelte-1s32ifo{display:flex;align-items:center;gap:12px;margin-bottom:16px}.search-wrap.svelte-1s32ifo{flex:1}.search-wrap.svelte-1s32ifo input:where(.svelte-1s32ifo),.filter-wrap.svelte-1s32ifo select:where(.svelte-1s32ifo){width:100%;border:1px solid var(--border-color-primary, #e5e7eb);border-radius:var(--radius-md, 6px);background:var(--background-fill-primary, white);color:var(--body-text-color, #1f2937);font-size:14px;padding:10px 12px;font-family:inherit}.filter-wrap.svelte-1s32ifo{display:flex;align-items:center;gap:8px;color:var(--body-text-color, #1f2937);font-size:14px;white-space:nowrap}.count.svelte-1s32ifo{margin-left:auto;color:var(--body-text-color-subdued, #6b7280);font-size:14px;white-space:nowrap}.traces-table-wrap.svelte-1s32ifo{border:1px solid var(--border-color-primary, #e5e7eb);border-radius:var(--radius-lg, 8px);overflow:hidden;transition:opacity .15s ease}.traces-table-wrap.dim.svelte-1s32ifo{opacity:.55}.traces-table.svelte-1s32ifo{width:100%;border-collapse:collapse;font-size:14px;table-layout:fixed}.trace-id-col.svelte-1s32ifo{width:140px}.request-col.svelte-1s32ifo{width:auto}.run-col.svelte-1s32ifo{width:180px}.step-col.svelte-1s32ifo{width:76px}.request-time-col.svelte-1s32ifo{width:150px}.traces-table.svelte-1s32ifo th:where(.svelte-1s32ifo){text-align:left;padding:10px 12px;border-bottom:1px solid var(--border-color-primary, #e5e7eb);color:var(--body-text-color-subdued, #6b7280);font-weight:600;font-size:12px;text-transform:uppercase;letter-spacing:.05em;background:var(--background-fill-primary, white)}.traces-table.svelte-1s32ifo td:where(.svelte-1s32ifo){padding:10px 12px;border-bottom:1px solid var(--border-color-primary, #e5e7eb);color:var(--body-text-color, #1f2937);vertical-align:top}.trace-row.svelte-1s32ifo{cursor:pointer}.trace-row.svelte-1s32ifo:hover{background:var(--background-fill-secondary, #f9fafb)}.trace-id-chip.svelte-1s32ifo{font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;font-size:13px;color:var(--body-text-color, #1f2937)}.request.svelte-1s32ifo{font-weight:500;margin-bottom:4px}.preview.svelte-1s32ifo{color:var(--body-text-color-subdued, #6b7280);font-size:13px;line-height:1.45;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden}.expanded-row.svelte-1s32ifo td:where(.svelte-1s32ifo){padding:0;background:var(--background-fill-secondary, #fafafa)}.trace-detail.svelte-1s32ifo{padding:16px 18px 18px}.detail-meta.svelte-1s32ifo{display:flex;gap:16px;flex-wrap:wrap;color:var(--body-text-color-subdued, #6b7280);font-size:13px;margin-bottom:14px}.conversation.svelte-1s32ifo{display:flex;flex-direction:column;gap:12px}.message.svelte-1s32ifo{border:1px solid var(--border-color-primary, #e5e7eb);border-radius:var(--radius-md, 6px);background:var(--background-fill-primary, white);padding:12px}.message-role.svelte-1s32ifo{margin-bottom:8px;color:var(--body-text-color-subdued, #6b7280);font-size:12px;font-weight:600;text-transform:uppercase;letter-spacing:.05em;display:flex;align-items:center;gap:8px;flex-wrap:wrap}.message-tag.svelte-1s32ifo{border:1px solid var(--border-color-primary, #e5e7eb);border-radius:999px;padding:2px 8px;font-size:11px;font-weight:500;text-transform:none;letter-spacing:0}.message-content.svelte-1s32ifo,.tool-block.svelte-1s32ifo{margin:0;white-space:pre-wrap;word-break:break-word;font-family:inherit;color:var(--body-text-color, #1f2937);line-height:1.5}.message-details.svelte-1s32ifo summary:where(.svelte-1s32ifo){cursor:pointer;margin-bottom:8px;color:var(--body-text-color-subdued, #6b7280)}.tool-blocks.svelte-1s32ifo{display:flex;flex-direction:column;gap:8px;margin-top:10px}.tool-block.svelte-1s32ifo{background:var(--background-fill-secondary, #f9fafb);border-radius:var(--radius-md, 6px);padding:10px;overflow-x:auto}.message-parts.svelte-1s32ifo{display:flex;flex-direction:column;gap:10px}.trace-image.svelte-1s32ifo{max-width:100%;max-height:360px;border:1px solid var(--border-color-primary, #e5e7eb);border-radius:var(--radius-md, 6px)}.empty-state.svelte-1s32ifo{max-width:640px;padding:40px 24px;color:var(--body-text-color, #1f2937)}.empty-state.svelte-1s32ifo h2:where(.svelte-1s32ifo){margin:0 0 8px;font-size:20px;font-weight:700}.empty-state.svelte-1s32ifo p:where(.svelte-1s32ifo){margin:12px 0 8px;color:var(--body-text-color-subdued, #6b7280)}.pagination.svelte-1s32ifo{display:flex;align-items:center;justify-content:center;gap:12px;padding:16px 0 4px}.pagination.svelte-1s32ifo button:where(.svelte-1s32ifo){border:1px solid var(--border-color-primary, #e5e7eb);border-radius:var(--radius-md, 6px);background:var(--background-fill-primary, white);color:var(--body-text-color, #1f2937);font-size:14px;padding:8px 14px;cursor:pointer;font-family:inherit}.pagination.svelte-1s32ifo button:where(.svelte-1s32ifo):hover:not(:disabled){background:var(--background-fill-secondary, #f9fafb)}.pagination.svelte-1s32ifo button:where(.svelte-1s32ifo):disabled{opacity:.5;cursor:not-allowed}.page-info.svelte-1s32ifo{color:var(--body-text-color-subdued, #6b7280);font-size:14px;min-width:120px;text-align:center}@media(max-width:1100px){.toolbar.svelte-1s32ifo{flex-wrap:wrap}.count.svelte-1s32ifo{margin-left:0}}.system-page.svelte-nv5os4{padding:20px 24px;overflow-y:auto;flex:1;min-height:0}.plot-grid.svelte-nv5os4{display:flex;flex-wrap:wrap;gap:12px}.subgroup-list.svelte-nv5os4{margin-top:16px}.empty-state.svelte-nv5os4{max-width:640px;padding:40px 24px;color:var(--body-text-color, #1f2937)}.empty-state.svelte-nv5os4 h2:where(.svelte-nv5os4){margin:0 0 8px;font-size:20px;font-weight:700}.empty-state.svelte-nv5os4 p:where(.svelte-nv5os4){margin:12px 0 8px;color:var(--body-text-color-subdued, #6b7280)}.empty-state.svelte-nv5os4 pre:where(.svelte-nv5os4){background:var(--background-fill-secondary, #f9fafb);padding:16px;border-radius:var(--radius-lg, 8px);border:1px solid var(--border-color-primary, #e5e7eb);font-size:13px;overflow-x:auto}.empty-state.svelte-nv5os4 ul:where(.svelte-nv5os4){list-style:disc;padding-left:20px;margin:4px 0 0}.empty-state.svelte-nv5os4 li:where(.svelte-nv5os4){margin:4px 0;color:var(--body-text-color, #1f2937)}.empty-state.svelte-nv5os4 code:where(.svelte-nv5os4){background:var(--background-fill-secondary, #f0f0f0);padding:1px 5px;border-radius:var(--radius-sm, 4px);font-size:13px}.empty-state.svelte-nv5os4 pre:where(.svelte-nv5os4) code:where(.svelte-nv5os4){background:none;padding:0}.wave-wrap.svelte-19wbodf{--wave-base: var(--body-text-color-subdued, #9ca3af);--wave-played: var(--color-accent, #f97316);display:flex;align-items:center;gap:8px;padding:8px 10px;background:var(--background-fill-secondary, #f9fafb);border:1px solid var(--border-color-primary, #e5e7eb);border-radius:var(--radius-lg, 8px);color:var(--body-text-color, #1f2937)}.play-btn.svelte-19wbodf{display:inline-flex;align-items:center;justify-content:center;width:28px;height:28px;border-radius:50%;background:var(--color-accent, #f97316);color:#fff;border:none;cursor:pointer;flex-shrink:0;padding:0}.play-btn.svelte-19wbodf:disabled{opacity:.4;cursor:not-allowed}.play-btn.svelte-19wbodf:hover:not(:disabled){filter:brightness(1.1)}.wave.svelte-19wbodf{flex:1;height:32px;min-width:0;cursor:pointer}.time.svelte-19wbodf{font-size:11px;color:var(--body-text-color-subdued, #6b7280);font-variant-numeric:tabular-nums;flex-shrink:0}audio.svelte-19wbodf{display:none}.media-page.svelte-outb32{padding:20px 24px;overflow-y:auto;flex:1}.section.svelte-outb32{margin:16px 0}.media-toolbar.svelte-outb32{display:flex;justify-content:flex-end;align-items:center;gap:12px;margin-bottom:12px}.media-control.svelte-outb32{display:flex;align-items:center;gap:8px;font-size:var(--text-sm, 12px);color:var(--body-text-color-subdued, #6b7280)}.media-control.svelte-outb32 select:where(.svelte-outb32){height:30px;border:1px solid var(--border-color-primary, #d1d5db);border-radius:var(--radius-sm, 4px);background:var(--background-fill-primary, white);color:var(--body-text-color, #1f2937);font-size:var(--text-sm, 12px);padding:0 28px 0 8px}.section-summary.svelte-outb32{display:flex;align-items:center;gap:6px;cursor:pointer;list-style:none;-webkit-user-select:none;user-select:none;padding:4px 0;margin-bottom:8px}.section-summary.svelte-outb32::-webkit-details-marker{display:none}.chevron.svelte-outb32{color:var(--body-text-color-subdued, #6b7280);transform:rotate(-90deg);transition:transform .15s ease;flex-shrink:0}details[open].svelte-outb32>.section-summary:where(.svelte-outb32) .chevron:where(.svelte-outb32){transform:rotate(0)}.section-title.svelte-outb32{font-size:var(--text-lg, 16px);font-weight:600;color:var(--body-text-color, #1f2937)}.media-label.svelte-outb32{font-size:var(--text-sm, 12px);font-weight:500;color:var(--body-text-color, #1f2937);word-break:break-word}.meta.svelte-outb32{display:flex;align-items:center;gap:3px;font-size:var(--text-xs, 11px);color:var(--body-text-color-subdued, #9ca3af);font-variant-numeric:tabular-nums}.meta.svelte-outb32 .run-dot:where(.svelte-outb32){width:8px;height:8px;border-radius:50%;flex-shrink:0;margin:0 2px}.meta-text.svelte-outb32{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.table-header.svelte-outb32{display:flex;align-items:center;justify-content:space-between;gap:12px;margin-bottom:6px}.runs-table.svelte-outb32{width:100%;border-collapse:collapse;font-size:var(--text-md, 14px)}.runs-table.svelte-outb32 th:where(.svelte-outb32){text-align:left;padding:8px 12px;border-bottom:2px solid var(--border-color-primary, #e5e7eb);color:var(--body-text-color-subdued, #6b7280);font-weight:600;font-size:var(--text-sm, 12px);text-transform:uppercase;letter-spacing:.05em}.runs-table.svelte-outb32 td:where(.svelte-outb32){padding:8px 12px;border-bottom:1px solid var(--border-color-primary, #e5e7eb);color:var(--body-text-color, #1f2937)}.runs-table.svelte-outb32 tbody:where(.svelte-outb32) tr:where(.svelte-outb32):nth-child(odd){background:var(--table-odd-background-fill, var(--background-fill-primary, white))}.runs-table.svelte-outb32 tbody:where(.svelte-outb32) tr:where(.svelte-outb32):nth-child(2n){background:var(--table-even-background-fill, var(--background-fill-secondary, #f9fafb))}.runs-table.svelte-outb32 tr:where(.svelte-outb32):hover{background:var(--background-fill-secondary, #f3f4f6)}.table-image-frame.svelte-outb32{position:relative;display:inline-flex;width:120px;height:80px;align-items:center;justify-content:center;overflow:hidden;border:0;border-radius:var(--radius-sm, 4px);background:var(--background-fill-secondary, #f3f4f6);color:var(--body-text-color-subdued, #6b7280);cursor:zoom-in;font:inherit;padding:0;text-decoration:none;vertical-align:top}.table-image-placeholder.svelte-outb32{position:absolute;top:0;right:0;bottom:0;left:0;display:grid;place-items:center;font-size:var(--text-xs, 11px)}.table-image-frame.svelte-outb32.image-loaded .table-image-placeholder:where(.svelte-outb32){display:none}.table-image-frame.svelte-outb32.image-failed .table-image-placeholder:where(.svelte-outb32){color:var(--error-text-color, #b91c1c)}.table-image.svelte-outb32{position:relative;z-index:1;max-height:80px;max-width:120px;border-radius:var(--radius-sm, 4px);display:block;object-fit:contain}.table-image-list.svelte-outb32{display:flex;flex-wrap:wrap;gap:4px}.gallery.svelte-outb32{display:grid;grid-template-columns:repeat(auto-fill,minmax(200px,1fr));gap:12px}.gallery-item.svelte-outb32{display:flex;flex-direction:column;gap:6px;padding:8px;border:1px solid var(--border-color-primary, #e5e7eb);border-radius:var(--radius-lg, 8px);background:var(--background-fill-secondary, #f9fafb);overflow:hidden}.image-frame.svelte-outb32{position:relative;display:block;width:100%;aspect-ratio:4 / 3;overflow:hidden;border:0;border-radius:var(--radius-sm, 4px);background:var(--background-fill-primary, #f3f4f6);color:var(--body-text-color-subdued, #6b7280);cursor:zoom-in;font:inherit;padding:0;text-decoration:none}.image-placeholder.svelte-outb32{position:absolute;top:0;right:0;bottom:0;left:0;display:grid;place-items:center;font-size:var(--text-sm, 12px)}.image-frame.svelte-outb32.image-loaded .image-placeholder:where(.svelte-outb32){display:none}.image-frame.svelte-outb32.image-failed .image-placeholder:where(.svelte-outb32){color:var(--error-text-color, #b91c1c)}.image-frame.svelte-outb32 img:where(.svelte-outb32){position:relative;z-index:1;width:100%;height:100%;display:block;object-fit:contain}.gallery-item.svelte-outb32 video:where(.svelte-outb32){width:100%;display:block;border-radius:var(--radius-sm, 4px)}.audio-gallery-item.svelte-outb32{justify-content:space-between}.caption.svelte-outb32{font-size:var(--text-sm, 12px);color:var(--body-text-color-subdued, #9ca3af)}.image-modal-backdrop.svelte-outb32{position:fixed;top:0;right:0;bottom:0;left:0;z-index:1000;display:flex;align-items:center;justify-content:center;padding:32px;background:#000000bf}.image-modal.svelte-outb32{position:relative;display:flex;max-width:min(92vw,1200px);max-height:92vh;flex-direction:column;overflow:hidden;border-radius:var(--radius-lg, 8px);background:var(--background-fill-primary, white);box-shadow:0 20px 60px #00000059}.image-modal-close.svelte-outb32{position:absolute;top:8px;right:8px;z-index:2;width:32px;height:32px;border:0;border-radius:999px;background:#0000008c;color:#fff;cursor:pointer;font-size:24px;line-height:1}.modal-image-frame.svelte-outb32{position:relative;display:grid;min-width:min(70vw,720px);min-height:min(65vh,520px);place-items:center;overflow:hidden;background:var(--background-fill-secondary, #f3f4f6);color:var(--body-text-color-subdued, #6b7280)}.modal-image-placeholder.svelte-outb32{position:absolute;top:0;right:0;bottom:0;left:0;display:grid;place-items:center;font-size:var(--text-sm, 12px)}.modal-image-frame.svelte-outb32.image-loaded .modal-image-placeholder:where(.svelte-outb32){display:none}.modal-image-frame.svelte-outb32.image-failed .modal-image-placeholder:where(.svelte-outb32){color:var(--error-text-color, #b91c1c)}.modal-image-frame.svelte-outb32 img:where(.svelte-outb32){position:relative;z-index:1;max-width:100%;max-height:calc(92vh - 96px);object-fit:contain}.image-modal-info.svelte-outb32{display:flex;flex-direction:column;gap:4px;padding:10px 14px 12px;text-align:center}.image-modal-title.svelte-outb32{font-size:var(--text-md, 14px);font-weight:600;color:var(--body-text-color, #1f2937)}.image-modal-caption.svelte-outb32{font-size:var(--text-sm, 12px);color:var(--body-text-color-subdued, #6b7280)}.image-modal-meta.svelte-outb32{justify-content:center}.table-section.svelte-outb32{margin-bottom:16px;overflow-x:auto}.pagination-row.svelte-outb32{display:flex;justify-content:center;align-items:center;gap:12px;margin-top:12px;font-size:var(--text-sm, 12px);color:var(--body-text-color-subdued, #6b7280)}.load-more-button.svelte-outb32{height:30px;border:1px solid var(--border-color-primary, #d1d5db);border-radius:var(--radius-sm, 4px);background:var(--background-fill-primary, white);color:var(--body-text-color, #1f2937);font-size:var(--text-sm, 12px);font-weight:500;padding:0 10px;cursor:pointer}.load-more-button.svelte-outb32:hover{background:var(--background-fill-secondary, #f9fafb)}.empty-state.svelte-outb32{max-width:640px;padding:40px 24px;color:var(--body-text-color, #1f2937)}.empty-state.svelte-outb32 h2:where(.svelte-outb32){margin:0 0 8px;font-size:20px;font-weight:700}.empty-state.svelte-outb32 p:where(.svelte-outb32){margin:12px 0 8px;color:var(--body-text-color-subdued, #6b7280)}.empty-state.svelte-outb32 pre:where(.svelte-outb32){background:var(--background-fill-secondary, #f9fafb);padding:16px;border-radius:var(--radius-lg, 8px);border:1px solid var(--border-color-primary, #e5e7eb);font-size:13px;overflow-x:auto}.empty-state.svelte-outb32 code:where(.svelte-outb32){background:var(--background-fill-secondary, #f0f0f0);padding:1px 5px;border-radius:var(--radius-sm, 4px);font-size:13px}.empty-state.svelte-outb32 pre:where(.svelte-outb32) code:where(.svelte-outb32){background:none;padding:0}.reports-page.svelte-iufsej{padding:20px 24px;overflow-y:auto;flex:1}.controls.svelte-iufsej{display:flex;gap:16px;margin-bottom:16px;flex-wrap:wrap;align-items:flex-end}.control.svelte-iufsej{min-width:200px}.filter-pills.svelte-iufsej{display:flex;gap:4px}.pill.svelte-iufsej{border:1px solid var(--border-color-primary, #e5e7eb);border-radius:var(--radius-xxl, 22px);padding:4px 12px;font-size:var(--text-sm, 12px);background:var(--background-fill-secondary, #f9fafb);color:var(--body-text-color-subdued, #6b7280);cursor:pointer;transition:background-color .15s,color .15s}.pill.svelte-iufsej:hover{background:var(--neutral-100, #f3f4f6)}.pill.active.svelte-iufsej{background:var(--color-accent, #f97316);color:#fff;border-color:var(--color-accent, #f97316)}.empty-state.svelte-iufsej{max-width:640px;padding:40px 24px;color:var(--body-text-color, #1f2937)}.empty-state.svelte-iufsej h2:where(.svelte-iufsej){margin:0 0 8px;font-size:20px;font-weight:700}.empty-state.svelte-iufsej p:where(.svelte-iufsej){margin:12px 0 8px;color:var(--body-text-color-subdued, #6b7280)}.empty-state.svelte-iufsej pre:where(.svelte-iufsej){background:var(--background-fill-secondary, #f9fafb);padding:16px;border-radius:var(--radius-lg, 8px);border:1px solid var(--border-color-primary, #e5e7eb);font-size:13px;overflow-x:auto}.empty-state.svelte-iufsej code:where(.svelte-iufsej){background:var(--background-fill-secondary, #f0f0f0);padding:1px 5px;border-radius:var(--radius-sm, 4px);font-size:13px}.empty-state.svelte-iufsej pre:where(.svelte-iufsej) code:where(.svelte-iufsej){background:none;padding:0}.alerts-table.svelte-iufsej{width:100%;border-collapse:collapse;font-size:var(--text-md, 14px)}.alerts-table.svelte-iufsej th:where(.svelte-iufsej){text-align:left;padding:8px 12px;border-bottom:2px solid var(--border-color-primary, #e5e7eb);color:var(--body-text-color-subdued, #6b7280);font-weight:600;font-size:var(--text-sm, 12px);text-transform:uppercase;letter-spacing:.05em}.alerts-table.svelte-iufsej td:where(.svelte-iufsej){padding:8px 12px;border-bottom:1px solid var(--border-color-primary, #e5e7eb);color:var(--body-text-color, #1f2937)}.alerts-table.svelte-iufsej tbody:where(.svelte-iufsej) tr:where(.svelte-iufsej):nth-child(odd){background:var(--table-odd-background-fill, var(--background-fill-primary, white))}.alerts-table.svelte-iufsej tbody:where(.svelte-iufsej) tr:where(.svelte-iufsej):nth-child(2n){background:var(--table-even-background-fill, var(--background-fill-secondary, #f9fafb))}.alerts-table.svelte-iufsej tr:where(.svelte-iufsej):hover{background:var(--background-fill-secondary, #f3f4f6)}.section-title.svelte-iufsej{font-size:16px;font-weight:700;margin:0 0 12px;color:var(--body-text-color, #1f2937)}.reports-section.svelte-iufsej,.alerts-section.svelte-iufsej{margin-bottom:32px}.report-card.svelte-iufsej{border:1px solid var(--border-color-primary, #e5e7eb);border-radius:var(--radius-lg, 8px);padding:16px 20px;margin-bottom:12px;background:var(--background-fill-primary, white)}.report-meta.svelte-iufsej{font-size:var(--text-sm, 12px);color:var(--body-text-color-subdued, #6b7280);margin-bottom:8px}.report-content.svelte-iufsej{font-size:var(--text-md, 14px);color:var(--body-text-color, #1f2937);line-height:1.6}.report-content.svelte-iufsej h2{font-size:18px;font-weight:700;margin:0 0 8px}.report-content.svelte-iufsej h3{font-size:16px;font-weight:600;margin:12px 0 6px}.report-content.svelte-iufsej h4{font-size:14px;font-weight:600;margin:10px 0 4px}.report-content.svelte-iufsej code{background:var(--background-fill-secondary, #f0f0f0);padding:1px 5px;border-radius:var(--radius-sm, 4px);font-size:13px}.report-content.svelte-iufsej ul{margin:4px 0;padding-left:20px}.report-content.svelte-iufsej li{margin:2px 0}.report-content.svelte-iufsej p{margin:6px 0}.filter-empty.svelte-iufsej{color:var(--body-text-color-subdued, #6b7280);font-size:var(--text-md, 14px)}.runs-page.svelte-1yb6d54{padding:20px 24px;overflow-y:auto;flex:1}.empty-state.svelte-1yb6d54{max-width:640px;padding:40px 24px;color:var(--body-text-color, #1f2937)}.empty-state.svelte-1yb6d54 h2:where(.svelte-1yb6d54){margin:0 0 8px;font-size:20px;font-weight:700}.empty-state.svelte-1yb6d54 p:where(.svelte-1yb6d54){margin:12px 0 8px;color:var(--body-text-color-subdued, #6b7280)}.empty-state.svelte-1yb6d54 pre:where(.svelte-1yb6d54){background:var(--background-fill-secondary, #f9fafb);padding:16px;border-radius:var(--radius-lg, 8px);border:1px solid var(--border-color-primary, #e5e7eb);font-size:13px;overflow-x:auto}.empty-state.svelte-1yb6d54 code:where(.svelte-1yb6d54){background:var(--background-fill-secondary, #f0f0f0);padding:1px 5px;border-radius:var(--radius-sm, 4px);font-size:13px}.empty-state.svelte-1yb6d54 pre:where(.svelte-1yb6d54) code:where(.svelte-1yb6d54){background:none;padding:0}.filter-count-row.svelte-1yb6d54{margin-bottom:12px}.filter-count.svelte-1yb6d54{font-size:var(--text-sm, 12px);color:var(--body-text-color-subdued, #6b7280)}.runs-table.svelte-1yb6d54{width:100%;border-collapse:collapse;font-size:var(--text-md, 14px)}.runs-table.svelte-1yb6d54 th:where(.svelte-1yb6d54){text-align:left;padding:8px 12px;border-bottom:2px solid var(--border-color-primary, #e5e7eb);color:var(--body-text-color-subdued, #6b7280);font-weight:600;font-size:var(--text-sm, 12px);text-transform:uppercase;letter-spacing:.05em}.runs-table.svelte-1yb6d54 td:where(.svelte-1yb6d54){padding:8px 12px;border-bottom:1px solid var(--border-color-primary, #e5e7eb);color:var(--body-text-color, #1f2937)}.runs-table.svelte-1yb6d54 tbody:where(.svelte-1yb6d54) tr:where(.svelte-1yb6d54):nth-child(odd){background:var(--table-odd-background-fill, var(--background-fill-primary, white))}.runs-table.svelte-1yb6d54 tbody:where(.svelte-1yb6d54) tr:where(.svelte-1yb6d54):nth-child(2n){background:var(--table-even-background-fill, var(--background-fill-secondary, #f9fafb))}.runs-table.svelte-1yb6d54 tr:where(.svelte-1yb6d54):hover{background:var(--background-fill-secondary, #f3f4f6)}.run-name-cell.svelte-1yb6d54{font-weight:500}.run-name-with-dot.svelte-1yb6d54{display:inline-flex;align-items:center;gap:8px;max-width:100%}.run-dot.svelte-1yb6d54{width:10px;height:10px;border-radius:50%;flex-shrink:0}.link-btn.svelte-1yb6d54{background:none;border:none;color:var(--color-accent, #f97316);cursor:pointer;font:inherit;font-weight:500;padding:0;text-align:left}.link-btn.svelte-1yb6d54:hover{text-decoration:underline}.rename-input.svelte-1yb6d54{font:inherit;padding:2px 6px;border:1px solid var(--color-accent, #f97316);border-radius:var(--radius-sm, 4px);outline:none;width:100%}.actions-wrap.svelte-1yb6d54{display:flex;gap:4px;align-items:center}.action-btn.svelte-1yb6d54{background:none;border:1px solid transparent;color:var(--body-text-color-subdued, #6b7280);cursor:pointer;padding:4px;border-radius:var(--radius-sm, 4px);display:flex;align-items:center}.action-btn.svelte-1yb6d54:hover{background:var(--background-fill-secondary, #f9fafb);border-color:var(--border-color-primary, #e5e7eb);color:var(--body-text-color, #1f2937)}.delete-btn.svelte-1yb6d54:hover{color:#dc2626;border-color:#fecaca;background:#fef2f2}.action-btn.svelte-1yb6d54:disabled{opacity:.45;cursor:not-allowed;pointer-events:none}.run-detail-page.svelte-1bpgsx2{padding:20px 24px;overflow-y:auto;flex:1}.detail-card.svelte-1bpgsx2{background:var(--background-fill-primary, white);border:1px solid var(--border-color-primary, #e5e7eb);border-radius:var(--radius-lg, 8px);padding:24px;max-width:800px}.detail-card.svelte-1bpgsx2 h2:where(.svelte-1bpgsx2){color:var(--body-text-color, #1f2937);margin:0 0 16px;font-size:var(--text-xl, 22px)}.detail-card.svelte-1bpgsx2 h3:where(.svelte-1bpgsx2){color:var(--body-text-color, #1f2937);margin:20px 0 8px;font-size:var(--text-lg, 16px)}.detail-grid.svelte-1bpgsx2{display:grid;grid-template-columns:repeat(auto-fill,minmax(200px,1fr));gap:12px}.detail-item.svelte-1bpgsx2{display:flex;flex-direction:column;gap:2px}.detail-label.svelte-1bpgsx2{font-size:var(--text-xs, 10px);font-weight:600;color:var(--body-text-color-subdued, #9ca3af);text-transform:uppercase}.detail-value.svelte-1bpgsx2{font-size:var(--text-md, 14px);color:var(--body-text-color, #1f2937)}.config-block.svelte-1bpgsx2{background:var(--background-fill-secondary, #f9fafb);padding:12px;border-radius:var(--radius-lg, 8px);border:1px solid var(--border-color-primary, #e5e7eb);font-size:var(--text-sm, 12px);color:var(--body-text-color, #1f2937);overflow-x:auto}.empty-state.svelte-1bpgsx2{max-width:640px;padding:40px 24px;color:var(--body-text-color, #1f2937)}.empty-state.svelte-1bpgsx2 h2:where(.svelte-1bpgsx2){margin:0 0 8px;font-size:20px;font-weight:700}.empty-state.svelte-1bpgsx2 p:where(.svelte-1bpgsx2){margin:12px 0 8px;color:var(--body-text-color-subdued, #6b7280)}.empty-state.svelte-1bpgsx2 pre:where(.svelte-1bpgsx2){background:var(--background-fill-secondary, #f9fafb);padding:16px;border-radius:var(--radius-lg, 8px);border:1px solid var(--border-color-primary, #e5e7eb);font-size:13px;overflow-x:auto}.empty-state.svelte-1bpgsx2 code:where(.svelte-1bpgsx2){background:var(--background-fill-secondary, #f0f0f0);padding:1px 5px;border-radius:var(--radius-sm, 4px);font-size:13px}.empty-state.svelte-1bpgsx2 pre:where(.svelte-1bpgsx2) code:where(.svelte-1bpgsx2){background:none;padding:0}.files-page.svelte-1xvfk9n{padding:20px 24px;overflow-y:auto;flex:1}.page-title.svelte-1xvfk9n{color:var(--body-text-color, #1f2937);font-size:16px;font-weight:700;margin:0 0 4px}.page-subtitle.svelte-1xvfk9n{color:var(--body-text-color-subdued, #6b7280);font-size:var(--text-sm, 12px);margin:0 0 16px}.file-list.svelte-1xvfk9n{display:flex;flex-direction:column;gap:4px}.file-item.svelte-1xvfk9n{border:1px solid var(--border-color-primary, #e5e7eb);border-radius:var(--radius-lg, 8px);background:var(--background-fill-primary, white);overflow:hidden}.file-item.expanded.svelte-1xvfk9n{border-color:var(--color-accent, #f97316)}.file-row.svelte-1xvfk9n{display:flex;align-items:center;justify-content:space-between;padding:10px 14px;gap:12px}.file-name.svelte-1xvfk9n{display:flex;align-items:center;gap:8px;background:none;border:none;padding:0;font-size:var(--text-md, 14px);color:var(--body-text-color, #1f2937);cursor:pointer;text-align:left}.file-name.svelte-1xvfk9n:hover{color:var(--color-accent, #f97316)}.file-icon.svelte-1xvfk9n{font-size:14px;flex-shrink:0}.file-actions.svelte-1xvfk9n{display:flex;align-items:center;gap:12px;flex-shrink:0}.file-size.svelte-1xvfk9n{font-size:var(--text-sm, 12px);color:var(--body-text-color-subdued, #6b7280);white-space:nowrap}.download-btn.svelte-1xvfk9n{display:flex;align-items:center;justify-content:center;width:28px;height:28px;border-radius:var(--radius-md, 6px);color:var(--body-text-color-subdued, #6b7280);transition:background-color .15s,color .15s}.download-btn.svelte-1xvfk9n:hover{background:var(--background-fill-secondary, #f3f4f6);color:var(--body-text-color, #1f2937)}.file-preview.svelte-1xvfk9n{border-top:1px solid var(--border-color-primary, #e5e7eb);padding:12px 14px;background:var(--background-fill-secondary, #f9fafb)}.preview-code.svelte-1xvfk9n{margin:0;font-size:12px;line-height:1.5;max-height:400px;overflow:auto;white-space:pre-wrap;word-break:break-all;color:var(--body-text-color, #1f2937)}.preview-loading.svelte-1xvfk9n,.preview-unavailable.svelte-1xvfk9n{color:var(--body-text-color-subdued, #6b7280);font-size:var(--text-sm, 12px);padding:8px 0}.preview-unavailable.svelte-1xvfk9n a:where(.svelte-1xvfk9n){color:var(--color-accent, #f97316);text-decoration:none}.preview-unavailable.svelte-1xvfk9n a:where(.svelte-1xvfk9n):hover{text-decoration:underline}.empty-state.svelte-1xvfk9n{max-width:640px;padding:40px 24px;color:var(--body-text-color, #1f2937)}.empty-state.svelte-1xvfk9n h2:where(.svelte-1xvfk9n){margin:0 0 8px;font-size:20px;font-weight:700}.empty-state.svelte-1xvfk9n p:where(.svelte-1xvfk9n){margin:12px 0 8px;color:var(--body-text-color-subdued, #6b7280)}.empty-state.svelte-1xvfk9n pre:where(.svelte-1xvfk9n){background:var(--background-fill-secondary, #f9fafb);padding:16px;border-radius:var(--radius-lg, 8px);border:1px solid var(--border-color-primary, #e5e7eb);font-size:13px;overflow-x:auto}.empty-state.svelte-1xvfk9n code:where(.svelte-1xvfk9n){background:var(--background-fill-secondary, #f0f0f0);padding:1px 5px;border-radius:var(--radius-sm, 4px);font-size:13px}.empty-state.svelte-1xvfk9n pre:where(.svelte-1xvfk9n) code:where(.svelte-1xvfk9n){background:none;padding:0}.settings-page.svelte-1ozf5k3{padding:24px 32px;overflow-y:auto;flex:1}.page-title.svelte-1ozf5k3{color:var(--body-text-color, #1f2937);font-size:18px;font-weight:700;margin:0 0 24px}.two-col.svelte-1ozf5k3{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1fr);gap:32px;align-items:start}@media(max-width:900px){.two-col.svelte-1ozf5k3{grid-template-columns:1fr}}.settings-section.svelte-1ozf5k3{margin-bottom:32px}.section-title.svelte-1ozf5k3{color:var(--body-text-color, #1f2937);font-size:15px;font-weight:600;margin:0 0 4px}.section-desc.svelte-1ozf5k3{color:var(--body-text-color-subdued, #6b7280);font-size:var(--text-sm, 12px);margin:0 0 12px;line-height:1.5}.section-desc.svelte-1ozf5k3 code:where(.svelte-1ozf5k3){background:var(--background-fill-secondary, #f3f4f6);padding:1px 5px;border-radius:var(--radius-sm, 3px);font-size:11px}.section-desc.svelte-1ozf5k3 strong:where(.svelte-1ozf5k3){color:var(--color-accent, #f97316)}.theme-switcher.svelte-1ozf5k3{display:inline-flex;border:1px solid var(--border-color-primary, #e5e7eb);border-radius:var(--radius-lg, 8px);overflow:hidden}.theme-option.svelte-1ozf5k3{display:inline-flex;align-items:center;gap:6px;padding:8px 20px;border:none;background:var(--background-fill-primary, white);color:var(--body-text-color-subdued, #6b7280);font-size:var(--text-md, 14px);cursor:pointer;transition:all .15s;border-right:1px solid var(--border-color-primary, #e5e7eb)}.theme-option.svelte-1ozf5k3:last-child{border-right:none}.theme-option.svelte-1ozf5k3:hover{color:var(--body-text-color, #1f2937);background:var(--background-fill-secondary, #f9fafb)}.theme-option.selected.svelte-1ozf5k3{background:var(--color-accent, #f97316);color:#fff;font-weight:500}.project-selector.svelte-1ozf5k3{display:flex;align-items:center;gap:10px;margin-bottom:12px}.selector-label.svelte-1ozf5k3{font-size:var(--text-sm, 12px);color:var(--body-text-color-subdued, #6b7280);flex-shrink:0}.selector-select.svelte-1ozf5k3{padding:6px 10px;border:1px solid var(--border-color-primary, #e5e7eb);border-radius:var(--radius-md, 4px);background:var(--background-fill-primary, white);color:var(--body-text-color, #1f2937);font-size:var(--text-sm, 12px);min-width:160px;cursor:pointer}.selector-select.svelte-1ozf5k3:focus{outline:none;border-color:var(--color-accent, #f97316)}.commands-table.svelte-1ozf5k3{border:1px solid var(--border-color-primary, #e5e7eb);border-radius:var(--radius-lg, 8px);overflow:hidden}.command-row.svelte-1ozf5k3{display:flex;align-items:center;gap:16px;padding:10px 14px;border-bottom:1px solid var(--border-color-primary, #e5e7eb)}.command-row.svelte-1ozf5k3:last-child{border-bottom:none}.command-label.svelte-1ozf5k3{width:180px;flex-shrink:0;font-size:var(--text-sm, 12px);color:var(--body-text-color-subdued, #6b7280)}.command-value.svelte-1ozf5k3{flex:1;display:flex;align-items:center;gap:8px;min-width:0}.command-value.svelte-1ozf5k3 code:where(.svelte-1ozf5k3){flex:1;font-family:SFMono-Regular,Consolas,Liberation Mono,Menlo,monospace;font-size:12px;color:var(--body-text-color, #1f2937);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.copy-btn.svelte-1ozf5k3{display:flex;align-items:center;justify-content:center;width:26px;height:26px;flex-shrink:0;border:none;background:none;border-radius:var(--radius-md, 4px);color:var(--body-text-color-subdued, #6b7280);cursor:pointer;transition:background-color .15s,color .15s}.copy-btn.svelte-1ozf5k3:hover{background:var(--background-fill-secondary, #f3f4f6);color:var(--body-text-color, #1f2937)}.copy-btn.copied.svelte-1ozf5k3{color:var(--color-accent, #f97316)}.agent-tabs.svelte-1ozf5k3{display:flex;border-bottom:1px solid var(--border-color-primary, #e5e7eb);gap:0;margin-bottom:0}.agent-tab.svelte-1ozf5k3{padding:8px 16px;border:none;background:none;color:var(--body-text-color-subdued, #6b7280);font-size:var(--text-sm, 12px);cursor:pointer;border-bottom:2px solid transparent;transition:all .15s;white-space:nowrap}.agent-tab.svelte-1ozf5k3:hover{color:var(--body-text-color, #1f2937)}.agent-tab.active.svelte-1ozf5k3{color:var(--color-accent, #f97316);border-bottom-color:var(--color-accent, #f97316);font-weight:500}.agent-panel.svelte-1ozf5k3{border:1px solid var(--border-color-primary, #e5e7eb);border-top:none;border-radius:0 0 var(--radius-lg, 8px) var(--radius-lg, 8px);padding:16px}.install-block.svelte-1ozf5k3{margin-bottom:16px}.install-label.svelte-1ozf5k3{display:block;font-size:11px;font-weight:500;color:var(--body-text-color-subdued, #6b7280);text-transform:uppercase;letter-spacing:.04em;margin-bottom:6px}.install-cmd.svelte-1ozf5k3{display:flex;align-items:center;gap:8px;background:var(--background-fill-secondary, #f3f4f6);border-radius:var(--radius-md, 4px);padding:8px 10px}.install-cmd.svelte-1ozf5k3 code:where(.svelte-1ozf5k3){flex:1;font-family:SFMono-Regular,Consolas,Liberation Mono,Menlo,monospace;font-size:12px;color:var(--body-text-color, #1f2937);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.example-block.svelte-1ozf5k3{background:var(--background-fill-secondary, #f9fafb);border:1px solid var(--border-color-primary, #e5e7eb);border-radius:var(--radius-md, 4px);padding:12px}.example-header.svelte-1ozf5k3{display:flex;align-items:center;justify-content:space-between;margin-bottom:8px}.example-label.svelte-1ozf5k3{font-size:11px;font-weight:500;color:var(--body-text-color-subdued, #6b7280);text-transform:uppercase;letter-spacing:.04em}.example-text.svelte-1ozf5k3{margin:0;font-size:var(--text-sm, 12px);color:var(--body-text-color, #1f2937);line-height:1.6;font-style:italic}*{margin:0;padding:0;box-sizing:border-box}body{font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,sans-serif;background:var(--background-fill-primary, #fff);color:var(--body-text-color, #1f2937);font-size:var(--text-md, 14px);-webkit-font-smoothing:antialiased}.app.svelte-1n46o8q{display:flex;height:100vh;overflow:hidden}.main.svelte-1n46o8q{flex:1;display:flex;flex-direction:column;overflow:hidden;min-width:0}.page-content.svelte-1n46o8q{flex:1;overflow:hidden;display:flex;background:var(--bg-primary)} diff --git a/trackio/frontend/dist/index.html b/trackio/frontend/dist/index.html new file mode 100644 index 0000000000000000000000000000000000000000..b6cbc00c297af33fc250a897a508f36360897b1d --- /dev/null +++ b/trackio/frontend/dist/index.html @@ -0,0 +1,14 @@ + + + + + + Trackio Dashboard + + + + + +
        + + diff --git a/trackio/frontend/eslint.config.js b/trackio/frontend/eslint.config.js new file mode 100644 index 0000000000000000000000000000000000000000..c0bd968851d9ee35d98943b9c2b04b91af245322 --- /dev/null +++ b/trackio/frontend/eslint.config.js @@ -0,0 +1,42 @@ +import js from "@eslint/js"; +import svelte from "eslint-plugin-svelte"; +import svelteParser from "svelte-eslint-parser"; +import globals from "globals"; + +export default [ + { ignores: ["dist/**", "node_modules/**"] }, + { + files: ["**/*.js"], + languageOptions: { + globals: { + ...globals.browser, + ...globals.es2021, + $state: "readonly", + $derived: "readonly", + $effect: "readonly", + $props: "readonly", + $bindable: "readonly", + $inspect: "readonly", + }, + }, + rules: { + ...js.configs.recommended.rules, + "no-unused-vars": ["error", { argsIgnorePattern: "^_" }], + "no-empty": "off", + }, + }, + { + files: ["**/*.svelte"], + languageOptions: { + parser: svelteParser, + globals: { ...globals.browser, ...globals.es2021 }, + }, + plugins: { svelte }, + rules: { + ...js.configs.recommended.rules, + ...svelte.configs.recommended.rules, + "no-unused-vars": ["error", { argsIgnorePattern: "^_", varsIgnorePattern: "^\\$" }], + "no-empty": "off", + }, + }, +]; diff --git a/trackio/frontend/index.html b/trackio/frontend/index.html new file mode 100644 index 0000000000000000000000000000000000000000..c3d5e2df6bb7db117ed1d554ea7d8d180b076799 --- /dev/null +++ b/trackio/frontend/index.html @@ -0,0 +1,13 @@ + + + + + + Trackio Dashboard + + + +
        + + + diff --git a/trackio/frontend_config.py b/trackio/frontend_config.py new file mode 100644 index 0000000000000000000000000000000000000000..cd40a82e907f7d88dbf9335dc341f999f206f5f0 --- /dev/null +++ b/trackio/frontend_config.py @@ -0,0 +1,175 @@ +import json +import os +import shutil +from dataclasses import dataclass +from pathlib import Path + +from huggingface_hub.constants import HF_HOME + +TRACKIO_USER_HOME = Path(HF_HOME) / "trackio" +TRACKIO_CONFIG_PATH = TRACKIO_USER_HOME / "config.json" +BUNDLED_FRONTEND_DIR = Path(__file__).parent / "frontend" / "dist" +STARTER_FRONTEND_DIR = Path(__file__).parent / "frontend_templates" / "starter" + + +@dataclass(frozen=True) +class ResolvedFrontend: + path: Path + source: str + is_custom: bool + used_fallback: bool = False + requested_path: Path | None = None + + +def _normalize_frontend_path(path: str | Path) -> Path: + return Path(path).expanduser().resolve() + + +def is_valid_frontend_dir(path: str | Path | None) -> bool: + if path is None: + return False + frontend_dir = _normalize_frontend_path(path) + return frontend_dir.is_dir() and (frontend_dir / "index.html").is_file() + + +def _is_empty_directory(path: Path) -> bool: + return path.is_dir() and not any(path.iterdir()) + + +def _copy_starter_template(destination: Path) -> None: + destination.mkdir(parents=True, exist_ok=True) + for child in STARTER_FRONTEND_DIR.iterdir(): + target = destination / child.name + if child.is_dir(): + shutil.copytree(child, target, dirs_exist_ok=True) + else: + shutil.copy2(child, target) + + +def _materialize_argument_frontend_dir(candidate: Path) -> bool: + existed_before = candidate.exists() + if existed_before and not _is_empty_directory(candidate): + return False + + _copy_starter_template(candidate) + state = "did not exist" if not existed_before else "was empty" + print( + f"* Trackio frontend directory from argument {state}: {candidate}. " + "Copied the starter template into it and serving that directory." + ) + return True + + +def load_trackio_config() -> dict: + if not TRACKIO_CONFIG_PATH.is_file(): + return {} + try: + data = json.loads(TRACKIO_CONFIG_PATH.read_text()) + except (json.JSONDecodeError, OSError): + return {} + return data if isinstance(data, dict) else {} + + +def save_trackio_config(config: dict) -> None: + TRACKIO_USER_HOME.mkdir(parents=True, exist_ok=True) + TRACKIO_CONFIG_PATH.write_text(json.dumps(config, indent=2, sort_keys=True) + "\n") + + +def get_persisted_frontend_dir() -> Path | None: + frontend_dir = load_trackio_config().get("frontend_dir") + if not frontend_dir: + return None + return _normalize_frontend_path(frontend_dir) + + +def set_persisted_frontend_dir(path: str | Path) -> Path: + frontend_dir = _normalize_frontend_path(path) + if not is_valid_frontend_dir(frontend_dir): + raise ValueError( + f"Invalid frontend directory: {frontend_dir}. Expected a directory containing index.html." + ) + config = load_trackio_config() + config["frontend_dir"] = str(frontend_dir) + save_trackio_config(config) + return frontend_dir + + +def unset_persisted_frontend_dir() -> bool: + config = load_trackio_config() + if "frontend_dir" not in config: + return False + del config["frontend_dir"] + if config: + save_trackio_config(config) + elif TRACKIO_CONFIG_PATH.exists(): + TRACKIO_CONFIG_PATH.unlink() + return True + + +def _configured_frontend_candidates( + frontend_dir: str | Path | None, +) -> list[tuple[str, Path]]: + candidates: list[tuple[str, Path]] = [] + if frontend_dir is not None: + candidates.append(("argument", _normalize_frontend_path(frontend_dir))) + env_dir = os.environ.get("TRACKIO_FRONTEND_DIR") + if env_dir: + candidates.append(("env", _normalize_frontend_path(env_dir))) + persisted_dir = get_persisted_frontend_dir() + if persisted_dir is not None: + candidates.append(("config", persisted_dir)) + return candidates + + +def _announce_config_frontend(frontend_dir: Path) -> None: + print( + f"* Using Trackio custom frontend from config: {frontend_dir}\n" + " Reset with `trackio config unset frontend`." + ) + + +def resolve_frontend_dir( + frontend_dir: str | Path | None = None, + *, + announce: bool = False, +) -> ResolvedFrontend: + for source, candidate in _configured_frontend_candidates(frontend_dir): + if source == "argument": + if not candidate.exists() or _is_empty_directory(candidate): + _materialize_argument_frontend_dir(candidate) + + if is_valid_frontend_dir(candidate): + if source == "config" and announce: + _announce_config_frontend(candidate) + return ResolvedFrontend( + path=candidate, + source=source, + is_custom=True, + ) + if source == "argument": + print( + f"* Trackio frontend from {source} is invalid: {candidate}. " + f"Falling back to starter template at {STARTER_FRONTEND_DIR}." + ) + return ResolvedFrontend( + path=STARTER_FRONTEND_DIR, + source="starter", + is_custom=True, + used_fallback=True, + requested_path=candidate, + ) + print(f"* Trackio frontend from {source} is invalid: {candidate}. Ignoring it.") + + if is_valid_frontend_dir(BUNDLED_FRONTEND_DIR): + return ResolvedFrontend( + path=BUNDLED_FRONTEND_DIR, + source="bundled", + is_custom=False, + ) + + return ResolvedFrontend( + path=STARTER_FRONTEND_DIR, + source="starter", + is_custom=True, + used_fallback=True, + ) diff --git a/trackio/frontend_server.py b/trackio/frontend_server.py new file mode 100644 index 0000000000000000000000000000000000000000..c8b27c697617fa4af5f021badb39250b5bd9ba99 --- /dev/null +++ b/trackio/frontend_server.py @@ -0,0 +1,145 @@ +"""Serves a static frontend alongside the Trackio HTTP API.""" + +import hashlib +import logging +from pathlib import Path + +from starlette.middleware.base import BaseHTTPMiddleware +from starlette.responses import FileResponse, HTMLResponse, JSONResponse +from starlette.routing import Mount, Route +from starlette.staticfiles import StaticFiles + +ASSETS_DIR = Path(__file__).parent / "assets" + +_logger = logging.getLogger(__name__) + +_LIVE_RELOAD_SCRIPT = """ + +""".strip() + + +def _frontend_version(frontend_root: Path) -> str: + digest = hashlib.sha256() + for path in sorted(frontend_root.rglob("*")): + if not path.is_file(): + continue + relative = path.relative_to(frontend_root) + digest.update(str(relative).encode("utf-8")) + stat = path.stat() + digest.update(str(stat.st_mtime_ns).encode("utf-8")) + digest.update(str(stat.st_size).encode("utf-8")) + return digest.hexdigest() + + +def _inject_live_reload(html: str) -> str: + if "/__trackio/frontend_version" in html: + return html + if "" in html: + return html.replace("", f"{_LIVE_RELOAD_SCRIPT}\n ") + return html + _LIVE_RELOAD_SCRIPT + + +def _html_response(path: Path) -> HTMLResponse: + html = path.read_text(encoding="utf-8") + return HTMLResponse(_inject_live_reload(html)) + + +class FrontendMiddleware(BaseHTTPMiddleware): + def __init__(self, app, frontend_root: Path, index_html_path: Path): + super().__init__(app) + self.frontend_root = frontend_root + self.index_html_path = index_html_path + self.reserved_prefixes = ( + "/api/", + "/file", + "/version", + "/static/trackio", + "/__trackio/frontend_version", + "/oauth/", + "/login/", + "/mcp", + ) + self.reserved_exact = { + "/api", + "/oauth", + "/login", + } + + async def dispatch(self, request, call_next): + if request.method not in {"GET", "HEAD"}: + return await call_next(request) + + path = request.url.path + if path in self.reserved_exact or path.startswith(self.reserved_prefixes): + return await call_next(request) + + relative_path = path.lstrip("/") + requested_path = (self.frontend_root / relative_path).resolve() + if ( + relative_path + and requested_path.is_file() + and requested_path.is_relative_to(self.frontend_root) + ): + if requested_path.suffix.lower() == ".html": + return _html_response(requested_path) + return FileResponse(requested_path) + + return _html_response(self.index_html_path) + + +def mount_frontend(app, frontend_dir: str | Path): + frontend_root = Path(frontend_dir).resolve() + if not frontend_root.exists(): + _logger.warning( + "Trackio dashboard UI was not mounted: %s is missing. " + "Build the frontend or provide a custom frontend directory.", + frontend_root, + ) + return + + index_html_path = frontend_root / "index.html" + if not index_html_path.exists(): + _logger.warning( + "Trackio dashboard UI was not mounted: %s is missing.", + index_html_path, + ) + return + + async def frontend_version(_request): + return JSONResponse({"version": _frontend_version(frontend_root)}) + + static_assets = StaticFiles(directory=str(ASSETS_DIR)) + + app.add_middleware( + FrontendMiddleware, + frontend_root=frontend_root, + index_html_path=index_html_path, + ) + app.routes.append(Mount("/static/trackio", app=static_assets)) + app.routes.append( + Route("/__trackio/frontend_version", frontend_version, methods=["GET"]) + ) diff --git a/trackio/frontend_templates/starter/app.js b/trackio/frontend_templates/starter/app.js new file mode 100644 index 0000000000000000000000000000000000000000..52dd7083d662e8a755328d86b24bf21f856546e6 --- /dev/null +++ b/trackio/frontend_templates/starter/app.js @@ -0,0 +1,555 @@ +const projectSelectEl = document.querySelector("#project-select"); +const runListEl = document.querySelector("#run-list"); +const metricsTitleEl = document.querySelector("#metrics-title"); +const metricsSubtitleEl = document.querySelector("#metrics-subtitle"); +const metricsGridEl = document.querySelector("#metrics-grid"); +const tracesSubtitleEl = document.querySelector("#traces-subtitle"); +const tracesBodyEl = document.querySelector("#traces-body"); +const navButtons = Array.from(document.querySelectorAll(".nav-link")); +const pages = Array.from(document.querySelectorAll(".page")); + +const state = { + projects: [], + selectedProject: null, + runs: [], + selectedRunIds: [], +}; + +/* +Trackio routes used by this starter today: +- /api/get_all_projects +- /api/get_runs_for_project +- /api/get_metrics_for_run +- /api/get_metric_values +- /api/get_traces + +Useful routes for expanding this starter toward the full dashboard: +- /api/get_system_metrics_for_run +- /api/get_system_logs +- /api/get_system_logs_batch +- /api/get_logs +- /api/get_logs_batch +- /api/get_snapshot +- /api/get_alerts +- /api/query_project +- /api/get_project_summary +- /api/get_run_summary +- /api/get_project_files +- /api/get_settings +- /api/get_run_mutation_status +- /api/delete_run +- /api/rename_run +- /api/force_sync +- /api/bulk_upload_media +- /api/upload + +File/media URLs: +- /file?path=ABSOLUTE_PATH_FROM_API +*/ +const RUN_COLORS = [ + "#1f77b4", + "#ff7f0e", + "#2ca02c", + "#d62728", + "#9467bd", + "#8c564b", + "#e377c2", + "#7f7f7f", + "#bcbd22", + "#17becf", +]; + +async function api(name, payload = {}) { + const response = await fetch(`/api/${name}`, { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify(payload), + }); + const json = await response.json(); + if (!response.ok || json.error) { + throw new Error(json.error || `Request failed for ${name}`); + } + return json.data; +} + +function runKey(run) { + return run.id || run.name; +} + +function colorForRun(run) { + const index = state.runs.findIndex((candidate) => runKey(candidate) === runKey(run)); + return RUN_COLORS[((index >= 0 ? index : 0) % RUN_COLORS.length + RUN_COLORS.length) % RUN_COLORS.length]; +} + +function formatValue(value) { + if (typeof value !== "number" || !Number.isFinite(value)) { + return String(value); + } + if (Math.abs(value) >= 1000 || Math.abs(value) < 0.01) { + return value.toExponential(2); + } + return value.toFixed(3); +} + +function getQueryParams() { + return new URLSearchParams(window.location.search); +} + +function setQueryParams(params) { + const next = new URL(window.location.href); + for (const [key, value] of Object.entries(params)) { + if (value == null || value === "" || (Array.isArray(value) && value.length === 0)) { + next.searchParams.delete(key); + continue; + } + next.searchParams.set(key, Array.isArray(value) ? value.join(",") : value); + } + window.history.replaceState({}, "", next); +} + +function setActivePage(pageName) { + navButtons.forEach((button) => { + button.classList.toggle("active", button.dataset.pageTarget === pageName); + }); + pages.forEach((page) => { + page.classList.toggle("active", page.dataset.page === pageName); + }); +} + +function bindNavigation() { + navButtons.forEach((button) => { + button.addEventListener("click", () => setActivePage(button.dataset.pageTarget)); + }); +} + +function pickInitialProject(projects) { + const params = getQueryParams(); + const project = params.get("project"); + if (project && projects.includes(project)) { + return project; + } + return projects[0] || null; +} + +function pickInitialRunIds(runs) { + const params = getQueryParams(); + const fromUrl = (params.get("run_ids") || "") + .split(",") + .map((item) => item.trim()) + .filter(Boolean); + const validIds = runs.map(runKey); + const selected = fromUrl.filter((id) => validIds.includes(id)); + if (selected.length) { + return selected; + } + return runs.slice(0, 2).map(runKey); +} + +function renderProjectSelect() { + projectSelectEl.innerHTML = ""; + if (!state.projects.length) { + const option = document.createElement("option"); + option.value = ""; + option.textContent = "No projects"; + projectSelectEl.appendChild(option); + projectSelectEl.disabled = true; + return; + } + + projectSelectEl.disabled = false; + for (const project of state.projects) { + const option = document.createElement("option"); + option.value = project; + option.textContent = project; + option.selected = project === state.selectedProject; + projectSelectEl.appendChild(option); + } +} + +function renderRunList() { + runListEl.innerHTML = ""; + if (!state.runs.length) { + const empty = document.createElement("div"); + empty.className = "sidebar-empty"; + empty.textContent = "No runs yet"; + runListEl.appendChild(empty); + return; + } + + for (const run of state.runs) { + const wrapper = document.createElement("label"); + wrapper.className = "run-option"; + + const input = document.createElement("input"); + input.type = "checkbox"; + input.checked = state.selectedRunIds.includes(runKey(run)); + input.addEventListener("change", async () => { + if (input.checked) { + state.selectedRunIds = [...new Set([...state.selectedRunIds, runKey(run)])]; + } else { + state.selectedRunIds = state.selectedRunIds.filter((id) => id !== runKey(run)); + } + setQueryParams({ + project: state.selectedProject, + run_ids: state.selectedRunIds, + }); + await renderDashboard(); + }); + + const marker = document.createElement("span"); + marker.className = "run-color-dot"; + marker.style.backgroundColor = colorForRun(run); + + const text = document.createElement("span"); + text.className = "run-option-text"; + text.innerHTML = `${run.name || "Unnamed run"}`; + + wrapper.appendChild(input); + wrapper.appendChild(marker); + wrapper.appendChild(text); + runListEl.appendChild(wrapper); + } +} + +function chartPoints(rows, width, height, padding, min, max) { + const span = max - min || 1; + return rows.map((row, index) => { + const x = padding + (index / Math.max(rows.length - 1, 1)) * (width - padding * 2); + const y = height - padding - ((row.value - min) / span) * (height - padding * 2); + return [x, y]; + }); +} + +function pathFromPoints(points) { + return points.map(([x, y], index) => `${index === 0 ? "M" : "L"} ${x} ${y}`).join(" "); +} + +function renderMetricCard(metricName, seriesByRun) { + const card = document.createElement("article"); + card.className = "metric-card"; + const nonEmptySeries = seriesByRun.filter((entry) => entry.rows.length); + if (!nonEmptySeries.length) { + card.innerHTML = ` +
        +
        +

        ${metricName}

        +
        Selected runs
        +
        +
        +
        No numeric values logged for this metric.
        + `; + return card; + } + + const width = 640; + const height = 220; + const padding = 20; + const values = nonEmptySeries.flatMap((entry) => entry.rows.map((row) => row.value)); + const min = Math.min(...values); + const max = Math.max(...values); + const lineMarkup = nonEmptySeries + .map((entry) => { + const points = chartPoints(entry.rows, width, height, padding, min, max); + const markers = points + .map(([x, y]) => ``) + .join(""); + return ` + + ${markers} + `; + }) + .join(""); + const legendMarkup = nonEmptySeries + .map( + (entry) => ` + + + ${entry.runName} + + `, + ) + .join(""); + const latestSummary = nonEmptySeries + .map((entry) => `${entry.runName}: ${formatValue(entry.rows.at(-1).value)}`) + .join(" | "); + + card.innerHTML = ` +
        +
        +

        ${metricName}

        +
        ${nonEmptySeries.length} run${nonEmptySeries.length === 1 ? "" : "s"} overlaid
        +
        +
        ${latestSummary}
        +
        +
        + + + ${lineMarkup} + +
        +
        ${legendMarkup}
        +
        Comparing ${nonEmptySeries.length} selected runs on the same metric scale.
        + `; + return card; +} + +function textFromContent(content) { + if (typeof content === "string") return content; + if (Array.isArray(content)) { + return content + .map((part) => { + if (typeof part === "string") return part; + if (typeof part?.text === "string") return part.text; + if (typeof part?.content === "string") return part.content; + return ""; + }) + .filter(Boolean) + .join(" "); + } + if (typeof content?.text === "string") return content.text; + return ""; +} + +function escapeHtml(value) { + return String(value) + .replaceAll("&", "&") + .replaceAll("<", "<") + .replaceAll(">", ">") + .replaceAll('"', """) + .replaceAll("'", "'"); +} + +function renderMessageContent(content) { + if (typeof content === "string") { + return `
        ${escapeHtml(content)}
        `; + } + if (Array.isArray(content)) { + const items = content + .map((part) => { + if (typeof part === "string") { + return `
        ${escapeHtml(part)}
        `; + } + if (typeof part?.text === "string") { + return `
        ${escapeHtml(part.text)}
        `; + } + if (typeof part?.content === "string") { + return `
        ${escapeHtml(part.content)}
        `; + } + return `
        [non-text content]
        `; + }) + .join(""); + return items || '
        (empty)
        '; + } + if (typeof content?.text === "string") { + return `
        ${escapeHtml(content.text)}
        `; + } + return '
        (empty)
        '; +} + +function renderTraceDetail(trace) { + const messages = Array.isArray(trace.messages) ? trace.messages : []; + if (!messages.length) { + return '
        No trace messages.
        '; + } + return messages + .map((message) => { + const role = escapeHtml(message?.role || "unknown"); + return ` +
        +
        ${role}
        + ${renderMessageContent(message?.content)} +
        + `; + }) + .join(""); +} + +function formatTraceTime(timestamp) { + if (!timestamp) return "—"; + const date = new Date(timestamp); + if (Number.isNaN(date.getTime())) { + return timestamp; + } + return date.toLocaleString(); +} + +function renderTraceRows(traces) { + tracesBodyEl.innerHTML = ""; + if (!traces.length) { + const row = document.createElement("tr"); + row.innerHTML = 'No traces for the selected runs.'; + tracesBodyEl.appendChild(row); + return; + } + + for (const trace of traces) { + const request = textFromContent( + (trace.messages || []).find((message) => message?.role === "user")?.content, + ) || "(no user message)"; + const row = document.createElement("tr"); + row.className = "trace-summary-row"; + row.setAttribute("role", "button"); + row.setAttribute("tabindex", "0"); + row.setAttribute("aria-expanded", "false"); + row.innerHTML = ` + ${trace.id} + ${request} + ${trace.run || "—"} + ${trace.step ?? "—"} + ${formatTraceTime(trace.timestamp)} + `; + const detailRow = document.createElement("tr"); + detailRow.className = "trace-detail-row"; + detailRow.hidden = true; + detailRow.innerHTML = ` + +
        +
        +
        + ${escapeHtml(trace.id)} +
        ${escapeHtml(trace.run || "—")} | step ${escapeHtml(trace.step ?? "—")} | ${escapeHtml(formatTraceTime(trace.timestamp))}
        +
        +
        +
        + ${renderTraceDetail(trace)} +
        +
        + + `; + const toggleRow = () => { + const expanded = row.getAttribute("aria-expanded") === "true"; + row.setAttribute("aria-expanded", expanded ? "false" : "true"); + row.classList.toggle("expanded", !expanded); + detailRow.hidden = expanded; + }; + row.addEventListener("click", toggleRow); + row.addEventListener("keydown", (event) => { + if (event.key === "Enter" || event.key === " ") { + event.preventDefault(); + toggleRow(); + } + }); + tracesBodyEl.appendChild(row); + tracesBodyEl.appendChild(detailRow); + } +} + +async function loadRuns() { + if (!state.selectedProject) { + state.runs = []; + state.selectedRunIds = []; + renderRunList(); + await renderDashboard(); + return; + } + + state.runs = await api("get_runs_for_project", { project: state.selectedProject }); + state.selectedRunIds = pickInitialRunIds(state.runs); + renderRunList(); + await renderDashboard(); +} + +async function renderDashboard() { + metricsGridEl.innerHTML = ""; + tracesBodyEl.innerHTML = ""; + + const selectedRuns = state.runs.filter((run) => state.selectedRunIds.includes(runKey(run))); + metricsTitleEl.textContent = state.selectedProject || "Metrics"; + + if (!state.selectedProject) { + metricsSubtitleEl.textContent = "No Trackio projects found."; + tracesSubtitleEl.textContent = "No traces available."; + return; + } + + if (!selectedRuns.length) { + metricsSubtitleEl.textContent = "Select one or more runs in the sidebar."; + tracesSubtitleEl.textContent = "Select one or more runs to load traces."; + metricsGridEl.innerHTML = '
        No runs selected.
        '; + renderTraceRows([]); + return; + } + + metricsSubtitleEl.textContent = `Plot cards for ${selectedRuns.length} selected run${selectedRuns.length === 1 ? "" : "s"}.`; + tracesSubtitleEl.textContent = `Recent traces for ${selectedRuns.length} selected run${selectedRuns.length === 1 ? "" : "s"}.`; + + const traceGroups = []; + const metricMap = new Map(); + + for (const run of selectedRuns) { + const metrics = await api("get_metrics_for_run", { + project: state.selectedProject, + run: run.name, + run_id: run.id, + }); + + const metricSeries = await Promise.all( + metrics.slice(0, 3).map(async (metricName) => ({ + metricName, + rows: await api("get_metric_values", { + project: state.selectedProject, + run: run.name, + run_id: run.id, + metric_name: metricName, + }), + })), + ); + + metricSeries.forEach(({ metricName, rows }) => { + const numericRows = rows.filter((row) => typeof row.value === "number" && Number.isFinite(row.value)); + if (!metricMap.has(metricName)) { + metricMap.set(metricName, []); + } + metricMap.get(metricName).push({ + runName: run.name || "Unnamed run", + color: colorForRun(run), + rows: numericRows, + }); + }); + + const runTraces = await api("get_traces", { + project: state.selectedProject, + run: run.name, + run_id: run.id, + sort: "request_time_desc", + limit: 6, + }); + traceGroups.push(...runTraces); + } + + for (const [metricName, seriesByRun] of metricMap.entries()) { + metricsGridEl.appendChild(renderMetricCard(metricName, seriesByRun)); + } + + if (!metricsGridEl.children.length) { + metricsGridEl.innerHTML = '
        No numeric metrics available.
        '; + } + + traceGroups.sort((left, right) => String(right.timestamp || "").localeCompare(String(left.timestamp || ""))); + renderTraceRows(traceGroups.slice(0, 12)); +} + +async function load() { + bindNavigation(); + projectSelectEl.addEventListener("change", async () => { + state.selectedProject = projectSelectEl.value || null; + setQueryParams({ project: state.selectedProject, run_ids: null }); + await loadRuns(); + renderProjectSelect(); + }); + try { + state.projects = await api("get_all_projects"); + state.selectedProject = pickInitialProject(state.projects); + renderProjectSelect(); + await loadRuns(); + } catch (error) { + projectSelectEl.innerHTML = ''; + projectSelectEl.disabled = true; + metricsSubtitleEl.textContent = "Could not load Trackio data."; + metricsGridEl.innerHTML = '
        The starter could not reach the Trackio API.
        '; + tracesSubtitleEl.textContent = "Could not load traces."; + renderTraceRows([]); + } +} + +load(); diff --git a/trackio/frontend_templates/starter/index.html b/trackio/frontend_templates/starter/index.html new file mode 100644 index 0000000000000000000000000000000000000000..17e6de399248bc384ade7fadd993f429401d7470 --- /dev/null +++ b/trackio/frontend_templates/starter/index.html @@ -0,0 +1,135 @@ + + + + + + Starter + + + +
        + + +
        + + +
        + +
        +
        + +
        + +
        + + + + + + + + + + + +
        Trace IDRequestRunStepRequest time
        +
        +
        + + +
        +
        + + + + diff --git a/trackio/frontend_templates/starter/styles.css b/trackio/frontend_templates/starter/styles.css new file mode 100644 index 0000000000000000000000000000000000000000..51058b424f66a5bacc736f1c7fbc9e4f0290dd74 --- /dev/null +++ b/trackio/frontend_templates/starter/styles.css @@ -0,0 +1,467 @@ +:root { + color-scheme: light; + --background-fill-primary: #ffffff; + --background-fill-secondary: #f9fafb; + --background-fill-tertiary: #f3f4f6; + --border-color-primary: #e5e7eb; + --border-color-accent: #d1d5db; + --body-text-color: #111827; + --body-text-color-subdued: #6b7280; + --body-text-color-soft: #9ca3af; + --accent: #1d4ed8; + --shadow-soft: 0 1px 2px rgba(16, 24, 40, 0.04); +} + +* { + box-sizing: border-box; +} + +html, +body { + margin: 0; + min-height: 100%; + background: var(--background-fill-secondary); + color: var(--body-text-color); + font-family: + ui-sans-serif, + system-ui, + -apple-system, + BlinkMacSystemFont, + "Segoe UI", + sans-serif; +} + +button, +input, +select, +table { + font: inherit; +} + +.app-shell { + display: grid; + grid-template-columns: 320px minmax(0, 1fr); + min-height: 100vh; +} + +.sidebar { + border-right: 1px solid var(--border-color-primary); + background: var(--background-fill-primary); +} + +.sidebar-scroll { + height: 100vh; + overflow-y: auto; + padding: 18px 16px 28px; +} + +.logo-section { + padding: 10px 10px 18px; + border-bottom: 1px solid var(--border-color-primary); +} + +.logo { + display: block; + width: 138px; + max-width: 100%; +} + +.sidebar-section { + padding: 18px 10px 0; +} + +.section-label, +.eyebrow { + margin: 0 0 10px; + color: var(--body-text-color-subdued); + font-size: 12px; + font-weight: 600; + letter-spacing: 0.08em; + text-transform: uppercase; +} + +.run-list { + display: grid; + gap: 8px; +} + +.dropdown-wrap { + position: relative; +} + +.project-select { + width: 100%; + padding: 10px 40px 10px 12px; + border: 1px solid var(--border-color-primary); + border-radius: 10px; + background: var(--background-fill-primary); + color: var(--body-text-color); + appearance: none; + -webkit-appearance: none; +} + +.project-select:focus { + outline: none; + border-color: var(--border-color-accent); + box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.08); +} + +.dropdown-icon { + position: absolute; + top: 50%; + right: 12px; + transform: translateY(-50%); + color: var(--body-text-color-subdued); + pointer-events: none; +} + +.run-option { + display: grid; + grid-template-columns: 18px 10px minmax(0, 1fr); + gap: 10px; + align-items: start; + padding: 10px 12px; + border: 1px solid var(--border-color-primary); + border-radius: 10px; + background: var(--background-fill-primary); + cursor: pointer; +} + +.run-option input { + margin: 2px 0 0; + accent-color: var(--accent); +} + +.run-color-dot { + width: 10px; + height: 10px; + margin-top: 5px; + border-radius: 999px; + background: var(--accent); +} + +.run-option-text strong, +.run-option-text span { + display: block; +} + +.run-option-text strong { + color: var(--body-text-color); + font-size: 14px; + font-weight: 600; +} + +.run-option-text span, +.sidebar-note, +.sidebar-empty { + color: var(--body-text-color-subdued); + font-size: 13px; + line-height: 1.5; +} + +.main-shell { + display: flex; + flex-direction: column; + min-width: 0; +} + +.navbar { + display: flex; + align-items: stretch; + min-height: 44px; + border-bottom: 1px solid var(--border-color-primary); + background: var(--background-fill-primary); +} + +.nav-spacer { + flex: 1 1 0; +} + +.nav-tabs { + display: flex; + padding-right: 8px; +} + +.nav-link { + padding: 10px 16px; + border: none; + border-bottom: 2px solid transparent; + background: none; + color: var(--body-text-color-subdued); + cursor: pointer; +} + +.nav-link.active { + border-bottom-color: var(--body-text-color); + color: var(--body-text-color); + font-weight: 500; +} + +.page { + display: none; + min-width: 0; + padding: 24px 28px 36px; +} + +.page.active { + display: block; +} + +.page-header { + margin-bottom: 22px; +} + +.page-header h1 { + margin: 0; + font-size: 32px; + line-height: 1.1; +} + +.page-subtitle { + margin: 8px 0 0; + color: var(--body-text-color-subdued); + font-size: 15px; +} + +.metrics-grid { + display: grid; + gap: 18px; +} + +.metric-card { + padding: 18px; + border: 1px solid var(--border-color-primary); + border-radius: 14px; + background: var(--background-fill-primary); + box-shadow: var(--shadow-soft); +} + +.metric-card-head { + display: flex; + align-items: start; + justify-content: space-between; + gap: 16px; +} + +.metric-card h3 { + margin: 0; + font-size: 18px; +} + +.metric-run, +.metric-meta, +.metric-empty, +.metric-latest { + color: var(--body-text-color-subdued); + font-size: 13px; +} + +.metric-latest { + color: var(--body-text-color); + max-width: 50%; + font-size: 13px; + font-weight: 600; + text-align: right; +} + +.plot-shell { + margin-top: 14px; + padding: 10px 12px; + border: 1px solid var(--border-color-primary); + border-radius: 12px; + background: linear-gradient(180deg, #ffffff, #f9fafb); +} + +.plot-shell svg { + display: block; + width: 100%; + height: auto; +} + +.plot-axis { + stroke: var(--border-color-accent); + stroke-width: 1.2; +} + +.plot-line { + fill: none; + stroke-width: 2.25; + stroke-linecap: round; + stroke-linejoin: round; +} + +.plot-marker { + fill: var(--background-fill-primary); + stroke: var(--body-text-color); + stroke-width: 1.5; +} + +.metric-legend { + display: flex; + flex-wrap: wrap; + gap: 10px 14px; + margin-top: 12px; +} + +.metric-legend-item { + display: inline-flex; + align-items: center; + gap: 8px; + color: var(--body-text-color-subdued); + font-size: 13px; +} + +.metric-legend-dot { + width: 10px; + height: 10px; + border-radius: 999px; +} + +.traces-table-wrap { + overflow: auto; + border: 1px solid var(--border-color-primary); + border-radius: 14px; + background: var(--background-fill-primary); + box-shadow: var(--shadow-soft); +} + +.traces-table { + width: 100%; + border-collapse: collapse; +} + +.traces-table thead { + background: var(--background-fill-secondary); +} + +.traces-table th, +.traces-table td { + padding: 14px 16px; + border-bottom: 1px solid var(--border-color-primary); + text-align: left; + vertical-align: top; + font-size: 14px; +} + +.traces-table th { + color: var(--body-text-color-subdued); + font-size: 12px; + font-weight: 600; + letter-spacing: 0.04em; + text-transform: uppercase; +} + +.trace-summary-row { + cursor: pointer; +} + +.trace-summary-row:hover { + background: var(--background-fill-secondary); +} + +.trace-summary-row.expanded { + background: var(--background-fill-secondary); +} + +.trace-id { + color: var(--body-text-color); + font-family: + ui-monospace, + SFMono-Regular, + Menlo, + monospace; + font-size: 12px; +} + +.trace-request { + max-width: 520px; + color: var(--body-text-color); +} + +.trace-detail-row td { + padding: 0; + background: var(--background-fill-secondary); +} + +.trace-detail-shell { + padding: 18px 20px; + border-top: 1px solid var(--border-color-primary); +} + +.trace-detail-head strong { + display: block; + color: var(--body-text-color); + font-size: 14px; +} + +.trace-detail-meta { + margin-top: 4px; + color: var(--body-text-color-subdued); + font-size: 12px; +} + +.trace-message-list { + display: grid; + gap: 12px; + margin-top: 16px; +} + +.trace-message { + padding: 12px 14px; + border: 1px solid var(--border-color-primary); + border-radius: 12px; + background: var(--background-fill-primary); +} + +.trace-message-role { + margin-bottom: 8px; + color: var(--body-text-color-subdued); + font-size: 12px; + font-weight: 600; + letter-spacing: 0.04em; + text-transform: uppercase; +} + +.trace-message-text { + color: var(--body-text-color); + font-size: 14px; + line-height: 1.55; + white-space: pre-wrap; + overflow-wrap: anywhere; +} + +.trace-message-muted { + color: var(--body-text-color-subdued); +} + +.empty-row, +.empty-panel { + color: var(--body-text-color-subdued); + text-align: center; +} + +.empty-panel { + padding: 48px 20px; + border: 1px dashed var(--border-color-accent); + border-radius: 14px; + background: var(--background-fill-primary); +} + +@media (max-width: 960px) { + .app-shell { + grid-template-columns: 1fr; + } + + .sidebar { + border-right: none; + border-bottom: 1px solid var(--border-color-primary); + } + + .sidebar-scroll { + height: auto; + } + + .page { + padding: 18px; + } +} diff --git a/trackio/gpu.py b/trackio/gpu.py new file mode 100644 index 0000000000000000000000000000000000000000..a84d903884069e1133532629aa1c63d22c3c792a --- /dev/null +++ b/trackio/gpu.py @@ -0,0 +1,381 @@ +import os +import threading +import warnings +from typing import TYPE_CHECKING, Any + +if TYPE_CHECKING: + from trackio.run import Run + +pynvml: Any = None +PYNVML_AVAILABLE = False +_nvml_initialized = False +_nvml_lock = threading.Lock() +_energy_baseline: dict[int, float] = {} + + +def _ensure_pynvml(): + global PYNVML_AVAILABLE, pynvml + if PYNVML_AVAILABLE: + return pynvml + try: + import pynvml as _pynvml + + pynvml = _pynvml + PYNVML_AVAILABLE = True + return pynvml + except ImportError: + raise ImportError( + "nvidia-ml-py is required for GPU monitoring. " + "Install it with: pip install nvidia-ml-py" + ) + + +def _init_nvml() -> bool: + global _nvml_initialized + with _nvml_lock: + if _nvml_initialized: + return True + try: + nvml = _ensure_pynvml() + nvml.nvmlInit() + _nvml_initialized = True + return True + except Exception: + return False + + +def get_gpu_count() -> tuple[int, list[int]]: + """ + Get the number of GPUs visible to this process and their physical indices. + Respects CUDA_VISIBLE_DEVICES environment variable. + + Returns: + Tuple of (count, physical_indices) where: + - count: Number of visible GPUs + - physical_indices: List mapping logical index to physical GPU index. + e.g., if CUDA_VISIBLE_DEVICES=2,3 returns (2, [2, 3]) + meaning logical GPU 0 = physical GPU 2, logical GPU 1 = physical GPU 3 + """ + if not _init_nvml(): + return 0, [] + + cuda_visible = os.environ.get("CUDA_VISIBLE_DEVICES") + if cuda_visible is not None and cuda_visible.strip(): + try: + indices = [int(x.strip()) for x in cuda_visible.split(",") if x.strip()] + return len(indices), indices + except ValueError: + pass + + try: + total = pynvml.nvmlDeviceGetCount() + return total, list(range(total)) + except Exception: + return 0, [] + + +def get_all_gpu_count() -> tuple[int, list[int]]: + """ + Get the total number of physical GPUs on the machine, ignoring CUDA_VISIBLE_DEVICES. + + Returns: + Tuple of (count, physical_indices) for ALL GPUs on the machine. + e.g., on a 4-GPU machine returns (4, [0, 1, 2, 3]) regardless of + CUDA_VISIBLE_DEVICES setting. + """ + if not _init_nvml(): + return 0, [] + + try: + total = pynvml.nvmlDeviceGetCount() + return total, list(range(total)) + except Exception: + return 0, [] + + +def gpu_available() -> bool: + """ + Check if GPU monitoring is available. + + Returns True if nvidia-ml-py is installed and at least one NVIDIA GPU is detected. + This is used for auto-detection of GPU logging. + """ + try: + _ensure_pynvml() + count, _ = get_gpu_count() + return count > 0 + except ImportError: + return False + except Exception: + return False + + +def reset_energy_baseline(): + """Reset the energy baseline for all GPUs. Called when a new run starts.""" + global _energy_baseline + _energy_baseline = {} + + +def collect_gpu_metrics(device: int | None = None, all_gpus: bool = False) -> dict: + """ + Collect GPU metrics for visible GPUs. + + Args: + device: CUDA device index to collect metrics from. If None, collects + from all GPUs visible to this process (respects CUDA_VISIBLE_DEVICES). + The device index is the logical CUDA index (0, 1, 2...), not the + physical GPU index. + all_gpus: If True and device is None, collect metrics for ALL physical GPUs + on the machine, ignoring CUDA_VISIBLE_DEVICES. Used by GpuMonitor + to report system-wide GPU metrics in distributed training. + + Returns: + Dictionary of GPU metrics. Keys use device indices (gpu/0/, gpu/1/, etc.). + """ + if not _init_nvml(): + return {} + + if all_gpus and device is None: + gpu_count, visible_gpus = get_all_gpu_count() + else: + gpu_count, visible_gpus = get_gpu_count() + if gpu_count == 0: + return {} + + if device is not None: + if device < 0 or device >= gpu_count: + return {} + gpu_indices = [(device, visible_gpus[device])] + else: + gpu_indices = list(enumerate(visible_gpus)) + + metrics = {} + total_util = 0.0 + total_mem_used_gib = 0.0 + total_power = 0.0 + max_temp = 0.0 + valid_util_count = 0 + + for logical_idx, physical_idx in gpu_indices: + prefix = f"gpu/{logical_idx}" + try: + handle = pynvml.nvmlDeviceGetHandleByIndex(physical_idx) + + try: + util = pynvml.nvmlDeviceGetUtilizationRates(handle) + metrics[f"{prefix}/utilization"] = util.gpu + metrics[f"{prefix}/memory_utilization"] = util.memory + total_util += util.gpu + valid_util_count += 1 + except Exception: + pass + + try: + mem = pynvml.nvmlDeviceGetMemoryInfo(handle) + mem_used_gib = mem.used / (1024**3) + mem_total_gib = mem.total / (1024**3) + metrics[f"{prefix}/allocated_memory"] = mem_used_gib + metrics[f"{prefix}/total_memory"] = mem_total_gib + if mem.total > 0: + metrics[f"{prefix}/memory_usage"] = mem.used / mem.total + total_mem_used_gib += mem_used_gib + except Exception: + pass + + try: + power_mw = pynvml.nvmlDeviceGetPowerUsage(handle) + power_w = power_mw / 1000.0 + metrics[f"{prefix}/power"] = power_w + total_power += power_w + except Exception: + pass + + try: + power_limit_mw = pynvml.nvmlDeviceGetPowerManagementLimit(handle) + power_limit_w = power_limit_mw / 1000.0 + metrics[f"{prefix}/power_limit"] = power_limit_w + if power_limit_w > 0 and f"{prefix}/power" in metrics: + metrics[f"{prefix}/power_percent"] = ( + metrics[f"{prefix}/power"] / power_limit_w + ) * 100 + except Exception: + pass + + try: + temp = pynvml.nvmlDeviceGetTemperature( + handle, pynvml.NVML_TEMPERATURE_GPU + ) + metrics[f"{prefix}/temp"] = temp + max_temp = max(max_temp, temp) + except Exception: + pass + + try: + sm_clock = pynvml.nvmlDeviceGetClockInfo(handle, pynvml.NVML_CLOCK_SM) + metrics[f"{prefix}/sm_clock"] = sm_clock + except Exception: + pass + + try: + mem_clock = pynvml.nvmlDeviceGetClockInfo(handle, pynvml.NVML_CLOCK_MEM) + metrics[f"{prefix}/memory_clock"] = mem_clock + except Exception: + pass + + try: + fan_speed = pynvml.nvmlDeviceGetFanSpeed(handle) + metrics[f"{prefix}/fan_speed"] = fan_speed + except Exception: + pass + + try: + pstate = pynvml.nvmlDeviceGetPerformanceState(handle) + metrics[f"{prefix}/performance_state"] = pstate + except Exception: + pass + + try: + energy_mj = pynvml.nvmlDeviceGetTotalEnergyConsumption(handle) + if physical_idx not in _energy_baseline: + _energy_baseline[physical_idx] = energy_mj + energy_consumed_mj = energy_mj - _energy_baseline[physical_idx] + metrics[f"{prefix}/energy_consumed"] = energy_consumed_mj / 1000.0 + except Exception: + pass + + try: + pcie_tx = pynvml.nvmlDeviceGetPcieThroughput( + handle, pynvml.NVML_PCIE_UTIL_TX_BYTES + ) + pcie_rx = pynvml.nvmlDeviceGetPcieThroughput( + handle, pynvml.NVML_PCIE_UTIL_RX_BYTES + ) + metrics[f"{prefix}/pcie_tx"] = pcie_tx / 1024.0 + metrics[f"{prefix}/pcie_rx"] = pcie_rx / 1024.0 + except Exception: + pass + + try: + throttle = pynvml.nvmlDeviceGetCurrentClocksThrottleReasons(handle) + metrics[f"{prefix}/throttle_thermal"] = int( + bool(throttle & pynvml.nvmlClocksThrottleReasonSwThermalSlowdown) + ) + metrics[f"{prefix}/throttle_power"] = int( + bool(throttle & pynvml.nvmlClocksThrottleReasonSwPowerCap) + ) + metrics[f"{prefix}/throttle_hw_slowdown"] = int( + bool(throttle & pynvml.nvmlClocksThrottleReasonHwSlowdown) + ) + metrics[f"{prefix}/throttle_apps"] = int( + bool( + throttle + & pynvml.nvmlClocksThrottleReasonApplicationsClocksSetting + ) + ) + except Exception: + pass + + try: + ecc_corrected = pynvml.nvmlDeviceGetTotalEccErrors( + handle, + pynvml.NVML_MEMORY_ERROR_TYPE_CORRECTED, + pynvml.NVML_VOLATILE_ECC, + ) + metrics[f"{prefix}/corrected_memory_errors"] = ecc_corrected + except Exception: + pass + + try: + ecc_uncorrected = pynvml.nvmlDeviceGetTotalEccErrors( + handle, + pynvml.NVML_MEMORY_ERROR_TYPE_UNCORRECTED, + pynvml.NVML_VOLATILE_ECC, + ) + metrics[f"{prefix}/uncorrected_memory_errors"] = ecc_uncorrected + except Exception: + pass + + except Exception: + continue + + if valid_util_count > 0: + metrics["gpu/mean_utilization"] = total_util / valid_util_count + if total_mem_used_gib > 0: + metrics["gpu/total_allocated_memory"] = total_mem_used_gib + if total_power > 0: + metrics["gpu/total_power"] = total_power + if max_temp > 0: + metrics["gpu/max_temp"] = max_temp + + return metrics + + +class GpuMonitor: + def __init__(self, run: "Run", interval: float = 10.0): + self._run = run + self._interval = interval + self._stop_flag = threading.Event() + self._thread: "threading.Thread | None" = None + + def start(self): + count, _ = get_all_gpu_count() + if count == 0: + warnings.warn( + "auto_log_gpu=True but no NVIDIA GPUs detected. GPU logging disabled." + ) + return + + reset_energy_baseline() + self._thread = threading.Thread(target=self._monitor_loop, daemon=True) + self._thread.start() + + def stop(self): + self._stop_flag.set() + if self._thread is not None: + self._thread.join(timeout=2.0) + + def _monitor_loop(self): + while not self._stop_flag.is_set(): + try: + metrics = collect_gpu_metrics(all_gpus=True) + if metrics: + self._run.log_system(metrics) + except Exception: + pass + + self._stop_flag.wait(timeout=self._interval) + + +def log_gpu(run: "Run | None" = None, device: int | None = None) -> dict: + """ + Log GPU metrics to the current or specified run as system metrics. + + Args: + run: Optional Run instance. If None, uses current run from context. + device: CUDA device index to collect metrics from. If None, collects + from all GPUs visible to this process (respects CUDA_VISIBLE_DEVICES). + + Returns: + dict: The GPU metrics that were logged. + + Example: + ```python + import trackio + + run = trackio.init(project="my-project") + trackio.log({"loss": 0.5}) + trackio.log_gpu() # logs all visible GPUs + trackio.log_gpu(device=0) # logs only CUDA device 0 + ``` + """ + from trackio import context_vars + + if run is None: + run = context_vars.current_run.get() + if run is None: + raise RuntimeError("Call trackio.init() before trackio.log_gpu().") + + metrics = collect_gpu_metrics(device=device) + if metrics: + run.log_system(metrics) + return metrics diff --git a/trackio/histogram.py b/trackio/histogram.py new file mode 100644 index 0000000000000000000000000000000000000000..1e00477907d55f7f5dcc1bf2bff05029d43b3ac1 --- /dev/null +++ b/trackio/histogram.py @@ -0,0 +1,71 @@ +from typing import Sequence + +import numpy as np + + +class Histogram: + """ + Histogram data type for Trackio, compatible with wandb.Histogram. + + Args: + sequence (`np.ndarray` or `Sequence[float]` or `Sequence[int]`, *optional*): + Sequence of values to create the histogram from. + np_histogram (`tuple`, *optional*): + Pre-computed NumPy histogram as a `(hist, bins)` tuple. + num_bins (`int`, *optional*, defaults to `64`): + Number of bins for the histogram (maximum `512`). + + Example: + ```python + import trackio + import numpy as np + + # Create histogram from sequence + data = np.random.randn(1000) + trackio.log({"distribution": trackio.Histogram(data)}) + + # Create histogram from numpy histogram + hist, bins = np.histogram(data, bins=30) + trackio.log({"distribution": trackio.Histogram(np_histogram=(hist, bins))}) + + # Specify custom number of bins + trackio.log({"distribution": trackio.Histogram(data, num_bins=50)}) + ``` + """ + + TYPE = "trackio.histogram" + + def __init__( + self, + sequence: np.ndarray | Sequence[float] | Sequence[int] | None = None, + np_histogram: tuple | None = None, + num_bins: int = 64, + ): + if sequence is None and np_histogram is None: + raise ValueError("Must provide either sequence or np_histogram") + + if sequence is not None and np_histogram is not None: + raise ValueError("Cannot provide both sequence and np_histogram") + + num_bins = min(num_bins, 512) + + if np_histogram is not None: + self.histogram, self.bins = np_histogram + self.histogram = np.asarray(self.histogram) + self.bins = np.asarray(self.bins) + else: + data = np.asarray(sequence).flatten() + data = data[np.isfinite(data)] + if len(data) == 0: + self.histogram = np.array([]) + self.bins = np.array([]) + else: + self.histogram, self.bins = np.histogram(data, bins=num_bins) + + def _to_dict(self) -> dict: + """Convert histogram to dictionary for storage.""" + return { + "_type": self.TYPE, + "bins": self.bins.tolist(), + "values": self.histogram.tolist(), + } diff --git a/trackio/imports.py b/trackio/imports.py new file mode 100644 index 0000000000000000000000000000000000000000..37516dbdc409b91f643ba3b0070c80379bb2252b --- /dev/null +++ b/trackio/imports.py @@ -0,0 +1,305 @@ +import csv +import os +from pathlib import Path + +from trackio import deploy, utils +from trackio.sqlite_storage import SQLiteStorage + + +def import_csv( + csv_path: str | Path, + project: str, + name: str | None = None, + space_id: str | None = None, + dataset_id: str | None = None, + private: bool | None = None, + force: bool = False, +) -> None: + """ + Imports a CSV file into a Trackio project. The CSV file must contain a `"step"` + column, may optionally contain a `"timestamp"` column, and any other columns will be + treated as metrics. It should also include a header row with the column names. + + TODO: call init() and return a Run object so that the user can continue to log metrics to it. + + Args: + csv_path (`str` or `Path`): + The str or Path to the CSV file to import. + project (`str`): + The name of the project to import the CSV file into. Must not be an existing + project. + name (`str`, *optional*): + The name of the Run to import the CSV file into. If not provided, a default + name will be generated. + name (`str`, *optional*): + The name of the run (if not provided, a default name will be generated). + space_id (`str`, *optional*): + If provided, the project will be logged to a Hugging Face Space instead of a + local directory. Should be a complete Space name like `"username/reponame"` + or `"orgname/reponame"`, or just `"reponame"` in which case the Space will + be created in the currently-logged-in Hugging Face user's namespace. If the + Space does not exist, it will be created. If the Space already exists, the + project will be logged to it. + dataset_id (`str`, *optional*): + Deprecated. Use `bucket_id` instead. + private (`bool`, *optional*): + Whether to make the Space private. If None (default), the repo will be + public unless the organization's default is private. This value is ignored + if the repo already exists. + """ + if SQLiteStorage.get_runs(project): + raise ValueError( + f"Project '{project}' already exists. Cannot import CSV into existing project." + ) + + csv_path = Path(csv_path) + if not csv_path.exists(): + raise FileNotFoundError(f"CSV file not found: {csv_path}") + + with csv_path.open(newline="", encoding="utf-8") as csv_file: + reader = csv.DictReader(csv_file) + source_columns = reader.fieldnames or [] + rows = list(reader) + + if not rows: + raise ValueError("CSV file is empty") + + column_mapping = utils.simplify_column_names(source_columns) + normalized_rows = [ + {column_mapping[key]: value for key, value in row.items()} for row in rows + ] + columns = list(normalized_rows[0].keys()) + + step_column = None + for col in columns: + if col.lower() == "step": + step_column = col + break + + if step_column is None: + raise ValueError("CSV file must contain a 'step' or 'Step' column") + + if name is None: + name = csv_path.stem + + metrics_list = [] + steps = [] + timestamps = [] + + numeric_columns = [] + for column in columns: + if column == step_column: + continue + if column == "timestamp": + continue + + try: + for row in normalized_rows: + value = row[column] + if value in ("", None): + continue + float(value) + except (ValueError, TypeError): + continue + numeric_columns.append(column) + + for row in normalized_rows: + metrics = {} + for column in numeric_columns: + value = row[column] + if value not in ("", None): + metrics[column] = float(value) + + if metrics: + metrics_list.append(metrics) + steps.append(int(float(row[step_column]))) + + if "timestamp" in row and row["timestamp"] not in ("", None): + timestamps.append(str(row["timestamp"])) + else: + timestamps.append("") + + if not metrics_list: + raise ValueError( + f"No numeric metric data found in CSV file: {csv_path}. Columns other " + "than 'step' and 'timestamp' must contain numeric values." + ) + + SQLiteStorage.bulk_log( + project=project, + run=name, + metrics_list=metrics_list, + steps=steps, + timestamps=timestamps, + ) + + print( + f"* Imported {len(metrics_list)} rows from {csv_path} into project '{project}' as run '{name}'" + ) + print(f"* Metrics found: {', '.join(metrics_list[0].keys())}") + + space_id, dataset_id, _ = utils.preprocess_space_and_dataset_ids( + space_id, dataset_id + ) + if dataset_id is not None: + os.environ["TRACKIO_DATASET_ID"] = dataset_id + print(f"* Trackio metrics will be synced to Hugging Face Dataset: {dataset_id}") + + if space_id is None: + utils.print_dashboard_instructions(project) + else: + deploy.create_space_if_not_exists( + space_id=space_id, dataset_id=dataset_id, private=private + ) + deploy.wait_until_space_exists(space_id=space_id) + deploy.upload_db_to_space(project=project, space_id=space_id, force=force) + print( + f"* View dashboard by going to: {deploy.SPACE_URL.format(space_id=space_id)}" + ) + + +def import_tf_events( + log_dir: str | Path, + project: str, + name: str | None = None, + space_id: str | None = None, + dataset_id: str | None = None, + private: bool | None = None, + force: bool = False, +) -> None: + """ + Imports TensorFlow Events files from a directory into a Trackio project. Each + subdirectory in the log directory will be imported as a separate run. + + Args: + log_dir (`str` or `Path`): + The str or Path to the directory containing TensorFlow Events files. + project (`str`): + The name of the project to import the TensorFlow Events files into. Must not + be an existing project. + name (`str`, *optional*): + The name prefix for runs (if not provided, will use directory names). Each + subdirectory will create a separate run. + space_id (`str`, *optional*): + If provided, the project will be logged to a Hugging Face Space instead of a + local directory. Should be a complete Space name like `"username/reponame"` + or `"orgname/reponame"`, or just `"reponame"` in which case the Space will + be created in the currently-logged-in Hugging Face user's namespace. If the + Space does not exist, it will be created. If the Space already exists, the + project will be logged to it. + dataset_id (`str`, *optional*): + Deprecated. Use `bucket_id` instead. + private (`bool`, *optional*): + Whether to make the Space private. If None (default), the repo will be + public unless the organization's default is private. This value is ignored + if the repo already exists. + """ + try: + from tbparse import SummaryReader + except ImportError: + raise ImportError( + "The `tbparse` package is not installed but is required for `import_tf_events`. Please install trackio with the `tensorboard` extra: `pip install trackio[tensorboard]`." + ) + + if SQLiteStorage.get_runs(project): + raise ValueError( + f"Project '{project}' already exists. Cannot import TF events into existing project." + ) + + path = Path(log_dir) + if not path.exists(): + raise FileNotFoundError(f"TF events directory not found: {path}") + + # Use tbparse to read all tfevents files in the directory structure + reader = SummaryReader(str(path), extra_columns={"dir_name"}) + df = reader.scalars + + if df.empty: + raise ValueError(f"No TensorFlow events data found in {path}") + + total_imported = 0 + imported_runs = [] + + # Group by dir_name to create separate runs + for dir_name, group_df in df.groupby("dir_name"): + try: + # Determine run name based on directory name + if dir_name == "": + run_name = "main" # For files in the root directory + else: + run_name = dir_name # Use directory name + + if name: + run_name = f"{name}_{run_name}" + + if group_df.empty: + print(f"* Skipping directory {dir_name}: no scalar data found") + continue + + metrics_list = [] + steps = [] + timestamps = [] + + for _, row in group_df.iterrows(): + # Convert row values to appropriate types + tag = str(row["tag"]) + value = float(row["value"]) + step = int(row["step"]) + + metrics = {tag: value} + metrics_list.append(metrics) + steps.append(step) + + # Use wall_time if present, else fallback + if "wall_time" in group_df.columns and not utils.is_missing_value( + row["wall_time"] + ): + timestamps.append(str(row["wall_time"])) + else: + timestamps.append("") + + if metrics_list: + SQLiteStorage.bulk_log( + project=project, + run=str(run_name), + metrics_list=metrics_list, + steps=steps, + timestamps=timestamps, + ) + + total_imported += len(metrics_list) + imported_runs.append(run_name) + + print( + f"* Imported {len(metrics_list)} scalar events from directory '{dir_name}' as run '{run_name}'" + ) + print(f"* Metrics in this run: {', '.join(set(group_df['tag']))}") + + except Exception as e: + print(f"* Error processing directory {dir_name}: {e}") + continue + + if not imported_runs: + raise ValueError("No valid TensorFlow events data could be imported") + + print(f"* Total imported events: {total_imported}") + print(f"* Created runs: {', '.join(imported_runs)}") + + space_id, dataset_id, _ = utils.preprocess_space_and_dataset_ids( + space_id, dataset_id + ) + if dataset_id is not None: + os.environ["TRACKIO_DATASET_ID"] = dataset_id + print(f"* Trackio metrics will be synced to Hugging Face Dataset: {dataset_id}") + + if space_id is None: + utils.print_dashboard_instructions(project) + else: + deploy.create_space_if_not_exists( + space_id, dataset_id=dataset_id, private=private + ) + deploy.wait_until_space_exists(space_id) + deploy.upload_db_to_space(project, space_id, force=force) + print( + f"* View dashboard by going to: {deploy.SPACE_URL.format(space_id=space_id)}" + ) diff --git a/trackio/launch.py b/trackio/launch.py new file mode 100644 index 0000000000000000000000000000000000000000..9fe4843dceb64c7c6ee74f95cbc22e5447a273c6 --- /dev/null +++ b/trackio/launch.py @@ -0,0 +1,202 @@ +from __future__ import annotations + +import os +import secrets +import socket +import threading +import time +import warnings +from pathlib import Path +from typing import Any + +import httpx +import uvicorn +from uvicorn.config import Config + +from trackio._vendor.gradio_exceptions import ChecksumMismatchError +from trackio._vendor.networking import normalize_share_url, setup_tunnel, url_ok +from trackio._vendor.tunneling import BINARY_PATH +from trackio.launch_utils import colab_check, is_hosted_notebook + +INITIAL_PORT_VALUE = int(os.getenv("GRADIO_SERVER_PORT", "7860")) +TRY_NUM_PORTS = int(os.getenv("GRADIO_NUM_PORTS", "100")) +LOCALHOST_NAME = os.getenv("GRADIO_SERVER_NAME", "127.0.0.1") + + +class _UvicornServer(uvicorn.Server): + def install_signal_handlers(self) -> None: + pass + + def run_in_thread(self) -> None: + self.thread = threading.Thread(target=self.run, daemon=True) + self.thread.start() + start = time.time() + while not self.started: + time.sleep(1e-3) + if time.time() - start > 60: + raise RuntimeError( + "Server failed to start. Please check that the port is available." + ) + + +def _bind_host(server_name: str) -> str: + if server_name.startswith("[") and server_name.endswith("]"): + return server_name[1:-1] + return server_name + + +def start_server( + app: Any, + server_name: str | None = None, + server_port: int | None = None, + ssl_keyfile: str | None = None, + ssl_certfile: str | None = None, + ssl_keyfile_password: str | None = None, +) -> tuple[str, int, str, _UvicornServer]: + server_name = server_name or LOCALHOST_NAME + url_host_name = "localhost" if server_name == "0.0.0.0" else server_name + + host = _bind_host(server_name) + + server_ports = ( + [server_port] + if server_port is not None + else range(INITIAL_PORT_VALUE, INITIAL_PORT_VALUE + TRY_NUM_PORTS) + ) + + port_used = None + server = None + for port in server_ports: + try: + socket_family = socket.AF_INET6 if ":" in host else socket.AF_INET + with socket.socket(socket_family, socket.SOCK_STREAM) as s: + s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + s.bind((host, port)) + config = Config( + app=app, + port=port, + host=host, + log_level="warning", + ssl_keyfile=ssl_keyfile, + ssl_certfile=ssl_certfile, + ssl_keyfile_password=ssl_keyfile_password, + ) + server = _UvicornServer(config=config) + server.run_in_thread() + port_used = port + break + except (OSError, RuntimeError): + continue + else: + raise OSError( + f"Cannot find empty port in range: {min(server_ports)}-{max(server_ports)}. " + "Set GRADIO_SERVER_PORT or pass server_port to trackio.show()." + ) + + assert port_used is not None and server is not None + + if ssl_keyfile is not None: + path_to_local_server = f"https://{url_host_name}:{port_used}/" + else: + path_to_local_server = f"http://{url_host_name}:{port_used}/" + + return server_name, port_used, path_to_local_server, server + + +def launch_trackio_dashboard( + starlette_app: Any, + *, + server_name: str | None = None, + server_port: int | None = None, + share: bool | None = None, + share_server_address: str | None = None, + share_server_protocol: str | None = None, + share_server_tls_certificate: str | None = None, + mcp_server: bool = False, + ssl_verify: bool = True, + quiet: bool = False, +) -> tuple[str | None, str | None, str | None, Any]: + is_colab = colab_check() + is_hosted_nb = is_hosted_notebook() + space_id = os.getenv("SPACE_ID") + + if share is None: + if is_colab or is_hosted_nb: + if not quiet: + print( + "It looks like you are running Trackio on a hosted Jupyter notebook, which requires " + "`share=True`. Automatically setting `share=True` " + "(set `share=False` in `show()` to disable).\n" + ) + share = True + else: + share = os.getenv("GRADIO_SHARE", "").lower() == "true" + + sn = server_name + if sn is None and os.getenv("SYSTEM") == "spaces": + sn = "0.0.0.0" + elif sn is None: + sn = LOCALHOST_NAME + + server_name_r, server_port_r, local_url, uv_server = start_server( + starlette_app, + server_name=sn, + server_port=server_port, + ) + + local_api_url = f"{local_url.rstrip('/')}/api/" + try: + httpx.get(f"{local_url.rstrip('/')}/version", verify=ssl_verify, timeout=10) + except Exception as e: + raise RuntimeError( + f"Could not reach Trackio server at {local_url.rstrip('/')}/version: {e}" + ) from e + + if share and space_id: + warnings.warn("Setting share=True is not supported on Hugging Face Spaces") + share = False + + share_url: str | None = None + if share: + try: + share_tok = secrets.token_urlsafe(32) + proto = share_server_protocol or ( + "http" if share_server_address is not None else "https" + ) + raw = setup_tunnel( + local_host=server_name_r, + local_port=server_port_r, + share_token=share_tok, + share_server_address=share_server_address, + share_server_tls_certificate=share_server_tls_certificate, + ) + share_url = normalize_share_url(raw, proto) + if not quiet: + print(f"* Running on public URL: {share_url}") + print( + "\nThis share link expires in 1 week. For permanent hosting, deploy to Hugging Face Spaces." + ) + except Exception as e: + share_url = None + if not quiet: + if isinstance(e, ChecksumMismatchError): + print( + "\nCould not create share link. Checksum mismatch for frpc binary." + ) + elif Path(BINARY_PATH).exists(): + print( + "\nCould not create share link. Check your internet connection or https://status.gradio.app." + ) + else: + print( + f"\nCould not create share link. Missing frpc at {BINARY_PATH}. {e}" + ) + + if not share_url and not quiet: + print("* To create a public link, set `share=True` in `trackio.show()`.") + + return local_url, share_url, local_api_url, uv_server + + +def url_ok_local(local_url: str) -> bool: + return url_ok(local_url) diff --git a/trackio/launch_utils.py b/trackio/launch_utils.py new file mode 100644 index 0000000000000000000000000000000000000000..4215f7564472ad42441be63ecec13d5d385a20fb --- /dev/null +++ b/trackio/launch_utils.py @@ -0,0 +1,33 @@ +import os + + +def colab_check() -> bool: + is_colab = False + try: + from IPython.core.getipython import get_ipython # noqa: PLC0415 + + from_ipynb = get_ipython() + if "google.colab" in str(from_ipynb): + is_colab = True + except (ImportError, NameError): + pass + return is_colab + + +def is_hosted_notebook() -> bool: + return bool( + os.environ.get("KAGGLE_KERNEL_RUN_TYPE") + or os.path.exists("/home/ec2-user/SageMaker") + ) + + +def ipython_check() -> bool: + is_ipython = False + try: + from IPython.core.getipython import get_ipython # noqa: PLC0415 + + if get_ipython() is not None: + is_ipython = True + except (ImportError, NameError): + pass + return is_ipython diff --git a/trackio/markdown.py b/trackio/markdown.py new file mode 100644 index 0000000000000000000000000000000000000000..910a7749517980578449801da53a279f3f5c11d1 --- /dev/null +++ b/trackio/markdown.py @@ -0,0 +1,21 @@ +class Markdown: + """ + Markdown report data type for Trackio. + + Args: + text (`str`): + Markdown content to log. + """ + + TYPE = "trackio.markdown" + + def __init__(self, text: str = ""): + if not isinstance(text, str): + raise ValueError("Markdown text must be a string") + self.text = text + + def _to_dict(self) -> dict: + return { + "_type": self.TYPE, + "_value": self.text, + } diff --git a/trackio/mcp_setup.py b/trackio/mcp_setup.py new file mode 100644 index 0000000000000000000000000000000000000000..178ff83dcc5eb98877fa5e3157b736025ed2df5e --- /dev/null +++ b/trackio/mcp_setup.py @@ -0,0 +1,156 @@ +from __future__ import annotations + +import os +import secrets +from contextlib import asynccontextmanager +from typing import Any + +from starlette.routing import Mount + +from trackio.sqlite_storage import SQLiteStorage + + +def _assert_mcp_mutation_access( + *, + hf_token: str | None = None, + write_token: str | None = None, +) -> None: + import trackio.server as trackio_server # noqa: PLC0415 + + if os.getenv("SYSTEM") == "spaces": + try: + trackio_server.check_hf_token_has_write_access(hf_token) + except PermissionError as e: + raise ValueError(str(e)) from e + return + + if not secrets.compare_digest(write_token or "", trackio_server.write_token or ""): + raise ValueError( + "A write_token is required for Trackio MCP mutations. " + "Use the write token from the dashboard URL." + ) + + +def create_mcp_integration() -> tuple[list[Any], Any]: + from mcp.server.fastmcp import FastMCP # noqa: PLC0415 + + import trackio.server as trackio_server # noqa: PLC0415 + + mcp = FastMCP( + "Trackio", + instructions="Inspect and manage Trackio experiment data.", + streamable_http_path="/", + log_level="WARNING", + ) + + mcp.add_tool( + trackio_server.get_all_projects, + description="List all Trackio projects available on this server.", + structured_output=True, + ) + mcp.add_tool( + trackio_server.get_runs_for_project, + description="List runs for a given Trackio project.", + structured_output=True, + ) + mcp.add_tool( + trackio_server.get_metrics_for_run, + description="List metric names recorded for a given Trackio run.", + structured_output=True, + ) + mcp.add_tool( + trackio_server.get_project_summary, + description="Return summary metadata for a Trackio project.", + structured_output=True, + ) + mcp.add_tool( + trackio_server.get_run_summary, + description="Return summary metadata for a Trackio run.", + structured_output=True, + ) + mcp.add_tool( + trackio_server.get_metric_values, + description="Fetch metric values for a run, optionally around a step or time.", + structured_output=True, + ) + mcp.add_tool( + trackio_server.get_system_metrics_for_run, + description="List system metric names recorded for a run.", + structured_output=True, + ) + mcp.add_tool( + trackio_server.get_system_logs, + description="Fetch system metric logs for a run.", + structured_output=True, + ) + mcp.add_tool( + trackio_server.get_snapshot, + description="Fetch a single Trackio snapshot around a step or timestamp.", + structured_output=True, + ) + mcp.add_tool( + trackio_server.get_logs, + description="Fetch Trackio metric logs for a run.", + structured_output=True, + ) + mcp.add_tool( + trackio_server.get_alerts, + description="Fetch alerts for a project, optionally filtered by run or level.", + structured_output=True, + ) + mcp.add_tool( + trackio_server.get_settings, + description="Return Trackio dashboard settings and asset configuration.", + structured_output=True, + ) + + @mcp.tool( + description="Delete a run. On Spaces, pass an hf_token with write access.", + structured_output=True, + ) + def delete_run( + project: str, + run: str, + hf_token: str | None = None, + write_token: str | None = None, + ) -> bool: + _assert_mcp_mutation_access(hf_token=hf_token, write_token=write_token) + return SQLiteStorage.delete_run(project, run) + + @mcp.tool( + description="Rename a run. On Spaces, pass an hf_token with write access.", + structured_output=True, + ) + def rename_run( + project: str, + old_name: str, + new_name: str, + hf_token: str | None = None, + write_token: str | None = None, + ) -> bool: + _assert_mcp_mutation_access(hf_token=hf_token, write_token=write_token) + SQLiteStorage.rename_run(project, old_name, new_name) + return True + + @mcp.tool( + description=( + "Trigger a Trackio export/sync pass. On Spaces, pass an hf_token with " + "write access." + ), + structured_output=True, + ) + def trigger_sync( + hf_token: str | None = None, + write_token: str | None = None, + ) -> bool: + _assert_mcp_mutation_access(hf_token=hf_token, write_token=write_token) + return trackio_server.force_sync() + + mcp_app = mcp.streamable_http_app() + + @asynccontextmanager + async def mcp_lifespan_context(app): + async with mcp.session_manager.run(): + yield + + return [Mount("/mcp", app=mcp_app)], mcp_lifespan_context diff --git a/trackio/media/__init__.py b/trackio/media/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..0fb247008abc2493044fe0a66a691f2d23a909c2 --- /dev/null +++ b/trackio/media/__init__.py @@ -0,0 +1,27 @@ +""" +Media module for Trackio. + +This module contains all media-related functionality including: +- TrackioImage, TrackioVideo, TrackioAudio classes +- Video writing utilities +- Audio conversion utilities +""" + +from trackio.media.audio import TrackioAudio +from trackio.media.image import TrackioImage +from trackio.media.media import TrackioMedia +from trackio.media.utils import get_project_media_path +from trackio.media.video import TrackioVideo + +write_audio = TrackioAudio.write_audio +write_video = TrackioVideo.write_video + +__all__ = [ + "TrackioMedia", + "TrackioImage", + "TrackioVideo", + "TrackioAudio", + "get_project_media_path", + "write_video", + "write_audio", +] diff --git a/trackio/media/audio.py b/trackio/media/audio.py new file mode 100644 index 0000000000000000000000000000000000000000..eb870bb39a2967516e20edac4f11db6b5d2277cd --- /dev/null +++ b/trackio/media/audio.py @@ -0,0 +1,189 @@ +import os +import shutil +import subprocess +import warnings +import wave +from pathlib import Path +from typing import Literal + +import numpy as np + +from trackio.media.media import TrackioMedia +from trackio.media.utils import check_ffmpeg_installed, check_path + +SUPPORTED_FORMATS = ["wav", "mp3"] +AudioFormatType = Literal["wav", "mp3"] +TrackioAudioSourceType = str | Path | np.ndarray + + +class TrackioAudio(TrackioMedia): + """ + Initializes an Audio object. + + Example: + ```python + import trackio + import numpy as np + + # Generate a 1-second 440 Hz sine wave (mono) + sr = 16000 + t = np.linspace(0, 1, sr, endpoint=False) + wave = 0.2 * np.sin(2 * np.pi * 440 * t) + audio = trackio.Audio(wave, caption="A4 sine", sample_rate=sr, format="wav") + trackio.log({"tone": audio}) + + # Stereo from numpy array (shape: samples, 2) + stereo = np.stack([wave, wave], axis=1) + audio = trackio.Audio(stereo, caption="Stereo", sample_rate=sr, format="mp3") + trackio.log({"stereo": audio}) + + # From an existing file + audio = trackio.Audio("path/to/audio.wav", caption="From file") + trackio.log({"file_audio": audio}) + ``` + + Args: + value (`str`, `Path`, or `numpy.ndarray`, *optional*): + A path to an audio file, or a numpy array. + The array should be shaped `(samples,)` for mono or `(samples, 2)` for stereo. + Float arrays will be peak-normalized and converted to 16-bit PCM; integer arrays will be converted to 16-bit PCM as needed. + caption (`str`, *optional*): + A string caption for the audio. + sample_rate (`int`, *optional*): + Sample rate in Hz. Required when `value` is a numpy array. + format (`Literal["wav", "mp3"]`, *optional*): + Audio format used when `value` is a numpy array. Default is "wav". + """ + + TYPE = "trackio.audio" + + def __init__( + self, + value: TrackioAudioSourceType, + caption: str | None = None, + sample_rate: int | None = None, + format: AudioFormatType | None = None, + ): + super().__init__(value, caption) + if isinstance(value, np.ndarray): + if sample_rate is None: + raise ValueError("Sample rate is required when value is an ndarray") + if format is None: + format = "wav" + self._format = format + self._sample_rate = sample_rate + + def _save_media(self, file_path: Path): + if isinstance(self._value, np.ndarray): + TrackioAudio.write_audio( + data=self._value, + sample_rate=self._sample_rate, + filename=file_path, + format=self._format, + ) + elif isinstance(self._value, str | Path): + if os.path.isfile(self._value): + shutil.copy(self._value, file_path) + else: + raise ValueError(f"File not found: {self._value}") + + @staticmethod + def ensure_int16_pcm(data: np.ndarray) -> np.ndarray: + """ + Convert input audio array to contiguous int16 PCM. + Peak normalization is applied to floating inputs. + """ + arr = np.asarray(data) + if arr.ndim not in (1, 2): + raise ValueError("Audio data must be 1D (mono) or 2D ([samples, channels])") + + if arr.dtype != np.int16: + warnings.warn( + f"Converting {arr.dtype} audio to int16 PCM; pass int16 to avoid conversion.", + stacklevel=2, + ) + + arr = np.nan_to_num(arr, copy=False) + + # Floating types: normalize to peak 1.0, then scale to int16 + if np.issubdtype(arr.dtype, np.floating): + max_abs = float(np.max(np.abs(arr))) if arr.size else 0.0 + if max_abs > 0.0: + arr = arr / max_abs + out = (arr * 32767.0).clip(-32768, 32767).astype(np.int16, copy=False) + return np.ascontiguousarray(out) + + converters: dict[np.dtype, callable] = { + np.dtype(np.int16): lambda a: a, + np.dtype(np.int32): lambda a: (a.astype(np.int32) // 65536).astype( + np.int16, copy=False + ), + np.dtype(np.uint16): lambda a: (a.astype(np.int32) - 32768).astype( + np.int16, copy=False + ), + np.dtype(np.uint8): lambda a: (a.astype(np.int32) * 257 - 32768).astype( + np.int16, copy=False + ), + np.dtype(np.int8): lambda a: (a.astype(np.int32) * 256).astype( + np.int16, copy=False + ), + } + + conv = converters.get(arr.dtype) + if conv is not None: + out = conv(arr) + return np.ascontiguousarray(out) + raise TypeError(f"Unsupported audio dtype: {arr.dtype}") + + @staticmethod + def write_audio( + data: np.ndarray, + sample_rate: int, + filename: str | Path, + format: AudioFormatType = "wav", + ) -> None: + if not isinstance(sample_rate, int) or sample_rate <= 0: + raise ValueError(f"Invalid sample_rate: {sample_rate}") + if format not in SUPPORTED_FORMATS: + raise ValueError( + f"Unsupported format: {format}. Supported: {SUPPORTED_FORMATS}" + ) + + check_path(filename) + + pcm = TrackioAudio.ensure_int16_pcm(data) + + if format != "wav": + check_ffmpeg_installed() + + channels = 1 if pcm.ndim == 1 else pcm.shape[1] + pcm_bytes = pcm.tobytes() + + if format == "wav": + with wave.open(str(filename), "wb") as wf: + wf.setnchannels(channels) + wf.setsampwidth(2) + wf.setframerate(sample_rate) + wf.writeframes(pcm_bytes) + else: + cmd = [ + "ffmpeg", + "-y", + "-loglevel", + "error", + "-f", + "s16le", + "-ar", + str(sample_rate), + "-ac", + str(channels), + "-i", + "pipe:0", + str(filename), + ] + proc = subprocess.run( + cmd, input=pcm_bytes, capture_output=True, check=False + ) + if proc.returncode != 0: + stderr = proc.stderr.decode("utf-8", errors="replace").strip() + raise RuntimeError(f"ffmpeg failed to encode {format} audio: {stderr}") diff --git a/trackio/media/image.py b/trackio/media/image.py new file mode 100644 index 0000000000000000000000000000000000000000..0f070df0fe4e05dbbaed34867a360abc483d2e72 --- /dev/null +++ b/trackio/media/image.py @@ -0,0 +1,84 @@ +import os +import shutil +from pathlib import Path + +import numpy as np +from PIL import Image as PILImage + +from trackio.media.media import TrackioMedia + +TrackioImageSourceType = str | Path | np.ndarray | PILImage.Image + + +class TrackioImage(TrackioMedia): + """ + Initializes an Image object. + + Example: + ```python + import trackio + import numpy as np + from PIL import Image + + # Create an image from numpy array + image_data = np.random.randint(0, 255, (64, 64, 3), dtype=np.uint8) + image = trackio.Image(image_data, caption="Random image") + trackio.log({"my_image": image}) + + # Create an image from PIL Image + pil_image = Image.new('RGB', (100, 100), color='red') + image = trackio.Image(pil_image, caption="Red square") + trackio.log({"red_image": image}) + + # Create an image from file path + image = trackio.Image("path/to/image.jpg", caption="Photo from file") + trackio.log({"file_image": image}) + ``` + + Args: + value (`str`, `Path`, `numpy.ndarray`, or `PIL.Image`, *optional*): + A path to an image, a PIL Image, or a numpy array of shape (height, width, channels). + If numpy array, should be of type `np.uint8` with RGB values in the range `[0, 255]`. + caption (`str`, *optional*): + A string caption for the image. + """ + + TYPE = "trackio.image" + + def __init__(self, value: TrackioImageSourceType, caption: str | None = None): + super().__init__(value, caption) + self._format: str | None = None + + if not isinstance(self._value, TrackioImageSourceType): + raise ValueError( + f"Invalid value type, expected {TrackioImageSourceType}, got {type(self._value)}" + ) + if isinstance(self._value, np.ndarray) and self._value.dtype != np.uint8: + raise ValueError( + f"Invalid value dtype, expected np.uint8, got {self._value.dtype}" + ) + if ( + isinstance(self._value, np.ndarray | PILImage.Image) + and self._format is None + ): + self._format = "png" + + def _as_pil(self) -> PILImage.Image | None: + try: + if isinstance(self._value, np.ndarray): + arr = np.asarray(self._value).astype("uint8") + return PILImage.fromarray(arr).convert("RGBA") + if isinstance(self._value, PILImage.Image): + return self._value.convert("RGBA") + except Exception as e: + raise ValueError(f"Failed to process image data: {self._value}") from e + return None + + def _save_media(self, file_path: Path): + if pil := self._as_pil(): + pil.save(file_path, format=self._format) + elif isinstance(self._value, str | Path): + if os.path.isfile(self._value): + shutil.copy(self._value, file_path) + else: + raise ValueError(f"File not found: {self._value}") diff --git a/trackio/media/media.py b/trackio/media/media.py new file mode 100644 index 0000000000000000000000000000000000000000..6ec3d65939c81d2e32089a6fb3d192fbab0e4209 --- /dev/null +++ b/trackio/media/media.py @@ -0,0 +1,79 @@ +import os +import uuid +from abc import ABC, abstractmethod +from pathlib import Path + +from trackio.media.utils import get_project_media_path +from trackio.utils import MEDIA_DIR + + +class TrackioMedia(ABC): + """ + Abstract base class for Trackio media objects + Provides shared functionality for file handling and serialization. + """ + + TYPE: str + + def __init_subclass__(cls, **kwargs): + """Ensure subclasses define the TYPE attribute.""" + super().__init_subclass__(**kwargs) + if not hasattr(cls, "TYPE") or cls.TYPE is None: + raise TypeError(f"Class {cls.__name__} must define TYPE attribute") + + def __init__(self, value, caption: str | None = None): + """ + Saves the value and caption, and if the value is a file path, checks if the file exists. + """ + self.caption = caption + self._value = value + self._file_path: Path | None = None + + if isinstance(self._value, str | Path): + if not os.path.isfile(self._value): + raise ValueError(f"File not found: {self._value}") + + def _file_extension(self) -> str: + if self._file_path: + return self._file_path.suffix[1:].lower() + if isinstance(self._value, str | Path): + path = Path(self._value) + return path.suffix[1:].lower() + if hasattr(self, "_format") and self._format: + return self._format + return "unknown" + + def _get_relative_file_path(self) -> Path | None: + return self._file_path + + def _get_absolute_file_path(self) -> Path | None: + if self._file_path: + return MEDIA_DIR / self._file_path + return None + + def _save(self, project: str, run: str, step: int = 0): + if self._file_path: + return + + media_dir = get_project_media_path(project=project, run=run, step=step) + filename = f"{uuid.uuid4()}.{self._file_extension()}" + file_path = media_dir / filename + + self._save_media(file_path) + self._file_path = file_path.relative_to(MEDIA_DIR) + + @abstractmethod + def _save_media(self, file_path: Path): + """ + Performs the actual media saving logic. + """ + pass + + def _to_dict(self) -> dict: + if not self._file_path: + raise ValueError("Media must be saved to file before serialization") + return { + "_type": self.TYPE, + "file_path": str(self._get_relative_file_path()), + "caption": self.caption, + } diff --git a/trackio/media/utils.py b/trackio/media/utils.py new file mode 100644 index 0000000000000000000000000000000000000000..11e17b4994b1b3ff138dbf790ce01f04761f2882 --- /dev/null +++ b/trackio/media/utils.py @@ -0,0 +1,60 @@ +import shutil +from pathlib import Path + +from trackio.utils import MEDIA_DIR + + +def check_path(file_path: str | Path) -> None: + """Raise an error if the parent directory does not exist.""" + file_path = Path(file_path) + if not file_path.parent.exists(): + try: + file_path.parent.mkdir(parents=True, exist_ok=True) + except OSError as e: + raise ValueError( + f"Failed to create parent directory {file_path.parent}: {e}" + ) + + +def check_ffmpeg_installed() -> None: + """Raise an error if ffmpeg is not available on the system PATH.""" + if shutil.which("ffmpeg") is None: + raise RuntimeError( + "ffmpeg is required to write this media format but was not found on your system. " + "Please install ffmpeg and ensure it is available on your PATH." + ) + + +def get_project_media_path( + project: str, + run: str | None = None, + step: int | None = None, + relative_path: str | Path | None = None, +) -> Path: + """ + Get the full path where uploaded files are stored for a Trackio project (and create the directory if it doesn't exist). + If a run is not provided, the files are stored in a project-level directory with the given relative path. + + Args: + project: The project name + run: The run name + step: The step number + relative_path: The relative path within the directory (only used if run is not provided) + + Returns: + The full path to the media file + """ + if step is not None and run is None: + raise ValueError("Uploading files at a specific step requires a run") + + path = MEDIA_DIR / project + if run: + path /= run + if step is not None: + path /= str(step) + else: + path /= "files" + if relative_path: + path /= relative_path + path.mkdir(parents=True, exist_ok=True) + return path diff --git a/trackio/media/video.py b/trackio/media/video.py new file mode 100644 index 0000000000000000000000000000000000000000..01210bca73d801322e9c4450917f9fc71556f634 --- /dev/null +++ b/trackio/media/video.py @@ -0,0 +1,246 @@ +import os +import shutil +import subprocess +from pathlib import Path +from typing import Literal + +import numpy as np + +from trackio.media.media import TrackioMedia +from trackio.media.utils import check_ffmpeg_installed, check_path + +TrackioVideoSourceType = str | Path | np.ndarray +TrackioVideoFormatType = Literal["gif", "mp4", "webm"] +VideoCodec = Literal["h264", "vp9", "gif"] + + +class TrackioVideo(TrackioMedia): + """ + Initializes a Video object. + + Example: + ```python + import trackio + import numpy as np + + # Create a simple video from numpy array + frames = np.random.randint(0, 255, (10, 3, 64, 64), dtype=np.uint8) + video = trackio.Video(frames, caption="Random video", fps=30) + + # Create a batch of videos + batch_frames = np.random.randint(0, 255, (3, 10, 3, 64, 64), dtype=np.uint8) + batch_video = trackio.Video(batch_frames, caption="Batch of videos", fps=15) + + # Create video from file path + video = trackio.Video("path/to/video.mp4", caption="Video from file") + ``` + + Args: + value (`str`, `Path`, or `numpy.ndarray`, *optional*): + A path to a video file, or a numpy array. + If numpy array, should be of type `np.uint8` with RGB values in the range `[0, 255]`. + It is expected to have shape of either (frames, channels, height, width) or (batch, frames, channels, height, width). + For the latter, the videos will be tiled into a grid. + caption (`str`, *optional*): + A string caption for the video. + fps (`int`, *optional*): + Frames per second for the video. Only used when value is an ndarray. Default is `24`. + format (`Literal["gif", "mp4", "webm"]`, *optional*): + Video format ("gif", "mp4", or "webm"). Only used when value is an ndarray. Default is "gif". + """ + + TYPE = "trackio.video" + + def __init__( + self, + value: TrackioVideoSourceType, + caption: str | None = None, + fps: int | None = None, + format: TrackioVideoFormatType | None = None, + ): + super().__init__(value, caption) + + if not isinstance(self._value, TrackioVideoSourceType): + raise ValueError( + f"Invalid value type, expected {TrackioVideoSourceType}, got {type(self._value)}" + ) + if isinstance(self._value, np.ndarray): + if self._value.dtype != np.uint8: + raise ValueError( + f"Invalid value dtype, expected np.uint8, got {self._value.dtype}" + ) + if format is None: + format = "gif" + if fps is None: + fps = 24 + self._fps = fps + self._format = format + + @staticmethod + def _check_array_format(video: np.ndarray) -> None: + """Raise an error if the array is not in the expected format.""" + if not (video.ndim == 4 and video.shape[-1] == 3): + raise ValueError( + f"Expected RGB input shaped (F, H, W, 3), got {video.shape}. " + f"Input has {video.ndim} dimensions, expected 4." + ) + if video.dtype != np.uint8: + raise TypeError( + f"Expected dtype=uint8, got {video.dtype}. " + "Please convert your video data to uint8 format." + ) + + @staticmethod + def write_video( + file_path: str | Path, video: np.ndarray, fps: float, codec: VideoCodec + ) -> None: + """RGB uint8 only, shape (F, H, W, 3).""" + check_ffmpeg_installed() + check_path(file_path) + + if codec not in {"h264", "vp9", "gif"}: + raise ValueError("Unsupported codec. Use h264, vp9, or gif.") + + arr = np.asarray(video) + TrackioVideo._check_array_format(arr) + + frames = np.ascontiguousarray(arr) + _, height, width, _ = frames.shape + out_path = str(file_path) + + cmd = [ + "ffmpeg", + "-y", + "-f", + "rawvideo", + "-s", + f"{width}x{height}", + "-pix_fmt", + "rgb24", + "-r", + str(fps), + "-i", + "-", + "-an", + ] + + if codec == "gif": + video_filter = "split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" + cmd += [ + "-vf", + video_filter, + "-loop", + "0", + ] + elif codec == "h264": + cmd += [ + "-vcodec", + "libx264", + "-pix_fmt", + "yuv420p", + "-movflags", + "+faststart", + ] + elif codec == "vp9": + bpp = 0.08 + bps = int(width * height * fps * bpp) + if bps >= 1_000_000: + bitrate = f"{round(bps / 1_000_000)}M" + elif bps >= 1_000: + bitrate = f"{round(bps / 1_000)}k" + else: + bitrate = str(max(bps, 1)) + cmd += [ + "-vcodec", + "libvpx-vp9", + "-b:v", + bitrate, + "-pix_fmt", + "yuv420p", + ] + cmd += [out_path] + proc = subprocess.Popen(cmd, stdin=subprocess.PIPE, stderr=subprocess.PIPE) + try: + for frame in frames: + proc.stdin.write(frame.tobytes()) + finally: + if proc.stdin: + proc.stdin.close() + stderr = ( + proc.stderr.read().decode("utf-8", errors="ignore") + if proc.stderr + else "" + ) + ret = proc.wait() + if ret != 0: + raise RuntimeError(f"ffmpeg failed with code {ret}\n{stderr}") + + @property + def _codec(self) -> str: + match self._format: + case "gif": + return "gif" + case "mp4": + return "h264" + case "webm": + return "vp9" + case _: + raise ValueError(f"Unsupported format: {self._format}") + + def _save_media(self, file_path: Path): + if isinstance(self._value, np.ndarray): + video = TrackioVideo._process_ndarray(self._value) + TrackioVideo.write_video(file_path, video, fps=self._fps, codec=self._codec) + elif isinstance(self._value, str | Path): + if os.path.isfile(self._value): + shutil.copy(self._value, file_path) + else: + raise ValueError(f"File not found: {self._value}") + + @staticmethod + def _process_ndarray(value: np.ndarray) -> np.ndarray: + # Verify value is either 4D (single video) or 5D array (batched videos). + # Expected format: (frames, channels, height, width) or (batch, frames, channels, height, width) + if value.ndim < 4: + raise ValueError( + "Video requires at least 4 dimensions (frames, channels, height, width)" + ) + if value.ndim > 5: + raise ValueError( + "Videos can have at most 5 dimensions (batch, frames, channels, height, width)" + ) + if value.ndim == 4: + # Reshape to 5D with single batch: (1, frames, channels, height, width) + value = value[np.newaxis, ...] + + value = TrackioVideo._tile_batched_videos(value) + return value + + @staticmethod + def _tile_batched_videos(video: np.ndarray) -> np.ndarray: + """ + Tiles a batch of videos into a grid of videos. + + Input format: (batch, frames, channels, height, width) - original FCHW format + Output format: (frames, total_height, total_width, channels) + """ + batch_size, frames, channels, height, width = video.shape + + next_pow2 = 1 << (batch_size - 1).bit_length() + if batch_size != next_pow2: + pad_len = next_pow2 - batch_size + pad_shape = (pad_len, frames, channels, height, width) + padding = np.zeros(pad_shape, dtype=video.dtype) + video = np.concatenate((video, padding), axis=0) + batch_size = next_pow2 + + n_rows = 1 << ((batch_size.bit_length() - 1) // 2) + n_cols = batch_size // n_rows + + # Reshape to grid layout: (n_rows, n_cols, frames, channels, height, width) + video = video.reshape(n_rows, n_cols, frames, channels, height, width) + + # Rearrange dimensions to (frames, total_height, total_width, channels) + video = video.transpose(2, 0, 4, 1, 5, 3) + video = video.reshape(frames, n_rows * height, n_cols * width, channels) + return video diff --git a/trackio/package.json b/trackio/package.json new file mode 100644 index 0000000000000000000000000000000000000000..716fd45fd27328fd9bd26f5b9a5b637c990d43a9 --- /dev/null +++ b/trackio/package.json @@ -0,0 +1,6 @@ +{ + "name": "trackio", + "version": "0.26.0", + "description": "", + "python": "true" +} diff --git a/trackio/py.typed b/trackio/py.typed new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/trackio/remote_client.py b/trackio/remote_client.py new file mode 100644 index 0000000000000000000000000000000000000000..529d2bfc4897b88dba92b663b2c1ad3c26896704 --- /dev/null +++ b/trackio/remote_client.py @@ -0,0 +1,266 @@ +from __future__ import annotations + +from pathlib import Path +from typing import Any +from urllib.parse import urljoin, urlparse + +import httpx +from gradio_client import Client as GradioClient +from huggingface_hub.utils import build_hf_headers + +from trackio.utils import parse_trackio_server_url + +HTTP_API_VERSION = 1 +FORCE_SYNC_TIMEOUT = 180.0 + +WRITE_TOKEN_HEADER = "x-trackio-write-token" + + +def _normalize_src(src: str) -> str: + return src if src.endswith("/") else src + "/" + + +def _space_id_to_url(space_id: str) -> str: + namespace, name = space_id.split("/", 1) + subdomain = f"{namespace}-{name}".lower().replace("_", "-").replace(".", "-") + return f"https://{subdomain}.hf.space/" + + +def _host_is_hf_space(url: str) -> bool: + p = urlparse(url) + h = (p.hostname or "").lower() + return h.endswith(".hf.space") + + +def _resolve_src_url(src: str) -> str: + if src.startswith(("http://", "https://")): + base, _ = parse_trackio_server_url(src) + return _normalize_src(base) + if "/" in src: + return _space_id_to_url(src) + raise ValueError( + f"Could not resolve Trackio remote source '{src}'. " + "Pass a full Space id like 'user/space' or a URL." + ) + + +def _is_local_file_data(value: Any) -> bool: + return ( + isinstance(value, dict) + and "path" in value + and isinstance(value["path"], str) + and value.get("meta", {}).get("_type") == "gradio.FileData" + and Path(value["path"]).exists() + ) + + +def _merge_client_headers( + hf_token: str | None, write_token: str | None +) -> dict[str, str]: + headers: dict[str, str] = {} + if hf_token: + headers.update(build_hf_headers(token=hf_token)) + if write_token: + headers[WRITE_TOKEN_HEADER] = write_token + return headers + + +def _request_timeout_for_api( + timeout: httpx.Timeout | float | int | None, api_name: str +) -> httpx.Timeout | float | int | None: + if api_name != "force_sync": + return timeout + + normalized = httpx.Timeout(timeout) + read_timeout = normalized.read if normalized.read is not None else 0.0 + if read_timeout >= FORCE_SYNC_TIMEOUT: + return timeout + + return httpx.Timeout( + connect=normalized.connect, + read=FORCE_SYNC_TIMEOUT, + write=normalized.write, + pool=normalized.pool, + ) + + +class _TrackioHTTPClient: + def __init__( + self, + src: str, + hf_token: str | None = None, + write_token: str | None = None, + httpx_kwargs: dict[str, Any] | None = None, + ) -> None: + self.src = _resolve_src_url(src) + self.httpx_kwargs = dict(httpx_kwargs or {}) + self.httpx_kwargs.setdefault("timeout", 60) + extra = self.httpx_kwargs.pop("headers", None) + h = _merge_client_headers(hf_token, write_token) + if isinstance(extra, dict): + h.update({str(k): str(v) for k, v in extra.items()}) + self.headers = h + + def _upload_file(self, file_data: dict[str, Any]) -> dict[str, Any]: + path = Path(file_data["path"]) + with path.open("rb") as f: + resp = httpx.post( + urljoin(self.src, "api/upload"), + headers=self.headers, + files={"files": (path.name, f)}, + **self.httpx_kwargs, + ) + resp.raise_for_status() + uploaded_path = resp.json()["paths"][0] + return { + **file_data, + "path": uploaded_path, + "orig_name": file_data.get("orig_name", path.name), + } + + def _prepare_value(self, value: Any) -> Any: + if _is_local_file_data(value): + return self._upload_file(value) + if isinstance(value, list): + return [self._prepare_value(item) for item in value] + if isinstance(value, tuple): + return [self._prepare_value(item) for item in value] + if isinstance(value, dict): + return {k: self._prepare_value(v) for k, v in value.items()} + return value + + def predict(self, *args, api_name: str, **kwargs) -> Any: + api_name = api_name.lstrip("/") + payload = { + "args": self._prepare_value(list(args)), + "kwargs": self._prepare_value(kwargs), + } + request_kwargs = dict(self.httpx_kwargs) + request_kwargs["timeout"] = _request_timeout_for_api( + request_kwargs.get("timeout"), api_name + ) + resp = httpx.post( + urljoin(self.src, f"api/{api_name}"), + headers=self.headers, + json=payload, + **request_kwargs, + ) + if resp.status_code == 404: + raise RuntimeError( + f"Space '{self.src}' does not support '/{api_name}'. Redeploy with `trackio sync`." + ) + resp.raise_for_status() + body = resp.json() + if body.get("error") is not None: + raise RuntimeError(body["error"]) + return body.get("data") + + +class _TrackioGradioCompatClient: + def __init__( + self, + src: str, + hf_token: str | None = None, + write_token: str | None = None, + httpx_kwargs: dict[str, Any] | None = None, + verbose: bool = False, + ) -> None: + kwargs: dict[str, Any] = {"verbose": verbose} + if hf_token: + kwargs["hf_token"] = hf_token + merged = dict(httpx_kwargs or {}) + h = _merge_client_headers( + hf_token if hf_token else None, + write_token, + ) + extra = merged.pop("headers", None) + if isinstance(extra, dict): + h.update({str(k): str(v) for k, v in extra.items()}) + if h: + merged["headers"] = h + if merged: + kwargs["httpx_kwargs"] = merged + self._client = GradioClient(src, **kwargs) + + def predict(self, *args, api_name: str, **kwargs) -> Any: + try: + return self._client.predict(*args, api_name=api_name, **kwargs) + except Exception as e: + if "API Not Found" in str(e) or "api_name" in str(e): + raise RuntimeError( + f"Space '{self._client.src}' does not support '{api_name}'. " + "Redeploy with `trackio sync`." + ) from e + raise + + +def _supports_http_api( + src: str, + hf_token: str | None = None, + write_token: str | None = None, + httpx_kwargs: dict[str, Any] | None = None, +) -> bool: + url = _resolve_src_url(src) + headers = _merge_client_headers(hf_token, write_token) + kwargs = dict(httpx_kwargs or {}) + kwargs.setdefault("timeout", 10) + try: + resp = httpx.get(urljoin(url, "version"), headers=headers, **kwargs) + if not resp.is_success: + return False + data = resp.json() + return data.get("api_version") == HTTP_API_VERSION + except Exception: + return False + + +class RemoteClient: + def __init__( + self, + space: str, + hf_token: str | None = None, + write_token: str | None = None, + httpx_kwargs: dict[str, Any] | None = None, + verbose: bool = False, + ) -> None: + self._space = space + src_for_resolve = space + hf_effective = hf_token + wt_effective = write_token + if space.startswith(("http://", "https://")): + base, url_tok = parse_trackio_server_url(space) + src_for_resolve = base + if wt_effective is None: + wt_effective = url_tok + if not _host_is_hf_space(_normalize_src(base)): + hf_effective = None + try: + if _supports_http_api( + src_for_resolve, + hf_token=hf_effective, + write_token=wt_effective, + httpx_kwargs=httpx_kwargs, + ): + self._client = _TrackioHTTPClient( + src_for_resolve, + hf_token=hf_effective, + write_token=wt_effective, + httpx_kwargs=httpx_kwargs, + ) + else: + self._client = _TrackioGradioCompatClient( + src_for_resolve, + hf_token=hf_effective, + write_token=wt_effective, + httpx_kwargs=httpx_kwargs, + verbose=verbose, + ) + except ValueError: + raise + except Exception as e: + raise ConnectionError( + f"Could not connect to Space '{space}'. Is it running?\n{e}" + ) from e + + def predict(self, *args, api_name: str, **kwargs) -> Any: + return self._client.predict(*args, api_name=api_name, **kwargs) diff --git a/trackio/run.py b/trackio/run.py new file mode 100644 index 0000000000000000000000000000000000000000..5baf125e1dd10f585c43b0a925fd650681c357b9 --- /dev/null +++ b/trackio/run.py @@ -0,0 +1,1060 @@ +import os +import shutil +import threading +import uuid +from datetime import datetime, timezone +from pathlib import Path +from typing import Any + +import huggingface_hub +from gradio_client import handle_file + +from trackio import utils +from trackio.alerts import ( + AlertLevel, + format_alert_terminal, + resolve_webhook_min_level, + send_webhook, + should_send_webhook, +) +from trackio.apple_gpu import AppleGpuMonitor, apple_gpu_available +from trackio.cpu import CpuMonitor, cpu_available +from trackio.gpu import GpuMonitor, gpu_available +from trackio.histogram import Histogram +from trackio.markdown import Markdown +from trackio.media import TrackioMedia, get_project_media_path +from trackio.remote_client import RemoteClient +from trackio.sqlite_storage import SQLiteStorage +from trackio.table import Table +from trackio.trace import Trace +from trackio.typehints import AlertEntry, LogEntry, SystemLogEntry, UploadEntry +from trackio.utils import MEDIA_DIR, _emit_nonfatal_warning, _get_default_namespace + +BATCH_SEND_INTERVAL = 0.5 +MAX_BACKOFF = 30 + + +class Run: + def __init__( + self, + url: str | None, + project: str, + client: Any | None, + name: str | None = None, + run_id: str | None = None, + group: str | None = None, + config: dict | None = None, + space_id: str | None = None, + server_base_url: str | None = None, + write_token: str | None = None, + existing_runs: list[str] | None = None, + initial_last_step: int | None = None, + auto_log_gpu: bool = False, + gpu_log_interval: float = 10.0, + auto_log_cpu: bool = False, + cpu_log_interval: float = 10.0, + webhook_url: str | None = None, + webhook_min_level: AlertLevel | str | None = None, + ): + """ + Initialize a Run for logging metrics to Trackio. + + Args: + url: The URL or Space id of the Trackio server. + project: The name of the project to log metrics to. + client: A pre-configured Trackio-compatible client instance, or None to + create one automatically in a background thread with retry logic. + Passing None is recommended for normal usage. Passing a client + is useful for testing (e.g., injecting a mock client). + name: The name of this run. If None, a readable name like + "brave-sunset-0" is auto-generated. If space_id is provided, + generates a "username-timestamp" format instead. + group: Optional group name to organize related runs together. + config: A dictionary of configuration/hyperparameters for this run. + Keys starting with '_' are reserved for internal use. + space_id: The HF Space ID if logging to a Space (e.g., "user/space"). + If provided, media files will be uploaded to the Space. + existing_runs: Optional pre-fetched run names for this project. Used to + avoid redundant storage or remote lookups during init. + initial_last_step: Optional pre-fetched last step for a resumed run. + auto_log_gpu: Whether to automatically log GPU metrics (utilization, + memory, temperature) at regular intervals. + gpu_log_interval: The interval in seconds between GPU metric logs. + Only used when auto_log_gpu is True. + auto_log_cpu: Whether to automatically log CPU and RAM metrics + (utilization, memory, disk I/O, network I/O, sensors) at regular + intervals. + cpu_log_interval: The interval in seconds between CPU metric logs. + Only used when auto_log_cpu is True. + webhook_url: A webhook URL to POST alert payloads to. Supports + Slack and Discord webhook URLs natively. Can also be set via + the TRACKIO_WEBHOOK_URL environment variable. + webhook_min_level: Minimum alert level that should trigger webhook + delivery. For example, `AlertLevel.WARN` sends only WARN and + ERROR alerts to webhook destinations. Can also be set via + `TRACKIO_WEBHOOK_MIN_LEVEL`. + """ + self.url = url + self.project = project + self._client_lock = threading.Lock() + self._warning_lock = threading.Lock() + self._warned_failures: set[str] = set() + self._local_sender_thread: threading.Thread | None = None + self._client_thread = None + self._client = client + self._space_id = space_id + self._server_base_url = server_base_url + self._write_token = write_token + self._remote_storage_key = space_id or server_base_url + self.id = run_id or uuid.uuid4().hex + self._existing_runs = existing_runs + self._initial_last_step = initial_last_step + if name is not None: + self.name = name + else: + try: + self.name = utils.generate_readable_name( + self._safe_get_existing_runs(), self._space_id + ) + except Exception as e: + self._warn_once( + "init-run-name", + f"trackio.init() could not generate a run name: {e}. Falling back to a random name.", + ) + self.name = f"trackio-run-{uuid.uuid4().hex[:8]}" + self.group = group + try: + self.config = utils.to_json_safe(config or {}) + except Exception as e: + self._warn_once( + "init-config", + f"trackio.init() failed to serialize the run config: {e}. Continuing without config.", + ) + self.config = {} + + if isinstance(self.config, dict): + for key in self.config: + if key.startswith("_"): + raise ValueError( + f"Config key '{key}' is reserved (keys starting with '_' are reserved for internal use)" + ) + + self.config["_Username"] = self._get_username() + self.config["_Created"] = datetime.now(timezone.utc).isoformat() + self.config["_Group"] = self.group + + self._queued_logs: list[LogEntry] = [] + self._queued_system_logs: list[SystemLogEntry] = [] + self._queued_uploads: list[UploadEntry] = [] + self._queued_alerts: list[AlertEntry] = [] + self._stop_flag = threading.Event() + self._config_logged = False + max_step = self._safe_get_max_step_for_run() + self._next_step = 0 if max_step is None else max_step + 1 + self._has_local_buffer = False + + self._is_local = space_id is None and server_base_url is None + self._webhook_url = webhook_url or os.environ.get("TRACKIO_WEBHOOK_URL") + self._webhook_min_level = resolve_webhook_min_level( + webhook_min_level or os.environ.get("TRACKIO_WEBHOOK_MIN_LEVEL") + ) + + if self._is_local: + self._start_background_thread( + "_local_sender_thread", + self._local_batch_sender, + warning_key="local-sender-thread", + description="local Trackio logging thread", + ) + else: + self._start_background_thread( + "_client_thread", + self._init_client_background, + warning_key="remote-sender-thread", + description="remote Trackio logging thread", + ) + + self._gpu_monitor: "GpuMonitor | AppleGpuMonitor | None" = None + if auto_log_gpu: + try: + if gpu_available(): + self._gpu_monitor = GpuMonitor(self, interval=gpu_log_interval) + self._gpu_monitor.start() + elif apple_gpu_available(): + self._gpu_monitor = AppleGpuMonitor(self, interval=gpu_log_interval) + self._gpu_monitor.start() + except Exception as e: + self._warn_once( + "gpu-monitor", + f"trackio.init() failed to start automatic GPU logging: {e}. Continuing without system metric auto-logging.", + ) + + self._cpu_monitor: "CpuMonitor | None" = None + if auto_log_cpu: + try: + if cpu_available(): + self._cpu_monitor = CpuMonitor(self, interval=cpu_log_interval) + self._cpu_monitor.start() + except Exception as e: + self._warn_once( + "cpu-monitor", + f"trackio.init() failed to start automatic CPU logging: {e}. Continuing without CPU metric auto-logging.", + ) + + def _hf_token_for_remote(self) -> str | None: + return huggingface_hub.utils.get_token() if self._space_id else None + + def _get_username(self) -> str | None: + try: + return _get_default_namespace() + except Exception: + return None + + def _warn_once(self, key: str, message: str) -> None: + with self._warning_lock: + if key in self._warned_failures: + return + self._warned_failures.add(key) + _emit_nonfatal_warning(message) + + def _safe_get_existing_runs(self) -> list[str]: + if self._existing_runs is not None: + return self._existing_runs + try: + return SQLiteStorage.get_runs(self.project) + except Exception as e: + self._warn_once( + "init-existing-runs", + f"trackio.init() could not inspect existing runs for project '{self.project}': {e}. Continuing without prior-run metadata.", + ) + return [] + + def _safe_get_max_step_for_run(self) -> int | None: + if self._initial_last_step is not None: + return self._initial_last_step + try: + return SQLiteStorage.get_max_step_for_run( + self.project, self.name, run_id=self.id + ) + except Exception as e: + self._warn_once( + "init-max-step", + f"trackio.init() could not recover the previous step for run '{self.name}': {e}. Continuing from step 0.", + ) + return None + + def _start_background_thread( + self, + attr_name: str, + target, + *, + warning_key: str, + description: str, + ) -> bool: + try: + thread = threading.Thread(target=target, daemon=True) + setattr(self, attr_name, thread) + thread.start() + return True + except Exception as e: + setattr(self, attr_name, None) + self._warn_once( + warning_key, + f"trackio failed to start the {description}: {e}. Logging will continue in degraded mode.", + ) + return False + + def _thread_is_alive(self, attr_name: str) -> bool: + thread = getattr(self, attr_name, None) + return isinstance(thread, threading.Thread) and thread.is_alive() + + def _flush_queues_inline(self) -> None: + if self._is_local: + if self._queued_logs: + logs_to_send = self._queued_logs.copy() + self._queued_logs.clear() + self._write_logs_to_sqlite(logs_to_send) + + if self._queued_system_logs: + system_logs_to_send = self._queued_system_logs.copy() + self._queued_system_logs.clear() + self._write_system_logs_to_sqlite(system_logs_to_send) + + if self._queued_alerts: + alerts_to_send = self._queued_alerts.copy() + self._queued_alerts.clear() + self._write_alerts_to_sqlite(alerts_to_send) + return + + if self._queued_logs: + logs_to_send = self._queued_logs.copy() + self._queued_logs.clear() + self._persist_logs_locally(logs_to_send) + + if self._queued_system_logs: + system_logs_to_send = self._queued_system_logs.copy() + self._queued_system_logs.clear() + self._persist_system_logs_locally(system_logs_to_send) + + if self._queued_uploads: + uploads_to_send = self._queued_uploads.copy() + self._queued_uploads.clear() + self._persist_uploads_locally(uploads_to_send) + + if self._queued_alerts: + alerts_to_send = self._queued_alerts.copy() + self._queued_alerts.clear() + self._write_alerts_to_sqlite(alerts_to_send) + + def _local_batch_sender(self): + while ( + not self._stop_flag.is_set() + or len(self._queued_logs) > 0 + or len(self._queued_system_logs) > 0 + or len(self._queued_alerts) > 0 + ): + if not self._stop_flag.is_set(): + self._stop_flag.wait(timeout=BATCH_SEND_INTERVAL) + + try: + with self._client_lock: + if self._queued_logs: + logs_to_send = self._queued_logs.copy() + self._queued_logs.clear() + self._write_logs_to_sqlite(logs_to_send) + + if self._queued_system_logs: + system_logs_to_send = self._queued_system_logs.copy() + self._queued_system_logs.clear() + self._write_system_logs_to_sqlite(system_logs_to_send) + + if self._queued_alerts: + alerts_to_send = self._queued_alerts.copy() + self._queued_alerts.clear() + self._write_alerts_to_sqlite(alerts_to_send) + except Exception as e: + self._warn_once( + "local-sender-loop", + f"trackio's local logging thread hit an internal error: {e}. User code will continue, but some Trackio data may be dropped.", + ) + + def _write_logs_to_sqlite(self, logs: list[LogEntry]): + try: + logs_by_run: dict[tuple, dict] = {} + for entry in logs: + key = (entry["project"], entry["run"], entry.get("run_id")) + if key not in logs_by_run: + logs_by_run[key] = { + "metrics": [], + "steps": [], + "log_ids": [], + "config": None, + } + logs_by_run[key]["metrics"].append(entry["metrics"]) + logs_by_run[key]["steps"].append(entry.get("step")) + logs_by_run[key]["log_ids"].append(entry.get("log_id")) + if entry.get("config") and logs_by_run[key]["config"] is None: + logs_by_run[key]["config"] = entry["config"] + + for (project, run, run_id), data in logs_by_run.items(): + has_log_ids = any(lid is not None for lid in data["log_ids"]) + SQLiteStorage.bulk_log( + project=project, + run=run, + run_id=run_id, + metrics_list=data["metrics"], + steps=data["steps"], + config=data["config"], + log_ids=data["log_ids"] if has_log_ids else None, + ) + except Exception as e: + self._warn_once( + "write-logs-to-sqlite", + f"trackio failed to flush metric logs for run '{self.name}': {e}. User code will continue, but this batch could not be persisted.", + ) + + def _write_system_logs_to_sqlite(self, logs: list[SystemLogEntry]): + try: + logs_by_run: dict[tuple, dict] = {} + for entry in logs: + key = (entry["project"], entry["run"], entry.get("run_id")) + if key not in logs_by_run: + logs_by_run[key] = {"metrics": [], "timestamps": [], "log_ids": []} + logs_by_run[key]["metrics"].append(entry["metrics"]) + logs_by_run[key]["timestamps"].append(entry.get("timestamp")) + logs_by_run[key]["log_ids"].append(entry.get("log_id")) + + for (project, run, run_id), data in logs_by_run.items(): + has_log_ids = any(lid is not None for lid in data["log_ids"]) + SQLiteStorage.bulk_log_system( + project=project, + run=run, + run_id=run_id, + metrics_list=data["metrics"], + timestamps=data["timestamps"], + log_ids=data["log_ids"] if has_log_ids else None, + ) + except Exception as e: + self._warn_once( + "write-system-logs-to-sqlite", + f"trackio failed to flush system logs for run '{self.name}': {e}. User code will continue, but this batch could not be persisted.", + ) + + def _write_alerts_to_sqlite(self, alerts: list[AlertEntry]): + try: + alerts_by_run: dict[tuple, dict] = {} + for entry in alerts: + key = (entry["project"], entry["run"], entry.get("run_id")) + if key not in alerts_by_run: + alerts_by_run[key] = { + "titles": [], + "texts": [], + "levels": [], + "steps": [], + "timestamps": [], + "alert_ids": [], + } + alerts_by_run[key]["titles"].append(entry["title"]) + alerts_by_run[key]["texts"].append(entry.get("text")) + alerts_by_run[key]["levels"].append(entry["level"]) + alerts_by_run[key]["steps"].append(entry.get("step")) + alerts_by_run[key]["timestamps"].append(entry.get("timestamp")) + alerts_by_run[key]["alert_ids"].append(entry.get("alert_id")) + + for (project, run, run_id), data in alerts_by_run.items(): + has_alert_ids = any(aid is not None for aid in data["alert_ids"]) + SQLiteStorage.bulk_alert( + project=project, + run=run, + run_id=run_id, + titles=data["titles"], + texts=data["texts"], + levels=data["levels"], + steps=data["steps"], + timestamps=data["timestamps"], + alert_ids=data["alert_ids"] if has_alert_ids else None, + ) + except Exception as e: + self._warn_once( + "write-alerts-to-sqlite", + f"trackio failed to flush alerts for run '{self.name}': {e}. User code will continue, but this batch could not be persisted.", + ) + + def _batch_sender(self): + consecutive_failures = 0 + while ( + not self._stop_flag.is_set() + or len(self._queued_logs) > 0 + or len(self._queued_system_logs) > 0 + or len(self._queued_uploads) > 0 + or len(self._queued_alerts) > 0 + or self._has_local_buffer + ): + if not self._stop_flag.is_set(): + if consecutive_failures: + sleep_time = min( + BATCH_SEND_INTERVAL * (2**consecutive_failures), MAX_BACKOFF + ) + else: + sleep_time = BATCH_SEND_INTERVAL + self._stop_flag.wait(timeout=sleep_time) + elif self._has_local_buffer: + self._stop_flag.wait(timeout=BATCH_SEND_INTERVAL) + + try: + with self._client_lock: + if self._client is None: + if self._stop_flag.is_set(): + if self._queued_logs: + self._persist_logs_locally(self._queued_logs) + self._queued_logs.clear() + if self._queued_system_logs: + self._persist_system_logs_locally( + self._queued_system_logs + ) + self._queued_system_logs.clear() + if self._queued_uploads: + self._persist_uploads_locally(self._queued_uploads) + self._queued_uploads.clear() + if self._queued_alerts: + self._write_alerts_to_sqlite(self._queued_alerts) + self._queued_alerts.clear() + return + + failed = False + + if self._queued_logs: + logs_to_send = self._queued_logs.copy() + self._queued_logs.clear() + try: + self._client.predict( + api_name="/bulk_log", + logs=logs_to_send, + hf_token=self._hf_token_for_remote(), + ) + except Exception: + self._persist_logs_locally(logs_to_send) + failed = True + + if self._queued_system_logs: + system_logs_to_send = self._queued_system_logs.copy() + self._queued_system_logs.clear() + try: + self._client.predict( + api_name="/bulk_log_system", + logs=system_logs_to_send, + hf_token=self._hf_token_for_remote(), + ) + except Exception: + self._persist_system_logs_locally(system_logs_to_send) + failed = True + + if self._queued_uploads: + uploads_to_send = self._queued_uploads.copy() + self._queued_uploads.clear() + try: + self._client.predict( + api_name="/bulk_upload_media", + uploads=uploads_to_send, + hf_token=self._hf_token_for_remote(), + ) + except Exception: + self._persist_uploads_locally(uploads_to_send) + failed = True + + if self._queued_alerts: + alerts_to_send = self._queued_alerts.copy() + self._queued_alerts.clear() + try: + self._client.predict( + api_name="/bulk_alert", + alerts=alerts_to_send, + hf_token=self._hf_token_for_remote(), + ) + except Exception: + self._write_alerts_to_sqlite(alerts_to_send) + failed = True + + if failed: + consecutive_failures += 1 + else: + consecutive_failures = 0 + if self._has_local_buffer: + self._flush_local_buffer() + except Exception as e: + consecutive_failures += 1 + self._warn_once( + "remote-sender-loop", + f"trackio's remote logging thread hit an internal error: {e}. User code will continue while Trackio retries in the background.", + ) + + def _persist_logs_locally(self, logs: list[LogEntry]): + if not self._remote_storage_key: + return + try: + logs_by_run: dict[tuple, dict] = {} + for entry in logs: + key = (entry["project"], entry["run"], entry.get("run_id")) + if key not in logs_by_run: + logs_by_run[key] = { + "metrics": [], + "steps": [], + "log_ids": [], + "config": None, + } + logs_by_run[key]["metrics"].append(entry["metrics"]) + logs_by_run[key]["steps"].append(entry.get("step")) + logs_by_run[key]["log_ids"].append(entry.get("log_id")) + if entry.get("config") and logs_by_run[key]["config"] is None: + logs_by_run[key]["config"] = entry["config"] + + for (project, run, run_id), data in logs_by_run.items(): + SQLiteStorage.bulk_log( + project=project, + run=run, + run_id=run_id, + metrics_list=data["metrics"], + steps=data["steps"], + log_ids=data["log_ids"], + config=data["config"], + space_id=self._remote_storage_key, + ) + self._has_local_buffer = True + except Exception as e: + self._warn_once( + "persist-logs-locally", + f"trackio could not persist failed remote metric logs locally for run '{self.name}': {e}. User code will continue, but this batch could be lost.", + ) + + def _persist_system_logs_locally(self, logs: list[SystemLogEntry]): + if not self._remote_storage_key: + return + try: + logs_by_run: dict[tuple, dict] = {} + for entry in logs: + key = (entry["project"], entry["run"], entry.get("run_id")) + if key not in logs_by_run: + logs_by_run[key] = {"metrics": [], "timestamps": [], "log_ids": []} + logs_by_run[key]["metrics"].append(entry["metrics"]) + logs_by_run[key]["timestamps"].append(entry.get("timestamp")) + logs_by_run[key]["log_ids"].append(entry.get("log_id")) + + for (project, run, run_id), data in logs_by_run.items(): + SQLiteStorage.bulk_log_system( + project=project, + run=run, + run_id=run_id, + metrics_list=data["metrics"], + timestamps=data["timestamps"], + log_ids=data["log_ids"], + space_id=self._remote_storage_key, + ) + self._has_local_buffer = True + except Exception as e: + self._warn_once( + "persist-system-logs-locally", + f"trackio could not persist failed remote system logs locally for run '{self.name}': {e}. User code will continue, but this batch could be lost.", + ) + + def _persist_uploads_locally(self, uploads: list[UploadEntry]): + if not self._remote_storage_key: + return + try: + for entry in uploads: + file_data = entry.get("uploaded_file") + file_path = "" + if isinstance(file_data, dict): + file_path = file_data.get("path", "") + elif hasattr(file_data, "path"): + file_path = str(file_data.path) + else: + file_path = str(file_data) + SQLiteStorage.add_pending_upload( + project=entry["project"], + space_id=self._remote_storage_key, + run_id=entry.get("run_id"), + run_name=entry.get("run"), + step=entry.get("step"), + file_path=file_path, + relative_path=entry.get("relative_path"), + ) + self._has_local_buffer = True + except Exception as e: + self._warn_once( + "persist-uploads-locally", + f"trackio could not persist failed remote file uploads locally for run '{self.name}': {e}. User code will continue, but some artifacts could be lost.", + ) + + def _flush_local_buffer(self): + try: + buffered_logs = SQLiteStorage.get_pending_logs(self.project) + if buffered_logs: + self._client.predict( + api_name="/bulk_log", + logs=buffered_logs["logs"], + hf_token=self._hf_token_for_remote(), + ) + SQLiteStorage.clear_pending_logs(self.project, buffered_logs["ids"]) + + buffered_sys = SQLiteStorage.get_pending_system_logs(self.project) + if buffered_sys: + self._client.predict( + api_name="/bulk_log_system", + logs=buffered_sys["logs"], + hf_token=self._hf_token_for_remote(), + ) + SQLiteStorage.clear_pending_system_logs( + self.project, buffered_sys["ids"] + ) + + buffered_uploads = SQLiteStorage.get_pending_uploads(self.project) + if buffered_uploads: + upload_entries = [] + for u in buffered_uploads["uploads"]: + fp = u["file_path"] + if Path(fp).exists(): + upload_entries.append( + { + "project": u["project"], + "run": u["run"], + "run_id": u.get("run_id"), + "step": u["step"], + "relative_path": u["relative_path"], + "uploaded_file": handle_file(fp), + } + ) + if upload_entries: + self._client.predict( + api_name="/bulk_upload_media", + uploads=upload_entries, + hf_token=self._hf_token_for_remote(), + ) + SQLiteStorage.clear_pending_uploads( + self.project, buffered_uploads["ids"] + ) + + self._has_local_buffer = False + except Exception as e: + self._warn_once( + "flush-local-buffer", + f"trackio could not flush buffered remote data for run '{self.name}': {e}. It will retry later if possible.", + ) + + def _init_client_background(self): + if self._client is None: + fib = utils.fibo() + for sleep_coefficient in fib: + if self._stop_flag.is_set(): + break + try: + if self._server_base_url is not None: + client = RemoteClient( + self._server_base_url, + hf_token=None, + write_token=self._write_token, + verbose=False, + ) + else: + client = RemoteClient( + self.url, + hf_token=huggingface_hub.utils.get_token(), + verbose=False, + ) + + with self._client_lock: + self._client = client + break + except Exception: + pass + sleep_time = min(0.1 * sleep_coefficient, MAX_BACKOFF) + self._stop_flag.wait(timeout=sleep_time) + + self._batch_sender() + + def _queue_upload( + self, + file_path, + step: int | None, + relative_path: str | None = None, + use_run_name: bool = True, + ): + try: + if self._is_local: + self._save_upload_locally(file_path, step, relative_path, use_run_name) + else: + upload_entry: UploadEntry = { + "project": self.project, + "run": self.name if use_run_name else None, + "run_id": self.id if use_run_name else None, + "step": step, + "relative_path": relative_path, + "uploaded_file": handle_file(file_path), + } + with self._client_lock: + self._queued_uploads.append(upload_entry) + self._ensure_sender_alive() + if not self._thread_is_alive("_client_thread"): + self._flush_queues_inline() + except Exception as e: + self._warn_once( + "queue-upload", + f"trackio could not queue the artifact '{file_path}' for run '{self.name}': {e}. User code will continue, but this artifact could be missing.", + ) + + def _save_upload_locally( + self, + file_path, + step: int | None, + relative_path: str | None = None, + use_run_name: bool = True, + ): + media_path = get_project_media_path( + project=self.project, + run=self.name if use_run_name else None, + step=step, + relative_path=relative_path, + ) + src = Path(file_path) + if src.exists() and str(src.resolve()) != str(Path(media_path).resolve()): + shutil.copy(str(src), str(media_path)) + + def _process_media(self, value: TrackioMedia, step: int | None) -> dict: + value._save(self.project, self.name, step if step is not None else 0) + if self._space_id or self._server_base_url: + self._queue_upload(value._get_absolute_file_path(), step) + return value._to_dict() + + def _scan_and_queue_media_uploads(self, value: Any, step: int | None): + if not self._space_id and not self._server_base_url: + return + if isinstance(value, dict): + if value.get("_type") in [ + "trackio.image", + "trackio.video", + "trackio.audio", + ]: + file_path = value.get("file_path") + if file_path: + absolute_path = MEDIA_DIR / file_path + self._queue_upload(absolute_path, step) + return + for nested in value.values(): + self._scan_and_queue_media_uploads(nested, step) + return + if isinstance(value, list): + for nested in value: + self._scan_and_queue_media_uploads(nested, step) + + def _ensure_sender_alive(self): + if self._is_local: + if ( + not self._thread_is_alive("_local_sender_thread") + and not self._stop_flag.is_set() + ): + self._start_background_thread( + "_local_sender_thread", + self._local_batch_sender, + warning_key="local-sender-thread-restart", + description="local Trackio logging thread", + ) + else: + if ( + not self._thread_is_alive("_client_thread") + and not self._stop_flag.is_set() + ): + self._start_background_thread( + "_client_thread", + self._init_client_background, + warning_key="remote-sender-thread-restart", + description="remote Trackio logging thread", + ) + + def log(self, metrics: dict, step: int | None = None): + try: + renamed_keys = [] + new_metrics = {} + + for k, v in metrics.items(): + if k in utils.RESERVED_KEYS or k.startswith("__"): + new_key = f"__{k}" + renamed_keys.append(k) + new_metrics[new_key] = v + else: + new_metrics[k] = v + + if renamed_keys: + _emit_nonfatal_warning( + f"Reserved keys renamed: {renamed_keys} → '__{{key}}'" + ) + + metrics = new_metrics + media_step = step if step is not None else self._next_step + for key, value in metrics.items(): + if isinstance(value, Table): + metrics[key] = value._to_dict( + project=self.project, run=self.name, step=media_step + ) + self._scan_and_queue_media_uploads(metrics[key], media_step) + elif isinstance(value, Trace): + metrics[key] = value._to_dict( + project=self.project, run=self.name, step=media_step + ) + self._scan_and_queue_media_uploads(metrics[key], media_step) + elif ( + isinstance(value, list) + and value + and all(isinstance(item, Trace) for item in value) + ): + converted = [ + item._to_dict( + project=self.project, run=self.name, step=media_step + ) + for item in value + ] + metrics[key] = converted + for item in converted: + self._scan_and_queue_media_uploads(item, media_step) + elif isinstance(value, Histogram): + metrics[key] = value._to_dict() + elif isinstance(value, Markdown): + metrics[key] = value._to_dict() + elif isinstance(value, TrackioMedia): + metrics[key] = self._process_media(value, media_step) + metrics = utils.serialize_values(metrics) + + if step is None: + step = self._next_step + self._next_step = max(self._next_step, step + 1) + + config_to_log = None + if not self._config_logged and self.config: + config_to_log = utils.to_json_safe(self.config) + self._config_logged = True + + log_entry: LogEntry = { + "project": self.project, + "run": self.name, + "run_id": self.id, + "metrics": metrics, + "step": step, + "config": config_to_log, + "log_id": uuid.uuid4().hex, + } + + with self._client_lock: + self._queued_logs.append(log_entry) + self._ensure_sender_alive() + if not self._thread_is_alive( + "_local_sender_thread" if self._is_local else "_client_thread" + ): + self._flush_queues_inline() + except Exception as e: + _emit_nonfatal_warning(f"trackio.log() failed to process metrics: {e}") + + def alert( + self, + title: str, + text: str | None = None, + level: AlertLevel = AlertLevel.WARN, + step: int | None = None, + webhook_url: str | None = None, + ): + try: + if step is None: + step = max(self._next_step - 1, 0) + timestamp = datetime.now(timezone.utc).isoformat() + + print(format_alert_terminal(level, title, text, step)) + + alert_entry: AlertEntry = { + "project": self.project, + "run": self.name, + "run_id": self.id, + "title": title, + "text": text, + "level": level.value, + "step": step, + "timestamp": timestamp, + "alert_id": uuid.uuid4().hex, + } + + with self._client_lock: + self._queued_alerts.append(alert_entry) + self._ensure_sender_alive() + if not self._thread_is_alive( + "_local_sender_thread" if self._is_local else "_client_thread" + ): + self._flush_queues_inline() + + url = webhook_url or self._webhook_url + if url and should_send_webhook(level, self._webhook_min_level): + t = threading.Thread( + target=send_webhook, + args=( + url, + level, + title, + text, + self.project, + self.name, + step, + timestamp, + ), + daemon=True, + ) + t.start() + except Exception as e: + _emit_nonfatal_warning(f"trackio.alert() failed: {e}") + + def log_system(self, metrics: dict): + try: + metrics = utils.serialize_values(metrics) + timestamp = datetime.now(timezone.utc).isoformat() + + system_log_entry: SystemLogEntry = { + "project": self.project, + "run": self.name, + "run_id": self.id, + "metrics": metrics, + "timestamp": timestamp, + "log_id": uuid.uuid4().hex, + } + + with self._client_lock: + self._queued_system_logs.append(system_log_entry) + self._ensure_sender_alive() + if not self._thread_is_alive( + "_local_sender_thread" if self._is_local else "_client_thread" + ): + self._flush_queues_inline() + except Exception as e: + _emit_nonfatal_warning(f"trackio.log_system() failed: {e}") + + def finish(self): + try: + if self._gpu_monitor is not None: + try: + self._gpu_monitor.stop() + except Exception as e: + self._warn_once( + "finish-gpu-monitor", + f"trackio.finish() could not stop automatic GPU logging cleanly: {e}.", + ) + + if self._cpu_monitor is not None: + try: + self._cpu_monitor.stop() + except Exception as e: + self._warn_once( + "finish-cpu-monitor", + f"trackio.finish() could not stop automatic CPU logging cleanly: {e}.", + ) + + self._stop_flag.set() + + if self._is_local: + if self._local_sender_thread is not None: + print("* Run finished. Uploading logs to Trackio (please wait...)") + self._local_sender_thread.join(timeout=30) + if self._local_sender_thread.is_alive(): + _emit_nonfatal_warning( + "Could not flush all logs within 30s. Some data may be buffered locally." + ) + else: + with self._client_lock: + self._flush_queues_inline() + else: + if self._client_thread is not None: + print( + "* Run finished. Uploading logs to the remote Trackio server (please wait...)" + ) + self._client_thread.join(timeout=30) + if self._client_thread.is_alive(): + _emit_nonfatal_warning( + "Could not flush all logs within 30s. Some data may be buffered locally." + ) + else: + with self._client_lock: + self._flush_queues_inline() + + try: + has_pending = SQLiteStorage.has_pending_data(self.project) + except Exception as e: + self._warn_once( + "finish-pending-data", + f"trackio.finish() could not inspect pending buffered logs for project '{self.project}': {e}.", + ) + has_pending = False + + if has_pending: + if self._space_id is not None: + retry = f'trackio.init(project="{self.project}", space_id="{self._space_id}")' + else: + retry = f'trackio.init(project="{self.project}", server_url="{self._server_base_url}")' + _emit_nonfatal_warning( + f"* Some logs could not be sent to the remote server (it may still be starting up). " + f"They have been saved locally and will be sent automatically next time you call: " + f"{retry}" + ) + except Exception as e: + _emit_nonfatal_warning(f"trackio.finish() failed: {e}") diff --git a/trackio/server.py b/trackio/server.py new file mode 100644 index 0000000000000000000000000000000000000000..4c26e894520276ccdc3530b0e53d8eca8d9a0186 --- /dev/null +++ b/trackio/server.py @@ -0,0 +1,1083 @@ +"""The main API layer for the Trackio UI.""" + +import base64 +import logging +import os +import re +import secrets +import shutil +import sqlite3 +import threading +import time +import warnings +from collections import deque +from functools import lru_cache +from typing import Any +from urllib.parse import urlencode + +import httpx +import huggingface_hub as hf +from starlette.requests import Request +from starlette.responses import RedirectResponse +from starlette.routing import Route + +import trackio.utils as utils +from trackio.asgi_app import ( + cleanup_uploaded_temp_file, + consume_uploaded_temp_file, + create_trackio_starlette_app, +) +from trackio.exceptions import TrackioAPIError +from trackio.media import get_project_media_path +from trackio.sqlite_storage import SQLiteStorage +from trackio.typehints import AlertEntry, LogEntry, SystemLogEntry, UploadEntry +from trackio.utils import on_spaces + +HfApi = hf.HfApi() + +logger = logging.getLogger("trackio") + +_write_queue: deque[tuple[str, Any]] = deque() +_flush_thread: threading.Thread | None = None +_flush_lock = threading.Lock() +_FLUSH_INTERVAL = 2.0 +_MAX_RETRIES = 30 + +_LOGS_BATCH_MAX_RUNS = 64 +_LOGS_BATCH_MAX_POINTS = 10_000 + + +def _normalize_logs_batch_runs(runs: Any) -> list[dict[str, Any]]: + if not isinstance(runs, list): + raise TrackioAPIError("runs must be a list") + if len(runs) > _LOGS_BATCH_MAX_RUNS: + raise TrackioAPIError( + f"runs cannot contain more than {_LOGS_BATCH_MAX_RUNS} entries" + ) + out: list[dict[str, Any]] = [] + for i, r in enumerate(runs): + if not isinstance(r, dict): + raise TrackioAPIError(f"runs[{i}] must be an object") + out.append({"run": r.get("run"), "run_id": r.get("run_id")}) + return out + + +def _normalize_logs_batch_max_points(max_points: Any) -> int: + if max_points is None: + return 3000 + if isinstance(max_points, bool): + raise TrackioAPIError("max_points must be a number or null") + if isinstance(max_points, float): + if not max_points.is_integer(): + raise TrackioAPIError("max_points must be a whole number") + max_points = int(max_points) + if not isinstance(max_points, int): + raise TrackioAPIError("max_points must be an integer or null") + if max_points < 1: + return 3000 + return min(max_points, _LOGS_BATCH_MAX_POINTS) + + +def _enqueue_write(kind: str, payload: Any) -> None: + _write_queue.append((kind, payload)) + _ensure_flush_thread() + + +def _ensure_flush_thread() -> None: + global _flush_thread + with _flush_lock: + if _flush_thread is not None and _flush_thread.is_alive(): + return + _flush_thread = threading.Thread(target=_flush_loop, daemon=True) + _flush_thread.start() + + +def _flush_loop() -> None: + retries = 0 + while _write_queue and retries < _MAX_RETRIES: + kind, payload = _write_queue[0] + try: + if kind == "bulk_log": + SQLiteStorage.bulk_log(**payload) + elif kind == "bulk_log_system": + SQLiteStorage.bulk_log_system(**payload) + elif kind == "bulk_alert": + SQLiteStorage.bulk_alert(**payload) + _write_queue.popleft() + retries = 0 + except sqlite3.OperationalError as e: + msg = str(e).lower() + if "disk i/o error" in msg or "readonly" in msg: + retries += 1 + logger.warning( + "write queue: flush failed (%s), retry %d/%d", + e, + retries, + _MAX_RETRIES, + ) + time.sleep(min(_FLUSH_INTERVAL * retries, 15.0)) + else: + logger.error("write queue: non-retryable error (%s), dropping entry", e) + _write_queue.popleft() + retries = 0 + if _write_queue: + logger.error( + "write queue: giving up after %d retries, %d entries dropped", + _MAX_RETRIES, + len(_write_queue), + ) + _write_queue.clear() + + +write_token = secrets.token_urlsafe(32) + +OAUTH_CALLBACK_PATH = "/login/callback" +OAUTH_START_PATH = "/oauth/hf/start" + + +def _hf_access_token(request: Request) -> str | None: + session_id = None + try: + session_id = request.headers.get("x-trackio-oauth-session") + except (AttributeError, TypeError): + pass + if session_id and session_id in _oauth_sessions: + token, created = _oauth_sessions[session_id] + if time.monotonic() - created <= _OAUTH_SESSION_TTL: + return token + del _oauth_sessions[session_id] + cookie_header = "" + try: + cookie_header = request.headers.get("cookie", "") + except (AttributeError, TypeError): + pass + if cookie_header: + for cookie in cookie_header.split(";"): + parts = cookie.strip().split("=", 1) + if len(parts) == 2 and parts[0] == "trackio_hf_access_token": + return parts[1] or None + return None + + +def _authorization_bearer_token(request: Request) -> str | None: + auth = request.headers.get("authorization") or request.headers.get("Authorization") + if not auth: + return None + parts = auth.split() + if len(parts) != 2 or parts[0].lower() != "bearer": + return None + token = parts[1].strip() + return token or None + + +def _oauth_redirect_uri(request: Request) -> str: + space_host = os.getenv("SPACE_HOST") + if space_host: + space_host = space_host.split(",")[0] + return f"https://{space_host}{OAUTH_CALLBACK_PATH}" + return str(request.base_url).rstrip("/") + OAUTH_CALLBACK_PATH + + +_OAUTH_STATE_TTL = 86400 +_OAUTH_SESSION_TTL = 86400 * 30 +_pending_oauth_states: dict[str, float] = {} +_oauth_sessions: dict[str, tuple[str, float]] = {} + + +def _evict_expired_oauth(): + now = time.monotonic() + expired_states = [ + k for k, t in _pending_oauth_states.items() if now - t > _OAUTH_STATE_TTL + ] + for k in expired_states: + del _pending_oauth_states[k] + expired_sessions = [ + k for k, (_, t) in _oauth_sessions.items() if now - t > _OAUTH_SESSION_TTL + ] + for k in expired_sessions: + del _oauth_sessions[k] + + +def oauth_hf_start(request: Request): + client_id = os.getenv("OAUTH_CLIENT_ID") + if not client_id: + return RedirectResponse(url="/", status_code=302) + _evict_expired_oauth() + state = secrets.token_urlsafe(32) + _pending_oauth_states[state] = time.monotonic() + redirect_uri = _oauth_redirect_uri(request) + scope = os.getenv("OAUTH_SCOPES", "openid profile").strip() + url = "https://huggingface.co/oauth/authorize?" + urlencode( + { + "client_id": client_id, + "redirect_uri": redirect_uri, + "response_type": "code", + "scope": scope, + "state": state, + } + ) + return RedirectResponse(url=url, status_code=302) + + +def oauth_hf_callback(request: Request): + client_id = os.getenv("OAUTH_CLIENT_ID") + client_secret = os.getenv("OAUTH_CLIENT_SECRET") + err = "/?oauth_error=1" + if not client_id or not client_secret: + return RedirectResponse(url=err, status_code=302) + got_state = request.query_params.get("state") + code = request.query_params.get("code") + if not got_state or got_state not in _pending_oauth_states or not code: + return RedirectResponse(url=err, status_code=302) + state_created = _pending_oauth_states.pop(got_state) + if time.monotonic() - state_created > _OAUTH_STATE_TTL: + return RedirectResponse(url=err, status_code=302) + redirect_uri = _oauth_redirect_uri(request) + auth_b64 = base64.b64encode(f"{client_id}:{client_secret}".encode()).decode() + try: + with httpx.Client() as client: + token_resp = client.post( + "https://huggingface.co/oauth/token", + headers={"Authorization": f"Basic {auth_b64}"}, + data={ + "grant_type": "authorization_code", + "code": code, + "redirect_uri": redirect_uri, + "client_id": client_id, + }, + ) + token_resp.raise_for_status() + access_token = token_resp.json()["access_token"] + except Exception: + return RedirectResponse(url=err, status_code=302) + session_id = secrets.token_urlsafe(32) + _oauth_sessions[session_id] = (access_token, time.monotonic()) + _on_spaces = on_spaces() + resp = RedirectResponse(url=f"/?oauth_session={session_id}", status_code=302) + resp.set_cookie( + key="trackio_hf_access_token", + value=access_token, + httponly=True, + samesite="none" if _on_spaces else "lax", + max_age=86400 * 30, + path="/", + secure=_on_spaces, + ) + return resp + + +def oauth_logout(request: Request): + _on_spaces = on_spaces() + resp = RedirectResponse(url="/", status_code=302) + resp.delete_cookie( + "trackio_hf_access_token", + path="/", + samesite="none" if _on_spaces else "lax", + secure=_on_spaces, + ) + return resp + + +@lru_cache(maxsize=32) +def check_hf_token_has_write_access(hf_token: str | None) -> None: + """ + Checks if the provided hf_token has write access to the space. If it does not + have write access, a PermissionError is raised. Otherwise, the function returns None. + + The function is cached in two separate caches to avoid unnecessary API calls to /whoami-v2 which is heavily rate-limited: + - A cache of the whoami response for the hf_token using .whoami(token=hf_token, cache=True). + - This entire function is cached using @lru_cache(maxsize=32). + """ + if on_spaces(): + if hf_token is None: + raise PermissionError( + "Expected a HF_TOKEN to be provided when logging to a Space" + ) + space_token = os.getenv("HF_TOKEN") + if space_token and hf_token == space_token: + # If the HF_TOKEN is the same as the space token, we can assume that the user has write access. + # This avoids unnecessary API calls to /whoami-v2 which is heavily rate-limited. + return + who = HfApi.whoami(token=hf_token, cache=True) + owner_name = os.getenv("SPACE_AUTHOR_NAME") + repo_name = os.getenv("SPACE_REPO_NAME") + orgs = [o["name"] for o in who["orgs"]] + if owner_name != who["name"] and owner_name not in orgs: + raise PermissionError( + "Expected the provided hf_token to be the user owner of the space, or be a member of the org owner of the space" + ) + access_token = who["auth"]["accessToken"] + if access_token["role"] == "fineGrained": + matched = False + for item in access_token["fineGrained"]["scoped"]: + if ( + item["entity"]["type"] == "space" + and item["entity"]["name"] == f"{owner_name}/{repo_name}" + and "repo.write" in item["permissions"] + ): + matched = True + break + if ( + ( + item["entity"]["type"] == "user" + or item["entity"]["type"] == "org" + ) + and item["entity"]["name"] == owner_name + and "repo.write" in item["permissions"] + ): + matched = True + break + if not matched: + raise PermissionError( + "Expected the provided hf_token with fine grained permissions to provide write access to the space" + ) + elif access_token["role"] != "write": + raise PermissionError( + "Expected the provided hf_token to provide write permissions" + ) + + +_oauth_write_cache: dict[str, tuple[bool, float]] = {} +_OAUTH_WRITE_CACHE_TTL = 300 + + +def check_oauth_token_has_write_access(oauth_token: str | None) -> None: + if not on_spaces(): + return + if oauth_token is None: + raise PermissionError( + "Expected an oauth to be provided when logging to a Space" + ) + now = time.monotonic() + cached = _oauth_write_cache.get(oauth_token) + if cached is not None: + allowed, ts = cached + if now - ts < _OAUTH_WRITE_CACHE_TTL: + if not allowed: + raise PermissionError( + "Expected the oauth token to be the user owner of the space, or be a member of the org owner of the space" + ) + return + who = HfApi.whoami(oauth_token, cache=True) + user_name = who["name"] + owner_name = os.getenv("SPACE_AUTHOR_NAME") + if user_name == owner_name: + _oauth_write_cache[oauth_token] = (True, now) + return + for org in who["orgs"]: + if org["name"] == owner_name and org["roleInOrg"] == "write": + _oauth_write_cache[oauth_token] = (True, now) + return + _oauth_write_cache[oauth_token] = (False, now) + raise PermissionError( + "Expected the oauth token to be the user owner of the space, or be a member of the org owner of the space" + ) + + +def check_write_access(request: Request, token: str) -> bool: + expected_token = token or "" + hdr = request.headers.get("x-trackio-write-token") + if hdr is not None: + return secrets.compare_digest(hdr, expected_token) + cookies = request.headers.get("cookie", "") + if cookies: + for cookie in cookies.split(";"): + parts = cookie.strip().split("=", 1) + if len(parts) == 2 and parts[0] == "trackio_write_token": + return secrets.compare_digest(parts[1], expected_token) + if hasattr(request, "query_params") and request.query_params: + qp = request.query_params.get("write_token") + return secrets.compare_digest(qp or "", expected_token) + return False + + +def assert_can_write_metrics(request: Request, hf_token: str | None) -> None: + if on_spaces(): + check_hf_token_has_write_access(hf_token) + else: + if check_write_access(request, write_token): + return + raise TrackioAPIError( + "A write_token is required to log metrics or upload to this server. " + "Use the write-access URL from trackio.show(), set TRACKIO_WRITE_TOKEN, " + "or send header X-Trackio-Write-Token." + ) + + +def assert_can_stage_upload(request: Request) -> None: + if not on_spaces(): + if check_write_access(request, write_token): + return + raise TrackioAPIError( + "A write_token is required to upload files to this server. " + "Use the write-access URL from trackio.show(), set TRACKIO_WRITE_TOKEN, " + "or send header X-Trackio-Write-Token." + ) + + bearer_token = _authorization_bearer_token(request) + if bearer_token is not None: + try: + check_hf_token_has_write_access(bearer_token) + except PermissionError as e: + raise TrackioAPIError(str(e)) from e + return + + oauth_token = _hf_access_token(request) + if oauth_token is not None: + try: + check_oauth_token_has_write_access(oauth_token) + except PermissionError as e: + raise TrackioAPIError(str(e)) from e + return + + if check_write_access(request, write_token): + return + + raise TrackioAPIError( + "Sign in with Hugging Face to upload files, or use a link that includes the write_token query parameter." + ) + + +def assert_can_mutate_runs(request: Request) -> None: + if not on_spaces(): + if check_write_access(request, write_token): + return + raise TrackioAPIError( + "A write_token is required to delete or rename runs. " + "Open the dashboard using the link that includes the write_token query parameter." + ) + hf_tok = _hf_access_token(request) + if hf_tok is not None: + try: + check_oauth_token_has_write_access(hf_tok) + except PermissionError as e: + raise TrackioAPIError(str(e)) from e + return + if check_write_access(request, write_token): + return + raise TrackioAPIError( + "Sign in with Hugging Face to delete or rename runs. You need write access to this Space, " + "or open the dashboard using a link that includes the write_token query parameter." + ) + + +def get_run_mutation_status(request: Request) -> dict[str, Any]: + if not on_spaces(): + if check_write_access(request, write_token): + return {"spaces": False, "allowed": True, "auth": "local"} + return {"spaces": False, "allowed": False, "auth": "none"} + hf_tok = _hf_access_token(request) + if hf_tok is not None: + try: + check_oauth_token_has_write_access(hf_tok) + return {"spaces": True, "allowed": True, "auth": "oauth"} + except PermissionError: + return {"spaces": True, "allowed": False, "auth": "oauth_insufficient"} + if check_write_access(request, write_token): + return {"spaces": True, "allowed": True, "auth": "write_token"} + return {"spaces": True, "allowed": False, "auth": "none"} + + +def upload_db_to_space( + request: Request, + project: str, + uploaded_db: dict, + hf_token: str | None, +) -> None: + assert_can_write_metrics(request, hf_token) + uploaded_path = consume_uploaded_temp_file(request, uploaded_db) + try: + db_project_path = SQLiteStorage.get_project_db_path(project) + os.makedirs(os.path.dirname(db_project_path), exist_ok=True) + shutil.copy(uploaded_path, db_project_path) + finally: + cleanup_uploaded_temp_file(uploaded_path) + + +def bulk_upload_media( + request: Request, + uploads: list[UploadEntry], + hf_token: str | None, +) -> None: + assert_can_write_metrics(request, hf_token) + for upload in uploads: + uploaded_path = consume_uploaded_temp_file(request, upload["uploaded_file"]) + try: + media_path = get_project_media_path( + project=upload["project"], + run=upload["run"], + step=upload["step"], + relative_path=upload["relative_path"], + ) + shutil.copy(uploaded_path, media_path) + finally: + cleanup_uploaded_temp_file(uploaded_path) + + +def log( + request: Request, + project: str, + run: str, + metrics: dict[str, Any], + step: int | None, + hf_token: str | None, + run_id: str | None = None, +) -> None: + assert_can_write_metrics(request, hf_token) + SQLiteStorage.log( + project=project, run=run, run_id=run_id, metrics=metrics, step=step + ) + + +def bulk_log( + request: Request, + logs: list[LogEntry], + hf_token: str | None, +) -> None: + assert_can_write_metrics(request, hf_token) + + logs_by_run = {} + for log_entry in logs: + key = (log_entry["project"], log_entry["run"], log_entry.get("run_id")) + if key not in logs_by_run: + logs_by_run[key] = { + "metrics": [], + "steps": [], + "log_ids": [], + "config": None, + } + logs_by_run[key]["metrics"].append(log_entry["metrics"]) + logs_by_run[key]["steps"].append(log_entry.get("step")) + logs_by_run[key]["log_ids"].append(log_entry.get("log_id")) + if log_entry.get("config") and logs_by_run[key]["config"] is None: + logs_by_run[key]["config"] = log_entry["config"] + + for (project, run, run_id), data in logs_by_run.items(): + has_log_ids = any(lid is not None for lid in data["log_ids"]) + payload = dict( + project=project, + run=run, + run_id=run_id, + metrics_list=data["metrics"], + steps=data["steps"], + config=data["config"], + log_ids=data["log_ids"] if has_log_ids else None, + ) + try: + SQLiteStorage.bulk_log(**payload) + except sqlite3.OperationalError: + _enqueue_write("bulk_log", payload) + + +def bulk_log_system( + request: Request, + logs: list[SystemLogEntry], + hf_token: str | None, +) -> None: + assert_can_write_metrics(request, hf_token) + + logs_by_run = {} + for log_entry in logs: + key = (log_entry["project"], log_entry["run"], log_entry.get("run_id")) + if key not in logs_by_run: + logs_by_run[key] = {"metrics": [], "timestamps": [], "log_ids": []} + logs_by_run[key]["metrics"].append(log_entry["metrics"]) + logs_by_run[key]["timestamps"].append(log_entry.get("timestamp")) + logs_by_run[key]["log_ids"].append(log_entry.get("log_id")) + + for (project, run, run_id), data in logs_by_run.items(): + has_log_ids = any(lid is not None for lid in data["log_ids"]) + payload = dict( + project=project, + run=run, + run_id=run_id, + metrics_list=data["metrics"], + timestamps=data["timestamps"], + log_ids=data["log_ids"] if has_log_ids else None, + ) + try: + SQLiteStorage.bulk_log_system(**payload) + except sqlite3.OperationalError: + _enqueue_write("bulk_log_system", payload) + + +def bulk_alert( + request: Request, + alerts: list[AlertEntry], + hf_token: str | None, +) -> None: + assert_can_write_metrics(request, hf_token) + + alerts_by_run: dict[tuple, dict] = {} + for entry in alerts: + key = (entry["project"], entry["run"], entry.get("run_id")) + if key not in alerts_by_run: + alerts_by_run[key] = { + "titles": [], + "texts": [], + "levels": [], + "steps": [], + "timestamps": [], + "alert_ids": [], + } + alerts_by_run[key]["titles"].append(entry["title"]) + alerts_by_run[key]["texts"].append(entry.get("text")) + alerts_by_run[key]["levels"].append(entry["level"]) + alerts_by_run[key]["steps"].append(entry.get("step")) + alerts_by_run[key]["timestamps"].append(entry.get("timestamp")) + alerts_by_run[key]["alert_ids"].append(entry.get("alert_id")) + + for (project, run, run_id), data in alerts_by_run.items(): + has_alert_ids = any(aid is not None for aid in data["alert_ids"]) + payload = dict( + project=project, + run=run, + run_id=run_id, + titles=data["titles"], + texts=data["texts"], + levels=data["levels"], + steps=data["steps"], + timestamps=data["timestamps"], + alert_ids=data["alert_ids"] if has_alert_ids else None, + ) + try: + SQLiteStorage.bulk_alert(**payload) + except sqlite3.OperationalError: + _enqueue_write("bulk_alert", payload) + + +def get_alerts( + project: str, + run: str | None = None, + run_id: str | None = None, + level: str | None = None, + since: str | None = None, +) -> list[dict[str, Any]]: + return SQLiteStorage.get_alerts( + project, run_name=run, run_id=run_id, level=level, since=since + ) + + +def get_metric_values( + project: str, + run: str | None, + metric_name: str, + step: int | None = None, + around_step: int | None = None, + at_time: str | None = None, + window: int | None = None, + run_id: str | None = None, +) -> list[dict[str, Any]]: + return SQLiteStorage.get_metric_values( + project, + run, + metric_name, + step=step, + around_step=around_step, + at_time=at_time, + window=window, + run_id=run_id, + ) + + +def get_runs_for_project(project: str) -> list[dict[str, Any]]: + return SQLiteStorage.get_run_records(project) + + +def get_run_configs(project: str) -> dict[str, Any]: + return SQLiteStorage.get_all_run_configs(project) + + +def get_metrics_for_run( + project: str, run: str | None = None, run_id: str | None = None +) -> list[str]: + return SQLiteStorage.get_all_metrics_for_run(project, run, run_id=run_id) + + +def filter_metrics_by_regex(metrics: list[str], filter_pattern: str) -> list[str]: + if not filter_pattern.strip(): + return metrics + try: + pattern = re.compile(filter_pattern, re.IGNORECASE) + return [metric for metric in metrics if pattern.search(metric)] + except re.error: + return [ + metric for metric in metrics if filter_pattern.lower() in metric.lower() + ] + + +def get_all_projects() -> list[str]: + return SQLiteStorage.get_projects() + + +def get_project_summary(project: str) -> dict[str, Any]: + runs = SQLiteStorage.get_run_records(project) + if not runs: + return {"project": project, "num_runs": 0, "runs": [], "last_activity": None} + + last_steps = SQLiteStorage.get_max_steps_for_runs(project) + + return { + "project": project, + "num_runs": len(runs), + "runs": runs, + "last_activity": max(last_steps.values()) if last_steps else None, + } + + +def get_run_summary( + project: str, run: str | None = None, run_id: str | None = None +) -> dict[str, Any]: + if run_id is not None: + record = next( + ( + record + for record in SQLiteStorage.get_run_records(project) + if record["id"] == run_id + ), + None, + ) + if record is not None: + run = record["name"] + + num_logs = SQLiteStorage.get_log_count(project, run, run_id=run_id) + if num_logs == 0: + return { + "project": project, + "run": run, + "run_id": run_id, + "num_logs": 0, + "metrics": [], + "config": None, + "last_step": None, + } + + metrics = SQLiteStorage.get_all_metrics_for_run(project, run, run_id=run_id) + config = SQLiteStorage.get_run_config(project, run, run_id=run_id) + last_step = SQLiteStorage.get_last_step(project, run, run_id=run_id) + + return { + "project": project, + "run": run, + "run_id": run_id, + "num_logs": num_logs, + "metrics": metrics, + "config": config, + "last_step": last_step, + } + + +def get_system_metrics_for_run( + project: str, run: str | None = None, run_id: str | None = None +) -> list[str]: + return SQLiteStorage.get_all_system_metrics_for_run(project, run, run_id=run_id) + + +def get_system_logs( + project: str, run: str | None = None, run_id: str | None = None +) -> list[dict[str, Any]]: + return SQLiteStorage.get_system_logs(project, run, run_id=run_id, max_points=3000) + + +def get_system_logs_batch( + project: str, + runs: list[dict[str, Any]], + max_points: int | None = 3000, +) -> list[dict[str, Any]]: + runs_clean = _normalize_logs_batch_runs(runs) + mp = _normalize_logs_batch_max_points(max_points) + return SQLiteStorage.get_system_logs_batch(project, runs_clean, max_points=mp) + + +def get_snapshot( + project: str, + run: str | None = None, + run_id: str | None = None, + step: int | None = None, + around_step: int | None = None, + at_time: str | None = None, + window: int | None = None, +) -> dict[str, Any]: + return SQLiteStorage.get_snapshot( + project, + run, + run_id=run_id, + step=step, + around_step=around_step, + at_time=at_time, + window=window, + ) + + +def get_logs( + project: str, run: str | None = None, run_id: str | None = None +) -> list[dict[str, Any]]: + return SQLiteStorage.get_logs(project, run, max_points=3000, run_id=run_id) + + +def get_logs_batch( + project: str, + runs: list[dict[str, Any]], + max_points: int | None = 3000, +) -> list[dict[str, Any]]: + runs_clean = _normalize_logs_batch_runs(runs) + mp = _normalize_logs_batch_max_points(max_points) + return SQLiteStorage.get_logs_batch(project, runs_clean, max_points=mp) + + +_ALLOWED_TRACE_SORTS = { + "request_time_desc", + "request_time_asc", + "step_asc", + "step_desc", +} + + +def get_traces( + project: str, + run: str | None = None, + run_id: str | None = None, + search: str | None = None, + sort: str | None = None, + limit: int | None = None, + offset: int | None = 0, + step: int | None = None, +) -> list[dict[str, Any]]: + try: + normalized_offset = max(0, int(offset)) if offset is not None else 0 + except (TypeError, ValueError): + normalized_offset = 0 + normalized_limit: int | None + if limit is None: + normalized_limit = None + else: + try: + normalized_limit = max(0, int(limit)) + except (TypeError, ValueError): + normalized_limit = None + normalized_step: int | None + if step is None: + normalized_step = None + else: + try: + normalized_step = int(step) + except (TypeError, ValueError): + normalized_step = None + normalized_sort = sort if sort in _ALLOWED_TRACE_SORTS else None + return SQLiteStorage.get_traces( + project, + run, + search=search, + sort=normalized_sort, + limit=normalized_limit, + offset=normalized_offset, + run_id=run_id, + step=normalized_step, + ) + + +def get_trace_steps( + project: str, + run: str | None = None, + run_id: str | None = None, +) -> dict[str, Any]: + return SQLiteStorage.get_trace_steps(project, run, run_id=run_id) + + +def query_project(project: str, query: str) -> dict[str, Any]: + return SQLiteStorage.query_project(project, query) + + +def get_settings() -> dict[str, Any]: + return { + "logo_urls": utils.get_logo_urls(), + "color_palette": utils.get_color_palette(), + "plot_order": [ + item.strip() + for item in os.environ.get("TRACKIO_PLOT_ORDER", "").split(",") + if item.strip() + ], + "table_truncate_length": int( + os.environ.get("TRACKIO_TABLE_TRUNCATE_LENGTH", "250") + ), + "media_dir": str(utils.MEDIA_DIR), + "space_id": os.getenv("SPACE_ID"), + } + + +def get_project_files(project: str) -> list[dict[str, Any]]: + files_dir = utils.MEDIA_DIR / project / "files" + if not files_dir.exists(): + return [] + results = [] + for file_path in sorted(files_dir.rglob("*")): + if file_path.is_file(): + relative = file_path.relative_to(files_dir) + results.append( + { + "name": str(relative), + "path": str(file_path), + "size": file_path.stat().st_size, + } + ) + return results + + +def _project_has_files(project: str) -> bool: + files_dir = utils.MEDIA_DIR / project / "files" + if not files_dir.exists(): + return False + for entry in files_dir.rglob("*"): + if entry.is_file(): + return True + return False + + +def get_tab_availability(project: str) -> dict[str, bool]: + flags = SQLiteStorage.get_tab_availability_flags(project) + return { + "metrics": flags["metrics"], + "system": flags["system"], + "traces": flags["traces"], + "media": flags["media"], + "reports": flags["reports"] or flags["alerts"], + "files": _project_has_files(project), + } + + +def delete_run( + request: Request, + project: str, + run: str | None = None, + run_id: str | None = None, +) -> bool: + assert_can_mutate_runs(request) + return SQLiteStorage.delete_run(project, run, run_id=run_id) + + +def rename_run( + request: Request, + project: str, + old_name: str, + new_name: str, + run_id: str | None = None, +) -> bool: + assert_can_mutate_runs(request) + SQLiteStorage.rename_run(project, old_name, new_name, run_id=run_id) + return True + + +def force_sync() -> bool: + if os.environ.get("TRACKIO_BUCKET_ID"): + return True + SQLiteStorage._dataset_import_attempted = True + SQLiteStorage.export_to_parquet() + scheduler = SQLiteStorage.get_scheduler() + scheduler.trigger().result() + return True + + +CSS = "" +HEAD = "" + + +def _api_registry() -> dict[str, Any]: + return { + "get_run_mutation_status": get_run_mutation_status, + "upload_db_to_space": upload_db_to_space, + "bulk_upload_media": bulk_upload_media, + "log": log, + "bulk_log": bulk_log, + "bulk_log_system": bulk_log_system, + "bulk_alert": bulk_alert, + "get_alerts": get_alerts, + "get_metric_values": get_metric_values, + "get_runs_for_project": get_runs_for_project, + "get_run_configs": get_run_configs, + "get_metrics_for_run": get_metrics_for_run, + "get_all_projects": get_all_projects, + "get_project_summary": get_project_summary, + "get_run_summary": get_run_summary, + "get_system_metrics_for_run": get_system_metrics_for_run, + "get_system_logs": get_system_logs, + "get_system_logs_batch": get_system_logs_batch, + "get_snapshot": get_snapshot, + "get_logs": get_logs, + "get_logs_batch": get_logs_batch, + "get_traces": get_traces, + "get_trace_steps": get_trace_steps, + "query_project": query_project, + "get_settings": get_settings, + "get_project_files": get_project_files, + "get_tab_availability": get_tab_availability, + "delete_run": delete_run, + "rename_run": rename_run, + "force_sync": force_sync, + } + + +class TrackioDashboardApp: + def __init__(self, starlette_app, uvicorn_server: Any, write_token: str) -> None: + self.app = starlette_app + self._uvicorn_server = uvicorn_server + self.write_token = write_token + + def close(self, verbose: bool = True) -> None: + if self._uvicorn_server is not None: + self._uvicorn_server.should_exit = True + + +def build_starlette_app_only( + mcp_server: bool = False, + frontend_dir: str | None = None, +) -> tuple[Any, str]: + oauth_routes = [ + Route(OAUTH_START_PATH, oauth_hf_start, methods=["GET"]), + Route(OAUTH_CALLBACK_PATH, oauth_hf_callback, methods=["GET"]), + Route("/oauth/logout", oauth_logout, methods=["GET"]), + ] + mcp_lifespan = None + mcp_routes: list[Any] = [] + mcp_enabled = False + if mcp_server: + try: + from trackio.mcp_setup import create_mcp_integration # noqa: PLC0415 + + mcp_routes, mcp_lifespan = create_mcp_integration() + mcp_enabled = True + except ImportError: + warnings.warn( + "MCP support requested, but the optional `mcp` package is not installed. " + "Install `trackio[mcp]` to expose `/mcp`.", + UserWarning, + stacklevel=2, + ) + starlette_app = create_trackio_starlette_app( + oauth_routes, + _api_registry(), + extra_routes=mcp_routes, + mcp_lifespan=mcp_lifespan, + mcp_enabled=mcp_enabled, + allowed_file_roots=[ + utils.MEDIA_DIR, + utils.TRACKIO_LOGO_DIR, + ], + upload_authorizer=assert_can_stage_upload, + ) + from trackio.frontend_config import resolve_frontend_dir # noqa: PLC0415 + from trackio.frontend_server import mount_frontend # noqa: PLC0415 + + resolved_frontend = resolve_frontend_dir(frontend_dir) + mount_frontend(starlette_app, frontend_dir=resolved_frontend.path) + return starlette_app, write_token + + +def make_trackio_server( + mcp_server: bool = False, + frontend_dir: str | None = None, +) -> TrackioDashboardApp: + app, wt = build_starlette_app_only( + mcp_server=mcp_server, + frontend_dir=frontend_dir, + ) + return TrackioDashboardApp(app, None, wt) diff --git a/trackio/sqlite_storage.py b/trackio/sqlite_storage.py new file mode 100644 index 0000000000000000000000000000000000000000..273ad48f347c350aefbe6601a45e5f2271c35471 --- /dev/null +++ b/trackio/sqlite_storage.py @@ -0,0 +1,3881 @@ +import atexit +import json as json_mod +import os +import shutil +import sqlite3 +import time +import uuid +from collections.abc import Iterator +from contextlib import contextmanager +from datetime import datetime, timezone +from pathlib import Path +from threading import Lock +from typing import Any + +try: + import fcntl +except ImportError: + fcntl = None + +try: + import msvcrt as _msvcrt +except ImportError: + _msvcrt = None + +import huggingface_hub as hf +import orjson + +from trackio.commit_scheduler import CommitScheduler +from trackio.dummy_commit_scheduler import DummyCommitScheduler +from trackio.utils import ( + MEDIA_DIR, + TRACKIO_DIR, + deserialize_values, + get_color_palette, + on_spaces, + serialize_values, +) + +DB_EXT = ".db" + +_JOURNAL_MODE_WHITELIST = frozenset( + {"wal", "delete", "truncate", "persist", "memory", "off"} +) +_READ_ONLY_QUERY_PREFIXES = ("select", "with", "pragma") +_QUERY_MAX_ROWS = 10_000 +_READ_ONLY_PRAGMAS = frozenset( + {"table_info", "table_xinfo", "index_list", "index_info", "index_xinfo"} +) + + +def _configure_sqlite_pragmas(conn: sqlite3.Connection) -> None: + override = os.environ.get("TRACKIO_SQLITE_JOURNAL_MODE", "").strip().lower() + if override in _JOURNAL_MODE_WHITELIST: + journal = override.upper() + elif on_spaces(): + journal = "DELETE" + else: + journal = "WAL" + conn.execute(f"PRAGMA journal_mode = {journal}") + conn.execute("PRAGMA synchronous = NORMAL") + conn.execute("PRAGMA temp_store = MEMORY") + conn.execute("PRAGMA cache_size = -20000") + if on_spaces(): + conn.execute("PRAGMA locking_mode = EXCLUSIVE") + + +_persistent_connections: dict[str, sqlite3.Connection] = {} +_persistent_lock = Lock() +_db_access_locks: dict[str, Lock] = {} + + +def _get_db_access_lock(db_path: Path) -> Lock: + key = str(db_path) + with _persistent_lock: + if key not in _db_access_locks: + _db_access_locks[key] = Lock() + return _db_access_locks[key] + + +def _get_or_create_persistent_conn( + db_path: Path, timeout: float = 30.0 +) -> sqlite3.Connection: + key = str(db_path) + with _persistent_lock: + conn = _persistent_connections.get(key) + if conn is not None: + try: + conn.execute("SELECT 1") + return conn + except sqlite3.Error: + try: + conn.close() + except sqlite3.Error: + pass + _persistent_connections.pop(key, None) + conn = sqlite3.connect(str(db_path), timeout=timeout, check_same_thread=False) + _configure_sqlite_pragmas(conn) + conn.execute("SELECT 1") + _persistent_connections[key] = conn + return conn + + +def _close_all_persistent_connections() -> None: + with _persistent_lock: + for conn in _persistent_connections.values(): + try: + conn.close() + except sqlite3.Error: + pass + _persistent_connections.clear() + + +atexit.register(_close_all_persistent_connections) + + +class ProcessLock: + """Lock used to coordinate database access. + + Normally uses file-based locking for cross-process coordination. When running + on a bucket-mounted filesystem where file locks are unreliable, + falls back to an in-memory threading Lock (single-process only).""" + + _thread_locks: dict[str, Lock] = {} + _meta_lock = Lock() + + def __init__(self, lockfile_path: Path): + self.lockfile_path = lockfile_path + self.lockfile = None + self._use_thread_lock = on_spaces() + if self._use_thread_lock: + key = str(lockfile_path) + with ProcessLock._meta_lock: + if key not in ProcessLock._thread_locks: + ProcessLock._thread_locks[key] = Lock() + self._thread_lock = ProcessLock._thread_locks[key] + + def __enter__(self): + if self._use_thread_lock: + self._thread_lock.acquire() + return self + if fcntl is None and _msvcrt is None: + return self + self.lockfile_path.parent.mkdir(parents=True, exist_ok=True) + self.lockfile = open(self.lockfile_path, "w") + + max_retries = 100 + for attempt in range(max_retries): + try: + if fcntl is not None: + fcntl.flock(self.lockfile.fileno(), fcntl.LOCK_EX | fcntl.LOCK_NB) + else: + _msvcrt.locking(self.lockfile.fileno(), _msvcrt.LK_NBLCK, 1) + return self + except (IOError, OSError): + if attempt < max_retries - 1: + time.sleep(0.1) + else: + raise IOError("Could not acquire database lock after 10 seconds") + + def __exit__(self, exc_type, exc_val, exc_tb): + if self._use_thread_lock: + self._thread_lock.release() + return + if self.lockfile: + try: + if fcntl is not None: + fcntl.flock(self.lockfile.fileno(), fcntl.LOCK_UN) + elif _msvcrt is not None: + _msvcrt.locking(self.lockfile.fileno(), _msvcrt.LK_UNLCK, 1) + except (IOError, OSError): + pass + self.lockfile.close() + + +_LOGS_READ_CACHE: dict[tuple[Any, ...], tuple[int, list[dict[str, Any]]]] = {} +_LOGS_READ_CACHE_LOCK = Lock() +_LOGS_READ_CACHE_MAX_KEYS = 512 +_LOGS_READ_CACHE_MAX_ROWS_PER_ENTRY = 4000 + + +def _spaces_logs_read_cache_enabled() -> bool: + if not on_spaces(): + return False + v = os.environ.get("TRACKIO_DISABLE_LOGS_CACHE", "").strip().lower() + return v not in ("1", "true", "yes") + + +def _sqlite_db_invalidation_mtime_ns(db_path: Path) -> int | None: + try: + m = db_path.stat().st_mtime_ns + except OSError: + return None + wal_path = db_path.with_name(db_path.name + "-wal") + if wal_path.is_file(): + try: + m = max(m, wal_path.stat().st_mtime_ns) + except OSError: + pass + return m + + +def _logs_read_cache_key( + project: str, + run: str | None, + run_id: str | None, + max_points: int | None, +) -> tuple[Any, ...]: + return ( + project, + run or "", + run_id or "", + max_points if max_points is not None else -1, + ) + + +def _logs_read_cache_get( + db_path: Path, key: tuple[Any, ...] +) -> list[dict[str, Any]] | None: + if not _spaces_logs_read_cache_enabled(): + return None + mtime_ns = _sqlite_db_invalidation_mtime_ns(db_path) + if mtime_ns is None: + return None + with _LOGS_READ_CACHE_LOCK: + item = _LOGS_READ_CACHE.get(key) + if item is None: + return None + cached_mtime, logs = item + if cached_mtime != mtime_ns: + del _LOGS_READ_CACHE[key] + return None + return [{**d} for d in logs] + + +def _logs_read_cache_put( + db_path: Path, key: tuple[Any, ...], logs: list[dict[str, Any]] +) -> None: + if not _spaces_logs_read_cache_enabled(): + return + if len(logs) > _LOGS_READ_CACHE_MAX_ROWS_PER_ENTRY: + return + mtime_ns = _sqlite_db_invalidation_mtime_ns(db_path) + if mtime_ns is None: + return + snapshot = [{**d} for d in logs] + with _LOGS_READ_CACHE_LOCK: + while len(_LOGS_READ_CACHE) >= _LOGS_READ_CACHE_MAX_KEYS: + _LOGS_READ_CACHE.pop(next(iter(_LOGS_READ_CACHE))) + _LOGS_READ_CACHE[key] = (mtime_ns, snapshot) + + +_SYSTEM_LOGS_READ_CACHE: dict[tuple[Any, ...], tuple[int, list[dict[str, Any]]]] = {} + + +def _system_logs_read_cache_key( + project: str, + run: str | None, + run_id: str | None, + max_points: int | None = None, +) -> tuple[Any, ...]: + return ( + "system_logs", + project, + run or "", + run_id or "", + max_points if max_points is not None else -1, + ) + + +def _system_logs_read_cache_get( + db_path: Path, key: tuple[Any, ...] +) -> list[dict[str, Any]] | None: + if not _spaces_logs_read_cache_enabled(): + return None + mtime_ns = _sqlite_db_invalidation_mtime_ns(db_path) + if mtime_ns is None: + return None + with _LOGS_READ_CACHE_LOCK: + item = _SYSTEM_LOGS_READ_CACHE.get(key) + if item is None: + return None + cached_mtime, logs = item + if cached_mtime != mtime_ns: + del _SYSTEM_LOGS_READ_CACHE[key] + return None + return [{**d} for d in logs] + + +def _system_logs_read_cache_put( + db_path: Path, key: tuple[Any, ...], logs: list[dict[str, Any]] +) -> None: + if not _spaces_logs_read_cache_enabled(): + return + if len(logs) > _LOGS_READ_CACHE_MAX_ROWS_PER_ENTRY: + return + mtime_ns = _sqlite_db_invalidation_mtime_ns(db_path) + if mtime_ns is None: + return + snapshot = [{**d} for d in logs] + with _LOGS_READ_CACHE_LOCK: + while len(_SYSTEM_LOGS_READ_CACHE) >= _LOGS_READ_CACHE_MAX_KEYS: + _SYSTEM_LOGS_READ_CACHE.pop(next(iter(_SYSTEM_LOGS_READ_CACHE))) + _SYSTEM_LOGS_READ_CACHE[key] = (mtime_ns, snapshot) + + +class SQLiteStorage: + _dataset_import_attempted = False + _current_scheduler: CommitScheduler | DummyCommitScheduler | None = None + _scheduler_lock = Lock() + + @staticmethod + @contextmanager + def _get_connection( + db_path: Path, + *, + timeout: float = 30.0, + configure_pragmas: bool = True, + row_factory=sqlite3.Row, + ) -> Iterator[sqlite3.Connection]: + if on_spaces(): + # On Spaces, all callers share a single persistent connection + # that is pragma-configured at creation time. The `configure_pragmas` + # flag is intentionally ignored here — the pragmas (journal mode, + # synchronous, locking mode) don't affect query semantics. + access_lock = _get_db_access_lock(db_path) + access_lock.acquire() + try: + conn = _get_or_create_persistent_conn(db_path, timeout=timeout) + conn.row_factory = row_factory + with conn: + yield conn + finally: + access_lock.release() + else: + conn = sqlite3.connect(str(db_path), timeout=timeout) + try: + if configure_pragmas: + _configure_sqlite_pragmas(conn) + if row_factory is not None: + conn.row_factory = row_factory + with conn: + yield conn + finally: + conn.close() + + @staticmethod + def _get_process_lock(project: str) -> ProcessLock: + lockfile_path = TRACKIO_DIR / f"{project}.lock" + return ProcessLock(lockfile_path) + + @staticmethod + def get_project_db_filename(project: str) -> str: + """Get the database filename for a specific project.""" + safe_project_name = "".join( + c for c in project if c.isalnum() or c in ("-", "_") + ).rstrip() + if not safe_project_name: + safe_project_name = "default" + return f"{safe_project_name}{DB_EXT}" + + @staticmethod + def get_project_db_path(project: str) -> Path: + """Get the database path for a specific project.""" + filename = SQLiteStorage.get_project_db_filename(project) + return TRACKIO_DIR / filename + + @staticmethod + def init_db(project: str) -> Path: + """ + Initialize the SQLite database with required tables. + Returns the database path. + """ + SQLiteStorage._ensure_hub_loaded() + db_path = SQLiteStorage.get_project_db_path(project) + db_path.parent.mkdir(parents=True, exist_ok=True) + with SQLiteStorage._get_process_lock(project): + with SQLiteStorage._get_connection(db_path, row_factory=None) as conn: + cursor = conn.cursor() + cursor.execute( + """ + CREATE TABLE IF NOT EXISTS metrics ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + run_id TEXT NOT NULL, + timestamp TEXT NOT NULL, + run_name TEXT NOT NULL, + step INTEGER NOT NULL, + metrics TEXT NOT NULL + ) + """ + ) + cursor.execute( + """ + CREATE TABLE IF NOT EXISTS configs ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + run_id TEXT NOT NULL, + run_name TEXT NOT NULL, + config TEXT NOT NULL, + created_at TEXT NOT NULL, + UNIQUE(run_id) + ) + """ + ) + cursor.execute( + """ + CREATE TABLE IF NOT EXISTS system_metrics ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + run_id TEXT NOT NULL, + timestamp TEXT NOT NULL, + run_name TEXT NOT NULL, + metrics TEXT NOT NULL + ) + """ + ) + + cursor.execute( + """ + CREATE TABLE IF NOT EXISTS traces ( + id TEXT PRIMARY KEY, + run_id TEXT NOT NULL, + timestamp TEXT NOT NULL, + run_name TEXT NOT NULL, + step INTEGER NOT NULL, + key TEXT NOT NULL, + trace_index INTEGER, + messages TEXT NOT NULL, + metadata TEXT NOT NULL, + search_text TEXT NOT NULL, + log_id TEXT, + space_id TEXT + ) + """ + ) + + cursor.execute( + """ + CREATE TABLE IF NOT EXISTS project_metadata ( + key TEXT PRIMARY KEY, + value TEXT NOT NULL + ) + """ + ) + + cursor.execute( + """ + CREATE TABLE IF NOT EXISTS pending_uploads ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + space_id TEXT NOT NULL, + run_id TEXT, + run_name TEXT, + step INTEGER, + file_path TEXT NOT NULL, + relative_path TEXT, + created_at TEXT NOT NULL + ) + """ + ) + + cursor.execute( + """ + CREATE TABLE IF NOT EXISTS alerts ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + run_id TEXT NOT NULL, + timestamp TEXT NOT NULL, + run_name TEXT NOT NULL, + title TEXT NOT NULL, + text TEXT, + level TEXT NOT NULL DEFAULT 'warn', + step INTEGER, + alert_id TEXT + ) + """ + ) + metrics_cols = SQLiteStorage._table_columns(conn, "metrics") + metrics_run_key = "run_id" if "run_id" in metrics_cols else "run_name" + cursor.execute( + f""" + CREATE INDEX IF NOT EXISTS idx_metrics_run_step + ON metrics({metrics_run_key}, step) + """ + ) + cursor.execute( + f""" + CREATE INDEX IF NOT EXISTS idx_metrics_run_timestamp + ON metrics({metrics_run_key}, timestamp) + """ + ) + cursor.execute( + """ + CREATE INDEX IF NOT EXISTS idx_configs_run_name + ON configs(run_name) + """ + ) + system_cols = SQLiteStorage._table_columns(conn, "system_metrics") + system_run_key = "run_id" if "run_id" in system_cols else "run_name" + cursor.execute( + f""" + CREATE INDEX IF NOT EXISTS idx_system_metrics_run_timestamp + ON system_metrics({system_run_key}, timestamp) + """ + ) + cursor.execute( + """ + CREATE INDEX IF NOT EXISTS idx_traces_run_step + ON traces(run_id, step) + """ + ) + cursor.execute( + """ + CREATE INDEX IF NOT EXISTS idx_traces_run_timestamp + ON traces(run_id, timestamp) + """ + ) + cursor.execute( + """ + CREATE INDEX IF NOT EXISTS idx_traces_search + ON traces(search_text) + """ + ) + alerts_cols = SQLiteStorage._table_columns(conn, "alerts") + alerts_run_key = "run_id" if "run_id" in alerts_cols else "run_name" + cursor.execute( + f""" + CREATE INDEX IF NOT EXISTS idx_alerts_run + ON alerts({alerts_run_key}) + """ + ) + cursor.execute( + """ + CREATE INDEX IF NOT EXISTS idx_alerts_timestamp + ON alerts(timestamp) + """ + ) + cursor.execute( + """ + CREATE UNIQUE INDEX IF NOT EXISTS idx_alerts_alert_id + ON alerts(alert_id) WHERE alert_id IS NOT NULL + """ + ) + + for table in ("metrics", "system_metrics"): + for col in ("log_id TEXT", "space_id TEXT"): + try: + cursor.execute(f"ALTER TABLE {table} ADD COLUMN {col}") + except sqlite3.OperationalError: + pass + cursor.execute( + f"""CREATE UNIQUE INDEX IF NOT EXISTS idx_{table}_log_id + ON {table}(log_id) WHERE log_id IS NOT NULL""" + ) + cursor.execute( + f"""CREATE INDEX IF NOT EXISTS idx_{table}_pending + ON {table}(space_id) WHERE space_id IS NOT NULL""" + ) + + conn.commit() + return db_path + + @staticmethod + def _require_pyarrow(): + try: + import pyarrow as pa + import pyarrow.parquet as pq + except ImportError as e: + raise ImportError( + "Parquet import/export requires `trackio[spaces]`." + ) from e + return pa, pq + + @staticmethod + def _table_columns(conn: sqlite3.Connection, table: str) -> set[str]: + cursor = conn.cursor() + try: + cursor.execute(f"PRAGMA table_info({table})") + except sqlite3.OperationalError: + return set() + return {row[1] for row in cursor.fetchall()} + + @staticmethod + def _supports_run_ids(conn: sqlite3.Connection, table: str = "metrics") -> bool: + return "run_id" in SQLiteStorage._table_columns(conn, table) + + @staticmethod + def _resolve_run_identity( + conn: sqlite3.Connection, + run_name: str | None = None, + run_id: str | None = None, + *, + table: str = "metrics", + ) -> tuple[str, str] | None: + supports_run_ids = SQLiteStorage._supports_run_ids(conn, table) + if supports_run_ids: + if run_id is not None: + return ("run_id", run_id) + if run_name is None: + return None + source_table = ( + table + if "timestamp" in SQLiteStorage._table_columns(conn, table) + else "metrics" + ) + cursor = conn.cursor() + cursor.execute( + f""" + SELECT run_id + FROM {source_table} + WHERE run_name = ? + GROUP BY run_id + ORDER BY MIN(timestamp) DESC + LIMIT 1 + """, + (run_name,), + ) + row = cursor.fetchone() + if row is None: + return None + return ("run_id", row[0]) + + resolved = run_name if run_name is not None else run_id + if resolved is None: + return None + return ("run_name", resolved) + + @staticmethod + def get_run_records(project: str) -> list[dict[str, str | None]]: + SQLiteStorage._ensure_hub_loaded() + db_path = SQLiteStorage.get_project_db_path(project) + if not db_path.exists(): + return [] + + try: + with SQLiteStorage._get_connection(db_path) as conn: + cursor = conn.cursor() + if SQLiteStorage._supports_run_ids(conn): + cursor.execute( + """ + SELECT run_id, run_name, MIN(timestamp) as created_at + FROM metrics + GROUP BY run_id, run_name + ORDER BY created_at ASC + """ + ) + return [ + { + "id": row["run_id"], + "name": row["run_name"], + "created_at": row["created_at"], + } + for row in cursor.fetchall() + ] + + cursor.execute( + """ + SELECT run_name, MIN(timestamp) as created_at + FROM metrics + GROUP BY run_name + ORDER BY created_at ASC + """ + ) + return [ + { + "id": row["run_name"], + "name": row["run_name"], + "created_at": row["created_at"], + } + for row in cursor.fetchall() + ] + except sqlite3.OperationalError as e: + if "no such table: metrics" in str(e): + return [] + raise + + @staticmethod + def get_latest_run_record_by_name( + project: str, run_name: str + ) -> dict[str, str | None] | None: + db_path = SQLiteStorage.get_project_db_path(project) + if not db_path.exists(): + return None + + with SQLiteStorage._get_connection(db_path) as conn: + cursor = conn.cursor() + if SQLiteStorage._supports_run_ids(conn): + cursor.execute( + """ + SELECT run_id, run_name, MIN(timestamp) as created_at + FROM metrics + WHERE run_name = ? + GROUP BY run_id, run_name + ORDER BY created_at DESC + LIMIT 1 + """, + (run_name,), + ) + row = cursor.fetchone() + if row is None: + return None + return { + "id": row["run_id"], + "name": row["run_name"], + "created_at": row["created_at"], + } + + cursor.execute( + """ + SELECT run_name, MIN(timestamp) as created_at + FROM metrics + WHERE run_name = ? + GROUP BY run_name + ORDER BY created_at DESC + LIMIT 1 + """, + (run_name,), + ) + row = cursor.fetchone() + if row is None: + return None + return { + "id": row["run_name"], + "name": row["run_name"], + "created_at": row["created_at"], + } + + @staticmethod + def _normalize_trace_rows_for_parquet( + rows: list[dict[str, object]], + ) -> list[dict[str, object]]: + normalized: list[dict[str, object]] = [] + for row in rows: + new_row = dict(row) + for col in ("messages", "metadata"): + value = new_row.get(col) + if value is None: + continue + if isinstance(value, memoryview): + value = value.tobytes() + if isinstance(value, (bytes, bytearray)): + new_row[col] = bytes(value).decode("utf-8") + elif not isinstance(value, str): + new_row[col] = orjson.dumps(value).decode("utf-8") + normalized.append(new_row) + return normalized + + @staticmethod + def _read_table_rows(db_path: Path, table: str) -> list[dict[str, object]]: + try: + with SQLiteStorage._get_connection( + db_path, timeout=5.0, configure_pragmas=False + ) as conn: + cursor = conn.cursor() + cursor.execute(f"SELECT * FROM {table}") + return [dict(row) for row in cursor.fetchall()] + except Exception: + return [] + + @staticmethod + def _decode_json_blob(value: object) -> dict[str, object]: + if value is None: + return {} + if isinstance(value, memoryview): + value = value.tobytes() + return deserialize_values(orjson.loads(value)) + + @staticmethod + def _flatten_json_rows( + rows: list[dict[str, object]], json_col: str + ) -> list[dict[str, object]]: + flattened_rows = [] + for row in rows: + flat_row = {key: value for key, value in row.items() if key != json_col} + expanded = SQLiteStorage._decode_json_blob(row.get(json_col)) + for key, value in expanded.items(): + if key not in flat_row: + flat_row[key] = value + flattened_rows.append(flat_row) + return flattened_rows + + @staticmethod + def _write_parquet_rows(parquet_path: Path, rows: list[dict[str, object]]) -> None: + if not rows: + return + pa, pq = SQLiteStorage._require_pyarrow() + column_names: list[str] = [] + seen_columns: set[str] = set() + for row in rows: + for key in row: + if key not in seen_columns: + column_names.append(key) + seen_columns.add(key) + normalized_rows = [{key: row.get(key) for key in column_names} for row in rows] + table = pa.Table.from_pylist(normalized_rows) + write_kwargs = { + "write_page_index": True, + "use_content_defined_chunking": True, + } + try: + pq.write_table(table, parquet_path, **write_kwargs) + except TypeError: + pq.write_table(table, parquet_path) + + @staticmethod + def _read_parquet_rows(parquet_path: Path) -> list[dict[str, object]]: + _, pq = SQLiteStorage._require_pyarrow() + return pq.read_table(parquet_path).to_pylist() + + @staticmethod + def _normalize_json_column_value(value: object) -> object: + if value is None: + return orjson.dumps({}) + if isinstance(value, memoryview): + return value.tobytes() + if isinstance(value, (bytes, bytearray, str)): + return value + return orjson.dumps(serialize_values(value)) + + @staticmethod + def _rows_to_sql_table_rows( + rows: list[dict[str, object]], + *, + json_col: str, + structural_cols: list[str], + ) -> list[dict[str, object]]: + sql_rows = [] + for row in rows: + sql_row = {col: row.get(col) for col in structural_cols} + if json_col in row: + sql_row[json_col] = SQLiteStorage._normalize_json_column_value( + row.get(json_col) + ) + else: + payload = { + key: value + for key, value in row.items() + if key not in structural_cols and key != json_col + } + sql_row[json_col] = orjson.dumps(serialize_values(payload)) + sql_rows.append(sql_row) + return sql_rows + + @staticmethod + def _replace_table_rows( + db_path: Path, + table: str, + rows: list[dict[str, object]], + columns: list[str], + ) -> None: + with SQLiteStorage._get_connection( + db_path, configure_pragmas=False, row_factory=None + ) as conn: + cursor = conn.cursor() + cursor.execute(f"DELETE FROM {table}") + if rows: + placeholders = ", ".join(["?"] * len(columns)) + cursor.executemany( + f"INSERT INTO {table} ({', '.join(columns)}) VALUES ({placeholders})", + [[row.get(column) for column in columns] for row in rows], + ) + conn.commit() + + @staticmethod + def _flatten_and_write_parquet( + db_path: Path, table: str, json_col: str, parquet_path: Path + ) -> None: + if ( + parquet_path.exists() + and db_path.stat().st_mtime <= parquet_path.stat().st_mtime + ): + return + rows = SQLiteStorage._read_table_rows(db_path, table) + if not rows: + return + flat_rows = SQLiteStorage._flatten_json_rows(rows, json_col) + SQLiteStorage._write_parquet_rows(parquet_path, flat_rows) + + @staticmethod + def export_to_parquet(): + """ + Exports all projects' DB files as Parquet under the same path but with extension ".parquet". + Also exports system_metrics to separate parquet files with "_system.parquet" suffix. + Also exports configs to separate parquet files with "_configs.parquet" suffix. + """ + if not SQLiteStorage._dataset_import_attempted: + return + if not TRACKIO_DIR.exists(): + return + + all_paths = os.listdir(TRACKIO_DIR) + db_names = [f for f in all_paths if f.endswith(DB_EXT)] + for db_name in db_names: + db_path = TRACKIO_DIR / db_name + SQLiteStorage._flatten_and_write_parquet( + db_path, "metrics", "metrics", db_path.with_suffix(".parquet") + ) + SQLiteStorage._flatten_and_write_parquet( + db_path, + "system_metrics", + "metrics", + TRACKIO_DIR / (db_path.stem + "_system.parquet"), + ) + SQLiteStorage._flatten_and_write_parquet( + db_path, + "configs", + "config", + TRACKIO_DIR / (db_path.stem + "_configs.parquet"), + ) + trace_rows = SQLiteStorage._read_table_rows(db_path, "traces") + if trace_rows: + SQLiteStorage._write_parquet_rows( + TRACKIO_DIR / (db_path.stem + "_traces.parquet"), + SQLiteStorage._normalize_trace_rows_for_parquet(trace_rows), + ) + + @staticmethod + def export_for_static_space( + project: str, output_dir: Path, db_path_override: Path | None = None + ) -> None: + """ + Exports a single project's data as Parquet + JSON files for static Space deployment. + + Args: + project: The project name. + output_dir: Directory to write the exported files to. + db_path_override: If provided, read from this DB file instead of the + default local project path. Useful when exporting from a downloaded + remote database. + """ + db_path = db_path_override or SQLiteStorage.get_project_db_path(project) + if not db_path.exists(): + raise FileNotFoundError(f"No database found for project '{project}'") + + output_dir.mkdir(parents=True, exist_ok=True) + aux_dir = output_dir / "aux" + aux_dir.mkdir(parents=True, exist_ok=True) + + metrics_rows = SQLiteStorage._read_table_rows(db_path, "metrics") + if metrics_rows: + flat = SQLiteStorage._flatten_json_rows(metrics_rows, "metrics") + SQLiteStorage._write_parquet_rows(output_dir / "metrics.parquet", flat) + + sys_rows = SQLiteStorage._read_table_rows(db_path, "system_metrics") + if sys_rows: + flat = SQLiteStorage._flatten_json_rows(sys_rows, "metrics") + SQLiteStorage._write_parquet_rows(aux_dir / "system_metrics.parquet", flat) + + trace_rows = SQLiteStorage._read_table_rows(db_path, "traces") + if trace_rows: + SQLiteStorage._write_parquet_rows( + aux_dir / "traces.parquet", + SQLiteStorage._normalize_trace_rows_for_parquet(trace_rows), + ) + + configs_rows = SQLiteStorage._read_table_rows(db_path, "configs") + if configs_rows: + flat = SQLiteStorage._flatten_json_rows(configs_rows, "config") + SQLiteStorage._write_parquet_rows(aux_dir / "configs.parquet", flat) + + try: + with SQLiteStorage._get_connection(db_path) as conn: + cursor = conn.cursor() + if SQLiteStorage._supports_run_ids(conn): + cursor.execute( + """SELECT run_id, run_name, MIN(timestamp) as created_at, + MAX(step) as last_step, COUNT(*) as log_count + FROM metrics + GROUP BY run_id, run_name + ORDER BY created_at ASC""" + ) + rows = cursor.fetchall() + runs_meta = [ + { + "id": row["run_id"], + "name": row["run_name"], + "created_at": row["created_at"], + "last_step": row["last_step"], + "log_count": row["log_count"], + } + for row in rows + ] + else: + cursor.execute( + """SELECT run_name, MIN(timestamp) as created_at, + MAX(step) as last_step, COUNT(*) as log_count + FROM metrics GROUP BY run_name ORDER BY created_at ASC""" + ) + rows = cursor.fetchall() + runs_meta = [ + { + "id": row["run_name"], + "name": row["run_name"], + "created_at": row["created_at"], + "last_step": row["last_step"], + "log_count": row["log_count"], + } + for row in rows + ] + except sqlite3.OperationalError: + runs_meta = [] + with open(output_dir / "runs.json", "w") as f: + json_mod.dump(runs_meta, f) + + settings = { + "color_palette": get_color_palette(), + "plot_order": [ + item.strip() + for item in os.environ.get("TRACKIO_PLOT_ORDER", "").split(",") + if item.strip() + ], + } + with open(output_dir / "settings.json", "w") as f: + json_mod.dump(settings, f) + + @staticmethod + def _cleanup_wal_sidecars(db_path: Path) -> None: + """Remove leftover -wal/-shm files for a DB basename (prevents disk I/O errors).""" + for suffix in ("-wal", "-shm"): + sidecar = Path(str(db_path) + suffix) + try: + if sidecar.exists(): + sidecar.unlink() + except Exception: + pass + + @staticmethod + def import_from_parquet(): + """ + Imports to all DB files that have matching files under the same path but with extension ".parquet". + Also imports system_metrics from "_system.parquet" files. + Also imports configs from "_configs.parquet" files. + """ + if not TRACKIO_DIR.exists(): + return + + all_paths = os.listdir(TRACKIO_DIR) + parquet_names = [ + f + for f in all_paths + if f.endswith(".parquet") + and not f.endswith("_system.parquet") + and not f.endswith("_configs.parquet") + and not f.endswith("_traces.parquet") + ] + imported_projects = {Path(name).stem for name in parquet_names} + for pq_name in parquet_names: + parquet_path = TRACKIO_DIR / pq_name + db_path = parquet_path.with_suffix(DB_EXT) + + SQLiteStorage._cleanup_wal_sidecars(db_path) + + rows = SQLiteStorage._read_parquet_rows(parquet_path) + project = db_path.stem + SQLiteStorage.init_db(project) + metrics_rows = SQLiteStorage._rows_to_sql_table_rows( + rows, + json_col="metrics", + structural_cols=[ + "id", + "run_id", + "timestamp", + "run_name", + "step", + "log_id", + "space_id", + ], + ) + SQLiteStorage._replace_table_rows( + db_path, + "metrics", + metrics_rows, + [ + "id", + "run_id", + "timestamp", + "run_name", + "step", + "metrics", + "log_id", + "space_id", + ], + ) + + system_parquet_names = [f for f in all_paths if f.endswith("_system.parquet")] + for pq_name in system_parquet_names: + parquet_path = TRACKIO_DIR / pq_name + db_name = pq_name.replace("_system.parquet", DB_EXT) + db_path = TRACKIO_DIR / db_name + project_name = db_path.stem + if project_name not in imported_projects and not db_path.exists(): + continue + + rows = SQLiteStorage._read_parquet_rows(parquet_path) + SQLiteStorage.init_db(project_name) + system_rows = SQLiteStorage._rows_to_sql_table_rows( + rows, + json_col="metrics", + structural_cols=[ + "id", + "run_id", + "timestamp", + "run_name", + "log_id", + "space_id", + ], + ) + SQLiteStorage._replace_table_rows( + db_path, + "system_metrics", + system_rows, + [ + "id", + "run_id", + "timestamp", + "run_name", + "metrics", + "log_id", + "space_id", + ], + ) + + configs_parquet_names = [f for f in all_paths if f.endswith("_configs.parquet")] + for pq_name in configs_parquet_names: + parquet_path = TRACKIO_DIR / pq_name + db_name = pq_name.replace("_configs.parquet", DB_EXT) + db_path = TRACKIO_DIR / db_name + project_name = db_path.stem + if project_name not in imported_projects and not db_path.exists(): + continue + + rows = SQLiteStorage._read_parquet_rows(parquet_path) + SQLiteStorage.init_db(project_name) + config_rows = SQLiteStorage._rows_to_sql_table_rows( + rows, + json_col="config", + structural_cols=["id", "run_id", "run_name", "created_at"], + ) + SQLiteStorage._replace_table_rows( + db_path, + "configs", + config_rows, + ["id", "run_id", "run_name", "config", "created_at"], + ) + + traces_parquet_names = [f for f in all_paths if f.endswith("_traces.parquet")] + for pq_name in traces_parquet_names: + parquet_path = TRACKIO_DIR / pq_name + db_name = pq_name.replace("_traces.parquet", DB_EXT) + db_path = TRACKIO_DIR / db_name + project_name = db_path.stem + if project_name not in imported_projects and not db_path.exists(): + continue + + rows = SQLiteStorage._read_parquet_rows(parquet_path) + SQLiteStorage.init_db(project_name) + SQLiteStorage._replace_table_rows( + db_path, + "traces", + rows, + [ + "id", + "run_id", + "timestamp", + "run_name", + "step", + "key", + "trace_index", + "messages", + "metadata", + "search_text", + "log_id", + "space_id", + ], + ) + + @staticmethod + def get_scheduler(): + """ + Get the scheduler for the database based on the environment variables. + This applies to both local and Spaces. + """ + with SQLiteStorage._scheduler_lock: + if SQLiteStorage._current_scheduler is not None: + return SQLiteStorage._current_scheduler + hf_token = os.environ.get("HF_TOKEN") + dataset_id = os.environ.get("TRACKIO_DATASET_ID") + space_repo_name = os.environ.get("SPACE_REPO_NAME") + if dataset_id is not None and space_repo_name is not None: + scheduler = CommitScheduler( + repo_id=dataset_id, + repo_type="dataset", + folder_path=TRACKIO_DIR, + private=True, + allow_patterns=[ + "*.parquet", + "*_system.parquet", + "*_configs.parquet", + "*_traces.parquet", + "aux/*.parquet", + "media/**/*", + ], + squash_history=True, + token=hf_token, + on_before_commit=SQLiteStorage.export_to_parquet, + ) + else: + scheduler = DummyCommitScheduler() + SQLiteStorage._current_scheduler = scheduler + return scheduler + + @staticmethod + def log( + project: str, + run: str, + metrics: dict, + step: int | None = None, + run_id: str | None = None, + ): + """ + Safely log metrics to the database. Before logging, this method will ensure the database exists + and is set up with the correct tables. It also uses a cross-process lock to prevent + database locking errors when multiple processes access the same database. + + This method is not used in the latest versions of Trackio (replaced by bulk_log) but + is kept for backwards compatibility for users who are connecting to a newer version of + a Trackio Spaces dashboard with an older version of Trackio installed locally. + """ + db_path = SQLiteStorage.init_db(project) + with SQLiteStorage._get_process_lock(project): + with SQLiteStorage._get_connection(db_path) as conn: + cursor = conn.cursor() + supports_run_ids = SQLiteStorage._supports_run_ids(conn) + resolved_run_id = run_id or run + run_col = "run_id" if supports_run_ids else "run_name" + cursor.execute( + f""" + SELECT MAX(step) + FROM metrics + WHERE {run_col} = ? + """, + (resolved_run_id if supports_run_ids else run,), + ) + last_step = cursor.fetchone()[0] + current_step = ( + 0 + if step is None and last_step is None + else (step if step is not None else last_step + 1) + ) + current_timestamp = datetime.now(timezone.utc).isoformat() + clean_metrics, trace_rows = SQLiteStorage._split_trace_metrics( + metrics, + run=run, + run_id=resolved_run_id, + step=current_step, + timestamp=current_timestamp, + log_id=None, + space_id=None, + ) + if supports_run_ids: + cursor.execute( + """ + INSERT INTO metrics + (timestamp, run_id, run_name, step, metrics) + VALUES (?, ?, ?, ?, ?) + """, + ( + current_timestamp, + resolved_run_id, + run, + current_step, + orjson.dumps(serialize_values(clean_metrics)), + ), + ) + else: + cursor.execute( + """ + INSERT INTO metrics + (timestamp, run_name, step, metrics) + VALUES (?, ?, ?, ?) + """, + ( + current_timestamp, + run, + current_step, + orjson.dumps(serialize_values(clean_metrics)), + ), + ) + SQLiteStorage._insert_trace_rows(cursor, trace_rows) + conn.commit() + + @staticmethod + def bulk_log( + project: str, + run: str, + metrics_list: list[dict], + steps: list[int] | None = None, + timestamps: list[str] | None = None, + config: dict | None = None, + log_ids: list[str] | None = None, + space_id: str | None = None, + run_id: str | None = None, + ): + """ + Safely log bulk metrics to the database. Before logging, this method will ensure the database exists + and is set up with the correct tables. It also uses a cross-process lock to prevent + database locking errors when multiple processes access the same database. + """ + if not metrics_list: + return + + if timestamps is None: + timestamps = [datetime.now(timezone.utc).isoformat()] * len(metrics_list) + + db_path = SQLiteStorage.init_db(project) + with SQLiteStorage._get_process_lock(project): + with SQLiteStorage._get_connection(db_path) as conn: + cursor = conn.cursor() + supports_run_ids = SQLiteStorage._supports_run_ids(conn) + resolved_run_id = run_id or run + + if steps is None: + steps = list(range(len(metrics_list))) + elif any(s is None for s in steps): + run_col = "run_id" if supports_run_ids else "run_name" + cursor.execute( + f"SELECT MAX(step) FROM metrics WHERE {run_col} = ?", + (resolved_run_id if supports_run_ids else run,), + ) + last_step = cursor.fetchone()[0] + current_step = 0 if last_step is None else last_step + 1 + processed_steps = [] + for step in steps: + if step is None: + processed_steps.append(current_step) + current_step += 1 + else: + processed_steps.append(step) + steps = processed_steps + + if len(metrics_list) != len(steps) or len(metrics_list) != len( + timestamps + ): + raise ValueError( + "metrics_list, steps, and timestamps must have the same length" + ) + + data = [] + trace_rows = [] + for i, metrics in enumerate(metrics_list): + lid = log_ids[i] if log_ids else None + clean_metrics, rows = SQLiteStorage._split_trace_metrics( + metrics, + run=run, + run_id=resolved_run_id, + step=steps[i], + timestamp=timestamps[i], + log_id=lid, + space_id=space_id, + ) + trace_rows.extend(rows) + if supports_run_ids: + data.append( + ( + timestamps[i], + resolved_run_id, + run, + steps[i], + orjson.dumps(serialize_values(clean_metrics)), + lid, + space_id, + ) + ) + else: + data.append( + ( + timestamps[i], + run, + steps[i], + orjson.dumps(serialize_values(clean_metrics)), + lid, + space_id, + ) + ) + + if supports_run_ids: + cursor.executemany( + """ + INSERT OR IGNORE INTO metrics + (timestamp, run_id, run_name, step, metrics, log_id, space_id) + VALUES (?, ?, ?, ?, ?, ?, ?) + """, + data, + ) + else: + cursor.executemany( + """ + INSERT OR IGNORE INTO metrics + (timestamp, run_name, step, metrics, log_id, space_id) + VALUES (?, ?, ?, ?, ?, ?) + """, + data, + ) + + SQLiteStorage._insert_trace_rows(cursor, trace_rows) + + if config: + current_timestamp = datetime.now(timezone.utc).isoformat() + if "run_id" in SQLiteStorage._table_columns(conn, "configs"): + cursor.execute( + """ + INSERT OR REPLACE INTO configs + (run_id, run_name, config, created_at) + VALUES (?, ?, ?, ?) + """, + ( + resolved_run_id, + run, + orjson.dumps(serialize_values(config)), + current_timestamp, + ), + ) + else: + cursor.execute( + """ + INSERT OR REPLACE INTO configs + (run_name, config, created_at) + VALUES (?, ?, ?) + """, + ( + run, + orjson.dumps(serialize_values(config)), + current_timestamp, + ), + ) + + conn.commit() + + @staticmethod + def bulk_log_system( + project: str, + run: str, + metrics_list: list[dict], + timestamps: list[str] | None = None, + log_ids: list[str] | None = None, + space_id: str | None = None, + run_id: str | None = None, + ): + """ + Log system metrics (GPU, etc.) to the database without step numbers. + These metrics use timestamps for the x-axis instead of steps. + """ + if not metrics_list: + return + + if timestamps is None: + timestamps = [datetime.now(timezone.utc).isoformat()] * len(metrics_list) + + if len(metrics_list) != len(timestamps): + raise ValueError("metrics_list and timestamps must have the same length") + + db_path = SQLiteStorage.init_db(project) + with SQLiteStorage._get_process_lock(project): + with SQLiteStorage._get_connection(db_path) as conn: + cursor = conn.cursor() + supports_run_ids = SQLiteStorage._supports_run_ids( + conn, "system_metrics" + ) + resolved_run_id = run_id or run + data = [] + for i, metrics in enumerate(metrics_list): + lid = log_ids[i] if log_ids else None + if supports_run_ids: + data.append( + ( + timestamps[i], + resolved_run_id, + run, + orjson.dumps(serialize_values(metrics)), + lid, + space_id, + ) + ) + else: + data.append( + ( + timestamps[i], + run, + orjson.dumps(serialize_values(metrics)), + lid, + space_id, + ) + ) + + if supports_run_ids: + cursor.executemany( + """ + INSERT OR IGNORE INTO system_metrics + (timestamp, run_id, run_name, metrics, log_id, space_id) + VALUES (?, ?, ?, ?, ?, ?) + """, + data, + ) + else: + cursor.executemany( + """ + INSERT OR IGNORE INTO system_metrics + (timestamp, run_name, metrics, log_id, space_id) + VALUES (?, ?, ?, ?, ?) + """, + data, + ) + conn.commit() + + @staticmethod + def bulk_alert( + project: str, + run: str, + titles: list[str], + texts: list[str | None], + levels: list[str], + steps: list[int | None], + timestamps: list[str] | None = None, + alert_ids: list[str] | None = None, + run_id: str | None = None, + ): + if not titles: + return + + if timestamps is None: + timestamps = [datetime.now(timezone.utc).isoformat()] * len(titles) + + db_path = SQLiteStorage.init_db(project) + with SQLiteStorage._get_process_lock(project): + with SQLiteStorage._get_connection(db_path) as conn: + cursor = conn.cursor() + supports_run_ids = SQLiteStorage._supports_run_ids(conn, "alerts") + resolved_run_id = run_id or run + data = [] + for i in range(len(titles)): + aid = alert_ids[i] if alert_ids else None + if supports_run_ids: + data.append( + ( + resolved_run_id, + timestamps[i], + run, + titles[i], + texts[i], + levels[i], + steps[i], + aid, + ) + ) + else: + data.append( + ( + timestamps[i], + run, + titles[i], + texts[i], + levels[i], + steps[i], + aid, + ) + ) + + if supports_run_ids: + cursor.executemany( + """ + INSERT OR IGNORE INTO alerts + (run_id, timestamp, run_name, title, text, level, step, alert_id) + VALUES (?, ?, ?, ?, ?, ?, ?, ?) + """, + data, + ) + else: + cursor.executemany( + """ + INSERT OR IGNORE INTO alerts + (timestamp, run_name, title, text, level, step, alert_id) + VALUES (?, ?, ?, ?, ?, ?, ?) + """, + data, + ) + conn.commit() + + @staticmethod + def get_alerts( + project: str, + run_name: str | None = None, + run_id: str | None = None, + level: str | None = None, + since: str | None = None, + ) -> list[dict]: + db_path = SQLiteStorage.get_project_db_path(project) + if not db_path.exists(): + return [] + + with SQLiteStorage._get_connection(db_path) as conn: + cursor = conn.cursor() + try: + query = ( + "SELECT timestamp, run_name, title, text, level, step FROM alerts" + ) + conditions = [] + params = [] + run_identity = SQLiteStorage._resolve_run_identity( + conn, run_name=run_name, run_id=run_id, table="alerts" + ) + if run_identity is not None: + conditions.append(f"{run_identity[0]} = ?") + params.append(run_identity[1]) + elif run_name is not None or run_id is not None: + return [] + if level is not None: + conditions.append("level = ?") + params.append(level) + if since is not None: + conditions.append("timestamp > ?") + params.append(since) + if conditions: + query += " WHERE " + " AND ".join(conditions) + query += " ORDER BY timestamp DESC" + cursor.execute(query, params) + + rows = cursor.fetchall() + return [ + { + "timestamp": row["timestamp"], + "run": row["run_name"], + "title": row["title"], + "text": row["text"], + "level": row["level"], + "step": row["step"], + } + for row in rows + ] + except sqlite3.OperationalError as e: + if "no such table: alerts" in str(e): + return [] + raise + + @staticmethod + def get_alert_count(project: str) -> int: + db_path = SQLiteStorage.get_project_db_path(project) + if not db_path.exists(): + return 0 + + with SQLiteStorage._get_connection(db_path) as conn: + cursor = conn.cursor() + try: + cursor.execute("SELECT COUNT(*) FROM alerts") + return cursor.fetchone()[0] + except sqlite3.OperationalError: + return 0 + + @staticmethod + def _fetch_system_logs_with_cursor( + cursor: sqlite3.Cursor, + run_identity: tuple[str, Any], + max_points: int | None = None, + ) -> list[dict[str, Any]]: + cursor.execute( + f""" + SELECT timestamp, metrics + FROM system_metrics + WHERE {run_identity[0]} = ? + ORDER BY timestamp + """, + (run_identity[1],), + ) + rows = cursor.fetchall() + rows = SQLiteStorage._subsample_metric_rows(rows, max_points) + results = [] + for row in rows: + metrics = orjson.loads(row["metrics"]) + metrics = deserialize_values(metrics) + metrics["timestamp"] = row["timestamp"] + results.append(metrics) + return results + + @staticmethod + def get_system_logs( + project: str, + run: str | None = None, + run_id: str | None = None, + max_points: int | None = None, + ) -> list[dict]: + """Retrieve system metrics for a specific run. Returns metrics with timestamps (no steps).""" + db_path = SQLiteStorage.get_project_db_path(project) + if not db_path.exists(): + return [] + + cache_key = _system_logs_read_cache_key(project, run, run_id, max_points) + cached = _system_logs_read_cache_get(db_path, cache_key) + if cached is not None: + return cached + + try: + with SQLiteStorage._get_connection(db_path) as conn: + cursor = conn.cursor() + run_identity = SQLiteStorage._resolve_run_identity( + conn, run_name=run, run_id=run_id, table="system_metrics" + ) + if run_identity is None: + logs: list[dict[str, Any]] = [] + else: + logs = SQLiteStorage._fetch_system_logs_with_cursor( + cursor, run_identity, max_points + ) + except sqlite3.OperationalError as e: + if "no such table: system_metrics" in str(e): + return [] + raise + + _system_logs_read_cache_put(db_path, cache_key, logs) + return [{**d} for d in logs] + + @staticmethod + def get_system_logs_batch( + project: str, + runs: list[dict[str, Any]] | None = None, + max_points: int | None = None, + ) -> list[dict[str, Any]]: + if not runs: + return [] + db_path = SQLiteStorage.get_project_db_path(project) + if not db_path.exists(): + return [ + { + "run": r.get("run"), + "run_id": r.get("run_id"), + "logs": [], + } + for r in runs + ] + + out: list[dict[str, Any]] = [] + try: + with SQLiteStorage._get_connection(db_path) as conn: + cursor = conn.cursor() + for r in runs: + run = r.get("run") + run_id = r.get("run_id") + cache_key = _system_logs_read_cache_key( + project, run, run_id, max_points + ) + cached = _system_logs_read_cache_get(db_path, cache_key) + if cached is not None: + out.append( + { + "run": run, + "run_id": run_id, + "logs": cached, + } + ) + continue + run_identity = SQLiteStorage._resolve_run_identity( + conn, run_name=run, run_id=run_id, table="system_metrics" + ) + if run_identity is None: + logs = [] + else: + logs = SQLiteStorage._fetch_system_logs_with_cursor( + cursor, run_identity, max_points + ) + _system_logs_read_cache_put(db_path, cache_key, logs) + out.append( + { + "run": run, + "run_id": run_id, + "logs": [{**d} for d in logs], + } + ) + except sqlite3.OperationalError as e: + if "no such table: system_metrics" in str(e): + return [ + { + "run": r.get("run"), + "run_id": r.get("run_id"), + "logs": [], + } + for r in runs + ] + raise + + return out + + @staticmethod + def get_all_system_metrics_for_run( + project: str, run: str | None = None, run_id: str | None = None + ) -> list[str]: + """Get all system metric names for a specific project/run.""" + return SQLiteStorage._get_metric_names( + project, + run, + "system_metrics", + exclude_keys={"timestamp"}, + run_id=run_id, + ) + + @staticmethod + def has_system_metrics(project: str) -> bool: + """Check if a project has any system metrics logged.""" + db_path = SQLiteStorage.get_project_db_path(project) + if not db_path.exists(): + return False + + with SQLiteStorage._get_connection(db_path) as conn: + cursor = conn.cursor() + try: + cursor.execute("SELECT COUNT(*) FROM system_metrics LIMIT 1") + count = cursor.fetchone()[0] + return count > 0 + except sqlite3.OperationalError: + return False + + @staticmethod + def get_log_count( + project: str, run: str | None = None, run_id: str | None = None + ) -> int: + SQLiteStorage._ensure_hub_loaded() + db_path = SQLiteStorage.get_project_db_path(project) + if not db_path.exists(): + return 0 + try: + with SQLiteStorage._get_connection(db_path) as conn: + cursor = conn.cursor() + run_identity = SQLiteStorage._resolve_run_identity( + conn, run_name=run, run_id=run_id + ) + if run_identity is None: + return 0 + cursor.execute( + f"SELECT COUNT(*) FROM metrics WHERE {run_identity[0]} = ?", + (run_identity[1],), + ) + return cursor.fetchone()[0] + except sqlite3.OperationalError as e: + if "no such table: metrics" in str(e): + return 0 + raise + + @staticmethod + def get_last_step( + project: str, run: str | None = None, run_id: str | None = None + ) -> int | None: + db_path = SQLiteStorage.get_project_db_path(project) + if not db_path.exists(): + return None + try: + with SQLiteStorage._get_connection(db_path) as conn: + cursor = conn.cursor() + run_identity = SQLiteStorage._resolve_run_identity( + conn, run_name=run, run_id=run_id + ) + if run_identity is None: + return None + cursor.execute( + f"SELECT MAX(step) FROM metrics WHERE {run_identity[0]} = ?", + (run_identity[1],), + ) + row = cursor.fetchone() + return row[0] if row and row[0] is not None else None + except sqlite3.OperationalError as e: + if "no such table: metrics" in str(e): + return None + raise + + @staticmethod + def get_tab_availability_flags(project: str) -> dict[str, bool]: + SQLiteStorage._ensure_hub_loaded() + flags = { + "metrics": False, + "system": False, + "traces": False, + "media": False, + "reports": False, + "alerts": False, + } + db_path = SQLiteStorage.get_project_db_path(project) + if not db_path.exists(): + return flags + + def _exists(conn, sql, params=()): + try: + cursor = conn.cursor() + cursor.execute(sql, params) + return cursor.fetchone() is not None + except sqlite3.OperationalError: + return False + + with SQLiteStorage._get_connection(db_path) as conn: + flags["metrics"] = _exists( + conn, + "SELECT 1 FROM metrics " + "WHERE CAST(metrics AS TEXT) GLOB '*:[0-9]*' " + "OR CAST(metrics AS TEXT) GLOB '*:-[0-9]*' " + "LIMIT 1", + ) + flags["media"] = _exists( + conn, + "SELECT 1 FROM metrics WHERE " + "CAST(metrics AS TEXT) GLOB ? " + "OR CAST(metrics AS TEXT) GLOB ? " + "OR CAST(metrics AS TEXT) GLOB ? " + "OR CAST(metrics AS TEXT) GLOB ? " + "LIMIT 1", + ( + '*"_type":"trackio.image"*', + '*"_type":"trackio.video"*', + '*"_type":"trackio.audio"*', + '*"_type":"trackio.table"*', + ), + ) + flags["reports"] = _exists( + conn, + "SELECT 1 FROM metrics WHERE CAST(metrics AS TEXT) GLOB ? LIMIT 1", + ('*"_type":"trackio.markdown"*',), + ) + flags["system"] = _exists(conn, "SELECT 1 FROM system_metrics LIMIT 1") + flags["traces"] = _exists(conn, "SELECT 1 FROM traces LIMIT 1") + flags["alerts"] = _exists(conn, "SELECT 1 FROM alerts LIMIT 1") + return flags + + @staticmethod + def _subsample_metric_rows(rows: list[Any], max_points: int | None) -> list[Any]: + if max_points is None or max_points < 1: + return rows + if len(rows) <= max_points: + return rows + step = len(rows) / max_points + indices = {int(i * step) for i in range(max_points)} + indices.add(len(rows) - 1) + return [rows[i] for i in sorted(indices)] + + @staticmethod + def _metric_rows_to_log_dicts(rows: list[Any]) -> list[dict[str, Any]]: + results = [] + for row in rows: + metrics = orjson.loads(row["metrics"]) + metrics = deserialize_values(metrics) + metrics["timestamp"] = row["timestamp"] + metrics["step"] = row["step"] + results.append(metrics) + return results + + @staticmethod + def _fetch_metric_logs_with_cursor( + cursor: sqlite3.Cursor, + run_identity: tuple[str, Any], + max_points: int | None, + ) -> list[dict[str, Any]]: + cursor.execute( + f""" + SELECT timestamp, step, metrics + FROM metrics + WHERE {run_identity[0]} = ? + ORDER BY timestamp + """, + (run_identity[1],), + ) + rows = cursor.fetchall() + rows = SQLiteStorage._subsample_metric_rows(rows, max_points) + return SQLiteStorage._metric_rows_to_log_dicts(rows) + + @staticmethod + def get_logs( + project: str, + run: str | None = None, + max_points: int | None = None, + run_id: str | None = None, + ) -> list[dict]: + """Retrieve logs for a specific run. Logs include the step count (int) and the timestamp (datetime object).""" + db_path = SQLiteStorage.get_project_db_path(project) + if not db_path.exists(): + return [] + + cache_key = _logs_read_cache_key(project, run, run_id, max_points) + cached = _logs_read_cache_get(db_path, cache_key) + if cached is not None: + return cached + + try: + with SQLiteStorage._get_connection(db_path) as conn: + cursor = conn.cursor() + run_identity = SQLiteStorage._resolve_run_identity( + conn, run_name=run, run_id=run_id + ) + if run_identity is None: + logs: list[dict[str, Any]] = [] + else: + logs = SQLiteStorage._fetch_metric_logs_with_cursor( + cursor, run_identity, max_points + ) + except sqlite3.OperationalError as e: + if "no such table: metrics" in str(e): + return [] + raise + + _logs_read_cache_put(db_path, cache_key, logs) + return [{**d} for d in logs] + + @staticmethod + def get_logs_batch( + project: str, + runs: list[dict[str, Any]] | None = None, + max_points: int | None = None, + ) -> list[dict[str, Any]]: + if not runs: + return [] + db_path = SQLiteStorage.get_project_db_path(project) + if not db_path.exists(): + return [ + { + "run": r.get("run"), + "run_id": r.get("run_id"), + "logs": [], + } + for r in runs + ] + + out: list[dict[str, Any]] = [] + try: + with SQLiteStorage._get_connection(db_path) as conn: + cursor = conn.cursor() + for r in runs: + run = r.get("run") + run_id = r.get("run_id") + cache_key = _logs_read_cache_key(project, run, run_id, max_points) + cached = _logs_read_cache_get(db_path, cache_key) + if cached is not None: + out.append( + { + "run": run, + "run_id": run_id, + "logs": cached, + } + ) + continue + run_identity = SQLiteStorage._resolve_run_identity( + conn, run_name=run, run_id=run_id + ) + if run_identity is None: + logs = [] + else: + logs = SQLiteStorage._fetch_metric_logs_with_cursor( + cursor, run_identity, max_points + ) + _logs_read_cache_put(db_path, cache_key, logs) + out.append( + { + "run": run, + "run_id": run_id, + "logs": [{**d} for d in logs], + } + ) + except sqlite3.OperationalError as e: + if "no such table: metrics" in str(e): + return [ + { + "run": r.get("run"), + "run_id": r.get("run_id"), + "logs": [], + } + for r in runs + ] + raise + + return out + + @staticmethod + def _is_trace_payload(value: Any) -> bool: + return isinstance(value, dict) and value.get("_type") == "trackio.trace" + + @staticmethod + def _split_trace_metrics( + metrics: dict, + *, + run: str, + run_id: str, + step: int, + timestamp: str, + log_id: str | None, + space_id: str | None, + ) -> tuple[dict, list[dict[str, Any]]]: + clean_metrics = {} + trace_rows: list[dict[str, Any]] = [] + + for key, value in metrics.items(): + is_list = isinstance(value, list) + candidates = value if is_list else [value] + traces_for_key = [ + (index if is_list else None, candidate) + for index, candidate in enumerate(candidates) + if SQLiteStorage._is_trace_payload(candidate) + ] + if not traces_for_key: + clean_metrics[key] = value + continue + + if is_list: + non_trace_items = [ + candidate + for candidate in candidates + if not SQLiteStorage._is_trace_payload(candidate) + ] + if non_trace_items: + clean_metrics[key] = non_trace_items + + for trace_index, trace in traces_for_key: + trace_id_parts = [run_id or run, log_id or uuid.uuid4().hex, key] + if trace_index is not None: + trace_id_parts.append(str(trace_index)) + trace_record = { + "id": ":".join(str(part) for part in trace_id_parts), + "run_id": run_id, + "timestamp": timestamp, + "run_name": run, + "step": step, + "key": key, + "trace_index": trace_index, + "messages": trace.get("messages", []), + "metadata": trace.get("metadata", {}), + "log_id": log_id, + "space_id": space_id, + } + trace_record["search_text"] = ( + f"{trace_record['id']} {key} " + f"{SQLiteStorage._flatten_trace_search_text(trace_record)}" + ).lower() + trace_rows.append(trace_record) + + return clean_metrics, trace_rows + + @staticmethod + def _insert_trace_rows(cursor: sqlite3.Cursor, trace_rows: list[dict[str, Any]]): + if not trace_rows: + return + cursor.executemany( + """ + INSERT OR IGNORE INTO traces + (id, run_id, timestamp, run_name, step, key, trace_index, messages, metadata, search_text, log_id, space_id) + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) + """, + [ + ( + row["id"], + row["run_id"], + row["timestamp"], + row["run_name"], + row["step"], + row["key"], + row["trace_index"], + orjson.dumps(serialize_values(row["messages"])), + orjson.dumps(serialize_values(row["metadata"])), + row["search_text"], + row["log_id"], + row["space_id"], + ) + for row in trace_rows + ], + ) + + @staticmethod + def _flatten_trace_search_text(trace: dict[str, Any]) -> str: + parts: list[str] = [] + + def visit(value: Any): + if value is None: + return + if isinstance(value, dict): + for nested in value.values(): + visit(nested) + return + if isinstance(value, list): + for nested in value: + visit(nested) + return + parts.append(str(value)) + + visit(trace.get("messages", [])) + visit(trace.get("metadata", {})) + return " ".join(parts).lower() + + @staticmethod + def _extract_traces_from_logs( + logs: list[dict[str, Any]], + run: str | None, + run_id: str | None, + ) -> list[dict[str, Any]]: + traces: list[dict[str, Any]] = [] + + for log in logs: + step = log.get("step") + timestamp = log.get("timestamp") + for key, value in log.items(): + if key in {"step", "timestamp"}: + continue + + candidates = value if isinstance(value, list) else [value] + for index, candidate in enumerate(candidates): + if ( + not isinstance(candidate, dict) + or candidate.get("_type") != "trackio.trace" + ): + continue + + trace_index = index if isinstance(value, list) else None + trace_id_parts = [run_id or run or "run", str(step), key] + if trace_index is not None: + trace_id_parts.append(str(trace_index)) + + trace_record = { + "id": ":".join(trace_id_parts), + "key": key, + "index": trace_index, + "run": run, + "run_id": run_id, + "step": step, + "timestamp": timestamp, + "messages": candidate.get("messages", []), + "metadata": candidate.get("metadata", {}), + } + trace_record["_search_text"] = ( + f"{trace_record['id']} {key} " + f"{SQLiteStorage._flatten_trace_search_text(trace_record)}" + ).lower() + traces.append(trace_record) + + return traces + + @staticmethod + def _sort_traces( + traces: list[dict[str, Any]], sort: str | None + ) -> list[dict[str, Any]]: + sort_key = sort or "request_time_desc" + if sort_key == "step_asc": + return sorted(traces, key=lambda trace: trace.get("step") or 0) + if sort_key == "step_desc": + return sorted( + traces, key=lambda trace: trace.get("step") or 0, reverse=True + ) + if sort_key == "request_time_asc": + return sorted(traces, key=lambda trace: trace.get("timestamp") or "") + return sorted( + traces, key=lambda trace: trace.get("timestamp") or "", reverse=True + ) + + @staticmethod + def get_traces( + project: str, + run: str | None = None, + search: str | None = None, + sort: str | None = None, + limit: int | None = None, + offset: int = 0, + run_id: str | None = None, + step: int | None = None, + ) -> list[dict[str, Any]]: + try: + offset = max(0, int(offset or 0)) + except (TypeError, ValueError): + offset = 0 + if limit is not None: + try: + limit = max(0, int(limit)) + except (TypeError, ValueError): + limit = None + + db_path = SQLiteStorage.get_project_db_path(project) + if not db_path.exists(): + return [] + + order_by = { + "step_asc": "step ASC, timestamp ASC, id ASC", + "step_desc": "step DESC, timestamp DESC, id DESC", + "request_time_asc": "timestamp ASC, id ASC", + "request_time_desc": "timestamp DESC, id DESC", + }.get(sort or "request_time_desc", "timestamp DESC, id DESC") + + try: + with SQLiteStorage._get_connection(db_path) as conn: + run_identity = SQLiteStorage._resolve_run_identity( + conn, run_name=run, run_id=run_id, table="traces" + ) + if run_identity is None: + return [] + + where = [f"{run_identity[0]} = ?"] + params: list[Any] = [run_identity[1]] + if step is not None: + where.append("step = ?") + params.append(step) + if search: + needle = search.strip().lower() + if needle: + where.append("search_text LIKE ?") + params.append(f"%{needle}%") + + query = f""" + SELECT id, key, trace_index, run_name, run_id, step, timestamp, messages, metadata + FROM traces + WHERE {" AND ".join(where)} + ORDER BY {order_by} + """ + if limit is not None: + query += " LIMIT ?" + params.append(limit) + if offset > 0: + if limit is None: + query += " LIMIT -1" + query += " OFFSET ?" + params.append(offset) + + cursor = conn.cursor() + cursor.execute(query, params) + rows = cursor.fetchall() + except sqlite3.OperationalError as e: + if "no such table: traces" in str(e): + return [] + raise + + return [ + { + "id": row["id"], + "key": row["key"], + "index": row["trace_index"], + "run": row["run_name"], + "run_id": row["run_id"], + "step": row["step"], + "timestamp": row["timestamp"], + "messages": deserialize_values(orjson.loads(row["messages"])), + "metadata": deserialize_values(orjson.loads(row["metadata"])), + } + for row in rows + ] + + @staticmethod + def get_trace_steps( + project: str, + run: str | None = None, + run_id: str | None = None, + ) -> dict[str, Any]: + """Return per-step trace counts and total for a run. + + Returns: {"total": int, "steps": [{"step": int, "count": int}, ...]} + Steps are returned in ascending order. + """ + db_path = SQLiteStorage.get_project_db_path(project) + if not db_path.exists(): + return {"total": 0, "steps": []} + + try: + with SQLiteStorage._get_connection(db_path) as conn: + run_identity = SQLiteStorage._resolve_run_identity( + conn, run_name=run, run_id=run_id, table="traces" + ) + if run_identity is None: + return {"total": 0, "steps": []} + cursor = conn.cursor() + cursor.execute( + f""" + SELECT step, COUNT(*) AS c + FROM traces + WHERE {run_identity[0]} = ? + GROUP BY step + ORDER BY step ASC + """, + (run_identity[1],), + ) + rows = cursor.fetchall() + except sqlite3.OperationalError as e: + if "no such table: traces" in str(e): + return {"total": 0, "steps": []} + raise + + steps = [{"step": row["step"], "count": row["c"]} for row in rows] + total = sum(item["count"] for item in steps) + return {"total": total, "steps": steps} + + @staticmethod + def load_from_dataset(): + bucket_id = os.environ.get("TRACKIO_BUCKET_ID") + if bucket_id is not None: + if not SQLiteStorage._dataset_import_attempted: + from trackio.bucket_storage import download_bucket_to_trackio_dir + + try: + download_bucket_to_trackio_dir(bucket_id) + except Exception: + pass + SQLiteStorage._dataset_import_attempted = True + return + dataset_id = os.environ.get("TRACKIO_DATASET_ID") + space_repo_name = os.environ.get("SPACE_REPO_NAME") + if dataset_id is not None and space_repo_name is not None: + hfapi = hf.HfApi() + updated = False + if not TRACKIO_DIR.exists(): + TRACKIO_DIR.mkdir(parents=True, exist_ok=True) + with SQLiteStorage.get_scheduler().lock: + try: + files = hfapi.list_repo_files(dataset_id, repo_type="dataset") + for file in files: + # Download parquet and media assets + if not (file.endswith(".parquet") or file.startswith("media/")): + continue + if (TRACKIO_DIR / file).exists(): + continue + hf.hf_hub_download( + dataset_id, file, repo_type="dataset", local_dir=TRACKIO_DIR + ) + updated = True + except hf.errors.EntryNotFoundError: + pass + except hf.errors.RepositoryNotFoundError: + pass + if updated: + SQLiteStorage.import_from_parquet() + SQLiteStorage._dataset_import_attempted = True + + @staticmethod + def _ensure_hub_loaded(): + if not SQLiteStorage._dataset_import_attempted: + SQLiteStorage.load_from_dataset() + + @staticmethod + def get_projects() -> list[str]: + """ + Get list of all projects by scanning the database files in the trackio directory. + """ + SQLiteStorage._ensure_hub_loaded() + + projects: set[str] = set() + if not TRACKIO_DIR.exists(): + return [] + + for db_file in TRACKIO_DIR.glob(f"*{DB_EXT}"): + project_name = db_file.stem + projects.add(project_name) + return sorted(projects) + + @staticmethod + def get_runs(project: str) -> list[str]: + """Get list of all runs for a project, ordered by creation time.""" + return [record["name"] for record in SQLiteStorage.get_run_records(project)] + + @staticmethod + def _validate_read_only_query(query: str) -> str: + normalized = query.strip().rstrip(";").strip() + if not normalized: + raise ValueError("Query cannot be empty.") + if not normalized.lower().startswith(_READ_ONLY_QUERY_PREFIXES): + raise ValueError( + "Only read-only SELECT, WITH, and safe PRAGMA queries are supported." + ) + return normalized + + @staticmethod + def _query_authorizer( + action_code: int, + arg1: str | None, + arg2: str | None, + db_name: str | None, + source: str | None, + ) -> int: + del arg2, db_name, source + if action_code in { + sqlite3.SQLITE_SELECT, + sqlite3.SQLITE_READ, + sqlite3.SQLITE_FUNCTION, + }: + return sqlite3.SQLITE_OK + pragma_code = getattr(sqlite3, "SQLITE_PRAGMA", None) + if action_code == pragma_code: + pragma_name = (arg1 or "").lower() + if pragma_name in _READ_ONLY_PRAGMAS: + return sqlite3.SQLITE_OK + return sqlite3.SQLITE_DENY + + @staticmethod + def _normalize_query_value(value: Any) -> Any: + if isinstance(value, (bytes, bytearray, memoryview)): + return bytes(value).hex() + return value + + @staticmethod + def query_project( + project: str, query: str, max_rows: int = _QUERY_MAX_ROWS + ) -> dict[str, Any]: + SQLiteStorage._ensure_hub_loaded() + db_path = SQLiteStorage.get_project_db_path(project) + if not db_path.exists(): + raise FileNotFoundError(f"Project '{project}' not found.") + + normalized_query = SQLiteStorage._validate_read_only_query(query) + with SQLiteStorage._get_connection(db_path) as conn: + conn.set_authorizer(SQLiteStorage._query_authorizer) + try: + cursor = conn.cursor() + cursor.execute(normalized_query) + description = cursor.description or [] + columns = [column[0] for column in description] + fetched = cursor.fetchmany(max_rows + 1) + if len(fetched) > max_rows: + raise ValueError( + f"Query returned more than {max_rows} rows. " + "Refine the query or add a LIMIT clause." + ) + rows = [ + { + column: SQLiteStorage._normalize_query_value(row[column]) + for column in columns + } + for row in fetched + ] + except sqlite3.DatabaseError as e: + raise ValueError(str(e)) from e + finally: + conn.set_authorizer(None) + + return { + "project": project, + "query": normalized_query, + "columns": columns, + "rows": rows, + "row_count": len(rows), + } + + @staticmethod + def get_max_steps_for_runs(project: str) -> dict[str, int]: + """Get the maximum step for each run in a project.""" + db_path = SQLiteStorage.get_project_db_path(project) + if not db_path.exists(): + return {} + + try: + with SQLiteStorage._get_connection(db_path) as conn: + cursor = conn.cursor() + if SQLiteStorage._supports_run_ids(conn): + cursor.execute( + """ + SELECT run_name, run_id, MAX(step) as max_step + FROM metrics + GROUP BY run_id, run_name + """ + ) + results = {} + for row in cursor.fetchall(): + results[row["run_id"]] = row["max_step"] + return results + + cursor.execute( + """ + SELECT run_name, MAX(step) as max_step + FROM metrics + GROUP BY run_name + """ + ) + + results = {} + for row in cursor.fetchall(): + results[row["run_name"]] = row["max_step"] + + return results + except sqlite3.OperationalError as e: + if "no such table: metrics" in str(e): + return {} + raise + + @staticmethod + def get_max_step_for_run( + project: str, run: str | None = None, run_id: str | None = None + ) -> int | None: + """Get the maximum step for a specific run, or None if no logs exist.""" + db_path = SQLiteStorage.get_project_db_path(project) + if not db_path.exists(): + return None + + try: + with SQLiteStorage._get_connection(db_path) as conn: + cursor = conn.cursor() + run_identity = SQLiteStorage._resolve_run_identity( + conn, run_name=run, run_id=run_id + ) + if run_identity is None: + return None + cursor.execute( + f"SELECT MAX(step) FROM metrics WHERE {run_identity[0]} = ?", + (run_identity[1],), + ) + result = cursor.fetchone()[0] + return result + except sqlite3.OperationalError as e: + if "no such table: metrics" in str(e): + return None + raise + + @staticmethod + def get_run_config( + project: str, run: str | None = None, run_id: str | None = None + ) -> dict | None: + """Get configuration for a specific run.""" + db_path = SQLiteStorage.get_project_db_path(project) + if not db_path.exists(): + return None + + with SQLiteStorage._get_connection(db_path) as conn: + cursor = conn.cursor() + try: + run_identity = SQLiteStorage._resolve_run_identity( + conn, run_name=run, run_id=run_id, table="metrics" + ) + if run_identity is None: + return None + config_col = ( + "run_id" + if "run_id" in SQLiteStorage._table_columns(conn, "configs") + else "run_name" + ) + cursor.execute( + f""" + SELECT config FROM configs WHERE {config_col} = ? + """, + (run_identity[1],), + ) + + row = cursor.fetchone() + if row: + config = orjson.loads(row["config"]) + return deserialize_values(config) + return None + except sqlite3.OperationalError as e: + if "no such table: configs" in str(e): + return None + raise + + @staticmethod + def delete_run(project: str, run: str, run_id: str | None = None) -> bool: + """Delete a run from the database (metrics, config, and system_metrics).""" + db_path = SQLiteStorage.get_project_db_path(project) + if not db_path.exists(): + return False + + with SQLiteStorage._get_process_lock(project): + with SQLiteStorage._get_connection(db_path) as conn: + cursor = conn.cursor() + try: + run_identity = SQLiteStorage._resolve_run_identity( + conn, run_name=run, run_id=run_id + ) + if run_identity is None: + return False + cursor.execute( + f"DELETE FROM metrics WHERE {run_identity[0]} = ?", + (run_identity[1],), + ) + config_identity = SQLiteStorage._resolve_run_identity( + conn, run_name=run, run_id=run_id, table="configs" + ) + if config_identity is not None: + cursor.execute( + f"DELETE FROM configs WHERE {config_identity[0]} = ?", + (config_identity[1],), + ) + try: + cursor.execute( + f"DELETE FROM system_metrics WHERE {run_identity[0]} = ?", + (run_identity[1],), + ) + except sqlite3.OperationalError: + pass + try: + cursor.execute( + f"DELETE FROM alerts WHERE {run_identity[0]} = ?", + (run_identity[1],), + ) + except sqlite3.OperationalError: + pass + try: + trace_identity = SQLiteStorage._resolve_run_identity( + conn, run_name=run, run_id=run_id, table="traces" + ) + if trace_identity is not None: + cursor.execute( + f"DELETE FROM traces WHERE {trace_identity[0]} = ?", + (trace_identity[1],), + ) + except sqlite3.OperationalError: + pass + conn.commit() + return True + except sqlite3.Error: + return False + + @staticmethod + def _update_media_paths(obj, old_prefix, new_prefix): + """Update media file paths in nested data structures.""" + if isinstance(obj, dict): + if obj.get("_type") in [ + "trackio.image", + "trackio.video", + "trackio.audio", + ]: + old_path = obj.get("file_path", "") + if isinstance(old_path, str): + normalized_path = old_path.replace("\\", "/") + if normalized_path.startswith(old_prefix): + new_path = normalized_path.replace(old_prefix, new_prefix, 1) + return {**obj, "file_path": new_path} + return { + key: SQLiteStorage._update_media_paths(value, old_prefix, new_prefix) + for key, value in obj.items() + } + elif isinstance(obj, list): + return [ + SQLiteStorage._update_media_paths(item, old_prefix, new_prefix) + for item in obj + ] + return obj + + @staticmethod + def _rewrite_metrics_rows( + metrics_rows, new_run_name, old_prefix, new_prefix, include_run_id=False + ): + """Deserialize metrics rows, update media paths, and reserialize.""" + result = [] + for row in metrics_rows: + metrics_data = orjson.loads(row["metrics"]) + metrics_deserialized = deserialize_values(metrics_data) + updated = SQLiteStorage._update_media_paths( + metrics_deserialized, old_prefix, new_prefix + ) + values = ( + row["timestamp"], + new_run_name, + row["step"], + orjson.dumps(serialize_values(updated)), + ) + if include_run_id: + values = values + (row["run_id"],) + result.append(values) + return result + + @staticmethod + def _rewrite_trace_rows( + trace_rows, + new_run_name, + old_prefix, + new_prefix, + *, + run_id: str | None = None, + ): + result = [] + for row in trace_rows: + messages = deserialize_values(orjson.loads(row["messages"])) + metadata = deserialize_values(orjson.loads(row["metadata"])) + messages = SQLiteStorage._update_media_paths( + messages, old_prefix, new_prefix + ) + metadata = SQLiteStorage._update_media_paths( + metadata, old_prefix, new_prefix + ) + result.append( + ( + row["id"], + run_id if run_id is not None else row["run_id"], + row["timestamp"], + new_run_name, + row["step"], + row["key"], + row["trace_index"], + orjson.dumps(serialize_values(messages)), + orjson.dumps(serialize_values(metadata)), + row["search_text"], + row["log_id"], + row["space_id"], + ) + ) + return result + + @staticmethod + def _move_media_dir(source: Path, target: Path): + """Move a media directory from source to target.""" + if source.exists(): + target.parent.mkdir(parents=True, exist_ok=True) + if target.exists(): + shutil.rmtree(target) + shutil.move(str(source), str(target)) + + @staticmethod + def rename_run( + project: str, old_name: str, new_name: str, run_id: str | None = None + ) -> None: + """Rename a run within the same project. + + Raises: + ValueError: If the new name is empty, the old run doesn't exist, + or a run with the new name already exists. + RuntimeError: If the database operation fails. + """ + if not new_name or not new_name.strip(): + raise ValueError("New run name cannot be empty") + + new_name = new_name.strip() + + db_path = SQLiteStorage.get_project_db_path(project) + if not db_path.exists(): + raise ValueError(f"Project '{project}' does not exist") + + with SQLiteStorage._get_process_lock(project): + with SQLiteStorage._get_connection(db_path) as conn: + cursor = conn.cursor() + supports_run_ids = SQLiteStorage._supports_run_ids(conn) + run_identity = SQLiteStorage._resolve_run_identity( + conn, run_name=old_name, run_id=run_id + ) + if run_identity is None: + raise ValueError( + f"Run '{old_name}' does not exist in project '{project}'" + ) + + run_col, run_value = run_identity + + if not supports_run_ids: + cursor.execute( + "SELECT COUNT(*) FROM metrics WHERE run_name = ?", (new_name,) + ) + if cursor.fetchone()[0] > 0: + raise ValueError( + f"A run named '{new_name}' already exists in project '{project}'" + ) + + try: + select_cols = ( + "run_id, timestamp, step, metrics" + if supports_run_ids + else "timestamp, step, metrics" + ) + cursor.execute( + f"SELECT {select_cols} FROM metrics WHERE {run_col} = ?", + (run_value,), + ) + metrics_rows = cursor.fetchall() + + old_prefix = f"{project}/{old_name}/" + new_prefix = f"{project}/{new_name}/" + + updated_rows = [] + for row in metrics_rows: + metrics_data = orjson.loads(row["metrics"]) + metrics_deserialized = deserialize_values(metrics_data) + updated = SQLiteStorage._update_media_paths( + metrics_deserialized, old_prefix, new_prefix + ) + if supports_run_ids: + updated_rows.append( + ( + row["run_id"], + row["timestamp"], + new_name, + row["step"], + orjson.dumps(serialize_values(updated)), + ) + ) + else: + updated_rows.append( + ( + row["timestamp"], + new_name, + row["step"], + orjson.dumps(serialize_values(updated)), + ) + ) + + cursor.execute( + f"DELETE FROM metrics WHERE {run_col} = ?", (run_value,) + ) + if supports_run_ids: + cursor.executemany( + "INSERT INTO metrics (run_id, timestamp, run_name, step, metrics) VALUES (?, ?, ?, ?, ?)", + updated_rows, + ) + else: + cursor.executemany( + "INSERT INTO metrics (timestamp, run_name, step, metrics) VALUES (?, ?, ?, ?)", + updated_rows, + ) + + config_col = ( + "run_id" + if "run_id" in SQLiteStorage._table_columns(conn, "configs") + else "run_name" + ) + cursor.execute( + f"UPDATE configs SET run_name = ? WHERE {config_col} = ?", + (new_name, run_value), + ) + + try: + cursor.execute( + f"UPDATE system_metrics SET run_name = ? WHERE {run_col} = ?", + (new_name, run_value), + ) + except sqlite3.OperationalError: + pass + + try: + cursor.execute( + f"UPDATE alerts SET run_name = ? WHERE {run_col} = ?", + (new_name, run_value), + ) + except sqlite3.OperationalError: + pass + + try: + cursor.execute( + f""" + SELECT id, run_id, timestamp, step, key, trace_index, messages, metadata, search_text, log_id, space_id + FROM traces WHERE {run_col} = ? + """, + (run_value,), + ) + trace_rows = cursor.fetchall() + updated_trace_rows = SQLiteStorage._rewrite_trace_rows( + trace_rows, + new_name, + old_prefix, + new_prefix, + run_id=new_name if not supports_run_ids else None, + ) + cursor.execute( + f"DELETE FROM traces WHERE {run_col} = ?", (run_value,) + ) + cursor.executemany( + """ + INSERT INTO traces + (id, run_id, timestamp, run_name, step, key, trace_index, messages, metadata, search_text, log_id, space_id) + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) + """, + updated_trace_rows, + ) + except sqlite3.OperationalError: + pass + + conn.commit() + + SQLiteStorage._move_media_dir( + MEDIA_DIR / project / old_name, + MEDIA_DIR / project / new_name, + ) + except sqlite3.Error as e: + raise RuntimeError( + f"Database error while renaming run '{old_name}' to '{new_name}': {e}" + ) from e + + @staticmethod + def move_run( + project: str, run: str, new_project: str, run_id: str | None = None + ) -> bool: + """Move a run from one project to another. + + When the source DB supports run_ids, ``run_id`` uniquely identifies the + run being moved; only that run is touched even when other runs share + the same ``run`` name. + """ + source_db_path = SQLiteStorage.get_project_db_path(project) + if not source_db_path.exists(): + return False + + target_db_path = SQLiteStorage.init_db(new_project) + + with SQLiteStorage._get_process_lock(project): + with SQLiteStorage._get_process_lock(new_project): + with SQLiteStorage._get_connection(source_db_path) as source_conn: + source_cursor = source_conn.cursor() + + metrics_has_run_id = SQLiteStorage._supports_run_ids( + source_conn, "metrics" + ) + configs_has_run_id = SQLiteStorage._supports_run_ids( + source_conn, "configs" + ) + system_has_run_id = SQLiteStorage._supports_run_ids( + source_conn, "system_metrics" + ) + alerts_has_run_id = SQLiteStorage._supports_run_ids( + source_conn, "alerts" + ) + + metrics_identity = SQLiteStorage._resolve_run_identity( + source_conn, run_name=run, run_id=run_id, table="metrics" + ) + if metrics_identity is None: + return False + metrics_col, metrics_val = metrics_identity + + configs_identity = SQLiteStorage._resolve_run_identity( + source_conn, run_name=run, run_id=run_id, table="configs" + ) + system_identity = SQLiteStorage._resolve_run_identity( + source_conn, + run_name=run, + run_id=run_id, + table="system_metrics", + ) + alerts_identity = SQLiteStorage._resolve_run_identity( + source_conn, run_name=run, run_id=run_id, table="alerts" + ) + traces_identity = SQLiteStorage._resolve_run_identity( + source_conn, run_name=run, run_id=run_id, table="traces" + ) + + metrics_select = ( + "SELECT timestamp, step, metrics" + + (", run_id" if metrics_has_run_id else "") + + f" FROM metrics WHERE {metrics_col} = ?" + ) + source_cursor.execute(metrics_select, (metrics_val,)) + metrics_rows = source_cursor.fetchall() + + config_row = None + if configs_identity is not None: + configs_col, configs_val = configs_identity + configs_select = ( + "SELECT config, created_at" + + (", run_id" if configs_has_run_id else "") + + f" FROM configs WHERE {configs_col} = ?" + ) + source_cursor.execute(configs_select, (configs_val,)) + config_row = source_cursor.fetchone() + + system_metrics_rows = [] + if system_identity is not None: + try: + system_col, system_val = system_identity + system_select = ( + "SELECT timestamp, metrics" + + (", run_id" if system_has_run_id else "") + + f" FROM system_metrics WHERE {system_col} = ?" + ) + source_cursor.execute(system_select, (system_val,)) + system_metrics_rows = source_cursor.fetchall() + except sqlite3.OperationalError: + system_metrics_rows = [] + + alert_rows = [] + if alerts_identity is not None: + try: + alerts_col, alerts_val = alerts_identity + alerts_select = ( + "SELECT timestamp, title, text, level, step, alert_id" + + (", run_id" if alerts_has_run_id else "") + + f" FROM alerts WHERE {alerts_col} = ?" + ) + source_cursor.execute(alerts_select, (alerts_val,)) + alert_rows = source_cursor.fetchall() + except sqlite3.OperationalError: + alert_rows = [] + + trace_rows = [] + if traces_identity is not None: + try: + traces_col, traces_val = traces_identity + source_cursor.execute( + f""" + SELECT id, run_id, timestamp, step, key, trace_index, messages, metadata, search_text, log_id, space_id + FROM traces WHERE {traces_col} = ? + """, + (traces_val,), + ) + trace_rows = source_cursor.fetchall() + except sqlite3.OperationalError: + trace_rows = [] + + if ( + not metrics_rows + and not config_row + and not system_metrics_rows + and not trace_rows + ): + return False + + with SQLiteStorage._get_connection(target_db_path) as target_conn: + target_cursor = target_conn.cursor() + + old_prefix = f"{project}/{run}/" + new_prefix = f"{new_project}/{run}/" + target_metrics_run_id = SQLiteStorage._supports_run_ids( + target_conn, "metrics" + ) + target_configs_run_id = SQLiteStorage._supports_run_ids( + target_conn, "configs" + ) + target_system_run_id = SQLiteStorage._supports_run_ids( + target_conn, "system_metrics" + ) + target_alerts_run_id = SQLiteStorage._supports_run_ids( + target_conn, "alerts" + ) + target_traces_run_id = SQLiteStorage._supports_run_ids( + target_conn, "traces" + ) + + needs_generated_run_id = ( + target_metrics_run_id + or target_configs_run_id + or target_system_run_id + or target_alerts_run_id + or target_traces_run_id + ) and not ( + metrics_has_run_id + or configs_has_run_id + or system_has_run_id + or alerts_has_run_id + ) + generated_run_id = ( + uuid.uuid4().hex if needs_generated_run_id else None + ) + + use_metrics_run_id = ( + metrics_has_run_id and target_metrics_run_id + ) + updated_rows = SQLiteStorage._rewrite_metrics_rows( + metrics_rows, + run, + old_prefix, + new_prefix, + include_run_id=use_metrics_run_id, + ) + + if use_metrics_run_id: + target_cursor.executemany( + "INSERT INTO metrics (timestamp, run_name, step, metrics, run_id) VALUES (?, ?, ?, ?, ?)", + updated_rows, + ) + elif target_metrics_run_id and generated_run_id is not None: + target_cursor.executemany( + "INSERT INTO metrics (timestamp, run_name, step, metrics, run_id) VALUES (?, ?, ?, ?, ?)", + [row + (generated_run_id,) for row in updated_rows], + ) + else: + target_cursor.executemany( + "INSERT INTO metrics (timestamp, run_name, step, metrics) VALUES (?, ?, ?, ?)", + updated_rows, + ) + + if config_row: + if ( + configs_has_run_id + and target_configs_run_id + and "run_id" in config_row.keys() + ): + target_cursor.execute( + """ + INSERT OR REPLACE INTO configs (run_name, config, created_at, run_id) + VALUES (?, ?, ?, ?) + """, + ( + run, + config_row["config"], + config_row["created_at"], + config_row["run_id"], + ), + ) + elif target_configs_run_id and generated_run_id is not None: + target_cursor.execute( + """ + INSERT OR REPLACE INTO configs (run_name, config, created_at, run_id) + VALUES (?, ?, ?, ?) + """, + ( + run, + config_row["config"], + config_row["created_at"], + generated_run_id, + ), + ) + else: + target_cursor.execute( + """ + INSERT OR REPLACE INTO configs (run_name, config, created_at) + VALUES (?, ?, ?) + """, + ( + run, + config_row["config"], + config_row["created_at"], + ), + ) + + for row in system_metrics_rows: + try: + if ( + system_has_run_id + and target_system_run_id + and "run_id" in row.keys() + ): + target_cursor.execute( + """ + INSERT INTO system_metrics (timestamp, run_name, metrics, run_id) + VALUES (?, ?, ?, ?) + """, + ( + row["timestamp"], + run, + row["metrics"], + row["run_id"], + ), + ) + elif ( + target_system_run_id + and generated_run_id is not None + ): + target_cursor.execute( + """ + INSERT INTO system_metrics (timestamp, run_name, metrics, run_id) + VALUES (?, ?, ?, ?) + """, + ( + row["timestamp"], + run, + row["metrics"], + generated_run_id, + ), + ) + else: + target_cursor.execute( + """ + INSERT INTO system_metrics (timestamp, run_name, metrics) + VALUES (?, ?, ?) + """, + (row["timestamp"], run, row["metrics"]), + ) + except sqlite3.OperationalError: + pass + + for row in alert_rows: + try: + if ( + alerts_has_run_id + and target_alerts_run_id + and "run_id" in row.keys() + ): + target_cursor.execute( + """ + INSERT OR IGNORE INTO alerts (timestamp, run_name, title, text, level, step, alert_id, run_id) + VALUES (?, ?, ?, ?, ?, ?, ?, ?) + """, + ( + row["timestamp"], + run, + row["title"], + row["text"], + row["level"], + row["step"], + row["alert_id"], + row["run_id"], + ), + ) + elif ( + target_alerts_run_id + and generated_run_id is not None + ): + target_cursor.execute( + """ + INSERT OR IGNORE INTO alerts (timestamp, run_name, title, text, level, step, alert_id, run_id) + VALUES (?, ?, ?, ?, ?, ?, ?, ?) + """, + ( + row["timestamp"], + run, + row["title"], + row["text"], + row["level"], + row["step"], + row["alert_id"], + generated_run_id, + ), + ) + else: + target_cursor.execute( + """ + INSERT OR IGNORE INTO alerts (timestamp, run_name, title, text, level, step, alert_id) + VALUES (?, ?, ?, ?, ?, ?, ?) + """, + ( + row["timestamp"], + run, + row["title"], + row["text"], + row["level"], + row["step"], + row["alert_id"], + ), + ) + except sqlite3.OperationalError: + pass + + if trace_rows: + trace_run_id = None + if target_traces_run_id: + if generated_run_id is not None: + trace_run_id = generated_run_id + elif traces_identity is not None and trace_rows: + trace_run_id = trace_rows[0]["run_id"] + updated_trace_rows = SQLiteStorage._rewrite_trace_rows( + trace_rows, + run, + old_prefix, + new_prefix, + run_id=trace_run_id, + ) + try: + target_cursor.executemany( + """ + INSERT OR IGNORE INTO traces + (id, run_id, timestamp, run_name, step, key, trace_index, messages, metadata, search_text, log_id, space_id) + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) + """, + updated_trace_rows, + ) + except sqlite3.OperationalError: + pass + + target_conn.commit() + + SQLiteStorage._move_media_dir( + MEDIA_DIR / project / run, + MEDIA_DIR / new_project / run, + ) + + source_cursor.execute( + f"DELETE FROM metrics WHERE {metrics_col} = ?", + (metrics_val,), + ) + if configs_identity is not None: + configs_col, configs_val = configs_identity + source_cursor.execute( + f"DELETE FROM configs WHERE {configs_col} = ?", + (configs_val,), + ) + if system_identity is not None: + try: + system_col, system_val = system_identity + source_cursor.execute( + f"DELETE FROM system_metrics WHERE {system_col} = ?", + (system_val,), + ) + except sqlite3.OperationalError: + pass + if alerts_identity is not None: + try: + alerts_col, alerts_val = alerts_identity + source_cursor.execute( + f"DELETE FROM alerts WHERE {alerts_col} = ?", + (alerts_val,), + ) + except sqlite3.OperationalError: + pass + if traces_identity is not None: + try: + traces_col, traces_val = traces_identity + source_cursor.execute( + f"DELETE FROM traces WHERE {traces_col} = ?", + (traces_val,), + ) + except sqlite3.OperationalError: + pass + source_conn.commit() + + return True + + @staticmethod + def get_all_run_configs(project: str) -> dict[str, dict]: + """Get configurations for all runs in a project.""" + db_path = SQLiteStorage.get_project_db_path(project) + if not db_path.exists(): + return {} + + with SQLiteStorage._get_connection(db_path) as conn: + cursor = conn.cursor() + try: + config_col = ( + "run_id" + if SQLiteStorage._supports_run_ids(conn, "configs") + else "run_name" + ) + cursor.execute(f"SELECT {config_col}, config FROM configs") + + results = {} + for row in cursor.fetchall(): + config = orjson.loads(row["config"]) + results[row[config_col]] = deserialize_values(config) + return results + except sqlite3.OperationalError as e: + if "no such table: configs" in str(e): + return {} + raise + + @staticmethod + def get_metric_values( + project: str, + run: str | None, + metric_name: str, + step: int | None = None, + around_step: int | None = None, + at_time: str | None = None, + window: int | float | None = None, + run_id: str | None = None, + ) -> list[dict]: + """Get values for a specific metric in a project/run with optional filtering. + + Filtering modes: + - step: return the single row at exactly this step + - around_step + window: return rows where step is in [around_step - window, around_step + window] + - at_time + window: return rows within ±window seconds of the ISO timestamp + - No filters: return all rows + """ + db_path = SQLiteStorage.get_project_db_path(project) + if not db_path.exists(): + return [] + + with SQLiteStorage._get_connection(db_path) as conn: + cursor = conn.cursor() + run_identity = SQLiteStorage._resolve_run_identity( + conn, run_name=run, run_id=run_id, table="metrics" + ) + if run_identity is None: + return [] + + query = f"SELECT timestamp, step, metrics FROM metrics WHERE {run_identity[0]} = ?" + params: list = [run_identity[1]] + + if step is not None: + query += " AND step = ?" + params.append(step) + elif around_step is not None and window is not None: + query += " AND step >= ? AND step <= ?" + params.extend([around_step - int(window), around_step + int(window)]) + elif at_time is not None and window is not None: + query += ( + " AND timestamp >= datetime(?, '-' || ? || ' seconds')" + " AND timestamp <= datetime(?, '+' || ? || ' seconds')" + ) + params.extend([at_time, int(window), at_time, int(window)]) + + query += " ORDER BY timestamp" + cursor.execute(query, params) + + rows = cursor.fetchall() + results = [] + for row in rows: + metrics = orjson.loads(row["metrics"]) + metrics = deserialize_values(metrics) + if metric_name in metrics: + results.append( + { + "timestamp": row["timestamp"], + "step": row["step"], + "value": metrics[metric_name], + } + ) + return results + + @staticmethod + def get_snapshot( + project: str, + run: str | None = None, + step: int | None = None, + around_step: int | None = None, + at_time: str | None = None, + window: int | float | None = None, + run_id: str | None = None, + ) -> dict[str, list[dict]]: + """Get all metrics at/around a point in time or step. + + Returns a dict mapping metric names to lists of {timestamp, step, value}. + """ + db_path = SQLiteStorage.get_project_db_path(project) + if not db_path.exists(): + return {} + + with SQLiteStorage._get_connection(db_path) as conn: + cursor = conn.cursor() + run_identity = SQLiteStorage._resolve_run_identity( + conn, run_name=run, run_id=run_id, table="metrics" + ) + if run_identity is None: + return {} + query = f"SELECT timestamp, step, metrics FROM metrics WHERE {run_identity[0]} = ?" + params: list = [run_identity[1]] + + if step is not None: + query += " AND step = ?" + params.append(step) + elif around_step is not None and window is not None: + query += " AND step >= ? AND step <= ?" + params.extend([around_step - int(window), around_step + int(window)]) + elif at_time is not None and window is not None: + query += ( + " AND timestamp >= datetime(?, '-' || ? || ' seconds')" + " AND timestamp <= datetime(?, '+' || ? || ' seconds')" + ) + params.extend([at_time, int(window), at_time, int(window)]) + + query += " ORDER BY timestamp" + cursor.execute(query, params) + + result: dict[str, list[dict]] = {} + for row in cursor.fetchall(): + metrics = orjson.loads(row["metrics"]) + metrics = deserialize_values(metrics) + for key, value in metrics.items(): + if key not in result: + result[key] = [] + result[key].append( + { + "timestamp": row["timestamp"], + "step": row["step"], + "value": value, + } + ) + return result + + @staticmethod + def get_all_metrics_for_run( + project: str, run: str | None = None, run_id: str | None = None + ) -> list[str]: + """Get all metric names for a specific project/run.""" + return SQLiteStorage._get_metric_names( + project, + run, + "metrics", + exclude_keys={"timestamp", "step"}, + run_id=run_id, + ) + + @staticmethod + def _get_metric_names( + project: str, + run: str | None, + table: str, + exclude_keys: set[str], + run_id: str | None = None, + ) -> list[str]: + db_path = SQLiteStorage.get_project_db_path(project) + if not db_path.exists(): + return [] + + with SQLiteStorage._get_connection(db_path) as conn: + cursor = conn.cursor() + try: + run_identity = SQLiteStorage._resolve_run_identity( + conn, run_name=run, run_id=run_id, table=table + ) + if run_identity is None: + return [] + cursor.execute( + f""" + SELECT metrics + FROM {table} + WHERE {run_identity[0]} = ? + ORDER BY timestamp + """, + (run_identity[1],), + ) + + rows = cursor.fetchall() + all_metrics = set() + for row in rows: + metrics = orjson.loads(row["metrics"]) + metrics = deserialize_values(metrics) + for key in metrics.keys(): + if key not in exclude_keys: + all_metrics.add(key) + return sorted(list(all_metrics)) + except sqlite3.OperationalError as e: + if f"no such table: {table}" in str(e): + return [] + raise + + @staticmethod + def set_project_metadata(project: str, key: str, value: str) -> None: + db_path = SQLiteStorage.init_db(project) + with SQLiteStorage._get_process_lock(project): + with SQLiteStorage._get_connection(db_path) as conn: + conn.execute( + "INSERT OR REPLACE INTO project_metadata (key, value) VALUES (?, ?)", + (key, value), + ) + conn.commit() + + @staticmethod + def get_project_metadata(project: str, key: str) -> str | None: + db_path = SQLiteStorage.get_project_db_path(project) + if not db_path.exists(): + return None + with SQLiteStorage._get_connection(db_path) as conn: + cursor = conn.cursor() + try: + cursor.execute( + "SELECT value FROM project_metadata WHERE key = ?", (key,) + ) + row = cursor.fetchone() + return row[0] if row else None + except sqlite3.OperationalError: + return None + + @staticmethod + def get_space_id(project: str) -> str | None: + return SQLiteStorage.get_project_metadata(project, "space_id") + + @staticmethod + def has_pending_data(project: str) -> bool: + db_path = SQLiteStorage.get_project_db_path(project) + if not db_path.exists(): + return False + with SQLiteStorage._get_connection(db_path) as conn: + cursor = conn.cursor() + try: + cursor.execute( + "SELECT EXISTS(SELECT 1 FROM metrics WHERE space_id IS NOT NULL LIMIT 1)" + ) + if cursor.fetchone()[0]: + return True + except sqlite3.OperationalError: + pass + try: + cursor.execute( + "SELECT EXISTS(SELECT 1 FROM system_metrics WHERE space_id IS NOT NULL LIMIT 1)" + ) + if cursor.fetchone()[0]: + return True + except sqlite3.OperationalError: + pass + try: + cursor.execute("SELECT EXISTS(SELECT 1 FROM pending_uploads LIMIT 1)") + if cursor.fetchone()[0]: + return True + except sqlite3.OperationalError: + pass + return False + + @staticmethod + def get_pending_logs(project: str) -> dict | None: + return SQLiteStorage._get_pending( + project, "metrics", extra_fields=["step"], include_config=True + ) + + @staticmethod + def clear_pending_logs(project: str, metric_ids: list[int]) -> None: + SQLiteStorage._clear_pending(project, "metrics", metric_ids) + + @staticmethod + def get_pending_system_logs(project: str) -> dict | None: + return SQLiteStorage._get_pending(project, "system_metrics") + + @staticmethod + def _get_pending( + project: str, + table: str, + extra_fields: list[str] | None = None, + include_config: bool = False, + ) -> dict | None: + db_path = SQLiteStorage.get_project_db_path(project) + if not db_path.exists(): + return None + extra_cols = ", ".join(extra_fields) + ", " if extra_fields else "" + with SQLiteStorage._get_connection(db_path) as conn: + cursor = conn.cursor() + try: + run_id_col = ( + "run_id, " if SQLiteStorage._supports_run_ids(conn, table) else "" + ) + cursor.execute( + f"""SELECT id, timestamp, {run_id_col}run_name, {extra_cols}metrics, log_id, space_id + FROM {table} WHERE space_id IS NOT NULL""" + ) + except sqlite3.OperationalError: + return None + rows = cursor.fetchall() + if not rows: + return None + logs = [] + ids = [] + for row in rows: + metrics = deserialize_values(orjson.loads(row["metrics"])) + entry = { + "project": project, + "run": row["run_name"], + "run_id": row["run_name"], + "metrics": metrics, + "timestamp": row["timestamp"], + "log_id": row["log_id"], + } + if "run_id" in row.keys(): + entry["run_id"] = row["run_id"] + for field in extra_fields or []: + entry[field] = row[field] + if include_config: + entry["config"] = None + logs.append(entry) + ids.append(row["id"]) + return {"logs": logs, "ids": ids, "space_id": rows[0]["space_id"]} + + @staticmethod + def clear_pending_system_logs(project: str, metric_ids: list[int]) -> None: + SQLiteStorage._clear_pending(project, "system_metrics", metric_ids) + + @staticmethod + def _clear_pending(project: str, table: str, ids: list[int]) -> None: + if not ids: + return + db_path = SQLiteStorage.get_project_db_path(project) + if not db_path.exists(): + return + with SQLiteStorage._get_process_lock(project): + with SQLiteStorage._get_connection(db_path) as conn: + placeholders = ",".join("?" * len(ids)) + conn.execute( + f"UPDATE {table} SET space_id = NULL WHERE id IN ({placeholders})", + ids, + ) + conn.commit() + + @staticmethod + def get_pending_uploads(project: str) -> dict | None: + db_path = SQLiteStorage.get_project_db_path(project) + if not db_path.exists(): + return None + with SQLiteStorage._get_connection(db_path) as conn: + cursor = conn.cursor() + try: + columns = SQLiteStorage._table_columns(conn, "pending_uploads") + run_id_col = "run_id, " if "run_id" in columns else "" + cursor.execute( + f"""SELECT id, space_id, {run_id_col}run_name, step, file_path, relative_path + FROM pending_uploads""" + ) + except sqlite3.OperationalError: + return None + rows = cursor.fetchall() + if not rows: + return None + uploads = [] + ids = [] + for row in rows: + uploads.append( + { + "project": project, + "run": row["run_name"], + "run_id": ( + row["run_id"] if "run_id" in row.keys() else row["run_name"] + ) + or row["run_name"], + "step": row["step"], + "file_path": row["file_path"], + "relative_path": row["relative_path"], + } + ) + ids.append(row["id"]) + return {"uploads": uploads, "ids": ids, "space_id": rows[0]["space_id"]} + + @staticmethod + def clear_pending_uploads(project: str, upload_ids: list[int]) -> None: + if not upload_ids: + return + db_path = SQLiteStorage.get_project_db_path(project) + if not db_path.exists(): + return + with SQLiteStorage._get_process_lock(project): + with SQLiteStorage._get_connection(db_path) as conn: + placeholders = ",".join("?" * len(upload_ids)) + conn.execute( + f"DELETE FROM pending_uploads WHERE id IN ({placeholders})", + upload_ids, + ) + conn.commit() + + @staticmethod + def add_pending_upload( + project: str, + space_id: str, + run_id: str | None, + run_name: str | None, + step: int | None, + file_path: str, + relative_path: str | None, + ) -> None: + db_path = SQLiteStorage.init_db(project) + with SQLiteStorage._get_process_lock(project): + with SQLiteStorage._get_connection(db_path) as conn: + if SQLiteStorage._supports_run_ids(conn, "pending_uploads"): + conn.execute( + """INSERT INTO pending_uploads + (space_id, run_id, run_name, step, file_path, relative_path, created_at) + VALUES (?, ?, ?, ?, ?, ?, ?)""", + ( + space_id, + run_id, + run_name, + step, + file_path, + relative_path, + datetime.now(timezone.utc).isoformat(), + ), + ) + else: + conn.execute( + """INSERT INTO pending_uploads + (space_id, run_name, step, file_path, relative_path, created_at) + VALUES (?, ?, ?, ?, ?, ?)""", + ( + space_id, + run_name, + step, + file_path, + relative_path, + datetime.now(timezone.utc).isoformat(), + ), + ) + conn.commit() + + @staticmethod + def get_all_logs_for_sync(project: str) -> list[dict]: + return SQLiteStorage._get_all_for_sync( + project, + "metrics", + order_by="run_name, step", + extra_fields=["step"], + include_config=True, + ) + + @staticmethod + def get_all_system_logs_for_sync(project: str) -> list[dict]: + return SQLiteStorage._get_all_for_sync( + project, "system_metrics", order_by="run_name, timestamp" + ) + + @staticmethod + def _get_all_for_sync( + project: str, + table: str, + order_by: str, + extra_fields: list[str] | None = None, + include_config: bool = False, + ) -> list[dict]: + db_path = SQLiteStorage.get_project_db_path(project) + if not db_path.exists(): + return [] + extra_cols = ", ".join(extra_fields) + ", " if extra_fields else "" + with SQLiteStorage._get_connection(db_path) as conn: + cursor = conn.cursor() + try: + run_id_col = ( + "run_id, " if SQLiteStorage._supports_run_ids(conn, table) else "" + ) + cursor.execute( + f"""SELECT timestamp, {run_id_col}run_name, {extra_cols}metrics, log_id + FROM {table} ORDER BY {order_by}""" + ) + except sqlite3.OperationalError: + return [] + rows = cursor.fetchall() + results = [] + for row in rows: + metrics = deserialize_values(orjson.loads(row["metrics"])) + entry = { + "project": project, + "run": row["run_name"], + "run_id": row["run_name"], + "metrics": metrics, + "timestamp": row["timestamp"], + "log_id": row["log_id"], + } + if "run_id" in row.keys(): + entry["run_id"] = row["run_id"] + for field in extra_fields or []: + entry[field] = row[field] + if include_config: + entry["config"] = None + results.append(entry) + return results diff --git a/trackio/table.py b/trackio/table.py new file mode 100644 index 0000000000000000000000000000000000000000..6f693a816bec971cc2d2b0f603a9cda051118f9e --- /dev/null +++ b/trackio/table.py @@ -0,0 +1,201 @@ +import os +from typing import Any, Literal +from urllib.parse import quote + +from trackio.media.media import TrackioMedia +from trackio.utils import MEDIA_DIR + + +class Table: + """ + Initializes a Table object. + + Tables can be used to log tabular data including images, numbers, and text. + + Args: + columns (`list[str]`, *optional*): + Names of the columns in the table. Optional if `data` is provided. Not + expected if `dataframe` is provided. Currently ignored. + data (`list[list[Any]]`, *optional*): + 2D row-oriented array of values. Each value can be a number, a string + (treated as Markdown and truncated if too long), or a `Trackio.Image` or + list of `Trackio.Image` objects. + dataframe (`pandas.DataFrame`, *optional*): + DataFrame used to create the table. When set, `data` and `columns` + arguments are ignored. + rows (`list[list[Any]]`, *optional*): + Currently ignored. + optional (`bool` or `list[bool]`, *optional*, defaults to `True`): + Currently ignored. + allow_mixed_types (`bool`, *optional*, defaults to `False`): + Currently ignored. + log_mode: (`Literal["IMMUTABLE", "MUTABLE", "INCREMENTAL"]` or `None`, *optional*, defaults to `"IMMUTABLE"`): + Currently ignored. + """ + + TYPE = "trackio.table" + + def __init__( + self, + columns: list[str] | None = None, + data: list[list[Any]] | None = None, + dataframe: Any | None = None, + rows: list[list[Any]] | None = None, + optional: bool | list[bool] = True, + allow_mixed_types: bool = False, + log_mode: Literal["IMMUTABLE", "MUTABLE", "INCREMENTAL"] | None = "IMMUTABLE", + ): + # TODO: implement support for columns, dtype, optional, allow_mixed_types, and log_mode. + # for now (like `rows`) they are included for API compat but don't do anything. + self.data = self._normalize_rows( + columns=columns, data=data, dataframe=dataframe + ) + + @staticmethod + def _normalize_rows( + columns: list[str] | None, + data: list[list[Any]] | None, + dataframe: Any | None, + ) -> list[dict[str, Any]]: + if dataframe is not None: + try: + records = dataframe.to_dict(orient="records") + except Exception as e: + raise TypeError( + "The `dataframe` argument must support `to_dict(orient='records')`." + ) from e + return [dict(row) for row in records] + + if data is None: + return [] + + if data and isinstance(data[0], dict): + return [dict(row) for row in data] + + normalized_rows: list[dict[str, Any]] = [] + for row in data: + row_dict: dict[str, Any] = {} + if columns is None: + for idx, value in enumerate(row): + row_dict[idx] = value + else: + for idx, column in enumerate(columns): + row_dict[column] = row[idx] if idx < len(row) else None + for idx in range(len(columns), len(row)): + row_dict[idx] = row[idx] + normalized_rows.append(row_dict) + return normalized_rows + + def _has_media_objects(self, rows: list[dict[str, Any]]) -> bool: + """Check if rows contain any TrackioMedia objects or lists of TrackioMedia objects.""" + for row in rows: + for value in row.values(): + if isinstance(value, TrackioMedia): + return True + if ( + isinstance(value, list) + and len(value) > 0 + and isinstance(value[0], TrackioMedia) + ): + return True + return False + + def _process_data(self, project: str, run: str, step: int = 0): + """Convert rows to dict format, processing any TrackioMedia objects if present.""" + if not self._has_media_objects(self.data): + return [dict(row) for row in self.data] + + processed_rows = [dict(row) for row in self.data] + for row in processed_rows: + for key, value in list(row.items()): + if isinstance(value, TrackioMedia): + value._save(project, run, step) + row[key] = value._to_dict() + if ( + isinstance(value, list) + and len(value) > 0 + and isinstance(value[0], TrackioMedia) + ): + [v._save(project, run, step) for v in value] + row[key] = [v._to_dict() for v in value] + + return processed_rows + + @staticmethod + def to_display_format(table_data: list[dict]) -> list[dict]: + """ + Converts stored table data to display format for UI rendering. + + Note: + This does not use the `self.data` attribute, but instead uses the + `table_data` parameter, which is what the UI receives. + + Args: + table_data (`list[dict]`): + List of dictionaries representing table rows (from stored `_value`). + + Returns: + `list[dict]`: Table data with images converted to markdown syntax and long + text truncated. + """ + truncate_length = int(os.getenv("TRACKIO_TABLE_TRUNCATE_LENGTH", "250")) + + def convert_image_to_markdown(image_data: dict) -> str: + relative_path = image_data.get("file_path", "") + caption = image_data.get("caption", "") + absolute_path = MEDIA_DIR / relative_path + return ( + f'{caption}' + ) + + processed_data = [] + for row in table_data: + processed_row = {} + for key, value in row.items(): + if isinstance(value, dict) and value.get("_type") == "trackio.image": + processed_row[key] = convert_image_to_markdown(value) + elif ( + isinstance(value, list) + and len(value) > 0 + and isinstance(value[0], dict) + and value[0].get("_type") == "trackio.image" + ): + # This assumes that if the first item is an image, all items are images. Ok for now since we don't support mixed types in a single cell. + processed_row[key] = ( + '
        ' + + "".join([convert_image_to_markdown(item) for item in value]) + + "
        " + ) + elif isinstance(value, str) and len(value) > truncate_length: + truncated = value[:truncate_length] + full_text = value.replace("<", "<").replace(">", ">") + processed_row[key] = ( + f'
        ' + f'{truncated}…(truncated, click to expand)' + f'
        ' + f'
        {full_text}
        ' + f"
        " + f"
        " + ) + else: + processed_row[key] = value + processed_data.append(processed_row) + return processed_data + + def _to_dict(self, project: str, run: str, step: int = 0): + """ + Converts the table to a dictionary representation. + + Args: + project (`str`): + Project name for saving media files. + run (`str`): + Run name for saving media files. + step (`int`, *optional*, defaults to `0`): + Step number for saving media files. + """ + data = self._process_data(project, run, step) + return { + "_type": self.TYPE, + "_value": data, + } diff --git a/trackio/trace.py b/trackio/trace.py new file mode 100644 index 0000000000000000000000000000000000000000..e773190bc38c3f59dfa56221ba323a50ecace925 --- /dev/null +++ b/trackio/trace.py @@ -0,0 +1,50 @@ +from __future__ import annotations + +from typing import Any + +from trackio.media import TrackioMedia + + +class Trace: + """ + Conversational or agent-style trace payload. + + Traces store OpenAI-style messages plus optional metadata. Nested Trackio + media objects inside messages or metadata are persisted and serialized + alongside the trace. + """ + + TYPE = "trackio.trace" + + def __init__(self, messages: list[dict[str, Any]], metadata: dict | None = None): + if not isinstance(messages, list) or not all( + isinstance(message, dict) for message in messages + ): + raise TypeError("`messages` must be a list of dictionaries.") + + self.messages = [dict(message) for message in messages] + self.metadata = dict(metadata) if metadata is not None else {} + + def _serialize_nested_value( + self, value: Any, project: str, run: str, step: int + ) -> Any: + if isinstance(value, TrackioMedia): + value._save(project, run, step) + return value._to_dict() + if isinstance(value, dict): + return { + key: self._serialize_nested_value(item, project, run, step) + for key, item in value.items() + } + if isinstance(value, list): + return [ + self._serialize_nested_value(item, project, run, step) for item in value + ] + return value + + def _to_dict(self, project: str, run: str, step: int = 0) -> dict[str, Any]: + return { + "_type": self.TYPE, + "messages": self._serialize_nested_value(self.messages, project, run, step), + "metadata": self._serialize_nested_value(self.metadata, project, run, step), + } diff --git a/trackio/typehints.py b/trackio/typehints.py new file mode 100644 index 0000000000000000000000000000000000000000..e65cd86cf40386a6526e0e71a4eeac9587641f4e --- /dev/null +++ b/trackio/typehints.py @@ -0,0 +1,43 @@ +from typing import Any, TypedDict + +from gradio_client import FileData + + +class LogEntry(TypedDict, total=False): + project: str + run: str + run_id: str | None + metrics: dict[str, Any] + step: int | None + config: dict[str, Any] | None + log_id: str | None + + +class SystemLogEntry(TypedDict, total=False): + project: str + run: str + run_id: str | None + metrics: dict[str, Any] + timestamp: str + log_id: str | None + + +class AlertEntry(TypedDict, total=False): + project: str + run: str + run_id: str | None + title: str + text: str | None + level: str + step: int | None + timestamp: str + alert_id: str | None + + +class UploadEntry(TypedDict): + project: str + run: str | None + run_id: str | None + step: int | None + relative_path: str | None + uploaded_file: FileData diff --git a/trackio/utils.py b/trackio/utils.py new file mode 100644 index 0000000000000000000000000000000000000000..1af2c3be1beb5497030ed440a05eb9d8df124737 --- /dev/null +++ b/trackio/utils.py @@ -0,0 +1,1022 @@ +import math +import os +import re +import secrets +import time +import warnings +from datetime import datetime, timezone +from pathlib import Path +from typing import TYPE_CHECKING, Any +from urllib.parse import quote, urlencode + +import huggingface_hub +import numpy as np +from huggingface_hub.constants import HF_HOME + +if TYPE_CHECKING: + from trackio.commit_scheduler import CommitScheduler + from trackio.dummy_commit_scheduler import DummyCommitScheduler + +RESERVED_KEYS = ["project", "run", "timestamp", "step", "time", "metrics"] + +TRACKIO_LOGO_DIR = Path(__file__).parent / "assets" + + +def _emit_nonfatal_warning(message: str, *args, **kwargs) -> None: + try: + warnings.warn(message, *args, **kwargs) + except Exception: + print(f"* Trackio warning: {message}") + + +def get_logo_urls() -> dict[str, str]: + """Get logo URLs from environment variables or use defaults.""" + light_url = os.environ.get( + "TRACKIO_LOGO_LIGHT_URL", + f"/file?path={quote(str(TRACKIO_LOGO_DIR / 'trackio_logo_type_light_transparent.png'))}", + ) + dark_url = os.environ.get( + "TRACKIO_LOGO_DARK_URL", + f"/file?path={quote(str(TRACKIO_LOGO_DIR / 'trackio_logo_type_dark_transparent.png'))}", + ) + return {"light": light_url, "dark": dark_url} + + +def order_metrics_by_plot_preference(metrics: list[str]) -> tuple[list[str], dict]: + """ + Order metrics based on TRACKIO_PLOT_ORDER environment variable and group them. + + Args: + metrics: List of metric names to order and group + + Returns: + Tuple of (ordered_group_names, grouped_metrics_dict) + """ + plot_order_env = os.environ.get("TRACKIO_PLOT_ORDER", "") + if not plot_order_env.strip(): + plot_order = [] + else: + plot_order = [ + item.strip() for item in plot_order_env.split(",") if item.strip() + ] + + def get_metric_priority(metric: str) -> tuple[int, int, str]: + if not plot_order: + return (float("inf"), float("inf"), metric) + + group_prefix = metric.split("/")[0] if "/" in metric else "charts" + no_match_priority = len(plot_order) + + group_priority = no_match_priority + for i, pattern in enumerate(plot_order): + pattern_group = pattern.split("/")[0] if "/" in pattern else "charts" + if pattern_group == group_prefix: + group_priority = i + break + + within_group_priority = no_match_priority + for i, pattern in enumerate(plot_order): + if pattern == metric: + within_group_priority = i + break + elif pattern.endswith("/*") and within_group_priority == no_match_priority: + pattern_prefix = pattern[:-2] + if metric.startswith(pattern_prefix + "/"): + within_group_priority = i + len(plot_order) + + return (group_priority, within_group_priority, metric) + + result = {} + for metric in metrics: + if "/" not in metric: + if "charts" not in result: + result["charts"] = {"direct_metrics": [], "subgroups": {}} + result["charts"]["direct_metrics"].append(metric) + else: + parts = metric.split("/") + main_prefix = parts[0] + if main_prefix not in result: + result[main_prefix] = {"direct_metrics": [], "subgroups": {}} + if len(parts) == 2: + result[main_prefix]["direct_metrics"].append(metric) + else: + subprefix = parts[1] + if subprefix not in result[main_prefix]["subgroups"]: + result[main_prefix]["subgroups"][subprefix] = [] + result[main_prefix]["subgroups"][subprefix].append(metric) + + for group_data in result.values(): + group_data["direct_metrics"].sort(key=get_metric_priority) + for subgroup_name in group_data["subgroups"]: + group_data["subgroups"][subgroup_name].sort(key=get_metric_priority) + + if "charts" in result and not result["charts"]["direct_metrics"]: + del result["charts"] + + def get_group_priority(group_name: str) -> tuple[int, str]: + if not plot_order: + return (float("inf"), group_name) + + min_priority = len(plot_order) + for i, pattern in enumerate(plot_order): + pattern_group = pattern.split("/")[0] if "/" in pattern else "charts" + if pattern_group == group_name: + min_priority = min(min_priority, i) + return (min_priority, group_name) + + ordered_groups = sorted(result.keys(), key=get_group_priority) + + return ordered_groups, result + + +def on_spaces() -> bool: + return os.environ.get("SYSTEM") == "spaces" + + +def resolve_space_id_and_server_url( + space_id: str | None, server_url: str | None +) -> tuple[str | None, str | None]: + space_id = space_id or os.environ.get("TRACKIO_SPACE_ID") + server_url = server_url or os.environ.get("TRACKIO_SERVER_URL") + if space_id is not None: + server_url = None + return space_id, server_url + + +def parse_trackio_server_url(url: str) -> tuple[str, str | None]: + from urllib.parse import parse_qsl, urlencode, urlparse, urlunparse + + p = urlparse(url.strip()) + if p.scheme not in ("http", "https"): + return url, None + pairs = parse_qsl(p.query, keep_blank_values=True) + write_token: str | None = None + rest: list[tuple[str, str]] = [] + for k, v in pairs: + if k == "write_token": + write_token = v + else: + rest.append((k, v)) + new_query = urlencode(rest) + rebuilt = urlunparse((p.scheme, p.netloc, p.path, p.params, new_query, p.fragment)) + return rebuilt, write_token + + +def _get_trackio_dir() -> Path: + if os.environ.get("TRACKIO_DIR"): + return Path(os.environ.get("TRACKIO_DIR")) + return Path(HF_HOME) / "trackio" + + +TRACKIO_DIR = _get_trackio_dir() +MEDIA_DIR = TRACKIO_DIR / "media" + + +def get_or_create_project_hash(project: str) -> str: + hash_path = TRACKIO_DIR / f"{project}.hash" + if hash_path.exists(): + return hash_path.read_text().strip() + hash_value = secrets.token_urlsafe(8) + TRACKIO_DIR.mkdir(parents=True, exist_ok=True) + hash_path.write_text(hash_value) + return hash_value + + +def generate_readable_name(used_names: list[str], space_id: str | None = None) -> str: + """ + Generates a random, readable name like "dainty-sunset-0". + If space_id is provided, generates username-timestamp format instead. + """ + if space_id is not None: + username = _get_default_namespace() + timestamp = int(time.time()) + return f"{username}-{timestamp}" + adjectives = [ + "dainty", + "brave", + "calm", + "eager", + "fancy", + "gentle", + "happy", + "jolly", + "kind", + "lively", + "merry", + "nice", + "proud", + "quick", + "hugging", + "silly", + "tidy", + "witty", + "zealous", + "bright", + "shy", + "bold", + "clever", + "daring", + "elegant", + "faithful", + "graceful", + "honest", + "inventive", + "jovial", + "keen", + "lucky", + "modest", + "noble", + "optimistic", + "patient", + "quirky", + "resourceful", + "sincere", + "thoughtful", + "upbeat", + "valiant", + "warm", + "youthful", + "zesty", + "adventurous", + "breezy", + "cheerful", + "delightful", + "energetic", + "fearless", + "glad", + "hopeful", + "imaginative", + "joyful", + "kindly", + "luminous", + "mysterious", + "neat", + "outgoing", + "playful", + "radiant", + "spirited", + "tranquil", + "unique", + "vivid", + "wise", + "zany", + "artful", + "bubbly", + "charming", + "dazzling", + "earnest", + "festive", + "gentlemanly", + "hearty", + "intrepid", + "jubilant", + "knightly", + "lively", + "magnetic", + "nimble", + "orderly", + "peaceful", + "quick-witted", + "robust", + "sturdy", + "trusty", + "upstanding", + "vibrant", + "whimsical", + ] + nouns = [ + "sunset", + "forest", + "river", + "mountain", + "breeze", + "meadow", + "ocean", + "valley", + "sky", + "field", + "cloud", + "star", + "rain", + "leaf", + "stone", + "flower", + "bird", + "tree", + "wave", + "trail", + "island", + "desert", + "hill", + "lake", + "pond", + "grove", + "canyon", + "reef", + "bay", + "peak", + "glade", + "marsh", + "cliff", + "dune", + "spring", + "brook", + "cave", + "plain", + "ridge", + "wood", + "blossom", + "petal", + "root", + "branch", + "seed", + "acorn", + "pine", + "willow", + "cedar", + "elm", + "falcon", + "eagle", + "sparrow", + "robin", + "owl", + "finch", + "heron", + "crane", + "duck", + "swan", + "fox", + "wolf", + "bear", + "deer", + "moose", + "otter", + "beaver", + "lynx", + "hare", + "badger", + "butterfly", + "bee", + "ant", + "beetle", + "dragonfly", + "firefly", + "ladybug", + "moth", + "spider", + "worm", + "coral", + "kelp", + "shell", + "pebble", + "face", + "boulder", + "cobble", + "sand", + "wavelet", + "tide", + "current", + "mist", + ] + number = 0 + name = f"{adjectives[0]}-{nouns[0]}-{number}" + while name in used_names: + number += 1 + adjective = adjectives[number % len(adjectives)] + noun = nouns[number % len(nouns)] + name = f"{adjective}-{noun}-{number}" + return name + + +def is_in_notebook(): + """ + Detect if code is running in a notebook environment (Jupyter, Colab, etc.). + """ + try: + from IPython import get_ipython + + if get_ipython() is not None: + return get_ipython().__class__.__name__ in [ + "ZMQInteractiveShell", # Jupyter notebook/lab + "Shell", # IPython terminal + ] or "google.colab" in str(get_ipython()) + except ImportError: + pass + return False + + +def block_main_thread_until_keyboard_interrupt(): + try: + while True: + time.sleep(0.1) + except (KeyboardInterrupt, OSError): + print("Keyboard interruption in main thread... closing dashboard.") + + +def simplify_column_names(columns: list[str]) -> dict[str, str]: + """ + Simplifies column names to first 10 alphanumeric or "/" characters with unique suffixes. + + Args: + columns: List of original column names + + Returns: + Dictionary mapping original column names to simplified names + """ + simplified_names = {} + used_names = set() + + for col in columns: + alphanumeric = re.sub(r"[^a-zA-Z0-9/]", "", col) + base_name = alphanumeric[:10] if alphanumeric else f"col_{len(used_names)}" + + final_name = base_name + suffix = 1 + while final_name in used_names: + final_name = f"{base_name}_{suffix}" + suffix += 1 + + simplified_names[col] = final_name + used_names.add(final_name) + + return simplified_names + + +def print_dashboard_instructions(project: str) -> None: + """ + Prints instructions for viewing the Trackio dashboard. + + Args: + project: The name of the project to show dashboard for. + """ + ORANGE = "\033[38;5;208m" + BOLD = "\033[1m" + RESET = "\033[0m" + + print("* View dashboard by running in your terminal:") + print(f'{BOLD}{ORANGE}trackio show --project "{project}"{RESET}') + print(f'* or by running in Python: trackio.show(project="{project}")') + + +def print_write_token_instructions(full_url: str) -> None: + print() + print(f"* Trackio dashboard opened in browser with write access at: {full_url}") + print( + "* Only share this write_token with trusted users, as it allows them to write logs, " + "rename/delete runs, and connect MCP tools." + ) + + +def preprocess_space_and_dataset_ids( + space_id: str | None, + dataset_id: str | None, + bucket_id: str | None = None, +) -> tuple[str | None, str | None, str | None]: + """ + Preprocesses the Space and Bucket names to ensure they are valid + "username/name" format. When space_id is provided and bucket_id is not + explicitly set, auto-generates a bucket_id. + """ + if space_id is not None and "/" not in space_id: + username = _get_default_namespace() + space_id = f"{username}/{space_id}" + if dataset_id is not None: + warnings.warn( + "`dataset_id` is deprecated. Use `bucket_id` instead.", + DeprecationWarning, + stacklevel=3, + ) + if dataset_id is not None and "/" not in dataset_id: + username = _get_default_namespace() + dataset_id = f"{username}/{dataset_id}" + if bucket_id is not None and "/" not in bucket_id: + username = _get_default_namespace() + bucket_id = f"{username}/{bucket_id}" + if space_id is not None and dataset_id is None and bucket_id is None: + bucket_id = f"{space_id}-bucket" + return space_id, dataset_id, bucket_id + + +def fibo(): + """Generator for Fibonacci backoff: 1, 1, 2, 3, 5, 8, ...""" + a, b = 1, 1 + while True: + yield a + a, b = b, a + b + + +def format_timestamp(timestamp_str): + """Convert ISO timestamp to human-readable format like '3 minutes ago'.""" + if not timestamp_str or is_missing_value(timestamp_str): + return "Unknown" + + try: + created_time = datetime.fromisoformat(timestamp_str.replace("Z", "+00:00")) + if created_time.tzinfo is None: + created_time = created_time.replace(tzinfo=timezone.utc) + + now = datetime.now(timezone.utc) + diff = now - created_time + + seconds = int(diff.total_seconds()) + if seconds < 60: + return "Just now" + elif seconds < 3600: + minutes = seconds // 60 + return f"{minutes} minute{'s' if minutes != 1 else ''} ago" + elif seconds < 86400: + hours = seconds // 3600 + return f"{hours} hour{'s' if hours != 1 else ''} ago" + else: + days = seconds // 86400 + return f"{days} day{'s' if days != 1 else ''} ago" + except Exception: + return "Unknown" + + +DEFAULT_COLOR_PALETTE = [ + "#A8769B", + "#E89957", + "#3B82F6", + "#10B981", + "#EF4444", + "#8B5CF6", + "#14B8A6", + "#F59E0B", + "#EC4899", + "#06B6D4", +] + + +def get_color_palette() -> list[str]: + """Get the color palette from environment variable or use default.""" + env_palette = os.environ.get("TRACKIO_COLOR_PALETTE") + if env_palette: + return [color.strip() for color in env_palette.split(",")] + return DEFAULT_COLOR_PALETTE + + +def get_color_mapping( + runs: list[str], smoothing: bool, color_palette: list[str] | None = None +) -> dict[str, str]: + """Generate color mapping for runs, with transparency for original data when smoothing is enabled.""" + if color_palette is None: + color_palette = get_color_palette() + + color_map = {} + + for i, run in enumerate(runs): + base_color = color_palette[i % len(color_palette)] + + if smoothing: + color_map[run] = base_color + "4D" + color_map[f"{run}_smoothed"] = base_color + else: + color_map[run] = base_color + + return color_map + + +def is_missing_value(value: object) -> bool: + if value is None: + return True + if isinstance(value, str): + return False + try: + return bool(math.isnan(value)) + except (TypeError, ValueError): + return False + + +def _to_records_with_columns( + data: object, +) -> tuple[list[dict[str, Any]], list[str], Any]: + if hasattr(data, "to_dict"): + try: + records = data.to_dict(orient="records") + except Exception: + pass + else: + columns = [str(column) for column in getattr(data, "columns", [])] + return [dict(row) for row in records], columns, data.__class__ + + if isinstance(data, list): + records = [dict(row) for row in data] + columns = list(records[0].keys()) if records else [] + return records, columns, None + + raise TypeError( + "downsample() expects a list of row dictionaries or a dataframe-like object." + ) + + +def _restore_records_shape( + records: list[dict[str, Any]], + columns: list[str], + dataframe_class: Any, +) -> Any: + if dataframe_class is None or not hasattr(dataframe_class, "from_records"): + return records + return dataframe_class.from_records(records, columns=columns) + + +def downsample( + data: object, + x: str, + y: str, + color: str | None, + x_lim: tuple[float | None, float | None] | None = None, +) -> tuple[Any, tuple[float, float] | None]: + """ + Downsample the dataframe to reduce the number of points plotted. + Also updates the x-axis limits to the data min/max if either of the x-axis limits are None. + + Args: + df: The dataframe to downsample. + x: The column name to use for the x-axis. + y: The column name to use for the y-axis. + color: The column name to use for the color. + x_lim: The x-axis limits to use. + + Returns: + A tuple containing the downsampled dataframe and the updated x-axis limits. + """ + rows, columns, dataframe_class = _to_records_with_columns(data) + + if not rows: + if x_lim is not None: + x_lim = (x_lim[0] or 0, x_lim[1] or 0) + return _restore_records_shape([], columns, dataframe_class), x_lim + + columns_to_keep = [x, y] + if color is not None and any(color in row for row in rows): + columns_to_keep.append(color) + filtered_rows = [ + {column: row.get(column) for column in columns_to_keep} for row in rows + ] + + data_x_values = [row[x] for row in filtered_rows] + data_x_min = min(data_x_values) + data_x_max = max(data_x_values) + + if x_lim is not None: + x_min, x_max = x_lim + if x_min is None: + x_min = data_x_min + if x_max is None: + x_max = data_x_max + updated_x_lim = (x_min, x_max) + else: + updated_x_lim = None + + n_bins = 100 + + groups: dict[Any, list[tuple[int, dict[str, Any]]]] = {} + if color is not None and color in columns_to_keep: + for idx, row in enumerate(filtered_rows): + groups.setdefault(row.get(color), []).append((idx, row)) + else: + groups[None] = list(enumerate(filtered_rows)) + + downsampled_indices: list[int] = [] + + for group_rows in groups.values(): + if not group_rows: + continue + + group_rows = sorted(group_rows, key=lambda item: item[1][x]) + + if updated_x_lim is not None: + x_min, x_max = updated_x_lim + before_point = [item for item in group_rows if item[1][x] < x_min] + after_point = [item for item in group_rows if item[1][x] > x_max] + group_rows = [item for item in group_rows if x_min <= item[1][x] <= x_max] + else: + before_point = after_point = None + x_min = group_rows[0][1][x] + x_max = group_rows[-1][1][x] + + if before_point: + downsampled_indices.append(before_point[-1][0]) + if after_point: + downsampled_indices.append(after_point[0][0]) + + if not group_rows: + continue + + if x_min == x_max: + min_y_idx = min(group_rows, key=lambda item: item[1][y])[0] + max_y_idx = max(group_rows, key=lambda item: item[1][y])[0] + if min_y_idx != max_y_idx: + downsampled_indices.extend([min_y_idx, max_y_idx]) + else: + downsampled_indices.append(min_y_idx) + continue + + if len(group_rows) < 500: + downsampled_indices.extend(idx for idx, _ in group_rows) + continue + + bins = np.linspace(x_min, x_max, n_bins + 1) + binned_rows: dict[int, list[tuple[int, dict[str, Any]]]] = {} + for idx, row in group_rows: + bin_idx = int( + np.clip(np.digitize(row[x], bins, right=False) - 1, 0, n_bins - 1) + ) + binned_rows.setdefault(bin_idx, []).append((idx, row)) + + for bin_rows in binned_rows.values(): + if not bin_rows: + continue + + min_y_idx = min(bin_rows, key=lambda item: item[1][y])[0] + max_y_idx = max(bin_rows, key=lambda item: item[1][y])[0] + + downsampled_indices.append(min_y_idx) + if min_y_idx != max_y_idx: + downsampled_indices.append(max_y_idx) + + unique_indices = sorted(set(downsampled_indices)) + selected_rows = [filtered_rows[idx] for idx in unique_indices] + + if color is not None and color in columns_to_keep: + grouped_rows: dict[Any, list[dict[str, Any]]] = {} + group_order: list[Any] = [] + for row in selected_rows: + group_key = row.get(color) + if group_key not in grouped_rows: + grouped_rows[group_key] = [] + group_order.append(group_key) + grouped_rows[group_key].append(row) + downsampled_rows = [] + for group_key in group_order: + downsampled_rows.extend( + sorted(grouped_rows[group_key], key=lambda row: row[x]) + ) + else: + downsampled_rows = sorted(selected_rows, key=lambda row: row[x]) + + return ( + _restore_records_shape(downsampled_rows, columns_to_keep, dataframe_class), + updated_x_lim, + ) + + +def sort_metrics_by_prefix(metrics: list[str]) -> list[str]: + """ + Sort metrics by grouping prefixes together for dropdown/list display. + Metrics without prefixes come first, then grouped by prefix. + + Args: + metrics: List of metric names + + Returns: + List of metric names sorted by prefix + + Example: + Input: ["train/loss", "loss", "train/acc", "val/loss"] + Output: ["loss", "train/acc", "train/loss", "val/loss"] + """ + groups = group_metrics_by_prefix(metrics) + result = [] + + if "charts" in groups: + result.extend(groups["charts"]) + + for group_name in sorted(groups.keys()): + if group_name != "charts": + result.extend(groups[group_name]) + + return result + + +def group_metrics_by_prefix(metrics: list[str]) -> dict[str, list[str]]: + """ + Group metrics by their prefix. Metrics without prefix go to 'charts' group. + + Args: + metrics: List of metric names + + Returns: + Dictionary with prefix names as keys and lists of metrics as values + + Example: + Input: ["loss", "accuracy", "train/loss", "train/acc", "val/loss"] + Output: { + "charts": ["loss", "accuracy"], + "train": ["train/loss", "train/acc"], + "val": ["val/loss"] + } + """ + no_prefix = [] + with_prefix = [] + + for metric in metrics: + if "/" in metric: + with_prefix.append(metric) + else: + no_prefix.append(metric) + + no_prefix.sort() + + prefix_groups = {} + for metric in with_prefix: + prefix = metric.split("/")[0] + if prefix not in prefix_groups: + prefix_groups[prefix] = [] + prefix_groups[prefix].append(metric) + + for prefix in prefix_groups: + prefix_groups[prefix].sort() + + groups = {} + if no_prefix: + groups["charts"] = no_prefix + + for prefix in sorted(prefix_groups.keys()): + groups[prefix] = prefix_groups[prefix] + + return groups + + +def get_sync_status(scheduler: "CommitScheduler | DummyCommitScheduler") -> int | None: + """Get the sync status from the CommitScheduler in an integer number of minutes, or None if not synced yet.""" + if getattr( + scheduler, "last_push_time", None + ): # DummyCommitScheduler doesn't have last_push_time + time_diff = time.time() - scheduler.last_push_time + return int(time_diff / 60) + else: + return None + + +def generate_share_url( + project: str, + metrics: str, + selected_runs: list = None, + hide_headers: bool = False, +) -> str: + """Generate the shareable Space URL based on current settings.""" + space_host = os.environ.get("SPACE_HOST", "") + if not space_host: + return "" + + params: dict[str, str] = {} + + if project: + params["project"] = project + + if metrics and metrics.strip(): + params["metrics"] = metrics + + if selected_runs: + params["runs"] = ",".join(selected_runs) + + if hide_headers: + params["accordion"] = "hidden" + params["sidebar"] = "hidden" + params["navbar"] = "hidden" + + query_string = urlencode(params) + return f"https://{space_host}?{query_string}" + + +def generate_embed_code( + project: str, + metrics: str, + selected_runs: list = None, + hide_headers: bool = False, +) -> str: + """Generate the embed iframe code based on current settings.""" + embed_url = generate_share_url(project, metrics, selected_runs, hide_headers) + if not embed_url: + return "" + + return f'' + + +def serialize_values(metrics): + """ + Serialize values to make them JSON-compliant. + + Converts: + - float('inf') -> "Infinity" + - float('-inf') -> "-Infinity" + - float('nan') -> "NaN" + + Example: + {"loss": float('inf'), "accuracy": 0.95} -> {"loss": "Infinity", "accuracy": 0.95} + """ + + def _serialize(value): + if isinstance(value, dict): + return {str(key): _serialize(item) for key, item in value.items()} + if isinstance(value, (list, tuple, set)): + return [_serialize(item) for item in value] + if isinstance(value, np.generic): + value = value.item() + if isinstance(value, bool | int): + return value + if isinstance(value, float): + if math.isinf(value): + return "Infinity" if value > 0 else "-Infinity" + if math.isnan(value): + return "NaN" + return float(value) + return value + + return _serialize(metrics) + + +def deserialize_values(metrics): + """ + Deserialize infinity and NaN string values back to their numeric forms. + Only handles top-level string values. + + Converts: + - "Infinity" -> float('inf') + - "-Infinity" -> float('-inf') + - "NaN" -> float('nan') + + Example: + {"loss": "Infinity", "accuracy": 0.95} -> {"loss": float('inf'), "accuracy": 0.95} + """ + if not isinstance(metrics, dict): + return metrics + + result = {} + for key, value in metrics.items(): + if value == "Infinity": + result[key] = float("inf") + elif value == "-Infinity": + result[key] = float("-inf") + elif value == "NaN": + result[key] = float("nan") + else: + result[key] = value + return result + + +def get_full_url( + base_url: str, project: str | None, write_token: str, footer: bool = True +) -> str: + params = [] + if project: + params.append(f"project={project}") + params.append(f"write_token={write_token}") + if not footer: + params.append("footer=false") + return base_url + "?" + "&".join(params) + + +def embed_url_in_notebook(url: str) -> None: + try: + from IPython.display import HTML, display + + embed_code = HTML( + f'
        ' + ) + display(embed_code) + except ImportError: + pass + + +def to_json_safe(obj): + if isinstance(obj, (str, int, float, bool, type(None))): + return obj + if isinstance(obj, np.generic): + return obj.item() + if isinstance(obj, dict): + return {str(k): to_json_safe(v) for k, v in obj.items()} + if isinstance(obj, (list, tuple, set)): + return [to_json_safe(v) for v in obj] + if hasattr(obj, "to_dict") and callable(obj.to_dict): + return to_json_safe(obj.to_dict()) + if hasattr(obj, "__dict__"): + return { + str(k): to_json_safe(v) + for k, v in vars(obj).items() + if not k.startswith("_") + } + return str(obj) + + +def get_space() -> str | None: + """ + Get the space ID ("user/space") if Trackio is running in a Space, or None if not. + """ + return os.environ.get("SPACE_ID") + + +def ordered_subset(items: list[str], subset: list[str] | None) -> list[str]: + subset_set = set(subset or []) + return [item for item in items if item in subset_set] + + +def _get_default_namespace() -> str: + """Get the default namespace (username). + + This function uses caching to avoid repeated API calls to /whoami-v2. + """ + token = huggingface_hub.get_token() + return huggingface_hub.whoami(token=token, cache=True)["name"]