|
| 1 | +# Vega 5 Previewer |
| 2 | + |
| 3 | +Visualizes data with the given [Vega](https://vega.github.io/vega/) or [Vega Lite](https://vega.github.io/vega-lite/) |
| 4 | +specs from the metadata |
| 5 | + |
| 6 | +## How to use: |
| 7 | + |
| 8 | +> Supports Vega v5 and Vega Lite v 4 |
| 9 | +
|
| 10 | +> Note: Currently, this previewer only works with JSON and CSV data. Check out the examples on [Vega website](https://vega.github.io/vega/examples/) to see how data can be structured. |
| 11 | +
|
| 12 | +This previewer is only for files. After uploading your data json or csv file, add `vega5-spec` to its metadata and set its value to |
| 13 | +the specs you want to use for visualization. |
| 14 | +You need to include a complete and valid vega specs. The only attribute you can omit in the specs is `data.url` |
| 15 | +for `vega-lite` and `data[0].url` for `vega`. The url attribute is automatically set to the file url by the previewer. |
| 16 | +In the case of `vega`, the previewer assumes the first item in `data` list is the source for the data that come from the file. You can |
| 17 | +have more data sources in that list, either pointing to other remote data or a transformation of the file data source. |
| 18 | + |
| 19 | +You can create and test your specs in [Vega Editor](https://vega.github.io/editor/) before adding it to the file |
| 20 | +metadata. |
| 21 | + |
| 22 | +After adding the specs to the file metadata, refresh the page. If the specs are valid for the data, then the |
| 23 | +visualization should load. |
| 24 | + |
| 25 | +## Example: |
| 26 | + |
| 27 | +Upload the following data as a csv file to a dataset in Clowder: |
| 28 | + |
| 29 | +| date | amount | program | state | |
| 30 | +|------|-------------|---------|----------| |
| 31 | +| 2010 | 4534553 | P1 | Illinois | |
| 32 | +| 2012 | 356554 | P1 | Illinois | |
| 33 | +| 2013 | 234234 | P1 | Illinois | |
| 34 | +| 2014 | 234654 | P1 | Illinois | |
| 35 | +| 2015 | 32434 | P1 | Illinois | |
| 36 | +| 2011 | 5656 | P1 | Illinois | |
| 37 | +| 2011 | 3806535.05 | P2 | Illinois | |
| 38 | +| 2010 | 3063068.92 | P2 | Illinois | |
| 39 | +| 2013 | 2249368.86 | P2 | Illinois | |
| 40 | +| 2014 | 2110818.23 | P2 | Illinois | |
| 41 | +| 2015 | 1801392.49 | P2 | Illinois | |
| 42 | +| 2009 | 1443174.99 | P2 | Illinois | |
| 43 | +| 2016 | 1415779.09 | P2 | Illinois | |
| 44 | +| 2012 | 1187657.01 | P2 | Illinois | |
| 45 | +| 2008 | 763992.9 | P2 | Illinois | |
| 46 | +| 2017 | 140875.29 | P2 | Illinois | |
| 47 | +| 2007 | 15076.35 | P2 | Illinois | |
| 48 | +| 2013 | 12318347.12 | P1 | Indiana | |
| 49 | +| 2014 | 11855957.24 | P1 | Indiana | |
| 50 | +| 2016 | 10131630.65 | P1 | Indiana | |
| 51 | +| 2011 | 9641385.14 | P1 | Indiana | |
| 52 | +| 2012 | 9579557.84 | P1 | Indiana | |
| 53 | +| 2010 | 8432728.5 | P2 | Indiana | |
| 54 | +| 2014 | 5945924 | P2 | Indiana | |
| 55 | +| 2016 | 5619332 | P2 | Indiana | |
| 56 | + |
| 57 | +Then add the following vega specs under `vega5-spec` metadata for the uploaded file and refresh the page: |
| 58 | + |
| 59 | +```{json} |
| 60 | +{ |
| 61 | + "$schema": "https://vega.github.io/schema/vega-lite/v4.json", |
| 62 | + "mark": "bar", |
| 63 | + "data": { |
| 64 | + "format": { |
| 65 | + "type": "csv" |
| 66 | + } |
| 67 | + }, |
| 68 | + "selection": { |
| 69 | + "program": { |
| 70 | + "type": "multi", |
| 71 | + "fields": [ |
| 72 | + "program" |
| 73 | + ], |
| 74 | + "bind": "legend" |
| 75 | + } |
| 76 | + }, |
| 77 | + "encoding": { |
| 78 | + "row": { |
| 79 | + "field": "state", |
| 80 | + "title": "States" |
| 81 | + }, |
| 82 | + "x": { |
| 83 | + "field": "amount", |
| 84 | + "title": "Amount", |
| 85 | + "type": "quantitative", |
| 86 | + "axis": { |
| 87 | + "format": ",.0f" |
| 88 | + } |
| 89 | + }, |
| 90 | + "y": { |
| 91 | + "field": "date", |
| 92 | + "title": "Year" |
| 93 | + }, |
| 94 | + "color": { |
| 95 | + "field": "program", |
| 96 | + "scale": { |
| 97 | + "scheme": "category10" |
| 98 | + }, |
| 99 | + "title": "Program", |
| 100 | + "legend": { |
| 101 | + "orient": "top" |
| 102 | + } |
| 103 | + }, |
| 104 | + "opacity": { |
| 105 | + "condition": { |
| 106 | + "selection": "program", |
| 107 | + "value": 1 |
| 108 | + }, |
| 109 | + "value": 0.2 |
| 110 | + }, |
| 111 | + "tooltip": { |
| 112 | + "field": "Amount", |
| 113 | + "format": ",.01f" |
| 114 | + } |
| 115 | + } |
| 116 | +} |
| 117 | +``` |
0 commit comments