Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[package]
name = "plotters-iced"
version = "0.11.0"
version = "0.12.0"
description = "Iced backend for Plotters"
readme = "README.md"
license = "MIT"
edition = "2021"
edition = "2024"
resolver = "2"
homepage = "https://github.com/Joylei/plotters-iced"
repository = "https://github.com/Joylei/plotters-iced.git"
Expand All @@ -19,8 +19,8 @@ members = [".", "examples/split-chart"]
[dependencies]
plotters = { version = "0.3", default-features = false }
plotters-backend = "0.3"
iced_widget = { version = "0.13", features = ["canvas"] }
iced_graphics = "0.13"
iced_widget = { version = "0.14", features = ["canvas"] }
iced_graphics = "0.14"
once_cell = "1"

[dev-dependencies]
Expand All @@ -30,7 +30,7 @@ plotters = { version = "0.3", default-features = false, features = [
"line_series",
"point_series",
] }
iced = { version = "0.13", features = ["canvas", "tokio"] }
iced = { version = "0.14", features = ["canvas", "tokio"] }
chrono = { version = "0.4", default-features = false }
rand = "0.8"
tokio = { version = "1", features = ["rt"], default-features = false }
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ Include `plotters-iced` in your `Cargo.toml` dependencies:

```toml
[dependencies]
plotters-iced = "0.11"
iced = { version = "0.13", features = ["canvas", "tokio"] }
plotters-iced = "0.12"
iced = { version = "0.14", features = ["canvas", "tokio"] }
plotters="0.3"
```

Expand Down
17 changes: 9 additions & 8 deletions examples/cpu-monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ extern crate sysinfo;

