Skip to content

Commit

Permalink
dynamicpanel works (without inspector)
Browse files Browse the repository at this point in the history
  • Loading branch information
garrekstemo committed Jun 21, 2022
1 parent f119db2 commit d719428
Show file tree
Hide file tree
Showing 13 changed files with 25,378 additions and 139 deletions.
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
FileWatching = "7b1f6079-737a-58dc-b8bc-7a2ca5c1b5ee"
GLMakie = "e9467ef8-e4e7-5192-8a1a-b1aee30e663a"
ImageMagick = "6218d12a-5da1-5696-b52f-db25d2ecc6d1"
LVM = "76785837-0c5d-45c2-90b8-8e8ea9f9a99d"
QuartzImageIO = "dca85d43-d64c-5e67-8c65-017450d5d020"
76 changes: 76 additions & 0 deletions src/demo.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
function loadfile(dir::String, file::String)

df = DataFrame(CSV.File(dir * file))

filename = chop(file, tail = length(".csv"))

return df[!, 1], df[!, 2], filename
end

function run(datadir::String, extension)

fig = Figure()
sc = display(fig)

inspector = DataInspector(fig,
indicator_color = :deepskyblue,
indicator_linewidth = 1.5,
text_align = (:left, :bottom)
)

xdata = [rand(10)]
ydata = [rand(10)]
xs = Observable(xdata[1])
ys = Observable(ydata[1])
plotnames = Observable(["nothing"])
plotname = Observable(plotnames[][1])

menu = Menu(fig, options = plotnames)
menu.i_selected = 1

fig[1, 1] = vgrid!(
Label(fig, "Data", width = nothing), menu,
Label(fig, "Plot 2", width = nothing), menu2;
tellheight = false, width = 200, height = 50
)

ax = Axis(fig[1, 2], title = plotname)
line = lines!(ax, xs, ys)


on(menu.selection) do s

i = to_value(menu.i_selected)
xs.val = xdata[i]
ys[] = ydata[i]
autolimits!(ax)
ax.title = plotnames[][i]
end

iswatching = Observable(true)
while true
while iswatching[]
(file, event) = watch_folder(datadir)

if endswith(file, extension)
println("New file: ", file)
x, y, name = loadfile(datadir, file)

if !(name in plotnames[])

xs[1].val = x
ys[1][] = y
autolimits!(axs[1])
axs[1].title = name

push!(xdata, x)
push!(ydata, y)
plotnames[] = push!(plotnames[], name)
end
end
end
end
end


f
229 changes: 90 additions & 139 deletions src/stream.jl
Original file line number Diff line number Diff line change
@@ -1,84 +1,118 @@
function single_panel(datadir::String, extension::String=".lvm")

function dynamicpanel(datadir::String, extension::String=".lvm")
datadir = abspath(datadir)
fig = Figure(resolution = (1400, 1000), fontsize = 30)

fig = Figure()
sc = display(fig)

inspector = DataInspector(fig,
indicator_color = :deepskyblue,
indicator_linewidth = 1.5,
text_align = (:left, :bottom)
)
# inspector = DataInspector(fig,
# indicator_color = :deepskyblue,
# indicator_linewidth = 1.5,
# text_align = (:left, :bottom)
# )

xdata = [rand(10)]
ydata = [rand(10)]
xdata = [rand(1)]
ydata = [rand(1)]
xs = Observable(xdata[1])
ys = Observable(ydata[1])
plotnames = Observable(["nothing"])
plotname = Observable(plotnames[][1])
xslive = Observable(xdata[1])
yslive = Observable(ydata[1])

menu = Menu(fig, options = plotnames)
menu.i_selected = 1
xs = [Observable(xdata[1])]
ys = [Observable(ydata[1])]
plotnames = Observable(["no options"])

axbutton = Button(fig, label = "Add Axis")

fig[1, 1] = vgrid!(
Label(fig, "Data", width = nothing), menu;
axbutton;
tellheight = false, width = 300, height = 50
)

ax = Axis(fig[1, 2], title = plotname)
line = lines!(ax, xs, ys)

on(menu.selection) do s
axlive = Axis(fig[1, 2])
livetext = text!(axlive, " • Live",
# textsize = 40,
color = :red,
space = :relative,
align = (:left, :bottom)
)

i = to_value(menu.i_selected)
xs.val = xdata[i]
ys[] = ydata[i]
autolimits!(ax)
ax.title = plotnames[][i]
axs = []
plots = []
menus = []

col = 3
row = 1
on(axbutton.clicks) do b
ax = Axis(fig[row, col])
push!(axs, ax)

newmenu = Menu(fig[row+1, col], options = plotnames, tellwidth=false)
newmenu.i_selected = 1
push!(menus, newmenu)

newx, newy = Observable(xdata[1]), Observable(ydata[1])
l = lines!(ax, newx, newy)
push!(plots, l)

on(newmenu.selection) do s
i = to_value(newmenu.i_selected)

newx.val = xdata[i]
newy[] = ydata[i]
ax.title = plotnames[][i]
autolimits!(ax)
end

col += 1
if col == 5
row += 2
col = 2
end
end

iswatching = Observable(true)
while true
while iswatching[]
(file, event) = watch_folder(datadir)

