@@ -9,12 +9,12 @@ function printtable(io::IO, source, typename::AbstractString; force_unknown_rows
9
9
if force_unknown_rows
10
10
rows = nothing
11
11
data = Iterators. take (source, 10 ) |> collect
12
- elseif Base. IteratorSize (source) isa Union{Base. HasLength, Base. HasShape{1 }}
12
+ elseif Base. IteratorSize (source) isa Union{Base. HasLength,Base. HasShape{1 }}
13
13
rows = length (source)
14
14
data = Iterators. take (source, 10 ) |> collect
15
15
else
16
16
data_plus_one = Iterators. take (source, 11 ) |> collect
17
- if length (data_plus_one)< 11
17
+ if length (data_plus_one) < 11
18
18
rows = length (data_plus_one)
19
19
data = data_plus_one
20
20
else
@@ -29,14 +29,14 @@ function printtable(io::IO, source, typename::AbstractString; force_unknown_rows
29
29
30
30
colnames = String .(fieldnames (eltype (source)))
31
31
32
- NAvalues = [r== 0 ? false : DataValues. isna (data[r][c]) for r in 0 : length (data), c in 1 : cols]
32
+ NAvalues = [r == 0 ? false : DataValues. isna (data[r][c]) for r in 0 : length (data), c in 1 : cols]
33
33
34
- data = [r== 0 ? colnames[c] : isa (data[r][c], AbstractString) ? data[r][c] : sprint (io-> show (IOContext (io, :compact => true ), data[r][c])) for r in 0 : length (data), c in 1 : cols]
34
+ data = [r == 0 ? colnames[c] : isa (data[r][c], AbstractString) ? data[r][c] : sprint (io -> show (IOContext (io, :compact => true ), data[r][c])) for r in 0 : length (data), c in 1 : cols]
35
35
36
- maxwidth = [maximum (Unicode. textwidth .(data[:,c])) for c in 1 : cols]
36
+ maxwidth = [maximum (Unicode. textwidth .(data[:, c])) for c in 1 : cols]
37
37
38
38
available_heigth, available_width = displaysize (io)
39
- available_width -= 1
39
+ available_width -= 1
40
40
41
41
shortened_rows = Set {Int} ()
42
42
@@ -47,67 +47,67 @@ function printtable(io::IO, source, typename::AbstractString; force_unknown_rows
47
47
return string (s, ' ' ^ m)
48
48
end
49
49
50
- while sum (maxwidth) + (size (data,2 ) - 1 ) * 3 > available_width
51
- if size (data,2 ) == 1
52
- for r in 1 : size (data,1 )
53
- if length (data[r,1 ])> available_width
54
- data[r,1 ] = data[r,1 ][1 : nextind (data[r,1 ], 0 , available_width- 2 )] * " \" "
50
+ while sum (maxwidth) + (size (data, 2 ) - 1 ) * 3 > available_width
51
+ if size (data, 2 ) == 1
52
+ for r in 1 : size (data, 1 )
53
+ if length (data[r, 1 ]) > available_width
54
+ data[r, 1 ] = data[r, 1 ][1 : nextind (data[r, 1 ], 0 , available_width - 2 )] * " \" "
55
55
push! (shortened_rows, r)
56
56
end
57
57
end
58
58
maxwidth[1 ] = available_width
59
59
break
60
60
else
61
- data = data[:,1 : end - 1 ]
61
+ data = data[:, 1 : end - 1 ]
62
62
63
- maxwidth = [maximum (length .(data[:,c])) for c in 1 : size (data,2 )]
63
+ maxwidth = [maximum (length .(data[:, c])) for c in 1 : size (data, 2 )]
64
64
end
65
65
end
66
66
67
- for c in 1 : size (data,2 )
67
+ for c in 1 : size (data, 2 )
68
68
print (io, rpad (colnames[c], maxwidth[c]))
69
- if c< size (data,2 )
69
+ if c < size (data, 2 )
70
70
print (io, " │ " )
71
71
end
72
72
end
73
73
println (io)
74
- for c in 1 : size (data,2 )
74
+ for c in 1 : size (data, 2 )
75
75
print (io, repeat (" ─" , maxwidth[c]))
76
- if c< size (data,2 )
76
+ if c < size (data, 2 )
77
77
print (io, " ─┼─" )
78
78
end
79
79
end
80
- for r in 2 : size (data,1 )
80
+ for r in 2 : size (data, 1 )
81
81
println (io)
82
- for c in 1 : size (data,2 )
82
+ for c in 1 : size (data, 2 )
83
83
84
84
if r in shortened_rows
85
- print (io, data[r,c],)
85
+ print (io, data[r, c],)
86
86
print (io, " …" )
87
87
else
88
- if NAvalues[r,c]
89
- printstyled (io, rpad (data[r,c], maxwidth[c]), color= :light_black )
88
+ if NAvalues[r, c]
89
+ printstyled (io, rpad (data[r, c], maxwidth[c]), color= :light_black )
90
90
else
91
- print (io, textwidth_based_rpad (data[r,c], maxwidth[c]))
91
+ print (io, textwidth_based_rpad (data[r, c], maxwidth[c]))
92
92
end
93
93
end
94
- if c< size (data,2 )
94
+ if c < size (data, 2 )
95
95
print (io, " │ " )
96
96
end
97
97
end
98
98
end
99
99
100
- if rows=== nothing
100
+ if rows === nothing
101
101
row_post_text = " more rows"
102
- elseif rows > size (data,1 ) - 1
102
+ elseif rows > size (data, 1 ) - 1
103
103
extra_rows = rows - 10
104
104
row_post_text = " $extra_rows more $(extra_rows== 1 ? " row" : " rows" ) "
105
105
else
106
106
row_post_text = " "
107
107
end
108
108
109
- if size (data,2 ) != cols
110
- extra_cols = cols- size (data,2 )
109
+ if size (data, 2 ) != cols
110
+ extra_cols = cols - size (data, 2 )
111
111
col_post_text = " $extra_cols more $(extra_cols== 1 ? " column" : " columns" ) : "
112
112
col_post_text *= Base. join ([colnames[cols- extra_cols+ 1 : end ]. .. ], " , " )
113
113
else
@@ -116,7 +116,7 @@ function printtable(io::IO, source, typename::AbstractString; force_unknown_rows
116
116
117
117
if ! isempty (row_post_text) || ! isempty (col_post_text)
118
118
println (io)
119
- print (io," ... with " )
119
+ print (io, " ... with " )
120
120
if ! isempty (row_post_text)
121
121
print (io, row_post_text)
122
122
end
@@ -136,11 +136,11 @@ function printHTMLtable(io, source; force_unknown_rows=false)
136
136
137
137
if force_unknown_rows
138
138
rows = nothing
139
- elseif Base. IteratorSize (source) isa Union{Base. HasLength, Base. HasShape{1 }}
139
+ elseif Base. IteratorSize (source) isa Union{Base. HasLength,Base. HasShape{1 }}
140
140
rows = length (source)
141
141
else
142
- count_needed_plus_one = Iterators. count (i-> true , Iterators. take (source, max_elements+ 1 ))
143
- rows = count_needed_plus_one< max_elements+ 1 ? count_needed_plus_one : nothing
142
+ count_needed_plus_one = Iterators. count (i -> true , Iterators. take (source, max_elements + 1 ))
143
+ rows = count_needed_plus_one < max_elements + 1 ? count_needed_plus_one : nothing
144
144
end
145
145
146
146
haslimit = get (io, :limit , true )
@@ -166,18 +166,18 @@ function printHTMLtable(io, source; force_unknown_rows=false)
166
166
for c in values (r)
167
167
print (io, " <td>" )
168
168
if c isa Dates. AbstractTime
169
- Markdown. htmlesc (io, sprint (io-> print (IOContext (io, :compact => true ),c)))
169
+ Markdown. htmlesc (io, sprint (io -> print (IOContext (io, :compact => true ), c)))
170
170
elseif c isa DataValues. DataValue && DataValues. hasvalue (c) && c[] isa Dates. AbstractDateTime
171
- Markdown. htmlesc (io, sprint (io-> print (IOContext (io, :compact => true ),c[])))
171
+ Markdown. htmlesc (io, sprint (io -> print (IOContext (io, :compact => true ), c[])))
172
172
else
173
- Markdown. htmlesc (io, sprint (io-> show (IOContext (io, :compact => true ),c)))
173
+ Markdown. htmlesc (io, sprint (io -> show (IOContext (io, :compact => true ), c)))
174
174
end
175
175
print (io, " </td>" )
176
176
end
177
177
print (io, " </tr>" )
178
178
end
179
179
180
- if rows== nothing
180
+ if rows == nothing
181
181
row_post_text = " ... with more rows."
182
182
elseif rows > max_elements
183
183
extra_rows = rows - max_elements
@@ -215,38 +215,38 @@ julia_type_to_schema_type(::Type{T}) where {T<:Dates.Time} = "time"
215
215
julia_type_to_schema_type (:: Type{T} ) where {T<: Dates.Date } = " date"
216
216
julia_type_to_schema_type (:: Type{T} ) where {T<: Dates.DateTime } = " datetime"
217
217
julia_type_to_schema_type (:: Type{T} ) where {T<: AbstractString } = " string"
218
- julia_type_to_schema_type (:: Type{T} ) where {S, T<: DataValues.DataValue{S} } = julia_type_to_schema_type (S)
218
+ julia_type_to_schema_type (:: Type{T} ) where {S,T<: DataValues.DataValue{S} } = julia_type_to_schema_type (S)
219
219
220
220
own_json_formatter (io, x) = JSON. print (io, x)
221
- own_json_formatter (io, x:: DataValues.DataValue ) = DataValues. isna (x) ? JSON. print (io,nothing ) : own_json_formatter (io, x[])
221
+ own_json_formatter (io, x:: DataValues.DataValue ) = DataValues. isna (x) ? JSON. print (io, nothing ) : own_json_formatter (io, x[])
222
222
223
223
function printdataresource (io:: IO , source)
224
224
if Base. IteratorEltype (source) isa Base. EltypeUnknown
225
225
first_el = first (source)
226
226
col_names = String .(propertynames (first_el))
227
- col_types = [fieldtype (typeof (first_el), i) for i= 1 : length (col_names)]
227
+ col_types = [fieldtype (typeof (first_el), i) for i = 1 : length (col_names)]
228
228
else
229
229
col_names = String .(fieldnames (eltype (source)))
230
- col_types = [fieldtype (eltype (source), i) for i= 1 : length (col_names)]
230
+ col_types = [fieldtype (eltype (source), i) for i = 1 : length (col_names)]
231
231
end
232
- schema = Dict (" fields" => [Dict (" name" => string (i[1 ]), " type" => julia_type_to_schema_type (i[2 ])) for i in zip (col_names, col_types)])
232
+ schema = Dict (" fields" => [Dict (" name" => string (i[1 ]), " type" => julia_type_to_schema_type (i[2 ])) for i in zip (col_names, col_types)])
233
233
234
234
print (io, " {" )
235
235
JSON. print (io, " schema" )
236
236
print (io, " :" )
237
- JSON. print (io,schema)
238
- print (io," ," )
237
+ JSON. print (io, schema)
238
+ print (io, " ," )
239
239
JSON. print (io, " data" )
240
240
print (io, " :[" )
241
241
242
242
for (row_i, row) in enumerate (source)
243
- if row_i> 1
243
+ if row_i > 1
244
244
print (io, " ," )
245
245
end
246
246
247
247
print (io, " {" )
248
248
for col in 1 : length (col_names)
249
- if col> 1
249
+ if col > 1
250
250
print (io, " ," )
251
251
end
252
252
JSON. print (io, col_names[col])
0 commit comments