plot: Rename Label and Axis include Plot prefix (#1597)

## Breaking changes

```diff
- Label::new()
+ PlotLabel::new()

- Axis::new()
+ PlotAxis::new()
```

This is to avoid naming conflicts with `gpui` and `gpui-component`.
This commit is contained in:
Floyd Wang 2025-11-14 11:49:07 +08:00 committed by GitHub
parent 993f9b20ae
commit 70fa330748
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 19 additions and 19 deletions

View file

@ -8,7 +8,7 @@ use crate::{
plot::{ plot::{
scale::{Scale, ScaleLinear, ScalePoint, Sealed}, scale::{Scale, ScaleLinear, ScalePoint, Sealed},
shape::Area, shape::Area,
Axis, AxisText, Grid, Plot, StrokeStyle, AXIS_GAP, AxisText, Grid, Plot, PlotAxis, StrokeStyle, AXIS_GAP,
}, },
ActiveTheme, PixelsExt, ActiveTheme, PixelsExt,
}; };
@ -142,7 +142,7 @@ where
} }
}); });
Axis::new() PlotAxis::new()
.x(height) .x(height)
.x_label(x_label) .x_label(x_label)
.stroke(cx.theme().border) .stroke(cx.theme().border)

View file

@ -9,7 +9,7 @@ use crate::{
label::Text, label::Text,
scale::{Scale, ScaleBand, ScaleLinear, Sealed}, scale::{Scale, ScaleBand, ScaleLinear, Sealed},
shape::Bar, shape::Bar,
Axis, AxisText, Grid, Plot, AXIS_GAP, PlotAxis, AxisText, Grid, Plot, AXIS_GAP,
}, },
ActiveTheme, PixelsExt, ActiveTheme, PixelsExt,
}; };
@ -125,7 +125,7 @@ where
} }
}); });
Axis::new() PlotAxis::new()
.x(height) .x(height)
.x_label(x_label) .x_label(x_label)
.stroke(cx.theme().border) .stroke(cx.theme().border)

View file

@ -8,7 +8,7 @@ use crate::{
plot::{ plot::{
scale::{Scale, ScaleLinear, ScalePoint, Sealed}, scale::{Scale, ScaleLinear, ScalePoint, Sealed},
shape::Line, shape::Line,
Axis, AxisText, Grid, Plot, StrokeStyle, AXIS_GAP, AxisText, Grid, Plot, PlotAxis, StrokeStyle, AXIS_GAP,
}, },
ActiveTheme, PixelsExt, ActiveTheme, PixelsExt,
}; };
@ -134,7 +134,7 @@ where
} }
}); });
Axis::new() PlotAxis::new()
.x(height) .x(height)
.x_label(x_label) .x_label(x_label)
.stroke(cx.theme().border) .stroke(cx.theme().border)

View file

@ -3,7 +3,7 @@ use gpui::{
Window, Window,
}; };
use super::{label::Label, label::Text, label::TEXT_GAP, label::TEXT_SIZE, origin_point}; use super::{label::PlotLabel, label::Text, label::TEXT_GAP, label::TEXT_SIZE, origin_point};
pub const AXIS_GAP: f32 = 18.; pub const AXIS_GAP: f32 = 18.;
@ -38,17 +38,17 @@ impl AxisText {
} }
#[derive(Default)] #[derive(Default)]
pub struct Axis { pub struct PlotAxis {
x: Option<Pixels>, x: Option<Pixels>,
x_label: Label, x_label: PlotLabel,
show_x_axis: bool, show_x_axis: bool,
y: Option<Pixels>, y: Option<Pixels>,
y_label: Label, y_label: PlotLabel,
show_y_axis: bool, show_y_axis: bool,
stroke: Hsla, stroke: Hsla,
} }
impl Axis { impl PlotAxis {
pub fn new() -> Self { pub fn new() -> Self {
Self { Self {
show_x_axis: true, show_x_axis: true,

View file

@ -56,7 +56,7 @@ impl Text {
} }
} }
impl<I> From<I> for Label impl<I> From<I> for PlotLabel
where where
I: Iterator<Item = Text>, I: Iterator<Item = Text>,
{ {
@ -66,9 +66,9 @@ where
} }
#[derive(Default)] #[derive(Default)]
pub struct Label(Vec<Text>); pub struct PlotLabel(Vec<Text>);
impl Label { impl PlotLabel {
pub fn new(items: Vec<Text>) -> Self { pub fn new(items: Vec<Text>) -> Self {
Self(items) Self(items)
} }

View file

@ -13,9 +13,9 @@ use gpui::{point, px, App, Bounds, IntoElement, Path, PathBuilder, Pixels, Point
use crate::PixelsExt; use crate::PixelsExt;
pub use axis::{Axis, AxisText, AXIS_GAP}; pub use axis::{AxisText, PlotAxis, AXIS_GAP};
pub use grid::Grid; pub use grid::Grid;
pub use label::Label; pub use label::PlotLabel;
pub trait Plot: IntoElement { pub trait Plot: IntoElement {
fn paint(&mut self, bounds: Bounds<Pixels>, window: &mut Window, cx: &mut App); fn paint(&mut self, bounds: Bounds<Pixels>, window: &mut Window, cx: &mut App);

View file

@ -1,7 +1,7 @@
use gpui::{fill, point, px, App, Bounds, Hsla, PaintQuad, Pixels, Point, Window}; use gpui::{fill, point, px, App, Bounds, Hsla, PaintQuad, Pixels, Point, Window};
use crate::plot::{ use crate::plot::{
label::{Label, Text, TEXT_GAP, TEXT_HEIGHT}, label::{PlotLabel, Text, TEXT_GAP, TEXT_HEIGHT},
origin_point, origin_point,
}; };
@ -93,7 +93,7 @@ impl<T> Bar<T> {
self self
} }
fn path(&self, bounds: &Bounds<Pixels>) -> (Vec<PaintQuad>, Label) { fn path(&self, bounds: &Bounds<Pixels>) -> (Vec<PaintQuad>, PlotLabel) {
let origin = bounds.origin; let origin = bounds.origin;
let mut graph = vec![]; let mut graph = vec![];
let mut labels = vec![]; let mut labels = vec![];
@ -136,7 +136,7 @@ impl<T> Bar<T> {
} }
} }
(graph, Label::new(labels)) (graph, PlotLabel::new(labels))
} }
/// Paint the Bar. /// Paint the Bar.