Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/12/16 14:35:31 (8 years ago)
Author:
jkarder
Message:

#1265: worked on visualization

  • brought back support for SnapToGrid methods
  • updated license headers
File:
1 edited

Legend:

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

    r13045 r13753  
    1 using System;
     1#region License Information
     2/* HeuristicLab
     3 * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     4 *
     5 * This file is part of HeuristicLab.
     6 *
     7 * HeuristicLab is free software: you can redistribute it and/or modify
     8 * it under the terms of the GNU General Public License as published by
     9 * the Free Software Foundation, either version 3 of the License, or
     10 * (at your option) any later version.
     11 *
     12 * HeuristicLab is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
     19 */
     20#endregion
     21
     22using System;
    223using System.Drawing;
    324
     
    728
    829    public virtual PointD Origin { get; set; }
    9     public virtual PointD Offset { get; set; }
    10     public virtual SizeD Size { get; set; }
    11 
    1230    public virtual double XPrecision { get; set; }
    1331    public virtual double YPrecision { get; set; }
     
    3351    }
    3452
    35     public Grid(IChart chart, PointD offset, SizeD size)
    36       : this(chart, offset, size, 1) { }
    37     public Grid(IChart chart, PointD offset, SizeD size, double precision)
    38       : base(chart) {
     53    public Grid(IChart chart) : this(chart, 1.0) { }
     54    public Grid(IChart chart, double precision) : base(chart) {
    3955      Origin = new PointD(0, 0);
    40       Offset = offset;
    41       Size = size;
    4256      XPrecision = precision;
    4357      YPrecision = precision;
     
    4862    }
    4963
    50     public override void Move(Offset delta) {
    51       Offset += delta;
    52     }
     64    public override void Move(Offset delta) { }
    5365
    54     public override void Move(PointD point, Offset delta) {
    55       Move(delta);
    56     }
     66    public override void Move(PointD point, Offset delta) { }
    5767
    5868    public override void SnapToGrid(IGrid grid) { }
     
    6171
    6272    public override void Draw(Graphics graphics) {
    63       if (!(Size.Width > 0) || !(Size.Height > 0)) return;
     73      if (!(Chart.Size.Width > 0) || !(Chart.Size.Height > 0)) return;
    6474      graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit;
    6575      var pen = new Pen(Color.LightGray, 1.0f);
    66       var pixelSize = Chart.TransformWorldToPixel(Size); // size of the drawing area in pixel coordinates
     76      var pixelSize = Chart.TransformWorldToPixel(Chart.Size); // size of the drawing area in pixel coordinates
    6777
    6878      var numberOfXParallelLines = (int)Math.Floor(pixelSize.Height / (double)CellSpacing); // how many x parallel lines can be drawn
    6979      var numberOfYParallelLines = (int)Math.Floor(pixelSize.Width / (double)CellSpacing); // how many y parallel lines can be drawn
    7080      if (numberOfXParallelLines <= 0 || numberOfYParallelLines <= 0) return;
    71       var cellWorldSize = new SizeD(Size.Width / numberOfYParallelLines, Size.Height / numberOfXParallelLines); // the cellSize in world coordinates
     81      var cellWorldSize = new SizeD(Chart.Size.Width / numberOfYParallelLines, Chart.Size.Height / numberOfXParallelLines); // the cellSize in world coordinates
    7282      cellWorldSize.Width = Math.Pow(10, Math.Floor(Math.Log10(cellWorldSize.Width)));
    7383      cellWorldSize.Height = Math.Pow(10, Math.Floor(Math.Log10(cellWorldSize.Width)));
     
    8191        cellPixelSize = Chart.TransformWorldToPixel(cellWorldSize);
    8292      }
    83       var firstX = Math.Floor(Offset.X / cellWorldSize.Width) * cellWorldSize.Width;
    84       var firstY = Math.Floor(Offset.Y / cellWorldSize.Height) * cellWorldSize.Height;
     93      var firstX = Math.Floor(Chart.LowerLeft.X / cellWorldSize.Width) * cellWorldSize.Width;
     94      var firstY = Math.Floor(Chart.LowerLeft.Y / cellWorldSize.Height) * cellWorldSize.Height;
    8595      double x = firstX, y = firstY;
    8696      var axisyLabel = new Font(FontFamily.GenericMonospace, 7.0f, FontStyle.Regular, GraphicsUnit.Point, 0);
     
    8898      var axisDrawing = new SolidBrush(Color.DarkGray);
    8999      try {
    90         var bottom = Chart.TransformWorldToPixel(Size).Height;
    91         while (x <= Offset.X + Size.Width) {
     100        var bottom = Chart.TransformWorldToPixel(Chart.Size).Height;
     101        while (x <= Chart.LowerLeft.X + Chart.Size.Width) {
    92102          var start = Chart.TransformWorldToPixel(new PointD(x, firstY));
    93           var end = Chart.TransformWorldToPixel(new PointD(x, Offset.Y + Size.Height));
     103          var end = Chart.TransformWorldToPixel(new PointD(x, Chart.LowerLeft.Y + Chart.Size.Height));
    94104          graphics.DrawLine(pen, start, end);
    95105          var axis = x.ToString("0.##");
     
    98108          x += cellWorldSize.Width;
    99109        }
    100         while (y <= Offset.Y + Size.Height) {
     110        while (y <= Chart.LowerLeft.Y + Chart.Size.Height) {
    101111          var start = Chart.TransformWorldToPixel(new PointD(firstX, y));
    102           var end = Chart.TransformWorldToPixel(new PointD(Offset.X + Size.Width, y));
     112          var end = Chart.TransformWorldToPixel(new PointD(Chart.LowerLeft.X + Chart.Size.Width, y));
    103113          graphics.DrawLine(pen, start, end);
    104114          graphics.DrawString(y.ToString("0.##"), axisxLabel, axisDrawing, 0, start.Y);
Note: See TracChangeset for help on using the changeset viewer.