Last active
May 1, 2020 16:42
-
-
Save dalcib/88483ba2999dab017be2239ddceae922 to your computer and use it in GitHub Desktop.
Vega
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"$schema": "https://vega.github.io/schema/vega/v5.json", | |
"width": 400, | |
"height": 400, | |
"padding": 5, | |
"signals": [ | |
{ | |
"name": "method", | |
"value": "squarify", | |
"bind": { | |
"input": "select", | |
"options": [ | |
"squarify", | |
"resquarify", | |
"binary", | |
"dice", | |
"slice", | |
"slicedice" | |
] | |
} | |
}, | |
{ | |
"name": "ratio", | |
"value": 1.6108, | |
"bind": {"input": "range", "min": 0.2, "max": 5, "step": 0.1} | |
} | |
], | |
"data": [ | |
{ | |
"name": "gapminder", | |
"url": "https://gist.githubusercontent.com/amitkaps/afc67606c057d1c8021d0f8e0d2cfa3e/raw/d7634900505d94ebb4eef0746f4c046f7cf42f7d/gapminder.csv", | |
"format": {"type": "csv"}, | |
"transform": [ | |
{"type": "nest", "keys": ["continent", "country"]}, | |
{ | |
"type": "treemap", | |
"field": "pop", | |
"method": {"signal": "method"}, | |
"ratio": {"signal": "ratio"}, | |
"paddingInner": 1, | |
"size": [{"signal": "width"}, {"signal": "height"}] | |
} | |
] | |
} | |
], | |
"scales": [ | |
{ | |
"name": "color", | |
"type": "ordinal", | |
"domain": {"data": "gapminder", "field": "continent"}, | |
"range": {"scheme": "category20"} | |
} | |
], | |
"marks": [ | |
{ | |
"type": "rect", | |
"from": {"data": "gapminder"}, | |
"encode": { | |
"update": { | |
"x": {"field": "x0"}, | |
"y": {"field": "y0"}, | |
"x2": {"field": "x1"}, | |
"y2": {"field": "y1"}, | |
"fill": {"scale": "color", "field": "continent", "opacity": 0.5}, | |
"tooltip": {"signal": "datum"} | |
} | |
} | |
} | |
] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"$schema": "https://vega.github.io/schema/vega/v5.json", | |
"description": "todo", | |
"title": "Treemap", | |
"width": 400, | |
"height": 250, | |
"padding": 5, | |
"autosize": {"type": "fit", "contains": "padding"}, | |
"data": [ | |
{ | |
"name": "table", | |
"values": [{"Category":"Technology","Sub-Category":"Phones","Sales":330007.05},{"Category":"Technology","Sub-Category":"Machines","Sales":189238.63},{"Category":"Technology","Sub-Category":"Copiers","Sales":149528.03},{"Category":"Technology","Sub-Category":"Accessories","Sales":167380.32},{"Category":"Office Supplies","Sub-Category":"Supplies","Sales":46673.54},{"Category":"Office Supplies","Sub-Category":"Storage","Sales":223843.61},{"Category":"Office Supplies","Sub-Category":"Paper","Sales":78479.21},{"Category":"Office Supplies","Sub-Category":"Labels","Sales":12486.31},{"Category":"Office Supplies","Sub-Category":"Fasteners","Sales":3024.28},{"Category":"Office Supplies","Sub-Category":"Envelopes","Sales":16476.4},{"Category":"Office Supplies","Sub-Category":"Binders","Sales":203412.73},{"Category":"Office Supplies","Sub-Category":"Art","Sales":27118.79},{"Category":"Office Supplies","Sub-Category":"Appliances","Sales":107532.16},{"Category":"Furniture","Sub-Category":"Tables","Sales":206965.53},{"Category":"Furniture","Sub-Category":"Furnishings","Sales":91705.16},{"Category":"Furniture","Sub-Category":"Chairs","Sales":328449.1},{"Category":"Furniture","Sub-Category":"Bookcases","Sales":114880}], | |
"transform": [ | |
{ | |
"type" : "nest", | |
"keys": ["Category", "Sub-Category"] | |
}, | |
{ | |
"type": "treemap", | |
"field": "Sales", | |
"ratio": 1, | |
"paddingInner": 1, | |
"size": [{"signal": "width"}, {"signal": "height"}] | |
} | |
] | |
} | |
], | |
"scales": [ | |
{ | |
"name": "color", | |
"type": "ordinal", | |
"domain": {"data": "table", "field": "Category"}, | |
"range": ["#96cbff", "#1A8CFF", "#115DAA", "#082A4D"] | |
} | |
], | |
"marks": [ | |
{ | |
"type": "rect", | |
"from": {"data": "table"}, | |
"encode": { | |
"update": { | |
"x": {"field": "x0"}, | |
"y": {"field": "y0"}, | |
"x2": {"field": "x1"}, | |
"y2": {"field": "y1"}, | |
"fill": {"scale": "color", "field": "Category"}, | |
"tooltip": {"signal": "datum"} | |
} | |
} | |
}, | |
{ | |
"type": "text", | |
"from": {"data": "table"}, | |
"encode": { | |
"update": { | |
"dx": {"value": 2}, | |
"dy": {"value": 10}, | |
"x": {"field": "x0"}, | |
"y": {"field": "y0"}, | |
"text": [ | |
{"test": "(datum.y1-datum.y0<20) || (datum.x1-datum.x0<30)", "value": ""}, | |
{"field": "Sub-Category"}], | |
"fill": {"value": "white"} | |
} | |
} | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment