[OCaml] Mobile-friendly clone of cgit.
refactor name the SVG number formatters
int_s and float_s used a bare _s for "to string", in a module whose other short names (x, y, rx, x1) at least mirror the SVG attributes they set. int_s was also a plain alias for string_of_int, so the abbreviation bought nothing. Rename to svg_int and svg_float, and record why the float form rounds to one decimal: finer precision is invisible and only inflates the markup.
lib/charts.ml
@@ -19,9 +19,13 @@
19
19
let y2 = string_attr "y2"
20
20
let text_anchor = string_attr "text-anchor"
21
21
let font_size = string_attr "font-size"
22
Removed:
let int_s = string_of_int
23
Removed:
let float_s f = Printf.sprintf "%.1f" f
24
22
23
Added:
(* SVG attribute values are strings, so every computed coordinate has to be
24
Added:
converted. Fractional coordinates are rounded to one decimal: sub-pixel
25
Added:
precision beyond that is invisible and only inflates the markup. *)
26
Added:
let svg_int = string_of_int
27
Added:
let svg_float value = Printf.sprintf "%.1f" value
28
Added:
25
29
(** Render a bar chart of daily commit frequency.
26
30
27
31
[values] is a list of [(label, count)] pairs representing consecutive days.
@@ -54,18 +58,18 @@
54
58
[
55
59
line
56
60
[
57
Removed:
x1 "%s" (int_s padding_left);
58
Removed:
y1 "%s" (int_s y_pos);
59
Removed:
x2 "%s" (int_s (chart_width - padding_right));
60
Removed:
y2 "%s" (int_s y_pos);
61
Added:
x1 "%s" (svg_int padding_left);
62
Added:
y1 "%s" (svg_int y_pos);
63
Added:
x2 "%s" (svg_int (chart_width - padding_right));
64
Added:
y2 "%s" (svg_int y_pos);
61
65
SVG.stroke "#333";
62
66
SVG.stroke_width "1";
63
67
]
64
68
[];
65
69
text_
66
70
[
67
Removed:
x "%s" (int_s (padding_left - 5));
68
Removed:
y "%s" (int_s (y_pos + 4));
71
Added:
x "%s" (svg_int (padding_left - 5));
72
Added:
y "%s" (svg_int (y_pos + 4));
69
73
text_anchor "end";
70
74
font_size "10";
71
75
SVG.fill "#888";
@@ -89,10 +93,10 @@
89
93
let by = padding_top + plot_height - bar_height in
90
94
rect
91
95
[
92
Removed:
x "%s" (float_s bx);
93
Removed:
y "%s" (int_s by);
94
Removed:
width_ "%s" (float_s bar_actual);
95
Removed:
height_ "%s" (int_s bar_height);
96
Added:
x "%s" (svg_float bx);
97
Added:
y "%s" (svg_int by);
98
Added:
width_ "%s" (svg_float bar_actual);
99
Added:
height_ "%s" (svg_int bar_height);
96
100
rx "2";
97
101
SVG.fill "rgb(194, 79, 30)";
98
102
]
@@ -111,8 +115,8 @@
111
115
in
112
116
text_
113
117
[
114
Removed:
x "%s" (float_s lx);
115
Removed:
y "%s" (int_s (chart_height - 5));
118
Added:
x "%s" (svg_float lx);
119
Added:
y "%s" (svg_int (chart_height - 5));
116
120
text_anchor "middle";
117
121
font_size "10";
118
122
SVG.fill "#888";