mirror of
https://github.com/storytold/deckcraft.git
synced 2026-10-26 19:46:58 -06:00
Fix up merged PRs: scatter trendlines follow the value x axis
#662 gives scatter and bubble charts one x scale over every series; #603's trendlines still mapped x over each series' own extent, so a fit drifted off its points. Use the chart's x scale where there is one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
256ad7057c
commit
5089d615bf
@@ -690,7 +690,7 @@ fn draw_inner(ctx: &mut RenderContext, rctx: &Ctx, c: &Chart, m: Affine, w: f64,
|
||||
}
|
||||
// A category position (0-based, fractional) as a slot, the way `slot` places the bars.
|
||||
let slot_at = |x: f64| if backwards { ncat as f64 - 1.0 - x + fwd } else { x + back };
|
||||
draw_trendlines(ctx, rctx, c, m, plot, band, &slot_at, ncat, horiz, base, text_col, &to_axis);
|
||||
draw_trendlines(ctx, rctx, c, m, plot, band, &slot_at, xscale, ncat, horiz, base, text_col, &to_axis);
|
||||
// Axis line.
|
||||
let mut ax = BezPath::new();
|
||||
if horiz {
|
||||
@@ -852,6 +852,7 @@ fn draw_trendlines(
|
||||
plot: Rect,
|
||||
band: f64,
|
||||
slot: &impl Fn(f64) -> f64,
|
||||
xscale: Option<(f64, f64, f64)>,
|
||||
ncat: usize,
|
||||
horiz: bool,
|
||||
base: f64,
|
||||
@@ -879,8 +880,11 @@ fn draw_trendlines(
|
||||
xs.push(x);
|
||||
ys.push(y);
|
||||
}
|
||||
// The same x extent the scatter marks use, so the fit sits on the points.
|
||||
let (sx0, sx1) = if scatter {
|
||||
// The same x extent the scatter marks use, so the fit sits on the points: the chart's
|
||||
// value x axis where it has one, else the series' own x values.
|
||||
let (sx0, sx1) = if let (true, Some((lo, hi, _))) = (scatter, xscale) {
|
||||
(lo, hi)
|
||||
} else if scatter {
|
||||
let mut lo = f64::MAX;
|
||||
let mut hi = f64::MIN;
|
||||
for v in s.x_values.iter().copied().flatten().filter(|v| v.is_finite()) {
|
||||
|
||||
Reference in New Issue
Block a user