ChartWindow: Fix warnings and avoid null-forgiving operator
Test / Run tests (push) Successful in 2m10s
Test / Run tests (push) Successful in 2m10s
This commit is contained in:
@@ -26,12 +26,12 @@ namespace Elwig.Windows {
|
|||||||
private bool HasChanged = false;
|
private bool HasChanged = false;
|
||||||
private bool Updating = false;
|
private bool Updating = false;
|
||||||
|
|
||||||
private Scatter DataPlot;
|
private Scatter? DataPlot;
|
||||||
private Scatter? GebundenPlot;
|
private Scatter? GebundenPlot;
|
||||||
private Marker HighlightedPointPlot;
|
private Marker? HighlightedPointPlot;
|
||||||
private Marker PrimaryMarkedPointPlot;
|
private Marker? PrimaryMarkedPointPlot;
|
||||||
private Marker SecondaryMarkedPointPlot;
|
private Marker? SecondaryMarkedPointPlot;
|
||||||
private Text TooltipPlot;
|
private Text? TooltipPlot;
|
||||||
|
|
||||||
private static readonly LegendItem
|
private static readonly LegendItem
|
||||||
UngebundenLegend = new() {
|
UngebundenLegend = new() {
|
||||||
@@ -77,7 +77,7 @@ namespace Elwig.Windows {
|
|||||||
PriceInput.Unit = $"{CurrencySymbol}/kg";
|
PriceInput.Unit = $"{CurrencySymbol}/kg";
|
||||||
GebundenFlatBonus.Unit = $"{CurrencySymbol}/kg";
|
GebundenFlatBonus.Unit = $"{CurrencySymbol}/kg";
|
||||||
PaymentVar = ctx.PaymentVariants.Find(year, avnr) ?? throw new ArgumentException("PaymentVar not found");
|
PaymentVar = ctx.PaymentVariants.Find(year, avnr) ?? throw new ArgumentException("PaymentVar not found");
|
||||||
Title = $"{PaymentVar?.Name} - Lese {year} - Elwig";
|
Title = $"{PaymentVar.Name} - Lese {year} - Elwig";
|
||||||
LockContext = true;
|
LockContext = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -215,10 +215,12 @@ namespace Elwig.Windows {
|
|||||||
GebundenPlot.MarkerStyle = new MarkerStyle(MarkerShape.FilledCircle, 9, ColorGebunden);
|
GebundenPlot.MarkerStyle = new MarkerStyle(MarkerShape.FilledCircle, 9, ColorGebunden);
|
||||||
}
|
}
|
||||||
|
|
||||||
DataPlot = OechslePricePlot.Plot.Add.Scatter(SelectedGraphEntry!.DataGraph.DataX, SelectedGraphEntry!.DataGraph.DataY);
|
if (SelectedGraphEntry != null) {
|
||||||
DataPlot.LineStyle.Color = ColorUngebunden;
|
DataPlot = OechslePricePlot.Plot.Add.Scatter(SelectedGraphEntry.DataGraph.DataX, SelectedGraphEntry.DataGraph.DataY);
|
||||||
DataPlot.Color = ColorUngebunden;
|
DataPlot.LineStyle.Color = ColorUngebunden;
|
||||||
DataPlot.MarkerStyle = new MarkerStyle(MarkerShape.FilledCircle, 9, ColorUngebunden);
|
DataPlot.Color = ColorUngebunden;
|
||||||
|
DataPlot.MarkerStyle = new MarkerStyle(MarkerShape.FilledCircle, 9, ColorUngebunden);
|
||||||
|
}
|
||||||
|
|
||||||
OechslePricePlot.Plot.Axes.SetLimits(Math.Min(GraphEntry.MinX, GraphEntry.MinXGeb) - 1, GraphEntry.MaxX + 1, -0.1, 1.5);
|
OechslePricePlot.Plot.Axes.SetLimits(Math.Min(GraphEntry.MinX, GraphEntry.MinXGeb) - 1, GraphEntry.MaxX + 1, -0.1, 1.5);
|
||||||
|
|
||||||
@@ -244,7 +246,10 @@ namespace Elwig.Windows {
|
|||||||
SecondaryMarkedPoint = -1;
|
SecondaryMarkedPoint = -1;
|
||||||
ChangeActiveGraph(null);
|
ChangeActiveGraph(null);
|
||||||
HideGradationLines();
|
HideGradationLines();
|
||||||
OechslePricePlot.Plot.Remove(DataPlot);
|
if (DataPlot != null) {
|
||||||
|
OechslePricePlot.Plot.Remove(DataPlot);
|
||||||
|
DataPlot = null;
|
||||||
|
}
|
||||||
if (GebundenPlot != null) {
|
if (GebundenPlot != null) {
|
||||||
OechslePricePlot.Plot.Remove(GebundenPlot);
|
OechslePricePlot.Plot.Remove(GebundenPlot);
|
||||||
GebundenPlot = null;
|
GebundenPlot = null;
|
||||||
@@ -254,9 +259,9 @@ namespace Elwig.Windows {
|
|||||||
OechslePricePlot.Refresh();
|
OechslePricePlot.Refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ChangeMarker(Marker point, bool visible, double x = 0, double y = 0) {
|
private static void ChangeMarker(Marker? point, bool visible, double x = 0, double y = 0) {
|
||||||
point.Location = new Coordinates(x, y);
|
point?.Location = new Coordinates(x, y);
|
||||||
point.IsVisible = visible;
|
point?.IsVisible = visible;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void EnableActionButtons() {
|
private void EnableActionButtons() {
|
||||||
@@ -416,7 +421,7 @@ namespace Elwig.Windows {
|
|||||||
var res = Validator.CheckDecimal(PriceInput, true, 2, Season.Precision);
|
var res = Validator.CheckDecimal(PriceInput, true, 2, Season.Precision);
|
||||||
if (res.IsValid && double.TryParse(PriceInput.Text, out double price)) {
|
if (res.IsValid && double.TryParse(PriceInput.Text, out double price)) {
|
||||||
ActiveGraph.SetPriceAt(PrimaryMarkedPoint, price);
|
ActiveGraph.SetPriceAt(PrimaryMarkedPoint, price);
|
||||||
PrimaryMarkedPointPlot.Location = new Coordinates(PrimaryMarkedPointPlot.Location.X, price);
|
PrimaryMarkedPointPlot?.Location = new Coordinates(PrimaryMarkedPointPlot.Location.X, price);
|
||||||
SetHasChanged();
|
SetHasChanged();
|
||||||
OechslePricePlot.Refresh();
|
OechslePricePlot.Refresh();
|
||||||
CheckGebundenTypeFixed();
|
CheckGebundenTypeFixed();
|
||||||
@@ -492,17 +497,19 @@ namespace Elwig.Windows {
|
|||||||
|
|
||||||
ChangeMarker(PrimaryMarkedPointPlot, true, ActiveGraph.GetOechsleAt(PrimaryMarkedPoint), ActiveGraph.GetPriceAt(PrimaryMarkedPoint));
|
ChangeMarker(PrimaryMarkedPointPlot, true, ActiveGraph.GetOechsleAt(PrimaryMarkedPoint), ActiveGraph.GetPriceAt(PrimaryMarkedPoint));
|
||||||
|
|
||||||
Updating = true;
|
if (Highlighted.Graph != null) {
|
||||||
OechsleInput.Text = Highlighted.Graph!.GetOechsleAt(Highlighted.Index).ToString();
|
Updating = true;
|
||||||
GebInput.IsChecked = Highlighted.Graph == SelectedGraphEntry?.GebundenGraph;
|
OechsleInput.Text = Highlighted.Graph.GetOechsleAt(Highlighted.Index).ToString();
|
||||||
PriceInput.Text = Math.Round(Highlighted.Graph.GetPriceAt(Highlighted.Index), Season.Precision).ToString();
|
GebInput.IsChecked = Highlighted.Graph == SelectedGraphEntry?.GebundenGraph;
|
||||||
Updating = false;
|
PriceInput.Text = Math.Round(Highlighted.Graph.GetPriceAt(Highlighted.Index), Season.Precision).ToString();
|
||||||
|
Updating = false;
|
||||||
|
}
|
||||||
|
|
||||||
EnableActionButtons();
|
EnableActionButtons();
|
||||||
} else {
|
} else {
|
||||||
PrimaryMarkedPoint = -1;
|
PrimaryMarkedPoint = -1;
|
||||||
SecondaryMarkedPoint = -1;
|
SecondaryMarkedPoint = -1;
|
||||||
if (SelectedGraphEntry!.GebundenGraph != null) {
|
if (SelectedGraphEntry?.GebundenGraph != null) {
|
||||||
ChangeActiveGraph(null);
|
ChangeActiveGraph(null);
|
||||||
}
|
}
|
||||||
ChangeMarker(PrimaryMarkedPointPlot, false);
|
ChangeMarker(PrimaryMarkedPointPlot, false);
|
||||||
@@ -548,21 +555,26 @@ namespace Elwig.Windows {
|
|||||||
|
|
||||||
if (mouseOnData != null) {
|
if (mouseOnData != null) {
|
||||||
ChangeMarker(HighlightedPointPlot, true, mouseOnData.Value.X, mouseOnData.Value.Y);
|
ChangeMarker(HighlightedPointPlot, true, mouseOnData.Value.X, mouseOnData.Value.Y);
|
||||||
HighlightedPointPlot.IsVisible = true;
|
HighlightedPointPlot?.IsVisible = true;
|
||||||
HoverChanged = true ^ HoverActive;
|
HoverChanged = true ^ HoverActive;
|
||||||
HoverActive = true;
|
HoverActive = true;
|
||||||
HandleTooltip(mouseOnData.Value.X, mouseOnData.Value.Y, mouseOnData.Value.Index, SelectedGraphEntry!.DataGraph, e.GetPosition(OechslePricePlot), e is MouseWheelEventArgs);
|
if (SelectedGraphEntry?.DataGraph is Graph g)
|
||||||
|
HandleTooltip(mouseOnData.Value.X, mouseOnData.Value.Y, mouseOnData.Value.Index, g, e.GetPosition(OechslePricePlot), e is MouseWheelEventArgs);
|
||||||
} else if (mouseOnGebunden != null) {
|
} else if (mouseOnGebunden != null) {
|
||||||
ChangeMarker(HighlightedPointPlot, true, mouseOnGebunden.Value.X, mouseOnGebunden.Value.Y);
|
ChangeMarker(HighlightedPointPlot, true, mouseOnGebunden.Value.X, mouseOnGebunden.Value.Y);
|
||||||
HighlightedPointPlot.IsVisible = true;
|
HighlightedPointPlot?.IsVisible = true;
|
||||||
HoverChanged = true ^ HoverActive;
|
HoverChanged = true ^ HoverActive;
|
||||||
HoverActive = true;
|
HoverActive = true;
|
||||||
HandleTooltip(mouseOnGebunden.Value.X, mouseOnGebunden.Value.Y, mouseOnGebunden.Value.Index, SelectedGraphEntry!.GebundenGraph!, e.GetPosition(OechslePricePlot), e is MouseWheelEventArgs);
|
if (SelectedGraphEntry?.GebundenGraph is Graph g)
|
||||||
|
HandleTooltip(mouseOnGebunden.Value.X, mouseOnGebunden.Value.Y, mouseOnGebunden.Value.Index, g, e.GetPosition(OechslePricePlot), e is MouseWheelEventArgs);
|
||||||
} else {
|
} else {
|
||||||
ChangeMarker(HighlightedPointPlot, false);
|
ChangeMarker(HighlightedPointPlot, false);
|
||||||
HoverChanged = false ^ HoverActive;
|
HoverChanged = false ^ HoverActive;
|
||||||
HoverActive = false;
|
HoverActive = false;
|
||||||
OechslePricePlot.Plot.PlottableList.Remove(TooltipPlot);
|
if (TooltipPlot != null) {
|
||||||
|
OechslePricePlot.Plot.PlottableList.Remove(TooltipPlot);
|
||||||
|
TooltipPlot = null;
|
||||||
|
}
|
||||||
OechslePricePlot.Refresh();
|
OechslePricePlot.Refresh();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -577,7 +589,10 @@ namespace Elwig.Windows {
|
|||||||
|
|
||||||
private void HandleTooltip(double pointX, double pointY, int pointIndex, Graph g, Point p, bool force) {
|
private void HandleTooltip(double pointX, double pointY, int pointIndex, Graph g, Point p, bool force) {
|
||||||
if (force || LastHighlighted != Highlighted || HoverChanged) {
|
if (force || LastHighlighted != Highlighted || HoverChanged) {
|
||||||
OechslePricePlot.Plot.PlottableList.Remove(TooltipPlot);
|
if (TooltipPlot != null) {
|
||||||
|
OechslePricePlot.Plot.PlottableList.Remove(TooltipPlot);
|
||||||
|
TooltipPlot = null;
|
||||||
|
}
|
||||||
if (TooltipInput.IsChecked == true) {
|
if (TooltipInput.IsChecked == true) {
|
||||||
Coordinates mouseLocation = GetMouseCoordinates(new(p.X, p.Y - 30));
|
Coordinates mouseLocation = GetMouseCoordinates(new(p.X, p.Y - 30));
|
||||||
TooltipPlot = OechslePricePlot.Plot.Add.Text($"Oechsle: {pointX:N2}, Preis: {Math.Round(pointY, Season.Precision)} {CurrencySymbol}/kg", mouseLocation.X, mouseLocation.Y);
|
TooltipPlot = OechslePricePlot.Plot.Add.Text($"Oechsle: {pointX:N2}, Preis: {Math.Round(pointY, Season.Precision)} {CurrencySymbol}/kg", mouseLocation.X, mouseLocation.Y);
|
||||||
@@ -676,7 +691,7 @@ namespace Elwig.Windows {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DisableTextBox(TextBox u) {
|
private static void DisableTextBox(TextBox u) {
|
||||||
u.IsEnabled = false;
|
u.IsEnabled = false;
|
||||||
u.IsReadOnly = true;
|
u.IsReadOnly = true;
|
||||||
}
|
}
|
||||||
@@ -707,10 +722,8 @@ namespace Elwig.Windows {
|
|||||||
ActiveGraph = g;
|
ActiveGraph = g;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ChangeLineWidth(Scatter? p, double lineWidth) {
|
private static void ChangeLineWidth(Scatter? p, double lineWidth) {
|
||||||
if (p != null) {
|
p?.LineWidth = (float)lineWidth;
|
||||||
p.LineWidth = (float)lineWidth;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void GraphList_SelectionChanged(object sender, SelectionChangedEventArgs e) {
|
private void GraphList_SelectionChanged(object sender, SelectionChangedEventArgs e) {
|
||||||
@@ -752,7 +765,7 @@ namespace Elwig.Windows {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SelectedGraphEntry!.Vaributes = VaributeInput.SelectedItems.Cast<Varibute>().ToList();
|
SelectedGraphEntry?.Vaributes = [.. VaributeInput.SelectedItems.Cast<Varibute>()];
|
||||||
SetHasChanged();
|
SetHasChanged();
|
||||||
GraphList.Items.Refresh();
|
GraphList.Items.Refresh();
|
||||||
VaributeInput.Items.Refresh();
|
VaributeInput.Items.Refresh();
|
||||||
|
|||||||
Reference in New Issue
Block a user