Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CairoMakie heatmap cell sizes #3625

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions CairoMakie/src/primitives.jl
Original file line number Diff line number Diff line change
Expand Up @@ -777,21 +777,20 @@ function _draw_rect_heatmap(ctx, xys, ni, nj, colors, margin_factor=0.05f0)
p2 = xys[i+1, j]
p3 = xys[i+1, j+1]
p4 = xys[i, j+1]

# dx and dy are the margin widths that are added to the
# heatmap cell sizes further down
# adding 5% seems like a good compromise between avoiding artifacts
# and not changing pixel sizes too much
# how much is added can be controlled via margin_factor

dx = abs(p2[1] - p1[1]) * 0.5f0 * margin_factor
dy = abs(p4[2] - p1[2]) * 0.5f0 * margin_factor


# Rectangles and polygons that are directly adjacent usually show
# white lines between them due to anti aliasing. To avoid this we
# increase their size slightly.

if alpha(colors[i, j]) == 1 && margin_factor > 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if using a transparent colormap here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem mostly goes away, but when you set alpha=0.99 for example, there are still some cases where artifacts occur. For example thin lines that shouldn't be there.

# dx and dy are the margin widths that are added to the
# heatmap cell sizes further down
# adding 5% seems like a good compromise between avoiding artifacts
# and not changing pixel sizes too much
# how much is added can be controlled via margin_factor
dx = abs(p2[1] - p1[1]) * 0.5f0 * margin_factor
dy = abs(p4[2] - p1[2]) * 0.5f0 * margin_factor

# 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
Expand Down
Loading