mirror of
				https://github.com/nsnail/spectre.console.git
				synced 2025-11-04 10:35:27 +08:00 
			
		
		
		
	Add breakdown chart support
This also cleans up the bar chart code slightly and fixes some minor bugs that were detected in related code. Closes #244
This commit is contained in:
		
				
					committed by
					
						
						Patrik Svensson
					
				
			
			
				
	
			
			
			
						parent
						
							58400fe74e
						
					
				
				
					commit
					b64e016e8c
				
			@@ -1,21 +1,42 @@
 | 
			
		||||
using Spectre.Console;
 | 
			
		||||
using Spectre.Console.Rendering;
 | 
			
		||||
 | 
			
		||||
namespace InfoExample
 | 
			
		||||
namespace Charts
 | 
			
		||||
{
 | 
			
		||||
    public static class Program
 | 
			
		||||
    {
 | 
			
		||||
        public static void Main()
 | 
			
		||||
        {
 | 
			
		||||
            var chart = new BarChart()
 | 
			
		||||
            // Render a bar chart
 | 
			
		||||
            AnsiConsole.WriteLine();
 | 
			
		||||
            Render("Fruits per month", new BarChart()
 | 
			
		||||
                .Width(60)
 | 
			
		||||
                .Label("[green bold underline]Number of fruits[/]")
 | 
			
		||||
                .CenterLabel()
 | 
			
		||||
                .AddItem("Apple", 12, Color.Yellow)
 | 
			
		||||
                .AddItem("Orange", 54, Color.Green)
 | 
			
		||||
                .AddItem("Banana", 33, Color.Red);
 | 
			
		||||
                .AddItem("Banana", 33, Color.Red));
 | 
			
		||||
 | 
			
		||||
            // Render a breakdown chart
 | 
			
		||||
            AnsiConsole.WriteLine();
 | 
			
		||||
            AnsiConsole.Render(chart);
 | 
			
		||||
            Render("Languages", new BreakdownChart()
 | 
			
		||||
                .FullSize()
 | 
			
		||||
                .Width(60)
 | 
			
		||||
                .ShowAsPercentages()
 | 
			
		||||
                .AddItem("SCSS", 37, Color.Red)
 | 
			
		||||
                .AddItem("HTML", 28.3, Color.Blue)
 | 
			
		||||
                .AddItem("C#", 22.6, Color.Green)
 | 
			
		||||
                .AddItem("JavaScript", 6, Color.Yellow)
 | 
			
		||||
                .AddItem("Ruby", 6, Color.LightGreen)
 | 
			
		||||
                .AddItem("Shell", 0.1, Color.Aqua));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private static void Render(string title, IRenderable chart)
 | 
			
		||||
        {
 | 
			
		||||
            AnsiConsole.Render(
 | 
			
		||||
                new Panel(chart)
 | 
			
		||||
                    .Padding(1, 1)
 | 
			
		||||
                    .Header(title));
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user