Skip to content

Commit

Permalink
Simplify schema
Browse files Browse the repository at this point in the history
  • Loading branch information
kanitw committed Jun 10, 2017
1 parent 584361b commit 6e2790a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 103 deletions.
133 changes: 33 additions & 100 deletions build/vega-lite-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1032,7 +1032,7 @@
"$ref": "#/definitions/CompositeUnitSpecAlias",
"description": "Unit spec that can have a composite mark."
},
"Condition<(LegendFieldDef<Field,number>|ValueDef<number>)>": {
"Condition<(LegendFieldDef|ValueDef<number>)>": {
"properties": {
"selection": {
"$ref": "#/definitions/LogicalOperand"
Expand All @@ -1043,7 +1043,7 @@
],
"type": "object"
},
"Condition<(LegendFieldDef<Field,string>|ValueDef<string>)>": {
"Condition<(LegendFieldDef|ValueDef<string>)>": {
"properties": {
"selection": {
"$ref": "#/definitions/LogicalOperand"
Expand Down Expand Up @@ -1120,23 +1120,23 @@
],
"type": "object"
},
"ConditionOnlyDef<LegendFieldDef<Field,number>,ValueDef<number>>": {
"ConditionOnlyDef<LegendFieldDef,ValueDef<number>>": {
"additionalProperties": false,
"properties": {
"condition": {
"$ref": "#/definitions/Condition<(LegendFieldDef<Field,number>|ValueDef<number>)>"
"$ref": "#/definitions/Condition<(LegendFieldDef|ValueDef<number>)>"
}
},
"required": [
"condition"
],
"type": "object"
},
"ConditionOnlyDef<LegendFieldDef<Field,string>,ValueDef<string>>": {
"ConditionOnlyDef<LegendFieldDef,ValueDef<string>>": {
"additionalProperties": false,
"properties": {
"condition": {
"$ref": "#/definitions/Condition<(LegendFieldDef<Field,string>|ValueDef<string>)>"
"$ref": "#/definitions/Condition<(LegendFieldDef|ValueDef<string>)>"
}
},
"required": [
Expand All @@ -1156,30 +1156,30 @@
],
"type": "object"
},
"Conditional<LegendFieldDef<Field,number>,ValueDef<number>>": {
"Conditional<LegendFieldDef,ValueDef<number>>": {
"anyOf": [
{
"$ref": "#/definitions/ConditionalFieldDef<LegendFieldDef<Field,number>,ValueDef<number>>"
"$ref": "#/definitions/ConditionalFieldDef<LegendFieldDef,ValueDef<number>>"
},
{
"$ref": "#/definitions/ConditionalValueDef<LegendFieldDef<Field,number>,ValueDef<number>>"
"$ref": "#/definitions/ConditionalValueDef<LegendFieldDef,ValueDef<number>>"
},
{
"$ref": "#/definitions/ConditionOnlyDef<LegendFieldDef<Field,number>,ValueDef<number>>"
"$ref": "#/definitions/ConditionOnlyDef<LegendFieldDef,ValueDef<number>>"
}
],
"description": "Generic type for conditional channelDef.\nF defines the underlying FieldDef type while V defines the underlying ValueDef type."
},
"Conditional<LegendFieldDef<Field,string>,ValueDef<string>>": {
"Conditional<LegendFieldDef,ValueDef<string>>": {
"anyOf": [
{
"$ref": "#/definitions/ConditionalFieldDef<LegendFieldDef<Field,string>,ValueDef<string>>"
"$ref": "#/definitions/ConditionalFieldDef<LegendFieldDef,ValueDef<string>>"
},
{
"$ref": "#/definitions/ConditionalValueDef<LegendFieldDef<Field,string>,ValueDef<string>>"
"$ref": "#/definitions/ConditionalValueDef<LegendFieldDef,ValueDef<string>>"
},
{
"$ref": "#/definitions/ConditionOnlyDef<LegendFieldDef<Field,string>,ValueDef<string>>"
"$ref": "#/definitions/ConditionOnlyDef<LegendFieldDef,ValueDef<string>>"
}
],
"description": "Generic type for conditional channelDef.\nF defines the underlying FieldDef type while V defines the underlying ValueDef type."
Expand All @@ -1198,7 +1198,7 @@
],
"description": "Generic type for conditional channelDef.\nF defines the underlying FieldDef type while V defines the underlying ValueDef type."
},
"ConditionalFieldDef<LegendFieldDef<Field,number>,ValueDef<number>>": {
"ConditionalFieldDef<LegendFieldDef,ValueDef<number>>": {
"additionalProperties": false,
"description": "A FieldDef with Condition<ValueDef>\n{\n condition: {value: ...},\n field: ...,\n ...\n}",
"properties": {
Expand Down Expand Up @@ -1269,7 +1269,7 @@
],
"type": "object"
},
"ConditionalFieldDef<LegendFieldDef<Field,string>,ValueDef<string>>": {
"ConditionalFieldDef<LegendFieldDef,ValueDef<string>>": {
"additionalProperties": false,
"description": "A FieldDef with Condition<ValueDef>\n{\n condition: {value: ...},\n field: ...,\n ...\n}",
"properties": {
Expand Down Expand Up @@ -1391,21 +1391,21 @@
],
"type": "object"
},
"ConditionalLegendDef<Field,number>": {
"$ref": "#/definitions/Conditional<LegendFieldDef<Field,number>,ValueDef<number>>"
"ConditionalLegendDef<number>": {
"$ref": "#/definitions/Conditional<LegendFieldDef,ValueDef<number>>"
},
"ConditionalLegendDef<Field,string>": {
"$ref": "#/definitions/Conditional<LegendFieldDef<Field,string>,ValueDef<string>>"
"ConditionalLegendDef<string>": {
"$ref": "#/definitions/Conditional<LegendFieldDef,ValueDef<string>>"
},
"ConditionalTextDef": {
"$ref": "#/definitions/Conditional<TextFieldDef,ValueDef<(string|number|boolean)>>"
},
"ConditionalValueDef<LegendFieldDef<Field,number>,ValueDef<number>>": {
"ConditionalValueDef<LegendFieldDef,ValueDef<number>>": {
"additionalProperties": false,
"description": "A ValueDef with Condition<ValueDef | FieldDef>\n{\n condition: {field: ...} | {value: ...},\n value: ...,\n}",
"properties": {
"condition": {
"$ref": "#/definitions/Condition<(LegendFieldDef<Field,number>|ValueDef<number>)>"
"$ref": "#/definitions/Condition<(LegendFieldDef|ValueDef<number>)>"
},
"value": {
"description": "A constant value in visual domain.",
Expand All @@ -1417,12 +1417,12 @@
],
"type": "object"
},
"ConditionalValueDef<LegendFieldDef<Field,string>,ValueDef<string>>": {
"ConditionalValueDef<LegendFieldDef,ValueDef<string>>": {
"additionalProperties": false,
"description": "A ValueDef with Condition<ValueDef | FieldDef>\n{\n condition: {field: ...} | {value: ...},\n value: ...,\n}",
"properties": {
"condition": {
"$ref": "#/definitions/Condition<(LegendFieldDef<Field,string>|ValueDef<string>)>"
"$ref": "#/definitions/Condition<(LegendFieldDef|ValueDef<string>)>"
},
"value": {
"description": "A constant value in visual domain.",
Expand Down Expand Up @@ -1792,7 +1792,7 @@
"additionalProperties": false,
"properties": {
"color": {
"$ref": "#/definitions/ConditionalLegendDef<Field,string>",
"$ref": "#/definitions/ConditionalLegendDef<string>",
"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 +1810,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<Field,number>",
"$ref": "#/definitions/ConditionalLegendDef<number>",
"description": "Opacity of the marks – either can be a value or a range."
},
"order": {
Expand All @@ -1828,11 +1828,11 @@
"description": "stack order for stacked marks or order of data points in line marks."
},
"shape": {
"$ref": "#/definitions/ConditionalLegendDef<Field,string>",
"$ref": "#/definitions/ConditionalLegendDef<string>",
"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<Field,number>",
"$ref": "#/definitions/ConditionalLegendDef<number>",
"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": {
Expand Down Expand Up @@ -1880,7 +1880,7 @@
"additionalProperties": false,
"properties": {
"color": {
"$ref": "#/definitions/ConditionalLegendDef<Field,string>",
"$ref": "#/definitions/ConditionalLegendDef<string>",
"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 +1902,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<Field,number>",
"$ref": "#/definitions/ConditionalLegendDef<number>",
"description": "Opacity of the marks – either can be a value or a range."
},
"order": {
Expand All @@ -1924,11 +1924,11 @@
"description": "Vertical facets for trellis plots."
},
"shape": {
"$ref": "#/definitions/ConditionalLegendDef<Field,string>",
"$ref": "#/definitions/ConditionalLegendDef<string>",
"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<Field,number>",
"$ref": "#/definitions/ConditionalLegendDef<number>",
"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": {
Expand Down Expand Up @@ -2921,74 +2921,7 @@
},
"type": "object"
},
"LegendFieldDef<Field,number>": {
"additionalProperties": false,
"properties": {
"aggregate": {
"anyOf": [
{
"$ref": "#/definitions/AggregateOp"
},
{
"$ref": "#/definitions/CompositeAggregate"
}
],
"description": "Aggregation function for the field\n(e.g., `mean`, `sum`, `median`, `min`, `max`, `count`).\n\n__Default value:__ `undefined` (None)"
},
"bin": {
"anyOf": [
{
"type": "boolean"
},
{
"$ref": "#/definitions/Bin"
}
],
"description": "Flag for binning a `quantitative` field, or a bin property object\nfor binning parameters."
},
"field": {
"$ref": "#/definitions/Field",
"description": "__Required.__ Name of the field from which to pull a data value.\n\n__Note:__ `field` is not required if `aggregate` is `count`."
},
"legend": {
"anyOf": [
{
"$ref": "#/definitions/Legend"
},
{
"type": "null"
}
]
},
"scale": {
"$ref": "#/definitions/Scale"
},
"sort": {
"anyOf": [
{
"$ref": "#/definitions/SortField"
},
{
"$ref": "#/definitions/SortOrder"
}
],
"description": "Sort order for a particular field.\nFor quantitative or temporal fields, this can be either `\"ascending\"` or `\"descending\"`\nFor quantitative or temporal fields, this can be `\"ascending\"`, `\"descending\"`, `\"none\"`, or a [sort field definition object](sort.html#sort-field) for sorting by an aggregate calculation of a specified sort field.\n\n__Default value:__ `\"ascending\"`"
},
"timeUnit": {
"$ref": "#/definitions/TimeUnit",
"description": "Time unit for a `temporal` field (e.g., `year`, `yearmonth`, `month`, `hour`).\n\n__Default value:__ `undefined` (None)"
},
"type": {
"$ref": "#/definitions/Type",
"description": "The encoded field's type of measurement. This can be either a full type\nname (`\"quantitative\"`, `\"temporal\"`, `\"ordinal\"`, and `\"nominal\"`)\nor an initial character of the type name (`\"Q\"`, `\"T\"`, `\"O\"`, `\"N\"`).\nThis property is case-insensitive."
}
},
"required": [
"type"
],
"type": "object"
},
"LegendFieldDef<Field,string>": {
"LegendFieldDef": {
"additionalProperties": false,
"properties": {
"aggregate": {
Expand Down
1 change: 1 addition & 0 deletions scripts/rename-schema.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
perl -pi -e s,'<Field>','',g build/vega-lite-schema.json
perl -pi -e s,'<Field\,','<',g build/vega-lite-schema.json
perl -pi -e s,'FacetedCompositeUnitSpec','FacetedUnitSpec',g build/vega-lite-schema.json
perl -pi -e s,'GenericLayerSpec<CompositeUnitSpec>','LayerSpec',g build/vega-lite-schema.json
perl -pi -e s,'GenericFacetSpec<CompositeUnitSpec>','FacetedSpec',g build/vega-lite-schema.json
Expand Down
6 changes: 3 additions & 3 deletions src/fielddef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,14 @@ export interface PositionFieldDef<F> extends ScaleFieldDef<F> {

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

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

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

// Detail

Expand Down Expand Up @@ -191,7 +191,7 @@ export function hasConditionFieldDef<F>(channelDef: ChannelDef<F>): channelDef i
return !!channelDef && !!channelDef.condition && isFieldDef(channelDef.condition);
}

export function isFieldDef<F>(channelDef: ChannelDef<F>): channelDef is FieldDef<F> | PositionFieldDef<F> | LegendFieldDef<F, any> | OrderFieldDef<F> | TextFieldDef<F> {
export function isFieldDef<F>(channelDef: ChannelDef<F>): channelDef is FieldDef<F> | PositionFieldDef<F> | LegendFieldDef<F> | OrderFieldDef<F> | TextFieldDef<F> {
return !!channelDef && (!!channelDef['field'] || channelDef['aggregate'] === 'count');
}

Expand Down

0 comments on commit 6e2790a

Please sign in to comment.