diff --git a/src/channeldef.ts b/src/channeldef.ts index be2a615f74..d39fb4e798 100644 --- a/src/channeldef.ts +++ b/src/channeldef.ts @@ -86,7 +86,12 @@ import {isSignalRef} from './vega.schema'; export type PrimitiveValue = number | string | boolean | null; -export type Value = PrimitiveValue | number[] | Gradient | Text | ExprRef | SignalRef; +export type Value = + | PrimitiveValue + | number[] + | Gradient + | Text + | ES; /** * Definition object for a constant value (primitive value or gradient definition) of an encoding channel. diff --git a/src/compile/mark/encode/valueref.ts b/src/compile/mark/encode/valueref.ts index 9f68b88486..8fc951e149 100644 --- a/src/compile/mark/encode/valueref.ts +++ b/src/compile/mark/encode/valueref.ts @@ -28,6 +28,7 @@ import { } from '../../../channeldef'; import {Config} from '../../../config'; import {dateTimeToExpr, isDateTime} from '../../../datetime'; +import {isExprRef} from '../../../expr'; import * as log from '../../../log'; import {isPathMark, Mark, MarkDef} from '../../../mark'; import {fieldValidPredicate} from '../../../predicate'; @@ -138,6 +139,8 @@ export function valueRefForFieldOrDatumDef( ref.signal = dateTimeToExpr(datum); } else if (isSignalRef(datum)) { ref.signal = datum.signal; + } else if (isExprRef(datum)) { + ref.signal = datum.expr; } else { ref.value = datum; } diff --git a/src/vega.schema.ts b/src/vega.schema.ts index 916955b4a7..82ff710d6d 100644 --- a/src/vega.schema.ts +++ b/src/vega.schema.ts @@ -92,7 +92,7 @@ export function isSignalRef(o: any): o is SignalRef { // TODO: add type of value (Make it VgValueRef {value?:V ...}) export interface VgValueRef { - value?: Value | number[]; + value?: Value; field?: | string | { diff --git a/test/compile/mark/point.test.ts b/test/compile/mark/point.test.ts index 9598f80286..32e9773b25 100644 --- a/test/compile/mark/point.test.ts +++ b/test/compile/mark/point.test.ts @@ -434,4 +434,17 @@ describe('Mark: Circle', () => { expect(filledCircleProps.stroke).toEqual({signal: "'red'"}); }); + + it('converts expression in mark properties into signal', () => { + const filledCircleModel = parseUnitModelWithScaleAndLayoutSize({ + mark: {type: 'circle'}, + encoding: { + x: {datum: {expr: 'myX'}, type: 'quantitative'} + } + }); + + const filledCircleProps = circle.encodeEntry(filledCircleModel); + + expect(filledCircleProps.x).toEqual({scale: 'x', signal: 'myX'}); + }); });