Skip to content

Commit

Permalink
0.0.37
Browse files Browse the repository at this point in the history
  • Loading branch information
Billy-Sheppard committed Sep 16, 2024
1 parent e2a7743 commit 54acdd7
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 14 deletions.
10 changes: 5 additions & 5 deletions 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.36"
version = "0.0.37"
edition = "2021"
authors = ["Billy Sheppard", "Luis Moreno"]
license = "Apache-2.0"
Expand Down
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ git = "https://github.com/Billy-Sheppard/chart-js-rs"

### Rust:
```rust
use chart_js_rs::ChartExt;

let id = "[YOUR CHART ID HERE]";
let chart = chart_js_rs::scatter::Scatter {
id: id.to_string(),
Expand All @@ -30,15 +32,15 @@ git = "https://github.com/Billy-Sheppard/chart-js-rs"
..Default::default()
};
// to use any JS callbacks or functions you use render_mutate and refer to the JS below
chart.to_chart().mutate().render();
chart.into_chart().mutate().render();

// to use any chart-js plugins, a few examples
chart.to_chart().plugins("[window['chartjs-plugin-autocolors']]").render(); // for autocolors and no mutating
chart.to_chart().mutate().plugins("[window['chartjs-plugin-autocolors']]").render(); // for autocolors and mutating
chart.to_chart().mutate().plugins("[ChartDataLabels, window['chartjs-plugin-autocolors']]").render(); // for datalabels, autocolors, and mutating
chart.into_chart().plugins("[window['chartjs-plugin-autocolors']]").render(); // for autocolors and no mutating
chart.into_chart().mutate().plugins("[window['chartjs-plugin-autocolors']]").render(); // for autocolors and mutating
chart.into_chart().mutate().plugins("[ChartDataLabels, window['chartjs-plugin-autocolors']]").render(); // for datalabels, autocolors, and mutating

// else use render
chart.to_chart().render();
chart.into_chart().render();
```

### Your html file:
Expand Down
2 changes: 1 addition & 1 deletion examples/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ impl Model {

backgroundColor: "palegreen".into(),
borderColor: "green".into(),
borderWidth: 2.into(),
borderWidth: Some(2.into()),
label: "Dataset 1".into(),
yAxisID: "y".into(),
..Default::default() // always use `..Default::default()` to make sure this works in the future
Expand Down
26 changes: 24 additions & 2 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,8 +403,8 @@ pub struct XYDataset {
pub borderRadius: NumberString,
#[serde(skip_serializing_if = "String::is_empty", default)]
pub borderSkipped: String,
#[serde(skip_serializing_if = "NumberString::is_empty", default)]
pub borderWidth: NumberString,
#[serde(skip_serializing_if = "Option::is_none")]
pub borderWidth: Option<Border>,
#[serde(skip_serializing_if = "String::is_empty", default)]
pub category_label: String,
#[serde(skip_serializing_if = "NumberString::is_empty", default)]
Expand Down Expand Up @@ -1002,6 +1002,28 @@ pub struct DataLabels {
pub z: NumberString,
}

#[derive(Debug, Clone, Deserialize, Serialize, Default, PartialEq, Eq, PartialOrd, Ord)]
pub struct Border {
#[serde(skip_serializing_if = "NumberString::is_empty", default)]
pub bottom: NumberString,
#[serde(skip_serializing_if = "NumberString::is_empty", default)]
pub left: NumberString,
#[serde(skip_serializing_if = "NumberString::is_empty", default)]
pub right: NumberString,
#[serde(skip_serializing_if = "NumberString::is_empty", default)]
pub top: NumberString,
}
impl From<i32> for Border {
fn from(value: i32) -> Self {
Border {
bottom: value.into(),
left: value.into(),
right: value.into(),
top: value.into(),
}
}
}

#[derive(Debug, Clone, Deserialize, Serialize, Default, PartialEq, Eq, PartialOrd, Ord)]
pub struct Padding {
#[serde(skip_serializing_if = "NumberString::is_empty", default)]
Expand Down

0 comments on commit 54acdd7

Please sign in to comment.