Пример #1
1
        private void Annotation_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            Chart1.Annotations.Clear();

            AnnotationStyle.Items.Clear();
            AnnotationStyle.Enabled = false;

            AnnotationStyle1.Items.Clear();
            AnnotationStyle1.Enabled = false;
            AnnotationStyle2.Items.Clear();
            AnnotationStyle2.Visible = false;

            if(Annotation.SelectedItem.ToString() == "Line")
            {
                LineAnnotation annotation = new LineAnnotation();
                annotation.AnchorDataPoint = Chart1.Series[0].Points[1];
                annotation.Height = -25;
                annotation.Width = -25;
                annotation.LineWidth = 2;

                Chart1.Annotations.Add(annotation);

                SetLineControls(true);

            }
            else if(Annotation.SelectedItem.ToString() == "Vertical Line")
            {
                VerticalLineAnnotation annotation = new VerticalLineAnnotation();
                annotation.AnchorDataPoint = Chart1.Series[0].Points[1];
                annotation.Height = -25;
                annotation.LineWidth = 2;

                Chart1.Annotations.Add(annotation);

                SetLineControls(true);

            }
            else if(Annotation.SelectedItem.ToString() == "Horizontal Line")
            {
                HorizontalLineAnnotation annotation = new HorizontalLineAnnotation();
                annotation.AnchorDataPoint = Chart1.Series[0].Points[1];
                annotation.Width = -25;
                annotation.LineWidth = 2;

                Chart1.Annotations.Add(annotation);

                SetLineControls(true);
            }
            else if(Annotation.SelectedItem.ToString() == "Polyline")
            {
                PolylineAnnotation annotation = new PolylineAnnotation();
                annotation.AnchorDataPoint = Chart1.Series[0].Points[1];

                // explicitly set the relative height and width
                annotation.Height = 50;
                annotation.Width = 30;

                PointF [] points = new PointF[5];
                points[0].X = 0;
                points[0].Y = 0;

                points[1].X = 100;
                points[1].Y = 0;

                points[2].X = 0;
                points[2].Y = 100;

                points[3].X = 100;
                points[3].Y = 100;

                points[4].X = 0;
                points[4].Y = 50;

                annotation.GraphicsPath.AddPolygon(points);

                Chart1.Annotations.Add(annotation);

                SetLineControls(false);
            }
            else if(Annotation.SelectedItem.ToString() == "Text")
            {
                TextAnnotation annotation = new TextAnnotation();
                annotation.AnchorDataPoint = Chart1.Series[0].Points[1];
                annotation.Text = "I am a TextAnnotation";
                annotation.ForeColor = Color.Black;
                annotation.Font = new Font("Arial", 12);;

                Chart1.Annotations.Add(annotation);
                SetTextControls();

            }
            else if(Annotation.SelectedItem.ToString() == "Rectangle")
            {
                RectangleAnnotation annotation = new RectangleAnnotation();
                annotation.AnchorDataPoint = Chart1.Series[0].Points[1];
                annotation.Text = "I am a\nRectangleAnnotation";
                annotation.ForeColor = Color.Black;
                annotation.Font = new Font("Arial", 12);;
                annotation.LineWidth = 2;

                Chart1.Annotations.Add(annotation);

                SetTextControls();
                SetColorLineControls();
                AnnotationStyle1.SelectedIndex = 2;
            }
            else if(Annotation.SelectedItem.ToString() == "Ellipse")
            {
                EllipseAnnotation annotation = new EllipseAnnotation();
                annotation.AnchorDataPoint = Chart1.Series[0].Points[1];
                annotation.Text = "I am an EllipseAnnotation";
                annotation.ForeColor = Color.Black;
                annotation.Font = new Font("Arial", 12);;
                annotation.LineWidth = 2;
                annotation.Height = 35;
                annotation.Width = 60;

                Chart1.Annotations.Add(annotation);

                SetTextControls();
                SetColorLineControls();
                AnnotationStyle1.SelectedIndex = 2;

            }
            else if(Annotation.SelectedItem.ToString() == "Arrow")
            {
                ArrowAnnotation annotation = new ArrowAnnotation();
                annotation.AnchorDataPoint = Chart1.Series[0].Points[1];
                annotation.Height = -25;
                annotation.Width = -25;
                annotation.LineWidth = 2;

                Chart1.Annotations.Add(annotation);

                SetArrowControls();

            }
            else if(Annotation.SelectedItem.ToString() == "Border3D")
            {
                Border3DAnnotation annotation = new Border3DAnnotation();
                annotation.AnchorDataPoint = Chart1.Series[0].Points[1];
                annotation.Text = "I am a Border3DAnnotation";
                annotation.ForeColor = Color.Black;
                annotation.Font = new Font("Arial", 12);
                annotation.Height = 40;
                annotation.Width = 50;

                Chart1.Annotations.Add(annotation);

                SetBorder3DControls();

            }
            else if(Annotation.SelectedItem.ToString() == "Callout")
            {
                CalloutAnnotation annotation = new CalloutAnnotation();
                annotation.AnchorDataPoint = Chart1.Series[0].Points[1];
                annotation.Text = "I am a\nCalloutAnnotation";
                annotation.ForeColor = Color.Black;
                annotation.Font = new Font("Arial", 10);;
                annotation.Height = 35;
                annotation.Width = 50;

                Chart1.Annotations.Add(annotation);

                SetCalloutControls();

            }
            else if(Annotation.SelectedItem.ToString() == "Polygon")
            {
                PolygonAnnotation annotation = new PolygonAnnotation();
                annotation.AnchorDataPoint = Chart1.Series[0].Points[1];

                // explicitly set the relative height and width
                annotation.Height = 50;
                annotation.Width = 30;

                annotation.BackColor = Color.FromArgb(128, Color.Orange);

                // define relative value points for a polygon
                PointF [] points = new PointF[5];
                points[0].X = 0;
                points[0].Y = 0;

                points[1].X = 100;
                points[1].Y = 0;

                points[2].X = 100;
                points[2].Y = 100;

                points[3].X = 0;
                points[3].Y = 100;

                points[4].X = 50;
                points[4].Y = 50;

                annotation.GraphicsPath.AddPolygon(points);

                Chart1.Annotations.Add(annotation);

                SetColorControl();
                SetColorLineControls();

            }
            else if(Annotation.SelectedItem.ToString() == "Image")
            {
                if(Chart1.Images.IndexOf("MyBmp") < 0)
                {
                    Bitmap Bmp = new Bitmap(200, 75);
                    Graphics g = Graphics.FromImage(Bmp);
                    g.FillRectangle(new SolidBrush(Color.Transparent), 0, 0, Bmp.Width, Bmp.Height);
                    g.FillRectangle(new SolidBrush(Color.PaleGoldenrod), Bmp.Width/2, 0, Bmp.Width/2, Bmp.Height);
                    g.FillRectangle(new SolidBrush(Color.PaleVioletRed), 0, 0, Bmp.Width/2, Bmp.Height);
                    g.FillRectangle(new SolidBrush(Color.FromArgb(128, Color.DarkOrange)), 0, Bmp.Height/2, Bmp.Width, Bmp.Height/2);
                    g.DrawString("I am an ImageAnnotation", new Font("Arial", 12),
                        new SolidBrush(Color.Black),
                        new Rectangle( 0, 0, Bmp.Width, Bmp.Height));

                    g.Dispose();

                    Chart1.Images.Add(new NamedImage("MyBmp", Bmp));
                }

                ImageAnnotation annotation = new ImageAnnotation();
                annotation.AnchorDataPoint = Chart1.Series[0].Points[1];
                annotation.Image = "MyBmp";

                Chart1.Annotations.Add(annotation);
                StyleLabel1.Text = "";
                StyleLabel2.Text = "";
            }
        }
        /// <summary>
        /// Add text annotation to chart.
        /// </summary>
        /// <param name="sender">Source Chart.</param>
        /// <param name="text">Text to display.</param>
        /// <param name="x">Text box upper left X Coordinate.</param>
        /// <param name="y">Text box upper left Y coordinate.</param>
        /// <param name="textColor">Text color.</param>
        /// <param name="name">Annotation name.</param>
        /// <param name="textStyle">Style of text.</param>
        public static void AddText(this Chart sender, string text,
                                   double x, double y,
                                   Drawing.Color textColor, string name = "",
                                   TextStyle textStyle = TextStyle.Default)
        {
            TextAnnotation textAnn       = new TextAnnotation();
            string         chartAreaName = sender.ChartAreas[0].Name;

            textAnn.ClipToChartArea      = chartAreaName;
            textAnn.AxisXName            = chartAreaName + "\\rX";
            textAnn.YAxisName            = chartAreaName + "\\rY";
            textAnn.IsSizeAlwaysRelative = false;

            textAnn.Text      = text;
            textAnn.ForeColor = textColor;
            textAnn.X         = x;
            textAnn.Y         = y;
            textAnn.TextStyle = textStyle;

            sender.Annotations.Add(textAnn);
            if (!string.IsNullOrEmpty(name))
            {
                textAnn.Name = name;
            }
        }
        public void CreateNewStarAnnotation()
        {
            // Create annotation group and add it to the chart annotations collection
            AnnotationGroup star = new AnnotationGroup();
            star.X = 20;
            star.Y = 20;
            star.Width = 30;
            star.Height = 20;
            star.AllowSelecting = true;
            star.AllowMoving = true;
            star.AllowResizing = true;

            Chart1.Annotations.Add(star);

            // Add star shaped polygon annotation into the group

            PointF[] starPolygon = new PointF[] {
                                                    new PointF(1,6), new PointF(27,23), new PointF(33,5), new PointF(44,22), new PointF(58,0),
                                                    new PointF(57,19), new PointF(75,11), new PointF(70,28), new PointF(100,37), new PointF(81,53),
                                                    new PointF(99,65), new PointF(75,67), new PointF(87,98), new PointF(63,69), new PointF(60,94),
                                                    new PointF(47,69), new PointF(34,100), new PointF(32,69), new PointF(23,74), new PointF(26,61),
                                                    new PointF(4,72), new PointF(22,49), new PointF(0,39), new PointF(23,32), new PointF(1,6) };

            GraphicsPath starPath = new GraphicsPath();

            starPath.AddPolygon(starPolygon);
            PolygonAnnotation poly = new PolygonAnnotation();
            poly.Name = "Star";
            poly.GraphicsPath = starPath;
            star.Annotations.Add(poly);

            // Set star polygon annotation position and appearance
            star.Annotations["Star"].X = 0;
            star.Annotations["Star"].Y = 0;
            star.Annotations["Star"].Width = 100;
            star.Annotations["Star"].Height = 100;
            star.Annotations["Star"].LineColor = Color.FromArgb(64,64,64);
            star.Annotations["Star"].BackColor = Color.FromArgb(220,255,255,192);
            star.Annotations["Star"].ShadowOffset = 2;

            // Add text in the middle of the star shape
            TextAnnotation textAnnotation = new TextAnnotation();
            textAnnotation.Name = "StarText";
            textAnnotation.Text = "New !!!";
            textAnnotation.X = 20;
            textAnnotation.Y = 20;
            textAnnotation.Width = 60;
            textAnnotation.Height = 60;
            star.Annotations.Add(textAnnotation);
            star.Annotations["StarText"].Font = new Font("MS Sans Serif", 10, FontStyle.Bold|FontStyle.Italic);
            star.Annotations["StarText"].ForeColor= Color.FromArgb(26, 59, 105);
        }
        /// <summary>
        /// Mouse was double clicked.
        /// </summary>
        internal void OnDoubleClick()
        {
            if (lastClickedAnnotation != null &&
                lastClickedAnnotation.AllowTextEditing)
            {
                TextAnnotation textAnnotation = lastClickedAnnotation as TextAnnotation;

                if (textAnnotation == null)
                {
                    AnnotationGroup group = lastClickedAnnotation as AnnotationGroup;

                    if (group != null)
                    {
                        // Try to edit text annotation in the group
                        foreach (Annotation annot in group.Annotations)
                        {
                            TextAnnotation groupAnnot = annot as TextAnnotation;
                            if (groupAnnot != null &&
                                groupAnnot.AllowTextEditing)
                            {
                                // Get annotation position in relative coordinates
                                PointF firstPoint  = PointF.Empty;
                                PointF anchorPoint = PointF.Empty;
                                SizeF  size        = SizeF.Empty;
                                groupAnnot.GetRelativePosition(out firstPoint, out size, out anchorPoint);
                                RectangleF textPosition = new RectangleF(firstPoint, size);

                                // Check if last clicked coordinate is inside this text annotation
                                if (groupAnnot.GetGraphics() != null &&
                                    textPosition.Contains(groupAnnot.GetGraphics().GetRelativePoint(this._movingResizingStartPoint)))
                                {
                                    textAnnotation        = groupAnnot;
                                    lastClickedAnnotation = textAnnotation;
                                    break;
                                }
                            }
                        }
                    }
                }

                if (textAnnotation != null)
                {
                    // Start annotation text editing
                    textAnnotation.BeginTextEditing();
                }
            }
        }
        /// <summary>
        /// Initializes the specified item.
        /// </summary>
        /// <param name="item">The item.</param>
        internal override void Initialize(Annotation item)
        {
            if (item != null)
            {
                TextAnnotation textAnnotation = item as TextAnnotation;
                if (textAnnotation != null && string.IsNullOrEmpty(textAnnotation.Text) && Chart != null && Chart.IsDesignMode())
                {
                    textAnnotation.Text = item.Name;
                }

                //If the collection belongs to annotation group we need to pass a ref to this group to all the child annotations
                if (this.AnnotationGroup != null)
                {
                    item.annotationGroup = this.AnnotationGroup;
                }

                item.ResetCurrentRelativePosition();
            }
            base.Initialize(item);
        }
