Created
May 4, 2023 17:21
-
-
Save ikiril01/f05615cd055a5f0a7d00880470c541df to your computer and use it in GitHub Desktop.
Vega spec from Thu May 04 2023
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": "A node-link diagram with force-directed layout, depicting character co-occurrence in the novel Les Misérables.", | |
"width": 700, | |
"height": 500, | |
"padding": 0, | |
"autosize": "none", | |
"signals": [ | |
{"name": "cx", "update": "width / 2"}, | |
{"name": "cy", "update": "height / 2"}, | |
{ | |
"name": "nodeRadius", | |
"value": 8, | |
"bind": {"input": "range", "min": 1, "max": 50, "step": 1} | |
}, | |
{ | |
"name": "nodeCharge", | |
"value": -30, | |
"bind": {"input": "range", "min": -100, "max": 10, "step": 1} | |
}, | |
{ | |
"name": "linkDistance", | |
"value": 30, | |
"bind": {"input": "range", "min": 5, "max": 100, "step": 1} | |
}, | |
{"name": "static", "value": true, "bind": {"input": "checkbox"}} | |
], | |
"data": [ | |
{ | |
"name": "node-data", | |
"url": "data/miserables.json", | |
"format": {"type": "json", "property": "nodes"} | |
}, | |
{ | |
"name": "link-data", | |
"url": "data/miserables.json", | |
"format": {"type": "json", "property": "links"} | |
} | |
], | |
"scales": [ | |
{ | |
"name": "color", | |
"type": "ordinal", | |
"domain": {"data": "node-data", "field": "group"}, | |
"range": {"scheme": "category20c"} | |
} | |
], | |
"marks": [ | |
{ | |
"name": "nodes", | |
"type": "symbol", | |
"zindex": 1, | |
"from": {"data": "node-data"}, | |
"encode": { | |
"enter": { | |
"fill": {"scale": "color", "field": "group"}, | |
"stroke": {"value": "white"} | |
}, | |
"update": { | |
"size": {"signal": "2 * nodeRadius * nodeRadius"}, | |
"cursor": {"value": "pointer"} | |
} | |
}, | |
"transform": [ | |
{ | |
"type": "force", | |
"iterations": 300, | |
"static": {"signal": "static"}, | |
"signal": "force", | |
"forces": [ | |
{"force": "center", "x": {"signal": "cx"}, "y": {"signal": "cy"}}, | |
{"force": "collide", "radius": {"signal": "nodeRadius"}}, | |
{"force": "nbody", "strength": {"signal": "nodeCharge"}}, | |
{ | |
"force": "link", | |
"links": "link-data", | |
"distance": {"signal": "linkDistance"} | |
} | |
] | |
} | |
] | |
}, | |
{ | |
"type": "path", | |
"from": {"data": "link-data"}, | |
"interactive": false, | |
"encode": { | |
"update": {"stroke": {"value": "#ccc"}, "strokeWidth": {"value": 0.5}} | |
}, | |
"transform": [ | |
{ | |
"type": "linkpath", | |
"require": {"signal": "force"}, | |
"shape": "line", | |
"sourceX": "datum.source.x", | |
"sourceY": "datum.source.y", | |
"targetX": "datum.target.x", | |
"targetY": "datum.target.y" | |
} | |
] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment