1 //-------------------------------------------------------------
2 // <copyright company=
\92Microsoft Corporation
\92>
3 // Copyright © Microsoft Corporation. All Rights Reserved.
5 //-------------------------------------------------------------
6 // @owner=alexgor, deliant
7 //=================================================================
8 // File: GroupAnnotation.cs
10 // Namespace: System.Web.UI.WebControls[Windows.Forms].Charting
12 // Classes: AnnotationGroup
14 // Purpose: Annotation group class.
18 //===================================================================
20 #region Used namespace
22 using System.Collections;
23 using System.Collections.Specialized;
24 using System.ComponentModel;
25 using System.ComponentModel.Design;
28 using System.Drawing.Design;
29 using System.Drawing.Text;
30 using System.Drawing.Drawing2D;
32 using System.Windows.Forms;
33 using System.Windows.Forms.DataVisualization.Charting;
34 using System.Windows.Forms.DataVisualization.Charting.Data;
35 using System.Windows.Forms.DataVisualization.Charting.ChartTypes;
36 using System.Windows.Forms.DataVisualization.Charting.Utilities;
37 using System.Windows.Forms.DataVisualization.Charting.Borders3D;
42 using System.Web.UI.DataVisualization.Charting;
43 using System.Web.UI.DataVisualization.Charting.Data;
44 using System.Web.UI.DataVisualization.Charting.Utilities;
51 namespace System.Windows.Forms.DataVisualization.Charting
54 namespace System.Web.UI.DataVisualization.Charting
59 /// <b>AnnotationGroup</b> is a class that represents an annotation group.
62 /// This class is a collection of annotations, and can be used
63 /// to manipulate annotations relative to each other.
66 SRDescription("DescriptionAttributeAnnotationGroup_AnnotationGroup"),
69 [AspNetHostingPermission(System.Security.Permissions.SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
70 [AspNetHostingPermission(System.Security.Permissions.SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
72 public class AnnotationGroup : Annotation
76 // Collection of annotations in the group
77 internal AnnotationCollection annotations = null;
81 #region Construction and Initialization
84 /// Default public constructor.
86 public AnnotationGroup()
89 annotations = new AnnotationCollection(this);
90 annotations.AnnotationGroup = this;
95 #region Miscellaneous Properties
98 /// Gets or sets the name of the chart area which an annotation is clipped to.
101 /// A string which represents the name of an existing chart area.
104 /// If the chart area name is specified, an annotation will only be drawn inside the
105 /// plotting area of the chart area specified. All parts of the annotation
106 /// outside of the plotting area will be clipped.
108 /// To disable chart area clipping, set the property to "NotSet" or an empty string.
112 SRCategory("CategoryAttributeMisc"),
113 DefaultValue(Constants.NotSetValue),
114 SRDescription("DescriptionAttributeAnnotationGroup_ClipToChartArea"),
115 TypeConverter(typeof(LegendAreaNameConverter)),
118 override public string ClipToChartArea
122 return base.ClipToChartArea;
126 base.ClipToChartArea = value;
127 foreach(Annotation annotation in this.annotations)
129 annotation.ClipToChartArea = value;
136 #region Position Properties
139 /// Gets or sets a flag that specifies whether the size of an annotation is always
140 /// defined in relative chart coordinates.
141 /// <seealso cref="Annotation.Width"/>
142 /// <seealso cref="Annotation.Height"/>
145 /// <b>True</b> if an annotation's <see cref="Annotation.Width"/> and <see cref="Annotation.Height"/> are always
146 /// in chart relative coordinates, <b>false</b> otherwise.
149 /// An annotation's width and height may be set in relative chart or axes coordinates.
150 /// By default, relative chart coordinates are used.
152 /// To use axes coordinates for size set the <b>IsSizeAlwaysRelative</b> property to
153 /// <b>false</b> and either anchor the annotation to a data point or set the
154 /// <see cref="Annotation.AxisX"/> or <see cref="Annotation.AxisY"/> properties.
158 SRCategory("CategoryAttributePosition"),
160 SRDescription("DescriptionAttributeAnnotationGroup_SizeAlwaysRelative"),
162 override public bool IsSizeAlwaysRelative
166 return base.IsSizeAlwaysRelative;
170 base.IsSizeAlwaysRelative = value;
176 #region Visual Properties
178 #if Microsoft_CONTROL
180 /// Gets or sets a flag that determines if an annotation is selected.
181 /// <seealso cref="Annotation.AllowSelecting"/>
184 /// <b>True</b> if the annotation is selected, <b>false</b> otherwise.
188 /// Gets or sets a flag that determines if an annotation is selected.
191 /// <b>True</b> if the annotation is selected, <b>false</b> otherwise.
193 #endif // Microsoft_CONTROL
195 SRCategory("CategoryAttributeAppearance"),
198 SRDescription("DescriptionAttributeAnnotationGroup_Selected"),
200 override public bool IsSelected
204 return base.IsSelected;
208 base.IsSelected = value;
210 // Clear selection for all annotations in the group
211 foreach(Annotation annotation in this.annotations)
213 annotation.IsSelected = false;
219 /// Gets or sets a flag that specifies whether an annotation is visible.
222 /// <b>True</b> if the annotation is visible, <b>false</b> otherwise.
225 SRCategory("CategoryAttributeAppearance"),
227 SRDescription("DescriptionAttributeAnnotationGroup_Visible"),
228 ParenthesizePropertyNameAttribute(true),
230 override public bool Visible
238 base.Visible = value;
243 /// Gets or sets an annotation's content alignment.
246 /// A <see cref="ContentAlignment"/> value that represents the content alignment.
249 /// This property is used to align text for <see cref="TextAnnotation"/>, <see cref="RectangleAnnotation"/>,
250 /// <see cref="EllipseAnnotation"/> and <see cref="CalloutAnnotation"/> objects, and to align
251 /// a non-scaled image inside an <see cref="ImageAnnotation"/> object.
254 SRCategory("CategoryAttributeAppearance"),
255 DefaultValue(typeof(ContentAlignment), "MiddleCenter"),
256 SRDescription("DescriptionAttributeAlignment"),
259 override public ContentAlignment Alignment
263 return base.Alignment;
267 base.Alignment = value;
268 foreach(Annotation annotation in this.annotations)
270 annotation.Alignment = value;
276 /// Gets or sets an annotation's text style.
277 /// <seealso cref="Font"/>
278 /// <seealso cref="ForeColor"/>
281 /// A <see cref="TextStyle"/> value used to draw an annotation's text.
284 [EditorBrowsable(EditorBrowsableState.Never)]
285 public override TextStyle TextStyle
289 return base.TextStyle;
293 base.TextStyle = value;
298 /// Gets or sets the text color of an annotation.
299 /// <seealso cref="Font"/>
302 /// A <see cref="Color"/> value used for the text color of an annotation.
305 SRCategory("CategoryAttributeAppearance"),
306 DefaultValue(typeof(Color), "Black"),
307 SRDescription("DescriptionAttributeForeColor"),
308 TypeConverter(typeof(ColorConverter)),
309 Editor(Editors.ChartColorEditor.Editor, Editors.ChartColorEditor.Base),
312 override public Color ForeColor
316 return base.ForeColor;
320 base.ForeColor = value;
321 foreach(Annotation annotation in this.annotations)
323 annotation.ForeColor = value;
329 /// Gets or sets the font of an annotation's text.
330 /// <seealso cref="ForeColor"/>
333 /// A <see cref="Font"/> object used for an annotation's text.
336 SRCategory("CategoryAttributeAppearance"),
337 DefaultValue(typeof(Font), "Microsoft Sans Serif, 8pt"),
338 SRDescription("DescriptionAttributeTextFont"),
341 override public Font Font
350 foreach(Annotation annotation in this.annotations)
352 annotation.Font = value;
358 /// Gets or sets the color of an annotation line.
359 /// <seealso cref="LineWidth"/>
360 /// <seealso cref="LineDashStyle"/>
363 /// A <see cref="Color"/> value used to draw an annotation line.
366 SRCategory("CategoryAttributeAppearance"),
367 DefaultValue(typeof(Color), "Black"),
368 SRDescription("DescriptionAttributeLineColor"),
369 TypeConverter(typeof(ColorConverter)),
370 Editor(Editors.ChartColorEditor.Editor, Editors.ChartColorEditor.Base),
373 override public Color LineColor
377 return base.LineColor;
381 base.LineColor = value;
382 foreach(Annotation annotation in this.annotations)
384 annotation.LineColor = value;
390 /// Gets or sets the width of an annotation line.
391 /// <seealso cref="LineColor"/>
392 /// <seealso cref="LineDashStyle"/>
395 /// An integer value defining the width of an annotation line in pixels.
398 SRCategory("CategoryAttributeAppearance"),
400 SRDescription("DescriptionAttributeLineWidth"),
403 override public int LineWidth
407 return base.LineWidth;
411 base.LineWidth = value;
412 foreach(Annotation annotation in this.annotations)
414 annotation.LineWidth = value;
420 /// Gets or sets the style of an annotation line.
421 /// <seealso cref="LineWidth"/>
422 /// <seealso cref="LineColor"/>
425 /// A <see cref="ChartDashStyle"/> value used to draw an annotation line.
428 SRCategory("CategoryAttributeAppearance"),
429 DefaultValue(ChartDashStyle.Solid),
430 SRDescription("DescriptionAttributeLineDashStyle"),
433 override public ChartDashStyle LineDashStyle
437 return base.LineDashStyle;
441 base.LineDashStyle = value;
442 foreach(Annotation annotation in this.annotations)
444 annotation.LineDashStyle = value;
450 /// Gets or sets the background color of an annotation.
451 /// <seealso cref="BackSecondaryColor"/>
452 /// <seealso cref="BackHatchStyle"/>
453 /// <seealso cref="BackGradientStyle"/>
456 /// A <see cref="Color"/> value used for the background of an annotation.
459 SRCategory("CategoryAttributeAppearance"),
460 DefaultValue(typeof(Color), ""),
461 SRDescription("DescriptionAttributeBackColor"),
462 NotifyParentPropertyAttribute(true),
463 TypeConverter(typeof(ColorConverter)),
464 Editor(Editors.ChartColorEditor.Editor, Editors.ChartColorEditor.Base),
467 override public Color BackColor
471 return base.BackColor;
475 base.BackColor = value;
476 foreach(Annotation annotation in this.annotations)
478 annotation.BackColor = value;
484 /// Gets or sets the background hatch style of an annotation.
485 /// <seealso cref="BackSecondaryColor"/>
486 /// <seealso cref="BackColor"/>
487 /// <seealso cref="BackGradientStyle"/>
490 /// A <see cref="ChartHatchStyle"/> value used for the background of an annotation.
493 /// Two colors are used to draw the hatching, <see cref="BackColor"/> and <see cref="BackSecondaryColor"/>.
496 SRCategory("CategoryAttributeAppearance"),
497 DefaultValue(ChartHatchStyle.None),
498 NotifyParentPropertyAttribute(true),
499 SRDescription("DescriptionAttributeBackHatchStyle"),
500 Editor(Editors.HatchStyleEditor.Editor, Editors.HatchStyleEditor.Base),
503 override public ChartHatchStyle BackHatchStyle
507 return base.BackHatchStyle;
511 base.BackHatchStyle = value;
512 foreach(Annotation annotation in this.annotations)
514 annotation.BackHatchStyle = value;
520 /// Gets or sets the background gradient style of an annotation.
521 /// <seealso cref="BackSecondaryColor"/>
522 /// <seealso cref="BackColor"/>
523 /// <seealso cref="BackHatchStyle"/>
526 /// A <see cref="GradientStyle"/> value used for the background of an annotation.
529 /// Two colors are used to draw the gradient, <see cref="BackColor"/> and <see cref="BackSecondaryColor"/>.
532 SRCategory("CategoryAttributeAppearance"),
533 DefaultValue(GradientStyle.None),
534 NotifyParentPropertyAttribute(true),
535 SRDescription("DescriptionAttributeBackGradientStyle"),
536 Editor(Editors.GradientEditor.Editor, Editors.GradientEditor.Base),
539 override public GradientStyle BackGradientStyle
543 return base.BackGradientStyle;
547 base.BackGradientStyle = value;
548 foreach(Annotation annotation in this.annotations)
550 annotation.BackGradientStyle = value;
556 /// Gets or sets the secondary background color of an annotation.
557 /// <seealso cref="BackColor"/>
558 /// <seealso cref="BackHatchStyle"/>
559 /// <seealso cref="BackGradientStyle"/>
562 /// A <see cref="Color"/> value used for the secondary color of an annotation background with
563 /// hatching or gradient fill.
566 /// This color is used with <see cref="BackColor"/> when <see cref="BackHatchStyle"/> or
567 /// <see cref="BackGradientStyle"/> are used.
570 SRCategory("CategoryAttributeAppearance"),
571 DefaultValue(typeof(Color), ""),
572 NotifyParentPropertyAttribute(true),
573 SRDescription("DescriptionAttributeBackSecondaryColor"),
574 TypeConverter(typeof(ColorConverter)),
575 Editor(Editors.ChartColorEditor.Editor, Editors.ChartColorEditor.Base),
578 override public Color BackSecondaryColor
582 return base.BackSecondaryColor;
586 base.BackSecondaryColor = value;
587 foreach(Annotation annotation in this.annotations)
589 annotation.BackSecondaryColor = value;
595 /// Gets or sets the color of an annotation's shadow.
596 /// <seealso cref="ShadowOffset"/>
599 /// A <see cref="Color"/> value used to draw an annotation's shadow.
602 SRCategory("CategoryAttributeAppearance"),
603 DefaultValue(typeof(Color), "128,0,0,0"),
604 SRDescription("DescriptionAttributeShadowColor"),
605 TypeConverter(typeof(ColorConverter)),
606 Editor(Editors.ChartColorEditor.Editor, Editors.ChartColorEditor.Base),
609 override public Color ShadowColor
613 return base.ShadowColor;
617 base.ShadowColor = value;
618 foreach(Annotation annotation in this.annotations)
620 annotation.ShadowColor = value;
626 /// Gets or sets the offset between an annotation and its shadow.
627 /// <seealso cref="ShadowColor"/>
630 /// An integer value that represents the offset between an annotation and its shadow.
633 SRCategory("CategoryAttributeAppearance"),
635 SRDescription("DescriptionAttributeShadowOffset"),
638 override public int ShadowOffset
642 return base.ShadowOffset;
646 base.ShadowOffset = value;
647 foreach(Annotation annotation in this.annotations)
649 annotation.ShadowOffset = value;
656 #region Editing Permissions Properties
658 #if Microsoft_CONTROL
661 /// Gets or sets a flag that specifies whether an annotation may be selected
662 /// with a mouse by the end user.
665 /// <b>True</b> if the annotation may be selected, <b>false</b> otherwise.
668 SRCategory("CategoryAttributeEditing"),
670 SRDescription("DescriptionAttributeAllowSelecting"),
672 override public bool AllowSelecting
676 return base.AllowSelecting;
680 base.AllowSelecting = value;
685 /// Gets or sets a flag that specifies whether an annotation may be moved
686 /// with a mouse by the end user.
689 /// <b>True</b> if the annotation may be moved, <b>false</b> otherwise.
692 SRCategory("CategoryAttributeEditing"),
694 SRDescription("DescriptionAttributeAllowMoving"),
696 override public bool AllowMoving
700 return base.AllowMoving;
704 base.AllowMoving = value;
708 /// Gets or sets a flag that specifies whether an annotation anchor may be moved
709 /// with a mouse by the end user.
712 /// <b>True</b> if the annotation anchor may be moved, <b>false</b> otherwise.
715 SRCategory("CategoryAttributeEditing"),
717 SRDescription("DescriptionAttributeAnnotationGroup_AllowAnchorMoving"),
719 override public bool AllowAnchorMoving
723 return base.AllowAnchorMoving;
727 base.AllowAnchorMoving = value;
732 /// Gets or sets a flag that specifies whether an annotation may be resized
733 /// with a mouse by the end user.
736 /// <b>True</b> if the annotation may be resized, <b>false</b> otherwise.
739 SRCategory("CategoryAttributeEditing"),
741 SRDescription("DescriptionAttributeAllowResizing"),
743 override public bool AllowResizing
747 return base.AllowResizing;
751 base.AllowResizing = value;
756 /// Gets or sets a flag that specifies whether an annotation's text may be edited
757 /// when the end user double clicks on the text.
760 /// <b>True</b> if the annotation text may be edited, <b>false</b> otherwise.
763 SRCategory("CategoryAttributeEditing"),
765 SRDescription("DescriptionAttributeAllowTextEditing"),
767 override public bool AllowTextEditing
771 return base.AllowTextEditing;
775 base.AllowTextEditing = value;
780 /// Gets or sets a flag that specifies whether a polygon annotation's points
781 /// may be moved with a mouse by the end user.
784 /// <b>True</b> if the polygon annotation's points may be moved, <b>false</b> otherwise.
787 SRCategory("CategoryAttributeEditing"),
789 SRDescription("DescriptionAttributeAnnotationGroup_AllowPathEditing"),
791 override public bool AllowPathEditing
795 return base.AllowPathEditing;
799 base.AllowPathEditing = value;
803 #endif // Microsoft_CONTROL
807 #region Other Properties
810 /// Gets the collection of annotations in the group.
813 /// An <see cref="AnnotationCollection"/> object.
816 /// Note that the coordinates of all annotations in the group are relative to the
817 /// group annotation.
820 SRCategory("CategoryAttributeAnnotations"),
821 SRDescription("DescriptionAttributeAnnotationGroup_Annotations"),
822 Editor(Editors.AnnotationCollectionEditor.Editor, Editors.AnnotationCollectionEditor.Base),
823 #if Microsoft_CONTROL
824 DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
825 #else // Microsoft_CONTROL
826 PersistenceMode(PersistenceMode.InnerProperty),
827 #endif // Microsoft_CONTROL
829 public AnnotationCollection Annotations
838 /// Gets or sets an annotation's type name.
841 /// This property is used to get the name of each annotation type
842 /// (e.g. Line, Rectangle, Ellipse).
844 /// This property is for internal use and is hidden at design and run time.
848 SRCategory("CategoryAttributeMisc"),
851 EditorBrowsableAttribute(EditorBrowsableState.Never),
852 DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden),
853 SerializationVisibilityAttribute(SerializationVisibility.Hidden),
854 SRDescription("DescriptionAttributeAnnotationType"),
856 public override string AnnotationType
865 /// Gets or sets annotation selection points style.
868 /// A <see cref="SelectionPointsStyle"/> value that represents annotation
872 /// This property is for internal use and is hidden at design and run time.
875 SRCategory("CategoryAttributeAppearance"),
876 DefaultValue(SelectionPointsStyle.Rectangle),
877 ParenthesizePropertyNameAttribute(true),
879 EditorBrowsableAttribute(EditorBrowsableState.Never),
880 DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden),
881 SerializationVisibilityAttribute(SerializationVisibility.Hidden),
882 SRDescription("DescriptionAttributeSelectionPointsStyle"),
884 override internal SelectionPointsStyle SelectionPointsStyle
888 return SelectionPointsStyle.Rectangle;
897 /// Paints an annotation object using the specified graphics.
899 /// <param name="graphics">
900 /// A <see cref="ChartGraphics"/> object, used to paint the annotation object.
902 /// <param name="chart">
903 /// Reference to the <see cref="Chart"/> control.
905 override internal void Paint(Chart chart, ChartGraphics graphics)
907 // Paint all annotations in the group
908 foreach(Annotation annotation in this.annotations)
910 annotation.Paint(chart, graphics);
913 if( (this.Common.ProcessModePaint && this.IsSelected) ||
914 this.Common.ProcessModeRegions )
916 // Get annotation position in relative coordinates
917 PointF firstPoint = PointF.Empty;
918 PointF anchorPoint = PointF.Empty;
919 SizeF size = SizeF.Empty;
920 GetRelativePosition(out firstPoint, out size, out anchorPoint);
921 PointF secondPoint = new PointF(firstPoint.X + size.Width, firstPoint.Y + size.Height);
923 // Create selection rectangle
924 RectangleF selectionRect = new RectangleF(firstPoint, new SizeF(secondPoint.X - firstPoint.X, secondPoint.Y - firstPoint.Y));
926 // Check rectangle orientation
927 if(selectionRect.Width < 0)
929 selectionRect.X = selectionRect.Right;
930 selectionRect.Width = -selectionRect.Width;
932 if(selectionRect.Height < 0)
934 selectionRect.Y = selectionRect.Bottom;
935 selectionRect.Height = -selectionRect.Height;
938 // Check if text position is valid
939 if( selectionRect.IsEmpty ||
940 float.IsNaN(selectionRect.X) ||
941 float.IsNaN(selectionRect.Y) ||
942 float.IsNaN(selectionRect.Right) ||
943 float.IsNaN(selectionRect.Bottom) )
948 if(this.Common.ProcessModeRegions)
951 this.Common.HotRegionsList.AddHotRegion(
953 ReplaceKeywords(this.ToolTip),
954 #if Microsoft_CONTROL
958 #else // Microsoft_CONTROL
959 ReplaceKeywords(this.Url),
960 ReplaceKeywords(this.MapAreaAttributes),
961 ReplaceKeywords(this.PostBackValue),
962 #endif // Microsoft_CONTROL
964 ChartElementType.Annotation,
968 // Paint selection handles
969 PaintSelectionHandles(graphics, selectionRect, null);
973 #endregion // Methods
975 #region IDisposable override
977 /// Releases unmanaged and - optionally - managed resources
979 /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
980 protected override void Dispose(bool disposing)
984 //Clean up managed resources
985 if (this.annotations != null)
987 this.annotations.Dispose();
988 this.annotations = null;
991 base.Dispose(disposing);