premier graphique
This commit is contained in:
@@ -280,6 +280,10 @@ impl App {
|
||||
}
|
||||
|
||||
pub fn get_trtype_data(&self, tr_type_id: i64) -> Vec<(f64, f64)> {
|
||||
return data_layer::get_tr_type_price_over_time(&self.connection, tr_type_id);
|
||||
return data_layer::get_tr_type_price_over_time(
|
||||
&self.connection,
|
||||
self.acc_list.get_selected_id(),
|
||||
tr_type_id,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -322,15 +322,27 @@ pub fn get_transactions(con: &Connection) -> Vec<Transaction> {
|
||||
return vec;
|
||||
}
|
||||
|
||||
pub fn get_tr_type_price_over_time(con: &Connection, tr_type_id: i64) -> Vec<(f64, f64)> {
|
||||
let query = "
|
||||
pub fn get_tr_type_price_over_time(
|
||||
con: &Connection,
|
||||
ac_id: i64,
|
||||
tr_type_id: i64,
|
||||
) -> Vec<(f64, f64)> {
|
||||
let mut query = "
|
||||
SELECT strftime('%Y%m', datetime(date, 'unixepoch')) as x, SUM(amount) as y
|
||||
FROM Transactions
|
||||
WHERE type_id = :tr_type
|
||||
GROUP BY x;
|
||||
";
|
||||
"
|
||||
.to_owned();
|
||||
if ac_id != 0 {
|
||||
query.push_str(" AND account_id = :ac_id");
|
||||
}
|
||||
query.push_str(" GROUP BY x;");
|
||||
|
||||
let mut statement = con.prepare(query).unwrap();
|
||||
statement.bind((":tr_type", tr_type_id)).unwrap();
|
||||
if ac_id != 0 {
|
||||
statement.bind((":ac_id", ac_id)).unwrap();
|
||||
}
|
||||
let mut data = Vec::<(f64, f64)>::new();
|
||||
|
||||
while let Ok(State::Row) = statement.next() {
|
||||
|
||||
36
src/ui.rs
36
src/ui.rs
@@ -113,15 +113,43 @@ pub fn ui(frame: &mut Frame, app: &mut App) {
|
||||
.style(Color::Blue)
|
||||
.data(slice);
|
||||
|
||||
let min_x = slice
|
||||
.into_iter()
|
||||
.map(|&(x, _)| x)
|
||||
.min_by(|a, b| a.partial_cmp(b).unwrap())
|
||||
.unwrap()
|
||||
.round()
|
||||
- 1.0;
|
||||
let max_x = slice
|
||||
.into_iter()
|
||||
.map(|&(x, _)| x)
|
||||
.max_by(|a, b| a.partial_cmp(b).unwrap())
|
||||
.unwrap()
|
||||
.round()
|
||||
+ 1.0;
|
||||
let x_axis = Axis::default()
|
||||
.title("Temps")
|
||||
.bounds([202501.0, 202606.0])
|
||||
.labels(["2025-01", "2026-06"]);
|
||||
.bounds([min_x, max_x])
|
||||
.labels([min_x.to_string(), max_x.to_string()]);
|
||||
|
||||
let min_y = slice
|
||||
.into_iter()
|
||||
.map(|&(_, y)| y)
|
||||
.min_by(|a, b| a.partial_cmp(b).unwrap())
|
||||
.unwrap()
|
||||
.round()
|
||||
- 1.0;
|
||||
let max_y = slice
|
||||
.into_iter()
|
||||
.map(|&(_, y)| y)
|
||||
.max_by(|a, b| a.partial_cmp(b).unwrap())
|
||||
.unwrap()
|
||||
.round()
|
||||
+ 1.0;
|
||||
let y_axis = Axis::default()
|
||||
.title("Coûts")
|
||||
.bounds([0.0, 750.0])
|
||||
.labels(["0", "50", "100", "750"]);
|
||||
.bounds([min_y, max_y])
|
||||
.labels([min_y.to_string(), max_y.to_string()]);
|
||||
|
||||
let chart = Chart::new(vec![dataset])
|
||||
.block(trx_block)
|
||||
|
||||
Reference in New Issue
Block a user