if endswith(file, extension)
println("New file: ", file)
x, y, name = loadfile(datadir, file, extension)
(file, event) = watch_folder(datadir)

if endswith(file, extension)
println("New file: ", file)
x, y, name = loadfile(datadir, file, extension)

if !(name in plotnames[])
if !(name in plotnames[])

xs.val = x
ys[] = y
autolimits!(ax)
ax.title = name
xslive.val = x
yslive[] = y

push!(xdata, x)
push!(ydata, y)
plotnames[] = push!(plotnames[], name)
if plotnames[][1] == "no options"
line = lines!(axlive, xslive, yslive, color = :firebrick4)
end

autolimits!(axlive)
axlive.title = name

push!(xdata, x)
push!(ydata, y)
plotnames[] = push!(plotnames[], name)
end
end
end

end

function double_panel(datadir::String, extension::String=".lvm")

function single_panel(datadir::String, extension::String=".lvm")

datadir = abspath(datadir)
fig = Figure(resolution = (2200, 1000), fontsize = 30)
fig = Figure(resolution = (1400, 1000), fontsize = 30)
sc = display(fig)

# inspector = DataInspector(fig,
# indicator_color = :deepskyblue,
# indicator_linewidth = 1.5,
# text_align = (:left, :bottom)
# )
inspector = DataInspector(fig,
indicator_color = :deepskyblue,
indicator_linewidth = 1.5,
text_align = (:left, :bottom)
)

xdata = [rand(10)]
ydata = [rand(10)]
xslive = Observable(xdata[1])
yslive = Observable(ydata[1])

xs = Observable(xdata[1])
ys = Observable(ydata[1])
plotnames = Observable(["nothing"])
Expand All @@ -88,21 +122,13 @@ function double_panel(datadir::String, extension::String=".lvm")
menu.i_selected = 1

fig[1, 1] = vgrid!(
Label(fig, "Select Data", width = nothing), menu;
Label(fig, "Data", width = nothing), menu;
tellheight = false, width = 300, height = 50
)

ax = Axis(fig[1, 2], title = plotnames[][1])
ax = Axis(fig[1, 2], title = plotname)
line = lines!(ax, xs, ys)

axlive = Axis(fig[1, 3], title = plotname)
line = lines!(axlive, xslive, yslive, color = :firebrick4)
livetext = text!(axlive, "• Live",
textsize = 40,
color = :red,
space = :relative,
align = (:left, :bottom))

on(menu.selection) do s

i = to_value(menu.i_selected)
Expand All @@ -112,79 +138,6 @@ function double_panel(datadir::String, extension::String=".lvm")
ax.title = plotnames[][i]
end

# iswatching = Observable(true)
while true
# while iswatching[]
(file, event) = watch_folder(datadir)

if endswith(file, extension)
println("New file: ", file)
x, y, name = loadfile(datadir, file, extension)

if !(name in plotnames[])

xslive.val = x
yslive[] = y
autolimits!(axlive)
axlive.title = name

push!(xdata, x)
push!(ydata, y)
plotnames[] = push!(plotnames[], name)
end
end
end
# end
end

function four_panels(datadir::String, extension::String=".lvm")

fig = Figure(resolution = (2000, 2000), fontsize = 40)
sc = display(fig)

# inspector = DataInspector(fig,
# indicator_color = :deepskyblue,
# indicator_linewidth = 3,
# )

fig[1:4, 1:2] = grid = GridLayout()

xdata = [rand(10)]
ydata = [rand(10)]
# xs = Observable(xdata[1])
# ys = Observable(ydata[1])
plotnames = Observable(["nothing"])
plotname = Observable(plotnames[][1])

menus = [Menu(grid[row, col], options = plotnames, tellwidth = false, width = 500) for row in [1, 3], col = 1:2]
axs = [Axis(grid[row, col]) for row in [2, 4], col = 1:2]
xs = [Observable(xdata[1]) for i in 1:length(axs)]
ys = [Observable(ydata[1]) for i in 1:length(axs)]

livetext = text!(axs[1], "• Live",
textsize = 40,
color = :red,
space = :relative,
align = (:left, :bottom))

for (m, menu) in enumerate(menus)
menu.i_selected = 1
if m == 1
lines!(axs[m], xs[m], ys[m], color = :firebrick4)
else
lines!(axs[m], xs[m], ys[m])
end

on(menu.selection) do s

i = to_value(menu.i_selected)
xs[m].val = xdata[i]
ys[m][] = ydata[i]
autolimits!(axs[m])
axs[m].title = plotnames[][i]
end
end

iswatching = Observable(true)
while true
while iswatching[]
Expand All @@ -196,10 +149,10 @@ function four_panels(datadir::String, extension::String=".lvm")

if !(name in plotnames[])

xs[1].val = x
ys[1][] = y
autolimits!(axs[1])
axs[1].title = name
xs.val = x
ys[] = y
autolimits!(ax)
ax.title = name

push!(xdata, x)
push!(ydata, y)
Expand All @@ -208,6 +161,4 @@ function four_panels(datadir::String, extension::String=".lvm")
end
end
end

end

Loading

0 comments on commit d719428

Please sign in to comment.