#! /bin/bash
# Last edited on 2014-07-12 14:27:42 by stolfilocal

# Plots the "Rise and Sise of Bitcoin" graph.

# Arguments are 
#
#   [ "SHOW" | "NOSHOW" ]
#

show="$1"; shift

title="The Rise and Rise of Bitcoin"
name="risenrise"

color=( '#0022ff' '#ff0000' '#008800' '#8800dd' '#dd4400' '#0066ff' )

dfile="${name}-data.txt"
pngfile="${name}-plot.png"
rm -f ${pngfile} 

tmp="/tmp/$$"
 
export GDFONTPATH=.
 
gnuplot <<EOF
set term png size 1800,900 font "courbd,24"
set output "${tmp}.png"
set title "${title}" 

set xtics 1.0
set mxtics 4
set format x "%.0f"

set xrange [2008.5:2019.5]
set grid xtics lt 1 lw 3 lc rgb '#ffddaa', lt 1 lw 1.5 lc rgb '#ffddaa'

set yrange [-0.01:11.9]
unset ytics
unset mytics
set y2tics ( "FOO" -100 )
unset my2tics
set grid y2tics lt 1 lw 3 lc rgb '#ffddaa', lt 1 lw 1.5 lc rgb '#ffddaa'

set key top left invert

plot \
  "${dfile}" using 3:4:y2ticlabels(5) title 'planned'  with linespoints pt 7 ps 2 lc rgb '#cc0000', \
  ""         using 1:4:y2ticlabels(5) title 'done'     with linespoints pt 7 ps 4 lc rgb '#0022cc'

EOF

#  ""         using 2:4:y2ticlabels(5) title 'underway' with      points pt 6 ps 5 lc rgb '#', \


if [[ -s ${tmp}.png ]]; then 
  convert ${tmp}.png -resize '50%' ${pngfile}

  if [[ "/${show}" == "/SHOW" ]]; then
    display ${pngfile}
  fi
fi
