Skip to content

Commit

Permalink
Merge pull request #3 from s-ccs/style
Browse files Browse the repository at this point in the history
Style
- formatting
- little styling improvements
  • Loading branch information
vladdez authored Dec 6, 2024
2 parents b312210 + 7d0d490 commit 3813bb6
Show file tree
Hide file tree
Showing 7 changed files with 204 additions and 137 deletions.
3 changes: 3 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ Bonito = "824d6782-a2ef-11e9-3a09-e5662e0c26f8"
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
DataFramesMeta = "1313f7d8-7da2-5740-9ea0-a2ca25f37964"
GeometryBasics = "5c1252a2-5f33-56bf-86c9-59e7332b4326"
JuliaFormatter = "98e50ef6-434e-11e9-1051-2b60c6c9e899"
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
MakieCore = "20f20a25-4f0e-4fdf-b5d1-57303727442b"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Revise = "295af30f-e4ad-537b-8983-00126c2a3abe"
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
StatsModels = "3eaba693-59b7-5ba5-a881-562e759f1c8d"
TopoPlots = "2bdbdf9c-dbd8-403f-947b-1a4e0dd41a7a"
Expand Down
12 changes: 7 additions & 5 deletions scripts/example.jl
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
begin
using Pkg
Pkg.activate(".")
Pkg.status()
Pkg.status()
using Revise
using ERPExplorer
using UnfoldSim
using DataFrames
using Random
using Unfold
using Bonito
using JuliaFormatter
using TopoPlots
end

include("gen_data.jl")
#formulaS = @formula(0 ~ 1 +luminance + contrast + saccade_amplitude + string + animal + fruit + color)
formulaS = @formula(0 ~ 1 + animal + fruit)
formulaS = @formula(0 ~ 1 + luminance + fruit + animal)
dataS, evts, pos2d = gen_data()
times = range(0, length=size(dataS, 2), step=1 ./ 100)
times = range(0, length = size(dataS, 2), step = 1 ./ 100)
model = Unfold.fit(UnfoldModel, formulaS, evts, dataS, times)

_, positions = TopoPlots.example_data()
explore(model; positions = positions)

explore(model; positions=pos2d)


#format_file("scripts/gen_data.jl")
21 changes: 14 additions & 7 deletions scripts/gen_data.jl
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
using UnfoldSim, DataFrames, Random
using GeometryBasics
function gen_data()
d1, evts = UnfoldSim.predef_eeg(n_repeats=120, noiselevel=25; return_epoched=true)
d1, evts = UnfoldSim.predef_eeg(n_repeats = 120, noiselevel = 25; return_epoched = true)
dataS = permutedims(repeat(d1, 1, 1, 64), (3, 1, 2))
dataS = dataS .+ rand(dataS)

evts = insertcols(evts,
evts = insertcols(
evts,
:saccade_amplitude => rand(nrow(evts)) .* 15,
:luminance => rand(nrow(evts)) .* 100,
:contrast => rand(nrow(evts)),
:string => shuffle(repeat(["stringsuperlong", "stringshort", "stringUPPERCASE", "stringEXCITED!!!!"], outer=div(nrow(evts), 4))),
:animal => shuffle(repeat(["cat", "dog"], outer=div(nrow(evts), 2))),
:fruit => shuffle(repeat(["orange", "banana"], outer=div(nrow(evts), 2))),
:color => shuffle(repeat(["black", "white"], outer=div(nrow(evts), 2))))
:string => shuffle(
repeat(
["stringsuperlong", "stringshort", "stringUPPERCASE", "stringEXCITED!!!!"],
outer = div(nrow(evts), 4),
),
),
:animal => shuffle(repeat(["cat", "dog"], outer = div(nrow(evts), 2))),
:fruit => shuffle(repeat(["orange", "banana"], outer = div(nrow(evts), 2))),
:color => shuffle(repeat(["black", "white"], outer = div(nrow(evts), 2))),
)

positions = rand(Point2f, size(dataS, 1))
return dataS, evts, positions
end

55 changes: 36 additions & 19 deletions src/ERPExplorer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@ include("formula_extractor.jl")
include("functions.jl")
include("widgets.jl")



