MCPcopy Index your code
hub / github.com/Joylei/plotters-iced

github.com/Joylei/plotters-iced @v0.11.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.11.0 ↗ · + Follow
118 symbols 205 edges 13 files 17 documented · 14%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

plotters-iced

Test and Build Documentation Crates.io License

This is an implementation of an Iced backend for Plotters, for both native and wasm applications.

This backend has been optimized as for speed. Note that some specific plotting features supported in the Bitmap backend may not be implemented there, though.

Showcase

CPU Monitor Example

WASM Example

What is Plotters?

Plotters is an extensible Rust drawing library that can be used to plot data on nice-looking graphs, rendering them through a plotting backend (eg. to a Bitmap image raw buffer, to your GUI backend, to an SVG file, etc.).

For more details on Plotters, please check the following links:

How to install?

Include plotters-iced in your Cargo.toml dependencies:

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

How to use?

First, import Chart and ChartWidget:

```rust,ignore use plotters_iced::{Chart, ChartWidget, DrawingBackend, ChartBuilder};


Then, derive `Chart` trait and build your chart, and let `plotters-iced` takes care the rest:

```rust,ignore
struct MyChart;
impl Chart<Message> for MyChart {
    type State = ();
    fn build_chart<DB:DrawingBackend>(&self, state: &Self::State, builder: ChartBuilder<DB>) {
        //build your chart here, please refer to plotters for more details
    }
}

Finally, render your chart view:

```rust,ignore impl MyChart { fn view(&mut self)->Element { ChartWidget::new(self) .width(Length::Fixed(200)) .height(Length::Fixed(200)) .into() } }


_If you are looking for a full example of an implementation, please check [cpu-monitor.rs](./examples/cpu-monitor.rs)._

## How to run the examples?

### Example #1: `cpu-monitor`

This example samples your CPU load every second, and renders it in a real-time chart:

```sh
cargo run --release --example cpu-monitor

From this example, you'll learn:

  • how to build charts by plotters-iced
  • how to feed data to charts
  • how to make layouts of charts responsive
  • how to use fonts with charts

Example #2: split-chart

This example shows you how to split drawing area.

  • run the native version
cargo run --release --example split-chart
  • run the web version
cd examples/split-chart
trunk serve

Are there any limitations?

Limitation #1: No image rendering

No image rendering for native and wasm applications.

Limitation #2: Limited text rendering for native applications

Only TTF font family are supported for text rendering, which is a limitation of Iced, please look at cpu-monitor.rs. As well, font transforms are not supported,which is also a limitation of Iced.

Credits

Extension points exported contracts — how you extend this code

Chart (Interface)
Chart View Model ## Example ```rust,ignore use plotters::prelude::*; use plotters_iced::{Chart,ChartWidget}; struct MyC [5 …
src/chart.rs
LttbSource (Interface)
data source for lttb sampling ## Known limitations - X-values must be in a strictly increasing order [4 implementers]
src/sample/lttb.rs
Renderer (Interface)
Graphics Renderer [2 implementers]
src/renderer.rs
CvtPoint (Interface)
(no doc) [2 implementers]
src/utils.rs
Renderer (Interface)
graphics renderer
src/chart.rs
DataPoint (Interface)
data point for [`LttbSource`] [3 implementers]
src/sample/lttb.rs
AndExt (Interface)
(no doc) [1 implementers]
src/utils.rs

Core symbols most depended-on inside this repo

height
called by 12
src/widget.rs
cvt_point
called by 10
src/utils.rs
width
called by 10
src/widget.rs
len
called by 9
src/sample/lttb.rs
size
called by 8
src/widget.rs
item_at
called by 7
src/sample/lttb.rs
cvt_color
called by 6
src/utils.rs
cvt_stroke
called by 4
src/utils.rs

Shape

Method 80
Class 16
Function 10
Interface 7
Enum 5

Languages

Rust100%

Modules by API surface

src/sample/lttb.rs19 symbols
src/backend/mod.rs15 symbols
src/widget.rs14 symbols
examples/cpu-monitor.rs14 symbols
examples/large-data.rs13 symbols
src/chart.rs11 symbols
examples/mouse_events.rs11 symbols
examples/split-chart/src/main.rs9 symbols
src/utils.rs6 symbols
src/renderer.rs4 symbols
src/error.rs2 symbols

For agents

$ claude mcp add plotters-iced \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact