Пример #1
0
        /// <summary>
        /// Adds a new graph line to the collection.
        /// </summary>
        /// <param name="lineColor">A <c>System.Drawing.Color</c> that represents the color of the graph line.</param>
        /// <param name="id">The Id of the graph line in the collection.</param>
        public void AddLine(int id, Color lineColor)
        {
            NuGenGraphLine pushGraphLine = new NuGenGraphLine(id);

            pushGraphLine.LineColor = lineColor;

            this.lines.Add(pushGraphLine);
        }
Пример #2
0
        /// <summary>
        /// Sets the value indicating whether to show the graph as a set of bars.
        /// </summary>
        /// <param name="index">The index of the graph line in the collection.</param>
        /// <param name="isBar"><c>true</c> to show the graph line as a set of bars; otherwise, <c>false</c>.</param>
        public void SetIsBar(int index, bool isBar)
        {
            NuGenGraphLine pushGraphLine = this.GetLineFromIndex(index);

            if (pushGraphLine != null)
            {
                pushGraphLine.IsBar = isBar;
            }
        }
Пример #3
0
        /*
         * DrawBarGdi
         */

        /// <summary>
        /// Draws a bar using native GDI.
        /// </summary>
        /// <param name="dc">Specifies drawing context for this <see cref="T:Genetibase.UI.NuGenPushGraphBar"/>.</param>
        /// <param name="rect">Specifies the bar bounds.</param>
        /// <param name="graphLine">Specifies graph line parameters.</param>
        /// <exception cref="ArgumentNullException">
        /// <para><paramref name="graphLine"/> is <see langword="null"/>.</para>
        /// </exception>
        protected virtual void DrawBarGdi(IntPtr dc, Rectangle rect, NuGenGraphLine graphLine)
        {
            if (graphLine == null)
            {
                throw new ArgumentNullException("graphLine");
            }

            RECT bufferRect = (RECT)rect;

            User32.FillSolidRect(dc, ref bufferRect, graphLine.LineColor);
        }
Пример #4
0
        /// <summary>
        /// Gets a value indicating whether to show the graph as a set of bars.
        /// </summary>
        /// <param name="index">The index of the graph line in the collection.</param>
        /// <returns><c>true</c> if the graph line is shown as a set of bars; otherwise, <c>false</c>.</returns>
        public bool GetIsBar(int index)
        {
            NuGenGraphLine pushGraphLine = this.GetLineFromIndex(index);

            if (pushGraphLine != null)
            {
                return(pushGraphLine.IsBar);
            }
            else
            {
                return(false);
            }
        }
Пример #5
0
        /// <summary>
        /// Adds a new value to the specified graph line.
        /// </summary>
        /// <param name="index">The index of the graph line to add the value to.</param>
        /// <param name="value">The value to add.</param>
        public void Push(int index, float value)
        {
            NuGenGraphLine pushGraphLine = this.GetLineFromIndex(index);

            value = Math.Max(value, this.Minimum);
            value = Math.Min(value, int.MaxValue);

            if (value > this.Maximum)
            {
                this.Maximum = value;
            }

            value -= this.Minimum;
            value += this.peekOffset;

            pushGraphLine.Values.Add(value);
        }
Пример #6
0
        /*
         * DrawBarGdiPlus
         */

        /// <summary>
        /// Draws a bar within the specified rectangle with the specified color.
        /// </summary>
        /// <param name="g">A <c>System.Drawing.Graphics</c> to draw on.</param>
        /// <param name="rect">A <c>System.Drawing.RectangleF</c> to fit the bar in.</param>
        /// <param name="line">Incapsulates a graph line.</param>
        /// <exception cref="ArgumentNullException">
        /// <para><paramref name="g"/> is <see langword="null"/>.</para>
        /// -or-
        /// <para><paramref name="line"/> is <see langword="null"/>.</para>
        /// </exception>
        protected virtual void DrawBarGdiPlus(Graphics g, RectangleF rect, NuGenGraphLine line)
        {
            if (g == null)
            {
                throw new ArgumentNullException("g");
            }

            if (line == null)
            {
                throw new ArgumentNullException("line");
            }

            using (SolidBrush sb = new SolidBrush(NuGenControlPaint.ColorFromArgb(this.ForegroundTransparency, line.LineColor)))
            {
                g.FillRectangle(sb, rect);
            }
        }
