Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix setter for Axis::matches to take string arg #178

Merged
merged 4 commits into from
Jun 19, 2024
Merged
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
46 changes: 46 additions & 0 deletions examples/subplots/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,50 @@ fn simple_subplot() {
plot.show();
}

fn simple_subplot_matches_x_axis() {
let trace1 = Scatter::new(vec![1, 2, 3], vec![4, 5, 6]).name("trace1");
let trace2 = Scatter::new(vec![20, 30, 40], vec![50, 60, 70])
.name("trace2")
.x_axis("x2")
.y_axis("y2");

let mut plot = Plot::new();
plot.add_trace(trace1);
plot.add_trace(trace2);

let layout = Layout::new().x_axis(Axis::new().matches("x2")).grid(
LayoutGrid::new()
.rows(1)
.columns(2)
.pattern(GridPattern::Independent),
);
plot.set_layout(layout);

plot.show();
}

fn simple_subplot_matches_y_axis() {
let trace1 = Scatter::new(vec![1, 2, 3], vec![4, 5, 6]).name("trace1");
let trace2 = Scatter::new(vec![20, 30, 40], vec![50, 60, 70])
.name("trace2")
.x_axis("x2")
.y_axis("y2");

let mut plot = Plot::new();
plot.add_trace(trace1);
plot.add_trace(trace2);

let layout = Layout::new().y_axis(Axis::new().matches("y2")).grid(
LayoutGrid::new()
.rows(1)
.columns(2)
.pattern(GridPattern::Independent),
);
plot.set_layout(layout);

plot.show();
}

fn custom_sized_subplot() {
let trace1 = Scatter::new(vec![1, 2, 3], vec![4, 5, 6]).name("trace1");
let trace2 = Scatter::new(vec![20, 30, 40], vec![50, 60, 70])
Expand Down Expand Up @@ -289,6 +333,8 @@ fn main() {

// Subplots
// simple_subplot();
// simple_subplot_matches_x_axis();
// simple_subplot_matches_y_axis();
// custom_sized_subplot();
// multiple_subplots();
// stacked_subplots();
Expand Down
8 changes: 3 additions & 5 deletions plotly/src/layout/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -546,10 +546,8 @@ impl Axis {
Default::default()
}

pub fn matches(mut self, matches: bool) -> Self {
if matches {
self.matches = Some(String::from("x"));
}
pub fn matches(mut self, matches: &str) -> Self {
self.matches = Some(matches.to_string());
self
}

Expand Down Expand Up @@ -2444,7 +2442,7 @@ mod tests {
.n_ticks(600)
.tick0(5.0)
.dtick(10.0)
.matches(true)
.matches("x")
.tick_values(vec![1.0, 2.0])
.tick_text(vec!["one".to_string(), "two".to_string()])
.ticks(TicksDirection::Inside)
Expand Down
Loading