Skip to main content

ferrochart_core/
frame.rs

1//! `Frame`: the platform-independent draw description that the core produces and
2//! the backends consume.
3//!
4//! The frame uses **flat pools**: every primitive instance lives in one `Vec` per
5//! type at frame level, and a [`DrawCmd`] only refers to a [`Span`] of a pool.
6//! Pools are cleared (keeping their capacity) at the start of each frame, so after
7//! a few frames building a frame no longer allocates. `DrawCmd` and everything it
8//! contains is `Copy`.
9
10use crate::data::IdxSpan;
11use crate::geom::{PointPx, Px, RectPx, Rgba, SizePx, Span};
12
13/// How much of the chart needs to be redrawn. Ordered from least to most work.
14///
15///
16/// # Examples
17///
18/// ```
19/// use ferrochart_core::frame::Invalidation;
20///
21/// assert!(Invalidation::Full > Invalidation::Light);
22/// assert_eq!(Invalidation::Cursor.max(Invalidation::Data), Invalidation::Data);
23/// ```
24#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
25pub enum Invalidation {
26    /// Nothing to redraw.
27    #[default]
28    None,
29    /// Only the crosshair / hover state changed: redraw the overlay layer.
30    Cursor,
31    /// The viewport changed (pan/zoom): uniforms, ticks and text.
32    Light,
33    /// Data changed: incremental upload plus `Light`.
34    Data,
35    /// Layout, theme or the set of series changed: rebuild everything.
36    Full,
37}
38
39/// Identifier of a font known to the [`TextMeasurer`](crate::text::TextMeasurer).
40/// `FontId(0)` is the built-in default font.
41#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
42pub struct FontId(pub u16);
43
44/// Font and size of a text run.
45///
46/// # Examples
47///
48/// ```
49/// use ferrochart_core::frame::{FontId, FontStyleRef};
50///
51/// let style = FontStyleRef { font: FontId(0), size: 12.0 };
52/// assert_eq!(style.size, 12.0);
53/// ```
54#[derive(Clone, Copy, Debug, Default, PartialEq)]
55pub struct FontStyleRef {
56    /// Font.
57    pub font: FontId,
58    /// Font size (em size) in physical pixels.
59    pub size: f32,
60}
61
62/// Horizontal alignment of a text run relative to its position.
63#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
64pub enum TextAlign {
65    /// `pos.x` is the left edge.
66    #[default]
67    Left,
68    /// `pos.x` is the center.
69    Center,
70    /// `pos.x` is the right edge.
71    Right,
72}
73
74/// Background box behind a label.
75#[derive(Clone, Copy, Debug, PartialEq)]
76pub struct LabelBg {
77    /// Fill color.
78    pub color: Rgba,
79    /// Padding around the text box.
80    pub padding: Px,
81}
82
83/// One line of text. The characters are `FramePools::text[text.range()]`.
84///
85/// `pos.y` is the vertical center of the line box (ascent to descent).
86#[derive(Clone, Copy, Debug, PartialEq)]
87pub struct TextRun {
88    /// Anchor point; see [`TextAlign`].
89    pub pos: PointPx,
90    /// Byte span in `FramePools::text`.
91    pub text: Span,
92    /// Font and size.
93    pub style: FontStyleRef,
94    /// Text color.
95    pub color: Rgba,
96    /// Horizontal alignment.
97    pub align: TextAlign,
98    /// Optional background box.
99    pub bg: Option<LabelBg>,
100}
101
102/// A filled rectangle.
103#[derive(Clone, Copy, Debug, PartialEq)]
104pub struct RectInst {
105    /// Rectangle.
106    pub rect: RectPx,
107    /// Fill color.
108    pub color: Rgba,
109}
110
111/// Dash pattern of a line.
112#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
113#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
114pub enum LineDash {
115    /// Solid.
116    #[default]
117    Solid,
118    /// Dashes.
119    Dashed,
120    /// Dots.
121    Dotted,
122}
123
124/// Stroke parameters of a line or polyline.
125#[derive(Clone, Copy, Debug, PartialEq)]
126pub struct StrokeStyle {
127    /// Line width.
128    pub width: Px,
129    /// Color.
130    pub color: Rgba,
131    /// Dash pattern.
132    pub dash: LineDash,
133}
134
135/// A straight line segment. Axis-aligned 1-px lines are placed on pixel centers
136/// (`floor(x) + 0.5`).
137#[derive(Clone, Copy, Debug, PartialEq)]
138pub struct LineInst {
139    /// Start point.
140    pub from: PointPx,
141    /// End point.
142    pub to: PointPx,
143    /// Stroke.
144    pub stroke: StrokeStyle,
145}
146
147/// A marker icon from the built-in set: the `ICON_*` constants
148/// of [`crate::transform_helpers`], drawn with
149/// [`crate::transform_helpers::icon_coverage`].
150#[derive(Clone, Copy, Debug, PartialEq)]
151pub struct IconInst {
152    /// Center.
153    pub pos: PointPx,
154    /// Width and height.
155    pub size: Px,
156    /// Icon number (`transform_helpers::ICON_*`).
157    pub icon: u16,
158    /// Tint color.
159    pub color: Rgba,
160}
161
162/// Built-in series kinds.
163///
164#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
165pub enum SeriesKind {
166    /// Candles: body + wick, up/down colors.
167    Candlestick,
168    /// OHLC bars.
169    OhlcBar,
170    /// Heikin-Ashi candles.
171    HeikinAshi,
172    /// Line.
173    Line,
174    /// Line with gradient fill to the baseline.
175    Area,
176    /// Two-colored fill above/below a baseline.
177    Baseline,
178    /// Histogram.
179    Histogram,
180    /// One dot per point, `line_width` across (e.g. Parabolic SAR).
181    Points,
182    /// Fill between two single-value series: `SeriesDraw::series` is
183    /// the upper one, `SeriesDraw::pair` the lower one; `fill_top` where
184    /// upper ≥ lower, `fill_bottom` where it is below. Created with
185    /// [`Chart::add_band`](crate::Chart::add_band), never with `add_series`.
186    Band,
187    /// Volume histogram of an OHLC series, colored by up/down.
188    Volume,
189    /// A plugin series; never in a [`SeriesDraw`].
190    Custom,
191    /// Kagi lines of a transform series, drawn by core as
192    /// primitives; never in a [`SeriesDraw`].
193    Kagi,
194    /// Point & Figure columns of a transform series, drawn by core
195    /// as primitives; never in a [`SeriesDraw`].
196    PointFigure,
197}
198
199/// Index into [`Frame::styles`].
200#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
201pub struct SeriesStyleRef(pub u32);
202
203/// Fully resolved colors of a series draw. The backend never decides colors; it
204/// only picks `up` or `down` per bar using the rule in `transform_helpers`.
205///
206/// Value series use the fields as follows: `Line`/`Area`: `up` is the line
207/// color; `Area` fills from `fill_top` at the top of the clip to `fill_bottom`
208/// at its bottom. `Baseline`: `up`/`fill_top` above `base_value`,
209/// `down`/`fill_bottom` below it. `Histogram`: `up` is the bar color (unless
210/// the point has its own color), bars stand on `base_value`.
211#[derive(Clone, Copy, Debug, Default, PartialEq)]
212pub struct SeriesStyle {
213    /// Body / bar color of up bars (`close >= open`).
214    pub up: Rgba,
215    /// Body / bar color of down bars.
216    pub down: Rgba,
217    /// Wick color of up bars.
218    pub up_wick: Rgba,
219    /// Wick color of down bars.
220    pub down_wick: Rgba,
221    /// Border color of up bodies.
222    pub up_border: Rgba,
223    /// Border color of down bodies.
224    pub down_border: Rgba,
225    /// Line width of line-like series.
226    pub line_width: Px,
227    /// Dash pattern of line-like series.
228    pub line_dash: LineDash,
229    /// Step line (horizontal, then vertical) instead of straight segments.
230    pub step: bool,
231    /// Upper fill color (see above).
232    pub fill_top: Rgba,
233    /// Lower fill color (see above).
234    pub fill_bottom: Rgba,
235    /// Base value of `Baseline` and `Histogram`, in price space.
236    pub base_value: f64,
237}
238
239/// Index-to-x mapping of a [`SeriesDraw`]: `x = (j - base) * step + offset`, where
240/// `j` is a logical index (level 0) or a bucket number (LOD level), and `x` is the
241/// center of element `j`. `j - base` is a small integer, so the f32 math is exact
242/// enough.
243#[derive(Clone, Copy, Debug, Default, PartialEq)]
244pub struct XTransform {
245    /// Index of the element at `offset`.
246    pub base: i64,
247    /// Distance between element centers in physical pixels.
248    pub step: f32,
249    /// x of the center of element `base`.
250    pub offset: f32,
251}
252
253/// Value mapping of a price scale.
254#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
255pub enum PriceMapping {
256    /// `f(p) = p`.
257    #[default]
258    Linear,
259    /// `f(p) = ln p`.
260    Log,
261}
262
263/// Value-to-y mapping of a [`SeriesDraw`]: `y = a * (f(value) - f(view_ref)) + b`.
264/// Renderers evaluate it per chunk in f32 as `(v_rel + bias) * a` with
265/// `v_rel = f(value) - f(chunk_ref)`; use
266/// `transform_helpers` instead of evaluating it by hand.
267#[derive(Clone, Copy, Debug, Default, PartialEq)]
268pub struct YTransform {
269    /// Scale.
270    pub a: f32,
271    /// y of `view_ref`.
272    pub b: f32,
273    /// Reference value (in price space) the transform is relative to.
274    pub view_ref: f64,
275    /// Linear or logarithmic.
276    pub mapping: PriceMapping,
277}
278
279/// A data-bound series draw: the backend reads the series data (of the given LOD
280/// level) and transforms it itself.
281#[derive(Clone, Copy, Debug, PartialEq)]
282pub struct SeriesDraw {
283    /// The series whose data is drawn (for `Volume`, the OHLC source series).
284    pub series: crate::data::SeriesId,
285    /// Data generation this draw was built for.
286    pub generation: u64,
287    /// Resolved colors.
288    pub style: SeriesStyleRef,
289    /// What to draw.
290    pub kind: SeriesKind,
291    /// LOD level (0 = original data).
292    pub lod_level: u8,
293    /// Elements to draw (logical indices or bucket numbers), one extra on each side.
294    pub index_range: IdxSpan,
295    /// Horizontal mapping.
296    pub x_transform: XTransform,
297    /// Vertical mapping.
298    pub y_transform: YTransform,
299    /// Clip rectangle.
300    pub clip: RectPx,
301    /// `Band`: the lower series (`series` is the upper one); otherwise `None`.
302    pub pair: Option<crate::data::SeriesId>,
303}
304
305/// Native drawing of a custom series: emitted instead of the plugin's
306/// primitives when the renderer declared its kind
307/// ([`crate::render::Renderer::native_kinds`]).
308///
309/// Point `i` of the series is at x `(idx(i) - base) * step + offset`, where
310/// `idx(i)` is its fractional logical index
311/// ([`crate::chart::ChartDataView::custom_index`]) and the terms are those of
312/// `x_transform`; prices map through `y_transform` like a [`SeriesDraw`].
313#[derive(Clone, Copy, Debug, PartialEq)]
314pub struct CustomDraw {
315    /// The series.
316    pub series: crate::data::SeriesId,
317    /// Data generation of the series' change log (in point numbers).
318    pub generation: u64,
319    /// `CustomSeries::kind`.
320    pub kind: &'static str,
321    /// The points to draw (the series' own point numbers): the visible ones
322    /// and one more on each side.
323    pub points: IdxSpan,
324    /// Logical index to x (`SeriesOptions::shift` included).
325    pub x_transform: XTransform,
326    /// Price to y.
327    pub y_transform: YTransform,
328    /// Resolved colors and line settings.
329    pub style: SeriesStyleRef,
330    /// Written by `CustomSeries::native_params` (e.g. a color-scale range).
331    pub params: [f32; 8],
332    /// Clip rectangle (the pane's plot).
333    pub clip: RectPx,
334}
335
336/// One draw command. All variants are `Copy` and hold no heap data.
337#[derive(Clone, Copy, Debug, PartialEq)]
338pub enum DrawCmd {
339    /// Intersects the clip with a rectangle until the matching `PopClip`.
340    PushClip(RectPx),
341    /// Restores the previous clip.
342    PopClip,
343    /// Data-bound series.
344    Series(SeriesDraw),
345    /// Filled rectangles: `FramePools::rects[span]`.
346    Rects(Span),
347    /// Line segments: `FramePools::lines[span]`.
348    Lines(Span),
349    /// A polyline through `FramePools::points[points]`.
350    Polyline {
351        /// Vertices.
352        points: Span,
353        /// Stroke.
354        style: StrokeStyle,
355    },
356    /// A filled polygon with vertices `FramePools::points[points]`.
357    Polygon {
358        /// Vertices.
359        points: Span,
360        /// Fill color.
361        fill: Rgba,
362    },
363    /// Text runs: `FramePools::text_runs[span]`.
364    Text(Span),
365    /// Icons: `FramePools::icons[span]`.
366    Icon(Span),
367    /// Native drawing of a custom series; only for kinds the renderer
368    /// declared.
369    Custom(CustomDraw),
370}
371
372/// Primitive pools of a frame.
373#[derive(Clone, Debug, Default)]
374pub struct FramePools {
375    /// Rectangles.
376    pub rects: Vec<RectInst>,
377    /// Lines.
378    pub lines: Vec<LineInst>,
379    /// Polyline / polygon vertices.
380    pub points: Vec<PointPx>,
381    /// Text runs.
382    pub text_runs: Vec<TextRun>,
383    /// Characters of all text runs, concatenated.
384    pub text: String,
385    /// Icons.
386    pub icons: Vec<IconInst>,
387}
388
389impl FramePools {
390    fn clear(&mut self) {
391        self.rects.clear();
392        self.lines.clear();
393        self.points.clear();
394        self.text_runs.clear();
395        self.text.clear();
396        self.icons.clear();
397    }
398
399    /// The characters of `run`, or `""` if its span is out of range.
400    ///
401    /// # Examples
402    ///
403    /// ```
404    /// use ferrochart_core::frame::{FramePools, TextRun};
405    /// use ferrochart_core::geom::Span;
406    ///
407    /// let mut pools = FramePools::default();
408    /// pools.text.push_str("12.50");
409    /// assert_eq!(pools.text_of(Span { start: 0, len: 2 }), "12");
410    /// ```
411    pub fn text_of(&self, span: Span) -> &str {
412        self.text.get(span.range()).unwrap_or("")
413    }
414}
415
416/// A layer of the frame.
417#[derive(Clone, Debug, Default)]
418pub struct Layer {
419    /// Content version; increases whenever the layer's content changes. Backends
420    /// that cache a layer compare it with the revision they cached.
421    pub revision: u64,
422    /// Commands, in painting order.
423    pub cmds: Vec<DrawCmd>,
424}
425
426/// Layer indices into [`Frame::layers`].
427#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
428pub enum LayerId {
429    /// Grid, watermark.
430    Background = 0,
431    /// Series, drawings, axes.
432    Main = 1,
433    /// Crosshair, hover, drawings being dragged.
434    Overlay = 2,
435}
436
437/// The draw description of one frame.
438///
439/// # Examples
440///
441/// ```
442/// use ferrochart_core::frame::{DrawCmd, Frame, LayerId, RectInst};
443/// use ferrochart_core::geom::{RectPx, Rgba};
444///
445/// let mut frame = Frame::default();
446/// let r = RectInst { rect: RectPx { x: 0.0, y: 0.0, w: 2.0, h: 2.0 }, color: Rgba::hex(0) };
447/// frame.push_rect(LayerId::Main, r);
448/// frame.push_rect(LayerId::Main, r); // merged into the same command
449/// assert_eq!(frame.layers[1].cmds.len(), 1);
450/// assert!(matches!(frame.layers[1].cmds[0], DrawCmd::Rects(s) if s.len == 2));
451/// ```
452#[derive(Clone, Debug, Default)]
453pub struct Frame {
454    /// Size of the target in physical pixels.
455    pub size_px: SizePx,
456    /// Background color the target is cleared to.
457    pub clear_color: Rgba,
458    /// Background, main and overlay layers.
459    pub layers: [Layer; 3],
460    /// What changed since the previous frame.
461    pub invalidation: Invalidation,
462    /// Primitive pools.
463    pub pools: FramePools,
464    /// Resolved series styles, referenced by [`SeriesStyleRef`].
465    pub styles: Vec<SeriesStyle>,
466}
467
468fn span_of(start: usize, len: usize) -> Span {
469    Span {
470        start: u32::try_from(start).unwrap_or(u32::MAX),
471        len: u32::try_from(len).unwrap_or(0),
472    }
473}
474
475impl Frame {
476    /// Starts a new frame: clears all pools and commands, keeping their
477    /// capacity, and sets the target size, clear color and invalidation.
478    ///
479    /// ```
480    /// use ferrochart_core::frame::{Frame, LayerId, RectInst};
481    /// use ferrochart_core::geom::{RectPx, Rgba, SizePx};
482    /// use ferrochart_core::frame::Invalidation;
483    ///
484    /// let mut frame = Frame::default();
485    /// frame.reserve();
486    /// let r = RectInst { rect: RectPx { x: 0.0, y: 0.0, w: 2.0, h: 2.0 }, color: Rgba::hex(0) };
487    /// frame.push_rect(LayerId::Main, r);
488    /// frame.begin(SizePx { w: 100.0, h: 50.0 }, Rgba::hex(0xFF), Invalidation::Full);
489    /// assert!(frame.pools.rects.is_empty() && frame.layers[1].cmds.is_empty());
490    /// ```
491    pub fn begin(&mut self, size: SizePx, clear: Rgba, invalidation: Invalidation) {
492        self.size_px = size;
493        self.clear_color = clear;
494        self.invalidation = invalidation;
495        self.pools.clear();
496        self.styles.clear();
497        for layer in &mut self.layers {
498            layer.cmds.clear();
499        }
500    }
501
502    /// Pre-allocates pools so that typical frames do not allocate.
503    pub fn reserve(&mut self) {
504        let _ = self.pools.rects.try_reserve(256);
505        let _ = self.pools.lines.try_reserve(512);
506        let _ = self.pools.text_runs.try_reserve(512);
507        let _ = self.pools.text.try_reserve(8192);
508        let _ = self.pools.icons.try_reserve(256);
509        let _ = self.styles.try_reserve(16);
510        for layer in &mut self.layers {
511            let _ = layer.cmds.try_reserve(64);
512        }
513    }
514
515    /// Appends a command to a layer.
516    pub fn push_cmd(&mut self, layer: LayerId, cmd: DrawCmd) {
517        self.layers[layer as usize].cmds.push(cmd);
518    }
519
520    /// Adds a resolved style and returns its reference.
521    pub fn push_style(&mut self, style: SeriesStyle) -> SeriesStyleRef {
522        self.styles.push(style);
523        SeriesStyleRef(u32::try_from(self.styles.len() - 1).unwrap_or(u32::MAX))
524    }
525
526    /// Adds a rectangle, extending the layer's last `Rects` command if it ends at
527    /// the end of the pool.
528    pub fn push_rect(&mut self, layer: LayerId, rect: RectInst) {
529        let start = self.pools.rects.len();
530        self.pools.rects.push(rect);
531        let cmds = &mut self.layers[layer as usize].cmds;
532        if let Some(DrawCmd::Rects(s)) = cmds.last_mut()
533            && s.range().end == start
534        {
535            s.len += 1;
536            return;
537        }
538        cmds.push(DrawCmd::Rects(span_of(start, 1)));
539    }
540
541    /// Adds a line, merging with the layer's last `Lines` command when possible.
542    pub fn push_line(&mut self, layer: LayerId, line: LineInst) {
543        let start = self.pools.lines.len();
544        self.pools.lines.push(line);
545        let cmds = &mut self.layers[layer as usize].cmds;
546        if let Some(DrawCmd::Lines(s)) = cmds.last_mut()
547            && s.range().end == start
548        {
549            s.len += 1;
550            return;
551        }
552        cmds.push(DrawCmd::Lines(span_of(start, 1)));
553    }
554
555    /// Adds a text run whose characters are `pools.text[text]` (already written),
556    /// merging with the layer's last `Text` command when possible.
557    pub fn push_text(&mut self, layer: LayerId, run: TextRun) {
558        let start = self.pools.text_runs.len();
559        self.pools.text_runs.push(run);
560        let cmds = &mut self.layers[layer as usize].cmds;
561        if let Some(DrawCmd::Text(s)) = cmds.last_mut()
562            && s.range().end == start
563        {
564            s.len += 1;
565            return;
566        }
567        cmds.push(DrawCmd::Text(span_of(start, 1)));
568    }
569
570    /// Adds an icon, merging with the layer's last `Icon` command when possible.
571    pub fn push_icon(&mut self, layer: LayerId, icon: IconInst) {
572        let start = self.pools.icons.len();
573        self.pools.icons.push(icon);
574        let cmds = &mut self.layers[layer as usize].cmds;
575        if let Some(DrawCmd::Icon(s)) = cmds.last_mut()
576            && s.range().end == start
577        {
578            s.len += 1;
579            return;
580        }
581        cmds.push(DrawCmd::Icon(span_of(start, 1)));
582    }
583
584    /// Writes `s` into the text pool and returns its span.
585    ///
586    /// # Examples
587    ///
588    /// ```
589    /// use ferrochart_core::frame::Frame;
590    ///
591    /// let mut frame = Frame::default();
592    /// let span = frame.push_str("2025");
593    /// assert_eq!(frame.pools.text_of(span), "2025");
594    /// ```
595    pub fn push_str(&mut self, s: &str) -> Span {
596        let start = self.pools.text.len();
597        self.pools.text.push_str(s);
598        span_of(start, s.len())
599    }
600}
601
602/// Gradual display of the data: the data layer is clipped to the
603/// left `progress` of the plot area while grid and axes stay whole. Used by
604/// [`Chart::set_reveal`](crate::chart::Chart::set_reveal) and by the plot
605/// crate; the host moves `progress` over time.
606///
607/// ```
608/// use ferrochart_core::frame::Reveal;
609/// use ferrochart_core::geom::RectPx;
610///
611/// let r = Reveal { progress: 0.25, pen: None };
612/// let plot = RectPx { x: 10.0, y: 0.0, w: 200.0, h: 100.0 };
613/// assert_eq!(r.clip(plot), RectPx { x: 10.0, y: 0.0, w: 50.0, h: 100.0 });
614/// assert!(!r.is_done());
615/// ```
616#[derive(Clone, Copy, Debug, PartialEq)]
617pub struct Reveal {
618    /// Share of the plot width shown, from the left: 0..=1 (NaN counts as 0).
619    pub progress: f32,
620    /// Color of the line at the cut-off, if any.
621    pub pen: Option<Rgba>,
622}
623
624impl Reveal {
625    /// `progress` clamped to 0..=1, NaN as 0.
626    pub fn amount(self) -> f32 {
627        if self.progress.is_nan() {
628            0.0
629        } else {
630            self.progress.clamp(0.0, 1.0)
631        }
632    }
633
634    /// Whether everything is shown (progress 1): drawn as without a reveal.
635    pub fn is_done(self) -> bool {
636        self.amount() >= 1.0
637    }
638
639    /// The part of `plot` the data is drawn in.
640    pub fn clip(self, plot: RectPx) -> RectPx {
641        RectPx {
642            w: (plot.w * self.amount()).round(),
643            ..plot
644        }
645    }
646
647    /// The pen line at the cut-off of `plot` (with two wider, fainter lines
648    /// as a glow), clipped to `plot`, on `layer`; nothing when there is no
649    /// pen or progress is 0 or 1.
650    pub fn push_pen(self, frame: &mut Frame, layer: LayerId, plot: RectPx, dpr: f32) {
651        let Some(color) = self.pen else {
652            return;
653        };
654        let a = self.amount();
655        if a <= 0.0 || a >= 1.0 || plot.w <= 0.0 || plot.h <= 0.0 {
656            return;
657        }
658        let x = plot.x + self.clip(plot).w;
659        frame.push_cmd(layer, DrawCmd::PushClip(plot));
660        for (width, alpha) in [(14.0, 0.10), (5.0, 0.28), (1.5, 1.0)] {
661            let alpha = (f32::from(color.a) * alpha).round() as u8;
662            frame.push_line(
663                layer,
664                LineInst {
665                    from: PointPx { x, y: plot.y },
666                    to: PointPx {
667                        x,
668                        y: plot.bottom(),
669                    },
670                    stroke: StrokeStyle {
671                        width: Px((width * dpr).max(1.0)),
672                        color: color.with_alpha(alpha),
673                        dash: LineDash::Solid,
674                    },
675                },
676            );
677        }
678        frame.push_cmd(layer, DrawCmd::PopClip);
679    }
680}