Skip to content

Commit

Permalink
Updated documentation and minor code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ncguilbeault committed May 20, 2024
1 parent f689496 commit 24a9829
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 71 deletions.
54 changes: 23 additions & 31 deletions src/Bonsai.ML.Visualizers/HeatMapSeriesOxyPlotBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,11 @@ internal class HeatMapSeriesOxyPlotBase : UserControl
/// </summary>
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
{
Expand All @@ -63,15 +57,13 @@ public HeatMapSeriesOxyPlotBase(int paletteSelectedIndex, int renderMethodSelect
_paletteSelectedIndex = paletteSelectedIndex;
_renderMethodSelectedIndex = renderMethodSelectedIndex;
_numColors = numColors;
// palette = OxyPalettes.Rainbow(_numColors);
Initialize();
}

private void Initialize()
{
view = new PlotView
{
Size = Size,
Dock = DockStyle.Fill,
};

Expand All @@ -97,8 +89,8 @@ private void Initialize()
view.Model = model;
Controls.Add(view);

InitilizeColorPalette();
InitilizeRenderMethod();
InitializeColorPalette();
InitializeRenderMethod();

statusStrip = new StatusStrip
{
Expand All @@ -117,7 +109,7 @@ private void Initialize()
AutoScaleDimensions = new SizeF(6F, 13F);
}

private void InitilizeColorPalette()
private void InitializeColorPalette()
{
paletteLabel = new ToolStripLabel
{
Expand All @@ -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);
}
Expand All @@ -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<int, OxyPalette> paletteMethod);
palette = paletteMethod(_numColors);
colorAxis.Palette = palette;
}

private void InitilizeRenderMethod()
private void InitializeRenderMethod()
{
renderMethodLabel = new ToolStripLabel
{
Expand Down Expand Up @@ -223,22 +215,22 @@ public void UpdatePlot()
model.InvalidatePlot(true);
}

private static readonly Dictionary<ColorPalettes, Func<int, OxyPalette>> paletteLookup = new Dictionary<ColorPalettes, Func<int, OxyPalette>>
private static readonly Dictionary<ColorPalette, Func<int, OxyPalette>> paletteLookup = new Dictionary<ColorPalette, Func<int, OxyPalette>>
{
{ 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) },
};
}
}
26 changes: 8 additions & 18 deletions src/Bonsai.ML.Visualizers/MultidimensionalArrayVisualizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,23 @@ namespace Bonsai.ML.Visualizers
/// </summary>
public class MultidimensionalArrayVisualizer : DialogTypeVisualizer
{

private int paletteSelectedIndex = 0;
private int renderMethodSelectedIndex = 0;

/// <summary>
/// Size of the window when loaded
/// Gets or sets the selected index of the color palette to use.
/// </summary>
public Size Size { get; set; } = new Size(320, 240);
public int PaletteSelectedIndex { get; set; }

/// <summary>
/// The selected index of the color palette to use
/// Gets or sets the selected index of the render method to use.
/// </summary>
public int PaletteSelectedIndex { get => paletteSelectedIndex; set => paletteSelectedIndex = value; }
public int RenderMethodSelectedIndex { get => renderMethodSelectedIndex; set => renderMethodSelectedIndex = value; }
public int RenderMethodSelectedIndex { get; set; }

private HeatMapSeriesOxyPlotBase Plot;

/// <inheritdoc/>
public override void Load(IServiceProvider provider)
{
Plot = new HeatMapSeriesOxyPlotBase(paletteSelectedIndex, renderMethodSelectedIndex)
Plot = new HeatMapSeriesOxyPlotBase(PaletteSelectedIndex, RenderMethodSelectedIndex)
{
Size = Size,
Dock = DockStyle.Fill,
};

Expand Down Expand Up @@ -85,18 +79,14 @@ public override void Unload()
}
}

/// <summary>
/// Callback function to update the selected index when the selected combobox index has changed
/// </summary>
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;
}
}
}
34 changes: 12 additions & 22 deletions src/Bonsai.ML.Visualizers/MultivariatePDFVisualizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,23 @@ namespace Bonsai.ML.Visualizers
/// </summary>
public class MultivariatePDFVisualizer : DialogTypeVisualizer
{

private int paletteSelectedIndex = 0;
private int renderMethodSelectedIndex = 0;

/// <summary>
/// Size of the window when loaded
/// Gets or sets the selected index of the color palette to use.
/// </summary>
public Size Size { get; set; } = new Size(320, 240);
public int PaletteSelectedIndex { get; set; }

/// <summary>
/// The selected index of the color palette to use
/// Gets or sets the selected index of the render method to use.
/// </summary>
public int PaletteSelectedIndex { get => paletteSelectedIndex; set => paletteSelectedIndex = value; }
public int RenderMethodSelectedIndex { get => renderMethodSelectedIndex; set => renderMethodSelectedIndex = value; }
public int RenderMethodSelectedIndex { get; set; }

private HeatMapSeriesOxyPlotBase Plot;

/// <inheritdoc/>
public override void Load(IServiceProvider provider)
{
Plot = new HeatMapSeriesOxyPlotBase(paletteSelectedIndex, renderMethodSelectedIndex)
Plot = new HeatMapSeriesOxyPlotBase(PaletteSelectedIndex, RenderMethodSelectedIndex)
{
Size = Size,
Dock = DockStyle.Fill,
};

Expand All @@ -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();
Expand All @@ -80,18 +74,14 @@ public override void Unload()
}
}

/// <summary>
/// Callback function to update the selected index when the selected combobox index has changed
/// </summary>
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;
}
}
}

0 comments on commit 24a9829

Please sign in to comment.