From 9ccac5bf882e3d8b05cd6dbe6b724de1514bb788 Mon Sep 17 00:00:00 2001 From: SimonDanisch Date: Wed, 24 Mar 2021 17:59:52 +0100 Subject: [PATCH] fix axis & bb --- src/basic_recipes/axis.jl | 24 +++++++++------------- src/layouting/boundingbox.jl | 29 +-------------------------- test/ReferenceTests/src/tests/text.jl | 2 +- 3 files changed, 11 insertions(+), 44 deletions(-) diff --git a/src/basic_recipes/axis.jl b/src/basic_recipes/axis.jl index 2023ac8a0..88f0c18fb 100644 --- a/src/basic_recipes/axis.jl +++ b/src/basic_recipes/axis.jl @@ -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) @@ -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], @@ -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 diff --git a/src/layouting/boundingbox.jl b/src/layouting/boundingbox.jl index f95235863..84f7c2e8d 100644 --- a/src/layouting/boundingbox.jl +++ b/src/layouting/boundingbox.jl @@ -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"()) @@ -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 diff --git a/test/ReferenceTests/src/tests/text.jl b/test/ReferenceTests/src/tests/text.jl index aee12c68e..d6966245a 100644 --- a/test/ReferenceTests/src/tests/text.jl +++ b/test/ReferenceTests/src/tests/text.jl @@ -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)