private static void CheckPathEnd(ConnectorInfoMeta source, ConnectorInfoMeta sink, bool showLastLine, PointCollection linePoints)
        {
            if (showLastLine)
            {
                Point  startPoint = new Point(0, 0);
                Point  endPoint   = new Point(0, 0);
                double marginPath = 15;
                switch (source.Orientation)
                {
                case ConnectorOrientation.Left:
                    startPoint = new Point(source.Position.X - marginPath, source.Position.Y);
                    break;

                case ConnectorOrientation.Top:
                    startPoint = new Point(source.Position.X, source.Position.Y - marginPath);
                    break;

                case ConnectorOrientation.Right:
                    startPoint = new Point(source.Position.X + marginPath, source.Position.Y);
                    break;

                case ConnectorOrientation.Bottom:
                    startPoint = new Point(source.Position.X, source.Position.Y + marginPath);
                    break;

                default:
                    break;
                }

                switch (sink.Orientation)
                {
                case ConnectorOrientation.Left:
                    endPoint = new Point(sink.Position.X - marginPath, sink.Position.Y);
                    break;

                case ConnectorOrientation.Top:
                    endPoint = new Point(sink.Position.X, sink.Position.Y - marginPath);
                    break;

                case ConnectorOrientation.Right:
                    endPoint = new Point(sink.Position.X + marginPath, sink.Position.Y);
                    break;

                case ConnectorOrientation.Bottom:
                    endPoint = new Point(sink.Position.X, sink.Position.Y + marginPath);
                    break;

                default:
                    break;
                }
                linePoints.Insert(0, startPoint);
                linePoints.Add(endPoint);
            }
            else
            {
                linePoints.Insert(0, source.Position);
                linePoints.Add(sink.Position);
            }
        }
Ejemplo n.º 2
0
        public void RedrawGraph(int StartPoint, int PointsCount)
        {
            PointCollection DataToPlot = new PointCollection();

            if ((StartPoint < 0) || (StartPoint >= CapturedData.Count))
            {
                return;
            }

            XOffset = CapturedData[StartPoint].X;

            for (int PointIndex = 0; PointIndex < PointsCount; PointIndex++)
            {
                if ((PointIndex + StartPoint) == CapturedData.Count)
                {
                    break;
                }
                Point NewPoint = new Point(CapturedData[PointIndex + StartPoint].X - XOffset, CapturedData[PointIndex + StartPoint].Y);
                DataToPlot.Add(NewPoint);
            }

            for (int PointIndex = 0; PointIndex < (DataToPlot.Count - 1); PointIndex++)
            {
                if (DataToPlot[PointIndex].X != DataToPlot[PointIndex + 1].X)
                {
                    if (((DataToPlot[PointIndex].Y == Start_Y) && (DataToPlot[PointIndex + 1].Y == (Start_Y + PulseHeight))) ||
                        ((DataToPlot[PointIndex].Y == (Start_Y + PulseHeight)) && (DataToPlot[PointIndex + 1].Y == Start_Y)))
                    {
                        DataToPlot.Insert(PointIndex + 1, new Point(DataToPlot[PointIndex + 1].X, DataToPlot[PointIndex].Y));
                    }
                }
            }

            graphpoints = DataToPlot;
        }
        private void Source_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            IEnumerable <Point> enumerable = sender as IEnumerable <Point>;
            PointCollection     points     = this.collectionAssociations[enumerable];

            switch (e.Action)
            {
            case NotifyCollectionChangedAction.Add:
                for (int i = 0; i < e.NewItems.Count; i++)
                {
                    points.Insert(e.NewStartingIndex + i, (Point)e.NewItems[i]);
                }
                break;

            case NotifyCollectionChangedAction.Move:
                for (int i = 0; i < e.NewItems.Count; i++)
                {
                    points.RemoveAt(e.OldStartingIndex);
                    points.Insert(e.NewStartingIndex + i, (Point)e.NewItems[i]);
                }
                break;

            case NotifyCollectionChangedAction.Remove:
                for (int i = 0; i < e.OldItems.Count; i++)
                {
                    points.RemoveAt(e.OldStartingIndex);
                }
                break;

            case NotifyCollectionChangedAction.Replace:
                for (int i = 0; i < e.NewItems.Count; i++)
                {
                    points[e.NewStartingIndex + i] = (Point)e.NewItems[i];
                }
                break;

            case NotifyCollectionChangedAction.Reset:
                points.Clear();
                break;
            }
        }
Ejemplo n.º 4
0
        private void canvas_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            Point newPoint = new Point()
            {
                X = (int)e.GetPosition(canvas).X, Y = (int)e.GetPosition(canvas).Y
            };
            bool alreadyInserted = false;

            foreach (Point p in _pointCollection)
            {
                if (p.X > newPoint.X)
                {
                    _pointCollection.Insert(_pointCollection.IndexOf(p), newPoint);
                    alreadyInserted = true;
                    break;
                }
            }
            if (!alreadyInserted)
            {
                _pointCollection.Add(newPoint);
            }
        }
