Skip to content

Commit

Permalink
Remove ConditionLegend/TextDef, PositionDef to simplify schema file
Browse files Browse the repository at this point in the history
  • Loading branch information
kanitw committed Jun 11, 2017
1 parent ddf2317 commit 61a62d7
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 59 deletions.
85 changes: 47 additions & 38 deletions build/vega-lite-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1156,7 +1156,7 @@
],
"type": "object"
},
"ConditionLegendDefAlias<NumberValueDef>": {
"ConditionLegendDef<NumberValueDef>": {
"anyOf": [
{
"$ref": "#/definitions/ConditionLegendFieldDef<NumberValueDef>"
Expand All @@ -1170,7 +1170,7 @@
],
"description": "Generic type for conditional channelDef.\nF defines the underlying FieldDef type while V defines the underlying ValueDef type."
},
"ConditionLegendDefAlias<StringValueDef>": {
"ConditionLegendDef<StringValueDef>": {
"anyOf": [
{
"$ref": "#/definitions/ConditionLegendFieldDef<StringValueDef>"
Expand All @@ -1184,7 +1184,7 @@
],
"description": "Generic type for conditional channelDef.\nF defines the underlying FieldDef type while V defines the underlying ValueDef type."
},
"ConditionTextDefAlias": {
"ConditionTextDef": {
"anyOf": [
{
"$ref": "#/definitions/ConditionTextFieldDef"
Expand Down Expand Up @@ -1391,15 +1391,6 @@
],
"type": "object"
},
"ConditionalLegendDef<number>": {
"$ref": "#/definitions/ConditionLegendDefAlias<NumberValueDef>"
},
"ConditionalLegendDef<string>": {
"$ref": "#/definitions/ConditionLegendDefAlias<StringValueDef>"
},
"ConditionalTextDef": {
"$ref": "#/definitions/ConditionTextDefAlias"
},
"ConditionLegendValueDef<NumberValueDef>": {
"additionalProperties": false,
"description": "A ValueDef with Condition<ValueDef | FieldDef>\n{\n condition: {field: ...} | {value: ...},\n value: ...,\n}",
Expand Down Expand Up @@ -1792,7 +1783,7 @@
"additionalProperties": false,
"properties": {
"color": {
"$ref": "#/definitions/ConditionalLegendDef<string>",
"$ref": "#/definitions/ConditionLegendDef<StringValueDef>",
"description": "Color of the marks – either fill or stroke color based on mark type.\n(By default, fill color for `area`, `bar`, `tick`, `text`, `circle`, and `square` /\nstroke color for `line` and `point`.)"
},
"detail": {
Expand All @@ -1810,7 +1801,7 @@
"description": "Additional levels of detail for grouping data in aggregate views and\nin line and area marks without mapping data to a specific visual channel."
},
"opacity": {
"$ref": "#/definitions/ConditionalLegendDef<number>",
"$ref": "#/definitions/ConditionLegendDef<NumberValueDef>",
"description": "Opacity of the marks – either can be a value or a range."
},
"order": {
Expand All @@ -1828,23 +1819,30 @@
"description": "stack order for stacked marks or order of data points in line marks."
},
"shape": {
"$ref": "#/definitions/ConditionalLegendDef<string>",
"$ref": "#/definitions/ConditionLegendDef<StringValueDef>",
"description": "The symbol's shape (only for `point` marks). The supported values are\n`\"circle\"` (default), `\"square\"`, `\"cross\"`, `\"diamond\"`, `\"triangle-up\"`,\nor `\"triangle-down\"`, or else a custom SVG path string."
},
"size": {
"$ref": "#/definitions/ConditionalLegendDef<number>",
"$ref": "#/definitions/ConditionLegendDef<NumberValueDef>",
"description": "Size of the mark.\n- For `point`, `square` and `circle`\n– the symbol size, or pixel area of the mark.\n- For `bar` and `tick` – the bar and tick's size.\n- For `text` – the text's font size.\n- Size is currently unsupported for `line` and `area`."
},
"text": {
"$ref": "#/definitions/ConditionalTextDef",
"$ref": "#/definitions/ConditionTextDef",
"description": "Text of the `text` mark."
},
"tooltip": {
"$ref": "#/definitions/ConditionalTextDef",
"$ref": "#/definitions/ConditionTextDef",
"description": "The tooltip text to show upon mouse hover."
},
"x": {
"$ref": "#/definitions/PositionDef",
"anyOf": [
{
"$ref": "#/definitions/PositionFieldDef"
},
{
"$ref": "#/definitions/NumberValueDef"
}
],
"description": "X coordinates for `point`, `circle`, `square`,\n`line`, `rule`, `text`, and `tick`\n(or to width and height for `bar` and `area` marks)."
},
"x2": {
Expand All @@ -1859,7 +1857,14 @@
"description": "X2 coordinates for ranged `bar`, `rule`, `area`."
},
"y": {
"$ref": "#/definitions/PositionDef",
"anyOf": [
{
"$ref": "#/definitions/PositionFieldDef"
},
{
"$ref": "#/definitions/NumberValueDef"
}
],
"description": "Y coordinates for `point`, `circle`, `square`,\n`line`, `rule`, `text`, and `tick`\n(or to width and height for `bar` and `area` marks)."
},
"y2": {
Expand All @@ -1880,7 +1885,7 @@
"additionalProperties": false,
"properties": {
"color": {
"$ref": "#/definitions/ConditionalLegendDef<string>",
"$ref": "#/definitions/ConditionLegendDef<StringValueDef>",
"description": "Color of the marks – either fill or stroke color based on mark type.\n(By default, fill color for `area`, `bar`, `tick`, `text`, `circle`, and `square` /\nstroke color for `line` and `point`.)"
},
"column": {
Expand All @@ -1902,7 +1907,7 @@
"description": "Additional levels of detail for grouping data in aggregate views and\nin line and area marks without mapping data to a specific visual channel."
},
"opacity": {
"$ref": "#/definitions/ConditionalLegendDef<number>",
"$ref": "#/definitions/ConditionLegendDef<NumberValueDef>",
"description": "Opacity of the marks – either can be a value or a range."
},
"order": {
Expand All @@ -1924,23 +1929,30 @@
"description": "Vertical facets for trellis plots."
},
"shape": {
"$ref": "#/definitions/ConditionalLegendDef<string>",
"$ref": "#/definitions/ConditionLegendDef<StringValueDef>",
"description": "The symbol's shape (only for `point` marks). The supported values are\n`\"circle\"` (default), `\"square\"`, `\"cross\"`, `\"diamond\"`, `\"triangle-up\"`,\nor `\"triangle-down\"`, or else a custom SVG path string."
},
"size": {
"$ref": "#/definitions/ConditionalLegendDef<number>",
"$ref": "#/definitions/ConditionLegendDef<NumberValueDef>",
"description": "Size of the mark.\n- For `point`, `square` and `circle`\n– the symbol size, or pixel area of the mark.\n- For `bar` and `tick` – the bar and tick's size.\n- For `text` – the text's font size.\n- Size is currently unsupported for `line` and `area`."
},
"text": {
"$ref": "#/definitions/ConditionalTextDef",
"$ref": "#/definitions/ConditionTextDef",
"description": "Text of the `text` mark."
},
"tooltip": {
"$ref": "#/definitions/ConditionalTextDef",
"$ref": "#/definitions/ConditionTextDef",
"description": "The tooltip text to show upon mouse hover."
},
"x": {
"$ref": "#/definitions/PositionDef",
"anyOf": [
{
"$ref": "#/definitions/PositionFieldDef"
},
{
"$ref": "#/definitions/NumberValueDef"
}
],
"description": "X coordinates for `point`, `circle`, `square`,\n`line`, `rule`, `text`, and `tick`\n(or to width and height for `bar` and `area` marks)."
},
"x2": {
Expand All @@ -1955,7 +1967,14 @@
"description": "X2 coordinates for ranged `bar`, `rule`, `area`."
},
"y": {
"$ref": "#/definitions/PositionDef",
"anyOf": [
{
"$ref": "#/definitions/PositionFieldDef"
},
{
"$ref": "#/definitions/NumberValueDef"
}
],
"description": "Y coordinates for `point`, `circle`, `square`,\n`line`, `rule`, `text`, and `tick`\n(or to width and height for `bar` and `area` marks)."
},
"y2": {
Expand Down Expand Up @@ -3583,16 +3602,6 @@
],
"minimum": 0
},
"PositionDef": {
"anyOf": [
{
"$ref": "#/definitions/PositionFieldDef"
},
{
"$ref": "#/definitions/NumberValueDef"
}
]
},
"PositionFieldDef": {
"additionalProperties": false,
"properties": {
Expand Down
4 changes: 2 additions & 2 deletions scripts/rename-schema.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ perl -pi -e s,'ValueDef<\(string\|number\|boolean\)>','TextValueDef',g build/veg
perl -pi -e s,'ValueDef<string>','StringValueDef',g build/vega-lite-schema.json
perl -pi -e s,'ValueDef<number>','NumberValueDef',g build/vega-lite-schema.json

perl -pi -e s,'Conditional<TextFieldDef\,TextValueDef>','ConditionTextDefAlias',g build/vega-lite-schema.json
perl -pi -e s,'Conditional<TextFieldDef\,TextValueDef>','ConditionTextDef',g build/vega-lite-schema.json
perl -pi -e s,'ConditionalFieldDef<TextFieldDef\,TextValueDef>','ConditionTextFieldDef',g build/vega-lite-schema.json
perl -pi -e s,'ConditionalValueDef<TextFieldDef\,TextValueDef>','ConditionTextValueDef',g build/vega-lite-schema.json
perl -pi -e s,'ConditionOnlyDef<TextFieldDef\,TextValueDef>','ConditionOnlyTextDef',g build/vega-lite-schema.json

perl -pi -e s,'Conditional<LegendFieldDef\,','ConditionLegendDefAlias<',g build/vega-lite-schema.json
perl -pi -e s,'Conditional<LegendFieldDef\,','ConditionLegendDef<',g build/vega-lite-schema.json
perl -pi -e s,'ConditionalFieldDef<LegendFieldDef\,','ConditionLegendFieldDef<',g build/vega-lite-schema.json
perl -pi -e s,'ConditionalValueDef<LegendFieldDef\,','ConditionLegendValueDef<',g build/vega-lite-schema.json
perl -pi -e s,'ConditionOnlyDef<LegendFieldDef\,','ConditionOnlyLegendDef<',g build/vega-lite-schema.json
Expand Down
28 changes: 15 additions & 13 deletions src/encoding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,22 @@ import {Facet} from './facet';
import {
ChannelDef,
Condition,
ConditionalLegendDef,
ConditionalTextDef,
ConditionalValueDef,
Conditional,
Field,
FieldDef,
getFieldDef,
hasConditionFieldDef,
isConditionalDef,
isFieldDef,
isValueDef,
LegendFieldDef,
normalize,
normalizeFieldDef,
OrderFieldDef,
PositionDef,
PositionFieldDef,
TextFieldDef,
ValueDef
} from './fielddef';
import {getFieldDef, hasConditionFieldDef, isConditionalDef} from './fielddef';
import * as log from './log';
import {Mark} from './mark';
import {isArray, some} from './util';
Expand All @@ -32,14 +34,14 @@ export interface Encoding<F> {
* `line`, `rule`, `text`, and `tick`
* (or to width and height for `bar` and `area` marks).
*/
x?: PositionDef<F>;
x?: PositionFieldDef<F> | ValueDef<number>;

/**
* Y coordinates for `point`, `circle`, `square`,
* `line`, `rule`, `text`, and `tick`
* (or to width and height for `bar` and `area` marks).
*/
y?: PositionDef<F>;
y?: PositionFieldDef<F> | ValueDef<number>;

/**
* X2 coordinates for ranged `bar`, `rule`, `area`.
Expand All @@ -58,12 +60,12 @@ export interface Encoding<F> {
* (By default, fill color for `area`, `bar`, `tick`, `text`, `circle`, and `square` /
* stroke color for `line` and `point`.)
*/
color?: ConditionalLegendDef<F, string>;
color?: Conditional<LegendFieldDef<F>, ValueDef<string>>;

/**
* Opacity of the marks – either can be a value or a range.
*/
opacity?: ConditionalLegendDef<F, number>;
opacity?: Conditional<LegendFieldDef<F>, ValueDef<number>>;

/**
* Size of the mark.
Expand All @@ -73,14 +75,14 @@ export interface Encoding<F> {
* - For `text` – the text's font size.
* - Size is currently unsupported for `line` and `area`.
*/
size?: ConditionalLegendDef<F, number>;
size?: Conditional<LegendFieldDef<F>, ValueDef<number>>;

/**
* The symbol's shape (only for `point` marks). The supported values are
* `"circle"` (default), `"square"`, `"cross"`, `"diamond"`, `"triangle-up"`,
* or `"triangle-down"`, or else a custom SVG path string.
*/
shape?: ConditionalLegendDef<F, string>; // TODO: maybe distinguish ordinal-only
shape?: Conditional<LegendFieldDef<F>, ValueDef<string>>; // TODO: maybe distinguish ordinal-only

/**
* Additional levels of detail for grouping data in aggregate views and
Expand All @@ -91,12 +93,12 @@ export interface Encoding<F> {
/**
* Text of the `text` mark.
*/
text?: ConditionalTextDef<F>;
text?: Conditional<TextFieldDef<F>, ValueDef<string|number|boolean>>;

/**
* The tooltip text to show upon mouse hover.
*/
tooltip?: ConditionalTextDef<F>;
tooltip?: Conditional<TextFieldDef<F>, ValueDef<string|number|boolean>>;

/**
* stack order for stacked marks or order of data points in line marks.
Expand Down
6 changes: 0 additions & 6 deletions src/fielddef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,17 +149,13 @@ export interface PositionFieldDef<F> extends ScaleFieldDef<F> {
stack?: StackOffset;
}

export type PositionDef<F> = PositionFieldDef<F> | ValueDef<number>;

export interface LegendFieldDef<F> extends ScaleFieldDef<F> {
/**
* @nullable
*/
legend?: Legend;
}

export type ConditionalLegendDef<F, T> = Conditional<LegendFieldDef<F>, ValueDef<T>>;

// Detail

// Order Path have no scale
Expand All @@ -176,8 +172,6 @@ export interface TextFieldDef<F> extends FieldDef<F> {
format?: string;
}

export type ConditionalTextDef<F> = Conditional<TextFieldDef<F>, ValueDef<string|number|boolean>>;

export type ChannelDef<F> = Conditional<FieldDef<F>, ValueDef<any>>;

export function isConditionalDef<F>(channelDef: ChannelDef<F>): channelDef is Conditional<FieldDef<F>, ValueDef<any>> {
Expand Down

0 comments on commit 61a62d7

Please sign in to comment.