- Timestamp:
- 01/11/09 19:30:54 (16 years ago)
- Location:
- branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Charting
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Charting/BubbleChart.cs
r1106 r1108 31 31 namespace HeuristicLab.CEDMA.Charting { 32 32 public class BubbleChart : Chart { 33 private const string X_JITTER = "__X_JITTER"; 34 private const string Y_JITTER = "__Y_JITTER"; 33 35 private const double maxXJitterPercent = 0.05; 34 36 private const double maxYJitterPercent = 0.05; … … 50 52 private double maxX = double.NegativeInfinity; 51 53 private double maxY = double.NegativeInfinity; 52 private List<Re cord> records;54 private List<ResultsEntry> records; 53 55 private Results results; 54 private Dictionary<IPrimitive, Re cord> primitiveToRecordDictionary;55 private Dictionary<Re cord, IPrimitive> recordToPrimitiveDictionary;56 private Dictionary<IPrimitive, ResultsEntry> primitiveToEntryDictionary; 57 private Dictionary<ResultsEntry, IPrimitive> entryToPrimitiveDictionary; 56 58 private Random random = new Random(); 57 59 private Group points; … … 59 61 public BubbleChart(Results results, PointD lowerLeft, PointD upperRight) 60 62 : base(lowerLeft, upperRight) { 61 records = new List<Re cord>();62 primitiveTo RecordDictionary = new Dictionary<IPrimitive, Record>();63 recordToPrimitiveDictionary = new Dictionary<Record, IPrimitive>();63 records = new List<ResultsEntry>(); 64 primitiveToEntryDictionary = new Dictionary<IPrimitive, ResultsEntry>(); 65 entryToPrimitiveDictionary = new Dictionary<ResultsEntry, IPrimitive>(); 64 66 this.results = results; 65 foreach(Record r in results.Records) {66 records.Add(r);67 }68 results.OnRecordAdded += new EventHandler<RecordAddedEventArgs>(results_OnRecordAdded);69 results.Changed += new EventHandler(results_Changed);70 67 } 71 68 … … 75 72 } 76 73 77 public BubbleChart(Result Listresults, double x1, double y1, double x2, double y2)74 public BubbleChart(Results results, double x1, double y1, double x2, double y2) 78 75 : this(results, new PointD(x1, y1), new PointD(x2, y2)) { 79 76 } 80 77 81 void results_OnRecordAdded(object sender, RecordAddedEventArgs e) {82 lock(records) {83 records.Add(e.Record);84 }85 }78 //void results_OnRecordAdded(object sender, RecordAddedEventArgs e) { 79 // lock(records) { 80 // records.Add(e.Record); 81 // } 82 //} 86 83 87 84 public void SetBubbleSizeDimension(string dimension, bool inverted) { … … 93 90 94 91 public void ShowXvsY(string xDimension, string yDimension) { 95 if (this.xDimension != xDimension || this.yDimension != yDimension) {92 if (this.xDimension != xDimension || this.yDimension != yDimension) { 96 93 this.xDimension = xDimension; 97 94 this.yDimension = yDimension; 95 96 foreach (var resultsEntry in results.SelectRows()) { 97 resultsEntry.Set(X_JITTER, random.NextDouble() * 2.0 - 1.0); 98 resultsEntry.Set(Y_JITTER, random.NextDouble() * 2.0 - 1.0); 99 records.Add(resultsEntry); 100 } 98 101 ResetViewSize(); 99 102 Repaint(); … … 110 113 111 114 private void Repaint() { 112 if(xDimension == null || yDimension == null) return; 113 lock(records) { 114 double maxSize = 1; 115 double minSize = 1; 116 if(sizeDimension != null) { 117 var sizes = records.Select(r => r.Get(sizeDimension)).Where(x => !double.IsInfinity(x) && x != double.MaxValue && x != double.MinValue).OrderBy(x=>x); 115 if (xDimension == null || yDimension == null) return; 116 double maxSize = 1; 117 double minSize = 1; 118 try { 119 if (sizeDimension != null && Results.OrdinalVariables.Contains(sizeDimension)) { 120 var sizes = records 121 .Select(x => Convert.ToDouble(x.Get(sizeDimension))) 122 .Where(size => !double.IsInfinity(size) && size != double.MaxValue && size != double.MinValue) 123 .OrderBy(r => r); 118 124 minSize = sizes.ElementAt((int)(sizes.Count() * 0.1)); 119 125 maxSize = sizes.ElementAt((int)(sizes.Count() * 0.9)); 120 126 } 121 UpdateEnabled = false; 122 Group.Clear(); 123 primitiveToRecordDictionary.Clear(); 124 recordToPrimitiveDictionary.Clear(); 125 points = new Group(this); 126 Group.Add(new Axis(this, 0, 0, AxisType.Both)); 127 UpdateViewSize(0, 0, 5); 128 foreach(Record r in records) { 129 double x = r.Get(xDimension) + r.Get(Record.X_JITTER) * xJitterFactor; 130 double y = r.Get(yDimension) + r.Get(Record.Y_JITTER) * yJitterFactor; 131 int size = CalculateSize(r.Get(sizeDimension), minSize, maxSize); 132 133 if(double.IsInfinity(x) || x == double.MaxValue || x == double.MinValue) x = double.NaN; 134 if(double.IsInfinity(y) || y == double.MaxValue || y == double.MinValue) y = double.NaN; 135 if(!double.IsNaN(x) && !double.IsNaN(y)) { 136 UpdateViewSize(x, y, size); 137 int alpha = CalculateAlpha(size); 138 Pen pen = new Pen(Color.FromArgb(alpha, r.Selected ? selectionColor : defaultColor)); 139 Brush brush = pen.Brush; 140 FixedSizeCircle c = new FixedSizeCircle(this, x, y, size, pen, brush); 141 c.ToolTipText = r.GetToolTipText(); 142 points.Add(c); 143 if(!r.Selected) c.IntoBackground(); 144 primitiveToRecordDictionary[c] = r; 145 recordToPrimitiveDictionary[r] = c; 146 } 147 } 148 Group.Add(points); 149 UpdateEnabled = true; 150 } 127 } 128 catch (InvalidCastException) { 129 minSize = 1; 130 maxSize = 1; 131 } 132 UpdateEnabled = false; 133 Group.Clear(); 134 primitiveToEntryDictionary.Clear(); 135 entryToPrimitiveDictionary.Clear(); 136 points = new Group(this); 137 Group.Add(new Axis(this, 0, 0, AxisType.Both)); 138 UpdateViewSize(0, 0, 5); 139 foreach (ResultsEntry r in records) { 140 double x, y; 141 int size; 142 try { 143 x = Convert.ToDouble(r.Get(xDimension)) + (double)r.Get(X_JITTER) * xJitterFactor; 144 y = Convert.ToDouble(r.Get(yDimension)) + (double)r.Get(Y_JITTER) * yJitterFactor; 145 size = CalculateSize(Convert.ToDouble(r.Get(sizeDimension)), minSize, maxSize); 146 } 147 catch (InvalidCastException) { 148 x = double.NaN; 149 y = double.NaN; 150 size = minBubbleSize; 151 } 152 if (double.IsInfinity(x) || x == double.MaxValue || x == double.MinValue) x = double.NaN; 153 if (double.IsInfinity(y) || y == double.MaxValue || y == double.MinValue) y = double.NaN; 154 if (!double.IsNaN(x) && !double.IsNaN(y)) { 155 UpdateViewSize(x, y, size); 156 int alpha = CalculateAlpha(size); 157 Pen pen = new Pen(Color.FromArgb(alpha, r.Selected ? selectionColor : defaultColor)); 158 Brush brush = pen.Brush; 159 FixedSizeCircle c = new FixedSizeCircle(this, x, y, size, pen, brush); 160 c.ToolTipText = r.GetToolTipText(); 161 points.Add(c); 162 if (!r.Selected) c.IntoBackground(); 163 primitiveToEntryDictionary[c] = r; 164 entryToPrimitiveDictionary[r] = c; 165 } 166 } 167 Group.Add(points); 168 UpdateEnabled = true; 151 169 } 152 170 153 171 private int CalculateSize(double size, double minSize, double maxSize) { 154 if(double.IsNaN(size) || double.IsInfinity(size) || size == double.MaxValue || size == double.MinValue) return minBubbleSize; 155 if(size > maxSize) size = maxSize; 156 if(size < minSize) size = minSize; 172 if (double.IsNaN(size) || double.IsInfinity(size) || size == double.MaxValue || size == double.MinValue) return minBubbleSize; 173 if (size > maxSize) size = maxSize; 174 if (size < minSize) size = minSize; 175 if (Math.Abs(maxSize - minSize) < 1.0E-10) return minBubbleSize; 157 176 double sizeDifference = ((size - minSize) / (maxSize - minSize) * (maxBubbleSize - minBubbleSize)); 158 if (invertSize) return maxBubbleSize - (int)sizeDifference;177 if (invertSize) return maxBubbleSize - (int)sizeDifference; 159 178 else return minBubbleSize + (int)sizeDifference; 160 179 } … … 165 184 166 185 private void ZoomToViewSize() { 167 if (minX < maxX && minY < maxY) {186 if (minX < maxX && minY < maxY) { 168 187 // enlarge view by 5% on each side 169 188 double width = maxX - minX; … … 178 197 179 198 private void UpdateViewSize(double x, double y, double size) { 180 if (x - size < minX) minX = x - size;181 if (x + size > maxX) maxX = x + size;182 if (y - size < minY) minY = y + size;183 if (y + size > maxY) maxY = y + size;199 if (x - size < minX) minX = x - size; 200 if (x + size > maxX) maxX = x + size; 201 if (y - size < minY) minY = y + size; 202 if (y + size > maxY) maxY = y + size; 184 203 } 185 204 … … 191 210 } 192 211 193 internal Re cord GetRecord(Point point) {194 Re cordr = null;212 internal ResultsEntry GetResultsEntry(Point point) { 213 ResultsEntry r = null; 195 214 IPrimitive p = points.GetPrimitive(TransformPixelToWorld(point)); 196 if (p != null) {197 primitiveTo RecordDictionary.TryGetValue(p, out r);215 if (p != null) { 216 primitiveToEntryDictionary.TryGetValue(p, out r); 198 217 } 199 218 return r; … … 202 221 203 222 public override void MouseDrag(Point start, Point end, MouseButtons button) { 204 if (button == MouseButtons.Left && Mode == ChartMode.Select) {223 if (button == MouseButtons.Left && Mode == ChartMode.Select) { 205 224 PointD a = TransformPixelToWorld(start); 206 225 PointD b = TransformPixelToWorld(end); … … 214 233 primitives.AddRange(points.Primitives); 215 234 216 foreach (FixedSizeCircle p in primitives) {217 if (rect.ContainsPoint(p.Point)) {218 Re cordr;219 primitiveTo RecordDictionary.TryGetValue(p, out r);220 if (r != null) r.ToggleSelected();235 foreach (FixedSizeCircle p in primitives) { 236 if (rect.ContainsPoint(p.Point)) { 237 ResultsEntry r; 238 primitiveToEntryDictionary.TryGetValue(p, out r); 239 if (r != null) r.ToggleSelected(); 221 240 } 222 241 } 223 results.FireChanged();242 // results.FireChanged(); 224 243 } else { 225 244 base.MouseDrag(start, end, button); … … 228 247 229 248 public override void MouseClick(Point point, MouseButtons button) { 230 if (button == MouseButtons.Left) {231 Re cord r = GetRecord(point);232 if (r != null) r.ToggleSelected();233 results.FireChanged();249 if (button == MouseButtons.Left) { 250 ResultsEntry r = GetResultsEntry(point); 251 if (r != null) r.ToggleSelected(); 252 // results.FireChanged(); 234 253 } else { 235 254 base.MouseClick(point, button); … … 237 256 } 238 257 239 public override void MouseDoubleClick(Point point, MouseButtons button) {240 if(button == MouseButtons.Left) {241 Record r = GetRecord(point);242 if(r != null) r.OpenModel();243 } else {244 base.MouseDoubleClick(point, button);245 }246 }258 //public override void MouseDoubleClick(Point point, MouseButtons button) { 259 // if(button == MouseButtons.Left) { 260 // Record r = GetRecord(point); 261 // if(r != null) r.OpenModel(); 262 // } else { 263 // base.MouseDoubleClick(point, button); 264 // } 265 //} 247 266 } 248 267 } -
branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Charting/BubbleChartView.cs
r1106 r1108 12 12 13 13 namespace HeuristicLab.CEDMA.Charting { 14 public partial class BubbleChartView : ViewBase {14 public partial class BubbleChartView : ViewBase, IResultsView { 15 15 private Results results; 16 16 private const string CONSTANT_SIZE = "<constant>"; 17 17 private Label pleaseSelectAxisLabel = new Label(); 18 18 19 public BubbleChartView(Results results) { 20 this.results = results; 19 public BubbleChartView() { 21 20 InitializeComponent(); 22 bubbleChartControl.Chart = new BubbleChart(results, 0, 0, 100, 100);23 xAxisComboBox.Items.AddRange(results.OrdinalVariableNames);24 yAxisComboBox.Items.AddRange(results.OrdinalVariableNames);25 sizeComboBox.Items.Add(CONSTANT_SIZE);26 sizeComboBox.Items.AddRange(results.VariableNames);27 sizeComboBox.SelectedItem = sizeComboBox.Items[0];28 sizeComboBox.Enabled = false;29 invertCheckbox.Enabled = false;30 sizeLabel.Enabled = false;31 yAxisComboBox.SelectedItem = yAxisComboBox.Items[0];32 xAxisComboBox.SelectedItem = xAxisComboBox.Items[0];33 21 } 34 22 … … 39 27 private void UpdateChart() { 40 28 if (xAxisComboBox.SelectedItem == null || yAxisComboBox.SelectedItem == null) return; 41 xJitterlabel.Enabled = true;42 xTrackBar.Enabled = true;43 yJitterLabel.Enabled = true;44 yTrackBar.Enabled = true;45 sizeComboBox.Enabled = true;46 invertCheckbox.Enabled = true;47 sizeLabel.Enabled = true;48 29 bubbleChartControl.Chart.ShowXvsY((string)xAxisComboBox.SelectedItem, (string)yAxisComboBox.SelectedItem); 49 30 } … … 64 45 } 65 46 } 47 48 #region IResultsView Members 49 50 public Control Control { 51 get { return this; } 52 } 53 54 string IResultsView.Name { 55 get { return "Bubble chart"; } 56 } 57 58 public void ShowResults(Results results) { 59 this.results = results; 60 bubbleChartControl.Chart = new BubbleChart(results, 0, 0, 100, 100); 61 xAxisComboBox.Items.AddRange(Results.OrdinalVariables); 62 xAxisComboBox.Items.AddRange(Results.CategoricalVariables); 63 yAxisComboBox.Items.AddRange(Results.OrdinalVariables); 64 yAxisComboBox.Items.AddRange(Results.CategoricalVariables); 65 sizeComboBox.Items.Add(CONSTANT_SIZE); 66 sizeComboBox.Items.AddRange(Results.OrdinalVariables); 67 sizeComboBox.SelectedItem = sizeComboBox.Items[0]; 68 yAxisComboBox.SelectedItem = yAxisComboBox.Items[0]; 69 xAxisComboBox.SelectedItem = xAxisComboBox.Items[0]; 70 } 71 72 #endregion 66 73 } 67 74 } -
branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Charting/HeuristicLab.CEDMA.Charting.csproj
r1106 r1108 66 66 </ItemGroup> 67 67 <ItemGroup> 68 <Compile Include="BubbleChart.cs" /> 69 <Compile Include="BubbleChartControl.cs"> 70 <SubType>UserControl</SubType> 71 </Compile> 72 <Compile Include="BubbleChartControl.Designer.cs"> 73 <DependentUpon>BubbleChartControl.cs</DependentUpon> 74 </Compile> 75 <Compile Include="BubbleChartView.cs"> 76 <SubType>UserControl</SubType> 77 </Compile> 78 <Compile Include="BubbleChartView.Designer.cs"> 79 <DependentUpon>BubbleChartView.cs</DependentUpon> 80 </Compile> 68 81 <Compile Include="HeuristicLabCedmaChartingPlugin.cs" /> 69 82 <Compile Include="Properties\AssemblyInfo.cs" /> … … 98 111 <Name>HeuristicLab.Data</Name> 99 112 </ProjectReference> 100 <ProjectReference Include="..\HeuristicLab.GP.StructureIdentification\HeuristicLab.GP.StructureIdentification.csproj">101 <Project>{74223A32-C726-4978-BE78-37113A18373C}</Project>102 <Name>HeuristicLab.GP.StructureIdentification</Name>103 </ProjectReference>104 <ProjectReference Include="..\HeuristicLab.GP\HeuristicLab.GP.csproj">105 <Project>{1F1CF3ED-374C-4288-995B-93F6B872F571}</Project>106 <Name>HeuristicLab.GP</Name>107 </ProjectReference>108 113 <ProjectReference Include="..\HeuristicLab.Logging\HeuristicLab.Logging.csproj"> 109 114 <Project>{4095C92C-5A4C-44BC-9963-5F384CF5CC3F}</Project> … … 118 123 <None Include="HeuristicLab.snk" /> 119 124 <None Include="Properties\AssemblyInfo.frame" /> 125 </ItemGroup> 126 <ItemGroup> 127 <EmbeddedResource Include="BubbleChartControl.resx"> 128 <DependentUpon>BubbleChartControl.cs</DependentUpon> 129 </EmbeddedResource> 130 <EmbeddedResource Include="BubbleChartView.resx"> 131 <DependentUpon>BubbleChartView.cs</DependentUpon> 132 </EmbeddedResource> 120 133 </ItemGroup> 121 134 <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Note: See TracChangeset
for help on using the changeset viewer.