Пример #7
0
        /*
         * DrawGraphGdi
         */

        /// <summary>
        /// Draws the graph using native GDI.
        /// </summary>
        /// <param name="dc">Specifies drawing context for this <see cref="T:Genetibase.UI.NuGenPushGraphBar"/>.</param>
        /// <param name="rect">Specifies the <see cref="T:System.Drawing.Rectangle"/> to fit the graph in.</param>
        protected virtual void DrawGraphGdi(IntPtr dc, Rectangle rect)
        {
            int maxPoints = 0;

            if (this.maxCoords == -1)
            {
                /* Maximum push points not yet calculated. */

                this.maxCoords = (rect.Width / this.Step) + 2
                                 + ((rect.Width % this.Step > 0) ? 1 : 0);

                if (this.maxCoords <= 0)
                {
                    this.maxCoords = 1;
                }
            }

            for (int lineIndex = 0; lineIndex < this.lines.Count; lineIndex++)
            {
                if (maxPoints < this.lines[lineIndex].Values.Count)
                {
                    maxPoints = this.lines[lineIndex].Values.Count;
                }
            }

            if (maxPoints == 0 /* No lines to draw. */)
            {
                return;
            }

            for (int lineIndex = 0; lineIndex < this.lines.Count; lineIndex++)
            {
                /*
                 * If the line has less push points than the line with the greatest
                 * number of push points, new push points are appended with
                 * the same value as the previous push point. If no push points
                 * exist for the line, one is added with the least value possible.
                 */

                NuGenGraphLine pushGraphLine = this.lines[lineIndex];

                if (pushGraphLine.Values.Count == 0)
                {
                    pushGraphLine.Values.Add(this.Minimum);
                }

                while (pushGraphLine.Values.Count < maxPoints)
                {
                    pushGraphLine.Values.Add(pushGraphLine.Values[pushGraphLine.Values.Count - 1]);
                }

                while (this.lines[lineIndex].Values.Count >= this.maxCoords)
                {
                    this.lines[lineIndex].Values.RemoveAt(0);
                }

                if (this.lines[lineIndex].Values.Count == 0 /* No push points to draw. */)
                {
                    return;
                }

                /* Now prepare to draw the line or bar. */

                IntPtr penLine = Gdi32.CreatePen(
                    WinGdi.PS_SOLID,
                    PEN_WIDTH,
                    ColorTranslator.ToWin32(this.lines[lineIndex].LineColor)
                    );

                IntPtr hOldPen = Gdi32.SelectObject(dc, penLine);

                if (pushGraphLine.IsBar)
                {
                    Gdi32.MoveTo(dc, rect.Left, rect.Height);
                }
                else
                {
                    float initialValue = pushGraphLine.Values[0];
                    float percent      = (float)(rect.Height - PEN_WIDTH) / (this.Maximum - this.Minimum);
                    float relValue     = (float)(rect.Height - PEN_WIDTH) - initialValue * percent;

                    Gdi32.MoveTo(dc, (int)rect.Left, (int)(maxPoints == 1 ? rect.Height : relValue));
                }

                for (int valueIndex = 0; valueIndex < pushGraphLine.Values.Count; valueIndex++)
                {
                    int   xOffset      = rect.Left + (valueIndex * this.Step);
                    float initialValue = pushGraphLine.Values[valueIndex];
                    float percent      = (float)rect.Height / (float)(this.Maximum - this.Minimum);
                    int   relValue     = Math.Max(PEN_WIDTH * 2, (int)(rect.Height - initialValue * percent));

                    if (pushGraphLine.IsBar)
                    {
                        /* Draw a bar. */

                        Rectangle rectBar = new Rectangle(
                            xOffset,
                            relValue,
                            this.Step,
                            rect.Height
                            );

                        this.DrawBarGdi(dc, rectBar, pushGraphLine);
                    }
                    else
                    {
                        /* Draw a line. */
                        Gdi32.LineTo(dc, xOffset, relValue);
                    }
                }

                Gdi32.SelectObject(dc, hOldPen);
                Gdi32.DeleteObject(penLine);
            }
        }
