int GetConnectionConflicts(IList <LabelState> lbls)
        {
            int ncon = 0;

            int len = lbls.Count;

            for (int i = 0; i < len; i++)
            {
                if (lbls[i].IsVisible)
                {
                    for (int j = 0; j < len; j++)
                    {
                        if (i != j && lbls[j].IsVisible)
                        {
                            if (!LabelHelper.Intersect(lbls[i].Point, lbls[i].GetConnectingPoint(), lbls[j].Point, lbls[j].GetConnectingPoint()).IsEmpty())
                            {
                                lbls[i].Energy += wRectConflict;
                                lbls[j].Energy += wRectConflict;
                                ncon++;
                            }
                        }
                    }
                }
            }

            return(ncon * wRectConflict);
        }
Esempio n. 2
0
        // verify whether the current label position is good relatively to the other labels
        static bool IsGoodPosition(LabelState lbl, Rect border, LabelState[] labels, IList <Rect> rects, int index)
        {
            // check border
            if (!Contains(lbl, border))
            {
                return(false);
            }

            if (rects != null)
            {
                int cnt = rects.Count;
                for (int i = 0; i < cnt; i++)
                {
                    if (Intersect(lbl, rects[i]))
                    {
                        return(false);
                    }
                }
            }

            // check other anchor points
            int len = labels.Length;

            for (int i = 0; i < len; i++)
            {
                if (i != index)
                {
                    if (IntersectPoint(lbl, labels[i].Point))
                    {
                        return(false);
                    }
                }
            }

            for (int i = 0; i < index; i++)
            {
                // check already placed labels
                if (labels[i].IsVisible)
                {
                    // label rectangle
                    if (Intersect(lbl, labels[i]))
                    {
                        return(false);
                    }

                    // connecting lines
                    if (!LabelHelper.Intersect(lbl.Point, lbl.GetConnectingPoint(), labels[i].Point, labels[i].GetConnectingPoint()).IsEmpty())
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
        void Render()
        {
            if (!_loaded || UpdateCount > 0)
            {
                return;
            }

            if (Chart != null)
            {
                var prect = Chart.View.PlotRect;
                var bnds  = new Rect(0, 0, prect.Width, prect.Height);
                bnds.Inflate(1, 1);

                var offset = Chart.TranslatePoint(new Point(), (UIElement)this.Parent);
                offset.X = prect.X - offset.X;
                offset.Y = prect.Y - offset.Y;

                foreach (var label in Children)
                {
                    if (!base.Children.Contains(label))
                    {
                        base.Children.Add(label);
                    }
                    var line = label.ConnectingLine;
                    if (!base.Children.Contains(line))
                    {
                        base.Children.Add(line);
                    }


                    if (!Chart.ChartType.ToString().StartsWith("Pie"))
                    {
                        label.UpdateAttachPoint(Chart, offset);

                        if (bnds.Contains(label.AttachPoint))
                        {
                            label.Visibility = Visibility.Visible;
                        }
                        else
                        {
                            label.Visibility = Visibility.Collapsed;
                        }
                    }
                    else
                    {
                        label.UpdateAttachPoint(Chart, new Point());
                    }
                }

                if (LabelArranger != null)
                {
                    LabelArranger.Arrange(Children.ToArray(), OccupiedRects, new Rect(0, 0, prect.Width, prect.Height));
                }

                foreach (var label in Children)
                {
                    var line = label.ConnectingLine;
                    var pt   = label.AttachPoint;

                    line.X1 = pt.X; line.Y1 = pt.Y;

                    var pt1 = LabelHelper.GetConnectingPoint(label);

                    if (!double.IsNaN(pt1.X) && !double.IsNaN(pt1.Y))
                    {
                        line.X2 = pt1.X; line.Y2 = pt1.Y;
                    }
                }

                _state = new ChartState(Chart);
            }
        }