Skip to content

Use a relative coefficient threshold in trendline equations - #1148

Merged
h-a-n-a-s-h-i merged 1 commit into
storytold:mainfrom
Silvertree2010:fix/h1231-trendline-equation-label-shows-y
Oct 23, 2026
Merged

h-a-n-a-s-h-i merged 1 commit into
storytold:mainfrom
Silvertree2010:fix/h1231-trendline-equation-label-shows-y

Conversation

@Silvertree2010

@Silvertree2010 Silvertree2010 commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Found while testing crates/model/src/trendline.rs:~507 (poly_equation) (no existing issue): Trendline equation label shows 'y = 0' for small-valued data because of an absolute coefficient threshold.

Cause

poly_equation set the term-skip threshold to max(|coeff|).max(1.0) * 1e-8. Because of the .max(1.0) floor, any coefficient below 1e-8 was always dropped, however small the data was. As a result, linear, polynomial and log trendlines fitted to tiny-valued data displayed y = 0.

Fix

The skip threshold is now relative to the largest coefficient magnitude, with no floor. It uses <=, so an all-zero fit still shows y = 0. The check that shows a coefficient of about 1 as a bare x keeps its old tolerance of scale.max(1.0) * 1e-8.

Verified

  • Regression test trendline::tests::equation_keeps_tiny_coefficients: fails on main without the fix and passes with it (cargo test -p deckcraft-model --lib trendline::tests::equation_keeps_tiny_coefficients).
  • cargo xtask ci passes except control_server::tests::a_line_that_is_not_a_request_closes_the_connection, which also fails on main without this change.

Not changed

Number formatting (num) and the exponential and power equation paths are unchanged.

🤖 Generated with AI by ApolloOffice, see the Co-Authored-By trailers for the models

Summary by CodeRabbit

  • Bug Fixes
    • Improved trendline equation display for fits with very small coefficients, preserving meaningful terms and formatting equations more accurately.

Found while testing crates/model/src/trendline.rs:~507 (poly_equation)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
📥 Commits

Reviewing files that changed from the base of the PR and between 128cb0b and 1dd96d3.

📒 Files selected for processing: 1
  • crates/model/src/trendline.rs

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 3 remain after this review.

📝 Walkthrough

Polynomial equation generation now filters terms relative to the largest coefficient, including for small-valued fits. Unit-coefficient formatting uses a minimum scale of 1. Tests cover tiny coefficients and an all-zero linear fit.

Changes: Polynomial equation formatting

Layer / File(s) Summary
Equation generation and regression tests
crates/model/src/trendline.rs
Term filtering now uses the largest coefficient as its scale, and the omission comparison includes coefficients equal to the threshold. Unit-coefficient formatting uses a scale of at least 1. Tests cover tiny linear, quadratic, and logarithmic coefficients, and a zero-valued linear fit.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix

Suggested reviewers: nikitkara

Merge Risk: ⚪ Minimal · up to 1dd96

No concrete merge-blocking risk remains in this change.

Architecture risk: 🔵 Low · up to 1dd96

The change affects 1 system.

Changed systems: crates

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — crates (service) was modified; 1 changed file maps to changed impact.

Before / after behavior

  • observed — Modified behavior in crates/model/src/trendline.rs: poly_equation no longer floors the coefficient scale at 1, so term omission is relative to the largest coefficient even when all coefficients are tiny. The omission comparison changes from < to <=.
  • observed — Modified behavior in crates/model/src/trendline.rs: The test for formatting a coefficient as a bare power now compares its distance from 1 against scale.max(1.0) * 1e-8 instead of scale * 1e-8.
  • observed — Modified behavior in crates/model/src/trendline.rs: Adds a test asserting that tiny linear, quadratic, and logarithmic coefficients remain in generated equations, and that an all-zero linear fit renders as y = 0.
Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: using a relative coefficient threshold in trendline equations.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@h-a-n-a-s-h-i
h-a-n-a-s-h-i merged commit a64487c into storytold:main Oct 23, 2026
3 checks passed
@echelon

echelon commented Oct 23, 2026

Copy link
Copy Markdown
Member

Landed on main — thank you for the contribution! If you haven't already, come join us on Discord: https://discord.gg/artcraft

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.

3 participants