void Place(LabelState label)
        {
            if (label.IsVisible && label.IsMovable)
            {
                var sz         = label.Size;
                var min_offset = Math.Sqrt(sz.Width * sz.Width + sz.Height * sz.Height);

                var range = MaxOffset - min_offset;
                if (range < 0)
                {
                    range = 0;
                }
                var offset = min_offset + rnd.NextDouble() * range;

                double angle = 0;

                if (Angles != null && Angles.Count > 0)
                {
                    angle = Angles[rnd.Next(Angles.Count)] * Math.PI / 180;
                }
                else
                {
                    angle = rnd.NextDouble() * Math.PI * 2;
                }

                var center = new Point(label.Point.X + offset * Math.Cos(angle), label.Point.Y + offset * Math.Sin(angle));

                label.Position = new Point(center.X - 0.5 * sz.Width, center.Y - 0.5 * sz.Height);
            }
        }
Beispiel #2
0
        // set label position relatively to anchor point
        static void SetPosition(LabelState label, LabelPosition position)
        {
            if (!label.IsMovable)
            {
                return;
            }

            var sz = label.Size;

            switch (position)
            {
            case LabelPosition.TopLeft:
                label.Position = label.Point;
                break;

            case LabelPosition.TopRight:
                label.Position = new Point(label.Point.X - sz.Width, label.Point.Y);
                break;

            case LabelPosition.BottomLeft:
                label.Position = new Point(label.Point.X, label.Point.Y - sz.Height);
                break;

            case LabelPosition.BottomRight:
                label.Position = new Point(label.Point.X - sz.Width, label.Point.Y - sz.Height);
                break;
            }
        }
Beispiel #3
0
        static double GetDistanceFromBorder(LabelState label, Rect border)
        {
            var pt = label.Point;
            var dx = Math.Min(pt.X - border.Left, border.Right - pt.X);
            var dy = Math.Min(pt.Y - border.Top, border.Bottom - pt.Y);

            return(Math.Min(dx, dy));
        }
 internal static LabelState[] CreateState(IList<ILabel> labels)
 {
     int cnt = labels.Count;
       var state = new LabelState[cnt];
       for (int i = 0; i < cnt; i++)
     state[i] = new LabelState(labels[i]);
       return state;
 }
Beispiel #5
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);
        }
Beispiel #6
0
        internal static LabelState[] CreateState(IList <ILabel> labels)
        {
            int cnt   = labels.Count;
            var state = new LabelState[cnt];

            for (int i = 0; i < cnt; i++)
            {
                state[i] = new LabelState(labels[i]);
            }
            return(state);
        }
Beispiel #7
0
        // set label position relatively to anchor point with specified angle and offset
        static void SetPosition(LabelState label, double angle, double offset)
        {
            if (!label.IsMovable)
            {
                return;
            }

            angle = angle * Math.PI / 180;

            var sz     = label.Size;
            var center = new Point(label.Point.X + offset * Math.Cos(angle), label.Point.Y + offset * Math.Sin(angle));

            label.Position = new Point(center.X - 0.5 * sz.Width, center.Y - 0.5 * sz.Height);
        }
Beispiel #8
0
 static int CompareLabelsByDistanceFromBorder(LabelState label1, LabelState label2)
 {
     return(Math.Sign(label1.DistanceFromBorder - label2.DistanceFromBorder));
 }
        // set label position relatively to anchor point with specified angle and offset
        static void SetPosition(LabelState label, double angle, double offset)
        {
            if (!label.IsMovable)
            return;

              angle = angle * Math.PI / 180;

              var sz = label.Size;
              var center = new Point(label.Point.X + offset * Math.Cos(angle), label.Point.Y + offset * Math.Sin(angle));

              label.Position = new Point(center.X - 0.5 * sz.Width, center.Y - 0.5 * sz.Height);
        }
        // set label position relatively to anchor point
        static void SetPosition(LabelState label, LabelPosition position)
        {
            if (!label.IsMovable)
            return;

              var sz = label.Size;

              switch (position)
              {
            case LabelPosition.TopLeft:
              label.Position = label.Point;
              break;
            case LabelPosition.TopRight:
              label.Position = new Point(label.Point.X - sz.Width, label.Point.Y);
              break;
            case LabelPosition.BottomLeft:
              label.Position = new Point(label.Point.X, label.Point.Y - sz.Height);
              break;
            case LabelPosition.BottomRight:
              label.Position = new Point(label.Point.X - sz.Width, label.Point.Y - sz.Height);
              break;
              }
        }
        // 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;
        }
        static double GetDistanceFromBorder(LabelState label, Rect border)
        {
            var pt = label.Point;
              var dx = Math.Min(pt.X - border.Left, border.Right - pt.X);
              var dy = Math.Min(pt.Y - border.Top, border.Bottom - pt.Y);

              return Math.Min(dx, dy);
        }
 static int CompareLabelsByDistanceFromBorder(LabelState label1, LabelState label2)
 {
     return Math.Sign( label1.DistanceFromBorder - label2.DistanceFromBorder);
 }
        void Place(LabelState label)
        {
            if( label.IsVisible && label.IsMovable)
              {
            var sz = label.Size;
            var min_offset = Math.Sqrt(sz.Width * sz.Width + sz.Height * sz.Height);

            var range = MaxOffset - min_offset;
            if (range < 0)
              range = 0;
            var offset = min_offset + rnd.NextDouble() * range;

            double angle = 0;

            if (Angles != null && Angles.Count > 0)
              angle = Angles[rnd.Next(Angles.Count)] * Math.PI / 180;
            else
              angle = rnd.NextDouble() * Math.PI * 2;

            var center = new Point(label.Point.X + offset * Math.Cos(angle), label.Point.Y + offset * Math.Sin(angle));

            label.Position = new Point(center.X - 0.5 * sz.Width, center.Y - 0.5 * sz.Height);
              }
        }