このコミットが含まれているのは:
2026-10-28 00:28:29 +09:00
コミット d6cf992622
27個のファイルの変更、630行の追加、60行の削除
+24 -1
ファイルの表示
@@ -10,7 +10,21 @@ class CountsPivotLayout
(1...keys.length).select { order.first(_1).sort == keys.first(_1).sort }
end
def self.headers(values, depths, next_values: nil, grand: false)
def self.label_key(row_count, column_count, row_depth, column_depth)
total = row_count + column_count
collapsed = total - row_depth - column_depth
return nil if collapsed.zero?
return 'grandTotal' if total >= 3 && collapsed == total
if (collapsed == 1 &&
((row_count > 1 && row_depth < row_count) ||
(column_count > 1 && column_depth < column_count)))
return 'subtotal'
end
'singleTotal'
end
def self.headers(values, depths, next_values: nil, grand: false, axis_count: nil,
other_count: 0, direction: :row)
result = []
values.each_with_index do |tuple, index|
result << { values: tuple, kind: 'data' }
@@ -23,6 +37,15 @@ class CountsPivotLayout
end
end
result << { values: [], kind: 'grand_total' } if grand
count = axis_count || values.first&.length || 0
result.each do |header|
depth = header[:values].length
label = if header[:kind] != 'data'
direction == :row ? label_key(count, other_count, depth, other_count) :
label_key(other_count, count, other_count, depth)
end
header.merge!(depth:, axis_count: count, label_key: label)
end
result
end
end