AUTHOR: Hristo Merdjanov
DATE POSTED: December 11, 2015
ChartPanZoomController, ChartTrackBallController and the LassoZoomController rely on the same mouse states in order to provide their functionality. Combining the tree in a single project might lead to an unexpected result, e.g. the panning feature would be overridden by the LassoZoomController.
Extend the LassoZoomController and perform lasso selection only if a modifier key is being pressed. In order to implement this feature we would need to create the following classes:
The animation below demonstrates how the chart control behaves after implementing this solution:
[C#]
public
partial
class
Form1 : Form
{
Form1()
InitializeComponent();
ChartPanZoomController panZoomController =
new
ChartPanZoomController();
radChartView1.Controllers.Add(panZoomController);
ChartTrackballController chartTrackBallController =
ChartTrackballController();
radChartView1.Controllers.Add(chartTrackBallController);
MyLassoZoomController lassoZoomController =
MyLassoZoomController();
this
.radChartView1.Controllers.Add(lassoZoomController);
.BindChart();
}
private
void
BindChart()
.radChartView1.AreaType = ChartAreaType.Cartesian;
LineSeries lineSeries1 =
LineSeries();
lineSeries1.Name =
"X"
;
lineSeries1.DataPoints.Add(
CategoricalDataPoint(10,
"1"
));
CategoricalDataPoint(4,
"2"
CategoricalDataPoint(23,
"3"
CategoricalDataPoint(11,
"4"
CategoricalDataPoint(15,
"5"
"6"
"7"
CategoricalDataPoint(7,
"8"
"9"
"10"
.radChartView1.Series.Add(lineSeries1);
LineSeries lineSeries2 =
lineSeries2.Name =
"Y"
lineSeries2.DataPoints.Add(
CategoricalDataPoint(6,
CategoricalDataPoint(20,
CategoricalDataPoint(8,
CategoricalDataPoint(24,
CategoricalDataPoint(17,
CategoricalDataPoint(18,
CategoricalDataPoint(43,
.radChartView1.Series.Add(lineSeries2);
[VB]
Public
Class
Form1
Sub
New
()
InitializeComponent()
Dim
panZoomController
As
ChartPanZoomController()
RadChartView1.Controllers.Add(panZoomController)
chartTrackBallController
ChartTrackballController()
RadChartView1.Controllers.Add(chartTrackBallController)
lassoZoomController
MyLassoZoomController()
Me
.RadChartView1.Controllers.Add(lassoZoomController)
.BindChart()
End
Private
.RadChartView1.AreaType = ChartAreaType.Cartesian
lineSeries1
LineSeries()
))
.RadChartView1.Series.Add(lineSeries1)
lineSeries2
.RadChartView1.Series.Add(lineSeries2)
MyLassoZoomView : IView
LassoZoomController owner;
MyLassoZoomView(LassoZoomController owner)
.owner = owner;
Render(
object
context)
Graphics graphics = context
as
Graphics;
using
(SolidBrush brush =
SolidBrush(Color.FromArgb(127, Color.LightBlue)))
Rectangle rect =
.owner.CreateLassoRectangle();
graphics.FillRectangle(brush, rect);
graphics.DrawRectangle(Pens.LightBlue, rect);
MyLassoZoomView
Implements
IView
owner
LassoZoomController
(owner
LassoZoomController)
.owner = owner
Render(context
Object
)
IView.Render
graphics
Graphics = TryCast(context, Graphics)
Using brush
SolidBrush(Color.FromArgb(127, Color.LightBlue))
rect
Rectangle =
.owner.CreateLassoRectangle()
graphics.FillRectangle(brush, rect)
graphics.DrawRectangle(Pens.LightBlue, rect)
Using
MyLassoZoomController : LassoZoomController
ViewResult result;
Keys modifierKey;
:
(Keys.Control) { }
MyLassoZoomController(Keys key)
.result =
ViewResult(
MyLassoZoomView(
.modifierKey = key;
Keys ModifierKey
get
return
.modifierKey;
set
if
(value == (Keys.Control | Keys.Shift | Keys.Alt))
.modifierKey = value;
else
throw
ArgumentException(
"Passed key needs to be Control, Shift or Alt"
);
protected
override
ActionResult OnMouseUp(MouseEventArgs e)
(Control.ModifierKeys ==
.modifierKey)
.View.ShowTrackBall =
true
.View.ShowPanZoom =
base
.OnMouseUp(e);
ActionResult OnMouseDown(System.Windows.Forms.MouseEventArgs e)
(e.Button == MouseButtons.Left && Control.ModifierKeys ==
false
.MouseDownLocation =
.ClipLocation(e.Location);
.result.ShouldInvalidate =
.OnMouseDown(e);
Controller.Empty;
ActionResult OnMouseMove(MouseEventArgs e)
.MouseMoveLocation =
.result;
Point ClipLocation(Point point)
CartesianArea area =
.Area.View.GetArea<CartesianArea>();
(area !=
null
RectangleF clipRect =
.GetCartesianClipRect();
(point.X < clipRect.X)
point =
Point((
int
)clipRect.X, point.Y);
(point.X > clipRect.Width + clipRect.X)
)clipRect.Width + (
(point.Y < clipRect.Y)
Point(point.X, (
)clipRect.Y);
(point.Y > clipRect.Height + clipRect.Y)
)clipRect.Height + (
point;
RectangleF GetCartesianClipRect()
float
x1, x2, y1, y2;
x1 = 0;
y1 = 0;
x2 = (
.Area.View.Viewport.Right;
y2 = (
.Area.View.Viewport.Bottom;
foreach
(Axis axis
in
.Area.View.Axes)
(axis.AxisType == AxisType.First)
(axis.Model.VerticalLocation == AxisVerticalLocation.Bottom)
y2 = Math.Min(y2, (
)axis.Model.LayoutSlot.Y);
y1 = Math.Max(y1, (
)axis.Model.LayoutSlot.Bottom);
x1 = Math.Min(x1, (
)axis.Model.LayoutSlot.X);
x2 = Math.Min(x2, (
)axis.Model.LayoutSlot.Right);
(axis.Model.HorizontalLocation == AxisHorizontalLocation.Left)
x1 = Math.Max(x1, (
RectangleF result =
RectangleF((
.Area.View.Viewport.X + x1, (
.Area.View.Viewport.Y + y1, x2 - x1 + 1, y2 - y1 + 1);
result;
MyLassoZoomController
Inherits
result
ViewResult
m_modifierKey
Keys
.
(Keys.Control)
(key
Keys)
.m_modifierKey = key
Property
ModifierKey()
Get
Return
.m_modifierKey
Set
(value
If
value = (Keys.Control
Or
Keys.Shift
Keys.Alt)
Then
.m_modifierKey = value
Else
Throw
Protected
Overrides
Function
OnMouseUp(e
MouseEventArgs)
ActionResult
Control.ModifierKeys =
True
MyBase
.OnMouseUp(e)
OnMouseDown(e
System.Windows.Forms.MouseEventArgs)
e.Button = MouseButtons.Left
AndAlso
False
.ClipLocation(e.Location)
.OnMouseDown(e)
Controller.Empty
OnMouseMove(e
.result
ClipLocation(point
Point)
Point
area
CartesianArea =
.Area.View.GetArea(Of CartesianArea)()
area IsNot
Nothing
clipRect
RectangleF =
.GetCartesianClipRect()
point.X < clipRect.X
Point(
CInt
(clipRect.X), point.Y)
point.X > clipRect.Width + clipRect.X
(clipRect.Width) +
point.Y < clipRect.Y
Point(point.X,
(clipRect.Y))
point.Y > clipRect.Height + clipRect.Y
(clipRect.Height) +
point
GetCartesianClipRect()
RectangleF
x1
Single
, x2
, y1
, y2
x1 = 0
y1 = 0
x2 =
CSng
(
.Area.View.Viewport.Right)
y2 =
.Area.View.Viewport.Bottom)
For
Each
axis
Axis
In
.Area.View.Axes
axis.AxisType = AxisType.First
axis.Model.VerticalLocation = AxisVerticalLocation.Bottom
y2 = Math.Min(y2,
(axis.Model.LayoutSlot.Y))
y1 = Math.Max(y1,
(axis.Model.LayoutSlot.Bottom))
x1 = Math.Min(x1,
(axis.Model.LayoutSlot.X))
x2 = Math.Min(x2,
(axis.Model.LayoutSlot.Right))
axis.Model.HorizontalLocation = AxisHorizontalLocation.Left
x1 = Math.Max(x1,
Next
RectangleF(
.Area.View.Viewport.X) + x1,
.Area.View.Viewport.Y) + y1, x2 - x1 + 1, y2 - y1 + 1)
Resources Buy Try