From 24a98291fb5463245dc0b879f2d8285713ffe0f8 Mon Sep 17 00:00:00 2001 From: ncguilbeault Date: Mon, 20 May 2024 12:25:05 +0100 Subject: [PATCH] Updated documentation and minor code refactoring --- .../HeatMapSeriesOxyPlotBase.cs | 54 ++++++++----------- .../MultidimensionalArrayVisualizer.cs | 26 +++------ .../MultivariatePDFVisualizer.cs | 34 +++++------- 3 files changed, 43 insertions(+), 71 deletions(-) diff --git a/src/Bonsai.ML.Visualizers/HeatMapSeriesOxyPlotBase.cs b/src/Bonsai.ML.Visualizers/HeatMapSeriesOxyPlotBase.cs index 91867197..2d1d3705 100644 --- a/src/Bonsai.ML.Visualizers/HeatMapSeriesOxyPlotBase.cs +++ b/src/Bonsai.ML.Visualizers/HeatMapSeriesOxyPlotBase.cs @@ -35,17 +35,11 @@ internal class HeatMapSeriesOxyPlotBase : UserControl /// public event EventHandler PaletteComboBoxValueChanged; - public ToolStripComboBox PaletteComboBox - { - get => paletteComboBox; - } + public ToolStripComboBox PaletteComboBox => paletteComboBox; public event EventHandler RenderMethodComboBoxValueChanged; - public ToolStripComboBox RenderMethodComboBox - { - get => renderMethodComboBox; - } + public ToolStripComboBox RenderMethodComboBox => renderMethodComboBox; public StatusStrip StatusStrip { @@ -63,7 +57,6 @@ public HeatMapSeriesOxyPlotBase(int paletteSelectedIndex, int renderMethodSelect _paletteSelectedIndex = paletteSelectedIndex; _renderMethodSelectedIndex = renderMethodSelectedIndex; _numColors = numColors; - // palette = OxyPalettes.Rainbow(_numColors); Initialize(); } @@ -71,7 +64,6 @@ private void Initialize() { view = new PlotView { - Size = Size, Dock = DockStyle.Fill, }; @@ -97,8 +89,8 @@ private void Initialize() view.Model = model; Controls.Add(view); - InitilizeColorPalette(); - InitilizeRenderMethod(); + InitializeColorPalette(); + InitializeRenderMethod(); statusStrip = new StatusStrip { @@ -117,7 +109,7 @@ private void Initialize() AutoScaleDimensions = new SizeF(6F, 13F); } - private void InitilizeColorPalette() + private void InitializeColorPalette() { paletteLabel = new ToolStripLabel { @@ -131,7 +123,7 @@ private void InitilizeColorPalette() AutoSize = true, }; - foreach (var value in Enum.GetValues(typeof(ColorPalettes))) + foreach (var value in Enum.GetValues(typeof(ColorPalette))) { paletteComboBox.Items.Add(value); } @@ -154,13 +146,13 @@ private void PaletteComboBoxSelectedIndexChanged(object sender, EventArgs e) private void UpdateColorPalette() { - var selectedPalette = (ColorPalettes)paletteComboBox.Items[_paletteSelectedIndex]; + var selectedPalette = (ColorPalette)paletteComboBox.Items[_paletteSelectedIndex]; paletteLookup.TryGetValue(selectedPalette, out Func paletteMethod); palette = paletteMethod(_numColors); colorAxis.Palette = palette; } - private void InitilizeRenderMethod() + private void InitializeRenderMethod() { renderMethodLabel = new ToolStripLabel { @@ -223,22 +215,22 @@ public void UpdatePlot() model.InvalidatePlot(true); } - private static readonly Dictionary> paletteLookup = new Dictionary> + private static readonly Dictionary> paletteLookup = new Dictionary> { - { ColorPalettes.Cividis, (numColors) => OxyPalettes.Cividis(numColors) }, - { ColorPalettes.Inferno, (numColors) => OxyPalettes.Inferno(numColors) }, - { ColorPalettes.Viridis, (numColors) => OxyPalettes.Viridis(numColors) }, - { ColorPalettes.Magma, (numColors) => OxyPalettes.Magma(numColors) }, - { ColorPalettes.Plasma, (numColors) => OxyPalettes.Plasma(numColors) }, - { ColorPalettes.BlackWhiteRed, (numColors) => OxyPalettes.BlackWhiteRed(numColors) }, - { ColorPalettes.BlueWhiteRed, (numColors) => OxyPalettes.BlueWhiteRed(numColors) }, - { ColorPalettes.Cool, (numColors) => OxyPalettes.Cool(numColors) }, - { ColorPalettes.Gray, (numColors) => OxyPalettes.Gray(numColors) }, - { ColorPalettes.Hot, (numColors) => OxyPalettes.Hot(numColors) }, - { ColorPalettes.Hue, (numColors) => OxyPalettes.Hue(numColors) }, - { ColorPalettes.HueDistinct, (numColors) => OxyPalettes.HueDistinct(numColors) }, - { ColorPalettes.Jet, (numColors) => OxyPalettes.Jet(numColors) }, - { ColorPalettes.Rainbow, (numColors) => OxyPalettes.Rainbow(numColors) }, + { ColorPalette.Cividis, (numColors) => OxyPalettes.Cividis(numColors) }, + { ColorPalette.Inferno, (numColors) => OxyPalettes.Inferno(numColors) }, + { ColorPalette.Viridis, (numColors) => OxyPalettes.Viridis(numColors) }, + { ColorPalette.Magma, (numColors) => OxyPalettes.Magma(numColors) }, + { ColorPalette.Plasma, (numColors) => OxyPalettes.Plasma(numColors) }, + { ColorPalette.BlackWhiteRed, (numColors) => OxyPalettes.BlackWhiteRed(numColors) }, + { ColorPalette.BlueWhiteRed, (numColors) => OxyPalettes.BlueWhiteRed(numColors) }, + { ColorPalette.Cool, (numColors) => OxyPalettes.Cool(numColors) }, + { ColorPalette.Gray, (numColors) => OxyPalettes.Gray(numColors) }, + { ColorPalette.Hot, (numColors) => OxyPalettes.Hot(numColors) }, + { ColorPalette.Hue, (numColors) => OxyPalettes.Hue(numColors) }, + { ColorPalette.HueDistinct, (numColors) => OxyPalettes.HueDistinct(numColors) }, + { ColorPalette.Jet, (numColors) => OxyPalettes.Jet(numColors) }, + { ColorPalette.Rainbow, (numColors) => OxyPalettes.Rainbow(numColors) }, }; } } diff --git a/src/Bonsai.ML.Visualizers/MultidimensionalArrayVisualizer.cs b/src/Bonsai.ML.Visualizers/MultidimensionalArrayVisualizer.cs index 456452aa..6977f8bd 100644 --- a/src/Bonsai.ML.Visualizers/MultidimensionalArrayVisualizer.cs +++ b/src/Bonsai.ML.Visualizers/MultidimensionalArrayVisualizer.cs @@ -23,29 +23,23 @@ namespace Bonsai.ML.Visualizers /// public class MultidimensionalArrayVisualizer : DialogTypeVisualizer { - - private int paletteSelectedIndex = 0; - private int renderMethodSelectedIndex = 0; - /// - /// Size of the window when loaded + /// Gets or sets the selected index of the color palette to use. /// - public Size Size { get; set; } = new Size(320, 240); + public int PaletteSelectedIndex { get; set; } /// - /// The selected index of the color palette to use + /// Gets or sets the selected index of the render method to use. /// - public int PaletteSelectedIndex { get => paletteSelectedIndex; set => paletteSelectedIndex = value; } - public int RenderMethodSelectedIndex { get => renderMethodSelectedIndex; set => renderMethodSelectedIndex = value; } + public int RenderMethodSelectedIndex { get; set; } private HeatMapSeriesOxyPlotBase Plot; /// public override void Load(IServiceProvider provider) { - Plot = new HeatMapSeriesOxyPlotBase(paletteSelectedIndex, renderMethodSelectedIndex) + Plot = new HeatMapSeriesOxyPlotBase(PaletteSelectedIndex, RenderMethodSelectedIndex) { - Size = Size, Dock = DockStyle.Fill, }; @@ -85,18 +79,14 @@ public override void Unload() } } - /// - /// Callback function to update the selected index when the selected combobox index has changed - /// private void PaletteIndexChanged(object sender, EventArgs e) { - var comboBox = Plot.PaletteComboBox; - paletteSelectedIndex = comboBox.SelectedIndex; + PaletteSelectedIndex = Plot.PaletteComboBox.SelectedIndex; } + private void RenderMethodIndexChanged(object sender, EventArgs e) { - var comboBox = Plot.RenderMethodComboBox; - renderMethodSelectedIndex = comboBox.SelectedIndex; + RenderMethodSelectedIndex = Plot.RenderMethodComboBox.SelectedIndex; } } } diff --git a/src/Bonsai.ML.Visualizers/MultivariatePDFVisualizer.cs b/src/Bonsai.ML.Visualizers/MultivariatePDFVisualizer.cs index 8e55be0e..4b9012c1 100644 --- a/src/Bonsai.ML.Visualizers/MultivariatePDFVisualizer.cs +++ b/src/Bonsai.ML.Visualizers/MultivariatePDFVisualizer.cs @@ -21,29 +21,23 @@ namespace Bonsai.ML.Visualizers /// public class MultivariatePDFVisualizer : DialogTypeVisualizer { - - private int paletteSelectedIndex = 0; - private int renderMethodSelectedIndex = 0; - /// - /// Size of the window when loaded + /// Gets or sets the selected index of the color palette to use. /// - public Size Size { get; set; } = new Size(320, 240); + public int PaletteSelectedIndex { get; set; } /// - /// The selected index of the color palette to use + /// Gets or sets the selected index of the render method to use. /// - public int PaletteSelectedIndex { get => paletteSelectedIndex; set => paletteSelectedIndex = value; } - public int RenderMethodSelectedIndex { get => renderMethodSelectedIndex; set => renderMethodSelectedIndex = value; } + public int RenderMethodSelectedIndex { get; set; } private HeatMapSeriesOxyPlotBase Plot; /// public override void Load(IServiceProvider provider) { - Plot = new HeatMapSeriesOxyPlotBase(paletteSelectedIndex, renderMethodSelectedIndex) + Plot = new HeatMapSeriesOxyPlotBase(PaletteSelectedIndex, RenderMethodSelectedIndex) { - Size = Size, Dock = DockStyle.Fill, }; @@ -62,10 +56,10 @@ public override void Show(object value) { var pdf = (MultivariatePDF)value; Plot.UpdateHeatMapSeries( - pdf.GridParameters.X0 - (1 / 2 * pdf.GridParameters.Xsteps), - pdf.GridParameters.X1 - (1 / 2 * pdf.GridParameters.Xsteps), - pdf.GridParameters.Y0 - (1 / 2 * pdf.GridParameters.Ysteps), - pdf.GridParameters.Y1 - (1 / 2 * pdf.GridParameters.Ysteps), + pdf.GridParameters.X0 - (1 / 2 * pdf.GridParameters.XSteps), + pdf.GridParameters.X1 - (1 / 2 * pdf.GridParameters.XSteps), + pdf.GridParameters.Y0 - (1 / 2 * pdf.GridParameters.YSteps), + pdf.GridParameters.Y1 - (1 / 2 * pdf.GridParameters.YSteps), pdf.Values ); Plot.UpdatePlot(); @@ -80,18 +74,14 @@ public override void Unload() } } - /// - /// Callback function to update the selected index when the selected combobox index has changed - /// private void PaletteIndexChanged(object sender, EventArgs e) { - var comboBox = Plot.PaletteComboBox; - paletteSelectedIndex = comboBox.SelectedIndex; + PaletteSelectedIndex = Plot.PaletteComboBox.SelectedIndex; } + private void RenderMethodIndexChanged(object sender, EventArgs e) { - var comboBox = Plot.RenderMethodComboBox; - renderMethodSelectedIndex = comboBox.SelectedIndex; + RenderMethodSelectedIndex = Plot.RenderMethodComboBox.SelectedIndex; } } }