Adds the much needed graph generation functions

This commit is contained in:
Dandaedre 2024-06-25 03:36:34 +02:00
parent 2ece26aac0
commit 0f0ec8c8f0
6 changed files with 65 additions and 18 deletions

2
.gitignore vendored
View File

@ -21,3 +21,5 @@ Cargo.lock
# Added by cargo
/target
.cargo/

View File

@ -8,7 +8,7 @@ edition = "2021"
[dependencies]
anyhow = "1.0.86"
charts-rs = { version = "0.3.11", features = ["image-encoder"] }
charts-rs = { version = "0.3.11" }
clap = { version = "4.5.7", features = ["derive"] }
console = "0.15.8"
csv = "1.3.0"

BIN
data/lmroman8-regular.ttf Normal file

Binary file not shown.

View File

@ -1,9 +1,9 @@
//! Export graphs
use charts_rs::{Box, Color, THEME_ANT};
use charts_rs::{get_or_try_init_fonts, RadarChart, RadarIndicator, Series};
use std::process::Command;
use charts_rs::{Box, Color, THEME_ANT};
use glob::glob;
use std::process::Command;
use std::{f32, fs::File, io::Write, iter, sync::LazyLock};
use anyhow::{Context, Result};
@ -49,12 +49,16 @@ pub(super) fn make_graphs(args: &GraphConfig, _config: &Config) -> Result<()> {
/// Delete the existing graphs
fn del_graphs(_args: &GraphConfig) -> Result<()> {
let mut cmd = Command::new("rm");
cmd.args(glob("Images/Radar/*.svg")?
.map(|v| v.unwrap().to_str().unwrap().to_string())
.collect::<Vec<String>>());
cmd.args(glob("Images/Radar/*.png")?
.map(|v| v.unwrap().to_str().unwrap().to_string())
.collect::<Vec<String>>());
cmd.args(
glob("Images/Radar/*.svg")?
.map(|v| v.unwrap().to_str().unwrap().to_string())
.collect::<Vec<String>>(),
);
cmd.args(
glob("Images/Radar/*.png")?
.map(|v| v.unwrap().to_str().unwrap().to_string())
.collect::<Vec<String>>(),
);
if let Err(e) = cmd.output() {
println!(
@ -79,26 +83,50 @@ fn gen_graph(args: &GraphConfig) -> Result<()> {
for graph in csv.values {
// println!("{:?} {:#?}", maxv, graph);
// let path = format!("{}/{}.png", args.destination, &graph.name);
let path = format!("{}/{}.svg", args.destination, &graph.name);
println!("[INFO] Processing {}",path);
let path_svg = format!("{}/{}.svg", args.destination, &graph.name);
let path_png = format!("{}/{}.png", args.destination, &graph.name);
println!("[INFO] Processing {}", path_svg);
let mut f = File::create(path)?;
let mut f = File::create(&path_svg)?;
let mut r = RadarChart::new_with_theme([graph].to_vec(), maxv.to_vec(), THEME_ANT);
r.legend_show = Some(false);
r.margin = Box{ left: -90.0, top: -20.0, right: -90.0, bottom: -30.0 };
r.margin = Box {
left: -90.0,
top: -20.0,
right: -90.0,
bottom: -30.0,
};
r.width = 800.0;
r.height = 600.0;
r.series_label_font_size = 20.0;
// r.grid_stroke_color = vec![Color{ r: 75,g: 114, b: 110, a: 0 }];
r.series_colors = vec![Color{ r: 0,g:127, b:142, a: 255}];
r.series_colors = vec![Color {
r: 0,
g: 127,
b: 142,
a: 255,
}];
// r.series_colors = vec![Color{ r: 140,g:170, b:161, a: 255}];
// r.series_colors = vec![Color{ r:150,g:251, b:199, a: 255 }];
r.font_family = "LMRoman8".to_string();
// f.write_all(&charts_rs::svg_to_png(r.svg().context("Converting to svg")?.as_str())?)?;
f.write_all(r.svg().context("Converting to SVG")?.as_bytes())?;
let mut cmd = Command::new("convert");
cmd.arg("--size")
.arg("800x600")
.arg(&path_svg)
.arg(path_png);
println!("[INFO] Using convert cli to convert to png");
if let Err(e) = cmd.output() {
println!(
"[ERRR] An error has occured when converting the file {} to png \n {:#?}",
path_svg, e
)
}
}
Ok(())
}

View File

@ -61,6 +61,10 @@ pub(super) struct MakeConfig {
/// Wether to add the initial and final context
#[arg(short = 'C', long, action = clap::ArgAction::SetFalse)]
pub(super) no_context: bool,
/// Activate shell escape
#[arg(short , long)]
pub(super) shell_escape: bool,
}
/// Make a pdf spawning a subprocess
@ -110,11 +114,15 @@ async fn launch_subprocess(
let last_run = BuildInfo::load(args);
let mut built = 0;
let to_build = last_run.lines_parsed;
let mut to_build = last_run.lines_parsed;
if args.non_interactive {
cmd.arg("--interaction=nonstopmode");
}
if args.shell_escape {
cmd.arg("--shell-escape");
}
cmd.arg(&rebuild_target.new_name);
cmd.env("max_print_line", "3000");
// Specify that we want the command's standard output piped back to us.
@ -158,9 +166,17 @@ async fn launch_subprocess(
loop {
let res = reader.next_segment().await;
let new = min(built + 1, to_build);
// let new = min(built + 1, to_build);
let new = if built < to_build{
built+1
} else{
to_build +=1;
pb.set_length(to_build);
built+1
};
built = new;
pb.set_position(new);
current_run.lines_parsed += 1;
if let Err(e) = res {
return Err(anyhow!("[CORE] Runtime error : {}", e));

View File

@ -242,6 +242,7 @@ pub(super) enum LineType {
LaTexVersion,
/// The write18 mode, whatever that is
#[token(" restricted \\write18 enabled.")]
#[token(" \\write18 enabled.")]
WriteMode,
/// The class of document (book, article, etc)