private ILegendItem CreateCategoryThemeLegendItem <T>(ILegendSettings settings, CategoryTheme <T> ct) where T : IComparable <T> { var res = new LegendItem { Label = " (" + ct.ColumnName + ")", LabelFont = settings.ItemFont, LabelBrush = settings.ForeColor, Indentation = settings.SymbolSize.Width }; var defaultItem = Factory[ct.Default.Style].Create(settings, ct.Default.Style); defaultItem.Label = "(" + ct.Default.Title + ")"; defaultItem.LabelBrush = settings.ForeColor; defaultItem.LabelFont = settings.ItemFont; defaultItem.Parent = res; res.SubItems.Add(defaultItem); foreach (var element in ct.ItemsAsReadOnly()) { var style = element.Style; var item = Factory[style].Create(settings, style); item.Label = element.Title; item.LabelFont = settings.ItemFont; item.LabelBrush = settings.ForeColor; item.Parent = res; item.Item = style; res.SubItems.Add(item); } return(res); }
public void TestCategoryThemeWithValues() { // Arrange var ct = new CategoryTheme <string>(); ct.ColumnName = "Value"; ct.Default = VectorStyle.CreateRandomStyle(); // Add unordered ct.Add(new CategoryThemeValuesItem <string> { Values = new List <string> { "A", "B" }, Style = VectorStyle.CreateRandomStyle() }); ct.Add(new CategoryThemeValuesItem <string> { Values = new List <string> { "C", "D" }, Style = VectorStyle.CreateRandomStyle() }); ct.Add(new CategoryThemeValuesItem <string> { Values = new List <string> { "E", "F" }, Style = VectorStyle.CreateRandomStyle() }); ct.Add(new CategoryThemeValuesItem <string> { Values = new List <string> { "G", "H" }, Style = VectorStyle.CreateRandomStyle() }); // act & assert Assert.That(ct, Is.Not.Null); Assert.That(ct.ItemsAsReadOnly(), Is.Not.Null); Assert.That(ct.ItemsAsReadOnly().Count, Is.EqualTo(4)); var fdt = CreateTable("test", ct.ColumnName, typeof(string), "A", "B", "C", "D", "E", "F", "G", "H", "I"); DoTest(ct, fdt); }
private static void DoTest <T>(CategoryTheme <T> ct, FeatureDataTable fdt) where T : IComparable <T> { var ctis = ct.ItemsAsReadOnly(); Assert.That(ctis, Is.Not.Null); var i = 0; foreach (FeatureDataRow dataRow in fdt.Rows) { i++; IStyle style = null; Assert.DoesNotThrow(() => style = ct.GetStyle(dataRow)); if (dataRow.IsNull(ct.ColumnName)) { if (ct.UseDefaultStyleForDbNull) { Assert.That(style, Is.SameAs(ct.Default)); } else { Assert.That(style, Is.Null); } } else { var cti = ctis.FirstOrDefault(t => t.Matches((T)Convert.ChangeType(dataRow[1], typeof(T)))); if (cti != null) { Assert.That(style, Is.SameAs(cti.Style)); } else { Assert.That(style, Is.SameAs(ct.Default)); } } } }