function explore(model::UnfoldModel; positions=nothing, size=(700, 600))
function explore(model::UnfoldModel; positions = nothing, size = (700, 600))
App() do
#formular = Unfold.formula(model)
variables = extract_variables(model)
widget_checkbox, widget_signal, widget_dom, value_ranges = formular_widgets(variables)
widget_checkbox, widget_signal, widget_dom, value_ranges =
formular_widgets(variables)

var_types = map(x -> x[2][3], variables)
varnames = first.(variables)
Expand All @@ -38,7 +37,7 @@ function explore(model::UnfoldModel; positions=nothing, size=(700, 600))
channel = Observable(1)
topo_widget = nothing
else
topo_widget, channel = topoplot_widget(positions; size=size .* 0.3)
topo_widget, channel = topoplot_widget(positions; size = size .* 0.5)
end
#@debug "mapping" mapping
#mapping = Observable(Dict(:color => :color, :fruit => :marker))
Expand All @@ -47,34 +46,52 @@ function explore(model::UnfoldModel; positions=nothing, size=(700, 600))
ws = widget_signal.val
ks_m = values(m)
ks_ws = [w.first for w in ws]
for k = ks_ws
for k in ks_ws
widget_checkbox[k][] = k ks_m
end
end
obs = Observable(S.GridLayout())
l = Base.ReentrantLock()
Makie.onany_latest(eff_signal, mapping; update=true) do eff, mapping # update = true means only, that it is run once immediately
Makie.onany_latest(eff_signal, mapping; update = true) do eff, mapping # update = true means only, that it is run once immediately
lock(l) do
#var_types = map(x -> x[2][3], variables)
obs[] = plot_data(eff, value_ranges, varnames[var_types.==:CategoricalTerm], varnames[var_types.==:ContinuousTerm], mapping)
obs[] = plot_data(
eff,
value_ranges,
varnames[var_types.==:CategoricalTerm],
varnames[var_types.==:ContinuousTerm],
mapping,
)
end
return
end
css = Asset(joinpath(@__DIR__, "..", "style.css"))
fig = plot(obs; figure=(size=size,))
return DOM.div(css, Bonito.TailwindCSS,
fig = plot(obs; figure = (size = size,))
return DOM.div(
css,
Bonito.TailwindCSS,
Grid(
Card(widget_dom, style=Styles("grid-area" => "header")),
Card(mapping_dom, style=Styles("grid-area" => "sidebar")),
Card(topo_widget, style=Styles("grid-area" => "topo")),
Card(fig, style=Styles("grid-area" => "content")); columns="5fr 1fr", rows="1fr 6fr 4fr", areas="""
'header header'
'content sidebar'
'content topo'
"""); style=Styles("height" => "$(1.2*size[2])px", "width" => "$(size[1])px", "margin" => "20px", "position" => :relative,))
Card(widget_dom, style = Styles("grid-area" => "header")),
Card(mapping_dom, style = Styles("grid-area" => "sidebar")),
Card(topo_widget, style = Styles("grid-area" => "topo")),
Card(fig, style = Styles("grid-area" => "content"));
columns = "5fr 1fr",
rows = "1fr 6fr 4fr",
areas = """
'header header'
'content sidebar'
'content topo'
""",
);
style = Styles(
"height" => "$(1.2*size[2])px",
"width" => "$(size[1])px",
"margin" => "20px",
"position" => :relative,
),
)
end
end
export explore

end

2 changes: 1 addition & 1 deletion src/formula_extractor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ get_sym(t::FunctionTerm) = ""
get_values(t::InterceptTerm) = (;)
get_values(t::CategoricalTerm) = t.contrasts.levels
get_values(t::BSplineTerm) = get_values(t.term)
get_values(t::ContinuousTerm) = (; min=t.min, max=t.max, var=t.var, mean=t.mean)
get_values(t::ContinuousTerm) = (; min = t.min, max = t.max, var = t.var, mean = t.mean)
get_values(t::InteractionTerm) = (;)

function extract_variables(model)
Expand Down
Loading

0 comments on commit 3813bb6

Please sign in to comment.