Пример #6
0
        /// <summary>
        /// Add text annotation to chart.
        /// </summary>
        /// <param name="sender">Source Chart.</param>
        /// <param name="text">Text to display.</param>
        /// <param name="x">Text box upper left X Coordinate.</param>
        /// <param name="y">Text box upper left Y coordinate.</param>
        /// <param name="textColor">Text color.</param>
        /// <param name="name">Annotation name.</param>
        /// <param name="textStyle">Style of text.</param>
        public static void AddText(this Chart sender, string text,
            double x, double y,
            Drawing.Color textColor, string name = "",
            TextStyle textStyle = TextStyle.Default)
        {
            TextAnnotation textAnn = new TextAnnotation();
            string chartAreaName = sender.ChartAreas[0].Name;
            textAnn.ClipToChartArea = chartAreaName;
            textAnn.AxisXName = chartAreaName + "\\rX";
            textAnn.YAxisName = chartAreaName + "\\rY";
            textAnn.IsSizeAlwaysRelative = false;

            textAnn.Text = text;
            textAnn.ForeColor = textColor;
            textAnn.X = x;
            textAnn.Y = y;
            textAnn.TextStyle = textStyle;

            sender.Annotations.Add(textAnn);
            if (!string.IsNullOrEmpty(name)) textAnn.Name = name;
        }
        public void AddAnnotation(string AnnotateName, double AnnotateValue, double AnnotateLength, Color color)
        {
            Series seriesMax = new Series(AnnotateName);
            seriesMax.ChartType = SeriesChartType.Line;
            seriesMax.Points.AddXY(0, AnnotateValue);
            seriesMax.Points.AddXY(AnnotateLength, AnnotateValue);
            seriesMax.BorderWidth = 1;
            //Add annotation
            TextAnnotation annotation =
            new TextAnnotation();
            annotation.Text = AnnotateName;
            annotation.Font = new System.Drawing.Font("Arial", 8);
            annotation.ForeColor = System.Drawing.Color.Black;
            chart1.Annotations.Add(annotation);
            annotation.AnchorDataPoint = seriesMax.Points[1];

            try
            {
                chart1.Series.Add(seriesMax);
                annotation.ForeColor = color;
                chart1.Series[chart1.Series.Count - 1].Color = color;
            }
            catch { }
        }
 private TextAnnotation CreateTextAnnotation(string name, int classIndex, Axis axisX, Axis axisY, double x, double y, ContentAlignment alignment) {
   TextAnnotation annotation = new TextAnnotation();
   annotation.Text = name;
   annotation.AllowMoving = true;
   annotation.AllowResizing = false;
   annotation.AllowSelecting = false;
   annotation.IsSizeAlwaysRelative = true;
   annotation.ClipToChartArea = chart.ChartAreas[0].Name;
   annotation.Tag = classIndex;
   annotation.AxisX = axisX;
   annotation.AxisY = axisY;
   annotation.Alignment = alignment;
   annotation.X = x;
   annotation.Y = y;
   return annotation;
 }
        /// <summary>
        /// Mouse button pressed in the control.
        /// </summary>
        /// <param name="e">Event arguments.</param>
        /// <param name="isHandled">Returns true if event is handled and no further processing required.</param>
        internal void OnMouseDown(MouseEventArgs e, ref bool isHandled)
        {
            // Reset last clicked annotation object and stop text editing
            if (lastClickedAnnotation != null)
            {
                TextAnnotation textAnnotation = lastClickedAnnotation as TextAnnotation;
                if (textAnnotation != null)
                {
                    // Stop annotation text editing
                    textAnnotation.StopTextEditing();
                }
                lastClickedAnnotation = null;
            }

            // Check if in annotation placement mode
            if (this.placingAnnotation != null)
            {
                // Process mouse down
                this.placingAnnotation.PlacementMouseDown(new PointF(e.X, e.Y), e.Button);

                // Set handled flag
                isHandled = true;
                return;
            }

            // Process only left mouse buttons
            if (e.Button == MouseButtons.Left)
            {
                bool updateRequired = false;
                this._resizingMode = ResizingMode.None;

                // Check if mouse buton was pressed in any selection handles areas
                Annotation annotation =
                    HitTestSelectionHandles(new PointF(e.X, e.Y), ref this._resizingMode);

                // Check if mouse button was pressed over one of the annotation objects
                if (annotation == null && this.Count > 0)
                {
                    HitTestResult result = this.Chart.HitTest(e.X, e.Y, ChartElementType.Annotation);
                    if (result != null && result.ChartElementType == ChartElementType.Annotation)
                    {
                        annotation = (Annotation)result.Object;
                    }
                }

                // Unselect all annotations if mouse clicked outside any annotations
                if (annotation == null || !annotation.IsSelected)
                {
                    if ((Control.ModifierKeys & Keys.Control) != Keys.Control &&
                        (Control.ModifierKeys & Keys.Shift) != Keys.Shift)
                    {
                        foreach (Annotation annot in this.Chart.Annotations)
                        {
                            if (annot != annotation && annot.IsSelected)
                            {
                                annot.IsSelected = false;
                                updateRequired   = true;

                                // Call selection changed notification
                                if (this.Chart != null)
                                {
                                    this.Chart.OnAnnotationSelectionChanged(annot);
                                }
                            }
                        }
                    }
                }

                // Process mouse action in the annotation object
                if (annotation != null)
                {
                    // Mouse down event handled
                    isHandled = true;

                    // Select/Unselect annotation
                    Annotation selectableAnnotation = annotation;
                    if (annotation.AnnotationGroup != null)
                    {
                        // Select annotation group when click on any child annotations
                        selectableAnnotation = annotation.AnnotationGroup;
                    }
                    if (!selectableAnnotation.IsSelected && selectableAnnotation.AllowSelecting)
                    {
                        selectableAnnotation.IsSelected = true;
                        updateRequired = true;

                        // Call selection changed notification
                        if (this.Chart != null)
                        {
                            this.Chart.OnAnnotationSelectionChanged(selectableAnnotation);
                        }
                    }
                    else if ((Control.ModifierKeys & Keys.Control) == Keys.Control ||
                             (Control.ModifierKeys & Keys.Shift) == Keys.Shift)
                    {
                        selectableAnnotation.IsSelected = false;
                        updateRequired = true;

                        // Call selection changed notification
                        if (this.Chart != null)
                        {
                            this.Chart.OnAnnotationSelectionChanged(selectableAnnotation);
                        }
                    }

                    // Remember last clicked and selected annotation
                    lastClickedAnnotation = annotation;

                    // Rember mouse position
                    this._movingResizingStartPoint = new PointF(e.X, e.Y);

                    // Start moving, repositioning or resizing of annotation
                    if (annotation.IsSelected)
                    {
                        // Check if one of selection handles was clicked on
                        this._resizingMode = annotation.GetSelectionHandle(this._movingResizingStartPoint);
                        if (!annotation.AllowResizing &&
                            this._resizingMode >= ResizingMode.TopLeftHandle &&
                            this._resizingMode <= ResizingMode.LeftHandle)
                        {
                            this._resizingMode = ResizingMode.None;
                        }
                        if (!annotation.AllowAnchorMoving &&
                            this._resizingMode == ResizingMode.AnchorHandle)
                        {
                            this._resizingMode = ResizingMode.None;
                        }
                        if (this._resizingMode == ResizingMode.None && annotation.AllowMoving)
                        {
                            // Annotation moving mode
                            this._resizingMode = ResizingMode.Moving;
                        }
                    }
                    else
                    {
                        if (this._resizingMode == ResizingMode.None && annotation.AllowMoving)
                        {
                            // Do not allow moving child annotations inside the group.
                            // Only the whole group can be selected, resized or repositioned.
                            if (annotation.AnnotationGroup != null)
                            {
                                // Move the group instead
                                lastClickedAnnotation = annotation.AnnotationGroup;
                            }

                            // Annotation moving mode
                            this._resizingMode = ResizingMode.Moving;
                        }
                    }
                }

                // Update chart
                if (updateRequired)
                {
                    // Invalidate and update the chart
                    this.Chart.Invalidate(true);
                    this.Chart.UpdateAnnotations();
                }
            }
        }
