first commit -push

This commit is contained in:
dungtt
2025-10-15 15:15:53 +07:00
parent 674ae395be
commit a9577c5756
885 changed files with 74595 additions and 0 deletions

View File

@@ -0,0 +1,149 @@
using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
namespace RobotNet.WebApp.Charts.Core;
public abstract class BlazorComponentBase : ComponentBase, IDisposable, IAsyncDisposable
{
private bool isAsyncDisposed;
private bool isDisposed;
/// <inheritdoc />
protected override async Task OnAfterRenderAsync(bool firstRender)
{
IsRenderComplete = true;
await base.OnAfterRenderAsync(firstRender);
}
/// <inheritdoc />
protected override void OnInitialized()
{
Id ??= Guid.NewGuid().ToString();
base.OnInitialized();
}
public static string BuildClassNames(params (string? cssClass, bool when)[] cssClassList)
{
var list = new HashSet<string>();
if (cssClassList is not null && cssClassList.Length != 0)
foreach (var (cssClass, when) in cssClassList)
{
if (!string.IsNullOrWhiteSpace(cssClass) && when)
list.Add(cssClass);
}
if (list.Count != 0)
return string.Join(" ", list);
else
return string.Empty;
}
public static string BuildClassNames(string? userDefinedCssClass, params (string? cssClass, bool when)[] cssClassList)
{
var list = new HashSet<string>();
if (cssClassList is not null && cssClassList.Length != 0)
foreach (var (cssClass, when) in cssClassList)
{
if (!string.IsNullOrWhiteSpace(cssClass) && when)
list.Add(cssClass);
}
if (!string.IsNullOrWhiteSpace(userDefinedCssClass))
list.Add(userDefinedCssClass.Trim());
if (list.Count != 0)
return string.Join(" ", list);
else
return string.Empty;
}
public static string BuildStyleNames(string? userDefinedCssStyle, params (string? cssStyle, bool when)[] cssStyleList)
{
var list = new HashSet<string>();
if (cssStyleList is not null && cssStyleList.Length != 0)
foreach (var (cssStyle, when) in cssStyleList)
{
if (!string.IsNullOrWhiteSpace(cssStyle) && when)
list.Add(cssStyle);
}
if (!string.IsNullOrWhiteSpace(userDefinedCssStyle))
list.Add(userDefinedCssStyle.Trim());
if (list.Count != 0)
return string.Join(';', list);
else
return string.Empty;
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
public async ValueTask DisposeAsync()
{
await DisposeAsyncCore(true).ConfigureAwait(false);
Dispose(false);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if (!isDisposed)
{
if (disposing)
{
// cleanup
}
isDisposed = true;
}
}
protected virtual ValueTask DisposeAsyncCore(bool disposing)
{
if (!isAsyncDisposed)
{
if (disposing)
{
// cleanup
}
isAsyncDisposed = true;
}
return ValueTask.CompletedTask;
}
[Parameter(CaptureUnmatchedValues = true)] public Dictionary<string, object> AdditionalAttributes { get; set; } = default!;
[Parameter] public string? Class { get; set; }
protected virtual string? ClassNames => Class;
public ElementReference Element { get; set; }
[Parameter] public string? Id { get; set; }
protected bool IsRenderComplete { get; private set; }
[Inject] protected IJSRuntime JSRuntime { get; set; } = default!;
[Parameter] public string? Style { get; set; }
protected virtual string? StyleNames => Style;
~BlazorComponentBase()
{
Dispose(false);
}
}

View File

@@ -0,0 +1,22 @@
namespace RobotNet.WebApp.Charts.Core;
public static class ChartColors
{
public static readonly System.Drawing.Color RedRGB = System.Drawing.Color.FromArgb(255, 0, 0);
public static readonly System.Drawing.Color YellowRGB = System.Drawing.Color.FromArgb(230, 162, 60);
public static readonly System.Drawing.Color GreenRGB = System.Drawing.Color.FromArgb(0, 204, 0);
public static readonly System.Drawing.Color OrangeRGB = System.Drawing.Color.FromArgb(255, 102, 0);
public static readonly System.Drawing.Color GrayRGB = System.Drawing.Color.FromArgb(147, 147, 147);
public static readonly string RedStr = "#ff0000";
public static readonly string YellowStr = "#e6a23c";
public static readonly string GreenStr = "#00cc00";
public static readonly string OrangeStr = "#ff6600";
public static readonly string GrayStr = "#939393";
public static readonly string BlueSkyStr = "#29a3ff";
public static readonly string BlueStr = "#223771";
public static readonly string Robot01Str = "#6300bd";
public static readonly string Robot02Str = "#8a2e47";
public static readonly List<string> ColorList = [Robot01Str, Robot02Str, BlueSkyStr, GrayStr, OrangeStr];
}

View File

@@ -0,0 +1,80 @@
using Microsoft.AspNetCore.Components;
using RobotNet.WebApp.Charts.Enums;
using System.Globalization;
namespace RobotNet.WebApp.Charts.Core;
public class RobotNetChart : BlazorComponentBase, IDisposable, IAsyncDisposable
{
internal ChartType chartType;
/// <inheritdoc />
public new virtual void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
/// <inheritdoc />
public new virtual async ValueTask DisposeAsync()
{
await DisposeAsyncCore(true);
Dispose(false);
GC.SuppressFinalize(this);
}
private string GetChartContainerSizeAsStyle()
{
var style = "";
if (Width > 0)
style += $"width:{Width.Value.ToString(CultureInfo.InvariantCulture)}{WidthUnit.ToCssString()};";
if (Height > 0)
style += $"height:{Height.Value.ToString(CultureInfo.InvariantCulture)}{HeightUnit.ToCssString()};";
return style;
}
internal string ContainerStyle => GetChartContainerSizeAsStyle();
/// <summary>
/// Gets or sets chart container height.
/// The default unit of measure is <see cref="Unit.Px" />.
/// To change the unit of measure see <see cref="HeightUnit" />.
/// </summary>
/// <remarks>
/// Default value is null.
/// </remarks>
[Parameter]
public int? Height { get; set; }
/// <summary>
/// Gets or sets chart container height unit of measure.
/// </summary>
/// <remarks>
/// Default value is <see cref="Unit.Px" />.
/// </remarks>
[Parameter]
public Unit HeightUnit { get; set; } = Unit.Px;
/// <summary>
/// Get or sets chart container width.
/// The default unit of measure is <see cref="Unit.Px" />.
/// To change the unit of measure see <see cref="WidthUnit" />.
/// </summary>
/// <remarks>
/// Default value is null.
/// </remarks>
[Parameter]
public int? Width { get; set; }
/// <summary>
/// Gets or sets chart container width unit of measure.
/// </summary>
/// <remarks>
/// Default value is <see cref="Unit.Px" />.
/// </remarks>
[Parameter]
public Unit WidthUnit { get; set; } = Unit.Px;
}