Пример #8
0
        /// <summary>
        /// Sets the color of a graph line at the specified index in the collection.
        /// </summary>
        /// <param name="index">The index of the line to set the color for.</param>
        /// <param name="lineColor">The color to set for the line.</param>
        public void SetLineColor(int index, Color lineColor)
        {
            NuGenGraphLine pushGraphLine = this.GetLineFromIndex(index);

            pushGraphLine.LineColor = lineColor;
        }
Пример #9
0
        /// <summary>
        /// Gets the color of a graph line at the specified index in the collection.
        /// </summary>
        /// <param name="index">The index of the graph line to get the color for.</param>
        /// <returns>A <c>System.Drawing.Color</c> that represents the color of the graph line.</returns>
        public Color GetLineColor(int index)
        {
            NuGenGraphLine pushGraphLine = this.GetLineFromIndex(index);

            return((pushGraphLine != null) ? pushGraphLine.LineColor : Color.Black);
        }
Пример #10
0
        /*
         * DrawGraphGdiPlus
         */

        /// <summary>
        /// Draws the graph.
        /// </summary>
        /// <param name="g">A <c>System.Drawing.Graphics</c> to draw on.</param>
        /// <param name="rect">A <c>System.Drawing.Rectangle</c> to fit the graph in.</param>
        /// <exception cref="ArgumentNullException">
        /// <para><paramref name="g"/> is <see langword="null"/>.</para>
        /// </exception>
        protected virtual void DrawGraphGdiPlus(Graphics g, Rectangle rect)
        {
            if (g == null)
            {
                throw new ArgumentNullException("g");
            }

            int maxPoints = 0;

            if (this.maxCoords == -1)
            {
                /* Maximum push points not yet calculated. */

                this.maxCoords = (rect.Width / this.Step) + 2
                                 + ((rect.Width % this.Step > 0) ? 1 : 0);

                if (this.maxCoords <= 0)
                {
                    this.maxCoords = 1;
                }
            }

            for (int lineIndex = 0; lineIndex < this.lines.Count; lineIndex++)
            {
                if (maxPoints < this.lines[lineIndex].Values.Count)
                {
                    maxPoints = this.lines[lineIndex].Values.Count;
                }
            }

            if (maxPoints == 0 /* No lines to draw. */)
            {
                return;
            }

            for (int lineIndex = 0; lineIndex < this.lines.Count; lineIndex++)
            {
                /*
                 * If the line has less push points than the line with the greatest
                 * number of push points, new push points are appended with
                 * the same value as the previous push point. If no push points
                 * exist for the line, one is added with the least value possible.
                 */

                NuGenGraphLine pushGraphLine = this.lines[lineIndex];

                if (pushGraphLine.Values.Count == 0)
                {
                    pushGraphLine.Values.Add(this.Minimum);
                }

                while (pushGraphLine.Values.Count < maxPoints)
                {
                    pushGraphLine.Values.Add(pushGraphLine.Values[pushGraphLine.Values.Count - 1]);
                }

                while (this.lines[lineIndex].Values.Count >= this.maxCoords)
                {
                    this.lines[lineIndex].Values.RemoveAt(0);
                }

                if (this.lines[lineIndex].Values.Count == 0 /* No push points to draw. */)
                {
                    return;
                }

                using (Pen p = new Pen(NuGenControlPaint.ColorFromArgb(this.ForegroundTransparency, (this.lines[lineIndex] as NuGenGraphLine).LineColor)))
                {
                    PointF startPoint = PointF.Empty;
                    PointF endPoint   = PointF.Empty;

                    if (pushGraphLine.IsBar)
                    {
                        startPoint = new PointF(rect.Left, rect.Height);
                    }
                    else
                    {
                        float initialValue = pushGraphLine.Values[0];
                        float percent      = (float)(rect.Height - PEN_WIDTH) / (this.Maximum - this.Minimum);
                        float relValue     = (float)(rect.Height - PEN_WIDTH) - initialValue * percent;

                        startPoint = new PointF(rect.Left, maxPoints == 1 ? rect.Height : relValue);
                    }

                    for (int valueIndex = 0; valueIndex < pushGraphLine.Values.Count; valueIndex++)
                    {
                        float xOffset      = rect.Left + (valueIndex * this.Step);
                        float initialValue = pushGraphLine.Values[valueIndex];
                        float percent      = (float)rect.Height / (float)(this.Maximum - this.Minimum);
                        float relValue     = Math.Max(PEN_WIDTH * 2, (float)rect.Height - initialValue * percent);

                        if (pushGraphLine.IsBar)
                        {
                            /* Draw a bar. */

                            RectangleF rectBar = new RectangleF(
                                xOffset,
                                relValue,
                                this.Step,
                                rect.Height
                                );

                            this.DrawBarGdiPlus(g, rectBar, pushGraphLine);
                        }
                        else
                        {
                            /* Draw a line. */

                            endPoint = new PointF(xOffset, relValue);
                            g.DrawLine(p, startPoint, endPoint);
                            startPoint = endPoint;
                        }
                    }
                }
            }
        }
