Skip to content

Commit

Permalink
Merge branch 'master' into jk/error-on-unknown-attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonDanisch authored Jul 14, 2023
2 parents 79bff1a + bd315b4 commit f87e68e
Show file tree
Hide file tree
Showing 88 changed files with 2,290 additions and 1,128 deletions.
12 changes: 12 additions & 0 deletions .github/ISSUE_TEMPLATE/bug-report-.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
name: 'Bug report '
about: Create a report to help us improve
title: ''
labels: bug
assignees: ''

---

- [ ] are you running newest version (version from docs) ?
- [ ] can you reproduce the bug with a fresh environment ? (`]activate --temp; add Makie`)
- [ ] What platform + GPU are you on?
12 changes: 12 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: enhancement
assignees: ''

---

### Feature description

### For plot types, please add an image of how it should look like
2 changes: 1 addition & 1 deletion CITATION.bib
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ @article{DanischKrumbiegel2021
number = {65},
pages = {3349},
author = {Simon Danisch and Julius Krumbiegel},
title = {Makie.jl: Flexible high-performance data visualization for Julia},
title = {{Makie.jl}: Flexible high-performance data visualization for {Julia}},
journal = {Journal of Open Source Software}
}
4 changes: 2 additions & 2 deletions CairoMakie/Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "CairoMakie"
uuid = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
author = ["Simon Danisch <[email protected]>"]
version = "0.10.5"
version = "0.10.6"

[deps]
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
Expand All @@ -23,7 +23,7 @@ FFTW = "1"
FileIO = "1.1"
FreeType = "3, 4.0"
GeometryBasics = "0.4.1"
Makie = "=0.19.5"
Makie = "=0.19.6"
PrecompileTools = "1.0"
julia = "1.3"

Expand Down
43 changes: 33 additions & 10 deletions CairoMakie/src/infrastructure.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function cairo_draw(screen::Screen, scene::Scene)
Cairo.save(screen.context)
draw_background(screen, scene)

allplots = get_all_plots(scene)
allplots = Makie.collect_atomic_plots(scene; is_atomic_plot = is_cairomakie_atomic_plot)
zvals = Makie.zvalue2d.(allplots)
permute!(allplots, sortperm(zvals))

Expand All @@ -23,10 +23,12 @@ function cairo_draw(screen::Screen, scene::Scene)

Cairo.save(screen.context)
for p in allplots
to_value(get(p, :visible, true)) || continue
check_parent_plots(p) do plot
to_value(get(plot, :visible, true))
end || continue
# only prepare for scene when it changes
# this should reduce the number of unnecessary clipping masks etc.
pparent = p.parent::Scene
pparent = Makie.parent_scene(p)
pparent.visible[] || continue
if pparent != last_scene
Cairo.restore(screen.context)
Expand All @@ -36,8 +38,8 @@ function cairo_draw(screen::Screen, scene::Scene)
end
Cairo.save(screen.context)

# When a plot is too large to save with a reasonable file size on a vector backend,
# the user can choose to rasterize it when plotting to vector backends, by using the
# When a plot is too large to save with a reasonable file size on a vector backend,
# the user can choose to rasterize it when plotting to vector backends, by using the
# `rasterize` keyword argument. This can be set to a Bool or an Int which describes
# the density of rasterization (in terms of a direct scaling factor.)
# TODO: In future, this can also be set to a Tuple{Module, Int} which describes
Expand All @@ -54,12 +56,33 @@ function cairo_draw(screen::Screen, scene::Scene)
return
end

function get_all_plots(scene, plots = AbstractPlot[])
append!(plots, scene.plots)
for c in scene.children
get_all_plots(c, plots)
"""
is_cairomakie_atomic_plot(plot::Combined)::Bool
Returns whether the plot is considered atomic for the CairoMakie backend.
This is overridden for `Poly`, `Band`, and `Tricontourf` so we can apply
CairoMakie can treat them as atomic plots and render them directly.
Plots with children are by default recursed into. This can be overridden
by defining specific dispatches for `is_cairomakie_atomic_plot` for a given plot type.
"""
is_cairomakie_atomic_plot(plot::Combined) = isempty(plot.plots) || to_value(get(plot, :rasterize, false)) != false

