ChartWindow: Upgrade to Scottplot 5
This commit is contained in:
@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
@ -12,27 +11,34 @@ using Elwig.Helpers.Billing;
|
||||
using Elwig.Models.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.ChangeTracking;
|
||||
using ScottPlot.Plottables;
|
||||
using ScottPlot;
|
||||
using ScottPlot.Plottable;
|
||||
using Xceed.Wpf.Toolkit.Primitives;
|
||||
using ScottPlot.Control;
|
||||
|
||||
namespace Elwig.Windows {
|
||||
public partial class ChartWindow : ContextWindow {
|
||||
|
||||
public static readonly Color ColorUngebunden = Color.Blue;
|
||||
public static readonly Color ColorGebunden = Color.Gold;
|
||||
public static readonly Color ColorUngebunden = Colors.Blue;
|
||||
public static readonly Color ColorGebunden = Colors.Gold;
|
||||
|
||||
public readonly int Year;
|
||||
public readonly int AvNr;
|
||||
public Season Season;
|
||||
private PaymentVar PaymentVar;
|
||||
private bool HasChanged = false;
|
||||
|
||||
private ScatterPlot DataPlot;
|
||||
private ScatterPlot? GebundenPlot;
|
||||
private MarkerPlot HighlightedPointPlot;
|
||||
private MarkerPlot PrimaryMarkedPointPlot;
|
||||
private MarkerPlot SecondaryMarkedPointPlot;
|
||||
private Tooltip TooltipPlot;
|
||||
private Scatter DataPlot;
|
||||
private Scatter? GebundenPlot;
|
||||
private Marker HighlightedPointPlot;
|
||||
private Marker PrimaryMarkedPointPlot;
|
||||
private Marker SecondaryMarkedPointPlot;
|
||||
private Text TooltipPlot;
|
||||
private LegendItem UngebundenLegend;
|
||||
private LegendItem GebundenLegend;
|
||||
private LegendItem LDWLegend;
|
||||
private LegendItem QUWLegend;
|
||||
private LegendItem KABLegend;
|
||||
|
||||
private (Graph? graph, int index) LastHighlighted = (null, -1);
|
||||
private (Graph? graph, int index) Highlighted = (null, -1);
|
||||
@ -44,7 +50,7 @@ namespace Elwig.Windows {
|
||||
private bool FillingInputs = false;
|
||||
|
||||
private List<GraphEntry> GraphEntries = [];
|
||||
private GraphEntry? SelectedGraphEntry;
|
||||
private GraphEntry? SelectedGraphEntry => (GraphEntry)GraphList.SelectedItem;
|
||||
|
||||
public ChartWindow(int year, int avnr) {
|
||||
InitializeComponent();
|
||||
@ -53,10 +59,26 @@ namespace Elwig.Windows {
|
||||
Season = Context.Seasons.Find(year) ?? throw new ArgumentException("Season not found");
|
||||
PaymentVar = Context.PaymentVariants.Find(year, avnr) ?? throw new ArgumentException("PaymentVar not found");
|
||||
Title = $"{PaymentVar?.Name} - Lese {year} - Elwig";
|
||||
LockContext = true;
|
||||
}
|
||||
|
||||
private void Window_Loaded(object sender, RoutedEventArgs evt) {
|
||||
OechslePricePlot.IsEnabled = false;
|
||||
}
|
||||
|
||||
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) {
|
||||
if (HasChanged) {
|
||||
var r = MessageBox.Show("Soll das Fenster wirklich geschlossen werden? Nicht gespeicherte Änderungen werden NICHT übernommen!", "Schließen bestätigen",
|
||||
MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.No);
|
||||
if (r != MessageBoxResult.Yes) {
|
||||
e.Cancel = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void SetHasChanged(bool hasChanged = true) {
|
||||
HasChanged = hasChanged;
|
||||
SaveButton.IsEnabled = hasChanged;
|
||||
}
|
||||
|
||||
private async Task RefreshGraphList() {
|
||||
@ -79,7 +101,6 @@ namespace Elwig.Windows {
|
||||
ControlUtils.RenewItemsSource(ContractInput, contracts, g => (g as ContractSelection)?.Listing);
|
||||
FillingInputs = false;
|
||||
ControlUtils.RenewItemsSource(GraphList, GraphEntries, g => (g as GraphEntry)?.Id, GraphList_SelectionChanged, ControlUtils.RenewSourceDefault.First);
|
||||
SelectedGraphEntry = GraphList.SelectedItem as GraphEntry;
|
||||
|
||||
RefreshInputs();
|
||||
}
|
||||
@ -89,7 +110,6 @@ namespace Elwig.Windows {
|
||||
if (SelectedGraphEntry != null) {
|
||||
CopyButton.IsEnabled = true;
|
||||
DeleteButton.IsEnabled = true;
|
||||
//EnableUnitTextBox(OechsleInput);
|
||||
GebundenTypeFixed.IsEnabled = true;
|
||||
GebundenTypeGraph.IsEnabled = true;
|
||||
GebundenTypeNone.IsEnabled = true;
|
||||
@ -144,55 +164,98 @@ namespace Elwig.Windows {
|
||||
}
|
||||
|
||||
private void InitPlot() {
|
||||
UngebundenLegend = new LegendItem() {
|
||||
Label = "Ungebunden",
|
||||
LineWidth = 1,
|
||||
LineColor = ColorUngebunden,
|
||||
Marker = new MarkerStyle(MarkerShape.FilledCircle, 5, ColorUngebunden)
|
||||
};
|
||||
|
||||
GebundenLegend = new LegendItem() {
|
||||
Label = "Gebunden",
|
||||
LineWidth = 1,
|
||||
LineColor = ColorGebunden,
|
||||
Marker = new MarkerStyle(MarkerShape.FilledCircle, 5, ColorGebunden)
|
||||
};
|
||||
|
||||
LDWLegend = new LegendItem() {
|
||||
Label = "68 °Oe (LDW)",
|
||||
LineWidth = 2,
|
||||
LineColor = Colors.Red,
|
||||
Marker = MarkerStyle.None
|
||||
};
|
||||
|
||||
QUWLegend = new LegendItem() {
|
||||
Label = "73 °Oe (QUW)",
|
||||
LineWidth = 2,
|
||||
LineColor = Colors.Orange,
|
||||
Marker = MarkerStyle.None
|
||||
};
|
||||
|
||||
KABLegend = new LegendItem() {
|
||||
Label = "84 °Oe (KAB)",
|
||||
LineWidth = 2,
|
||||
LineColor = Colors.Green,
|
||||
Marker = MarkerStyle.None
|
||||
};
|
||||
|
||||
RefreshGradationLines();
|
||||
|
||||
if (SelectedGraphEntry?.GebundenGraph != null) {
|
||||
GebundenPlot = OechslePricePlot.Plot.AddScatter(SelectedGraphEntry.GebundenGraph.DataX, SelectedGraphEntry.GebundenGraph.DataY, label: "Gebunden");
|
||||
GebundenPlot.LineColor = ColorGebunden;
|
||||
GebundenPlot.MarkerColor = ColorGebunden;
|
||||
GebundenPlot.MarkerSize = 9;
|
||||
GebundenPlot = OechslePricePlot.Plot.Add.Scatter(SelectedGraphEntry.GebundenGraph.DataX, SelectedGraphEntry.GebundenGraph.DataY);
|
||||
GebundenPlot.LineStyle.Color = ColorGebunden;
|
||||
GebundenPlot.Color = ColorGebunden;
|
||||
GebundenPlot.MarkerStyle = new MarkerStyle(MarkerShape.FilledCircle, 9, ColorGebunden);
|
||||
}
|
||||
|
||||
DataPlot = OechslePricePlot.Plot.AddScatter(SelectedGraphEntry!.DataGraph.DataX, SelectedGraphEntry!.DataGraph.DataY, label: "Ungebunden");
|
||||
DataPlot.LineColor = ColorUngebunden;
|
||||
DataPlot.MarkerColor = ColorUngebunden;
|
||||
DataPlot.MarkerSize = 9;
|
||||
DataPlot = OechslePricePlot.Plot.Add.Scatter(SelectedGraphEntry!.DataGraph.DataX, SelectedGraphEntry!.DataGraph.DataY);
|
||||
DataPlot.LineStyle.Color = ColorUngebunden;
|
||||
DataPlot.Color = ColorUngebunden;
|
||||
DataPlot.MarkerStyle = new MarkerStyle(MarkerShape.FilledCircle, 9, ColorUngebunden);
|
||||
|
||||
if (SelectedGraphEntry?.GebundenGraph == null) {
|
||||
ChangeActiveGraph(SelectedGraphEntry?.DataGraph);
|
||||
}
|
||||
|
||||
OechslePricePlot.RightClicked -= OechslePricePlot.DefaultRightClickEvent;
|
||||
OechslePricePlot.Configuration.DoubleClickBenchmark = false;
|
||||
//OechslePricePlot.Plot.XAxis.ManualTickSpacing(1);
|
||||
OechslePricePlot.Plot.YAxis.ManualTickSpacing(0.1);
|
||||
OechslePricePlot.Plot.SetAxisLimits(Math.Min(GraphEntry.MinX, GraphEntry.MinXGeb) - 1, GraphEntry.MaxX + 1, -0.1, 2);
|
||||
|
||||
OechslePricePlot.Plot.Layout(padding: 0);
|
||||
OechslePricePlot.Plot.XAxis2.Layout(padding: 0);
|
||||
OechslePricePlot.Plot.YAxis.Layout(padding: 0);
|
||||
OechslePricePlot.Plot.YAxis2.Layout(padding: 0);
|
||||
OechslePricePlot.Interaction.Enable(new PlotActions() {
|
||||
ZoomIn = StandardActions.ZoomIn,
|
||||
ZoomOut = StandardActions.ZoomOut,
|
||||
PanUp = StandardActions.PanUp,
|
||||
PanDown = StandardActions.PanDown,
|
||||
PanLeft = StandardActions.PanLeft,
|
||||
PanRight = StandardActions.PanRight,
|
||||
DragPan = StandardActions.DragPan,
|
||||
DragZoom = StandardActions.DragZoom,
|
||||
DragZoomRectangle = StandardActions.DragZoomRectangle,
|
||||
ZoomRectangleClear = StandardActions.ZoomRectangleClear,
|
||||
ZoomRectangleApply = StandardActions.ZoomRectangleApply,
|
||||
AutoScale = StandardActions.AutoScale,
|
||||
});
|
||||
|
||||
HighlightedPointPlot = OechslePricePlot.Plot.AddPoint(0, 0);
|
||||
HighlightedPointPlot.Color = Color.Red;
|
||||
HighlightedPointPlot.MarkerSize = 10;
|
||||
HighlightedPointPlot.MarkerShape = MarkerShape.openCircle;
|
||||
//OechslePricePlot.Plot.XAxis.ManualTickSpacing(1);
|
||||
//OechslePricePlot.Plot.YAxis.ManualTickSpacing(0.1);
|
||||
OechslePricePlot.Plot.Axes.SetLimits(Math.Min(GraphEntry.MinX, GraphEntry.MinXGeb) - 1, GraphEntry.MaxX + 1, -0.1, 2);
|
||||
|
||||
//OechslePricePlot.Plot.Layout(padding: 0);
|
||||
//OechslePricePlot.Plot.XAxis2.Layout(padding: 0);
|
||||
//OechslePricePlot.Plot.YAxis.Layout(padding: 0);
|
||||
//OechslePricePlot.Plot.YAxis2.Layout(padding: 0);
|
||||
|
||||
HighlightedPointPlot = OechslePricePlot.Plot.Add.Marker(0, 0, MarkerShape.OpenCircle, 10, Colors.Red);
|
||||
HighlightedPointPlot.IsVisible = false;
|
||||
|
||||
PrimaryMarkedPointPlot = OechslePricePlot.Plot.AddPoint(0, 0);
|
||||
PrimaryMarkedPointPlot.Color = Color.Red;
|
||||
PrimaryMarkedPointPlot.MarkerSize = 6;
|
||||
PrimaryMarkedPointPlot.MarkerShape = MarkerShape.filledCircle;
|
||||
PrimaryMarkedPointPlot = OechslePricePlot.Plot.Add.Marker(0, 0, MarkerShape.FilledCircle, 6, Colors.Red);
|
||||
PrimaryMarkedPointPlot.IsVisible = false;
|
||||
|
||||
SecondaryMarkedPointPlot = OechslePricePlot.Plot.AddPoint(0, 0);
|
||||
SecondaryMarkedPointPlot.Color = Color.Red;
|
||||
SecondaryMarkedPointPlot.MarkerSize = 6;
|
||||
SecondaryMarkedPointPlot.MarkerShape = MarkerShape.filledCircle;
|
||||
SecondaryMarkedPointPlot = OechslePricePlot.Plot.Add.Marker(0, 0, MarkerShape.FilledCircle, 6, Colors.Red);
|
||||
SecondaryMarkedPointPlot.IsVisible = false;
|
||||
|
||||
|
||||
|
||||
OechslePricePlot.Refresh();
|
||||
|
||||
RefreshFreeZoom();
|
||||
RefreshGradationLines();
|
||||
OechslePricePlot.Refresh();
|
||||
}
|
||||
|
||||
private void ResetPlot() {
|
||||
@ -201,22 +264,20 @@ namespace Elwig.Windows {
|
||||
ChangeActiveGraph(null);
|
||||
HideGradationLines();
|
||||
OechslePricePlot.Plot.Remove(DataPlot);
|
||||
OechslePricePlot.Plot.Remove(GebundenPlot);
|
||||
if (GebundenPlot != null) {
|
||||
OechslePricePlot.Plot.Remove(GebundenPlot);
|
||||
GebundenPlot = null;
|
||||
}
|
||||
OechslePricePlot.Plot.Clear();
|
||||
OechslePricePlot.Reset();
|
||||
OechslePricePlot.Refresh();
|
||||
}
|
||||
|
||||
private void ChangeMarker(MarkerPlot point, bool visible, double x = 0, double y = 0) {
|
||||
point.X = x;
|
||||
point.Y = y;
|
||||
private void ChangeMarker(Marker point, bool visible, double x = 0, double y = 0) {
|
||||
point.Location = new Coordinates(x, y);
|
||||
point.IsVisible = visible;
|
||||
}
|
||||
|
||||
private void LinearIncreaseGraph(int begin, int end, double inc) {
|
||||
|
||||
}
|
||||
|
||||
private void EnableActionButtons() {
|
||||
if (PaymentVar.TestVariant) {
|
||||
LeftFlatButton.IsEnabled = true;
|
||||
@ -246,18 +307,32 @@ namespace Elwig.Windows {
|
||||
}
|
||||
|
||||
private void LockZoom() {
|
||||
OechslePricePlot.Plot.XAxis.SetBoundary(GraphEntry.MinX - 1, GraphEntry.MaxX + 1);
|
||||
OechslePricePlot.Plot.YAxis.SetBoundary(-0.1, 2);
|
||||
OechslePricePlot.Plot.XAxis.SetZoomOutLimit(GraphEntry.MaxX - GraphEntry.MinX + 2);
|
||||
OechslePricePlot.Plot.YAxis.SetZoomOutLimit(2.1);
|
||||
OechslePricePlot.Plot.SetAxisLimits(GraphEntry.MinX - 1, GraphEntry.MaxX + 1, -0.1, 2);
|
||||
ScottPlot.AxisRules.MaximumBoundary BoundaryRule = new(
|
||||
xAxis: OechslePricePlot.Plot.Axes.Bottom,
|
||||
yAxis: OechslePricePlot.Plot.Axes.Left,
|
||||
limits: new AxisLimits(GraphEntry.MinX - 1, GraphEntry.MaxX + 1, -0.1, 2));
|
||||
|
||||
ScottPlot.AxisRules.MaximumSpan SpanRule = new(
|
||||
xAxis: OechslePricePlot.Plot.Axes.Bottom,
|
||||
yAxis: OechslePricePlot.Plot.Axes.Left,
|
||||
xSpan: GraphEntry.MaxX - GraphEntry.MinX + 2,
|
||||
ySpan: 2.1);
|
||||
|
||||
OechslePricePlot.Plot.Axes.Rules.Clear();
|
||||
OechslePricePlot.Plot.Axes.Rules.Add(BoundaryRule);
|
||||
OechslePricePlot.Plot.Axes.Rules.Add(SpanRule);
|
||||
OechslePricePlot.Plot.Axes.SetLimits(GraphEntry.MinX - 1, GraphEntry.MaxX + 1, -0.1, 2);
|
||||
}
|
||||
|
||||
private void UnlockZoom() {
|
||||
OechslePricePlot.Plot.XAxis.SetBoundary();
|
||||
OechslePricePlot.Plot.YAxis.SetBoundary();
|
||||
OechslePricePlot.Plot.XAxis.SetZoomOutLimit((GraphEntry.MaxX - GraphEntry.MinX) * 1.5);
|
||||
OechslePricePlot.Plot.YAxis.SetZoomOutLimit(3.5);
|
||||
ScottPlot.AxisRules.MaximumSpan SpanRule = new(
|
||||
xAxis: OechslePricePlot.Plot.Axes.Bottom,
|
||||
yAxis: OechslePricePlot.Plot.Axes.Left,
|
||||
xSpan: (GraphEntry.MaxX - GraphEntry.MinX) * 1.5,
|
||||
ySpan: 3.5);
|
||||
|
||||
OechslePricePlot.Plot.Axes.Rules.Clear();
|
||||
OechslePricePlot.Plot.Axes.Rules.Add(SpanRule);
|
||||
}
|
||||
|
||||
private void EnableOptionButtons() {
|
||||
@ -277,7 +352,7 @@ namespace Elwig.Windows {
|
||||
}
|
||||
|
||||
private void RefreshGradationLines() {
|
||||
if (GradationLinesInput.IsChecked == true && SelectedGraphEntry != null && !OechslePricePlot.Plot.GetPlottables().OfType<VLine>().Any()) {
|
||||
if (GradationLinesInput.IsChecked == true && SelectedGraphEntry != null && !OechslePricePlot.Plot.PlottableList.OfType<VerticalLine>().Any()) {
|
||||
ShowGradationLines();
|
||||
ShowLegend();
|
||||
} else if (GradationLinesInput.IsChecked == false) {
|
||||
@ -288,21 +363,29 @@ namespace Elwig.Windows {
|
||||
}
|
||||
|
||||
private void ShowGradationLines() {
|
||||
OechslePricePlot.Plot.AddVerticalLine(68, Color.Red, 2, label: "68 °Oe (LDW)");
|
||||
OechslePricePlot.Plot.AddVerticalLine(73, Color.Orange, 2, label: "73 °Oe (QUW)");
|
||||
OechslePricePlot.Plot.AddVerticalLine(84, Color.Green, 2, label: "84 °Oe (KAB)");
|
||||
OechslePricePlot.Plot.Add.VerticalLine(68, 2, Colors.Red);
|
||||
OechslePricePlot.Plot.Add.VerticalLine(73, 2, Colors.Orange);
|
||||
OechslePricePlot.Plot.Add.VerticalLine(84, 2, Colors.Green);
|
||||
}
|
||||
|
||||
private void HideGradationLines() {
|
||||
OechslePricePlot.Plot.Clear(typeof(VLine));
|
||||
OechslePricePlot.Plot.PlottableList.RemoveAll(p => p is VerticalLine);
|
||||
}
|
||||
|
||||
private void ShowLegend() {
|
||||
OechslePricePlot.Plot.Legend(true, Alignment.UpperLeft);
|
||||
OechslePricePlot.Plot.Legend.Location = Alignment.UpperLeft;
|
||||
OechslePricePlot.Plot.Legend.IsVisible = true;
|
||||
|
||||
OechslePricePlot.Plot.Legend.ManualItems.Add(LDWLegend);
|
||||
OechslePricePlot.Plot.Legend.ManualItems.Add(QUWLegend);
|
||||
OechslePricePlot.Plot.Legend.ManualItems.Add(KABLegend);
|
||||
OechslePricePlot.Plot.Legend.ManualItems.Add(UngebundenLegend);
|
||||
if (SelectedGraphEntry?.GebundenGraph != null) OechslePricePlot.Plot.Legend.ManualItems.Add(GebundenLegend);
|
||||
}
|
||||
|
||||
private void HideLegend() {
|
||||
OechslePricePlot.Plot.Legend(false, Alignment.UpperLeft);
|
||||
OechslePricePlot.Plot.Legend.IsVisible = false;
|
||||
OechslePricePlot.Plot.Legend.ManualItems.Clear();
|
||||
}
|
||||
|
||||
private void OechsleInput_TextChanged(object sender, TextChangedEventArgs evt) {
|
||||
@ -323,19 +406,18 @@ namespace Elwig.Windows {
|
||||
PriceInput.Text = ActiveGraph.GetPriceAt(PrimaryMarkedPoint).ToString();
|
||||
|
||||
EnableActionButtons();
|
||||
OechslePricePlot.Render();
|
||||
OechslePricePlot.Refresh();
|
||||
EnableUnitTextBox(PriceInput);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
PrimaryMarkedPoint = -1;
|
||||
//ChangeActiveGraph(null);
|
||||
ChangeMarker(PrimaryMarkedPointPlot, false);
|
||||
DisableActionButtons();
|
||||
PriceInput.Text = "";
|
||||
DisableUnitTextBox(PriceInput);
|
||||
OechslePricePlot.Render();
|
||||
OechslePricePlot.Refresh();
|
||||
DisableUnitTextBox(PriceInput);
|
||||
}
|
||||
|
||||
@ -343,7 +425,8 @@ namespace Elwig.Windows {
|
||||
if (PrimaryMarkedPoint != -1 && ActiveGraph != null) {
|
||||
if (double.TryParse(PriceInput.Text, out double price)) {
|
||||
ActiveGraph.SetPriceAt(PrimaryMarkedPoint, price);
|
||||
PrimaryMarkedPointPlot.Y = price;
|
||||
PrimaryMarkedPointPlot.Location = new Coordinates(PrimaryMarkedPointPlot.Location.X, price);
|
||||
SetHasChanged();
|
||||
OechslePricePlot.Refresh();
|
||||
CheckGebundenTypeFixed();
|
||||
}
|
||||
@ -355,7 +438,8 @@ namespace Elwig.Windows {
|
||||
return;
|
||||
}
|
||||
ActiveGraph.FlattenGraphLeft(PrimaryMarkedPoint);
|
||||
OechslePricePlot.Render();
|
||||
SetHasChanged();
|
||||
OechslePricePlot.Refresh();
|
||||
CheckGebundenTypeFixed();
|
||||
}
|
||||
|
||||
@ -364,7 +448,8 @@ namespace Elwig.Windows {
|
||||
return;
|
||||
}
|
||||
ActiveGraph.FlattenGraphRight(PrimaryMarkedPoint);
|
||||
OechslePricePlot.Render();
|
||||
SetHasChanged();
|
||||
OechslePricePlot.Refresh();
|
||||
CheckGebundenTypeFixed();
|
||||
}
|
||||
|
||||
@ -373,7 +458,8 @@ namespace Elwig.Windows {
|
||||
return;
|
||||
}
|
||||
ActiveGraph.InterpolateGraph(PrimaryMarkedPoint, SecondaryMarkedPoint);
|
||||
OechslePricePlot.Render();
|
||||
SetHasChanged();
|
||||
OechslePricePlot.Refresh();
|
||||
CheckGebundenTypeFixed();
|
||||
}
|
||||
|
||||
@ -386,7 +472,8 @@ namespace Elwig.Windows {
|
||||
return;
|
||||
}
|
||||
ActiveGraph.LinearIncreaseGraphToEnd(PrimaryMarkedPoint, priceIncrease.Value);
|
||||
OechslePricePlot.Render();
|
||||
SetHasChanged();
|
||||
OechslePricePlot.Refresh();
|
||||
CheckGebundenTypeFixed();
|
||||
}
|
||||
|
||||
@ -396,7 +483,7 @@ namespace Elwig.Windows {
|
||||
}
|
||||
|
||||
if (HoverActive) {
|
||||
if (PaymentVar.TestVariant && Keyboard.IsKeyDown(Key.LeftCtrl)) {
|
||||
if (PaymentVar.TestVariant && Keyboard.IsKeyDown(System.Windows.Input.Key.LeftCtrl)) {
|
||||
if (PrimaryMarkedPoint == -1 || ActiveGraph == null || ActiveGraph != Highlighted.graph) {
|
||||
return;
|
||||
}
|
||||
@ -410,7 +497,7 @@ namespace Elwig.Windows {
|
||||
}
|
||||
|
||||
PrimaryMarkedPoint = Highlighted.index;
|
||||
ChangeActiveGraph(Highlighted.graph);
|
||||
if (ActiveGraph != Highlighted.graph) ChangeActiveGraph(Highlighted.graph);
|
||||
|
||||
ChangeMarker(PrimaryMarkedPointPlot, true, ActiveGraph.GetOechsleAt(PrimaryMarkedPoint), ActiveGraph.GetPriceAt(PrimaryMarkedPoint));
|
||||
|
||||
@ -435,32 +522,21 @@ namespace Elwig.Windows {
|
||||
}
|
||||
}
|
||||
|
||||
private (double, double, int)? MouseOnPlot(ScatterPlot? plot) {
|
||||
if (plot == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
(double mouseCoordX, double mouseCoordY) = OechslePricePlot.GetMouseCoordinates();
|
||||
(double mousePixelX, double mousePixelY) = OechslePricePlot.GetMousePixel();
|
||||
double xyRatio = OechslePricePlot.Plot.XAxis.Dims.PxPerUnit / OechslePricePlot.Plot.YAxis.Dims.PxPerUnit;
|
||||
|
||||
(double pointX, double pointY, int pointIndex) = plot.GetPointNearest(mouseCoordX, mouseCoordY, xyRatio);
|
||||
(double pointPixelX, double pointPixelY) = OechslePricePlot.Plot.GetPixel(pointX, pointY);
|
||||
|
||||
if (Math.Abs(mousePixelX - pointPixelX) < 3 && Math.Abs(mousePixelY - pointPixelY) < 3) {
|
||||
return (pointX, pointY, pointIndex);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
private void OechslePricePlot_MouseMove(object sender, MouseEventArgs e) {
|
||||
MouseChange(e);
|
||||
}
|
||||
|
||||
private void OechslePricePlot_MouseMove(object sender, MouseEventArgs e) {
|
||||
private void OechslePricePlot_MouseWheel(object sender, MouseWheelEventArgs e) {
|
||||
MouseChange(e);
|
||||
}
|
||||
|
||||
private void MouseChange(MouseEventArgs e) {
|
||||
if (GraphList.SelectedItem == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
(double x, double y, int index)? mouseOnData = MouseOnPlot(DataPlot);
|
||||
(double x, double y , int index)? mouseOnGebunden = MouseOnPlot(GebundenPlot);
|
||||
(double x, double y, int index)? mouseOnData = MouseOnPlot(DataPlot, e.GetPosition(OechslePricePlot));
|
||||
(double x, double y, int index)? mouseOnGebunden = MouseOnPlot(GebundenPlot, e.GetPosition(OechslePricePlot));
|
||||
|
||||
Highlighted = LastHighlighted;
|
||||
|
||||
@ -469,31 +545,57 @@ namespace Elwig.Windows {
|
||||
HighlightedPointPlot.IsVisible = true;
|
||||
HoverChanged = true ^ HoverActive;
|
||||
HoverActive = true;
|
||||
HandleTooltip(mouseOnData.Value.x, mouseOnData.Value.y, mouseOnData.Value.index, SelectedGraphEntry!.DataGraph);
|
||||
HandleTooltip(mouseOnData.Value.x, mouseOnData.Value.y, mouseOnData.Value.index, SelectedGraphEntry!.DataGraph, e.GetPosition(OechslePricePlot), e is MouseWheelEventArgs);
|
||||
} else if (mouseOnGebunden != null) {
|
||||
ChangeMarker(HighlightedPointPlot, true, mouseOnGebunden.Value.x, mouseOnGebunden.Value.y);
|
||||
HighlightedPointPlot.IsVisible = true;
|
||||
HoverChanged = true ^ HoverActive;
|
||||
HoverActive = true;
|
||||
HandleTooltip(mouseOnGebunden.Value.x, mouseOnGebunden.Value.y, mouseOnGebunden.Value.index, SelectedGraphEntry!.GebundenGraph!);
|
||||
HandleTooltip(mouseOnGebunden.Value.x, mouseOnGebunden.Value.y, mouseOnGebunden.Value.index, SelectedGraphEntry!.GebundenGraph!, e.GetPosition(OechslePricePlot), e is MouseWheelEventArgs);
|
||||
} else {
|
||||
ChangeMarker(HighlightedPointPlot, false);
|
||||
HoverChanged = false ^ HoverActive;
|
||||
HoverActive = false;
|
||||
OechslePricePlot.Plot.Remove(TooltipPlot);
|
||||
OechslePricePlot.Render();
|
||||
OechslePricePlot.Plot.PlottableList.Remove(TooltipPlot);
|
||||
OechslePricePlot.Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleTooltip(double pointX, double pointY, int pointIndex, Graph g) {
|
||||
if (LastHighlighted != Highlighted || HoverChanged) {
|
||||
OechslePricePlot.Plot.Remove(TooltipPlot);
|
||||
private (double, double, int)? MouseOnPlot(Scatter? plot, Point p) {
|
||||
if (plot == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
OechslePricePlot.Refresh();
|
||||
Pixel mousePixel = new(p.X, p.Y);
|
||||
Coordinates mouseLocation = OechslePricePlot.Plot.GetCoordinates(mousePixel);
|
||||
DataPoint nearestPoint = plot.Data.GetNearest(mouseLocation, OechslePricePlot.Plot.LastRender, 3);
|
||||
|
||||
if (nearestPoint.IsReal) {
|
||||
return (nearestPoint.X, nearestPoint.Y, nearestPoint.Index);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleTooltip(double pointX, double pointY, int pointIndex, Graph g, Point p, bool force) {
|
||||
if (force || LastHighlighted != Highlighted || HoverChanged) {
|
||||
OechslePricePlot.Plot.PlottableList.Remove(TooltipPlot);
|
||||
if (TooltipInput.IsChecked == true) {
|
||||
TooltipPlot = OechslePricePlot.Plot.AddTooltip($"Oechsle: {pointX:N2}, Preis: {Math.Round(pointY, Season.Precision)}€/kg)", pointX, pointY);
|
||||
Pixel mousePixel = new(p.X, p.Y - 30);
|
||||
Coordinates mouseLocation = OechslePricePlot.Plot.GetCoordinates(mousePixel);
|
||||
TooltipPlot = OechslePricePlot.Plot.Add.Text($"Oechsle: {pointX:N2}, Preis: {Math.Round(pointY, Season.Precision)}€/kg", mouseLocation.X, mouseLocation.Y);
|
||||
TooltipPlot.Label.FontSize = 12;
|
||||
TooltipPlot.Label.Bold = true;
|
||||
TooltipPlot.Label.BorderColor = Colors.Black;
|
||||
TooltipPlot.Label.BorderWidth = 2;
|
||||
TooltipPlot.Label.BackColor = Colors.White;
|
||||
TooltipPlot.Label.Padding = 10;
|
||||
TooltipPlot.Label.Alignment = Alignment.MiddleLeft;
|
||||
}
|
||||
LastHighlighted = (g, pointIndex);
|
||||
HoverChanged = false;
|
||||
OechslePricePlot.Render();
|
||||
OechslePricePlot.Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
@ -504,6 +606,7 @@ namespace Elwig.Windows {
|
||||
private void AddButton_Click(object sender, RoutedEventArgs e) {
|
||||
GraphEntry newGraphEntry = new(GetMaxGraphId() + 1, Season.Precision, BillingData.CurveMode.Oe);
|
||||
GraphEntries.Add(newGraphEntry);
|
||||
SetHasChanged();
|
||||
GraphList.Items.Refresh();
|
||||
GraphList.SelectedItem = newGraphEntry;
|
||||
}
|
||||
@ -513,6 +616,7 @@ namespace Elwig.Windows {
|
||||
|
||||
GraphEntry newGraphEntry = SelectedGraphEntry.Copy(GetMaxGraphId() + 1);
|
||||
GraphEntries.Add(newGraphEntry);
|
||||
SetHasChanged();
|
||||
GraphList.Items.Refresh();
|
||||
GraphList.SelectedItem = newGraphEntry;
|
||||
}
|
||||
@ -521,12 +625,14 @@ namespace Elwig.Windows {
|
||||
if (SelectedGraphEntry == null) return;
|
||||
|
||||
var r = MessageBox.Show(
|
||||
$"Soll der Graph {SelectedGraphEntry.Id} (verwendet in folgenden Verträgen: {SelectedGraphEntry.Contracts}) wirklich gelöscht werden?",
|
||||
$"Soll der Graph {SelectedGraphEntry.Id} (verwendet in folgenden Verträgen: {SelectedGraphEntry.ContractsStringSimple}) wirklich gelöscht werden?",
|
||||
"Graph löschen", MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.No);
|
||||
|
||||
if (r == MessageBoxResult.Yes) {
|
||||
GraphEntries.Remove(SelectedGraphEntry);
|
||||
SetHasChanged();
|
||||
GraphList.Items.Refresh();
|
||||
OechslePricePlot.IsEnabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -548,6 +654,7 @@ namespace Elwig.Windows {
|
||||
MessageBox.Show(str, "Auszahlungsvariante speichern", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
LockContext = true;
|
||||
SetHasChanged(false);
|
||||
}
|
||||
|
||||
private void EnableUnitTextBox(UnitTextBox u) {
|
||||
@ -565,7 +672,7 @@ namespace Elwig.Windows {
|
||||
private void ChangeActiveGraph(Graph? g) {
|
||||
if (g != null && g == SelectedGraphEntry?.DataGraph) {
|
||||
EnableUnitTextBox(OechsleInput);
|
||||
ChangeLineWidth(DataPlot, 4);
|
||||
if (SelectedGraphEntry?.GebundenGraph != null) ChangeLineWidth(DataPlot, 4);
|
||||
ChangeLineWidth(GebundenPlot, 1);
|
||||
} else if (g != null && g == SelectedGraphEntry?.GebundenGraph) {
|
||||
EnableUnitTextBox(OechsleInput);
|
||||
@ -582,14 +689,13 @@ namespace Elwig.Windows {
|
||||
ActiveGraph = g;
|
||||
}
|
||||
|
||||
private void ChangeLineWidth(ScatterPlot? p, double lineWidth) {
|
||||
private void ChangeLineWidth(Scatter? p, double lineWidth) {
|
||||
if (p != null) {
|
||||
p.LineWidth = lineWidth;
|
||||
p.LineWidth = (float)lineWidth;
|
||||
}
|
||||
}
|
||||
|
||||
private void GraphList_SelectionChanged(object sender, SelectionChangedEventArgs e) {
|
||||
SelectedGraphEntry = GraphList.SelectedItem as GraphEntry;
|
||||
RefreshInputs();
|
||||
}
|
||||
|
||||
@ -631,8 +737,10 @@ namespace Elwig.Windows {
|
||||
}
|
||||
|
||||
private void AbgewertetInput_Changed(object sender, RoutedEventArgs e) {
|
||||
if (FillingInputs) return;
|
||||
if (SelectedGraphEntry == null) return;
|
||||
SelectedGraphEntry.Abgewertet = AbgewertetInput.IsChecked == true;
|
||||
SetHasChanged();
|
||||
}
|
||||
|
||||
private void GebundenType_Checked(object sender, RoutedEventArgs e) {
|
||||
@ -652,6 +760,7 @@ namespace Elwig.Windows {
|
||||
SelectedGraphEntry.AddGebundenGraph();
|
||||
DisableUnitTextBox(GebundenFlatBonus);
|
||||
}
|
||||
SetHasChanged();
|
||||
RefreshInputs();
|
||||
}
|
||||
|
||||
@ -661,8 +770,9 @@ namespace Elwig.Windows {
|
||||
GebundenTypeFixed.IsChecked = true;
|
||||
GebundenFlatBonus.Text = $"{bonus}";
|
||||
EnableUnitTextBox(GebundenFlatBonus);
|
||||
} else {
|
||||
} else if (SelectedGraphEntry?.GebundenGraph != null) {
|
||||
GebundenTypeGraph.IsChecked = true;
|
||||
GebundenFlatBonus.Text = "";
|
||||
DisableUnitTextBox(GebundenFlatBonus);
|
||||
}
|
||||
FillingInputs = false;
|
||||
|
Reference in New Issue
Block a user