├── README.md ├── deps.edn ├── resources ├── .keep ├── vega-lite.js └── vega.js ├── src └── applied_science │ └── darkstar.clj └── test └── applied_science ├── darkstar_test.clj ├── data ├── 7zip.png ├── airports.csv ├── annual-precip.json ├── barley.json ├── budgets.json ├── cars.json ├── chart.json ├── driving.json ├── earthquakes.json ├── ffox.png ├── flare-dependencies.json ├── flare.json ├── flights-200k.json ├── flights-airport.csv ├── gapminder.json ├── gimp.png ├── iris.json ├── jobs.json ├── miserables.json ├── monarchs.json ├── movies.json ├── normal-2d.json ├── population.json ├── seattle-temps.csv ├── sp500.csv ├── stocks.csv ├── unemployment-across-industries.json ├── unemployment.tsv ├── uniform-2d.json ├── us-10m.json ├── volcano.json ├── weather.json ├── wheat.json └── world-110m.json └── vega-specs ├── airports.vg.json ├── arc-diagram.vg.json ├── arc.vg.json ├── area.vg.json ├── autosize-fit-x.vg.json ├── autosize-fit-y.vg.json ├── autosize-fit.vg.json ├── bar-hover-label.vg.json ├── bar-rangestep.vg.json ├── bar-time.vg.json ├── bar.vg.json ├── barley.vg.json ├── budget-forecasts.vg.json ├── chart-rangestep.vg.json ├── chart.vg.json ├── choropleth.vg.json ├── contour-map.vg.json ├── contour-scatter.vg.json ├── corner-radius.vg.json ├── crossfilter-multi.vg.json ├── crossfilter.vg.json ├── density.vg.json ├── dimpvis.vg.json ├── dot-plot.vg.json ├── driving.vg.json ├── dynamic-format.vg.json ├── dynamic-url.vg.json ├── error.vg.json ├── falkensee.vg.json ├── flush-axis-labels.vg.json ├── font-size-steps.vg.json ├── force-beeswarm.vg.json ├── force-network.vg.json ├── gapminder.vg.json ├── gradient.vg.json ├── grouped-bar.vg.json ├── heatmap-image.vg.json ├── heatmap-lines.vg.json ├── heatmap-sinusoids.vg.json ├── heatmap.vg.json ├── histogram.vg.json ├── hops.vg.json ├── horizon.vg.json ├── images-inline.vg.json ├── images.vg.json ├── isocontour-airports.vg.json ├── isocontour-precipitation.vg.json ├── isocontour-volcano.vg.json ├── jobs.vg.json ├── kde.vg.json ├── layout-facet.vg.json ├── layout-hconcat.vg.json ├── layout-splom.vg.json ├── layout-vconcat.vg.json ├── layout-wrap.vg.json ├── legends-continuous.vg.json ├── legends-discrete.vg.json ├── legends-ordinal.vg.json ├── legends-symbol.vg.json ├── legends.vg.json ├── lifelines.vg.json ├── map-area-compare.vg.json ├── map-bind.vg.json ├── map-fit.vg.json ├── map-point-radius.vg.json ├── map.vg.json ├── matrix-reorder.vg.json ├── movies-sort.vg.json ├── nested-plot.vg.json ├── nulls-histogram.vg.json ├── nulls-scatter-plot.vg.json ├── overview-detail-bins.vg.json ├── overview-detail.vg.json ├── panzoom.vg.json ├── parallel-coords.vg.json ├── playfair.vg.json ├── population.vg.json ├── quantile-dot-plot.vg.json ├── quantile-quantile-plot.vg.json ├── regression.vg.json ├── scales-bin.vg.json ├── scales-discretize.vg.json ├── scatter-brush-filter.vg.json ├── scatter-brush-panzoom.vg.json ├── scatter-plot-contours.vg.json ├── scatter-plot-guides.vg.json ├── scatter-plot-heatmap.vg.json ├── scatter-plot.vg.json ├── shift-select.vg.json ├── splom-inner.vg.json ├── splom-outer.vg.json ├── stacked-area.vg.json ├── stacked-bar.vg.json ├── stocks-index.vg.json ├── symbol-angle.vg.json ├── text-multiline.vg.json ├── titles.vg.json ├── tree-cluster.vg.json ├── tree-nest.vg.json ├── tree-radial-bundle.vg.json ├── tree-radial.vg.json ├── treemap.vg.json ├── violin-plot.vg.json ├── weather.vg.json └── window.vg.json /README.md: -------------------------------------------------------------------------------- 1 | # Darkstar 2 | 3 | Darkstar packages Vega `5.10.1` and Vega-lite `4.10.1` as a single 4 | dependency Clojure library with a very small API surface. 5 | 6 | This was made relatively easy by the GraalJS Javascript runtime, which 7 | should work on any stock JVM >= `1.8.0_131`. I have tested it on that 8 | version of HotSpot, as well as OpenJDK 11 and 13. 9 | 10 | ## Installation 11 | 12 | We have not yet released to Clojars, so we recommended you use deps.edn: 13 | 14 | ``` clojure 15 | applied-science/darkstar {:git/url "https://github.com/applied-science/darkstar/" 16 | :sha "541a3ff36065c59e92fe6aa61e41a4385ba6f893"} 17 | ``` 18 | 19 | ## Usage 20 | 21 | ``` clojure 22 | (ns test 23 | (:require [applied-science.darkstar :as darkstar])) 24 | 25 | ;; write an SVG from a Vega spec 26 | (->> (slurp "vega-example.json") 27 | darkstar/vega-spec->svg 28 | (spit "vg-example.svg")) 29 | 30 | ;; write an SVG from a Vega-lite spec 31 | (->> (slurp "vega-lite-example.json") 32 | darkstar/vega-lite-spec->svg 33 | (spit "vl-example.svg")) 34 | ``` 35 | 36 | ## Development 37 | 38 | Build a deployable jar of this library: 39 | 40 | $ clojure -A:jar 41 | 42 | Install it locally: 43 | 44 | $ clojure -A:install 45 | 46 | Deploy it to Clojars -- needs `CLOJARS_USERNAME` and `CLOJARS_PASSWORD` environment variables: 47 | 48 | $ clojure -A:deploy 49 | 50 | ## License 51 | 52 | Copyright © 2020 Applied Science 53 | 54 | Distributed under the MIT License. 55 | -------------------------------------------------------------------------------- /deps.edn: -------------------------------------------------------------------------------- 1 | {:paths ["src" "resources"] 2 | :deps {org.clojure/clojure {:mvn/version "1.10.1"} 3 | org.graalvm.js/js {:mvn/version "20.0.0"} 4 | org.graalvm.js/js-scriptengine {:mvn/version "20.0.0"}} 5 | :aliases 6 | {:test {:extra-paths ["test"] 7 | :extra-deps {org.clojure/test.check {:mvn/version "0.10.0"}}} 8 | :runner 9 | {:extra-deps {com.cognitect/test-runner 10 | {:git/url "https://github.com/cognitect-labs/test-runner" 11 | :sha "f7ef16dc3b8332b0d77bc0274578ad5270fbfedd"}} 12 | :main-opts ["-m" "cognitect.test-runner" 13 | "-d" "test"]} 14 | :release 15 | {:extra-deps {applied-science/deps-library {:mvn/version "0.4.0"}} 16 | :main-opts ["-m" "applied-science.deps-library"]}}} 17 | 18 | ;; :jar {:extra-deps {seancorfield/depstar {:mvn/version "0.5.2"}} 19 | ;; :main-opts ["-m" "hf.depstar.jar" "darkstar.jar"]} 20 | ;; :install {:extra-deps {deps-deploy {:mvn/version "0.0.9"}} 21 | ;; :main-opts ["-m" "deps-deploy.deps-deploy" "install" "darkstar.jar"]} 22 | ;; :deploy {:extra-deps {deps-deploy {:mvn/version "0.0.9"}} 23 | ;; :main-opts ["-m" "deps-deploy.deps-deploy" "deploy" "darkstar.jar"]} 24 | -------------------------------------------------------------------------------- /resources/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/applied-science/darkstar/abd480cc382b7ae143f7902ee9d300cdc1a705cc/resources/.keep -------------------------------------------------------------------------------- /src/applied_science/darkstar.clj: -------------------------------------------------------------------------------- 1 | (ns applied-science.darkstar) 2 | 3 | (def ^:dynamic *base-directory* nil) 4 | 5 | (defn read-file 6 | "A very, very slight polyfill for Node's fs.readFile that uses `*base-directory*` as Vega's idea of current working directory." 7 | [filename] 8 | ;; TODO only system error handling! 9 | (slurp (.getAbsolutePath (java.io.File. (str *base-directory* filename))))) 10 | 11 | (def engine 12 | (let [engine (.getEngineByName (javax.script.ScriptEngineManager.) "graal.js") 13 | bindings (.getBindings engine javax.script.ScriptContext/ENGINE_SCOPE)] 14 | (.put bindings "polyglot.js.allowAllAccess" true) 15 | (doto engine 16 | ;; XXX minimal polyfill for part of the fetch and fs APIs, brittle af 17 | (.eval " 18 | async function fetch(path, options) { 19 | var body = Java.type('clojure.core$slurp').invokeStatic(path,null); 20 | return {'ok' : true, 21 | 'body' : body, 22 | 'text' : (function() {return body;}), 23 | 'json' : (function() {return JSON.parse(body);})}; 24 | } 25 | function readFile(path, callback) { 26 | try { 27 | var data = Java.type('applied_science.darkstar$read_file').invokeStatic(path); 28 | callback(null, data); 29 | } catch (err) { 30 | printErr(err); 31 | } 32 | } 33 | var fs = {'readFile':readFile}; 34 | ") 35 | (.eval (slurp (clojure.java.io/resource "vega.js"))) 36 | (.eval (slurp (clojure.java.io/resource "vega-lite.js")))))) 37 | 38 | (defn make-js-fn [js-text] 39 | (let [^java.util.function.Function f (.eval engine js-text)] 40 | (fn [& args] (.apply f (to-array args))))) 41 | 42 | (def vega-lite->vega 43 | "Converts a VegaLite spec into a Vega spec." 44 | (make-js-fn "function(vlSpec) { return JSON.stringify(vegaLite.compile(JSON.parse(vlSpec)).spec);}")) 45 | 46 | (def vega-spec->view 47 | "Converts a Vega spec into a Vega view object, finalizing all resources." 48 | (make-js-fn "function(spec) { return new vega.View(vega.parse(JSON.parse(spec)), {renderer:'svg'}).finalize();}")) 49 | 50 | (def view->svg 51 | "Converts a Vega view object into an SVG." 52 | (make-js-fn "function (view) { 53 | var promise = Java.type('clojure.core$promise').invokeStatic(); 54 | view.toSVG(1.0).then(function(svg) { 55 | Java.type('clojure.core$deliver').invokeStatic(promise,svg); 56 | }).catch(function(err) { 57 | Java.type('clojure.core$deliver').invokeStatic(promise,'error'); 58 | }); 59 | return promise; 60 | }")) 61 | 62 | (defn vega-spec->svg 63 | "Calls Vega to render the spec in `vega-spec-json-string` to the SVG described by that spec." 64 | [vega-spec-json-string] 65 | @(view->svg (vega-spec->view vega-spec-json-string))) 66 | 67 | (defn vega-lite-spec->svg 68 | "Converts `vega-lite-spec-json-string` to a full Vega spec, then uses Vega to render the SVG described by that spec." 69 | [vega-lite-spec-json-string] 70 | (vega-spec->svg (vega-lite->vega vega-lite-spec-json-string))) 71 | 72 | (comment 73 | 74 | (->> (slurp "vega-lite-movies.json") 75 | vega-lite-spec->svg 76 | (spit "vl-movies.svg")) 77 | 78 | ) 79 | -------------------------------------------------------------------------------- /test/applied_science/data/7zip.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/applied-science/darkstar/abd480cc382b7ae143f7902ee9d300cdc1a705cc/test/applied_science/data/7zip.png -------------------------------------------------------------------------------- /test/applied_science/data/driving.json: -------------------------------------------------------------------------------- 1 | [ 2 | {"side": "left", "year": 1956, "miles": 3675, "gas": 2.38}, 3 | {"side": "right", "year": 1957, "miles": 3706, "gas": 2.40}, 4 | {"side": "bottom", "year": 1958, "miles": 3766, "gas": 2.26}, 5 | {"side": "top", "year": 1959, "miles": 3905, "gas": 2.31}, 6 | {"side": "right", "year": 1960, "miles": 3935, "gas": 2.27}, 7 | {"side": "bottom", "year": 1961, "miles": 3977, "gas": 2.25}, 8 | {"side": "right", "year": 1962, "miles": 4085, "gas": 2.22}, 9 | {"side": "bottom", "year": 1963, "miles": 4218, "gas": 2.12}, 10 | {"side": "bottom", "year": 1964, "miles": 4369, "gas": 2.11}, 11 | {"side": "bottom", "year": 1965, "miles": 4538, "gas": 2.14}, 12 | {"side": "top", "year": 1966, "miles": 4676, "gas": 2.14}, 13 | {"side": "bottom", "year": 1967, "miles": 4827, "gas": 2.14}, 14 | {"side": "right", "year": 1968, "miles": 5038, "gas": 2.13}, 15 | {"side": "right", "year": 1969, "miles": 5207, "gas": 2.07}, 16 | {"side": "right", "year": 1970, "miles": 5376, "gas": 2.01}, 17 | {"side": "bottom", "year": 1971, "miles": 5617, "gas": 1.93}, 18 | {"side": "bottom", "year": 1972, "miles": 5973, "gas": 1.87}, 19 | {"side": "right", "year": 1973, "miles": 6154, "gas": 1.90}, 20 | {"side": "left", "year": 1974, "miles": 5943, "gas": 2.34}, 21 | {"side": "bottom", "year": 1975, "miles": 6111, "gas": 2.31}, 22 | {"side": "bottom", "year": 1976, "miles": 6389, "gas": 2.32}, 23 | {"side": "top", "year": 1977, "miles": 6630, "gas": 2.36}, 24 | {"side": "bottom", "year": 1978, "miles": 6883, "gas": 2.23}, 25 | {"side": "left", "year": 1979, "miles": 6744, "gas": 2.68}, 26 | {"side": "left", "year": 1980, "miles": 6672, "gas": 3.30}, 27 | {"side": "right", "year": 1981, "miles": 6732, "gas": 3.30}, 28 | {"side": "right", "year": 1982, "miles": 6835, "gas": 2.92}, 29 | {"side": "right", "year": 1983, "miles": 6943, "gas": 2.66}, 30 | {"side": "right", "year": 1984, "miles": 7130, "gas": 2.48}, 31 | {"side": "right", "year": 1985, "miles": 7323, "gas": 2.36}, 32 | {"side": "left", "year": 1986, "miles": 7558, "gas": 1.76}, 33 | {"side": "top", "year": 1987, "miles": 7770, "gas": 1.76}, 34 | {"side": "bottom", "year": 1988, "miles": 8089, "gas": 1.68}, 35 | {"side": "left", "year": 1989, "miles": 8397, "gas": 1.75}, 36 | {"side": "top", "year": 1990, "miles": 8529, "gas": 1.88}, 37 | {"side": "right", "year": 1991, "miles": 8535, "gas": 1.78}, 38 | {"side": "right", "year": 1992, "miles": 8662, "gas": 1.69}, 39 | {"side": "left", "year": 1993, "miles": 8855, "gas": 1.60}, 40 | {"side": "bottom", "year": 1994, "miles": 8909, "gas": 1.59}, 41 | {"side": "bottom", "year": 1995, "miles": 9150, "gas": 1.60}, 42 | {"side": "top", "year": 1996, "miles": 9192, "gas": 1.67}, 43 | {"side": "right", "year": 1997, "miles": 9416, "gas": 1.65}, 44 | {"side": "bottom", "year": 1998, "miles": 9590, "gas": 1.39}, 45 | {"side": "right", "year": 1999, "miles": 9687, "gas": 1.50}, 46 | {"side": "top", "year": 2000, "miles": 9717, "gas": 1.89}, 47 | {"side": "left", "year": 2001, "miles": 9699, "gas": 1.77}, 48 | {"side": "bottom", "year": 2002, "miles": 9814, "gas": 1.64}, 49 | {"side": "right", "year": 2003, "miles": 9868, "gas": 1.86}, 50 | {"side": "left", "year": 2004, "miles": 9994, "gas": 2.14}, 51 | {"side": "left", "year": 2005, "miles": 10067, "gas": 2.53}, 52 | {"side": "right", "year": 2006, "miles": 10037, "gas": 2.79}, 53 | {"side": "right", "year": 2007, "miles": 10025, "gas": 2.95}, 54 | {"side": "left", "year": 2008, "miles": 9880, "gas": 3.31}, 55 | {"side": "bottom", "year": 2009, "miles": 9657, "gas": 2.38}, 56 | {"side": "left", "year": 2010, "miles": 9596, "gas": 2.61} 57 | ] -------------------------------------------------------------------------------- /test/applied_science/data/ffox.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/applied-science/darkstar/abd480cc382b7ae143f7902ee9d300cdc1a705cc/test/applied_science/data/ffox.png -------------------------------------------------------------------------------- /test/applied_science/data/gimp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/applied-science/darkstar/abd480cc382b7ae143f7902ee9d300cdc1a705cc/test/applied_science/data/gimp.png -------------------------------------------------------------------------------- /test/applied_science/data/monarchs.json: -------------------------------------------------------------------------------- 1 | [ 2 | {"name":"Elizabeth","start":1565,"end":1603,"index":0}, 3 | {"name":"James I","start":1603,"end":1625,"index":1}, 4 | {"name":"Charles I","start":1625,"end":1649,"index":2}, 5 | {"name":"Cromwell","start":1649,"end":1660,"commonwealth":true,"index":3}, 6 | {"name":"Charles II","start":1660,"end":1685,"index":4}, 7 | {"name":"James II","start":1685,"end":1689,"index":5}, 8 | {"name":"W&M","start":1689,"end":1702,"index":6}, 9 | {"name":"Anne","start":1702,"end":1714,"index":7}, 10 | {"name":"George I","start":1714,"end":1727,"index":8}, 11 | {"name":"George II","start":1727,"end":1760,"index":9}, 12 | {"name":"George III","start":1760,"end":1820,"index":10}, 13 | {"name":"George IV","start":1820,"end":1820,"index":11} 14 | ] -------------------------------------------------------------------------------- /test/applied_science/data/sp500.csv: -------------------------------------------------------------------------------- 1 | date,price 2 | Jan 1 2000,1394.46 3 | Feb 1 2000,1366.42 4 | Mar 1 2000,1498.58 5 | Apr 1 2000,1452.43 6 | May 1 2000,1420.6 7 | Jun 1 2000,1454.6 8 | Jul 1 2000,1430.83 9 | Aug 1 2000,1517.68 10 | Sep 1 2000,1436.51 11 | Oct 1 2000,1429.4 12 | Nov 1 2000,1314.95 13 | Dec 1 2000,1320.28 14 | Jan 1 2001,1366.01 15 | Feb 1 2001,1239.94 16 | Mar 1 2001,1160.33 17 | Apr 1 2001,1249.46 18 | May 1 2001,1255.82 19 | Jun 1 2001,1224.38 20 | Jul 1 2001,1211.23 21 | Aug 1 2001,1133.58 22 | Sep 1 2001,1040.94 23 | Oct 1 2001,1059.78 24 | Nov 1 2001,1139.45 25 | Dec 1 2001,1148.08 26 | Jan 1 2002,1130.2 27 | Feb 1 2002,1106.73 28 | Mar 1 2002,1147.39 29 | Apr 1 2002,1076.92 30 | May 1 2002,1067.14 31 | Jun 1 2002,989.82 32 | Jul 1 2002,911.62 33 | Aug 1 2002,916.07 34 | Sep 1 2002,815.28 35 | Oct 1 2002,885.76 36 | Nov 1 2002,936.31 37 | Dec 1 2002,879.82 38 | Jan 1 2003,855.7 39 | Feb 1 2003,841.15 40 | Mar 1 2003,848.18 41 | Apr 1 2003,916.92 42 | May 1 2003,963.59 43 | Jun 1 2003,974.5 44 | Jul 1 2003,990.31 45 | Aug 1 2003,1008.01 46 | Sep 1 2003,995.97 47 | Oct 1 2003,1050.71 48 | Nov 1 2003,1058.2 49 | Dec 1 2003,1111.92 50 | Jan 1 2004,1131.13 51 | Feb 1 2004,1144.94 52 | Mar 1 2004,1126.21 53 | Apr 1 2004,1107.3 54 | May 1 2004,1120.68 55 | Jun 1 2004,1140.84 56 | Jul 1 2004,1101.72 57 | Aug 1 2004,1104.24 58 | Sep 1 2004,1114.58 59 | Oct 1 2004,1130.2 60 | Nov 1 2004,1173.82 61 | Dec 1 2004,1211.92 62 | Jan 1 2005,1181.27 63 | Feb 1 2005,1203.6 64 | Mar 1 2005,1180.59 65 | Apr 1 2005,1156.85 66 | May 1 2005,1191.5 67 | Jun 1 2005,1191.33 68 | Jul 1 2005,1234.18 69 | Aug 1 2005,1220.33 70 | Sep 1 2005,1228.81 71 | Oct 1 2005,1207.01 72 | Nov 1 2005,1249.48 73 | Dec 1 2005,1248.29 74 | Jan 1 2006,1280.08 75 | Feb 1 2006,1280.66 76 | Mar 1 2006,1294.87 77 | Apr 1 2006,1310.61 78 | May 1 2006,1270.09 79 | Jun 1 2006,1270.2 80 | Jul 1 2006,1276.66 81 | Aug 1 2006,1303.82 82 | Sep 1 2006,1335.85 83 | Oct 1 2006,1377.94 84 | Nov 1 2006,1400.63 85 | Dec 1 2006,1418.3 86 | Jan 1 2007,1438.24 87 | Feb 1 2007,1406.82 88 | Mar 1 2007,1420.86 89 | Apr 1 2007,1482.37 90 | May 1 2007,1530.62 91 | Jun 1 2007,1503.35 92 | Jul 1 2007,1455.27 93 | Aug 1 2007,1473.99 94 | Sep 1 2007,1526.75 95 | Oct 1 2007,1549.38 96 | Nov 1 2007,1481.14 97 | Dec 1 2007,1468.36 98 | Jan 1 2008,1378.55 99 | Feb 1 2008,1330.63 100 | Mar 1 2008,1322.7 101 | Apr 1 2008,1385.59 102 | May 1 2008,1400.38 103 | Jun 1 2008,1280 104 | Jul 1 2008,1267.38 105 | Aug 1 2008,1282.83 106 | Sep 1 2008,1166.36 107 | Oct 1 2008,968.75 108 | Nov 1 2008,896.24 109 | Dec 1 2008,903.25 110 | Jan 1 2009,825.88 111 | Feb 1 2009,735.09 112 | Mar 1 2009,797.87 113 | Apr 1 2009,872.81 114 | May 1 2009,919.14 115 | Jun 1 2009,919.32 116 | Jul 1 2009,987.48 117 | Aug 1 2009,1020.62 118 | Sep 1 2009,1057.08 119 | Oct 1 2009,1036.19 120 | Nov 1 2009,1095.63 121 | Dec 1 2009,1115.1 122 | Jan 1 2010,1073.87 123 | Feb 1 2010,1104.49 124 | Mar 1 2010,1140.45 125 | -------------------------------------------------------------------------------- /test/applied_science/data/weather.json: -------------------------------------------------------------------------------- 1 | [{"day":"M","record":{"high":62,"low":15},"normal":{"high":50,"low":38},"actual":{"high":48,"low":36},"id":0},{"day":"T","record":{"high":62,"low":23},"normal":{"high":50,"low":38},"actual":{"high":50,"low":40},"id":1},{"day":"W","record":{"high":61,"low":20},"normal":{"high":50,"low":38},"actual":{"high":55,"low":36},"id":2},{"day":"T","record":{"high":67,"low":21},"normal":{"high":50,"low":38},"actual":{"high":51,"low":33},"id":3},{"day":"F","record":{"high":61,"low":23},"normal":{"high":50,"low":38},"actual":{"high":50,"low":30},"id":4},{"day":"S","record":{"high":67,"low":20},"normal":{"high":50,"low":38},"forecast":{"high":{"high":53,"low":49},"low":{"high":40,"low":35}},"id":5},{"day":"S","record":{"high":63,"low":23},"normal":{"high":50,"low":39},"forecast":{"high":{"high":55,"low":49},"low":{"high":42,"low":37}},"id":6},{"day":"M","record":{"high":61,"low":26},"normal":{"high":51,"low":39},"forecast":{"high":{"high":53,"low":49},"low":{"high":43,"low":40}},"id":7},{"day":"T","record":{"high":61,"low":24},"normal":{"high":51,"low":39},"forecast":{"high":{"high":52,"low":46},"low":{"high":44,"low":40}},"id":8},{"day":"W","record":{"high":63,"low":20},"normal":{"high":51,"low":39},"forecast":{"high":{"high":53,"low":46},"low":{"high":43,"low":38}},"id":9}] -------------------------------------------------------------------------------- /test/applied_science/data/wheat.json: -------------------------------------------------------------------------------- 1 | [ 2 | {"year":"1565","wheat":41,"wages":5}, 3 | {"year":"1570","wheat":45,"wages":5.05}, 4 | {"year":"1575","wheat":42,"wages":5.08}, 5 | {"year":"1580","wheat":49,"wages":5.12}, 6 | {"year":"1585","wheat":41.5,"wages":5.15}, 7 | {"year":"1590","wheat":47,"wages":5.25}, 8 | {"year":"1595","wheat":64,"wages":5.54}, 9 | {"year":"1600","wheat":27,"wages":5.61}, 10 | {"year":"1605","wheat":33,"wages":5.69}, 11 | {"year":"1610","wheat":32,"wages":5.78}, 12 | {"year":"1615","wheat":33,"wages":5.94}, 13 | {"year":"1620","wheat":35,"wages":6.01}, 14 | {"year":"1625","wheat":33,"wages":6.12}, 15 | {"year":"1630","wheat":45,"wages":6.22}, 16 | {"year":"1635","wheat":33,"wages":6.3}, 17 | {"year":"1640","wheat":39,"wages":6.37}, 18 | {"year":"1645","wheat":53,"wages":6.45}, 19 | {"year":"1650","wheat":42,"wages":6.5}, 20 | {"year":"1655","wheat":40.5,"wages":6.6}, 21 | {"year":"1660","wheat":46.5,"wages":6.75}, 22 | {"year":"1665","wheat":32,"wages":6.8}, 23 | {"year":"1670","wheat":37,"wages":6.9}, 24 | {"year":"1675","wheat":43,"wages":7}, 25 | {"year":"1680","wheat":35,"wages":7.3}, 26 | {"year":"1685","wheat":27,"wages":7.6}, 27 | {"year":"1690","wheat":40,"wages":8}, 28 | {"year":"1695","wheat":50,"wages":8.5}, 29 | {"year":"1700","wheat":30,"wages":9}, 30 | {"year":"1705","wheat":32,"wages":10}, 31 | {"year":"1710","wheat":44,"wages":11}, 32 | {"year":"1715","wheat":33,"wages":11.75}, 33 | {"year":"1720","wheat":29,"wages":12.5}, 34 | {"year":"1725","wheat":39,"wages":13}, 35 | {"year":"1730","wheat":26,"wages":13.3}, 36 | {"year":"1735","wheat":32,"wages":13.6}, 37 | {"year":"1740","wheat":27,"wages":14}, 38 | {"year":"1745","wheat":27.5,"wages":14.5}, 39 | {"year":"1750","wheat":31,"wages":15}, 40 | {"year":"1755","wheat":35.5,"wages":15.7}, 41 | {"year":"1760","wheat":31,"wages":16.5}, 42 | {"year":"1765","wheat":43,"wages":17.6}, 43 | {"year":"1770","wheat":47,"wages":18.5}, 44 | {"year":"1775","wheat":44,"wages":19.5}, 45 | {"year":"1780","wheat":46,"wages":21}, 46 | {"year":"1785","wheat":42,"wages":23}, 47 | {"year":"1790","wheat":47.5,"wages":25.5}, 48 | {"year":"1795","wheat":76,"wages":27.5}, 49 | {"year":"1800","wheat":79,"wages":28.5}, 50 | {"year":"1805","wheat":81,"wages":29.5}, 51 | {"year":"1810","wheat":99,"wages":30}, 52 | {"year":"1815","wheat":78}, 53 | {"year":"1820","wheat":54} 54 | ] -------------------------------------------------------------------------------- /test/applied_science/vega-specs/arc-diagram.vg.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://vega.github.io/schema/vega/v5.json", 3 | "width": 770, 4 | "padding": 5, 5 | 6 | "data": [ 7 | { 8 | "name": "edges", 9 | "url": "data/miserables.json", 10 | "format": {"type": "json", "property": "links"} 11 | }, 12 | { 13 | "name": "sourceDegree", 14 | "source": "edges", 15 | "transform": [ 16 | {"type": "aggregate", "groupby": ["source"]} 17 | ] 18 | }, 19 | { 20 | "name": "targetDegree", 21 | "source": "edges", 22 | "transform": [ 23 | {"type": "aggregate", "groupby": ["target"]} 24 | ] 25 | }, 26 | { 27 | "name": "nodes", 28 | "url": "data/miserables.json", 29 | "format": {"type": "json", "property": "nodes"}, 30 | "transform": [ 31 | { "type": "window", "ops": ["rank"], "as": ["order"] }, 32 | { 33 | "type": "lookup", "from": "sourceDegree", "key": "source", 34 | "fields": ["index"], "as": ["sourceDegree"], 35 | "default": {"count": 0} 36 | }, 37 | { 38 | "type": "lookup", "from": "targetDegree", "key": "target", 39 | "fields": ["index"], "as": ["targetDegree"], 40 | "default": {"count": 0} 41 | }, 42 | { 43 | "type": "formula", "as": "degree", 44 | "expr": "datum.sourceDegree.count + datum.targetDegree.count" 45 | } 46 | ] 47 | } 48 | ], 49 | 50 | "scales": [ 51 | { 52 | "name": "position", 53 | "type": "band", 54 | "domain": {"data": "nodes", "field": "order", "sort": true}, 55 | "range": "width" 56 | }, 57 | { 58 | "name": "color", 59 | "type": "ordinal", 60 | "range": "category", 61 | "domain": {"data": "nodes", "field": "group"} 62 | } 63 | ], 64 | 65 | "marks": [ 66 | { 67 | "type": "symbol", 68 | "name": "layout", 69 | "interactive": false, 70 | "from": {"data": "nodes"}, 71 | "encode": { 72 | "enter": { 73 | "opacity": {"value": 0} 74 | }, 75 | "update": { 76 | "x": {"scale": "position", "field": "order"}, 77 | "y": {"value": 0}, 78 | "size": {"field": "degree", "mult": 5, "offset": 10}, 79 | "fill": {"scale": "color", "field": "group"} 80 | } 81 | } 82 | }, 83 | { 84 | "type": "path", 85 | "from": {"data": "edges"}, 86 | "encode": { 87 | "update": { 88 | "stroke": {"value": "#000"}, 89 | "strokeOpacity": {"value": 0.2}, 90 | "strokeWidth": {"field": "value"} 91 | } 92 | }, 93 | "transform": [ 94 | { 95 | "type": "lookup", "from": "layout", "key": "datum.index", 96 | "fields": ["datum.source", "datum.target"], 97 | "as": ["sourceNode", "targetNode"] 98 | }, 99 | { 100 | "type": "linkpath", 101 | "sourceX": {"expr": "min(datum.sourceNode.x, datum.targetNode.x)"}, 102 | "targetX": {"expr": "max(datum.sourceNode.x, datum.targetNode.x)"}, 103 | "sourceY": {"expr": "0"}, 104 | "targetY": {"expr": "0"}, 105 | "shape": "arc" 106 | } 107 | ] 108 | }, 109 | { 110 | "type": "symbol", 111 | "from": {"data": "layout"}, 112 | "encode": { 113 | "update": { 114 | "x": {"field": "x"}, 115 | "y": {"field": "y"}, 116 | "fill": {"field": "fill"}, 117 | "size": {"field": "size"} 118 | } 119 | } 120 | }, 121 | { 122 | "type": "text", 123 | "from": {"data": "nodes"}, 124 | "encode": { 125 | "update": { 126 | "x": {"scale": "position", "field": "order"}, 127 | "y": {"value": 7}, 128 | "fontSize": {"value": 9}, 129 | "align": {"value": "right"}, 130 | "baseline": {"value": "middle"}, 131 | "angle": {"value": -90}, 132 | "text": {"field": "name"} 133 | } 134 | } 135 | } 136 | ] 137 | } 138 | -------------------------------------------------------------------------------- /test/applied_science/vega-specs/arc.vg.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://vega.github.io/schema/vega/v5.json", 3 | "width": 400, 4 | "height": 400, 5 | 6 | "data": [ 7 | { 8 | "name": "table", 9 | "values": [12, 23, 47, 6, 52, 19], 10 | "transform": [{"type": "pie", "field": "data"}] 11 | } 12 | ], 13 | 14 | "scales": [ 15 | { 16 | "name": "r", 17 | "type": "sqrt", 18 | "domain": {"data": "table", "field": "data"}, 19 | "zero": true, 20 | "range": [20, 100] 21 | } 22 | ], 23 | 24 | "marks": [ 25 | { 26 | "type": "arc", 27 | "from": {"data": "table"}, 28 | "encode": { 29 | "enter": { 30 | "x": {"field": {"group": "width"}, "mult": 0.5}, 31 | "y": {"field": {"group": "height"}, "mult": 0.5}, 32 | "startAngle": {"field": "startAngle"}, 33 | "endAngle": {"field": "endAngle"}, 34 | "innerRadius": {"value": 20}, 35 | "outerRadius": {"scale": "r", "field": "data"}, 36 | "stroke": {"value": "#fff"} 37 | }, 38 | "update": { 39 | "fill": {"value": "#ccc"} 40 | }, 41 | "hover": { 42 | "fill": {"value": "pink"} 43 | } 44 | } 45 | }, 46 | 47 | { 48 | "type": "text", 49 | "from": {"data": "table"}, 50 | "encode": { 51 | "enter": { 52 | "x": {"field": {"group": "width"}, "mult": 0.5}, 53 | "y": {"field": {"group": "height"}, "mult": 0.5}, 54 | "radius": {"scale": "r", "field": "data", "offset": 8}, 55 | "theta": {"signal": "(datum.startAngle + datum.endAngle)/2"}, 56 | "fill": {"value": "#000"}, 57 | "align": {"value": "center"}, 58 | "baseline": {"value": "middle"}, 59 | "text": {"field": "data"} 60 | } 61 | } 62 | } 63 | ] 64 | } 65 | -------------------------------------------------------------------------------- /test/applied_science/vega-specs/area.vg.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://vega.github.io/schema/vega/v5.json", 3 | "width": 500, 4 | "height": 200, 5 | "padding": 5, 6 | 7 | "signals": [ 8 | { 9 | "name": "curve", "value": "monotone", 10 | "bind": { 11 | "input": "select", 12 | "options": [ 13 | "basis", 14 | "cardinal", 15 | "catmull-rom", 16 | "linear", 17 | "monotone", 18 | "natural", 19 | "step", 20 | "step-after", 21 | "step-before" 22 | ] 23 | } 24 | } 25 | ], 26 | 27 | "data": [ 28 | { 29 | "name": "table", 30 | "values": [ 31 | {"u": 1, "v": 28}, {"u": 2, "v": 55}, 32 | {"u": 3, "v": 43}, {"u": 4, "v": 91}, 33 | {"u": 5, "v": 81}, {"u": 6, "v": 53}, 34 | {"u": 7, "v": 19}, {"u": 8, "v": 87}, 35 | {"u": 9, "v": 52}, {"u": 10, "v": 48}, 36 | {"u": 11, "v": 24}, {"u": 12, "v": 49}, 37 | {"u": 13, "v": 87}, {"u": 14, "v": 66}, 38 | {"u": 15, "v": 17}, {"u": 16, "v": 27}, 39 | {"u": 17, "v": 68}, {"u": 18, "v": 16}, 40 | {"u": 19, "v": 49}, {"u": 20, "v": 15} 41 | ] 42 | } 43 | ], 44 | 45 | "scales": [ 46 | { 47 | "name": "xscale", 48 | "type": "linear", 49 | "range": "width", 50 | "zero": false, 51 | "domain": {"data": "table", "field": "u"} 52 | }, 53 | { 54 | "name": "yscale", 55 | "type": "linear", 56 | "range": "height", 57 | "nice": true, 58 | "zero": true, 59 | "domain": {"data": "table", "field": "v"} 60 | } 61 | ], 62 | 63 | "axes": [ 64 | {"orient": "bottom", "scale": "xscale", "tickCount": 20, "zindex": 1}, 65 | {"orient": "left", "scale": "yscale", "zindex": 1} 66 | ], 67 | 68 | "marks": [ 69 | { 70 | "type": "area", 71 | "from": {"data": "table"}, 72 | "encode": { 73 | "enter": { 74 | "x": {"scale": "xscale", "field": "u"}, 75 | "y": {"scale": "yscale", "field": "v"}, 76 | "y2": {"scale": "yscale", "value": 0}, 77 | "fill": {"value": "steelblue"} 78 | }, 79 | "update": { 80 | "interpolate": {"signal": "curve"}, 81 | "fillOpacity": {"value": 1} 82 | }, 83 | "hover": { 84 | "fillOpacity": {"value": 0.5} 85 | } 86 | } 87 | } 88 | ] 89 | } 90 | -------------------------------------------------------------------------------- /test/applied_science/vega-specs/autosize-fit-x.vg.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://vega.github.io/schema/vega/v5.json", 3 | "width": 300, 4 | "height": 200, 5 | "padding": 5, 6 | "autosize": {"type": "fit-x", "contains": "padding"}, 7 | 8 | "data": [ 9 | { 10 | "name": "source", 11 | "url": "data/cars.json", 12 | "transform": [ 13 | { 14 | "type": "filter", 15 | "expr": "datum['Horsepower'] != null && datum['Miles_per_Gallon'] != null && datum['Acceleration'] != null" 16 | } 17 | ] 18 | } 19 | ], 20 | 21 | "scales": [ 22 | { 23 | "name": "x", 24 | "type": "linear", 25 | "round": true, 26 | "nice": true, 27 | "zero": true, 28 | "domain": {"data": "source", "field": "Horsepower"}, 29 | "range": "width" 30 | }, 31 | { 32 | "name": "y", 33 | "type": "linear", 34 | "round": true, 35 | "nice": true, 36 | "zero": true, 37 | "domain": {"data": "source", "field": "Miles_per_Gallon"}, 38 | "range": "height" 39 | }, 40 | { 41 | "name": "size", 42 | "type": "linear", 43 | "round": true, 44 | "nice": false, 45 | "zero": true, 46 | "domain": {"data": "source", "field": "Acceleration"}, 47 | "range": [4,361] 48 | } 49 | ], 50 | 51 | "axes": [ 52 | { 53 | "scale": "x", 54 | "grid": true, 55 | "domain": false, 56 | "orient": "bottom", 57 | "tickCount": 5, 58 | "title": "Horsepower" 59 | }, 60 | { 61 | "scale": "y", 62 | "grid": true, 63 | "domain": false, 64 | "orient": "left", 65 | "titlePadding": 5, 66 | "title": "Miles_per_Gallon" 67 | } 68 | ], 69 | 70 | "legends": [ 71 | { 72 | "size": "size", 73 | "title": "Acceleration", 74 | "format": "s", 75 | "encode": { 76 | "symbols": { 77 | "update": { 78 | "strokeWidth": {"value": 2}, 79 | "opacity": {"value": 0.5}, 80 | "stroke": {"value": "#4682b4"}, 81 | "shape": {"value": "circle"} 82 | } 83 | } 84 | } 85 | } 86 | ], 87 | 88 | "marks": [ 89 | { 90 | "name": "marks", 91 | "type": "symbol", 92 | "from": {"data": "source"}, 93 | "encode": { 94 | "update": { 95 | "x": {"scale": "x", "field": "Horsepower"}, 96 | "y": {"scale": "y", "field": "Miles_per_Gallon"}, 97 | "size": {"scale": "size", "field": "Acceleration"}, 98 | "shape": {"value": "circle"}, 99 | "strokeWidth": {"value": 2}, 100 | "opacity": {"value": 0.5}, 101 | "stroke": {"value": "#4682b4"}, 102 | "fill": {"value": "transparent"} 103 | } 104 | } 105 | } 106 | ] 107 | } 108 | -------------------------------------------------------------------------------- /test/applied_science/vega-specs/autosize-fit-y.vg.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://vega.github.io/schema/vega/v5.json", 3 | "width": 200, 4 | "height": 300, 5 | "padding": 5, 6 | "autosize": {"type": "fit-y", "contains": "padding"}, 7 | 8 | "data": [ 9 | { 10 | "name": "source", 11 | "url": "data/cars.json", 12 | "transform": [ 13 | { 14 | "type": "filter", 15 | "expr": "datum['Horsepower'] != null && datum['Miles_per_Gallon'] != null && datum['Acceleration'] != null" 16 | } 17 | ] 18 | } 19 | ], 20 | 21 | "scales": [ 22 | { 23 | "name": "x", 24 | "type": "linear", 25 | "round": true, 26 | "nice": true, 27 | "zero": true, 28 | "domain": {"data": "source", "field": "Horsepower"}, 29 | "range": "width" 30 | }, 31 | { 32 | "name": "y", 33 | "type": "linear", 34 | "round": true, 35 | "nice": true, 36 | "zero": true, 37 | "domain": {"data": "source", "field": "Miles_per_Gallon"}, 38 | "range": "height" 39 | }, 40 | { 41 | "name": "size", 42 | "type": "linear", 43 | "round": true, 44 | "nice": false, 45 | "zero": true, 46 | "domain": {"data": "source", "field": "Acceleration"}, 47 | "range": [4,361] 48 | } 49 | ], 50 | 51 | "axes": [ 52 | { 53 | "scale": "x", 54 | "grid": true, 55 | "domain": false, 56 | "orient": "bottom", 57 | "tickCount": 5, 58 | "title": "Horsepower" 59 | }, 60 | { 61 | "scale": "y", 62 | "grid": true, 63 | "domain": false, 64 | "orient": "left", 65 | "titlePadding": 5, 66 | "title": "Miles_per_Gallon" 67 | } 68 | ], 69 | 70 | "legends": [ 71 | { 72 | "size": "size", 73 | "title": "Acceleration", 74 | "format": "s", 75 | "encode": { 76 | "symbols": { 77 | "update": { 78 | "strokeWidth": {"value": 2}, 79 | "opacity": {"value": 0.5}, 80 | "stroke": {"value": "#4682b4"}, 81 | "shape": {"value": "circle"} 82 | } 83 | } 84 | } 85 | } 86 | ], 87 | 88 | "marks": [ 89 | { 90 | "name": "marks", 91 | "type": "symbol", 92 | "from": {"data": "source"}, 93 | "encode": { 94 | "update": { 95 | "x": {"scale": "x", "field": "Horsepower"}, 96 | "y": {"scale": "y", "field": "Miles_per_Gallon"}, 97 | "size": {"scale": "size", "field": "Acceleration"}, 98 | "shape": {"value": "circle"}, 99 | "strokeWidth": {"value": 2}, 100 | "opacity": {"value": 0.5}, 101 | "stroke": {"value": "#4682b4"}, 102 | "fill": {"value": "transparent"} 103 | } 104 | } 105 | } 106 | ] 107 | } 108 | -------------------------------------------------------------------------------- /test/applied_science/vega-specs/autosize-fit.vg.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://vega.github.io/schema/vega/v5.json", 3 | "width": 300, 4 | "height": 300, 5 | "padding": 5, 6 | "autosize": {"type": "fit", "contains": "padding"}, 7 | 8 | "data": [ 9 | { 10 | "name": "source", 11 | "url": "data/cars.json", 12 | "transform": [ 13 | { 14 | "type": "filter", 15 | "expr": "datum['Horsepower'] != null && datum['Miles_per_Gallon'] != null && datum['Acceleration'] != null" 16 | } 17 | ] 18 | } 19 | ], 20 | 21 | "scales": [ 22 | { 23 | "name": "x", 24 | "type": "linear", 25 | "round": true, 26 | "nice": true, 27 | "zero": true, 28 | "domain": {"data": "source", "field": "Horsepower"}, 29 | "range": "width" 30 | }, 31 | { 32 | "name": "y", 33 | "type": "linear", 34 | "round": true, 35 | "nice": true, 36 | "zero": true, 37 | "domain": {"data": "source", "field": "Miles_per_Gallon"}, 38 | "range": "height" 39 | }, 40 | { 41 | "name": "size", 42 | "type": "linear", 43 | "round": true, 44 | "nice": false, 45 | "zero": true, 46 | "domain": {"data": "source", "field": "Acceleration"}, 47 | "range": [4,361] 48 | } 49 | ], 50 | 51 | "axes": [ 52 | { 53 | "scale": "x", 54 | "grid": true, 55 | "domain": false, 56 | "orient": "bottom", 57 | "tickCount": 5, 58 | "title": "Horsepower" 59 | }, 60 | { 61 | "scale": "y", 62 | "grid": true, 63 | "domain": false, 64 | "orient": "left", 65 | "titlePadding": 5, 66 | "title": "Miles_per_Gallon" 67 | } 68 | ], 69 | 70 | "legends": [ 71 | { 72 | "size": "size", 73 | "title": "Acceleration", 74 | "format": "s", 75 | "encode": { 76 | "symbols": { 77 | "update": { 78 | "strokeWidth": {"value": 2}, 79 | "opacity": {"value": 0.5}, 80 | "stroke": {"value": "#4682b4"}, 81 | "shape": {"value": "circle"} 82 | } 83 | } 84 | } 85 | } 86 | ], 87 | 88 | "marks": [ 89 | { 90 | "name": "marks", 91 | "type": "symbol", 92 | "from": {"data": "source"}, 93 | "encode": { 94 | "update": { 95 | "x": {"scale": "x", "field": "Horsepower"}, 96 | "y": {"scale": "y", "field": "Miles_per_Gallon"}, 97 | "size": {"scale": "size", "field": "Acceleration"}, 98 | "shape": {"value": "circle"}, 99 | "strokeWidth": {"value": 2}, 100 | "opacity": {"value": 0.5}, 101 | "stroke": {"value": "#4682b4"}, 102 | "fill": {"value": "transparent"} 103 | } 104 | } 105 | } 106 | ] 107 | } 108 | -------------------------------------------------------------------------------- /test/applied_science/vega-specs/bar-hover-label.vg.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://vega.github.io/schema/vega/v5.json", 3 | "width": 400, 4 | "height": 200, 5 | "padding": 5, 6 | 7 | "signals": [ 8 | { 9 | "name": "blank", 10 | "value": {"x": 0, "y": 0} 11 | }, 12 | { 13 | "name": "label", 14 | "update": "blank", 15 | "on": [ 16 | {"events": "rect:mouseover", "update": "datum"}, 17 | {"events": "rect:mouseout", "update": "blank"} 18 | ] 19 | } 20 | ], 21 | 22 | "data": [ 23 | { 24 | "name": "table", 25 | "values": [ 26 | {"x": 1, "y": 28}, {"x": 2, "y": 55}, 27 | {"x": 3, "y": 43}, {"x": 4, "y": 91}, 28 | {"x": 5, "y": 81}, {"x": 6, "y": 53}, 29 | {"x": 7, "y": 19}, {"x": 8, "y": 87}, 30 | {"x": 9, "y": 52}, {"x": 10, "y": 48}, 31 | {"x": 11, "y": 24}, {"x": 12, "y": 49}, 32 | {"x": 13, "y": 87}, {"x": 14, "y": 66}, 33 | {"x": 15, "y": 17}, {"x": 16, "y": 27}, 34 | {"x": 17, "y": 68}, {"x": 18, "y": 16}, 35 | {"x": 19, "y": 49}, {"x": 20, "y": 15} 36 | ] 37 | } 38 | ], 39 | 40 | "scales": [ 41 | { 42 | "name": "xscale", 43 | "type": "band", 44 | "range": "width", 45 | "padding": 0.05, 46 | "round": true, 47 | "domain": {"data": "table", "field": "x"} 48 | }, 49 | { 50 | "name": "yscale", 51 | "type": "linear", 52 | "range": "height", 53 | "domain": {"data": "table", "field": "y"}, 54 | "nice": true 55 | } 56 | ], 57 | 58 | "axes": [ 59 | {"orient": "bottom", "scale": "xscale", "zindex": 1}, 60 | {"orient": "left", "scale": "yscale", "zindex": 1} 61 | ], 62 | 63 | "marks": [ 64 | { 65 | "type": "rect", 66 | "from": {"data": "table"}, 67 | "encode": { 68 | "enter": { 69 | "x": {"scale": "xscale", "field": "x"}, 70 | "width": {"scale": "xscale", "band": 1}, 71 | "y": {"scale": "yscale", "field": "y"}, 72 | "y2": {"scale": "yscale", "value": 0} 73 | }, 74 | "update": { 75 | "fill": [ 76 | {"test": "datum === label", "value": "red"}, 77 | {"value": "steelblue"} 78 | ] 79 | } 80 | } 81 | }, 82 | { 83 | "type": "text", 84 | "encode": { 85 | "enter": { 86 | "align": {"value": "center"}, 87 | "fill": {"value": "#333"} 88 | }, 89 | "update": { 90 | "x": {"scale": "xscale", "signal": "label.x", "band": 0.5}, 91 | "y": {"scale": "yscale", "signal": "label.y", "offset": -5}, 92 | "text": {"signal": "label.y"}, 93 | "fillOpacity": [ 94 | {"test": "label === blank", "value": 0}, 95 | {"value": 1} 96 | ] 97 | } 98 | } 99 | } 100 | ] 101 | } 102 | -------------------------------------------------------------------------------- /test/applied_science/vega-specs/bar-rangestep.vg.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://vega.github.io/schema/vega/v5.json", 3 | "height": 200, 4 | "padding": 5, 5 | 6 | "signals": [ 7 | { 8 | "name": "step", "value": 20, 9 | "bind": {"input": "range", "min": 0, "max": 40, "step": 1} 10 | }, 11 | { 12 | "name": "inner", "value": 0.1, 13 | "bind": {"input": "range", "min": 0, "max": 1} 14 | }, 15 | { 16 | "name": "outer", "value": 0.1, 17 | "bind": {"input": "range", "min": 0, "max": 1} 18 | }, 19 | { 20 | "name": "count", "value": 10, 21 | "bind": {"input": "range", "min": 0, "max": 20, "step": 1} 22 | }, 23 | { 24 | "name": "round", "value": false, 25 | "bind": {"input": "checkbox"} 26 | }, 27 | { 28 | "name": "width", 29 | "update": "ceil(step * bandspace(count, inner, outer))" 30 | } 31 | ], 32 | 33 | "data": [ 34 | { 35 | "name": "table", 36 | "values": [ 37 | {"u": 1, "v": 91}, {"u": 2, "v": 55}, 38 | {"u": 3, "v": 43}, {"u": 4, "v": 28}, 39 | {"u": 5, "v": 81}, {"u": 6, "v": 53}, 40 | {"u": 7, "v": 19}, {"u": 8, "v": 87}, 41 | {"u": 9, "v": 52}, {"u": 10, "v": 48}, 42 | {"u": 11, "v": 24}, {"u": 12, "v": 49}, 43 | {"u": 13, "v": 87}, {"u": 14, "v": 66}, 44 | {"u": 15, "v": 17}, {"u": 16, "v": 27}, 45 | {"u": 17, "v": 68}, {"u": 18, "v": 16}, 46 | {"u": 19, "v": 49}, {"u": 20, "v": 15} 47 | ], 48 | "transform": [ 49 | { "type": "filter", "expr": "datum.u <= count" } 50 | ] 51 | } 52 | ], 53 | 54 | "scales": [ 55 | { 56 | "name": "xscale", 57 | "type": "band", 58 | "range": {"step": {"signal": "step"}}, 59 | "paddingInner": {"signal": "inner"}, 60 | "paddingOuter": {"signal": "outer"}, 61 | "round": {"signal": "round"}, 62 | "domain": {"data": "table", "field": "u"} 63 | }, 64 | { 65 | "name": "yscale", 66 | "type": "linear", 67 | "range": "height", 68 | "domain": [0, 100], 69 | "zero": true, 70 | "nice": true 71 | } 72 | ], 73 | 74 | "axes": [ 75 | {"orient": "bottom", "scale": "xscale", "offset": 4}, 76 | {"orient": "left", "scale": "yscale", "offset": 4} 77 | ], 78 | 79 | "marks": [ 80 | { 81 | "type": "rect", 82 | "from": {"data": "table"}, 83 | "encode": { 84 | "enter": { 85 | "y": {"scale": "yscale", "field": "v"}, 86 | "y2": {"scale": "yscale", "value": 0}, 87 | "fill": {"value": "steelblue"} 88 | }, 89 | "update": { 90 | "x": {"scale": "xscale", "field": "u"}, 91 | "width": {"scale": "xscale", "band": 1} 92 | } 93 | } 94 | } 95 | ] 96 | } 97 | -------------------------------------------------------------------------------- /test/applied_science/vega-specs/bar.vg.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://vega.github.io/schema/vega/v5.json", 3 | "width": 400, 4 | "height": 200, 5 | "padding": 5, 6 | 7 | "data": [ 8 | { 9 | "name": "table", 10 | "values": [ 11 | {"u": 1, "v": 28}, {"u": 2, "v": 55}, 12 | {"u": 3, "v": 43}, {"u": 4, "v": 91}, 13 | {"u": 5, "v": 81}, {"u": 6, "v": 53}, 14 | {"u": 7, "v": 19}, {"u": 8, "v": 87}, 15 | {"u": 9, "v": 52}, {"u": 10, "v": 48}, 16 | {"u": 11, "v": 24}, {"u": 12, "v": 49}, 17 | {"u": 13, "v": 87}, {"u": 14, "v": 66}, 18 | {"u": 15, "v": 17}, {"u": 16, "v": 27}, 19 | {"u": 17, "v": 68}, {"u": 18, "v": 16}, 20 | {"u": 19, "v": 49}, {"u": 20, "v": 15} 21 | ] 22 | } 23 | ], 24 | 25 | "scales": [ 26 | { 27 | "name": "xscale", 28 | "type": "band", 29 | "range": "width", 30 | "padding": 0.05, 31 | "round": true, 32 | "domain": {"data": "table", "field": "u"} 33 | }, 34 | { 35 | "name": "yscale", 36 | "type": "linear", 37 | "range": "height", 38 | "domain": {"data": "table", "field": "v"}, 39 | "zero": true, 40 | "nice": true 41 | } 42 | ], 43 | 44 | "axes": [ 45 | {"orient": "bottom", "scale": "xscale", "zindex": 1}, 46 | {"orient": "left", "scale": "yscale", "zindex": 1} 47 | ], 48 | 49 | "marks": [ 50 | { 51 | "type": "rect", 52 | "from": {"data": "table"}, 53 | "encode": { 54 | "enter": { 55 | "x": {"scale": "xscale", "field": "u"}, 56 | "width": {"scale": "xscale", "band": 1}, 57 | "y": {"scale": "yscale", "field": "v"}, 58 | "y2": {"scale": "yscale", "value": 0} 59 | }, 60 | "update": { 61 | "fill": {"value": "steelblue"} 62 | }, 63 | "hover": { 64 | "fill": {"value": "red"} 65 | } 66 | } 67 | } 68 | ] 69 | } 70 | -------------------------------------------------------------------------------- /test/applied_science/vega-specs/barley.vg.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://vega.github.io/schema/vega/v5.json", 3 | "width": 200, 4 | "padding": 5, 5 | 6 | "signals": [ 7 | {"name": "offset", "value": 15}, 8 | {"name": "cellHeight", "value": 100}, 9 | {"name": "height", "update": "6 * (offset + cellHeight)"} 10 | ], 11 | 12 | "data": [ 13 | { 14 | "name": "barley", 15 | "url": "data/barley.json" 16 | } 17 | ], 18 | 19 | "scales": [ 20 | { 21 | "name": "gscale", 22 | "type": "band", 23 | "range": [0, {"signal": "height"}], 24 | "round": true, 25 | "domain": { 26 | "data": "barley", 27 | "field": "site", 28 | "sort": { 29 | "field": "yield", 30 | "op": "median", 31 | "order": "descending" 32 | } 33 | } 34 | }, 35 | { 36 | "name": "xscale", 37 | "type": "linear", 38 | "nice": true, 39 | "range": "width", 40 | "round": true, 41 | "domain": {"data": "barley", "field": "yield"} 42 | }, 43 | { 44 | "name": "cscale", 45 | "type": "ordinal", 46 | "range": "category", 47 | "domain": {"data": "barley", "field": "year"} 48 | } 49 | ], 50 | 51 | "axes": [ 52 | {"orient": "bottom", "scale": "xscale", "tickCount": 5, "zindex": 1} 53 | ], 54 | 55 | "legends": [ 56 | { 57 | "stroke": "cscale", 58 | "title": "Year", 59 | "padding": 4, 60 | "encode": { 61 | "symbols": { 62 | "enter": { 63 | "strokeWidth": {"value": 2}, 64 | "size": {"value": 50} 65 | } 66 | } 67 | } 68 | } 69 | ], 70 | 71 | "marks": [ 72 | { 73 | "name": "site", 74 | "type": "group", 75 | 76 | "from": { 77 | "facet": { 78 | "data": "barley", 79 | "name": "sites", 80 | "groupby": "site" 81 | } 82 | }, 83 | 84 | "encode": { 85 | "enter": { 86 | "y": {"scale": "gscale", "field": "site", "offset": {"signal": "offset"}}, 87 | "height": {"signal": "cellHeight"}, 88 | "width": {"signal": "width"}, 89 | "stroke": {"value": "#ccc"} 90 | } 91 | }, 92 | 93 | "scales": [ 94 | { 95 | "name": "yscale", 96 | "type": "point", 97 | "range": [0, {"signal": "cellHeight"}], 98 | "padding": 1, 99 | "round": true, 100 | "domain": { 101 | "data": "barley", 102 | "field": "variety", 103 | "sort": { 104 | "field": "yield", 105 | "op": "median", 106 | "order": "descending" 107 | } 108 | } 109 | } 110 | ], 111 | 112 | "axes": [ 113 | { 114 | "orient": "left", 115 | "scale": "yscale", 116 | "tickSize": 0, 117 | "domain": false, 118 | "grid": true, 119 | "encode": { 120 | "grid": { 121 | "enter": {"strokeDash": {"value": [3,3]}} 122 | } 123 | } 124 | }, 125 | { 126 | "orient": "right", 127 | "scale": "yscale", 128 | "tickSize": 0, 129 | "domain": false 130 | } 131 | ], 132 | 133 | "marks": [ 134 | { 135 | "type": "symbol", 136 | "from": {"data": "sites"}, 137 | "encode": { 138 | "enter": { 139 | "x": {"scale": "xscale", "field": "yield"}, 140 | "y": {"scale": "yscale", "field": "variety"}, 141 | "stroke": {"scale": "cscale", "field": "year"}, 142 | "strokeWidth": {"value": 2}, 143 | "size": {"value": 50} 144 | } 145 | } 146 | } 147 | ] 148 | }, 149 | 150 | { 151 | "type": "text", 152 | "from": {"data": "site"}, 153 | "encode": { 154 | "enter": { 155 | "x": {"field": "width", "mult": 0.5}, 156 | "y": {"field": "y"}, 157 | "fontSize": {"value": 11}, 158 | "fontWeight": {"value": "bold"}, 159 | "text": {"field": "datum.site"}, 160 | "align": {"value": "center"}, 161 | "baseline": {"value": "bottom"}, 162 | "fill": {"value": "#000"} 163 | } 164 | } 165 | } 166 | ] 167 | } 168 | -------------------------------------------------------------------------------- /test/applied_science/vega-specs/choropleth.vg.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://vega.github.io/schema/vega/v5.json", 3 | "width": 960, 4 | "height": 500, 5 | "autosize": "none", 6 | 7 | "data": [ 8 | { 9 | "name": "unemp", 10 | "url": "data/unemployment.tsv", 11 | "format": {"type": "tsv", "parse": "auto"} 12 | }, 13 | { 14 | "name": "counties", 15 | "url": "data/us-10m.json", 16 | "format": {"type": "topojson", "feature": "counties"}, 17 | "transform": [ 18 | { "type": "lookup", "from": "unemp", "key": "id", "fields": ["id"], "values": ["rate"] }, 19 | { "type": "filter", "expr": "datum.rate != null" } 20 | ] 21 | } 22 | ], 23 | 24 | "projections": [ 25 | { 26 | "name": "projection", 27 | "type": "albersUsa" 28 | } 29 | ], 30 | 31 | "scales": [ 32 | { 33 | "name": "color", 34 | "type": "quantize", 35 | "domain": [0, 0.15], 36 | "range": {"scheme": "blues", "count": 9} 37 | } 38 | ], 39 | 40 | "legends": [ 41 | { 42 | "fill": "color", 43 | "orient": "bottom-right", 44 | "title": "Unemployment", 45 | "format": "0.1%" 46 | } 47 | ], 48 | 49 | "marks": [ 50 | { 51 | "type": "shape", 52 | "from": {"data": "counties"}, 53 | "encode": { 54 | "enter": { "tooltip": {"signal": "format(datum.rate, '0.1%')"}}, 55 | "update": { "fill": {"scale": "color", "field": "rate"} }, 56 | "hover": { "fill": {"value": "red"} } 57 | }, 58 | "transform": [ 59 | { "type": "geoshape", "projection": "projection" } 60 | ] 61 | } 62 | ] 63 | } 64 | -------------------------------------------------------------------------------- /test/applied_science/vega-specs/contour-map.vg.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://vega.github.io/schema/vega/v5.json", 3 | "width": 900, 4 | "height": 560, 5 | "padding": 10, 6 | "autosize": "none", 7 | 8 | "signals": [ 9 | { 10 | "name": "count", "value": 10, 11 | "bind": {"input": "select", "options": [1, 5, 10, 20]} 12 | } 13 | ], 14 | 15 | "title": { 16 | "text": "Density of U.S. Airports, 2008", 17 | "offset": -15 18 | }, 19 | 20 | "data": [ 21 | { 22 | "name": "states", 23 | "url": "data/us-10m.json", 24 | "format": {"type": "topojson", "feature": "states"}, 25 | "transform": [ 26 | { 27 | "type": "geopath", 28 | "projection": "projection" 29 | } 30 | ] 31 | }, 32 | { 33 | "name": "airports", 34 | "url": "data/airports.csv", 35 | "format": {"type": "csv","parse": "auto" 36 | }, 37 | "transform": [ 38 | { 39 | "type": "geopoint", 40 | "projection": "projection", 41 | "fields": ["longitude", "latitude"] 42 | }, 43 | { 44 | "type": "filter", 45 | "expr": "datum.x != null && datum.y != null" 46 | } 47 | ] 48 | } 49 | ], 50 | 51 | "projections": [ 52 | { 53 | "name": "projection", 54 | "type": "albers", 55 | "scale": 1150, 56 | "translate": [{"signal": "width / 2"}, {"signal": "height / 2"}] 57 | } 58 | ], 59 | 60 | "marks": [ 61 | { 62 | "type": "path", 63 | "clip": true, 64 | "from": {"data": "states"}, 65 | "encode": { 66 | "enter": { 67 | "fill": {"value": "#dedede"}, 68 | "stroke": {"value": "white"} 69 | }, 70 | "update": { 71 | "path": {"field": "path"} 72 | } 73 | } 74 | }, 75 | { 76 | "type": "symbol", 77 | "clip": true, 78 | "from": {"data": "airports"}, 79 | "encode": { 80 | "enter": { 81 | "size": {"value": 10}, 82 | "fill": {"value": "steelblue"}, 83 | "fillOpacity": {"value": 0.8}, 84 | "stroke": {"value": "white"}, 85 | "strokeWidth": {"value": 0.5} 86 | }, 87 | "update": { 88 | "x": {"field": "x"}, 89 | "y": {"field": "y"} 90 | } 91 | } 92 | }, 93 | { 94 | "type": "group", 95 | "clip": true, 96 | "data": [ 97 | { 98 | "name": "contours", 99 | "source": "airports", 100 | "transform": [ 101 | { 102 | "type": "contour", 103 | "x": "x", 104 | "y": "y", 105 | "size": [{"signal": "width"}, {"signal": "height"}], 106 | "count": {"signal": "count"}, 107 | "bandwidth": 20 108 | } 109 | ] 110 | } 111 | ], 112 | "scales": [ 113 | { 114 | "name": "color", 115 | "type": "linear", 116 | "domain": {"data": "contours", "field": "value"}, 117 | "range": {"scheme": "viridis"} 118 | } 119 | ], 120 | "marks": [ 121 | { 122 | "type": "shape", 123 | "from": {"data": "contours"}, 124 | "encode": { 125 | "enter": { 126 | "stroke": {"value": "firebrick"}, 127 | "fill": {"scale": "color", "field": "value"}, 128 | "fillOpacity": {"value": 0.3} 129 | }, 130 | "update": { 131 | "strokeWidth": {"value": 1} 132 | }, 133 | "hover": { 134 | "strokeWidth": {"value": 3} 135 | } 136 | }, 137 | "transform": [ 138 | { "type": "geoshape", "field": "datum" } 139 | ] 140 | } 141 | ] 142 | } 143 | ] 144 | } 145 | -------------------------------------------------------------------------------- /test/applied_science/vega-specs/contour-scatter.vg.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://vega.github.io/schema/vega/v5.json", 3 | "width": 200, 4 | "height": 200, 5 | "padding": 5, 6 | "autosize": "pad", 7 | 8 | "signals": [ 9 | { 10 | "name": "count", "value": 5, 11 | "bind": {"input": "select", "options": [1, 2, 3, 4, 5, 10]} 12 | }, 13 | { 14 | "name": "nice", "value": false, 15 | "bind": {"input": "checkbox"} 16 | } 17 | ], 18 | 19 | "data": [ 20 | { 21 | "name": "source", 22 | "url": "data/cars.json", 23 | "transform": [ 24 | { 25 | "type": "filter", 26 | "expr": "datum.Horsepower != null && datum.Miles_per_Gallon != null && datum.Acceleration != null" 27 | } 28 | ] 29 | } 30 | ], 31 | 32 | "scales": [ 33 | { 34 | "name": "x", 35 | "type": "linear", 36 | "round": true, 37 | "nice": true, 38 | "zero": true, 39 | "domain": {"data": "source", "field": "Horsepower"}, 40 | "range": [0,200] 41 | }, 42 | { 43 | "name": "y", 44 | "type": "linear", 45 | "round": true, 46 | "nice": true, 47 | "zero": true, 48 | "domain": {"data": "source", "field": "Miles_per_Gallon"}, 49 | "range": [200,0] 50 | } 51 | ], 52 | 53 | "axes": [ 54 | { 55 | "scale": "x", 56 | "grid": true, 57 | "domain": false, 58 | "orient": "bottom", 59 | "tickCount": 5, 60 | "title": "Horsepower" 61 | }, 62 | { 63 | "scale": "y", 64 | "grid": true, 65 | "domain": false, 66 | "orient": "left", 67 | "titlePadding": 5, 68 | "title": "Miles_per_Gallon" 69 | } 70 | ], 71 | 72 | "marks": [ 73 | { 74 | "type": "group", 75 | "clip": true, 76 | "data": [ 77 | { 78 | "name": "contours", 79 | "source": "source", 80 | "transform": [ 81 | { 82 | "type": "contour", 83 | "x": {"expr": "scale('x', datum.Horsepower)"}, 84 | "y": {"expr": "scale('y', datum.Miles_per_Gallon)"}, 85 | "size": [{"signal": "width"}, {"signal": "height"}], 86 | "count": {"signal": "count"}, 87 | "nice": {"signal": "nice"}, 88 | "bandwidth": 20 89 | } 90 | ] 91 | } 92 | ], 93 | "scales": [ 94 | { 95 | "name": "color", 96 | "type": "linear", 97 | "domain": {"data": "contours", "field": "value"}, 98 | "range": "ramp" 99 | } 100 | ], 101 | "marks": [ 102 | { 103 | "type": "path", 104 | "from": {"data": "contours"}, 105 | "encode": { 106 | "enter": { 107 | "stroke": {"value": "#888"}, 108 | "strokeWidth": {"value": 1}, 109 | "fill": {"scale": "color", "field": "value"}, 110 | "fillOpacity": {"value": 0.35} 111 | } 112 | }, 113 | "transform": [ 114 | { "type": "geopath", "field": "datum" } 115 | ] 116 | } 117 | ] 118 | }, 119 | { 120 | "name": "marks", 121 | "type": "symbol", 122 | "from": {"data": "source"}, 123 | "encode": { 124 | "update": { 125 | "x": {"scale": "x", "field": "Horsepower"}, 126 | "y": {"scale": "y", "field": "Miles_per_Gallon"}, 127 | "size": {"value": 4}, 128 | "fill": {"value": "black"} 129 | } 130 | } 131 | } 132 | ] 133 | } 134 | -------------------------------------------------------------------------------- /test/applied_science/vega-specs/density.vg.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://vega.github.io/schema/vega/v5.json", 3 | "width": 500, 4 | "height": 100, 5 | "padding": 5, 6 | 7 | "signals": [ 8 | { "name": "bandwidth", "value": 0, 9 | "bind": {"input": "range", "min": 0, "max": 0.1, "step": 0.001} }, 10 | { "name": "steps", "value": 0, 11 | "bind": {"input": "range", "min": 0, "max": 500, "step": 1} }, 12 | { "name": "method", "value": "pdf", 13 | "bind": { 14 | "input": "radio", "options": ["pdf", "cdf"], 15 | "labels": ["Probability Density", "Cumulative Distribution"] 16 | } 17 | }, 18 | { "name": "summary", 19 | "update": "data('summary')[0] || {mean: 0, stdev: 0}" } 20 | ], 21 | 22 | "data": [ 23 | { 24 | "name": "points", 25 | "url": "data/normal-2d.json" 26 | }, 27 | { 28 | "name": "summary", 29 | "source": "points", 30 | "transform": [ 31 | { 32 | "type": "aggregate", 33 | "fields": ["u", "u"], 34 | "ops": ["mean", "stdev"], 35 | "as": ["mean", "stdev"] 36 | } 37 | ] 38 | }, 39 | { 40 | "name": "density", 41 | "source": "points", 42 | "transform": [ 43 | { 44 | "type": "density", 45 | "extent": {"signal": "domain('xscale')"}, 46 | "steps": {"signal": "steps"}, 47 | "method": {"signal": "method"}, 48 | "distribution": { 49 | "function": "kde", 50 | "field": "u", 51 | "bandwidth": {"signal": "bandwidth"} 52 | } 53 | } 54 | ] 55 | }, 56 | { 57 | "name": "normal", 58 | "transform": [ 59 | { 60 | "type": "density", 61 | "extent": {"signal": "domain('xscale')"}, 62 | "steps": {"signal": "steps"}, 63 | "method": {"signal": "method"}, 64 | "distribution": { 65 | "function": "normal", 66 | "mean": {"signal": "summary.mean"}, 67 | "stdev": {"signal": "summary.stdev"} 68 | } 69 | } 70 | ] 71 | } 72 | ], 73 | 74 | "scales": [ 75 | { 76 | "name": "xscale", 77 | "type": "linear", 78 | "range": "width", 79 | "domain": {"data": "points", "field": "u"}, 80 | "nice": true 81 | }, 82 | { 83 | "name": "yscale", 84 | "type": "linear", 85 | "range": "height", "round": true, 86 | "domain": { 87 | "fields": [ 88 | {"data": "density", "field": "density"}, 89 | {"data": "normal", "field": "density"} 90 | ] 91 | } 92 | }, 93 | { 94 | "name": "color", 95 | "type": "ordinal", 96 | "domain": ["Normal Estimate", "Kernel Density Estimate"], 97 | "range": ["#444", "steelblue"] 98 | } 99 | ], 100 | 101 | "axes": [ 102 | {"orient": "bottom", "scale": "xscale", "zindex": 1} 103 | ], 104 | 105 | "legends": [ 106 | {"orient": "top-left", "fill": "color", "offset": 0, "zindex": 1} 107 | ], 108 | 109 | "marks": [ 110 | { 111 | "type": "area", 112 | "from": {"data": "density"}, 113 | "encode": { 114 | "update": { 115 | "x": {"scale": "xscale", "field": "value"}, 116 | "y": {"scale": "yscale", "field": "density"}, 117 | "y2": {"scale": "yscale", "value": 0}, 118 | "fill": {"signal": "scale('color', 'Kernel Density Estimate')"} 119 | } 120 | } 121 | }, 122 | { 123 | "type": "line", 124 | "from": {"data": "normal"}, 125 | "encode": { 126 | "update": { 127 | "x": {"scale": "xscale", "field": "value"}, 128 | "y": {"scale": "yscale", "field": "density"}, 129 | "stroke": {"signal": "scale('color', 'Normal Estimate')"}, 130 | "strokeWidth": {"value": 2} 131 | } 132 | } 133 | }, 134 | { 135 | "type": "rect", 136 | "from": {"data": "points"}, 137 | "encode": { 138 | "enter": { 139 | "x": {"scale": "xscale", "field": "u"}, 140 | "width": {"value": 1}, 141 | "y": {"value": 25, "offset": {"signal": "height"}}, 142 | "height": {"value": 5}, 143 | "fill": {"value": "steelblue"}, 144 | "fillOpacity": {"value": 0.4} 145 | } 146 | } 147 | } 148 | ] 149 | } 150 | -------------------------------------------------------------------------------- /test/applied_science/vega-specs/dot-plot.vg.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://vega.github.io/schema/vega/v5.json", 3 | "width": 300, 4 | "padding": 5, 5 | 6 | "signals": [ 7 | { 8 | "name": "step", "value": 0.65, 9 | "bind": {"input": "range", "min": 0.1, "max": 2, "step": 0.01} 10 | }, 11 | { 12 | "name": "offset", "value": "zero", 13 | "bind": {"input": "radio", "options": ["zero", "center"]} 14 | }, 15 | { 16 | "name": "smooth", "value": true, 17 | "bind": {"input": "checkbox"} 18 | }, 19 | {"name": "size", "update": "scale('x', step) - scale('x', 0)"}, 20 | {"name": "area", "update": "size * size"}, 21 | {"name": "ddh", "update": "(span(ddext) + 1) * size"}, 22 | {"name": "hdh", "update": "(span(hdext) + 1) * size"}, 23 | {"name": "height", "update": "max(ddh, hdh)"} 24 | ], 25 | 26 | "data": [ 27 | { 28 | "name": "points", 29 | "values": [ 30 | 6.3, 2.1, 9.1, 15.8, 5.2, 10.9, 8.3, 11.0, 3.2, 7.6, 6.3, 8.6, 6.6, 31 | 9.5, 4.8, 12.0, 3.3, 11.0, 4.7, 10.4, 7.4, 2.1, 7.7, 17.9, 6.1, 8.2, 32 | 8.4, 11.9, 10.8, 13.8, 14.3, 15.2, 10.0, 11.9, 6.5, 7.5, 10.6, 7.4, 33 | 8.4, 5.7, 4.9, 3.2, 8.1, 11.0, 4.9, 13.2, 9.7, 12.8 34 | ], 35 | "transform": [ 36 | { 37 | "type": "dotbin", 38 | "field": "data", 39 | "smooth": {"signal": "smooth"}, 40 | "step": {"signal": "step"} 41 | }, 42 | { 43 | "type": "stack", 44 | "groupby": ["bin"], 45 | "offset": {"signal": "offset"}, 46 | "as": ["d0", "d1"] 47 | }, 48 | { 49 | "type": "extent", 50 | "field": "d1", 51 | "signal": "ddext" 52 | }, 53 | { 54 | "type": "extent", 55 | "field": "data", 56 | "signal": "ext" 57 | }, 58 | { 59 | "type": "bin", 60 | "field": "data", 61 | "step": {"signal": "step"}, 62 | "extent": {"signal": "ext"} 63 | }, 64 | { 65 | "type": "stack", 66 | "offset": {"signal": "offset"}, 67 | "groupby": ["bin0"] 68 | }, 69 | { 70 | "type": "extent", 71 | "field": "y0", 72 | "signal": "hdext" 73 | } 74 | ] 75 | } 76 | ], 77 | 78 | "scales": [ 79 | { 80 | "name": "x", 81 | "domain": [0, 20], 82 | "range": "width" 83 | }, 84 | { 85 | "name": "ddy", 86 | "domain": {"signal": "[0, ddh / size]"}, 87 | "range": {"signal": "[height, height - ddh]"} 88 | }, 89 | { 90 | "name": "hdy", 91 | "domain": {"signal": "[0, hdh / size]"}, 92 | "range": {"signal": "[height, height - hdh]"} 93 | } 94 | ], 95 | 96 | "marks": [ 97 | { 98 | "type": "group", 99 | "encode": { 100 | "update": { 101 | "width": {"signal": "width"}, 102 | "height": {"signal": "height"} 103 | } 104 | }, 105 | "axes": [ 106 | {"scale": "x", "orient": "bottom", "tickCount": 5, "title": "Density Dot Plot"} 107 | ], 108 | "marks": [ 109 | { 110 | "type": "symbol", 111 | "from": {"data": "points"}, 112 | "encode": { 113 | "update": { 114 | "x": {"scale": "x", "field": "bin"}, 115 | "y": {"scale": "ddy", "signal": "datum.d0 + 0.5"}, 116 | "size": {"signal": "area"}, 117 | "fill": {"value": "steelblue"} 118 | } 119 | } 120 | } 121 | ] 122 | }, 123 | { 124 | "type": "group", 125 | "encode": { 126 | "update": { 127 | "x": {"signal": "width + 10"}, 128 | "width": {"signal": "width"}, 129 | "height": {"signal": "height"} 130 | } 131 | }, 132 | "axes": [ 133 | {"scale": "x", "orient": "bottom", "tickCount": 5, "title": "Histogram Dot Plot"} 134 | ], 135 | "marks": [ 136 | { 137 | "type": "symbol", 138 | "from": {"data": "points"}, 139 | "encode": { 140 | "update": { 141 | "x": {"scale": "x", "signal": "(datum.bin0 + datum.bin1) / 2"}, 142 | "y": {"scale": "hdy", "signal": "datum.y0 + 0.5"}, 143 | "size": {"signal": "area"}, 144 | "fill": {"value": "steelblue"} 145 | } 146 | } 147 | } 148 | ] 149 | } 150 | ] 151 | } 152 | -------------------------------------------------------------------------------- /test/applied_science/vega-specs/driving.vg.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://vega.github.io/schema/vega/v5.json", 3 | "width": 800, 4 | "height": 500, 5 | "padding": 5, 6 | 7 | "config": { 8 | "axis": { 9 | "domain": false, 10 | "grid": true, 11 | "labelFontSize": 12, 12 | "labelFontWeight": "bold", 13 | "tickSize": 0 14 | } 15 | }, 16 | 17 | "data": [ 18 | { 19 | "name": "drive", 20 | "url": "data/driving.json" 21 | } 22 | ], 23 | 24 | "scales": [ 25 | { 26 | "name": "x", 27 | "type": "linear", 28 | "domain": {"data": "drive", "field": "miles"}, 29 | "range": "width", 30 | "nice": true, 31 | "zero": false, 32 | "round": true 33 | }, 34 | { 35 | "name": "y", 36 | "type": "linear", 37 | "domain": {"data": "drive", "field": "gas"}, 38 | "range": "height", 39 | "nice": true, 40 | "zero": false, 41 | "round": true 42 | }, 43 | { 44 | "name": "align", 45 | "type": "ordinal", 46 | "domain": ["left", "right", "top", "bottom"], 47 | "range": ["right", "left", "center", "center"] 48 | }, 49 | { 50 | "name": "base", 51 | "type": "ordinal", 52 | "domain": ["left", "right", "top", "bottom"], 53 | "range": ["middle", "middle", "bottom", "top"] 54 | }, 55 | { 56 | "name": "dx", 57 | "type": "ordinal", 58 | "domain": ["left", "right", "top", "bottom"], 59 | "range": [-7, 6, 0, 0] 60 | }, 61 | { 62 | "name": "dy", 63 | "type": "ordinal", 64 | "domain": ["left", "right", "top", "bottom"], 65 | "range": [1, 1, -5, 6] 66 | } 67 | ], 68 | 69 | "axes": [ 70 | { 71 | "orient": "top", 72 | "scale": "x", 73 | "tickCount": 5 74 | }, 75 | { 76 | "orient": "left", 77 | "scale": "y", 78 | "tickCount": 5, 79 | "format": "$0.2f" 80 | } 81 | ], 82 | 83 | "marks": [ 84 | { 85 | "type": "line", 86 | "from": {"data": "drive"}, 87 | "encode": { 88 | "enter": { 89 | "interpolate": {"value": "cardinal"}, 90 | "x": {"scale": "x", "field": "miles"}, 91 | "y": {"scale": "y", "field": "gas"}, 92 | "stroke": {"value": "#000"}, 93 | "strokeWidth": {"value": 3} 94 | } 95 | } 96 | }, 97 | { 98 | "type": "symbol", 99 | "from": {"data": "drive"}, 100 | "encode": { 101 | "enter": { 102 | "x": {"scale": "x", "field": "miles"}, 103 | "y": {"scale": "y", "field": "gas"}, 104 | "fill": {"value": "#fff"}, 105 | "stroke": {"value": "#000"}, 106 | "strokeWidth": {"value": 1}, 107 | "size": {"value": 49} 108 | } 109 | } 110 | }, 111 | { 112 | "type": "text", 113 | "from": {"data": "drive"}, 114 | "encode": { 115 | "enter": { 116 | "x": {"scale": "x", "field": "miles"}, 117 | "y": {"scale": "y", "field": "gas"}, 118 | "dx": {"scale": "dx", "field": "side"}, 119 | "dy": {"scale": "dy", "field": "side"}, 120 | "fill": {"value": "#000"}, 121 | "text": {"field": "year"}, 122 | "align": {"scale": "align", "field": "side"}, 123 | "baseline": {"scale": "base", "field": "side"} 124 | } 125 | } 126 | } 127 | ] 128 | } 129 | -------------------------------------------------------------------------------- /test/applied_science/vega-specs/dynamic-format.vg.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://vega.github.io/schema/vega/v5.json", 3 | "width": 400, 4 | "height": 200, 5 | "padding": 5, 6 | 7 | "signals": [ 8 | { 9 | "name": "property", "value": "a", 10 | "bind": {"input": "select", "options": ["a", "b"]} 11 | } 12 | ], 13 | 14 | "data": [ 15 | { 16 | "name": "table", 17 | "format": { 18 | "type": "json", 19 | "property": {"signal": "property"} 20 | }, 21 | "values": { 22 | "a": [ 23 | {"u": 1, "v": 28}, {"u": 2, "v": 55}, 24 | {"u": 3, "v": 43}, {"u": 4, "v": 91}, 25 | {"u": 5, "v": 81}, {"u": 6, "v": 53}, 26 | {"u": 7, "v": 19}, {"u": 8, "v": 87}, 27 | {"u": 9, "v": 52}, {"u": 10, "v": 48} 28 | ], 29 | "b": [ 30 | {"u": 1, "v": 24}, {"u": 2, "v": 49}, 31 | {"u": 3, "v": 87}, {"u": 4, "v": 66}, 32 | {"u": 5, "v": 17}, {"u": 6, "v": 27}, 33 | {"u": 7, "v": 68}, {"u": 8, "v": 16}, 34 | {"u": 9, "v": 49}, {"u": 10, "v": 15} 35 | ] 36 | } 37 | } 38 | ], 39 | 40 | "scales": [ 41 | { 42 | "name": "xscale", 43 | "type": "band", 44 | "range": "width", 45 | "padding": 0.05, 46 | "round": true, 47 | "domain": {"data": "table", "field": "u"} 48 | }, 49 | { 50 | "name": "yscale", 51 | "type": "linear", 52 | "range": "height", 53 | "domain": {"data": "table", "field": "v"}, 54 | "zero": true, 55 | "nice": true 56 | } 57 | ], 58 | 59 | "axes": [ 60 | {"orient": "bottom", "scale": "xscale", "zindex": 1}, 61 | {"orient": "left", "scale": "yscale", "zindex": 1} 62 | ], 63 | 64 | "marks": [ 65 | { 66 | "type": "rect", 67 | "from": {"data": "table"}, 68 | "encode": { 69 | "enter": { 70 | "x": {"scale": "xscale", "field": "u"}, 71 | "width": {"scale": "xscale", "band": 1}, 72 | "y": {"scale": "yscale", "field": "v"}, 73 | "y2": {"scale": "yscale", "value": 0} 74 | }, 75 | "update": { 76 | "fill": {"value": "steelblue"} 77 | }, 78 | "hover": { 79 | "fill": {"value": "red"} 80 | } 81 | } 82 | } 83 | ] 84 | } 85 | -------------------------------------------------------------------------------- /test/applied_science/vega-specs/dynamic-url.vg.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://vega.github.io/schema/vega/v5.json", 3 | "width": 300, 4 | "height": 300, 5 | "padding": 5, 6 | 7 | "signals": [ 8 | { 9 | "name": "url", 10 | "value": "data/normal-2d.json", 11 | "bind": { 12 | "input": "select", 13 | "options": [ 14 | "data/normal-2d.json", 15 | "data/uniform-2d.json" 16 | ] 17 | } 18 | }, 19 | { 20 | "name": "async", 21 | "value": false, 22 | "bind": {"input": "checkbox"} 23 | } 24 | ], 25 | 26 | "data": [ 27 | { 28 | "name": "table", 29 | "url": {"signal": "url"}, 30 | "async": {"signal": "async"} 31 | } 32 | ], 33 | 34 | "scales": [ 35 | { 36 | "name": "xscale", 37 | "type": "linear", 38 | "range": "width", 39 | "domain": [-0.7, 0.7] 40 | }, 41 | { 42 | "name": "yscale", 43 | "type": "linear", 44 | "range": "height", 45 | "domain": [-0.7, 0.7] 46 | } 47 | ], 48 | 49 | "axes": [ 50 | {"orient": "bottom", "scale": "xscale", "tickCount": 5, "zindex": 1}, 51 | {"orient": "left", "scale": "yscale", "tickCount": 5, "zindex": 1} 52 | ], 53 | 54 | "marks": [ 55 | { 56 | "type": "symbol", 57 | "from": {"data": "table"}, 58 | "encode": { 59 | "enter": { 60 | "x": {"scale": "xscale", "field": "u"}, 61 | "y": {"scale": "yscale", "field": "v"}, 62 | "fillOpacity": {"value": 0.8} 63 | }, 64 | "update": { 65 | "fill": {"value": "steelblue"} 66 | }, 67 | "hover": { 68 | "fill": {"value": "red"} 69 | } 70 | } 71 | } 72 | ] 73 | } 74 | -------------------------------------------------------------------------------- /test/applied_science/vega-specs/error.vg.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://vega.github.io/schema/vega/v5.json", 3 | "width": 400, 4 | "height": 100, 5 | "padding": 5, 6 | 7 | "data": [ 8 | { 9 | "name": "aggregate", 10 | "values": [ 11 | {"label": "Category A", "mean": 1, "lo": 0, "hi": 2}, 12 | {"label": "Category B", "mean": 2, "lo": 1.5, "hi": 2.5}, 13 | {"label": "Category C", "mean": 3, "lo": 1.7, "hi": 4.3}, 14 | {"label": "Category D", "mean": 4, "lo": 3, "hi": 5}, 15 | {"label": "Category E", "mean": 5, "lo": 4.1, "hi": 5.9} 16 | ] 17 | } 18 | ], 19 | 20 | "scales": [ 21 | { 22 | "name": "y", 23 | "type": "band", 24 | "range": "height", 25 | "domain": {"data": "aggregate", "field": "label"} 26 | }, 27 | { 28 | "name": "x", 29 | "type": "linear", 30 | "domain": {"data": "aggregate", "field": "hi"}, 31 | "range": [100, 400], 32 | "nice": true, "zero": true 33 | } 34 | ], 35 | 36 | "axes": [ 37 | {"orient": "bottom", "scale": "x", "tickCount": 6} 38 | ], 39 | 40 | "marks": [ 41 | { 42 | "type": "text", 43 | "from": {"data": "aggregate"}, 44 | "encode": { 45 | "enter": { 46 | "x": {"value": 0}, 47 | "y": {"scale": "y", "field": "label"}, 48 | "baseline": {"value": "middle"}, 49 | "fill": {"value": "#000"}, 50 | "text": {"field": "label"}, 51 | "font": {"value": "Helvetica Neue"}, 52 | "fontSize": {"value": 13} 53 | } 54 | } 55 | }, 56 | { 57 | "type": "rect", 58 | "from": {"data": "aggregate"}, 59 | "encode": { 60 | "enter": { 61 | "x": {"scale": "x", "field": "lo"}, 62 | "x2": {"scale": "x", "field": "hi"}, 63 | "y": {"scale": "y", "field": "label", "offset": -1}, 64 | "height": {"value": 1}, 65 | "fill": {"value": "#888"} 66 | } 67 | } 68 | }, 69 | { 70 | "type": "symbol", 71 | "from": {"data": "aggregate"}, 72 | "encode": { 73 | "enter": { 74 | "x": {"scale": "x", "field": "mean"}, 75 | "y": {"scale": "y", "field": "label"}, 76 | "size": {"value": 40}, 77 | "fill": {"value": "#000"} 78 | } 79 | } 80 | } 81 | ] 82 | } 83 | -------------------------------------------------------------------------------- /test/applied_science/vega-specs/flush-axis-labels.vg.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://vega.github.io/schema/vega/v5.json", 3 | "width": 300, 4 | "height": 200, 5 | "padding": 5, 6 | 7 | "signals": [ 8 | { 9 | "name": "labelFlush", "value": true, 10 | "bind": {"input": "select", "options": [true, false, null, 0, 1, 5]} 11 | }, 12 | { 13 | "name": "labelOverlap", "value": true, 14 | "bind": {"input": "select", "options": [true, false, "parity", "greedy"]} 15 | }, 16 | { 17 | "name": "labelSeparation", "value": 0, 18 | "bind": {"input": "range", "min": -10, "max": 30, "step": 1} 19 | }, 20 | { 21 | "name": "labelBound", "value": -1, 22 | "bind": {"input": "range", "min": -1, "max": 30, "step": 1} 23 | }, 24 | { 25 | "name": "labelFlushOffset", "value": 0, 26 | "bind": {"input": "range", "min": 0, "max": 10, "step": 1} 27 | }, 28 | { 29 | "name": "scalePadding", "value": 0, 30 | "bind": {"input": "range", "min": 0, "max": 10, "step": 1} 31 | } 32 | ], 33 | 34 | "scales": [ 35 | { 36 | "name": "forwardx", 37 | "domain": [0, 1000000], 38 | "padding": {"signal": "scalePadding"}, 39 | "range": "width" 40 | }, 41 | { 42 | "name": "backwardx", 43 | "domain": [0, 1000000], 44 | "padding": {"signal": "scalePadding"}, 45 | "range": "width", 46 | "reverse": true 47 | }, 48 | { 49 | "name": "forwardy", 50 | "domain": [0, 1000000], 51 | "padding": {"signal": "scalePadding"}, 52 | "range": "height" 53 | }, 54 | { 55 | "name": "backwardy", 56 | "domain": [0, 1000000], 57 | "padding": {"signal": "scalePadding"}, 58 | "range": "height", 59 | "reverse": true 60 | } 61 | ], 62 | 63 | "axes": [ 64 | { 65 | "orient": "top", 66 | "scale": "forwardx", 67 | "format": "s", 68 | "labelFlush": {"signal": "labelFlush"}, 69 | "labelFlushOffset": {"signal": "labelFlushOffset"}, 70 | "labelSeparation": {"signal": "labelSeparation"}, 71 | "labelOverlap": {"signal": "labelOverlap"}, 72 | "labelBound": {"signal": "labelBound"} 73 | }, 74 | { 75 | "orient": "bottom", 76 | "scale": "backwardx", 77 | "labelFlush": {"signal": "labelFlush"}, 78 | "labelFlushOffset": {"signal": "labelFlushOffset"}, 79 | "labelSeparation": {"signal": "labelSeparation"}, 80 | "labelOverlap": {"signal": "labelOverlap"}, 81 | "labelBound": {"signal": "labelBound"} 82 | }, 83 | { 84 | "orient": "left", 85 | "scale": "forwardy", 86 | "format": "s", 87 | "labelFlush": {"signal": "labelFlush"}, 88 | "labelFlushOffset": {"signal": "labelFlushOffset"}, 89 | "labelSeparation": {"signal": "labelSeparation"}, 90 | "labelOverlap": {"signal": "labelOverlap"}, 91 | "labelBound": {"signal": "labelBound"} 92 | }, 93 | { 94 | "orient": "right", 95 | "scale": "backwardy", 96 | "labelFlush": {"signal": "labelFlush"}, 97 | "labelFlushOffset": {"signal": "labelFlushOffset"}, 98 | "labelSeparation": {"signal": "labelSeparation"}, 99 | "labelOverlap": {"signal": "labelOverlap"}, 100 | "labelBound": {"signal": "labelBound"} 101 | } 102 | ] 103 | } -------------------------------------------------------------------------------- /test/applied_science/vega-specs/font-size-steps.vg.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://vega.github.io/schema/vega/v5.json", 3 | "width": 850, 4 | "height": 200, 5 | "padding": 5, 6 | "config": { 7 | "signals": [ 8 | {"name": "baseFontSize", "value": 14} 9 | ], 10 | "title": { 11 | "fontSize": {"signal": "baseFontSize + 2"} 12 | } 13 | }, 14 | "title": { 15 | "text": "Font Size Steps and Weber's Law?", 16 | "anchor": "start", 17 | "frame": "group", 18 | "orient": "top", 19 | "dy": 30 20 | }, 21 | "data": [ 22 | { 23 | "name": "sizes", 24 | "values": [ 25 | {"size": 10}, 26 | {"size": 11}, 27 | {"size": 12}, 28 | {"size": 14}, 29 | {"size": 16}, 30 | {"size": 18}, 31 | {"size": 21}, 32 | {"size": 24}, 33 | {"size": 36}, 34 | {"size": 48}, 35 | {"size": 60}, 36 | {"size": 72} 37 | ] 38 | } 39 | ], 40 | "scales": [ 41 | { 42 | "name": "x", 43 | "type": "point", 44 | "domain": {"data": "sizes", "field": "size"}, 45 | "range": "width" 46 | }, 47 | { 48 | "name": "y", 49 | "domain": [10, 72], 50 | "range": "height", 51 | "zero": false 52 | }, 53 | { 54 | "name": "logy", 55 | "type": "log", 56 | "domain": [10, 72], 57 | "range": "height" 58 | }, 59 | { 60 | "name": "dash", 61 | "type": "ordinal", 62 | "domain": ["log", "linear"], 63 | "range": [[3, 3], []] 64 | } 65 | ], 66 | "axes": [ 67 | { 68 | "orient": "left", 69 | "scale": "y", 70 | "offset": 5, 71 | "values": [10, 20, 30, 40, 50, 60, 72], 72 | "title": ["Font Size", "(Linear)"], 73 | "titlePadding": 8 74 | }, 75 | { 76 | "orient": "right", 77 | "scale": "logy", 78 | "offset": 5, 79 | "title": ["Font Size", "(Log-Transformed)"], 80 | "titlePadding": 8 81 | }, 82 | { 83 | "orient": "top", 84 | "scale": "x", 85 | "offset": 5, 86 | "labelFontSize": {"field": "value"}, 87 | "labelBaseline": "alphabetic", 88 | "labelPadding": 10 89 | } 90 | ], 91 | "legends": [ 92 | { 93 | "orient": "bottom-right", 94 | "offset": 5, 95 | "strokeDash": "dash", 96 | "symbolStrokeColor": "steelblue", 97 | "symbolType": "stroke", 98 | "symbolSize": 250 99 | } 100 | ], 101 | "marks": [ 102 | { 103 | "type": "line", 104 | "from": {"data": "sizes"}, 105 | "encode": { 106 | "update": { 107 | "x": {"scale": "x", "field": "size"}, 108 | "y": {"scale": "y", "field": "size"}, 109 | "stroke": {"value": "steelblue"}, 110 | "strokeDash": {"scale": "dash", "value": "linear"}, 111 | "strokeWidth": {"value": 2} 112 | } 113 | } 114 | }, 115 | { 116 | "type": "line", 117 | "from": {"data": "sizes"}, 118 | "encode": { 119 | "update": { 120 | "x": {"scale": "x", "field": "size"}, 121 | "y": {"scale": "logy", "field": "size"}, 122 | "stroke": {"value": "steelblue"}, 123 | "strokeDash": {"scale": "dash", "value": "log"}, 124 | "strokeWidth": {"value": 2} 125 | } 126 | } 127 | } 128 | ] 129 | } -------------------------------------------------------------------------------- /test/applied_science/vega-specs/force-beeswarm.vg.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://vega.github.io/schema/vega/v5.json", 3 | "width": 800, 4 | "height": 100, 5 | "padding": {"left": 5, "right": 5, "top": 0, "bottom": 20}, 6 | "autosize": "none", 7 | 8 | "signals": [ 9 | { "name": "cx", "update": "width / 2" }, 10 | { "name": "cy", "update": "height / 2" }, 11 | { "name": "radius", "value": 8, "bind": {"input": "range", "min": 2, "max": 15, "step": 1} }, 12 | { "name": "collide", "value": 1, "bind": {"input": "range", "min": 1, "max": 10, "step": 1} }, 13 | { "name": "gravityX", "value": 0.2, "bind": {"input": "range", "min": 0, "max": 1} }, 14 | { "name": "gravityY", "value": 0.1, "bind": {"input": "range", "min": 0, "max": 1} }, 15 | { "name": "static", "value": true, "bind": {"input": "checkbox"} } 16 | ], 17 | 18 | "data": [ 19 | { 20 | "name": "people", 21 | "url": "data/miserables.json", 22 | "format": {"type": "json", "property": "nodes"} 23 | } 24 | ], 25 | 26 | "scales": [ 27 | { 28 | "name": "xscale", 29 | "type": "band", 30 | "domain": { 31 | "data": "people", 32 | "field": "group", 33 | "sort": true 34 | }, 35 | "range": "width" 36 | }, 37 | { 38 | "name": "color", 39 | "type": "ordinal", 40 | "range": {"scheme": "category20c"} 41 | } 42 | ], 43 | 44 | "axes": [ 45 | { "orient": "bottom", "scale": "xscale" } 46 | ], 47 | 48 | "marks": [ 49 | { 50 | "name": "nodes", 51 | "type": "symbol", 52 | "from": {"data": "people"}, 53 | "encode": { 54 | "enter": { 55 | "fill": {"scale": "color", "field": "group"}, 56 | "xfocus": {"scale": "xscale", "field": "group", "band": 0.5}, 57 | "yfocus": {"signal": "cy"} 58 | }, 59 | "update": { 60 | "size": {"signal": "pow(2 * radius, 2)"}, 61 | "stroke": {"value": "white"}, 62 | "strokeWidth": {"value": 1}, 63 | "zindex": {"value": 0} 64 | }, 65 | "hover": { 66 | "stroke": {"value": "purple"}, 67 | "strokeWidth": {"value": 3}, 68 | "zindex": {"value": 1} 69 | } 70 | }, 71 | "transform": [ 72 | { 73 | "type": "force", 74 | "iterations": 300, 75 | "static": {"signal": "static"}, 76 | "forces": [ 77 | {"force": "collide", "iterations": {"signal": "collide"}, "radius": {"signal": "radius"}}, 78 | {"force": "x", "x": "xfocus", "strength": {"signal": "gravityX"}}, 79 | {"force": "y", "y": "yfocus", "strength": {"signal": "gravityY"}} 80 | ] 81 | } 82 | ] 83 | } 84 | ] 85 | } 86 | -------------------------------------------------------------------------------- /test/applied_science/vega-specs/force-network.vg.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://vega.github.io/schema/vega/v5.json", 3 | "width": 800, 4 | "height": 500, 5 | "padding": 0, 6 | "autosize": "none", 7 | 8 | "signals": [ 9 | { "name": "cx", "update": "width / 2" }, 10 | { "name": "cy", "update": "height / 2" }, 11 | { "name": "nodeRadius", "value": 8, 12 | "bind": {"input": "range", "min": 1, "max": 50, "step": 1} }, 13 | { "name": "nodeCharge", "value": -30, 14 | "bind": {"input": "range", "min":-100, "max": 10, "step": 1} }, 15 | { "name": "linkDistance", "value": 30, 16 | "bind": {"input": "range", "min": 5, "max": 100, "step": 1} }, 17 | { "name": "static", "value": true, 18 | "bind": {"input": "checkbox"} }, 19 | { 20 | "description": "State variable for active node fix status.", 21 | "name": "fix", "value": false, 22 | "on": [ 23 | { 24 | "events": "symbol:mouseout[!event.buttons], window:mouseup", 25 | "update": "false" 26 | }, 27 | { 28 | "events": "symbol:mouseover", 29 | "update": "fix || true" 30 | }, 31 | { 32 | "events": "[symbol:mousedown, window:mouseup] > window:mousemove!", 33 | "update": "xy()", 34 | "force": true 35 | } 36 | ] 37 | }, 38 | { 39 | "description": "Graph node most recently interacted with.", 40 | "name": "node", "value": null, 41 | "on": [ 42 | { 43 | "events": "symbol:mouseover", 44 | "update": "fix === true ? item() : node" 45 | } 46 | ] 47 | }, 48 | { 49 | "description": "Flag to restart Force simulation upon data changes.", 50 | "name": "restart", "value": false, 51 | "on": [ 52 | {"events": {"signal": "fix"}, "update": "fix && fix.length"} 53 | ] 54 | } 55 | ], 56 | 57 | "data": [ 58 | { 59 | "name": "node-data", 60 | "url": "data/miserables.json", 61 | "format": {"type": "json", "property": "nodes"} 62 | }, 63 | { 64 | "name": "link-data", 65 | "url": "data/miserables.json", 66 | "format": {"type": "json", "property": "links"} 67 | } 68 | ], 69 | 70 | "scales": [ 71 | { 72 | "name": "color", 73 | "type": "ordinal", 74 | "domain": {"data": "node-data", "field": "group"}, 75 | "range": {"scheme": "category20c"} 76 | } 77 | ], 78 | 79 | "marks": [ 80 | { 81 | "name": "nodes", 82 | "type": "symbol", 83 | "zindex": 1, 84 | 85 | "from": {"data": "node-data"}, 86 | "on": [ 87 | { 88 | "trigger": "fix", 89 | "modify": "node", 90 | "values": "fix === true ? {fx: node.x, fy: node.y} : {fx: fix[0], fy: fix[1]}" 91 | }, 92 | { 93 | "trigger": "!fix", 94 | "modify": "node", "values": "{fx: null, fy: null}" 95 | } 96 | ], 97 | 98 | "encode": { 99 | "enter": { 100 | "fill": {"scale": "color", "field": "group"}, 101 | "stroke": {"value": "white"} 102 | }, 103 | "update": { 104 | "size": {"signal": "2 * nodeRadius * nodeRadius"}, 105 | "cursor": {"value": "pointer"} 106 | } 107 | }, 108 | 109 | "transform": [ 110 | { 111 | "type": "force", 112 | "iterations": 300, 113 | "restart": {"signal": "restart"}, 114 | "static": {"signal": "static"}, 115 | "signal": "force", 116 | "forces": [ 117 | {"force": "center", "x": {"signal": "cx"}, "y": {"signal": "cy"}}, 118 | {"force": "collide", "radius": {"signal": "nodeRadius"}}, 119 | {"force": "nbody", "strength": {"signal": "nodeCharge"}}, 120 | {"force": "link", "links": "link-data", "distance": {"signal": "linkDistance"}} 121 | ] 122 | } 123 | ] 124 | }, 125 | { 126 | "type": "path", 127 | "from": {"data": "link-data"}, 128 | "interactive": false, 129 | "encode": { 130 | "update": { 131 | "stroke": {"value": "#ccc"}, 132 | "strokeWidth": {"value": 0.5} 133 | } 134 | }, 135 | "transform": [ 136 | { 137 | "type": "linkpath", 138 | "require": {"signal": "force"}, 139 | "shape": "line", 140 | "sourceX": "datum.source.x", "sourceY": "datum.source.y", 141 | "targetX": "datum.target.x", "targetY": "datum.target.y" 142 | } 143 | ] 144 | } 145 | ] 146 | } 147 | -------------------------------------------------------------------------------- /test/applied_science/vega-specs/gapminder.vg.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://vega.github.io/schema/vega/v5.json", 3 | "width": 800, 4 | "height": 600, 5 | "padding": 5, 6 | 7 | "signals": [ 8 | { 9 | "name": "animate", "value": false, 10 | "bind": {"input": "checkbox"} 11 | }, 12 | { 13 | "name": "interval", "value": 1000, 14 | "bind": {"input": "select", "options": [500, 1000, 2000]} 15 | }, 16 | { 17 | "name": "count", "value": 0, 18 | "on": [ 19 | { 20 | "events": "timer{500}", 21 | "update": "(count + 500) % 10000" 22 | } 23 | ] 24 | }, 25 | { 26 | "name": "step", 27 | "update": "~~(count / interval)" 28 | }, 29 | { 30 | "name": "regions", 31 | "value": { 32 | "0": "South Asia", 33 | "1": "Europe & Central Asia", 34 | "2": "Sub-Saharan Africa", 35 | "3": "America", 36 | "4": "East Asia & Pacific", 37 | "5": "Middle East & North Africa" 38 | } 39 | }, 40 | { 41 | "name": "minYear", 42 | "update": "extentYear[0]" 43 | }, 44 | { 45 | "name": "maxYear", 46 | "update": "extentYear[1]" 47 | }, 48 | { 49 | "name": "year", "value": 1955, 50 | "bind": {"input": "range", "min": 1955, "max": 2000, "step": 5}, 51 | "on": [ 52 | { 53 | "events": {"signal": "~~(count / interval)"}, 54 | "update": "animate && year < maxYear ? year + 5 : year" 55 | } 56 | ] 57 | } 58 | ], 59 | 60 | "title": { 61 | "text": {"signal": "'World Development Trends in ' + year"}, 62 | "anchor": "start", "frame": "group", 63 | "fontSize": 18 64 | }, 65 | 66 | "data": [ 67 | { 68 | "name": "gapminder", 69 | "url": "data/gapminder.json", 70 | "transform": [ 71 | { "type": "extent", "field": "year", "signal": "extentYear" }, 72 | { "type": "formula", "as": "region", "expr": "regions[datum.cluster]" } 73 | ] 74 | }, 75 | { 76 | "name": "filtered", 77 | "source": "gapminder", 78 | "transform": [ 79 | { "type": "filter", "expr": "datum.year === year" } 80 | ] 81 | } 82 | ], 83 | 84 | "axes": [ 85 | { 86 | "orient": "left", 87 | "scale": "y", 88 | "title": "Life Expentancy (Years)", 89 | "titleColor": "#444", 90 | "titleAlign": "right", 91 | "titleAnchor": "end", 92 | "titleBaseline": "top", 93 | "titleX": 5 94 | }, 95 | { 96 | "orient": "bottom", 97 | "scale": "x", 98 | "title": "Fertility (# Children)", 99 | "titleColor": "#444", 100 | "titleAlign": "right", 101 | "titleAnchor": "end", 102 | "titleBaseline": "bottom", 103 | "titleY": -5 104 | } 105 | ], 106 | 107 | "legends": [ 108 | { 109 | "orient": "bottom-left", 110 | "fill": "color", 111 | "title": "Region", 112 | "offset": 10 113 | } 114 | ], 115 | 116 | "scales": [ 117 | { 118 | "name": "x", 119 | "type": "linear", "nice": true, 120 | "domain": {"data": "gapminder", "field": "fertility"}, 121 | "range": "width" 122 | }, 123 | { 124 | "name": "y", 125 | "type": "linear", "nice": true, "zero": false, 126 | "domain": {"data": "gapminder", "field": "life_expect"}, 127 | "range": "height" 128 | }, 129 | { 130 | "name": "color", 131 | "type": "ordinal", 132 | "domain": {"data": "gapminder", "field": "region"}, 133 | "range": "category" 134 | }, 135 | { 136 | "name": "size", 137 | "domain": {"data": "gapminder", "field": "pop"}, 138 | "range": [100, 5000] 139 | } 140 | ], 141 | 142 | "marks": [ 143 | { 144 | "type": "symbol", 145 | "from": {"data": "filtered"}, 146 | "sort": {"field": "size", "order": "descending"}, 147 | "encode": { 148 | "enter": { 149 | "fill": {"scale": "color", "field": "region"}, 150 | "stroke": {"value": "#fff"}, 151 | "strokeWidth": {"value": 0.5} 152 | }, 153 | "update": { 154 | "x": {"scale": "x", "field": "fertility"}, 155 | "y": {"scale": "y", "field": "life_expect"}, 156 | "size": {"scale": "size", "field": "pop"} 157 | } 158 | } 159 | } 160 | ] 161 | } 162 | -------------------------------------------------------------------------------- /test/applied_science/vega-specs/gradient.vg.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://vega.github.io/schema/vega/v5.json", 3 | "width": 300, 4 | "padding": 5, 5 | 6 | "scales": [ 7 | { 8 | "name": "color", 9 | "type": "linear", 10 | "range": {"scheme": "viridis"}, 11 | "domain": [0, 100] 12 | } 13 | ], 14 | 15 | "marks": [ 16 | { 17 | "type": "rect", 18 | "encode": { 19 | "update": { 20 | "width": {"signal": "width"}, 21 | "height": {"value": 15}, 22 | "fill": {"gradient": "color"} 23 | } 24 | } 25 | }, 26 | { 27 | "type": "rect", 28 | "encode": { 29 | "update": { 30 | "y": {"value": 20}, 31 | "width": {"signal": "width"}, 32 | "height": {"value": 15}, 33 | "fill": { 34 | "value": { 35 | "gradient": "linear", 36 | "stops": [ 37 | {"offset": 0.0, "color": "red"}, 38 | {"offset": 0.5, "color": "white"}, 39 | {"offset": 1.0, "color": "blue"} 40 | ] 41 | } 42 | } 43 | } 44 | } 45 | }, 46 | { 47 | "type": "symbol", 48 | "encode": { 49 | "update": { 50 | "x": {"value": 25}, 51 | "y": {"value": 62}, 52 | "size": {"value": 1900}, 53 | "fill": { 54 | "value": { 55 | "gradient": "radial", 56 | "stops": [ 57 | {"offset": 0.0, "color": "red"}, 58 | {"offset": 0.5, "color": "white"}, 59 | {"offset": 1.0, "color": "blue"} 60 | ] 61 | } 62 | } 63 | } 64 | } 65 | }, 66 | { 67 | "type": "rect", 68 | "encode": { 69 | "update": { 70 | "x": {"value": 100}, 71 | "y": {"value": 40}, 72 | "width": {"value": 200}, 73 | "height": {"value": 45}, 74 | "fill": { 75 | "value": { 76 | "gradient": "radial", 77 | "stops": [ 78 | {"offset": 0.0, "color": "red"}, 79 | {"offset": 0.5, "color": "white"}, 80 | {"offset": 1.0, "color": "blue"} 81 | ] 82 | } 83 | } 84 | } 85 | } 86 | } 87 | ] 88 | } 89 | -------------------------------------------------------------------------------- /test/applied_science/vega-specs/grouped-bar.vg.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://vega.github.io/schema/vega/v5.json", 3 | "width": 300, 4 | "height": 240, 5 | 6 | "data": [ 7 | { 8 | "name": "table", 9 | "values": [ 10 | {"category":"A", "position":0, "value":0.1}, 11 | {"category":"A", "position":1, "value":0.6}, 12 | {"category":"A", "position":2, "value":0.9}, 13 | {"category":"A", "position":3, "value":0.4}, 14 | {"category":"B", "position":0, "value":0.7}, 15 | {"category":"B", "position":1, "value":0.2}, 16 | {"category":"B", "position":2, "value":1.1}, 17 | {"category":"B", "position":3, "value":0.8}, 18 | {"category":"C", "position":0, "value":0.6}, 19 | {"category":"C", "position":1, "value":0.1}, 20 | {"category":"C", "position":2, "value":0.2}, 21 | {"category":"C", "position":3, "value":0.7} 22 | ] 23 | } 24 | ], 25 | 26 | "scales": [ 27 | { 28 | "name": "yscale", 29 | "type": "band", 30 | "domain": {"data": "table", "field": "category"}, 31 | "range": "height", 32 | "padding": 0.2 33 | }, 34 | { 35 | "name": "xscale", 36 | "type": "linear", 37 | "domain": {"data": "table", "field": "value"}, 38 | "range": "width", 39 | "round": true, 40 | "zero": true, 41 | "nice": true 42 | }, 43 | { 44 | "name": "color", 45 | "type": "ordinal", 46 | "domain": {"data": "table", "field": "position"}, 47 | "range": {"scheme": "category20"} 48 | } 49 | ], 50 | 51 | "axes": [ 52 | {"orient": "left", "scale": "yscale", "ticks": false, "labelPadding": 4, "zindex": 1}, 53 | {"orient": "bottom", "scale": "xscale"} 54 | ], 55 | 56 | "marks": [ 57 | { 58 | "type": "group", 59 | 60 | "from": { 61 | "facet": { 62 | "data": "table", 63 | "name": "facet", 64 | "groupby": "category" 65 | } 66 | }, 67 | 68 | "encode": { 69 | "enter": { 70 | "y": {"scale": "yscale", "field": "category"} 71 | } 72 | }, 73 | 74 | "signals": [ 75 | {"name": "height", "update": "bandwidth('yscale')"} 76 | ], 77 | 78 | "scales": [ 79 | { 80 | "name": "pos", 81 | "type": "band", 82 | "range": "height", 83 | "domain": {"data": "facet", "field": "position"} 84 | } 85 | ], 86 | 87 | "marks": [ 88 | { 89 | "name": "bars", 90 | "from": {"data": "facet"}, 91 | "type": "rect", 92 | "encode": { 93 | "enter": { 94 | "y": {"scale": "pos", "field": "position"}, 95 | "height": {"scale": "pos", "band": 1}, 96 | "x": {"scale": "xscale", "field": "value"}, 97 | "x2": {"scale": "xscale", "value": 0}, 98 | "fill": {"scale": "color", "field": "position"} 99 | } 100 | } 101 | }, 102 | { 103 | "type": "text", 104 | "from": {"data": "bars"}, 105 | "encode": { 106 | "enter": { 107 | "x": {"field": "x2", "offset": -5}, 108 | "y": {"field": "y", "offset": {"field": "height", "mult": 0.5}}, 109 | "fill": [ 110 | {"test": "contrast('white', datum.fill) > contrast('black', datum.fill)", "value": "white"}, 111 | {"value": "black"} 112 | ], 113 | "align": {"value": "right"}, 114 | "baseline": {"value": "middle"}, 115 | "text": {"field": "datum.value"} 116 | } 117 | } 118 | } 119 | ] 120 | } 121 | ] 122 | } 123 | -------------------------------------------------------------------------------- /test/applied_science/vega-specs/heatmap-lines.vg.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://vega.github.io/schema/vega/v5.json", 3 | "width": 800, 4 | "padding": 5, 5 | 6 | "config": { 7 | "title": {"fontSize": 14} 8 | }, 9 | 10 | "title": { 11 | "text": "Seattle Annual Temperatures", 12 | "anchor": "start", "offset": 4 13 | }, 14 | 15 | "signals": [ 16 | {"name": "rangeStep", "value": 25}, 17 | {"name": "height", "update": "rangeStep * 24"} 18 | ], 19 | 20 | "data": [ 21 | { 22 | "name": "temperature", 23 | "url": "data/seattle-temps.csv", 24 | "format": {"type": "csv", "parse": {"temp": "number", "date": "date"}}, 25 | "transform": [ 26 | {"type": "formula", "as": "hour", "expr": "hours(datum.date)"}, 27 | { "type": "formula", "as": "date", 28 | "expr": "datetime(year(datum.date), month(datum.date), date(datum.date))"} 29 | ] 30 | } 31 | ], 32 | 33 | "scales": [ 34 | { 35 | "name": "row", 36 | "type": "band", 37 | "domain": [ 38 | 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 39 | 0, 1, 2, 3, 4, 5 40 | ], 41 | "range": {"step": {"signal": "rangeStep"}} 42 | }, 43 | { 44 | "name": "x", 45 | "type": "time", 46 | "domain": {"data": "temperature", "field": "date"}, 47 | "range": "width" 48 | }, 49 | { 50 | "name": "y", 51 | "type": "linear", "zero": false, 52 | "domain": {"data": "temperature", "field": "temp"}, 53 | "range": [{"signal": "rangeStep"}, 1] 54 | } 55 | ], 56 | 57 | "axes": [ 58 | {"orient": "bottom", "scale": "x", "domain": false, "title": "Month", "format": "%b"}, 59 | { 60 | "orient": "left", "scale": "row", "domain": false, "title": "Hour", 61 | "ticks": false, 62 | "encode": { 63 | "labels": { 64 | "update": { 65 | "text": {"signal": "datum.value === 0 ? 'Midnight' : datum.value === 12 ? 'Noon' : datum.value < 12 ? datum.value + ':00 am' : (datum.value - 12) + ':00 pm'"} 66 | } 67 | } 68 | } 69 | } 70 | ], 71 | 72 | "marks": [ 73 | { 74 | "type": "group", 75 | "from": { 76 | "facet": { 77 | "name": "hour", 78 | "data": "temperature", 79 | "groupby": "hour" 80 | } 81 | }, 82 | "encode": { 83 | "enter": { 84 | "x": {"value": 0}, 85 | "y": {"scale": "row", "field": "hour"}, 86 | "width": {"signal": "width"}, 87 | "height": {"signal": "rangeStep"} 88 | } 89 | }, 90 | "marks": [ 91 | { 92 | "type": "area", 93 | "from": {"data": "hour"}, 94 | "encode": { 95 | "enter": { 96 | "x": {"scale": "x", "field": "date"}, 97 | "y": {"scale": "y", "field": "temp"}, 98 | "y2": {"signal": "rangeStep"} 99 | } 100 | } 101 | } 102 | ] 103 | } 104 | ] 105 | } 106 | -------------------------------------------------------------------------------- /test/applied_science/vega-specs/heatmap-sinusoids.vg.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://vega.github.io/schema/vega/v5.json", 3 | "width": 750, 4 | "height": 500, 5 | "padding": 0, 6 | "autosize": "none", 7 | 8 | "signals": [ 9 | { 10 | "name": "scale", "value": 0.05, 11 | "bind": {"input": "range", "min": 0.005, "max": 0.1, "step": 0.001} 12 | }, 13 | { 14 | "name": "offset", "value": 0, 15 | "bind": {"input": "range", "min": 0, "max": 10, "step": 0.1} 16 | }, 17 | { 18 | "name": "smooth", "value": true, "bind": {"input": "checkbox"} 19 | } 20 | ], 21 | 22 | "data": [ 23 | { 24 | "name": "source", 25 | "values": [{"width": 150, "height": 100}] 26 | } 27 | ], 28 | 29 | "scales": [ 30 | { 31 | "name": "color", 32 | "type": "linear", 33 | "zero": true, 34 | "domain": [-1, 1], 35 | "range": {"scheme": "spectral"} 36 | } 37 | ], 38 | 39 | "marks": [ 40 | { 41 | "type": "image", 42 | "from": {"data": "source"}, 43 | "encode": { 44 | "update": { 45 | "x": {"value": 0}, 46 | "y": {"value": 0}, 47 | "width": {"signal": "width"}, 48 | "height": {"signal": "height"}, 49 | "aspect": {"value": false}, 50 | "smooth": {"signal": "smooth"} 51 | } 52 | }, 53 | "transform": [ 54 | { 55 | "type": "heatmap", 56 | "field": "datum", 57 | "color": {"expr": "scale('color', sin(offset + scale * (datum.$x + datum.$y)) * sin(scale * (datum.$x - datum.$y)))"}, 58 | "opacity": 1 59 | } 60 | ] 61 | } 62 | ] 63 | } 64 | -------------------------------------------------------------------------------- /test/applied_science/vega-specs/histogram.vg.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://vega.github.io/schema/vega/v5.json", 3 | "width": 500, 4 | "height": 100, 5 | "padding": 5, 6 | 7 | "signals": [ 8 | { "name": "binOffset", "value": 0, 9 | "bind": {"input": "range", "min": -0.1, "max": 0.1} }, 10 | { "name": "binStep", "value": 0.1, 11 | "bind": {"input": "range", "min": 0.001, "max": 0.4, "step": 0.001} } 12 | ], 13 | 14 | "data": [ 15 | { 16 | "name": "points", 17 | "url": "data/normal-2d.json" 18 | }, 19 | { 20 | "name": "binned", 21 | "source": "points", 22 | "transform": [ 23 | { 24 | "type": "bin", "field": "u", 25 | "extent": [-1, 1], 26 | "anchor": {"signal": "binOffset"}, 27 | "step": {"signal": "binStep"}, 28 | "nice": false 29 | }, 30 | { 31 | "type": "aggregate", 32 | "key": "bin0", "groupby": ["bin0", "bin1"], 33 | "fields": ["bin0"], "ops": ["count"], "as": ["count"] 34 | } 35 | ] 36 | } 37 | ], 38 | 39 | "scales": [ 40 | { 41 | "name": "xscale", 42 | "type": "linear", 43 | "range": "width", 44 | "domain": [-1, 1] 45 | }, 46 | { 47 | "name": "yscale", 48 | "type": "linear", 49 | "range": "height", "round": true, 50 | "domain": {"data": "binned", "field": "count"}, 51 | "zero": true, "nice": true 52 | } 53 | ], 54 | 55 | "axes": [ 56 | {"orient": "bottom", "scale": "xscale", "zindex": 1}, 57 | {"orient": "left", "scale": "yscale", "tickCount": 5, "zindex": 1} 58 | ], 59 | 60 | "marks": [ 61 | { 62 | "type": "rect", 63 | "from": {"data": "binned"}, 64 | "encode": { 65 | "update": { 66 | "x": {"scale": "xscale", "field": "bin0"}, 67 | "x2": {"scale": "xscale", "field": "bin1", 68 | "offset": {"signal": "binStep > 0.02 ? -0.5 : 0"}}, 69 | "y": {"scale": "yscale", "field": "count"}, 70 | "y2": {"scale": "yscale", "value": 0}, 71 | "fill": {"value": "steelblue"} 72 | }, 73 | "hover": { "fill": {"value": "firebrick"} } 74 | } 75 | }, 76 | { 77 | "type": "rect", 78 | "from": {"data": "points"}, 79 | "encode": { 80 | "enter": { 81 | "x": {"scale": "xscale", "field": "u"}, 82 | "width": {"value": 1}, 83 | "y": {"value": 25, "offset": {"signal": "height"}}, 84 | "height": {"value": 5}, 85 | "fill": {"value": "steelblue"}, 86 | "fillOpacity": {"value": 0.4} 87 | } 88 | } 89 | } 90 | ] 91 | } 92 | -------------------------------------------------------------------------------- /test/applied_science/vega-specs/hops.vg.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://vega.github.io/schema/vega/v5.json", 3 | "width": 300, 4 | "height": 300, 5 | "padding": 5, 6 | "autosize": "pad", 7 | 8 | "signals": [ 9 | { 10 | "name": "count", 11 | "value": 0, 12 | "on": [ 13 | { 14 | "events": {"type": "timer", "throttle": 500}, 15 | "update": "(count + 1) % 10" 16 | } 17 | ] 18 | } 19 | ], 20 | 21 | "data": [ 22 | { 23 | "name": "points", 24 | "url": "data/normal-2d.json" 25 | }, 26 | { 27 | "name": "source", 28 | "source": "points", 29 | "transform": [ 30 | {"type": "filter", "expr": "(count + 1) && random() < 0.1"} 31 | ] 32 | }, 33 | { 34 | "name": "summary", 35 | "source": "source", 36 | "transform": [ 37 | { 38 | "type": "aggregate", 39 | "fields": ["v", "v", "u", "u"], 40 | "ops": ["mean", "stderr", "mean", "stderr"], 41 | "as": ["vm", "ve", "um", "ue"] 42 | } 43 | ] 44 | } 45 | ], 46 | 47 | "scales": [ 48 | { 49 | "name": "x", 50 | "type": "linear", 51 | "nice": true, 52 | "domain": {"data": "points", "fields": ["u", "v"]}, 53 | "range": "width" 54 | }, 55 | { 56 | "name": "y", 57 | "type": "linear", 58 | "nice": true, 59 | "domain": {"data": "points", "fields": ["u", "v"]}, 60 | "range": "height" 61 | } 62 | ], 63 | 64 | "axes": [ 65 | { "scale": "x", "orient": "bottom" }, 66 | { "scale": "y", "orient": "left" } 67 | ], 68 | 69 | "marks": [ 70 | { 71 | "type": "rect", 72 | "from": {"data": "summary"}, 73 | "encode": { 74 | "enter": { 75 | "fill": {"value": "#aaa"}, 76 | "fillOpacity": {"value": 0.2} 77 | }, 78 | "update": { 79 | "x": {"value": 0}, 80 | "x2": {"signal": "width"}, 81 | "y": {"signal": "scale('y', datum.vm - 1.96*datum.ve)"}, 82 | "y2": {"signal": "scale('y', datum.vm + 1.96*datum.ve)"} 83 | } 84 | } 85 | }, 86 | { 87 | "type": "rect", 88 | "from": {"data": "summary"}, 89 | "encode": { 90 | "enter": { 91 | "fill": {"value": "#aaa"}, 92 | "fillOpacity": {"value": 0.2} 93 | }, 94 | "update": { 95 | "y": {"value": 0}, 96 | "y2": {"signal": "height"}, 97 | "x": {"signal": "scale('x', datum.um - 1.96*datum.ue)"}, 98 | "x2": {"signal": "scale('x', datum.um + 1.96*datum.ue)"} 99 | } 100 | } 101 | }, 102 | { 103 | "type": "symbol", 104 | "from": {"data": "source"}, 105 | "encode": { 106 | "enter": { 107 | "size": {"value": 25} 108 | }, 109 | "update": { 110 | "x": {"scale": "x", "field": "u"}, 111 | "y": {"scale": "y", "field": "v"} 112 | } 113 | } 114 | }, 115 | { 116 | "type": "rule", 117 | "from": {"data": "summary"}, 118 | "encode": { 119 | "enter": { 120 | "stroke": {"value": "firebrick"}, 121 | "strokeWidth": {"value": 1.5} 122 | }, 123 | "update": { 124 | "x": {"value": 0}, 125 | "x2": {"signal": "width"}, 126 | "y": {"scale": "y", "field": "vm"} 127 | } 128 | } 129 | }, 130 | { 131 | "type": "rule", 132 | "from": {"data": "summary"}, 133 | "encode": { 134 | "enter": { 135 | "stroke": {"value": "firebrick"}, 136 | "strokeWidth": {"value": 1.5} 137 | }, 138 | "update": { 139 | "y": {"value": 0}, 140 | "y2": {"signal": "height"}, 141 | "x": {"scale": "x", "field": "um"} 142 | } 143 | } 144 | } 145 | ] 146 | } 147 | -------------------------------------------------------------------------------- /test/applied_science/vega-specs/horizon.vg.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://vega.github.io/schema/vega/v5.json", 3 | "width": 500, 4 | "height": 50, 5 | 6 | "signals": [ 7 | { 8 | "name": "layers", 9 | "value": 2, 10 | "on": [{"events": "mousedown!", "update": "1 + (layers % 4)"}] 11 | }, 12 | { 13 | "name": "vheight", 14 | "update": "height * layers" 15 | }, 16 | { 17 | "name": "opacity", 18 | "update": "pow(layers, -2/3)" 19 | } 20 | ], 21 | 22 | "data": [ 23 | { 24 | "name": "layer_indices", 25 | "values": [0, 1, 2, 3], 26 | "transform": [ 27 | {"type": "filter", "expr": "datum.data < layers"}, 28 | {"type": "formula", "expr": "datum.data * -height", "as": "offset"} 29 | ] 30 | }, 31 | { 32 | "name": "table", 33 | "values": [ 34 | {"x": 1, "y": 28}, {"x": 2, "y": 55}, 35 | {"x": 3, "y": 43}, {"x": 4, "y": 91}, 36 | {"x": 5, "y": 81}, {"x": 6, "y": 53}, 37 | {"x": 7, "y": 19}, {"x": 8, "y": 87}, 38 | {"x": 9, "y": 52}, {"x": 10, "y": 48}, 39 | {"x": 11, "y": 24}, {"x": 12, "y": 49}, 40 | {"x": 13, "y": 87}, {"x": 14, "y": 66}, 41 | {"x": 15, "y": 17}, {"x": 16, "y": 27}, 42 | {"x": 17, "y": 68}, {"x": 18, "y": 16}, 43 | {"x": 19, "y": 49}, {"x": 20, "y": 15} 44 | ] 45 | } 46 | ], 47 | 48 | "scales": [ 49 | { 50 | "name": "x", 51 | "type": "linear", 52 | "range": "width", 53 | "zero": false, "round": true, 54 | "domain": {"data": "table", "field": "x"} 55 | }, 56 | { 57 | "name": "y", 58 | "type": "linear", 59 | "range": [{"signal":"vheight"}, 0], 60 | "nice": true, "zero": true, 61 | "domain": {"data": "table", "field": "y"} 62 | } 63 | ], 64 | 65 | "axes": [ 66 | {"orient": "bottom", "scale": "x", "tickCount": 20, "zindex": 1} 67 | ], 68 | 69 | "marks": [ 70 | { 71 | "type": "group", 72 | "encode": { 73 | "update": { 74 | "width": {"field": {"group": "width"}}, 75 | "height": {"field": {"group": "height"}}, 76 | "clip": {"value": true} 77 | } 78 | }, 79 | "marks": [ 80 | { 81 | "type": "group", 82 | "from": {"data": "layer_indices"}, 83 | "encode": { 84 | "update": { 85 | "y": {"field": "offset"} 86 | } 87 | }, 88 | "marks": [ 89 | { 90 | "type": "area", 91 | "from": {"data": "table"}, 92 | "encode": { 93 | "enter": { 94 | "interpolate": {"value": "monotone"}, 95 | "x": {"scale": "x", "field": "x"}, 96 | "fill": {"value": "steelblue"} 97 | }, 98 | "update": { 99 | "y": {"scale": "y", "field": "y"}, 100 | "y2": {"scale": "y", "value": 0}, 101 | "fillOpacity": {"signal": "opacity"} 102 | } 103 | } 104 | } 105 | ] 106 | } 107 | ] 108 | } 109 | ] 110 | } 111 | -------------------------------------------------------------------------------- /test/applied_science/vega-specs/images-inline.vg.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://vega.github.io/schema/vega/v5.json", 3 | "description": "Test using inline base64-encoded image data.", 4 | "background": "white", 5 | "padding": 5, 6 | "width": 100, 7 | "height": 100, 8 | "marks": [ 9 | { 10 | "type": "image", 11 | "encode": { 12 | "update": { 13 | "x": {"value": 0}, 14 | "width": {"signal": "width"}, 15 | "y": {"value": 0}, 16 | "height": {"signal": "height"}, 17 | "url": { 18 | "value": "data:image/png;base64,iVBORw0KGgoAAA%20ANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4%20//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU%205ErkJggg==" 19 | } 20 | } 21 | } 22 | } 23 | ] 24 | } -------------------------------------------------------------------------------- /test/applied_science/vega-specs/images.vg.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://vega.github.io/schema/vega/v5.json", 3 | "width": 200, 4 | "height": 200, 5 | "padding": 5, 6 | 7 | "data": [ 8 | { 9 | "name": "data", 10 | "values": [ 11 | {"x": 0.5, "y": 0.5, "img": "data/ffox.png"}, 12 | {"x": 0.5, "y": 1.5, "img": "data/gimp.png"}, 13 | {"x": 0.5, "y": 2.5, "img": "data/7zip.png"} 14 | ] 15 | } 16 | ], 17 | 18 | "scales": [ 19 | { 20 | "name": "x", 21 | "type": "linear", 22 | "domain": [0, 4], 23 | "range": "width" 24 | }, 25 | { 26 | "name": "y", 27 | "type": "linear", 28 | "domain": [0, 3], 29 | "range": "height" 30 | } 31 | ], 32 | 33 | "axes": [ 34 | {"orient": "bottom", "scale": "x", "tickCount": 5}, 35 | {"orient": "left", "scale": "y", "tickCount": 5} 36 | ], 37 | 38 | "marks": [ 39 | { 40 | "type": "image", 41 | "from": {"data": "data"}, 42 | "encode": { 43 | "enter": { 44 | "url": {"field": "img"}, 45 | "width": {"value": 50}, 46 | "height": {"value": 50}, 47 | "x": {"scale": "x", "field": "x"}, 48 | "y": {"scale": "y", "field": "y"}, 49 | "align": {"value": "center"}, 50 | "baseline": {"value": "middle"} 51 | }, 52 | "update": { 53 | "opacity": {"value": 1.0} 54 | }, 55 | "hover": { 56 | "opacity": {"value": 0.5} 57 | } 58 | } 59 | }, 60 | { 61 | "type": "image", 62 | "from": {"data": "data"}, 63 | "encode": { 64 | "enter": { 65 | "url": {"field": "img"}, 66 | "width": {"value": 25}, 67 | "height": {"value": 50}, 68 | "aspect": {"value": false}, 69 | "x": {"scale": "x", "signal": "datum.x + 1"}, 70 | "y": {"scale": "y", "field": "y"}, 71 | "align": {"value": "center"}, 72 | "baseline": {"value": "middle"} 73 | }, 74 | "update": { 75 | "opacity": {"value": 1.0} 76 | }, 77 | "hover": { 78 | "opacity": {"value": 0.5} 79 | } 80 | } 81 | }, 82 | { 83 | "type": "image", 84 | "from": {"data": "data"}, 85 | "encode": { 86 | "enter": { 87 | "url": {"field": "img"}, 88 | "width": {"value": 50}, 89 | "height": {"value": 30}, 90 | "aspect": {"value": true}, 91 | "x": {"scale": "x", "signal": "datum.x + 2"}, 92 | "y": {"scale": "y", "field": "y"}, 93 | "align": {"value": "center"}, 94 | "baseline": {"value": "middle"} 95 | }, 96 | "update": { 97 | "opacity": {"value": 1.0} 98 | }, 99 | "hover": { 100 | "opacity": {"value": 0.5} 101 | } 102 | } 103 | }, 104 | { 105 | "type": "image", 106 | "from": {"data": "data"}, 107 | "encode": { 108 | "enter": { 109 | "url": {"field": "img"}, 110 | "width": {"value": 25}, 111 | "x": {"scale": "x", "signal": "datum.x + 3"}, 112 | "y": {"scale": "y", "field": "y"}, 113 | "align": {"value": "center"}, 114 | "baseline": {"value": "middle"} 115 | }, 116 | "update": { 117 | "opacity": {"value": 1.0} 118 | }, 119 | "hover": { 120 | "opacity": {"value": 0.5} 121 | } 122 | } 123 | } 124 | ] 125 | } 126 | -------------------------------------------------------------------------------- /test/applied_science/vega-specs/isocontour-airports.vg.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://vega.github.io/schema/vega/v5.json", 3 | "width": 900, 4 | "height": 560, 5 | "padding": 0, 6 | "autosize": "none", 7 | 8 | "signals": [ 9 | { 10 | "name": "bandwidth", "value": 20, 11 | "bind": {"input": "range", "min": -1, "max": 100, "step": 1} 12 | }, 13 | { 14 | "name": "cellSize", "value": 4, 15 | "bind": {"input": "select", "options": [1, 2, 4, 8, 16, 32]} 16 | }, 17 | { 18 | "name": "levels", "value": 10, 19 | "bind": {"input": "select", "options": [1, 5, 10, 20]} 20 | } 21 | ], 22 | 23 | "title": { 24 | "text": "Density of U.S. Airports, 2008", 25 | "offset": -20 26 | }, 27 | 28 | "data": [ 29 | { 30 | "name": "states", 31 | "url": "data/us-10m.json", 32 | "format": {"type": "topojson", "feature": "states"}, 33 | "transform": [ 34 | { 35 | "type": "geopath", 36 | "projection": "projection" 37 | } 38 | ] 39 | }, 40 | { 41 | "name": "airports", 42 | "url": "data/airports.csv", 43 | "format": {"type": "csv","parse": "auto" 44 | }, 45 | "transform": [ 46 | { 47 | "type": "geopoint", 48 | "projection": "projection", 49 | "fields": ["longitude", "latitude"] 50 | }, 51 | { 52 | "type": "filter", 53 | "expr": "datum.x != null && datum.y != null" 54 | } 55 | ] 56 | }, 57 | { 58 | "name": "contours", 59 | "source": "airports", 60 | "transform": [ 61 | { 62 | "type": "kde2d", 63 | "x": "x", 64 | "y": "y", 65 | "size": [{"signal": "width"}, {"signal": "height"}], 66 | "bandwidth": {"signal": "[bandwidth, bandwidth]"}, 67 | "cellSize": {"signal": "cellSize"} 68 | }, 69 | { 70 | "type": "isocontour", 71 | "field": "grid", 72 | "levels": {"signal": "levels"}, 73 | "as": null 74 | } 75 | ] 76 | } 77 | ], 78 | 79 | "projections": [ 80 | { 81 | "name": "projection", 82 | "type": "albers", 83 | "scale": 1150, 84 | "translate": [{"signal": "width / 2"}, {"signal": "height / 2"}] 85 | } 86 | ], 87 | 88 | "scales": [ 89 | { 90 | "name": "color", 91 | "type": "linear", 92 | "domain": {"data": "contours", "field": "value"}, 93 | "range": {"scheme": "viridis"} 94 | } 95 | ], 96 | 97 | "marks": [ 98 | { 99 | "type": "path", 100 | "clip": true, 101 | "from": {"data": "states"}, 102 | "encode": { 103 | "enter": { 104 | "fill": {"value": "#dedede"}, 105 | "stroke": {"value": "white"} 106 | }, 107 | "update": { 108 | "path": {"field": "path"} 109 | } 110 | } 111 | }, 112 | { 113 | "type": "symbol", 114 | "clip": true, 115 | "from": {"data": "airports"}, 116 | "encode": { 117 | "enter": { 118 | "size": {"value": 10}, 119 | "fill": {"value": "steelblue"}, 120 | "fillOpacity": {"value": 0.8}, 121 | "stroke": {"value": "white"}, 122 | "strokeWidth": {"value": 0.5} 123 | }, 124 | "update": { 125 | "x": {"field": "x"}, 126 | "y": {"field": "y"} 127 | } 128 | } 129 | }, 130 | { 131 | "type": "shape", 132 | "clip": true, 133 | "from": {"data": "contours"}, 134 | "encode": { 135 | "enter": { 136 | "stroke": {"value": "#000"}, 137 | "fill": {"scale": "color", "field": "value"}, 138 | "fillOpacity": {"value": 0.4} 139 | }, 140 | "update": { 141 | "strokeWidth": {"value": 0} 142 | }, 143 | "hover": { 144 | "strokeWidth": {"value": 1.5} 145 | } 146 | }, 147 | "transform": [ 148 | { "type": "geoshape", "field": "datum" } 149 | ] 150 | } 151 | ] 152 | } 153 | -------------------------------------------------------------------------------- /test/applied_science/vega-specs/isocontour-precipitation.vg.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://vega.github.io/schema/vega/v5.json", 3 | "width": 600, 4 | "height": 300, 5 | "autosize": "fit-x", 6 | 7 | "signals": [ 8 | { 9 | "name": "projection", "value": "naturalEarth1", 10 | "bind": {"input": "select", "options": [ 11 | "azimuthalEqualArea", "equalEarth", "equirectangular", 12 | "naturalEarth1", "orthographic" 13 | ]} 14 | }, 15 | { 16 | "name": "scale", "value": 110, 17 | "bind": {"input": "range", "min": 50, "max": 400, "step": 5} 18 | }, 19 | { 20 | "name": "rotate0", "value": 0, 21 | "bind": {"input": "range", "min": -180, "max": 180, "step": 1} 22 | }, 23 | { 24 | "name": "rotate1", "value": 0, 25 | "bind": {"input": "range", "min": -180, "max": 180, "step": 1} 26 | }, 27 | { 28 | "name": "rotate2", 29 | "value": 0 30 | }, 31 | { 32 | "name": "opacity", "value": 0.5, 33 | "bind": {"input": "range", "min": 0, "max": 1, "step": 0.01} 34 | }, 35 | { 36 | "name": "levels", "value": 6, 37 | "bind": {"input": "range", "min": 2, "max": 12, "step": 1} 38 | }, 39 | { 40 | "name": "step", 41 | "update": "3000 / levels" 42 | } 43 | ], 44 | 45 | "data": [ 46 | { 47 | "name": "precipitation", 48 | "url": "data/annual-precip.json" 49 | }, 50 | { 51 | "name": "contours", 52 | "source": "precipitation", 53 | "transform": [ 54 | { 55 | "type": "isocontour", 56 | "thresholds": {"signal": "sequence(step, 3000, step)"} 57 | } 58 | ] 59 | }, 60 | { 61 | "name": "world", 62 | "url": "data/world-110m.json", 63 | "format": {"type": "topojson", "feature": "countries"} 64 | } 65 | ], 66 | 67 | "projections": [ 68 | { 69 | "name": "projection", 70 | "type": {"signal": "projection"}, 71 | "scale": {"signal": "scale"}, 72 | "rotate": {"signal": "[rotate0, rotate1, rotate2]"}, 73 | "translate": {"signal": "[width/2, height/2]"} 74 | } 75 | ], 76 | 77 | "scales": [ 78 | { 79 | "name": "color", 80 | "type": "quantize", 81 | "domain": [0, 3000], 82 | "range": {"scheme": "bluepurple", "count": {"signal": "levels"}} 83 | } 84 | ], 85 | 86 | "marks": [ 87 | { 88 | "type": "shape", 89 | "clip": true, 90 | "from": {"data": "world"}, 91 | "encode": { 92 | "update": { 93 | "strokeWidth": {"value": 1}, 94 | "stroke": {"value": "#eee"}, 95 | "fill": {"value": "#ddd"} 96 | } 97 | }, 98 | "transform": [ 99 | { 100 | "type": "geoshape", 101 | "projection": "projection" 102 | } 103 | ] 104 | }, 105 | { 106 | "type": "shape", 107 | "clip": true, 108 | "from": { "data": "contours"}, 109 | "encode": { 110 | "update": { 111 | "fill": {"scale": "color", "field": "contour.value"}, 112 | "fillOpacity": {"signal": "opacity"} 113 | } 114 | }, 115 | "transform": [ 116 | { 117 | "type": "geoshape", 118 | "field": "datum.contour", 119 | "projection": "projection" 120 | } 121 | ] 122 | } 123 | ], 124 | 125 | "legends": [ 126 | { 127 | "title": "Annual Precipitation (mm)", 128 | "fill": "color", 129 | "orient": "bottom", 130 | "offset": 5, 131 | "type": "gradient", 132 | "gradientLength": 300, 133 | "gradientThickness": 12, 134 | "titlePadding": 10, 135 | "titleOrient": "left", 136 | "titleAnchor": "end", 137 | "direction": "horizontal" 138 | } 139 | ], 140 | 141 | "config": { 142 | "legend": {"layout": {"anchor": "middle"}} 143 | } 144 | } -------------------------------------------------------------------------------- /test/applied_science/vega-specs/isocontour-volcano.vg.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://vega.github.io/schema/vega/v5.json", 3 | "width": 960, 4 | "autosize": "none", 5 | 6 | "scales": [ 7 | { 8 | "name": "color", 9 | "type": "linear", 10 | "domain": [90, 190], 11 | "range": {"scheme": "blueorange"} 12 | } 13 | ], 14 | 15 | "marks": [ 16 | { 17 | "type": "path", 18 | "from": {"data": "contours"}, 19 | "encode": { 20 | "enter": { 21 | "stroke": {"value": "#ccc"}, 22 | "strokeWidth": {"value": 1}, 23 | "fill": {"scale": "color", "field": "contour.value"} 24 | } 25 | }, 26 | "transform": [ 27 | { 28 | "type": "geopath", 29 | "field": "datum.contour" 30 | } 31 | ] 32 | } 33 | ], 34 | 35 | "data": [ 36 | { 37 | "name": "volcano", 38 | "url": "data/volcano.json" 39 | }, 40 | { 41 | "name": "contours", 42 | "source": "volcano", 43 | "transform": [ 44 | { 45 | "type": "isocontour", 46 | "scale": {"expr": "width / datum.width"}, 47 | "smooth": {"signal": "smooth"}, 48 | "thresholds": {"signal": "sequence(90, 195, 5)"} 49 | } 50 | ] 51 | } 52 | ], 53 | 54 | "signals": [ 55 | { 56 | "name": "grid", 57 | "init": "data('volcano')[0]" 58 | }, 59 | { 60 | "name": "height", 61 | "update": "round(grid.height * width / grid.width)" 62 | }, 63 | { 64 | "name": "smooth", "value": true, 65 | "bind": {"input": "radio", "options": [true, false]} 66 | } 67 | ] 68 | } -------------------------------------------------------------------------------- /test/applied_science/vega-specs/kde.vg.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://vega.github.io/schema/vega/v5.json", 3 | "width": 500, 4 | "padding": 5, 5 | 6 | "signals": [ 7 | { "name": "plotHeight", "value": 50 }, 8 | { "name": "bandwidth", "value": 0, 9 | "bind": {"input": "range", "min": 0, "max": 1, "step": 0.01} } 10 | ], 11 | 12 | "data": [ 13 | { 14 | "name": "points", 15 | "values": [ 16 | {"k": "a", "v": 1}, {"k": "a", "v": 3}, {"k": "a", "v": 3}, {"k": "a", "v": 5}, 17 | {"k": "b", "v": 2}, {"k": "b", "v": 2}, {"k": "b", "v": 4} 18 | ] 19 | }, 20 | { 21 | "name": "pdf", 22 | "source": "points", 23 | "transform": [ 24 | { 25 | "type": "kde", 26 | "groupby": ["k"], 27 | "field": "v", 28 | "bandwidth": {"signal": "bandwidth"} 29 | } 30 | ] 31 | }, 32 | { 33 | "name": "cdf", 34 | "source": "points", 35 | "transform": [ 36 | { 37 | "type": "kde", 38 | "cumulative": true, 39 | "groupby": ["k"], 40 | "field": "v", 41 | "bandwidth": {"signal": "bandwidth"} 42 | } 43 | ] 44 | } 45 | ], 46 | 47 | "scales": [ 48 | { 49 | "name": "xscale", 50 | "type": "linear", 51 | "range": "width", 52 | "domain": {"data": "points", "field": "v"}, 53 | "zero": false, 54 | "nice": true 55 | }, 56 | { 57 | "name": "ypdf", 58 | "type": "linear", 59 | "range": [{"signal": "plotHeight"}, 0], 60 | "domain": {"data": "pdf", "field": "density"} 61 | }, 62 | { 63 | "name": "ycdf", 64 | "type": "linear", 65 | "range": [{"signal": "plotHeight"}, 0], 66 | "domain": {"data": "cdf", "field": "density"} 67 | } 68 | ], 69 | 70 | "layout": { 71 | "columns": 1, 72 | "padding": 10 73 | }, 74 | 75 | "marks": [ 76 | { 77 | "type": "group", 78 | "from": { 79 | "facet": { 80 | "data": "pdf", 81 | "name": "facet", 82 | "groupby": "k" 83 | } 84 | }, 85 | "encode": { 86 | "enter": { 87 | "height": {"signal": "plotHeight"} 88 | } 89 | }, 90 | "axes": [ 91 | {"orient": "bottom", "scale": "xscale", "zindex": 1} 92 | ], 93 | "marks": [ 94 | { 95 | "type": "area", 96 | "from": {"data": "facet"}, 97 | "encode": { 98 | "update": { 99 | "x": {"scale": "xscale", "field": "value"}, 100 | "y": {"scale": "ypdf", "field": "density"}, 101 | "y2": {"scale": "ypdf", "value": 0}, 102 | "fill": {"value": "steelblue"} 103 | } 104 | } 105 | } 106 | ] 107 | }, 108 | { 109 | "type": "group", 110 | "from": { 111 | "facet": { 112 | "data": "cdf", 113 | "name": "facet", 114 | "groupby": "k" 115 | } 116 | }, 117 | "encode": { 118 | "enter": { 119 | "height": {"signal": "plotHeight"} 120 | } 121 | }, 122 | "axes": [ 123 | {"orient": "bottom", "scale": "xscale", "zindex": 1} 124 | ], 125 | "marks": [ 126 | { 127 | "type": "area", 128 | "from": {"data": "facet"}, 129 | "encode": { 130 | "update": { 131 | "x": {"scale": "xscale", "field": "value"}, 132 | "y": {"scale": "ycdf", "field": "density"}, 133 | "y2": {"scale": "ycdf", "value": 0}, 134 | "fill": {"value": "steelblue"} 135 | } 136 | } 137 | } 138 | ] 139 | } 140 | ] 141 | } 142 | -------------------------------------------------------------------------------- /test/applied_science/vega-specs/layout-wrap.vg.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://vega.github.io/schema/vega/v5.json", 3 | "width": 200, 4 | "padding": 5, 5 | "autosize": {"type": "pad", "resize": true}, 6 | 7 | "signals": [ 8 | {"name": "offset", "value": 15}, 9 | {"name": "cellHeight", "value": 100}, 10 | {"name": "columns", "value": 3, "bind": {"input": "radio", "options": [1,2,3,4]}} 11 | ], 12 | 13 | "data": [ 14 | { 15 | "name": "barley", 16 | "url": "data/barley.json" 17 | }, 18 | { 19 | "name": "footers", 20 | "transform": [ 21 | { 22 | "type": "sequence", 23 | "start": 0, 24 | "stop": {"signal": "columns"} 25 | } 26 | ] 27 | } 28 | ], 29 | 30 | "scales": [ 31 | { 32 | "name": "xscale", 33 | "type": "linear", 34 | "nice": true, 35 | "range": "width", 36 | "round": true, 37 | "domain": {"data": "barley", "field": "yield"} 38 | }, 39 | { 40 | "name": "yscale", 41 | "type": "point", 42 | "range": [0, {"signal": "cellHeight"}], 43 | "padding": 1, 44 | "round": true, 45 | "domain": { 46 | "data": "barley", 47 | "field": "variety", 48 | "sort": { 49 | "field": "yield", 50 | "op": "median", 51 | "order": "descending" 52 | } 53 | } 54 | }, 55 | { 56 | "name": "cscale", 57 | "type": "ordinal", 58 | "range": "category", 59 | "domain": {"data": "barley", "field": "year"} 60 | } 61 | ], 62 | 63 | "layout": { 64 | "padding": {"column": 10, "row": 5}, 65 | "offset": 0, 66 | "columns": {"signal": "columns"}, 67 | "bounds": "full" 68 | }, 69 | 70 | "legends": [ 71 | { 72 | "stroke": "cscale", 73 | "title": "Year", 74 | "padding": 4 75 | } 76 | ], 77 | 78 | "marks": [ 79 | { 80 | "role": "column-footer", 81 | "type": "group", 82 | "from": {"data": "footers"}, 83 | 84 | "axes": [ 85 | {"orient": "bottom", "scale": "xscale", "title": "Yield"} 86 | ] 87 | }, 88 | { 89 | "name": "site", 90 | "type": "group", 91 | 92 | "from": { 93 | "facet": { 94 | "data": "barley", 95 | "name": "sites", 96 | "groupby": "site" 97 | } 98 | }, 99 | 100 | "encode": { 101 | "enter": { 102 | "height": {"signal": "cellHeight"}, 103 | "width": {"signal": "width"}, 104 | "stroke": {"value": "#ccc"} 105 | } 106 | }, 107 | 108 | "axes": [ 109 | { 110 | "orient": "left", 111 | "scale": "yscale", 112 | "tickSize": 0, 113 | "domain": false, 114 | "grid": true, 115 | "encode": { 116 | "grid": { 117 | "enter": {"strokeDash": {"value": [3,3]}} 118 | } 119 | } 120 | } 121 | ], 122 | 123 | "title": { 124 | "text": {"signal": "parent.site"}, 125 | "frame": "group" 126 | }, 127 | 128 | "marks": [ 129 | { 130 | "type": "symbol", 131 | "from": {"data": "sites"}, 132 | "encode": { 133 | "enter": { 134 | "x": {"scale": "xscale", "field": "yield"}, 135 | "y": {"scale": "yscale", "field": "variety"}, 136 | "stroke": {"scale": "cscale", "field": "year"}, 137 | "strokeWidth": {"value": 2}, 138 | "size": {"value": 50} 139 | } 140 | } 141 | } 142 | ] 143 | } 144 | ] 145 | } 146 | -------------------------------------------------------------------------------- /test/applied_science/vega-specs/legends-ordinal.vg.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://vega.github.io/schema/vega/v5.json", 3 | "padding": 5, 4 | 5 | "config": { 6 | "legend": { 7 | "offset": 5, 8 | "symbolSize": 200 9 | } 10 | }, 11 | 12 | "signals": [ 13 | { "name": "data", "value": [ 14 | "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", 15 | "k", "l", "m", "n", "o", "p", "q", "r", "s", "t" 16 | ] 17 | }, 18 | { "name": "count", "value": 20, 19 | "bind": {"input": "range", "min": 0, "max": 20, "step": 1} 20 | }, 21 | { "name": "domain", "update": "slice(data, 0, count)"} 22 | ], 23 | 24 | "scales": [ 25 | { 26 | "name": "category", 27 | "type": "ordinal", 28 | "range": "category", 29 | "domain": {"signal": "domain"} 30 | }, 31 | { 32 | "name": "ordinal", 33 | "type": "ordinal", 34 | "range": "ordinal", 35 | "domain": {"signal": "domain"} 36 | }, 37 | { 38 | "name": "ramp", 39 | "type": "ordinal", 40 | "range": "ramp", 41 | "domain": {"signal": "domain"} 42 | }, 43 | { 44 | "name": "diverging", 45 | "type": "ordinal", 46 | "range": "diverging", 47 | "domain": {"signal": "domain"} 48 | }, 49 | { 50 | "name": "heatmap", 51 | "type": "ordinal", 52 | "range": "heatmap", 53 | "domain": {"signal": "domain"} 54 | }, 55 | { 56 | "name": "custom", 57 | "type": "ordinal", 58 | "range": {"scheme": ["goldenrod", "lightgray", "royalblue"]}, 59 | "domain": {"signal": "domain"} 60 | } 61 | ], 62 | 63 | "legends": [ 64 | {"orient": "none", "fill": "category", "title": "Category", "encode": {"legend": {"update": {"x": {"value":0}, "y": {"value":0}}}}}, 65 | {"orient": "none", "fill": "ordinal", "title": "Ordinal", "encode": {"legend": {"update": {"x": {"value":60}, "y": {"value": 0}}}}}, 66 | {"orient": "none", "fill": "ramp", "title": "Ramp", "encode": {"legend": {"update": {"x": {"value":120}, "y": {"value": 0}}}}}, 67 | {"orient": "none", "fill": "diverging", "title": "Diverging", "encode": {"legend": {"update": {"x": {"value":180}, "y": {"value": 0}}}}}, 68 | {"orient": "none", "fill": "heatmap", "title": "Heatmap", "encode": {"legend": {"update": {"x": {"value":240}, "y": {"value": 0}}}}}, 69 | {"orient": "none", "fill": "custom", "title": "Custom", "encode": {"legend": {"update": {"x": {"value":300}, "y": {"value": 0}}}}} 70 | ] 71 | } 72 | -------------------------------------------------------------------------------- /test/applied_science/vega-specs/legends.vg.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://vega.github.io/schema/vega/v5.json", 3 | "width": 0, 4 | "height": 0, 5 | "padding": 5, 6 | "autosize": {"type": "pad", "resize": true}, 7 | 8 | "config": { 9 | "legend": { 10 | "gradientDirection": "horizontal", 11 | "gradientLength": 100, 12 | "layout": { 13 | "right": { 14 | "direction": {"signal": "direction"}, 15 | "offset": {"signal": "offset"} 16 | } 17 | } 18 | } 19 | }, 20 | 21 | "signals": [ 22 | { 23 | "name": "direction", "value": "vertical", 24 | "bind": {"input": "select", "options": ["horizontal", "vertical"]} 25 | }, 26 | { 27 | "name": "offset", "value": 18, 28 | "bind": {"input": "range", "min": 0, "max": 30, "step": 1} 29 | } 30 | ], 31 | 32 | "scales": [ 33 | { 34 | "name": "sequence", 35 | "type": "linear", 36 | "range": {"scheme": "viridis"}, 37 | "domain": [0, 100] 38 | }, 39 | { 40 | "name": "stops", 41 | "type": "linear", 42 | "range": ["#f00", "#a44", "#666", "#4a4", "#0f0"], 43 | "domain": [-100, -35, 0, 35, 100] 44 | } 45 | ], 46 | 47 | "legends": [ 48 | { 49 | "type": "gradient", 50 | "fill": "sequence", 51 | "orient": "left", 52 | "title": "Gradient", 53 | "offset": 0 54 | }, 55 | { 56 | "type": "gradient", 57 | "stroke": "stops", 58 | "orient": "left", 59 | "title": "Multi-Stop", 60 | "offset": 0 61 | }, 62 | { 63 | "type": "symbol", 64 | "stroke": "sequence", 65 | "orient": "right", 66 | "title": "Sequence", 67 | "encode": { 68 | "symbols": { 69 | "interactive": true, 70 | "update": {"fill": {"value": "transparent"}}, 71 | "hover": {"fill": {"value": "#ccc"}} 72 | }, 73 | "labels": { 74 | "interactive": true, 75 | "update": {"fill": {"value": "#000"}, "fontWeight": {"value": null}}, 76 | "hover": {"fill": {"value": "firebrick"}, "fontWeight": {"value": "bold"}} 77 | } 78 | } 79 | }, 80 | { 81 | "type": "symbol", 82 | "fill": "stops", 83 | "orient": "right", 84 | "title": "Stops", 85 | "values": [-100, -35, 0, 35, 100] 86 | }, 87 | { 88 | "type": "symbol", 89 | "fill": "stops", 90 | "direction": "horizontal", 91 | "orient": "none", 92 | "title": "Orient None", 93 | "titleOrient": "bottom", 94 | "titleAnchor": "end", 95 | "values": [-50, 0, 50], 96 | "legendX": -100, 97 | "legendY": 105 98 | } 99 | ] 100 | } 101 | -------------------------------------------------------------------------------- /test/applied_science/vega-specs/lifelines.vg.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://vega.github.io/schema/vega/v5.json", 3 | "width": 500, 4 | "height": 80, 5 | "padding": 5, 6 | 7 | "data": [ 8 | { 9 | "name": "people", 10 | "values": [ 11 | { 12 | "label": "Washington", 13 | "born": -7506057600000, 14 | "died": -5366196000000, 15 | "enter": -5701424400000, 16 | "leave": -5453884800000 17 | }, 18 | { 19 | "label": "Adams", 20 | "born": -7389766800000, 21 | "died": -4528285200000, 22 | "enter": -5453884800000, 23 | "leave": -5327740800000 24 | }, 25 | { 26 | "label": "Jefferson", 27 | "born": -7154586000000, 28 | "died": -4528285200000, 29 | "enter": -5327740800000, 30 | "leave": -5075280000000 31 | }, 32 | { 33 | "label": "Madison", 34 | "born": -6904544400000, 35 | "died": -4213184400000, 36 | "enter": -5075280000000, 37 | "leave": -4822819200000 38 | }, 39 | { 40 | "label": "Monroe", 41 | "born": -6679904400000, 42 | "died": -4370518800000, 43 | "enter": -4822819200000, 44 | "leave": -4570358400000 45 | } 46 | ] 47 | }, 48 | { 49 | "name": "events", 50 | "format": {"type":"json", "parse":{"when":"date"}}, 51 | "values": [ 52 | { "name":"Decl. of Independence", "when":"July 4, 1776" }, 53 | { "name":"U.S. Constitution", "when":"3/4/1789" }, 54 | { "name":"Louisiana Purchase", "when":"April 30, 1803" }, 55 | { "name":"Monroe Doctrine", "when":"Dec 2, 1823" } 56 | ] 57 | } 58 | ], 59 | 60 | "scales": [ 61 | { 62 | "name": "yscale", 63 | "type": "band", 64 | "range": [0, {"signal": "height"}], 65 | "domain": {"data": "people", "field": "label"} 66 | }, 67 | { 68 | "name": "xscale", 69 | "type": "time", 70 | "range": "width", 71 | "round": true, 72 | "domain": {"data": "people", "fields": ["born", "died"]} 73 | } 74 | ], 75 | 76 | "axes": [ 77 | {"orient": "bottom", "scale": "xscale", "format": "%Y"} 78 | ], 79 | 80 | "marks": [ 81 | { 82 | "type": "text", 83 | "from": {"data": "events"}, 84 | "encode": { 85 | "enter": { 86 | "x": {"scale": "xscale", "field": "when"}, 87 | "y": {"value": -10}, 88 | "angle": {"value": -25}, 89 | "fill": {"value": "#000"}, 90 | "text": {"field": "name"}, 91 | "font": {"value": "Helvetica Neue"}, 92 | "fontSize": {"value": 10} 93 | } 94 | } 95 | }, 96 | { 97 | "type": "rect", 98 | "from": {"data": "events"}, 99 | "encode": { 100 | "enter": { 101 | "x": {"scale": "xscale", "field": "when"}, 102 | "y": {"value": -8}, 103 | "width": {"value": 1}, 104 | "height": {"field": {"group": "height"}, "offset": 8}, 105 | "fill": {"value": "#888"} 106 | } 107 | } 108 | }, 109 | { 110 | "type": "text", 111 | "from": {"data": "people"}, 112 | "encode": { 113 | "enter": { 114 | "x": {"scale": "xscale", "field": "born"}, 115 | "y": {"scale": "yscale", "field": "label", "offset": -3}, 116 | "fill": {"value": "#000"}, 117 | "text": {"field": "label"}, 118 | "font": {"value": "Helvetica Neue"}, 119 | "fontSize": {"value": 10} 120 | } 121 | } 122 | }, 123 | { 124 | "type": "rect", 125 | "from": {"data": "people"}, 126 | "encode": { 127 | "enter": { 128 | "x": {"scale": "xscale", "field": "born"}, 129 | "x2": {"scale": "xscale", "field": "died"}, 130 | "y": {"scale": "yscale", "field": "label"}, 131 | "height": {"value": 2}, 132 | "fill": {"value": "#557"} 133 | } 134 | } 135 | }, 136 | { 137 | "type": "rect", 138 | "from": {"data": "people"}, 139 | "encode": { 140 | "enter": { 141 | "x": {"scale": "xscale", "field": "enter"}, 142 | "x2": {"scale": "xscale", "field": "leave"}, 143 | "y": {"scale": "yscale", "field": "label", "offset":-1}, 144 | "height": {"value": 4}, 145 | "fill": {"value": "#e44"} 146 | } 147 | } 148 | } 149 | ] 150 | } 151 | -------------------------------------------------------------------------------- /test/applied_science/vega-specs/map-bind.vg.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://vega.github.io/schema/vega/v5.json", 3 | "width": 900, 4 | "height": 500, 5 | "autosize": "none", 6 | 7 | "encode": { 8 | "update": { 9 | "fill": {"signal": "bgcolor"} 10 | } 11 | }, 12 | 13 | "signals": [ 14 | { 15 | "name": "type", 16 | "value": "mercator", 17 | "bind": { 18 | "input": "select", 19 | "options": [ 20 | "albers", 21 | "albersUsa", 22 | "azimuthalEqualArea", 23 | "azimuthalEquidistant", 24 | "conicConformal", 25 | "conicEqualArea", 26 | "conicEquidistant", 27 | "equalEarth", 28 | "equirectangular", 29 | "gnomonic", 30 | "mercator", 31 | "naturalEarth1", 32 | "orthographic", 33 | "stereographic", 34 | "transverseMercator" 35 | ] 36 | } 37 | }, 38 | { "name": "scale", "value": 150, 39 | "bind": {"input": "range", "min": 50, "max": 2000, "step": 1} }, 40 | { "name": "rotate0", "value": 0, 41 | "bind": {"input": "range", "min": -180, "max": 180, "step": 1} }, 42 | { "name": "rotate1", "value": 0, 43 | "bind": {"input": "range", "min": -90, "max": 90, "step": 1} }, 44 | { "name": "rotate2", "value": 0, 45 | "bind": {"input": "range", "min": -180, "max": 180, "step": 1} }, 46 | { "name": "center0", "value": 0, 47 | "bind": {"input": "range", "min": -180, "max": 180, "step": 1} }, 48 | { "name": "center1", "value": 0, 49 | "bind": {"input": "range", "min": -90, "max": 90, "step": 1} }, 50 | { "name": "translate0", "update": "width / 2" }, 51 | { "name": "translate1", "update": "height / 2" }, 52 | 53 | { "name": "graticuleDash", "value": 0, 54 | "bind": {"input": "radio", "options": [0, 3, 5, 10]} }, 55 | { "name": "borderWidth", "value": 1, 56 | "bind": {"input": "text"} }, 57 | { "name": "bgcolor", "value": "#ffffff", 58 | "bind": {"input": "color"} }, 59 | { "name": "invert", "value": false, 60 | "bind": {"input": "checkbox"} } 61 | ], 62 | 63 | "projections": [ 64 | { 65 | "name": "projection", 66 | "type": {"signal": "type"}, 67 | "scale": {"signal": "scale"}, 68 | "rotate": [ 69 | {"signal": "rotate0"}, 70 | {"signal": "rotate1"}, 71 | {"signal": "rotate2"} 72 | ], 73 | "center": [ 74 | {"signal": "center0"}, 75 | {"signal": "center1"} 76 | ], 77 | "translate": [ 78 | {"signal": "translate0"}, 79 | {"signal": "translate1"} 80 | ] 81 | } 82 | ], 83 | 84 | "data": [ 85 | { 86 | "name": "world", 87 | "url": "data/world-110m.json", 88 | "format": { 89 | "type": "topojson", 90 | "feature": "countries" 91 | } 92 | }, 93 | { 94 | "name": "graticule", 95 | "transform": [ 96 | { "type": "graticule" } 97 | ] 98 | } 99 | ], 100 | 101 | "marks": [ 102 | { 103 | "type": "shape", 104 | "from": {"data": "graticule"}, 105 | "encode": { 106 | "update": { 107 | "strokeWidth": {"value": 1}, 108 | "strokeDash": {"signal": "[+graticuleDash, +graticuleDash]"}, 109 | "stroke": {"signal": "invert ? '#444' : '#ddd'"}, 110 | "fill": {"value": null} 111 | } 112 | }, 113 | "transform": [ 114 | { "type": "geoshape", "projection": "projection" } 115 | ] 116 | }, 117 | { 118 | "type": "shape", 119 | "from": {"data": "world"}, 120 | "encode": { 121 | "update": { 122 | "strokeWidth": {"signal": "+borderWidth"}, 123 | "stroke": {"signal": "invert ? '#777' : '#bbb'"}, 124 | "fill": {"signal": "invert ? '#fff' : '#000'"}, 125 | "zindex": {"value": 0} 126 | }, 127 | "hover": { 128 | "strokeWidth": {"signal": "+borderWidth + 1"}, 129 | "stroke": {"value": "firebrick"}, 130 | "zindex": {"value": 1} 131 | } 132 | }, 133 | "transform": [ 134 | { "type": "geoshape", "projection": "projection" } 135 | ] 136 | } 137 | ] 138 | } 139 | -------------------------------------------------------------------------------- /test/applied_science/vega-specs/map-fit.vg.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://vega.github.io/schema/vega/v5.json", 3 | "width": 700, 4 | "height": 400, 5 | "padding": 10, 6 | "autosize": {"type": "fit", "contains": "padding"}, 7 | 8 | "title": { 9 | "text": "Unemployment", 10 | "anchor": "start" 11 | }, 12 | 13 | "signals": [ 14 | { 15 | "name": "type", 16 | "value": "mercator", 17 | "bind": { 18 | "input": "select", 19 | "options": [ 20 | "albers", 21 | "albersUsa", 22 | "azimuthalEqualArea", 23 | "azimuthalEquidistant", 24 | "conicConformal", 25 | "conicEqualArea", 26 | "conicEquidistant", 27 | "equalEarth", 28 | "equirectangular", 29 | "gnomonic", 30 | "mercator", 31 | "orthographic", 32 | "stereographic", 33 | "transverseMercator" 34 | ] 35 | } 36 | }, 37 | { 38 | "name": "angle", 39 | "value": 90, 40 | "bind": {"input": "range", "min": -180, "max": 180, "step": 1} 41 | } 42 | ], 43 | 44 | "data": [ 45 | { 46 | "name": "unemp", 47 | "url": "data/unemployment.tsv", 48 | "format": {"type": "tsv", "parse": "auto"} 49 | }, 50 | { 51 | "name": "counties", 52 | "url": "data/us-10m.json", 53 | "format": {"type": "topojson", "feature": "counties"}, 54 | "transform": [ 55 | { 56 | "type": "lookup", 57 | "from": "unemp", "key": "id", "values": ["rate"], 58 | "fields": ["id"], "as": ["unemp"] 59 | }, 60 | { "type": "filter", "expr": "datum.unemp != null" } 61 | ] 62 | } 63 | ], 64 | 65 | "projections": [ 66 | { 67 | "name": "projection", 68 | "type": {"signal": "type"}, 69 | "rotate": [{"signal": "angle"}, 0, 0], 70 | "fit": {"signal": "data('counties')"}, 71 | "size": {"signal": "[width, height]"} 72 | } 73 | ], 74 | 75 | "scales": [ 76 | { 77 | "name": "color", 78 | "type": "quantize", 79 | "domain": [0, 0.15], 80 | "range": {"scheme": "blues", "count": 9} 81 | } 82 | ], 83 | 84 | "legends": [ 85 | { 86 | "fill": "color", 87 | "type": "gradient", 88 | "orient": "left", 89 | "direction": "vertical", 90 | "gradientLength": {"signal": "height"}, 91 | "format": "0.1%" 92 | } 93 | ], 94 | 95 | "marks": [ 96 | { 97 | "type": "shape", 98 | "from": {"data": "counties"}, 99 | "encode": { 100 | "update": { "fill": {"scale": "color", "field": "unemp"} }, 101 | "hover": { "fill": {"value": "red"} } 102 | }, 103 | "transform": [ 104 | { "type": "geoshape", "projection": "projection" } 105 | ] 106 | } 107 | ] 108 | } 109 | -------------------------------------------------------------------------------- /test/applied_science/vega-specs/map-point-radius.vg.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://vega.github.io/schema/vega/v5.json", 3 | "padding": 10, 4 | "width": 450, 5 | "height": 450, 6 | "autosize": "none", 7 | 8 | "signals": [ 9 | { 10 | "name": "quakeSize", "value": 6, 11 | "bind": {"input": "range", "min": 0, "max": 12} 12 | }, 13 | { 14 | "name": "rotate0", "value": 90, 15 | "bind": {"input": "range", "min": -180, "max": 180} 16 | }, 17 | { 18 | "name": "rotate1", "value": 0, 19 | "bind": {"input": "range", "min": -180, "max": 180} 20 | } 21 | ], 22 | 23 | "data": [ 24 | { 25 | "name": "sphere", 26 | "values": [ 27 | {"type": "Sphere"} 28 | ] 29 | }, 30 | { 31 | "name": "world", 32 | "url": "data/world-110m.json", 33 | "format": { 34 | "type": "topojson", 35 | "feature": "countries" 36 | } 37 | }, 38 | { 39 | "name": "earthquakes", 40 | "url": "data/earthquakes.json", 41 | "format": { 42 | "type": "json", 43 | "property": "features" 44 | } 45 | } 46 | ], 47 | 48 | "projections": [ 49 | { 50 | "name": "projection", 51 | "scale": 225, 52 | "type": "orthographic", 53 | "translate": {"signal": "[width/2, height/2]"}, 54 | "rotate": [{"signal": "rotate0"}, {"signal": "rotate1"}, 0] 55 | } 56 | ], 57 | 58 | "scales": [ 59 | { 60 | "name": "size", 61 | "type": "sqrt", 62 | "domain": [0, 100], 63 | "range": [0, {"signal": "quakeSize"}] 64 | } 65 | ], 66 | 67 | "marks": [ 68 | { 69 | "type": "shape", 70 | "from": {"data": "sphere"}, 71 | "encode": { 72 | "update": { 73 | "fill": {"value": "aliceblue"}, 74 | "stroke": {"value": "black"}, 75 | "strokeWidth": {"value": 1.5} 76 | } 77 | }, 78 | "transform": [ 79 | { 80 | "type": "geoshape", 81 | "projection": "projection" 82 | } 83 | ] 84 | }, 85 | { 86 | "type": "shape", 87 | "from": {"data": "world"}, 88 | "encode": { 89 | "update": { 90 | "fill": {"value": "mintcream"}, 91 | "stroke": {"value": "black"}, 92 | "strokeWidth": {"value": 0.35} 93 | } 94 | }, 95 | "transform": [ 96 | { 97 | "type": "geoshape", 98 | "projection": "projection" 99 | } 100 | ] 101 | }, 102 | { 103 | "type": "shape", 104 | "from": {"data": "earthquakes"}, 105 | "encode": { 106 | "update": { 107 | "opacity": {"value": 0.25}, 108 | "fill": {"value": "red"} 109 | } 110 | }, 111 | "transform": [ 112 | { 113 | "type": "geoshape", 114 | "projection": "projection", 115 | "pointRadius": {"expr": "scale('size', exp(datum.properties.mag))"} 116 | } 117 | ] 118 | } 119 | ] 120 | } 121 | -------------------------------------------------------------------------------- /test/applied_science/vega-specs/map.vg.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://vega.github.io/schema/vega/v5.json", 3 | "width": 900, 4 | "height": 500, 5 | "autosize": "none", 6 | 7 | "signals": [ 8 | { "name": "tx", "update": "width / 2" }, 9 | { "name": "ty", "update": "height / 2" }, 10 | { 11 | "name": "scale", 12 | "value": 150, 13 | "on": [{ 14 | "events": {"type": "wheel", "consume": true}, 15 | "update": "clamp(scale * pow(1.0005, -event.deltaY * pow(16, event.deltaMode)), 150, 3000)" 16 | }] 17 | }, 18 | { 19 | "name": "angles", 20 | "value": [0, 0], 21 | "on": [{ 22 | "events": "mousedown", 23 | "update": "[rotateX, centerY]" 24 | }] 25 | }, 26 | { 27 | "name": "cloned", 28 | "value": null, 29 | "on": [{ 30 | "events": "mousedown", 31 | "update": "copy('projection')" 32 | }] 33 | }, 34 | { 35 | "name": "start", 36 | "value": null, 37 | "on": [{ 38 | "events": "mousedown", 39 | "update": "invert(cloned, xy())" 40 | }] 41 | }, 42 | { 43 | "name": "drag", "value": null, 44 | "on": [{ 45 | "events": "[mousedown, window:mouseup] > window:mousemove", 46 | "update": "invert(cloned, xy())" 47 | }] 48 | }, 49 | { 50 | "name": "delta", "value": null, 51 | "on": [{ 52 | "events": {"signal": "drag"}, 53 | "update": "[drag[0] - start[0], start[1] - drag[1]]" 54 | }] 55 | }, 56 | { 57 | "name": "rotateX", "value": 0, 58 | "on": [{ 59 | "events": {"signal": "delta"}, 60 | "update": "angles[0] + delta[0]" 61 | }] 62 | }, 63 | { 64 | "name": "centerY", "value": 0, 65 | "on": [{ 66 | "events": {"signal": "delta"}, 67 | "update": "clamp(angles[1] + delta[1], -60, 60)" 68 | }] 69 | } 70 | ], 71 | 72 | "projections": [ 73 | { 74 | "name": "projection", 75 | "type": "mercator", 76 | "scale": {"signal": "scale"}, 77 | "rotate": [{"signal": "rotateX"}, 0, 0], 78 | "center": [0, {"signal": "centerY"}], 79 | "translate": [{"signal": "tx"}, {"signal": "ty"}] 80 | } 81 | ], 82 | 83 | "data": [ 84 | { 85 | "name": "world", 86 | "url": "data/world-110m.json", 87 | "format": { 88 | "type": "topojson", 89 | "feature": "countries" 90 | } 91 | }, 92 | { 93 | "name": "graticule", 94 | "transform": [ 95 | { "type": "graticule", "step": [15, 15] } 96 | ] 97 | } 98 | ], 99 | 100 | "marks": [ 101 | { 102 | "type": "shape", 103 | "from": {"data": "graticule"}, 104 | "encode": { 105 | "enter": { 106 | "strokeWidth": {"value": 1}, 107 | "stroke": {"value": "#ddd"}, 108 | "fill": {"value": null} 109 | } 110 | }, 111 | "transform": [ 112 | { "type": "geoshape", "projection": "projection" } 113 | ] 114 | }, 115 | { 116 | "type": "shape", 117 | "from": {"data": "world"}, 118 | "encode": { 119 | "enter": { 120 | "strokeWidth": {"value": 0.5}, 121 | "stroke": {"value": "#bbb"}, 122 | "fill": {"value": "#e5e8d3"} 123 | } 124 | }, 125 | "transform": [ 126 | { "type": "geoshape", "projection": "projection" } 127 | ] 128 | } 129 | ] 130 | } 131 | -------------------------------------------------------------------------------- /test/applied_science/vega-specs/movies-sort.vg.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://vega.github.io/schema/vega/v5.json", 3 | "width": 15, 4 | "padding": 5, 5 | "autosize": "pad", 6 | 7 | "config": { 8 | "axisLeft": { 9 | "titleX": -5, 10 | "titleY": -2, 11 | "titleAlign": "right", 12 | "titleAngle": 0, 13 | "titleBaseline": "bottom" 14 | } 15 | }, 16 | 17 | "signals": [ 18 | { 19 | "name": "cellSize", 20 | "value": 15 21 | }, 22 | { 23 | "name": "height", 24 | "update": "cellSize * max(0, extent[1])" 25 | }, 26 | { 27 | "name": "sortop", 28 | "value": "count", 29 | "bind": {"input": "radio", "options": ["count", "min"]} 30 | }, 31 | { 32 | "name": "sortorder", 33 | "value": "descending", 34 | "bind": {"input": "radio", "options": ["ascending", "descending"]} 35 | } 36 | ], 37 | 38 | "data": [ 39 | { 40 | "name": "source", 41 | "url": "data/movies.json" 42 | }, 43 | { 44 | "name": "layout", 45 | "source": "source", 46 | "transform": [ 47 | { 48 | "type": "aggregate", 49 | "fields": ["Title"], 50 | "ops": ["distinct"], 51 | "signal": "aggregate" 52 | }, 53 | { 54 | "type": "extent", 55 | "field": "distinct_Title", 56 | "signal": "extent" 57 | } 58 | ] 59 | } 60 | ], 61 | 62 | "marks": [ 63 | { 64 | "type": "symbol", 65 | "from": {"data": "source"}, 66 | "encode": { 67 | "update": { 68 | "x": {"value": 10}, 69 | "y": {"scale": "y", "field": "Title"}, 70 | "size": {"value": 36}, 71 | "shape": {"value": "circle"}, 72 | "strokeWidth": {"value": 1.5}, 73 | "opacity": {"value": 0.7}, 74 | "stroke": {"value": "steelblue"}, 75 | "fill": {"value": "transparent"} 76 | }, 77 | "hover": { 78 | "stroke": {"value": "firebrick"}, 79 | "cursor": {"value": "pointer"} 80 | } 81 | } 82 | } 83 | ], 84 | 85 | "scales": [ 86 | { 87 | "name": "y", 88 | "type": "point", 89 | "domain": { 90 | "data": "source", 91 | "field": "Title", 92 | "sort": { 93 | "field": "Title", 94 | "op": {"signal": "sortop"}, 95 | "order": {"signal": "sortorder"} 96 | } 97 | }, 98 | "range": {"step": {"signal": "cellSize"}}, 99 | "padding": 0.5 100 | } 101 | ], 102 | 103 | "axes": [ 104 | { 105 | "scale": "y", 106 | "orient": "left", 107 | "title": "Film Title", 108 | "encode": { 109 | "labels": { 110 | "interactive": true, 111 | "enter": { 112 | "text": {"signal": "truncate(datum.label, 25)"} 113 | }, 114 | "update": { 115 | "fill": {"value": "black"} 116 | }, 117 | "hover": { 118 | "fill": {"value": "firebrick"}, 119 | "cursor": {"value": "pointer"} 120 | } 121 | } 122 | } 123 | } 124 | ] 125 | } 126 | -------------------------------------------------------------------------------- /test/applied_science/vega-specs/nulls-histogram.vg.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://vega.github.io/schema/vega/v5.json", 3 | "width": 400, 4 | "height": 200, 5 | "padding": 5, 6 | "autosize": {"type": "fit", "resize": true}, 7 | 8 | "signals": [ 9 | { 10 | "name": "maxbins", "value": 10, 11 | "bind": {"input": "select", "options": [5, 10, 20]} 12 | }, 13 | { 14 | "name": "binCount", 15 | "update": "(bins.stop - bins.start) / bins.step" 16 | }, 17 | { 18 | "name": "nullGap", "value": 10 19 | }, 20 | { 21 | "name": "barStep", 22 | "update": "(width - nullGap) / (1 + binCount)" 23 | } 24 | ], 25 | 26 | "data": [ 27 | { 28 | "name": "table", 29 | "url": "data/movies.json", 30 | "transform": [ 31 | { 32 | "type": "extent", "field": "IMDB_Rating", 33 | "signal": "extent" 34 | }, 35 | { 36 | "type": "bin", "signal": "bins", 37 | "field": "IMDB_Rating", "extent": {"signal": "extent"}, 38 | "maxbins": {"signal": "maxbins"} 39 | } 40 | ] 41 | }, 42 | { 43 | "name": "counts", 44 | "source": "table", 45 | "transform": [ 46 | { 47 | "type": "filter", 48 | "expr": "datum['IMDB_Rating'] != null" 49 | }, 50 | { 51 | "type": "aggregate", 52 | "groupby": ["bin0", "bin1"] 53 | } 54 | ] 55 | }, 56 | { 57 | "name": "nulls", 58 | "source": "table", 59 | "transform": [ 60 | { 61 | "type": "filter", 62 | "expr": "datum['IMDB_Rating'] == null" 63 | }, 64 | { 65 | "type": "aggregate" 66 | } 67 | ] 68 | } 69 | ], 70 | 71 | "scales": [ 72 | { 73 | "name": "yscale", 74 | "type": "linear", 75 | "range": "height", 76 | "round": true, "nice": true, 77 | "domain": { 78 | "fields": [ 79 | {"data": "counts", "field": "count"}, 80 | {"data": "nulls", "field": "count"} 81 | ] 82 | } 83 | }, 84 | { 85 | "name": "xscale", 86 | "type": "linear", 87 | "range": [{"signal": "barStep + nullGap"}, {"signal": "width"}], 88 | "round": true, 89 | "domain": {"signal": "[bins.start, bins.stop]"}, 90 | "bins": {"signal": "bins"} 91 | }, 92 | { 93 | "name": "xscale-null", 94 | "type": "band", 95 | "range": [0, {"signal": "barStep"}], 96 | "round": true, 97 | "domain": [null] 98 | } 99 | ], 100 | 101 | "axes": [ 102 | {"orient": "bottom", "scale": "xscale", "tickCount": 10, "zindex": 1}, 103 | {"orient": "bottom", "scale": "xscale-null", "zindex": 1}, 104 | {"orient": "left", "scale": "yscale", "tickCount": 5, "offset": 5, "zindex": 1} 105 | ], 106 | 107 | "marks": [ 108 | { 109 | "type": "rect", 110 | "from": {"data": "counts"}, 111 | "encode": { 112 | "update": { 113 | "x": {"scale": "xscale", "field": "bin0", "offset": 1}, 114 | "x2": {"scale": "xscale", "field": "bin1"}, 115 | "y": {"scale": "yscale", "field": "count"}, 116 | "y2": {"scale": "yscale", "value": 0}, 117 | "fill": {"value": "steelblue"} 118 | }, 119 | "hover": { 120 | "fill": {"value": "firebrick"} 121 | } 122 | } 123 | }, 124 | { 125 | "type": "rect", 126 | "from": {"data": "nulls"}, 127 | "encode": { 128 | "update": { 129 | "x": {"scale": "xscale-null", "value": null, "offset": 1}, 130 | "x2": {"scale": "xscale-null", "band": 1}, 131 | "y": {"scale": "yscale", "field": "count"}, 132 | "y2": {"scale": "yscale", "value": 0}, 133 | "fill": {"value": "#aaa"} 134 | }, 135 | "hover": { 136 | "fill": {"value": "firebrick"} 137 | } 138 | } 139 | } 140 | ] 141 | } 142 | -------------------------------------------------------------------------------- /test/applied_science/vega-specs/quantile-dot-plot.vg.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://vega.github.io/schema/vega/v5.json", 3 | "width": 400, 4 | "height": 90, 5 | "padding": 5, 6 | 7 | "signals": [ 8 | { 9 | "name": "quantiles", "value": 20, 10 | "bind": {"input": "range", "min": 10, "max": 200, "step": 1} 11 | }, 12 | {"name": "mean", "update": "log(11.4)"}, 13 | {"name": "sd", "value": 0.2}, 14 | {"name": "step", "update": "1.25 * sqrt(20 / quantiles)"}, 15 | {"name": "size", "update": "scale('x', step) - scale('x', 0)"}, 16 | {"name": "area", "update": "size * size"}, 17 | { 18 | "name": "select", "init": "quantileLogNormal(0.05, mean, sd)", 19 | "on": [ 20 | { 21 | "events": "click, [mousedown, window:mouseup] > mousemove", 22 | "update": "clamp(invert('x', x()), 0.0001, 30)" 23 | }, 24 | { 25 | "events": "dblclick", 26 | "update": "0" 27 | } 28 | ] 29 | } 30 | ], 31 | 32 | "data": [ 33 | { 34 | "name": "quantiles", 35 | "transform": [ 36 | { 37 | "type": "sequence", "as": "p", 38 | "start": {"signal": "0.5 / quantiles"}, 39 | "step": {"signal": "1 / quantiles"}, 40 | "stop": 1 41 | }, 42 | { 43 | "type": "formula", "as": "value", 44 | "expr": "quantileLogNormal(datum.p, mean, sd)" 45 | }, 46 | { 47 | "type": "dotbin", 48 | "field": "value", 49 | "step": {"signal": "step"} 50 | }, 51 | { 52 | "type": "stack", 53 | "groupby": ["bin"] 54 | }, 55 | { 56 | "type": "extent", 57 | "field": "y1", 58 | "signal": "ext" 59 | } 60 | ] 61 | } 62 | ], 63 | 64 | "scales": [ 65 | { 66 | "name": "x", 67 | "domain": [0, 30], 68 | "range": "width" 69 | }, 70 | { 71 | "name": "y", 72 | "domain": {"signal": "[0, height / size]"}, 73 | "range": "height" 74 | } 75 | ], 76 | 77 | "axes": [ 78 | {"scale": "x", "orient": "bottom"} 79 | ], 80 | 81 | "marks": [ 82 | { 83 | "type": "symbol", 84 | "from": {"data": "quantiles"}, 85 | "encode": { 86 | "enter": { 87 | "x": {"scale": "x", "field": "bin"}, 88 | "y": {"scale": "y", "signal": "datum.y0 + 0.5"}, 89 | "size": {"signal": "area"} 90 | }, 91 | "update": { 92 | "fill": {"signal": "datum.bin < select ? 'firebrick' : 'steelblue'"} 93 | } 94 | } 95 | }, 96 | { 97 | "type": "rule", 98 | "interactive": false, 99 | "encode": { 100 | "update": { 101 | "x": {"scale": "x", "signal": "select"}, 102 | "y": {"value": 0}, 103 | "y2": {"signal": "height"}, 104 | "stroke": {"signal": "select ? '#ccc': 'transparent'"} 105 | } 106 | } 107 | }, 108 | { 109 | "type": "text", 110 | "interactive": false, 111 | "encode": { 112 | "enter": { 113 | "baseline": {"value": "top"}, 114 | "dx": {"value": 3}, 115 | "y": {"value": 2} 116 | }, 117 | "update": { 118 | "x": {"scale": "x", "signal": "select"}, 119 | "text": {"signal": "format(cumulativeLogNormal(select, mean, sd), '.1%')"}, 120 | "fill": {"signal": "select ? '#000': 'transparent'"} 121 | } 122 | } 123 | } 124 | ] 125 | } 126 | -------------------------------------------------------------------------------- /test/applied_science/vega-specs/quantile-quantile-plot.vg.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://vega.github.io/schema/vega/v5.json", 3 | "padding": 5, 4 | 5 | "signals": [ 6 | { "name": "plotWidth", "value": 250 }, 7 | { "name": "height", "update": "plotWidth" }, 8 | { 9 | "name": "numQuantiles", "value": 100, 10 | "bind": {"input": "range", "min": 20, "max": 200, "step": 1} 11 | }, 12 | { 13 | "name": "url", 14 | "value": "data/normal-2d.json", 15 | "bind": { 16 | "input": "select", 17 | "options": [ 18 | "data/normal-2d.json", 19 | "data/uniform-2d.json" 20 | ] 21 | } 22 | } 23 | ], 24 | 25 | "data": [ 26 | { 27 | "name": "points", 28 | "url": {"signal": "url"} 29 | }, 30 | { 31 | "name": "quantiles", 32 | "source": "points", 33 | "transform": [ 34 | { 35 | "type": "quantile", 36 | "field": "u", 37 | "step": {"signal": "1 / (numQuantiles + 1)"} 38 | }, 39 | { 40 | "type": "formula", 41 | "as": "quniform", 42 | "expr": "quantileUniform(datum.prob)" 43 | }, 44 | { 45 | "type": "formula", 46 | "as": "qnormal", 47 | "expr": "quantileNormal(datum.prob)" 48 | } 49 | ] 50 | } 51 | ], 52 | 53 | "scales": [ 54 | { 55 | "name": "y", 56 | "domain": {"data": "points", "field": "u"}, 57 | "range": "height", 58 | "nice": true 59 | } 60 | ], 61 | 62 | "layout": { 63 | "columns": 2, 64 | "padding": 10 65 | }, 66 | 67 | "marks": [ 68 | { 69 | "type": "group", 70 | "encode": { 71 | "update": { 72 | "width": {"signal": "plotWidth"}, 73 | "height": {"signal": "plotWidth"} 74 | } 75 | }, 76 | "signals": [ 77 | {"name": "width", "update": "plotWidth"} 78 | ], 79 | "scales": [ 80 | { 81 | "name": "x", 82 | "domain": [0, 1], 83 | "range": "width" 84 | } 85 | ], 86 | "axes": [ 87 | { 88 | "scale": "y", 89 | "orient": "left", 90 | "offset": 10, 91 | "grid": true, 92 | "title": "Empirical Data Quantiles" 93 | }, 94 | { 95 | "scale": "x", 96 | "orient": "bottom", 97 | "grid": true, 98 | "title": "Theoretical Uniform Quantiles" 99 | } 100 | ], 101 | "marks": [ 102 | { 103 | "type": "symbol", 104 | "from": {"data": "quantiles"}, 105 | "encode": { 106 | "update": { 107 | "x": {"scale": "x", "field": "quniform"}, 108 | "y": {"scale": "y", "field": "value"}, 109 | "fill": {"value": "steelblue"}, 110 | "size": {"value": 16} 111 | } 112 | } 113 | } 114 | ] 115 | }, 116 | { 117 | "type": "group", 118 | "encode": { 119 | "update": { 120 | "width": {"signal": "plotWidth"}, 121 | "height": {"signal": "plotWidth"} 122 | } 123 | }, 124 | "signals": [ 125 | {"name": "width", "update": "plotWidth"} 126 | ], 127 | "scales": [ 128 | { 129 | "name": "x", 130 | "domain": [-3, 3], 131 | "range": "width" 132 | } 133 | ], 134 | "axes": [ 135 | { 136 | "scale": "y", 137 | "orient": "left", 138 | "domain": false, "labels": false, "ticks": false, "grid": true 139 | }, 140 | { 141 | "scale": "x", 142 | "orient": "bottom", 143 | "grid": true, 144 | "title": "Theoretical Normal Quantiles" 145 | } 146 | ], 147 | "marks": [ 148 | { 149 | "type": "symbol", 150 | "from": {"data": "quantiles"}, 151 | "encode": { 152 | "update": { 153 | "x": {"scale": "x", "field": "qnormal"}, 154 | "y": {"scale": "y", "field": "value"}, 155 | "fill": {"value": "steelblue"}, 156 | "size": {"value": 16} 157 | } 158 | } 159 | } 160 | ] 161 | } 162 | ] 163 | } 164 | -------------------------------------------------------------------------------- /test/applied_science/vega-specs/regression.vg.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://vega.github.io/schema/vega/v5.json", 3 | "padding": 5, 4 | "autosize": "pad", 5 | 6 | "signals": [ 7 | { 8 | "name": "plotSize", 9 | "value": 200 10 | } 11 | ], 12 | 13 | "data": [ 14 | { 15 | "name": "movies", 16 | "url": "data/movies.json", 17 | "transform": [ 18 | { 19 | "type": "filter", 20 | "expr": "datum.Rotten_Tomatoes_Rating != null && datum.IMDB_Rating != null" 21 | } 22 | ] 23 | }, 24 | { 25 | "name": "methods", 26 | "values": ["linear", "log", "exp", "pow", "quad", "poly"] 27 | }, 28 | { 29 | "name": "bandwidths", 30 | "values": [0.05, 0.3] 31 | } 32 | ], 33 | 34 | "scales": [ 35 | { 36 | "name": "x", 37 | "type": "linear", 38 | "domain": {"data": "movies", "field": "Rotten_Tomatoes_Rating"}, 39 | "range": [0, {"signal": "plotSize"}] 40 | }, 41 | { 42 | "name": "y", 43 | "type": "linear", 44 | "domain": {"data": "movies", "field": "IMDB_Rating"}, 45 | "range": [{"signal": "plotSize"}, 0] 46 | } 47 | ], 48 | 49 | "layout": { 50 | "columns": 4, 51 | "padding": 5 52 | }, 53 | 54 | "marks": [ 55 | { 56 | "type": "group", 57 | "from": {"data": "methods"}, 58 | 59 | "data": [ 60 | { 61 | "name": "fit", 62 | "source": "movies", 63 | "transform": [ 64 | { 65 | "type": "regression", 66 | "method": {"signal": "parent.data"}, 67 | "x": "Rotten_Tomatoes_Rating", 68 | "y": "IMDB_Rating", 69 | "as": ["u", "v"] 70 | } 71 | ] 72 | } 73 | ], 74 | "title": { 75 | "text": {"signal": "parent.data"} 76 | }, 77 | "marks": [ 78 | { 79 | "type": "symbol", 80 | "from": {"data": "movies"}, 81 | "encode": { 82 | "enter": { 83 | "x": {"scale": "x", "field": "Rotten_Tomatoes_Rating"}, 84 | "y": {"scale": "y", "field": "IMDB_Rating"}, 85 | "fillOpacity": {"value": 0.5}, 86 | "size": {"value": 4} 87 | } 88 | } 89 | }, 90 | { 91 | "type": "line", 92 | "from": {"data": "fit"}, 93 | "encode": { 94 | "enter": { 95 | "x": {"scale": "x", "field": "u"}, 96 | "y": {"scale": "y", "field": "v"}, 97 | "stroke": {"value": "firebrick"} 98 | } 99 | } 100 | } 101 | ] 102 | }, 103 | { 104 | "type": "group", 105 | "from": {"data": "bandwidths"}, 106 | 107 | "data": [ 108 | { 109 | "name": "fit", 110 | "source": "movies", 111 | "transform": [ 112 | { 113 | "type": "loess", 114 | "bandwidth": {"signal": "parent.data"}, 115 | "x": "Rotten_Tomatoes_Rating", 116 | "y": "IMDB_Rating", 117 | "as": ["u", "v"] 118 | } 119 | ] 120 | } 121 | ], 122 | "title": { 123 | "text": {"signal": "'loess, bandwidth ' + parent.data"} 124 | }, 125 | "marks": [ 126 | { 127 | "type": "symbol", 128 | "from": {"data": "movies"}, 129 | "encode": { 130 | "enter": { 131 | "x": {"scale": "x", "field": "Rotten_Tomatoes_Rating"}, 132 | "y": {"scale": "y", "field": "IMDB_Rating"}, 133 | "fillOpacity": {"value": 0.5}, 134 | "size": {"value": 4} 135 | } 136 | } 137 | }, 138 | { 139 | "type": "line", 140 | "from": {"data": "fit"}, 141 | "encode": { 142 | "enter": { 143 | "x": {"scale": "x", "field": "u"}, 144 | "y": {"scale": "y", "field": "v"}, 145 | "stroke": {"value": "firebrick"} 146 | } 147 | } 148 | } 149 | ] 150 | } 151 | ] 152 | } 153 | -------------------------------------------------------------------------------- /test/applied_science/vega-specs/scales-bin.vg.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://vega.github.io/schema/vega/v5.json", 3 | "width": 400, 4 | "height": 300, 5 | "padding": 5, 6 | "autosize": {"type": "pad", "resize": true}, 7 | 8 | "signals": [ 9 | { 10 | "name": "maxbins", "value": 10, 11 | "bind": {"input": "select", "options": [5, 10, 20, 50]} 12 | }, 13 | { 14 | "name": "binDomain", 15 | "update": "[bins.start, bins.stop]" 16 | } 17 | ], 18 | 19 | "data": [ 20 | { 21 | "name": "table", 22 | "values": [ 23 | {"v": 28}, {"v": 55}, {"v": 43}, {"v": 91}, {"v": 34}, 24 | {"v": 81}, {"v": 53}, {"v": 19}, {"v": 87}, {"v": 38}, 25 | {"v": 52}, {"v": 48}, {"v": 24}, {"v": 49}, 26 | {"v": 87}, {"v": 66}, {"v": 17}, {"v": 27}, 27 | {"v": 68}, {"v": 12}, {"v": 49}, {"v": 4} 28 | ], 29 | "transform": [ 30 | { 31 | "type": "extent", "field": "v", 32 | "signal": "extent" 33 | }, 34 | { 35 | "type": "bin", "signal": "bins", 36 | "field": "v", "extent": {"signal": "extent"}, 37 | "maxbins": {"signal": "maxbins"} 38 | } 39 | ] 40 | }, 41 | { 42 | "name": "counts", 43 | "source": "table", 44 | "transform": [ 45 | { 46 | "type": "aggregate", 47 | "groupby": ["bin0", "bin1"] 48 | } 49 | ] 50 | } 51 | ], 52 | 53 | "scales": [ 54 | { 55 | "name": "yscale", 56 | "type": "linear", 57 | "range": "height", 58 | "domain": {"data": "counts", "field": "count"} 59 | }, 60 | { 61 | "name": "xscale", 62 | "type": "linear", 63 | "range": "width", 64 | "round": true, 65 | "domain": {"signal": "binDomain"}, 66 | "bins": {"signal": "bins"} 67 | }, 68 | { 69 | "name": "size", 70 | "type": "linear", 71 | "range": [10, 100], 72 | "round": true, 73 | "domain": {"signal": "binDomain"}, 74 | "bins": {"signal": "bins"} 75 | }, 76 | { 77 | "name": "color", 78 | "type": "bin-ordinal", 79 | "range": {"scheme": "purpleorange"}, 80 | "bins": { 81 | "start": {"signal": "bins.start"}, 82 | "stop": {"signal": "bins.stop"}, 83 | "step": {"signal": "bins.step"} 84 | } 85 | } 86 | ], 87 | 88 | "axes": [ 89 | {"orient": "bottom", "scale": "xscale", "tickCount": 20, "labelOverlap": true, "zindex": 1}, 90 | {"orient": "left", "scale": "yscale", "tickCount": 5, "zindex": 1} 91 | ], 92 | 93 | "legends": [ 94 | {"fill": "color", "size": "size", "title": "Bins"} 95 | ], 96 | 97 | "marks": [ 98 | { 99 | "type": "rect", 100 | "from": {"data": "counts"}, 101 | "encode": { 102 | "enter": { 103 | "x": {"scale": "xscale", "field": "bin0", "offset": 1}, 104 | "x2": {"scale": "xscale", "field": "bin1"}, 105 | "y": {"scale": "yscale", "field": "count"}, 106 | "y2": {"scale": "yscale", "value": 0} 107 | }, 108 | "update": { 109 | "fill": {"scale": "color", "field": "bin0"} 110 | } 111 | } 112 | } 113 | ] 114 | } 115 | -------------------------------------------------------------------------------- /test/applied_science/vega-specs/scales-discretize.vg.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://vega.github.io/schema/vega/v5.json", 3 | "padding": 5, 4 | "autosize": "pad", 5 | "width": 20, 6 | "height": 200, 7 | 8 | "data": [ 9 | { 10 | "name": "source", 11 | "values": [ 12 | {"a": "A", "b": 28}, 13 | {"a": "B", "b": 55}, 14 | {"a": "C", "b": 43}, 15 | {"a": "D", "b": 91}, 16 | {"a": "E", "b": 81}, 17 | {"a": "F", "b": 53}, 18 | {"a": "G", "b": 19}, 19 | {"a": "H", "b": 87}, 20 | {"a": "I", "b": 52} 21 | ], 22 | "format": {"type": "json","parse": {"b": "number"}} 23 | } 24 | ], 25 | 26 | "scales": [ 27 | { 28 | "name": "quantize", 29 | "type": "quantize", 30 | "range": [1, 80, 160, 240, 320, 400], 31 | "domain": {"data": "source", "field": "b"}, 32 | "zero": true, "nice": true 33 | }, 34 | { 35 | "name": "colorQuantize", 36 | "type": "quantize", 37 | "range": {"scheme": "brownbluegreen", "count": 6}, 38 | "domain": {"data": "source", "field": "b"}, 39 | "zero": true, "nice": true 40 | }, 41 | { 42 | "name": "quantile", 43 | "type": "quantile", 44 | "range": [80, 160, 240, 320, 400], 45 | "domain": {"data": "source", "field": "b"} 46 | }, 47 | { 48 | "name": "colorQuantile", 49 | "type": "quantile", 50 | "range": {"scheme": "dark2", "count": 5}, 51 | "domain": {"data": "source", "field": "b"} 52 | }, 53 | { 54 | "name": "threshold", 55 | "type": "threshold", 56 | "range": [80, 200, 320], 57 | "domain": [30, 70] 58 | }, 59 | { 60 | "name": "colorThreshold", 61 | "type": "threshold", 62 | "range": {"scheme": "redyellowblue"}, 63 | "domain": [30, 70] 64 | }, 65 | { 66 | "name": "yscale", 67 | "type": "band", 68 | "range": [10, {"signal": "height"}], 69 | "domain": {"data": "source", "field": "a"} 70 | } 71 | ], 72 | 73 | "legends": [ 74 | {"size": "quantize", "fill": "colorQuantize", "title": "quantize"}, 75 | {"size": "quantile", "fill": "colorQuantile", "title": "quantile"}, 76 | {"size": "threshold", "fill": "colorThreshold", "title": "threshold"} 77 | ], 78 | 79 | "marks": [ 80 | { 81 | "name": "marks", 82 | "type": "symbol", 83 | "from": {"data": "source"}, 84 | "encode": { 85 | "update": { 86 | "x": {"value": 10}, 87 | "y": {"scale": "yscale", "field": "a"}, 88 | "size": {"scale": "quantize", "field": "b"}, 89 | "fill": {"scale": "colorQuantize", "field": "b"}, 90 | "strokeWidth": {"value": 1.5} 91 | } 92 | } 93 | }, 94 | { 95 | "type": "text", 96 | "from": {"data": "source"}, 97 | "encode": { 98 | "update": { 99 | "x": {"value": -15}, 100 | "y": {"scale": "yscale", "field": "a"}, 101 | "text": {"field": "b"}, 102 | "baseline": {"value": "middle"} 103 | } 104 | } 105 | } 106 | ] 107 | } 108 | -------------------------------------------------------------------------------- /test/applied_science/vega-specs/scatter-plot-contours.vg.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://vega.github.io/schema/vega/v5.json", 3 | "width": 400, 4 | "height": 300, 5 | "padding": 5, 6 | "autosize": "pad", 7 | 8 | "signals": [ 9 | { 10 | "name": "bandwidth", "value": -1, 11 | "bind": {"input": "range", "min": -1, "max": 100, "step": 1} 12 | }, 13 | { 14 | "name": "resolve", "value": "shared", 15 | "bind": {"input": "select", "options": ["independent", "shared"]} 16 | }, 17 | { 18 | "name": "counts", "value": true, 19 | "bind": {"input": "checkbox"} 20 | } 21 | ], 22 | 23 | "data": [ 24 | { 25 | "name": "source", 26 | "url": "data/cars.json", 27 | "transform": [ 28 | { 29 | "type": "filter", 30 | "expr": "datum.Horsepower != null && datum.Miles_per_Gallon != null && datum.Acceleration != null" 31 | } 32 | ] 33 | }, 34 | { 35 | "name": "density", 36 | "source": "source", 37 | "transform": [ 38 | { 39 | "type": "kde2d", 40 | "groupby": ["Origin"], 41 | "size": [{"signal": "width"}, {"signal": "height"}], 42 | "x": {"expr": "scale('x', datum.Horsepower)"}, 43 | "y": {"expr": "scale('y', datum.Miles_per_Gallon)"}, 44 | "bandwidth": {"signal": "[bandwidth, bandwidth]"}, 45 | "counts": {"signal": "counts"} 46 | } 47 | ] 48 | }, 49 | { 50 | "name": "contours", 51 | "source": "density", 52 | "transform": [ 53 | { 54 | "type": "isocontour", 55 | "field": "grid", 56 | "resolve": {"signal": "resolve"}, 57 | "levels": 3 58 | } 59 | ] 60 | } 61 | ], 62 | 63 | "scales": [ 64 | { 65 | "name": "x", 66 | "type": "linear", 67 | "round": true, 68 | "nice": true, 69 | "zero": true, 70 | "domain": {"data": "source", "field": "Horsepower"}, 71 | "range": "width" 72 | }, 73 | { 74 | "name": "y", 75 | "type": "linear", 76 | "round": true, 77 | "nice": true, 78 | "zero": true, 79 | "domain": {"data": "source", "field": "Miles_per_Gallon"}, 80 | "range": "height" 81 | }, 82 | { 83 | "name": "color", 84 | "type": "ordinal", 85 | "domain": { 86 | "data": "source", "field": "Origin", 87 | "sort": {"order": "descending"} 88 | }, 89 | "range": "category" 90 | } 91 | ], 92 | 93 | "axes": [ 94 | { 95 | "scale": "x", 96 | "grid": true, 97 | "domain": false, 98 | "orient": "bottom", 99 | "tickCount": 5, 100 | "title": "Horsepower" 101 | }, 102 | { 103 | "scale": "y", 104 | "grid": true, 105 | "domain": false, 106 | "orient": "left", 107 | "titlePadding": 5, 108 | "title": "Miles_per_Gallon" 109 | } 110 | ], 111 | 112 | "legends": [ 113 | {"stroke": "color", "symbolType": "stroke"} 114 | ], 115 | 116 | "marks": [ 117 | { 118 | "name": "marks", 119 | "type": "symbol", 120 | "from": {"data": "source"}, 121 | "encode": { 122 | "update": { 123 | "x": {"scale": "x", "field": "Horsepower"}, 124 | "y": {"scale": "y", "field": "Miles_per_Gallon"}, 125 | "size": {"value": 4}, 126 | "fill": {"value": "#ccc"} 127 | } 128 | } 129 | }, 130 | { 131 | "type": "image", 132 | "from": {"data": "density"}, 133 | "encode": { 134 | "update": { 135 | "x": {"value": 0}, 136 | "y": {"value": 0}, 137 | "width": {"signal": "width"}, 138 | "height": {"signal": "height"}, 139 | "aspect": {"value": false} 140 | } 141 | }, 142 | "transform": [ 143 | { 144 | "type": "heatmap", 145 | "field": "datum.grid", 146 | "resolve": {"signal": "resolve"}, 147 | "color": {"expr": "scale('color', datum.datum.Origin)"} 148 | } 149 | ] 150 | }, 151 | { 152 | "type": "path", 153 | "clip": true, 154 | "from": {"data": "contours"}, 155 | "encode": { 156 | "enter": { 157 | "strokeWidth": {"value": 1}, 158 | "strokeOpacity": {"value": 1}, 159 | "stroke": {"scale": "color", "field": "Origin"} 160 | } 161 | }, 162 | "transform": [ 163 | { "type": "geopath", "field": "datum.contour" } 164 | ] 165 | } 166 | ] 167 | } 168 | -------------------------------------------------------------------------------- /test/applied_science/vega-specs/scatter-plot-heatmap.vg.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://vega.github.io/schema/vega/v5.json", 3 | "width": 400, 4 | "height": 300, 5 | "padding": 5, 6 | "autosize": "pad", 7 | 8 | "signals": [ 9 | { 10 | "name": "bandwidthX", "value": -1, 11 | "bind": {"input": "range", "min": -1, "max": 100, "step": 1} 12 | }, 13 | { 14 | "name": "bandwidthY", "value": -1, 15 | "bind": {"input": "range", "min": -1, "max": 100, "step": 1} 16 | }, 17 | { 18 | "name": "cellSize", "value": 4, 19 | "bind": {"input": "select", "options": [1, 2, 4, 8, 16]} 20 | }, 21 | { 22 | "name": "smooth", "value": true, 23 | "bind": {"input": "checkbox"} 24 | } 25 | ], 26 | 27 | "data": [ 28 | { 29 | "name": "source", 30 | "url": "data/cars.json", 31 | "transform": [ 32 | { 33 | "type": "filter", 34 | "expr": "datum.Horsepower != null && datum.Miles_per_Gallon != null" 35 | } 36 | ] 37 | }, 38 | { 39 | "name": "density", 40 | "source": "source", 41 | "transform": [ 42 | { 43 | "type": "kde2d", 44 | "size": [{"signal": "width"}, {"signal": "height"}], 45 | "x": {"expr": "scale('x', datum.Horsepower)"}, 46 | "y": {"expr": "scale('y', datum.Miles_per_Gallon)"}, 47 | "bandwidth": {"signal": "[bandwidthX, bandwidthY]"}, 48 | "cellSize": {"signal": "cellSize"} 49 | } 50 | ] 51 | } 52 | ], 53 | 54 | "scales": [ 55 | { 56 | "name": "x", 57 | "type": "linear", 58 | "round": true, 59 | "nice": true, 60 | "zero": true, 61 | "domain": {"data": "source", "field": "Horsepower"}, 62 | "range": "width" 63 | }, 64 | { 65 | "name": "y", 66 | "type": "linear", 67 | "round": true, 68 | "nice": true, 69 | "zero": true, 70 | "domain": {"data": "source", "field": "Miles_per_Gallon"}, 71 | "range": "height" 72 | }, 73 | { 74 | "name": "density", 75 | "type": "linear", 76 | "zero": true, 77 | "domain": [0, 1], 78 | "range": {"scheme": "viridis"} 79 | } 80 | ], 81 | 82 | "axes": [ 83 | { 84 | "scale": "x", 85 | "domain": false, 86 | "orient": "bottom", 87 | "tickCount": 5, 88 | "title": "Horsepower" 89 | }, 90 | { 91 | "scale": "y", 92 | "domain": false, 93 | "orient": "left", 94 | "titlePadding": 5, 95 | "title": "Miles_per_Gallon" 96 | } 97 | ], 98 | 99 | "legends": [ 100 | {"fill": "density", "title": "Density"} 101 | ], 102 | 103 | "marks": [ 104 | { 105 | "type": "image", 106 | "from": {"data": "density"}, 107 | "encode": { 108 | "update": { 109 | "x": {"value": 0}, 110 | "y": {"value": 0}, 111 | "width": {"signal": "width"}, 112 | "height": {"signal": "height"}, 113 | "aspect": {"value": false}, 114 | "smooth": {"signal": "smooth"} 115 | } 116 | }, 117 | "transform": [ 118 | { 119 | "type": "heatmap", 120 | "field": "datum.grid", 121 | "color": {"expr": "scale('density', datum.$value / datum.$max)"}, 122 | "opacity": 1 123 | } 124 | ] 125 | } 126 | ] 127 | } 128 | -------------------------------------------------------------------------------- /test/applied_science/vega-specs/scatter-plot.vg.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://vega.github.io/schema/vega/v5.json", 3 | "width": 400, 4 | "height": 350, 5 | "padding": 10, 6 | "autosize": "pad", 7 | 8 | "config": { 9 | "legend": { 10 | "titleOrient": "left", 11 | "offset": 4, 12 | 13 | "symbolDirection": "horizontal", 14 | "symbolFillColor": "#4682b4", 15 | "symbolStrokeWidth": 0, 16 | "symbolOpacity": 1, 17 | "symbolType": "circle", 18 | 19 | "layout": { 20 | "right": { 21 | "direction": "vertical", 22 | "anchor": {"signal": "anchorRight"} 23 | }, 24 | "bottom": { 25 | "margin": 2, 26 | "direction": "vertical", 27 | "anchor": "middle", 28 | "center": true 29 | }, 30 | "top": { 31 | "margin": 2, 32 | "direction": "vertical", 33 | "anchor": "end" 34 | } 35 | } 36 | } 37 | }, 38 | 39 | "signals": [ 40 | { 41 | "name": "anchorRight", "value": "middle", 42 | "bind": {"input": "select", "options": ["start", "middle", "end"]} 43 | } 44 | ], 45 | 46 | "data": [ 47 | { 48 | "name": "source", 49 | "url": "data/cars.json", 50 | "transform": [ 51 | { 52 | "type": "filter", 53 | "expr": "datum.Horsepower != null && datum.Miles_per_Gallon != null && datum.Acceleration != null" 54 | } 55 | ] 56 | } 57 | ], 58 | 59 | "scales": [ 60 | { 61 | "name": "x", 62 | "type": "linear", 63 | "round": true, 64 | "nice": true, 65 | "zero": true, 66 | "domain": {"data": "source", "field": "Horsepower"}, 67 | "range": "width" 68 | }, 69 | { 70 | "name": "y", 71 | "type": "linear", 72 | "round": true, 73 | "nice": true, 74 | "zero": true, 75 | "domain": {"data": "source", "field": "Miles_per_Gallon"}, 76 | "range": "height" 77 | }, 78 | { 79 | "name": "size", 80 | "type": "linear", 81 | "round": true, 82 | "nice": false, 83 | "zero": true, 84 | "domain": {"data": "source", "field": "Acceleration"}, 85 | "range": [4, 361] 86 | } 87 | ], 88 | 89 | "axes": [ 90 | { 91 | "scale": "x", 92 | "grid": true, 93 | "domain": false, 94 | "orient": "bottom", 95 | "tickCount": 5, 96 | "title": "Horsepower", 97 | "titleAnchor": "end", 98 | "titleBaseline": "bottom", 99 | "titleY": -5 100 | }, 101 | { 102 | "scale": "y", 103 | "grid": true, 104 | "domain": false, 105 | "orient": "left", 106 | "titlePadding": 5, 107 | "title": "Miles_per_Gallon", 108 | "titleAlign": "left", 109 | "titleBaseline": "bottom", 110 | "titleAnchor": "end", 111 | "titleAngle": 90, 112 | "titleX": 5 113 | } 114 | ], 115 | 116 | "legends": [ 117 | { 118 | "size": "size", 119 | "orient": "right", 120 | "title": "Acceleration", 121 | "direction": "vertical", 122 | "titleOrient": "top", 123 | "values": [1, 5, 10, 20] 124 | }, 125 | { 126 | "size": "size", 127 | "orient": "bottom", 128 | "title": "Legend 1", 129 | "values": [0, 2, 5, 10, 12, 15, 18, 20] 130 | }, 131 | { 132 | "size": "size", 133 | "orient": "bottom", 134 | "title": "Legend 2", 135 | "values": [0, 2, 5, 10, 15, 20] 136 | } 137 | ], 138 | 139 | "marks": [ 140 | { 141 | "name": "marks", 142 | "type": "symbol", 143 | "from": {"data": "source"}, 144 | "encode": { 145 | "enter": { 146 | "x": {"scale": "x", "field": "Horsepower"}, 147 | "y": {"scale": "y", "field": "Miles_per_Gallon"}, 148 | "size": {"scale": "size", "field": "Acceleration"}, 149 | "shape": {"value": "circle"}, 150 | "opacity": {"value": 0.25} 151 | }, 152 | "update": { 153 | "fill": {"value": "#4682b4"} 154 | }, 155 | "hover": { 156 | "fill": {"value": "firebrick"} 157 | } 158 | } 159 | } 160 | ] 161 | } 162 | -------------------------------------------------------------------------------- /test/applied_science/vega-specs/shift-select.vg.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://vega.github.io/schema/vega/v5.json", 3 | "width": 600, 4 | "height": 300, 5 | "padding": 10, 6 | 7 | "signals": [ 8 | { 9 | "name": "shift", 10 | "value": false, 11 | "on": [ 12 | { 13 | "events": {"marktype": "rect", "type": "click"}, 14 | "update": "event.shiftKey", 15 | "force": true 16 | } 17 | ] 18 | }, 19 | { 20 | "name": "clicked", 21 | "value": null, 22 | "on": [ 23 | { 24 | "events": {"marktype": "rect", "type": "click"}, 25 | "update": "datum", 26 | "force": true 27 | } 28 | ] 29 | } 30 | ], 31 | 32 | "data": [ 33 | { 34 | "name": "values", 35 | "values": [ 36 | {"x": 0, "y": 28}, 37 | {"x": 1, "y": 43}, 38 | {"x": 2, "y": 99}, 39 | {"x": 3, "y": 56}, 40 | {"x": 4, "y": 38}, 41 | {"x": 5, "y": 83}, 42 | {"x": 6, "y": 69}, 43 | {"x": 7, "y": 24} 44 | ] 45 | }, 46 | { 47 | "name": "selected", 48 | "on": [ 49 | {"trigger": "!shift", "remove": true}, 50 | {"trigger": "!shift && clicked", "insert": "clicked"}, 51 | {"trigger": "shift && clicked", "toggle": "clicked"} 52 | ] 53 | } 54 | ], 55 | 56 | "scales": [ 57 | { 58 | "name": "xscale", 59 | "type": "band", 60 | "range": "width", 61 | "round": true, 62 | "domain": {"data": "values", "field": "x"} 63 | }, 64 | { 65 | "name": "yscale", 66 | "type": "linear", 67 | "range": "height", 68 | "round": true, 69 | "domain": {"data": "values", "field": "y"}, 70 | "zero": true, 71 | "nice": true 72 | } 73 | ], 74 | 75 | "axes": [ 76 | { 77 | "scale": "yscale", 78 | "orient": "left", 79 | "tickCount": 5, 80 | "zindex": 1 81 | }, 82 | { 83 | "scale": "xscale", 84 | "orient": "bottom", 85 | "zindex": 1 86 | } 87 | ], 88 | 89 | "marks": [ 90 | { 91 | "type": "rect", 92 | "from": {"data": "values"}, 93 | "encode": { 94 | "enter": { 95 | "x": {"scale": "xscale", "field": "x"}, 96 | "width": {"scale": "xscale", "band": 1}, 97 | "y": {"scale": "yscale", "field": "y"}, 98 | "y2": {"scale": "yscale", "value": 0} 99 | }, 100 | "update": { 101 | "fill": [ 102 | {"test": "indata('selected', 'x', datum.x)", "value": "steelblue"}, 103 | {"value": "#ccc"} 104 | ] 105 | } 106 | } 107 | } 108 | ] 109 | } 110 | -------------------------------------------------------------------------------- /test/applied_science/vega-specs/stacked-area.vg.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://vega.github.io/schema/vega/v5.json", 3 | "width": 500, 4 | "height": 200, 5 | "padding": 5, 6 | 7 | "data": [ 8 | { 9 | "name": "table", 10 | "values": [ 11 | {"x": 0, "y": 28, "c":0}, {"x": 0, "y": 55, "c":1}, 12 | {"x": 1, "y": 43, "c":0}, {"x": 1, "y": 91, "c":1}, 13 | {"x": 2, "y": 81, "c":0}, {"x": 2, "y": 53, "c":1}, 14 | {"x": 3, "y": 19, "c":0}, {"x": 3, "y": 87, "c":1}, 15 | {"x": 4, "y": 52, "c":0}, {"x": 4, "y": 48, "c":1}, 16 | {"x": 5, "y": 24, "c":0}, {"x": 5, "y": 49, "c":1}, 17 | {"x": 6, "y": 87, "c":0}, {"x": 6, "y": 66, "c":1}, 18 | {"x": 7, "y": 17, "c":0}, {"x": 7, "y": 27, "c":1}, 19 | {"x": 8, "y": 68, "c":0}, {"x": 8, "y": 16, "c":1}, 20 | {"x": 9, "y": 49, "c":0}, {"x": 9, "y": 15, "c":1} 21 | ], 22 | "transform": [ 23 | { 24 | "type": "stack", 25 | "groupby": ["x"], 26 | "sort": {"field": "c"}, 27 | "field": "y" 28 | } 29 | ] 30 | } 31 | ], 32 | 33 | "scales": [ 34 | { 35 | "name": "x", 36 | "type": "point", 37 | "range": "width", 38 | "domain": {"data": "table", "field": "x"} 39 | }, 40 | { 41 | "name": "y", 42 | "type": "linear", 43 | "range": "height", 44 | "nice": true, "zero": true, 45 | "domain": {"data": "table", "field": "y1"} 46 | }, 47 | { 48 | "name": "color", 49 | "type": "ordinal", 50 | "range": "category", 51 | "domain": {"data": "table", "field": "c"} 52 | } 53 | ], 54 | 55 | "axes": [ 56 | {"orient": "bottom", "scale": "x", "zindex": 1}, 57 | {"orient": "left", "scale": "y", "zindex": 1} 58 | ], 59 | 60 | "marks": [ 61 | { 62 | "type": "group", 63 | "from": { 64 | "facet": { 65 | "name": "series", 66 | "data": "table", 67 | "groupby": "c" 68 | } 69 | }, 70 | "marks": [ 71 | { 72 | "type": "area", 73 | "from": {"data": "series"}, 74 | "encode": { 75 | "enter": { 76 | "interpolate": {"value": "monotone"}, 77 | "x": {"scale": "x", "field": "x"}, 78 | "y": {"scale": "y", "field": "y0"}, 79 | "y2": {"scale": "y", "field": "y1"}, 80 | "fill": {"scale": "color", "field": "c"} 81 | }, 82 | "update": { 83 | "fillOpacity": {"value": 1} 84 | }, 85 | "hover": { 86 | "fillOpacity": {"value": 0.5} 87 | } 88 | } 89 | } 90 | ] 91 | } 92 | ] 93 | } 94 | -------------------------------------------------------------------------------- /test/applied_science/vega-specs/stacked-bar.vg.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://vega.github.io/schema/vega/v5.json", 3 | "width": 500, 4 | "height": 200, 5 | "padding": 5, 6 | 7 | "data": [ 8 | { 9 | "name": "table", 10 | "values": [ 11 | {"x": 0, "y": 28, "c":0}, {"x": 0, "y": 55, "c":1}, 12 | {"x": 1, "y": 43, "c":0}, {"x": 1, "y": 91, "c":1}, 13 | {"x": 2, "y": 81, "c":0}, {"x": 2, "y": 53, "c":1}, 14 | {"x": 3, "y": 19, "c":0}, {"x": 3, "y": 87, "c":1}, 15 | {"x": 4, "y": 52, "c":0}, {"x": 4, "y": 48, "c":1}, 16 | {"x": 5, "y": 24, "c":0}, {"x": 5, "y": 49, "c":1}, 17 | {"x": 6, "y": 87, "c":0}, {"x": 6, "y": 66, "c":1}, 18 | {"x": 7, "y": 17, "c":0}, {"x": 7, "y": 27, "c":1}, 19 | {"x": 8, "y": 68, "c":0}, {"x": 8, "y": 16, "c":1}, 20 | {"x": 9, "y": 49, "c":0}, {"x": 9, "y": 15, "c":1} 21 | ], 22 | "transform": [ 23 | { 24 | "type": "stack", 25 | "groupby": ["x"], 26 | "sort": {"field": "c"}, 27 | "field": "y" 28 | } 29 | ] 30 | } 31 | ], 32 | 33 | "scales": [ 34 | { 35 | "name": "x", 36 | "type": "band", 37 | "range": "width", 38 | "domain": {"data": "table", "field": "x"} 39 | }, 40 | { 41 | "name": "y", 42 | "type": "linear", 43 | "range": "height", 44 | "nice": true, "zero": true, 45 | "domain": {"data": "table", "field": "y1"} 46 | }, 47 | { 48 | "name": "color", 49 | "type": "ordinal", 50 | "range": "category", 51 | "domain": {"data": "table", "field": "c"} 52 | } 53 | ], 54 | 55 | "axes": [ 56 | {"orient": "bottom", "scale": "x", "zindex": 1}, 57 | {"orient": "left", "scale": "y", "zindex": 1} 58 | ], 59 | 60 | "marks": [ 61 | { 62 | "type": "rect", 63 | "from": {"data": "table"}, 64 | "encode": { 65 | "enter": { 66 | "x": {"scale": "x", "field": "x"}, 67 | "width": {"scale": "x", "band": 1, "offset": -1}, 68 | "y": {"scale": "y", "field": "y0"}, 69 | "y2": {"scale": "y", "field": "y1"}, 70 | "fill": {"scale": "color", "field": "c"} 71 | }, 72 | "update": { 73 | "fillOpacity": {"value": 1} 74 | }, 75 | "hover": { 76 | "fillOpacity": {"value": 0.5} 77 | } 78 | } 79 | } 80 | ] 81 | } 82 | -------------------------------------------------------------------------------- /test/applied_science/vega-specs/text-multiline.vg.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://vega.github.io/schema/vega/v5.json", 3 | "width": 400, 4 | "height": 300, 5 | "padding": 30, 6 | "autosize": "none", 7 | 8 | "config": { 9 | "text": { 10 | "lineBreak": "|" 11 | } 12 | }, 13 | 14 | "signals": [ 15 | { 16 | "name": "angle", "value": 0, 17 | "bind": {"input": "range", "min": 0, "max": 360, "step": 1} 18 | }, 19 | { 20 | "name": "limit", "value": 100, 21 | "bind": {"input": "range", "min": 0, "max": 100, "step": 1} 22 | } 23 | ], 24 | 25 | "data": [ 26 | { 27 | "name": "table", 28 | "values": [ 29 | {"text": "Longer text|Short"} 30 | ] 31 | }, 32 | { 33 | "name": "configs", 34 | "values": [ 35 | {"align": "left", "baseline": "top"}, 36 | {"align": "center", "baseline": "top"}, 37 | {"align": "right", "baseline": "top"}, 38 | {"align": "left", "baseline": "middle"}, 39 | {"align": "center", "baseline": "middle"}, 40 | {"align": "right", "baseline": "middle"}, 41 | {"align": "left", "baseline": "alphabetic"}, 42 | {"align": "center", "baseline": "alphabetic"}, 43 | {"align": "right", "baseline": "alphabetic"}, 44 | {"align": "left", "baseline": "bottom"}, 45 | {"align": "center", "baseline": "bottom"}, 46 | {"align": "right", "baseline": "bottom"} 47 | ] 48 | } 49 | ], 50 | 51 | "scales": [ 52 | { 53 | "name": "x", 54 | "type": "band", 55 | "domain": {"data": "configs", "field": "align"}, 56 | "range": "width", 57 | "padding": 0 58 | }, 59 | { 60 | "name": "y", 61 | "type": "band", 62 | "domain": {"data": "configs", "field": "baseline"}, 63 | "range": "height", 64 | "padding": 0 65 | } 66 | ], 67 | 68 | "marks": [ 69 | { 70 | "type": "group", 71 | "from": {"data": "configs"}, 72 | "encode": { 73 | "enter": { 74 | "x": {"scale": "x", "field": "align", "band": 0.5}, 75 | "y": {"scale": "y", "field": "baseline", "band": 0.5} 76 | } 77 | }, 78 | "marks": [ 79 | { 80 | "type": "rule", 81 | "encode": { 82 | "enter": { 83 | "x": {"value": -10}, 84 | "x2": {"value": 10}, 85 | "y": {"value": 0.5}, 86 | "stroke": {"value": "steelblue"}, 87 | "strokeWidth": {"value": 1} 88 | } 89 | } 90 | }, 91 | { 92 | "type": "text", 93 | "from": {"data": "table"}, 94 | "encode": { 95 | "enter": { 96 | "x": {"value": 0}, 97 | "y": {"value": 0}, 98 | "text": {"field": "text"}, 99 | "align": {"signal": "parent.align"}, 100 | "baseline": {"signal": "parent.baseline"}, 101 | "fontSize": {"value": 12}, 102 | "href": {"signal": "'#' + parent.align + '_' + parent.baseline"}, 103 | "cursor": {"value": "pointer"} 104 | }, 105 | "update": { 106 | "fill": {"value": "black"}, 107 | "angle": {"signal": "angle"}, 108 | "limit": {"signal": "limit"} 109 | }, 110 | "hover": { 111 | "fill": {"value": "firebrick"} 112 | } 113 | } 114 | } 115 | ] 116 | } 117 | ] 118 | } 119 | -------------------------------------------------------------------------------- /test/applied_science/vega-specs/tree-cluster.vg.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://vega.github.io/schema/vega/v5.json", 3 | "width": 600, 4 | "height": 1900, 5 | "padding": 5, 6 | 7 | "signals": [ 8 | { 9 | "name": "labels", "value": true, 10 | "bind": {"input": "checkbox"} 11 | }, 12 | { 13 | "name": "layout", "value": "cluster", 14 | "bind": {"input": "radio", "options": ["tidy", "cluster"]} 15 | }, 16 | { 17 | "name": "links", "value": "orthogonal", 18 | "bind": { 19 | "input": "select", 20 | "options": ["line", "curve", "diagonal", "orthogonal"] 21 | } 22 | }, 23 | { 24 | "name": "separation", "value": false, 25 | "bind": {"input": "checkbox"} 26 | } 27 | ], 28 | 29 | "data": [ 30 | { 31 | "name": "tree", 32 | "url": "data/flare.json", 33 | "transform": [ 34 | { 35 | "type": "stratify", 36 | "key": "id", 37 | "parentKey": "parent" 38 | }, 39 | { 40 | "type": "tree", 41 | "method": {"signal": "layout"}, 42 | "size": [{"signal": "height"}, {"signal": "width - 100"}], 43 | "separation": {"signal": "separation"}, 44 | "as": ["y", "x", "depth", "children"] 45 | } 46 | ] 47 | }, 48 | { 49 | "name": "links", 50 | "source": "tree", 51 | "transform": [ 52 | { "type": "treelinks" }, 53 | { 54 | "type": "linkpath", 55 | "orient": "horizontal", 56 | "shape": {"signal": "links"} 57 | } 58 | ] 59 | } 60 | ], 61 | 62 | "scales": [ 63 | { 64 | "name": "color", 65 | "type": "linear", 66 | "range": {"scheme": "magma"}, 67 | "domain": {"data": "tree", "field": "depth"}, 68 | "zero": true 69 | } 70 | ], 71 | 72 | "marks": [ 73 | { 74 | "type": "path", 75 | "from": {"data": "links"}, 76 | "encode": { 77 | "update": { 78 | "path": {"field": "path"}, 79 | "stroke": {"value": "#ccc"} 80 | } 81 | } 82 | }, 83 | { 84 | "type": "text", 85 | "from": {"data": "tree"}, 86 | "encode": { 87 | "enter": { 88 | "text": {"field": "name"}, 89 | "fontSize": {"value": 8}, 90 | "baseline": {"value": "middle"} 91 | }, 92 | "update": { 93 | "x": {"field": "x"}, 94 | "y": {"field": "y"}, 95 | "dx": {"signal": "datum.children ? -3 : 2"}, 96 | "align": {"signal": "datum.children ? 'right' : 'left'"}, 97 | "opacity": {"signal": "labels ? 1 : 0"} 98 | } 99 | } 100 | } 101 | ] 102 | } 103 | -------------------------------------------------------------------------------- /test/applied_science/vega-specs/tree-nest.vg.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://vega.github.io/schema/vega/v5.json", 3 | "width": 200, 4 | "height": 100, 5 | "padding": 5, 6 | 7 | "signals": [ 8 | { 9 | "name": "nodeCutoff", "value": 100, 10 | "bind": {"input": "range", "min": 0, "max": 100} 11 | }, 12 | { 13 | "name": "linkCutoff", "value": 70, 14 | "bind": {"input": "range", "min": 0, "max": 100} 15 | } 16 | ], 17 | 18 | "data": [ 19 | { 20 | "name": "tree", 21 | "values": [ 22 | {"id": "A", "job": "Doctor", "region": "East"}, 23 | {"id": "B", "job": "Doctor", "region": "East"}, 24 | {"id": "C", "job": "Lawyer", "region": "East"}, 25 | {"id": "D", "job": "Lawyer", "region": "East"}, 26 | {"id": "E", "job": "Doctor", "region": "West"}, 27 | {"id": "F", "job": "Doctor", "region": "West"}, 28 | {"id": "G", "job": "Lawyer", "region": "West"}, 29 | {"id": "H", "job": "Lawyer", "region": "West"} 30 | ], 31 | "transform": [ 32 | { 33 | "type": "nest", 34 | "generate": true, 35 | "keys": ["job", "region"] 36 | }, 37 | { 38 | "type": "tree", 39 | "method": "tidy", 40 | "size": [{"signal": "width"}, {"signal": "height"}] 41 | }, 42 | { 43 | "type": "filter", 44 | "expr": "datum.y <= nodeCutoff" 45 | } 46 | ] 47 | }, 48 | { 49 | "name": "links", 50 | "source": "tree", 51 | "transform": [ 52 | { 53 | "type": "filter", 54 | "expr": "datum.y <= linkCutoff" 55 | }, 56 | { 57 | "type": "treelinks" 58 | }, 59 | { 60 | "type": "linkpath" 61 | } 62 | ] 63 | } 64 | ], 65 | 66 | "scales": [ 67 | { 68 | "name": "color", 69 | "type": "ordinal", 70 | "range": {"scheme": "category20"} 71 | } 72 | ], 73 | 74 | "marks": [ 75 | { 76 | "type": "path", 77 | "from": {"data": "links"}, 78 | "encode": { 79 | "enter": { 80 | "stroke": {"value": "#ccc"} 81 | }, 82 | "update": { 83 | "path": {"field": "path"} 84 | } 85 | } 86 | }, 87 | { 88 | "type": "symbol", 89 | "from": {"data": "tree"}, 90 | "encode": { 91 | "enter": { 92 | "fill": {"scale": "color", "field": "id"}, 93 | "stroke": {"value": "white"}, 94 | "size": {"value": 400} 95 | }, 96 | "update": { 97 | "x": {"field": "x"}, 98 | "y": {"field": "y"} 99 | } 100 | } 101 | } 102 | ] 103 | } 104 | -------------------------------------------------------------------------------- /test/applied_science/vega-specs/tree-radial.vg.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://vega.github.io/schema/vega/v5.json", 3 | "width": 810, 4 | "height": 810, 5 | "padding": 20, 6 | 7 | "signals": [ 8 | { 9 | "name": "labels", "value": true, 10 | "bind": {"input": "checkbox"} 11 | }, 12 | { 13 | "name": "radius", "value": 330, 14 | "bind": {"input": "range", "min": 20, "max": 600} 15 | }, 16 | { 17 | "name": "extent", "value": 360, 18 | "bind": {"input": "range", "min": 0, "max": 360, "step": 1} 19 | }, 20 | { 21 | "name": "rotate", "value": 0, 22 | "bind": {"input": "range", "min": 0, "max": 360, "step": 1} 23 | }, 24 | { 25 | "name": "layout", "value": "tidy", 26 | "bind": {"input": "radio", "options": ["tidy", "cluster"]} 27 | }, 28 | { 29 | "name": "links", "value": "line", 30 | "bind": { 31 | "input": "radio", 32 | "options": ["line", "curve", "diagonal", "orthogonal"] 33 | } 34 | }, 35 | { "name": "originX", "update": "width / 2" }, 36 | { "name": "originY", "update": "height / 2" } 37 | ], 38 | 39 | "data": [ 40 | { 41 | "name": "tree", 42 | "url": "data/flare.json", 43 | "transform": [ 44 | { 45 | "type": "stratify", 46 | "key": "id", 47 | "parentKey": "parent" 48 | }, 49 | { 50 | "type": "tree", 51 | "method": {"signal": "layout"}, 52 | "size": [1, {"signal": "radius"}], 53 | "as": ["alpha", "radius", "depth", "children"] 54 | }, 55 | { 56 | "type": "formula", 57 | "expr": "(rotate + extent * datum.alpha + 270) % 360", 58 | "as": "angle" 59 | }, 60 | { 61 | "type": "formula", 62 | "expr": "PI * datum.angle / 180", 63 | "as": "radians" 64 | }, 65 | { 66 | "type": "formula", 67 | "expr": "inrange(datum.angle, [90, 270])", 68 | "as": "leftside" 69 | }, 70 | { 71 | "type": "formula", 72 | "expr": "originX + datum.radius * cos(datum.radians)", 73 | "as": "x" 74 | }, 75 | { 76 | "type": "formula", 77 | "expr": "originY + datum.radius * sin(datum.radians)", 78 | "as": "y" 79 | } 80 | ] 81 | }, 82 | { 83 | "name": "links", 84 | "source": "tree", 85 | "transform": [ 86 | { "type": "treelinks" }, 87 | { 88 | "type": "linkpath", 89 | "shape": {"signal": "links"}, "orient": "radial", 90 | "sourceX": "source.radians", "sourceY": "source.radius", 91 | "targetX": "target.radians", "targetY": "target.radius" 92 | } 93 | ] 94 | } 95 | ], 96 | 97 | "scales": [ 98 | { 99 | "name": "color", 100 | "type": "linear", 101 | "range": {"scheme": "magma"}, 102 | "domain": {"data": "tree", "field": "depth"}, 103 | "zero": true 104 | } 105 | ], 106 | 107 | "marks": [ 108 | { 109 | "type": "path", 110 | "from": {"data": "links"}, 111 | "encode": { 112 | "update": { 113 | "x": {"signal": "originX"}, 114 | "y": {"signal": "originY"}, 115 | "path": {"field": "path"}, 116 | "stroke": {"value": "#ccc"} 117 | } 118 | } 119 | }, 120 | { 121 | "type": "symbol", 122 | "from": {"data": "tree"}, 123 | "encode": { 124 | "enter": { 125 | "size": {"value": 100}, 126 | "stroke": {"value": "#fff"} 127 | }, 128 | "update": { 129 | "x": {"field": "x"}, 130 | "y": {"field": "y"}, 131 | "fill": {"scale": "color", "field": "depth"} 132 | } 133 | } 134 | }, 135 | { 136 | "type": "text", 137 | "from": {"data": "tree"}, 138 | "encode": { 139 | "enter": { 140 | "text": {"field": "name"}, 141 | "fontSize": {"value": 9}, 142 | "baseline": {"value": "middle"} 143 | }, 144 | "update": { 145 | "x": {"field": "x"}, 146 | "y": {"field": "y"}, 147 | "dx": {"signal": "(datum.leftside ? -1 : 1) * 6"}, 148 | "angle": {"signal": "datum.leftside ? datum.angle - 180 : datum.angle"}, 149 | "align": {"signal": "datum.leftside ? 'right' : 'left'"}, 150 | "opacity": {"signal": "labels ? 1 : 0"} 151 | } 152 | } 153 | } 154 | ] 155 | } 156 | -------------------------------------------------------------------------------- /test/applied_science/vega-specs/treemap.vg.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://vega.github.io/schema/vega/v5.json", 3 | "width": 960, 4 | "height": 500, 5 | "padding": 2.5, 6 | "autosize": "none", 7 | 8 | "signals": [ 9 | { 10 | "name": "layout", "value": "squarify", 11 | "bind": { 12 | "input": "select", 13 | "options": [ 14 | "squarify", 15 | "binary", 16 | "slicedice" 17 | ] 18 | } 19 | }, 20 | { 21 | "name": "aspectRatio", "value": 1.6, 22 | "bind": {"input": "range", "min": 0.2, "max": 5, "step": 0.1} 23 | } 24 | ], 25 | 26 | "data": [ 27 | { 28 | "name": "tree", 29 | "url": "data/flare.json", 30 | "transform": [ 31 | { 32 | "type": "stratify", 33 | "key": "id", 34 | "parentKey": "parent" 35 | }, 36 | { 37 | "type": "treemap", 38 | "field": "size", 39 | "sort": {"field": "value"}, 40 | "round": true, 41 | "method": {"signal": "layout"}, 42 | "ratio": {"signal": "aspectRatio"}, 43 | "size": [{"signal": "width"}, {"signal": "height"}] 44 | } 45 | ] 46 | }, 47 | { 48 | "name": "nodes", 49 | "source": "tree", 50 | "transform": [{ "type": "filter", "expr": "datum.children" }] 51 | }, 52 | { 53 | "name": "leaves", 54 | "source": "tree", 55 | "transform": [{ "type": "filter", "expr": "!datum.children" }] 56 | } 57 | ], 58 | 59 | "scales": [ 60 | { 61 | "name": "color", 62 | "type": "ordinal", 63 | "range": [ 64 | "#3182bd", "#6baed6", "#9ecae1", "#c6dbef", "#e6550d", 65 | "#fd8d3c", "#fdae6b", "#fdd0a2", "#31a354", "#74c476", 66 | "#a1d99b", "#c7e9c0", "#756bb1", "#9e9ac8", "#bcbddc", 67 | "#dadaeb", "#636363", "#969696", "#bdbdbd", "#d9d9d9" 68 | ] 69 | }, 70 | { 71 | "name": "size", 72 | "type": "ordinal", 73 | "domain": [0, 1, 2, 3], 74 | "range": [256, 28, 20, 14] 75 | }, 76 | { 77 | "name": "opacity", 78 | "type": "ordinal", 79 | "domain": [0, 1, 2, 3], 80 | "range": [0.15, 0.5, 0.8, 1.0] 81 | } 82 | ], 83 | 84 | "marks": [ 85 | { 86 | "type": "rect", 87 | "from": {"data": "nodes"}, 88 | "interactive": false, 89 | "encode": { 90 | "enter": { 91 | "fill": {"scale": "color", "field": "name"} 92 | }, 93 | "update": { 94 | "x": {"field": "x0"}, 95 | "y": {"field": "y0"}, 96 | "x2": {"field": "x1"}, 97 | "y2": {"field": "y1"} 98 | } 99 | } 100 | }, 101 | { 102 | "type": "rect", 103 | "from": {"data": "leaves"}, 104 | "encode": { 105 | "enter": { 106 | "stroke": {"value": "#fff"} 107 | }, 108 | "update": { 109 | "x": {"field": "x0"}, 110 | "y": {"field": "y0"}, 111 | "x2": {"field": "x1"}, 112 | "y2": {"field": "y1"}, 113 | "fill": {"value": "transparent"} 114 | }, 115 | "hover": { 116 | "fill": {"value": "red"} 117 | } 118 | } 119 | }, 120 | { 121 | "type": "text", 122 | "from": {"data": "nodes"}, 123 | "interactive": false, 124 | "encode": { 125 | "enter": { 126 | "font": {"value": "Helvetica Neue"}, 127 | "align": {"value": "center"}, 128 | "baseline": {"value": "middle"}, 129 | "fill": {"value": "#000"}, 130 | "text": {"field": "name"}, 131 | "fontSize": {"scale": "size", "field": "depth"}, 132 | "fillOpacity": {"scale": "opacity", "field": "depth"} 133 | }, 134 | "update": { 135 | "x": {"signal": "0.5 * (datum.x0 + datum.x1)"}, 136 | "y": {"signal": "0.5 * (datum.y0 + datum.y1)"} 137 | } 138 | } 139 | } 140 | ] 141 | } 142 | -------------------------------------------------------------------------------- /test/applied_science/vega-specs/window.vg.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://vega.github.io/schema/vega/v5.json", 3 | "width": 500, 4 | "height": 150, 5 | "padding": 5, 6 | 7 | "signals": [ 8 | { 9 | "name": "curve", "value": "linear", 10 | "bind": { 11 | "input": "select", 12 | "options": ["linear", "monotone", "step"] 13 | } 14 | }, 15 | { 16 | "name": "aggregate", "value": "sum", 17 | "bind": { 18 | "input": "select", 19 | "options": ["sum", "count", "average", "median", "stdev"] 20 | } 21 | }, 22 | { 23 | "name": "frameStart", "value": null, 24 | "bind": {"input": "select", "options": [null, -5, -2, 0]} 25 | }, 26 | { 27 | "name": "frameEnd", "value": 0, 28 | "bind": {"input": "select", "options": [0, 2, 5, null]} 29 | }, 30 | { 31 | "name": "startLabel", 32 | "update": "if(frameStart == null, '-\u221e', frameStart)" 33 | }, 34 | { 35 | "name": "endLabel", 36 | "update": "if(frameEnd == null, '+\u221e', frameEnd)" 37 | } 38 | ], 39 | 40 | "data": [ 41 | { 42 | "name": "table", 43 | "values": [ 44 | {"u": 1, "v": 28}, {"u": 2, "v": 55}, 45 | {"u": 3, "v": 43}, {"u": 4, "v": 91}, 46 | {"u": 5, "v": 81}, {"u": 6, "v": 53}, 47 | {"u": 7, "v": 19}, {"u": 8, "v": 87}, 48 | {"u": 9, "v": 52}, {"u": 10, "v": 48}, 49 | {"u": 11, "v": 24}, {"u": 12, "v": 49}, 50 | {"u": 13, "v": 87}, {"u": 14, "v": 66}, 51 | {"u": 15, "v": 17}, {"u": 16, "v": 27}, 52 | {"u": 17, "v": 68}, {"u": 18, "v": 16}, 53 | {"u": 19, "v": 49}, {"u": 20, "v": 15} 54 | ], 55 | "transform": [ 56 | { 57 | "type": "window", 58 | "sort": {"field": "u"}, 59 | "frame": [{"signal": "frameStart"}, {"signal": "frameEnd"}], 60 | "ops": [{"signal": "aggregate"}, "rank"], 61 | "fields": ["v", null], 62 | "as": ["value", null] 63 | } 64 | ] 65 | } 66 | ], 67 | 68 | "scales": [ 69 | { 70 | "name": "xscale", 71 | "type": "linear", 72 | "range": "width", 73 | "zero": false, 74 | "domain": {"data": "table", "field": "u"} 75 | }, 76 | { 77 | "name": "yscale", 78 | "type": "linear", 79 | "range": "height", 80 | "nice": true, 81 | "zero": true, 82 | "domain": {"data": "table", "field": "value"} 83 | } 84 | ], 85 | 86 | "title": { 87 | "text": {"signal": "aggregate + '(value) over sliding window: [' + startLabel + ',' + endLabel + ']'"}, 88 | "orient": "bottom" 89 | }, 90 | 91 | "axes": [ 92 | { "orient": "bottom", "scale": "xscale", "tickCount": 20, "zindex": 1 }, 93 | { "orient": "left", "scale": "yscale", "tickCount": 5, "zindex": 1 } 94 | ], 95 | 96 | "marks": [ 97 | { 98 | "type": "line", 99 | "from": {"data": "table"}, 100 | "encode": { 101 | "enter": { 102 | "x": {"scale": "xscale", "field": "u"}, 103 | "stroke": {"value": "steelblue"}, 104 | "strokeWidth": {"value": 3} 105 | }, 106 | "update": { 107 | "y": {"scale": "yscale", "field": "value"}, 108 | "interpolate": {"signal": "curve"} 109 | } 110 | } 111 | } 112 | ] 113 | } 114 | --------------------------------------------------------------------------------