Changeset 12647
- Timestamp:
- 07/07/15 14:35:09 (9 years ago)
- Location:
- branches/BubbleChart
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/BubbleChart/HeuristicLab.Optimization.BubbleChart/3.3/BubbleChartView.cs
r12600 r12647 187 187 RebuildInverseIndex(); 188 188 189 chart.ChartAreas[0].AxisX.IsMarginVisible = XAxisValue != AxisDimension.Index.ToString();190 chart.ChartAreas[0].AxisY.IsMarginVisible = YAxisValue != AxisDimension.Index.ToString();189 chart.ChartAreas[0].AxisX.IsMarginVisible = !(XAxisValue != null && XAxisValue.Contains(AxisDimension.Index.ToString())); 190 chart.ChartAreas[0].AxisY.IsMarginVisible = !(YAxisValue != null && YAxisValue.Contains(AxisDimension.Index.ToString())); 191 191 192 192 if (Content != null) { 193 var items = GetAvailableItems(); 194 foreach (var item in items) { 195 var xs = GetValues(item, XAxisValue).ToList(); 196 var ys = GetValues(item, YAxisValue).ToList(); 197 var ss = GetValues(item, SizeAxisValue).ToList(); 198 if (xs.Count > 0 && ys.Count > 0 && (ss.Count == 1 || ss.Count == xs.Count || ss.Count == ys.Count)) { 199 var sEnum = ss.Count > 1 ? ss.GetEnumerator() : Enumerable.Repeat(ss[0], xs.Count * ys.Count).GetEnumerator(); 200 sEnum.MoveNext(); 201 if (xs.Count > 1 && ys.Count > 1) { // index matching 202 for (int i = 0; i < Math.Min(xs.Count, ys.Count); i++) 203 series.Points.Add(new DataPoint(xs[i], new[] { ys[i], sEnum.Current })); 204 } else { 205 foreach (var x in xs) { 206 foreach (var y in ys) { 207 series.Points.Add(new DataPoint(x, new[] { y, sEnum.Current })); 208 sEnum.MoveNext(); 193 var items = GetAvailableItems().ToList(); 194 var xss = GetValues(items, XAxisValue).Select(x => x.ToList()).ToList(); 195 var yss = GetValues(items, YAxisValue).Select(x => x.ToList()).ToList(); 196 var sss = GetValues(items, SizeAxisValue).Select(x => x.ToList()).ToList(); 197 198 if (xss.Any(xs => xs.Any()) && yss.Any(ys => ys.Any()) && sss.Any(ss => ss.Any())) { 199 var xDim = Tuple.Create(xss.Count, xss.Max(xs => xs.Count)); 200 var yDim = Tuple.Create(yss.Count, yss.Max(ys => ys.Count)); 201 var sDim = Tuple.Create(sss.Count, sss.Max(ss => ss.Count)); 202 203 var isSimple = new Func<Tuple<int, int>, bool>(dim => dim.Item1 == 1 && dim.Item2 > 1 || dim.Item1 > 1 && dim.Item2 == 1); 204 var flatten = new Func<List<List<double>>, List<double>>(ss => ss.SelectMany(s => s).ToList()); 205 206 if (isSimple(xDim) && isSimple(yDim)) { 207 var xs = flatten(xss); 208 var ys = flatten(yss); 209 if (xs.Count == ys.Count) { 210 var xsEnum = xs.GetEnumerator(); 211 var ysEnum = ys.GetEnumerator(); 212 while (xsEnum.MoveNext() & ysEnum.MoveNext()) 213 series.Points.Add(new DataPoint(xsEnum.Current, new[] { ysEnum.Current, sss[0][0] })); 214 } /*else { 215 foreach (var x in xs) 216 foreach (var y in ys) 217 series.Points.Add(new DataPoint(x, new[] { y, sss[0][0] })); 218 }*/ 219 } else if (isSimple(xDim)) { 220 var xs = flatten(xss); 221 if (xs.Count == yss.Count) { 222 var xsEnum = xs.GetEnumerator(); 223 var yssEnum = yss.GetEnumerator(); 224 while (xsEnum.MoveNext() & yssEnum.MoveNext()) { 225 var x = xsEnum.Current; 226 var ys = yssEnum.Current; 227 foreach (var y in ys) 228 series.Points.Add(new DataPoint(x, new[] { y, sss[0][0] })); 229 } 230 } 231 } else if (isSimple(yDim)) { 232 var ys = flatten(yss); 233 if (xss.Count == ys.Count) { 234 var xssEnum = xss.GetEnumerator(); 235 var ysEnum = ys.GetEnumerator(); 236 while (xssEnum.MoveNext() & ysEnum.MoveNext()) { 237 var xs = xssEnum.Current; 238 var y = ysEnum.Current; 239 foreach (var x in xs) 240 series.Points.Add(new DataPoint(x, new[] { y, sss[0][0] })); 241 } 242 } 243 } else { 244 if (xss.Count == yss.Count) { 245 var xssEnum = xss.GetEnumerator(); 246 var yssEnum = yss.GetEnumerator(); 247 while (xssEnum.MoveNext() & yssEnum.MoveNext()) { 248 var xs = xssEnum.Current; 249 var ys = yssEnum.Current; 250 if (xs.Count == ys.Count) { 251 var xsEnum = xs.GetEnumerator(); 252 var ysEnum = ys.GetEnumerator(); 253 while (xsEnum.MoveNext() & ysEnum.MoveNext()) 254 series.Points.Add(new DataPoint(xsEnum.Current, new[] { ysEnum.Current, sss[0][0] })); 255 } 256 } 257 } else if (xDim.Item2 == yDim.Item2) { 258 foreach (var xs in xss) { 259 foreach (var ys in yss) { 260 var xsEnum = xs.GetEnumerator(); 261 var ysEnum = ys.GetEnumerator(); 262 while (xsEnum.MoveNext() & ysEnum.MoveNext()) { 263 series.Points.Add(new DataPoint(xsEnum.Current, new[] { ysEnum.Current, sss[0][0] })); 264 } 209 265 } 210 266 } … … 214 270 UpdateMarkerSizes(); 215 271 } 272 } 273 274 /*var items = GetAvailableItems(); 275 foreach (var item in items) { 276 var xs = GetValues(item, XAxisValue).ToList(); 277 var ys = GetValues(item, YAxisValue).ToList(); 278 var ss = GetValues(item, SizeAxisValue).ToList(); 279 if (xs.Count > 0 && ys.Count > 0 && (ss.Count == 1 || ss.Count == xs.Count || ss.Count == ys.Count)) { 280 var sEnum = ss.Count > 1 ? ss.GetEnumerator() : Enumerable.Repeat(ss[0], xs.Count * ys.Count).GetEnumerator(); 281 sEnum.MoveNext(); 282 if (xs.Count > 1 && ys.Count > 1) { // index matching 283 for (int i = 0; i < Math.Min(xs.Count, ys.Count); i++) 284 series.Points.Add(new DataPoint(xs[i], new[] { ys[i], sEnum.Current })); 285 } else { 286 foreach (var x in xs) { 287 foreach (var y in ys) { 288 series.Points.Add(new DataPoint(x, new[] { y, sEnum.Current })); 289 sEnum.MoveNext(); 290 } 291 } 292 } 293 } 294 }*/ 295 296 private IEnumerable<IEnumerable<double>> GetValues(IEnumerable<RecursiveDataItem> items, string key) { 297 if (key == null) yield break; 298 var keyTokens = key.Split(new[] { Separator }, StringSplitOptions.RemoveEmptyEntries); 299 if (keyTokens.Length == 1) { 300 if (Enum.IsDefined(typeof(SizeDimension), key)) { 301 var sizeDimension = (SizeDimension)Enum.Parse(typeof(SizeDimension), key); 302 yield return GetValue(null, sizeDimension).ToEnumerable(); 303 } else 304 foreach (var item in items) { 305 if (Enum.IsDefined(typeof(AxisDimension), key)) { 306 var axisDimension = (AxisDimension)Enum.Parse(typeof(AxisDimension), key); 307 yield return GetValue(item, axisDimension).ToEnumerable(); 308 } else if (item.Data.ContainsKey(key)) { 309 yield return item.Data[key] as IEnumerable<double> ?? ConvertToDouble(item, key).ToEnumerable(); 310 } 311 } 312 } else if (keyTokens.Length == 2) { 313 string parentName = keyTokens[0]; 314 key = keyTokens[1]; 315 foreach (var item in items.Where(item => item.Name == parentName)) { 316 foreach (var child in item.Children.Where(child => child.Data.ContainsKey(key))) { 317 yield return child.Data[key] as IEnumerable<double> ?? ConvertToDouble(child, key).ToEnumerable(); 318 } 319 } 320 } else throw new InvalidOperationException("key either contains a single key or a child/data key"); 321 216 322 } 217 323 … … 370 476 double sizeRange = maxSizeValue - minSizeValue; 371 477 372 const int smallestBubbleSize = 7;478 const int smallestBubbleSize = 5; 373 479 374 480 foreach (DataPoint point in series.Points) {
Note: See TracChangeset
for help on using the changeset viewer.