Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support field in condition #1980

Merged
merged 16 commits into from
Jun 11, 2017
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
538 changes: 373 additions & 165 deletions build/vega-lite-schema.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions examples/specs/brush.vl.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
"x": {"field": "Horsepower", "type": "quantitative"},
"y": {"field": "Miles_per_Gallon", "type": "quantitative"},
"color": {
"condition": {"selection": {"not": "brush"}, "value": "grey"},
"field": "Cylinders", "type": "ordinal"
"condition": {"selection": "brush", "field": "Cylinders", "type": "ordinal"},
"value": "grey"
}
}
}
7 changes: 4 additions & 3 deletions examples/specs/interactive_splom.vl.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@
"type": "quantitative"
},
"color": {
"field": "Origin","type": "nominal",
"condition": {
"selection": {"not": "brush"}, "value": "grey"
}
"selection": "brush",
"field": "Origin","type": "nominal"
},
"value": "grey"
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions examples/specs/layered_selections.vl.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
"x": {"field": "Horsepower", "type": "quantitative"},
"y": {"field": "Miles_per_Gallon", "type": "quantitative"},
"color": {
"condition": {"selection": {"not": "brush"}, "value": "grey"},
"field": "Cylinders", "type": "ordinal"
"condition": {"selection": "brush", "field": "Cylinders", "type": "ordinal"},
"value": "grey"
},
"size": {
"value": 50,
Expand Down
4 changes: 2 additions & 2 deletions examples/specs/query_widgets.vl.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
"x": {"field": "Horsepower", "type": "quantitative"},
"y": {"field": "Miles_per_Gallon", "type": "quantitative"},
"color": {
"field": "Origin", "type": "nominal",
"condition": {"selection": {"not": "CylYr"}, "value": "grey"}
"condition": {"selection": "CylYr", "field": "Origin", "type": "nominal"},
"value": "grey"
}
}
}, {
Expand Down
8 changes: 4 additions & 4 deletions examples/vg-specs/brush.vg.json
Original file line number Diff line number Diff line change
Expand Up @@ -344,12 +344,12 @@
},
"stroke": [
{
"test": "!(vlInterval(\"brush_store\", \"\", datum, \"union\", \"all\"))",
"value": "grey"
},
{
"test": "vlInterval(\"brush_store\", \"\", datum, \"union\", \"all\")",
"scale": "color",
"field": "Cylinders"
},
{
"value": "grey"
}
],
"fill": {
Expand Down
32 changes: 16 additions & 16 deletions examples/vg-specs/interactive_splom.vg.json
Original file line number Diff line number Diff line change
Expand Up @@ -505,12 +505,12 @@
},
"stroke": [
{
"test": "!(vlInterval(\"brush_store\", \"child_Horsepower_Horsepower_\", datum, \"union\", \"all\"))",
"value": "grey"
},
{
"test": "vlInterval(\"brush_store\", \"child_Horsepower_Horsepower_\", datum, \"union\", \"all\")",
"scale": "color",
"field": "Origin"
},
{
"value": "grey"
}
],
"fill": {
Expand Down Expand Up @@ -1063,12 +1063,12 @@
},
"stroke": [
{
"test": "!(vlInterval(\"brush_store\", \"child_Horsepower_Miles_per_Gallon_\", datum, \"union\", \"all\"))",
"value": "grey"
},
{
"test": "vlInterval(\"brush_store\", \"child_Horsepower_Miles_per_Gallon_\", datum, \"union\", \"all\")",
"scale": "color",
"field": "Origin"
},
{
"value": "grey"
}
],
"fill": {
Expand Down Expand Up @@ -1622,12 +1622,12 @@
},
"stroke": [
{
"test": "!(vlInterval(\"brush_store\", \"child_Acceleration_Horsepower_\", datum, \"union\", \"all\"))",
"value": "grey"
},
{
"test": "vlInterval(\"brush_store\", \"child_Acceleration_Horsepower_\", datum, \"union\", \"all\")",
"scale": "color",
"field": "Origin"
},
{
"value": "grey"
}
],
"fill": {
Expand Down Expand Up @@ -2181,12 +2181,12 @@
},
"stroke": [
{
"test": "!(vlInterval(\"brush_store\", \"child_Acceleration_Miles_per_Gallon_\", datum, \"union\", \"all\"))",
"value": "grey"
},
{
"test": "vlInterval(\"brush_store\", \"child_Acceleration_Miles_per_Gallon_\", datum, \"union\", \"all\")",
"scale": "color",
"field": "Origin"
},
{
"value": "grey"
}
],
"fill": {
Expand Down
8 changes: 4 additions & 4 deletions examples/vg-specs/layered_selections.vg.json
Original file line number Diff line number Diff line change
Expand Up @@ -616,12 +616,12 @@
},
"fill": [
{
"test": "!(vlInterval(\"brush_store\", \"layer_1_\", datum, \"union\", \"all\"))",
"value": "grey"
},
{
"test": "vlInterval(\"brush_store\", \"layer_1_\", datum, \"union\", \"all\")",
"scale": "color",
"field": "Cylinders"
},
{
"value": "grey"
}
],
"size": [
Expand Down
8 changes: 4 additions & 4 deletions examples/vg-specs/query_widgets.vg.json
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,12 @@
},
"fill": [
{
"test": "!(vlPoint(\"CylYr_store\", \"layer_0_\", datum, \"union\", \"all\"))",
"value": "grey"
},
{
"test": "vlPoint(\"CylYr_store\", \"layer_0_\", datum, \"union\", \"all\")",
"scale": "color",
"field": "Origin"
},
{
"value": "grey"
}
],
"shape": {
Expand Down
7 changes: 7 additions & 0 deletions src/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ export const TOOLTIP = Channel.TOOLTIP;
export const CHANNELS = [X, Y, X2, Y2, ROW, COLUMN, SIZE, SHAPE, COLOR, ORDER, OPACITY, TEXT, DETAIL, TOOLTIP];
const CHANNEL_INDEX = toSet(CHANNELS);

export const SINGLE_DEF_CHANNELS = [X, Y, X2, Y2, ROW, COLUMN, SIZE, SHAPE, COLOR, OPACITY, TEXT, TOOLTIP];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is a "single def" channel? Perhaps a comment to explain what this class of channels is and why it's needed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch.

I'll add

/**
 * Channels cannot have an array of channelDef.
 * model.fieldDef, getFieldDef only work for these channels.
 *
 * (The only two channels that can have an array of channelDefs are "detail" and "order".
 * Since there can be multiple fieldDefs for detail and order, getFieldDef/model.fieldDef
 * are not applicable for them.  Similarly, selection projecttion won't work with "detail" and "order".)
 */


// export type SingleDefChannel = typeof SINGLE_DEF_CHANNELS[0];
// FIXME somehow the typeof above leads to the following error when running npm run schema
// UnknownNodeError: Unknown node "SingleDefChannel" (ts.SyntaxKind = 171) at /Users/kanitw/Documents/_code/_idl/_visrec/vega-lite/src/selection.ts(17,14)
export type SingleDefChannel = 'x' | 'y' | 'x2' | 'y2' | 'row' | 'column' | 'size' | 'shape' | 'color' | 'opacity' | 'text' | 'tooltip';

export function isChannel(str: string): str is Channel {
return !!CHANNEL_INDEX[str];
}
Expand Down
11 changes: 8 additions & 3 deletions src/compile/axis/encode.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Channel, X} from '../../channel';
import {Channel, SpatialScaleChannel, X} from '../../channel';
import {NOMINAL, ORDINAL, TEMPORAL} from '../../type';
import {contains, extend, keys} from '../../util';
import {VgAxis} from '../../vega.schema';
Expand All @@ -7,8 +7,13 @@ import {ScaleType} from '../../scale';
import {timeFormatExpression} from '../common';
import {UnitModel} from '../unit';

