Exemplo n.º 1
0
        /// <summary>
        /// Gets the symbol for the datapoint.
        /// </summary>
        /// <param name="graphPoint">Point at which the symbol needs to be positioned.</param>
        /// <returns>A symbol at a specified position.</returns>
        protected override FrameworkElement GetPlottedDataMarker(GraphPoint graphPoint)
        {
            FrameworkElement dataMarkerTemplate = this.DataMarkerTemplate.LoadContent() as FrameworkElement;

            if (dataMarkerTemplate == null)
            {
                throw new ArgumentException(GraphingResources.GraphDisplayDataMarkerError);
            }

            Canvas.SetLeft(dataMarkerTemplate, graphPoint.X1Pixel + GraphBase.GetXOffset(dataMarkerTemplate));
            Canvas.SetTop(dataMarkerTemplate, graphPoint.Y1Pixel + GraphBase.GetYOffset(dataMarkerTemplate));

            if (true == this.DebugDataPointMarkers)
            {
                TextBlock tb = new TextBlock();
                tb.FontSize = 8;
                markerCount++;
                tb.Text = (markerCount - markerCountStart).ToString(System.Globalization.CultureInfo.InvariantCulture);
                Canvas.SetZIndex(tb, markerCount);
                Canvas.SetLeft(tb, graphPoint.X1Pixel);
                Canvas.SetTop(tb, graphPoint.Y1Pixel);
                this.DynamicPlotLayer.Children.Add(tb);
                System.Diagnostics.Debug.WriteLine("Added point at " + graphPoint.X1Pixel + " : " + graphPoint.Y1Pixel + " : " + dataMarkerTemplate.ActualHeight + " : " + dataMarkerTemplate.ActualWidth + " Point ID IS : " + tb.Text);
            }

            GraphBase.SetDataPoint(dataMarkerTemplate, true);
            dataMarkerTemplate.Tag = (markerCount - markerCountStart).ToString(System.Globalization.CultureInfo.InvariantCulture);
            return(dataMarkerTemplate);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Doeses the element clash.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <returns>The clash element.</returns>
        private FrameworkElement DoesElementClash(FrameworkElement element)
        {
            FrameworkElement result     = null;
            double           leftPointX = Canvas.GetLeft(element);

            double elementWidth = 0;

            elementWidth = element.ActualWidth;
            if (0 == element.ActualWidth)
            {
                element.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
                elementWidth = element.DesiredSize.Width;
            }

            for (int x = (int)(leftPointX + elementWidth); x >= (int)leftPointX; x--)
            {
                if (true == this.elementLookupToX.ContainsKey(x))
                {
                    foreach (FrameworkElement clashElement in this.elementLookupToX[x])
                    {
                        if (clashElement != element)
                        {
                            // check the X as well because we register against an Int
                            // not a double, so it is possible they do not overlap
                            // as one may finish at say 6.2, and the next might start at 6.4.
                            double clashElementWidth = 0;
                            clashElementWidth = clashElement.ActualWidth;
                            if (0 == clashElement.ActualWidth)
                            {
                                clashElement.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
                                clashElementWidth = clashElement.DesiredSize.Width;
                            }

                            double clashElementLeft = Canvas.GetLeft(clashElement);
                            double elementLeft      = Canvas.GetLeft(element);

                            // the middle point should fall in betweent eh left and right if this is to be a collision.
                            double leftPoint   = 0;
                            double middlePoint = 0;
                            double rightPoint  = 0;

                            bool performHeightChecks = false;

                            // if non of these then they are the same and must overlap on X
                            if (clashElementLeft < elementLeft)
                            {
                                // clash element right point should be between start and end point of element
                                middlePoint = elementLeft;
                                leftPoint   = clashElementLeft;
                                rightPoint  = clashElementLeft + clashElementWidth;
                            }
                            else if (clashElementLeft > elementLeft)
                            {
                                // element right point should be between start and end point of clash element
                                middlePoint = clashElementLeft;
                                leftPoint   = elementLeft;
                                rightPoint  = elementLeft + elementWidth;
                            }
                            else
                            {
                                // they are at same x position.
                                performHeightChecks = true;
                            }

                            if (middlePoint > leftPoint && middlePoint < rightPoint)
                            {
                                performHeightChecks = true;
                            }

                            if (true == performHeightChecks)
                            {
                                double clashHeight   = clashElement.ActualHeight;
                                double elementHeight = element.ActualHeight;

                                if (0 == clashHeight)
                                {
                                    clashElement.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
                                    clashHeight = clashElement.DesiredSize.Height;
                                }

                                if (0 == elementHeight)
                                {
                                    element.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
                                    elementHeight = element.DesiredSize.Height;
                                }

                                double topOfClash    = Canvas.GetTop(clashElement);
                                double bottomOfClash = topOfClash + clashHeight;

                                double topOfElement    = Canvas.GetTop(element);
                                double bottomOfElement = topOfElement + elementHeight;

                                if ((topOfElement >= topOfClash && topOfElement <= bottomOfClash) ||
                                    (bottomOfElement >= topOfClash && bottomOfElement <= bottomOfClash))
                                {
                                    // we have a clash
                                    result = clashElement;
                                }

                                if ((topOfClash >= topOfElement && topOfClash <= bottomOfElement) ||
                                    (bottomOfClash >= topOfElement && bottomOfClash <= bottomOfElement))
                                {
                                    // we have a clash
                                    result = clashElement;
                                }

                                if (false == GraphBase.GetDataPoint(clashElement))
                                {
                                    // this element is a label
                                    if (true == GraphBase.GetDataPointOverlapProperty(clashElement))
                                    {
                                        // this element will not be visible so it does not clash
                                        result = null;
                                    }
                                }
                            }

                            if (null != result)
                            {
                                break;
                            }
                        }
                    }
                }

                if (null != result)
                {
                    break;
                }
            }

            return(result);
        }