Skip to content

Commit

Permalink
Merge branch 'master' into feat-leptos
Browse files Browse the repository at this point in the history
  • Loading branch information
clementwanjau authored May 8, 2024
2 parents 48e7e90 + 4c4317b commit 83695af
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 38 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ authors = ["Clement Wanjau <clementwanjau@gmail.com>"]
repository = "https://github.com/clementwanjau/apexcharts-rs"
version = "0.1.4"
edition = "2021"
license = "Apache-2.0 or MIT"
keywords = ["apexcharts", "wasm-chrts", "visualization", "yew-charts", "leptos-charts"]
license = "Apache-2.0"
categories = ["wasm", "web-programming", "visualization"]
readme = "README.md"

Expand All @@ -15,8 +15,8 @@ crate-type = ["cdylib", "rlib"]

[features]
default = []
yew-component = ["yew", "gloo"]
leptos = ["dep:leptos"]
yew = ["dep:yew", "dep:gloo"]

[dependencies]
wasm-bindgen = { version = "0.2", features = ["serde-serialize"] }
Expand Down
4 changes: 1 addition & 3 deletions examples/yew-chart/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ name = "yew-chart"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
wasm-bindgen = "0.2.92"
web-sys = { version = "0.3.69", features = ["console"]}
console = "0.15.8"
yew = { version="0.21.0", features = ["csr"] }
apexcharts-rs = {path = "../../../apexcharts-rs", features = ["yew-component"]}
apexcharts-rs = {path = "../../../apexcharts-rs", features = ["yew"]}
4 changes: 3 additions & 1 deletion examples/yew-chart/Readme.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# ApexCharts Examples
# ApexCharts Yew Examples
This is a collection of examples of how to use the [ApexCharts](https://apexcharts.com/) library in Yew.

## Running the examples
To run the examples, change into the examples directory and run the following command:
```bash
tailwindcss -c ./tailwind.config.js -i ./assets/stylesheets/main.css -o ./assets/stylesheets/output.css

trunk serve
```

Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
mod options;
mod bindings;

#[cfg(feature = "yew-component")]
#[cfg(feature = "yew")]
mod yew;
#[cfg(feature = "leptos")]
mod leptos;

pub mod prelude {
pub use crate::bindings::ApexChart;
pub use crate::options::{ChartType, ChartSeries, SeriesData, to_jsvalue};
#[cfg(feature = "yew-component")]
#[cfg(feature = "yew")]
pub use crate::yew::{ApexChartComponent, ApexChartComponentProps};
#[cfg(feature = "leptos")]
pub use crate::leptos::ApexChartComponent;
Expand Down
50 changes: 20 additions & 30 deletions src/yew.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,66 +7,56 @@ use crate::prelude::{ApexChart, ChartSeries, ChartType, SeriesData};
/// An ApexCharts component for Yew.
///
/// This component is used to render an ApexCharts chart in a Yew application. It is used to render different types of charts
/// such as line, bar, pie, donut, and radial bar charts. To use this component, you need to enable the `yew-component` feature
/// such as line, bar, pie, donut, and radial bar charts. To use this component, you need to enable the `yew` feature
/// in the `apexcharts-rs` crate.
///
///
/// # Example
///
/// ```rust
/// ```rust,ignore
/// use yew::prelude::*;
/// use apexcharts_rs::prelude::{ApexChartComponent, ApexChartComponentProps, ChartSeries, SeriesData, ChartType};
///
/// use apexcharts_rs::prelude::{ApexChartComponent, ApexChartComponentProps, ChartSeries, SeriesData};
///
/// pub struct App {
/// link: ComponentLink<Self>,
/// }
///
/// pub enum AppMsg {
/// Noop
/// }
/// pub struct App;
///
/// impl Component for App {
/// type Message = AppMsg;
/// type Message = ();
/// type Properties = ();
///
/// fn create(ctx: &Context<Self>) -> Self {
/// Self {
/// link: ctx.link()
/// }
/// }
///
/// fn update(&mut self, _ctx: &Context<Self>, _msg: Self::Message) -> bool {
/// true
/// Self {}
/// }
///
/// fn view(&self, _ctx: &Context<Self>) -> Html {
/// let series = vec![
/// ChartSeries {
/// name: "Series 1".to_string(),
/// data: SeriesData::Linear(vec![10.0, 20.0, 30.0, 40.0, 50.0]),
/// data: SeriesData::Single(vec![10, 20, 30, 40, 50]),
/// color: "#008FFB".to_string(),
/// r#type: None,
/// z_index: None,
/// },
/// ChartSeries {
/// name: "Series 2".to_string(),
/// data: SeriesData::Linear(vec![30.0, 40.0, 50.0, 60.0, 70.0]),
/// data: SeriesData::Single(vec![30, 40, 50, 60, 70]),
/// color: "#00E396".to_string(),
/// r#type: None,
/// z_index: None,
/// }
/// ];
///
/// html! {
/// <ApexChartComponent
/// id="chart"
/// r#type=ChartType::Line
/// series=series
/// width="100%"
/// height="300px"
/// />
/// }
/// html! {
/// <>
/// <ApexChartComponent
/// id={"my_area_chart".to_string()}
/// r#type={ChartType::Area}
/// series={series}
/// width={"100%".to_string()}
/// height={"300px".to_string()}
/// />
/// </>
/// }
/// }
/// }
///
pub struct ApexChartComponent {
Expand Down

0 comments on commit 83695af

Please sign in to comment.