Skip to content

Commit e804579

Browse files
committed
added minimal ExtTable presentation
1 parent 5a867f6 commit e804579

2 files changed

Lines changed: 79 additions & 7 deletions

File tree

‎_includes/table.toric.html‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
{% assign class = include.class | default: page.class %}
33
{% assign dim = class | remove: 'fano-' | plus: 0 %}
44
{% assign row_limit = include.row_limit | default: page.row_limit | default: 20 %}
5+
{% assign force_svg = include.force_svg | default: false %}
6+
{% if dim >= 4 %}
7+
{% assign force_svg = true %}
8+
{% endif %}
59

610
<style>
711
.pad3 {
@@ -33,6 +37,10 @@
3337
.row-toggle[aria-expanded="true"] {
3438
transform: rotate(90deg);
3539
}
40+
41+
.minimal-matrix {
42+
vertical-align: middle;
43+
}
3644
</style>
3745

3846
<div class="table-wrap">
@@ -72,7 +80,7 @@
7280
<span class="pad3">{{ X[1].rays[0] }}:</span> ${{ X[1].degs | latex_matrix: true }}$<br/>
7381
<span class="pad3">{{ X[1].theta[0] }}:</span> ${{ X[1].theta[1] | latex_matrix: true }}$</td>
7482
<td class="align-middle ExtTable" data-sort="{{ X[1].Ext[1] }}">
75-
${{ X[1].Ext[0] | latex_matrix: false }}$</td>
83+
{{ X[1].Ext[0] | matrix_preview: false, force_svg }}</td>
7684
</tr>
7785
<tr id="details-{{ identifier }}" class="detail-row" style="display: none;">
7886
<td colspan="6">

‎_plugins/matrix.rb‎

Lines changed: 70 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,88 @@
11
module MatrixFilters
2+
CELL_SIZE = 7
3+
T_COLORS = {
4+
1 => '#c00',
5+
2 => '#e66a00',
6+
3 => '#c0a000',
7+
4 => '#008800',
8+
5 => '#0070c0',
9+
6 => '#00c'
10+
}.freeze
11+
212
def latex_matrix(input, transpose = false)
13+
rows = matrix_rows(input, transpose)
14+
return input if rows.empty?
15+
16+
latex_from_rows(rows)
17+
end
18+
19+
def matrix_preview(input, transpose = false, force_svg = false, column_limit = 20)
20+
rows = matrix_rows(input, transpose)
21+
return input if rows.empty?
22+
23+
force_svg = force_svg || rows.first.length > column_limit.to_i
24+
force_svg ? minimal_matrix_svg(rows) : "$#{latex_from_rows(rows)}$"
25+
end
26+
27+
def strip_times(input)
28+
input.gsub(/\*/, '')
29+
end
30+
31+
def normalize_grouped_superscripts(input)
32+
input.gsub(/\^\(([^()]*)\)/, '^{\1}')
33+
end
34+
35+
def matrix_rows(input, transpose = false)
336
columns = parse_brace_list(input.to_s.strip)
4-
return input if columns.empty?
37+
return [] if columns.empty?
538

639
widths = columns.map(&:length).uniq
740
raise ArgumentError, "matrix columns must all have the same length" unless widths.length == 1
841

9-
rows = transpose ? columns.transpose : columns
42+
transpose ? columns.transpose : columns
43+
end
44+
45+
def latex_from_rows(rows)
1046
rows = rows.map do |row|
1147
row.map { |entry| normalize_grouped_superscripts(entry) }.join(' & ')
1248
end
1349
"\\begin{pmatrix}#{rows.join(' \\\\ ')}\\end{pmatrix}".gsub(/\*/, '')
1450
end
1551

16-
def strip_times(input)
17-
input.gsub(/\*/, '')
52+
def minimal_matrix_svg(rows)
53+
width = rows.first.length * CELL_SIZE
54+
height = rows.length * CELL_SIZE
55+
black = +''
56+
t_paths = Hash.new { |paths, exponent| paths[exponent] = +'' }
57+
58+
rows.each_with_index do |row, y_index|
59+
row.each_with_index do |entry, x_index|
60+
next if entry == '0'
61+
62+
x = x_index * CELL_SIZE
63+
y = y_index * CELL_SIZE
64+
path = "M#{x} #{y}h#{CELL_SIZE}v#{CELL_SIZE}h-#{CELL_SIZE}z"
65+
exponent = t_exponent(entry)
66+
exponent ? t_paths[exponent] << path : black << path
67+
end
68+
end
69+
70+
svg = %(<svg class="minimal-matrix" width="#{width}" height="#{height}" viewBox="0 0 #{width} #{height}" role="img" aria-label="#{rows.length} by #{rows.first.length} matrix preview" shape-rendering="crispEdges">)
71+
svg << %(<path fill="#000" d="#{black}"/>) unless black.empty?
72+
T_COLORS.each do |exponent, color|
73+
path = t_paths[exponent]
74+
svg << %(<path fill="#{color}" d="#{path}"/>) unless path.empty?
75+
end
76+
svg << %(</svg>)
1877
end
1978

20-
def normalize_grouped_superscripts(input)
21-
input.gsub(/\^\(([^()]*)\)/, '^{\1}')
79+
def t_exponent(entry)
80+
exponents = entry.scan(/T(?:\^\(?(-?\d+)\)?)?/).map do |match|
81+
match[0].nil? || match[0].empty? ? 1 : match[0].to_i
82+
end
83+
return nil if exponents.empty?
84+
85+
[[exponents.max, 1].max, 6].min
2286
end
2387

2488
def parse_brace_list(source)

0 commit comments

Comments
 (0)