- Timestamp:
- 11/29/08 12:19:58 (16 years ago)
- Location:
- trunk/sources
- Files:
-
- 6 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Visualization.Test/HeuristicLab.Visualization.Test.csproj
r858 r861 52 52 </PropertyGroup> 53 53 <ItemGroup> 54 <Reference Include="nunit.framework, Version=2.4.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL"> 55 <SpecificVersion>False</SpecificVersion> 56 <HintPath>NUnit-2.4.8-bin\nunit.framework.dll</HintPath> 57 </Reference> 54 58 <Reference Include="System" /> 55 59 <Reference Include="System.Core"> … … 70 74 <Compile Include="HeuristicLabVisualizationTestApplication.cs" /> 71 75 <Compile Include="HeuristicLabVisualizationTestPlugin.cs" /> 76 <Compile Include="LineChartTestForm.cs"> 77 <SubType>Form</SubType> 78 </Compile> 79 <Compile Include="LineChartTestForm.Designer.cs"> 80 <DependentUpon>LineChartTestForm.cs</DependentUpon> 81 </Compile> 82 <Compile Include="LineChartTests.cs" /> 72 83 <Compile Include="MainForm.cs"> 73 84 <SubType>Form</SubType> … … 83 94 </ItemGroup> 84 95 <ItemGroup> 96 <ProjectReference Include="..\HeuristicLab.Core\HeuristicLab.Core.csproj"> 97 <Project>{F43B59AB-2B8C-4570-BC1E-15592086517C}</Project> 98 <Name>HeuristicLab.Core</Name> 99 </ProjectReference> 85 100 <ProjectReference Include="..\HeuristicLab.PluginInfrastructure\HeuristicLab.PluginInfrastructure.csproj"> 86 101 <Project>{94186A6A-5176-4402-AE83-886557B53CCA}</Project> … … 93 108 </ItemGroup> 94 109 <ItemGroup> 110 <EmbeddedResource Include="LineChartTestForm.resx"> 111 <DependentUpon>LineChartTestForm.cs</DependentUpon> 112 </EmbeddedResource> 95 113 <EmbeddedResource Include="MainForm.resx"> 96 114 <DependentUpon>MainForm.cs</DependentUpon> -
trunk/sources/HeuristicLab.Visualization/LineChart.cs
r761 r861 1 1 using System; 2 using System. Drawing;2 using System.Collections.Generic; 3 3 using HeuristicLab.Core; 4 4 5 namespace HeuristicLab.Visualization 6 { 7 public partial class LineChart : ViewBase 8 { 5 namespace HeuristicLab.Visualization { 6 public partial class LineChart : ViewBase { 9 7 private readonly IChartDataRowsModel model; 10 private Color[] lineColors;11 8 12 9 /// <summary> 13 10 /// This constructor shouldn't be called. Only required for the designer. 14 11 /// </summary> 15 public LineChart() 16 { 12 public LineChart() { 17 13 InitializeComponent(); 18 14 } … … 22 18 /// </summary> 23 19 /// <param name="model">Referenz to the model, for data</param> 24 public LineChart(IChartDataRowsModel model) : this() 25 { 20 public LineChart(IChartDataRowsModel model) : this() { 26 21 if (model == null) 27 {28 22 throw new NullReferenceException("Model cannot be null."); 29 }30 23 31 24 this.model = model; 25 this.Item = (IItem)model; 32 26 33 //TODO: read line colors instead of static ones34 lineColors = new Color[3];35 lineColors[0] = Color.Red;36 lineColors[1] = Color.Green;37 lineColors[2] = Color.Blue;38 39 27 //TODO: correct Rectangle to fit 40 RectangleD clientRectangle = new RectangleD(ClientRectangle.Left, ClientRectangle.Top, ClientRectangle.Right, 41 ClientRectangle.Bottom); 28 RectangleD clientRectangle = new RectangleD(-1, -1, 11, 11); 42 29 canvasUI1.MainCanvas.WorldShape = new WorldShape(clientRectangle, clientRectangle); 43 Reset();44 }45 46 /// <summary>47 /// Resets the line chart by deleting all shapes and reloading all data from the model.48 /// </summary>49 private void Reset()50 {51 // TODO an neues model interface anpassen52 throw new NotImplementedException();53 54 // BeginUpdate();55 //56 // // TODO clear existing shapes57 //58 // WorldShape mainWorld = canvasUI1.MainCanvas.WorldShape;59 //60 // double spacing = mainWorld.BoundingBox.Width/model.Columns.Count;61 // double oldX = 0;62 // double currentX = spacing;63 // ChartDataRowsModelColumn oldColumn = null;64 // // reload data from the model and create shapes65 // foreach (ChartDataRowsModelColumn column in model.Columns)66 // {67 // if (oldColumn != null)68 // {69 // if (column.Values != null)70 // {71 // for (int i = 0; i < column.Values.Length; i++)72 // {73 // LineShape line = new LineShape(oldX, oldColumn.Values[i], currentX, column.Values[i], 0, lineColors[i]);74 // mainWorld.AddShape(line);75 // }76 // oldX = currentX;77 // currentX += spacing;78 // }79 // oldColumn = column;80 // }81 // else82 // {83 // oldColumn = column;84 // }85 //86 // canvasUI1.Invalidate();87 //88 // // AddColumn(column.ColumnId, column.Values);89 // }90 //91 // EndUpdate();92 }93 94 /// <summary>95 /// Event handler which gets called when data in the model changes.96 /// </summary>97 /// <param name="type">Type of change</param>98 /// <param name="columnId">Id of the changed column</param>99 /// <param name="values">Values contained within the changed column</param>100 private void OnDataChanged(ChangeType type, long columnId, double[] values)101 {102 switch (type)103 {104 case ChangeType.Add:105 AddColumn(columnId, values);106 break;107 case ChangeType.Modify:108 ModifyColumn(columnId, values);109 break;110 case ChangeType.Remove:111 RemoveColumn(columnId);112 break;113 default:114 throw new ArgumentOutOfRangeException("type");115 }116 }117 118 /// <summary>119 /// Adds a new column to the chart.120 /// </summary>121 /// <param name="columnId">Id of the column</param>122 /// <param name="values">Values of the column</param>123 private void AddColumn(long columnId, double[] values)124 {125 throw new NotImplementedException();126 }127 128 /// <summary>129 /// Modifies an existing column of the chart.130 /// </summary>131 /// <param name="columnId">Id of the column</param>132 /// <param name="values">Values of the column</param>133 private void ModifyColumn(long columnId, double[] values)134 {135 throw new NotImplementedException();136 }137 138 /// <summary>139 /// Removes a column from the chart.140 /// </summary>141 /// <param name="columnId">Id of the column</param>142 private void RemoveColumn(long columnId)143 {144 throw new NotImplementedException();145 30 } 146 31 147 32 #region Add-/RemoveItemEvents 148 33 149 protected override void AddItemEvents() 150 {151 // TODO an neues model interface anpassen 152 throw new NotImplementedException();153 // base.AddItemEvents();154 // model.ColumnChanged += OnDataChanged;34 protected override void AddItemEvents() { 35 base.AddItemEvents(); 36 37 model.DataRowAdded += OnDataRowAdded; 38 model.DataRowRemoved += OnDataRowRemoved; 39 model.ModelChanged += OnModelChanged; 155 40 } 156 41 157 protected override void RemoveItemEvents() 158 { 159 // TODO an neues model interface anpassen 160 throw new NotImplementedException(); 42 protected override void RemoveItemEvents() { 43 base.RemoveItemEvents(); 161 44 162 // base.RemoveItemEvents(); 163 // model.ColumnChanged -= OnDataChanged; 45 model.DataRowAdded -= OnDataRowAdded; 46 model.DataRowRemoved -= OnDataRowRemoved; 47 model.ModelChanged -= OnModelChanged; 48 } 49 50 private void OnDataRowAdded(IDataRow row) { 51 row.ValueChanged += OnRowValueChanged; 52 row.ValuesChanged += OnRowValuesChanged; 53 54 InitShapes(row); 55 } 56 57 private void InitShapes(IDataRow row) { 58 List<LineShape> lineShapes = new List<LineShape>(); 59 60 for (int i = 1; i < row.Count; i++) { 61 LineShape lineShape = new LineShape(i - 1, row[i - 1], i, row[i], 0, row.Color); 62 lineShapes.Add(lineShape); 63 canvasUI1.MainCanvas.WorldShape.AddShape(lineShape); 64 } 65 66 rowToLineShapes[row] = lineShapes; 67 68 canvasUI1.Invalidate(); 69 } 70 71 private void OnDataRowRemoved(IDataRow row) { 72 row.ValueChanged -= OnRowValueChanged; 73 row.ValuesChanged -= OnRowValuesChanged; 74 } 75 76 private readonly IDictionary<IDataRow, List<LineShape>> rowToLineShapes = new Dictionary<IDataRow, List<LineShape>>(); 77 78 private void OnRowValueChanged(IDataRow row, double value, int index) { 79 List<LineShape> lineShapes = rowToLineShapes[row]; 80 81 if (index > lineShapes.Count+1) 82 throw new NotImplementedException(); 83 84 // new value was added 85 if (index > 0 && index == lineShapes.Count+1) { 86 LineShape lineShape = new LineShape(index - 1, row[index - 1], index, row[index], 0, row.Color); 87 lineShapes.Add(lineShape); 88 canvasUI1.MainCanvas.WorldShape.AddShape(lineShape); 89 } 90 91 // not the first value 92 if (index > 0) 93 lineShapes[index-1].Y2 = value; 94 95 // not the last value 96 if (index > 0 && index < row.Count) 97 lineShapes[index].Y1 = value; 98 99 canvasUI1.Invalidate(); 100 } 101 102 private void OnRowValuesChanged(IDataRow row, double[] values, int index) { 103 foreach (double value in values) { 104 OnRowValueChanged(row, value, index++); 105 } 106 } 107 108 private void OnModelChanged() { 164 109 } 165 110 … … 170 115 private int beginUpdateCount = 0; 171 116 172 public void BeginUpdate() 173 { 117 public void BeginUpdate() { 174 118 beginUpdateCount++; 175 119 } 176 120 177 public void EndUpdate() 178 { 121 public void EndUpdate() { 179 122 if (beginUpdateCount == 0) 180 {181 123 throw new InvalidOperationException("Too many EndUpdates."); 182 }183 124 184 125 beginUpdateCount--; 185 126 186 127 if (beginUpdateCount == 0) 187 {188 128 Invalidate(); 189 }190 129 } 191 130 -
trunk/sources/HeuristicLab.Visualization/LineShape.cs
r754 r861 3 3 namespace HeuristicLab.Visualization { 4 4 public class LineShape : IShape { 5 private RectangleD bounding Rect;5 private RectangleD boundingBox; 6 6 private double z; 7 7 private Color color; … … 16 16 /// <param name="color">color for the LineShape</param> 17 17 public LineShape(double x1, double y1, double x2, double y2, double z, Color color) { 18 this.bounding Rect= new RectangleD(x1, y1, x2, y2);18 this.boundingBox = new RectangleD(x1, y1, x2, y2); 19 19 this.z = z; 20 20 this.color = color; … … 22 22 23 23 public RectangleD BoundingBox { 24 get { return boundingRect; } 24 get { return boundingBox; } 25 } 26 27 public double Y1 { 28 get { return boundingBox.Y1; } 29 set { boundingBox.Y1 = value; } 30 } 31 32 public double Y2 { 33 get { return boundingBox.Y2; } 34 set { boundingBox.Y2 = value; } 35 } 36 37 public double X1 { 38 get { return boundingBox.X1; } 39 set { boundingBox.X1 = value; } 40 } 41 42 public double X2 { 43 get { return boundingBox.X2; } 44 set { boundingBox.X2 = value; } 25 45 } 26 46 … … 33 53 public void Draw(Graphics graphics, Rectangle viewport, RectangleD clippingArea) { 34 54 using (Pen pen = new Pen(color, 3)){ 35 Rectangle screenRect = Transform.ToScreen(bounding Rect, viewport, clippingArea);55 Rectangle screenRect = Transform.ToScreen(boundingBox, viewport, clippingArea); 36 56 graphics.DrawLine(pen,screenRect.Left, screenRect.Bottom, screenRect.Right, screenRect.Top); 37 57 }
Note: See TracChangeset
for help on using the changeset viewer.