Files
gpw_next/GPW.CORE.Comp/CalWeekColumn.razor.cs
T
2023-01-20 13:09:52 +01:00

196 lines
5.8 KiB
C#

using Microsoft.AspNetCore.Components;
using System.Drawing;
namespace GPW.CORE.Comp
{
public partial class CalWeekColumn
{
#region Public Enums
public enum ColType
{
/// <summary>
/// Tipo etichetta Start (SX)
/// </summary>
labelStart,
/// <summary>
/// Tipo etichetta End (DX)
/// </summary>
labelEnd,
/// <summary>
/// Colonna dati
/// </summary>
dataContainer
}
#endregion Public Enums
#region Public Properties
/// <summary>
/// Lista etichette da mostrare (richiede tipo label...)
/// </summary>
[Parameter]
public List<CalendarEvent> EventList { get; set; } = new List<CalendarEvent>();
/// <summary>
/// Modalità di disegno
/// </summary>
[Parameter]
public ColType ItemMode { get; set; } = ColType.dataContainer;
[Parameter]
public int ValMax { get; set; } = 19;
[Parameter]
public int ValMin { get; set; } = 9;
/// <summary>
/// Dimensioni viewbox
/// </summary>
[Parameter]
public Size vBox { get; set; } = new Size(1200, 3600);
#endregion Public Properties
#region Protected Methods
protected string getLabel(labelData currData)
{
return $"<text class=\"lblText\">{currData.value}</text>";
}
protected string getRect(boxData currData)
{
return $"<rect x=\"0\" y=\"0\" width=\"{currData.width}\" height=\"{currData.height}\" fill=\"rgba(120,120,120,0.5)\" rx=\"3\" ry=\"3\" />";
}
protected string getBoxTitle(boxData currData)
{
return $"<text class=\"lblBoxTitle\" x=\"2\" y=\"4\">{currData.title}</text>";
}
protected string getBoxDesc(boxData currData)
{
return $"<text class=\"lblBoxText\" x=\"2\" y=\"8\">{currData.value}</text>";
}
protected int mFO
{
get => vBox.Width * 2 / 100;
}
protected int wFO
{
get => vBox.Width * 98 / 100;
}
protected int hFO
{
get => 100;// EventList.Count > 0 ? vBox.Height / EventList.Count : vBox.Height;
}
/// <summary>
/// Converte la stringa in formato markup valido
/// </summary>
/// <param name="rawData"></param>
/// <returns></returns>
protected MarkupString getMarkup(string rawData)
{
return new MarkupString(rawData);
}
private int numEv
{
get => EventList.Count > 0 ? EventList.Count : 1;
}
/// <summary>
/// Genera una lista di etichette con corrdinate
/// </summary>
/// <returns></returns>
protected List<labelData> LabelItems()
{
int step = vBox.Height / numEv;// (ValMax - ValMin);
int offset = 0;// step / 2;
List<labelData> answ = EventList
.OrderBy(x => x.Inizio)
.Select(x => new labelData()
{
pX = vBox.Width / 10,
pY = offset + (x.Inizio.Hour - ValMin) * step,
//pY = (x.Inizio.Hour - ValMin) * vBox.Height / (ValMax - ValMin),
value = x.Title
})
.ToList();
return answ;
}
protected List<boxData> BoxItems()
{
List<boxData> answ = new List<boxData>();
int step = vBox.Height / (ValMax - ValMin);
int numEv = EventList.Count;
int evWidth = numEv > 1 ? (int)(1.2 * vBox.Width / numEv) : (int)(0.9 * vBox.Width);
int offsetX = 1;
int offsetY = 0;// step / 2;
if (numEv > 0)
{
int xStep = evWidth / EventList.Count;
int deltaX = 0;
answ = EventList
.OrderBy(x => x.Inizio)
.Select(x => new boxData()
{
pX = offsetX + xStep * (deltaX++),
pY = offsetY + (x.Inizio.Hour - ValMin) * step,
width = evWidth,
height = offsetY + (x.Fine.Hour - x.Inizio.Hour) * step,
title = x.Title,
value = x.Description,
start = x.Inizio,
end = x.Fine,
cssClass = x.CssClass
})
.ToList();
}
return answ;
}
#endregion Protected Methods
#region Protected Classes
protected class labelData
{
#region Public Properties
public int pX { get; set; } = 0;
public int pY { get; set; } = 0;
public string value { get; set; } = "";
#endregion Public Properties
}
protected class boxData
{
#region Public Properties
public int pX { get; set; } = 0;
public int pY { get; set; } = 0;
public int width { get; set; } = 0;
public int height { get; set; } = 0;
public DateTime start { get; set; } = DateTime.Today;
public DateTime end { get; set; } = DateTime.Today;
public string title { get; set; } = "";
public string value { get; set; } = "";
public string cssClass { get; set; } = "";
#endregion Public Properties
}
#endregion Protected Classes
}
}