forked from tyleradams/json-toolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjson-to-plot
More file actions
executable file
·50 lines (42 loc) · 1.16 KB
/
json-to-plot
File metadata and controls
executable file
·50 lines (42 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env bash
DATA="$(cat | jq '.')"
TITLE="$(echo "$DATA" | jq '.Title')"
XLABEL="$(echo "$DATA" | jq '.XLabel')"
YLABEL="$(echo "$DATA" | jq '.YLabel')"
OUTFILE="$1"
OUTFILE_EXTENSION="$(echo "$OUTFILE" | cut -d '.' -f 2-)"
if [ -z "$DATA" ]; then
echo "stdin must be valid json"
exit 1
fi
if [ -z "$TITLE" ]; then
echo ".Title must be set"
exit 1
fi
if [ -z "$XLABEL" ]; then
echo ".XLabel must be set"
exit 1
fi
if [ -z "$YLABEL" ]; then
echo ".YLabel must be set"
exit 1
fi
if [ -z "$OUTFILE" ]; then
echo "OUTFILE must be specified as argv[1]"
exit 1
fi
if [ "$OUTFILE_EXTENSION" != "png" ]; then
echo "OUTFILE must be a png"
exit 1
fi
echo "$DATA" | jq '.data' | json-to-dsv '#' | gnuplot \
-e "set terminal png enhanced font 'verdana,8' size 1920,1080" \
-e "set title '$TITLE'" \
-e "set xlabel '$XLABEL'" \
-e "set ylabel '$YLABEL'" \
-e "set output '$OUTFILE'" \
-e "set datafile separator '#'" \
-e "set nokey" \
-e "set border linewidth 1.5" \
-e "set style line 1 lc rgb '#0060ad' pt 7 ps .2 lt 1 lw 2 # --- blue" \
-e "plot '< cat -' using 2:xticlabels(1) with lines ls 1"