Skip to content

Commit f09ac73

Browse files
committed
📚 [HTML] Add examples
1 parent fb30e85 commit f09ac73

File tree

2 files changed

+224
-1
lines changed

2 files changed

+224
-1
lines changed

docs/make.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ makedocs(
2222
"Pre-defined Formats" => "man/text/predefined_formats.md",
2323
"Examples" => "man/text/text_examples.md",
2424
],
25-
"HTML" => "man/html/html_backend.md",
25+
"HTML" => Any[
26+
"HTML Backend" => "man/html/html_backend.md",
27+
"Examples" => "man/html/html_examples.md",
28+
],
2629
"LaTeX" => Any[
2730
"LaTeX Backend" => "man/latex/latex_backend.md",
2831
"Examples" => "man/latex/latex_examples.md",

docs/src/man/html/html_examples.md

Lines changed: 220 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
1+
# HTML Backend Examples
2+
3+
```@meta
4+
CurrentModule = PrettyTables
5+
```
6+
7+
```@setup html_examples
8+
using PrettyTables
9+
10+
function pt_to_html(args...; kwargs...)
11+
str = pretty_table(String, args...; kwargs...)
12+
return Base.HTML(str)
13+
end
14+
```
15+
16+
Here, we can see some examples of text tables generated by PrettyTables.jl. The `A` object,
17+
when referenced, is defined as:
18+
19+
```julia-repl
20+
julia> A = Any[
21+
1 false 1.0 0x01
22+
2 true 2.0 0x02
23+
3 false 3.0 0x03
24+
4 true 4.0 0x04
25+
5 false 5.0 0x05
26+
6 true 6.0 0x06
27+
]
28+
```
29+
30+
```@setup html_examples
31+
A = Any[
32+
1 false 1.0 0x01
33+
2 true 2.0 0x02
34+
3 false 3.0 0x03
35+
4 true 4.0 0x04
36+
5 false 5.0 0x05
37+
6 true 6.0 0x06
38+
]
39+
```
40+
41+
---
42+
43+
```julia-repl
44+
julia> pretty_table(A; backend = :html)
45+
```
46+
47+
```@example html_examples
48+
pt_to_html( # hide
49+
A; # hide
50+
backend = :html # hide
51+
) # hide
52+
```
53+
54+
---
55+
56+
```julia-repl
57+
julia> pretty_table(
58+
A;
59+
backend = :html,
60+
style = HtmlTableStyle(;
61+
first_line_column_label = ["color" => "BurlyWood", "font-weight" => "bold"]
62+
)
63+
)
64+
```
65+
66+
```@example html_examples
67+
pt_to_html( # hide
68+
A; # hide
69+
backend = :html, # hide
70+
style = HtmlTableStyle(; # hide
71+
first_line_column_label = ["color" => "BurlyWood", "font-weight" => "bold"] # hide
72+
) # hide
73+
) # hide
74+
```
75+
76+
---
77+
78+
```julia-repl
79+
julia> data = [
80+
10.0 6.5
81+
3.0 3.0
82+
0.1 1.0
83+
]
84+
85+
julia> row_labels = [
86+
"Atmospheric drag"
87+
"Gravity gradient"
88+
"Solar radiation pressure"
89+
]
90+
91+
julia> column_labels = [
92+
[MultiColumn(2, "Value", :c)],
93+
[
94+
"Torque [10⁻⁶ Nm]",
95+
"Angular Momentum [10⁻³ Nms]"
96+
]
97+
]
98+
99+
julia> pretty_table(
100+
data;
101+
backend = :html,
102+
column_labels,
103+
merge_column_label_cells = :auto,
104+
row_labels,
105+
stubhead_label = "Effect",
106+
style = HtmlTableStyle(;
107+
first_line_merged_column_label = ["color" => "BurlyWood", "font-weight" => "bold"],
108+
column_label = ["color" => "DarkGrey"],
109+
stubhead_label = ["color" => "BurlyWood", "font-weight" => "bold"],
110+
summary_row_label = ["color" => "red", "font-weight" => "bold"]
111+
),
112+
summary_row_labels = ["Total"],
113+
summary_rows = [(data, i) -> sum(data[:, i])],
114+
)
115+
```
116+
117+
```@example html_examples
118+
data = [ # hide
119+
10.0 6.5 # hide
120+
3.0 3.0 # hide
121+
0.1 1.0 # hide
122+
] # hide
123+
# hide
124+
row_labels = [ # hide
125+
"Atmospheric drag" # hide
126+
"Gravity gradient" # hide
127+
"Solar radiation pressure" # hide
128+
] # hide
129+
# hide
130+
column_labels = [ # hide
131+
[MultiColumn(2, "Value", :c)], # hide
132+
[ # hide
133+
"Torque [10⁻⁶ Nm]", # hide
134+
"Angular Momentum [10⁻³ Nms]" # hide
135+
] # hide
136+
] # hide
137+
# hide
138+
pt_to_html( # hide
139+
data; # hide
140+
backend = :html, # hide
141+
column_labels, # hide
142+
merge_column_label_cells = :auto, # hide
143+
row_labels, # hide
144+
stubhead_label = "Effect", # hide
145+
style = HtmlTableStyle(; # hide
146+
first_line_merged_column_label = ["color" => "BurlyWood", "font-weight" => "bold"], # hide
147+
column_label = ["color" => "DarkGrey"], # hide
148+
stubhead_label = ["color" => "BurlyWood", "font-weight" => "bold"], # hide
149+
summary_row_label = ["color" => "red", "font-weight" => "bold"] # hide
150+
), # hide
151+
summary_row_labels = ["Total"], # hide
152+
summary_rows = [(data, i) -> sum(data[:, i])], # hide
153+
) # hide
154+
```
155+
156+
---
157+
158+
```julia-repl
159+
julia> t = 0:1:20
160+
161+
julia> data = hcat(t, ones(length(t) ), t, 0.5.*t.^2);
162+
163+
julia> column_labels = [
164+
["Time", "Acceleration", "Velocity", "Distance"],
165+
[ "[s]", "[m / s²]", "[m / s]", "[m]"]
166+
]
167+
168+
julia> hl_p = HtmlHighlighter(
169+
(data, i, j) -> (j == 4) && (data[i, j] > 9),
170+
["color" => "blue"]
171+
)
172+
173+
julia> hl_v = TextHighlighter(
174+
(data, i, j) -> (j == 3) && (data[i, j] > 9),
175+
["color" => "red"]
176+
)
177+
178+
julia> pretty_table(
179+
data;
180+
backend = :html,
181+
column_labels = column_labels,
182+
highlighters = [hl_p, hl_v],
183+
style = HtmlTableStyle(;
184+
first_line_column_label = ["color" => "BurlyWood", "font-weight" => "bold"],
185+
column_label = ["color" => "DarkGrey"],
186+
)
187+
)
188+
```
189+
190+
```@example html_examples
191+
t = 0:1:20 # hide
192+
# hide
193+
data = hcat(t, ones(length(t) ), t, 0.5.*t.^2); # hide
194+
# hide
195+
column_labels = [ # hide
196+
["Time", "Acceleration", "Velocity", "Distance"], # hide
197+
[ "[s]", "[m / s²]", "[m / s]", "[m]"] # hide
198+
] # hide
199+
# hide
200+
hl_p = HtmlHighlighter( # hide
201+
(data, i, j) -> (j == 4) && (data[i, j] > 9), # hide
202+
["color" => "blue"] # hide
203+
) # hide
204+
# hide
205+
hl_v = HtmlHighlighter( # hide
206+
(data, i, j) -> (j == 3) && (data[i, j] > 9), # hide
207+
["color" => "red"] # hide
208+
) # hide
209+
# hide
210+
pt_to_html( # hide
211+
data; # hide
212+
backend = :html, # hide
213+
column_labels = column_labels, # hide
214+
highlighters = [hl_p, hl_v], # hide
215+
style = HtmlTableStyle(; # hide
216+
first_line_column_label = ["color" => "BurlyWood", "font-weight" => "bold"], # hide
217+
column_label = ["color" => "DarkGrey"], # hide
218+
) # hide
219+
) # hide
220+
```

0 commit comments

Comments
 (0)