- Timestamp:
- 06/30/15 15:40:22 (9 years ago)
- Location:
- branches/BubbleChart
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/BubbleChart/HeuristicLab.Optimization.BubbleChart/3.3/BubbleChartView.cs
r12499 r12554 35 35 [Content(typeof(RecursiveDataItem), false)] 36 36 public partial class BubbleChartView : ItemView { 37 private const string Separator = ":"; 38 37 39 private enum SizeDimension { Constant = 0 } 38 40 private enum AxisDimension { Index = 0 } … … 78 80 } 79 81 private IEnumerable<string> GetAvailableKeys() { 80 return GetAvailableItems() 81 .SelectMany(n => n.Data.Keys) 82 .Distinct(); 82 var collector = new HashSet<string>(); 83 GetAvailableKeys(Content, collector); 84 return collector; 85 } 86 private void GetAvailableKeys(RecursiveDataItem node, ISet<string> collector) { 87 foreach (var child in node.Children) { 88 foreach (var key in child.Data.Keys) { 89 collector.Add(node.Name + Separator + key); 90 } 91 } 92 93 foreach (var child in node.Children) 94 GetAvailableKeys(child, collector); 83 95 } 84 96 #endregion … … 175 187 var items = GetAvailableItems(); 176 188 foreach (var item in items) { 177 var x = GetValue(item, XAxisValue); 178 var y = GetValue(item, YAxisValue); 179 var s = GetValue(item, SizeAxisValue); 180 if (x.HasValue && y.HasValue && s.HasValue) { 181 var dataPoint = new DataPoint(x.Value, new[] { y.Value, s.Value }); 182 series.Points.Add(dataPoint); 189 var xs = GetValues(item, XAxisValue).ToList(); 190 var ys = GetValues(item, YAxisValue).ToList(); 191 var ss = GetValues(item, SizeAxisValue).ToList(); 192 if (xs.Count > 0 && ys.Count > 0 && ss.Count == 1) { 193 var s = ss[0]; 194 if (xs.Count > 1 && ys.Count > 1) { // index matching 195 for (int i = 0; i < Math.Min(xs.Count, ys.Count); i++) 196 series.Points.Add(new DataPoint(xs[i], new[] { ys[i], s })); 197 } else { 198 foreach (var x in xs) 199 foreach (var y in ys) 200 series.Points.Add(new DataPoint(x, new[] { y, s })); 201 } 202 183 203 } 184 204 } 185 205 } 186 206 } 187 private double? GetValue(RecursiveDataItem item, string key) { 188 if (item == null || string.IsNullOrEmpty(key)) 189 return null; 190 191 if (Enum.IsDefined(typeof(AxisDimension), key)) { 192 var axisDimension = (AxisDimension)Enum.Parse(typeof(AxisDimension), key); 193 return GetValue(item, axisDimension); 194 } else if (Enum.IsDefined(typeof(SizeDimension), key)) { 195 var sizeDimension = (SizeDimension)Enum.Parse(typeof(SizeDimension), key); 196 return GetValue(item, sizeDimension); 197 } else if (item.Data.ContainsKey(key)) { 198 IItem value = item.Data[key]; 199 var doubleValue = value as DoubleValue; 200 var intValue = value as IntValue; 201 var timeSpanValue = value as TimeSpanValue; 202 double? ret = null; 203 if (doubleValue != null) { 204 if (!double.IsNaN(doubleValue.Value) && !double.IsInfinity(doubleValue.Value)) 205 ret = doubleValue.Value; 206 } else if (intValue != null) 207 ret = intValue.Value; 208 else if (timeSpanValue != null) 209 ret = timeSpanValue.Value.TotalSeconds; 210 else 211 ret = GetCategoricalValue(item, key, value.ToString()); 212 return ret; 207 208 private IEnumerable<double> GetValues(RecursiveDataItem parent, string key) { 209 if (parent == null || string.IsNullOrEmpty(key)) 210 return Enumerable.Empty<double>(); 211 var tokens = key.Split(new[] { Separator }, StringSplitOptions.RemoveEmptyEntries); 212 if (tokens.Length == 2) { 213 var parentKey = tokens[0]; 214 var dataKey = tokens[1]; 215 if (parent.Name == parentKey) { 216 return parent.Children 217 .Where(child => child.Data.ContainsKey(dataKey)) 218 .Select(child => ConvertToDouble(child.Data[dataKey], child, dataKey)); 219 } 220 return Enumerable.Empty<double>(); 213 221 } else { 214 return null; 215 } 216 } 222 var item = parent; 223 if (item == null || string.IsNullOrEmpty(key)) 224 return Enumerable.Empty<double>(); 225 226 if (Enum.IsDefined(typeof(AxisDimension), key)) { 227 var axisDimension = (AxisDimension)Enum.Parse(typeof(AxisDimension), key); 228 return GetValue(item, axisDimension).ToEnumerable(); 229 } else if (Enum.IsDefined(typeof(SizeDimension), key)) { 230 var sizeDimension = (SizeDimension)Enum.Parse(typeof(SizeDimension), key); 231 return GetValue(item, sizeDimension).ToEnumerable(); 232 } else if (item.Data.ContainsKey(key)) { 233 IItem value = item.Data[key]; 234 return ConvertToDouble(value, item, key).ToEnumerable(); 235 } else { 236 return Enumerable.Empty<double>(); 237 } 238 } 239 } 240 241 private double ConvertToDouble(IItem value, RecursiveDataItem item, string key) { 242 var doubleValue = value as DoubleValue; 243 var intValue = value as IntValue; 244 var timeSpanValue = value as TimeSpanValue; 245 double? ret = null; 246 if (doubleValue != null) { 247 if (!double.IsNaN(doubleValue.Value) && !double.IsInfinity(doubleValue.Value)) 248 ret = doubleValue.Value; 249 } else if (intValue != null) 250 ret = intValue.Value; 251 else if (timeSpanValue != null) 252 ret = timeSpanValue.Value.TotalSeconds; 253 else 254 ret = GetCategoricalValue(item, key, value.ToString()); 255 return ret.Value; 256 } 257 217 258 private double? GetCategoricalValue(RecursiveDataItem item, string key, string value) { 218 259 if (!categoricalMapping.ContainsKey(key)) {
Note: See TracChangeset
for help on using the changeset viewer.