Ejemplo n.º 5
0
        private PointCollection GetAreaPoints()
        {
            PointCollection points = new PointCollection();

            if (Locations == null)
            {
                return(points);
            }

            CopyLocationsToPoints(points);

            if (points.Count > 0)
            {
                points.Insert(0, new Point(points[0].X, GroundLevel));
                points.Add(new Point(points[points.Count - 1].X, GroundLevel));
            }
            return(points);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Inserts a polygon point at the specified position and at the specified index in the point collection.
        /// </summary>
        /// <param name="position">Position of the point</param>
        /// <param name="insertPosition">Index into the point collection</param>
        public void InsertPoint(Point position, int insertPosition)
        {
            // Create a new polygon point model object
            PolygonPoint modelPoint = new PolygonPoint();

            // Create a new view model polygon point object
            PolygonPointViewModel viewModelPoint = new PolygonPointViewModel(modelPoint, this);

            // Insert the model point into the model point collection
            Polygon.Points.Insert(insertPosition, modelPoint);

            // Insert the view model point into the point collection
            PointCollection.Insert(insertPosition, viewModelPoint);

            // Initialize the position of the point
            viewModelPoint.X = position.X;
            viewModelPoint.Y = position.Y;
        }
Ejemplo n.º 7
0
        public void AddCrater(double X)
        {
            floor_PointCollection.Insert(floor_PointCollection.Count - 2, new Point(X - 20, 350));
            floor_PointCollection.Insert(floor_PointCollection.Count - 2, new Point(X - 20, 350));
            floor_PointCollection.Insert(floor_PointCollection.Count - 2, new Point(X - 5, 370));
            floor_PointCollection.Insert(floor_PointCollection.Count - 2, new Point(X + 5, 370));
            floor_PointCollection.Insert(floor_PointCollection.Count - 2, new Point(X + 20, 350));
            floor_PointCollection.Insert(floor_PointCollection.Count - 2, new Point(X + 20, 350));

            foreach (Point p in floor_PointCollection)
            {
                Debug.WriteLine(p.X + "," + p.Y);
            }
        }
Ejemplo n.º 8
0
        private void vertexLayer_MouseLeftButtonDown(object sender, GraphicMouseButtonEventArgs args)
        {
            Graphic graphic = args.Graphic;

            if (graphic.Geometry is MapPoint)             //Moving point
            {
                DraggingVertex = graphic;
                args.Handled   = true;               //Prevent map from reacting to mouse event
                DraggingVertex.Select();
                StartTracking();
                fromPoint = new MapPoint((graphic.Geometry as MapPoint).X, (graphic.Geometry as MapPoint).Y);
            }
            else if (graphic.Geometry is Polyline)             //Adding vertex
            {
                Polyline line    = graphic.Geometry as Polyline;
                Point    pScreen = args.GetPosition(MyMap);
                MapPoint pMap    = MyMap.ScreenToMap(pScreen);
                MapPoint snap    = FindPointOnLineClosestToPoint(line.Paths[0][0], line.Paths[0][1], pMap);
                args.Handled = true;
                PointCollection pnts   = graphic.Attributes["PointCollection"] as PointCollection;
                Graphic         parent = graphic.Attributes["Feature"] as Graphic;
                //Add new vertex and immediately start tracking it
                if (snapVertex != null)
                {
                    vertexLayer.Graphics.Remove(snapVertex);
                }
                DraggingVertex = AddVertexToEditLayer(parent, vertexLayer, snap);
                DraggingVertex.Select();
                args.Handled = true;                 //Prevent map from reacting to mouse event
                StartTracking();
                DraggingVertex.Attributes.Add("PointCollection", pnts);
                int index = pnts.IndexOf(line.Paths[0][0]);
                pnts.Insert(index + 1, snap);
                vertexLayer.Graphics.Remove(graphic);
                AddHoverLineSegment(pnts, line.Paths[0][0], snap, parent);
                AddHoverLineSegment(pnts, snap, line.Paths[0][1], parent);
                OnGeometryEdit(graphic, snap, null, Action.VertexAdded);
                fromPoint = new MapPoint(snap.X, snap.Y);
            }
        }
        private static PointCollection OptimizeLinePoints(PointCollection linePoints, Rect[] rectangles, ConnectorOrientation sourceOrientation, ConnectorOrientation sinkOrientation)
        {
            var points = new PointCollection();
            int cut    = 0;

            for (int i = 0; i < linePoints.Count; i++)
            {
                if (i >= cut)
                {
                    for (int k = linePoints.Count - 1; k > i; k--)
                    {
                        if (IsPointVisible(linePoints[i], linePoints[k], rectangles))
                        {
                            cut = k;
                            break;
                        }
                    }
                    points.Add(linePoints[i]);
                }
            }

            #region Line
            for (int j = 0; j < points.Count - 1; j++)
            {
                if (points[j].X != points[j + 1].X && points[j].Y != points[j + 1].Y)
                {
                    ConnectorOrientation orientationFrom;
                    ConnectorOrientation orientationTo;

                    // orientation from point
                    if (j == 0)
                    {
                        orientationFrom = sourceOrientation;
                    }
                    else
                    {
                        orientationFrom = GetOrientation(points[j], points[j - 1]);
                    }

                    // orientation to pint
                    if (j == points.Count - 2)
                    {
                        orientationTo = sinkOrientation;
                    }
                    else
                    {
                        orientationTo = GetOrientation(points[j + 1], points[j + 2]);
                    }


                    if ((orientationFrom == ConnectorOrientation.Left || orientationFrom == ConnectorOrientation.Right) &&
                        (orientationTo == ConnectorOrientation.Left || orientationTo == ConnectorOrientation.Right))
                    {
                        double centerX = Math.Min(points[j].X, points[j + 1].X) + Math.Abs(points[j].X - points[j + 1].X) / 2;
                        points.Insert(j + 1, new Point(centerX, points[j].Y));
                        points.Insert(j + 2, new Point(centerX, points[j + 2].Y));
                        if (points.Count - 1 > j + 3)
                        {
                            points.RemoveAt(j + 3);
                        }
                        return(points);
                    }

                    if ((orientationFrom == ConnectorOrientation.Top || orientationFrom == ConnectorOrientation.Bottom) &&
                        (orientationTo == ConnectorOrientation.Top || orientationTo == ConnectorOrientation.Bottom))
                    {
                        double centerY = Math.Min(points[j].Y, points[j + 1].Y) + Math.Abs(points[j].Y - points[j + 1].Y) / 2;
                        points.Insert(j + 1, new Point(points[j].X, centerY));
                        points.Insert(j + 2, new Point(points[j + 2].X, centerY));
                        if (points.Count - 1 > j + 3)
                        {
                            points.RemoveAt(j + 3);
                        }
                        return(points);
                    }

                    if ((orientationFrom == ConnectorOrientation.Left || orientationFrom == ConnectorOrientation.Right) &&
                        (orientationTo == ConnectorOrientation.Top || orientationTo == ConnectorOrientation.Bottom))
                    {
                        points.Insert(j + 1, new Point(points[j + 1].X, points[j].Y));
                        return(points);
                    }

                    if ((orientationFrom == ConnectorOrientation.Top || orientationFrom == ConnectorOrientation.Bottom) &&
                        (orientationTo == ConnectorOrientation.Left || orientationTo == ConnectorOrientation.Right))
                    {
                        points.Insert(j + 1, new Point(points[j].X, points[j + 1].Y));
                        return(points);
                    }
                }
            }
            #endregion

            return(points);
        }
Ejemplo n.º 10
0
 // 设定点为顶点
 private void ChangeToVertex(Point point, int index)
 {
     pointsUnknown.Remove(point);
     pointsVertex.Insert(index, point);
 }
        void TransformToScreenCoInLog(ChartTransform.ChartCartesianTransformer cartesianTransformer)
        {
            int    i            = 0;
            bool   x_isInversed = cartesianTransformer.XAxis.IsInversed;
            bool   y_isInversed = cartesianTransformer.YAxis.IsInversed;
            double xStart       = cartesianTransformer.XAxis.VisibleRange.Start;
            double xEnd         = cartesianTransformer.XAxis.VisibleRange.End;
            double yStart       = cartesianTransformer.YAxis.VisibleRange.Start;
            double yEnd         = cartesianTransformer.YAxis.VisibleRange.End;
            double xDelta       = x_isInversed ? xStart - xEnd : xEnd - xStart;
            double yDelta       = y_isInversed ? yStart - yEnd : yEnd - yStart;

            double width  = cartesianTransformer.XAxis.RenderedRect.Width;
            double height = cartesianTransformer.YAxis.RenderedRect.Height;

            availableSize = new Size(width, height);

            double xTolerance = Math.Abs((xDelta * 1) / availableSize.Width);
            double yTolerance = Math.Abs((yDelta * 1) / availableSize.Height);
            double left       = cartesianTransformer.XAxis.RenderedRect.Left - fastSeries.Area.SeriesClipRect.Left;
            double top        = cartesianTransformer.YAxis.RenderedRect.Top - fastSeries.Area.SeriesClipRect.Top;

            double xBase = cartesianTransformer.XAxis.IsLogarithmic ? (cartesianTransformer.XAxis as LogarithmicAxis).LogarithmicBase : 1;
            double yBase = cartesianTransformer.YAxis.IsLogarithmic ? (cartesianTransformer.YAxis as LogarithmicAxis).LogarithmicBase : 1;

            int count = (int)(Math.Ceiling(xEnd));
            int start = (int)(Math.Floor(xStart));

            if (x_isInversed)
            {
                double temp = xStart;
                xStart = xEnd;
                xEnd   = temp;
            }

            if (y_isInversed)
            {
                double temp = yStart;
                yStart = yEnd;
                yEnd   = temp;
            }
            if (RenderingMode == RenderingMode.Default)
            {
                Points = new PointCollection();
                double xValue     = 0;
                double yValue     = 0;
                double prevXValue = 0;
                double prevYValue = 0;
                if (fastSeries.IsIndexed)
                {
                    prevXValue = 1;
                    for (i = start; i <= count; i++)
                    {
                        double yVal = yBase == 1 ? yChartVals[i] : Math.Log(yChartVals[i], yBase);
                        double xVal = xBase == 1 ? i : Math.Log(i, xBase);

                        if (Math.Abs(prevXValue - i) >= xTolerance || Math.Abs(prevYValue - yVal) >= yTolerance)
                        {
                            xValue = left + (availableSize.Width * ((xVal - xStart) / xDelta));
                            yValue = top + (availableSize.Height * (1 - ((yVal - yStart) / yDelta)));
                            Points.Add(new Point(xValue, yValue));
                            prevXValue = i;
                            prevYValue = yVal;
                        }
                    }

                    if (start > 0)
                    {
                        i = start - 1;
                        double yVal = yBase == 1 ? yChartVals[i] : Math.Log(yChartVals[i], yBase);
                        xValue = left + (availableSize.Width * ((i - xStart) / xDelta));
                        yValue = top + (availableSize.Height * (1 - ((yVal - yStart) / yDelta)));
                        Points.Insert(0, new Point(xValue, yValue));
                    }

                    if (count < yChartVals.Count - 1)
                    {
                        i = count + 1;
                        double yVal = yBase == 1 ? yChartVals[i] : Math.Log(yChartVals[i], yBase);
                        xValue = left + (availableSize.Width * ((i - xStart) / xDelta));
                        yValue = top + (availableSize.Height * (1 - ((yVal - yStart) / yDelta)));
                        Points.Add(new Point(xValue, yValue));
                    }
                }
                else
                {
                    int startIndex = 0;
                    for (i = 0; i < xChartVals.Count; i++)
                    {
                        double xVal = xBase == 1 ? xChartVals[i] : Math.Log(xChartVals[i], xBase);
                        double yVal = yBase == 1 ? yChartVals[i] : Math.Log(yChartVals[i], yBase);

                        if ((xVal <= count) && (xVal >= start))
                        {
                            if (Math.Abs(prevXValue - xVal) >= xTolerance || Math.Abs(prevYValue - yVal) >= yTolerance)
                            {
                                xValue = left + (availableSize.Width * ((xVal - xStart) / xDelta));
                                yValue = top + (availableSize.Height * (1 - ((yVal - yStart) / yDelta)));
                                Points.Add(new Point(xValue, yValue));
                                prevXValue = xVal;
                                prevYValue = yVal;
                            }
                        }
                        else if (xVal < start)
                        {
                            startIndex = i;
                        }
                        else if (xVal > count)
                        {
                            xVal   = xBase == 1 ? xVal : Math.Log(xVal, xBase);
                            yVal   = yBase == 1 ? yVal : Math.Log(yVal, yBase);
                            xValue = left + (availableSize.Width * ((xVal - xStart) / xDelta));
                            yValue = top + (availableSize.Height * (1 - ((yVal - yStart) / yDelta)));
                            Points.Add(new Point(xValue, yValue));
                            break;
                        }
                    }

                    if (startIndex > 0)
                    {
                        double xVal = xBase == 1 ? xChartVals[startIndex] : Math.Log(xChartVals[startIndex], xBase);
                        double yVal = yBase == 1 ? yChartVals[startIndex] : Math.Log(yChartVals[startIndex], yBase);
                        xValue = left + (availableSize.Width * ((xVal - xStart) / xDelta));
                        yValue = top + (availableSize.Height * (1 - ((yVal - yStart) / yDelta)));
                        Points.Insert(0, new Point(xValue, yValue));
                    }
                }
            }
            else
            {
                xValues.Clear();
                yValues.Clear();
                double prevXValue = 0;
                double prevYValue = 0;
                float  xValue     = 0;
                float  yValue     = 0;
                if (fastSeries.IsIndexed)
                {
                    prevXValue = 1;
                    for (i = start; i <= count; i++)
                    {
                        double yVal = yBase == 1 ? yChartVals[i] : Math.Log(yChartVals[i], yBase);
                        double xVal = xBase == 1 ? i : Math.Log(i, xBase);

                        if (Math.Abs(prevXValue - i) >= 1 || Math.Abs(prevYValue - yVal) >= 1)
                        {
                            xValue = (float)(left + availableSize.Width * ((xVal - xStart) / xDelta));
                            yValue = (float)(top + availableSize.Height * (1 - ((yVal - yStart) / yDelta)));
                            xValues.Add(xValue);
                            yValues.Add(yValue);
                            prevXValue = i;
                            prevYValue = yVal;
                        }
                    }

                    if (start > 0)
                    {
                        i = start - 1;
                        double yVal = yBase == 1 ? yChartVals[i] : Math.Log(yChartVals[i], yBase);
                        double xVal = xBase == 1 ? i : Math.Log(i, xBase);
                        xValue = (float)(left + availableSize.Width * ((xVal - xStart) / xDelta));
                        yValue = (float)(top + availableSize.Height * (1 - ((yVal - yStart) / yDelta)));
                        xValues.Insert(0, xValue);
                        yValues.Insert(0, yValue);
                    }

                    if (count < yChartVals.Count - 1)
                    {
                        i = count + 1;
                        double yVal = yBase == 1 ? yChartVals[i] : Math.Log(yChartVals[i], yBase);
                        double xVal = xBase == 1 ? i : Math.Log(i, xBase);
                        xValue = (float)(left + availableSize.Width * ((xVal - xStart) / xDelta));
                        yValue = (float)(top + availableSize.Height * (1 - ((yVal - yStart) / yDelta)));
                        xValues.Add(xValue);
                        yValues.Add(yValue);
                    }
                }
                else
                {
                    int startIndex = 0;
                    for (i = 0; i < xChartVals.Count; i++)
                    {
                        double xVal = xBase == 1 ? xChartVals[i] : Math.Log(xChartVals[i], xBase);
                        double yVal = yBase == 1 ? yChartVals[i] : Math.Log(yChartVals[i], yBase);

                        if ((xVal <= count) && (xVal >= start))
                        {
                            if (Math.Abs(prevXValue - xVal) >= xTolerance || Math.Abs(prevYValue - yVal) >= yTolerance)
                            {
                                xValue = (float)(left + availableSize.Width * ((xVal - xStart) / xDelta));
                                yValue = (float)(top + availableSize.Height * (1 - ((yVal - yStart) / yDelta)));
                                xValues.Add(xValue);
                                yValues.Add(yValue);
                                prevXValue = xVal;
                                prevYValue = yVal;
                            }
                        }
                        else if (xVal < start)
                        {
                            startIndex = i;
                        }
                        else if (xVal > count)
                        {
                            xVal   = xBase == 1 ? xVal : Math.Log(xVal, xBase);
                            yVal   = yBase == 1 ? yVal : Math.Log(yVal, yBase);
                            xValue = (float)(left + availableSize.Width * ((xVal - xStart) / xDelta));
                            yValue = (float)(top + availableSize.Height * (1 - ((yVal - yStart) / yDelta)));
                            xValues.Add(xValue);
                            yValues.Add(yValue);
                            break;
                        }
                    }

                    if (startIndex > 0)
                    {
                        double xVal = xBase == 1 ? xChartVals[startIndex] : Math.Log(xChartVals[startIndex], xBase);
                        double yVal = yBase == 1 ? yChartVals[startIndex] : Math.Log(yChartVals[startIndex], yBase);
                        xValue = (float)(left + availableSize.Width * ((xVal - xStart) / xDelta));
                        yValue = (float)(top + availableSize.Height * (1 - ((yVal - yStart) / yDelta)));
                        xValues.Insert(0, xValue);
                        yValues.Insert(0, yValue);
                    }
                }
            }
        }
        void TransformToScreenCo(ChartTransform.ChartCartesianTransformer cartesianTransformer)
        {
            int    i            = 0;
            bool   x_isInversed = cartesianTransformer.XAxis.IsInversed;
            bool   y_isInversed = cartesianTransformer.YAxis.IsInversed;
            double xStart       = cartesianTransformer.XAxis.VisibleRange.Start;
            double xEnd         = cartesianTransformer.XAxis.VisibleRange.End;
            double yStart       = cartesianTransformer.YAxis.VisibleRange.Start;
            double yEnd         = cartesianTransformer.YAxis.VisibleRange.End;
            double xDelta       = x_isInversed ? xStart - xEnd : xEnd - xStart;
            double yDelta       = y_isInversed ? yStart - yEnd : yEnd - yStart;

            double width  = cartesianTransformer.XAxis.RenderedRect.Width;
            double height = cartesianTransformer.YAxis.RenderedRect.Height;

            availableSize = new Size(width, height);

            double xTolerance = Math.Abs((xDelta * 1) / availableSize.Width);
            double yTolerance = Math.Abs((yDelta * 1) / availableSize.Height);
            double left       = cartesianTransformer.XAxis.RenderedRect.Left - fastSeries.Area.SeriesClipRect.Left;
            double top        = cartesianTransformer.YAxis.RenderedRect.Top - fastSeries.Area.SeriesClipRect.Top;
            int    count      = (int)(Math.Ceiling(xEnd));
            int    start      = (int)(Math.Floor(xStart));

            if (x_isInversed)
            {
                double temp = xStart;
                xStart = xEnd;
                xEnd   = temp;
            }

            if (y_isInversed)
            {
                double temp = yStart;
                yStart = yEnd;
                yEnd   = temp;
            }
            if (RenderingMode == RenderingMode.Default)
            {
                Points = new PointCollection();
                double xValue     = 0;
                double yValue     = 0;
                double prevXValue = 0;
                double prevYValue = 0;

                if (fastSeries.IsIndexed)
                {
                    int length = Length - 1;
                    start = start > length ? start : length;
                    start = start < 0 ? 0 : start;
                    count = count > yChartVals.Count ? yChartVals.Count : count;
                    for (i = start; i <= count; i++)
                    {
                        double xVal = 0;
                        double yVal = 0;
                        if (i >= 0 && i < yChartVals.Count)
                        {
                            xVal = xChartVals[i];
                            yVal = yChartVals[i];
                        }
                        else
                        {
                            continue;
                        }
                        if (Math.Abs(prevXValue - i) >= xTolerance || Math.Abs(prevYValue - yVal) >= yTolerance)
                        {
                            if (xVal <= xEnd && xVal >= xStart)
                            {
                                xValue = left + (availableSize.Width * ((i - xStart) / xDelta));
                                yValue = top + (availableSize.Height * (1 - ((yVal - yStart) / yDelta)));
                                Points.Add(new Point(xValue, yValue));
                            }

                            else if (xVal < xStart && i + 1 < yChartVals.Count)
                            {
                                double y = ChartMath.GetInterpolarationPoint(xChartVals[i], xChartVals[i + 1], yVal, yChartVals[i + 1], xStart);

                                xValue = left;
                                yValue = top + (availableSize.Height * (1 - ((y - yStart) / yDelta)));
                                Points.Add(new Point(xValue, yValue));
                            }
                            else if (xVal > xEnd && i - 1 > 0)
                            {
                                double y = ChartMath.GetInterpolarationPoint(xChartVals[i - 1], xChartVals[i], yChartVals[i - 1], yVal, xEnd);

                                xValue = left + availableSize.Width;
                                yValue = top + (availableSize.Height * (1 - ((y - yStart) / yDelta)));
                                Points.Add(new Point(xValue, yValue));
                            }

                            prevXValue = i;
                            prevYValue = yVal;
                        }
                    }
                }
                else
                {
                    int startIndex = 0;
                    for (i = Length - 1; i < xChartVals.Count; i++)
                    {
                        double xVal = xChartVals[i];
                        double yVal = yChartVals[i];

                        if (Math.Abs(prevXValue - xVal) >= xTolerance || Math.Abs(prevYValue - yVal) >= yTolerance)
                        {
                            if ((xVal <= xEnd) && (xVal >= xStart))
                            {
                                xValue = left + (availableSize.Width * ((xVal - xStart) / xDelta));
                                yValue = top + (availableSize.Height * (1 - ((yVal - yStart) / yDelta)));
                                Points.Add(new Point(xValue, yValue));
                            }

                            else if (xVal < xStart)
                            {
                                startIndex = i;
                            }
                            else if (xVal > xEnd)
                            {
                                if (i - 1 > -1)
                                {
                                    double y = ChartMath.GetInterpolarationPoint(xChartVals[i - 1], xChartVals[i], yChartVals[i - 1], yVal, xEnd);

                                    xValue = left + availableSize.Width;
                                    yValue = top + (availableSize.Height * (1 - ((y - yStart) / yDelta)));
                                    Points.Add(new Point(xValue, yValue));
                                    break;
                                }
                            }
                        }
                        prevXValue = xVal;
                        prevYValue = yVal;
                    }

                    if (startIndex > 0)
                    {
                        if (startIndex + 1 < xChartVals.Count)
                        {
                            double y = ChartMath.GetInterpolarationPoint(xChartVals[startIndex], xChartVals[startIndex + 1], yChartVals[startIndex], yChartVals[startIndex + 1], xStart);

                            xValue = left;
                            yValue = top + (availableSize.Height * (1 - ((y - yStart) / yDelta)));
                            Points.Insert(0, new Point(xValue, yValue));
                        }
                    }
                }
            }
            else
            {
                xValues.Clear();
                yValues.Clear();
                double prevXValue = 0;
                double prevYValue = 0;
                float  xValue     = 0;
                float  yValue     = 0;
                if (fastSeries.IsIndexed)
                {
                    prevXValue = 1;
                    for (i = start; i <= count; i++)
                    {
                        double yVal = yChartVals[i];

                        if (Math.Abs(prevXValue - i) >= xTolerance || Math.Abs(prevYValue - yVal) >= yTolerance)
                        {
                            xValue = (float)(left + availableSize.Width * ((i - xStart) / xDelta));
                            yValue = (float)(top + availableSize.Height * (1 - ((yVal - yStart) / yDelta)));
                            xValues.Add(xValue);
                            yValues.Add(yValue);
                            prevXValue = i;
                            prevYValue = yVal;
                        }
                    }

                    if (start > 0)
                    {
                        i = start - 1;
                        double yVal = yChartVals[i];
                        xValue = (float)(left + availableSize.Width * ((i - xStart) / xDelta));
                        yValue = (float)(top + availableSize.Height * (1 - ((yVal - yStart) / yDelta)));
                        xValues.Insert(0, xValue);
                        yValues.Insert(0, yValue);
                    }

                    if (count < yChartVals.Count - 1)
                    {
                        i = count + 1;
                        double yVal = yChartVals[i];
                        xValue = (float)(left + availableSize.Width * ((i - xStart) / xDelta));
                        yValue = (float)(top + availableSize.Height * (1 - ((yVal - yStart) / yDelta)));
                        xValues.Add(xValue);
                        yValues.Add(yValue);
                    }
                }
                else
                {
                    int startIndex = 0;
                    for (i = Length - 1; i < xChartVals.Count; i++)
                    {
                        double xVal = xChartVals[i];
                        double yVal = yChartVals[i];

                        if ((xVal <= count) && (xVal >= start))
                        {
                            if (Math.Abs(prevXValue - xVal) >= xTolerance || Math.Abs(prevYValue - yVal) >= yTolerance)
                            {
                                xValue = (float)(left + availableSize.Width * ((xVal - xStart) / xDelta));
                                yValue = (float)(top + availableSize.Height * (1 - ((yVal - yStart) / yDelta)));
                                xValues.Add(xValue);
                                yValues.Add(yValue);
                                prevXValue = xVal;
                                prevYValue = yVal;
                            }
                        }
                        else if (xVal < start)
                        {
                            startIndex = i;
                        }
                        else if (xVal > count)
                        {
                            xValue = (float)(left + availableSize.Width * ((xVal - xStart) / xDelta));
                            yValue = (float)(top + availableSize.Height * (1 - ((yVal - yStart) / yDelta)));
                            xValues.Add(xValue);
                            yValues.Add(yValue);
                            break;
                        }
                    }

                    if (startIndex > 0)
                    {
                        xValue = (float)(left + availableSize.Width * ((xChartVals[startIndex] - xStart) / xDelta));
                        yValue = (float)(top + availableSize.Height * (1 - ((yChartVals[startIndex] - yStart) / yDelta)));
                        xValues.Insert(0, xValue);
                        yValues.Insert(0, yValue);
                    }
                }
            }
        }
Ejemplo n.º 13
0
        private void TransformToScreenCoInLogVertical(double xBase, double yBase)
        {
            Points = new PointCollection();
            double prevXValue = 0;
            double prevYValue = 0;
            int    startIndex = 0;
            int    i          = 0;

            double xVal, yVal;

            prevXValue = fastSeries.IsIndexed ? 1 : xChartVals[0];
            prevYValue = yChartVals[0];
            int cnt = xChartVals.Count - 1;

            if (fastSeries.isLinearData)
            {
                for (i = 1; i < cnt; i++)
                {
                    xVal = xBase == 1 || xChartVals[i] <= 0 ? xChartVals[i] : Math.Log(xChartVals[i], xBase);
                    yVal = yBase == 1 || yChartVals[i] <= 0 ? yChartVals[i] : Math.Log(yChartVals[i], yBase);
                    if ((xVal <= xEnd) && (xVal >= xStart))
                    {
                        if (Math.Abs(prevXValue - xVal) >= xTolerance || Math.Abs(prevYValue - yVal) >= yTolerance)
                        {
                            Points.Add(new Point((yOffset + ySize * (1 - ((yEnd - yVal) / yDelta))), (xOffset + xSize * ((xEnd - xVal) / xDelta))));
                            prevXValue = xVal;
                            prevYValue = yVal;
                        }
                    }
                    else if (xVal < xStart)
                    {
                        if (x_isInversed)
                        {
                            Points.Add(new Point((yOffset + ySize * (1 - ((yEnd - yVal) / yDelta))), (xOffset + xSize * ((xEnd - xVal) / xDelta))));
                        }
                        else
                        {
                            startIndex = i;
                        }
                    }
                    else if (xVal > xEnd)
                    {
                        Points.Add(new Point((yOffset + ySize * (1 - ((yEnd - yVal) / yDelta))), (xOffset + xSize * ((xEnd - xVal) / xDelta))));
                        break;
                    }
                }
            }
            else
            {
                for (i = 1; i < cnt; i++)
                {
                    xVal = xBase == 1 || xChartVals[i] <= 0 ? xChartVals[i] : Math.Log(xChartVals[i], xBase);
                    yVal = yBase == 1 || yChartVals[i] <= 0 ? yChartVals[i] : Math.Log(yChartVals[i], yBase);
                    if (Math.Abs(prevXValue - xVal) >= xTolerance || Math.Abs(prevYValue - yVal) >= yTolerance)
                    {
                        Points.Add(new Point((yOffset + ySize * (1 - ((yEnd - yVal) / yDelta))), (xOffset + xSize * ((xEnd - xVal) / xDelta))));
                        prevXValue = xVal;
                        prevYValue = yVal;
                    }
                }
            }

            xVal = xBase == 1 || xChartVals[startIndex] <= 0 ? xChartVals[startIndex] : Math.Log(xChartVals[startIndex], xBase);
            yVal = yBase == 1 || yChartVals[startIndex] <= 0 ? yChartVals[startIndex] : Math.Log(yChartVals[startIndex], yBase);
            Points.Insert(0, new Point((yOffset + ySize * (1 - ((yEnd - yVal) / yDelta))), (xOffset + xSize * ((xEnd - xVal) / xDelta))));
            if (i == cnt)
            {
                xVal = xBase == 1 || xChartVals[cnt] <= 0 ? xChartVals[cnt] : Math.Log(xChartVals[cnt], xBase);
                yVal = yBase == 1 || yChartVals[cnt] <= 0 ? yChartVals[cnt] : Math.Log(yChartVals[cnt], yBase);
                Points.Add(new Point((yOffset + ySize * (1 - ((yEnd - yVal) / yDelta))), (xOffset + xSize * ((xEnd - xVal) / xDelta))));
            }
        }
Ejemplo n.º 14
0
        private void TransformToScreenCoVertical()
        {
            Points = new PointCollection();
            double prevXValue    = 0;
            double prevYValue    = 0;
            int    i             = 0;
            double yCoefficient  = 0;
            var    numericalAxis = fastSeries.ActualYAxis as NumericalAxis;
            bool   isScaleBreak  = numericalAxis != null && numericalAxis.AxisRanges != null && numericalAxis.AxisRanges.Count > 0;

            xValues = (Series.ActualXValues is List <double> && !Series.IsIndexed) ? Series.ActualXValues as List <double> : Series.GetXValues();
            var isGrouping = (fastSeries.ActualXAxis is CategoryAxis) ? (fastSeries.ActualXAxis as CategoryAxis).IsIndexed : true;

            int startIndex = 0;

            prevXValue = fastSeries.IsIndexed ? 1 : xChartVals[0];
            prevYValue = yChartVals[0];
            int cnt = xChartVals.Count - 1;

            if (fastSeries.isLinearData)
            {
                for (i = 1; i < cnt; i++)
                {
                    double xVal = xChartVals[i];
                    double yVal = yChartVals[i];

                    if ((xVal <= xEnd) && (xVal >= xStart))
                    {
                        if (Math.Abs(prevXValue - xVal) >= xTolerance || Math.Abs(prevYValue - yVal) >= yTolerance)
                        {
                            yCoefficient = (isScaleBreak ? numericalAxis.CalculateValueToCoefficient(yVal) : 1 - ((yEnd - yVal) / yDelta));
                            Points.Add(new Point((yOffset + ySize * yCoefficient), (xOffset + xSize * ((xEnd - xVal) / xDelta))));
                            prevXValue = xVal;
                            prevYValue = yVal;
                        }
                    }
                    else if (xVal < xStart)
                    {
                        if (x_isInversed)
                        {
                            yCoefficient = (isScaleBreak ? numericalAxis.CalculateValueToCoefficient(yVal) : 1 - ((yEnd - yVal) / yDelta));
                            Points.Add(new Point((yOffset + ySize * yCoefficient), (xOffset + xSize * ((xEnd - xVal) / xDelta))));
                        }
                        else
                        {
                            startIndex = i;
                        }
                    }
                    else if (xVal > xEnd)
                    {
                        double yValue = ChartMath.GetInterpolarationPoint(xChartVals[i - 1], xChartVals[i], yChartVals[i - 1], yChartVals[i], xEnd);
                        yCoefficient = (isScaleBreak ? numericalAxis.CalculateValueToCoefficient(yValue) : 1 - ((yEnd - yValue) / yDelta));
                        Points.Add(new Point((yOffset + ySize * yCoefficient), (xOffset)));
                        break;
                    }
                }
            }
            else
            {
                for (i = 1; i < cnt; i++)
                {
                    double xVal = xChartVals[i];
                    double yVal = yChartVals[i];
                    if (Math.Abs(prevXValue - xVal) >= xTolerance || Math.Abs(prevYValue - yVal) >= yTolerance)
                    {
                        yCoefficient = (isScaleBreak ? numericalAxis.CalculateValueToCoefficient(yVal) : 1 - ((yEnd - yVal) / yDelta));
                        Points.Add(new Point((yOffset + ySize * yCoefficient), (xOffset + xSize * ((xEnd - xVal) / xDelta))));
                        prevXValue = xVal;
                        prevYValue = yVal;
                    }
                }
            }

            if (startIndex > 0)
            {
                double yValue = ChartMath.GetInterpolarationPoint(xChartVals[startIndex], xChartVals[startIndex + 1], yChartVals[startIndex], yChartVals[startIndex + 1], xStart);
                yCoefficient = (isScaleBreak ? numericalAxis.CalculateValueToCoefficient(yValue) : 1 - ((yEnd - yValue) / yDelta));
                Points.Insert(0, new Point((yOffset + ySize * yCoefficient), (xOffset + xSize * ((xEnd - xStart) / xDelta))));
            }
            else
            {
                yCoefficient = (isScaleBreak ? numericalAxis.CalculateValueToCoefficient(yChartVals[startIndex]) : 1 - ((yEnd - yChartVals[startIndex]) / yDelta));
                Points.Insert(0, new Point((yOffset + ySize * yCoefficient), (xOffset + xSize * ((xEnd - xChartVals[startIndex]) / xDelta))));
            }

            if (i == cnt)
            {
                yCoefficient = (isScaleBreak ? numericalAxis.CalculateValueToCoefficient(yChartVals[cnt]) : 1 - ((yEnd - yChartVals[cnt]) / yDelta));
                Points.Add(new Point((yOffset + ySize * yCoefficient), (xOffset + xSize * ((xEnd - xChartVals[cnt]) / xDelta))));
            }
        }
Ejemplo n.º 15
0
        protected void drag_Changed(DragListener drag)
        {
            PointCollection points = GetPointCollection();

            MultiPointThumb mprt = drag.Target as MultiPointThumb;

            if (mprt != null)
            {
                double dx = 0;
                double dy = 0;
                //if has zoomed
                if (_zoom != null)
                {
                    dx = drag.Delta.X * (1 / _zoom.CurrentZoom);
                    dy = drag.Delta.Y * (1 / _zoom.CurrentZoom);
                }

                Double theta;
                //if one point selected snapping angle is calculated in relation to previous point
                if (_selectedPoints.Count == 1 && mprt.Index > 0)
                {
                    theta = (180 / Math.PI) * Math.Atan2(_selectedPoints[mprt.Index].Y + dy - points[mprt.Index - 1].Y, _selectedPoints[mprt.Index].X + dx - points[mprt.Index - 1].X);
                }
                else                     //if multiple points snapping angle is calculated in relation to mouse dragging angle
                {
                    theta = (180 / Math.PI) * Math.Atan2(dy, dx);
                }

                //snappingAngle is used for snapping function to horizontal or vertical plane in line drawing, and is activated by pressing ctrl or shift button
                int?snapAngle = null;

                //shift+alt gives a new point
                if ((Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift)) && (Keyboard.IsKeyDown(Key.LeftAlt) || Keyboard.IsKeyDown(Key.RightAlt)))
                {
                    //if dragging occurs on a point and that point is the only selected, a new node will be added.
                    //_isCtrlDragging is needed since this method is called for every x pixel that the mouse moves
                    //so it could be many thousands of times during a single dragging
                    if (!_isDragging && _selectedPoints.Count == 1 && (Math.Abs(dx) > 0 || Math.Abs(dy) > 0))
                    {
                        //duplicate point that is selected
                        Point p = points[mprt.Index];

                        //insert duplicate
                        points.Insert(mprt.Index, p);

                        //create adorner marker
                        CreateThumb(PlacementAlignment.BottomRight, Cursors.Cross, mprt.Index);

                        //set index of all points that had a higher index than selected to +1
                        foreach (FrameworkElement rt in adornerPanel.Children)
                        {
                            if (rt is MultiPointThumb)
                            {
                                MultiPointThumb t = rt as MultiPointThumb;
                                if (t.Index > mprt.Index)
                                {
                                    t.Index++;
                                }
                            }
                        }

                        //set index of new point to old point index + 1
                        mprt.Index = mprt.Index + 1;
                        ResetThumbs();
                        SelectThumb(mprt);
                    }
                    snapAngle = 10;
                }

                //snapping occurs when mouse is within 10 degrees from horizontal or vertical plane if shift is pressed
                else if (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift))
                {
                    snapAngle = 10;
                }
                //snapping occurs within 45 degree intervals that is line will always be horizontal or vertical if alt is pressed
                else if (Keyboard.IsKeyDown(Key.LeftAlt) || Keyboard.IsKeyDown(Key.RightAlt))
                {
                    snapAngle = 45;
                }
                _isDragging = true;
                points      = MovePoints(points, dx, dy, theta, snapAngle);
            }

            (drag.Target as DesignerThumb).InvalidateArrange();
        }
