Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/Console/Charts/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public static void Main()
.FullSize()
.Width(60)
.ShowPercentage()
.WithValueColor(Color.Orange1)
.AddItem("SCSS", 37, Color.Red)
.AddItem("HTML", 28.3, Color.Blue)
.AddItem("C#", 22.6, Color.Green)
Expand Down
17 changes: 17 additions & 0 deletions src/Spectre.Console/Extensions/BreakdownChartExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -297,4 +297,21 @@ public static BreakdownChart Compact(this BreakdownChart chart, bool compact)
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;
}
}
6 changes: 6 additions & 0 deletions src/Spectre.Console/Widgets/Charts/BreakdownChart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -94,6 +99,7 @@ protected override IEnumerable<Segment> Render(RenderOptions options, int maxWid
Culture = Culture,
ShowTagValues = ShowTagValues,
ValueFormatter = ValueFormatter,
ValueColor = ValueColor,
});
}

Expand Down
4 changes: 3 additions & 1 deletion src/Spectre.Console/Widgets/Charts/BreakdownTags.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -55,8 +56,9 @@ private string FormatValue(IBreakdownChartItem item, CultureInfo culture)

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));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
████████████████████████████████████████████████████████████
■ SCSS 37 ■ HTML 28.3 ■ C# 22.6 ■ JavaScript 6
■ Ruby 6 ■ Shell 0.1
15 changes: 15 additions & 0 deletions test/Spectre.Console.Tests/Unit/Widgets/BreakdownChartTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,21 @@ public async Task Should_Render_Correct_Ansi()
await Verifier.Verify(console.Output);
}

[Fact]
[Expectation("ValueColor")]
public async Task Should_Render_Correct_ValueColor()
{
// Given
var console = new TestConsole().EmitAnsiSequences();
var chart = Fixture.GetChart().Width(60).WithValueColor(Color.Red);

// When
console.Write(chart);

// Then
await Verifier.Verify(console.Output);
}

public static class Fixture
{
public static BreakdownChart GetChart()
Expand Down