"""
check_parent_plots(f, plot::Combined)::Bool
Returns whether the plot's parent tree satisfies the predicate `f`.
`f` must return a `Bool` and take a plot as its only argument.
"""
function check_parent_plots(f, plot::Combined)
if f(plot)
check_parent_plots(f, parent(plot))
else
return false
end
plots
end

function check_parent_plots(f, scene::Scene)
return true
end

function prepare_for_scene(screen::Screen, scene::Scene)
Expand Down
16 changes: 16 additions & 0 deletions CairoMakie/src/overrides.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ function draw_plot(scene::Scene, screen::Screen, poly::Poly)
draw_poly(scene, screen, poly, to_value.(poly.input_args)...)
end

# Override `is_cairomakie_atomic_plot` to allow `poly` to remain a unit,
# instead of auto-decomposing in lines and mesh.
is_cairomakie_atomic_plot(plot::Poly) = true

"""
Fallback method for args without special treatment.
"""
Expand Down Expand Up @@ -182,6 +186,12 @@ function draw_plot(scene::Scene, screen::Screen,
nothing
end

# Override `is_cairomakie_atomic_plot` to allow this dispatch of `band` to remain a unit,
# instead of auto-decomposing in lines and mesh.
function is_cairomakie_atomic_plot(plot::Band{<:Tuple{<:AbstractVector{<:Point2},<:AbstractVector{<:Point2}}})
return true
end

#################################################################################
# Tricontourf #
# Tricontourf creates many disjoint polygons that are adjacent and form contour #
Expand Down Expand Up @@ -214,3 +224,9 @@ function draw_plot(scene::Scene, screen::Screen, tric::Tricontourf)

return
end

# Override `is_cairomakie_atomic_plot` to allow `Tricontourf` to remain a unit,
# instead of auto-decomposing in lines and mesh.
function is_cairomakie_atomic_plot(plot::Tricontourf)
return true
end
4 changes: 2 additions & 2 deletions CairoMakie/src/screen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ end
to_cairo_antialias(aa::Int) = aa

"""
* `px_per_unit = 1.0`: see [figure size docs](https://docs.makie.org/v0.17.13/documentation/figure_size/index.html).
* `pt_per_unit = 0.75`: see [figure size docs](https://docs.makie.org/v0.17.13/documentation/figure_size/index.html).
* `px_per_unit = 1.0`: see [figure size docs](https://docs.makie.org/stable/documentation/figure_size/).
* `pt_per_unit = 0.75`: see [figure size docs](https://docs.makie.org/stable/documentation/figure_size/).
* `antialias::Union{Symbol, Int} = :best`: antialias modus Cairo uses to draw. Applicable options: `[:best => Cairo.ANTIALIAS_BEST, :good => Cairo.ANTIALIAS_GOOD, :subpixel => Cairo.ANTIALIAS_SUBPIXEL, :none => Cairo.ANTIALIAS_NONE]`.
* `visible::Bool`: if true, a browser/image viewer will open to display rendered output.
"""
Expand Down
4 changes: 2 additions & 2 deletions GLMakie/Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "GLMakie"
uuid = "e9467ef8-e4e7-5192-8a1a-b1aee30e663a"
version = "0.8.5"
version = "0.8.6"

[deps]
ColorTypes = "3da002f7-5984-5a60-b8a6-cbb66c0b333f"
Expand Down Expand Up @@ -29,7 +29,7 @@ FixedPointNumbers = "0.7, 0.8"
FreeTypeAbstraction = "0.10"
GLFW = "3"
GeometryBasics = "0.4.1"
Makie = "=0.19.5"
Makie = "=0.19.6"
MeshIO = "0.4"
ModernGL = "1"
Observables = "0.5.1"
Expand Down
43 changes: 39 additions & 4 deletions GLMakie/assets/shader/distance_shape.frag
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ struct Nothing{ //Nothing type, to encode if some variable doesn't contain any d
#define ROUNDED_RECTANGLE 2
#define DISTANCEFIELD 3
#define TRIANGLE 4
#define ELLIPSE 5

#define M_SQRT_2 1.4142135

Expand All @@ -37,6 +38,7 @@ flat in uvec2 f_id;
flat in int f_primitive_index;
in vec2 f_uv; // f_uv.{x,y} are in the interval [-a, 1+a]
flat in vec4 f_uv_texture_bbox;
flat in vec2 f_sprite_scale;

// These versions of aastep assume that `dist` is a signed distance function
// which has been scaled to be in units of pixels.
Expand Down Expand Up @@ -65,15 +67,46 @@ float triangle(vec2 P){
return -max(r1,r2);
}
float circle(vec2 uv){
return 0.5-length(uv-vec2(0.5));
return 0.5 - length(uv - vec2(0.5));
}
float rectangle(vec2 uv){
vec2 d = max(-uv, uv-vec2(1));
vec2 s = f_sprite_scale / min(f_sprite_scale.x, f_sprite_scale.y);
vec2 d = s * max(-uv, uv-vec2(1));
return -((length(max(vec2(0.0), d)) + min(0.0, max(d.x, d.y))));
}
float rounded_rectangle(vec2 uv, vec2 tl, vec2 br){
vec2 d = max(tl-uv, uv-br);
return -((length(max(vec2(0.0), d)) + min(0.0, max(d.x, d.y)))-tl.x);
vec2 s = f_sprite_scale / min(f_sprite_scale.x, f_sprite_scale.y);
vec2 d = s * max(tl-uv, uv-br);
return -((length(max(vec2(0.0), d)) + min(0.0, max(d.x, d.y))) - s.x * tl.x);
}
// See https://iquilezles.org/articles/ellipsedist/
float ellipse(vec2 uv, vec2 scale)
{
// to central coordinates, use symmetry (quarter ellipse, 0 <= p <= wh)
vec2 wh = scale / min(scale.x, scale.y);
vec2 p = wh * abs(uv - vec2(0.5));
wh = wh * 0.5;

// initial value
vec2 q = wh * (p - wh);
vec2 cs = normalize( (q.x<q.y) ? vec2(0.01,1) : vec2(1,0.01) );

// find root with Newton solver
for( int i=0; i<5; i++ )
{
vec2 u = wh * vec2( cs.x, cs.y);
vec2 v = wh * vec2(-cs.y, cs.x);
float a = dot(p-u,v);
float c = dot(p-u,u) + dot(v,v);
float b = sqrt(c*c-a*a);
cs = vec2( cs.x*b-cs.y*a, cs.y*b+cs.x*a )/c;
}

// compute final point and distance
float d = length(p - wh*cs);

// return signed distance
return (dot(p/wh,p/wh)>1.0) ? -d : d;
}

void fill(vec4 fillcolor, Nothing image, vec2 uv, float infill, inout vec4 color){
Expand Down Expand Up @@ -141,6 +174,8 @@ void main(){
signed_distance = rectangle(f_uv);
else if(shape == TRIANGLE)
signed_distance = triangle(f_uv);
else if(shape == ELLIPSE)
signed_distance = ellipse(f_uv, f_sprite_scale);

// See notes in geometry shader where f_viewport_from_u_scale is computed.
signed_distance *= f_viewport_from_u_scale;
Expand Down
40 changes: 31 additions & 9 deletions GLMakie/assets/shader/lines.geom
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,21 @@ vec3 screen_space(vec4 vertex)
// Manual uv calculation
// - position in screen space (double resolution as generally used)
// - uv with uv.u normalized (0..1), uv.v unnormalized (0..pattern_length)
void emit_vertex(vec3 position, vec2 uv, int index)
void emit_vertex(vec3 position, vec2 uv, int index, float thickness)
{
f_uv = uv;
f_color = g_color[index];
gl_Position = vec4((position.xy / resolution), position.z, 1.0);
f_id = g_id[index];
f_thickness = g_thickness[index];
// linewidth scaling may shrink the effective linewidth
f_thickness = thickness;
EmitVertex();
}
// default for miter joins
void emit_vertex(vec3 position, vec2 uv, int index)
{
emit_vertex(position, uv, index, g_thickness[index]);
}

// For center point
void emit_vertex(vec3 position, vec2 uv)
Expand All @@ -71,15 +77,20 @@ void emit_vertex(vec3 position, vec2 uv)
}

// Debug
void emit_vertex(vec3 position, vec2 uv, int index, vec4 color)
void emit_vertex(vec3 position, vec2 uv, int index, vec4 color, float thickness)
{
f_uv = uv;
f_color = color;
gl_Position = vec4((position.xy / resolution), position.z, 1.0);
f_id = g_id[index];
f_thickness = g_thickness[index];
f_thickness = thickness;
EmitVertex();
}
// default for miter joins
void emit_vertex(vec3 position, vec2 uv , int index, vec4 color)
{
emit_vertex(position, uv , index, color, g_thickness[index]);
}
void emit_vertex(vec3 position, vec2 uv, vec4 color)
{
f_uv = uv;
Expand All @@ -97,8 +108,11 @@ void emit_vertex(vec3 position, vec2 offset, vec2 line_dir, vec2 uv, int index)
emit_vertex(
position + vec3(offset, 0),
vec2(uv.x + px2uv * dot(line_dir, offset), uv.y),
index
index,
abs(uv.y) - AA_THICKNESS
);
// `abs(uv.y) - AA_THICKNESS` corrects for enlarged AA padding between
// segments of different linewidth, see #2953
}

void emit_vertex(vec3 position, vec2 offset, vec2 line_dir, vec2 uv)
Expand Down Expand Up @@ -618,10 +632,6 @@ void draw_solid_line(bool isvalid[4])
vec3 p2 = screen_space(gl_in[2].gl_Position); // end of current segment, start of next segment
vec3 p3 = screen_space(gl_in[3].gl_Position); // end of next segment

// linewidth with padding for anti aliasing
float thickness_aa1 = g_thickness[1] + AA_THICKNESS;
float thickness_aa2 = g_thickness[2] + AA_THICKNESS;

// determine the direction of each of the 3 segments (previous, current, next)
vec3 v1 = p2 - p1;
float segment_length = length(v1.xy);
Expand All @@ -641,6 +651,14 @@ void draw_solid_line(bool isvalid[4])
vec2 n1 = vec2(-v1.y, v1.x);
vec2 n2 = vec2(-v2.y, v2.x);

// determine stretching of AA border due to linewidth change
float temp = (g_thickness[2] - g_thickness[1]) / segment_length;
float edge_scale = sqrt(1 + temp * temp);

// linewidth with padding for anti aliasing (used for geometry)
float thickness_aa1 = g_thickness[1] + edge_scale * AA_THICKNESS;
float thickness_aa2 = g_thickness[2] + edge_scale * AA_THICKNESS;

// Setup for sharp corners (see above)
vec2 miter_a = normalize(n0 + n1);
vec2 miter_b = normalize(n1 + n2);
Expand Down Expand Up @@ -717,6 +735,10 @@ void draw_solid_line(bool isvalid[4])
segment_length += corner_offset;
}

// scaling of uv.y due to different linewidths
// the padding for AA_THICKNESS should always have AA_THICKNESS width in uv
thickness_aa1 = g_thickness[1] / edge_scale + AA_THICKNESS;
thickness_aa2 = g_thickness[2] / edge_scale + AA_THICKNESS;

// Generate line segment
u1 *= px2uv;
Expand Down
4 changes: 3 additions & 1 deletion GLMakie/assets/shader/sprites.geom
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ flat out vec4 f_glow_color;
flat out uvec2 f_id;
out vec2 f_uv;
flat out vec4 f_uv_texture_bbox;
flat out vec2 f_sprite_scale;

uniform mat4 projection, view, model;

Expand Down Expand Up @@ -88,6 +89,7 @@ void emit_vertex(vec4 vertex, vec2 uv)
f_stroke_color = g_stroke_color[0];
f_glow_color = g_glow_color[0];
f_id = g_id[0];
f_sprite_scale = g_offset_width[0].zw;
EmitVertex();
}

Expand Down Expand Up @@ -157,7 +159,7 @@ void main(void)
// any calculation based on them will not be a distance function.)
// * For sampled distance fields, we need to consistently choose the *x*
// for the scaling in get_distancefield_scale().
float sprite_from_u_scale = abs(o_w.z);
float sprite_from_u_scale = min(abs(o_w.z), abs(o_w.w));
f_viewport_from_u_scale = viewport_from_sprite_scale * sprite_from_u_scale;
f_distancefield_scale = get_distancefield_scale(distancefield);

Expand Down
Loading

0 comments on commit f87e68e

Please sign in to comment.