Пример #11
0
		/*
		 * DrawBarGdi
		 */

		/// <summary>
		/// Draws a bar using native GDI.
		/// </summary>
		/// <param name="dc">Specifies drawing context for this <see cref="T:Genetibase.UI.NuGenPushGraphBar"/>.</param>
		/// <param name="rect">Specifies the bar bounds.</param>
		/// <param name="graphLine">Specifies graph line parameters.</param>
		/// <exception cref="ArgumentNullException">
		/// <para><paramref name="graphLine"/> is <see langword="null"/>.</para>
		/// </exception>
		protected virtual void DrawBarGdi(IntPtr dc, Rectangle rect, NuGenGraphLine graphLine)
		{
			if (graphLine == null)
			{
				throw new ArgumentNullException("graphLine");
			}

			RECT bufferRect = (RECT)rect;
			User32.FillSolidRect(dc, ref bufferRect, graphLine.LineColor);
		}
Пример #12
0
		/// <summary>
		/// Adds a new graph line to the collection.
		/// </summary>
		/// <param name="lineColor">A <c>System.Drawing.Color</c> that represents the color of the graph line.</param>
		/// <param name="id">The Id of the graph line in the collection.</param>
		public void AddLine(int id, Color lineColor)
		{
			NuGenGraphLine pushGraphLine = new NuGenGraphLine(id);
			pushGraphLine.LineColor = lineColor;

			this.lines.Add(pushGraphLine);
		}
Пример #13
0
		/*
		 * DrawBarGdiPlus
		 */

		/// <summary>
		/// Draws a bar within the specified rectangle with the specified color.
		/// </summary>
		/// <param name="g">A <c>System.Drawing.Graphics</c> to draw on.</param>
		/// <param name="rect">A <c>System.Drawing.RectangleF</c> to fit the bar in.</param>
		/// <param name="line">Incapsulates a graph line.</param>
		/// <exception cref="ArgumentNullException">
		/// <para><paramref name="g"/> is <see langword="null"/>.</para>
		/// -or-
		/// <para><paramref name="line"/> is <see langword="null"/>.</para>
		/// </exception>
		protected virtual void DrawBarGdiPlus(Graphics g, RectangleF rect, NuGenGraphLine line)
		{
			if (g == null)
			{
				throw new ArgumentNullException("g");
			}

			if (line == null)
			{
				throw new ArgumentNullException("line");
			}

			using (SolidBrush sb = new SolidBrush(NuGenControlPaint.ColorFromArgb(this.ForegroundTransparency, line.LineColor)))
			{
				g.FillRectangle(sb, rect);
			}
		}