Compare commits
1 Commits
plot-popup
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 0c2588a299 |
@@ -8,11 +8,11 @@ use std::{
|
|||||||
|
|
||||||
use ratatui::{
|
use ratatui::{
|
||||||
DefaultTerminal, Frame,
|
DefaultTerminal, Frame,
|
||||||
crossterm::event::{self, KeyCode},
|
crossterm::event,
|
||||||
layout::{self, Constraint, Layout, Margin, Rect},
|
layout::{self, Constraint, Layout, Rect},
|
||||||
prelude,
|
prelude,
|
||||||
style::{Color, Modifier, Style},
|
style::{Color, Modifier, Style},
|
||||||
widgets::{Block, Borders, Paragraph, Widget},
|
widgets::{Paragraph, Widget},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::app::{
|
use crate::app::{
|
||||||
@@ -20,7 +20,6 @@ use crate::app::{
|
|||||||
error_msg::StatusMessage,
|
error_msg::StatusMessage,
|
||||||
logic::{calc::Grid, cell::CellType},
|
logic::{calc::Grid, cell::CellType},
|
||||||
mode::Mode,
|
mode::Mode,
|
||||||
plot::Plot,
|
|
||||||
screen::ScreenSpace,
|
screen::ScreenSpace,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -36,7 +35,6 @@ pub struct App {
|
|||||||
// this could probably be a normal array
|
// this could probably be a normal array
|
||||||
pub marks: HashMap<char, (usize, usize)>,
|
pub marks: HashMap<char, (usize, usize)>,
|
||||||
pub clipboard: Clipboard,
|
pub clipboard: Clipboard,
|
||||||
pub plot_popup: Option<Plot>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Widget for &App {
|
impl Widget for &App {
|
||||||
@@ -44,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)) | Mode::VisualCmd((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;
|
||||||
@@ -219,7 +217,6 @@ impl App {
|
|||||||
marks: HashMap::new(),
|
marks: HashMap::new(),
|
||||||
clipboard: Clipboard::new(),
|
clipboard: Clipboard::new(),
|
||||||
file_modified_date: SystemTime::now(),
|
file_modified_date: SystemTime::now(),
|
||||||
plot_popup: None,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -318,46 +315,9 @@ impl App {
|
|||||||
)),
|
)),
|
||||||
cmd_line_debug,
|
cmd_line_debug,
|
||||||
);
|
);
|
||||||
|
|
||||||
// popups
|
|
||||||
if let Some(plot) = &self.plot_popup {
|
|
||||||
let block = Block::default()
|
|
||||||
.title("Plot Editor")
|
|
||||||
.title_alignment(layout::Alignment::Center)
|
|
||||||
.border_type(ratatui::widgets::BorderType::Rounded)
|
|
||||||
.borders(Borders::all())
|
|
||||||
.style(Style::default().fg(Color::White));
|
|
||||||
let popup_y = 20;
|
|
||||||
let popup_x = 40;
|
|
||||||
|
|
||||||
let a = frame.area();
|
|
||||||
let xpos = (a.width / 2) - (popup_x / 2);
|
|
||||||
let ypos = (a.height / 2) - (popup_y / 2);
|
|
||||||
let area = Rect::new(xpos, ypos, popup_x, popup_y);
|
|
||||||
|
|
||||||
frame.render_widget(ratatui::widgets::Clear, area);
|
|
||||||
frame.render_widget(block, area);
|
|
||||||
|
|
||||||
let area = area.inner(Margin::new(1, 1));
|
|
||||||
frame.render_widget(plot, area);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_events(&mut self) -> io::Result<()> {
|
fn handle_events(&mut self) -> io::Result<()> {
|
||||||
if let Some(plot) = &mut self.plot_popup {
|
|
||||||
if let event::Event::Key(key) = event::read()? {
|
|
||||||
match key.code {
|
|
||||||
KeyCode::Esc => self.plot_popup = None,
|
|
||||||
KeyCode::PrintScreen | KeyCode::Enter => unimplemented!("Generate plot data"),
|
|
||||||
KeyCode::Delete => plot.del_column(),
|
|
||||||
KeyCode::Insert => plot.add_column(),
|
|
||||||
KeyCode::Char(c) => plot.process_key(c),
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
|
|
||||||
match &mut self.mode {
|
match &mut self.mode {
|
||||||
Mode::VisualCmd(pos, chord) => match event::read()? {
|
Mode::VisualCmd(pos, chord) => match event::read()? {
|
||||||
event::Event::Key(key) => match key.code {
|
event::Event::Key(key) => match key.code {
|
||||||
|
|||||||
@@ -3,5 +3,4 @@ mod mode;
|
|||||||
mod error_msg;
|
mod error_msg;
|
||||||
mod screen;
|
mod screen;
|
||||||
mod logic;
|
mod logic;
|
||||||
mod clipboard;
|
mod clipboard;
|
||||||
mod plot;
|
|
||||||
@@ -17,7 +17,7 @@ use crate::app::{
|
|||||||
logic::{
|
logic::{
|
||||||
calc::{CSV_EXT, CUSTOM_EXT, Grid, LEN},
|
calc::{CSV_EXT, CUSTOM_EXT, Grid, LEN},
|
||||||
cell::CellType,
|
cell::CellType,
|
||||||
}, plot::Plot,
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub enum Mode {
|
pub enum Mode {
|
||||||
@@ -198,8 +198,6 @@ impl Mode {
|
|||||||
app.mode = Mode::Normal
|
app.mode = Mode::Normal
|
||||||
}
|
}
|
||||||
"plot" => {
|
"plot" => {
|
||||||
app.plot_popup = Some(Plot::new(0, 1));
|
|
||||||
return;
|
|
||||||
// Use gnuplot to plot the selected data.
|
// Use gnuplot to plot the selected data.
|
||||||
// * Temp data will be stored in /tmp/
|
// * Temp data will be stored in /tmp/
|
||||||
// * Output will either be plot.png or a name that you pass in
|
// * Output will either be plot.png or a name that you pass in
|
||||||
|
|||||||
@@ -1,45 +0,0 @@
|
|||||||
use ratatui::{layout::{Constraint, Direction, Layout}, widgets::{Paragraph, Widget}};
|
|
||||||
|
|
||||||
pub struct Plot {
|
|
||||||
x: usize,
|
|
||||||
y: Vec<usize>,
|
|
||||||
}
|
|
||||||
impl Plot {
|
|
||||||
pub fn new(x: usize, y: usize) -> Self {
|
|
||||||
Self {
|
|
||||||
x,
|
|
||||||
y: vec![y],
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn add_column(&mut self) {
|
|
||||||
self.y.push(1)
|
|
||||||
}
|
|
||||||
pub fn del_column(&mut self) {
|
|
||||||
self.y.pop();
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn process_key(&mut self, c: char) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Widget for &Plot {
|
|
||||||
fn render(self, area: ratatui::prelude::Rect, buf: &mut ratatui::prelude::Buffer) {
|
|
||||||
// plus 1 for x
|
|
||||||
let columns = self.y.len() + 1;
|
|
||||||
|
|
||||||
let mut constraints = Vec::new();
|
|
||||||
for _ in 0..=columns {
|
|
||||||
constraints.push(Constraint::Min(1));
|
|
||||||
}
|
|
||||||
|
|
||||||
Paragraph::new("Foobar").render(area, buf);
|
|
||||||
let layout = Layout::default()
|
|
||||||
.direction(Direction::Vertical)
|
|
||||||
.constraints(constraints)
|
|
||||||
.split(area);
|
|
||||||
|
|
||||||
let x_space = layout[0];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -14,4 +14,5 @@ set grid
|
|||||||
set term png size 1280, 720
|
set term png size 1280, 720
|
||||||
set output '$OUTPUT'
|
set output '$OUTPUT'
|
||||||
plot datafile using 1:2 with linespoints linestyle 1
|
plot datafile using 1:2 with linespoints linestyle 1
|
||||||
|
# plot datafile using 1:2 with linespoints linestyle 1, datafile using 1:3, etc...
|
||||||
replot
|
replot
|
||||||
|
|||||||
Reference in New Issue
Block a user