Example #1
0
        private void RenderOnBitmap(Graphics gfx, LegendItem[] items, System.Drawing.Font font,
                                    float locationX, float locationY, float width, float height, float maxLabelHeight,
                                    bool shadow = true, bool outline = true)
        {
            using (var fillBrush = new SolidBrush(FillColor))
                using (var shadowBrush = new SolidBrush(ShadowColor))
                    using (var textBrush = new SolidBrush(Font.Color))
                        using (var outlinePen = new Pen(OutlineColor))
                        {
                            if (AntiAlias)
                            {
                                gfx.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                                gfx.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
                            }

                            RectangleF rectShadow = new RectangleF(locationX + ShadowOffsetX, locationY + ShadowOffsetY, width, height);
                            RectangleF rectFill   = new RectangleF(locationX, locationY, width, height);

                            if (shadow)
                            {
                                gfx.FillRectangle(shadowBrush, rectShadow);
                            }

                            gfx.FillRectangle(fillBrush, rectFill);

                            if (outline)
                            {
                                gfx.DrawRectangle(outlinePen, Rectangle.Round(rectFill));
                            }

                            for (int i = 0; i < items.Length; i++)
                            {
                                var   item           = items[i];
                                float verticalOffset = i * maxLabelHeight;

                                // draw text
                                gfx.DrawString(item.label, font, textBrush, locationX + SymbolWidth, locationY + verticalOffset);

                                // prepare values for drawing a line
                                outlinePen.Color = item.color;
                                outlinePen.Width = 1;
                                float lineY  = locationY + verticalOffset + maxLabelHeight / 2;
                                float lineX1 = locationX + SymbolPad;
                                float lineX2 = lineX1 + SymbolWidth - SymbolPad * 2;

                                // prepare values for drawing a rectangle
                                PointF     rectOrigin = new PointF(lineX1, (float)(lineY - item.lineWidth / 2));
                                SizeF      rectSize   = new SizeF(lineX2 - lineX1, (float)item.lineWidth);
                                RectangleF rect       = new RectangleF(rectOrigin, rectSize);

                                if (item.IsRectangle)
                                {
                                    // draw a rectangle
                                    using (var legendItemFillBrush = GDI.Brush(item.color, item.hatchColor, item.hatchStyle))
                                        using (var legendItemOutlinePen = new Pen(item.borderColor, item.borderWith))
                                        {
                                            gfx.FillRectangle(legendItemFillBrush, rect);
                                            gfx.DrawRectangle(legendItemOutlinePen, rect.X, rect.Y, rect.Width, rect.Height);
                                        }
                                }
                                else
                                {
                                    // draw a line
                                    using (var linePen = GDI.Pen(item.color, item.lineWidth, item.lineStyle, false))
                                        gfx.DrawLine(linePen, lineX1, lineY, lineX2, lineY);

                                    // and perhaps a marker in the middle of the line
                                    float  lineXcenter = (lineX1 + lineX2) / 2;
                                    PointF markerPoint = new PointF(lineXcenter, lineY);
                                    if ((item.markerShape != MarkerShape.none) && (item.markerSize > 0))
                                    {
                                        MarkerTools.DrawMarker(gfx, markerPoint, item.markerShape, MarkerWidth, item.color);
                                    }
                                }
                            }
                        }
        }
Example #2
0
        /// <summary>
        /// Render an evenly-spaced 2D vector field.
        /// </summary>
        public void Render(PlotDimensions dims, Graphics gfx, double[] xs, double[] ys, Statistics.Vector2[,] vectors, Color[] colors)
        {
            (float tipScale, float headAngle) = GetTipDimensions(); // precalculate angles for fancy arrows

            using Pen pen = Drawing.GDI.Pen(Color.Black);
            if (!ScaledArrowheads)
            {
                pen.CustomEndCap = new System.Drawing.Drawing2D.AdjustableArrowCap(NonScaledArrowheadWidth, NonScaledArrowheadLength);
            }

            for (int i = 0; i < xs.Length; i++)
            {
                for (int j = 0; j < ys.Length; j++)
                {
                    Statistics.Vector2 v = vectors[i, j];
                    float tailX, tailY, endX, endY;

                    switch (Anchor)
                    {
                    case ArrowAnchor.Base:
                        tailX = dims.GetPixelX(xs[i]);
                        tailY = dims.GetPixelY(ys[j]);
                        endX  = dims.GetPixelX(xs[i] + v.X);
                        endY  = dims.GetPixelY(ys[j] + v.Y);
                        break;

                    case ArrowAnchor.Center:
                        tailX = dims.GetPixelX(xs[i] - v.X / 2);
                        tailY = dims.GetPixelY(ys[j] - v.Y / 2);
                        endX  = dims.GetPixelX(xs[i] + v.X / 2);
                        endY  = dims.GetPixelY(ys[j] + v.Y / 2);
                        break;

                    case ArrowAnchor.Tip:
                        tailX = dims.GetPixelX(xs[i] - v.X);
                        tailY = dims.GetPixelY(ys[j] - v.Y);
                        endX  = dims.GetPixelX(xs[i]);
                        endY  = dims.GetPixelY(ys[j]);
                        break;

                    default:
                        throw new NotImplementedException("unsupported anchor type");
                    }

                    pen.Color = colors[i * ys.Length + j];
                    if (ScaledArrowheads)
                    {
                        DrawFancyArrow(gfx, pen, tailX, tailY, endX, endY, headAngle, tipScale);
                    }
                    else
                    {
                        gfx.DrawLine(pen, tailX, tailY, endX, endY);
                    }

                    if (MarkerShape != MarkerShape.none && MarkerSize > 0)
                    {
                        PointF markerPoint = new PointF(dims.GetPixelX(xs[i]), dims.GetPixelY(ys[j]));
                        MarkerTools.DrawMarker(gfx, markerPoint, MarkerShape, MarkerSize, pen.Color);
                    }
                }
            }
        }
Example #3
0
 public void Draw(Graphics gfx, PointF center, float size, Brush brush, Pen pen)
 {
     PointF[] points = MarkerTools.DiamondPoints(center, size);
     gfx.DrawPolygon(pen, points);
 }
Example #4
0
 public void Draw(Graphics gfx, PointF center, float size, Brush brush, Pen pen)
 {
     PointF[] points = MarkerTools.TriangleDownPoints(center, size);
     gfx.FillPolygon(brush, points);
 }
Example #5
0
 public void Draw(Graphics gfx, PointF center, float size, Brush brush, Pen pen)
 {
     PointF[] points = MarkerTools.TriangleUpPoints(center, size);
     MarkerTools.DrawRadial(gfx, pen, center, points);
 }