use chrono::{DateTime, Utc};
use iced::{
Alignment, Element, Font, Length, Size, Task,
alignment::{Horizontal, Vertical},
font,
widget::{
canvas::{Cache, Frame, Geometry},
Column, Container, Row, Scrollable, Space, Text,
canvas::{Cache, Frame, Geometry},
},
Alignment, Element, Font, Length, Size, Task,
};
use plotters::prelude::ChartBuilder;
use plotters_backend::DrawingBackend;
Expand All @@ -28,7 +28,7 @@ use std::{
use sysinfo::{CpuRefreshKind, RefreshKind, System};

const PLOT_SECONDS: usize = 60; //1 min
const TITLE_FONT_SIZE: u16 = 22;
const TITLE_FONT_SIZE: u32 = 22;
const SAMPLE_EVERY: Duration = Duration::from_millis(1000);

const FONT_BOLD: Font = Font {
Expand All @@ -38,14 +38,15 @@ const FONT_BOLD: Font = Font {
};

fn main() {
iced::application("CPU Monitor Example", State::update, State::view)
iced::application(State::new, State::update, State::view)
.title("CPU Monitor Example")
.antialiasing(true)
.default_font(Font::with_name("Noto Sans"))
.subscription(|_| {
const FPS: u64 = 50;
iced::time::every(Duration::from_millis(1000 / FPS)).map(|_| Message::Tick)
})
.run_with(State::new)
.run()
.unwrap();
}

Expand Down Expand Up @@ -165,7 +166,7 @@ impl SystemChart {
}
}

fn view(&self) -> Element<Message> {
fn view(&self) -> Element<'_, Message> {
if !self.is_initialized() {
Text::new("Loading...")
.align_x(Horizontal::Center)
Expand All @@ -191,7 +192,7 @@ impl SystemChart {
idx += 1;
}
while idx % self.items_per_row != 0 {
row = row.push(Space::new(Length::Fill, Length::Fixed(50.0)));
row = row.push(Space::new().width(Length::Fill).height(Length::Fixed(50.0)));
idx += 1;
}
col = col.push(row);
Expand Down Expand Up @@ -234,7 +235,7 @@ impl CpuUsageChart {
self.cache.clear();
}

fn view(&self, idx: usize, chart_height: f32) -> Element<Message> {
fn view(&self, idx: usize, chart_height: f32) -> Element<'_, Message> {
Column::new()
.width(Length::Fill)
.height(Length::Shrink)
Expand Down
16 changes: 8 additions & 8 deletions examples/large-data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,23 @@ extern crate tokio;

use chrono::{DateTime, Utc};
use iced::{
font,
Alignment, Element, Font, Length, Size, Task, font,
widget::{
canvas::{Cache, Frame, Geometry},
Column, Container, Text,
canvas::{Cache, Frame, Geometry},
},
Alignment, Element, Font, Length, Size, Task,
};
use plotters::prelude::ChartBuilder;
use plotters_backend::DrawingBackend;
use plotters_iced::{
sample::lttb::{DataPoint, LttbSource},
Chart, ChartWidget, Renderer,
sample::lttb::{DataPoint, LttbSource},
};
use rand::Rng;
use std::time::Duration;
use std::{collections::VecDeque, time::Instant};

const TITLE_FONT_SIZE: u16 = 22;
const TITLE_FONT_SIZE: u32 = 22;

const FONT_BOLD: Font = Font {
family: font::Family::Name("Noto Sans"),
Expand All @@ -37,10 +36,11 @@ const FONT_BOLD: Font = Font {
};

fn main() {
iced::application("Large Data Example", State::update, State::view)
iced::application(State::new, State::update, State::view)
.title("Large Data Example")
.antialiasing(true)
.default_font(Font::with_name("Noto Sans"))
.run_with(State::new)
.run()
.unwrap();
}

Expand Down Expand Up @@ -145,7 +145,7 @@ impl ExampleChart {
}
}

fn view(&self) -> Element<Message> {
fn view(&self) -> Element<'_, Message> {
let chart = ChartWidget::new(self)
.width(Length::Fill)
.height(Length::Fill);
Expand Down
22 changes: 13 additions & 9 deletions examples/mouse_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@
// License: MIT

use iced::{
event,
Alignment, Element, Length, Point, Size, event,
mouse::Cursor,
widget::{
canvas::{self, Cache, Frame, Geometry},
Column, Container, Text,
canvas::{self, Cache, Frame, Geometry},
},
Alignment, Element, Length, Point, Size,
};
use plotters::{
coord::{types::RangedCoordf32, ReverseCoordTranslate},
coord::{ReverseCoordTranslate, types::RangedCoordf32},
prelude::*,
};
use plotters_iced::{Chart, ChartWidget, Renderer};
Expand All @@ -26,6 +25,10 @@ struct State {
}

impl State {
fn new() -> Self {
Self::default()
}

fn update(&mut self, message: Message) {
match message {
Message::MouseEvent(event, point) => {
Expand All @@ -45,7 +48,7 @@ impl State {
}
}

fn view(&self) -> Element<Message> {
fn view(&self) -> Element<'_, Message> {
let content = Column::new()
.spacing(20)
.width(Length::Fill)
Expand Down Expand Up @@ -75,7 +78,7 @@ struct ArtChart {
}

impl ArtChart {
fn view(&self) -> Element<Message> {
fn view(&self) -> Element<'_, Message> {
let chart = ChartWidget::new(self)
.width(Length::Fill)
.height(Length::Fill);
Expand Down Expand Up @@ -212,7 +215,7 @@ impl Chart<Message> for ArtChart {
fn update(
&self,
_state: &mut Self::State,
event: canvas::Event,
event: &iced::Event,
bounds: iced::Rectangle,
cursor: Cursor,
) -> (event::Status, Option<Message>) {
Expand All @@ -223,7 +226,7 @@ impl Chart<Message> for ArtChart {
let p = point - p_origin;
return (
event::Status::Captured,
Some(Message::MouseEvent(evt, Point::new(p.x, p.y))),
Some(Message::MouseEvent(evt.clone(), Point::new(p.x, p.y))),
);
}
_ => {}
Expand All @@ -239,7 +242,8 @@ enum Message {
}

fn main() -> iced::Result {
iced::application("Art", State::update, State::view)
iced::application(State::new, State::update, State::view)
.title("Art")
.antialiasing(true)
.run()
}
4 changes: 2 additions & 2 deletions examples/split-chart/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2021"
publish = false

[dependencies]
iced = { version = "0.13", features = ["canvas"] }
iced = { version = "0.14", features = ["canvas"] }
plotters-iced = { path = "../../" }
plotters = { version = "0.3", default-features = false, features = [
"chrono",
Expand All @@ -16,7 +16,7 @@ plotters = { version = "0.3", default-features = false, features = [
] }

[target.'cfg(target_arch = "wasm32")'.dependencies]
iced.version = "0.13"
iced.version = "0.14"
iced.features = ["canvas", "debug", "webgl"]

console_error_panic_hook = "0.1"
Expand Down
7 changes: 6 additions & 1 deletion examples/split-chart/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ fn main() {
console_log::init().expect("Initialize logger");
std::panic::set_hook(Box::new(console_error_panic_hook::hook));
}
let app = iced::application("Split Chart Example", State::update, State::view)
let app = iced::application(State::new, State::update, State::view)
.title("Split Chart Example")
.antialiasing(cfg!(not(target_arch = "wasm32")))
.subscription(|_| window::frames().map(|_| Message::Tick));
app.run().unwrap();
Expand All @@ -59,6 +60,10 @@ struct State {
}

impl State {
fn new() -> Self {
Self::default()
}

fn update(&mut self, _message: Message) {}

fn view(&self) -> Element<'_, Message> {
Expand Down
Loading
Loading