Skip to content

Commit

Permalink
Merge pull request #44 from Z2h-A6n/center-root
Browse files Browse the repository at this point in the history
Center root node
  • Loading branch information
Kharacternyk authored Sep 7, 2020
2 parents 33a4fab + d873c30 commit 8acc6fb
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 6 deletions.
11 changes: 10 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ Customizations can be made on the command line, see the options with
If OUTLINE value is bigger than 1, then OUTLINE-1 additional circles are drawn
around the corresponding packages.
ROOT is the package that will be put in the center of the graph.
ROOT is the package that will be put in the center of the graph. If not
specified, a package will be chosen, and the graph may be slightly off center.
RANKSEP is the distance in **inches** between the concentric circles.
OUTPUT is the path where the generated image is put.
SCREEN_SIZE makes sense to set only if -D is enabled and you're on Wayland.
Expand Down Expand Up @@ -192,6 +193,14 @@ If the graph is too large/small, use ``-r``.
For example, ``-r 0.3`` means that the distance between the concentric circles
of the graph will be 0.3 **inch**.

~~~~~~~~~~~~~~~~~~~
Centering the graph
~~~~~~~~~~~~~~~~~~~
If the ``-c ROOT`` option is not used to specify a pacage to put at the center of
the graph, one will be chosen (see the ``twopi`` man page). In this case, the
central node will likely be somewhat off center in the resulting image.
Specifying a root package will fix this.

------------
Contributors
------------
Expand Down
35 changes: 30 additions & 5 deletions pacwall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ use_xresources_colors() {
render_graph() {
# Style the graph according to preferences.
declare -a twopi_args=(
'-Tpng' 'pacwall.gv'
'-O' '-Tpng' '-Tplain' 'pacwall.gv'
"-Gbgcolor=${BACKGROUND}"
"-Granksep=${RANKSEP}"
"-Ecolor=${EDGE}"
Expand All @@ -304,7 +304,29 @@ render_graph() {
# Optional arguments
[[ -n $ROOT ]] && twopi_args+=("-Groot=${ROOT}")

twopi "${twopi_args[@]}" > pacwall.png
twopi "${twopi_args[@]}"
}

center_root() {
[[ -z $ROOT ]] && return 0
HEADLINE=($(head -n1 pacwall.gv.plain))
GPHW=${HEADLINE[2]}
GPHH=${HEADLINE[3]}
ROOTLINE=($(grep -E "node \"?$ROOT\"? " pacwall.gv.plain))
ROOTX=${ROOTLINE[2]}
ROOTY=${ROOTLINE[3]}
IMGW=$(convert pacwall.gv.png -print '%w\n' /dev/null)
IMGH=$(convert pacwall.gv.png -print '%h\n' /dev/null)
XOFFSET=$(bc <<< "scale=5; $IMGW*(2.0*$ROOTX/$GPHW-1.0)")
YOFFSET=$(bc <<< "scale=5; $IMGH*(2.0*$ROOTY/$GPHH-1.0)")
# Set -gravity string depending on absolute values of XOFFSET and YOFFSET
[[ $XOFFSET = -* ]] && GRAVX='west' || GRAVX='east'
[[ $YOFFSET = -* ]] && GRAVY='south' || GRAVY='north'
convert pacwall.gv.png \
-background "$BACKGROUND" \
-gravity "$GRAVY$GRAVX" \
-splice ${XOFFSET#-}x${YOFFSET#-} \
pacwall.gv.png
}

set_wallpaper() {
Expand All @@ -325,7 +347,7 @@ set_wallpaper() {
#TODO: handle if neither exists
fi

convert pacwall.png \
convert pacwall.gv.png \
-gravity center \
-background "${BACKGROUND}" \
-extent "${SCREEN_SIZE}" \
Expand Down Expand Up @@ -386,7 +408,9 @@ main() {

render_graph

cp "${WORKDIR}/pacwall.png" "${OUTPUT}"
center_root

cp "${WORKDIR}/pacwall.gv.png" "${OUTPUT}"

if [[ -z $IMAGE_ONLY ]]; then
set_wallpaper
Expand Down Expand Up @@ -433,7 +457,8 @@ help() {
If OUTLINE value is bigger than 1, then OUTLINE-1 additional circles are drawn
around the corresponding packages.
ROOT is the package that will be put in the center of the graph.
ROOT is the package that will be put in the center of the graph. If not
specified, a package will be chosen, and the graph may be slightly off center.
RANKSEP is the distance in **inches** between the concentric circles.
OUTPUT is the path where the generated image is put.
SCREEN_SIZE makes sense to set only if -D is enabled and you're on Wayland.
Expand Down

0 comments on commit 8acc6fb

Please sign in to comment.