recipe Trace2d

This commit is contained in:
qwjyh 2024-01-05 23:06:58 +09:00
parent 3a6d0da83e
commit 9996227460

View file

@ -107,7 +107,6 @@ TODO
marker = theme(scene, :marker), marker = theme(scene, :marker),
markercolormap = theme(scene, :colormap), markercolormap = theme(scene, :colormap),
markersize = theme(scene, :markersize), markersize = theme(scene, :markersize),
strokecolor = theme(scene, :strokecolor),
strokewidth = theme(scene, :strokewidth), strokewidth = theme(scene, :strokewidth),
linecolormap = theme(scene, :colormap), linecolormap = theme(scene, :colormap),
linestyle = theme(scene, :linestyle), linestyle = theme(scene, :linestyle),
@ -127,6 +126,7 @@ function Makie.plot!(tr2d::Trace2Ds)
ntraces = length(tr2d.log[]) # number of CoordLog ntraces = length(tr2d.log[]) # number of CoordLog
linesegs = Observable(Point2f[]) linesegs = Observable(Point2f[])
points = Observable(Point2f[])
notes = Observable(String[]) notes = Observable(String[])
if tr2d.markercolormap[] isa Symbol if tr2d.markercolormap[] isa Symbol
tr2d.markercolormap[] = getproperty(ColorSchemes, tr2d.markercolormap[]) tr2d.markercolormap[] = getproperty(ColorSchemes, tr2d.markercolormap[])
@ -137,10 +137,6 @@ function Makie.plot!(tr2d::Trace2Ds)
end end
# @info "lcolormapfunc" lcolormapfunc # @info "lcolormapfunc" lcolormapfunc
linecolors = Observable(lcolormapfunc[](tr2d.linecolormap[], tr2d.log[])) linecolors = Observable(lcolormapfunc[](tr2d.linecolormap[], tr2d.log[]))
on(linecolors) do lc
@info "linecolors update"
end
@info "linecolors" linecolors
# helper function which mutates observables # helper function which mutates observables
function update_plot( function update_plot(
@ -151,18 +147,13 @@ function Makie.plot!(tr2d::Trace2Ds)
mcolormapfunc, mcolormapfunc,
) )
@info "update_plot" @info "update_plot"
markercolors[]
linecolors[] linecolors[]
# @info "logs on update_plot" logs # @info "logs on update_plot" logs
# init # init
empty!(linesegs[]) empty!(linesegs[])
if !isnothing(mcolormapfunc) empty!(points[])
# if markercolors[] isa AbstractVector empty!(markercolors[])
# empty!(markercolors[])
# else
# markercolors[] = []
# end
markercolors[] = mcolormapfunc(mcolormap, logs)
end
if linecolors[] isa AbstractVector if linecolors[] isa AbstractVector
empty!(linecolors[]) empty!(linecolors[])
else else
@ -170,15 +161,17 @@ function Makie.plot!(tr2d::Trace2Ds)
end end
# update # update
linecolors_count = 1 colors_count = 1
for (i, log) in enumerate(logs) for (i, log) in enumerate(logs)
first = true first = true
for point in eachrow(log.coords) for point in eachrow(log.coords)
push!(linesegs[], Point2f(point[1], point[3])) push!(linesegs[], Point2f(point[1], point[3]))
push!(linesegs[], Point2f(point[1], point[3])) push!(linesegs[], Point2f(point[1], point[3]))
push!(linecolors[], lcolormapfunc(lcolormap, logs)[linecolors_count]) push!(points[], Point2f(point[1], point[3]))
push!(linecolors[], lcolormapfunc(lcolormap, logs)[linecolors_count]) push!(linecolors[], lcolormapfunc(lcolormap, logs)[colors_count])
linecolors_count += 1 push!(linecolors[], lcolormapfunc(lcolormap, logs)[colors_count])
push!(markercolors[], mcolormapfunc(mcolormap, logs)[colors_count])
colors_count += 1
# # marker # # marker
# if !isnothing(mcolormapfunc) # if !isnothing(mcolormapfunc)
@ -201,6 +194,7 @@ function Makie.plot!(tr2d::Trace2Ds)
push!(notes[], log.note) push!(notes[], log.note)
end end
markercolors[] = markercolors[]
linecolors[] = linecolors[] linecolors[] = linecolors[]
end end
@ -212,7 +206,6 @@ function Makie.plot!(tr2d::Trace2Ds)
lcolormapfunc, lcolormapfunc,
tr2d.mcolormapfunc, tr2d.mcolormapfunc,
) )
@info "tr2d" lcolormapfunc
# init # init
update_plot( update_plot(
@ -230,6 +223,13 @@ function Makie.plot!(tr2d::Trace2Ds)
linewidth = tr2d.linewidth, linewidth = tr2d.linewidth,
linestyle = tr2d.linestyle, linestyle = tr2d.linestyle,
) )
scatter!(
tr2d,
points,
color = markercolors,
markersize = tr2d.markersize,
strokewidth = tr2d.strokewidth,
)
# @info "dump" dump(tr2d, maxdepth = 1) # @info "dump" dump(tr2d, maxdepth = 1)
# @info "attributes" dump(tr2d.attributes, maxdepth = 3) # @info "attributes" dump(tr2d.attributes, maxdepth = 3)