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

Overview

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.1"
iced = { version = "0.3", features = ["canvas", "tokio"] }
plotters="0.3"

How to use?

First, import Chart and ChartWidget:

use plotters_iced::{Chart, ChartWidget, DrawingBackend, ChartBuilder};

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

struct MyChart;
impl Chart 
   for 
   MyChart {
    
   fn 
   build_chart
   
    (
    &
    self, builder: ChartBuilder
    
     ) {
        
     //build your chart here, please refer to plotters for more details
    }
}
    
   
  

Finally, render your chart view:

impl MyChart {
    fn view(&mut self)->Element
    {
        ChartWidget
   ::
   new(
   self)
            .
   width(Length
   ::
   Unit(
   200))
            .
   height(Length
   ::
   Unit(
   200))
            .
   into()
    }
}
  

If you are looking for a full example of an implementation, please check 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:

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 as native application
cargo run --release --example split-chart
  • Run as wasm application

First, install wasm-bindgen-cli v0.2.69 (iced requires this version)

cargo install -f wasm-bindgen-cli --version 0.2.69

Then build the code and generate wasm bindings

cargo build --example split-chart --target wasm32-unknown-unknown
wasm-bindgen ./target/wasm32-unknown-unknown/debug/examples/split-chart.wasm --out-dir ./examples/js --target web

Then, host the examples folder with a http server

cargo install https
http examples

visit http://localhost:8000/web-demo.html in your browser.

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

