Skip to content

FE-591: Add Metrics: timeline picker, compiler, and drawer#8633

Draft
kube wants to merge 3 commits intocf/fe-532-implement-basic-experimentfrom
cf/fe-591-implement-basic-metrics
Draft

FE-591: Add Metrics: timeline picker, compiler, and drawer#8633
kube wants to merge 3 commits intocf/fe-532-implement-basic-experimentfrom
cf/fe-591-implement-basic-metrics

Conversation

@kube
Copy link
Copy Markdown
Collaborator

@kube kube commented Apr 15, 2026

🌟 What is the purpose of this PR?

🔗 Related links

  • ...

🚫 Blocked by

  • ...

🔍 What does this change?

  • ...

Pre-Merge Checklist 🚀

🚢 Has this modified a publishable library?

This PR:

  • does not modify any publishable blocks or libraries, or modifications do not need publishing
  • modifies an npm-publishable library and I have added a changeset file(s)
  • modifies a Cargo-publishable library and I have amended the version
  • modifies a Cargo-publishable library, but it is not yet ready to publish
  • modifies a block that will need publishing via GitHub action once merged
  • I am unsure / need advice

📜 Does this require a change to the docs?

The changes in this PR:

  • are internal and do not require a docs change
  • are in a state where docs changes are not yet required but will be
  • require changes to docs which are made as part of this PR
  • require changes to docs which are not made in this PR
    • Provide more detail here
  • I am unsure / need advice

🕸️ Does this require a change to the Turbo Graph?

The changes in this PR:

  • do not affect the execution graph
  • affected the execution graph, and the turbo.json's have been updated to reflect this
  • I am unsure / need advice

⚠️ Known issues

🐾 Next steps

🛡 What tests cover this?

❓ How to test this?

  1. Checkout the branch / view the deployment
  2. Try X
  3. Confirm that Y

📹 Demo

kube added 3 commits April 15, 2026 22:19
Introduces user-authored metric functions that run over each simulation
frame and plot a single number on the timeline chart.

- Schema: Metric type on SDCPN with Zod validation; round-trips via the
  file format (legacy files default to an empty list).
- Compiler: compileMetric mirrors compileScenario's hardening (strict
  mode, shadowed globals, frozen prototype-less state), plus a
  buildMetricState helper that reshapes a frame's buffer into named
  tokens per place.
- Timeline: metric picker in the header (Default + each metric) with
  Create/Edit/Manage IconButtons matching the scenarios picker pattern.
  When a metric is picked, useStreamingData streams a single series
  computed per frame; runtime errors render as NaN gaps, compile errors
  replace the chart with a message.
- Drawers: CreateMetricDrawer and ViewMetricDrawer with a multi-line
  CodeEditor for the function body and live compile preview in the
  footer. Metrics CRUD added to MutationContext under the scenarioMutate
  guard so edits work in simulate mode.
- SimulateView: Metrics tab enabled with a MetricList; sidebar mode
  lifted to EditorContext so the Manage button can open the tab.
- Example: SIR model gains an "Infected Fraction" metric.
- Add a "Metric" label and widen the timeline picker to match the
  Scenario picker in simulation settings.
- Truncate Select dropdown labels with ellipsis on overflow instead of
  wrapping, by applying min-width:0 on items and an ItemText style that
  clips the default label.
- Dedent the SIR "Infected Fraction" example code so it renders at
  column 0 in the editor.
Introduces a second built-in view alongside the existing per-place
breakdown, aggregating token counts by color type. Places with no color
are collapsed into a single "Untyped" series.

- Replaces `timelineMetricId` with a discriminated `TimelineView` union
  so native views and user metrics share one state field.
- Refactors useStreamingData to drive all three modes off a single
  `{ series, extract }` config, unifying the frame loop.
- Picker now shows "Tokens per place", "Tokens per type", then each
  metric; the Edit icon is only relevant for user-defined metrics.
- Legend is gated on series count (>= 2) rather than mode, so a
  single-series per-type run also hides it.
@vercel
Copy link
Copy Markdown

vercel bot commented Apr 15, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
hash Ready Ready Preview, Comment Apr 15, 2026 9:26pm
petrinaut Ready Ready Preview Apr 15, 2026 9:26pm
2 Skipped Deployments
Project Deployment Actions Updated (UTC)
hashdotdesign Ignored Ignored Preview Apr 15, 2026 9:26pm
hashdotdesign-tokens Ignored Ignored Preview Apr 15, 2026 9:26pm

@github-actions github-actions bot added area/infra Relates to version control, CI, CD or IaC (area) area/libs Relates to first-party libraries/crates/packages (area) type/eng > frontend Owned by the @frontend team labels Apr 15, 2026
Copy link
Copy Markdown
Collaborator Author

kube commented Apr 15, 2026

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@kube kube changed the title Add Metrics: timeline picker, compiler, and drawer FE-591: Add Metrics: timeline picker, compiler, and drawer Apr 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/infra Relates to version control, CI, CD or IaC (area) area/libs Relates to first-party libraries/crates/packages (area) type/eng > frontend Owned by the @frontend team

Development

Successfully merging this pull request may close these issues.

1 participant