Ejemplo n.º 1
0
        private void EdgeLabelControl_LayoutUpdatedDrawLoop(object sender, EventArgs e)
        {
            if (!IsLoaded)
            {
                return;
            }
            var edgeControl = GetEdgeControl(VisualParent);

            if (edgeControl == null)
            {
                return;
            }
            var source = edgeControl.Source;
            var p1     = new Point(GraphCanvas.GetX(source), GraphCanvas.GetY(source));
            var target = edgeControl.Target;
            var p2     = new Point(GraphCanvas.GetX(target), GraphCanvas.GetY(target));

            if (source != target)
            {
                return;
            }


            Point pp0 = new Point(p2.X, p2.Y + 50);
            Point pp1 = new Point(p2.X + 150, p2.Y + 50);
            Point pp2 = new Point(p2.X + 150, p2.Y);

            Point[] pt = new Point[] { pp0, pp1, pp2 };

            edgeControl.RoutePoints = pt;
        }
        /// <summary>
        /// Updates the vertex internal information.
        /// Maintains consistency between the vertex's position on the
        /// screen and ins internal information.
        /// </summary>
        /// <param name="vertex"></param>
        /// <param name="graphLayout"></param>
        public void UpdateVertexInfo(ref VertexCity vertex, ref GraphLayoutCity graphLayout)
        {
            if (vertex != null)
            {
                // Get the vertex control
                VertexControl vertexControl = graphLayout.GetVertexControl(vertex);

                // If we could find the verex control
                if (vertexControl != null)
                {
                    double tempXCoord, tempYCoord;

                    // Get the vertex screen coordinates
                    tempXCoord = GraphCanvas.GetX(vertexControl);
                    tempYCoord = GraphCanvas.GetY(vertexControl);

                    // Update the internal information if the coordinates
                    // are in range from 0 to 800
                    if ((tempXCoord > 0) && (tempXCoord < 800) &&
                        (tempYCoord > 0) && (tempYCoord < 800))
                    {
                        vertex.CityCoordinates.setX((int)tempXCoord);
                        vertex.CityCoordinates.setY((int)tempYCoord);
                    }

                    // Set the new screen coordinates
                    GraphCanvas.SetX(vertexControl, vertex.CityCoordinates.getX());
                    GraphCanvas.SetY(vertexControl, vertex.CityCoordinates.getY());
                }
            }
        }
Ejemplo n.º 3
0
        /// <inheritdoc />
        public void Animate(
            IAnimationContext context,
            System.Windows.Controls.Control control,
            double x,
            double y,
            TimeSpan duration)
        {
            if (!double.IsNaN(x))
            {
                double from = GraphCanvas.GetX(control);
                from = double.IsNaN(from) ? 0.0 : from;

                // Create the animation for the horizontal position
                var animationX = new DoubleAnimation(
                    from,
                    x,
                    duration,
                    FillBehavior.HoldEnd);
                animationX.Completed += (s, e) =>
                {
                    control.BeginAnimation(GraphCanvas.XProperty, null);
                    control.SetValue(GraphCanvas.XProperty, x);
                };
                control.BeginAnimation(GraphCanvas.XProperty, animationX, HandoffBehavior.Compose);
            }

            if (!double.IsNaN(y))
            {
                double from = GraphCanvas.GetY(control);
                from = (double.IsNaN(from) ? 0.0 : from);

                // Create an animation for the vertical position
                var animationY = new DoubleAnimation(
                    from, y,
                    duration,
                    FillBehavior.HoldEnd);
                animationY.Completed += (s, e) =>
                {
                    control.BeginAnimation(GraphCanvas.YProperty, null);
                    control.SetValue(GraphCanvas.YProperty, y);
                };
                control.BeginAnimation(GraphCanvas.YProperty, animationY, HandoffBehavior.Compose);
            }
        }
        /// <summary>
        /// Get the data about the current graph's
        /// node, edges and their coordinates. Save this
        /// data to citiesLocations and citiesConnections.
        /// </summary>
        public void GetCurrentGraph(GraphLayoutCity graphLayout,
                                    ref CitiesLocations citiesLocations)
        {
            VertexControl vertexControl = new VertexControl();
            Coordinates   tempVertexCoordinates;
            int           tempXCoord;
            int           tempYCoord;

            foreach (VertexCity vertex in graphLayout.Graph.Vertices)
            {
                // Get the vertex data and a vertex control
                citiesLocations.locations.TryGetValue(vertex.City, out tempVertexCoordinates);
                vertexControl = graphLayout.GetVertexControl(vertex);

                // Get current coordinates
                tempXCoord = (int)GraphCanvas.GetX(vertexControl);
                tempYCoord = (int)GraphCanvas.GetY(vertexControl);

                // Update the information
                tempVertexCoordinates.setX(tempXCoord);
                tempVertexCoordinates.setY(tempYCoord);
            }
        }
