mod axis; mod grid; pub mod label; pub mod scale; pub mod shape; pub mod tooltip; pub use gpui_component_macros::IntoPlot; use std::{fmt::Debug, ops::Add}; use gpui::{point, px, App, Bounds, IntoElement, Path, PathBuilder, Pixels, Point, Window}; use crate::PixelsExt; pub use axis::{Axis, AxisText, AXIS_GAP}; pub use grid::Grid; pub use label::Label; pub trait Plot: IntoElement { fn paint(&mut self, bounds: Bounds, window: &mut Window, cx: &mut App); } #[derive(Clone, Copy, Default)] pub enum StrokeStyle { #[default] Natural, Linear, StepAfter, } pub fn origin_point(x: T, y: T, origin: Point) -> Point where T: Default + Clone + Debug + PartialEq + Add, { point(x, y) + origin } pub fn polygon(points: &[Point], bounds: &Bounds) -> Option> where T: Default + Clone + Copy + Debug + Into + PartialEq, { let mut path = PathBuilder::stroke(px(1.)); let points = &points .iter() .map(|p| { point( px(p.x.into() + bounds.origin.x.as_f32()), px(p.y.into() + bounds.origin.y.as_f32()), ) }) .collect::>(); path.add_polygon(points, false); path.build().ok() }