Esempio n. 1
0
        /// <summary>
        /// Draw the text on the graphics.
        /// </summary>
        public static void Draw(Graphics g, Point pos, string Text, System.Drawing.Rectangle rectangle, xPFT.Charting.Base.FontDrawFlags fontDrawFlag, System.Drawing.Color color, float opacity, float RotateAngle, System.Drawing.Font font)
        {
            //! Set the String Format.
            StringFormat sf = new StringFormat();

            if (fontDrawFlag == xPFT.Charting.Base.FontDrawFlags.Left)
            {
                sf.Alignment = StringAlignment.Near;
            }
            else if (fontDrawFlag == xPFT.Charting.Base.FontDrawFlags.Right)
            {
                sf.Alignment = StringAlignment.Far;
            }
            else if (fontDrawFlag == xPFT.Charting.Base.FontDrawFlags.Center)
            {
                sf.Alignment = StringAlignment.Center;
            }
            //! Create A font from parent control font.
            rectangle.Height = (int)(font.SizeInPoints * 1.5);
            //! Translate the text.
            g.TranslateTransform(rectangle.X + pos.X, rectangle.Y + pos.Y);
            //! Rotate the text.
            if (RotateAngle != 0)
            {
                //  g.TranslateTransform(-rectangle.Width / 2 - rectangle.Height / 2, 0);
                g.RotateTransform((float)(RotateAngle * 180 / Math.PI));
            }
            System.Drawing.Font newFont = new System.Drawing.Font(font.FontFamily, font.Size * 0.8f, font.Style);
            rectangle.Height = (int)(newFont.SizeInPoints * 1.5);
            //! Draw the text.
            g.DrawString(Text, newFont, new SolidBrush(BrushMaker.SetOpacity(color, opacity)), new RectangleF(0, 0, rectangle.Width, rectangle.Height), sf);
            //! Reset the transform.
            g.ResetTransform();
        }
Esempio n. 2
0
 /// <summary>
 /// Draw a point on the each point of the collections.
 /// </summary>
 public static void DrawPoints(Graphics g, Point pos, System.Drawing.PointF[] points, System.Drawing.Color color, float opacity = 1, int pointType = 0, float lineWidth = 1)
 {
     g.TranslateTransform(pos.X, pos.Y);
     for (int index = 0; index < points.Length; index++)
     {
         if (pointType == 0)
         {
             g.FillEllipse(new SolidBrush(BrushMaker.SetOpacity(color, opacity)), points[index].X - lineWidth / 2, points[index].Y - lineWidth / 2, lineWidth, lineWidth);
         }
         if (pointType == 1)
         {
             g.FillRectangle(new SolidBrush(BrushMaker.SetOpacity(color, opacity)), points[index].X - lineWidth / 2, points[index].Y - lineWidth / 2, lineWidth, lineWidth);
         }
         if (pointType == 2)
         {
             g.DrawLines(new Pen(BrushMaker.SetOpacity(color, opacity)), GetDrawStarArray(points[index].X, points[index].Y, 5).ToArray());
         }
         if (pointType == 3)
         {
             g.DrawLines(new Pen(BrushMaker.SetOpacity(color, opacity)), GetDrawXArray(points[index].X, points[index].Y, 5).ToArray());
         }
         if (pointType == 4)
         {
             g.DrawPolygon(new Pen(BrushMaker.SetOpacity(color, opacity), 1), GetDrawDiamondArrayPointF(points[index].X, points[index].Y, 5).ToArray());
         }
     }
     g.ResetTransform();
 }
Esempio n. 3
0
 public static void Draw(Graphics g, Point pos, System.Drawing.PointF[] points, System.Drawing.Color color, float opacity = 1, float lineWidth = 1)
 {
     g.TranslateTransform(pos.X, pos.Y);
     if (color != null)
     {
         g.DrawPolygon(new Pen(BrushMaker.SetOpacity((Color)color, opacity), lineWidth), points);
     }
     g.ResetTransform();
 }
