plot: Add StepAfter kind to StokeStrike (#1356)
Implements new `StokeStrike::StepAfter` for plot component <img width="1700" height="1030" alt="step-after-plot-stoke-style" src="https://github.com/user-attachments/assets/89252ba9-2834-4c9a-9020-7977ffea6865" />
This commit is contained in:
parent
20ddb88e95
commit
32b8d65075
6 changed files with 46 additions and 0 deletions
|
|
@ -246,6 +246,15 @@ impl Render for ChartStory {
|
||||||
false,
|
false,
|
||||||
cx,
|
cx,
|
||||||
))
|
))
|
||||||
|
.child(chart_container(
|
||||||
|
"Line Chart - Step After",
|
||||||
|
LineChart::new(self.monthly_devices.clone())
|
||||||
|
.x(|d| d.month.clone())
|
||||||
|
.y(|d| d.desktop)
|
||||||
|
.step_after(),
|
||||||
|
false,
|
||||||
|
cx,
|
||||||
|
))
|
||||||
.child(chart_container(
|
.child(chart_container(
|
||||||
"Line Chart - Dots",
|
"Line Chart - Dots",
|
||||||
LineChart::new(self.monthly_devices.clone())
|
LineChart::new(self.monthly_devices.clone())
|
||||||
|
|
@ -278,6 +287,15 @@ impl Render for ChartStory {
|
||||||
false,
|
false,
|
||||||
cx,
|
cx,
|
||||||
))
|
))
|
||||||
|
.child(chart_container(
|
||||||
|
"Area Chart - Step After",
|
||||||
|
AreaChart::new(self.monthly_devices.clone())
|
||||||
|
.x(|d| d.month.clone())
|
||||||
|
.y(|d| d.desktop)
|
||||||
|
.step_after(),
|
||||||
|
false,
|
||||||
|
cx,
|
||||||
|
))
|
||||||
.child(chart_container(
|
.child(chart_container(
|
||||||
"Area Chart - Linear Gradient",
|
"Area Chart - Linear Gradient",
|
||||||
AreaChart::new(self.monthly_devices.clone())
|
AreaChart::new(self.monthly_devices.clone())
|
||||||
|
|
|
||||||
|
|
@ -74,6 +74,11 @@ where
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn step_after(mut self) -> Self {
|
||||||
|
self.stroke_style = StrokeStyle::StepAfter;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub fn tick_margin(mut self, tick_margin: usize) -> Self {
|
pub fn tick_margin(mut self, tick_margin: usize) -> Self {
|
||||||
self.tick_margin = tick_margin;
|
self.tick_margin = tick_margin;
|
||||||
self
|
self
|
||||||
|
|
|
||||||
|
|
@ -64,6 +64,11 @@ where
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn step_after(mut self) -> Self {
|
||||||
|
self.stroke_style = StrokeStyle::StepAfter;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub fn dot(mut self) -> Self {
|
pub fn dot(mut self) -> Self {
|
||||||
self.dot = true;
|
self.dot = true;
|
||||||
self
|
self
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ pub enum StrokeStyle {
|
||||||
#[default]
|
#[default]
|
||||||
Natural,
|
Natural,
|
||||||
Linear,
|
Linear,
|
||||||
|
StepAfter,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn origin_point<T>(x: T, y: T, origin: Point<T>) -> Point<T>
|
pub fn origin_point<T>(x: T, y: T, origin: Point<T>) -> Point<T>
|
||||||
|
|
|
||||||
|
|
@ -144,6 +144,16 @@ impl<T> Area<T> {
|
||||||
line_builder.line_to(*p);
|
line_builder.line_to(*p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
StrokeStyle::StepAfter => {
|
||||||
|
area_builder.move_to(points[0]);
|
||||||
|
line_builder.move_to(points[0]);
|
||||||
|
for p in points.windows(2) {
|
||||||
|
area_builder.line_to(Point::new(p[1].x, p[0].y));
|
||||||
|
area_builder.line_to(Point::new(p[1].x, p[1].y));
|
||||||
|
line_builder.line_to(Point::new(p[1].x, p[0].y));
|
||||||
|
line_builder.line_to(Point::new(p[1].x, p[1].y));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close path
|
// Close path
|
||||||
|
|
|
||||||
|
|
@ -182,6 +182,13 @@ impl<T> Line<T> {
|
||||||
builder.line_to(*p);
|
builder.line_to(*p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
StrokeStyle::StepAfter => {
|
||||||
|
builder.move_to(dots[0]);
|
||||||
|
for d in dots.windows(2) {
|
||||||
|
builder.line_to(Point::new(d[1].x, d[0].y));
|
||||||
|
builder.line_to(Point::new(d[1].x, d[1].y));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
(builder.build().ok(), paint_dots)
|
(builder.build().ok(), paint_dots)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue