diff --git a/src/compile/mark/encode/nonposition.ts b/src/compile/mark/encode/nonposition.ts index 3f2380d4d1..8ffe7b1ffa 100644 --- a/src/compile/mark/encode/nonposition.ts +++ b/src/compile/mark/encode/nonposition.ts @@ -1,6 +1,6 @@ import type {SignalRef} from 'vega'; import {NonPositionScaleChannel} from '../../../channel'; -import {Value} from '../../../channeldef'; +import {Value, isConditionalDef} from '../../../channeldef'; import {VgEncodeChannel, VgEncodeEntry, VgValueRef} from '../../../vega.schema'; import {getMarkPropOrConfig, signalOrValueRef} from '../../common'; import {UnitModel} from '../../unit'; @@ -24,16 +24,22 @@ export function nonPosition( const {vgChannel} = opt; let {defaultRef, defaultValue} = opt; + const channelDef = encoding[channel]; + if (defaultRef === undefined) { // prettier-ignore - defaultValue ??= getMarkPropOrConfig(channel, markDef, config, {vgChannel, ignoreVgConfig: true}); + defaultValue ??= getMarkPropOrConfig(channel, markDef, config, { + vgChannel, + // If there is no conditonal def, we ignore vgConfig so the output spec is concise. + // However, if there is a conditional def, we must include vgConfig so the default is respected. + ignoreVgConfig: !isConditionalDef(channelDef) + }); if (defaultValue !== undefined) { defaultRef = signalOrValueRef(defaultValue); } } - const channelDef = encoding[channel]; const commonProps = { markDef, config,