Skip to content

Commit 783fc0e

Browse files
authored
Merge pull request #22 from s-ccs/docum
Adding docstrings - Doctstring to majority of big functions were added - Functions which are not used moved into "old" folder - Some functions and variables are renamed
2 parents 1bacded + 045af2f commit 783fc0e

File tree

14 files changed

+672
-490
lines changed

14 files changed

+672
-490
lines changed

Project.toml

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,17 @@ UnfoldSim = "ed8ae6d2-84d3-44c6-ab46-0baf21700804"
2525
WGLMakie = "276b4fcb-3e11-5398-bf8b-a0c2d153d008"
2626

2727
[compat]
28-
Colors = "0.12, 0.13"
29-
GeometryBasics = "0.4, 0.5"
30-
JuliaFormatter = "1"
31-
Test = "1.11.0"
32-
Bonito = "4"
33-
BSplineKit = "0.17"
34-
TopoPlots = "0.2"
35-
Unfold = "0.7"
36-
28+
Bonito = "4"
29+
BSplineKit = "0.17"
30+
Colors = "0.12, 0.13"
31+
GeometryBasics = "0.4, 0.5"
32+
JuliaFormatter = "1"
33+
Makie = "0.21"
34+
StatsBase = "0.34"
35+
StatsModels = "0.7"
36+
Test = "1.11"
37+
TopoPlots = "0.2"
38+
Unfold = "0.7"
39+
UnfoldMakie = "0.5"
40+
UnfoldSim = "0.3"
41+
WGLMakie = "0.10"

docs/index.md

Lines changed: 0 additions & 4 deletions
This file was deleted.

docs/src/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# ERPExplorer Highlights
22

3-
# ERPExplorer.jl allows interactive exploration of regression-ERPs.
4-
# You can switch on and off formula terms, term values, row and column faceting, line colours and style, marker style.
3+
`ERPExplorer.jl` allows interactive exploration of regression-ERPs.
4+
You can switch on and off formula terms, term values, row and column faceting, line colours and style, marker style.

