Skip to content

Commit 3bee721

Browse files
Merge pull request #1303 from nils-a/feature/GH-684
2 parents c82d8c4 + bef21e8 commit 3bee721

File tree

6 files changed

+45
-1
lines changed

6 files changed

+45
-1
lines changed

examples/Console/Charts/Program.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public static void Main()
2323
.FullSize()
2424
.Width(60)
2525
.ShowPercentage()
26+
.WithValueColor(Color.Orange1)
2627
.AddItem("SCSS", 37, Color.Red)
2728
.AddItem("HTML", 28.3, Color.Blue)
2829
.AddItem("C#", 22.6, Color.Green)

src/Spectre.Console/Extensions/BreakdownChartExtensions.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,4 +297,21 @@ public static BreakdownChart Compact(this BreakdownChart chart, bool compact)
297297
chart.Compact = compact;
298298
return chart;
299299
}
300+
301+
/// <summary>
302+
/// Sets the <see cref="BreakdownChart.ValueColor"/>.
303+
/// </summary>
304+
/// <param name="chart">The breakdown chart.</param>
305+
/// <param name="color">The <see cref="Color"/> to set.</param>
306+
/// <returns>The same instance so that multiple calls can be chained.</returns>
307+
public static BreakdownChart WithValueColor(this BreakdownChart chart, Color color)
308+
{
309+
if (chart is null)
310+
{
311+
throw new ArgumentNullException(nameof(chart));
312+
}
313+
314+
chart.ValueColor = color;
315+
return chart;
316+
}
300317
}

src/Spectre.Console/Widgets/Charts/BreakdownChart.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ public sealed class BreakdownChart : Renderable, IHasCulture, IExpandable
3030
/// </summary>
3131
public Func<double, CultureInfo, string>? ValueFormatter { get; set; }
3232

33+
/// <summary>
34+
/// Gets or sets the Color in which the values will be shown.
35+
/// </summary>
36+
public Color ValueColor { get; set; } = Color.Grey;
37+
3338
/// <summary>
3439
/// Gets or sets a value indicating whether or not the
3540
/// chart and tags should be rendered in compact mode.
@@ -94,6 +99,7 @@ protected override IEnumerable<Segment> Render(RenderOptions options, int maxWid
9499
Culture = Culture,
95100
ShowTagValues = ShowTagValues,
96101
ValueFormatter = ValueFormatter,
102+
ValueColor = ValueColor,
97103
});
98104
}
99105

src/Spectre.Console/Widgets/Charts/BreakdownTags.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ internal sealed class BreakdownTags : Renderable
88
public CultureInfo? Culture { get; set; }
99
public bool ShowTagValues { get; set; } = true;
1010
public Func<double, CultureInfo, string>? ValueFormatter { get; set; }
11+
public Color ValueColor { get; set; } = Color.Grey;
1112

1213
public BreakdownTags(List<IBreakdownChartItem> data)
1314
{
@@ -55,8 +56,9 @@ private string FormatValue(IBreakdownChartItem item, CultureInfo culture)
5556

5657
if (ShowTagValues)
5758
{
58-
return string.Format(culture, "{0} [grey]{1}[/]",
59+
return string.Format(culture, "{0} [{1}]{2}[/]",
5960
item.Label.EscapeMarkup(),
61+
ValueColor.ToMarkup(),
6062
formatter(item.Value, culture));
6163
}
6264

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
████████████████████████████████████████████████████████████
2+
■ SCSS 37 ■ HTML 28.3 ■ C# 22.6 ■ JavaScript 6
3+
■ Ruby 6 ■ Shell 0.1

test/Spectre.Console.Tests/Unit/Widgets/BreakdownChartTests.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,21 @@ public async Task Should_Render_Correct_Ansi()
127127
await Verifier.Verify(console.Output);
128128
}
129129

130+
[Fact]
131+
[Expectation("ValueColor")]
132+
public async Task Should_Render_Correct_ValueColor()
133+
{
134+
// Given
135+
var console = new TestConsole().EmitAnsiSequences();
136+
var chart = Fixture.GetChart().Width(60).WithValueColor(Color.Red);
137+
138+
// When
139+
console.Write(chart);
140+
141+
// Then
142+
await Verifier.Verify(console.Output);
143+
}
144+
130145
public static class Fixture
131146
{
132147
public static BreakdownChart GetChart()

0 commit comments

Comments
 (0)