Esempio n. 4
0
 public static void Draw(Graphics g, Point pos, System.Drawing.Rectangle rectangle, System.Drawing.Bitmap bitmap, System.Drawing.Color?borderColor, float opacity = 1, float lineWidth = 1)
 {
     g.TranslateTransform(pos.X, pos.Y);
     if (bitmap != null)
     {
         g.FillRectangle(new TextureBrush(bitmap), rectangle);
     }
     if (borderColor != null)
     {
         g.DrawRectangle(new Pen(BrushMaker.SetOpacity((Color)borderColor, opacity), lineWidth), rectangle);
     }
     g.ResetTransform();
 }
Esempio n. 5
0
 public static void Draw(Graphics g, Point pos, System.Drawing.Rectangle rectangle, System.Drawing.Color?borderColor, System.Drawing.Color?fillColor, float opacity, xPFT.Charting.Base.FillPattern fillPattern, float patternSize, float lineWidth)
 {
     g.TranslateTransform(pos.X, pos.Y);
     if (fillColor != null)
     {
         g.FillRectangle(BrushMaker.GetPatternBrush((System.Drawing.Color)fillColor, opacity, fillPattern, (int)patternSize), rectangle);
     }
     if (borderColor != null)
     {
         g.DrawRectangle(new Pen(BrushMaker.SetOpacity((Color)borderColor, opacity), lineWidth), rectangle);
     }
     g.ResetTransform();
 }
Esempio n. 6
0
 /// <summary>
 /// Draw line with the width and height scale.
 /// </summary>
 public static void Draw(Graphics g, Point pos, System.Drawing.PointF[] points, System.Drawing.Color color, float wScale, float hScale, float opacity = 1, float width = 1, Charting.Base.LineDrawPattern linePattern = Charting.Base.LineDrawPattern.SOLID)
 {
     if (g != null)
     {
         Pen pen = new Pen(BrushMaker.SetOpacity(color, opacity), width);
         if (linePattern != Charting.Base.LineDrawPattern.SOLID)
         {
             pen.DashPattern = Charting.Base.GetLineDrawPattern.ForD2D1(linePattern);
         }
         g.TranslateTransform(pos.X, pos.Y);
         g.ScaleTransform(wScale, hScale);
         g.DrawLines(pen, points);
     }
 }
Esempio n. 7
0
 /// <summary>
 /// Draw the Line.
 /// </summary>
 public static void Draw(Graphics g, Point pos, System.Drawing.PointF[] points, System.Drawing.Color color, float opacity = 1, float width = 1, Charting.Base.LineDrawPattern linePattern = Charting.Base.LineDrawPattern.SOLID)
 {
     try
     {
         Pen pen = new Pen(BrushMaker.SetOpacity(color, opacity), width);
         if (linePattern != Charting.Base.LineDrawPattern.SOLID)
         {
             pen.DashPattern = Charting.Base.GetLineDrawPattern.ForD2D1(linePattern);
             pen.DashOffset  = width;
         }
         g.TranslateTransform(pos.X, pos.Y);
         g.DrawLines(pen, points);
         g.ResetTransform();
     }
     catch { }
 }
Esempio n. 8
0
        /// <summary>
        /// Draw line with the data point collection.
        /// </summary>
        public static void Draw(Graphics g, Point pos, Charting.Base.DataPointCollection points, float xAxesCenterHeight, float yAxesCenterWidth, float HeightRate, float WidthRate, float xAxesMaxValue, System.Drawing.Color color, float opacity = 1, bool autoShift = true, bool keepInRightOfYAxis = false, float width = 1, Charting.Base.LineDrawPattern linePattern = Charting.Base.LineDrawPattern.SOLID)
        {
            PointF[] tmpPointArray;
            float    MinX;
            float    tmpYAxesCenterWidth = yAxesCenterWidth;

            tmpPointArray = DrawingBase.Convertor.convertDataPointToPointFArray(points, HeightRate, WidthRate, out MinX);
            if (tmpPointArray.Length > 1)
            {
                if (autoShift)
                {
                    if (points.GetLast().XValue > xAxesMaxValue)
                    {
                        tmpYAxesCenterWidth = -((float)points.GetLast().XValue - xAxesMaxValue) * WidthRate + yAxesCenterWidth;
                    }
                    else
                    {
                        tmpYAxesCenterWidth = -tmpPointArray[0].X + yAxesCenterWidth;
                    }
                }
                if (keepInRightOfYAxis)
                {
                    if (MinX < 0)
                    {
                        tmpYAxesCenterWidth = tmpYAxesCenterWidth - MinX;
                    }
                }
                var oldTrans = g.Transform;
                g.TranslateTransform(tmpYAxesCenterWidth + pos.X, xAxesCenterHeight + pos.Y);
                Pen pen = new Pen(BrushMaker.SetOpacity(color, opacity), width);
                if (linePattern != Charting.Base.LineDrawPattern.SOLID)
                {
                    pen.DashPattern = Charting.Base.GetLineDrawPattern.ForD2D1(linePattern);
                }
                g.DrawLines(pen, tmpPointArray);
                //g.TranslateTransform(-tmpYAxesCenterWidth, -xAxesCenterHeight);
                g.Transform = oldTrans;
            }
        }
