Skip to content
This repository has been archived by the owner on Jul 13, 2021. It is now read-only.

Commit

Permalink
Merge pull request #671 from JuliaPlots/sd/axis_fix
Browse files Browse the repository at this point in the history
fix axis & bb
  • Loading branch information
SimonDanisch authored Mar 24, 2021
2 parents ee3c30b + 9ccac5b commit 9c1b330
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 44 deletions.
24 changes: 9 additions & 15 deletions src/basic_recipes/axis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ function draw_axis3d(textbuffer, linebuffer, scale, limits, ranges_labels, args.
titlegap = 0.01limit_widths[offset_indices] .* titlegap
tgap = 0.01limit_widths[offset_indices] .* tgap

for i = 1:N
for i in 1:N
axis_vec = unit(Point{N, Float32}, i)
width = Float32(limit_widths[i])
stop = origin .+ (width .* axis_vec)
Expand All @@ -271,13 +271,11 @@ function draw_axis3d(textbuffer, linebuffer, scale, limits, ranges_labels, args.
end
end
if !isempty(axisnames[i])
tick_widths = if length(ticklabels[i]) >= 3
w = widths(text_bb(ticklabels[i][end-1], to_font(tfont[i]), ttextsize[i]))[1]
w / scale[j]
else
0f0
end
pos = (labelposition(ranges, i, tickdir, titlegap[i] + tick_widths, origin) .+ offset2)
font = to_font(tfont[i])
tick_widths = maximum(ticklabels[i]) do label
widths(text_bb(label, font, ttextsize[i]))[1]
end / scale[j]
pos = labelposition(ranges, i, tickdir, titlegap[i] + tick_widths, origin) .+ offset2
push!(
textbuffer, to_latex(axisnames[i]), pos,
textsize = axisnames_size[i], color = axisnames_color[i],
Expand Down Expand Up @@ -307,14 +305,10 @@ function draw_axis3d(textbuffer, linebuffer, scale, limits, ranges_labels, args.
end

function text_bb(str, font, size)
layout = layout_text(str, size, font, Vec2f0(0), Quaternionf0(0,0,0,1), Mat4f0(I), 0.5, 1.0)
rot = Quaternionf0(0,0,0,1)
layout = layout_text(str, size, font, Vec2f0(0), rot, Mat4f0(I), 0.5, 1.0)
@assert typeof(layout.bboxes) <: Vector{FRect2D}

bbs = map(layout.origins, layout.bboxes) do o, bb
bb3 = FRect3D(bb)
FRect3D(bb3.origin + o * size, bb3.widths * size)
end
bb = reduce(union, bbs[2:end], init = bbs[1])
return data_text_boundingbox(str, layout, rot, Point3f0(0))
end


Expand Down
29 changes: 1 addition & 28 deletions src/layouting/boundingbox.jl
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ end
function boundingbox(x::Text, text::String, position::VecTypes)

glyphlayout = x._glyphlayout[]

pos = to_ndim(Point3f0, x.position[], 0)
rot = convert_attribute(x.rotation[], key"rotation"())

Expand All @@ -99,33 +99,6 @@ function boundingbox(x::Text, text::String, position::VecTypes)
end
end

# function boundingbox(x::Text, text::String, positions::AbstractArray)

# glyphorigins, glyphbbs = x._glyphlayout[]

# if x.space[] == :data

# bb = FRect3D()
# for (pos, char, charo, glyphbb) in zip(positions, x[1][], glyphorigins, glyphbbs)
# # ignore line breaks
# char in ('\r', '\n') && continue

# # TODO: Correct BBox
# charbb = FRect3D(glyphbb) + charo + to_ndim(Point3f0, pos, 0)
# if !isfinite(bb)
# bb = charbb
# else
# bb = union(bb, charbb)
# end
# end

# elseif x.space[] == :screen
# bb = data_limits(x)
# end

# bb
# end

function data_text_boundingbox(string::String, glyphlayout::Glyphlayout, rotation::Quaternion, position::Point3f0)
bb = FRect3D()
glyphorigins, glyphbbs = glyphlayout.origins, glyphlayout.bboxes
Expand Down
2 changes: 1 addition & 1 deletion test/ReferenceTests/src/tests/text.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ end
fig = text(
["0 is the ORIGIN of this", "10 says hi"],
position = pos,
aspect = DataAspect(),
axis = (aspect = DataAspect(),),
space = :data,
align = (:center, :center),
textsize = 2)
Expand Down

0 comments on commit 9c1b330

Please sign in to comment.