Skip to content

Commit

Permalink
add color, linewidth doubling for LineSegments
Browse files Browse the repository at this point in the history
  • Loading branch information
ffreyer committed Dec 7, 2024
1 parent 1e5f342 commit 1afc32a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
10 changes: 5 additions & 5 deletions GLMakie/src/new-primitives.jl
Original file line number Diff line number Diff line change
Expand Up @@ -684,9 +684,9 @@ function draw_atomic(screen::Screen, scene::Scene, plot::LineSegments)
inputs = [
:space, :scene, :screen,
:positions_transformed_f32c,
:color, :colormap, :_colorrange,
:synched_color, :colormap, :_colorrange,
# Auto
:pattern, :pattern_length, :linecap, :linewidth,
:pattern, :pattern_length, :linecap, :synched_linewidth,
:scene_origin, :px_per_unit, :model_f32c,
:transparency, :fxaa, :debug,
:visible,
Expand All @@ -695,8 +695,8 @@ function draw_atomic(screen::Screen, scene::Scene, plot::LineSegments)

input2glname = Dict{Symbol, Symbol}(
:positions_transformed_f32c => :vertex,
:linewidth => :thickness, :model_f32c => :model,
:color => :color, :colormap => :color_map, :_colorrange => :color_norm,
:synched_linewidth => :thickness, :model_f32c => :model,
:synched_color => :color, :colormap => :color_map, :_colorrange => :color_norm,
:_lowclip => :lowclip, :_highclip => :highclip,
:gl_clip_planes => :clip_planes, :gl_num_clip_planes => :_num_clip_planes
)
Expand All @@ -707,7 +707,7 @@ function draw_atomic(screen::Screen, scene::Scene, plot::LineSegments)
robj = assemble_linesegments_robj(args[1:7]..., attr[:linestyle]) do data

# Generate name mapping
haskey(data, :intensity) && (input2glname[:color] = :intensity)
haskey(data, :intensity) && (input2glname[:synched_color] = :intensity)
gl_names = get.(Ref(input2glname), inputs, inputs)

# Simple defaults
Expand Down
16 changes: 16 additions & 0 deletions src/compute-plots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,22 @@ function LineSegments(args::Tuple, user_kw::Dict{Symbol,Any})
register_computation!(attr, [:positions], [:data_limits]) do (positions,), changed, last
return (Rect3d(positions[]),)
end

# allow color/linewidth per segment (like calculated_attributes! did)
for key in [:color, :linewidth]
register_computation!(attr, [:positions, key], [Symbol(:synched_, key)]) do (positions, input), changed, last
N = length(positions[])
output = isnothing(last) ? copy(input[]) : last[1][]
if changed[2] && (output isa AbstractVector) && (div(N, 2) == length(input[]))
resize!(output, N)
for i in eachindex(output) # TODO: @inbounds
output[i] = input[][div(i+1, 2)]
end
end
return (output,)
end
end

T = typeof(attr[:positions][])
p = Plot{linesegments,Tuple{T}}(user_kw, Observable(Pair{Symbol,Any}[]), Any[attr], Observable[])
p.transformation = Transformation()
Expand Down

0 comments on commit 1afc32a

Please sign in to comment.