From 15986f7468f772da86d6bba232d257c557ea8c84 Mon Sep 17 00:00:00 2001 From: Pascal Date: Sun, 28 Feb 2021 23:46:38 -0500 Subject: [PATCH] [add] added legend alignment option --- plotter/pinger.gp | 8 +++++++- plotter/plot.sh | 20 +++++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/plotter/pinger.gp b/plotter/pinger.gp index 0a4fabf..83f1b10 100644 --- a/plotter/pinger.gp +++ b/plotter/pinger.gp @@ -19,7 +19,11 @@ col_average=5 col_max=6 col_deviation=7 +# legend alignment +legend_align="center" + if(exists("TZ")) tz=TZ*3600 +if(exists("LEGEND_ALIGN")) legend_align=LEGEND_ALIGN # gnuplot does not like spaces in -e so we recreate them here via system call to sed if(exists("SERVERS")) server_list=system("echo '".SERVERS."' | sed 's|;| |g'") if(exists("CSV_FILE")) csv_file=CSV_FILE @@ -46,7 +50,9 @@ set key box lt rgb "#000000" set key width 1.5 set key height 0.5 set key samplen 0.1 -set key center top +if (legend_align eq "left") set key left top +if (legend_align eq "center") set key center top +if (legend_align eq "right") set key right top ## axis set y2tics # enable second axis set ytics nomirror # dont show the tics on that side diff --git a/plotter/plot.sh b/plotter/plot.sh index 92b5ba1..a25ec8d 100755 --- a/plotter/plot.sh +++ b/plotter/plot.sh @@ -5,6 +5,7 @@ Backup Script Version $script_version usage: SERVER:LABEL [...] [--file|-f CSV_FILE] [--limit-y|-l Y_MAX] [--time-zone|-t UTC_HOURS] [--start-date|-S DATE] [--end-date|-E DATE] [--show-hours|-H HOURS] + [--align-legend|-a POSITION] args: SERVER:LABEL [...] Space sperated list of servers to plot. Needs to be before any other args. @@ -34,6 +35,10 @@ Backup Script Version $script_version --show-hours|-H HOURS HOURSE defaults to $default_hours and sets the Y Axis starting point HOURS before the end point. Will be overwritten by -s if declared later. + + --align-legend|-a POSITION + POSITION can be left, center or right and aligns the legend of the plot. + Default is $default_align alignment. example: ${BASH_SOURCE[0]} example.com:example 0.0.0.0:localhost --limit-y 100 --show-hours 5 --end-date "$(date +"%Y-%m-%d %H:%M")" --time-zone $(date +%-:::z) ${BASH_SOURCE[0]} example.com:example 0.0.0.0:localhost -S "$(date --date='yesterday' +"%Y-%m-%d")" -E "$(date +"%Y-%m-%d")" -f data.csv @@ -56,6 +61,7 @@ default_start_date=$(date --date="1 week ago" -Is) default_end_date=$(date -Is) default_hours=24 default_tz=$(date +%-:::z) +default_align=center # end configuration ############################## @@ -131,7 +137,8 @@ main() { local unknown_args=() local servers=$(load_server_env) - local csv_file="$default_csv" limit time_zone="$default_tz" start_date end_date hours + local csv_file="$default_csv" + local limit time_zone="$default_tz" start_date end_date hours legend="$default_align" # if servers passed as args reset list and parse [[ $# -gt 0 ]] && [[ $1 != -* ]] && servers="" @@ -205,6 +212,16 @@ main() shift # past value fi ;; + --align-legend|-a) + if [[ $2 == -* ]] || [[ -z "$2" ]]; then + echo "log WAR main Invalid legend alignment, using default: $legend" + shift # past argument, no value + else + legend=$2 + shift # past argument + shift # past value + fi + ;; --help|-h) help exit @@ -230,6 +247,7 @@ main() [[ ! -z "$start_date" ]] && plot_env[X_MIN]=$start_date [[ ! -z "$end_date" ]] && plot_env[X_MAX]=$end_date [[ ! -z "$hours" ]] && set_relative_X_MIN $hours + [[ ! -z "$legend" ]] && plot_env[LEGEND_ALIGN]=\"$legend\" [[ ${#unknown_args[@]} -ne 0 ]] && log main WARNING "ignored unknown args: ${unknown_args[@]}"