This commit is contained in:
2025-07-20 10:31:19 +02:00
parent 8e47487a23
commit cbde29a8b4
12 changed files with 414 additions and 387 deletions

View File

@@ -19,7 +19,7 @@ pub struct RowActionArgs {
pub mut:
name string
action RowAction
val f64
val ?f64
rows []&Row
tags string
descr string
@@ -98,15 +98,16 @@ pub fn (mut r Row) action(args_ RowActionArgs) !&Row {
}
}
}
if args.val > 0.0 {
val := args.val or { 999999999 }
if val != 999999999 {
if args.action == .add {
row_result.cells[x].val = row_result.cells[x].val + args.val
row_result.cells[x].val = row_result.cells[x].val + val
} else if args.action == .substract {
row_result.cells[x].val = row_result.cells[x].val - args.val
row_result.cells[x].val = row_result.cells[x].val - val
} else if args.action == .multiply {
row_result.cells[x].val = row_result.cells[x].val * args.val
row_result.cells[x].val = row_result.cells[x].val * val
} else if args.action == .divide {
row_result.cells[x].val = row_result.cells[x].val / args.val
row_result.cells[x].val = row_result.cells[x].val / val
} else if args.action == .aggregate {
row_result.cells[x].val = row_result.cells[x].val + prevval
prevval = row_result.cells[x].val
@@ -115,12 +116,12 @@ pub fn (mut r Row) action(args_ RowActionArgs) !&Row {
} else if args.action == .roundint {
row_result.cells[x].val = int(row_result.cells[x].val)
} else if args.action == .max {
if args.val > row_result.cells[x].val {
row_result.cells[x].val = args.val
if val > row_result.cells[x].val {
row_result.cells[x].val = val
}
} else if args.action == .min {
if args.val < row_result.cells[x].val {
row_result.cells[x].val = args.val
if val < row_result.cells[x].val {
row_result.cells[x].val = val
}
} else {
return error('Action wrongly specified for ${r} with\nargs:${args}')
@@ -141,9 +142,8 @@ pub fn (mut r Row) action(args_ RowActionArgs) !&Row {
return row_result
}
// pub fn (mut r Row) add(name string, r2 Row) !&Row {
// return r.action(name:name, rows:[]r2, tags:r.tags)
// }
pub fn (mut r Row) delay(monthdelay int) ! {
mut todelay := []f64{}
for x in 0 .. r.sheet.nrcol {

View File

@@ -23,7 +23,7 @@ pub mut:
nr_columns int = 0 //number of columns to show in the table, 0 is all
description bool //show description in the table
aggrtype bool = true //show aggregate type in the table
tags bool //show tags in the table
tags bool = true //show tags in the table
subgroup bool //show subgroup in the table
}
// calculate_column_widths calculates the maximum width for each column
@@ -31,8 +31,14 @@ fn calculate_column_widths(rows [][]string) []int {
if rows.len == 0 {
return []int{}
}
mut max_nr_cols := 0
for row in rows {
if row.len > max_nr_cols {
max_nr_cols = row.len
}
}
mut widths := []int{len: rows[0].len, init: 0}
mut widths := []int{len: max_nr_cols, init: 0}
for _, row in rows {
for i, cell in row {
if cell.len > widths[i] {
@@ -124,6 +130,32 @@ pub fn (mut s Sheet) pprint(args PPrintArgs) ! {
}
}
if args.nr_columns > 0 {
mut data_start_index := 1 // for row.name
if args.description {
data_start_index++
}
if args.aggrtype {
data_start_index++
}
if args.tags {
data_start_index++
}
if args.subgroup {
data_start_index++
}
max_cols := data_start_index + args.nr_columns
mut new_all_rows := [][]string{}
for i, row in all_rows {
if row.len > max_cols {
new_all_rows << row[0..max_cols]
} else {
new_all_rows << row
}
}
all_rows = new_all_rows.clone()
}
// Calculate column widths
widths := calculate_column_widths(all_rows)