Comments
  • Resolver error: failed to select a version for `servo-fontconfig-sys` which could resolve this conflict

    Resolver error: failed to select a version for `servo-fontconfig-sys` which could resolve this conflict

    Up to iced 0.4.2 everything was fine, but from v0.5.0 on I have a conflict I'm not able to solve. It is related to a dependency in common between plotters, iced and plotters-iced. I see that you updated the crate and the instruction to the new versions, didn't you face this problem? I am running on MacOS.

    error: failed to select a version for `servo-fontconfig-sys`.
        ... required by package `servo-fontconfig v0.5.1`
        ... which satisfies dependency `servo-fontconfig = "^0.5.1"` of package `crossfont v0.5.0`
        ... which satisfies dependency `crossfont = "^0.5.0"` of package `sctk-adwaita v0.4.1`
        ... which satisfies dependency `sctk-adwaita = "^0.4.1"` of package `winit v0.27.0`
        ... which satisfies dependency `winit = "^0.27"` of package `iced_winit v0.6.0`
        ... which satisfies dependency `iced_winit = "^0.6"` of package `iced v0.6.0`
        ... which satisfies dependency `iced = "^0.6.0"` of package `sniffnet v1.0.1 (/Users/giulianobellini/Desktop/GitHub/sniffnet)`
    versions that meet the requirements `^5.1.0` are: 5.1.0
    
    the package `servo-fontconfig-sys` links to the native library `fontconfig`, but it conflicts with a previous package which links to `fontconfig` as well:
    package `yeslogic-fontconfig-sys v3.0.0`
        ... which satisfies dependency `yeslogic-fontconfig-sys = "^3.0.0"` of package `font-kit v0.11.0`
        ... which satisfies dependency `font-kit = "^0.11.0"` of package `plotters v0.3.4`
        ... which satisfies dependency `plotters = "^0.3"` of package `plotters-iced v0.5.0`
        ... which satisfies dependency `plotters-iced = "^0.5.0"` of package `sniffnet v1.0.1 (/Users/giulianobellini/Desktop/GitHub/sniffnet)`
    Only one package in the dependency graph may specify the same links value. This helps ensure that only one copy of a native library is linked in the final binary. Try to adjust your dependencies so that only one package uses the links ='servo-fontconfig-sys' value. For more information, see https://doc.rust-lang.org/cargo/reference/resolver.html#links.
    
    failed to select a version for `servo-fontconfig-sys` which could resolve this conflict
    
    opened by GyulyVGC 4
  • Outdated Iced Backend

    Outdated Iced Backend

    When creating a simple gui with a text box and a graph, when setting widths/lengths for both, the program fails to compile saying

    expected enum iced_core::length::Length, found enum Length.

    It suggests that multiple versions of iced_core are being used. I'm using iced version 0.4, which uses iced_native 0.5. I looked, and it seems like this repository is using iced_native 0.4. I think this is preventing people from using newer versions of iced in conjunction with plotters-iced. Is there any possibility this repository will be updated? Or is there another issue here?

    opened by BeaconBrigade 4
  • Should be updated to use `iced` 0.5

    Should be updated to use `iced` 0.5

    iced 0.5 was recently released. This causes (if you try to use iced 0.5 in your project) type mismatches with, for example, iced_core::length::Length (mismatch between iced_core 0.5 and 0.6), thus making it impossible to use iced 0.5 with this library.

    opened by yjhn 2
  • iced is now pure by default; iced_pure deprecated

    iced is now pure by default; iced_pure deprecated

    The pure way of doing things seems to be the default now: https://github.com/iced-rs/iced/pull/1393

    Note that this change hasn't been released yet, but it's coming so just a heads-up. 🙂

    opened by black-puppydog 2
  • Pure verion examples

    Pure verion examples

    There are no examples given for the pure version of this widget and it seems that the pure version also requires mutable access to state object from fn view.

    Is the pure version incomplete? An example would be much appreciated.

    opened by RagibHasin 1
  • Allow more generic usage of chart widget

    Allow more generic usage of chart widget

    Commit af59edc1b673a86656aadd95ae3980503f4e7323 addresses the following lints:

    Commit dabfd8db95b2f54dd708377e465eaca0f5f45dff and 3983f42c070099a2d08e6e13bb41dbc2ee149442 fix other small pedantic things I noticed while making other changes.

    The meat of the change is in commit b95f26823e40b39dec156c1c74f6231fcdb615e2. This commit does not restrict the chart passed to the ChartWidget to a &mut reference to something that implements Chart. This commit instead allows the ChartWidget to be generic over any type that implements Chart and also adds a blanket implementation over all &mut T where T: Chart. These two changes in conjunction allow for the ChartWidget to take either a mutable reference to or ownership of a type that implements Chart.

    The previous implementation of ChartWidget to always take a &mut Chart makes sense in most use cases since the user is most likely to create a struct to hold persistent data about the chart and pass a mutable reference to that to the chart widget in the view method on the iced::Application. My use-case however required that I pass extra data to all of the charts in the update function. To accomplish this, I needed to return a new structure with the new data that will implement Chart, but this was not possible since the ChartWidget implementation required a reference to this temporary structure that could not persist.

    I have not thoroughly tested the change in implementation to ensure it will not break any existing code though my idea was to ensure this would be 100% backwards compatible with the previous implementation. I have tested the implementation on both of the native examples.

    I did not implement this change on the web implementation due to my lack of familiarity with its implementation and the implementation seeming reliant on the chart passed as a reference as seen here:

    https://github.com/Joylei/plotters-iced/blob/master/src/web/widget.rs#L97

    opened by DusterTheFirst 1
  • Add  user defined Theme support to plotters_iced::renderer::Renderer trait.

    Add user defined Theme support to plotters_iced::renderer::Renderer trait.

    I was unable to compile using a Theme that I defined myself instead of using iced_style::Theme which was added in iced 0.5.

    error[E0277]: the trait bound `iced_graphics::renderer::Renderer<iced_glow::backend::Backend, MyTheme>: plotters_iced::renderer::Renderer` is not satisfied
       --> src/panel/pqn.rs:698:9
        |
    698 | /         plotters_iced::ChartWidget::new(self)
    699 | |             .width(iced::Length::Units(40))
    700 | |             .height(iced::Length::Fill)
        | |_______________________________________^ the trait `plotters_iced::renderer::Renderer` is not implemented for `iced_graphics::renderer::Renderer<iced_glow::backend::Backend, MyTheme>`
    701 |               .into()
        |                ---- required by a bound introduced by this call
        |
        = help: the trait `plotters_iced::renderer::Renderer` is implemented for `iced_graphics::renderer::Renderer<B, iced::Theme>`
        = note: required for `iced_native::Element<'_, Message, iced_graphics::renderer::Renderer<iced_glow::backend::Backend, MyTheme>>` to implement `From<ChartWidget<'_, Message, iced_graphics::renderer::Renderer<iced_glow::backend::Backend, MyTheme>, &LegendWidget>>`
        = note: required for `ChartWidget<'_, Message, iced_graphics::renderer::Renderer<iced_glow::backend::Backend, MyTheme>, &LegendWidget>` to implement `std::convert::Into<iced_native::Element<'_, Message, iced_graphics::renderer::Renderer<iced_glow::backend::Backend, MyTheme>>>`
    

    The reason is that the plotters_iced::renderer::Renderer trait is limited to implement for iced_graphics::Renderer<B, iced_style::Theme>.

    In the patch, the concrete type iced_style::Theme was changed to a type parameter.

    opened by sumomoneko 0
  • Changes to allow the ChartWidget to be used in pure applications

    Changes to allow the ChartWidget to be used in pure applications

    By enabling and disabling the pure and native features for this crate, the ChartWidget can be either used in impure applications or pure applications.

    opened by chanderlud 0
  • Add support for mouse events

    Add support for mouse events

    Thanks for this super useful library! It's made it extremely easy for me to make an interactive visualization application.

    I was hoping to incorporate user interaction with the diagram into my application, but it seemed that the plotters-iced ChartWidget isn't doing anything with mouse events. This PR adds the ability for users to listen for mouse events that take place in their ChartWidgets.

    I've also added an example of using this feature to make a simple grid that can be sketched on (see picture below).

    plotters-iced

    opened by mxgrey 0