Пример #10
0
 /// <summary>
 /// Draws the provided segment
 /// </summary>
 /// <param name="segment"></param>
 /// <param name="start"></param>
 /// <param name="end"></param>
 /// <param name="maxValue"></param>
 private void DrawSegment(ISegment segment, double start, double end, double maxValue)
 {
     if (segment.D0 < maxValue)
     {
         Data.Points.Add(new DataPoint(start, segment.D0));
         Data.Points.Add(new DataPoint(end, segment.D0));
         DataPoint emptyPoint = new DataPoint((start + end) / 2, segment.D0 + (Math.Min(segment.Length, (maxValue - segment.D0)) / 2));
         emptyPoint.IsEmpty = true;
         Data.Points.Add(emptyPoint);
         TextAnnotation annotation = new TextAnnotation();
         annotation.AxisX = GraphVisualizer.ChartAreas[0].AxisX;
         annotation.AxisY = GraphVisualizer.ChartAreas[0].AxisY;
         annotation.AnchorAlignment = System.Drawing.ContentAlignment.MiddleCenter;
         annotation.AnchorX = emptyPoint.XValue;
         annotation.AnchorY = emptyPoint.YValues[0];
         annotation.Text = segment.V0 + "m/s²";
         GraphVisualizer.Annotations.Add(annotation);
     }
 }
