Skip to content

Commit

Permalink
other charts (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
Billy-Sheppard authored Jan 30, 2024
1 parent 5dd69d8 commit b16ed95
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 42 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "chart-js-rs"
version = "0.0.14"
version = "0.0.15"
edition = "2021"
authors = ["Billy Sheppard", "Luis Moreno"]
license = "Apache-2.0"
Expand Down
6 changes: 3 additions & 3 deletions examples/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ impl Model {
.prop("id", id)
.style("height", "calc(100vh - 270px)")
.after_inserted(move |_| {
chart.to_chart().render() // use .to_chart().render_mutate(id) if you wish to run some javascript on this chart, for more detail see bar and index.html
chart.into_chart().render() // use .to_chart().render_mutate(id) if you wish to run some javascript on this chart, for more detail see bar and index.html
})
})
}
Expand Down Expand Up @@ -333,7 +333,7 @@ impl Model {
.prop("id", three_id)
.style("height", "calc(100vh - 270px)")
.after_inserted(move |_| {
three_a_chart.to_chart().render()
three_a_chart.into_chart().render()
})
}))
}),
Expand All @@ -344,7 +344,7 @@ impl Model {
.prop("id", four_id)
.style("height", "calc(100vh - 270px)")
.after_inserted(move |_| {
three_b_chart.to_chart().render()
three_b_chart.into_chart().render()
})
}))
})
Expand Down
20 changes: 8 additions & 12 deletions src/bar.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use gloo_utils::format::JsValueSerdeExt;
use serde::Serialize;
use serde::{de::DeserializeOwned, Deserialize, Serialize};

use crate::{types::*, utils::*, ChartOptions};
use crate::{types::*, ChartExt, ChartOptions};

#[derive(Debug, Clone, Serialize, Default)]
#[derive(Debug, Clone, Deserialize, Serialize, Default)]
pub struct Bar<A: Annotation> {
#[serde(rename = "type")]
pub r#type: BarString,
Expand All @@ -12,16 +11,13 @@ pub struct Bar<A: Annotation> {
pub id: String,
}

impl<A: Annotation> Bar<A> {
pub fn to_chart(self) -> Chart {
Chart(
<::wasm_bindgen::JsValue as JsValueSerdeExt>::from_serde(&self)
.expect("Unable to serialize chart."),
self.id,
)
impl<A: Annotation + DeserializeOwned> ChartExt for Bar<A> {
fn get_id(self) -> String {
self.id
}
}
#[derive(Debug, Clone)]

#[derive(Debug, Clone, Deserialize)]
pub struct BarString(String);
impl Serialize for BarString {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
Expand Down
20 changes: 7 additions & 13 deletions src/doughnut.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,22 @@
use gloo_utils::format::JsValueSerdeExt;
use serde::Serialize;
use serde::{de::DeserializeOwned, Deserialize, Serialize};

use crate::{types::*, utils::*, ChartOptions};
use crate::{types::*, ChartExt, ChartOptions};

#[derive(Debug, Clone, Serialize, Default)]
#[derive(Debug, Clone, Deserialize, Serialize, Default)]
pub struct Doughnut<A: Annotation> {
#[serde(rename = "type")]
pub r#type: DoughnutString,
pub data: Dataset<Vec<SinglePointDataset>>,
pub options: ChartOptions<A>,
pub id: String,
}

impl<A: Annotation> Doughnut<A> {
pub fn to_chart(self) -> Chart {
Chart(
<::wasm_bindgen::JsValue as JsValueSerdeExt>::from_serde(&self)
.expect("Unable to serialize chart."),
self.id,
)
impl<A: Annotation + DeserializeOwned> ChartExt for Doughnut<A> {
fn get_id(self) -> String {
self.id
}
}

#[derive(Debug, Clone)]
#[derive(Debug, Clone, Deserialize)]
pub struct DoughnutString(String);
impl Serialize for DoughnutString {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
Expand Down
19 changes: 7 additions & 12 deletions src/pie.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use gloo_utils::format::JsValueSerdeExt;
use serde::Serialize;
use serde::{de::DeserializeOwned, Deserialize, Serialize};

use crate::{types::*, utils::*, ChartOptions};
use crate::{types::*, ChartExt, ChartOptions};

#[derive(Debug, Clone, Serialize, Default)]
#[derive(Debug, Clone, Deserialize, Serialize, Default)]
pub struct Pie<A: Annotation> {
#[serde(rename = "type")]
pub r#type: PieString,
Expand All @@ -12,17 +11,13 @@ pub struct Pie<A: Annotation> {
pub id: String,
}

impl<A: Annotation> Pie<A> {
pub fn to_chart(self) -> Chart {
Chart(
<::wasm_bindgen::JsValue as JsValueSerdeExt>::from_serde(&self)
.expect("Unable to serialize chart."),
self.id,
)
impl<A: Annotation + DeserializeOwned> ChartExt for Pie<A> {
fn get_id(self) -> String {
self.id
}
}

#[derive(Debug, Clone)]
#[derive(Debug, Clone, Deserialize)]
pub struct PieString(String);
impl Serialize for PieString {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
Expand Down

0 comments on commit b16ed95

Please sign in to comment.