Ejemplo n.º 16
0
        internal void AlignAxisToolTipPolygon(
            ContentControl control,
            ChartAlignment verticalAlignemnt,
            ChartAlignment horizontalAlignment,
            double x,
            double y,
            ChartBehavior behavior)
        {
            double labelHeight              = control.DesiredSize.Height;
            double labelWidth               = control.DesiredSize.Width;
            double axisTipHypotenuse        = (2 * axisTipHeight) / Math.Sqrt(3);
            var    isChartTrackBallBehavior = behavior is ChartTrackBallBehavior;

            PointCollection polygonPoints = new PointCollection();

            polygonPoints.Add(new Point(0, 0));
            polygonPoints.Add(new Point(0, labelHeight));
            polygonPoints.Add(new Point(labelWidth, labelHeight));

            if (chartAxis.Orientation == Orientation.Horizontal)
            {
                polygonPoints.Add(new Point(labelWidth, 0));

                if (chartAxis.OpposedPosition)
                {
                    double tipPosition, leftTipWidth, rightTipWidth;
                    if ((control.Content as ChartPointInfo).Axis.CrosshairLabelTemplate == null && !isChartTrackBallBehavior)
                    {
                        control.Margin = new Thickness(0, -6, 0, 0);
                    }

                    if (((control.Content as ChartPointInfo).X - control.DesiredSize.Height <= ChartArea.SeriesClipRect.X))
                    {
                        if (isChartTrackBallBehavior)
                        {
                            AlignDefaultLabel(
                                ChartAlignment.Far,
                                ChartAlignment.Far,
                                ChartArea.SeriesClipRect.X,
                                (control.Content as ChartPointInfo).Y,
                                control);
                        }
                        else
                        {
                            AlignDefaultLabel(
                                verticalAlignemnt,
                                ChartAlignment.Far,
                                ChartArea.SeriesClipRect.X,
                                (control.Content as ChartPointInfo).Y,
                                control);
                        }

                        tipPosition   = (control.Content as ChartPointInfo).BaseX - ChartArea.SeriesClipRect.X;
                        leftTipWidth  = tipPosition - axisTipHypotenuse / 2;
                        rightTipWidth = tipPosition + axisTipHypotenuse / 2;

                        if (leftTipWidth < 0)
                        {
                            leftTipWidth = 0;
                        }

                        polygonPoints.Insert(2, (new Point(leftTipWidth, labelHeight)));
                        polygonPoints.Insert(3, (new Point(tipPosition, labelHeight + axisTipHeight)));
                        polygonPoints.Insert(4, (new Point(rightTipWidth, labelHeight)));
                    }
                    else if ((control.Content as ChartPointInfo).X + control.DesiredSize.Width
                             >= ChartArea.SeriesClipRect.X + ChartArea.SeriesClipRect.Width)
                    {
                        if (isChartTrackBallBehavior)
                        {
                            AlignDefaultLabel(
                                ChartAlignment.Far,
                                ChartAlignment.Near,
                                ChartArea.SeriesClipRect.X + ChartArea.SeriesClipRect.Width,
                                (control.Content as ChartPointInfo).Y,
                                control);
                        }
                        else
                        {
                            AlignDefaultLabel(
                                verticalAlignemnt,
                                ChartAlignment.Near,
                                ChartArea.SeriesClipRect.X + ChartArea.SeriesClipRect.Width,
                                (control.Content as ChartPointInfo).Y,
                                control);
                        }

                        tipPosition   = (control.Content as ChartPointInfo).BaseX - (control.Content as ChartPointInfo).X;
                        leftTipWidth  = tipPosition - axisTipHypotenuse / 2;
                        rightTipWidth = tipPosition + axisTipHypotenuse / 2;

                        if (rightTipWidth > control.DesiredSize.Width)
                        {
                            rightTipWidth = control.DesiredSize.Width;
                        }
                        if (leftTipWidth < 0)
                        {
                            leftTipWidth = 0;
                        }

                        polygonPoints.Insert(2, (new Point(leftTipWidth, labelHeight)));
                        polygonPoints.Insert(3, (new Point(tipPosition, labelHeight + axisTipHeight)));
                        polygonPoints.Insert(4, (new Point(rightTipWidth, labelHeight)));
                    }
                    else
                    {
                        AlignDefaultLabel(verticalAlignemnt, horizontalAlignment, x, y, control);

                        polygonPoints.Insert(2, new Point(labelWidth / 2 - axisTipHypotenuse / 2, labelHeight));
                        polygonPoints.Insert(3, new Point(labelWidth / 2, labelHeight + axisTipHeight));
                        polygonPoints.Insert(4, new Point(labelWidth / 2 + axisTipHypotenuse / 2, labelHeight));
                    }
                }
                else
                {
                    double tipPosition, leftTipWidth, rightTipWidth;
                    if ((control.Content as ChartPointInfo).Axis.CrosshairLabelTemplate == null && !isChartTrackBallBehavior)
                    {
                        control.Margin = new Thickness(0, 6, 0, 0);
                    }

                    if (((control.Content as ChartPointInfo).X - control.DesiredSize.Height <= ChartArea.SeriesClipRect.X))
                    {
                        AlignDefaultLabel(
                            ChartAlignment.Far,
                            ChartAlignment.Far,
                            ChartArea.SeriesClipRect.X,
                            (control.Content as ChartPointInfo).Y,
                            control);

                        tipPosition   = (control.Content as ChartPointInfo).BaseX - ChartArea.SeriesClipRect.X;
                        leftTipWidth  = tipPosition - axisTipHypotenuse / 2;
                        rightTipWidth = tipPosition + axisTipHypotenuse / 2;

                        if (leftTipWidth < 0)
                        {
                            leftTipWidth = 0;
                        }

                        polygonPoints.Insert(4, (new Point(rightTipWidth, 0)));
                        polygonPoints.Insert(5, (new Point(tipPosition, -axisTipHeight)));
                        polygonPoints.Insert(6, (new Point(leftTipWidth, 0)));
                    }
                    else if ((control.Content as ChartPointInfo).X + control.DesiredSize.Width
                             >= ChartArea.SeriesClipRect.X + ChartArea.SeriesClipRect.Width)
                    {
                        AlignDefaultLabel(
                            ChartAlignment.Far,
                            ChartAlignment.Near,
                            ChartArea.SeriesClipRect.X + ChartArea.SeriesClipRect.Width,
                            (control.Content as ChartPointInfo).Y,
                            control);

                        tipPosition   = ((control.Content as ChartPointInfo).BaseX - (control.Content as ChartPointInfo).X);
                        leftTipWidth  = tipPosition - axisTipHypotenuse / 2;
                        rightTipWidth = tipPosition + axisTipHypotenuse / 2;

                        if (rightTipWidth > control.DesiredSize.Width)
                        {
                            rightTipWidth = control.DesiredSize.Width;
                        }
                        if (leftTipWidth < 0)
                        {
                            leftTipWidth = 0;
                        }

                        polygonPoints.Insert(4, new Point(rightTipWidth, 0));
                        polygonPoints.Insert(5, new Point(tipPosition, -axisTipHeight));
                        polygonPoints.Insert(6, new Point(leftTipWidth, 0));
                    }
                    else
                    {
                        AlignDefaultLabel(verticalAlignemnt, horizontalAlignment, x, y, control);

                        polygonPoints.Insert(4, new Point(labelWidth / 2 + axisTipHypotenuse / 2, 0));
                        polygonPoints.Insert(5, new Point(labelWidth / 2, -axisTipHeight));
                        polygonPoints.Insert(6, new Point(labelWidth / 2 - axisTipHypotenuse / 2, 0));
                    }
                }

                polygonPoints.Add(new Point(0, 0));
                (control.Content as ChartPointInfo).PolygonPoints = polygonPoints;
            }
            else
            {
                if (chartAxis.OpposedPosition)
                {
                    if ((control.Content as ChartPointInfo).Axis.CrosshairLabelTemplate == null && !isChartTrackBallBehavior)
                    {
                        control.Margin = new Thickness(6, 0, 0, 0);
                    }

                    if (((control.Content as ChartPointInfo).Y - control.DesiredSize.Height <= ChartArea.SeriesClipRect.Y))
                    {
                        if (isChartTrackBallBehavior)
                        {
                            AlignDefaultLabel(
                                ChartAlignment.Far,
                                ChartAlignment.Far,
                                (control.Content as ChartPointInfo).X,
                                ChartArea.SeriesClipRect.Y,
                                control);
                        }
                        else
                        {
                            AlignDefaultLabel(
                                ChartAlignment.Far,
                                horizontalAlignment,
                                (control.Content as ChartPointInfo).X,
                                ChartArea.SeriesClipRect.Y,
                                control);
                        }

                        double tipPosition   = (control.Content as ChartPointInfo).BaseY - ChartArea.SeriesClipRect.Y;
                        double lefttipWidth  = tipPosition - axisTipHypotenuse / 2;
                        double righttipWidth = tipPosition + axisTipHypotenuse / 2;

                        if (lefttipWidth < 0)
                        {
                            lefttipWidth = 0;
                        }
                        if (righttipWidth > labelHeight)
                        {
                            righttipWidth = labelHeight;
                        }

                        polygonPoints.Insert(1, new Point(0, lefttipWidth));
                        polygonPoints.Insert(2, new Point(-axisTipHeight, tipPosition));
                        polygonPoints.Insert(3, new Point(0, righttipWidth));
                    }
                    else if ((control.Content as ChartPointInfo).Y + control.DesiredSize.Height
                             >= ChartArea.SeriesClipRect.Y + ChartArea.SeriesClipRect.Height)
                    {
                        if (isChartTrackBallBehavior)
                        {
                            AlignDefaultLabel(
                                ChartAlignment.Near,
                                ChartAlignment.Far,
                                (control.Content as ChartPointInfo).X,
                                ChartArea.SeriesClipRect.Y + ChartArea.SeriesClipRect.Height,
                                control);
                        }
                        else
                        {
                            AlignDefaultLabel(
                                ChartAlignment.Near,
                                horizontalAlignment,
                                (control.Content as ChartPointInfo).X,
                                ChartArea.SeriesClipRect.Y + ChartArea.SeriesClipRect.Height,
                                control);
                        }

                        double tipPosition   = (control.Content as ChartPointInfo).BaseY - (control.Content as ChartPointInfo).Y;
                        double lefttipWidth  = tipPosition - axisTipHypotenuse / 2;
                        double righttipWidth = tipPosition + axisTipHypotenuse / 2;

                        if (righttipWidth > control.DesiredSize.Height)
                        {
                            righttipWidth = control.DesiredSize.Height;
                        }
                        if (lefttipWidth < 0)
                        {
                            lefttipWidth = 0;
                        }

                        polygonPoints.Insert(1, new Point(0, lefttipWidth));
                        polygonPoints.Insert(2, new Point(-axisTipHeight, tipPosition));
                        polygonPoints.Insert(3, new Point(0, righttipWidth));
                    }
                    else
                    {
                        if (!isChartTrackBallBehavior)
                        {
                            AlignDefaultLabel(verticalAlignemnt, horizontalAlignment, x, y, control);
                        }

                        polygonPoints.Insert(1, new Point(0, labelHeight / 3));
                        polygonPoints.Insert(2, new Point(-axisTipHeight, labelHeight / 2));
                        polygonPoints.Insert(3, new Point(0, labelHeight / 1.5));
                    }
                }
                else
                {
                    if ((control.Content as ChartPointInfo).Axis.CrosshairLabelTemplate == null && !isChartTrackBallBehavior)
                    {
                        control.Margin = new Thickness(-6, 0, 0, 0);
                    }

                    if (((control.Content as ChartPointInfo).Y - control.DesiredSize.Height <= ChartArea.SeriesClipRect.Y))
                    {
                        if (isChartTrackBallBehavior)
                        {
                            AlignDefaultLabel(
                                ChartAlignment.Far,
                                ChartAlignment.Far,
                                (control.Content as ChartPointInfo).X,
                                ChartArea.SeriesClipRect.Y,
                                control);
                        }
                        else
                        {
                            AlignDefaultLabel(
                                ChartAlignment.Far,
                                horizontalAlignment,
                                (control.Content as ChartPointInfo).X,
                                ChartArea.SeriesClipRect.Y,
                                control);
                        }

                        double tipPosition   = (control.Content as ChartPointInfo).BaseY - ChartArea.SeriesClipRect.Y;
                        double lefttipWidth  = tipPosition - axisTipHypotenuse / 2;
                        double righttipWidth = tipPosition + axisTipHypotenuse / 2;

                        if (lefttipWidth < 0)
                        {
                            lefttipWidth = 0;
                        }
                        if (righttipWidth > labelHeight)
                        {
                            righttipWidth = labelHeight;
                        }

                        polygonPoints.Insert(3, new Point(labelWidth, righttipWidth));
                        polygonPoints.Insert(4, new Point(labelWidth + axisTipHeight, tipPosition));
                        polygonPoints.Insert(5, new Point(labelWidth, lefttipWidth));
                    }
                    else if ((control.Content as ChartPointInfo).Y + control.DesiredSize.Height
                             >= ChartArea.SeriesClipRect.Y + ChartArea.SeriesClipRect.Height)
                    {
                        if (isChartTrackBallBehavior)
                        {
                            AlignDefaultLabel(
                                ChartAlignment.Near,
                                ChartAlignment.Far,
                                (control.Content as ChartPointInfo).X,
                                ChartArea.SeriesClipRect.Y + ChartArea.SeriesClipRect.Height,
                                control);
                        }
                        else
                        {
                            AlignDefaultLabel(
                                ChartAlignment.Near,
                                horizontalAlignment,
                                (control.Content as ChartPointInfo).X,
                                ChartArea.SeriesClipRect.Y + ChartArea.SeriesClipRect.Height,
                                control);
                        }

                        double tipPosition   = (control.Content as ChartPointInfo).BaseY - (control.Content as ChartPointInfo).Y;
                        double lefttipWidth  = tipPosition - axisTipHypotenuse / 2;
                        double righttipWidth = tipPosition + axisTipHypotenuse / 2;

                        if (lefttipWidth < 0)
                        {
                            lefttipWidth = 0;
                        }
                        if (righttipWidth > control.DesiredSize.Height)
                        {
                            righttipWidth = control.DesiredSize.Height;
                        }

                        polygonPoints.Add(new Point(labelWidth, righttipWidth));
                        polygonPoints.Add(new Point(labelWidth + axisTipHeight, tipPosition));
                        polygonPoints.Add(new Point(labelWidth, lefttipWidth));
                    }
                    else
                    {
                        if (!isChartTrackBallBehavior)
                        {
                            AlignDefaultLabel(verticalAlignemnt, horizontalAlignment, x, y, control);
                        }

                        polygonPoints.Add(new Point(labelWidth, labelHeight / 1.5));
                        polygonPoints.Add(new Point(labelWidth + axisTipHeight, labelHeight / 2));
                        polygonPoints.Add(new Point(labelWidth, labelHeight / 3));
                    }
                }

                polygonPoints.Add(new Point(labelWidth, 0));
                polygonPoints.Add(new Point(0, 0));

                (control.Content as ChartPointInfo).PolygonPoints = polygonPoints;
            }
        }
