#!/bin/bash
# doc/tool/graphviz - dynamic graph generation support

set -e


######
# Native dependencies

doc_tool_graphviz_client_packages=( graphviz )


######
# Settings

doc_tool_graphviz_config_init() {
	lib_setting_vars --null dot_node_attr
}


######
# Internal functions

_dot_graph() {
	min_args 3 "$@"
	local kind=$1
	local name=$2
	shift 2
	local tmp
	tmp=$(cmd_tempfile)
	"$@" >"$tmp"
	[ -s "$tmp" ] || return 0

	echo "$kind $name {"
	cat "$tmp"
	echo "}"
}


######
# Graph generation

dot_graph() { _dot_graph graph "$@"; }
dot_digraph() { _dot_graph digraph "$@"; }

dot_node_list() {
	local str
	for node in "$@"; do
		str="$str${str:+ -> }\"$node\""
	done
	echo "  $str${dot_node_attr:+ }$dot_node_attr;"
}


######
# Output generation

graphviz_dot() {
	local kind=$1
	local src=$2
	local dst=${3:-$src.$kind}
	run dot -T$1 "$src" -o "$dst"
}
graphviz_dot_ps() { graphviz_dot ps "$@"; }
graphviz_dot_pdf() { graphviz_dot pdf "$@"; }
graphviz_dot_svg() { graphviz_dot svg "$@"; }
graphviz_dot_imap() { graphviz_dot imap "$@"; }
graphviz_dot_cmapx() { graphviz_dot cmapx "$@"; }

View the Developer Guide Index

View the Reference Manual Index


Generated on Fri Jul 28 14:35:38 PDT 2017 by mcsh d14 v0.23.0.