예제 #1
0
        /// <summary>
        ///     Строит график.
        /// </summary>
        /// <param name="g"></param>
        /// <param name="task">Задание для отрисовки.</param>
        /// <param name="taskIndex">Порядковый номер объекта task среди всех объектов для отрисовки.</param>
        private void Plot(Graphics g, PlotTask task, int taskIndex)
        {
            if (task.Points == null)
            {
                return;
            }
            var xValDelta = Settings.StopX - Settings.StartX;
            var yValDelta = Settings.StopY - Settings.StartY;

            var totalLen = task.Points.Sum(t => t.Length);

            if (totalLen == 0)
            {
                return;
            }

            var pointCount = (int)(totalLen * task.DrawPart);

            if (task.DrawPart > 1.0)
            {
                pointCount = task.Points.Length;
            }
            if (task.DrawPart < 0.0)
            {
                pointCount = 0;
            }
            var pointsDrawn = 0;

            var taskPen   = Theme.PlotPens[taskIndex % Theme.PlotPens.Length];
            var taskBrush = new SolidBrush(taskPen.Color);

            for (var j = 0; j < task.Points.Length && pointsDrawn < pointCount; ++j)
            {
                var tmp = new List <PointF>();
                for (var i = 0; i < task.Points[j].Length && pointsDrawn < pointCount; ++i)
                {
                    var tt = new PointF((float)(LeftMargin + (task.Points[j][i].X - Settings.StartX) / xValDelta
                                                * (Width - LeftMargin - RightMargin)),
                                        (float)
                                        (Height - (BottomMargin + (ScaleYPoint(task.Points[j][i].Y) - Settings.StartY) / yValDelta
                                                   * (Height - TopMargin - BottomMargin))));
                    if (task.Points[j].Length == 1)
                    {
                        g.FillEllipse(taskBrush, tt.X - 3, tt.Y - 3, 6, 6);
                    }
                    else
                    {
                        tmp.Add(tt);
                    }
                    pointsDrawn += 1;
                }

                if (tmp.Count > 1)
                {
                    g.DrawLines(taskPen, tmp.ToArray());
                }
            }
        }
예제 #2
0
        /// <summary>
        ///     Рисует легенду для графика.
        /// </summary>
        /// <param name="g"></param>
        /// <param name="task"></param>
        /// <param name="taskIndex">Порядковый номер объекта task среди всех объектов для отрисовки.</param>
        /// <param name="taskCount">Количество объектов task для отрисовки.</param>
        private void DrawLegend(Graphics g, PlotTask task, int taskIndex, int taskCount)
        {
            var font      = new Font("Arial", 14);
            var brush     = new SolidBrush(Theme.LegendTextColor);
            var mid       = taskCount / 2.0;
            var labelYPos = (int)(TopMargin + (Height - TopMargin - BottomMargin) / 2 + (taskIndex - mid + 0.5) * 50);

            g.DrawLine(Theme.PlotPens[taskIndex % Theme.PlotPens.Length], Width - RightMargin + 40 - 10, labelYPos,
                       Width - RightMargin + 50, labelYPos);
            g.DrawString(task.Legend, font, brush,
                         Width - RightMargin + 40 - 5 + 25, labelYPos - 12);
        }
예제 #3
0
        /// <summary>
        ///     Строит график.
        /// </summary>
        /// <param name="g"></param>
        /// <param name="task">Задание для отрисовки.</param>
        /// <param name="taskIndex">Порядковый номер объекта task среди всех объектов для отрисовки.</param>
        private void Plot(Graphics g, PlotTask task, int taskIndex)
        {
            if (task.Points == null) return;
            var xValDelta = Settings.StopX - Settings.StartX;
            var yValDelta = Settings.StopY - Settings.StartY;

            var totalLen = task.Points.Sum(t => t.Length);

            if (totalLen == 0) return;

            var pointCount = (int)(totalLen * task.DrawPart);
            if (task.DrawPart > 1.0)
                pointCount = task.Points.Length;
            if (task.DrawPart < 0.0)
                pointCount = 0;
            var pointsDrawn = 0;

            var taskPen = Theme.PlotPens[taskIndex % Theme.PlotPens.Length];
            var taskBrush = new SolidBrush(taskPen.Color);

            for (var j = 0; j < task.Points.Length && pointsDrawn < pointCount; ++j)
            {
                var tmp = new List<PointF>();
                for (var i = 0; i < task.Points[j].Length && pointsDrawn < pointCount; ++i)
                {
                    var tt = new PointF((float)(LeftMargin + (task.Points[j][i].X - Settings.StartX) / xValDelta
                                                 * (Width - LeftMargin - RightMargin)),
                        (float)
                            (Height - (BottomMargin + (ScaleYPoint(task.Points[j][i].Y) - Settings.StartY) / yValDelta
                                       * (Height - TopMargin - BottomMargin))));
                    if (task.Points[j].Length == 1)
                    {
                        g.FillEllipse(taskBrush, tt.X - 3, tt.Y - 3, 6, 6);
                    }
                    else
                    {
                        tmp.Add(tt);
                    }
                    pointsDrawn += 1;
                }

                if (tmp.Count > 1)
                {
                    g.DrawLines(taskPen, tmp.ToArray());
                }
            }
        }
예제 #4
0
 /// <summary>
 ///     Рисует легенду для графика.
 /// </summary>
 /// <param name="g"></param>
 /// <param name="task"></param>
 /// <param name="taskIndex">Порядковый номер объекта task среди всех объектов для отрисовки.</param>
 /// <param name="taskCount">Количество объектов task для отрисовки.</param>
 private void DrawLegend(Graphics g, PlotTask task, int taskIndex, int taskCount)
 {
     var font = new Font("Arial", 14);
     var brush = new SolidBrush(Theme.LegendTextColor);
     var mid = taskCount / 2.0;
     var labelYPos = (int)(TopMargin + (Height - TopMargin - BottomMargin) / 2 + (taskIndex - mid + 0.5) * 50);
     g.DrawLine(Theme.PlotPens[taskIndex % Theme.PlotPens.Length], Width - RightMargin + 40 - 10, labelYPos,
         Width - RightMargin + 50, labelYPos);
     g.DrawString(task.Legend, font, brush,
         Width - RightMargin + 40 - 5 + 25, labelYPos - 12);
 }