Ejemplo n.º 17
0
        private void PointCollectionOperations(object sender, SelectionChangedEventArgs e)
        {
            RadioButton li = (sender as RadioButton);

            // Strings used to display the results
            String syntaxString, resultType, operationString;

            // The local variables point1, point2, vector2, etc are defined in each
            // case block for readability reasons. Each variable is contained within
            // the scope of each case statement.
            switch (li.Name)
            {   //begin switch
            case "rb1":
            {
                //<SnippetPointCollectionAdd>

                // Instantiating and initializing Point structures
                Point point1 = new Point(10, 10);
                Point point2 = new Point(20, 20);
                Point point3 = new Point(30, 30);
                Point point4 = new Point(40, 40);

                // Instantiating an array of Points to the points
                Point[] pointArray = new Point[3];

                // Adding points to array
                pointArray[0] = point1;
                pointArray[1] = point2;
                pointArray[2] = point3;

                // Instantiating a PointCollection and initializing with an array
                PointCollection pointCollection1 = new PointCollection(pointArray);

                //  Adding a point to the PointCollection
                pointCollection1.Add(point4);

                // pointCollection1 is equal to (10,10 20,20 30,30 40,40)

                //</SnippetPointCollectionAdd>



                break;
            }

            case "rb2":
            {
                //<SnippetPointCollectionClear>

                // Instantiating and initializing Point structures
                Point point1 = new Point(10, 10);
                Point point2 = new Point(20, 20);
                Point point3 = new Point(30, 30);

                // Instantiating a PointCollection
                PointCollection pointCollection1 = new PointCollection();

                // Adding Points to the PointCollection
                pointCollection1.Add(point1);
                pointCollection1.Add(point2);
                pointCollection1.Add(point3);

                // pointCollection1 is equal to (10,10 20,20 30,30)

                // clearing the PointCollection
                pointCollection1.Clear();

                // pointCollection1 is now empty

                //</SnippetPointCollectionClear>

                break;
            }

            case "rb3":
            {
                //<SnippetPointCollectionContains>

                Boolean inCollection;

                // Instantiating and Initializing Point structures
                Point point1 = new Point(10, 10);
                Point point2 = new Point(20, 20);
                Point point3 = new Point(30, 30);
                Point point4 = new Point(40, 40);

                // Instantiating a PointCollection
                PointCollection pointCollection1 = new PointCollection();

                pointCollection1.Add(point1);
                pointCollection1.Add(point2);
                pointCollection1.Add(point3);

                // pointCollection1 is equal to (10,10 20,20 30,30)

                inCollection = pointCollection1.Contains(point4);

                // inCollection is equal to False

                //</SnippetPointCollectionContains>

                break;
            }

            case "rb4":
            {
                //<SnippetPointCollectionIndexOf>

                int pIndex;

                // Instantiating and initializing Point structures
                Point point1 = new Point(10, 10);
                Point point2 = new Point(20, 20);
                Point point3 = new Point(30, 30);

                // Instantiating a PointCollection
                PointCollection pointCollection1 = new PointCollection();

                // Adding Points to PointCollection
                pointCollection1.Add(point1);
                pointCollection1.Add(point2);
                pointCollection1.Add(point3);
                // pointCollection1 is equal to (10,10 20,20 30,30)

                // Getting the index of a Point
                pIndex = pointCollection1.IndexOf(point2);

                // pointIndex is equal to 1

                //</SnippetPointCollectionIndexOf>

                break;
            }

            case "rb5":
            {
                //<SnippetPointCollectionInsert>

                // Instantiating and initializing Point structures
                Point point1 = new Point(10, 10);
                Point point2 = new Point(20, 20);
                Point point3 = new Point(30, 30);
                Point point4 = new Point(40, 40);

                // Instantiating a PointCollection
                PointCollection pointCollection1 = new PointCollection();

                // Adding Points to the PointCollection
                pointCollection1.Add(point1);
                pointCollection1.Add(point2);
                pointCollection1.Add(point3);

                // pointCollection1 is equal to (10,10 20,20 30,30)

                // Inserting a Point into the PointCollection
                pointCollection1.Insert(1, point4);

                // pointCollection1 is now equal to (10,10 40,40 20,20 30,30

                //</SnippetPointCollectionInsert>

                break;
            }

            case "rb6":
            {
                //<SnippetPointCollectionRemove>

                // Instantiating and initializing Point structures
                Point point1 = new Point(10, 10);
                Point point2 = new Point(20, 20);
                Point point3 = new Point(30, 30);

                // Instantiating a PointCollection
                PointCollection pointCollection1 = new PointCollection();

                // Adding Points to PointCollection
                pointCollection1.Add(point1);
                pointCollection1.Add(point2);
                pointCollection1.Add(point3);

                // pointCollection1 is equal to (10,10 20,20 30,30)

                // Removing a Point from the PointCollection
                pointCollection1.Remove(point2);

                // pointCollection1 is equal to 10,10 30,30

                //</SnippetPointCollectionRemove>

                break;
            }

            case "rb7":
            {
                //<SnippetPointCollectionRemoveAt>

                // Instantiating and initializing Point structures
                Point point1 = new Point(10, 10);
                Point point2 = new Point(20, 20);
                Point point3 = new Point(30, 30);

                // Instantiating a PointCollection
                PointCollection pointCollection1 = new PointCollection();

                // Adding Points to the PointCollection
                pointCollection1.Add(point1);
                pointCollection1.Add(point2);
                pointCollection1.Add(point3);

                // pointCollection1 is equal to (10,10 20,20 30,30)

                // Removing a range of Points
                pointCollection1.RemoveAt(1);

                // pointCollection1 is equal to (10,10 30,30)

                //</SnippetPointCollectionRemoveAt>

                break;
            }

            case "rb8":
            {
                //<SnippetPointCollectionToString>
                string pcString;

                // Instantiating and initializing Point structures
                Point point1 = new Point(10, 10);
                Point point2 = new Point(20, 20);
                Point point3 = new Point(30, 30);

                // Instantiating a PointCollection
                PointCollection pointCollection1 = new PointCollection();

                // Adding Points to PointCollection
                pointCollection1.Add(point1);
                pointCollection1.Add(point2);
                pointCollection1.Add(point3);

                // pointCollection1 is equal to (10,10 20,20 30,30)

                // Getting a string representation of the PointCollection
                pcString = pointCollection1.ToString();


                // pcString is equal to "10,10 20,20 30,30"

                //</SnippetPointCollectionToString>


                break;
            }

            case "rb9":
            {
                break;
            }

            case "rb10":
            {
                break;
            }

            case "rb11":
            {
                break;
            }

            case "rb12":
            {
                break;
            }
            } //end switch
        }
