/// <summary>
        /// Initializes a new instance of the <see cref="TimeIntervalAnnotationTrackVisualizationObjectViewItem"/> class.
        /// </summary>
        /// <param name="parent">The parent view.</param>
        /// <param name="trackIndex">The track index.</param>
        /// <param name="trackCount">The number of tracks.</param>
        /// <param name="trackName">The track name.</param>
        internal TimeIntervalAnnotationTrackVisualizationObjectViewItem(TimeIntervalAnnotationVisualizationObjectView parent, int trackIndex, int trackCount, string trackName)
        {
            this.parent = parent;

            this.grid = new Grid
            {
                RenderTransform  = new TranslateTransform(),
                IsHitTestVisible = false,
                Height           = this.parent.Canvas.ActualHeight / trackCount,
            };

            (this.grid.RenderTransform as TranslateTransform).X = 0;
            (this.grid.RenderTransform as TranslateTransform).Y = trackIndex * this.parent.Canvas.ActualHeight / trackCount;

            var border = new Border()
            {
                BorderBrush       = new SolidColorBrush(Colors.DarkGray),
                Background        = new SolidColorBrush(Color.FromRgb(0x2D, 0x2D, 0x30)),
                BorderThickness   = new Thickness(1),
                VerticalAlignment = VerticalAlignment.Center,
                Child             = new TextBlock()
                {
                    Foreground          = new SolidColorBrush(Colors.DarkGray),
                    VerticalAlignment   = VerticalAlignment.Center,
                    HorizontalAlignment = HorizontalAlignment.Center,
                    TextWrapping        = TextWrapping.Wrap,
                    Margin           = new Thickness(3),
                    IsHitTestVisible = false,
                    Text             = trackName,
                    FontSize         = this.parent.StreamVisualizationObject.FontSize,
                },
            };

            this.grid.Children.Add(border);
            this.parent.Canvas.Children.Add(this.grid);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="TimeIntervalAnnotationVisualizationObjectViewItem"/> class.
        /// </summary>
        /// <param name="parent">The parent view.</param>
        /// <param name="annotationDisplayData">The data for all annotations in this view item.</param>
        internal TimeIntervalAnnotationVisualizationObjectViewItem(TimeIntervalAnnotationVisualizationObjectView parent, TimeIntervalAnnotationDisplayData annotationDisplayData)
        {
            this.parent = parent;
            this.annotationDisplayData             = annotationDisplayData;
            annotationDisplayData.PropertyChanged += this.AnnotationDisplayData_PropertyChanged;

            this.figures = new List <Path>();
            this.labels  = new List <Grid>();

            foreach (AnnotationSchemaDefinition schemaDefinition in annotationDisplayData.Definition.SchemaDefinitions)
            {
                PathFigure annotationElementFigure = new PathFigure()
                {
                    StartPoint = new Point(0, 0),
                    IsClosed   = true,
                    IsFilled   = true,
                };

                annotationElementFigure.Segments.Add(new LineSegment(new Point(0, 0), true));
                annotationElementFigure.Segments.Add(new LineSegment(new Point(0, 0), true));
                annotationElementFigure.Segments.Add(new LineSegment(new Point(0, 0), true));

                PathGeometry pathGeometry = new PathGeometry()
                {
                    Transform = this.parent.TransformGroup
                };
                pathGeometry.Figures.Add(annotationElementFigure);
                Path path = new Path()
                {
                    Data = pathGeometry
                };
                this.figures.Add(path);

                Grid labelGrid = new Grid
                {
                    RenderTransform  = new TranslateTransform(),
                    IsHitTestVisible = false,
                };

                TextBlock textBlock = new TextBlock()
                {
                    VerticalAlignment   = VerticalAlignment.Center,
                    HorizontalAlignment = HorizontalAlignment.Center,
                    TextWrapping        = TextWrapping.Wrap,
                    Margin           = new Thickness(3),
                    IsHitTestVisible = false,
                };

                labelGrid.Children.Add(textBlock);
                this.labels.Add(labelGrid);

                // Get the current value
                object value = annotationDisplayData.Annotation.Data.Values[schemaDefinition.Name];

                // Get the metadata associtaed with the value
                AnnotationSchemaValueMetadata schemaMetadata = this.GetAnnotationValueMetadata(value, schemaDefinition.Schema);

                // Set the colors etc
                path.Stroke          = this.parent.GetBrush(schemaMetadata.BorderColor);
                path.StrokeThickness = schemaMetadata.BorderWidth;
                path.Fill            = this.parent.GetBrush(schemaMetadata.FillColor);
                textBlock.Foreground = this.parent.GetBrush(schemaMetadata.TextColor);
            }

            foreach (Path figure in this.figures)
            {
                this.parent.Canvas.Children.Add(figure);
            }

            foreach (Grid label in this.labels)
            {
                this.parent.Canvas.Children.Add(label);
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="TimeIntervalAnnotationVisualizationObjectViewItem"/> class.
        /// </summary>
        /// <param name="parent">The parent view.</param>
        /// <param name="annotationDisplayData">The data for all annotations in this view item.</param>
        internal TimeIntervalAnnotationVisualizationObjectViewItem(TimeIntervalAnnotationVisualizationObjectView parent, TimeIntervalAnnotationDisplayData annotationDisplayData)
        {
            this.parent = parent;
            this.annotationDisplayData             = annotationDisplayData;
            annotationDisplayData.PropertyChanged += this.AnnotationDisplayData_PropertyChanged;

            this.figures = new List <Path>();
            this.labels  = new List <Grid>();

            foreach (var attributeSchema in annotationDisplayData.AnnotationSchema.AttributeSchemas)
            {
                var annotationElementFigure = new PathFigure()
                {
                    StartPoint = new Point(0, 0),
                    IsClosed   = true,
                    IsFilled   = true,
                };

                annotationElementFigure.Segments.Add(new LineSegment(new Point(0, 0), true));
                annotationElementFigure.Segments.Add(new LineSegment(new Point(0, 0), true));
                annotationElementFigure.Segments.Add(new LineSegment(new Point(0, 0), true));

                var pathGeometry = new PathGeometry()
                {
                    Transform = this.parent.TransformGroup
                };
                pathGeometry.Figures.Add(annotationElementFigure);
                var path = new Path()
                {
                    Data = pathGeometry
                };
                this.figures.Add(path);

                var labelGrid = new Grid
                {
                    RenderTransform  = new TranslateTransform(),
                    IsHitTestVisible = false,
                };

                var textBlock = new TextBlock()
                {
                    VerticalAlignment   = VerticalAlignment.Center,
                    HorizontalAlignment = HorizontalAlignment.Center,
                    TextWrapping        = TextWrapping.Wrap,
                    Margin           = new Thickness(3),
                    IsHitTestVisible = false,
                };

                labelGrid.Children.Add(textBlock);
                this.labels.Add(labelGrid);

                // Set the colors etc
                var annotationValue = annotationDisplayData.Annotation.AttributeValues[attributeSchema.Name];
                path.Fill            = this.parent.GetBrush(annotationValue.FillColor);
                textBlock.Foreground = this.parent.GetBrush(annotationValue.TextColor);
            }

            var borderElementFigure = new PathFigure()
            {
                StartPoint = new Point(0, 0),
                IsClosed   = true,
                IsFilled   = true,
            };

            borderElementFigure.Segments.Add(new LineSegment(new Point(0, 0), true));
            borderElementFigure.Segments.Add(new LineSegment(new Point(0, 0), true));
            borderElementFigure.Segments.Add(new LineSegment(new Point(0, 0), true));

            var borderPathGeometry = new PathGeometry()
            {
                Transform = this.parent.TransformGroup
            };

            borderPathGeometry.Figures.Add(borderElementFigure);

            this.borderPath = new Path()
            {
                Data            = borderPathGeometry,
                Stroke          = new SolidColorBrush(Colors.Gray),
                StrokeThickness = 2,
            };

            // Insert the figure and labels in the parent canvas, but at the beginning, starting
            // from index 1. At index 0 we have the track highlight child. Inserting from index
            // 1 ensures that the track label items remain towards the tail of the list of canvas
            // children, making sure they stay on top in z-order.
            int index = 2;

            foreach (var figure in this.figures)
            {
                this.parent.Canvas.Children.Insert(index++, figure);
            }

            foreach (var label in this.labels)
            {
                this.parent.Canvas.Children.Insert(index++, label);
            }

            this.parent.Canvas.Children.Insert(index++, this.borderPath);
        }