#!/bin/sh -- # \ exec jq -Crf "$0" -- "$@" def children: objects | .path as $p | (.firstChild | objects | .path = $p + "/1"), (.secondChild | objects | .path = $p + "/2") | select(has("id")); def isInnerNode: any(children; true); def isNonVacantLeaf: .vacant or isInnerNode | not; def numberOfBranchesWithNonVacantLeaves: [ children | select(any(recurse(children); isNonVacantLeaf)) ] | length; def pathString: "@\(.path // "/")"; def node: "\t\(.id) \( "[color=\( if isInnerNode then numberOfBranchesWithNonVacantLeaves | if . == 0 then "gray" # fully vacant inner node elif . == 1 then "yellow" # non-splitting inner node else empty # splitting inner node end elif .vacant then "red" # vacant window elif .client != null then "green" # non-vacant window else "blue" # receptacle end )]", "[label=<\( [ pathString, ( select(numberOfBranchesWithNonVacantLeaves == 2) | "\( if .splitType == "vertical" then "V" else "H" end ):\(.splitRatio)" ), .id, ( select(isNonVacantLeaf).rectangle | objects | "\(.width)x\(.height)+\(.x)+\(.y)" ), ( .client | objects | @json "\(.className):\(.instanceName)" ) | @html ] | join("
") )>]", "-> \(children.id | values)" );"; "digraph BSPTree {", ( objects.root | select(type == "object" and (.path | type | IN("string", "null"))) | recurse(children) | node ), "}"