diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index ba0d3ee0..43b293b1 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -55,9 +55,9 @@ jobs: - run: | julia --project=docs -e ' using Documenter: DocMeta, doctest - using UnfoldMakie - DocMeta.setdocmeta!(UnfoldMakie, :DocTestSetup, :(using UnfoldMakie); recursive=true) - doctest(UnfoldMakie)' + using ERPgnostics + DocMeta.setdocmeta!(ERPgnostics, :DocTestSetup, :(using ERPgnostics); recursive=true) + doctest(ERPgnostics)' - run: julia --project=docs docs/make.jl env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/src/ERPgnostics.jl b/src/ERPgnostics.jl index 76e58b29..4c07db84 100755 --- a/src/ERPgnostics.jl +++ b/src/ERPgnostics.jl @@ -20,6 +20,7 @@ using WGLMakie using Revise using ProgressBars +include("configs.jl") include("interactive_heatmap.jl") include("interactive_topoplots.jl") include("pattern_detection.jl") diff --git a/src/configs.jl b/src/configs.jl new file mode 100644 index 00000000..1afea2ca --- /dev/null +++ b/src/configs.jl @@ -0,0 +1,44 @@ + +""" + supportive_defaults(cfg_symb::Symbol) + +Default configurations for the supporting axis. Similar to PlotConfig, but these configurations are not shared by all plots.\\ +Such supporting axes allow users to flexibly see defaults in docstrings and manipulate them using corresponding axes. + +For developers: to make them updateable in the function, use `update_axis`. +**Return value:** `NamedTuple`. +""" +function supportive_defaults(cfg_symb::Symbol) + # plot_splines + if cfg_symb == :toposeries_default + return (; + nrows = 1, + col_labels = true, + mapping = (; col = :condition), + axis = (; xlabel = "Conditions", xlabelvisible = false), + visual = ( + label_scatter = (markersize = 10, strokewidth = 2), + contours = (; levels = 0), + colormap = Reverse(:RdGy_4), + ), + colorbar = (; + label = "Pattern detection function value", + colorrange = (0, 1), + height = 300, + ), + layout = (; use_colorbar = true), + ) + elseif cfg_symb == :erpimage_defaults + return (; show_sortval = true, meanplot = true, axis = (; title = "ERP image")) + end +end + +""" + update_axis(support_axis::NamedTuple; kwargs...) +Update values of `NamedTuple{key = value}`.\\ +Used for supportive axes to make users be able to flexibly change them. +""" +function update_axis(support_axis::NamedTuple; kwargs...) + support_axis = (; support_axis..., kwargs...) + return support_axis +end diff --git a/src/interactive_topoplots.jl b/src/interactive_topoplots.jl index e995be30..b8882271 100644 --- a/src/interactive_topoplots.jl +++ b/src/interactive_topoplots.jl @@ -7,6 +7,13 @@ Plot interactive topoplot series. - `pattern_detection_values::DataFrame`\\ DataFrame with columns condition and estimate. Each condition is resposible for a topoplot. Estimates will be projected across channels. +- `figure_configs::NamedTuple = (;)`\\ + Here you can flexibly change configurations of the Figure axis.\\ + To see all options just type `?Figure` in REPL.\\ +- `toposeries_configs::NamedTuple = (;)`\\ + Here you can flexibly change configurations of the topoplot series.\\ + To see all options just type `?plot_topoplotseries` in REPL.\\ + Defaults: $(supportive_defaults(:toposeries_default)) - `kwargs...`\\ Additional styling behavior. \\ @@ -20,7 +27,7 @@ function inter_toposeries( pattern_detection_values::DataFrame; positions::Vector{Point{2,Float64}} = positions_128, figure_configs = (; size = (1500, 400)), - toposeries_configs = (; nrows = 1,), + toposeries_configs = (;), ) names = unique(pattern_detection_values.condition) @@ -51,15 +58,14 @@ function inter_toposeries( end hidespines!(ax) hidedecorations!(ax) + + toposeries_configs = + update_axis(supportive_defaults(:toposeries_default); toposeries_configs...) plot_topoplotseries!( # make configurable f[1, 1], pattern_detection_values; - mapping = (; col = :condition), positions = positions, - nrows = nrows, interactive_scatter = obs_tuple, - visual = (label_scatter = (markersize = 10, strokewidth = 2),), - layout = (; use_colorbar = true), toposeries_configs..., ) @@ -84,6 +90,17 @@ ERP image will have trials on y-axis and time on x-axis 3-dimensional Array of voltages of Event-related potentials. Dimensions: channels, time of recording, trials. - `timing::?`\\ Timing of recording. Should be similar to y-value of erps. +- `figure_configs::NamedTuple = (;)`\\ + Here you can flexibly change configurations of the Figure axis.\\ + To see all options just type `?Figure` in REPL.\\ +- `toposeries_configs::NamedTuple = (;)`\\ + Here you can flexibly change configurations of the topoplot series.\\ + To see all options just type `?plot_topoplotseries` in REPL.\\ + Defaults: $(supportive_defaults(:toposeries_default)) +- `erpimage_configs::NamedTuple = (;)`\\ + Here you can flexibly change configurations of the ERP image plot.\\ + To see all options just type `?plot_erpimage` in REPL.\\ + Defaults: $(supportive_defaults(:erpimage_defaults)) - `kwargs...`\\ Additional styling behavior. \\ @@ -98,8 +115,10 @@ function inter_toposeries_image( events, erps, #::Array{Float64,3}, timing; - figure_configs = (; size = (1500, 400)), positions = positions_128, + figure_configs = (; size = (1500, 400)), + toposeries_configs = (;), + erpimage_configs = (;), ) cond_names = unique(pattern_detection_values.condition) @@ -116,24 +135,17 @@ function inter_toposeries_image( hidespines!(ax) hidedecorations!(ax) + toposeries_configs = + update_axis(supportive_defaults(:toposeries_default); toposeries_configs...) + erpimage_configs = + update_axis(supportive_defaults(:erpimage_defaults); erpimage_configs...) + plot_topoplotseries!( f[1, 1:5], pattern_detection_values; positions = positions, - col_labels = true, - mapping = (; col = :condition), - axis = (; xlabel = "Conditions", xlabelvisible = false), - visual = ( - label_scatter = (markersize = 10, strokewidth = 2), - contours = (; levels = 0), - colormap = Reverse(:RdGy_4), - ), interactive_scatter = obs_tuple, - colorbar = (; - label = "Pattern detection function value", - colorrange = (0, 1), - height = 300, - ), + toposeries_configs..., ) single_channel_erpimage = @lift(erps[$obs_tuple[3], :, :]) @@ -145,10 +157,8 @@ function inter_toposeries_image( timing, single_channel_erpimage; sortvalues = sortval, - show_sortval = true, - meanplot = true, sortval_xlabel = str2, - axis = (; title = "ERP image"), + erpimage_configs..., ) #= on(events(f).mousebutton, priority = 1) do event diff --git a/test/interactive_topoplots_test.jl b/test/interactive_topoplots_test.jl index c561bd88..f1773724 100644 --- a/test/interactive_topoplots_test.jl +++ b/test/interactive_topoplots_test.jl @@ -13,7 +13,18 @@ desired_conditions = ["duration", "fix_avgpos_x", "fix_avgpos_y", "fix_avgpupils ) end -@testset "inter_toposeries" begin +@testset "inter_toposeries_image" begin + inter_toposeries_image( + filter(row -> row.condition in desired_conditions, pattern_detection_values_32), + evts, + erps_fix_32, + 1:151; + positions = positions_128[1:32], + figure_configs = (; size = (1500, 700)), + ) +end + +@testset "inter_toposeries_image: toposeries_config" begin inter_toposeries_image( filter(row -> row.condition in desired_conditions, pattern_detection_values_32), evts, @@ -21,5 +32,6 @@ end 1:151; positions = positions_128[1:32], figure_configs = (; size = (1500, 700)), + toposeries_configs = (; colorbar = (; label = "test")), ) end