From 5cc989852142659eefa54f677c8af6a52243f0f7 Mon Sep 17 00:00:00 2001 From: Kanit Wongsuphasawat Date: Wed, 31 Jul 2024 14:59:40 -0700 Subject: [PATCH] fix(#9401): conditional opacity should respect default value --- src/compile/mark/encode/nonposition.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) 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,