[873] | 1 | using System.Collections.Generic;
|
---|
[866] | 2 | using System.Drawing;
|
---|
| 3 |
|
---|
| 4 | namespace HeuristicLab.Visualization {
|
---|
[873] | 5 | public class LegendItem {
|
---|
[1049] | 6 | public LegendItem(string label, Color color, int thickness) {
|
---|
[873] | 7 | Label = label;
|
---|
| 8 | Color = color;
|
---|
[1049] | 9 | Thickness = thickness;
|
---|
[873] | 10 | }
|
---|
| 11 |
|
---|
| 12 | public string Label { get; set; }
|
---|
| 13 | public Color Color { get; set; }
|
---|
[1049] | 14 | public int Thickness { get; set; }
|
---|
[873] | 15 | }
|
---|
| 16 |
|
---|
| 17 |
|
---|
[1049] | 18 | public class LegendShape : CompositeShape {
|
---|
| 19 | private RectangleD boundingBox;
|
---|
| 20 | private Color color;
|
---|
[873] | 21 |
|
---|
| 22 | private readonly IList<LegendItem> legendItems = new List<LegendItem>();
|
---|
[866] | 23 |
|
---|
| 24 | public LegendShape(double x1, double y1, double x2, double y2, double z, Color color) {
|
---|
[1049] | 25 | boundingBox = new RectangleD(x1, y1, x2, y2);
|
---|
[873] | 26 | Z = z;
|
---|
[866] | 27 | this.color = color;
|
---|
[1049] | 28 | CreateLegend();
|
---|
[866] | 29 | }
|
---|
| 30 |
|
---|
| 31 | public double Z { get; set; }
|
---|
| 32 |
|
---|
| 33 | public RectangleD BoundingBox {
|
---|
[1049] | 34 | get { return boundingBox; }
|
---|
| 35 | set { boundingBox = value; }
|
---|
[866] | 36 | }
|
---|
| 37 |
|
---|
[1049] | 38 | public void CreateLegend() {
|
---|
| 39 | double y = boundingBox.Y2;
|
---|
| 40 | foreach (LegendItem item in legendItems) {
|
---|
| 41 | AddShape(new LineShape(10, y - 10, 30, y - 10, 0, item.Color, item.Thickness, DrawingStyle.Solid));
|
---|
| 42 | AddShape(new TextShape(35, y, item.Label));
|
---|
| 43 | y -= 15;
|
---|
[866] | 44 | }
|
---|
| 45 | }
|
---|
| 46 |
|
---|
[873] | 47 | public void AddLegendItem(LegendItem item) {
|
---|
| 48 | legendItems.Add(item);
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 | public void RemoveLegendItem(LegendItem item) {
|
---|
| 52 | legendItems.Remove(item);
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | public void ClearLegendItems() {
|
---|
| 56 | legendItems.Clear();
|
---|
| 57 | }
|
---|
[866] | 58 | }
|
---|
| 59 | } |
---|