Skip to content

Commit

Permalink
Support mashup of rolling and 2D graph panels
Browse files Browse the repository at this point in the history
  • Loading branch information
glopesdev committed Mar 25, 2024
1 parent edc20b7 commit 359d9a9
Show file tree
Hide file tree
Showing 15 changed files with 1,151 additions and 182 deletions.
6 changes: 3 additions & 3 deletions src/Bonsai.Gui.Visualizers/BarGraphOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using Bonsai.Expressions;
using ZedGraph;

[assembly: TypeVisualizer(typeof(BarGraphOverlay), Target = typeof(MashupSource<GraphPanelVisualizer, BarGraphVisualizer>))]
[assembly: TypeVisualizer(typeof(BarGraphOverlay), Target = typeof(MashupSource<RollingGraphPanelVisualizer, BarGraphVisualizer>))]


namespace Bonsai.Gui.Visualizers
Expand All @@ -18,7 +18,7 @@ namespace Bonsai.Gui.Visualizers
/// </summary>
public class BarGraphOverlay : BufferedVisualizer, IBarGraphVisualizer
{
GraphPanelVisualizer visualizer;
RollingGraphPanelVisualizer visualizer;
BarGraphBuilder.VisualizerController controller;
BoundedPointPairList[] series;

Expand Down Expand Up @@ -83,7 +83,7 @@ void AddBaseY()
/// <inheritdoc/>
public override void Load(IServiceProvider provider)
{
visualizer = (GraphPanelVisualizer)provider.GetService(typeof(MashupVisualizer));
visualizer = (RollingGraphPanelVisualizer)provider.GetService(typeof(MashupVisualizer));
var context = (ITypeVisualizerContext)provider.GetService(typeof(ITypeVisualizerContext));
var barGraphBuilder = (BarGraphBuilder)ExpressionBuilder.GetVisualizerElement(context.Source).Builder;
controller = barGraphBuilder.Controller;
Expand Down
8 changes: 4 additions & 4 deletions src/Bonsai.Gui.Visualizers/Bonsai.Gui.Visualizers.csproj.user
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
<Compile Update="GraphControl.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Update="GraphPanel.cs">
<Compile Update="RollingGraphPanel.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Update="GraphPanel2D.cs">
<Compile Update="GraphPanel.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Update="GraphPanelView.cs">
<Compile Update="RollingGraphPanelView.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Update="GraphPanelView2D.cs">
<Compile Update="GraphPanelView.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Update="LineGraph.cs">
Expand Down
75 changes: 53 additions & 22 deletions src/Bonsai.Gui.Visualizers/GraphPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,56 +4,87 @@ namespace Bonsai.Gui.Visualizers
{
internal class GraphPanel : BoundedGraphPanel
{
bool autoScale;
bool autoScaleX;
bool autoScaleY;

public GraphPanel()
{
autoScale = true;
autoScaleX = true;
autoScaleY = true;
}

public Axis ScaleAxis => GraphPane.BarSettings.Base switch
public double XMin
{
BarBase.Y => GraphPane.XAxis,
BarBase.Y2 => GraphPane.X2Axis,
BarBase.X2 => GraphPane.Y2Axis,
_ => GraphPane.YAxis
};
get { return GraphPane.XAxis.Scale.Min; }
set
{
GraphPane.XAxis.Scale.Min = value;
GraphPane.AxisChange();
Invalidate();
}
}

public double Min
public double XMax
{
get { return ScaleAxis.Scale.Min; }
get { return GraphPane.XAxis.Scale.Max; }
set
{
ScaleAxis.Scale.Min = value;
GraphPane.XAxis.Scale.Max = value;
GraphPane.AxisChange();
Invalidate();
}
}

public double Max
public double YMin
{
get { return ScaleAxis.Scale.Max; }
get { return GraphPane.YAxis.Scale.Min; }
set
{
ScaleAxis.Scale.Max = value;
GraphPane.YAxis.Scale.Min = value;
GraphPane.AxisChange();
Invalidate();
}
}

public bool AutoScale
public double YMax
{
get { return GraphPane.YAxis.Scale.Max; }
set
{
GraphPane.YAxis.Scale.Max = value;
GraphPane.AxisChange();
Invalidate();
}
}

public bool AutoScaleX
{
get { return autoScaleX; }
set
{
var changed = autoScaleX != value;
autoScaleX = value;
if (changed)
{
GraphPane.XAxis.Scale.MaxAuto = autoScaleX;
GraphPane.XAxis.Scale.MinAuto = autoScaleX;
if (autoScaleX) Invalidate();
}
}
}

public bool AutoScaleY
{
get { return autoScale; }
get { return autoScaleY; }
set
{
var changed = autoScale != value;
autoScale = value;
var changed = autoScaleY != value;
autoScaleY = value;
if (changed)
{
var baseAxis = ScaleAxis;
baseAxis.Scale.MaxAuto = autoScale;
baseAxis.Scale.MinAuto = autoScale;
if (autoScale) Invalidate();
GraphPane.YAxis.Scale.MaxAuto = autoScaleY;
GraphPane.YAxis.Scale.MinAuto = autoScaleY;
if (autoScaleY) Invalidate();
}
}
}
Expand Down
48 changes: 24 additions & 24 deletions src/Bonsai.Gui.Visualizers/GraphPanelBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Linq.Expressions;
using System.Reactive.Linq;
using System.Reactive;
using ZedGraph;

namespace Bonsai.Gui.Visualizers
{
Expand All @@ -16,46 +15,47 @@ namespace Bonsai.Gui.Visualizers
public class GraphPanelBuilder : GraphPanelBuilderBase
{
/// <summary>
/// Gets or sets a value specifying the axis on which the bars in the graph will be displayed.
/// Gets or sets a value specifying a fixed lower limit for the X-axis range.
/// If no fixed range is specified, the graph limits can be edited online.
/// </summary>
[TypeConverter(typeof(BaseAxisConverter))]
[Category(nameof(CategoryAttribute.Appearance))]
[Description("Specifies the axis on which the bars in the graph will be displayed.")]
public BarBase BaseAxis { get; set; }
[Category("Range")]
[Description("Specifies the optional fixed lower limit of the X-axis range.")]
public double? XMin { get; set; }

/// <summary>
/// Gets or sets a value specifying how the different bars in the graph will be visually arranged.
/// Gets or sets a value specifying a fixed upper limit for the X-axis range.
/// If no fixed range is specified, the graph limits can be edited online.
/// </summary>
[Category(nameof(CategoryAttribute.Appearance))]
[Description("Specifies how the different bars in the graph will be visually arranged.")]
public BarType BarType { get; set; }
[Category("Range")]
[Description("Specifies the optional fixed upper limit of the X-axis range.")]
public double? XMax { get; set; }

/// <summary>
/// Gets or sets a value specifying a fixed lower limit for the axis range.
/// Gets or sets a value specifying a fixed lower limit for the Y-axis range.
/// If no fixed range is specified, the graph limits can be edited online.
/// </summary>
[Category("Range")]
[Description("Specifies the optional fixed lower limit of the axis range.")]
public double? Min { get; set; }
[Description("Specifies the optional fixed lower limit of the Y-axis range.")]
public double? YMin { get; set; }

/// <summary>
/// Gets or sets a value specifying a fixed upper limit for the axis range.
/// Gets or sets a value specifying a fixed upper limit for the Y-axis range.
/// If no fixed range is specified, the graph limits can be edited online.
/// </summary>
[Category("Range")]
[Description("Specifies the optional fixed upper limit of the axis range.")]
public double? Max { get; set; }
[Description("Specifies the optional fixed upper limit of the Y-axis range.")]
public double? YMax { get; set; }

internal VisualizerController Controller { get; set; }

internal class VisualizerController
{
internal BarBase BaseAxis;
internal BarType BarType;
internal double? Span;
internal int? Capacity;
internal double? Min;
internal double? Max;
internal double? XMin;
internal double? XMax;
internal double? YMin;
internal double? YMax;
internal bool ReverseX;
internal bool ReverseY;
}
Expand All @@ -69,12 +69,12 @@ public override Expression Build(IEnumerable<Expression> arguments)
{
Controller = new VisualizerController
{
BaseAxis = BaseAxis,
BarType = BarType,
Span = Span,
Capacity = Capacity,
Min = Min,
Max = Max,
XMin = XMin,
XMax = XMax,
YMin = YMin,
YMax = YMax,
ReverseX = ReverseX,
ReverseY = ReverseY
};
Expand Down
Loading

0 comments on commit 359d9a9

Please sign in to comment.