[561] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
| 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Collections.Generic;
|
---|
| 24 | using System.ComponentModel;
|
---|
| 25 | using System.Drawing;
|
---|
[566] | 26 | using System.Drawing.Drawing2D;
|
---|
[561] | 27 | using System.Data;
|
---|
| 28 | using System.Text;
|
---|
| 29 | using System.Windows.Forms;
|
---|
| 30 | using HeuristicLab.Charting;
|
---|
| 31 |
|
---|
| 32 | namespace HeuristicLab.CEDMA.Charting {
|
---|
[566] | 33 | public partial class BubbleChartControl : UserControl {
|
---|
| 34 | private Bitmap bitmap;
|
---|
| 35 | private bool renderingRequired;
|
---|
[567] | 36 | private Point mousePosition;
|
---|
[566] | 37 | private Point buttonDownPoint;
|
---|
[2132] | 38 | private IPrimitive primitiveUnderCursor;
|
---|
[567] | 39 |
|
---|
[566] | 40 | private BubbleChart myChart;
|
---|
| 41 | public BubbleChart Chart {
|
---|
| 42 | get { return myChart; }
|
---|
[561] | 43 | set {
|
---|
[566] | 44 | if(myChart != null) myChart.Update -= new EventHandler(myChart_Update);
|
---|
| 45 | myChart = value;
|
---|
| 46 | if(myChart != null) {
|
---|
| 47 | myChart.Update += new EventHandler(myChart_Update);
|
---|
| 48 | SetMode(Chart.Mode);
|
---|
[561] | 49 | }
|
---|
[566] | 50 | GenerateImage();
|
---|
[561] | 51 | }
|
---|
| 52 | }
|
---|
[566] | 53 | private bool myScaleOnResize;
|
---|
| 54 | public bool ScaleOnResize {
|
---|
| 55 | get { return myScaleOnResize; }
|
---|
| 56 | set { myScaleOnResize = value; }
|
---|
[561] | 57 | }
|
---|
| 58 |
|
---|
| 59 | public BubbleChartControl() {
|
---|
| 60 | InitializeComponent();
|
---|
[566] | 61 | myScaleOnResize = true;
|
---|
| 62 | GenerateImage();
|
---|
[561] | 63 | }
|
---|
[566] | 64 |
|
---|
| 65 | private void myChart_Update(object sender, EventArgs e) {
|
---|
| 66 | GenerateImage();
|
---|
| 67 | }
|
---|
| 68 | private void pictureBox_SizeChanged(object sender, EventArgs e) {
|
---|
| 69 | if(ScaleOnResize) {
|
---|
| 70 | if((pictureBox.Width > 0) && (pictureBox.Height > 0) && (Chart != null)) {
|
---|
| 71 | PointD point = Chart.TransformPixelToWorld(new Point(pictureBox.Width, Chart.SizeInPixels.Height - pictureBox.Height));
|
---|
| 72 | Chart.SetPosition(Chart.LowerLeft, point);
|
---|
| 73 | }
|
---|
| 74 | }
|
---|
| 75 | GenerateImage();
|
---|
| 76 | }
|
---|
| 77 | private void pictureBox_VisibleChanged(object sender, EventArgs e) {
|
---|
| 78 | if(pictureBox.Visible && renderingRequired) {
|
---|
| 79 | GenerateImage();
|
---|
| 80 | }
|
---|
| 81 | }
|
---|
| 82 |
|
---|
| 83 | private void pictureBox_MouseDown(object sender, MouseEventArgs e) {
|
---|
| 84 | buttonDownPoint = e.Location;
|
---|
| 85 | }
|
---|
| 86 | private void pictureBox_MouseUp(object sender, MouseEventArgs e) {
|
---|
| 87 | if(e.Button == MouseButtons.Left) {
|
---|
| 88 | Point lowerLeft = new Point(Math.Min(e.X, buttonDownPoint.X),
|
---|
| 89 | Math.Max(e.Y, buttonDownPoint.Y));
|
---|
| 90 | Point upperRight = new Point(Math.Max(e.X, buttonDownPoint.X),
|
---|
| 91 | Math.Min(e.Y, buttonDownPoint.Y));
|
---|
| 92 | if(Chart.Mode == ChartMode.Zoom) {
|
---|
| 93 | pictureBox.Refresh();
|
---|
| 94 | if((lowerLeft.X != upperRight.X) && (lowerLeft.Y != upperRight.Y)) {
|
---|
| 95 | Chart.ZoomIn(lowerLeft, upperRight);
|
---|
| 96 | }
|
---|
| 97 | } else if(Chart.Mode == ChartMode.Select) {
|
---|
| 98 | if((lowerLeft.X != upperRight.X) && (lowerLeft.Y != upperRight.Y)) {
|
---|
| 99 | Chart.MouseDrag(lowerLeft, upperRight, e.Button);
|
---|
| 100 | }
|
---|
[567] | 101 | } else if(Chart.Mode == ChartMode.Move) {
|
---|
[566] | 102 | }
|
---|
| 103 | } else if(e.Button == MouseButtons.Middle) {
|
---|
| 104 | if(Chart.Mode == ChartMode.Zoom) {
|
---|
[567] | 105 | Chart.ZoomOut();
|
---|
[566] | 106 | }
|
---|
| 107 | }
|
---|
| 108 | }
|
---|
| 109 | private void pictureBox_MouseMove(object sender, MouseEventArgs e) {
|
---|
[2132] | 110 | if (Chart.GetPrimitive(e.Location) != primitiveUnderCursor) {
|
---|
| 111 | primitiveUnderCursor = Chart.GetPrimitive(e.Location);
|
---|
| 112 | toolTip.SetToolTip(pictureBox, Chart.GetToolTipText(e.Location));
|
---|
| 113 | }
|
---|
[566] | 114 | if(e.Button != MouseButtons.None) {
|
---|
| 115 | if((Chart.Mode == ChartMode.Zoom || Chart.Mode == ChartMode.Select) && (e.Button == MouseButtons.Left)) {
|
---|
| 116 | pictureBox.Refresh();
|
---|
| 117 | Graphics graphics = pictureBox.CreateGraphics();
|
---|
| 118 | Pen pen = new Pen(Color.Gray);
|
---|
| 119 | pen.DashStyle = DashStyle.Dash;
|
---|
| 120 | graphics.DrawRectangle(pen,
|
---|
| 121 | Math.Min(e.X, buttonDownPoint.X),
|
---|
| 122 | Math.Min(e.Y, buttonDownPoint.Y),
|
---|
| 123 | Math.Abs(e.X - buttonDownPoint.X),
|
---|
| 124 | Math.Abs(e.Y - buttonDownPoint.Y));
|
---|
| 125 | pen.Dispose();
|
---|
| 126 | graphics.Dispose();
|
---|
| 127 | }
|
---|
| 128 | }
|
---|
| 129 | mousePosition = e.Location;
|
---|
| 130 | }
|
---|
| 131 |
|
---|
| 132 | private void zoomToolStripMenuItem_Click(object sender, EventArgs e) {
|
---|
| 133 | SetMode(ChartMode.Zoom);
|
---|
| 134 | }
|
---|
| 135 | private void selectToolStripMenuItem_Click(object sender, EventArgs e) {
|
---|
| 136 | SetMode(ChartMode.Select);
|
---|
| 137 | }
|
---|
[567] | 138 | private void moveToolStripMenuItem_Click(object sender, EventArgs e) {
|
---|
| 139 | SetMode(ChartMode.Move);
|
---|
| 140 | }
|
---|
[566] | 141 |
|
---|
| 142 | private void GenerateImage() {
|
---|
| 143 | if(!Visible) {
|
---|
| 144 | renderingRequired = true;
|
---|
| 145 | } else {
|
---|
| 146 | if((pictureBox.Width == 0) || (pictureBox.Height == 0)) {
|
---|
| 147 | bitmap = null;
|
---|
| 148 | } else {
|
---|
| 149 | bitmap = new Bitmap(pictureBox.Width, pictureBox.Height);
|
---|
| 150 | if(Chart != null) {
|
---|
| 151 | Graphics graphics = Graphics.FromImage(bitmap);
|
---|
| 152 | graphics.SetClip(new System.Drawing.Rectangle(0, 0, pictureBox.Width, pictureBox.Height));
|
---|
| 153 | Chart.Render(graphics, pictureBox.Width, pictureBox.Height);
|
---|
| 154 | graphics.Dispose();
|
---|
| 155 | }
|
---|
| 156 | }
|
---|
| 157 | pictureBox.Image = bitmap;
|
---|
| 158 | renderingRequired = false;
|
---|
| 159 | }
|
---|
| 160 | }
|
---|
| 161 |
|
---|
| 162 | private void SetMode(ChartMode mode) {
|
---|
| 163 | zoomToolStripMenuItem.Checked = false;
|
---|
| 164 | selectToolStripMenuItem.Checked = false;
|
---|
[567] | 165 | moveToolStripMenuItem.Checked = false;
|
---|
[566] | 166 | if(mode == ChartMode.Zoom) zoomToolStripMenuItem.Checked = true;
|
---|
| 167 | else if(mode == ChartMode.Select) selectToolStripMenuItem.Checked = true;
|
---|
[567] | 168 | else if(mode == ChartMode.Move) moveToolStripMenuItem.Checked = true;
|
---|
[566] | 169 | Chart.Mode = mode;
|
---|
| 170 | }
|
---|
| 171 |
|
---|
| 172 | private void pictureBox_MouseClick(object sender, MouseEventArgs e) {
|
---|
[569] | 173 | Chart.MouseClick(e.Location, e.Button);
|
---|
[566] | 174 | }
|
---|
| 175 |
|
---|
| 176 | private void pictureBox_MouseDoubleClick(object sender, MouseEventArgs e) {
|
---|
[569] | 177 | Chart.MouseDoubleClick(e.Location, e.Button);
|
---|
[566] | 178 | }
|
---|
[2139] | 179 |
|
---|
| 180 | private void invertSelectionToolStripMenuItem_Click(object sender, EventArgs e) {
|
---|
| 181 | Chart.ToggleSelected();
|
---|
| 182 | }
|
---|
| 183 |
|
---|
| 184 | private void hideSelectedToolStripMenuItem_Click(object sender, EventArgs e) {
|
---|
| 185 | showHiddenToolStripMenuItem.Enabled = true;
|
---|
| 186 | Chart.ApplyFilter(x => x.Selected == true && x.Visible==true);
|
---|
| 187 | }
|
---|
| 188 |
|
---|
| 189 | private void clearSelectionMenuItem_Click(object sender, EventArgs e) {
|
---|
| 190 | Chart.ClearSelection();
|
---|
| 191 | }
|
---|
| 192 |
|
---|
| 193 | private void showHiddenToolStripMenuItem_Click(object sender, EventArgs e) {
|
---|
| 194 | Chart.ClearFilter();
|
---|
| 195 | showHiddenToolStripMenuItem.Enabled = false;
|
---|
| 196 | }
|
---|
[561] | 197 | }
|
---|
| 198 | }
|
---|