Skip to content

Commit

Permalink
fix: use expression to generalize zeroOrMinOrMax when there is a scale
Browse files Browse the repository at this point in the history
  • Loading branch information
kanitw committed May 9, 2024
1 parent cd7d913 commit e0d2a64
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/compile/mark/encode/zeroOrMinOrMax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,21 @@ export function zeroOrMinOrMax({
};
}

if (scaleName) {
const domain = `domain('${scaleName}')`;
const min = `${domain}[0]`;
const max = `peek(${domain})`; // peek = the last item of the array

switch (mode) {
case 'min':
return {signal: `scale('${scaleName}', ${min})`}; // encode the scale domain min
case 'zeroOrMin':
return {signal: `scale('${scaleName}', inrange(0, ${domain}) ? 0 : ${min})`}; // encode the scale domain min
default: //zeroOrMax
return {signal: `scale('${scaleName}', inrange(0, ${domain}) ? 0 : ${max})`}; // encode the scale domain max
}
}

if (mode === 'zeroOrMin' || mode === 'min') {
switch (mainChannel) {
case 'radius':
Expand All @@ -29,7 +44,7 @@ export function zeroOrMinOrMax({
case 'y':
return {field: {group: 'height'}};
default:
return {signal: `scale('${scaleName}', domain('${scaleName}')[0])`}; // encode the scale domain min
return undefined; // For non-position, it's impossible to reach this line if the field doesn't have a scale.
}
} else {
// zeroOrMax
Expand All @@ -48,7 +63,7 @@ export function zeroOrMinOrMax({
case 'y':
return {value: 0};
default:
return {signal: `scale('${scaleName}', domain('${scaleName}')[1])`}; // encode the scale domain max
return undefined; // For non-position, it's impossible to reach this line if the field doesn't have a scale.
}
}
}

0 comments on commit e0d2a64

Please sign in to comment.