Created
April 29, 2020 14:58
-
-
Save jaidevd/063ddbc6af46b97c6167370f8ee10490 to your computer and use it in GitHub Desktop.
Vega Treemap Spec
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": "An example of treemap layout for hierarchical data.", | |
"width": 960, | |
"height": 500, | |
"padding": 2.5, | |
"autosize": "none", | |
"scales": [ | |
{ | |
"name": "color", | |
"type": "ordinal", | |
"domain": {"data": "nodes", "field": "name"}, | |
"range": [ | |
"#3182bd", "#6baed6", "#9ecae1", "#c6dbef", "#e6550d", | |
"#fd8d3c", "#fdae6b", "#fdd0a2", "#31a354", "#74c476", | |
"#a1d99b", "#c7e9c0", "#756bb1", "#9e9ac8", "#bcbddc", | |
"#dadaeb", "#636363", "#969696", "#bdbdbd", "#d9d9d9" | |
] | |
}, | |
{ | |
"name": "size", | |
"type": "ordinal", | |
"domain": [0, 1, 2, 3], | |
"range": [256, 28, 20, 14] | |
}, | |
{ | |
"name": "opacity", | |
"type": "ordinal", | |
"domain": [0, 1, 2, 3], | |
"range": [0.15, 0.5, 0.8, 1.0] | |
} | |
], | |
"marks": [ | |
{ | |
"type": "rect", | |
"from": {"data": "nodes"}, | |
"interactive": false, | |
"encode": { | |
"enter": { | |
"fill": {"scale": "color", "field": "name"} | |
}, | |
"update": { | |
"x": {"field": "x0"}, | |
"y": {"field": "y0"}, | |
"x2": {"field": "x1"}, | |
"y2": {"field": "y1"} | |
} | |
} | |
}, | |
{ | |
"type": "rect", | |
"from": {"data": "leaves"}, | |
"encode": { | |
"enter": { | |
"stroke": {"value": "#fff"} | |
}, | |
"update": { | |
"x": {"field": "x0"}, | |
"y": {"field": "y0"}, | |
"x2": {"field": "x1"}, | |
"y2": {"field": "y1"}, | |
"fill": {"value": "transparent"} | |
}, | |
"hover": { | |
"fill": {"value": "red"} | |
} | |
} | |
}, | |
{ | |
"type": "text", | |
"from": {"data": "nodes"}, | |
"interactive": false, | |
"encode": { | |
"enter": { | |
"font": {"value": "Helvetica Neue, Arial"}, | |
"align": {"value": "center"}, | |
"baseline": {"value": "middle"}, | |
"fill": {"value": "#000"}, | |
"text": {"field": "name"}, | |
"fontSize": {"scale": "size", "field": "depth"}, | |
"fillOpacity": {"scale": "opacity", "field": "depth"} | |
}, | |
"update": { | |
"x": {"signal": "0.5 * (datum.x0 + datum.x1)"}, | |
"y": {"signal": "0.5 * (datum.y0 + datum.y1)"} | |
} | |
} | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment