-
Notifications
You must be signed in to change notification settings - Fork 10
/
plotting_nested.ml
94 lines (88 loc) · 2.47 KB
/
plotting_nested.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
module B = PrintBox
module BPlot = PrintBox_ext_plot
(* This tests the printbox-ext-plot extension. *)
let reg_45 =
B.(
frame
(vlist
[
text "123456789";
frame ~stretch:true
(vlist [ text "...." |> align ~h:`Right ~v:`Top; text "." ]);
]))
let for_3 =
let n = 3 in
Array.init n (fun i -> Array.init n (fun j -> B.sprintf "(%d,%d)" i j))
|> B.grid
let nice_unicode =
B.(
frame
@@ vlist
[
text "nice unicode! 💪";
frame
@@ hlist
[
vlist
[
text "oï ωεird nums:\nπ/2\nτ/4";
center_hv
@@ tree (text "0")
[ text "1"; tree (text "ω") [ text "ω²" ] ];
];
frame @@ frame @@ frame
@@ vlist
[
text "sum=Σ_i a·xᵢ²\n—————\n1+1";
align_right @@ text "Ōₒ\nÀ";
];
];
])
let test ~size =
BPlot.(
box
{
default_config with
size;
specs =
[
Scatterbag
{ points = [| (0.06, 0.95), reg_45; (0.3, 0.3), reg_45 |] };
Scatterbag
{
points =
[|
(0., 1.), nice_unicode;
(0.08, 0.9), nice_unicode;
(1., 0.), for_3;
(0.3, 0.3), nice_unicode;
(0.75, 0.75), nice_unicode;
(0.8, 0.8), nice_unicode;
|];
};
Map
{
callback =
(fun (x, y) ->
let s = ((x ** 2.) +. (y ** 2.)) ** 0.5 in
B.line
@@
if s < 0.3 then
" "
else if s < 0.6 then
"."
else if s < 0.9 then
","
else if s < 1.2 then
":"
else
";");
};
];
})
let () =
print_endline "Text output:";
print_endline @@ PrintBox_text.to_string
@@ test ~size:BPlot.default_config.size;
print_endline "\nHTML output:";
print_endline @@ PrintBox_html.to_string @@ test ~size:(800, 800)