()
| 365 | |
| 366 | #[test] |
| 367 | fn test_plot_tick_labels() -> Result<(), StrError> { |
| 368 | // data |
| 369 | let vegetables = [ |
| 370 | "cucumber", |
| 371 | "tomato", |
| 372 | "lettuce", |
| 373 | "asparagus", |
| 374 | "potato", |
| 375 | "wheat", |
| 376 | "barley", |
| 377 | ]; |
| 378 | let farmers = [ |
| 379 | "Farmer Joe", |
| 380 | "Upland Bros.", |
| 381 | "Smith Gardening", |
| 382 | "Agrifun", |
| 383 | "Organiculture", |
| 384 | "BioGoods Ltd.", |
| 385 | "Cornylee Corp.", |
| 386 | ]; |
| 387 | let harvest = [ |
| 388 | [0.8, 2.4, 2.5, 3.9, 0.0, 4.0, 0.0], |
| 389 | [2.4, 0.0, 4.0, 1.0, 2.7, 0.0, 0.0], |
| 390 | [1.1, 2.4, 0.8, 4.3, 1.9, 4.4, 0.0], |
| 391 | [0.6, 0.0, 0.3, 0.0, 3.1, 0.0, 0.0], |
| 392 | [0.7, 1.7, 0.6, 2.6, 2.2, 6.2, 0.0], |
| 393 | [1.3, 1.2, 0.0, 0.0, 0.0, 3.2, 5.1], |
| 394 | [0.1, 2.0, 0.0, 1.4, 0.0, 1.9, 6.3], |
| 395 | ]; |
| 396 | |
| 397 | // draw image |
| 398 | let mut img = Image::new(); |
| 399 | img.draw(&harvest); |
| 400 | |
| 401 | // set tick labels |
| 402 | let mut plot = Plot::new(); |
| 403 | let ticks: Vec<_> = (0..vegetables.len()).into_iter().collect(); |
| 404 | plot.add(&img) |
| 405 | .set_rotation_ticks_x(45.0) |
| 406 | .set_ticks_x_labels(&ticks, &farmers) |
| 407 | .set_ticks_y_labels(&ticks, &vegetables); |
| 408 | |
| 409 | // add text |
| 410 | let mut text = Text::new(); |
| 411 | text.set_color("white").set_align_horizontal("center"); |
| 412 | for i in 0..vegetables.len() { |
| 413 | for j in 0..farmers.len() { |
| 414 | text.draw(j as f64, i as f64, harvest[i][j].to_string().as_str()); |
| 415 | } |
| 416 | } |
| 417 | plot.add(&text); |
| 418 | |
| 419 | // save figure |
| 420 | let path = Path::new(OUT_DIR).join("integ_plot_tick_labels.svg"); |
| 421 | plot.set_show_errors(true).save(&path)?; |
| 422 | |
| 423 | // check number of lines |
| 424 | let file = File::open(path).map_err(|_| "cannot open file")?; |
nothing calls this directly
no test coverage detected