Skip to content

fix(Regression): preserve time scale and activate fx/fy faceting#549

Merged
gka merged 3 commits intomainfrom
fix/regression-time-scale-and-faceting
Apr 12, 2026
Merged

fix(Regression): preserve time scale and activate fx/fy faceting#549
gka merged 3 commits intomainfrom
fix/regression-time-scale-and-faceting

Conversation

@gka
Copy link
Copy Markdown
Contributor

@gka gka commented Apr 12, 2026

Summary

  • Time scale broken by RegressionY/X: Regression.svelte was calling toOutputX(value, plot.scales[independent].type) to decide whether to convert epoch-ms numbers back to Date objects for the inner Line mark. On the first render pass the scale type isn't resolved yet ("linear"), so numbers were emitted. Scale inference then saw a mix of Date values (from the user's marks) and numbers (from Regression's Line) and permanently fell back to "linear", destroying nice time-axis ticks. Fix: derive temporality from filteredData[0] (instanceof Date) instead of the scale type, breaking the circular dependency.

  • fx/fy faceting not activated: the outer <Mark type="regression"> in RegressionY/RegressionX had no data and no fx/fy props, and the inner <Line> explicitly set fx: null, fy: null. Neither contributed to the fx/fy scale domain. FacetGrid checks plot.scales.fx.domain.length > 0 to decide whether to split into facet cells — with an empty domain it never did. Fix: pass {data}, fx={options.fx}, and fy={options.fy} to the outer <Mark> in both RegressionY and RegressionX.

Test plan

  • pnpm test — all 834 tests pass (added regression tests for both bugs)
  • New test: preserves time scale when x channel contains Date values — verifies regression path is valid and NaN-free on a time x-axis
  • New test: activates fx faceting when fx channel is set — verifies two g.facet elements are created and each contains a regression line

🤖 Generated with Claude Code

Two bugs fixed in RegressionY/RegressionX:

1. Time scale regression: toOutputX was reading plot.scales[independent].type
   to decide whether to emit Date objects for the inner Line mark. On the first
   render pass the scale type is not yet resolved, so numeric values were emitted
   instead. Scale inference then saw a mix of Dates (from the user's marks) and
   numbers (from Regression's Line) and permanently fell back to 'linear'.
   Fix: detect temporality from the raw input data (instanceof Date) instead of
   the scale type, breaking the circular dependency.

2. fx/fy faceting: the outer <Mark type="regression"> had no data and no fx/fy
   props, so it contributed nothing to the fx/fy scale domain. The inner <Line>
   also had fx:null/fy:null. With no mark populating the domain, FacetGrid saw
   an empty domain and never split into facet cells.
   Fix: pass {data}, fx, and fy to the outer <Mark> in RegressionY and
   RegressionX so scale computation collects the facet domain values.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@netlify
Copy link
Copy Markdown

netlify bot commented Apr 12, 2026

Deploy Preview for svelteplot ready!

Name Link
🔨 Latest commit 8737931
🔍 Latest deploy log https://app.netlify.com/projects/svelteplot/deploys/69dc135f74397500087282af
😎 Deploy Preview https://deploy-preview-549--svelteplot.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@github-actions
Copy link
Copy Markdown

📦 Preview package for this PR is published!

Version: 0.14.1-pr-549.0

Install it with:

npm install svelteplot@pr-549
# or install the specific version
npm install svelteplot@0.14.1-pr-549.0

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b5cb58fa3a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/lib/marks/helpers/Regression.svelte Outdated
…irst

independentIsDate was checking only filteredData[0]. A leading row with a
null/undefined/invalid independent-channel value returns null from
resolveChannel, not a Date, so the flag would be false even when later rows
are Dates. This caused regrData to emit numeric __x values, which could push
scale inference back to 'linear' when Regression is the only contributing mark.

Switch to Array.some() so we find the first row that actually resolves to a
Date, regardless of position.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown

📦 Preview package for this PR is published!

Version: 0.14.1-pr-549.1

Install it with:

npm install svelteplot@pr-549
# or install the specific version
npm install svelteplot@0.14.1-pr-549.1

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown

📦 Preview package for this PR is published!

Version: 0.14.1-pr-549.2

Install it with:

npm install svelteplot@pr-549
# or install the specific version
npm install svelteplot@0.14.1-pr-549.2

@gka gka merged commit f0e769a into main Apr 12, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant