#region License Information
/* HeuristicLab
* Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
*
* This file is part of HeuristicLab.
*
* HeuristicLab is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HeuristicLab is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HeuristicLab. If not, see .
*/
#endregion
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Linq;
using HeuristicLab.Charting;
using System.Windows.Forms;
using HeuristicLab.CEDMA.Core;
using HeuristicLab.PluginInfrastructure;
using HeuristicLab.Core;
using HeuristicLab.CEDMA.DB.Interfaces;
using System.Diagnostics;
namespace HeuristicLab.CEDMA.Charting {
public class BubbleChart : Chart {
private const string X_JITTER = "__X_JITTER";
private const string Y_JITTER = "__Y_JITTER";
private const double maxXJitterPercent = 0.05;
private const double maxYJitterPercent = 0.05;
private const int minBubbleSize = 5;
private const int maxBubbleSize = 30;
private const int maxAlpha = 255;
private const int minAlpha = 50;
private static readonly Color defaultColor = Color.Blue;
private static readonly Color selectionColor = Color.Red;
private double xJitterFactor = 0.0;
private double yJitterFactor = 0.0;
private string xDimension;
private string yDimension;
private string sizeDimension;
private bool invertSize;
private double minX = double.PositiveInfinity;
private double minY = double.PositiveInfinity;
private double maxX = double.NegativeInfinity;
private double maxY = double.NegativeInfinity;
private List filteredEntries;
private Results results;
private Dictionary primitiveToEntryDictionary;
private Random random = new Random();
private Group points;
public BubbleChart(Results results, PointD lowerLeft, PointD upperRight)
: base(lowerLeft, upperRight) {
primitiveToEntryDictionary = new Dictionary();
this.results = results;
filteredEntries = new List();
foreach (var resultsEntry in results.GetEntries()) {
if (resultsEntry.Get(X_JITTER) == null)
resultsEntry.Set(X_JITTER, random.NextDouble() * 2.0 - 1.0);
if (resultsEntry.Get(Y_JITTER) == null)
resultsEntry.Set(Y_JITTER, random.NextDouble() * 2.0 - 1.0);
}
results.Changed += new EventHandler(results_Changed);
}
void results_Changed(object sender, EventArgs e) {
Repaint();
EnforceUpdate();
}
public BubbleChart(Results results, double x1, double y1, double x2, double y2)
: this(results, new PointD(x1, y1), new PointD(x2, y2)) {
}
public void SetBubbleSizeDimension(string dimension, bool inverted) {
this.sizeDimension = dimension;
this.invertSize = inverted;
Repaint();
EnforceUpdate();
}
public void ShowXvsY(string xDimension, string yDimension) {
if (this.xDimension != xDimension || this.yDimension != yDimension) {
this.xDimension = xDimension;
this.yDimension = yDimension;
ResetViewSize();
Repaint();
ZoomToViewSize();
}
}
internal void SetJitter(double xJitterFactor, double yJitterFactor) {
this.xJitterFactor = xJitterFactor * maxXJitterPercent * Size.Width;
this.yJitterFactor = yJitterFactor * maxYJitterPercent * Size.Height;
Repaint();
EnforceUpdate();
}
public override void Render(Graphics graphics, int width, int height) {
graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
base.Render(graphics, width, height);
}
private void Repaint() {
if (xDimension == null || yDimension == null) return;
double maxSize = 1;
double minSize = 1;
if (sizeDimension != null && results.OrdinalVariables.Contains(sizeDimension)) {
var sizes = results.GetEntries()
.Select(x => Convert.ToDouble(x.Get(sizeDimension)))
.Where(size => !double.IsInfinity(size) && size != double.MaxValue && size != double.MinValue)
.OrderBy(r => r);
minSize = sizes.ElementAt((int)(sizes.Count() * 0.1));
maxSize = sizes.ElementAt((int)(sizes.Count() * 0.9));
} else {
minSize = 1;
maxSize = 1;
}
UpdateEnabled = false;
Group.Clear();
primitiveToEntryDictionary.Clear();
points = new Group(this);
Group.Add(new Axis(this, 0, 0, AxisType.Both));
UpdateViewSize(0, 0, TransformPixelToWorld(new Size(5, 0)).Width);
foreach (ResultsEntry r in results.GetEntries().Where(x => x.Visible)) {
List xs = new List();
List ys = new List();
List