-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChartGenerator.cs
More file actions
265 lines (230 loc) · 9.58 KB
/
Copy pathChartGenerator.cs
File metadata and controls
265 lines (230 loc) · 9.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ManufacturingKnowledgeGraph
{
public class ChartGenerator
{
/// <summary>
/// Creates a horizontal bar chart
/// </summary>
public static void DrawBarChart(string title, Dictionary<string, int> data, int maxBarLength = 40)
{
Console.WriteLine($"\n{title}");
Console.WriteLine(new string('═', 70));
if (!data.Any())
{
Console.WriteLine(" No data available");
return;
}
var maxValue = data.Values.Max();
var sortedData = data.OrderByDescending(x => x.Value).Take(10);
foreach (var item in sortedData)
{
var barLength = maxValue > 0 ? (int)((double)item.Value / maxValue * maxBarLength) : 0;
var bar = new string('█', barLength);
var label = item.Key.Length > 20 ? item.Key.Substring(0, 17) + "..." : item.Key;
Console.Write($" {label,-20} ");
Console.ForegroundColor = GetColorForValue(item.Value, maxValue);
Console.Write(bar);
Console.ResetColor();
Console.WriteLine($" {item.Value}");
}
}
/// <summary>
/// Creates a pie chart representation
/// </summary>
public static void DrawPieChart(string title, Dictionary<string, int> data)
{
Console.WriteLine($"\n{title}");
Console.WriteLine(new string('═', 70));
if (!data.Any())
{
Console.WriteLine(" No data available");
return;
}
var total = data.Values.Sum();
Console.WriteLine(" ┌────────────────────────────────────────┐");
Console.WriteLine(" │ │");
foreach (var item in data.OrderByDescending(x => x.Value))
{
var percentage = (double)item.Value / total * 100;
var barLength = (int)(percentage / 100 * 30);
var bar = new string('█', barLength);
Console.Write($" │ {item.Key,-12} ");
Console.ForegroundColor = GetColorForCategory(item.Key);
Console.Write($"{bar,-30}");
Console.ResetColor();
Console.WriteLine($" {percentage:F1}% │");
}
Console.WriteLine(" │ │");
Console.WriteLine(" └────────────────────────────────────────┘");
Console.WriteLine($" Total: {total}");
}
/// <summary>
/// Creates a heatmap table
/// </summary>
public static void DrawHeatmap(string title, string[] rowLabels, string[] colLabels, int[,] data)
{
Console.WriteLine($"\n{title}");
Console.WriteLine(new string('═', 70));
// Header
Console.Write(" Product".PadRight(20));
foreach (var col in colLabels)
{
Console.Write($"{col,8}");
}
Console.WriteLine(" Total");
Console.WriteLine(" " + new string('─', 60));
// Rows
for (int i = 0; i < rowLabels.Length; i++)
{
var label = rowLabels[i].Length > 18 ? rowLabels[i].Substring(0, 15) + "..." : rowLabels[i];
Console.Write($" {label,-18} ");
int rowTotal = 0;
for (int j = 0; j < colLabels.Length; j++)
{
var value = data[i, j];
rowTotal += value;
if (value == 0)
{
Console.Write($"{"·",8}");
}
else
{
Console.ForegroundColor = GetHeatmapColor(value);
Console.Write($"{value,8}");
Console.ResetColor();
}
}
Console.WriteLine($"{rowTotal,8}");
}
}
/// <summary>
/// Draws a network diagram showing relationships
/// </summary>
public static void DrawNetworkDiagram(string title, List<(string from, string to, string relation)> connections)
{
Console.WriteLine($"\n{title}");
Console.WriteLine(new string('═', 70));
if (!connections.Any())
{
Console.WriteLine(" No connections to display");
return;
}
// Group by relation type
var grouped = connections.GroupBy(c => c.relation).Take(3);
foreach (var group in grouped)
{
Console.WriteLine($"\n {group.Key}:");
Console.WriteLine(" " + new string('─', 60));
foreach (var conn in group.Take(5))
{
Console.WriteLine($" [{conn.from}]");
Console.WriteLine($" │");
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine($" ├──{conn.relation}──>");
Console.ResetColor();
Console.WriteLine($" │");
Console.WriteLine($" └──> [{conn.to}]");
Console.WriteLine();
}
}
}
/// <summary>
/// Creates a dashboard view with multiple metrics
/// </summary>
public static void DrawDashboard(
string title,
Dictionary<string, string> keyMetrics,
List<string> insights)
{
Console.Clear();
// Title
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine("╔" + new string('═', 68) + "╗");
Console.WriteLine($"║{title.PadLeft(34 + title.Length / 2).PadRight(68)}║");
Console.WriteLine("╚" + new string('═', 68) + "╝");
Console.ResetColor();
Console.WriteLine();
// Key Metrics
Console.WriteLine("📊 KEY METRICS");
Console.WriteLine(new string('─', 70));
var metricsList = keyMetrics.ToList();
for (int i = 0; i < metricsList.Count; i += 2)
{
var metric1 = metricsList[i];
Console.ForegroundColor = ConsoleColor.Yellow;
Console.Write($" ▪ {metric1.Key}: ");
Console.ResetColor();
Console.Write($"{metric1.Value,-25}");
if (i + 1 < metricsList.Count)
{
var metric2 = metricsList[i + 1];
Console.ForegroundColor = ConsoleColor.Yellow;
Console.Write($"▪ {metric2.Key}: ");
Console.ResetColor();
Console.WriteLine(metric2.Value);
}
else
{
Console.WriteLine();
}
}
// Insights
if (insights.Any())
{
Console.WriteLine($"\n💡 TOP INSIGHTS");
Console.WriteLine(new string('─', 70));
foreach (var insight in insights.Take(5))
{
Console.ForegroundColor = ConsoleColor.Green;
Console.Write(" ✓ ");
Console.ResetColor();
Console.WriteLine(insight);
}
}
Console.WriteLine();
}
private static ConsoleColor GetColorForValue(int value, int maxValue)
{
var percentage = (double)value / maxValue;
if (percentage > 0.7) return ConsoleColor.Red;
if (percentage > 0.4) return ConsoleColor.Yellow;
return ConsoleColor.Green;
}
private static ConsoleColor GetColorForCategory(string category)
{
return category.ToLower() switch
{
var c when c.Contains("high") => ConsoleColor.Red,
var c when c.Contains("medium") => ConsoleColor.Yellow,
var c when c.Contains("low") => ConsoleColor.Green,
_ => ConsoleColor.Cyan
};
}
private static ConsoleColor GetHeatmapColor(int value)
{
if (value >= 10) return ConsoleColor.Red;
if (value >= 5) return ConsoleColor.Yellow;
return ConsoleColor.Green;
}
/// <summary>
/// Draw a simple progress bar
/// </summary>
public static void DrawProgressBar(string label, int current, int total, int width = 40)
{
var percentage = (double)current / total;
var filled = (int)(percentage * width);
var bar = new string('█', filled) + new string('░', width - filled);
Console.Write($"\r {label}: [");
Console.ForegroundColor = ConsoleColor.Cyan;
Console.Write(bar);
Console.ResetColor();
Console.Write($"] {percentage:P0} ({current}/{total})");
if (current >= total)
Console.WriteLine();
}
}
}