-
Notifications
You must be signed in to change notification settings - Fork 302
Advanced Flexbox Layout #259
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
base: master
Are you sure you want to change the base?
Changes from 7 commits
821a655
a9a477c
5c0f3a5
b403db3
353c6a6
9938d7b
79ec8f3
45cb820
6d81f7c
6f23207
6514ed9
1b85ad0
a9e7037
8cc45ea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
use plotters::prelude::*; | ||
|
||
const OUT_FILE_NAME: &'static str = "plotters-doc-data/layout2.png"; | ||
|
||
fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
const W: u32 = 600; | ||
const H: u32 = 400; | ||
let root = BitMapBackend::new(OUT_FILE_NAME, (W, H)).into_drawing_area(); | ||
root.fill(&full_palette::WHITE)?; | ||
|
||
let mut chart = ChartLayout::new(&root); | ||
chart | ||
.set_chart_title_text("Chart Title")? | ||
.set_chart_title_style(("serif", 60.).into_font().with_color(&RED))? | ||
.set_left_label_text("Ratio of Sides")? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, this seems odd as we also have https://docs.rs/plotters/0.3.1/plotters/chart/struct.MeshStyle.html#method.x_desc which have the similar effect. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess this should be a broader discussion about how charts should be configured and what belongs to the chart vs. the coordinate system. The way plotters seems to do it now is to attach labels to the coordinate system and then adjust whether the axes are printed to the left right/etc. Since I think that maybe the best solution would be to have both. If you set via the coordinate system, it would automatically call the What do you think? |
||
.set_right_label_text("Right label")? | ||
.set_bottom_label_text("Radians")? | ||
.set_bottom_label_margin(10.)? | ||
.set_left_label_margin(10.)? | ||
.set_right_label_margin(10.)? | ||
.draw()?; | ||
|
||
// If we extract a drawing area corresponding to a chart area, we can | ||
// use the usual chart API to draw. | ||
let da_chart = chart.get_chart_drawing_area()?; | ||
let x_axis = (-3.4f32..3.4).step(0.1); | ||
let mut cc = ChartBuilder::on(&da_chart) | ||
.margin(5) | ||
.set_all_label_area_size(15) | ||
.build_cartesian_2d(-3.4f32..3.4, -1.2f32..1.2f32)?; | ||
|
||
cc.configure_mesh() | ||
.x_labels(20) | ||
.y_labels(10) | ||
.disable_mesh() | ||
.x_label_formatter(&|v| format!("{:.1}", v)) | ||
.y_label_formatter(&|v| format!("{:.1}", v)) | ||
.draw()?; | ||
|
||
cc.draw_series(LineSeries::new(x_axis.values().map(|x| (x, x.sin())), &RED))? | ||
.label("Sine") | ||
.legend(|(x, y)| PathElement::new(vec![(x, y), (x + 20, y)], &RED)); | ||
|
||
cc.draw_series(LineSeries::new( | ||
x_axis.values().map(|x| (x, x.cos())), | ||
&BLUE, | ||
))? | ||
.label("Cosine") | ||
.legend(|(x, y)| PathElement::new(vec![(x, y), (x + 20, y)], &BLUE)); | ||
|
||
cc.configure_series_labels().border_style(&BLACK).draw()?; | ||
|
||
siefkenj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Ok(()) | ||
} | ||
#[test] | ||
fn entry_point() { | ||
main().unwrap() | ||
} |
Uh oh!
There was an error while loading. Please reload this page.