1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2016 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.Drawing;
|
---|
23 |
|
---|
24 | namespace HeuristicLab.Visualization {
|
---|
25 | public abstract class AxisPrimitiveBase : PrimitiveBase {
|
---|
26 | private AxisType myAxisType;
|
---|
27 | public AxisType AxisType {
|
---|
28 | get { return myAxisType; }
|
---|
29 | }
|
---|
30 | private PointD myPoint;
|
---|
31 | public virtual PointD Point {
|
---|
32 | get { return myPoint; }
|
---|
33 | }
|
---|
34 | private bool myShowGrid;
|
---|
35 | public bool ShowGrid {
|
---|
36 | get { return myShowGrid; }
|
---|
37 | set {
|
---|
38 | if (value != myShowGrid) {
|
---|
39 | myShowGrid = value;
|
---|
40 | OnRedrawRequired();
|
---|
41 | }
|
---|
42 | }
|
---|
43 | }
|
---|
44 | private string myHorizontalLabel;
|
---|
45 | public string HorizontalLabel {
|
---|
46 | get { return myHorizontalLabel; }
|
---|
47 | set {
|
---|
48 | if (value != myHorizontalLabel) {
|
---|
49 | myHorizontalLabel = value;
|
---|
50 | OnRedrawRequired();
|
---|
51 | }
|
---|
52 | }
|
---|
53 | }
|
---|
54 | private string myVerticalLabel;
|
---|
55 | public string VerticalLabel {
|
---|
56 | get { return myVerticalLabel; }
|
---|
57 | set {
|
---|
58 | if (value != myVerticalLabel) {
|
---|
59 | myVerticalLabel = value;
|
---|
60 | OnRedrawRequired();
|
---|
61 | }
|
---|
62 | }
|
---|
63 | }
|
---|
64 |
|
---|
65 | protected AxisPrimitiveBase(IChart chart, PointD point, AxisType axisType)
|
---|
66 | : this(chart, point, axisType, Pens.Black, Brushes.Black) { }
|
---|
67 | protected AxisPrimitiveBase(IChart chart, PointD point, AxisType axisType, Pen pen, Brush brush)
|
---|
68 | : base(chart, pen, brush) {
|
---|
69 | myPoint = point;
|
---|
70 | myAxisType = axisType;
|
---|
71 | myShowGrid = true;
|
---|
72 | }
|
---|
73 |
|
---|
74 | public virtual void SetPosition(PointD point) {
|
---|
75 | myPoint = point;
|
---|
76 | OnRedrawRequired();
|
---|
77 | }
|
---|
78 |
|
---|
79 | public override void Move(Offset delta) {
|
---|
80 | SetPosition(Point + delta);
|
---|
81 | }
|
---|
82 |
|
---|
83 | public override void Move(PointD point, Offset delta) {
|
---|
84 | Move(delta);
|
---|
85 | }
|
---|
86 |
|
---|
87 | public override void SnapToGrid(IGrid grid) {
|
---|
88 | Move(grid.GetBottomLeftGridPoint(myPoint) - myPoint);
|
---|
89 | }
|
---|
90 |
|
---|
91 | public override void SnapToGrid(PointD point, IGrid grid) {
|
---|
92 | SnapToGrid(grid);
|
---|
93 | }
|
---|
94 |
|
---|
95 | public override bool ContainsPoint(PointD point) {
|
---|
96 | var size = Chart.TransformPixelToWorld(new Size(5, 5));
|
---|
97 | bool result = false;
|
---|
98 | if ((AxisType & AxisType.Horizontal) == AxisType.Horizontal)
|
---|
99 | result = result || (point.Y >= Point.Y - (size.Height / 2)) && (point.Y <= Point.Y + (size.Height / 2));
|
---|
100 | if ((AxisType & AxisType.Vertical) == AxisType.Vertical)
|
---|
101 | result = result || (point.X >= Point.X - (size.Height / 2)) && (point.X <= Point.X + (size.Height / 2));
|
---|
102 | return result;
|
---|
103 | }
|
---|
104 | }
|
---|
105 | }
|
---|