private void refreshAgeBar(SvgConfig config, SvgDocument svg, ResponseValue responseVar, bool vertical) { AgeBar ageBarConfig = config.SchemeAgeBars.First(p => p.id == responseVar.Id); int i = 0; while (i < 1000) { string id = responseVar.Id + "#" + i; if (svg.GetElementById(id) is SvgRectangle) { var element = (SvgRectangle)svg.GetElementById(id); string defaultAgeBarId = responseVar.Id + "initial"; SvgRectangle defaultAgeBar; if (svg.GetElementById(defaultAgeBarId) is SvgRectangle) { defaultAgeBar = element; } else { defaultAgeBar = createDefaultAgeBar(element, defaultAgeBarId); } setAgeBar(svg, responseVar, ageBarConfig, ref element, ref defaultAgeBar, vertical); break; } else { i++; } } }
public static void getAgeBar(string pathSvgCfg, string ageBarsCfgPath, List <AgeBar> ageBarList) { var lines = System.IO.File.ReadAllLines(ageBarsCfgPath).Select(line => line.Split(new char[] { '\t' }, StringSplitOptions.RemoveEmptyEntries)); List <string[]> ageBars = lines.Where(line => line.Length != 0).ToList(); foreach (string[] ageBar in ageBars) { AgeBar AB = new AgeBar(); AB.id = int.Parse(ageBar[0]); AB.table = ageBar[1]; AB.column = ageBar[2]; AB.maxAge = int.Parse(ageBar[3]); AB.firstColor = ageBar[4]; AB.firstLimit = int.Parse(ageBar[5]); AB.secondColor = ageBar[6]; AB.secLimit = int.Parse(ageBar[7]); AB.thirdColor = ageBar[8]; ageBarList.Add(AB); } XmlSerializer serializer = new XmlSerializer(typeof(List <AgeBar>)); using (TextWriter writer = new StreamWriter(pathSvgCfg, append: true)) { serializer.Serialize(writer, ageBarList); } }
public static void getAgeBar(string pathSvgCfg, string ageBarsCfgPath, List <AgeBar> ageBarList) { var lines = System.IO.File.ReadAllLines(ageBarsCfgPath).Select(line => line.Split(new char[] { '\t' }, StringSplitOptions.RemoveEmptyEntries)); List <string[]> ageBars = lines.Where(line => line.Length != 0).ToList(); foreach (string[] ageBar in ageBars) { AgeBar AB = new AgeBar(); AB.id = ageBar[0]; AB.maxAge = int.Parse(ageBar[3]); AB.firstColor = ageBar[4]; AB.firstLimit = int.Parse(ageBar[5]); AB.secondColor = ageBar[6]; AB.secLimit = int.Parse(ageBar[7]); AB.thirdColor = ageBar[8]; ageBarList.Add(AB); } }
private void setAgeBar(SvgDocument svg, ResponseValue responseValue, AgeBar ageBar, ref SvgRectangle rectangle, ref SvgRectangle defaultRectangle, bool vertical = false) { float value = float.Parse(responseValue.value.ToString()); if (vertical == false) { var widthType = defaultRectangle.Width.Type; float widthValue = (defaultRectangle.Width.Value / ageBar.maxAge) * value; SvgUnit width = new SvgUnit(widthType, widthValue); if (widthValue > ageBar.firstLimit && widthValue < ageBar.secLimit) { SvgColourServer rectangleColor = new SvgColourServer(Color.FromName(ageBar.firstColor)); rectangle.Fill = rectangleColor; } else if (widthValue > ageBar.secLimit) { SvgColourServer rectangleColor = new SvgColourServer(Color.FromName(ageBar.secondColor)); rectangle.Fill = rectangleColor; } else { SvgColourServer rectangleColor = new SvgColourServer(Color.FromName(ageBar.thirdColor)); rectangle.Fill = rectangleColor; } rectangle.Width = width; } else { var c = Color.FromName(ageBar.thirdColor); //initial height is missing in config SvgColourServer rectangleColor = new SvgColourServer(c); rectangle.Fill = rectangleColor; var heightType = defaultRectangle.Height.Type; float heightValue = (defaultRectangle.Height.Value / ageBar.maxAge) * value; SvgUnit height = new SvgUnit(heightType, heightValue); rectangle.Height = heightValue; } }