Created
September 21, 2024 16:59
-
-
Save PBI-DataVizzle/8812f85988583978d7c742f111deaf79 to your computer and use it in GitHub Desktop.
radial_sunburst_v3
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 a space-fulling radial layout for hierarchical data.", | |
| "width": 600, | |
| "height": 600, | |
| "padding": 5, | |
| "autosize": "none", | |
| "data": [ | |
| { | |
| "name": "tree", | |
| "url": "data/flare.json", | |
| "transform": [ | |
| {"type": "stratify", "key": "id", "parentKey": "parent"}, | |
| { | |
| "type": "partition", | |
| "field": "size", | |
| "sort": {"field": "value"}, | |
| "size": [{"signal": "2 * PI"}, {"signal": "width / 2"}], | |
| "as": ["a0", "r0", "a1", "r1", "depth", "children"] | |
| }, | |
| { | |
| "type": "formula", | |
| "expr": "datum.depth === 0 ? 'white' : datum.color", | |
| "as": "color" | |
| }, | |
| { | |
| "type": "formula", | |
| "expr": "datum.depth > 2 && length(datum.name) > 10 ? slice(datum.name, 0, 10) + '\\n ' + slice(datum.name, 10) : datum.name", | |
| "as": "wrappedText" | |
| } | |
| ] | |
| } | |
| ], | |
| "scales": [ | |
| { | |
| "name": "color", | |
| "type": "ordinal", | |
| "domain": {"data": "tree", "field": "depth"}, | |
| "range": {"scheme": "tableau20"} | |
| } | |
| ], | |
| "marks": [ | |
| { | |
| "type": "arc", | |
| "from": {"data": "tree"}, | |
| "encode": { | |
| "enter": { | |
| "x": {"signal": "width / 2"}, | |
| "y": {"signal": "height / 2"}, | |
| "fill": {"scale": "color", "field": "depth"}, | |
| "tooltip": {"signal": "datum.name"} | |
| }, | |
| "update": { | |
| "startAngle": {"field": "a0"}, | |
| "endAngle": {"field": "a1"}, | |
| "innerRadius": {"field": "r0"}, | |
| "outerRadius": {"field": "r1"}, | |
| "stroke": {"value": "white"}, | |
| "strokeWidth": {"value": 0.5}, | |
| "zindex": {"value": 0} | |
| }, | |
| "hover": { | |
| "stroke": {"value": "red"}, | |
| "strokeWidth": {"value": 2}, | |
| "zindex": {"value": 1} | |
| } | |
| } | |
| }, | |
| { | |
| "type": "text", | |
| "from": {"data": "tree"}, | |
| "encode": { | |
| "enter": { | |
| "fill": {"value": "black"}, | |
| "align": { | |
| "signal": "datum.depth > 2 ? (datum.a0 < PI ? 'left' : 'left') : 'center'" | |
| }, | |
| "baseline": {"value": "middle"}, | |
| "text": {"field": "wrappedText"}, | |
| "x": {"signal": "width / 2"}, | |
| "y": {"signal": "height / 2"}, | |
| "radius": { | |
| "signal": "datum.depth > 2 ? (datum.a0 > PI ? datum.r0 + 55: datum.r0 + 5) : datum.r0 + 15 " | |
| }, | |
| "theta": {"signal": "(datum.a0 + datum.a1) / 2"}, | |
| "fontSize": {"signal": "(datum.r1 - datum.r0) > 20 ? 10 : 8"}, | |
| "opacity": {"signal": "(datum.r1 - datum.r0) > 20 ? 1 : 0.5"}, | |
| "angle": { | |
| "signal": " datum.depth > 0 ? (datum.a0 < PI ? ((datum.a0 + datum.a1) / 2) * (180 / PI) - 90 : ((datum.a0 + datum.a1) / 2) * (180 / PI) + 90) : 0" | |
| } | |
| } | |
| } | |
| } | |
| ] | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment