Free cookie consent management tool by TermsFeed Policy Generator

Changeset 981


Ignore:
Timestamp:
12/12/08 10:06:10 (16 years ago)
Author:
dwagner
Message:

Added Feature: ZoomToFullView, which shows the whole datarows in the chart. #345

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Visualization/LineChart.cs

    r980 r981  
    99  public partial class LineChart : ViewBase {
    1010    private readonly IChartDataRowsModel model;
     11    private int maxDataRowCount;
     12    private Boolean zoomFullView;
     13    private double minDataValue;
     14    private double maxDataValue;
    1115
    1216    /// <summary>
     
    2731
    2832      //TODO: correct Rectangle to fit
    29       RectangleD clientRectangle = new RectangleD(-1, -1, 11, 11);
     33      RectangleD clientRectangle = new RectangleD(-1, -1, 1, 1);
    3034      canvasUI1.MainCanvas.WorldShape = new WorldShape(clientRectangle, clientRectangle);
    31 
     35         
    3236      CreateMouseEventListeners();
    33 
     37         
    3438      this.model = model;
    3539      Item = (IItem)model;
     40      maxDataRowCount = 0;
     41      //The whole data rows are shown per default
     42      zoomFullView = true;
     43      minDataValue = Double.PositiveInfinity;
     44      maxDataValue = Double.NegativeInfinity;
     45
    3646    }
    3747
     
    6171      row.ValueChanged += OnRowValueChanged;
    6272      row.ValuesChanged += OnRowValuesChanged;
    63 
     73      if (row.Count > maxDataRowCount)
     74        maxDataRowCount = row.Count;
     75     
    6476      InitShapes(row);
    6577    }
    6678
     79    private void ZoomToFullView() {
     80      if(!zoomFullView)
     81        return;
     82      RectangleD newClippingArea =  new RectangleD(-0.1,
     83        minDataValue-((maxDataValue-minDataValue)*0.05),
     84        maxDataRowCount-0.9,
     85        maxDataValue + ((maxDataValue - minDataValue) * 0.05));
     86      canvasUI1.MainCanvas.WorldShape.ClippingArea = newClippingArea;
     87    }
     88
    6789    private void InitShapes(IDataRow row) {
     90     
     91       
    6892      List<LineShape> lineShapes = new List<LineShape>();
    69 
     93      if (row.Count > 0) {
     94        maxDataValue = Max(row[0], this.maxDataValue);
     95        minDataValue = Min(row[0], minDataValue);
     96      }
    7097      for (int i = 1; i < row.Count; i++) {
    7198        LineShape lineShape = new LineShape(i - 1, row[i - 1], i, row[i], 0, row.Color, row.Thickness, row.Style);
     
    73100        // TODO each DataRow needs its own WorldShape so Y Axes can be zoomed independently.
    74101        canvasUI1.MainCanvas.WorldShape.AddShape(lineShape);
     102        maxDataValue = Max(row[i], maxDataValue);
     103        minDataValue = Min(row[i], minDataValue);
    75104      }
    76105
    77106      rowToLineShapes[row] = lineShapes;
    78 
     107      ZoomToFullView();
    79108      canvasUI1.Invalidate();
     109    }
     110
     111    private double Min(double d, double value) {
     112      return d < value ? d : value;
     113    }
     114
     115    private double Max(double d, double value) {
     116      return d>value ? d : value;
    80117    }
    81118
     
    90127    private void OnRowValueChanged(IDataRow row, double value, int index, Action action) {
    91128      List<LineShape> lineShapes = rowToLineShapes[row];
     129      maxDataValue = Max(value, maxDataValue);
     130      minDataValue = Min(value, minDataValue);
    92131
    93132      if (index > lineShapes.Count + 1) {
     
    97136      // new value was added
    98137      if (index > 0 && index == lineShapes.Count + 1) {
     138       
     139        if (maxDataRowCount < row.Count)
     140          maxDataRowCount = row.Count;
    99141        LineShape lineShape = new LineShape(index - 1, row[index - 1], index, row[index], 0, row.Color, row.Thickness, row.Style);
    100142        lineShapes.Add(lineShape);
     
    112154        lineShapes[index].Y1 = value;
    113155      }
    114 
     156      ZoomToFullView();
    115157      canvasUI1.Invalidate();
    116158    }
     
    189231      panListener.StartPoint = startPoint;
    190232
     233      this.zoomFullView = false; //user wants to pan => no full view
     234
    191235      canvasUI1.Invalidate();
    192236    }
Note: See TracChangeset for help on using the changeset viewer.