- Timestamp:
- 10/19/10 17:06:58 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Visualization.ChartControlsExtensions/3.3/EnhancedChart.cs
r4614 r4621 20 20 #endregion 21 21 22 using System.ComponentModel; 22 23 using System.Drawing; 23 24 using System.Windows.Forms; … … 25 26 namespace HeuristicLab.Visualization.ChartControlsExtensions { 26 27 public partial class EnhancedChart : Chart { 28 29 27 30 public EnhancedChart() 28 31 : base() { 32 EnableDoubleClickResetsZoom = true; 33 EnableMiddleClickPanning = true; 29 34 } 35 36 [DefaultValue(true)] 37 public bool EnableDoubleClickResetsZoom { get; set; } 38 39 [DefaultValue(true)] 40 public bool EnableMiddleClickPanning { get; set; } 41 42 public void InitializeChartAreas() { 43 ChartAreas.Clear(); 44 ChartAreas.Add(GetDefaultChartArea("ChartArea")); 45 } 46 47 public static ChartArea GetDefaultChartArea(string name) { 48 ChartArea chartArea = new ChartArea(name); 49 chartArea.AxisX.MajorGrid.LineColor = SystemColors.GradientInactiveCaption; 50 chartArea.AxisY.MajorGrid.LineColor = SystemColors.GradientInactiveCaption; 51 chartArea.AxisX.MajorTickMark.TickMarkStyle = TickMarkStyle.AcrossAxis; 52 chartArea.AxisY.MajorTickMark.TickMarkStyle = TickMarkStyle.AcrossAxis; 53 chartArea.AxisX.ScrollBar.BackColor = Color.Transparent; 54 chartArea.AxisY.ScrollBar.BackColor = Color.Transparent; 55 chartArea.AxisX.ScrollBar.LineColor = Color.Transparent; 56 chartArea.AxisY.ScrollBar.LineColor = Color.Transparent; 57 chartArea.AxisX.ScrollBar.ButtonColor = SystemColors.GradientInactiveCaption; 58 chartArea.AxisY.ScrollBar.ButtonColor = SystemColors.GradientInactiveCaption; 59 chartArea.AxisX.ScrollBar.ButtonStyle = ScrollBarButtonStyles.SmallScroll; 60 chartArea.AxisY.ScrollBar.ButtonStyle = ScrollBarButtonStyles.SmallScroll; 61 chartArea.AxisX.ScrollBar.Size = 12; 62 chartArea.AxisY.ScrollBar.Size = 12; 63 chartArea.CursorX.Interval = 0; 64 chartArea.CursorY.Interval = 0; 65 chartArea.CursorX.IsUserSelectionEnabled = true; 66 chartArea.CursorY.IsUserSelectionEnabled = true; 67 chartArea.CursorX.SelectionColor = SystemColors.GradientActiveCaption; 68 chartArea.CursorY.SelectionColor = SystemColors.GradientActiveCaption; 69 return chartArea; 70 } 71 72 #region Mouse event ehancements 73 74 protected override void OnMouseDoubleClick(MouseEventArgs e) { 75 if (EnableDoubleClickResetsZoom) { 76 HitTestResult result = HitTest(e.X, e.Y); 77 if (result.ChartArea != null && result.ChartElementType == ChartElementType.PlottingArea) { 78 foreach (var axis in result.ChartArea.Axes) 79 axis.ScaleView.ZoomReset(); 80 } 81 } 82 base.OnMouseDoubleClick(e); 83 } 84 85 #region panning 86 87 private class PanningSupport { 88 89 public ChartArea ChartArea { get; private set; } 90 91 private Point PixelStartPosition; 92 private PointF ChartStartPosition; 93 private SizeF Pixel2ChartScale; 94 95 public PanningSupport(Point pixelStartPos, ChartArea chartArea, Size size) { 96 PixelStartPosition = pixelStartPos; 97 ChartArea = chartArea; 98 ChartStartPosition = new PointF( 99 (float)chartArea.AxisX.ScaleView.Position, 100 (float)chartArea.AxisY.ScaleView.Position); 101 Pixel2ChartScale = new SizeF( 102 (float)chartArea.AxisX.ScaleView.Size / 103 (size.Width * chartArea.Position.Width * chartArea.InnerPlotPosition.Width / 100 / 100), 104 (float)chartArea.AxisY.ScaleView.Size / 105 (size.Height * chartArea.Position.Height * chartArea.InnerPlotPosition.Height / 100 / 100)); 106 } 107 108 public double ChartX(double pixelX) { 109 return ChartStartPosition.X - (pixelX - PixelStartPosition.X) * Pixel2ChartScale.Width; 110 } 111 112 public double ChartY(double pixelY) { 113 return ChartStartPosition.Y + (pixelY - PixelStartPosition.Y) * Pixel2ChartScale.Height; 114 } 115 } 116 117 private PanningSupport panning = null; 118 119 protected override void OnMouseDown(MouseEventArgs e) { 120 if (EnableMiddleClickPanning && e.Button == MouseButtons.Middle) { 121 HitTestResult result = HitTest(e.X, e.Y); 122 if (result.ChartArea != null) 123 panning = new PanningSupport(e.Location, result.ChartArea, Size); 124 } 125 base.OnMouseDown(e); 126 } 127 128 protected override void OnMouseUp(MouseEventArgs e) { 129 if (e.Button == MouseButtons.Middle && panning != null) 130 panning = null; 131 base.OnMouseUp(e); 132 } 133 134 protected override void OnMouseMove(MouseEventArgs e) { 135 if (panning != null) { 136 panning.ChartArea.AxisX.ScaleView.Scroll(panning.ChartX(e.Location.X)); 137 panning.ChartArea.AxisY.ScaleView.Scroll(panning.ChartY(e.Location.Y)); 138 } 139 base.OnMouseMove(e); 140 } 141 142 #endregion 143 144 #endregion 30 145 31 146 private void saveImageToolStripMenuItem_Click(object sender, System.EventArgs e) { … … 42 157 if (saveFileDialog.ShowDialog() == DialogResult.OK) { 43 158 ChartImageFormat format = ChartImageFormat.Bmp; 44 45 if ( saveFileDialog.FileName.EndsWith("bmp")) {159 string filename = saveFileDialog.FileName.ToLower(); 160 if (filename.EndsWith("bmp")) { 46 161 format = ChartImageFormat.Bmp; 47 } else if ( saveFileDialog.FileName.EndsWith("jpg")) {162 } else if (filename.EndsWith("jpg")) { 48 163 format = ChartImageFormat.Jpeg; 49 } else if ( saveFileDialog.FileName.EndsWith("emf")) {164 } else if (filename.EndsWith("emf")) { 50 165 format = ChartImageFormat.EmfDual; 51 } else if ( saveFileDialog.FileName.EndsWith("gif")) {166 } else if (filename.EndsWith("gif")) { 52 167 format = ChartImageFormat.Gif; 53 } else if ( saveFileDialog.FileName.EndsWith("png")) {168 } else if (filename.EndsWith("png")) { 54 169 format = ChartImageFormat.Png; 55 } else if ( saveFileDialog.FileName.EndsWith("tif")) {170 } else if (filename.EndsWith("tif")) { 56 171 format = ChartImageFormat.Tiff; 57 172 }
Note: See TracChangeset
for help on using the changeset viewer.