Skip to content

Commit 34555ad

Browse files
authored
Merge pull request #55 from maxfreu/dev-max
Improve show
2 parents 5030485 + 3a16616 commit 34555ad

File tree

1 file changed

+30
-19
lines changed

1 file changed

+30
-19
lines changed

src/show.jl

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -78,29 +78,40 @@ function keyed_print_matrix(io::IO, A, reduce_size::Bool=false)
7878
end
7979

8080
h, w = displaysize(io)
81-
# If the matrix has millions of rows, avoid making huge ::Any array
82-
ind1 = size(A,1) < h ? Colon() : vcat(1:(h÷2), size(A,1)-(h÷2):size(A,1))
8381
wn = w÷3 # integers take 3 columns each when printed, floats more
84-
ind2 = size(A,2) < wn ? Colon() : vcat(1:(wn÷2), (wn÷2)+1:size(A,2))
8582

8683
fakearray = if ndims(A) == 1
87-
hcat(
88-
ShowWith.(no_offset(axiskeys(A,1))[ind1]; color=colour(A,1)),
89-
# showvec(A, 1, ind1),
90-
getindex(no_offset(unname(keyless(A))), ind1) # avoid trailing index
91-
)
84+
top = size(A,1) < h ? Colon() : (1:(h÷2))
85+
bottom = size(A,1) < h ? (1:0) : size(A,1)-(h÷2):size(A,1)
86+
hcat(vcat(ShowWith.(no_offset(axiskeys(A,1))[top]; color=colour(A,1)),
87+
ShowWith.(no_offset(axiskeys(A,1))[bottom]; color=colour(A,1))),
88+
vcat(getindex(no_offset(unname(keyless(A))), top),
89+
getindex(no_offset(unname(keyless(A))), bottom)))
9290
else
93-
fakearray = hcat(
94-
ShowWith.(no_offset(axiskeys(A,1))[ind1]; color=colour(A,1)),
95-
# showvec(A, 1, ind1),
96-
getindex(no_offset(unname(keyless(A))), ind1, ind2)
97-
)
98-
toprow = vcat(
99-
ShowWith(0, hide=true),
100-
ShowWith.(no_offset(axiskeys(A,2))[ind2]; color=colour(A,2)),
101-
# showvec(A, 2, ind2),
102-
)
103-
fakearray = vcat(permutedims(toprow), fakearray)
91+
top = size(A,1) < h ? Colon() : (1:(h÷2))
92+
bottom = size(A,1) < h ? (1:0) : size(A,1)-(h÷2):size(A,1)
93+
left = size(A,2) < wn ? Colon() : (1:(wn÷2))
94+
right = size(A,2) < wn ? (1:0) : size(A,2)-(wn÷2)+1:size(A,2)
95+
96+
topleft = hcat(ShowWith.(no_offset(axiskeys(A,1))[top]; color=colour(A,1)),
97+
getindex(no_offset(unname(keyless(A))), top, left))
98+
99+
bottomleft = hcat(ShowWith.(no_offset(axiskeys(A,1))[bottom]; color=colour(A,1)),
100+
getindex(no_offset(unname(keyless(A))), bottom, left))
101+
102+
leftblock = vcat(topleft, bottomleft)
103+
104+
bottomblock = hcat(leftblock,
105+
# right block
106+
vcat(getindex(no_offset(unname(keyless(A))), top, right),
107+
getindex(no_offset(unname(keyless(A))), bottom, right)))
108+
109+
# permute it so it becomes a row
110+
toprow = permutedims(vcat(ShowWith(0, hide=true),
111+
ShowWith.(no_offset(axiskeys(A,2))[left]; color=colour(A,2)),
112+
ShowWith.(no_offset(axiskeys(A,2))[right]; color=colour(A,2))))
113+
114+
vcat(toprow, bottomblock)
104115
end
105116
Base.print_matrix(io, fakearray)
106117
end

0 commit comments

Comments
 (0)