Skip to content

Commit fd88b36

Browse files
committed
Merge branch 'next'
# Conflicts: # Cargo.toml # src/graphics.rs # src/native/mod.rs # src/native/widget.rs # src/pure/renderer.rs # src/renderer.rs
2 parents 2f5af6f + 47b3700 commit fd88b36

40 files changed

+608
-4329
lines changed

Cargo.toml

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "plotters-iced"
3-
version = "0.3.3"
3+
version = "0.4.0"
44
description = "Iced backend for Plotters"
55
readme = "README.md"
66
license = "MIT"
@@ -19,16 +19,8 @@ members = [".", "examples/split-chart"]
1919
[dependencies]
2020
plotters = { version = "0.3", default_features = false }
2121
plotters-backend = "0.3"
22-
iced_native = "0.5"
23-
iced_graphics = { version = "0.3", features = ["canvas", "pure"] }
24-
iced_pure = { version = "0.2", optional = true }
25-
26-
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
27-
num-traits = "0.2"
28-
libc = "0.2"
29-
30-
[build-dependencies]
31-
cc = "1.0"
22+
iced_native = "0.6"
23+
iced_graphics = { version = "0.4", features = ["canvas"] }
3224

3325
[dev-dependencies]
3426
plotters = { version = "0.3", default_features = false, features = [
@@ -37,18 +29,10 @@ plotters = { version = "0.3", default_features = false, features = [
3729
"line_series",
3830
"point_series",
3931
] }
40-
iced = { version = "0.4.2", features = ["canvas", "tokio", "pure"] }
32+
iced = { version = "0.5", features = ["canvas", "tokio"] }
4133
chrono = { version = "0.4", default-features = false }
4234
rand = "0.8"
35+
tokio = { version = "1", features = ["rt"], default-features = false }
4336

4437
[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
4538
sysinfo = { version = "0.26", default_features = false }
46-
47-
[features]
48-
default = ["native"]
49-
pure = ["iced_pure", "iced/pure"]
50-
native = []
51-
52-
[[example]]
53-
name = "pure_example"
54-
required-features = ["pure"]

build.rs

Lines changed: 0 additions & 21 deletions
This file was deleted.

examples/cpu-monitor.rs

Lines changed: 24 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,20 @@
33
// Iced backend for Plotters
44
// Copyright: 2022, Joylei <[email protected]>
55
// License: MIT
6+
67
extern crate iced;
78
extern crate plotters;
89
extern crate sysinfo;
910

1011
use chrono::{DateTime, Utc};
1112
use iced::{
1213
alignment::{Horizontal, Vertical},
13-
canvas::{Cache, Frame, Geometry},
14-
executor, scrollable, Alignment, Application, Column, Command, Container, Element, Font,
15-
Length, Row, Scrollable, Settings, Size, Space, Subscription,
14+
executor,
15+
widget::{
16+
canvas::{Cache, Frame, Geometry},
17+
Column, Container, Row, Scrollable, Space, Text,
18+
},
19+
Alignment, Application, Command, Element, Font, Length, Settings, Size, Subscription, Theme,
1620
};
1721
use plotters::prelude::ChartBuilder;
1822
use plotters_backend::DrawingBackend;
@@ -58,6 +62,7 @@ impl Application for State {
5862
type Message = self::Message;
5963
type Executor = executor::Default;
6064
type Flags = ();
65+
type Theme = Theme;
6166

6267
fn new(_flags: Self::Flags) -> (Self, Command<Self::Message>) {
6368
(
@@ -81,14 +86,14 @@ impl Application for State {
8186
Command::none()
8287
}
8388

84-
fn view(&mut self) -> Element<'_, Self::Message> {
89+
fn view(&self) -> Element<'_, Self::Message> {
8590
let content = Column::new()
8691
.spacing(20)
8792
.align_items(Alignment::Start)
8893
.width(Length::Fill)
8994
.height(Length::Fill)
9095
.push(
91-
iced::Text::new("Iced test chart")
96+
Text::new("Iced test chart")
9297
.size(TITLE_FONT_SIZE)
9398
.font(FONT_BOLD),
9499
)
@@ -115,7 +120,6 @@ struct SystemChart {
115120
last_sample_time: Instant,
116121
items_per_row: usize,
117122
processors: Vec<CpuUsageChart>,
118-
scroll: scrollable::State,
119123
chart_height: u16,
120124
}
121125

@@ -128,7 +132,6 @@ impl Default for SystemChart {
128132
last_sample_time: Instant::now(),
129133
items_per_row: 3,
130134
processors: Default::default(),
131-
scroll: Default::default(),
132135
chart_height: 300,
133136
}
134137
}
@@ -171,20 +174,18 @@ impl SystemChart {
171174
}
172175
}
173176

174-
fn view(&mut self) -> Element<Message> {
177+
fn view(&self) -> Element<Message> {
175178
if !self.is_initialized() {
176-
iced::Text::new("Loading...")
179+
Text::new("Loading...")
177180
.horizontal_alignment(Horizontal::Center)
178181
.vertical_alignment(Vertical::Center)
179182
.into()
180183
} else {
181-
let mut scroll = Scrollable::new(&mut self.scroll)
182-
.width(Length::Fill)
183-
.height(Length::Fill);
184+
let mut col = Column::new().width(Length::Fill).height(Length::Fill);
184185

185186
let chart_height = self.chart_height;
186187
let mut idx = 0;
187-
for chunk in self.processors.chunks_mut(self.items_per_row) {
188+
for chunk in self.processors.chunks(self.items_per_row) {
188189
let mut row = Row::new()
189190
.spacing(15)
190191
.padding(20)
@@ -199,10 +200,10 @@ impl SystemChart {
199200
row = row.push(Space::new(Length::Fill, Length::Fill));
200201
idx += 1;
201202
}
202-
scroll = scroll.push(row);
203+
col = col.push(row);
203204
}
204205

205-
scroll.into()
206+
Scrollable::new(col).height(Length::Fill).into()
206207
}
207208
}
208209
}
@@ -239,13 +240,13 @@ impl CpuUsageChart {
239240
self.cache.clear();
240241
}
241242

242-
fn view(&mut self, idx: usize) -> Element<Message> {
243+
fn view(&self, idx: usize) -> Element<Message> {
243244
Container::new(
244245
Column::new()
245246
.width(Length::Fill)
246247
.height(Length::Fill)
247248
.spacing(5)
248-
.push(iced::Text::new(format!("Processor {}", idx)))
249+
.push(Text::new(format!("Processor {}", idx)))
249250
.push(
250251
ChartWidget::new(self).height(Length::Fill).resolve_font(
251252
|_, style| match style {
@@ -255,7 +256,6 @@ impl CpuUsageChart {
255256
),
256257
),
257258
)
258-
.style(style::ChartContainer)
259259
.width(Length::Fill)
260260
.height(Length::Fill)
261261
.align_x(Horizontal::Center)
@@ -265,6 +265,7 @@ impl CpuUsageChart {
265265
}
266266

267267
impl Chart<Message> for CpuUsageChart {
268+
type State = ();
268269
// fn update(
269270
// &mut self,
270271
// event: Event,
@@ -280,7 +281,7 @@ impl Chart<Message> for CpuUsageChart {
280281
self.cache.draw(bounds, draw_fn)
281282
}
282283

283-
fn build_chart<DB: DrawingBackend>(&self, mut chart: ChartBuilder<DB>) {
284+
fn build_chart<DB: DrawingBackend>(&self, _state: &Self::State, mut chart: ChartBuilder<DB>) {
284285
use plotters::{prelude::*, style::Color};
285286

286287
const PLOT_LINE_COLOR: RGBColor = RGBColor(0, 175, 255);
@@ -307,14 +308,14 @@ impl Chart<Message> for CpuUsageChart {
307308

308309
chart
309310
.configure_mesh()
310-
.bold_line_style(&plotters::style::colors::WHITE.mix(0.1))
311-
.light_line_style(&plotters::style::colors::WHITE.mix(0.05))
312-
.axis_style(ShapeStyle::from(&plotters::style::colors::WHITE.mix(0.45)).stroke_width(1))
311+
.bold_line_style(&plotters::style::colors::BLUE.mix(0.1))
312+
.light_line_style(&plotters::style::colors::BLUE.mix(0.05))
313+
.axis_style(ShapeStyle::from(&plotters::style::colors::BLUE.mix(0.45)).stroke_width(1))
313314
.y_labels(10)
314315
.y_label_style(
315316
("sans-serif", 15)
316317
.into_font()
317-
.color(&plotters::style::colors::WHITE.mix(0.65))
318+
.color(&plotters::style::colors::BLUE.mix(0.65))
318319
.transform(FontTransform::Rotate90),
319320
)
320321
.y_label_formatter(&|y| format!("{}%", y))
@@ -333,18 +334,3 @@ impl Chart<Message> for CpuUsageChart {
333334
.expect("failed to draw chart data");
334335
}
335336
}
336-
337-
mod style {
338-
use iced::Color;
339-
340-
pub struct ChartContainer;
341-
impl iced::container::StyleSheet for ChartContainer {
342-
fn style(&self) -> iced::container::Style {
343-
iced::container::Style {
344-
background: Some(Color::BLACK.into()),
345-
text_color: Some(Color::WHITE),
346-
..Default::default()
347-
}
348-
}
349-
}
350-
}

0 commit comments

Comments
 (0)