mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-06-19 21:38:16 +08:00
(#684) Enable setting the color of the values in a BreakdownChart
This commit is contained in:
@ -297,4 +297,21 @@ public static class BreakdownChartExtensions
|
||||
chart.Compact = compact;
|
||||
return chart;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the <see cref="BreakdownChart.ValueColor"/>.
|
||||
/// </summary>
|
||||
/// <param name="chart">The breakdown chart.</param>
|
||||
/// <param name="color">The <see cref="Color"/> to set.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static BreakdownChart WithValueColor(this BreakdownChart chart, Color color)
|
||||
{
|
||||
if (chart is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(chart));
|
||||
}
|
||||
|
||||
chart.ValueColor = color;
|
||||
return chart;
|
||||
}
|
||||
}
|
@ -30,6 +30,11 @@ public sealed class BreakdownChart : Renderable, IHasCulture, IExpandable
|
||||
/// </summary>
|
||||
public Func<double, CultureInfo, string>? ValueFormatter { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Color in which the values will be shown.
|
||||
/// </summary>
|
||||
public Color ValueColor { get; set; } = Color.Grey;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether or not the
|
||||
/// chart and tags should be rendered in compact mode.
|
||||
@ -94,6 +99,7 @@ public sealed class BreakdownChart : Renderable, IHasCulture, IExpandable
|
||||
Culture = Culture,
|
||||
ShowTagValues = ShowTagValues,
|
||||
ValueFormatter = ValueFormatter,
|
||||
ValueColor = ValueColor,
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,7 @@ internal sealed class BreakdownTags : Renderable
|
||||
public CultureInfo? Culture { get; set; }
|
||||
public bool ShowTagValues { get; set; } = true;
|
||||
public Func<double, CultureInfo, string>? ValueFormatter { get; set; }
|
||||
public Color ValueColor { get; set; } = Color.Grey;
|
||||
|
||||
public BreakdownTags(List<IBreakdownChartItem> data)
|
||||
{
|
||||
@ -55,8 +56,9 @@ internal sealed class BreakdownTags : Renderable
|
||||
|
||||
if (ShowTagValues)
|
||||
{
|
||||
return string.Format(culture, "{0} [grey]{1}[/]",
|
||||
return string.Format(culture, "{0} [{1}]{2}[/]",
|
||||
item.Label.EscapeMarkup(),
|
||||
ValueColor.ToMarkup(),
|
||||
formatter(item.Value, culture));
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user