ChartWindow/Billing: Misc improvements
This commit is contained in:
@ -1,3 +1,4 @@
|
||||
using Elwig.Models.Entities;
|
||||
using ScottPlot;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -7,20 +8,32 @@ using System.Text.Json.Nodes;
|
||||
namespace Elwig.Helpers.Billing {
|
||||
public class Graph : ICloneable {
|
||||
|
||||
private readonly Season Season;
|
||||
public double[] DataX { get; set; }
|
||||
public double[] DataY { get; set; }
|
||||
public int MinX { get; set; }
|
||||
public int MaxX { get; set; }
|
||||
|
||||
public Graph(int minX, int maxX) {
|
||||
public Graph(Season season, int minX, int maxX) {
|
||||
Season = season;
|
||||
MinX = minX;
|
||||
MaxX = maxX;
|
||||
DataX = DataGen.Range(minX, maxX + 1);
|
||||
DataY = DataGen.Zeros(maxX - minX + 1);
|
||||
}
|
||||
|
||||
public Graph(Dictionary<double, decimal> data, int minX, int maxX) {
|
||||
public Graph(Dictionary<double, decimal> data, Season season, int minX, int maxX) {
|
||||
Season = season;
|
||||
MinX = minX;
|
||||
MaxX = maxX;
|
||||
DataX = DataGen.Range(minX, maxX + 1);
|
||||
DataY = DataX.Select(i => (double)BillingData.GetCurveValueAt(data, i)).ToArray();
|
||||
}
|
||||
|
||||
public Graph(double[] dataX, double[] dataY) {
|
||||
private Graph(double[] dataX, double[] dataY, Season season, int minX, int maxX) {
|
||||
Season = season;
|
||||
MinX = minX;
|
||||
MaxX = maxX;
|
||||
DataX = dataX;
|
||||
DataY = dataY;
|
||||
}
|
||||
@ -57,7 +70,7 @@ namespace Elwig.Helpers.Billing {
|
||||
|
||||
private void LinearIncreaseGraph(int begin, int end, double inc) {
|
||||
for (int i = begin; i < end; i++) {
|
||||
DataY[i + 1] = Math.Round(DataY[i] + inc, 4); //TODO richtig runden
|
||||
DataY[i + 1] = Math.Round(DataY[i] + inc, Season.Precision);
|
||||
}
|
||||
}
|
||||
|
||||
@ -74,7 +87,7 @@ namespace Elwig.Helpers.Billing {
|
||||
double step = (DataY[highIndex] - DataY[lowIndex]) / steps;
|
||||
|
||||
for (int i = lowIndex; i < highIndex - 1; i++) {
|
||||
DataY[i + 1] = Math.Round(DataY[i] + step, 4); // TODO richtig runden
|
||||
DataY[i + 1] = Math.Round(DataY[i] + step, Season.Precision);
|
||||
}
|
||||
}
|
||||
|
||||
@ -86,21 +99,21 @@ namespace Elwig.Helpers.Billing {
|
||||
var data = new JsonObject();
|
||||
|
||||
if (DataY[0] != DataY[1]) {
|
||||
data.Add(new KeyValuePair<string, JsonNode?>(DataX[0] + mode, Math.Round(DataY[0], 4)));
|
||||
data.Add(new KeyValuePair<string, JsonNode?>(DataX[0] + mode, Math.Round(DataY[0], Season.Precision)));
|
||||
}
|
||||
for (int i = 1; i < DataX.Length - 1; i++) {
|
||||
if (Math.Round(DataY[i] - DataY[i - 1], 10) != Math.Round(DataY[i + 1] - DataY[i], 10)) {
|
||||
data.Add(new KeyValuePair<string, JsonNode?>(DataX[i] + mode, Math.Round(DataY[i], 4)));
|
||||
data.Add(new KeyValuePair<string, JsonNode?>(DataX[i] + mode, Math.Round(DataY[i], Season.Precision)));
|
||||
}
|
||||
}
|
||||
if (DataY[^1] != DataY[^2]) {
|
||||
data.Add(new KeyValuePair<string, JsonNode?>(DataX[^1] + mode, Math.Round(DataY[^1], 4)));
|
||||
data.Add(new KeyValuePair<string, JsonNode?>(DataX[^1] + mode, Math.Round(DataY[^1], Season.Precision)));
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
public object Clone() {
|
||||
return new Graph((double[])DataX.Clone(), (double[])DataY.Clone());
|
||||
return new Graph((double[])DataX.Clone(), (double[])DataY.Clone(), Season, MinX, MaxX);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user