Пример #11
0
        private void update_TrafficChart()
        {
            List<float> inboundPoints = new List<float>();
            List<float> outboundPoints = new List<float>();
            TextAnnotation inboundAnnotation = new TextAnnotation();
            TextAnnotation outboundAnnotation = new TextAnnotation();
            BandwidthScaleInfo bandwidthScale;
            const long minScale = 50;
            long maxSpeed = 0;
            long lastInbound, lastOutbound;

            lock (_lock)
            {
                if (traffic.Count == 0)
                    return;
                foreach (var trafficPerSecond in traffic)
                {
                    inboundPoints.Add(trafficPerSecond.inbound);
                    outboundPoints.Add(trafficPerSecond.outbound);
                    maxSpeed = Math.Max(maxSpeed, Math.Max(trafficPerSecond.inbound, trafficPerSecond.outbound));
                }
                lastInbound = traffic.Last().inbound;
                lastOutbound = traffic.Last().outbound;
            }

            if (maxSpeed > 0)
            {
                lastMaxSpeed -= lastMaxSpeed / 32;
                maxSpeed = Math.Max(minScale, Math.Max(maxSpeed, lastMaxSpeed));
                lastMaxSpeed = maxSpeed;
            }
            else
            {
                maxSpeed = lastMaxSpeed = minScale;
            }

            bandwidthScale = Utils.GetBandwidthScale(maxSpeed);

            //rescale the original data points, since it is List<float>, .ForEach does not work
            inboundPoints = inboundPoints.Select(p => p / bandwidthScale.unit).ToList();
            outboundPoints = outboundPoints.Select(p => p / bandwidthScale.unit).ToList();

            if (trafficChart.IsHandleCreated)
            {
                trafficChart.Series["Inbound"].Points.DataBindY(inboundPoints);
                trafficChart.Series["Outbound"].Points.DataBindY(outboundPoints);
                trafficChart.ChartAreas[0].AxisY.LabelStyle.Format = "{0:0.##} " + bandwidthScale.unit_name;
                trafficChart.ChartAreas[0].AxisY.Maximum = bandwidthScale.value;
                inboundAnnotation.AnchorDataPoint = trafficChart.Series["Inbound"].Points.Last();
                inboundAnnotation.Text = Utils.FormatBandwidth(lastInbound);
                outboundAnnotation.AnchorDataPoint = trafficChart.Series["Outbound"].Points.Last();
                outboundAnnotation.Text = Utils.FormatBandwidth(lastOutbound);
                trafficChart.Annotations.Clear();
                trafficChart.Annotations.Add(inboundAnnotation);
                trafficChart.Annotations.Add(outboundAnnotation);
            }
        }