Esempio n. 9
0
        /// <summary>
        /// Draw a point on the each point of the collections.
        /// </summary>
        public static void DrawPoints(Graphics g, Point pos, Charting.Base.DataPointCollection points, float xAxesCenterHeight, float yAxesCenterWidth, float HeightRate, float WidthRate, float xAxesMaxValue, System.Drawing.Color color, int pointType = 0, float opacity = 1, bool autoShift = true, bool keepInRightOfYAxis = false, float Width = 1, bool isDrawPointLabel = false, Font font = null)
        {
            if (font == null)
            {
                font = new Font("arial", 8);
            }
            PointF[] tmpPointArray;
            float    MinX;
            float    tmpYAxesCenterWidth = yAxesCenterWidth;

            tmpPointArray = DrawingBase.Convertor.convertDataPointToPointFArray(points, HeightRate, WidthRate, out MinX);
            if (tmpPointArray.Length > 1)
            {
                if (autoShift)
                {
                    if (points.GetLast().XValue > xAxesMaxValue)
                    {
                        tmpYAxesCenterWidth = -((float)points.GetLast().XValue - xAxesMaxValue) * WidthRate + yAxesCenterWidth;
                    }
                    else
                    {
                        tmpYAxesCenterWidth = -tmpPointArray[0].X + yAxesCenterWidth;
                    }
                }
                if (keepInRightOfYAxis)
                {
                    if (MinX < 0)
                    {
                        tmpYAxesCenterWidth = tmpYAxesCenterWidth - MinX;
                    }
                }

                g.TranslateTransform(tmpYAxesCenterWidth + pos.X, xAxesCenterHeight + pos.Y);
                for (int index = 0; index < tmpPointArray.Length; index++)
                {
                    if (pointType == 0)
                    {
                        g.FillEllipse(new SolidBrush(BrushMaker.SetOpacity(color, opacity)), tmpPointArray[index].X - Width / 2, tmpPointArray[index].Y - Width / 2, Width, Width);
                    }
                    if (pointType == 1)
                    {
                        g.FillRectangle(new SolidBrush(BrushMaker.SetOpacity(color, opacity)), tmpPointArray[index].X - Width / 2, tmpPointArray[index].Y - Width / 2, Width, Width);
                    }
                    if (pointType == 2)
                    {
                        g.DrawLines(new Pen(BrushMaker.SetOpacity(color, opacity)), GetDrawStarArray(tmpPointArray[index].X, tmpPointArray[index].Y, 5).ToArray());
                    }
                    if (pointType == 3)
                    {
                        g.DrawLines(new Pen(BrushMaker.SetOpacity(color, opacity)), GetDrawXArray(tmpPointArray[index].X, tmpPointArray[index].Y, 5).ToArray());
                    }
                    if (pointType == 4)
                    {
                        g.DrawPolygon(new Pen(BrushMaker.SetOpacity(color, opacity), 1), GetDrawDiamondArrayPointF(tmpPointArray[index].X, tmpPointArray[index].Y, 5).ToArray());
                    }

                    //   g.ResetTransform();
                    if (isDrawPointLabel)
                    {
                        var str = tmpPointArray[index].Y.ToString();
                        if (points[index].Tag != null)
                        {
                            str = points[index].Tag.ToString();
                        }
                        System.Drawing.Drawing2D.Matrix tempMat = g.Transform;
                        // g.TranslateTransform(tmpYAxesCenterWidth , xAxesCenterHeight );
                        TextWriter.Draw(g, new Point(), str, new System.Drawing.Rectangle((int)(tmpPointArray[index].X) - 20, (int)(tmpPointArray[index].Y) - 15, 40, 40), Charting.Base.FontDrawFlags.Center, color, 1, 0, font);
                        g.Transform = tempMat;
                    }
                }
            }
        }
