chart by tr_type
This commit is contained in:
29
src/app.rs
29
src/app.rs
@@ -18,6 +18,8 @@ pub struct App {
|
|||||||
pub tabs: Vec<String>,
|
pub tabs: Vec<String>,
|
||||||
pub error: String,
|
pub error: String,
|
||||||
pub error_showing: bool,
|
pub error_showing: bool,
|
||||||
|
pub selected_tr_type_chart: i64,
|
||||||
|
pub selected_tr_type_chart_desc: String,
|
||||||
pub connection: Connection,
|
pub connection: Connection,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,6 +34,7 @@ impl App {
|
|||||||
};
|
};
|
||||||
|
|
||||||
data_layer::setup(&con);
|
data_layer::setup(&con);
|
||||||
|
let tr_types = data_layer::get_transaction_types(&con);
|
||||||
|
|
||||||
return App {
|
return App {
|
||||||
current_screen: CurrentScreen::Main,
|
current_screen: CurrentScreen::Main,
|
||||||
@@ -43,17 +46,24 @@ impl App {
|
|||||||
selected_transaction_input: TransactionInput::Type,
|
selected_transaction_input: TransactionInput::Type,
|
||||||
selected_account_input: AccountInput::Asset,
|
selected_account_input: AccountInput::Asset,
|
||||||
current_input: String::new(),
|
current_input: String::new(),
|
||||||
tr_types: data_layer::get_transaction_types(&con),
|
tr_types: tr_types.clone(),
|
||||||
selected_tab: 0,
|
selected_tab: 0,
|
||||||
tabs: [
|
tabs: [
|
||||||
"Transactions".to_string(),
|
"Transactions".to_string(),
|
||||||
"Épicerie".to_string(),
|
"Amnt by Type".to_string(),
|
||||||
"Chart 2".to_string(),
|
"Chart 2".to_string(),
|
||||||
"Chart 3".to_string(),
|
"Chart 3".to_string(),
|
||||||
]
|
]
|
||||||
.to_vec(),
|
.to_vec(),
|
||||||
error: String::new(),
|
error: String::new(),
|
||||||
error_showing: false,
|
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,
|
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(
|
return data_layer::get_tr_type_price_over_time(
|
||||||
&self.connection,
|
&self.connection,
|
||||||
self.acc_list.get_selected_id(),
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
10
src/main.rs
10
src/main.rs
@@ -132,7 +132,17 @@ where
|
|||||||
app.set_current_input_tr();
|
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 {
|
CurrentScreen::NewAccount => match key.code {
|
||||||
KeyCode::Down => {
|
KeyCode::Down => {
|
||||||
|
|||||||
30
src/ui.rs
30
src/ui.rs
@@ -106,7 +106,7 @@ pub fn ui(frame: &mut Frame, app: &mut App) {
|
|||||||
&mut app.trx_table.state,
|
&mut app.trx_table.state,
|
||||||
);
|
);
|
||||||
} else if app.selected_tab == 1 {
|
} 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()
|
let dataset = Dataset::default()
|
||||||
.marker(Marker::Braille)
|
.marker(Marker::Braille)
|
||||||
.graph_type(GraphType::Line)
|
.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()]);
|
.labels([min_y.to_string(), max_y.to_string()]);
|
||||||
|
|
||||||
let chart = Chart::new(vec![dataset])
|
let chart = Chart::new(vec![dataset])
|
||||||
.block(trx_block)
|
.block(trx_block.clone())
|
||||||
.x_axis(x_axis)
|
.x_axis(x_axis)
|
||||||
.y_axis(y_axis);
|
.y_axis(y_axis);
|
||||||
frame.render_widget(chart, right_layout[1]);
|
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 {
|
} else {
|
||||||
let p = Paragraph::new("Tab not implemented")
|
let p = Paragraph::new("Tab not implemented")
|
||||||
.block(trx_block)
|
.block(trx_block)
|
||||||
@@ -346,7 +370,7 @@ fn helper_rect(r: Rect) -> Rect {
|
|||||||
|
|
||||||
return Layout::default()
|
return Layout::default()
|
||||||
.direction(Direction::Horizontal)
|
.direction(Direction::Horizontal)
|
||||||
.constraints([Constraint::Percentage(30), Constraint::Percentage(70)])
|
.constraints([Constraint::Percentage(20), Constraint::Percentage(70)])
|
||||||
.split(popup_layout[1])[0];
|
.split(popup_layout[1])[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user