Skip to content

Commit

Permalink
refactor: removed underlines from functionnames
Browse files Browse the repository at this point in the history
  • Loading branch information
jomaway committed May 22, 2024
1 parent 8bc6de3 commit 13fae10
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 73 deletions.
8 changes: 4 additions & 4 deletions lib/api.typ
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
side: (left_cols: pre, right_cols: post)
)

let meta = generate_meta(fields.pos(), args)
let fields = finalize_fields(fields.pos(), meta)
let cells = generate_cells(meta, fields)
let table = generate_table(meta, cells)
let meta = generate-meta(fields.pos(), args)
let fields = finalize-fields(fields.pos(), meta)
let cells = generate-cells(meta, fields)
let table = generate-table(meta, cells)
return table
}

Expand Down
22 changes: 11 additions & 11 deletions lib/asserts.typ
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
#import "@preview/oxifmt:0.2.0": strfmt


#let assert_dict(arg, var_name) = {
#let assert-dict(arg, var_name) = {
assert.eq(type(arg),dictionary, message: strfmt("expected {} to be a dictionary, found {}",var_name, type(arg)));
}


/// fail if field is not a bf-field
#let assert_bf-field(field) = {
assert_dict(field, "field")
#let assert-bf-field(field) = {
assert-dict(field, "field")
let bf-type = field.at("bf-type", default: none)
assert.eq(bf-type, "bf-field", message: strfmt("expected bf-type of 'bf-field', found {}",bf-type));
let field-type = field.at("field-type", default: none)
assert.ne(field-type, none, message: strfmt("could not find field-type at bf-field {}", field));
}

/// fail if field is not a bf-field of type data-field
#let assert_data-field(field) = {
assert_bf-field(field);
#let assert-data-field(field) = {
assert-bf-field(field);
let field-type = field.at("field-type", default: none)
assert.eq(field-type, "data-field", message: strfmt("expected field-type == data-field, found {}",field-type))
let size = field.data.size;
assert(type(size) == int, message: strfmt("expected integer for parameter size, found {} ", type(size)))
}

/// fail if field is not a bf-field of type data-field
#let assert_note-field(field) = {
assert_bf-field(field);
#let assert-note-field(field) = {
assert-bf-field(field);
// Check for correct field-type
let field-type = field.at("field-type", default: none)
assert.eq(field-type, "note-field", message: strfmt("expected field-type == note-field, found {}",field-type))
Expand All @@ -39,13 +39,13 @@
}

/// fail if it does not match
#let assert_header-field(field) = {
assert_bf-field(field);
#let assert-header-field(field) = {
assert-bf-field(field);
}

/// fail if cell is not a bf-cell
#let assert_bf-cell(cell) = {
assert_dict(cell, "cell");
#let assert-bf-cell(cell) = {
assert-dict(cell, "cell");
// Check bf-type
let bf-type = cell.at("bf-type", default: none)
assert.eq(bf-type, "bf-cell", message: strfmt("expected bf-type of 'bf-cell', found {}",bf-type));
Expand Down
84 changes: 42 additions & 42 deletions lib/gen.typ
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#import "asserts.typ": *
#import "states.typ": *

#let assert_level_cols(levels, cols, side) = {
#let assert-level-cols(levels, cols, side) = {
if (cols != auto) {
cols = if (int == type(cols)) { cols } else if (array == type(cols)) { cols.len() } else { panic(strfmt("expected {} argument to be auto, int or array, found {}",if (side == "left") {"pre"} else {"post"} ,type(cols) )) }

Expand All @@ -12,13 +12,13 @@
}

/// generate metadata which is needed later on
#let generate_meta(fields, args) = {
#let generate-meta(fields, args) = {
// collect metadata into an dictionary
let bh = fields.find(f => is-header-field(f))
// check level indentation for annotations
let (pre_levels, post_levels) = _get_max_annotation_levels(fields.filter(f => is-note-field(f) ))
assert_level_cols(pre_levels, args.side.left_cols, "left")
assert_level_cols(post_levels, args.side.right_cols, "right")
let (pre_levels, post_levels) = get-max-annotation-levels(fields.filter(f => is-note-field(f) ))
assert-level-cols(pre_levels, args.side.left_cols, "left")
assert-level-cols(post_levels, args.side.right_cols, "right")
// check if msb value is valid
assert(args.msb in (left,right), message: strfmt("expected left or right for msb, found {}", args.msb))
let meta = (
Expand Down Expand Up @@ -58,7 +58,7 @@
}

