summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkshay <[email protected]>2021-08-21 12:27:06 +0100
committerAkshay <[email protected]>2021-08-21 12:27:06 +0100
commitf29b3c83dd653bf833f937833a74d1e8cad5a488 (patch)
tree39752862c3001cbe1831d6a2063ab3a9eea9e56d
parent8f590f63abdf2336c0f6496bfa187f1331fa0db4 (diff)
feat: add y-axisHEADmaster
-rw-r--r--src/chart.ml20
-rw-r--r--src/utils.ml2
2 files changed, 19 insertions, 3 deletions
diff --git a/src/chart.ml b/src/chart.ml
index 39f97f9..807f026 100644
--- a/src/chart.ml
+++ b/src/chart.ml
@@ -8,11 +8,14 @@ let with_options v c = { c with opts = v }
8 8
9let pp formatter { vals : int list; opts : Options.t } = 9let pp formatter { vals : int list; opts : Options.t } =
10 let open Utils in 10 let open Utils in
11 let height = opts.height in 11 let height = opts.height - 1 in
12 let min_val = list_min vals in 12 let min_val = list_min vals in
13 let max_val = list_max vals in 13 let max_val = list_max vals in
14 let range = max_val - min_val in 14 let range = max_val - min_val in
15 let scale v = (v - min_val) * height / range in 15 let scale v =
16 int_of_float
17 (float_of_int (v - min_val) /. float_of_int range *. float_of_int height)
18 in
16 let new_vals = List.map scale vals in 19 let new_vals = List.map scale vals in
17 let rec pad left right s = 20 let rec pad left right s =
18 if left = 0 then s :: repeat right space 21 if left = 0 then s :: repeat right space
@@ -51,7 +54,18 @@ let pp formatter { vals : int list; opts : Options.t } =
51 | (s, e) :: tl -> 54 | (s, e) :: tl ->
52 make_marker axis s (height - s) m :: make_connector s e :: make_graph tl 55 make_marker axis s (height - s) m :: make_connector s e :: make_graph tl
53 in 56 in
54 make_graph new_vals' |> rot_left 57 let unscale v =
58 (float_of_int (v * range) /. float_of_int height) +. float_of_int min_val
59 in
60 let y_vals =
61 Format.sprintf "%10s" "┤"
62 ::
63 List.map
64 (fun x -> Format.sprintf "%6.2f ┤" (unscale x))
65 (0 -- (height + 1))
66 in
67 y_vals :: make_graph new_vals'
68 |> rot_left
55 |> List.map (String.concat "") 69 |> List.map (String.concat "")
56 |> String.concat "\n" 70 |> String.concat "\n"
57 |> Format.fprintf formatter "%s" 71 |> Format.fprintf formatter "%s"
diff --git a/src/utils.ml b/src/utils.ml
index 59eac6c..b3dbbda 100644
--- a/src/utils.ml
+++ b/src/utils.ml
@@ -37,3 +37,5 @@ let space = to_string ' '
37let axis = "┬" 37let axis = "┬"
38 38
39let axis_spc = "─" 39let axis_spc = "─"
40
41let rec ( -- ) i j = if i >= j then [] else i :: (i + 1 -- j)