From 0eb50c34adaea177eeb00a0269501ddcf4540a7e Mon Sep 17 00:00:00 2001 From: Anshul Singhvi Date: Thu, 19 Mar 2020 20:56:11 +0530 Subject: [PATCH 1/5] Try to fix the y label offset bug --- src/basic_recipes/axis.jl | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/basic_recipes/axis.jl b/src/basic_recipes/axis.jl index 749bf5fe0..20550ab56 100644 --- a/src/basic_recipes/axis.jl +++ b/src/basic_recipes/axis.jl @@ -383,11 +383,9 @@ function draw_titles( textcolor, textsize, rotation, align, font, title ) - tickspace_x = maximum(map(yticks) do tick - str = last(tick) - tick_bb = text_bb(str, to_font(tickfont[2]), tick_size[2]) - widths(tick_bb)[1] - end) + tickspace_y = widths(text_bb( + last(first(yticks)), to_font(tickfont[2]), tick_size[2] + ))[2] tickspace_y = widths(text_bb( last(first(xticks)), to_font(tickfont[1]), tick_size[1] From 43d7dc256c0ef572f104d673b9f1898dda475ca0 Mon Sep 17 00:00:00 2001 From: Anshul Singhvi Date: Thu, 19 Mar 2020 20:57:26 +0530 Subject: [PATCH 2/5] fix --- src/basic_recipes/axis.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/basic_recipes/axis.jl b/src/basic_recipes/axis.jl index 20550ab56..46e714996 100644 --- a/src/basic_recipes/axis.jl +++ b/src/basic_recipes/axis.jl @@ -383,9 +383,9 @@ function draw_titles( textcolor, textsize, rotation, align, font, title ) - tickspace_y = widths(text_bb( + tickspace_x = widths(text_bb( last(first(yticks)), to_font(tickfont[2]), tick_size[2] - ))[2] + ))[1] tickspace_y = widths(text_bb( last(first(xticks)), to_font(tickfont[1]), tick_size[1] From 9b954164db68abace2bb0f15d91e0228bfeb4657 Mon Sep 17 00:00:00 2001 From: SimonDanisch Date: Mon, 23 Mar 2020 22:31:34 +0100 Subject: [PATCH 3/5] improve text bbs --- src/layouting/boundingbox.jl | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/layouting/boundingbox.jl b/src/layouting/boundingbox.jl index 73d3a4bdd..f86b000a8 100644 --- a/src/layouting/boundingbox.jl +++ b/src/layouting/boundingbox.jl @@ -99,11 +99,10 @@ function boundingbox( text::String, position, textsize; font = "default", align = (:left, :bottom), rotation = 0.0 ) - boundingbox( + return boundingbox( text, position, textsize, to_font(font), to_align(align), to_rotation(rotation) ) - end # function boundingbox( @@ -138,6 +137,7 @@ end # return bb # end + function boundingbox( text::String, position, textsize, font, align, rotation, model = Mat4f0(I) @@ -157,12 +157,19 @@ function boundingbox( ctext_state = iterate(text, text_state) # TODO fix center + align + rotation if c != '\r' - pos = if pos_per_char - to_ndim(Vec3f0, position[i], 0.0) + posnd = if pos_per_char + position[i] else last_pos = calc_position(last_pos, Point2f0(0, 0), atlas, c, font, scale) - start_pos3d .+ (rotation * to_ndim(Vec3f0, last_pos, 0.0)) + advance_x, advance_y = glyph_advance!(atlas, c, font, scale) + without_advance = if c != '\n' + last_pos .- Point2f0(advance_x, 0) + else + last_pos + end + start_pos3d .+ (rotation * to_ndim(Vec3f0, without_advance, 0.0)) end + pos = to_ndim(Vec3f0, posnd, 0.0) s = glyph_scale!(atlas, c, font, scale) srot = rotation * to_ndim(Vec3f0, s, 0.0) bb = GeometryTypes.update(bb, pos) From 69dbddfb139ab6543eae1ec2540cb0d1bc4f6bd0 Mon Sep 17 00:00:00 2001 From: SimonDanisch Date: Tue, 24 Mar 2020 11:44:16 +0100 Subject: [PATCH 4/5] improve bearing offset --- src/layouting/boundingbox.jl | 7 ++++--- src/utilities/texture_atlas.jl | 23 +++++++++++++++++------ 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/layouting/boundingbox.jl b/src/layouting/boundingbox.jl index f86b000a8..26307645b 100644 --- a/src/layouting/boundingbox.jl +++ b/src/layouting/boundingbox.jl @@ -162,10 +162,11 @@ function boundingbox( else last_pos = calc_position(last_pos, Point2f0(0, 0), atlas, c, font, scale) advance_x, advance_y = glyph_advance!(atlas, c, font, scale) - without_advance = if c != '\n' - last_pos .- Point2f0(advance_x, 0) - else + without_advance = if c == '\n' + # advance doesn't get added for newlines last_pos + else + last_pos .- Point2f0(advance_x, 0) end start_pos3d .+ (rotation * to_ndim(Vec3f0, without_advance, 0.0)) end diff --git a/src/utilities/texture_atlas.jl b/src/utilities/texture_atlas.jl index fca342086..cd0f5bdd1 100644 --- a/src/utilities/texture_atlas.jl +++ b/src/utilities/texture_atlas.jl @@ -290,12 +290,23 @@ function calc_position(glyphs, start_pos, scales, fonts, atlas) positions = zeros(Point2f0, length(glyphs)) last_pos = Point2f0(start_pos) s, f = iter_or_array(scales), iter_or_array(fonts) - c1 = first(glyphs) - for (i, (c2, scale, font)) in enumerate(zip(glyphs, s, f)) - c2 == '\r' && continue # stupid windows! - b = glyph_bearing!(atlas, c2, font, scale) - positions[i] = last_pos .+ b - last_pos = calc_position(last_pos, start_pos, atlas, c2, font, scale) + iter = enumerate(zip(glyphs, s, f)) + next = iterate(iter) + if next !== nothing + (i, (char, scale, font)), state = next + first_bearing = glyph_bearing!(atlas, char, font, scale) + while next !== nothing + (i, (char, scale, font)), state = next + next = iterate(iter, state) + char == '\r' && continue # stupid windows! + # we draw the glyph at the last position we calculated + bearing = glyph_bearing!(atlas, char, font, scale) + # we substract the first bearing, since we want to start at + # startposition without any additional offset! + positions[i] = last_pos .+ bearing .- first_bearing + # then we add the advance for the next glyph to start + last_pos = calc_position(last_pos, start_pos, atlas, char, font, scale) + end end return positions end From b8ea6bf191c39f56196c3688260c015e22f26bb9 Mon Sep 17 00:00:00 2001 From: SimonDanisch Date: Wed, 25 Mar 2020 16:54:28 +0100 Subject: [PATCH 5/5] fix tests --- src/basic_recipes/axis.jl | 20 +++++++++++--------- src/theming.jl | 2 +- test/runtests.jl | 3 +-- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/basic_recipes/axis.jl b/src/basic_recipes/axis.jl index 46e714996..fa0edf34e 100644 --- a/src/basic_recipes/axis.jl +++ b/src/basic_recipes/axis.jl @@ -36,14 +36,13 @@ $(ATTRIBUTES) showgrid = true, showticks = true, showtickmarks = true, - padding = 0.1, + padding = 0.0, ticks = Theme( - ranges_labels = (automatic, automatic), formatter = Formatters.plain, - gap = 3, + gap = 1, title_gap = 3, linewidth = (1, 1), @@ -56,9 +55,10 @@ $(ATTRIBUTES) align = ((:center, :top), (:right, :center)), font = lift(dim2, theme(scene, :font)), ), + tickmarks = Theme( - length = (3.0, 3.0), - linewidth = (1,1), + length = (1.0, 1.0), + linewidth = (1, 1), linecolor = ((:black, 0.4), (:black, 0.2)), linestyle = (nothing, nothing) ), @@ -383,9 +383,12 @@ function draw_titles( textcolor, textsize, rotation, align, font, title ) - tickspace_x = widths(text_bb( - last(first(yticks)), to_font(tickfont[2]), tick_size[2] - ))[1] + + tickspace_x = maximum(map(yticks) do tick + str = last(tick) + tick_bb = text_bb(str, to_font(tickfont[2]), tick_size[2]) + widths(tick_bb)[1] + end) tickspace_y = widths(text_bb( last(first(xticks)), to_font(tickfont[1]), tick_size[1] @@ -409,7 +412,6 @@ function draw_titles( ) end end - if title !== nothing # TODO give title own text attributes push!( diff --git a/src/theming.jl b/src/theming.jl index 755c50fa5..224604863 100644 --- a/src/theming.jl +++ b/src/theming.jl @@ -44,7 +44,7 @@ const minimal_default = Attributes( axis_type = automatic, camera = automatic, limits = automatic, - padding = Vec3f0(0.1), + padding = Vec3f0(0.05), raw = false ) diff --git a/test/runtests.jl b/test/runtests.jl index 10c1332e2..51ccf0b2f 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -4,7 +4,6 @@ using Test using GLMakie # Download reference images from master -MakieGallery.current_ref_version[] = "master" const MINIMAL = get(ENV, "ABSTRACTPLOTTING_MINIMAL", "false") @@ -35,7 +34,7 @@ include("shorthands.jl") @test scene[Axis].ticks.title_gap[] == 3 scene[Axis].ticks.title_gap = 4 @test scene[Axis].ticks.title_gap[] == 4 - @test scene[Axis].tickmarks.length[] == (3, 3) + @test scene[Axis].tickmarks.length[] == (1, 1) end