Releases(v0.5.0)
  • v0.5.0(Dec 7, 2022)

  • v0.4.1(Nov 21, 2022)

    What's Changed

    • Add user defined Theme support to plotters_iced::renderer::Renderer trait. by @sumomoneko in https://github.com/Joylei/plotters-iced/pull/10

    New Contributors

    • @sumomoneko made their first contribution in https://github.com/Joylei/plotters-iced/pull/10

    Full Changelog: https://github.com/Joylei/plotters-iced/compare/v0.4.0...v0.4.1

    Source code(tar.gz)
    Source code(zip)
  • v0.4.0(Nov 13, 2022)

    What's Changed

    • upgraded to iced v0.5
    • removed unsafe poly2tri
    • added LTTB sampling algorithm

    Full Changelog: https://github.com/Joylei/plotters-iced/compare/v0.3.3...v0.4.0

    Source code(tar.gz)
    Source code(zip)
  • v0.3.3(Sep 27, 2022)

  • v0.3.2(Sep 18, 2022)

  • v0.3.1(Jul 24, 2022)

    What's Changed

    • Changes to allow the ChartWidget to be used in pure applications by @chanderlud in https://github.com/Joylei/plotters-iced/pull/5

    New Contributors

    • @chanderlud made their first contribution in https://github.com/Joylei/plotters-iced/pull/5

    Full Changelog: https://github.com/Joylei/plotters-iced/compare/v0.3.0...v0.3.1

    Source code(tar.gz)
    Source code(zip)
  • v0.3.0(Jun 19, 2022)

    • update for iced v0.4
    • the web version is not supported due to wgpu webgl errors

    Full Changelog: https://github.com/Joylei/plotters-iced/compare/v0.2.0...v0.3.0

    Source code(tar.gz)
    Source code(zip)
  • v0.2.0(Apr 10, 2022)

    What's Changed

    • Add support for mouse events by @mxgrey in https://github.com/Joylei/plotters-iced/pull/3

    New Contributors

    • @mxgrey made their first contribution in https://github.com/Joylei/plotters-iced/pull/3

    Full Changelog: https://github.com/Joylei/plotters-iced/compare/v0.1.4...v0.2.0

    Source code(tar.gz)
    Source code(zip)
  • v0.1.4(Nov 12, 2021)

    What's Changed

    • Allow more generic usage of chart widget by @DusterTheFirst in https://github.com/Joylei/plotters-iced/pull/2

    New Contributors

    • @DusterTheFirst made their first contribution in https://github.com/Joylei/plotters-iced/pull/2

    Full Changelog: https://github.com/Joylei/plotters-iced/compare/v0.1.3...v0.1.4

    Source code(tar.gz)
    Source code(zip)
  • v0.1.3(Oct 17, 2021)

Owner
joylei
Rust, C#, Python
joylei
A small charting/visualization tool and partial vega implementation for Rust

Gust A charting library for rust! Disclaimer This is still very much a work in progress! APIs are very unstable and subject to change. Contributions a

Samuel Resendez 128 Dec 24, 2022
This is a Rust implementation of a boid flocking simulation using the ggez graphics crate.

Boidflock This is a Rust implementation of a boid flocking simulation using the ggez graphics crate. The CLI for this program is built using the struc

Andrew Lee 12 Jan 4, 2023
KDash - A fast and simple dashboard for Kubernetes

KDash - A fast and simple dashboard for Kubernetes

null 915 Jan 4, 2023
🌱 Easy to use, blazing-fast, and reliable Chia plot manager for your farm

?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? UNDER DEVELOPME

Daniel De Lucca 8 May 31, 2022
Swash is a pure Rust, cross-platform crate that provides font introspection, complex text shaping and glyph rendering.

