Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(VisData): include Min/Max and fix OrdinalDictionary order #38

Merged
merged 1 commit into from
Mar 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 41 additions & 6 deletions src/LadybugDisplaySchema/ManualAdded/Model/VisualizationData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,26 @@ namespace LadybugDisplaySchema

public partial class VisualizationData
{
/// <summary>
/// Possible max value while removing nones values. Max will be double.NaN if no numerical value found.
/// </summary>
public double Max { get; set; } = double.NaN;

/// <summary>
/// Possible min value while removing nones values. Min will be double.NaN if no numerical value found.
/// </summary>
public double Min { get; set; } = double.NaN;

public VisualizationData(List<double> results, LegendParameters legend = default) : this()
{
this.Values = results;
this.LegendParameters = legend;
UpdateLegendWithValues();
if (HasMinMax(results, out var numBounds))
{
this.Max = numBounds.Value.max;
this.Min = numBounds.Value.min;
}
UpdateLegendWithValues(numBounds);
}


Expand All @@ -20,6 +35,13 @@ public VisualizationData(List<string> results, LegendParameters legend = default
this.LegendParameters = legend;
var isNumber = IsNumberList(results, out var nums, out var numBounds); // checks for None case
var values = new List<double>(results.Count);

if (numBounds.HasValue)
{
this.Max = numBounds.Value.max;
this.Min = numBounds.Value.min;
}

if (isNumber)
{
this.Values = nums;
Expand All @@ -29,13 +51,13 @@ public VisualizationData(List<string> results, LegendParameters legend = default
else
{

values = Enumerable.Repeat(-99.0, results.Count).ToList();
values = Enumerable.Repeat(double.NaN, results.Count).ToList();
var keyMapper = new Dictionary<double, string>();
var gps = results.Select((_, i) => new { _, i }).GroupBy(_ => _._).ToList();

// sort keys
var comparer = new StringComparer();
gps = gps.OrderByDescending(_ => _.Key, comparer).ToList();
gps = gps.OrderBy(_ => _.Key, comparer).ToList();
var steps = gps.Count;
for (int i = 0; i < steps; i++)
{
Expand Down Expand Up @@ -101,16 +123,29 @@ public static bool IsNumberList(List<string> results, out List<double> values, o

// get bounds
// values.Min() will be NaN if there is any NaN found, Max() will return the max value and ignore the NaN
var nonNaNs = values.Where(_ => !double.IsNaN(_));
numBounds = nonNaNs.Any() ? (nonNaNs.Min(), nonNaNs.Max()): (double.NaN, double.NaN);
HasMinMax(values, out numBounds);
return true;
}
else
{
return false;
}


}

private static bool HasMinMax(IEnumerable<double> values, out (double min, double max)? numBounds)
{
var nonNaNs = values.Where(_ => !double.IsNaN(_));
if (nonNaNs.Any())
{
numBounds = (nonNaNs.Min(), nonNaNs.Max());
return true;
}
else
{
numBounds = (double.NaN, double.NaN);
return false;
}
}

public void UpdateLegendWithValues((double min, double max)? numBounds = default)
Expand Down
Loading