-
Notifications
You must be signed in to change notification settings - Fork 1
/
csv2pivot
executable file
·47 lines (37 loc) · 3.78 KB
/
csv2pivot
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
#!/bin/sh
# Optionally take an input file
if [ "$#" -gt 1 ] ; then
echo "Too many options"
exit 1
elif [ "$#" = 1 ] ; then
FILE="pivottable.html"
CSV="$1"
else
echo "Path to csv file needed"
exit 1
fi
# Check environment
if [ ! -f "$CSV" ] ; then
echo "$CSV was not found"
exit 1
fi
if [ -f "$FILE" ] ; then
echo -n "$FILE exists. Delete it (y/n)? "
read answer
if [ "$answer" != "${answer#[Yy]}" ] ; then
rm -f $FILE
fi
fi
PREAMBLE='<!DOCTYPE html><html><head><meta charset="UTF-8"><title>PivotTable</title><!-- Original html is found in the pivottablejs python module - MIT License --><!-- external libs from cdnjs --><link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/c3/0.4.11/c3.min.css"><script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script><script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/c3/0.4.11/c3.min.js"></script><script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script><script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script><script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery-csv/0.71/jquery.csv-0.71.min.js"></script><link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/pivottable/2.19.0/pivot.min.css"><script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pivottable/2.19.0/pivot.min.js"></script><script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pivottable/2.19.0/d3_renderers.min.js"></script><script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pivottable/2.19.0/c3_renderers.min.js"></script><script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pivottable/2.19.0/export_renderers.min.js"></script><style>body {font-family: Verdana;} .node { border: solid 1px white; font: 10px sans-serif; line-height: 12px; overflow: hidden; position: absolute; text-indent: 2px; } .c3-line, .c3-focused {stroke-width: 3px !important;} .c3-bar {stroke: white !important; stroke-width: 1;} .c3 text { font-size: 12px; color: grey;} .tick line {stroke: white;} .c3-axis path {stroke: grey;} .c3-circle { opacity: 1 !important; } .c3-xgrid-focus {visibility: hidden !important;} </style> </head> <body> <script type="text/javascript"> $(function(){ if(window.location != window.parent.location) $("<a>", {target:"_blank", href:""}) .text("[pop out]").prependTo($("body")); $("#output").pivotUI( $.csv.toArrays($("#output").text()), $.extend({ renderers: $.extend( $.pivotUtilities.renderers, $.pivotUtilities.c3_renderers, $.pivotUtilities.d3_renderers, $.pivotUtilities.export_renderers ), hiddenAttributes: [""] }, {}) ).show(); }); </script><div id="output" style="display: none;">XXXxX'
# Glue the html around the csv
echo "$PREAMBLE" > "$FILE"
cat "$CSV" >> "$FILE"
echo "</div></body></html>" >> "$FILE"
# Now splice beginning of CSV to last line of pivottablejs
sed -i '/XXXxX/{N;s/\n//;}' "$FILE"
# Remove the splice marker
sed -i 's/XXXxX//g' "$FILE"
# Get rid of empty lines
sed -i '/^[[:space:]]*$/d' "$FILE"
# Done...take a look
echo "Note: the pivottable.html page requires a network connection to view"