Swash is a pure Rust, cross-platform crate that provides font introspection, complex text shaping and glyph rendering. Goals This crate aims to

Chad Brokaw 398 Dec 14, 2022
below is an interactive tool to view and record historical system data.

A time traveling resource monitor for modern Linux systems

Facebook Incubator 824 Dec 31, 2022
📝 Web-based, reactive Datalog notebooks for data analysis and visualization

?? Web-based, reactive Datalog notebooks for data analysis and visualization

Eric Zhang 486 Dec 28, 2022
Animation Library for github.com/iced-rs/iced

Very much still a WIP. API is mostly final and this can create animations. Just missing large amounts of features to make this useful in any real proj

Pop!_OS 11 Feb 1, 2023
A rust drawing library for high quality data plotting for both WASM and native, statically and realtimely 🦀 📈🚀

Plotters - A Rust drawing library focus on data plotting for both WASM and native applications ?? ?? ?? Plotters is drawing library designed for rende

Hao Hou 2.7k Jan 4, 2023
Minimal Rust HTTP client for both native and WASM

ehttp: a minimal Rust HTTP client for both native and WASM If you want to do HTTP requests and are targetting both native and web (WASM), then this is

Emil Ernerfeldt 105 Dec 25, 2022
Easy c̵̰͠r̵̛̠ö̴̪s̶̩̒s̵̭̀-t̶̲͝h̶̯̚r̵̺͐e̷̖̽ḁ̴̍d̶̖̔ ȓ̵͙ė̶͎ḟ̴͙e̸̖͛r̶̖͗ë̶̱́ṉ̵̒ĉ̷̥e̷͚̍ s̷̹͌h̷̲̉a̵̭͋r̷̫̊ḭ̵̊n̷̬͂g̵̦̃ f̶̻̊ơ̵̜ṟ̸̈́ R̵̞̋ù̵̺s̷̖̅ţ̸͗!̸̼͋

Rust S̵̓i̸̓n̵̉ I̴n̴f̶e̸r̵n̷a̴l mutability! Howdy, friendly Rust developer! Ever had a value get m̵̯̅ð̶͊v̴̮̾ê̴̼͘d away right under your nose just when

null 294 Dec 23, 2022
This contract is to provide vesting account feature for the both cw20 and native tokens, which is controlled by a master address

Token Vesting This contract is to provide vesting account feature for the both cw20 and native tokens, which is controlled by a master address. Instan

yys 7 Oct 7, 2022
The rust client for CeresDB. CeresDB is a high-performance, distributed, schema-less, cloud native time-series database that can handle both time-series and analytics workloads.

The rust client for CeresDB. CeresDB is a high-performance, distributed, schema-less, cloud native time-series database that can handle both time-series and analytics workloads.

null 12 Nov 18, 2022
egui: an easy-to-use immediate mode GUI in Rust that runs on both web and native

?? egui: an easy-to-use GUI in pure Rust ?? Click to run the web demo ?? egui is a simple, fast, and highly portable immediate mode GUI library for Ru

Cronus Diamond 7 Aug 13, 2022
Synchronization primitives for both web and native.

wasm_sync wasm_sync offers synchronization primitives that work in both browser and native contexts. In web browsers, use of atomic wait instructions

Douglas Dwyer 3 Jul 31, 2023
Dr-dotnet - 🩺 One-click diagnosis of your dotnet applications. Works both locally or remotely as a web service

Dr-dotnet - ?? One-click diagnosis of your dotnet applications. Works both locally or remotely as a web service. Based on the lowest level dotnet profiling APIs and using the rust language ?? for a minimal runtime penalty.

Olivier Giniaux 25 Dec 17, 2022
A framework independent animation library for rust, works nicely with Iced and the others

anim A framework independent animation library for rust, works nicely with Iced and the others. Showcase How to install? Include anim in your Cargo.to

joylei 37 Nov 10, 2022
A custom frontend for the TradeOgre exchange, written using Iced

Forest A custom frontend for the TradeOgre exchange, written using Iced. Why TradeOgre? It's a simple, non-KYC exchange that I found out about recentl

null 3 Aug 24, 2022
A CHIP-8 emulator in Rust with iced-powered GUI

CHIP-8 Emulator in Rust A CHIP-8 emulator written in Rust and iced-powered GUI. All 34 CHIP-8 instructions (SUPER CHIP instructions are not supported)

Yuto Takahashi 6 Dec 27, 2022