Changeset 1351


Ignore:
Timestamp:
03/16/09 20:51:48 (12 years ago)
Author:
mstoeger
Message:

Fixed Zoom & Pan. Improved Mouse-Wheel-Zoom. (#424)

Location:
trunk/sources/HeuristicLab.Visualization
Files:
2 edited

Legend:

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

    r1350 r1351  
    2121    private readonly ViewSettings viewSettings;
    2222
    23 //    private readonly Stack<RectangleD> clippingAreaHistory = new Stack<RectangleD>();
    2423    private readonly WorldShape userInteractionShape = new WorldShape();
    2524    private readonly RectangleShape rectangleShape = new RectangleShape(0, 0, 0, 0, Color.FromArgb(50, 0, 0, 255));
     
    162161    }
    163162
    164     private void UpdateYAxisInfo(YAxisDescriptor yAxisDescriptor) {
    165 //      if (yAxisInfos.ContainsKey(yAxisDescriptor)) {
    166 //        yAxisInfos.Remove(yAxisDescriptor);
    167 //      }
    168     }
    169 
    170163    /// <summary>
    171164    /// sets the legend position
     
    234227
    235228    public void OnDataRowChanged(IDataRow row) {
    236       UpdateYAxisInfo(row.YAxis);
    237 
    238229      RowEntry rowEntry = rowToRowEntry[row];
    239230
     
    447438
    448439    private void Pan(Point startPoint, Point endPoint) {
     440      RectangleD clippingArea = Translate.ClippingArea(startPoint, endPoint, xAxis.ClippingArea, xAxis.Viewport);
     441
     442      SetClipX(clippingArea.X1, clippingArea.X2);
     443
    449444      foreach (RowEntry rowEntry in rowEntries) {
    450         RectangleD clippingArea = CalcPanClippingArea(startPoint, endPoint, rowEntry.LinesShape);
    451 
    452         SetClipX(clippingArea.X1, clippingArea.X1);
     445        clippingArea = Translate.ClippingArea(startPoint, endPoint, rowEntry.LinesShape.ClippingArea, rowEntry.LinesShape.Viewport);
    453446        SetClipY(rowEntry, clippingArea.Y1, clippingArea.Y2);
    454447      }
     
    458451
    459452    private void PanEnd(Point startPoint, Point endPoint) {
     453      Pan(startPoint, endPoint);
     454    }
     455
     456    private void SetClippingArea(Rectangle rectangle) {
     457      RectangleD clippingArea = Transform.ToWorld(rectangle, xAxis.Viewport, xAxis.ClippingArea);
     458
     459      SetClipX(clippingArea.X1, clippingArea.X2);
     460
    460461      foreach (RowEntry rowEntry in rowEntries) {
    461         RectangleD clippingArea = CalcPanClippingArea(startPoint, endPoint, rowEntry.LinesShape);
    462 
    463         SetClipX(clippingArea.X1, clippingArea.X1);
    464         SetClipY(rowEntry, clippingArea.Y1, clippingArea.Y2);
    465       }
    466 
    467       canvasUI.Invalidate();
    468     }
    469 
    470     private static RectangleD CalcPanClippingArea(Point startPoint, Point endPoint, LinesShape linesShape) {
    471       return Translate.ClippingArea(startPoint, endPoint, linesShape.ClippingArea, linesShape.Viewport);
    472     }
    473 
    474     private void SetClippingArea(Rectangle rectangle) {
    475       foreach (RowEntry rowEntry in rowEntries) {
    476         RectangleD clippingArea = Transform.ToWorld(rectangle, rowEntry.LinesShape.Viewport, rowEntry.LinesShape.ClippingArea);
    477 
    478         SetClipX(clippingArea.X1, clippingArea.X1);
     462        clippingArea = Transform.ToWorld(rectangle, rowEntry.LinesShape.Viewport, rowEntry.LinesShape.ClippingArea);
     463
    479464        SetClipY(rowEntry, clippingArea.Y1, clippingArea.Y2);
    480465      }
     
    490475
    491476    private void canvasUI1_KeyDown(object sender, KeyEventArgs e) {
    492 //      if (e.KeyCode == Keys.Back && clippingAreaHistory.Count > 1) {
    493 //        clippingAreaHistory.Pop();
    494 //
    495 //        RectangleD clippingArea = clippingAreaHistory.Peek();
    496 //
    497 //        SetLineClippingArea(clippingArea, false);
    498 //      }
    499477    }
    500478
     
    540518    private void canvasUI1_MouseWheel(object sender, MouseEventArgs e) {
    541519      if (ModifierKeys == Keys.Control) {
    542         double zoomFactor = (e.Delta > 0) ? 0.9 : 1.1;
     520        double zoomFactor = (e.Delta > 0) ? 0.7 : 1.3;
     521
     522        PointD world;
     523
     524        world = Transform.ToWorld(e.Location, xAxis.Viewport, xAxis.ClippingArea);
     525
     526        double x1 = world.X - (world.X - xAxis.ClippingArea.X1)*zoomFactor;
     527        double x2 = world.X + (xAxis.ClippingArea.X2 - world.X)*zoomFactor;
     528
     529        SetClipX(x1, x2);
    543530
    544531        foreach (RowEntry rowEntry in rowEntries) {
    545           RectangleD clippingArea = ZoomListener.ZoomClippingArea(rowEntry.LinesShape.ClippingArea, zoomFactor);
    546          
    547           SetClipX(clippingArea.X1, clippingArea.X1);
    548           SetClipY(rowEntry, clippingArea.Y1, clippingArea.Y2);
    549         }
     532          world = Transform.ToWorld(e.Location, rowEntry.LinesShape.Viewport, rowEntry.LinesShape.ClippingArea);
     533
     534          double y1 = world.Y - (world.Y - rowEntry.LinesShape.ClippingArea.Y1) * zoomFactor;
     535          double y2 = world.Y + (rowEntry.LinesShape.ClippingArea.Y2 - world.Y)*zoomFactor;
     536
     537          SetClipY(rowEntry, y1, y2);
     538        }
     539
     540        canvasUI.Invalidate();
    550541      }
    551542    }
  • trunk/sources/HeuristicLab.Visualization/RectangleShape.cs

    r1240 r1351  
    77
    88    private Color color;
    9     private int opacity = 255;
    109
    1110    private Pen pen;
     
    5453    private Brush GetBrush() {
    5554      if (brush == null)
    56         brush = new SolidBrush(Color.FromArgb(opacity, color));
     55        brush = new SolidBrush(color);
    5756      return brush;
    58     }
    59 
    60     public int Opacity {
    61       get { return opacity; }
    62       set {
    63         opacity = value;
    64         DisposeDrawingTools();
    65       }
    6657    }
    6758
Note: See TracChangeset for help on using the changeset viewer.