#!/bin/bash

typeset -i idx=1

function hl()
{
  local x1="$1"
  local y="$2"
  local x2="$3"
  local lt=${4:-"rgbcolor \"#0000FF\""} 
  local label="$5"
  local labelpos="$6"

  echo "set arrow $idx from $x1,$y to $x2,$y nohead front lt $lt lw 2"
  ((idx++))
  if [[ -n $label ]]; then
    if [[ -n $labelpos ]]; then
      echo "set label $idx \"$label\" at $labelpos center arial,10"
    else
	echo "set label $idx \"$label\" at $(( x1 + (x2 - x1)/2 )),$y center arial,10"
    fi
    ((idx++))
  fi
}

function vl()
{
  local x=$1
  local lt=${2:-"rgbcolor \"#00FF00\""} 
  local label="$3"
  local labelpos="$4"

  echo "set arrow $idx from $x, graph 0 to $x, graph 1 nohead front lt $lt lw 2"
  ((idx++))
  if [[ -n "$label" ]]; then 
    if [[ -n $labelpos ]]; then
	echo "set label $idx \"$label\" at $labelpos right font \"arial,10\""
    else
      echo "set label $idx \"$label\" at $x, graph 0.8 right font \"arial,10\""
    fi
    ((idx++))
  fi
}

function rect()
{
    local x1="$1"
    local x2="$2"
    local y1=${3:-"graph 0"}
    local y2=${4:-"graph 1"}
    local fc=${5:-"rgbcolor \"#7F7F7F\""}
    local label=$6
    local labelpos="$7"
    local fs=${8:-"transparent solid 0.5 noborder"}

    echo "set object $idx rectangle from $x1,$y1 to $x2,$y2 behind fc $fc fs $fs"
    ((idx++))
    if [[ -n "$label" ]]; then
      if [[ -n $labelpos ]]; then
         echo "set label $idx \"$label\" at $labelpos center arial,10"
      else 
         echo "set label $idx \"$label\" at $(( x1 + ((x2-x1)/2) )),$(( y1 + ((y2-y1)/2) )) center arial,10"
      fi
      ((idx++))
    fi
}

function pt()
{
    local x="$1"
    local y="$2"
    local fc=${3:-"rgbcolor \"#FF0000\""}
    local label=${4:-"$x,$y"}
    local fs=${5:-"empty"}
    local lw=${6:-"1"}

    echo "set object $idx cicle at $x,$y size 3 front fc $fc fs $fs lw $lw"
    ((idx++))
    echo "set label $idx \"$label\" at $x,$((y+5)) center arial,10"
    ((idx++))
}

#pt 45 300 
#pt 100 200 "rgbcolor #00FF00" "This is a point"

#rect 0 0 500 500
#rect 100 300 200 400 "rgbcolor #00FF00" "My region"
#rect 200 "graph 0" 400 "graph 1" "rgbcolor #0000FF" "node 13413" "300,graph 0.5" 

eval "$@"
