2023-06-20 12:26:48 +00:00
|
|
|
using System.Diagnostics.CodeAnalysis;
|
|
|
|
using InnovEnergy.Lib.Units;
|
|
|
|
using InnovEnergy.Lib.Utils;
|
|
|
|
|
|
|
|
|
|
|
|
namespace InnovEnergy.App.SaliMax;
|
|
|
|
|
|
|
|
public static class Flow
|
|
|
|
{
|
2023-08-25 15:17:41 +00:00
|
|
|
private static readonly String RightArrowChar = ">";
|
|
|
|
private static readonly String LeftArrowChar = "<";
|
|
|
|
private static readonly String DownArrowChar = "V";
|
|
|
|
private static readonly String UpArrowChar = "^";
|
|
|
|
private static readonly String UnknownArrowChar = "?";
|
2023-06-20 12:26:48 +00:00
|
|
|
|
2023-08-25 15:17:41 +00:00
|
|
|
public static TextBlock Horizontal(Unit? amount) => Horizontal(amount, 10);
|
2023-08-16 13:15:45 +00:00
|
|
|
|
2023-08-25 15:17:41 +00:00
|
|
|
public static TextBlock Horizontal(Unit? amount, Int32 width)
|
2023-06-20 12:26:48 +00:00
|
|
|
{
|
2023-08-25 15:17:41 +00:00
|
|
|
var label = amount?.ToDisplayString() ?? "";
|
|
|
|
|
|
|
|
var arrowChar = amount switch
|
|
|
|
{
|
|
|
|
{ Value: < 0 } => LeftArrowChar,
|
|
|
|
{ Value: >= 0 } => RightArrowChar,
|
|
|
|
_ => UnknownArrowChar,
|
|
|
|
};
|
|
|
|
|
|
|
|
//var arrowChar = amount.Value < 0 ? LeftArrowChar : RightArrowChar;
|
2023-06-20 12:26:48 +00:00
|
|
|
var arrow = Enumerable.Repeat(arrowChar, width).Join();
|
|
|
|
|
|
|
|
// note : appending "fake label" below to make it vertically symmetric
|
2023-07-03 13:47:34 +00:00
|
|
|
return TextBlock.AlignCenterHorizontal(label, arrow, "");
|
2023-06-20 12:26:48 +00:00
|
|
|
}
|
2023-08-16 13:15:45 +00:00
|
|
|
|
2023-08-25 15:17:41 +00:00
|
|
|
public static TextBlock Vertical(Unit? amount) => Vertical(amount, 4);
|
2023-08-16 13:15:45 +00:00
|
|
|
|
2023-06-20 12:26:48 +00:00
|
|
|
[SuppressMessage("ReSharper", "PossibleMultipleEnumeration")]
|
|
|
|
[SuppressMessage("ReSharper", "CoVariantArrayConversion")]
|
2023-08-25 15:17:41 +00:00
|
|
|
public static TextBlock Vertical(Unit? amount, Int32 height)
|
2023-06-20 12:26:48 +00:00
|
|
|
{
|
2023-08-25 15:17:41 +00:00
|
|
|
var label = amount?.ToDisplayString() ?? UnknownArrowChar;
|
|
|
|
var arrowChar = amount switch
|
|
|
|
{
|
|
|
|
{ Value: < 0 } => UpArrowChar,
|
|
|
|
{ Value: >= 0 } => DownArrowChar,
|
|
|
|
_ => UnknownArrowChar,
|
|
|
|
};
|
2023-06-20 12:26:48 +00:00
|
|
|
|
2023-08-25 15:17:41 +00:00
|
|
|
// var arrowChar = amount is null ? UnknownArrowChar
|
|
|
|
// : amount.Value < 0 ? UpArrowChar
|
|
|
|
// : DownArrowChar;
|
2023-06-20 12:26:48 +00:00
|
|
|
|
2023-08-25 15:17:41 +00:00
|
|
|
return TextBlock.AlignCenterHorizontal(arrowChar, arrowChar, label, arrowChar, arrowChar);
|
2023-06-20 12:26:48 +00:00
|
|
|
}
|
|
|
|
}
|