Пример #12
0
 public void AddText(string Text)
 {
     TA = new TextAnnotation();
     TA.X = this.Position;
     TA.Text = Text;
 }
Пример #13
0
        /// <summary>
        /// Dumps the Column/Rows determination (based on aspect ratio) Plot.
        /// </summary>
        /// <param name="filename">name of the image file to write to.</param>
        /// <param name="plotThresholds">if set to <c>true</c> plot threshold info.</param>
        private void DumpColRowsPlot(string filename, bool plotThresholds)
        {
            bool detailsPage;
            int nThumbs, nCols, nRows;
            double crossoverThreshold;

            filename = System.IO.Path.GetFileNameWithoutExtension (filename) + ".png";
            if (System.IO.File.Exists (filename))
                {
                Console.Write ("'{0}' already exists. Overwrite (Y/N) [N]?", filename);
                string answer = Console.ReadLine ();
                answer = answer.Trim ().ToLower ();
                if (answer != "y" && answer != "yes")
                    {
                    Console.Write ("Aborting operation.");
                    return;
                    }
                }

            if (_tnSettings.Interval.TotalSeconds > 0)
                {
                detailsPage = true;
                nThumbs = _tnSettings.DetailThumbs;
                nCols = _tnSettings.DetailColumns;
                nRows = _tnSettings.DetailRows;
                crossoverThreshold = _tnSettings.DetailThreshold;
                }
            else
                {
                detailsPage = false;
                nThumbs = _tnSettings.OverviewThumbs;
                nCols = _tnSettings.OverviewColumns;
                nRows = _tnSettings.OverviewRows;
                crossoverThreshold = _tnSettings.OverviewThreshold;
                }

            THelper.Information ("");
            THelper.Information ("Dumping Column/Rows Determination Plot");
            THelper.Information ("Page:             {0}  {1}x{2} ({3:F2}:1)",
                                 detailsPage ? "Detail" : "Overview",
                                 _tnSettings.Width, _tnSettings.Height,
                                 _tnSettings.AspectRatio);
            THelper.Information ("Layout Mode:      {0}", _tnSettings.LayoutMode);
            if (_tnSettings.LayoutMode == ThumbnailSettings.LayoutModes.Auto)
                THelper.Information ("Threshold:        {0:F2}", crossoverThreshold);
            if (_tnSettings.LayoutMode == ThumbnailSettings.LayoutModes.Actual)
                {
                THelper.Information ("Actual:           {1}x{2}", nCols, nRows);
                }
            else
                {
                THelper.Information ("RC Optimization:  {0}", _tnSettings.RCOptimization);
                THelper.Information ("Max RC Opt Steps: {0}", _tnSettings.MaxOptimizationSteps);
                THelper.Information ("Desired:          {0} thumbs", nThumbs);
                THelper.Information ("Minimum:          {0} columns, {1} rows",
                                     _tnSettings.MinColumns, _tnSettings.MinRows);
                }
            THelper.Information ("");

            System.Drawing.Font titleFont =
                new System.Drawing.Font ("Ariel", 24, System.Drawing.FontStyle.Bold);
            System.Drawing.Font subTitleFont =
                new System.Drawing.Font ("Ariel", 13, System.Drawing.FontStyle.Bold);
            System.Drawing.Font axisLabelFont =
                new System.Drawing.Font ("Ariel", 20, System.Drawing.FontStyle.Bold);
            System.Drawing.Font axisFont =
                new System.Drawing.Font ("Ariel", 12, System.Drawing.FontStyle.Bold);
            System.Drawing.Font annotationFont =
                new System.Drawing.Font ("Ariel", 10, System.Drawing.FontStyle.Regular);
            System.Drawing.Font annotationItFont =
                new System.Drawing.Font ("Ariel", 10, System.Drawing.FontStyle.Italic);

            Charting.Chart chart = new Charting.Chart ();
            Charting.ChartArea chartArea = chart.ChartAreas.Add ("Wasted");
            Charting.Legend legend = new Charting.Legend ("Wasted");
            legend.DockedToChartArea = "Wasted";
            legend.Font = axisFont;
            legend.Docking = Charting.Docking.Bottom;
            legend.Alignment = System.Drawing.StringAlignment.Far;
            legend.LegendStyle = Charting.LegendStyle.Column;
            chart.Legends.Add (legend);

            Charting.LabelStyle labelStyle1 = new Charting.LabelStyle();
            labelStyle1.Font = axisFont;
            Charting.LabelStyle labelStyle2 = new Charting.LabelStyle ();
            labelStyle2.Font = axisFont;
            Charting.LabelStyle labelStyle3 = new Charting.LabelStyle ();
            labelStyle3.Font = axisFont;

            chart.BackColor = System.Drawing.Color.Wheat;

            chartArea.BorderWidth = 3;
            chartArea.BorderDashStyle = Charting.ChartDashStyle.Solid;
            //chartArea.BorderColor = System.Drawing.Color.Violet;

            legend.BackColor = System.Drawing.Color.Wheat;

            string titleStr = "Optimum Number of Columns & Rows";
            if (plotThresholds)
                titleStr += "\nUsing % Wasted Thumbnail Width & Height";
            Charting.Title title = chart.Titles.Add (titleStr);
            title.Font = titleFont;
            //subTitle.DockingOffset = -2;

            Charting.TextAnnotation desired = new Charting.TextAnnotation ();
            desired.Font = subTitleFont;
            switch (_tnSettings.LayoutMode)
                {
                case ThumbnailSettings.LayoutModes.Auto:
                    chartArea.BackColor = System.Drawing.Color.Beige;
                    desired.Text = String.Format (
                        "{0} Cols or Rows; Min {1} Cols, {2} Rows; {3} Max Opt Steps",
                        nThumbs, _tnSettings.MinColumns, _tnSettings.MinRows,
                        _tnSettings.MaxOptimizationSteps);
                    break;

                case ThumbnailSettings.LayoutModes.Actual:
                    chartArea.BackColor = System.Drawing.Color.Ivory;
                    desired.Text = String.Format ("{0} Columns and {1} Rows",
                                                  nCols, nRows);
                    break;

                case ThumbnailSettings.LayoutModes.RowPriority:
                    chartArea.BackColor = System.Drawing.Color.Beige;
                    desired.Text = String.Format (
                        "{0} Rows; Min {1} Columns; {2} Max Opt Steps",
                        nThumbs, _tnSettings.MinColumns, _tnSettings.MaxOptimizationSteps);
                    break;

                case ThumbnailSettings.LayoutModes.ColumnPriority:
                    chartArea.BackColor = System.Drawing.Color.AliceBlue;
                    desired.Text = String.Format (
                        "{0} Columns; Min {1} Rows; {2} Max Opt Steps",
                        nThumbs, _tnSettings.MinRows, _tnSettings.MaxOptimizationSteps);
                    break;
                }
            desired.Text += detailsPage ? "\nDetail Page" : "\nOverview Page";
            desired.Text += String.Format ("  {0}x{1} ({2:F2}:1)",
                                           _tnSettings.Width, _tnSettings.Height,
                                           _tnSettings.AspectRatio);

            desired.Alignment = System.Drawing.ContentAlignment.BottomLeft;

            desired.X = 1;
            desired.Y = 95;
            chart.Annotations.Add (desired);

            Charting.TextAnnotation layout = new Charting.TextAnnotation ();
            layout.Font = subTitleFont;
            layout.Text = String.Format("{0} Layout Mode", _tnSettings.LayoutMode);
            if (_tnSettings.LayoutMode != ThumbnailSettings.LayoutModes.Actual)
                layout.Text += String.Format ("\nRow/Column Optimization {0}",
                                              _tnSettings.RCOptimization ? "enabled" : "disabled");
            layout.Alignment = System.Drawing.ContentAlignment.BottomRight;
            layout.X = 77;
            layout.Y = 95;
            chart.Annotations.Add (layout);

            chart.Width = 1280;
            chart.Height = 1024;
            int lineWidth = 5;
            int dotsWidth = 2;

            chartArea.AxisX.Title = "Video Aspect Ratio";
            chartArea.AxisX.TitleFont = axisLabelFont;
            chartArea.AxisX.MajorGrid.Enabled = false;
            chartArea.AxisX.MajorTickMark.Interval = 0.10;
            chartArea.AxisX.Minimum = 1.0;
            chartArea.AxisX.Maximum = 3.0;
            chartArea.AxisX.Interval = 0.5;
            chartArea.AxisX.LineWidth = 3;
            chartArea.AxisX.MajorTickMark.LineWidth = 3;
            chartArea.AxisX.LabelStyle = labelStyle1;
            chartArea.AxisX.LabelStyle.Format = "F2";
            chartArea.AxisX.IsMarginVisible = true;

            if (_tnSettings.LayoutMode == ThumbnailSettings.LayoutModes.Auto &&
                crossoverThreshold > 1.0)
                {
                Charting.StripLine stripLine = new Charting.StripLine ();
                stripLine.IntervalOffset = 0.0;
                stripLine.StripWidth = crossoverThreshold - 1.0;
                stripLine.Interval = 10000;
                stripLine.BackColor = System.Drawing.Color.AliceBlue;
                chartArea.AxisX.StripLines.Add (stripLine);
                }

            chartArea.AxisY.Title = "# of Columns or Rows";
            chartArea.AxisY.TitleFont = axisLabelFont;
            chartArea.AxisY.MajorGrid.Enabled = false;
            chartArea.AxisY.MajorTickMark.Interval = 1.0;
            chartArea.AxisY.LineWidth = 3;
            chartArea.AxisY.MajorTickMark.LineWidth = 3;
            chartArea.AxisY.LabelStyle = labelStyle2;
            //chartArea.AxisY.LabelStyle.IsEndLabelVisible = false;
            chartArea.AxisY.IsMarginVisible = true;

            if (!plotThresholds)
                {
                chartArea.AxisY2.Enabled = Charting.AxisEnabled.True;
                //chartArea.AxisY2.Title = "# of Columns or Rows";
                chartArea.AxisY2.TitleFont = axisLabelFont;
                chartArea.AxisY2.MajorGrid.Enabled = false;
                chartArea.AxisY2.MajorTickMark.Interval = 1.0;
                chartArea.AxisY2.LineWidth = 3;
                chartArea.AxisY2.MajorTickMark.LineWidth = 3;
                chartArea.AxisY2.LabelStyle = labelStyle3;
                //chartArea.AxisY2.LabelStyle.IsEndLabelVisible = false;
                chartArea.AxisY2.IsMarginVisible = true;
                }

            Charting.Series seriesNCols = chart.Series.Add ("# of Columns");
            seriesNCols.ChartType = Charting.SeriesChartType.StepLine;
            seriesNCols.ChartArea = "Wasted";
            seriesNCols.Legend = "Wasted";
            seriesNCols.IsVisibleInLegend = true;
            seriesNCols.BorderWidth = lineWidth;

            Charting.Series seriesNRows = chart.Series.Add ("# of Rows");
            seriesNRows.ChartType = Charting.SeriesChartType.StepLine;
            seriesNRows.ChartArea = "Wasted";
            seriesNRows.Legend = "Wasted";
            seriesNRows.IsVisibleInLegend = true;
            seriesNRows.BorderWidth = lineWidth;

            Charting.Series seriesWW = null;
            Charting.Series seriesWH = null;

            if (plotThresholds)
                {
                chartArea.AxisY2.Title = "% Wasted Thumbnail Width or Height";
                chartArea.AxisY2.TitleFont = axisLabelFont;
                chartArea.AxisY2.MajorGrid.Enabled = false;
                chartArea.AxisY2.LineWidth = 3;
                chartArea.AxisY2.MajorTickMark.LineWidth = 3;
                chartArea.AxisY2.LabelStyle = labelStyle3;
                //chartArea.AxisY2.LabelStyle.IsEndLabelVisible = false;
                chartArea.AxisY2.Maximum = 100.0;

                seriesWW = chart.Series.Add ("%Wasted Width");
                seriesWW.ChartType = Charting.SeriesChartType.Line;
                seriesWW.ChartArea = "Wasted";
                seriesWW.Legend = "Wasted";
                seriesWW.IsVisibleInLegend = true;
                seriesWW.BorderWidth = dotsWidth;
                seriesWW.BorderDashStyle = Charting.ChartDashStyle.Dot;
                seriesWW.YAxisType = Charting.AxisType.Secondary;

                seriesWH = chart.Series.Add ("%Wasted Height");
                seriesWH.ChartType = Charting.SeriesChartType.Line;
                seriesWH.ChartArea = "Wasted";
                seriesWH.Legend = "Wasted";
                seriesWH.IsVisibleInLegend = true;
                seriesWH.BorderWidth = dotsWidth;
                seriesWH.BorderDashStyle = Charting.ChartDashStyle.Dot;
                seriesWH.YAxisType = Charting.AxisType.Secondary;
                }

            ThumbnailCreator creator = new ThumbnailCreator (_tnSettings, null);
            ThumbnailPageLayout container = new ThumbnailPageLayout (_tnSettings);
            ThumbnailPageLayout newContainer;

            double wastedWidth, wastedHeight;
            int extraWidth, extraHeight;
            double extraWidthPercent, extraHeightPercent;

            for (double aspectRatio=1.0; aspectRatio <= 3.0; aspectRatio += 0.01)
                {
                _tnSettings.ThumbAspectRatio = aspectRatio;

                ThumbnailGrid tg = creator.CreateThumbnailGrid(_tnSettings.LayoutMode,
                                                               nThumbs,
                                                               nCols, nRows,
                                                               crossoverThreshold);

                newContainer = tg.Layout;
                container.CalcWasted (_tnSettings, tg, out wastedWidth, out wastedHeight);

                extraWidth = (int) (wastedWidth * tg.ThumbWidth);
                extraHeight = (int) (wastedHeight * tg.ThumbHeight);
                extraWidthPercent = 100.0 * extraWidth / newContainer.Width;
                extraHeightPercent = 100.0 * extraHeight / newContainer.Height;

                THelper.Information (String.Format (
                    "{9,4}x{10,4} ({13,4:F2})  {0,4:F2} {1,2}x{2,2} {3,3:D}x{4,3:D} " +
                    "{5,6:F2}x{6,6:F2} {7,3:D}x{8,3:D}  {11:F1}x{12:F1}",
                    aspectRatio,
                    tg.NColumns, tg.NRows, tg.ThumbWidth, tg.ThumbHeight,
                    wastedWidth, wastedHeight,
                    extraWidth, extraHeight,
                    newContainer.Width, newContainer.Height,
                    extraWidthPercent, extraHeightPercent,
                    newContainer.AspectRatio
                    ));

                int index;

                if (plotThresholds)
                    {
                    index = seriesWW.Points.AddXY (aspectRatio, wastedWidth * 100.0);
                    if (wastedWidth == 0.0)
                        seriesWW.Points[index].IsEmpty = true;

                    index = seriesWH.Points.AddXY (aspectRatio, wastedHeight * 100.0);
                    if (wastedHeight == 0.0)
                        seriesWH.Points[index].IsEmpty = true;
                    }

                seriesNCols.Points.AddXY (aspectRatio, tg.NColumns);
                seriesNRows.Points.AddXY (aspectRatio, tg.NRows);
                }
            chartArea.RecalculateAxesScale ();

            AddARAnnotation (chart, "Fullscreen 4:3\n(1.33)", 1.33, annotationFont, plotThresholds);
            AddARAnnotation (chart, "HD 16:9\n(1.78)", 1.78, annotationFont, plotThresholds);
            AddARAnnotation (chart, "Widescreen\n(1.85)", 1.85, annotationFont, plotThresholds);
            AddARAnnotation (chart, "CinemaScope\n(2.35)", 2.35, annotationFont, plotThresholds);
            AddARAnnotation (chart, "Ultra-Panavision\n(2.76)", 2.76, annotationFont, plotThresholds);

            AddARAnnotation (chart,
                    String.Format ("Layout Threshold\n({0:F2})",
                                crossoverThreshold),
                    crossoverThreshold,
                    _tnSettings.LayoutMode == ThumbnailSettings.LayoutModes.Auto ?
                        annotationFont : annotationItFont,
                    plotThresholds,
                    true);

            if (_tnSettings.RCOptimization && plotThresholds)
                {
                switch (_tnSettings.LayoutMode)
                    {
                    case ThumbnailSettings.LayoutModes.Auto:

                        if (_tnSettings.WidthThreshold == _tnSettings.HeightThreshold)
                            AddThresholdAnnotation (chart,
                                                   String.Format ("Width & Height Threshold\n" +
                                                                 "({0:F2})", _tnSettings.WidthThreshold),
                                                   _tnSettings.WidthThreshold,
                                                   annotationFont);
                        else
                            {
                            AddThresholdAnnotation (chart,
                                                   String.Format ("Width Threshold\n" +
                                                                 "({0:F2})", _tnSettings.WidthThreshold),
                                                   _tnSettings.WidthThreshold,
                                                   annotationFont);
                            AddThresholdAnnotation (chart,
                                                   String.Format ("Height Threshold\n" +
                                                                 "({0:F2})", _tnSettings.HeightThreshold),
                                                   _tnSettings.HeightThreshold,
                                                   annotationFont);
                            }
                        break;

                    case ThumbnailSettings.LayoutModes.RowPriority:
                        AddThresholdAnnotation (chart,
                                               String.Format ("Width Threshold\n" +
                                                             "({0:F2})", _tnSettings.WidthThreshold),
                                               _tnSettings.WidthThreshold,
                                               annotationFont);
                        break;

                    case ThumbnailSettings.LayoutModes.ColumnPriority:
                        AddThresholdAnnotation (chart,
                                               String.Format ("Height Threshold\n" +
                                                             "({0:F2})", _tnSettings.HeightThreshold),
                                               _tnSettings.HeightThreshold,
                                               annotationFont);
                        break;
                    }
                }

            chart.SaveImage (filename, Charting.ChartImageFormat.Png);
            THelper.Information ("'{0}' created.", filename);

            labelStyle1.Dispose ();
            labelStyle2.Dispose ();
            labelStyle3.Dispose ();

            titleFont.Dispose ();
            subTitleFont.Dispose ();
            axisFont.Dispose ();
            annotationFont.Dispose ();
            annotationItFont.Dispose ();
            chart.Dispose ();
        }
