Skip to content

Commit

Permalink
Merge branch 'master' into cscale-overlap
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonDanisch authored Aug 17, 2023
2 parents 93a4af3 + 280421b commit 94483e4
Show file tree
Hide file tree
Showing 19 changed files with 303 additions and 95 deletions.
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 <sdanisch@gmail.com>"]
version = "0.10.7"
version = "0.10.8"

[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.7"
Makie = "=0.19.8"
PrecompileTools = "1.0"
julia = "1.3"

Expand Down
1 change: 1 addition & 0 deletions CairoMakie/src/overrides.jl
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ function draw_poly(scene::Scene, screen::Screen, poly, rects::Vector{<:Rect2})
end

function polypath(ctx, polygon)
isempty(polygon) && return nothing
ext = decompose(Point2f, polygon.exterior)
Cairo.set_fill_type(ctx, Cairo.CAIRO_FILL_RULE_EVEN_ODD)
Cairo.move_to(ctx, ext[1]...)
Expand Down
121 changes: 103 additions & 18 deletions CairoMakie/src/primitives.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@ function draw_atomic(scene::Scene, screen::Screen, @nospecialize(primitive::Unio
# stroke each segment separately, this means disjointed segments with probably
# wonky dash patterns if segments are short

# we can hide the gaps by setting the line cap to round
Cairo.set_line_cap(ctx, Cairo.CAIRO_LINE_CAP_ROUND)
# Butted segments look the best for varying colors, at least when connection angles are small.
# While round style has nicer sharp joins, it looks bad with alpha colors (double paint) and
# also messes with dash patterns (they are too long because of the caps)
Cairo.set_line_cap(ctx, Cairo.CAIRO_LINE_CAP_BUTT)
draw_multi(
primitive, ctx,
projected_positions,
Expand Down Expand Up @@ -158,30 +160,22 @@ function draw_multi(primitive, ctx, positions, color, linewidths::AbstractArray,
draw_multi(primitive, ctx, positions, [color for l in linewidths], linewidths, dash)
end

function draw_multi(primitive::Union{Lines, LineSegments}, ctx, positions, colors::AbstractArray, linewidths::AbstractArray, dash)
if primitive isa LineSegments
@assert iseven(length(positions))
end
function draw_multi(primitive::LineSegments, ctx, positions, colors::AbstractArray, linewidths::AbstractArray, dash)
@assert iseven(length(positions))
@assert length(positions) == length(colors)
@assert length(linewidths) == length(colors)

iterator = if primitive isa Lines
1:length(positions)-1
elseif primitive isa LineSegments
1:2:length(positions)
end

for i in iterator
for i in 1:2:length(positions)
if isnan(positions[i+1]) || isnan(positions[i])
continue
end
Cairo.move_to(ctx, positions[i]...)

Cairo.line_to(ctx, positions[i+1]...)
if linewidths[i] != linewidths[i+1]
error("Cairo doesn't support two different line widths ($(linewidths[i]) and $(linewidths[i+1])) at the endpoints of a line.")
end
Cairo.move_to(ctx, positions[i]...)
Cairo.line_to(ctx, positions[i+1]...)
Cairo.set_line_width(ctx, linewidths[i])

!isnothing(dash) && Cairo.set_dash(ctx, dash .* linewidths[i])
c1 = colors[i]
c2 = colors[i+1]
Expand All @@ -199,8 +193,99 @@ function draw_multi(primitive::Union{Lines, LineSegments}, ctx, positions, color
Cairo.destroy(pat)
end
end
# force clearing of path in case of skipped NaN
Cairo.new_path(ctx)
end

function draw_multi(primitive::Lines, ctx, positions, colors::AbstractArray, linewidths::AbstractArray, dash)
@assert length(positions) == length(colors)
@assert length(linewidths) == length(colors)

prev_color = colors[begin]
prev_linewidth = linewidths[begin]
prev_position = positions[begin]
prev_nan = isnan(prev_position)
prev_continued = false

if !prev_nan
# first is not nan, move_to
Cairo.move_to(ctx, positions[begin]...)
else
# first is nan, do nothing
end

for i in eachindex(positions)[2:end]
this_position = positions[i]
this_color = colors[i]
this_nan = isnan(this_position)
this_linewidth = linewidths[i]
if this_nan
# this is nan
if prev_continued
# and this is prev_continued, so set source and stroke to finish previous line
Cairo.set_line_width(ctx, this_linewidth)
!isnothing(dash) && Cairo.set_dash(ctx, dash .* this_linewidth)
Cairo.set_source_rgba(ctx, red(prev_color), green(prev_color), blue(prev_color), alpha(prev_color))
Cairo.stroke(ctx)
else
# but this is not prev_continued, so do nothing
end
end
if prev_nan
# previous was nan
if !this_nan
# but this is not nan, so move to this position
Cairo.move_to(ctx, this_position...)
else
# and this is also nan, do nothing
end
else
if this_color == prev_color
# this color is like the previous
if !this_nan
# and this is not nan, so line_to and set prev_continued
this_linewidth != prev_linewidth && error("Encountered two different linewidth values $prev_linewidth and $this_linewidth in `lines` at index $(i-1). Different linewidths in one line are only permitted in CairoMakie when separated by a NaN point.")
Cairo.line_to(ctx, this_position...)
prev_continued = true

if i == lastindex(positions)
# this is the last element so stroke this
Cairo.set_line_width(ctx, this_linewidth)
!isnothing(dash) && Cairo.set_dash(ctx, dash .* this_linewidth)
Cairo.set_source_rgba(ctx, red(this_color), green(this_color), blue(this_color), alpha(this_color))
Cairo.stroke(ctx)
end
else
# but this is nan, so do nothing
end
else
prev_continued = false
if !this_nan
this_linewidth != prev_linewidth && error("Encountered two different linewidth values $prev_linewidth and $this_linewidth in `lines` at index $(i-1). Different linewidths in one line are only permitted in CairoMakie when separated by a NaN point.")
# this is not nan
# and this color is different than the previous, so move_to prev and line_to this
# create gradient pattern and stroke
Cairo.move_to(ctx, prev_position...)
Cairo.line_to(ctx, this_position...)
!isnothing(dash) && Cairo.set_dash(ctx, dash .* this_linewidth)
Cairo.set_line_width(ctx, this_linewidth)

pat = Cairo.pattern_create_linear(prev_position..., this_position...)
Cairo.pattern_add_color_stop_rgba(pat, 0, red(prev_color), green(prev_color), blue(prev_color), alpha(prev_color))
Cairo.pattern_add_color_stop_rgba(pat, 1, red(this_color), green(this_color), blue(this_color), alpha(this_color))
Cairo.set_source(ctx, pat)
Cairo.stroke(ctx)
Cairo.destroy(pat)

Cairo.move_to(ctx, this_position...)
else
# this is nan, do nothing
end
end
end
prev_nan = this_nan
prev_color = this_color
prev_linewidth = linewidths[i]
prev_position = this_position
end
end

################################################################################
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.7"
version = "0.8.8"

[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.7"
Makie = "=0.19.8"
MeshIO = "0.4"
ModernGL = "1"
Observables = "0.5.1"
Expand Down
2 changes: 1 addition & 1 deletion MakieCore/Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
authors = ["Simon Danisch"]
name = "MakieCore"
uuid = "20f20a25-4f0e-4fdf-b5d1-57303727442b"
version = "0.6.4"
version = "0.6.5"

[deps]
Observables = "510215fc-4207-5dde-b226-833fc4488ee2"
Expand Down
2 changes: 2 additions & 0 deletions MakieCore/src/basic_plots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,7 @@ Plots polygons, which are defined by
Vector or Matrices of numbers can be used as well, which will use the colormap arguments to map the numbers to colors.
One can also use `Makie.LinePattern`, to cover the poly with a regular stroke pattern.
- `strokecolor::Union{Symbol, <:Colorant} = :black` sets the color of the outline around a marker.
- `strokecolormap`::Union{Symbol, Vector{<:Colorant}} = :viridis` sets the colormap that is sampled for numeric `color`s.
- `strokewidth::Real = 0` sets the width of the outline around a marker.
- `linestyle::Union{Nothing, Symbol, Vector} = nothing` sets the pattern of the line (e.g. `:solid`, `:dot`, `:dashdot`)
Expand All @@ -533,6 +534,7 @@ $(Base.Docs.doc(MakieCore.generic_plot_attributes!))
color = theme(scene, :patchcolor),

strokecolor = theme(scene, :patchstrokecolor),
strokecolormap = theme(scene, :colormap),
strokewidth = theme(scene, :patchstrokewidth),
linestyle = nothing,

Expand Down
7 changes: 6 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@

## master

- Allow arbitrary reversible scale functions through `Makie.ReversibleScale`.
- Allow arbitrary reversible scale functions through `Makie.ReversibleScale` [#3095](https://github.com/MakieOrg/Makie.jl/pull/3095).

## v0.19.8

- Improved CairoMakie rendering of `lines` with repeating colors in an array [#3141](https://github.com/MakieOrg/Makie.jl/pull/3141).
- Added `strokecolormap` to poly. [#3145](https://github.com/MakieOrg/Makie.jl/pull/3145)
- Added `xreversed`, `yreversed` and `zreversed` attributes to `Axis3` [#3138](https://github.com/MakieOrg/Makie.jl/pull/3138).
- Fixed incorrect placement of contourlabels with transform functions [#3083](https://github.com/MakieOrg/Makie.jl/pull/3083)
- Fixed automatic normal generation for meshes with shading and no normals [#3041](https://github.com/MakieOrg/Makie.jl/pull/3041).
Expand Down
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Makie"
uuid = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
authors = ["Simon Danisch", "Julius Krumbiegel"]
version = "0.19.7"
version = "0.19.8"

[deps]
Animations = "27a7e980-b3e6-11e9-2bcd-0b925532e340"
Expand Down Expand Up @@ -82,7 +82,7 @@ Isoband = "0.1"
KernelDensity = "0.5, 0.6"
LaTeXStrings = "1.2"
MacroTools = "0.5"
MakieCore = "=0.6.4"
MakieCore = "=0.6.5"
Match = "1.1"
MathTeXEngine = "0.5"
Observables = "0.5.3"
Expand Down
Loading

0 comments on commit 94483e4

Please sign in to comment.