Esempio n. 10
0
        public static Brush GetPatternBrush(System.Drawing.Color fillColor, float opacity, xPFT.Charting.Base.FillPattern fillPattern, int patternSize = 10)
        {
            //BitmapRenderTarget brt = new BitmapRenderTarget(renderTarget, CompatibleRenderTargetOptions.None, new SharpDX.Size2F(patternSize, patternSize));
            Bitmap     bitmap     = new Bitmap(patternSize, patternSize);
            Graphics   g          = Graphics.FromImage(bitmap);
            Pen        pen        = new Pen(BrushMaker.SetOpacity(fillColor, opacity), 1);
            SolidBrush solidBrush = new SolidBrush(BrushMaker.SetOpacity(fillColor, opacity));

            if (fillPattern == xPFT.Charting.Base.FillPattern.Solid)
            {
                return(solidBrush);
            }
            switch (fillPattern)
            {
            case xPFT.Charting.Base.FillPattern.Hachure_Double:
                g.DrawLine(pen, new Point(0, 0), new Point(patternSize, patternSize));
                g.DrawLine(pen, new Point(patternSize, 0), new Point(0, patternSize));
                break;

            case xPFT.Charting.Base.FillPattern.Hachure:
                g.DrawLine(pen, new Point(patternSize, 0), new Point(0, patternSize));
                break;

            case xPFT.Charting.Base.FillPattern.Hashure_Back:
                g.DrawLine(pen, new Point(0, 0), new Point(patternSize, patternSize));
                break;

            case xPFT.Charting.Base.FillPattern.Dash:
                g.DrawLine(pen, new Point(0, patternSize / 4), new Point(patternSize / 4, patternSize / 4));
                g.DrawLine(pen, new Point(patternSize * 3 / 4, patternSize / 4), new Point(patternSize, patternSize / 4));
                g.DrawLine(pen, new Point(patternSize / 4, patternSize * 3 / 4), new Point(patternSize * 3 / 4, patternSize * 3 / 4));
                break;

            case xPFT.Charting.Base.FillPattern.Squre:
                g.DrawLine(pen, new Point(0, patternSize / 2), new Point(patternSize, patternSize / 2));
                g.DrawLine(pen, new Point(patternSize / 2, 0), new Point(patternSize / 2, patternSize));
                break;

            case xPFT.Charting.Base.FillPattern.Dot:
                g.FillEllipse(solidBrush, patternSize / 4, patternSize / 4, 1, 1);
                g.FillEllipse(solidBrush, patternSize / 4, patternSize * 3 / 4, 1, 1);
                g.FillEllipse(solidBrush, patternSize * 3 / 4, patternSize / 4, 1, 1);
                g.FillEllipse(solidBrush, patternSize * 3 / 4, patternSize * 3 / 4, 1, 1);
                break;

            case xPFT.Charting.Base.FillPattern.Zig_Zag_Horizontal:
                g.DrawLine(pen, new Point(0, patternSize / 2), new Point(patternSize / 2, 0));
                g.DrawLine(pen, new Point(patternSize, patternSize / 2), new Point(patternSize / 2, 0));
                g.DrawLine(pen, new Point(0, patternSize), new Point(patternSize / 2, patternSize / 2));
                g.DrawLine(pen, new Point(patternSize, patternSize), new Point(patternSize / 2, patternSize / 2));
                break;

            case xPFT.Charting.Base.FillPattern.Zig_Zag_Vertical:
                g.DrawLine(pen, new Point(patternSize / 2, 0), new Point(0, patternSize / 2));
                g.DrawLine(pen, new Point(patternSize / 2, patternSize), new Point(0, patternSize / 2));
                g.DrawLine(pen, new Point(patternSize, 0), new Point(patternSize / 2, patternSize / 2));
                g.DrawLine(pen, new Point(patternSize, patternSize), new Point(patternSize / 2, patternSize / 2));
                break;
            }

            TextureBrush br = new TextureBrush(bitmap);

            g.Dispose();
            pen.Dispose();
            bitmap.Dispose();
            solidBrush.Dispose();
            return(br);
        }