Ejemplo n.º 5
0
        private void EdgeLabelControl_LayoutUpdated(object sender, EventArgs e)
        {
            if (!IsLoaded)
            {
                return;
            }


            var edgeControl = GetEdgeControl(VisualParent);

            if (edgeControl == null)
            {
                return;
            }
            var source = edgeControl.Source;
            var p1     = new Point(GraphCanvas.GetX(source), GraphCanvas.GetY(source));
            var target = edgeControl.Target;
            var p2     = new Point(GraphCanvas.GetX(target), GraphCanvas.GetY(target));


            double edgeLength;
            var    routePoints = edgeControl.RoutePoints;

            if (routePoints == null)
            {
                // the edge is a single segment (p1,p2)
                edgeLength = GetLabelDistance(GetDistanceBetweenPoints(p1, p2));
            }
            else
            {
                // the edge has one or more segments
                // compute the total length of all the segments
                edgeLength = 0;
                for (int i = 0; i <= routePoints.Length; ++i)
                {
                    if (i == 0)
                    {
                        edgeLength += GetDistanceBetweenPoints(p1, routePoints[0]);
                    }
                    else if (i == routePoints.Length)
                    {
                        edgeLength += GetDistanceBetweenPoints(routePoints[routePoints.Length - 1], p2);
                    }
                    else
                    {
                        edgeLength += GetDistanceBetweenPoints(routePoints[i - 1], routePoints[i]);
                    }
                }
                // find the line segment where the half distance is located
                edgeLength = GetLabelDistance(edgeLength);
                Point newp1 = p1;
                Point newp2 = p2;
                for (int i = 0; i <= routePoints.Length; ++i)
                {
                    double lengthOfSegment;
                    if (i == 0)
                    {
                        lengthOfSegment = GetDistanceBetweenPoints(newp1 = p1, newp2 = routePoints[0]);
                    }
                    else if (i == routePoints.Length)
                    {
                        lengthOfSegment = GetDistanceBetweenPoints(newp1 = routePoints[routePoints.Length - 1], newp2 = p2);
                    }
                    else
                    {
                        lengthOfSegment = GetDistanceBetweenPoints(newp1 = routePoints[i - 1], newp2 = routePoints[i]);
                    }
                    if (lengthOfSegment >= edgeLength)
                    {
                        break;
                    }
                    edgeLength -= lengthOfSegment;
                }
                // redefine our edge points
                p1 = newp1;
                p2 = newp2;
            }
            // align the point so that it  passes through the center of the label content
            var p           = p1;
            var desiredSize = DesiredSize;

            p.Offset(-desiredSize.Width / 2, -desiredSize.Height / 2);

            // move it "edgLength" on the segment
            var angleBetweenPoints = GetAngleBetweenPoints(p1, p2);

            p.Offset(edgeLength * Math.Cos(angleBetweenPoints), -edgeLength * Math.Sin(angleBetweenPoints));
            Arrange(new Rect(p, desiredSize));
        }