Skip to content

Commit

Permalink
fix: misc typings for the experimental guideEncodeEntry
Browse files Browse the repository at this point in the history
  • Loading branch information
kanitw committed Sep 13, 2020
1 parent b404b86 commit 70f9b78
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 11 deletions.
3 changes: 1 addition & 2 deletions examples/compiled/selection_heatmap.vg.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,9 @@
"zindex": [
{
"test": "!(length(data(\"highlight_store\"))) || (vlSelectionTest(\"highlight_store\", datum))",
"selection": "highlight",
"value": 1
},
{"condition": {"selection": "highlight", "value": 1}, "value": 0}
{"value": 0}
],
"description": {
"signal": "\"actual: \" + (isValid(datum[\"actual\"]) ? datum[\"actual\"] : \"\"+datum[\"actual\"]) + \"; predicted: \" + (isValid(datum[\"predicted\"]) ? datum[\"predicted\"] : \"\"+datum[\"predicted\"]) + \"; count: \" + (format(datum[\"count\"], \"\"))"
Expand Down
7 changes: 3 additions & 4 deletions src/compile/guide.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import {SignalRef} from 'vega';
import {ValueDef} from '../channeldef';
import {GuideEncodingEntry} from '../guide';
import {keys} from '../util';
import {isSignalRef, VgEncodeChannel} from '../vega.schema';
import {VgEncodeChannel} from '../vega.schema';
import {signalOrValueRef} from './common';
import {wrapCondition} from './mark/encode';
import {UnitModel} from './unit';

Expand All @@ -11,7 +10,7 @@ export function guideEncodeEntry(encoding: GuideEncodingEntry, model: UnitModel)
const valueDef = encoding[channel];
return {
...encode,
...wrapCondition(model, valueDef, channel, (x: ValueDef | SignalRef) => (isSignalRef(x) ? x : {value: x.value}))
...wrapCondition(model, valueDef, channel, def => signalOrValueRef(def.value))
};
}, {});
}
3 changes: 1 addition & 2 deletions src/compile/mark/encode/conditional.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import {SignalRef} from 'vega';
import {array} from 'vega-util';
import {
ChannelDef,
Expand All @@ -17,7 +16,7 @@ import {UnitModel} from '../../unit';
* Return a mixin that includes a Vega production rule for a Vega-Lite conditional channel definition
* or a simple mixin if channel def has no condition.
*/
export function wrapCondition<CD extends ChannelDef | GuideEncodingConditionalValueDef | SignalRef>(
export function wrapCondition<CD extends ChannelDef | GuideEncodingConditionalValueDef>(
model: UnitModel,
channelDef: CD,
vgChannel: string,
Expand Down
3 changes: 2 additions & 1 deletion src/compile/mark/encode/zindex.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {isValueDef} from '../../../channeldef';
import {isPathMark} from '../../../mark';
import {signalOrValueRef} from '../../common';
import {UnitModel} from '../../unit';
import {wrapCondition} from './conditional';

Expand All @@ -8,7 +9,7 @@ export function zindex(model: UnitModel) {
const order = encoding.order;

if (!isPathMark(mark) && isValueDef(order)) {
return wrapCondition(model, order, 'zindex', cd => cd);
return wrapCondition(model, order, 'zindex', cd => signalOrValueRef(cd.value));
}
return {};
}
2 changes: 1 addition & 1 deletion src/guide.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export interface VlOnlyGuideConfig {

export type GuideEncodingConditionalValueDef = ValueDef & ConditionValueDefMixins;

export type GuideEncodingEntry = Partial<Record<VgEncodeChannel, GuideEncodingConditionalValueDef | SignalRef>>;
export type GuideEncodingEntry = Partial<Record<VgEncodeChannel, GuideEncodingConditionalValueDef>>;

export const VL_ONLY_LEGEND_CONFIG: (keyof LegendConfig<any>)[] = [
'gradientHorizontalMaxLength',
Expand Down
2 changes: 1 addition & 1 deletion test/compile/axis/parse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ describe('Axis', () => {
axis: {
encoding: {
labels: {
dx: {signal: 'a'},
dx: {value: {signal: 'a'}},
dy: {value: 2}
}
}
Expand Down

0 comments on commit 70f9b78

Please sign in to comment.