public void LayoutRespecting(Graphics go, ChronodexSector prev) { Font stringFont = new Font("Monoid", 12); SizeF stringSize = new SizeF(); RectangleF labelRectangle = prev.LabelRectangle; int maxWidth = (int)Math.Min(_calloutEnd.X, (1200-_calloutEnd.X)); int i = 0; if (prev.Area == _area) { for (i=0; i < _styles.Length; i++) { if (_styles[i] == prev.HatchType) { _hatchType = _styles[(i+1) % _styles.Length]; break; } } } do { stringSize = go.MeasureString(_description, stringFont, maxWidth); // adjust callout line length _calloutEnd = new PointF(615.0f + (float)Math.Cos((_angleMiddle + i * 3.75f) * Math.PI / 180) * 380 , 509.0f + (float)Math.Sin((_angleMiddle + i * 3.75f) * Math.PI / 180) * 380 ); // adjust label rectangle dimensions PointF calloutPosition = new PointF(); if (_angleMiddle > 90 && _angleMiddle <= 270) { calloutPosition.X = _calloutEnd.X - stringSize.Width; maxWidth = (int)_calloutEnd.X; } else { calloutPosition.X = _calloutEnd.X; maxWidth = (int)(1200 - _calloutEnd.X); } calloutPosition.Y = _calloutEnd.Y - stringSize.Height; _labelRectangle = new RectangleF(calloutPosition, stringSize); i += 1; } while (_labelRectangle.IntersectsWith(labelRectangle)); _layedOut = true; }
private static void DrawChronodexSector(ChronodexSector cs, Graphics go) { GraphicsPath gp = new GraphicsPath(); gp.AddArc(levels[(int)cs.Focus], angles[cs.StartTime], cs.Duration * 7.5f); gp.AddArc(levels[0], angles[cs.StartTime], cs.Duration * 7.5f); gp.AddLine(gp.PathPoints[0], gp.PathPoints[4]); gp.AddLine(gp.PathPoints[3], gp.PathPoints[7]); HatchBrush brush = new HatchBrush(cs.HatchType, colors[cs.Area], Color.Transparent); go.FillPath(brush, gp); gp.Dispose(); if (cs.Description != string.Empty) { Font stringFont = new Font("Monoid", 12); SolidBrush textBrush = new SolidBrush(colors[cs.Area]); go.DrawString(cs.Description, stringFont, textBrush, cs.LabelRectangle); Pen pen = new Pen(colors[cs.Area], 4.0f); go.DrawLine(pen, cs.CentralPoint, cs.CalloutEnd); go.DrawLine(pen, new PointF(cs.LabelRectangle.Left, cs.LabelRectangle.Bottom), new PointF(cs.LabelRectangle.Right, cs.LabelRectangle.Bottom)); } }