-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathinit.q
41 lines (30 loc) · 2.1 KB
/
init.q
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
system "rm -rf ", .qchart.libpath, "/output"; //clear previous output file
.qchart.read_template: {read0 hsym `$"/" sv (.qchart.libpath; "template"; string ` sv (x;`html))};
.qchart.generate_tempfile: {hsym `$"/" sv (.qchart.libpath; "output"; string ` sv (`$-3_(string .z.Z) except ".:";`html))};
.qchart.generate_tempfile: {`$"/" sv (.qchart.libpath; "output"; string ` sv (`$-3_(string .z.Z) except ".:";`html))};
.qchart.render: {[template; data] .qchart.render_json[template; .j.j data]}
.qchart.render_json: {[template; json] outfile: .qchart.generate_tempfile[]; (hsym outfile) 0: {ssr[y; "{{data}}"; x]}[json] each .qchart.read_template[template]; outfile}
.qchart.launch_command: (("m";"l"; "w")!("open "; "open"; "start "))[first string .z.o]
.qchart.launch: {system cmd: (.qchart.launch_command, string x); cmd};
/pretty print json
.j.pp: {`$enlist each "\n" vs ssr[;;{"\n",x}] over (except[x;"\""];"[[]";"[]]")};
.nv.t1: {x: 0!x; {`key`values!(y;`x`y xcol (x,'y)#z)}[;;x]/:[c[0];1_c:cols x]};
.nv.t2: {{`key`values!(y;?[x; enlist(=;`sym;enlist y);0b;(`x`y!2#(cols x)except `sym)])}[x] each exec distinct sym from x};
.nv.byKey: {[t; k] {(`key`values)!(y;?[x; enlist(=;z;enlist y);0b;(`x`y!2#(cols x)except z)])}[t;;k] each distinct (0!t) k};
//.nv.t3: {.j.j enlist`key`values!((cols x)1;`x`y xcol 0!x)}
//just remove sym columns since it does not plot properly in parallel graph
//.nv.t3: {.j.j #[;x] exec c from (meta x) where t<>"s"};
//internal plot function
.qchart.plot:{[template; data] .qchart.launch .qchart.render[template; data]};
//public functions
qchart.points: {.qchart.plot[`nvscatter] .nv.t1 x};
qchart.line: {.qchart.plot[`nvline] .nv.t1 x};
qchart.lineSym: {.qchart.plot[`nvline] .nv.t2 x};
qchart.lineKey: {.qchart.plot[`nvline] .nv.byKey[x; y]};
qchart.bar: {.qchart.plot[`nvbar] .nv.t1 x};
qchart.hbar: {.qchart.plot[`nvhbar] .nv.t1 x};
qchart.histbar: {.qchart.plot[`nvhistbar] .nv.t1 x};
qchart.stackedbar: {.qchart.plot[`nvstackedbar] .nv.t2 x};
qchart.stackedbarKey: {.qchart.plot[`nvstackedbar] .nv.byKey[x; y]};
qchart.parallel: {.qchart.plot[`nvpar] x};
qchart.pie: {.qchart.plot[`nvpie] `x`y xcol 0!x};