diff --git a/build/vega-lite-schema.json b/build/vega-lite-schema.json index 8b946af575d..465e8258dc0 100644 --- a/build/vega-lite-schema.json +++ b/build/vega-lite-schema.json @@ -21763,6 +21763,10 @@ ], "description": "Sets the minimum value in the scale domain, overriding the domain property. This property is only intended for use with scales having continuous domains." }, + "domainRaw": { + "$ref": "#/definitions/ExprRef", + "description": "An expression for an array of raw values that, if non-null, directly overrides the _domain_ property. This is useful for supporting interactions such as panning or zooming a scale. The scale may be initially determined using a data-driven domain, then modified in response to user input by setting the rawDomain value." + }, "exponent": { "anyOf": [ { diff --git a/examples/compiled/interactive_point_domainRaw_binding.png b/examples/compiled/interactive_point_domainRaw_binding.png new file mode 100644 index 00000000000..eace58471b8 Binary files /dev/null and b/examples/compiled/interactive_point_domainRaw_binding.png differ diff --git a/examples/compiled/interactive_point_domainRaw_binding.svg b/examples/compiled/interactive_point_domainRaw_binding.svg new file mode 100644 index 00000000000..bfcc3c8d9e9 --- /dev/null +++ b/examples/compiled/interactive_point_domainRaw_binding.svg @@ -0,0 +1 @@ +50100150200250Horsepower01020304050Miles_per_Gallon2468Cylinders \ No newline at end of file diff --git a/examples/compiled/interactive_point_domainRaw_binding.vg.json b/examples/compiled/interactive_point_domainRaw_binding.vg.json new file mode 100644 index 00000000000..45d5a3127d5 --- /dev/null +++ b/examples/compiled/interactive_point_domainRaw_binding.vg.json @@ -0,0 +1,148 @@ +{ + "$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/cars.json", + "format": {"type": "json"}, + "transform": [ + { + "type": "filter", + "expr": "isValid(datum[\"Horsepower\"]) && isFinite(+datum[\"Horsepower\"]) && isValid(datum[\"Miles_per_Gallon\"]) && isFinite(+datum[\"Miles_per_Gallon\"]) && isValid(datum[\"Cylinders\"]) && isFinite(+datum[\"Cylinders\"])" + } + ] + } + ], + "signals": [ + { + "name": "min_x", + "value": 50, + "bind": {"input": "range", "min": 0, "max": 300} + }, + { + "name": "max_x", + "value": 250, + "bind": {"input": "range", "min": 0, "max": 300} + }, + {"name": "use_custom_x", "value": true, "bind": {"input": "checkbox"}} + ], + "marks": [ + { + "name": "marks", + "type": "symbol", + "clip": true, + "style": ["circle"], + "from": {"data": "source_0"}, + "encode": { + "update": { + "opacity": {"value": 0.7}, + "fill": {"value": "#4c78a8"}, + "ariaRoleDescription": {"value": "circle"}, + "description": { + "signal": "\"Horsepower: \" + (format(datum[\"Horsepower\"], \"\")) + \"; Miles_per_Gallon: \" + (format(datum[\"Miles_per_Gallon\"], \"\")) + \"; Cylinders: \" + (format(datum[\"Cylinders\"], \"\"))" + }, + "x": {"scale": "x", "field": "Horsepower"}, + "y": {"scale": "y", "field": "Miles_per_Gallon"}, + "size": {"scale": "size", "field": "Cylinders"}, + "shape": {"value": "circle"} + } + } + } + ], + "scales": [ + { + "name": "x", + "type": "linear", + "domain": {"data": "source_0", "field": "Horsepower"}, + "range": [0, {"signal": "width"}], + "domainRaw": {"signal": "use_custom_x ? [min_x, max_x] : null"}, + "nice": true, + "zero": true + }, + { + "name": "y", + "type": "linear", + "domain": {"data": "source_0", "field": "Miles_per_Gallon"}, + "range": [{"signal": "height"}, 0], + "nice": true, + "zero": true + }, + { + "name": "size", + "type": "linear", + "domain": {"data": "source_0", "field": "Cylinders"}, + "range": [0, 361], + "zero": true + } + ], + "axes": [ + { + "scale": "x", + "orient": "bottom", + "gridScale": "y", + "grid": true, + "tickCount": {"signal": "ceil(width/40)"}, + "domain": false, + "labels": false, + "aria": 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, + "aria": false, + "maxExtent": 0, + "minExtent": 0, + "ticks": false, + "zindex": 0 + }, + { + "scale": "x", + "orient": "bottom", + "grid": false, + "title": "Horsepower", + "labelFlush": true, + "labelOverlap": true, + "tickCount": {"signal": "ceil(width/40)"}, + "zindex": 0 + }, + { + "scale": "y", + "orient": "left", + "grid": false, + "title": "Miles_per_Gallon", + "labelOverlap": true, + "tickCount": {"signal": "ceil(height/40)"}, + "zindex": 0 + } + ], + "legends": [ + { + "size": "size", + "symbolType": "circle", + "title": "Cylinders", + "encode": { + "symbols": { + "update": { + "fill": {"value": "#4c78a8"}, + "opacity": {"value": 0.7}, + "stroke": {"value": "transparent"} + } + } + } + } + ] +} diff --git a/examples/specs/interactive_point_domainRaw_binding.vl.json b/examples/specs/interactive_point_domainRaw_binding.vl.json new file mode 100644 index 00000000000..1861553be87 --- /dev/null +++ b/examples/specs/interactive_point_domainRaw_binding.vl.json @@ -0,0 +1,40 @@ +{ + "$schema": "https://vega.github.io/schema/vega-lite/v5.json", + "data": {"url": "data/cars.json"}, + "params": [{ + "name": "min_x", + "value": 50, + "bind": { + "input": "range", + "min": 0, + "max": 300 + } + }, { + "name": "max_x", + "value": 250, + "bind": { + "input": "range", + "min": 0, + "max": 300 + } + },{ + "name": "use_custom_x", + "value": true, + "bind": { + "input": "checkbox" + } + }], + "mark": {"type": "circle", "clip": true}, + "encoding": { + "x": { + "field": "Horsepower", "type": "quantitative", + "scale": { + "domainRaw": {"expr": "use_custom_x ? [min_x, max_x] : null"} + } + }, + "y": { + "field": "Miles_per_Gallon", "type": "quantitative" + }, + "size": {"field": "Cylinders", "type": "quantitative"} + } +} diff --git a/site/docs/encoding/scale.md b/site/docs/encoding/scale.md index 4d06cd44d24..86673fb9558 100644 --- a/site/docs/encoding/scale.md +++ b/site/docs/encoding/scale.md @@ -75,7 +75,7 @@ bar, image, rect, and rule marks while `"point"` is the default scales for all o By default, a scale in Vega-Lite draws domain values directly from a channel's encoded field. Users can specify the `domain` property of a scale to customize its domain values. To sort the order of the domain of the encoded, the [`sort`](sort.html) property of a [field definition](encoding.html#field-def) can be specified. -{% include table.html props="domain,domainMax,domainMin,domainMid" source="Scale" %} +{% include table.html props="domain,domainMax,domainMin,domainMid,domainRaw" source="Scale" %} A common use case for the `domain` property is to limit, for example, the `x` range of values to include in a plot. However, setting the domain property alone is insufficient to achieve the desired effect. @@ -101,6 +101,10 @@ There are two approaches to keep the mark from being plotted outside the desired
+### Example: Using `domainRaw` to bind domain interactively + +
+