Skip to content

Commit

Permalink
feat: support getBinStepSignal for prebinned data (#7063)
Browse files Browse the repository at this point in the history
  • Loading branch information
domoritz authored Nov 20, 2020
1 parent 2059beb commit 6ae3648
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions src/compile/scale/range.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,27 @@ export function parseUnitScaleRange(model: UnitModel) {
function getBinStepSignal(model: UnitModel, channel: 'x' | 'y'): SignalRefWrapper {
const fieldDef = model.fieldDef(channel);

if (fieldDef && fieldDef.bin && isBinning(fieldDef.bin)) {
const binSignal = getBinSignalName(model, fieldDef.field, fieldDef.bin);

// TODO: extract this to be range step signal
if (fieldDef?.bin) {
const {bin, field} = fieldDef;
const sizeType = getSizeChannel(channel);
const sizeSignal = model.getName(sizeType);
return new SignalRefWrapper(() => {
const updatedName = model.getSignalName(binSignal);
const binCount = `(${updatedName}.stop - ${updatedName}.start) / ${updatedName}.step`;
return `${model.getSignalName(sizeSignal)} / (${binCount})`;
});

if (isObject(bin) && bin.binned && bin.step !== undefined) {
return new SignalRefWrapper(() => {
const scaleName = model.scaleName(channel);
const binCount = `(domain("${scaleName}")[1] - domain("${scaleName}")[0]) / ${bin.step}`;
return `${model.getSignalName(sizeSignal)} / (${binCount})`;
});
} else if (isBinning(bin)) {
const binSignal = getBinSignalName(model, field, bin);

// TODO: extract this to be range step signal
return new SignalRefWrapper(() => {
const updatedName = model.getSignalName(binSignal);
const binCount = `(${updatedName}.stop - ${updatedName}.start) / ${updatedName}.step`;
return `${model.getSignalName(sizeSignal)} / (${binCount})`;
});
}
}
return undefined;
}
Expand Down

0 comments on commit 6ae3648

Please sign in to comment.