#!/bin/sh -- # \ exec jq -rf "$0" -- "$@" def children: objects | .path as $p | (.firstChild | objects | .path = $p + "/1"), (.secondChild | objects | .path = $p + "/2") | select(has("id")); def isInnerNode: .firstChild != null; def isNonVacantLeaf: isInnerNode or .vacant | not; def pathString: "@" + (.path // "/"); def node: "\t\(.id) \( "[color=\( . as $node | [ limit(2; recurse(children) | select(isNonVacantLeaf)) ] | length | if . == 0 then if $node.client != null then "red" # vacant window else "grey" # fully vacant inner node end elif . == 1 then if $node.client != null then "green" # window elif isempty($node | children) then "blue" # receptacle else "yellow" # inner node with single non-vacant end else empty # normal inner node end )]", "[label=\"\( [ pathString, ( select( [ children ] | length != 0 and all(any(recurse(children); isNonVacantLeaf)) ) | "\( if .splitType == "vertical" then "V" else "H" end ):\(.splitRatio)" ), .id, ( select(isNonVacantLeaf) | ( .rectangle | objects | "\(.width)x\(.height)+\(.x)+\(.y)" ), ( .client | objects | "\(.className):\(.instanceName)" ) ) | tostring | gsub("[\\\\\"]"; "\\" + .) ] | join("\\n") )\"]", "-> \(children.id | values)" );"; "digraph BSPTree {", ( objects.root | objects | recurse(children) | node ), "}"