export function labels(model: UnitModel, channel: Channel, labelsSpec: any, def: VgAxis) {
const fieldDef = model.fieldDef(channel);
export function labels(model: UnitModel, channel: SpatialScaleChannel, labelsSpec: any, def: VgAxis) {
const fieldDef = model.fieldDef(channel) ||
(
channel === 'x' ? model.fieldDef('x2') :
channel === 'y' ? model.fieldDef('y2') :
undefined
);
const axis = model.axis(channel);
const config = model.config;

Expand Down
12 changes: 6 additions & 6 deletions src/compile/axis/parse.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Axis, AXIS_PROPERTIES} from '../../axis';
import {Channel} from '../../channel';
import {Channel, SpatialScaleChannel} from '../../channel';
import {VgAxis} from '../../vega.schema';

import * as encode from './encode';
Expand All @@ -12,7 +12,7 @@ import {AxisComponent, AxisComponentIndex} from './component';
type AxisPart = 'domain' | 'grid' | 'labels' | 'ticks' | 'title';
const AXIS_PARTS: AxisPart[] = ['domain', 'grid', 'labels', 'ticks', 'title'];

export function parseAxisComponent(model: UnitModel, axisChannels: Channel[]): AxisComponentIndex {
export function parseAxisComponent(model: UnitModel, axisChannels: SpatialScaleChannel[]): AxisComponentIndex {
return axisChannels.reduce(function(axis, channel) {
const axisComponent: AxisComponent = {axes:[], gridAxes: []};
if (model.axis(channel)) {
Expand Down Expand Up @@ -58,16 +58,16 @@ function hasAxisPart(axis: VgAxis, part: AxisPart) {
/**
* Make an inner axis for showing grid for shared axis.
*/
export function parseGridAxis(channel: Channel, model: UnitModel): VgAxis {
export function parseGridAxis(channel: SpatialScaleChannel, model: UnitModel): VgAxis {
// FIXME: support adding ticks for grid axis that are inner axes of faceted plots.
return parseAxis(channel, model, true);
}

export function parseMainAxis(channel: Channel, model: UnitModel) {
export function parseMainAxis(channel: SpatialScaleChannel, model: UnitModel) {
return parseAxis(channel, model, false);
}

function parseAxis(channel: Channel, model: UnitModel, isGridAxis: boolean): VgAxis {
function parseAxis(channel: SpatialScaleChannel, model: UnitModel, isGridAxis: boolean): VgAxis {
const axis = model.axis(channel);

const vgAxis: VgAxis = {
Expand Down Expand Up @@ -114,7 +114,7 @@ function parseAxis(channel: Channel, model: UnitModel, isGridAxis: boolean): VgA
return vgAxis;
}

function getSpecifiedOrDefaultValue(property: keyof VgAxis, specifiedAxis: Axis, channel: Channel, model: UnitModel, isGridAxis: boolean) {
function getSpecifiedOrDefaultValue(property: keyof VgAxis, specifiedAxis: Axis, channel: SpatialScaleChannel, model: UnitModel, isGridAxis: boolean) {
const fieldDef = model.fieldDef(channel);

switch (property) {
Expand Down
11 changes: 3 additions & 8 deletions src/compile/axis/rules.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as log from '../../log';

import {Axis} from '../../axis';
import {Channel, COLUMN, ROW, X, Y} from '../../channel';
import {Channel, COLUMN, ROW, SpatialScaleChannel, X, Y} from '../../channel';
import {Config} from '../../config';
import {DateTime, dateTimeExpr, isDateTime} from '../../datetime';
import {FieldDef, title as fieldDefTitle} from '../../fielddef';
Expand All @@ -20,7 +20,7 @@ export function format(specifiedAxis: Axis, channel: Channel, fieldDef: FieldDef
* Default rules for whether to show a grid should be shown for a channel.
* If `grid` is unspecified, the default value is `true` for ordinal scales that are not binned
*/
export function gridShow(model: UnitModel, channel: Channel) {
export function gridShow(model: UnitModel, channel: SpatialScaleChannel) {
const grid = model.axis(channel).grid;
if (grid !== undefined) {
return grid;
Expand All @@ -29,12 +29,7 @@ export function gridShow(model: UnitModel, channel: Channel) {
return !model.hasDiscreteDomain(channel) && !model.fieldDef(channel).bin;
}

export function grid(model: UnitModel, channel: Channel, isGridAxis: boolean) {
if (channel === ROW || channel === COLUMN) {
// never apply grid for ROW and COLUMN since we manually create rule-group for them
return false;
}

export function grid(model: UnitModel, channel: SpatialScaleChannel, isGridAxis: boolean) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For my edification, why do we no longer skip grid for ROW and CHANNEL?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the new layout operator, we no longer use axes for row/column but use layout header instead. Here I basically forgot to remove the code.

if (!isGridAxis) {
return undefined;
}
Expand Down
2 changes: 1 addition & 1 deletion src/compile/data/bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export class BinNode extends DataFlowNode {

public static makeBinFromEncoding(model: ModelWithField) {
const bins = model.reduceFieldDef((binComponent: Dict<BinComponent>, fieldDef, channel) => {
const fieldDefBin = model.fieldDef(channel).bin;
const fieldDefBin = fieldDef.bin;
if (fieldDefBin) {
const bin = normalizeBin(fieldDefBin, undefined) || {};
const key = binKey(fieldDefBin, fieldDef.field);
Expand Down
3 changes: 2 additions & 1 deletion src/compile/data/nonpositivefilter.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {SCALE_CHANNELS} from '../../channel';
import {ScaleType} from '../../scale';
import {Dict, duplicate, extend, keys} from '../../util';
import {VgFilterTransform, VgTransform} from '../../vega.schema';
Expand All @@ -18,7 +19,7 @@ export class NonPositiveFilterNode extends DataFlowNode {
}

public static make(model: UnitModel) {
const filter = model.channels().reduce(function(nonPositiveComponent, channel) {
const filter = SCALE_CHANNELS.reduce(function(nonPositiveComponent, channel) {
const scale = model.getScaleComponent(channel);
if (!scale || !model.field(channel)) {
// don't set anything
Expand Down
4 changes: 0 additions & 4 deletions src/compile/facet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,10 +307,6 @@ export class FacetModel extends ModelWithField {
return marks;
}

public channels() {
return [ROW, COLUMN];
}

protected getMapping() {
return this.facet;
}
Expand Down
6 changes: 3 additions & 3 deletions src/compile/legend/parse.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Channel, COLOR, OPACITY, SHAPE, SIZE} from '../../channel';
import {Channel, COLOR, NonspatialScaleChannel, OPACITY, SHAPE, SIZE} from '../../channel';
import {Legend, LEGEND_PROPERTIES} from '../../legend';
import {Dict, keys} from '../../util';
import {VgLegend} from '../../vega.schema';
Expand Down Expand Up @@ -36,7 +36,7 @@ function getLegendDefWithScale(model: UnitModel, channel: Channel): LegendCompon
return null;
}

export function parseLegend(model: UnitModel, channel: Channel): LegendComponent {
export function parseLegend(model: UnitModel, channel: NonspatialScaleChannel): LegendComponent {
const fieldDef = model.fieldDef(channel);
const legend = model.legend(channel);

Expand Down Expand Up @@ -64,7 +64,7 @@ export function parseLegend(model: UnitModel, channel: Channel): LegendComponent
return def;
}

function getSpecifiedOrDefaultValue(property: keyof VgLegend, specifiedLegend: Legend, channel: Channel, model: UnitModel) {
function getSpecifiedOrDefaultValue(property: keyof VgLegend, specifiedLegend: Legend, channel: NonspatialScaleChannel, model: UnitModel) {
const fieldDef = model.fieldDef(channel);

switch (property) {
Expand Down
5 changes: 2 additions & 3 deletions src/compile/mark/mark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ import {UnitModel} from '../unit';

import {isArray} from 'vega-util';
import {X, Y} from '../../channel';
import {getFieldDef} from '../../encoding';
import {field} from '../../fielddef';
import {field, getFieldDef} from '../../fielddef';
import {isSelectionDomain} from '../../scale';

const markCompiler: {[type: string]: MarkCompiler} = {
Expand Down Expand Up @@ -131,7 +130,7 @@ function detailFields(model: UnitModel): string[] {
});
}
} else {
const fieldDef = getFieldDef(encoding, channel);
const fieldDef = getFieldDef<string>(encoding[channel]);
if (fieldDef && !fieldDef.aggregate) {
details.push(field(fieldDef, {binSuffix: 'start'}));
}
Expand Down
Loading