old/unused_functions.jl

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
function rectselect(ax)
2+
selrect, h = select_vspan(ax.scene; color = (0.9))
3+
translate!(h, 0, 0, -1) # move to background
4+
return selrect
5+
end
6+
7+
function Bonito.jsrender(s::Session, selector::SelectSet)
8+
rows = map(selector.items[]) do value
9+
c = Bonito.Checkbox(true; class = "p-1 m-1")
10+
on(s, c.value) do x
11+
values = selector.value[]
12+
has_item = (value in values)
13+
if x
14+
!has_item && push!(values, value)
15+
else
16+
has_item && filter!(x -> x != value, values)
17+
end
18+
notify(selector.value)
19+
end
20+
return Row(value, c)
21+
end
22+
return Bonito.jsrender(s, Card(Col(rows...)))
23+
end
24+
25+
function style_map(::AbstractRange{<:Number})
26+
return Dict(
27+
:color => identity,
28+
:colormap => RGBAf.(Colors.color.(to_colormap(:lighttest)), 0.5),
29+
)
30+
end
31+
32+
function style_map(values::Set)
33+
mpalette = [:circle, :star4, :xcross, :diamond]
34+
dict = Dict(v => mpalette[i] for (i, v) in enumerate(values))
35+
mcmap = Makie.wong_colors(0.5)
36+
mcolor_lookup = Dict(v => mcmap[i] for (i, v) in enumerate(values))
37+
return Dict(:marker => v -> dict[v], :marker_color => mcolor_lookup)
38+
end
39+
40+
function select_vspan(scene; blocking = false, priority = 2, kwargs...)
41+
key = Mouse.left
42+
waspressed = Observable(false)
43+
rect = Observable(Rectf(0, 0, 1, 1)) # plotted rectangle
44+
rect_ret = Observable(Rectf(0, 0, 1, 1)) # returned rectangle
45+
46+
# Create an initially hidden rectangle
47+
low = Observable(0.0f0)
48+
high = Observable(0.0f0)
49+
50+
on(rect) do r
51+
low.val = r.origin[1]
52+
high[] = r.origin[1] + r.widths[1]
53+
end
54+
plotted_span = vspan!(
55+
scene,
56+
low,
57+
high,
58+
visible = false,
59+
kwargs...,
60+
transparency = true,
61+
color = (:black, 0.1),
62+
)
63+
64+
on(events(scene).mousebutton, priority = priority) do event
65+
if event.button == key
66+
if event.action == Mouse.press && is_mouseinside(scene)
67+
mp = mouseposition(scene)
68+
waspressed[] = true
69+
plotted_span[:visible] = true # start displaying
70+
rect[] = Rectf(mp, 0.0, 0.0)
71+
return Consume(blocking)
72+
end
73+
end
74+
if !(event.button == key && event.action == Mouse.press)
75+
if waspressed[] # User has selected the rectangle
76+
waspressed[] = false
77+
r = Makie.absrect(rect[])
78+
w, h = widths(r)
79+
rect_ret[] = r
80+
end
81+
# always hide if not the right key is pressed
82+
#plotted_span[:visible] = false # make the plotted rectangle invisible
83+
return Consume(blocking)
84+
end
85+
86+
return Consume(false)
87+
end
88+
on(events(scene).mouseposition, priority = priority) do event
89+
if waspressed[]
90+
mp = mouseposition(scene)
91+
mini = minimum(rect[])
92+
rect[] = Rectf(mini, mp - mini)
93+
return Consume(blocking)
94+
end
95+
return Consume(false)
96+
end
97+
98+
return rect_ret, plotted_span
99+
end
100+
101+
function Bonito.jsrender(s::Session, selector::SelectSet)
102+
rows = map(selector.items[]) do value
103+
c = Bonito.Checkbox(true; class = "p-1 m-1")
104+
on(s, c.value) do x
105+
values = selector.value[]
106+
has_item = (value in values)
107+
if x
108+
!has_item && push!(values, value)
109+
else
110+
has_item && filter!(x -> x != value, values)
111+
end
112+
notify(selector.value)
113+
end
114+
return Row(value, c)
115+
end
116+
return Bonito.jsrender(s, Card(Col(rows...)))
117+
end
118+
119+
function variable_legend(name, values::AbstractRange{<:Number}, palette::Dict)
120+
range, cmap = palette[:colormap]
121+
return S.Colorbar(limits = range, colormap = cmap, label = string(name))
122+
end
123+
124+
function variable_legend(name, values::Set, palette::Dict)
125+
marker_color_lookup = (x) -> begin
126+
if haskey(palette, :color)
127+
return get(palette[:color], x, :black)
128+
else
129+
return :black
130+
end
131+
end
132+
marker_lookup = (x) -> begin
133+
if haskey(palette, :marker)
134+
return palette[:marker][x]
135+
else
136+
return :rect
137+
end
138+
end
139+
conditions = collect(values)
140+
elements = map(conditions) do c
141+
return MarkerElement(marker = marker_lookup(c), color = marker_color_lookup(c))
142+
end
143+
return S.Legend(elements, conditions)
144+
end
145+
146+
147+
widget_value(w::Vector{<:String}; resolution = 1) = w
148+
widget_value(x::Vector; resolution = 1) =
149+
x[1] x[end] ? Float64[] : range(Float64(x[1]), Float64(x[end]), length = 5)

scripts/example.jl renamed to scripts/runner.jl

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ begin
1111
using Bonito
1212
using JuliaFormatter
1313
using TopoPlots
14+
ENV["JULIA_DEBUG"] = "ERPExplorer"
1415
end
1516

17+
1618
include("gen_data.jl")
1719
#formulaS = @formula(0 ~ 1 +luminance + contrast + saccade_amplitude + string + animal + fruit + color)
1820
formulaS = @formula(0 ~ 1 + animal + fruit)
@@ -24,4 +26,31 @@ model = Unfold.fit(UnfoldModel, formulaS, evts, dataS, times)
2426
_, positions = TopoPlots.example_data()
2527
explore(model; positions = positions)
2628

