-
Notifications
You must be signed in to change notification settings - Fork 41
Closed
Labels
enhancementNew feature or requestNew feature or request
Milestone
Description
Feature Description
Create component wrapper for BarChart renderable.
Problem Statement
No response
Proposed Solution
Component with this api (not implemented XML docs yet):
@namespace RazorConsole.Components
@using Spectre.Console
<barchart
data-items="@ItemsJson"
data-width="@WidthAttribute"
data-label="@Label"
data-label-style="@LabelStyleAttributes"
data-label-alignment="@LabelAlignmentAttribute"
data-max-value="@MaxValueAttribute"
data-show-values="@ShowValuesAttribute"
/>
@code{
[Parameter]
[EditorRequired]
public required List<IBarChartItem> BarChartItems { get; set; }
[Parameter]
public int? Width { get; set; }
[Parameter]
public string? Label { get; set; }
[Parameter]
public Color LabelForeground { get; set; } = Style.Plain.Foreground;
[Parameter]
public Color LabelBackground { get; set; } = Style.Plain.Background;
[Parameter]
public Decoration LabelDecoration { get; set; } = Decoration.None;
[Parameter]
public Justify? LabelAlignment { get; set; }
[Parameter]
public double? MaxValue { get; set; }
[Parameter]
public bool ShowValues { get; set; }
private string ItemsJson => System.Text.Json.JsonSerializer.Serialize(
BarChartItems.Select(item => new
{
item.Label,
item.Value,
Color = item.Color?.ToHex() ?? Color.White.ToHex()
}
).ToList<object>()
);
private string WidthAttribute => Width?.ToString() ?? string.Empty;
private string LabelStyleAttributes => new Style(LabelForeground, LabelBackground, LabelDecoration).ToMarkup();
private string LabelAlignmentAttribute => LabelAlignment?.ToString().ToLowerInvariant() ?? string.Empty;
private string MaxValueAttribute => MaxValue?.ToString() ?? string.Empty;
private string ShowValuesAttribute => ShowValues ? "true" : "false";
}Alternatives Considered
No response
Additional Context
No response
Contribution
- I'd be willing to contribute this feature
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request