Files
2025-01-13 18:04:39 +01:00

175 lines
5.2 KiB
C#

using EgwCoreLib.Razor;
using EgwCoreLib.Razor.Data;
using EgwCoreLib.Utils;
using static EgwCoreLib.Razor.Data.chartJsData;
using static EgwCoreLib.Razor.Toggler;
namespace EgwCoreLib.BlazorTest.Pages
{
public partial class TestChart
{
#region Public Fields
public List<DoughnutStyling> colors = new List<DoughnutStyling>();
public List<double> Data = new List<double>();
public List<string> Labels = new List<string>();
#endregion Public Fields
#region Protected Fields
protected Random rnd = new Random();
#endregion Protected Fields
#region Protected Properties
protected List<string>? ChLabels { get; set; } = null;
protected List<chartJsData.chartJsDataSetXY>? currDS { get; set; } = null;
protected DtUtils.Periodo? periodo { get; set; } = new DtUtils.Periodo(DtUtils.PeriodSet.ThisTrim);
#endregion Protected Properties
#region Protected Methods
protected string[] histData(int num)
{
List<string> answ = new List<string>();
for (int i = 0; i < 50; i++)
{
answ.Add($"{(double)(rnd.Next(10, 100)) / 10 + i}");
}
return answ.ToArray();
}
protected string[] histLabel(int num)
{
List<string> answ = new List<string>();
for (int i = 0; i < 50; i++)
{
answ.Add($"LBL_{i:00}");
}
return answ.ToArray();
}
protected override async Task OnInitializedAsync()
{
CurrFilt = new Toggler.SelectGlobalToggle()
{
leftString = "Multi-linea",
rightString = "Singolo",
isActive = true,
toolTip = "Tipo di grafico"
};
currDS = null;
await Task.Delay(200);
await setupData();
}
protected override async Task OnParametersSetAsync()
{
await ReloadData();
await Task.Delay(1);
}
protected async Task ReloadData()
{
await Task.Delay(1);
}
protected async Task setPeriodo(DtUtils.Periodo newPeriodo)
{
await Task.Delay(1);
periodo = newPeriodo;
}
protected void SetTipo(SelectGlobalToggle selFilt)
{
if (selFilt != null)
{
showMulti = !selFilt.isActive;
}
}
protected double[] SimData()
{
List<double> answ = new List<double>();
double currColor = 0;
for (int i = 0; i < 10; i++)
{
currColor = (double)(rnd.Next(10, 100)) / 10;
answ.Add(currColor);
if (currColor > 7)
{
colors.Add(new DoughnutStyling("#28FF69", "#00AA00"));
}
else if (currColor > 3)
{
colors.Add(new DoughnutStyling("orange", "#99AA00"));
}
else
{
colors.Add(new DoughnutStyling("red", "#FF6969"));
}
}
return answ.ToArray();
}
#endregion Protected Methods
#region Private Fields
private bool showMulti = false;
#endregion Private Fields
#region Private Properties
private Toggler.SelectGlobalToggle CurrFilt { get; set; } = new Toggler.SelectGlobalToggle();
#endregion Private Properties
#region Private Methods
private async Task setupData()
{
currDS = null;
List<chartJsData.chartJsDataSetXY> currDemo = new List<chartJsData.chartJsDataSetXY>();
ChLabels = new List<string>();
int numMesi = 6;
for (int iMese = 1; iMese <= numMesi; iMese++)
{
ChLabels.Add($"{iMese:00}");
}
for (int iSerie = 0; iSerie < 4; iSerie++)
{
// simulo 12 mesi...
List<chartJsXY> simData = new List<chartJsXY>();
for (int iMese = 1; iMese <= numMesi; iMese++)
{
simData.Add(new chartJsXY() { x = iMese, y = iMese + rnd.Next(-4, 4) });
}
int rCol = rnd.Next(0, 155);
int gCol = rnd.Next(0, 155);
int bCol = rnd.Next(0, 100);
chartJsData.chartJsDataSetXY singleData = new chartJsData.chartJsDataSetXY()
{
label = $"Data_{iSerie:00}",
data = simData,
borderColor = $"#{10 + rCol:X2}{30 + gCol:X2}{100 + bCol:X2}",
backgroundColor = $"rgba({60 + rCol},{80 + gCol},{155 + bCol},0.3)",
lineTension = 0,
stepped = iSerie % 5 == 0,
fill = iSerie % 3 == 0 ? "start" : "false"
};
// aggiungo
currDemo.Add(singleData);
}
currDS = currDemo;
await Task.Delay(10);
}
#endregion Private Methods
}
}