Created
May 20, 2019 18:41
-
-
Save djbarnwal/35af72ea3580e4b19f8cf7576c1edfd5 to your computer and use it in GitHub Desktop.
Sample Vega Spec for Comparison Operator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "$schema": "https://vega.github.io/schema/vega/v5.json", | |
| "autosize": "pad", | |
| "padding": 5, | |
| "width": 200, | |
| "height": 200, | |
| "style": "cell", | |
| "data": [ | |
| {"name": "sel1_store"}, | |
| {"name": "sel2_store"}, | |
| { | |
| "name": "source_0", | |
| "url": "data/cars.json", | |
| "format": {"type": "json"}, | |
| "transform": [ | |
| { | |
| "type": "filter", | |
| "expr": "datum[\"Horsepower\"] !== null && !isNaN(datum[\"Horsepower\"]) && datum[\"Miles_per_Gallon\"] !== null && !isNaN(datum[\"Miles_per_Gallon\"])" | |
| } | |
| ] | |
| }, | |
| { | |
| "name": "sel1_aggregates", | |
| "source": "source_0", | |
| "transform": [ | |
| {"type":"filter", "expr": "datum.Origin == vlSelectionResolve(\"sel1_store\").Origin"}, | |
| { | |
| "type": "aggregate", | |
| "fields": ["Cylinders", "Horsepower"], | |
| "ops": ["min", "mean"], | |
| "as": ["CylMIN", "HorsepowerMEAN"] | |
| } | |
| ] | |
| }, | |
| { | |
| "name": "sel2_aggregates", | |
| "source": "source_0", | |
| "transform": [ | |
| {"type":"filter", "expr": "datum.Horsepower == vlSelectionResolve(\"sel2_store\").Horsepower && datum.Cylinders == vlSelectionResolve(\"sel2_store\").Cylinders"}, | |
| { | |
| "type": "aggregate", | |
| "fields": ["Miles_per_Gallon"], | |
| "ops": ["mean"], | |
| "as": ["MilesGallonMEAN"] | |
| } | |
| ] | |
| }, | |
| { | |
| "name": "test_store", | |
| "source": "source_0", | |
| "transform": [ | |
| {"type":"filter", "expr": "datum.Cylinders > (data(\"sel1_aggregates\")[0] && data(\"sel1_aggregates\")[0].CylMIN) && datum.Horsepower != (data(\"sel1_aggregates\")[0] && data(\"sel1_aggregates\")[0].HorsepowerMEAN) && datum.Miles_per_Gallon >= (data(\"sel2_aggregates\")[0] && data(\"sel2_aggregates\")[0].MilesGallonMEAN)"} | |
| ] | |
| } | |
| ], | |
| "signals": [ | |
| { | |
| "name": "unit", | |
| "value": {}, | |
| "on": [ | |
| {"events": "mousemove", "update": "isTuple(group()) ? group() : unit"} | |
| ] | |
| }, | |
| {"name": "sel1", "update": "vlSelectionResolve(\"sel1_store\")"}, | |
| {"name": "sel2", "update": "vlSelectionResolve(\"sel2_store\")"}, | |
| { | |
| "name": "sample_signal", | |
| "on": [ | |
| { | |
| "events": [{"source": "scope", "type": "click"}], | |
| "update": "data(\"sel1_aggregates\")[0] && data(\"sel1_aggregates\")[0].CylMIN" | |
| } | |
| ] | |
| }, | |
| { | |
| "name": "sel1_tuple", | |
| "on": [ | |
| { | |
| "events": [{"source": "scope", "type": "click"}], | |
| "update": "datum && item().mark.marktype !== 'group' ? {unit: \"\", fields: sel1_tuple_fields, values: [(item().isVoronoi ? datum.datum : datum)[\"Origin\"]]} : null", | |
| "force": true | |
| }, | |
| {"events": [{"source": "scope", "type": "dblclick"}], "update": "null"} | |
| ] | |
| }, | |
| {"name": "sel1_tuple_fields", "value": [{"type": "E", "field": "Origin"}]}, | |
| { | |
| "name": "sel1_toggle", | |
| "value": false, | |
| "on": [ | |
| { | |
| "events": [{"source": "scope", "type": "click"}], | |
| "update": "event.shiftKey" | |
| }, | |
| {"events": [{"source": "scope", "type": "dblclick"}], "update": "false"} | |
| ] | |
| }, | |
| { | |
| "name": "sel1_modify", | |
| "update": "modify(\"sel1_store\", sel1_toggle ? null : sel1_tuple, sel1_toggle ? null : true, sel1_toggle ? sel1_tuple : null)" | |
| }, | |
| { | |
| "name": "sel2_tuple", | |
| "on": [ | |
| { | |
| "events": [{"source": "scope", "type": "click"}], | |
| "update": "datum && item().mark.marktype !== 'group' ? {unit: \"\", fields: sel2_tuple_fields, values: [(item().isVoronoi ? datum.datum : datum)[\"Horsepower\"], (item().isVoronoi ? datum.datum : datum)[\"Cylinders\"]]} : null", | |
| "force": true | |
| }, | |
| {"events": [{"source": "scope", "type": "dblclick"}], "update": "null"} | |
| ] | |
| }, | |
| { | |
| "name": "sel2_tuple_fields", | |
| "value": [ | |
| {"type": "E", "field": "Horsepower"}, | |
| {"type": "E", "field": "Cylinders"} | |
| ] | |
| }, | |
| { | |
| "name": "sel2_toggle", | |
| "value": false, | |
| "on": [ | |
| { | |
| "events": [{"source": "scope", "type": "click"}], | |
| "update": "event.shiftKey" | |
| }, | |
| {"events": [{"source": "scope", "type": "dblclick"}], "update": "false"} | |
| ] | |
| }, | |
| { | |
| "name": "sel2_modify", | |
| "update": "modify(\"sel2_store\", sel2_toggle ? null : sel2_tuple, sel2_toggle ? null : true, sel2_toggle ? sel2_tuple : null)" | |
| } | |
| ], | |
| "marks": [ | |
| { | |
| "name": "marks", | |
| "type": "symbol", | |
| "style": ["circle"], | |
| "from": {"data": "source_0"}, | |
| "encode": { | |
| "update": { | |
| "opacity": {"value": 0.7}, | |
| "fill": [ | |
| { | |
| "test": "!(length(data(\"sel1_store\"))) || (vlSelectionTest(\"sel1_store\", datum))", | |
| "scale": "color", | |
| "field": "Origin" | |
| }, | |
| {"value": "grey"} | |
| ], | |
| "tooltip": { | |
| "signal": "{\"Horsepower\": format(datum[\"Horsepower\"], \"\"), \"Miles_per_Gallon\": format(datum[\"Miles_per_Gallon\"], \"\"), \"Origin\": ''+datum[\"Origin\"]}" | |
| }, | |
| "x": {"scale": "x", "field": "Horsepower"}, | |
| "y": {"scale": "y", "field": "Miles_per_Gallon"}, | |
| "shape": {"value": "circle"} | |
| } | |
| } | |
| } | |
| ], | |
| "scales": [ | |
| { | |
| "name": "x", | |
| "type": "linear", | |
| "domain": {"data": "source_0", "field": "Horsepower"}, | |
| "range": [0, {"signal": "width"}], | |
| "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": "color", | |
| "type": "ordinal", | |
| "domain": {"data": "source_0", "field": "Origin", "sort": true}, | |
| "range": "category" | |
| } | |
| ], | |
| "axes": [ | |
| { | |
| "scale": "x", | |
| "orient": "bottom", | |
| "grid": false, | |
| "title": "Horsepower", | |
| "labelFlush": true, | |
| "labelOverlap": true, | |
| "tickCount": {"signal": "ceil(width/40)"}, | |
| "zindex": 1 | |
| }, | |
| { | |
| "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", | |
| "grid": false, | |
| "title": "Miles_per_Gallon", | |
| "labelOverlap": true, | |
| "tickCount": {"signal": "ceil(height/40)"}, | |
| "zindex": 1 | |
| }, | |
| { | |
| "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 | |
| } | |
| ], | |
| "legends": [ | |
| { | |
| "fill": "color", | |
| "gradientLength": {"signal": "clamp(height, 64, 200)"}, | |
| "symbolType": "circle", | |
| "title": "Origin", | |
| "encode": { | |
| "symbols": { | |
| "update": {"shape": {"value": "circle"}, "opacity": {"value": 0.7}} | |
| } | |
| } | |
| } | |
| ] | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment