add support for unknown/nullable flows
This commit is contained in:
parent
27a4411ebf
commit
4907654841
|
@ -7,38 +7,50 @@ namespace InnovEnergy.App.SaliMax;
|
||||||
|
|
||||||
public static class Flow
|
public static class Flow
|
||||||
{
|
{
|
||||||
private static readonly String RightArrowChar = ">";
|
private static readonly String RightArrowChar = ">";
|
||||||
private static readonly String LeftArrowChar = "<";
|
private static readonly String LeftArrowChar = "<";
|
||||||
private static readonly String DownArrowChar = "V";
|
private static readonly String DownArrowChar = "V";
|
||||||
private static readonly String UpArrowChar = "^";
|
private static readonly String UpArrowChar = "^";
|
||||||
|
private static readonly String UnknownArrowChar = "?";
|
||||||
|
|
||||||
public static TextBlock Horizontal(Unit amount) => Horizontal(amount, 10);
|
public static TextBlock Horizontal(Unit? amount) => Horizontal(amount, 10);
|
||||||
|
|
||||||
public static TextBlock Horizontal(Unit amount, Int32 width)
|
public static TextBlock Horizontal(Unit? amount, Int32 width)
|
||||||
{
|
{
|
||||||
var label = amount.ToDisplayString();
|
var label = amount?.ToDisplayString() ?? "";
|
||||||
var arrowChar = amount.Value < 0 ? LeftArrowChar : RightArrowChar;
|
|
||||||
|
var arrowChar = amount switch
|
||||||
|
{
|
||||||
|
{ Value: < 0 } => LeftArrowChar,
|
||||||
|
{ Value: >= 0 } => RightArrowChar,
|
||||||
|
_ => UnknownArrowChar,
|
||||||
|
};
|
||||||
|
|
||||||
|
//var arrowChar = amount.Value < 0 ? LeftArrowChar : RightArrowChar;
|
||||||
var arrow = Enumerable.Repeat(arrowChar, width).Join();
|
var arrow = Enumerable.Repeat(arrowChar, width).Join();
|
||||||
|
|
||||||
// note : appending "fake label" below to make it vertically symmetric
|
// note : appending "fake label" below to make it vertically symmetric
|
||||||
return TextBlock.AlignCenterHorizontal(label, arrow, "");
|
return TextBlock.AlignCenterHorizontal(label, arrow, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TextBlock Vertical(Unit amount) => Vertical(amount, 4);
|
public static TextBlock Vertical(Unit? amount) => Vertical(amount, 4);
|
||||||
|
|
||||||
[SuppressMessage("ReSharper", "PossibleMultipleEnumeration")]
|
[SuppressMessage("ReSharper", "PossibleMultipleEnumeration")]
|
||||||
[SuppressMessage("ReSharper", "CoVariantArrayConversion")]
|
[SuppressMessage("ReSharper", "CoVariantArrayConversion")]
|
||||||
public static TextBlock Vertical(Unit amount, Int32 height)
|
public static TextBlock Vertical(Unit? amount, Int32 height)
|
||||||
{
|
{
|
||||||
var label = amount.ToDisplayString();
|
var label = amount?.ToDisplayString() ?? UnknownArrowChar;
|
||||||
var arrowChar = amount.Value < 0 ? UpArrowChar : DownArrowChar;
|
var arrowChar = amount switch
|
||||||
var halfArrow = Enumerable.Repeat(arrowChar, height/2);
|
{
|
||||||
|
{ Value: < 0 } => UpArrowChar,
|
||||||
|
{ Value: >= 0 } => DownArrowChar,
|
||||||
|
_ => UnknownArrowChar,
|
||||||
|
};
|
||||||
|
|
||||||
var lines = halfArrow
|
// var arrowChar = amount is null ? UnknownArrowChar
|
||||||
.Append(label)
|
// : amount.Value < 0 ? UpArrowChar
|
||||||
.Concat(halfArrow)
|
// : DownArrowChar;
|
||||||
.ToArray(height / 2 * 2 + 1);
|
|
||||||
|
|
||||||
return TextBlock.AlignCenterHorizontal(lines);
|
return TextBlock.AlignCenterHorizontal(arrowChar, arrowChar, label, arrowChar, arrowChar);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue