3using System.Collections.Generic;
14 private readonly LinkedList<KeyValuePair<string, long>> counts =
new LinkedList<KeyValuePair<string, long>>();
15 private readonly Dictionary<string, string> bgColors =
new Dictionary<string, string>();
16 private readonly Dictionary<string, string> fgColors =
new Dictionary<string, string>();
17 private long maxCount = 1;
18 private int count = 0;
32 public void Add(
string Id,
long Count)
34 this.counts.AddLast(
new KeyValuePair<string, long>(Id, Count));
37 if (Count > this.maxCount)
38 this.maxCount = Count;
48 this.fgColors[Id] = Color;
58 this.bgColors[Id] = Color;
72 Output.WriteLine(
" | Count |");
73 Output.WriteLine(
"|:---------|------:|");
75 foreach (KeyValuePair<string, long> P
in this.counts)
80 Output.Write(P.Value.ToString());
81 Output.WriteLine(
" |");
88 Output.WriteLine(
"]");
102 Output.Write(
"```layout: ");
103 Output.WriteLine(Title);
104 Output.WriteLine(
"<Layout2D xmlns=\"http://waher.se/Schema/Layout2D.xsd\"");
105 Output.WriteLine(
" background=\"WhiteBackground\" pen=\"BlackPen\"");
106 Output.WriteLine(
" font=\"Text\" textColor=\"Black\">");
107 Output.WriteLine(
" <SolidPen id=\"BlackPen\" color=\"Black\" width=\"1px\"/>");
108 Output.WriteLine(
" <SolidBackground id=\"WhiteBackground\" color=\"WhiteSmoke\"/>");
110 foreach (KeyValuePair<string, long> P
in this.counts)
112 SKColor Color = Palette[i++];
114 Output.Write(
" <SolidBackground id=\"");
116 Output.Write(
"Bg\" color=\"");
118 if (this.bgColors.TryGetValue(P.Key, out
string s))
123 Output.WriteLine(
"\"/>");
126 Output.WriteLine(
" <Font id=\"Text\" name=\"Arial\" size=\"12pt\" color=\"Black\"/>");
128 foreach (KeyValuePair<string, string> P
in this.fgColors)
130 Output.Write(
" <Font id=\"");
132 Output.Write(
"Fg\" name=\"Arial\" size=\"12pt\" color=\"");
133 Output.Write(P.Value);
134 Output.WriteLine(
"\"/>");
137 Output.WriteLine(
" <Grid columns=\"2\">");
139 long HalfMaxCount = this.maxCount / 2;
141 foreach (KeyValuePair<string, long> P
in this.counts)
143 Output.WriteLine(
" <Cell>");
144 Output.WriteLine(
" <Margins left=\"0.5em\" right=\"0.5em\">");
145 Output.Write(
" <Label text=\"");
147 Output.WriteLine(
"\" x=\"100%\" y=\"50%\" halign=\"Right\" valign=\"Center\" font=\"Text\"/>");
148 Output.WriteLine(
" </Margins>");
149 Output.WriteLine(
" </Cell>");
150 Output.WriteLine(
" <Cell>");
151 Output.WriteLine(
" <Margins left=\"1mm\" top=\"1mm\" bottom=\"1mm\" right=\"1mm\">");
152 Output.Write(
" <RoundedRectangle radiusX=\"3mm\" radiusY=\"3mm\" width=\"");
153 Output.Write(
CommonTypes.
Encode(((P.Value * 10000 + HalfMaxCount) /
this.maxCount)*0.01));
154 Output.Write(
"%\" height=\"1cm\" fill=\"");
157 Output.WriteLine(
"\">");
158 Output.WriteLine(
" <Margins left=\"0.5em\" right=\"0.5em\">");
159 Output.Write(
" <Label text=\"");
160 Output.Write(P.Value.ToString());
161 Output.Write(
"\" x=\"50%\" y=\"50%\" halign=\"Center\" valign=\"Center\"");
163 if (this.fgColors.ContainsKey(P.Key))
165 Output.Write(
" font=\"");
167 Output.Write(
"Fg\"");
170 Output.WriteLine(
"/>");
171 Output.WriteLine(
" </Margins>");
172 Output.WriteLine(
" </RoundedRectangle>");
173 Output.WriteLine(
" </Margins>");
174 Output.WriteLine(
" </Cell>");
177 Output.WriteLine(
" </Grid>");
178 Output.WriteLine(
"</Layout2D>");
179 Output.WriteLine(
"```");
Root node of a simulation model
static SKColor[] CreatePalette(int N)
Creates a palette for graphs.
static string ToString(SKColor Color)
Gets the string representation of a color.
Represents a simple count table
void ExportTableGraph(StreamWriter Output, string Title)
Exports data as a graph embedded in markdown
void ExportTableMarkdown(StreamWriter Output, string Header, string Title, string Id)
Exports data as a Markdown Table
void Add(string Id, long Count)
Adds a record to the table.
void SetFgColor(string Id, string Color)
Sets the foreground color for a record.
CountTable()
Represents a simple count table
void SetBgColor(string Id, string Color)
Sets the background color for a record.
Helps with parsing of commong data types.
static string Encode(bool x)
Encodes a Boolean for use in XML and other formats.