/// helper to calc number values from autofill string arguments
#let _get_header_autofill_values(autofill, fields, meta) = {
#let get-header-autofill-values(autofill, fields, meta) = {
if (autofill == "bounds") {
return fields.filter(f => is-data-field(f)).map(f => if f.data.range.start == f.data.range.end { (f.data.range.start,) } else {(f.data.range.start, f.data.range.end)}).flatten()
} else if (autofill == "all") {
Expand All @@ -79,18 +79,18 @@
}

/// Index all fields
#let index_fields(fields) = {
#let index-fields(fields) = {
fields.enumerate().map(((idx, f)) => {
assert_bf-field(f)
dict_insert_and_return(f, "field-index", idx)
assert-bf-field(f)
dict-insert-and-return(f, "field-index", idx)
})
}

/// indexes all fields and add some additional field data
#let finalize_fields(fields, meta) = {
#let finalize-fields(fields, meta) = {

// This part must be changed if the user low level api changes.
let _fields = index_fields(fields)
let _fields = index-fields(fields)

// Define some variables
let bpr = meta.cols.main
Expand All @@ -111,22 +111,22 @@
// note fields
for f in _fields.filter(f => is-note-field(f)) {
let row = if (f.data.row == auto) {
let anchor = _get_index_of_next_data_field(f.field-index, _fields)
let anchor = get-index-of-next-data-field(f.field-index, _fields)
let anchor_field = fields.find(f => f.field-index == anchor)
int( if (meta.msb == left) { (meta.size - anchor_field.data.range.end)/bpr } else { anchor_field.data.range.start/bpr })
} else {
f.data.row
}
let data = dict_insert_and_return(f.data, "row", row)
let field = dict_insert_and_return(f, "data", data)
assert_note-field(field);
let data = dict-insert-and-return(f.data, "row", row)
let field = dict-insert-and-return(f, "data", data)
assert-note-field(field);
fields.push(field)
}


