public TextLabel(Graphics gfx = null) { this.gfx = gfx ?? Graphics.FromImage(new Bitmap(1, 1)); // set things which can't be instantiated at the class level color = Color.Black; colorBackground = Color.Magenta; colorBorder = Color.Black; _fontName = Fonts.GetDefaultFontName(); }
public PlottableScaleBar(double sizeX, double sizeY, string labelX, string labelY, double thickness, double fontSize, Color color, double padPx) { this.sizeX = sizeX; this.sizeY = sizeY; this.labelX = (labelX is null) ? sizeX.ToString() : labelX; this.labelY = (labelY is null) ? sizeY.ToString() : labelY; this.thickness = thickness; this.fontSize = fontSize; this.color = color; this.padPx = padPx; fontName = Fonts.GetDefaultFontName(); }
public static Bitmap DesignerModeBitmap(Size size, bool drawArrows = false) { Bitmap bmp = new Bitmap(size.Width, size.Height); Graphics gfx = Graphics.FromImage(bmp); gfx.Clear(ColorTranslator.FromHtml("#003366")); Brush brushLogo = new SolidBrush(ColorTranslator.FromHtml("#FFFFFF")); Brush brushMeasurements = new SolidBrush(ColorTranslator.FromHtml("#006699")); Pen pen = new Pen(ColorTranslator.FromHtml("#006699"), 3); pen.StartCap = System.Drawing.Drawing2D.LineCap.Round; pen.EndCap = System.Drawing.Drawing2D.LineCap.Round; float arrowSize = 7; float padding = 3; // logo FontFamily ff = new FontFamily(Fonts.GetDefaultFontName()); gfx.DrawString("ScottPlot", new Font(ff, 24, FontStyle.Bold), brushLogo, 10, 10); var titleSize = GDI.MeasureString(gfx, "ScottPlot", new Font(ff, 24, FontStyle.Bold)); gfx.DrawString($"version {GetVersionString()}", new Font(ff, 12, FontStyle.Italic), brushLogo, 12, (int)(10 + titleSize.Height * .7)); if (drawArrows) { // horizontal arrow PointF left = new PointF(padding, size.Height / 2); PointF leftA = new PointF(left.X + arrowSize, left.Y + arrowSize); PointF leftB = new PointF(left.X + arrowSize, left.Y - arrowSize); PointF right = new PointF(size.Width - padding, size.Height / 2); PointF rightA = new PointF(right.X - arrowSize, right.Y + arrowSize); PointF rightB = new PointF(right.X - arrowSize, right.Y - arrowSize); gfx.DrawLine(pen, left, right); gfx.DrawLine(pen, left, leftA); gfx.DrawLine(pen, left, leftB); gfx.DrawLine(pen, right, rightA); gfx.DrawLine(pen, right, rightB); gfx.DrawString($"{size.Width}px", new Font(ff, 12, FontStyle.Bold), brushMeasurements, (float)(size.Width * .2), (float)(size.Height * .5)); // vertical arrow PointF top = new PointF(size.Width / 2, padding); PointF topA = new PointF(top.X - arrowSize, top.Y + arrowSize); PointF topB = new PointF(top.X + arrowSize, top.Y + arrowSize); PointF bot = new PointF(size.Width / 2, size.Height - padding); PointF botA = new PointF(bot.X - arrowSize, bot.Y - arrowSize); PointF botB = new PointF(bot.X + arrowSize, bot.Y - arrowSize); gfx.DrawLine(pen, top, bot); gfx.DrawLine(pen, bot, botA); gfx.DrawLine(pen, bot, botB); gfx.DrawLine(pen, top, topA); gfx.DrawLine(pen, top, topB); gfx.RotateTransform(-90); gfx.DrawString($"{size.Height}px", new Font(ff, 12, FontStyle.Bold), brushMeasurements, (float)(-size.Height * .4), (float)(size.Width * .5)); } return(bmp); }
public PlottableBar(double[] xs, double[] ys, string label, double barWidth, double xOffset, bool fill, Color fillColor, double outlineWidth, Color outlineColor, double[] yErr, double errorLineWidth, double errorCapSize, Color errorColor, bool horizontal, bool showValues, Color valueColor, double[] yOffsets, Color negativeColor ) { if (ys is null || ys.Length == 0) { throw new ArgumentException("ys must contain data values"); } if (xs is null) { xs = DataGen.Consecutive(ys.Length); } if (xs.Length != ys.Length) { throw new ArgumentException("xs and ys must have same number of elements"); } if (yErr is null) { yErr = DataGen.Zeros(ys.Length); } if (yErr.Length != ys.Length) { throw new ArgumentException("yErr and ys must have same number of elements"); } if (yOffsets is null) { yOffsets = DataGen.Zeros(ys.Length); } this.xs = xs; this.ys = ys; this.yErr = yErr; this.xOffset = xOffset; this.label = label; this.verticalBars = !horizontal; this.showValues = showValues; this.barWidth = barWidth; this.errorCapSize = errorCapSize; this.fill = fill; this.fillColor = fillColor; this.negativeColor = negativeColor; this.yOffsets = yOffsets; fillBrush = new SolidBrush(fillColor); outlinePen = new Pen(outlineColor, (float)outlineWidth); errorPen = new Pen(errorColor, (float)errorLineWidth); valueTextFont = new Font(Fonts.GetDefaultFontName(), 12); valueTextBrush = new SolidBrush(valueColor); }