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

feat: support datum in encoding #6150

Merged
merged 9 commits into from
Mar 25, 2020
Merged
Show file tree
Hide file tree
Changes from 8 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
1,968 changes: 1,258 additions & 710 deletions build/vega-lite-schema.json

Large diffs are not rendered by default.

38 changes: 7 additions & 31 deletions examples/compiled/layer_bar_annotations.vg.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@
{"Day": 15, "Value": 130.5}
]
},
{
"name": "source_1",
"values": [{"ThresholdValue": 300, "Threshold": "hazardous"}]
},
{"name": "source_1", "values": [{}]},
{
"name": "data_1",
"source": "source_0",
Expand All @@ -51,26 +48,6 @@
"expr": "isValid(datum[\"baseline\"]) && isFinite(+datum[\"baseline\"])"
}
]
},
{
"name": "data_4",
"source": "source_1",
"transform": [
{
"type": "filter",
"expr": "isValid(datum[\"ThresholdValue\"]) && isFinite(+datum[\"ThresholdValue\"])"
}
]
},
{
"name": "data_5",
"source": "source_1",
"transform": [
{
"type": "filter",
"expr": "isValid(datum[\"ThresholdValue\"]) && isFinite(+datum[\"ThresholdValue\"])"
}
]
}
],
"signals": [
Expand Down Expand Up @@ -115,31 +92,31 @@
"name": "layer_1_layer_0_marks",
"type": "rule",
"style": ["rule"],
"from": {"data": "data_4"},
"from": {"data": "source_1"},
"encode": {
"update": {
"stroke": {"value": "black"},
"x": {"field": {"group": "width"}},
"x2": {"value": 0},
"y": {"scale": "y", "field": "ThresholdValue"}
"y": {"scale": "y", "value": 300}
}
}
},
{
"name": "layer_1_layer_1_marks",
"type": "text",
"style": ["text"],
"from": {"data": "data_5"},
"from": {"data": "source_1"},
"encode": {
"update": {
"align": {"value": "right"},
"baseline": {"value": "bottom"},
"text": {"value": "hazardous"},
"dx": {"value": -2},
"dy": {"value": -2},
"fill": {"value": "black"},
"x": {"field": {"group": "width"}},
"y": {"scale": "y", "field": "ThresholdValue"},
"text": {"signal": "''+datum[\"Threshold\"]"}
"y": {"scale": "y", "value": 300}
}
}
}
Expand Down Expand Up @@ -167,8 +144,7 @@
{"data": "data_1", "field": "Value"},
{"data": "data_2", "field": "baseline"},
{"data": "data_2", "field": "Value"},
{"data": "data_4", "field": "ThresholdValue"},
{"data": "data_5", "field": "ThresholdValue"}
[300]
]
},
"range": [{"signal": "height"}, 0],
Expand Down
1 change: 1 addition & 0 deletions examples/compiled/layer_line_datum_rule.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
140 changes: 140 additions & 0 deletions examples/compiled/layer_line_datum_rule.vg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
{
"$schema": "https://vega.github.io/schema/vega/v5.json",
"background": "white",
"padding": 5,
"width": 200,
"height": 200,
"style": "cell",
"data": [
{
"name": "source_0",
"url": "data/stocks.csv",
"format": {"type": "csv", "parse": {"date": "date"}}
},
{"name": "source_1", "values": [{}]}
],
"marks": [
{
"name": "layer_0_pathgroup",
"type": "group",
"from": {
"facet": {
"name": "faceted_path_layer_0_main",
"data": "source_0",
"groupby": ["symbol"]
}
},
"encode": {
"update": {
"width": {"field": {"group": "width"}},
"height": {"field": {"group": "height"}}
}
},
"marks": [
{
"name": "layer_0_marks",
"type": "line",
"style": ["line"],
"sort": {"field": "datum[\"date\"]"},
"from": {"data": "faceted_path_layer_0_main"},
"encode": {
"update": {
"stroke": {"scale": "color", "field": "symbol"},
"x": {"scale": "x", "field": "date"},
"y": {"scale": "y", "field": "price"},
"defined": {
"signal": "isValid(datum[\"date\"]) && isFinite(+datum[\"date\"]) && isValid(datum[\"price\"]) && isFinite(+datum[\"price\"])"
}
}
}
}
]
},
{
"name": "layer_1_marks",
"type": "rule",
"style": ["rule"],
"from": {"data": "source_1"},
"encode": {
"update": {
"strokeDash": {"value": [2, 2]},
"stroke": {"value": "black"},
"x": {"field": {"group": "width"}},
"x2": {"value": 0},
"y": {"scale": "y", "value": 300},
"strokeWidth": {"value": 2}
}
}
}
],
"scales": [
{
"name": "x",
"type": "time",
"domain": {"data": "source_0", "field": "date"},
"range": [0, {"signal": "width"}]
},
{
"name": "y",
"type": "linear",
"domain": {"fields": [{"data": "source_0", "field": "price"}, [300]]},
"range": [{"signal": "height"}, 0],
"nice": true,
"zero": true
},
{
"name": "color",
"type": "ordinal",
"domain": {"data": "source_0", "field": "symbol", "sort": true},
"range": "category"
}
],
"axes": [
{
"scale": "x",
"orient": "bottom",
"gridScale": "y",
"grid": true,
"tickCount": {"signal": "ceil(width/40)"},
"domain": false,
"labels": false,
"maxExtent": 0,
"minExtent": 0,
"ticks": false,
"zindex": 0
},
{
"scale": "y",
"orient": "left",
"gridScale": "x",
"grid": true,
"tickCount": {"signal": "ceil(height/40)"},
"domain": false,
"labels": false,
"maxExtent": 0,
"minExtent": 0,
"ticks": false,
"zindex": 0
},
{
"scale": "x",
"orient": "bottom",
"grid": false,
"title": "date",
"labelFlush": true,
"labelOverlap": true,
"tickCount": {"signal": "ceil(width/40)"},
"zindex": 0
},
{
"scale": "y",
"orient": "left",
"grid": false,
"title": "price",
"labelOverlap": true,
"tickCount": {"signal": "ceil(height/40)"},
"zindex": 0
}
],
"legends": [{"stroke": "color", "symbolType": "stroke", "title": "symbol"}]
}
2 changes: 1 addition & 1 deletion examples/compiled/repeat_layer.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 11 additions & 4 deletions examples/compiled/repeat_layer.vg.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"from": {"data": "source_0"},
"encode": {
"update": {
"stroke": {"value": "#4c78a8"},
"stroke": {"scale": "color", "value": "US_Gross"},
"x": {
"signal": "scale(\"x\", 0.5 * datum[\"bin_maxbins_10_IMDB_Rating\"] + 0.5 * datum[\"bin_maxbins_10_IMDB_Rating_end\"])"
},
Expand All @@ -70,7 +70,7 @@
"from": {"data": "source_0"},
"encode": {
"update": {
"stroke": {"value": "#4c78a8"},
"stroke": {"scale": "color", "value": "Worldwide_Gross"},
"x": {
"signal": "scale(\"x\", 0.5 * datum[\"bin_maxbins_10_IMDB_Rating\"] + 0.5 * datum[\"bin_maxbins_10_IMDB_Rating_end\"])"
},
Expand Down Expand Up @@ -105,6 +105,12 @@
"range": [{"signal": "height"}, 0],
"nice": true,
"zero": true
},
{
"name": "color",
"type": "ordinal",
"domain": {"fields": [["US_Gross"], ["Worldwide_Gross"]]},
"range": "category"
}
],
"axes": [
Expand Down Expand Up @@ -135,10 +141,11 @@
"scale": "y",
"orient": "left",
"grid": false,
"title": "Mean of US_Gross, Mean of Worldwide_Gross",
"title": "Mean of US and Worldwide Gross",
"labelOverlap": true,
"tickCount": {"signal": "ceil(height/40)"},
"zindex": 0
}
]
],
"legends": [{"stroke": "color", "symbolType": "stroke"}]
}
4 changes: 2 additions & 2 deletions examples/specs/geo_constant_value.vl.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"mark": "square",
"encoding": {
"longitude": {
"value": -122.335167
"datum": -122.335167
},
"latitude": {
"field": "latitude",
Expand All @@ -54,7 +54,7 @@
"type": "quantitative"
},
"latitude": {
"value": 47.608013
"datum": 47.608013
},
"size": {
"value": 1
Expand Down
29 changes: 9 additions & 20 deletions examples/specs/layer_bar_annotations.vl.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,40 +35,29 @@
],
"encoding": {
"x": {"field": "Day", "type": "ordinal"},
"y": {"field": "baseline", "type": "quantitative"},
"y": {"field": "baseline", "type": "quantitative", "title": "PM2.5 Value"},
"y2": {"field": "Value"},
"color": {"value": "#e45755"}
}
}
]}, {
"data": {
"values": [
{"ThresholdValue": 300, "Threshold": "hazardous"}
]
"values": [{}]
},
"encoding": {
"y": {"datum": 300}
},
"layer": [{
"mark": "rule",
"encoding": {
"y": {"field": "ThresholdValue", "type": "quantitative"}
}
"mark": "rule"
}, {
"mark": {
"type": "text",
"align": "right",
"baseline": "bottom",
"dx": -2,
"dy": -2
},
"encoding": {
"x": {
"value": "width"
},
"y": {
"field": "ThresholdValue",
"type": "quantitative",
"axis": {"title": "PM2.5 Value"}
},
"text": {"field": "Threshold", "type": "ordinal"}
"dy": -2,
"x": "width",
"text": "hazardous"
}
}]
}
Expand Down
21 changes: 21 additions & 0 deletions examples/specs/layer_line_datum_rule.vl.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"$schema": "https://vega.github.io/schema/vega-lite/v4.json",
"layer": [
{
"data": {"url": "data/stocks.csv"},
"mark": "line",
"encoding": {
"x": {"field": "date", "type": "temporal"},
"y": {"field": "price", "type": "quantitative"},
"color": {"field": "symbol", "type": "nominal"}
}
},
{
"data": {"values": [{}]},
"mark": {"type": "rule", "strokeDash": [2, 2], "size": 2},
"encoding": {
"y": {"datum": 300}
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
{
"mark": "square",
"encoding": {
"longitude": {"value": -122.335167},
"longitude": {"datum": -122.335167},
"latitude": {"field": "latitude", "type": "quantitative"},
"size": {"value": 1},
"color": {"value": "steelblue"}
Expand All @@ -28,7 +28,7 @@
"mark": "square",
"encoding": {
"longitude": {"field": "longitude", "type": "quantitative"},
"latitude": {"value": 47.608013},
"latitude": {"datum": 47.608013},
"size": {"value": 1},
"color": {"value": "firebrick"}
},
Expand Down
Loading