package pfff

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Source file plot_jgraph.ml

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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
open Common

module Color = Simple_color

(*****************************************************************************)
(* Prelude *)
(*****************************************************************************)

(* http://www.cs.utk.edu/~plank/plank/jgraph/jgraph.html
*)



let tmpfile = "/tmp/test.jgr" 


let prelude () = 
"  newgraph
      xaxis
      size 7in
      min 0 
      hash 1 mhash 0
(* autogenerated by jgraph.ml *)
"


let xaxis_font () = 
"hash_labels hjr font Helvetica fontsize 10 rotate 45"



let yaxis_label s = 
  spf "
      yaxis 
      hash_labels fontsize 12 label fontsize 12 : %s
      " s

let xaxis_label xpos s = 
  spf "
      newstring x %d y -4 fontsize 12 : %s
   " xpos s





(*****************************************************************************)
(* communicating with a pipe with R seems harder so use R batch mode *)
let jgraph_program file = 
  Common.command2(spf "jgraph %s > %s.ps" file file)

let gv_command file =
  let _status = Unix.system (spf "gv %s.ps &" file) in
  (* zarb: I need this when I launch the program via eshell, otherwise gv
     do not get the chance to be launched 
  *)
  Unix.sleep 1; 
  ()



(*****************************************************************************)

(* the colomns will be x, the lines will be the y *)
let plot_matrix ~lines ~columns ~xlabel ~ylabel matrix = 

  let limx = List.length columns - 1 in
  let limy = List.length lines - 1 in

  Common.with_open_outfile tmpfile (fun (pr_no_nl, _chan) -> 
    let pr s = pr_no_nl (s ^ "\n") in


    pr (prelude());


    Common.index_list columns +> List.iter (fun (s, i) -> 
      pr (spf "hash_label at %d : %s" i s);
    );
    let middle = limx / 2 in
    pr (xaxis_font());
    pr (yaxis_label ylabel);
    pr (xaxis_label middle xlabel);
    pr "";
    
    for j = 0 to limy do 
      let color = 
        let (r,g,b) = Color.rainbow_color j in
        spf "color %f %f %f" r g b
      in
      let lbl = List.nth lines j in
      pr (spf "newcurve marktype x linetype solid %s label : %s" 
             color lbl);
      pr "pts";
      
      for i = 0 to limx do 
        pr (spf "%d %f" i matrix.(j).(i));
      done
    done
  );
  
  jgraph_program tmpfile;
  gv_command tmpfile;
  ()


OCaml

Innovation. Community. Security.