27-
#format_file("scripts/gen_data.jl")
29+
#format_file("scripts/gen_data.jl")
30+
begin
31+
using Pkg
32+
Pkg.activate(".")
33+
Pkg.status()
34+
end
35+
36+
include("/store/users/mikheev/projects/erpexplorer_dev/dev/ERPExplorer/docs/make.jl")
37+
38+
using JuliaFormatter
39+
begin
40+
test_entries = readdir("./test")
41+
cd("./test")
42+
for i in test_entries
43+
format_file(i)
44+
end
45+
src_entries = readdir("../src")
46+
cd("../src")
47+
for i in src_entries
48+
format_file(i)
49+
end
50+
docs_entries = readdir("../docs")
51+
cd("../docs")
52+
for i in docs_entries
53+
format_file(i)
54+
end
55+
cd("../")
56+
end

src/ERPExplorer.jl

Lines changed: 6 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -17,81 +17,13 @@ using StatsModels
1717
using StatsBase
1818
using TopoPlots
1919

20-
include("formula_extractor.jl")
21-
include("functions.jl")
22-
include("widgets.jl")
20+
include("explore.jl")
21+
include("functions_preprocessing.jl")
22+
include("functions_formular.jl")
23+
include("functions_plotting.jl")
2324

24-
function explore(model::UnfoldModel; positions = nothing, size = (700, 600))
25-
App() do
26-
#formular = Unfold.formula(model)
27-
variables = extract_variables(model)
28-
widget_checkbox, widget_signal, widget_dom, value_ranges =
29-
formular_widgets(variables)
25+
include("widgets_short.jl")
26+
include("widgets_long.jl")
3027

31-
var_types = map(x -> x[2][3], variables)
32-
varnames = first.(variables)
33-
34-
mapping, mapping_dom = mapping_widget(varnames, var_types)
35-
36-
if isnothing(positions)
37-
channel = Observable(1)
38-
topo_widget = nothing
39-
else
40-
topo_widget, channel = topoplot_widget(positions; size = size .* 0.5)
41-
end
42-
#@debug "mapping" mapping
43-
#mapping = Observable(Dict(:color => :color, :fruit => :marker))
44-
eff_signal = effects_signal(model, widget_signal, channel)
45-
on(mapping) do m
46-
ws = widget_signal.val
47-
ks_m = values(m)
48-
ks_ws = [w.first for w in ws]
49-
for k in ks_ws
50-
widget_checkbox[k][] = k ks_m
51-
end
52-
end
53-
obs = Observable(S.GridLayout())
54-
l = Base.ReentrantLock()
55-
Makie.onany_latest(eff_signal, mapping; update = true) do eff, mapping # update = true means only, that it is run once immediately
56-
lock(l) do
57-
#var_types = map(x -> x[2][3], variables)
58-
obs[] = plot_data(
59-
eff,
60-
value_ranges,
61-
varnames[var_types.==:CategoricalTerm],
62-
varnames[var_types.==:ContinuousTerm],
63-
mapping,
64-
)
65-
end
66-
return
67-
end
68-
css = Asset(joinpath(@__DIR__, "..", "style.css"))
69-
fig = plot(obs; figure = (size = size,))
70-
return DOM.div(
71-
css,
72-
Bonito.TailwindCSS,
73-
Grid(
74-
Card(widget_dom, style = Styles("grid-area" => "header")),
75-
Card(mapping_dom, style = Styles("grid-area" => "sidebar")),
76-
Card(topo_widget, style = Styles("grid-area" => "topo")),
77-
Card(fig, style = Styles("grid-area" => "content"));
78-
columns = "5fr 1fr",
79-
rows = "1fr 6fr 4fr",
80-
areas = """
81-
'header header'
82-
'content sidebar'
83-
'content topo'
84-
""",
85-
);
86-
style = Styles(
87-
"height" => "$(1.2*size[2])px",
88-
"width" => "$(size[1])px",
89-
"margin" => "20px",
90-
"position" => :relative,
91-
),
92-
)
93-
end
94-
end
95-
export explore
9628

9729
end

0 commit comments

Comments
 (0)