// header fields -- needs data fields already processed !!
for f in _fields.filter(f => is-header-field(f)) {
let autofill_values = _get_header_autofill_values(f.data.autofill, fields, meta);
let autofill_values = get-header-autofill-values(f.data.autofill, fields, meta);
let numbers = if f.data.numbers == none { () } else { f.data.numbers + autofill_values }
let labels = f.data.at("labels", default: (:))
fields.push(header-field(
Expand All @@ -143,7 +143,7 @@
}

/// generate data cells from data-fields
#let generate_data_cells(fields, meta) = {
#let generate-data-cells(fields, meta) = {
let data_fields = fields.filter(f => is-data-field(f))
if (meta.msb == left ) { data_fields = data_fields.rev() }
data_fields = data_fields
Expand All @@ -153,7 +153,7 @@
let idx = 0;

for field in data_fields {
assert_data-field(field)
assert-data-field(field)
let len = field.data.size

let slice_idx = 0;
Expand Down Expand Up @@ -217,13 +217,13 @@
}

/// generate note cells from note-fields
#let generate_note_cells(fields, meta) = {
#let generate-note-cells(fields, meta) = {
let note_fields = fields.filter(f => is-note-field(f))
let _cells = ()
let bpr = meta.cols.main

for field in note_fields {
assert_note-field(field)
assert-note-field(field)
let side = field.data.side
let level = field.data.level

Expand All @@ -247,14 +247,14 @@
}

/// generate header cells from header-fields
#let generate_header_cells(fields, meta) = {
#let generate-header-cells(fields, meta) = {
let header_fields = fields.filter(f => is-header-field(f))
let bpr = meta.cols.main

let _cells = ()

for header in header_fields {
assert_header-field(header)
assert-header-field(header)
let nums = header.data.at("numbers", default: ()) + header.data.at("labels").keys().map(k => int(k))
let cell = nums.filter(num => num >= header.data.range.start and num < header.data.range.end).dedup().map(num =>{

Expand Down Expand Up @@ -311,28 +311,28 @@
}

/// generates cells from fields
#let generate_cells(meta, fields) = {
#let generate-cells(meta, fields) = {
// data
let data_cells = generate_data_cells(fields, meta);
let data_cells = generate-data-cells(fields, meta);
// notes
let note_cells = generate_note_cells(fields, meta);
let note_cells = generate-note-cells(fields, meta);
// header
let header_cells = generate_header_cells(fields, meta);
let header_cells = generate-header-cells(fields, meta);

return (header_cells, data_cells, note_cells).flatten()
}

/// map bf custom cells to tablex cells
#let map_cells(cells) = {
#let map-cells(cells) = {
cells.map(c => {
assert_bf-cell(c)
assert-bf-cell(c)

let body = if is-header-cell(c) {
let label_text = c.label.text
let label_num = c.label.num
context {
style(styles => {
set text(if c.format.text-size == auto { _get_header_font_size() } else { c.format.text-size })
set text(if c.format.text-size == auto { get-default-header-font-size() } else { c.format.text-size })
set align(center + bottom)
let size = measure(label_text, styles).width
stack(dir: ttb, spacing: 0pt,
Expand All @@ -350,14 +350,14 @@
} else {
{
[
#if (is-data-cell(c) and (_get_field_font_size() != auto)) {
#if (is-data-cell(c) and (get-default-field-font-size() != auto)) {
[
#set text(_get_field_font_size());
#set text(get-default-field-font-size());
#c.label
]
} else if (is-note-cell(c) and (_get_note_font_size() != auto)) {
} else if (is-note-cell(c) and (get-default-note-font-size() != auto)) {
[
#set text(_get_note_font_size());
#set text(get-default-note-font-size());
#c.label
]
} else { c.label }
Expand All @@ -380,36 +380,36 @@
}

/// produce the final output
#let generate_table(meta, cells) = {
#let generate-table(meta, cells) = {
let table = context {
let rows = if (meta.rows.main == auto) { _get_row_height() } else { meta.rows.main }
if (type(rows) == array) { rows = rows.map(r => if (r == auto) { _get_row_height() } else { r } )}
let rows = if (meta.rows.main == auto) { get-default-row-height() } else { meta.rows.main }
if (type(rows) == array) { rows = rows.map(r => if (r == auto) { get-default-row-height() } else { r } )}

// somehow grid_header still needs to exists.
let grid_header = if (meta.header != none) {
grid(
columns: (1fr,)*meta.cols.main,
rows: auto,
..map_cells(cells.filter(c => is-in-header-grid(c)))
..map-cells(cells.filter(c => is-in-header-grid(c)))
)
} else { none }

let grid_left = grid(
columns: meta.side.left.cols,
rows: rows,
..map_cells(cells.filter(c => is-in-left-grid(c)))
..map-cells(cells.filter(c => is-in-left-grid(c)))
)

let grid_right = grid(
columns: meta.side.right.cols,
rows: rows,
..map_cells(cells.filter(c => is-in-right-grid(c)))
..map-cells(cells.filter(c => is-in-right-grid(c)))
)

let grid_center = grid(
columns:(1fr,)*meta.cols.main,
rows: rows,
..map_cells(cells.filter(c => is-in-main-grid(c)))
..map-cells(cells.filter(c => is-in-main-grid(c)))
)


Expand All @@ -420,8 +420,8 @@
([/* top left*/],
align(bottom, box(
width: 100%,
fill: if (meta.header.fill != auto) { meta.header.fill } else { _get_header_background() },
stroke: if (meta.header.stroke != auto) { meta.header.stroke } else { _get_header_border() },
fill: if (meta.header.fill != auto) { meta.header.fill } else { get-default-header-background() },
stroke: if (meta.header.stroke != auto) { meta.header.stroke } else { get-default-header-border() },
grid_header
)),
[/*top right*/],)
Expand Down
12 changes: 6 additions & 6 deletions lib/states.typ
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,26 @@
}


#let _get_row_height() = {
#let get-default-row-height() = {
default_row_height.get()
}

#let _get_header_font_size() = {
#let get-default-header-font-size() = {
default_header_font_size.get()
}

#let _get_field_font_size() = {
#let get-default-field-font-size() = {
default_field_font_size.get()
}

#let _get_note_font_size() = {
#let get-default-note-font-size() = {
default_note_font_size.get()
}

#let _get_header_background() = {
#let get-default-header-background() = {
default_header_background.get()
}

#let _get_header_border() = {
#let get-default-header-border() = {
default_header_border.get()
}
Loading

0 comments on commit 13fae10

Please sign in to comment.