diff --git a/GLMakie/src/new-primitives.jl b/GLMakie/src/new-primitives.jl index aac45331b59..354bad60219 100644 --- a/GLMakie/src/new-primitives.jl +++ b/GLMakie/src/new-primitives.jl @@ -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, @@ -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 ) @@ -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 diff --git a/src/compute-plots.jl b/src/compute-plots.jl index 8db457be94b..b180913a7d2 100644 --- a/src/compute-plots.jl +++ b/src/compute-plots.jl @@ -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()