Skip to content

Commit

Permalink
Separate Condition<F | V> to Condition<F> | Condition<V> to
Browse files Browse the repository at this point in the history
1) Avoid schema generator bug (cc: @domoritz)
2) Produce better schema

Also update rename script
  • Loading branch information
kanitw committed Jun 11, 2017
1 parent 61a62d7 commit 06cc8dc
Show file tree
Hide file tree
Showing 3 changed files with 168 additions and 35 deletions.
197 changes: 164 additions & 33 deletions build/vega-lite-schema.json
Expand Up @@ -1032,40 +1032,129 @@
"$ref": "#/definitions/CompositeUnitSpecAlias",
"description": "Unit spec that can have a composite mark."
},
"Condition<(LegendFieldDef|NumberValueDef)>": {
"properties": {
"selection": {
"$ref": "#/definitions/LogicalOperand"
}
},
"required": [
"selection"
],
"type": "object"
},
"Condition<(LegendFieldDef|StringValueDef)>": {
"ConditionLegendFieldDef": {
"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"
},
"selection": {
"$ref": "#/definitions/LogicalOperand"
},
"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": [
"selection"
"selection",
"type"
],
"type": "object"
},
"Condition<(TextFieldDef|TextValueDef)>": {
"ConditionTextFieldDef": {
"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`."
},
"format": {
"description": "The formatting pattern for text value. If not defined, this will be determined automatically.",
"type": "string"
},
"selection": {
"$ref": "#/definitions/LogicalOperand"
},
"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": [
"selection"
"selection",
"type"
],
"type": "object"
},
"Condition<TextValueDef>": {
"ConditionTextValueDef": {
"additionalProperties": false,
"properties": {
"selection": {
Expand All @@ -1086,7 +1175,7 @@
],
"type": "object"
},
"Condition<NumberValueDef>": {
"ConditionNumberValueDef": {
"additionalProperties": false,
"properties": {
"selection": {
Expand All @@ -1103,7 +1192,7 @@
],
"type": "object"
},
"Condition<StringValueDef>": {
"ConditionStringValueDef": {
"additionalProperties": false,
"properties": {
"selection": {
Expand All @@ -1124,7 +1213,14 @@
"additionalProperties": false,
"properties": {
"condition": {
"$ref": "#/definitions/Condition<(LegendFieldDef|NumberValueDef)>"
"anyOf": [
{
"$ref": "#/definitions/ConditionLegendFieldDef"
},
{
"$ref": "#/definitions/ConditionNumberValueDef"
}
]
}
},
"required": [
Expand All @@ -1136,7 +1232,14 @@
"additionalProperties": false,
"properties": {
"condition": {
"$ref": "#/definitions/Condition<(LegendFieldDef|StringValueDef)>"
"anyOf": [
{
"$ref": "#/definitions/ConditionLegendFieldDef"
},
{
"$ref": "#/definitions/ConditionStringValueDef"
}
]
}
},
"required": [
Expand All @@ -1148,7 +1251,14 @@
"additionalProperties": false,
"properties": {
"condition": {
"$ref": "#/definitions/Condition<(TextFieldDef|TextValueDef)>"
"anyOf": [
{
"$ref": "#/definitions/ConditionTextFieldDef"
},
{
"$ref": "#/definitions/ConditionTextValueDef"
}
]
}
},
"required": [
Expand Down Expand Up @@ -1200,7 +1310,7 @@
},
"ConditionLegendFieldDef<NumberValueDef>": {
"additionalProperties": false,
"description": "A FieldDef with Condition<ValueDef>\n{\n condition: {value: ...},\n field: ...,\n ...\n}",
"description": "A FieldDef with ConditionValueDef\n{\n condition: {value: ...},\n field: ...,\n ...\n}",
"properties": {
"aggregate": {
"anyOf": [
Expand All @@ -1225,7 +1335,7 @@
"description": "Flag for binning a `quantitative` field, or a bin property object\nfor binning parameters."
},
"condition": {
"$ref": "#/definitions/Condition<NumberValueDef>"
"$ref": "#/definitions/ConditionNumberValueDef"
},
"field": {
"$ref": "#/definitions/Field",
Expand Down Expand Up @@ -1271,7 +1381,7 @@
},
"ConditionLegendFieldDef<StringValueDef>": {
"additionalProperties": false,
"description": "A FieldDef with Condition<ValueDef>\n{\n condition: {value: ...},\n field: ...,\n ...\n}",
"description": "A FieldDef with ConditionValueDef\n{\n condition: {value: ...},\n field: ...,\n ...\n}",
"properties": {
"aggregate": {
"anyOf": [
Expand All @@ -1296,7 +1406,7 @@
"description": "Flag for binning a `quantitative` field, or a bin property object\nfor binning parameters."
},
"condition": {
"$ref": "#/definitions/Condition<StringValueDef>"
"$ref": "#/definitions/ConditionStringValueDef"
},
"field": {
"$ref": "#/definitions/Field",
Expand Down Expand Up @@ -1342,7 +1452,7 @@
},
"ConditionTextFieldDef": {
"additionalProperties": false,
"description": "A FieldDef with Condition<ValueDef>\n{\n condition: {value: ...},\n field: ...,\n ...\n}",
"description": "A FieldDef with ConditionValueDef\n{\n condition: {value: ...},\n field: ...,\n ...\n}",
"properties": {
"aggregate": {
"anyOf": [
Expand All @@ -1367,7 +1477,7 @@
"description": "Flag for binning a `quantitative` field, or a bin property object\nfor binning parameters."
},
"condition": {
"$ref": "#/definitions/Condition<TextValueDef>"
"$ref": "#/definitions/ConditionTextValueDef"
},
"field": {
"$ref": "#/definitions/Field",
Expand All @@ -1393,10 +1503,17 @@
},
"ConditionLegendValueDef<NumberValueDef>": {
"additionalProperties": false,
"description": "A ValueDef with Condition<ValueDef | FieldDef>\n{\n condition: {field: ...} | {value: ...},\n value: ...,\n}",
"description": "A ValueDef with ConditionValueDef | FieldDef\n{\n condition: {field: ...} | {value: ...},\n value: ...,\n}",
"properties": {
"condition": {
"$ref": "#/definitions/Condition<(LegendFieldDef|NumberValueDef)>"
"anyOf": [
{
"$ref": "#/definitions/ConditionLegendFieldDef"
},
{
"$ref": "#/definitions/ConditionNumberValueDef"
}
]
},
"value": {
"description": "A constant value in visual domain.",
Expand All @@ -1410,10 +1527,17 @@
},
"ConditionLegendValueDef<StringValueDef>": {
"additionalProperties": false,
"description": "A ValueDef with Condition<ValueDef | FieldDef>\n{\n condition: {field: ...} | {value: ...},\n value: ...,\n}",
"description": "A ValueDef with ConditionValueDef | FieldDef\n{\n condition: {field: ...} | {value: ...},\n value: ...,\n}",
"properties": {
"condition": {
"$ref": "#/definitions/Condition<(LegendFieldDef|StringValueDef)>"
"anyOf": [
{
"$ref": "#/definitions/ConditionLegendFieldDef"
},
{
"$ref": "#/definitions/ConditionStringValueDef"
}
]
},
"value": {
"description": "A constant value in visual domain.",
Expand All @@ -1427,10 +1551,17 @@
},
"ConditionTextValueDef": {
"additionalProperties": false,
"description": "A ValueDef with Condition<ValueDef | FieldDef>\n{\n condition: {field: ...} | {value: ...},\n value: ...,\n}",
"description": "A ValueDef with ConditionValueDef | FieldDef\n{\n condition: {field: ...} | {value: ...},\n value: ...,\n}",
"properties": {
"condition": {
"$ref": "#/definitions/Condition<(TextFieldDef|TextValueDef)>"
"anyOf": [
{
"$ref": "#/definitions/ConditionTextFieldDef"
},
{
"$ref": "#/definitions/ConditionTextValueDef"
}
]
},
"value": {
"description": "A constant value in visual domain.",
Expand Down
2 changes: 2 additions & 0 deletions scripts/rename-schema.sh
Expand Up @@ -16,6 +16,8 @@ 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,'Condition<(.*)>','Condition\1',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
Expand Down
4 changes: 2 additions & 2 deletions src/fielddef.ts
Expand Up @@ -49,7 +49,7 @@ export type Condition<T> = {
export type ConditionalFieldDef<F extends FieldDef<any>, V extends ValueDef<any>> = F & {condition?: Condition<V>};

export interface ConditionOnlyDef <F extends FieldDef<any>, V extends ValueDef<any>> {
condition: Condition<F | V>;
condition: Condition<F> | Condition<V>;
}


Expand All @@ -60,7 +60,7 @@ export interface ConditionOnlyDef <F extends FieldDef<any>, V extends ValueDef<a
* value: ...,
* }
*/
export type ConditionalValueDef<F extends FieldDef<any>, V extends ValueDef<any>> = V & {condition?: Condition<F | V>;};
export type ConditionalValueDef<F extends FieldDef<any>, V extends ValueDef<any>> = V & {condition?: Condition<F> | Condition<V>;};

/**
* Reference to a repeated value.
Expand Down

0 comments on commit 06cc8dc

Please sign in to comment.