mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-06-19 21:38:16 +08:00
Add support custom max value for barcharts (#545)
This commit is contained in:
@ -43,6 +43,12 @@ namespace Spectre.Console
|
||||
/// <remarks>Defaults to invariant culture.</remarks>
|
||||
public CultureInfo? Culture { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the fixed max value for a bar chart.
|
||||
/// </summary>
|
||||
/// <remarks>Defaults to null, which corresponds to largest value in chart.</remarks>
|
||||
public double? MaxValue { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="BarChart"/> class.
|
||||
/// </summary>
|
||||
@ -62,7 +68,7 @@ namespace Spectre.Console
|
||||
protected override IEnumerable<Segment> Render(RenderContext context, int maxWidth)
|
||||
{
|
||||
var width = Math.Min(Width ?? maxWidth, maxWidth);
|
||||
var maxValue = Data.Max(item => item.Value);
|
||||
var maxValue = Math.Max(MaxValue ?? 0d, Data.Max(item => item.Value));
|
||||
|
||||
var grid = new Grid();
|
||||
grid.Collapse();
|
||||
@ -96,4 +102,4 @@ namespace Spectre.Console
|
||||
return ((IRenderable)grid).Render(context, width);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user