Skip to content

Commit 4bc44ff

Browse files
committed
solved: bug while alternatin toggles
1 parent 53a0d31 commit 4bc44ff

File tree

4 files changed

+42
-47
lines changed

4 files changed

+42
-47
lines changed

src/explore.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function explore(model::UnfoldModel; positions = nothing, size = (700, 600))
2727
mapping, mapping_dom = mapping_dropdowns(var_names, var_types)
2828

2929
# Create interactive topoplot widget on the lower left panel of the dashboard.
30-
channel_chosen = Observable(4)
30+
channel_chosen = Observable(1)
3131
if isnothing(positions)
3232
topo_widget = nothing
3333
else
@@ -47,7 +47,8 @@ function explore(model::UnfoldModel; positions = nothing, size = (700, 600))
4747
end
4848

4949
# Create a new empty grid layout
50-
plot_layout = Observable(S.GridLayout())
50+
51+
global plot_layout = Observable(S.GridLayout())
5152

5253
# Create a new reentrant mutex (mutual exclusion) lock for safe thread synchronization during plot updates
5354
# mutex - allows only one thread to access protected code at a time
@@ -73,7 +74,6 @@ function explore(model::UnfoldModel; positions = nothing, size = (700, 600))
7374

7475
css = Asset(joinpath(@__DIR__, "..", "style.css"))
7576
fig = plot(plot_layout; figure = (size = size,))
76-
7777
# Create header, sidebar, topo and content (figure) panels
7878
cards = Grid(
7979
Card(formula_DOM, style = Styles("grid-area" => "header")),

src/functions_plotting.jl

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11

22
"""
3-
update_grid(data, value_ranges, categorical_vars, continuous_vars, mapping_obs)
3+
update_grid(data, formula_values, categorical_vars, continuous_terms, mapping_obs)
44
Plotting and updating an interactive dashboard.
55
66
Arguments:\\
77
- `data::DataFrame` - the result of `effects(Dict(...), model) ` with columns: yhat, channel, dummy, time, eventname and unique columns for each formula term.\\
8-
- `value_ranges::Vector{Pair{Symbol}}` - value range for continuous variables, levels for categorical.\\
8+
- `formula_values::Vector{Pair{Symbol}}` - value range for continuous variables, levels for categorical.\\
99
- `categorical_vars::Vector{Symbol}` - categorical terms.\\
10-
- `continuous_vars::Vector{Symbol}` - continuous terms.\\
10+
- `continuous_terms::Vector{Symbol}` - continuous terms.\\
1111
- `mapping::Dict{Symbol, Symbol}` - dictionary with dropdown menus and their default values.\\
1212
1313
Action:\\
@@ -19,33 +19,33 @@ Action:\\
1919
2020
**Return Value:** `Makie.GridLayoutSpec`.
2121
"""
22-
function update_grid(data, value_ranges, cat_terms, continuous_vars, mapping_obs)
22+
function update_grid(data, formula_values, cat_terms, continuous_terms, mapping_obs)
2323
# Convert observable mapping to values
2424
mapping = to_value(mapping_obs)
2525

26-
# Identify activated categorical and continuous variables
26+
# Identify is categorical term activated
2727
cat_active = Dict(cat => data[1, cat] != "typical_value" for cat in cat_terms)
28-
cont_active = Dict(cont => data[1, cont] != "typical_value" for cont in continuous_vars)
29-
#@debug cat_active
30-
# Retrieve unique categorical levels
31-
cat_levels = [unique(data[!, cat]) for cat in cat_terms]
28+
# Identify is continuous term activated
29+
cont_active = Dict(cont => data[1, cont] != "typical_value" for cont in continuous_terms)
30+
# Retrieve levels for selected and unselected categorical terms
31+
cat_levels = [unique(data[!, cat]) for cat in cat_terms] # empty unless selected
3232

3333
# Prepare styles for categorical and continuous variables
3434
scatter_styles, line_styles = prepare_styles(
3535
data,
3636
cat_terms,
37-
continuous_vars,
37+
continuous_terms,
3838
mapping,
3939
cat_active,
4040
cont_active,
4141
cat_levels,
4242
)
4343

44-
col_term = mapping[:col]
45-
row_term = mapping[:row]
44+
col_term = mapping[:col] # not used yet
45+
row_term = mapping[:row] # not used yet
4646

4747
legend_entries =
48-
[n => v for (n, v) in value_ranges if merge(cat_active, cont_active)[n]]
48+
[n => v for (n, v) in formula_values if merge(cat_active, cont_active)[n]]
4949

5050
row_levels =
5151
row_term == :none ? [""] :
@@ -75,45 +75,45 @@ function update_grid(data, value_ranges, cat_terms, continuous_vars, mapping_obs
7575
if col_term != :none
7676
active_cat_vars[col_term] = [col_level]
7777
end
78+
7879
# Iterate over categorical levels to define styles
7980
for level_grid in Iterators.product(collect(values(active_cat_vars))...)
8081
if !isempty(level_grid) && level_grid[1] .== "typical_value"
8182
continue
8283
end
83-
# create a new term => values (e.g. animal => [fish,cow] ) Dict
84+
dict_grid = Dict(collect(keys(active_cat_vars)) .=> level_grid)
8485
define_scatter_line_style!(
8586
plots,
8687
subdata,
87-
Dict(collect(keys(active_cat_vars)) .=> level_grid),
88+
dict_grid,
8889
scatter_styles,
8990
line_styles,
90-
continuous_vars,
91+
continuous_terms,
9192
)
9293
end
93-
axes[r_ix, c_ix] = S.Axis(; plots = plots)
94+
axes[r_ix, c_ix] = S.Axis(; plots = plots)
9495
end
9596
end
9697
palettes = merge(line_styles, scatter_styles)
9798

98-
legends = Union{Nothing,Makie.BlockSpec}[]
99+
legends = Union{Nothing, Makie.BlockSpec}[]
99100
for (term, levels) in legend_entries
100101
if haskey(palettes, term)
101102
push!(legends, variable_legend(term, levels, Dict(palettes[term])))
102103
end
103104
end
104-
105-
if isempty(legends)
106-
return S.GridLayout(axes)
107-
else
108-
return S.GridLayout([(1, 1) => S.GridLayout(axes), (:, 2) => S.GridLayout(legends)])
109-
end
105+
res = S.GridLayout([
106+
(1, 1) => S.GridLayout(axes),
107+
(:, 2) => S.GridLayout(legends)
108+
])
109+
return res
110110
end
111111

112112

113113
function prepare_styles(
114114
data,
115115
cat_terms,
116-
continuous_vars,
116+
continuous_terms,
117117
mapping,
118118
cat_active,
119119
cont_active,
@@ -127,30 +127,28 @@ function prepare_styles(
127127

128128
# Assign styles to categorical variables
129129
scatter_styles = Dict()
130-
131130
for (vals, cat) in zip(cat_levels, cat_terms)
132131
if !cat_active[cat]
133132
continue
134133
end
135-
136134
for (target, pal) in
137135
zip([:color, :marker, :linestyle], (cpalette, mpalette, lpalette))
138-
if mapping[target] == cat
136+
if mapping[target] == cat
139137
p = cat => (target => Dict(zip(vals, pal)))
140138
push!(scatter_styles, p)
141139
end
142140
end
143141
end
144142
# Assign styles to continuous variables
145-
continuous_values = [extrema(data[!, con]) for con in continuous_vars]
146-
if isempty(continuous_vars)
143+
continuous_values = [extrema(data[!, con]) for con in continuous_terms]
144+
if isempty(continuous_terms)
147145
# if no continuous variable, use the scatter-color for plotting
148146
line_styles = Dict()
149147

150148
else
151149
line_styles = Dict(
152150
cont => (:colormap => (val, style)) for (style, val, cont) in
153-
zip(continuous_styles, continuous_values, continuous_vars) if
151+
zip(continuous_styles, continuous_values, continuous_terms) if
154152
cont_active[cont]
155153
)
156154
end

src/functions_scatter_linestyle.jl

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,16 @@ function define_scatter_line_style!(
4141
(term, val) in dict_grid if term keys(scatter_styles)
4242
]
4343

44-
# define style for lines
44+
# define style for lines and scatter
4545
if isempty(line_styles)
4646
line_cmap = []
4747
line_crange = []
4848

49-
line_color = args
50-
if isempty(args) || !any(x -> x[1] == :color, args)
51-
args = convert(Vector{Pair{Symbol, Any}}, args)
52-
push!(args, :color => RGBA(0.0f0, 0.0f0, 0.0f0, 1.0f0)) # set scatte color to default black
53-
line_color = [:color => Dict(args)[:color]] # set line color to default black
49+
args = convert(Vector{Pair{Symbol, Any}}, args)
50+
if isempty(args) || !any(x -> x[1] == :color, args)
51+
push!(args, :color => RGBA(0.0f0, 0.0f0, 0.0f0, 1.0f0)) # set scatter color to default black
5452
end
53+
line_color = [:color => Dict(args)[:color]]
5554

5655
else # if contionus terms are present
5756
line_cmap = [kw => cmap for (_, (kw, (_, cmap))) in line_styles]

src/widgets_long.jl

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
1-
2-
31
"""
42
mapping_dropdowns(varnames, var_types)
5-
Map and arrange dropdown menus on the left panel of the dashboard.\\
3+
Map and arrange drop-down menus on the left panel of the dashboard.\\
64
75
Arguments:\\
86
- `varnames::Vector{Symbol}` - vector of the model formula terms.\\
97
- `var_types::Vector{Symbol}` - vector of types of the model formula terms.\\
108
119
Actions:\\
12-
- Take categorical variables and put their values into dropdown menus.\\
10+
- Take categorical variables and put their values into drop-down menus.\\
1311
- There will be 5 menus for: color, markers, line styles, column and row facets.\\
14-
- Map each menu object with its name on the Figure.\\
15-
- Create HTML containers using Document Object Model (DOM) from Bonito.\\
16-
- Arrange containers on the panel using Col() and Row(). Specify their styling.\\
12+
- Map each menu object to its name in the image.\\
13+
- Create HTML containers using Bonito's Document Object Model (DOM).\\
14+
- Arrange the containers on the panel using Col() and Row(). Specify their styling.\\
1715
1816
**Return Values:**\\
1917
- `mapping::Observable{Dict{Symbol, Symbol}}` - interactive dictionary with menues and their default value.\\

0 commit comments

Comments
 (0)