Free cookie consent management tool by TermsFeed Policy Generator

Changeset 10518


Ignore:
Timestamp:
02/26/14 10:46:57 (11 years ago)
Author:
bburlacu
Message:

#1265: Removed labeled primitives and added text property to the RectangularPrimitiveBase. If the string is not null or empty it is drawn centered inside the rectangular primitive.

Location:
branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/Primitives
Files:
2 deleted
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Visualization/HeuristicLab.Visualization/3.3/Primitives/RectangularPrimitiveBase.cs

    r7780 r10518  
    4040      get { return new SizeD(UpperRight.X - LowerLeft.X, UpperRight.Y - LowerLeft.Y); }
    4141    }
     42
     43    public string Text { get; set; }
     44    public Font Font { get; set; }
    4245
    4346    protected RectangularPrimitiveBase(IChart chart, PointD lowerLeft, PointD upperRight)
     
    133136      }
    134137    }
     138
     139    protected virtual void DrawText(Graphics graphics) {  // draw the text in the center of the bounding rectangle4
     140      var p = Chart.TransformWorldToPixel(new PointD(LowerLeft.X, LowerLeft.Y));
     141      var s = Chart.TransformWorldToPixel(Size);
     142      var stringSize = graphics.MeasureString(Text, Font);
     143      var fontSize = Font.Size * s.Width / stringSize.Width;
     144      if (fontSize > 12) fontSize = 12; // limit maximum font size so that nodes look nicer
     145      Font = new Font(Font.FontFamily, fontSize, GraphicsUnit.Pixel);
     146      stringSize = graphics.MeasureString(Text, Font);
     147      graphics.DrawString(Text, Font, new SolidBrush(Pen.Color), p.X + (s.Width - stringSize.Width) / 2f, p.Y - (s.Height + stringSize.Height) / 2f);
     148    }
     149
     150    public override void Draw(Graphics graphics) {
     151      if (!string.IsNullOrEmpty(Text))
     152        DrawText(graphics);
     153      base.Draw(graphics);
     154    }
    135155  }
    136156}
Note: See TracChangeset for help on using the changeset viewer.