diff --git a/lib/api.typ b/lib/api.typ index 46ee36c..9386c25 100644 --- a/lib/api.typ +++ b/lib/api.typ @@ -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 } diff --git a/lib/asserts.typ b/lib/asserts.typ index 6bb54f0..b88d139 100644 --- a/lib/asserts.typ +++ b/lib/asserts.typ @@ -1,14 +1,14 @@ #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) @@ -16,8 +16,8 @@ } /// 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; @@ -25,8 +25,8 @@ } /// 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)) @@ -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)); diff --git a/lib/gen.typ b/lib/gen.typ index df93776..38a8425 100644 --- a/lib/gen.typ +++ b/lib/gen.typ @@ -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) )) } @@ -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 = ( @@ -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") { @@ -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 @@ -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( @@ -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 @@ -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; @@ -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 @@ -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 =>{ @@ -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, @@ -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 } @@ -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))) ) @@ -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*/],) diff --git a/lib/states.typ b/lib/states.typ index 65df47e..7059da7 100644 --- a/lib/states.typ +++ b/lib/states.typ @@ -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() } \ No newline at end of file diff --git a/lib/utils.typ b/lib/utils.typ index 92eabda..0283b7b 100644 --- a/lib/utils.typ +++ b/lib/utils.typ @@ -1,15 +1,15 @@ #import "asserts.typ": * // insert a value into an dict and return the dict -#let dict_insert_and_return(dict, key, value) = { +#let dict-insert-and-return(dict, key, value) = { assert.eq(type(dict), dictionary); assert.eq(type(key), str); dict.insert(key,value); return dict } -#let _get_field_type(field) = { - assert_bf-field(field); +#let get-field-type(field) = { + assert-bf-field(field); return field.at("field-type", default: none); } @@ -21,24 +21,24 @@ /// Check if a given field is a data-field #let is-data-field(field) = { - assert_bf-field(field); + assert-bf-field(field); field.at("field-type", default: none) == "data-field" } /// Check if a given field is a note-field #let is-note-field(field) = { - assert_bf-field(field); + assert-bf-field(field); field.at("field-type", default: none) == "note-field" } /// Check if a given field is a header-field #let is-header-field(field) = { - assert_bf-field(field); + assert-bf-field(field); field.at("field-type", default: none) == "header-field" } /// Return the index of the next data-field -#let _get_index_of_next_data_field(idx, fields) = { +#let get-index-of-next-data-field(idx, fields) = { let res = fields.sorted(key: f => f.field-index).find(f => f.field-index > idx and is-data-field(f)) if res != none { res.field-index } else { none } } @@ -54,11 +54,11 @@ } /// calculates the max annotation level for both sides -#let _get_max_annotation_levels(annotations) = { +#let get-max-annotation-levels(annotations) = { let left_max_level = -1 let right_max_level = -1 for field in annotations { - assert_bf-field(field) + assert-bf-field(field) let (side, level, ..) = field.data; if (side == left) { left_max_level = calc.max(left_max_level,level) @@ -109,7 +109,7 @@ } /// Return the current index of a field or cell -#let _get_index(f) = { +#let get-index(f) = { if is-bf-field(f) { return f.field-index } else if is-bf-cell(f) {