protected override Bitmap GetLegendBmp(int w, int h) { if (_legendItems == null || _count == 0) { return(null); } if (w <= 0 || h <= 0) { return(null); } Bitmap bm = new Bitmap(w, h); using (Graphics gps = Graphics.FromImage(bm)) { gps.Clear(_backColor); gps.SmoothingMode = SmoothingMode.HighQuality; int i = 0; if (!string.IsNullOrEmpty(_text)) { using (LegendItem textItem = new LegendItem(_text)) { DrawLegendItem(gps, textItem, i, w); i++; } } foreach (LegendItem it in _legendItems) { DrawLegendItem(gps, it, i, w); i++; } } return(bm); }
/// <summary> /// 暂未使用 /// </summary> /// <param name="xml">Parent xml</param> /// <returns></returns> public static LegendItem[] ToLegendItems(XElement parentXml) { if (parentXml == null) { return(null); } XElement root = parentXml.Element("LegendItems"); if (root == null) { return(null); } IEnumerable <XElement> xmls = root.Elements("LegendItem"); if (xmls == null || xmls.Count() == 0) { return(null); } List <LegendItem> items = new List <LegendItem>(); foreach (XElement xml in xmls) { LegendItem item = LegendItem.ToLegendItem(xml); if (item != null) { items.Add(item); } } if (items.Count == 0) { return(null); } return(items.ToArray()); }
/// <summary> /// 暂未使用 /// </summary> /// <param name="items"></param> /// <returns></returns> public static XElement ToXml(LegendItem[] items) { if (items == null || items.Length == 0) { return(null); } List <XElement> content = new List <XElement>(); foreach (LegendItem item in items) { XElement xml = LegendItem.ToXml(item); if (xml != null) { content.Add(xml); } } if (content.Count == 0) { return(null); } else { return(new XElement("LegendItems", content)); } }
private void DrawLegendItem(Graphics g, LegendItem legendItem, int i, int legendWidth) { int x = i * _legendItemWidth + BORDER_BLANK * 2; SizeF textSize = g.MeasureString(_text, _legendTextFont); if (legendItem.Color.IsEmpty) { g.DrawString(_text, _legendTextFont, Brushes.Black, x + BORDER_BLANK, BORDER_BLANK); } else { float y = textSize.Height == 0 ?BORDER_BLANK: BORDER_BLANK + textSize.Height + _legendTextSpan; using (Brush brush = new SolidBrush(legendItem.Color)) { if (brush == null) { return; } g.FillRectangle(brush, x, y, _legendItemWidth, _legendItemHeight); if (_isShowBorder) { g.DrawRectangle(new Pen(_borderColor), x, y, _legendItemWidth, _legendItemHeight); } } float textY = textSize.Height == 0 ? _legendItemHeight + BORDER_BLANK + _legendTextSpan : _legendItemHeight + BORDER_BLANK + _legendTextSpan * 2 + textSize.Height; g.DrawString(legendItem.Text, _legendTextFont, Brushes.Black, x - BORDER_BLANK, textY); } }
protected override Bitmap GetLegendBmp(int w, int h) { if (_legendItems == null || _count == 0) { return(null); } if (w <= 0 || h <= 0) { return(null); } Bitmap bm = new Bitmap(w, h); using (Graphics gps = Graphics.FromImage(bm)) { gps.Clear(_backColor); gps.SmoothingMode = SmoothingMode.HighQuality; if (_isTopToBottom) { _topY = 0; } else { SizeF textSize = gps.MeasureString(_text, _legendTextFont); _topY = h - (_legendItems.Length * (_legendItemHeight + _legendItemSpan) + textSize.Height); } int i = 0; if (!string.IsNullOrEmpty(_text)) //图例标题 { using (LegendItem textItem = new LegendItem(_text)) { DrawLegendItem(gps, textItem, i, w); i++; } } foreach (LegendItem it in _legendItems) { DrawLegendItem(gps, it, i, w); i++; } } return(bm); }
private void DrawLegendItem(Graphics g, LegendItem legendItem, int i, int legendWidth) { SizeF textSize = g.MeasureString(legendItem.Text, _legendTextFont); float y; float textY; if (!string.IsNullOrEmpty(_text)) { if (i == 0) { y = BORDER_BLANK + _topY; } else { y = textSize.Height + _legendTextSpan + BORDER_BLANK + (i - 1) * (_legendItemHeight + _legendItemSpan) + _topY; } } else { y = (BORDER_BLANK + i * (_legendItemHeight + _legendItemSpan)) + _topY; } if (legendItem.Color.IsEmpty) { g.DrawString(legendItem.Text, _legendTextFont, Brushes.Black, BORDER_BLANK * 2, y); } else { using (Brush brush = new SolidBrush(legendItem.Color)) { g.FillRectangle(brush, BORDER_BLANK, y, _legendItemWidth, _legendItemHeight); if (_isShowBorder) { g.DrawRectangle(new Pen(_borderColor), BORDER_BLANK, y, _legendItemWidth, _legendItemHeight); } } textY = (_legendItemHeight < textSize.Height ? y : y + Math.Abs(_legendItemHeight - textSize.Height) / 2f); g.DrawString(legendItem.Text, _legendTextFont, Brushes.Black, _legendItemWidth + BORDER_BLANK + _legendTextSpan, textY); } }
private void DrawLegendItem(Graphics g, LegendItem legendItem, int i, int legendWidth) { int rowNo = i / _colCount; //当前行 int colNo = i % _colCount; //当前列 float y = 0f; //图块x坐标 float x = 0f; //图块y坐标 if (!string.IsNullOrEmpty(_text)) { y = rowNo * (_legendItemHeight + _legendItemSpan) + _titleSize.Height + _legendTextSpan + BORDER_BLANK; } else { y = rowNo * (_legendItemHeight + _legendItemSpan) + BORDER_BLANK; } if (colNo == 0) { x = BORDER_BLANK; } else { x = colNo * (_legendItemWidth + _legendItemSpan + _maxTextWidth) + BORDER_BLANK; } if (!legendItem.Color.IsEmpty) { using (Brush brush = new SolidBrush(legendItem.Color)) { g.FillRectangle(brush, x, y, _legendItemWidth, _legendItemHeight); } } if (_isShowBorder) { g.DrawRectangle(new Pen(_borderColor), x, y, _legendItemWidth, _legendItemHeight); } SizeF textSize = g.MeasureString(legendItem.Text, _legendTextFont); g.DrawString(legendItem.Text, _legendTextFont, Brushes.Black, x + _legendItemWidth + _legendItemSpan, y + Math.Abs(_legendItemHeight - textSize.Height) / 2f); }