|
1 |
| -#let decision-matrix(properties: none, ..choices) = {} |
| 1 | +#import "/utils.typ" |
| 2 | +#import "../colors.typ": * |
| 3 | + |
| 4 | +#let decision-matrix( |
| 5 | + properties: none, |
| 6 | + ..choices, |
| 7 | +) = { |
| 8 | + let data = utils.calc-decision-matrix( |
| 9 | + properties: properties, |
| 10 | + ..choices, |
| 11 | + ) |
| 12 | + |
| 13 | + //repr(data) |
| 14 | + |
| 15 | + let winning-column |
| 16 | + for ( |
| 17 | + index, |
| 18 | + result, |
| 19 | + ) in data.enumerate() { |
| 20 | + if result.values.total.highest == true { |
| 21 | + winning-column = index + 2 |
| 22 | + break |
| 23 | + } |
| 24 | + } |
| 25 | + |
| 26 | + let table-height = properties.len() + 2 |
| 27 | + let table-length = choices.pos().len() + 2 |
| 28 | + |
| 29 | + import table: hline, vline, cell |
| 30 | + show cell: it => { |
| 31 | + set align(center + horizon) |
| 32 | + box( |
| 33 | + height: 30pt, |
| 34 | + it, |
| 35 | + ) |
| 36 | + } |
| 37 | + table( |
| 38 | + columns: for _ in range(choices.pos().len() + 2) { |
| 39 | + ( |
| 40 | + 1fr, |
| 41 | + ) |
| 42 | + }, |
| 43 | + stroke: none, |
| 44 | + fill: ( |
| 45 | + x, |
| 46 | + y, |
| 47 | + ) => { |
| 48 | + if y == 0 or ( |
| 49 | + x == 0 and not y == properties.len() + 1 |
| 50 | + ) { |
| 51 | + yellow.lighten(50%) |
| 52 | + } |
| 53 | + |
| 54 | + if x == winning-column and not y == 0 {yellow.lighten(50%)} |
| 55 | + }, |
| 56 | + |
| 57 | + // we make lines |
| 58 | + |
| 59 | + vline(stroke: yellow, end: table-height - 1), |
| 60 | + hline(stroke: yellow), |
| 61 | + |
| 62 | + ..for num in range(0, table-height) { |
| 63 | + let stroke = if num < 2 {yellow} else {gray} |
| 64 | + (hline(y: num, stroke: stroke, start: 2),) |
| 65 | + }, |
| 66 | + |
| 67 | + hline(stroke: gray, y: table-height, start: 1), |
| 68 | + |
| 69 | + ..for num in range(1, table-height + 2) { |
| 70 | + ( |
| 71 | + vline(x: num, stroke: yellow, start: 0, end: 1), |
| 72 | + vline(x: num, stroke: gray, start: 1), |
| 73 | + ) |
| 74 | + }, |
| 75 | + |
| 76 | + // outline the properties |
| 77 | + ..for num in range(0, table-height) { |
| 78 | + (hline(y: num, stroke: yellow, start: 0, end: 1),) |
| 79 | + }, |
| 80 | + |
| 81 | + |
| 82 | + |
| 83 | + // outline the weights |
| 84 | + hline(stroke: pro-green, start: 1, end: 2), |
| 85 | + hline(y: table-height - 1, stroke: pro-green, start: 1, end: 2), |
| 86 | + vline(x: 1, stroke: pro-green, end: table-height - 1), |
| 87 | + vline(x: 2, stroke: pro-green, end: table-height - 1), |
| 88 | + |
| 89 | + ..for num in range(0, table-height) { |
| 90 | + (hline(y: num, stroke: pro-green, start: 1, end: 2),) |
| 91 | + }, |
| 92 | + |
| 93 | + |
| 94 | + // outline the best choice |
| 95 | + hline(start: winning-column, end: winning-column + 1, stroke: yellow), |
| 96 | + vline(x: winning-column, stroke: yellow), |
| 97 | + vline(x: winning-column + 1, stroke: yellow), |
| 98 | + hline(y: table-height, start: winning-column, end: winning-column + 1, stroke: yellow), |
| 99 | + |
| 100 | + ..for num in range(0, table-height + 1) { |
| 101 | + (hline(y: num, stroke: yellow, start: winning-column, end: winning-column + 1),) |
| 102 | + }, |
| 103 | + |
| 104 | + |
| 105 | + // ok we're done making lines |
| 106 | + |
| 107 | + |
| 108 | + [], |
| 109 | + cell(fill: pro-green.lighten(50%))[*Weights*], |
| 110 | + ..for choice in choices.pos() { |
| 111 | + ( |
| 112 | + [*#choice.at(0)*], |
| 113 | + ) |
| 114 | + }, |
| 115 | + ..for ( |
| 116 | + index, |
| 117 | + property, |
| 118 | + ) in properties.enumerate() { |
| 119 | + ( |
| 120 | + [*#property.name*], |
| 121 | + table.cell(fill: pro-green.lighten(50%))[#property.weight], |
| 122 | + ..for result in data { |
| 123 | + ( |
| 124 | + [#result.values.values().at(index).value], |
| 125 | + ) |
| 126 | + }, |
| 127 | + ) |
| 128 | + }, |
| 129 | + [], |
| 130 | + [*Totals:*], |
| 131 | + ..for ( |
| 132 | + index, |
| 133 | + result, |
| 134 | + ) in data.enumerate() { |
| 135 | + ( |
| 136 | + [#result.values.at("total").value], |
| 137 | + ) |
| 138 | + }, |
| 139 | + ) |
| 140 | +} |
0 commit comments