chart by tr_type

This commit is contained in:
thatscringebro
2026-03-31 13:59:58 -04:00
parent 69686460b2
commit 35379214e9
3 changed files with 63 additions and 8 deletions

View File

@@ -18,6 +18,8 @@ pub struct App {
pub tabs: Vec<String>,
pub error: String,
pub error_showing: bool,
pub selected_tr_type_chart: i64,
pub selected_tr_type_chart_desc: String,
pub connection: Connection,
}
@@ -32,6 +34,7 @@ impl App {
};
data_layer::setup(&con);
let tr_types = data_layer::get_transaction_types(&con);
return App {
current_screen: CurrentScreen::Main,
@@ -43,17 +46,24 @@ impl App {
selected_transaction_input: TransactionInput::Type,
selected_account_input: AccountInput::Asset,
current_input: String::new(),
tr_types: data_layer::get_transaction_types(&con),
tr_types: tr_types.clone(),
selected_tab: 0,
tabs: [
"Transactions".to_string(),
"Épicerie".to_string(),
"Amnt by Type".to_string(),
"Chart 2".to_string(),
"Chart 3".to_string(),
]
.to_vec(),
error: String::new(),
error_showing: false,
selected_tr_type_chart: 1,
selected_tr_type_chart_desc: tr_types
.iter()
.filter(|x| x.get_id() == 1)
.next()
.unwrap()
.get_description(),
connection: con,
};
}
@@ -295,11 +305,22 @@ impl App {
}
}
pub fn get_trtype_data(&self, tr_type_id: i64) -> Vec<(f64, f64)> {
pub fn get_trtype_data(&self) -> Vec<(f64, f64)> {
return data_layer::get_tr_type_price_over_time(
&self.connection,
self.acc_list.get_selected_id(),
tr_type_id,
self.selected_tr_type_chart,
);
}
pub fn select_tr_type_chart(&mut self, id: i64) {
self.selected_tr_type_chart = id;
self.selected_tr_type_chart_desc = self
.tr_types
.iter()
.filter(|x| x.get_id() == id)
.next()
.unwrap()
.get_description();
}
}

View File

@@ -132,7 +132,17 @@ where
app.set_current_input_tr();
}
},
_ => {}
_ => {
if let CurrentWidget::TrxList = app.current_widget
&& app.selected_tab == 1
{
let char_u = key.code.to_string().parse::<i64>();
match char_u {
Ok(c) => app.select_tr_type_chart(c),
_ => {}
}
}
}
},
CurrentScreen::NewAccount => match key.code {
KeyCode::Down => {

View File

@@ -106,7 +106,7 @@ pub fn ui(frame: &mut Frame, app: &mut App) {
&mut app.trx_table.state,
);
} else if app.selected_tab == 1 {
let slice: &[(f64, f64)] = &app.get_trtype_data(1);
let slice: &[(f64, f64)] = &app.get_trtype_data();
let dataset = Dataset::default()
.marker(Marker::Braille)
.graph_type(GraphType::Line)
@@ -151,10 +151,34 @@ pub fn ui(frame: &mut Frame, app: &mut App) {
.labels([min_y.to_string(), max_y.to_string()]);
let chart = Chart::new(vec![dataset])
.block(trx_block)
.block(trx_block.clone())
.x_axis(x_axis)
.y_axis(y_axis);
frame.render_widget(chart, right_layout[1]);
let p = Paragraph::new(app.selected_tr_type_chart_desc.clone())
.block(trx_block)
.style(Style::default())
.alignment(ratatui::layout::HorizontalAlignment::Center);
frame.render_widget(p, right_layout[1]);
let helper = Block::default()
.title("Helper")
.borders(Borders::all())
.style(Style::default());
let helper_string: String = app
.tr_types
.iter()
.map(|tr_type| tr_type.get_id().to_string() + " " + &tr_type.get_description() + "\n")
.collect();
let helper_text = Text::styled(helper_string, Style::default());
let helper_paragraph = Paragraph::new(helper_text)
.block(helper)
.wrap(Wrap { trim: false });
let area = helper_rect(frame.area());
frame.render_widget(Clear, area);
frame.render_widget(helper_paragraph, area);
} else {
let p = Paragraph::new("Tab not implemented")
.block(trx_block)
@@ -346,7 +370,7 @@ fn helper_rect(r: Rect) -> Rect {
return Layout::default()
.direction(Direction::Horizontal)
.constraints([Constraint::Percentage(30), Constraint::Percentage(70)])
.constraints([Constraint::Percentage(20), Constraint::Percentage(70)])
.split(popup_layout[1])[0];
}