Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Rust

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

env:
CARGO_TERM_COLOR: always
jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Test
uses: icepuma/rust-action@master
with:
args: cargo fmt -- --check && cargo test
8 changes: 5 additions & 3 deletions examples/area_series_chart.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use charts::{Chart, ScaleLinear, MarkerType, PointLabelPosition, AreaSeriesView};
use charts::{AreaSeriesView, Chart, MarkerType, PointLabelPosition, ScaleLinear};

fn main() {
// Define chart related sizes.
Expand Down Expand Up @@ -30,7 +30,8 @@ fn main() {
.set_y_scale(&y)
.set_marker_type(MarkerType::Circle)
.set_label_position(PointLabelPosition::N)
.load_data(&area_data).unwrap();
.load_data(&area_data)
.unwrap();

// Generate and save the chart.
Chart::new()
Expand All @@ -43,5 +44,6 @@ fn main() {
.add_axis_left(&y)
.add_left_axis_label("Custom Y Axis Label")
.add_bottom_axis_label("Custom X Axis Label")
.save("area-chart.svg").unwrap();
.save("area-chart.svg")
.unwrap();
}
32 changes: 23 additions & 9 deletions examples/composite_bar_and_scatter_chart.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use charts::{Chart, VerticalBarView, ScaleBand, ScaleLinear, ScatterView, MarkerType, Color, PointLabelPosition};
use charts::{
Chart, Color, MarkerType, PointLabelPosition, ScaleBand, ScaleLinear, ScatterView,
VerticalBarView,
};

fn main() {
// Define chart related sizes.
Expand All @@ -9,7 +12,11 @@ fn main() {
// Create a band scale that maps ["A", "B", "C"] categories to values in the [0, availableWidth]
// range (the width of the chart without the margins).
let x = ScaleBand::new()
.set_domain(vec![String::from("A"), String::from("B"), String::from("C")])
.set_domain(vec![
String::from("A"),
String::from("B"),
String::from("C"),
])
.set_range(vec![0, width - left - right]);

// Create a linear scale that will interpolate values in [0, 100] range to corresponding
Expand All @@ -25,13 +32,18 @@ fn main() {
let bar_data = vec![("A", 70), ("B", 10), ("C", 30)];

// You can use your own iterable as data as long as its items implement the `PointDatum` trait.
let scatter_data = vec![(String::from("A"), 90.3), (String::from("B"), 20.1), (String::from("C"), 10.8)];
let scatter_data = vec![
(String::from("A"), 90.3),
(String::from("B"), 20.1),
(String::from("C"), 10.8),
];

// Create VerticalBar view that is going to represent the data as vertical bars.
let bar_view = VerticalBarView::new()
.set_x_scale(&x)
.set_y_scale(&y)
.load_data(&bar_data).unwrap();
.load_data(&bar_data)
.unwrap();

// Create Scatter view that is going to represent the data as points.
let scatter_view = ScatterView::new()
Expand All @@ -40,19 +52,21 @@ fn main() {
.set_label_position(PointLabelPosition::NE)
.set_marker_type(MarkerType::Circle)
.set_colors(Color::from_vec_of_hex_strings(vec!["#FF4700"]))
.load_data(&scatter_data).unwrap();
.load_data(&scatter_data)
.unwrap();

// Generate and save the chart.
Chart::new()
.set_width(width)
.set_height(height)
.set_margins(top, right, bottom, left)
.add_title(String::from("Composite Bar + Scatter Chart"))
.add_view(&bar_view) // <-- add bar view
.add_view(&scatter_view) // <-- add scatter view
.add_view(&bar_view) // <-- add bar view
.add_view(&scatter_view) // <-- add scatter view
.add_axis_bottom(&x)
.add_axis_left(&y)
.add_left_axis_label("Units of Measurement")
.add_bottom_axis_label("Categories")
.save("composite-bar-and-scatter-chart.svg").unwrap();
}
.save("composite-bar-and-scatter-chart.svg")
.unwrap();
}
14 changes: 10 additions & 4 deletions examples/horizontal_bar_chart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ fn main() {
// Create a band scale that maps ["A", "B", "C"] categories to values in the [0, availableHeight]
// range (the height of the chart without the margins).
let y = ScaleBand::new()
.set_domain(vec![String::from("A"), String::from("B"), String::from("C")])
.set_domain(vec![
String::from("A"),
String::from("B"),
String::from("C"),
])
.set_range(vec![0, height - top - bottom]);

// You can use your own iterable as data as long as its items implement the `BarDatum` trait.
Expand All @@ -25,7 +29,8 @@ fn main() {
let view = HorizontalBarView::new()
.set_x_scale(&x)
.set_y_scale(&y)
.load_data(&data).unwrap();
.load_data(&data)
.unwrap();

// Generate and save the chart.
Chart::new()
Expand All @@ -39,5 +44,6 @@ fn main() {
.add_axis_left(&y)
.add_left_axis_label("Y Axis Custom Label")
.add_bottom_axis_label("X Axis Custom Label")
.save("horizontal-bar-chart.svg").unwrap();
}
.save("horizontal-bar-chart.svg")
.unwrap();
}
8 changes: 5 additions & 3 deletions examples/line_series_chart.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use charts::{Chart, ScaleLinear, MarkerType, PointLabelPosition, LineSeriesView};
use charts::{Chart, LineSeriesView, MarkerType, PointLabelPosition, ScaleLinear};

fn main() {
// Define chart related sizes.
Expand Down Expand Up @@ -30,7 +30,8 @@ fn main() {
.set_y_scale(&y)
.set_marker_type(MarkerType::Circle)
.set_label_position(PointLabelPosition::N)
.load_data(&line_data).unwrap();
.load_data(&line_data)
.unwrap();

// Generate and save the chart.
Chart::new()
Expand All @@ -43,5 +44,6 @@ fn main() {
.add_axis_left(&y)
.add_left_axis_label("Custom Y Axis Label")
.add_bottom_axis_label("Custom X Axis Label")
.save("line-chart.svg").unwrap();
.save("line-chart.svg")
.unwrap();
}
10 changes: 6 additions & 4 deletions examples/scatter_chart.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use charts::{Chart, ScaleLinear, ScatterView, MarkerType, PointLabelPosition};
use charts::{Chart, MarkerType, PointLabelPosition, ScaleLinear, ScatterView};

fn main() {
// Define chart related sizes.
Expand Down Expand Up @@ -30,7 +30,8 @@ fn main() {
.set_y_scale(&y)
.set_label_position(PointLabelPosition::E)
.set_marker_type(MarkerType::Square)
.load_data(&scatter_data).unwrap();
.load_data(&scatter_data)
.unwrap();

// Generate and save the chart.
Chart::new()
Expand All @@ -43,5 +44,6 @@ fn main() {
.add_axis_left(&y)
.add_left_axis_label("Custom X Axis Label")
.add_bottom_axis_label("Custom Y Axis Label")
.save("scatter-chart.svg").unwrap();
}
.save("scatter-chart.svg")
.unwrap();
}
17 changes: 12 additions & 5 deletions examples/scatter_chart_multiple_keys.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use charts::{Chart, ScaleLinear, ScatterView, MarkerType, Color, PointLabelPosition};
use charts::{Chart, Color, MarkerType, PointLabelPosition, ScaleLinear, ScatterView};

fn main() {
// Define chart related sizes.
Expand All @@ -22,7 +22,12 @@ fn main() {
.set_range(vec![height - top - bottom, 0]);

// You can use your own iterable as data as long as its items implement the `PointDatum` trait.
let scatter_data = vec![(120, 90, "foo"), (12, 54, "foo"), (100, 40, "bar"), (180, 10, "baz")];
let scatter_data = vec![
(120, 90, "foo"),
(12, 54, "foo"),
(100, 40, "bar"),
(180, 10, "baz"),
];

// Create Scatter view that is going to represent the data as points.
let scatter_view = ScatterView::new()
Expand All @@ -31,7 +36,8 @@ fn main() {
.set_label_position(PointLabelPosition::E)
.set_marker_type(MarkerType::Circle)
.set_colors(Color::color_scheme_dark())
.load_data(&scatter_data).unwrap();
.load_data(&scatter_data)
.unwrap();

// Generate and save the chart.
Chart::new()
Expand All @@ -44,5 +50,6 @@ fn main() {
.add_axis_left(&y)
.add_left_axis_label("Custom X Axis Label")
.add_bottom_axis_label("Custom Y Axis Label")
.save("scatter-chart-multiple-keys.svg").unwrap();
}
.save("scatter-chart-multiple-keys.svg")
.unwrap();
}
15 changes: 10 additions & 5 deletions examples/scatter_chart_two_datasets.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use charts::{Chart, ScaleLinear, ScatterView, MarkerType, PointLabelPosition, Color, AxisPosition};
use charts::{
AxisPosition, Chart, Color, MarkerType, PointLabelPosition, ScaleLinear, ScatterView,
};

fn main() {
// Define chart related sizes.
Expand Down Expand Up @@ -32,7 +34,8 @@ fn main() {
.set_marker_type(MarkerType::Circle)
.set_label_position(PointLabelPosition::N)
.set_custom_data_label("Apples".to_owned())
.load_data(&scatter_data_1).unwrap();
.load_data(&scatter_data_1)
.unwrap();

// Create Scatter view that is going to represent the data as points.
let scatter_view_2 = ScatterView::new()
Expand All @@ -42,7 +45,8 @@ fn main() {
.set_label_position(PointLabelPosition::N)
.set_custom_data_label("Oranges".to_owned())
.set_colors(Color::from_vec_of_hex_strings(vec!["#aa0000"]))
.load_data(&scatter_data_2).unwrap();
.load_data(&scatter_data_2)
.unwrap();

// Generate and save the chart.
Chart::new()
Expand All @@ -57,5 +61,6 @@ fn main() {
.add_left_axis_label("Custom X Axis Label")
.add_bottom_axis_label("Custom Y Axis Label")
.add_legend_at(AxisPosition::Bottom)
.save("scatter-chart-two-datasets.svg").unwrap();
}
.save("scatter-chart-two-datasets.svg")
.unwrap();
}
24 changes: 18 additions & 6 deletions examples/stacked_horizontal_bar_chart.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use charts::{Chart, HorizontalBarView, ScaleBand, ScaleLinear, BarLabelPosition};
use charts::{BarLabelPosition, Chart, HorizontalBarView, ScaleBand, ScaleLinear};

fn main() {
// Define chart related sizes.
Expand All @@ -15,18 +15,29 @@ fn main() {
// Create a band scale that maps ["A", "B", "C"] categories to values in the [0, availableHeight]
// range (the height of the chart without the margins).
let y = ScaleBand::new()
.set_domain(vec![String::from("A"), String::from("B"), String::from("C")])
.set_domain(vec![
String::from("A"),
String::from("B"),
String::from("C"),
])
.set_range(vec![0, height - top - bottom]);

// You can use your own iterable as data as long as its items implement the `BarDatum` trait.
let data = vec![("A", 70, "foo"), ("B", 10, "foo"), ("C", 30, "foo"), ("A", 20, "bar"), ("A", 5, "baz")];
let data = vec![
("A", 70, "foo"),
("B", 10, "foo"),
("C", 30, "foo"),
("A", 20, "bar"),
("A", 5, "baz"),
];

// Create VerticalBar view that is going to represent the data as vertical bars.
let view = HorizontalBarView::new()
.set_x_scale(&x)
.set_y_scale(&y)
.set_label_position(BarLabelPosition::Center)
.load_data(&data).unwrap();
.load_data(&data)
.unwrap();

// Generate and save the chart.
Chart::new()
Expand All @@ -39,5 +50,6 @@ fn main() {
.add_axis_left(&y)
.add_left_axis_label("Y Axis Custom Label")
.add_bottom_axis_label("X Axis Custom Label")
.save("stacked-horizontal-bar-chart.svg").unwrap();
}
.save("stacked-horizontal-bar-chart.svg")
.unwrap();
}
24 changes: 18 additions & 6 deletions examples/stacked_vertical_bar_chart.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use charts::{Chart, VerticalBarView, ScaleBand, ScaleLinear, BarLabelPosition};
use charts::{BarLabelPosition, Chart, ScaleBand, ScaleLinear, VerticalBarView};

fn main() {
// Define chart related sizes.
Expand All @@ -9,7 +9,11 @@ fn main() {
// Create a band scale that maps ["A", "B", "C"] categories to values in [0, availableWidth]
// range (the width of the chart without the margins).
let x = ScaleBand::new()
.set_domain(vec![String::from("A"), String::from("B"), String::from("C")])
.set_domain(vec![
String::from("A"),
String::from("B"),
String::from("C"),
])
.set_range(vec![0, width - left - right]);

// Create a linear scale that will interpolate values in [0, 100] range to corresponding
Expand All @@ -22,15 +26,22 @@ fn main() {
.set_range(vec![height - top - bottom, 0]);

// You can use your own iterable as data as long as its items implement the `BarDatum` trait.
let data = vec![("A", 70, "foo"), ("B", 10, "foo"), ("C", 30, "foo"), ("A", 20, "bar"), ("A", 5, "baz")];
let data = vec![
("A", 70, "foo"),
("B", 10, "foo"),
("C", 30, "foo"),
("A", 20, "bar"),
("A", 5, "baz"),
];

// Create VerticalBar view that is going to represent the data as vertical bars.
let view = VerticalBarView::new()
.set_x_scale(&x)
.set_y_scale(&y)
// .set_label_visibility(false) // <-- uncomment this line to hide bar value labels
.set_label_position(BarLabelPosition::Center)
.load_data(&data).unwrap();
.load_data(&data)
.unwrap();

// Generate and save the chart.
Chart::new()
Expand All @@ -43,5 +54,6 @@ fn main() {
.add_axis_left(&y)
.add_left_axis_label("Units of Measurement")
.add_bottom_axis_label("Categories")
.save("stacked-vertical-bar-chart.svg").unwrap();
}
.save("stacked-vertical-bar-chart.svg")
.unwrap();
}
Loading