Skip to content

Instantly share code, notes, and snippets.

@ikiril01
Created May 10, 2023 20:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ikiril01/e6bf7cc9fb9e933abe008a9f3ad43b47 to your computer and use it in GitHub Desktop.
Save ikiril01/e6bf7cc9fb9e933abe008a9f3ad43b47 to your computer and use it in GitHub Desktop.
Vega spec from Wed May 10 2023
{
"$schema": "https://vega.github.io/schema/vega/v5.json",
"width": 500,
"height": 500,
"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": -15,
"bind": {"input": "range", "min": -500, "max": 5, "step": 1}
},
{
"name": "$linkDistance",
"value": 80,
"bind": {"input": "range", "min": 5, "max": 500, "step": 1}
},
{"name": "$static", "value": true}
],
"data": [
{
"name": "zeek-conn",
"url": "https://gist.githubusercontent.com/aaron-nimocks/2dc737872e09dfed25cd2873273109d4/raw/4335626d3ccd21bf3f40e4c931aeec9eb24cdf40/network.json",
"format": {"property": "hits.hits"},
"transform": [
{
"type": "formula",
"as": "source",
"expr": "datum['_source']['id.orig_h']"
},
{
"type": "formula",
"as": "target",
"expr": "datum['_source']['id.resp_h']"
},
{
"type": "formula",
"as": "source_port",
"expr": "datum['_source']['id.orig_p']"
},
{
"type": "formula",
"as": "target_port",
"expr": "datum['_source']['id.resp_p']"
},
{
"type": "project",
"fields": [
"source",
"target",
"source_port",
"target_port",
"_source.proto"
],
"as": ["source", "target", "source_port", "target_port", "proto"]
}
]
},
{
"name": "node-data",
"source": "zeek-conn",
"transform": [
{"type": "fold", "fields": ["source", "target"]},
{
"type": "aggregate",
"groupby": ["value"],
"fields": ["conn_state"],
"ops": ["values"]
},
{
"type": "project",
"fields": ["value", "values_conn_state"],
"as": ["name", "conn_state"]
},
{"type": "identifier", "as": "index"},
{"type": "formula", "as": "index", "expr": "datum['index'] - 1"},
{
"type": "formula",
"as": "conn_state",
"expr": "datum['conn_state'][0]['conn_state']"
}
]
},
{
"name": "link-data",
"source": "zeek-conn",
"transform": [
{
"type": "lookup",
"from": "node-data",
"key": "name",
"fields": ["source", "target"],
"as": ["source", "target"]
},
{"type": "formula", "as": "source", "expr": "datum['source']['index']"},
{"type": "formula", "as": "target", "expr": "datum['target']['index']"}
]
},
{"name": "test-data", "source": "link-data"}
],
"scales": [
{
"name": "color",
"type": "ordinal",
"reverse": false,
"domain": {"data": "zeek-conn", "field": "proto"},
"range": {"scheme": "category20"}
}
],
"legends": [
{
"fill": "color",
"orient": "top-left",
"encode": {
"title": {"update": {"fontSize": {"value": 14}}},
"labels": {
"interactive": true,
"update": {"fontSize": {"value": 12}, "fill": {"value": "black"}},
"hover": {"fill": {"value": "firebrick"}}
},
"symbols": {"update": {"stroke": {"value": "transparent"}}},
"legend": {"update": {}}
}
}
],
"marks": [
{
"name": "nodes",
"type": "symbol",
"zindex": 1,
"from": {"data": "node-data"},
"encode": {
"enter": {"fill": {"value": "black"}, "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": {"scale": "color", "field": "proto"},
"strokeWidth": {"value": 2}
}
},
"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