Пример #14
0
        /// <summary>
        /// Function to add text as an annotation to the chart.
        /// </summary>
        /// <param name="text">The text that we wish to display.</param>
        /// <param name="AxisX">X-Axis that the text annotation is to use for co-ordinates.</param>
        /// <param name="AxisY">Y-Axis that the text annotation is to use for co-ordinates.</param>
        /// <param name="X">X value for the start of the text.</param>
        /// <param name="Y">Y value for the start of the text.</param>
        /// <param name="output">The chart that the line annotation is being added to.</param>
        private void addTextAnnotation(string text, Axis AxisX, Axis AxisY, double X, double Y, Chart output)
        {
            //Create a new line annotation.
            TextAnnotation textAnnotation = new TextAnnotation();

            //Set each property to the parameters passed in.
            textAnnotation.AxisX = AxisX;
            textAnnotation.AxisY = AxisY;
            textAnnotation.Y = Y;
            textAnnotation.X = X;
            textAnnotation.Text = text;

            //Turn off relative size to get graph-oriented co-ordinates and set the aesthetic properties.
            textAnnotation.IsSizeAlwaysRelative = false;
            textAnnotation.ForeColor = myForeColor;
            textAnnotation.Font = myFont;

            //Add the annotation to the chart.
            output.Annotations.Add(textAnnotation);
        }