mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-06-19 13:28:16 +08:00

committed by
Patrik Svensson

parent
b64e016e8c
commit
705cf745ea
@ -20,12 +20,6 @@ namespace Spectre.Console
|
||||
/// </summary>
|
||||
public int? Width { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether or not
|
||||
/// to show values as percentages or not.
|
||||
/// </summary>
|
||||
public bool ShowAsPercentages { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether or not to show tags.
|
||||
/// </summary>
|
||||
@ -36,6 +30,11 @@ namespace Spectre.Console
|
||||
/// </summary>
|
||||
public bool ShowTagValues { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the tag value format.
|
||||
/// </summary>
|
||||
public string? TagValueFormat { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether or not the
|
||||
/// chart and tags should be rendered in compact mode.
|
||||
@ -91,8 +90,8 @@ namespace Spectre.Console
|
||||
{
|
||||
Width = width,
|
||||
Culture = Culture,
|
||||
ShowPercentages = ShowAsPercentages,
|
||||
ShowTagValues = ShowTagValues,
|
||||
TagValueFormat = TagValueFormat,
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -11,8 +11,8 @@ namespace Spectre.Console
|
||||
|
||||
public int? Width { get; set; }
|
||||
public CultureInfo? Culture { get; set; }
|
||||
public bool ShowPercentages { get; set; }
|
||||
public bool ShowTagValues { get; set; } = true;
|
||||
public string? TagValueFormat { get; set; }
|
||||
|
||||
public BreakdownTags(List<IBreakdownChartItem> data)
|
||||
{
|
||||
@ -56,11 +56,13 @@ namespace Spectre.Console
|
||||
|
||||
private string FormatValue(IBreakdownChartItem item, CultureInfo culture)
|
||||
{
|
||||
var formatter = TagValueFormat ?? "{0}";
|
||||
|
||||
if (ShowTagValues)
|
||||
{
|
||||
return string.Format(culture, "{0} [grey]{1}{2}[/]",
|
||||
item.Label.EscapeMarkup(), item.Value,
|
||||
ShowPercentages ? "%" : string.Empty);
|
||||
return string.Format(culture, "{0} [grey]{1}[/]",
|
||||
item.Label.EscapeMarkup(),
|
||||
string.Format(culture, formatter, item.Value));
|
||||
}
|
||||
|
||||
return item.Label.EscapeMarkup();
|
||||
|
Reference in New Issue
Block a user