public void Legend( bool enableLegend = true, string fontName = null, float fontSize = 12, bool bold = false, Color?fontColor = null, Color?backColor = null, Color?frameColor = null, legendLocation location = legendLocation.lowerRight, shadowDirection shadowDirection = shadowDirection.lowerRight, bool?fixedLineWidth = null ) { if (fontName == null) { fontName = Config.Fonts.GetDefaultFontName(); } if (fontColor != null) { settings.legend.colorText = (Color)fontColor; } if (backColor != null) { settings.legend.colorBackground = (Color)backColor; } if (frameColor != null) { settings.legend.colorFrame = (Color)frameColor; } fontName = Config.Fonts.GetValidFontName(fontName); FontStyle fontStyle = (bold) ? FontStyle.Bold : FontStyle.Regular; settings.legend.font = new Font(fontName, fontSize, fontStyle); if (fixedLineWidth != null) { settings.legend.fixedLineWidth = (bool)fixedLineWidth; } if (enableLegend) { settings.legend.location = location; settings.legend.shadow = shadowDirection; } else { settings.legend.location = legendLocation.none; settings.legend.shadow = shadowDirection.none; } }
public void Legend( bool enableLegend = true, string fontName = "Segoe UI", float fontSize = 12, bool bold = false, Color?fontColor = null, Color?backColor = null, Color?frameColor = null, legendLocation location = legendLocation.lowerRight, shadowDirection shadowDirection = shadowDirection.lowerRight, LineStyle lineStyle = LineStyle.Solid ) { if (fontColor != null) { settings.legendFontColor = (Color)fontColor; } if (backColor != null) { settings.legendBackColor = (Color)backColor; } if (frameColor != null) { settings.legendFrameColor = (Color)frameColor; } fontName = ScottPlot.Tools.VerifyFont(fontName); FontStyle fontStyle = (bold) ? FontStyle.Bold : FontStyle.Regular; settings.legendFont = new Font(fontName, fontSize, fontStyle); if (enableLegend) { settings.legendLocation = location; settings.legendShadowDirection = shadowDirection; } else { settings.legendLocation = legendLocation.none; settings.legendShadowDirection = shadowDirection.none; } }
private static Point[] GetLocations(ScottPlot.Settings settings, int padding, Size frameSize, float legendFontMaxWidth) { Point frameLocation = new Point(); Point textLocation = new Point(); Point shadowLocation = new Point(); // calculate locations even if it's not going to be displayed legendLocation loc = settings.legend.location; if (loc == legendLocation.none) { loc = legendLocation.lowerRight; } int frameWidth = frameSize.Width; int frameHeight = frameSize.Height; switch (loc) { case (legendLocation.lowerRight): frameLocation.X = (int)(settings.dataSize.Width - frameWidth - padding); frameLocation.Y = (int)(settings.dataSize.Height - frameHeight - padding); textLocation.X = (int)(settings.dataSize.Width - (legendFontMaxWidth + padding)); textLocation.Y = settings.dataSize.Height - padding * 2; break; case (legendLocation.upperLeft): frameLocation.X = (int)(padding); frameLocation.Y = (int)(padding); textLocation.X = (int)(frameWidth - legendFontMaxWidth + padding); textLocation.Y = (int)(frameHeight); break; case (legendLocation.lowerLeft): frameLocation.X = (int)(padding); frameLocation.Y = (int)(settings.dataSize.Height - frameHeight - padding); textLocation.X = (int)(frameWidth - legendFontMaxWidth + padding); textLocation.Y = settings.dataSize.Height - padding * 2; break; case (legendLocation.upperRight): frameLocation.X = (int)(settings.dataSize.Width - frameWidth - padding); frameLocation.Y = (int)(padding); textLocation.X = (int)(settings.dataSize.Width - (legendFontMaxWidth + padding)); textLocation.Y = (int)(frameHeight); break; case (legendLocation.upperCenter): frameLocation.X = (int)((settings.dataSize.Width) / 2 - frameWidth / 2); frameLocation.Y = (int)(padding); textLocation.X = (int)(frameLocation.X + frameWidth - legendFontMaxWidth); textLocation.Y = (int)(frameHeight); break; case (legendLocation.lowerCenter): frameLocation.X = (int)((settings.dataSize.Width) / 2 - frameWidth / 2); frameLocation.Y = (int)(settings.dataSize.Height - frameHeight - padding); textLocation.X = (int)(frameLocation.X + frameWidth - legendFontMaxWidth); textLocation.Y = settings.dataSize.Height - padding * 2; break; case (legendLocation.middleLeft): frameLocation.X = (int)(padding); frameLocation.Y = (int)(settings.dataSize.Height / 2 - frameHeight / 2); textLocation.X = (int)(frameWidth - legendFontMaxWidth + padding); textLocation.Y = (int)(frameLocation.Y + frameHeight - padding); break; case (legendLocation.middleRight): frameLocation.X = (int)(settings.dataSize.Width - frameWidth - padding); frameLocation.Y = (int)(settings.dataSize.Height / 2 - frameHeight / 2); textLocation.X = (int)(settings.dataSize.Width - (legendFontMaxWidth + padding)); textLocation.Y = (int)(frameLocation.Y + frameHeight - padding); break; default: throw new NotImplementedException($"legend location {settings.legend.location} is not supported"); } switch (settings.legend.shadow) { case (shadowDirection.lowerRight): shadowLocation.X = frameLocation.X + 2; shadowLocation.Y = frameLocation.Y + 2; break; case (shadowDirection.lowerLeft): shadowLocation.X = frameLocation.X - 2; shadowLocation.Y = frameLocation.Y + 2; break; case (shadowDirection.upperRight): shadowLocation.X = frameLocation.X + 2; shadowLocation.Y = frameLocation.Y - 2; break; case (shadowDirection.upperLeft): shadowLocation.X = frameLocation.X - 2; shadowLocation.Y = frameLocation.Y - 2; break; default: settings.legend.shadow = shadowDirection.none; break; } textLocation.Y += padding; return(new Point[] { frameLocation, textLocation, shadowLocation }); }
public void Legend( bool enableLegend = true, string fontName = null, float?fontSize = null, bool?bold = null, Color?fontColor = null, Color?backColor = null, Color?frameColor = null, legendLocation location = legendLocation.lowerRight, shadowDirection shadowDirection = shadowDirection.lowerRight, bool?fixedLineWidth = null, bool?reverseOrder = null ) { settings.Legend.Visible = enableLegend; if (fontName != null) { settings.Legend.FontName = fontName; } if (fontSize != null) { settings.Legend.FontSize = fontSize.Value; } if (fontColor != null) { settings.Legend.FontColor = fontColor.Value; } if (backColor != null) { settings.Legend.FillColor = backColor.Value; } if (frameColor != null) { settings.Legend.OutlineColor = frameColor.Value; } if (reverseOrder != null) { settings.Legend.ReverseOrder = reverseOrder.Value; } if (bold != null) { settings.Legend.FontBold = bold.Value; } if (fixedLineWidth != null) { settings.Legend.FixedLineWidth = fixedLineWidth.Value; } if (location == legendLocation.upperLeft) { settings.Legend.Location = Direction.NW; } else if (location == legendLocation.upperCenter) { settings.Legend.Location = Direction.N; } else if (location == legendLocation.upperRight) { settings.Legend.Location = Direction.NE; } else if (location == legendLocation.middleRight) { settings.Legend.Location = Direction.E; } else if (location == legendLocation.lowerRight) { settings.Legend.Location = Direction.SE; } else if (location == legendLocation.lowerCenter) { settings.Legend.Location = Direction.S; } else if (location == legendLocation.lowerLeft) { settings.Legend.Location = Direction.SW; } else if (location == legendLocation.middleLeft) { settings.Legend.Location = Direction.W; } }