From 61a62d7193433ee7fdae37ee911c2246be784867 Mon Sep 17 00:00:00 2001 From: Kanit Wongsuphasawat Date: Sat, 10 Jun 2017 19:25:43 -0700 Subject: [PATCH] Remove ConditionLegend/TextDef, PositionDef to simplify schema file --- build/vega-lite-schema.json | 85 ++++++++++++++++++++----------------- scripts/rename-schema.sh | 4 +- src/encoding.ts | 28 ++++++------ src/fielddef.ts | 6 --- 4 files changed, 64 insertions(+), 59 deletions(-) diff --git a/build/vega-lite-schema.json b/build/vega-lite-schema.json index a28181ac8b..de84bd3f44 100644 --- a/build/vega-lite-schema.json +++ b/build/vega-lite-schema.json @@ -1156,7 +1156,7 @@ ], "type": "object" }, - "ConditionLegendDefAlias": { + "ConditionLegendDef": { "anyOf": [ { "$ref": "#/definitions/ConditionLegendFieldDef" @@ -1170,7 +1170,7 @@ ], "description": "Generic type for conditional channelDef.\nF defines the underlying FieldDef type while V defines the underlying ValueDef type." }, - "ConditionLegendDefAlias": { + "ConditionLegendDef": { "anyOf": [ { "$ref": "#/definitions/ConditionLegendFieldDef" @@ -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" @@ -1391,15 +1391,6 @@ ], "type": "object" }, - "ConditionalLegendDef": { - "$ref": "#/definitions/ConditionLegendDefAlias" - }, - "ConditionalLegendDef": { - "$ref": "#/definitions/ConditionLegendDefAlias" - }, - "ConditionalTextDef": { - "$ref": "#/definitions/ConditionTextDefAlias" - }, "ConditionLegendValueDef": { "additionalProperties": false, "description": "A ValueDef with Condition\n{\n condition: {field: ...} | {value: ...},\n value: ...,\n}", @@ -1792,7 +1783,7 @@ "additionalProperties": false, "properties": { "color": { - "$ref": "#/definitions/ConditionalLegendDef", + "$ref": "#/definitions/ConditionLegendDef", "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": { @@ -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", + "$ref": "#/definitions/ConditionLegendDef", "description": "Opacity of the marks – either can be a value or a range." }, "order": { @@ -1828,23 +1819,30 @@ "description": "stack order for stacked marks or order of data points in line marks." }, "shape": { - "$ref": "#/definitions/ConditionalLegendDef", + "$ref": "#/definitions/ConditionLegendDef", "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", + "$ref": "#/definitions/ConditionLegendDef", "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": { @@ -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": { @@ -1880,7 +1885,7 @@ "additionalProperties": false, "properties": { "color": { - "$ref": "#/definitions/ConditionalLegendDef", + "$ref": "#/definitions/ConditionLegendDef", "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": { @@ -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", + "$ref": "#/definitions/ConditionLegendDef", "description": "Opacity of the marks – either can be a value or a range." }, "order": { @@ -1924,23 +1929,30 @@ "description": "Vertical facets for trellis plots." }, "shape": { - "$ref": "#/definitions/ConditionalLegendDef", + "$ref": "#/definitions/ConditionLegendDef", "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", + "$ref": "#/definitions/ConditionLegendDef", "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": { @@ -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": { @@ -3583,16 +3602,6 @@ ], "minimum": 0 }, - "PositionDef": { - "anyOf": [ - { - "$ref": "#/definitions/PositionFieldDef" - }, - { - "$ref": "#/definitions/NumberValueDef" - } - ] - }, "PositionFieldDef": { "additionalProperties": false, "properties": { diff --git a/scripts/rename-schema.sh b/scripts/rename-schema.sh index c56de69b75..ede5a319cf 100755 --- a/scripts/rename-schema.sh +++ b/scripts/rename-schema.sh @@ -16,12 +16,12 @@ perl -pi -e s,'ValueDef<\(string\|number\|boolean\)>','TextValueDef',g build/veg perl -pi -e s,'ValueDef','StringValueDef',g build/vega-lite-schema.json perl -pi -e s,'ValueDef','NumberValueDef',g build/vega-lite-schema.json -perl -pi -e s,'Conditional','ConditionTextDefAlias',g build/vega-lite-schema.json +perl -pi -e s,'Conditional','ConditionTextDef',g build/vega-lite-schema.json perl -pi -e s,'ConditionalFieldDef','ConditionTextFieldDef',g build/vega-lite-schema.json perl -pi -e s,'ConditionalValueDef','ConditionTextValueDef',g build/vega-lite-schema.json perl -pi -e s,'ConditionOnlyDef','ConditionOnlyTextDef',g build/vega-lite-schema.json -perl -pi -e s,'Conditional { * `line`, `rule`, `text`, and `tick` * (or to width and height for `bar` and `area` marks). */ - x?: PositionDef; + x?: PositionFieldDef | ValueDef; /** * Y coordinates for `point`, `circle`, `square`, * `line`, `rule`, `text`, and `tick` * (or to width and height for `bar` and `area` marks). */ - y?: PositionDef; + y?: PositionFieldDef | ValueDef; /** * X2 coordinates for ranged `bar`, `rule`, `area`. @@ -58,12 +60,12 @@ export interface Encoding { * (By default, fill color for `area`, `bar`, `tick`, `text`, `circle`, and `square` / * stroke color for `line` and `point`.) */ - color?: ConditionalLegendDef; + color?: Conditional, ValueDef>; /** * Opacity of the marks – either can be a value or a range. */ - opacity?: ConditionalLegendDef; + opacity?: Conditional, ValueDef>; /** * Size of the mark. @@ -73,14 +75,14 @@ export interface Encoding { * - For `text` – the text's font size. * - Size is currently unsupported for `line` and `area`. */ - size?: ConditionalLegendDef; + size?: Conditional, ValueDef>; /** * 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; // TODO: maybe distinguish ordinal-only + shape?: Conditional, ValueDef>; // TODO: maybe distinguish ordinal-only /** * Additional levels of detail for grouping data in aggregate views and @@ -91,12 +93,12 @@ export interface Encoding { /** * Text of the `text` mark. */ - text?: ConditionalTextDef; + text?: Conditional, ValueDef>; /** * The tooltip text to show upon mouse hover. */ - tooltip?: ConditionalTextDef; + tooltip?: Conditional, ValueDef>; /** * stack order for stacked marks or order of data points in line marks. diff --git a/src/fielddef.ts b/src/fielddef.ts index ffeeacb1ae..6e62d4ff2e 100644 --- a/src/fielddef.ts +++ b/src/fielddef.ts @@ -149,8 +149,6 @@ export interface PositionFieldDef extends ScaleFieldDef { stack?: StackOffset; } -export type PositionDef = PositionFieldDef | ValueDef; - export interface LegendFieldDef extends ScaleFieldDef { /** * @nullable @@ -158,8 +156,6 @@ export interface LegendFieldDef extends ScaleFieldDef { legend?: Legend; } -export type ConditionalLegendDef = Conditional, ValueDef>; - // Detail // Order Path have no scale @@ -176,8 +172,6 @@ export interface TextFieldDef extends FieldDef { format?: string; } -export type ConditionalTextDef = Conditional, ValueDef>; - export type ChannelDef = Conditional, ValueDef>; export function isConditionalDef(channelDef: ChannelDef): channelDef is Conditional, ValueDef> {