Compare commits
2 Commits
1323d15333
...
0c527bb3cb
| Author | SHA1 | Date | |
|---|---|---|---|
| 0c527bb3cb | |||
| 6ca21b407d |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -2,3 +2,4 @@
|
|||||||
/.vscode
|
/.vscode
|
||||||
/*.csv
|
/*.csv
|
||||||
/*.nscim
|
/*.nscim
|
||||||
|
/plot.png
|
||||||
@@ -42,7 +42,7 @@ impl Widget for &App {
|
|||||||
let (x_max, y_max) = self.screen.how_many_cells_fit_in(&area, &self.vars);
|
let (x_max, y_max) = self.screen.how_many_cells_fit_in(&area, &self.vars);
|
||||||
|
|
||||||
let is_selected = |x: usize, y: usize| -> bool {
|
let is_selected = |x: usize, y: usize| -> bool {
|
||||||
if let Mode::Visual((mut x1, mut y1)) = self.mode {
|
if let Mode::Visual((mut x1, mut y1)) | Mode::VisualCmd((mut x1, mut y1), _)= self.mode {
|
||||||
let (mut x2, mut y2) = self.grid.cursor();
|
let (mut x2, mut y2) = self.grid.cursor();
|
||||||
x1 += 1;
|
x1 += 1;
|
||||||
y1 += 1;
|
y1 += 1;
|
||||||
@@ -80,10 +80,6 @@ impl Widget for &App {
|
|||||||
y_idx = y as usize - 1 + self.screen.scroll_y();
|
y_idx = y as usize - 1 + self.screen.scroll_y();
|
||||||
}
|
}
|
||||||
|
|
||||||
if is_selected(x.into(), y.into()) {
|
|
||||||
style = style.fg(Color::LightMagenta).bg(Color::Blue);
|
|
||||||
}
|
|
||||||
|
|
||||||
const ORANGE1: Color = Color::Rgb(200, 160, 0);
|
const ORANGE1: Color = Color::Rgb(200, 160, 0);
|
||||||
const ORANGE2: Color = Color::Rgb(180, 130, 0);
|
const ORANGE2: Color = Color::Rgb(180, 130, 0);
|
||||||
|
|
||||||
@@ -171,6 +167,10 @@ impl Widget for &App {
|
|||||||
}
|
}
|
||||||
None => should_render = false,
|
None => should_render = false,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if is_selected(x.into(), y.into()) {
|
||||||
|
style = style.bg(Color::Blue);
|
||||||
|
}
|
||||||
if (x_idx, y_idx) == self.grid.cursor() {
|
if (x_idx, y_idx) == self.grid.cursor() {
|
||||||
should_render = true;
|
should_render = true;
|
||||||
style = Style::new().fg(Color::Black).bg(Color::White);
|
style = Style::new().fg(Color::Black).bg(Color::White);
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
use std::{
|
use std::{
|
||||||
cmp::{max, min}, fmt::Display, fs, path::PathBuf
|
cmp::{max, min},
|
||||||
|
fmt::Display,
|
||||||
|
fs,
|
||||||
|
path::PathBuf, process::Command,
|
||||||
};
|
};
|
||||||
|
|
||||||
use ratatui::{
|
use ratatui::{
|
||||||
@@ -12,7 +15,7 @@ use crate::app::{
|
|||||||
app::App,
|
app::App,
|
||||||
error_msg::StatusMessage,
|
error_msg::StatusMessage,
|
||||||
logic::{
|
logic::{
|
||||||
calc::{CSV_EXT, CUSTOM_EXT, LEN},
|
calc::{CSV_EXT, CUSTOM_EXT, Grid, LEN},
|
||||||
cell::CellType,
|
cell::CellType,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@@ -152,8 +155,73 @@ impl Mode {
|
|||||||
if args.is_empty() {
|
if args.is_empty() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// These values are going to be used in probably all
|
||||||
|
// the commands related to ranges, we will just write
|
||||||
|
// logic here first, once.
|
||||||
|
let (x1, y1) = pos;
|
||||||
|
let (x1, y1) = (*x1, *y1);
|
||||||
|
let (x2, y2) = app.grid.cursor();
|
||||||
|
let (low_x, hi_x) = if x1 < x2 { (x1, x2) } else { (x2, x1) };
|
||||||
|
let (low_y, hi_y) = if y1 < y2 { (y1, y2) } else { (y2, y1) };
|
||||||
|
|
||||||
|
let mut save_range = |to: &str| {
|
||||||
|
let mut g = Grid::new();
|
||||||
|
for (i, x) in (low_x..=hi_x).enumerate() {
|
||||||
|
for (j, y) in (low_y..=hi_y).enumerate() {
|
||||||
|
g.set_cell_raw((i, j), app.grid.get_cell_raw(x, y).clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if let Err(_e) = g.save_to(to) {
|
||||||
|
app.msg = StatusMessage::error("Failed to save file");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let get_project_name = || {
|
||||||
|
if let Some(file) = &app.file {
|
||||||
|
if let Some(name) = file.file_name() {
|
||||||
|
if let Some(name) = name.to_str() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "unknown"
|
||||||
|
};
|
||||||
|
|
||||||
match args[0] {
|
match args[0] {
|
||||||
"foo" => {}
|
"export" => {
|
||||||
|
if let Some(arg1) = args.get(1) {
|
||||||
|
save_range(&arg1);
|
||||||
|
} else {
|
||||||
|
app.msg = StatusMessage::error("export <path.csv>")
|
||||||
|
}
|
||||||
|
app.mode = Mode::Normal
|
||||||
|
}
|
||||||
|
"plot" => {
|
||||||
|
// Use gnuplot to plot the selected data.
|
||||||
|
// * Temp data will be stored in /tmp/
|
||||||
|
// * Output will either be plot.png or a name that you pass in
|
||||||
|
let output_filename = if let Some(arg1) = args.get(1) {
|
||||||
|
arg1
|
||||||
|
} else {
|
||||||
|
"plot.png"
|
||||||
|
};
|
||||||
|
|
||||||
|
save_range("/tmp/plot.csv");
|
||||||
|
let plot = include_str!("../../template.gnuplot");
|
||||||
|
let s = plot.replace("$FILE", "/tmp/plot.csv");
|
||||||
|
let s = s.replace("$TITLE", get_project_name());
|
||||||
|
let s = s.replace("$XLABEL", "hard-coded x");
|
||||||
|
let s = s.replace("$YLABEL", "hard-coded y");
|
||||||
|
let s = s.replace("$OUTPUT", "/tmp/output.png");
|
||||||
|
let _ = fs::write("/tmp/plot.p", s);
|
||||||
|
|
||||||
|
let _ = Command::new("gnuplot").arg("/tmp/plot.p").output();
|
||||||
|
let _ = fs::copy("/tmp/output.png", output_filename);
|
||||||
|
|
||||||
|
app.msg = StatusMessage::info("Wrote gnuplot data to /tmp");
|
||||||
|
app.mode = Mode::Normal
|
||||||
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
datafile = 'data.csv'
|
datafile = '$FILE'
|
||||||
set datafile separator ','
|
set datafile separator ','
|
||||||
|
|
||||||
set title 'Probably the filename'
|
set title '$TITLE'
|
||||||
set key autotitle columnhead
|
set key autotitle columnhead
|
||||||
set xlabel "x"
|
set xlabel "$XLABEL"
|
||||||
set ylabel "y"
|
set ylabel "$YLABEL"
|
||||||
|
|
||||||
set style line 1 linewidth 2 linecolor 1 pointtype 7 pointsize 1.5
|
set style line 1 linewidth 2 linecolor 1 pointtype 7 pointsize 1.5
|
||||||
|
|
||||||
@@ -12,6 +12,6 @@ set autoscale
|
|||||||
set grid
|
set grid
|
||||||
|
|
||||||
set term png size 1280, 720
|
set term png size 1280, 720
|
||||||
set output 'output.png'
|
set output '$OUTPUT'
|
||||||
plot datafile using 1:2 with linespoints linestyle 1
|
plot datafile using 1:2 with linespoints linestyle 1
|
||||||
replot
|
replot
|
||||||
Reference in New Issue
Block a user