Ejemplo n.º 18
0
        private void FunctionFilterEntry_Checked(object sender, RoutedEventArgs e)
        {
            FilterFunctionSettings.Visibility = Visibility.Visible;

            int         index = -1;
            RadioButton btn   = sender as RadioButton;

            if (btn != null)
            {
                object item = btn.DataContext;
                if (item != null)
                {
                    index = FunctionFilterEntriesList.Items.IndexOf(item);
                }
            }

            SelectedFilterEntry = functionFilterEntries[index];


            if (SelectedFilterEntry.Name == "Average Dithering") // Load function K settings
            {
                FilterFunctionDitheringSettings.Visibility = Visibility.Visible;
            }

            if (SelectedFilterEntry.Name == "Octree Color Quantization") // Load function color settings
            {
                FilterFunctionQuantizationSettings.Visibility = Visibility.Visible;
            }

            if (SelectedFilterEntry.Type == FilterEntryType.Graph) // Load function graph viewer if function graph is available in filter
            {
                FunctionFormula selectedFunctionGraph = (((SelectedFilterEntry.Filter as FunctionFilter).Function as FunctionFormula));

                //// Draw graph
                FilterFunctionGraphViewer.Visibility = Visibility.Visible;

                // Clear previous graph
                for (int p = activeDraggingPoints.Count - 1; p >= 0; p--)
                {
                    FilterFunctionGraph.Children.Remove(activeDraggingPoints[p]);
                    activeDraggingPoints.Remove(activeDraggingPoints[p]);
                }

                if (functionGraph != null)
                {
                    FilterFunctionGraph.Children.Remove(functionGraph); // Remove line
                }
                functionGraphPoints.Clear();                            // Remove line

                // Add new dragging points
                for (int p = 0; p < (selectedFunctionGraph.otherFunctionParams[0] as Graph).points.Count; p++)
                {
                    CreateDraggingPoint(p);
                }

                Ellipse CreateDraggingPoint(int p)
                {
                    Ellipse draggingPoint = new Ellipse()
                    {
                    };

                    draggingPoint.Width        = DRAGGING_POINT_SIZE;
                    draggingPoint.Height       = DRAGGING_POINT_SIZE;
                    draggingPoint.Cursor       = Cursors.Hand;
                    draggingPoint.Fill         = new SolidColorBrush(Colors.Black);
                    draggingPoint.Fill.Opacity = 0;
                    draggingPoint.Stroke       = new SolidColorBrush(Colors.Black);

                    Point canvasPoint = CalculateCanvasPositionFromPointValue((selectedFunctionGraph.otherFunctionParams[0] as Graph).points[p]);

                    Canvas.SetLeft(draggingPoint, canvasPoint.X);
                    Canvas.SetTop(draggingPoint, canvasPoint.Y);
                    Panel.SetZIndex(draggingPoint, 5); // Higher means top

                    draggingPoint.MouseLeftButtonDown += (senderPoint, argsPoint) =>
                    {
                        activeDraggingPoint        = draggingPoint;
                        draggingPoint.Fill.Opacity = 1;

                        drag = true;                                                                     // start dragging
                        draggingStartPoint = Mouse.GetPosition(FilterFunctionGraph);                     // save start point of dragging
                        int draggedItemIndex = activeDraggingPoints.IndexOf(senderPoint as Ellipse);
                        if (draggedItemIndex != 0 && draggedItemIndex != activeDraggingPoints.Count - 1) //If not first or last
                        {
                            previousDraggingPoint = activeDraggingPoints[draggedItemIndex - 1];
                            nextDraggingPoint     = activeDraggingPoints[draggedItemIndex + 1];
                        }
                    };
                    draggingPoint.MouseMove += (senderPoint, argsPoint) =>
                    {
                        // if dragging, then adjust rectangle position based on mouse movement
                        if (drag)
                        {
                            Ellipse draggedItem      = senderPoint as Ellipse;
                            int     draggedItemIndex = activeDraggingPoints.IndexOf(senderPoint as Ellipse);

                            Point newPoint = Mouse.GetPosition(FilterFunctionGraph);

                            // Restrain dragging
                            if (newPoint.Y < 0)
                            {
                                newPoint.Y = 0;
                            }
                            if (newPoint.Y > FilterFunctionGraph.ActualHeight + DRAGGING_POINT_SIZE / 2)
                            {
                                newPoint.Y = FilterFunctionGraph.ActualHeight + DRAGGING_POINT_SIZE / 2;
                            }

                            if (draggedItemIndex != 0 && draggedItemIndex != activeDraggingPoints.Count - 1) //If not first or last
                            {
                                double previousDraggingPointX = Canvas.GetLeft(previousDraggingPoint) + MINIMAL_DRAGGING_POINT_MARGIN + DRAGGING_POINT_SIZE / 2;
                                double nextDraggingPointX     = Canvas.GetLeft(nextDraggingPoint) - MINIMAL_DRAGGING_POINT_MARGIN + DRAGGING_POINT_SIZE / 2;
                                if (newPoint.X < previousDraggingPointX)
                                {
                                    newPoint.X = previousDraggingPointX;
                                }
                                if (newPoint.X > nextDraggingPointX)
                                {
                                    newPoint.X = nextDraggingPointX;
                                }
                            }

                            double left = Canvas.GetLeft(draggedItem);
                            double top  = Canvas.GetTop(draggedItem);

                            double newLeft = left;
                            if (draggedItemIndex != 0 && draggedItemIndex != activeDraggingPoints.Count - 1) //If not first or last
                            {
                                newLeft += (newPoint.X - draggingStartPoint.X);
                            }

                            double newTop = top + (newPoint.Y - draggingStartPoint.Y);
                            Canvas.SetLeft(draggedItem, newLeft);
                            Canvas.SetTop(draggedItem, newTop);

                            // Update line
                            functionGraphPoints[draggedItemIndex] = new Point(newLeft + DRAGGING_POINT_SIZE / 2, newTop + DRAGGING_POINT_SIZE / 2);
                            functionGraph.Points = functionGraphPoints;


                            draggingStartPoint = newPoint;
                        }
                    };
                    draggingPoint.MouseLeftButtonUp += (senderPoint, argsPoint) =>
                    {
                        StopDraggingPoint(senderPoint, selectedFunctionGraph);
                    };
                    draggingPoint.MouseLeave += (senderPoint, argsPoint) =>
                    {
                        StopDraggingPoint(senderPoint, selectedFunctionGraph);
                    };

                    FilterFunctionGraph.Children.Insert(p, draggingPoint); // Draw points on canvas
                    activeDraggingPoints.Insert(p, draggingPoint);

                    return(draggingPoint);
                }

                // Draw line on canvas
                functionGraphPoints = new PointCollection();
                for (int i = 0; i < activeDraggingPoints.Count; i++)
                {
                    Ellipse draggingPoint         = activeDraggingPoints[i];
                    Point   draggingPointPosition = new Point(Canvas.GetLeft(draggingPoint) + DRAGGING_POINT_SIZE / 2, Canvas.GetTop(draggingPoint) + DRAGGING_POINT_SIZE / 2);
                    functionGraphPoints.Add(draggingPointPosition);
                }
                functionGraph                 = new Polyline();
                functionGraph.Points          = functionGraphPoints;
                functionGraph.Stroke          = new SolidColorBrush(Colors.Black);
                functionGraph.StrokeThickness = 1.5;

                functionGraph.Cursor = Cursors.Hand;

                functionGraph.MouseLeftButtonDown += (object sender2, MouseButtonEventArgs e2) => {
                    Point mousePosition = e2.GetPosition(FilterFunctionGraph);

                    //Calculate new point value
                    Point newGraphPoint = CalculatePointValueFromCanvasPosition(new Point(mousePosition.X - DRAGGING_POINT_SIZE / 2, mousePosition.Y + DRAGGING_POINT_SIZE / 2));

                    // Add new point to graph function
                    int graphPointIndex = (((SelectedFilterEntry.Filter as FunctionFilter).Function as FunctionFormula).otherFunctionParams[0] as Graph).AddPoint(new GraphPoint((int)newGraphPoint.X, (int)newGraphPoint.Y));

                    Ellipse draggingPoint = CreateDraggingPoint(graphPointIndex);

                    //Deselect active dragging point and select this one
                    SelectActiveDraggingPoint(draggingPoint);

                    // Update line
                    Point draggingPointPosition = new Point(Canvas.GetLeft(draggingPoint) + DRAGGING_POINT_SIZE / 2, Canvas.GetTop(draggingPoint) + DRAGGING_POINT_SIZE / 2);
                    functionGraphPoints.Insert(graphPointIndex, draggingPointPosition);
                    functionGraph.Points = functionGraphPoints;
                };
                FilterFunctionGraph.Children.Add(functionGraph);
            }
            else // For filters that do not have function graph available
            {
                FilterFunctionGraphViewer.Visibility = Visibility.Collapsed;
            }
        }