Skip to content

Commit b161bfc

Browse files
committed
treatments around high-card row/col/xoffset
1 parent 75b797d commit b161bfc

File tree

1 file changed

+27
-20
lines changed

1 file changed

+27
-20
lines changed

src/app/utils.tsx

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -421,32 +421,39 @@ export const assembleVegaChart = (
421421
})
422422

423423
// Handle nominal axes with many entries
424-
for (const channel of ['x', 'y']) {
424+
for (const channel of ['x', 'y', 'column', 'row', 'xOffset']) {
425425
const encoding = vgObj.encoding?.[channel];
426426
if (encoding?.type === 'nominal') {
427427
const fieldName = encoding.field;
428-
const uniqueValues = [...new Set(workingTable.map(r => r[fieldName]))];
428+
const uniqueValues = [...new Set(values.map((r: any) => r[fieldName]))];
429429

430+
let valuesToKeep: any[];
430431
if (uniqueValues.length > maxNominalValues) {
431-
const oppositeChannel = channel === 'x' ? 'y' : 'x';
432-
const oppositeEncoding = vgObj.encoding?.[oppositeChannel];
433-
434-
let valuesToKeep: any[];
435-
if (oppositeEncoding?.type === 'quantitative') {
436-
// Sort by the quantitative field and take top maxNominalValues
437-
const quantField = oppositeEncoding.field;
438-
valuesToKeep = uniqueValues
439-
.map(val => ({
440-
value: val,
441-
sum: workingTable
442-
.filter(r => r[fieldName] === val)
443-
.reduce((sum, r) => sum + (r[quantField] || 0), 0)
444-
}))
445-
.sort((a, b) => b.sum - a.sum)
446-
.slice(0, maxNominalValues)
447-
.map(v => v.value);
432+
433+
if (channel == 'x' || channel == 'y') {
434+
const oppositeChannel = channel === 'x' ? 'y' : 'x';
435+
const oppositeEncoding = vgObj.encoding?.[oppositeChannel];
436+
437+
if (oppositeEncoding?.type === 'quantitative') {
438+
// Sort by the quantitative field and take top maxNominalValues
439+
const quantField = oppositeEncoding.field;
440+
valuesToKeep = uniqueValues
441+
.map(val => ({
442+
value: val,
443+
sum: workingTable
444+
.filter(r => r[fieldName] === val)
445+
.reduce((sum, r) => sum + (r[quantField] || 0), 0)
446+
}))
447+
.sort((a, b) => b.sum - a.sum)
448+
.slice(0, maxNominalValues)
449+
.map(v => v.value);
450+
} else {
451+
// If no quantitative axis, just take first maxNominalValues
452+
valuesToKeep = uniqueValues.slice(0, maxNominalValues);
453+
}
454+
} else if (channel == 'row') {
455+
valuesToKeep = uniqueValues.slice(0, 20);
448456
} else {
449-
// If no quantitative axis, just take first maxNominalValues
450457
valuesToKeep = uniqueValues.slice(0, maxNominalValues);
451458
}
452459

0 commit comments

Comments
 (0)