예제 #1
0
        public void Render(PlotDimensions dims, Bitmap bmp, bool lowQuality = false)
        {
            PointF[] points = new PointF[Count];
            for (int i = 0; i < Count; i++)
            {
                points[i] = new PointF(dims.GetPixelX(Xs[i]), dims.GetPixelY(Ys[i]));
            }

            using (var gfx = GDI.Graphics(bmp, dims, lowQuality))
                using (var linePen = GDI.Pen(Color, LineWidth, LineStyle, true))
                {
                    if (LineStyle != LineStyle.None && LineWidth > 0 && Count > 1)
                    {
                        gfx.DrawLines(linePen, points);
                    }

                    if (MarkerShape != MarkerShape.none && MarkerSize > 0 && Count > 0)
                    {
                        foreach (PointF point in points)
                        {
                            MarkerTools.DrawMarker(gfx, point, MarkerShape, MarkerSize, Color);
                        }
                    }
                }
        }
예제 #2
0
        private void RenderOnBitmap(Graphics gfx, LegendItem[] items, Font font,
                                    float locationX, float locationY, float width, float height, float maxLabelHeight,
                                    bool shadow = true, bool fill = true, bool outline = true)
        {
            using (var fillBrush = new SolidBrush(FillColor))
                using (var shadowBrush = new SolidBrush(ShadowColor))
                    using (var textBrush = new SolidBrush(FontColor))
                        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);

                                // draw line
                                outlinePen.Color = item.color;
                                outlinePen.Width = 1;
                                float lineY  = locationY + verticalOffset + maxLabelHeight / 2;
                                float lineX1 = locationX + symbolPad;
                                float lineX2 = lineX1 + symbolWidth - symbolPad * 2;
                                using (var linePen = GDI.Pen(item.color, item.lineWidth, item.lineStyle, false))
                                    gfx.DrawLine(linePen, lineX1, lineY, lineX2, lineY);

                                // draw marker
                                float  lineXcenter = (lineX1 + lineX2) / 2;
                                PointF markerPoint = new PointF(lineXcenter, lineY);
                                MarkerTools.DrawMarker(gfx, markerPoint, item.markerShape, markerWidth, item.color);
                            }
                        }
        }
예제 #3
0
        public new void Render(PlotDimensions dims, Bitmap bmp, bool lowQuality = false)
        {
            base.Render(dims, bmp, lowQuality);

            if (isHighlighted is null || isHighlighted.Length == 0)
            {
                return;
            }

            using (var gfx = GDI.Graphics(bmp, dims, lowQuality))
            {
                var highlightedIndexes = Enumerable.Range(0, isHighlighted.Length).Where(x => isHighlighted[x]);
                foreach (int i in highlightedIndexes)
                {
                    PointF pt = new PointF(dims.GetPixelX(xs[i]), dims.GetPixelY(ys[i]));
                    MarkerTools.DrawMarker(gfx, pt, highlightedShape, highlightedMarkerSize, highlightedColor);
                }
            }
        }
예제 #4
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);
                                    }
                                }
                            }
                        }
        }
예제 #5
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);
                    }
                }
            }
        }