Skip to content

Commit

Permalink
Merge branch 'master' into ff/fix_position_on_plot
Browse files Browse the repository at this point in the history
  • Loading branch information
ffreyer authored Sep 28, 2024
2 parents 708d4a3 + c2b7b0b commit e3b9108
Show file tree
Hide file tree
Showing 15 changed files with 103 additions and 30 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# Changelog

## [Unreleased]
- Fix NaN handling in WGLMakie [#4282](https://github.com/MakieOrg/Makie.jl/pull/4282).

- Show DataInspector tooltip on NaN values if `nan_color` has been set to other than `:transparent` [#4310](https://github.com/MakieOrg/Makie.jl/pull/4310)
- Fix `linestyle` not being used in `triplot` [#4332](https://github.com/MakieOrg/Makie.jl/pull/4332)
- Fix voxel clipping not being based on voxel centers [#4397](https://github.com/MakieOrg/Makie.jl/pull/4397)
- Fix incorrect inverse transformation in `position_on_plot` for lines, causing incorrect tooltip placement in DataInspector [#4402](https://github.com/MakieOrg/Makie.jl/pull/4402)
- Parsing `Q` and `q` commands in svg paths with `BezierPath` is now supported [#4413](https://github.com/MakieOrg/Makie.jl/pull/4413)

## [0.21.11] - 2024-09-13

Expand All @@ -18,7 +20,7 @@
- Make sure we wait for the screen session [#4316](https://github.com/MakieOrg/Makie.jl/pull/4316).
- Fix for absrect [#4312](https://github.com/MakieOrg/Makie.jl/pull/4312).
- Fix attribute updates for SpecApi and SpecPlots (e.g. ecdfplot) [#4265](https://github.com/MakieOrg/Makie.jl/pull/4265).
- Bring back `poly` convert arguments for matrix with points as row [#4266](https://github.com/MakieOrg/Makie.jl/pull/4258).
- Bring back `poly` convert arguments for matrix with points as row [#4258](https://github.com/MakieOrg/Makie.jl/pull/4258).
- Fix gl_ClipDistance related segfault on WSL with GLMakie [#4270](https://github.com/MakieOrg/Makie.jl/pull/4270).
- Added option `label_position = :center` to place labels centered over each bar [#4274](https://github.com/MakieOrg/Makie.jl/pull/4274).
- `plotfunc()` and `func2type()` support functions ending with `!` [#4275](https://github.com/MakieOrg/Makie.jl/pull/4275).
Expand Down
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ FreeTypeAbstraction = "0.10.3"
GeometryBasics = "0.4.11"
GridLayoutBase = "0.11"
ImageBase = "0.1.7"
ImageIO = "0.2, 0.3, 0.4, 0.5, 0.6"
ImageIO = "0.5, 0.6"
InteractiveUtils = "1.0, 1.6"
Interpolations = "0.15.1"
Interpolations = "0.14, 0.15.1"
IntervalSets = "0.3, 0.4, 0.5, 0.6, 0.7"
Isoband = "0.1"
KernelDensity = "0.5, 0.6"
Expand Down
4 changes: 2 additions & 2 deletions WGLMakie/src/Lines.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ function lines_vertex_shader(uniforms, attributes, is_linesegments) {
// used to compute width sdf
f_linewidth = halfwidth;
f_instance_id = uint(2 * gl_InstanceID);
f_instance_id = lineindex_start; // NOTE: this is correct, no need to multiple by 2
// we restart patterns for each segment
f_cumulative_length = 0.0;
Expand Down Expand Up @@ -640,7 +640,7 @@ function lines_vertex_shader(uniforms, attributes, is_linesegments) {
// used to compute width sdf
f_linewidth = halfwidth;
f_instance_id = uint(gl_InstanceID);
f_instance_id = lineindex_start;
f_cumulative_length = lastlen_start;
Expand Down
22 changes: 16 additions & 6 deletions WGLMakie/src/Shaders.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
function typedarray_to_vectype(typedArray, ndim) {
if (ndim === 1) {
return "float";
} else if (typedArray instanceof Float32Array) {
return "vec" + ndim;
if (typedArray instanceof Float32Array) {
if (ndim === 1) {
return "float";
} else {
return "vec" + ndim;
}
} else if (typedArray instanceof Int32Array) {
return "ivec" + ndim;
if (ndim === 1) {
return "int";
} else {
return "ivec" + ndim;
}
} else if (typedArray instanceof Uint32Array) {
return "uvec" + ndim;
if (ndim === 1) {
return "uint";
} else {
return "uvec" + ndim;
}
} else {
return;
}
Expand Down
7 changes: 5 additions & 2 deletions WGLMakie/src/lines.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function serialize_three(scene::Scene, plot::Union{Lines, LineSegments})
# involved point are not NaN, i.e. p1 -- p2 is only drawn if all of
# (p0, p1, p2, p3) are not NaN. So if p3 is NaN we need to dublicate p2 to
# make the p1 -- p2 segment draw, which is what indices does.
indices = Observable(Int[])
indices = Observable(UInt32[])
points_transformed = lift(
plot, f32c, transform_func_obs(plot), plot.model, plot[1], plot.space
) do f32c, tf, model, ps, space
Expand Down Expand Up @@ -118,7 +118,10 @@ function serialize_three(scene::Scene, plot::Union{Lines, LineSegments})
end
end
positions = lift(serialize_buffer_attribute, plot, points_transformed)
attributes = Dict{Symbol, Any}(:linepoint => positions)
attributes = Dict{Symbol, Any}(
:linepoint => positions,
:lineindex => lift(_ -> serialize_buffer_attribute(indices[]), plot, points_transformed),
)

# TODO: in Javascript
# NOTE: clip.w needs to be available in shaders to avoid line inversion problems
Expand Down
26 changes: 18 additions & 8 deletions WGLMakie/src/wglmakie.bundled.js
Original file line number Diff line number Diff line change
Expand Up @@ -20196,14 +20196,24 @@ function getErrorMessage(version) {
return element;
}
function typedarray_to_vectype(typedArray, ndim) {
if (ndim === 1) {
return "float";
} else if (typedArray instanceof Float32Array) {
return "vec" + ndim;
if (typedArray instanceof Float32Array) {
if (ndim === 1) {
return "float";
} else {
return "vec" + ndim;
}
} else if (typedArray instanceof Int32Array) {
return "ivec" + ndim;
if (ndim === 1) {
return "int";
} else {
return "ivec" + ndim;
}
} else if (typedArray instanceof Uint32Array) {
return "uvec" + ndim;
if (ndim === 1) {
return "uint";
} else {
return "uvec" + ndim;
}
} else {
return;
}
Expand Down Expand Up @@ -21473,7 +21483,7 @@ function lines_vertex_shader(uniforms, attributes, is_linesegments) {
// used to compute width sdf
f_linewidth = halfwidth;

f_instance_id = uint(2 * gl_InstanceID);
f_instance_id = lineindex_start; // NOTE: this is correct, no need to multiple by 2

// we restart patterns for each segment
f_cumulative_length = 0.0;
Expand Down Expand Up @@ -21920,7 +21930,7 @@ function lines_vertex_shader(uniforms, attributes, is_linesegments) {
// used to compute width sdf
f_linewidth = halfwidth;

f_instance_id = uint(gl_InstanceID);
f_instance_id = lineindex_start;

f_cumulative_length = lastlen_start;

Expand Down
2 changes: 1 addition & 1 deletion docs/src/explanations/backends/rprmakie.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ using RadeonProRender
RadeonProRender.Context()
```

To use RPRMakie on a Mac with an M-series chip, for now, you need to use the x84 build of Julia (not the ARM build, you may have to download this manually). RadeonProRender does not distribute binaries built for the ARM architecture of the M-series processors yet.
To use RPRMakie on a Mac with an M-series chip, for now, you need to use the x86_64 build of Julia (not the ARM build, you may have to download this manually). RadeonProRender does not distribute binaries built for the ARM architecture of the M-series processors yet.

## Activation and screen config

Expand Down
6 changes: 3 additions & 3 deletions docs/src/tutorials/wrap-existing-recipe.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ nothing # hide
```

Our target type is the `MyHist`, which has two fields, as defined above. Roughly speaking, when we
plot a histograms, we're talking about drawing a bar plot, where `barcenters` tells us where to draw
these bars and `barcounts` tells us how high each bar is.
plot a histograms, we're talking about drawing a bar plot, where `bincenters` tells us where to draw
these bars and `bincounts` tells us how high each bar is.

## BarPlot recipe -- extend `Makie.convert_arguments`

Expand Down Expand Up @@ -76,4 +76,4 @@ function Makie.plot!(plot::Hist{<:Tuple{<:MyHist}})
end
h = MyHist([1, 10, 100], 1:3)
hist(h; color=:red, direction=:x)
```
```
2 changes: 1 addition & 1 deletion src/basic_recipes/buffers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ function push!(tb::Annotations, text::String, position::VecTypes{N}; kw_args...)
end

function append!(tb::Annotations, text::Vector{String}, positions::Vector{Point{N, Float32}}; kw_args...) where N
text_positions = convert_argument(Annotations, text, positions)[1]
text_positions = convert_arguments(Annotations, text, positions)[1]
append!(tb, text_positions; kw_args...)
return
end
Expand Down
23 changes: 23 additions & 0 deletions src/bezier.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,19 @@ CurveTo(cx1, cy1, cx2, cy2, p1, p2) = CurveTo(
Point2d(cx1, cy1), Point2d(cx2, cy2), Point2d(p1, p2)
)

"""
quadratic_curve_to(x0::Real, y0::Real, cx1::Real, cy1::Real, p1::Real, p2::Real)
A path command for use within a `BezierPath` which continues the current subpath with a quadratic
bezier curve to point `p`, with the control point `c`. The curve is converted into a cubic bezier
curve internally.
"""
quadratic_curve_to(x0, y0, cx1, cy1, p1, p2) = CurveTo(
x0 + 2/3 * (cx1 - x0), y0 + 2/3 * (cy1 - y0),
p1 + 2/3 * (cx1 - p1), p2 + 2/3 * (cy1 - p2),
p1, p2
)

"""
EllipticalArc(c::VecTypes, r1::Real, r2::Real, angle::Real, a1::Real, a2::Real)
EllipticalArc(cx::Real, cy::Real, r1::Real, r2::Real, angle::Real, a1::Real, a2::Real)
Expand Down Expand Up @@ -492,6 +505,16 @@ function parse_bezier_commands(svg)
l = lastp()
push!(commands, LineTo(Point2d(l[1], y)))
i += 2
elseif comm == "Q"
x0, y0 = lastp()
x1, y1, x2, y2 = parse.(Float64, args[i+1:i+4])
push!(commands, quadratic_curve_to(x0, y0, x1, y1, x2, y2))
i += 5
elseif comm == "q"
x0, y0 = lastp()
x1, y1, x2, y2 = parse.(Float64, args[i+1:i+4])
push!(commands, quadratic_curve_to(x0, y0, x1 + x0, y1 + y0, x2 + x0, y2 + y0))
i += 5
else
for c in commands
println(c)
Expand Down
5 changes: 5 additions & 0 deletions src/conversions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ end
# Leave concretely typed vectors alone (AbstractArray{<:Union{Missing, <:Real}} also dispatches for `Vector{Float32}`)
convert_single_argument(a::AbstractArray{T}) where {T<:Real} = a
convert_single_argument(a::AbstractArray{<:Point{N, T}}) where {N, T} = a
convert_single_argument(a::OffsetArray{<:Point}) = OffsetArrays.no_offset_view(a)


################################################################################
Expand Down Expand Up @@ -88,6 +89,10 @@ function convert_arguments(::PointBased, positions::AbstractVector{<: VecTypes{N
return (elconvert(Point{N, float_type(_T)}, positions),)
end

function convert_arguments(T::PointBased, positions::OffsetVector)
return convert_arguments(T, OffsetArrays.no_offset_view(positions))
end

function convert_arguments(::PointBased, positions::SubArray{<: VecTypes, 1})
# TODO figure out a good subarray solution
(positions,)
Expand Down
8 changes: 5 additions & 3 deletions src/interaction/inspector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -677,10 +677,12 @@ function show_imagelike(inspector, plot, name, edge_based)
tt.text[] = plot[:inspector_label][](plot, (i, j), ins_p)
end

a._color[] = if z isa Real
get(plot.calculated_colors[], z)
if z isa Real
if haskey(plot, :calculated_colors)
a._color[] = get(plot.calculated_colors[], z)
end
else
z
a._color[] = z
end

proj_pos = Point2f(mouseposition_px(inspector.root))
Expand Down
2 changes: 2 additions & 0 deletions src/interfaces.jl
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ expand_dimensions(trait, args...) = nothing

expand_dimensions(::PointBased, y::VecTypes) = nothing # VecTypes are nd points
expand_dimensions(::PointBased, y::RealVector) = (keys(y), y)
expand_dimensions(::PointBased, y::OffsetVector{<:Real}) =
(OffsetArrays.no_offset_view(keys(y)), OffsetArrays.no_offset_view(y))

function expand_dimensions(::Union{ImageLike, GridBased}, data::AbstractMatrix{<:Union{<:Real, <:Colorant}})
# Float32, because all ploteable sizes should fit into float32
Expand Down
16 changes: 15 additions & 1 deletion test/bezier.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@ using Makie, Test
@test_nowarn BezierPath("m 0,9 L 0,5138 0,9 z")
@test_broken BezierPath("m 0,1e-5 L 0,5138 0,9 z") isa BezierPath
@test_nowarn BezierPath("M 100,100 C 100,200 200,100 200,200 z")
@test_broken BezierPath("M 100,100 Q 50,150,100,100 z") isa BezierPath
@test_nowarn BezierPath("M 100,100 Q 50,150,100,100 z") isa BezierPath
@test_broken BezierPath("M 3.0 10.0 A 10.0 7.5 0.0 0.0 0.0 20.0 15.0 z") isa BezierPath
end

@testset "Parsing Q/q" begin
x0, y0, x1, y1, x, y = 5.0, 0.0, 14.6, 5.2, 13.0, 15.9
C = Makie.quadratic_curve_to(x0, y0, x1, y1, x, y)
C2 = Makie.CurveTo(x0 + 2 / 3 * (x1 - x0), y0 + 2 / 3 * (y1 - y0), x + 2 / 3 * (x1 - x),
y + 2 / 3 * (y1 - y),
x, y)
@test C == C2
path = BezierPath("M 5.0 0.0 Q 14.6 5.2 13.0 15.9")
@test path.commands[2] == C2
path = BezierPath("M 5.0 0.0 q 0.2 2.3 1.0 -2.0")
C = Makie.quadratic_curve_to(x0, y0, x0 + 0.2, y0 + 2.3, x0 + 1.0, y0 - 2.0)
@test path.commands[2] == C
end
2 changes: 2 additions & 0 deletions test/convert_arguments.jl
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ Makie.convert_arguments(::PointBased, ::MyConvVector) = ([Point(10, 20)],)
nan = vcat(xs[1:4], NaN, zs[6:end])
r = T_in(1):T_in(1):T_in(10)
i = T_in(1)..T_in(10)
ov = Makie.OffsetVector(ys, -5:4)

ps2 = Point2.(xs, ys)
ps3 = Point3.(xs, ys, zs)
Expand Down Expand Up @@ -172,6 +173,7 @@ Makie.convert_arguments(::PointBased, ::MyConvVector) = ([Point(10, 20)],)

# because indices are Int we end up converting to Float64 no matter what
@test apply_conversion(CT, xs) isa Tuple{Vector{Point2{Float64}}}
@test apply_conversion(CT, ov) isa Tuple{Vector{Point2{Float64}}}

@test apply_conversion(CT, xs, ys) isa Tuple{Vector{Point2{T_out}}}
@test apply_conversion(CT, xs, v32) isa Tuple{Vector{Point2{T_out}}}
Expand Down

0 comments on commit e3b9108

Please sign in to comment.