Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        public List <UIElement> InitializeGraphs(List <GraphBase> graphs, GraphParams graphParams)
        {
            var elements = new List <UIElement>();

            foreach (var graph in graphs)
            {
                _displayedGraphs.Add(new DisplayedGraph
                {
                    Graph       = graph,
                    IsDisplayed = true
                });

                switch (graph)
                {
                case ComplexShape complexShape:
                    elements.Add(GetComplexShapePath(complexShape, graphParams));
                    break;

                case CircleGraph circleGraph:
                    elements.Add(GetCirclePath(circleGraph, graphParams));
                    break;

                case LineGraph lineGraph:
                    elements.AddRange(GetLinePaths(lineGraph, graphParams));
                    break;
                }
            }

            return(elements);
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        public static Point TransformToCanvasCoords(GraphParams graphParams, Point pointCartesian)
        {
            double graphX = pointCartesian.X * graphParams.Step / graphParams.Scale + (graphParams.Width - graphParams.Step) / 2;
            double graphY = (graphParams.Height - graphParams.Step) / 2 - pointCartesian.Y * graphParams.Step / graphParams.Scale;

            return(new Point(graphX, graphY));
        }
Ejemplo n.º 5
0
        public void FSM2Dot1()
        {
            FSM           fa    = FSM.FromTerm(CompoundTerm.Parse(FSMTRIANGLE));
            GraphParams   gp    = new GraphParams("Test1", fa);
            StringBuilder sb    = DotWriter.ToDot(gp);
            string        s     = sb.ToString();
            Regex         r     = new Regex("\\[ label = \"AssignColor\" \\];", RegexOptions.Multiline);
            int           count = 0;

            count = r.Matches(s).Count;
            Assert.AreEqual(42, count);
        }
Ejemplo n.º 6
0
        public List <UIElement> Refresh(GraphParams graphParams)
        {
            var elements = new List <UIElement>();

            foreach (var graph in _displayedGraphs.Select(g => g.Graph))
            {
                switch (graph)
                {
                case ComplexShape complexShape:
                    elements.Add(GetComplexShapePath(complexShape, graphParams));
                    break;

                case CircleGraph circleGraph:
                    elements.Add(GetCirclePath(circleGraph, graphParams));
                    break;

                case LineGraph lineGraph:
                    elements.AddRange(GetLinePaths(lineGraph, graphParams));
                    break;
                }
            }

            return(elements);
        }
Ejemplo n.º 7
0
        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);
        }