Skip to content

Commit a0f43f9

Browse files
committed
refactor: in axis normalize values to arrays, include all span levels
Axis setter now wraps single values in arrays (["A"] instead of "A"), matching data-viewer. This eliminates Array.isArray branching in builders, Data slicing/trimming, and format-table. Also includes the final level in getSpans, fixing a latent crash when collapseColumns is false on multi-level headers.
1 parent 1cb6e12 commit a0f43f9

4 files changed

Lines changed: 6 additions & 18 deletions

File tree

src/builders/base-builder.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,6 @@ export class BaseTableBuilder {
160160
getMarginEdgeCols() {
161161
const cols = []
162162
this.data.columns.values.forEach((value, icol) => {
163-
if (!Array.isArray(value)) {
164-
if (this.options.marginLabels.includes(value)) cols.push(icol)
165-
return
166-
}
167163
for (let level = 0; level < value.length; level++) {
168164
if (!this.options.marginLabels.includes(value[level])) continue
169165
if (this.data.columns.spans[level].some(s => s.iloc === icol)) {

src/builders/default-builder.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ export class DefaultTableBuilder extends BaseTableBuilder {
278278
* @returns {string} HTML string for the th element
279279
*/
280280
buildColumnLabel(value, mappedValue, iloc) {
281-
const selectedValue = Array.isArray(mappedValue) ? mappedValue.at(-1) : mappedValue
281+
const selectedValue = mappedValue.at(-1)
282282
const attrs = this.data.columns.attrs[iloc]
283283

284284
const attributes = {
@@ -491,7 +491,7 @@ export class DefaultTableBuilder extends BaseTableBuilder {
491491
* @returns {string} HTML string for the index cell
492492
*/
493493
buildIndex(value) {
494-
const selectedValue = Array.isArray(value) ? value.at(-1) : value
494+
const selectedValue = value.at(-1)
495495
const level = this.data.index.nlevels - 1
496496
const attrs = this.data.index.attrs[level]
497497
const formattedValue = this.formatValue(selectedValue, attrs.dtype, attrs.formatOptions ?? this.options)

src/data.js

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,7 @@ export class Data extends EventTarget {
111111

112112
const indexValues = this.index.values
113113
.slice(startRow, endRow)
114-
.map(value =>
115-
Array.isArray(value)
116-
? value.slice(dropLevels)
117-
: value
118-
)
114+
.map(value => value.slice(dropLevels))
119115

120116
return new Data({
121117
values: slicedValues,
@@ -156,19 +152,15 @@ export class Data extends EventTarget {
156152

157153
const headIdx = indexValues.slice(0, trimSize)
158154
const tailIdx = indexValues.slice(-trimSize)
159-
const sepIdx = Array.isArray(indexValues[0])
160-
? Array(this.index.nlevels).fill(separator)
161-
: separator
155+
const sepIdx = Array(this.index.nlevels).fill(separator)
162156
indexValues = [...headIdx, sepIdx, ...tailIdx]
163157
}
164158

165159
// Handle columns if needed
166160
if (this.columns.length > maxColumns) {
167161
const headCols = columnValues.slice(0, trimSize)
168162
const tailCols = columnValues.slice(-trimSize)
169-
const sepCol = Array.isArray(columnValues[0])
170-
? Array(this.columns.nlevels).fill(separator)
171-
: separator
163+
const sepCol = Array(this.columns.nlevels).fill(separator)
172164
columnValues = [...headCols, sepCol, ...tailCols]
173165

174166
values = values.map(row => {

src/settings/format/format-table.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ export class FormatTable extends HTMLElement {
322322

323323
return `
324324
<tr data-column-index="${idx}">
325-
<td>${Array.isArray(col) ? col.at(-1) : col}</td>
325+
<td>${col.at(-1)}</td>
326326
<td>${attrs.dtype ?? "-"}</td>
327327
<td>${this.getFormatSummary(attrs.formatOptions, attrs.dtype)}</td>
328328
<td>

0 commit comments

Comments
 (0)