Skip to content

Commit

Permalink
Fix CairoMakie heatmap offsets (#4633)
Browse files Browse the repository at this point in the history
* fix heatmap offsets

* Update CHANGELOG.md

* widen pad on hidden side to full pixel/unit

* increase padding for 3D and clamp it

* extend along cell directions, not index dimensions

---------

Co-authored-by: Simon <[email protected]>
  • Loading branch information
ffreyer and SimonDanisch authored Nov 29, 2024
1 parent a4e4d73 commit 068670b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- Fix render order of Axis3 frame lines in CairoMakie [#4591](https://github.com/MakieOrg/Makie.jl/pull/4591)
- Fix color mapping between contourf and colorbar [#4618](https://github.com/MakieOrg/Makie.jl/pull/4618)
- Fixed an incorrect comparison in CairoMakie's line clipping code causing a line segment to disappear [#4631](https://github.com/MakieOrg/Makie.jl/pull/4631)
- Fixed heatmap cells being 0.5px/units too large in CairoMakie [4633](https://github.com/MakieOrg/Makie.jl/pull/4633)

## [0.21.16] - 2024-11-06

Expand Down
23 changes: 13 additions & 10 deletions CairoMakie/src/primitives.jl
Original file line number Diff line number Diff line change
Expand Up @@ -866,15 +866,18 @@ function _draw_rect_heatmap(ctx, xys, ni, nj, colors)
# increase their size slightly.

if alpha(colors[i, j]) == 1
# sign.(p - center) gives the direction in which we need to
# extend the polygon. (Which may change due to rotations in the
# model matrix.) (i!=1) etc is used to avoid increasing the
# outer extent of the heatmap.
center = 0.25f0 * (p1 + p2 + p3 + p4)
p1 += sign.(p1 - center) .* Point2f(0.5f0 * (i!=1), 0.5f0 * (j!=1))
p2 += sign.(p2 - center) .* Point2f(0.5f0 * (i!=ni), 0.5f0 * (j!=1))
p3 += sign.(p3 - center) .* Point2f(0.5f0 * (i!=ni), 0.5f0 * (j!=nj))
p4 += sign.(p4 - center) .* Point2f(0.5f0 * (i!=1), 0.5f0 * (j!=nj))
# To avoid gaps between heatmap cells we pad cells.
# For 3D compatability (and rotation, inversion/mirror) we pad cells
# using directional vectors, not along x/y directions.
v1 = normalize(p2 - p1)
v2 = normalize(p4 - p1)
# To avoid shifting cells we only pad them on the +i, +j side, which
# gets covered by later cells.
# To avoid enlarging the final column and row of the heatmap, the
# last set of cells is not padded. (i != ni), (j != nj)
p2 += Float32(i != ni) * v1
p3 += Float32(i != ni) * v1 + Float32(j != nj) * v2
p4 += Float32(j != nj) * v2
end

Cairo.set_line_width(ctx, 0)
Expand Down Expand Up @@ -1254,7 +1257,7 @@ function draw_atomic(scene::Scene, screen::Screen, @nospecialize(primitive::Maki
scale = Makie.voxel_size(primitive)
colors = Makie.voxel_colors(primitive)
marker = GeometryBasics.normal_mesh(Rect3f(Point3f(-0.5), Vec3f(1)))

# Face culling
if !isempty(primitive.clip_planes[]) && Makie.is_data_space(primitive.space[])
valid = [is_visible(primitive.clip_planes[], p) for p in pos]
Expand Down

0 comments on commit 068670b

Please sign in to comment.