private List <UIElement> GetLinePaths(LineGraph lineGraph, GraphParams graphParams) { var result = new List <UIElement>(); for (int i = 0; i < lineGraph.Points.Count - 1; i++) { var lineGeometry = new LineGeometry { StartPoint = GraphMathUtilities.TransformToCanvasCoords(graphParams, lineGraph.Points.ElementAt(i).Value), EndPoint = GraphMathUtilities.TransformToCanvasCoords(graphParams, lineGraph.Points.ElementAt(i + 1).Value) }; var linePath = new Path { Stroke = new SolidColorBrush(lineGraph.Color), Fill = new SolidColorBrush(lineGraph.Color), StrokeThickness = 2, Data = lineGeometry }; if (lineGraph.LineType != LinePattern.Solid) { linePath.StrokeDashArray = GraphMappingUtilities.GetLinePattern(lineGraph.LineType); } result.Add(linePath); } return(result); }
private UIElement GetCirclePath(CircleGraph circleGraph, GraphParams graphParams) { var circleGeometry = new EllipseGeometry { Center = GraphMathUtilities.TransformToCanvasCoords(graphParams, circleGraph.Center), RadiusX = circleGraph.Radius, RadiusY = circleGraph.Radius }; var pathGeometry = PathGeometry.CreateFromGeometry(circleGeometry); var path = new Path { Stroke = new SolidColorBrush(circleGraph.Color), StrokeThickness = 2, Data = pathGeometry }; if (circleGraph.Filled) { path.Fill = new SolidColorBrush(circleGraph.Color); } if (circleGraph.LineType != LinePattern.Solid) { path.StrokeDashArray = GraphMappingUtilities.GetLinePattern(circleGraph.LineType); } return(path); }
public IEnumerable <GraphBase> ParseGraphContentFile(string content, IGraphBuilder graphBuilder) { var fileContent = JsonConvert.DeserializeObject <GraphData>(content); return(fileContent.Graphs.Select(graphMap => graphBuilder.Initialize(GraphMappingUtilities.GetGraphType(graphMap)) .CreateGraphFromData(graphMap)).ToList()); }
public GraphBase CreateGraphFromData(Dictionary <string, string> data) { return(new LineGraph { Color = GraphMappingUtilities.BuildColor(data[GraphVariables.Color]), LineType = GraphMappingUtilities.GetLineType(data), Points = GraphMappingUtilities.GetPointsDictionary(data, Models.Enums.GraphType.Line) }); }
public IEnumerable <GraphBase> ParseGraphContentFile(string content, IGraphBuilder graphBuilder) { var xmlDoc = new XmlDocument(); xmlDoc.LoadXml(content); var xmlContent = new GraphData { Graphs = new List <Dictionary <string, string> >() }; var graphs = xmlDoc.GetElementsByTagName("graph"); foreach (XmlNode graphXml in graphs) { var xmlDictionary = graphXml.ChildNodes.Cast <XmlNode>().ToDictionary(graph => graph.Name, graph => graph.InnerText); xmlContent.Graphs.Add(xmlDictionary); } return(xmlContent.Graphs.Select(graphMap => graphBuilder.Initialize(GraphMappingUtilities.GetGraphType(graphMap)).CreateGraphFromData(graphMap)).ToList()); }
public GraphBase CreateGraphFromData(Dictionary <string, string> data) { var graphType = GraphMappingUtilities.GetGraphType(data); GraphBase graph; switch (graphType) { case Models.Enums.GraphType.Circle: graph = new CircleGraph { Radius = Convert.ToDouble(data[GraphVariables.Radius]), Center = GraphMappingUtilities.BuildPoint(data[GraphVariables.Center]), Filled = Convert.ToBoolean(data[GraphVariables.Filled]) }; break; case Models.Enums.GraphType.Triangle: graph = new TriangleGraph { Filled = Convert.ToBoolean(data[GraphVariables.Filled]), Points = GraphMappingUtilities.GetPointsDictionary(data, graphType) }; break; case Models.Enums.GraphType.Rectangle: graph = new RectangleGraph { Filled = Convert.ToBoolean(data[GraphVariables.Filled]), Points = GraphMappingUtilities.GetPointsDictionary(data, graphType) }; break; default: throw new ArgumentOutOfRangeException($"Graph type[{graphType}] is invalid!"); } graph.LineType = GraphMappingUtilities.GetLineType(data); graph.Color = GraphMappingUtilities.BuildColor(data[GraphVariables.Color]); return(graph); }
private UIElement GetComplexShapePath(ComplexShape complexShape, GraphParams graphParams) { var points = complexShape.Points.Select(p => GraphMathUtilities.TransformToCanvasCoords(graphParams, p.Value)); var polygon = new Polygon { Stroke = new SolidColorBrush(complexShape.Color), StrokeThickness = 2 }; var myPointCollection = new PointCollection(points); polygon.Points = myPointCollection; if (complexShape.Filled) { polygon.Fill = new SolidColorBrush(complexShape.Color); } if (complexShape.LineType != LinePattern.Solid) { polygon.StrokeDashArray = GraphMappingUtilities.GetLinePattern(complexShape.LineType); } return(polygon); }