Page 1 of 1
Is there a way to draw the zoom rectangle without zooming?
Posted: Wed Aug 27, 2008 7:16 pm
by 14045609
Our users are producing graphs with Time on the X axis and they need the ability to select a range of Time from that graph.
They want to be able to highlight the graph similar to how zooming looks when you are zooming only in the Horizontal direction (highlights from top of the graph to the bottom and expands as the user moves the cursor from left to right) but when they release that highlight selection I need the graph to NOT zoom.
Is there a way that I can use the zoom range selection but suppress the actual zoom of the graph? These graphs contain a very large number of points so zooming and then quickly unzooming is not an option.
I looked at the cursor tools and also played around with the options under the Zoom property on the chart but it seems like I have no way to intercept the action. I tried catching the MouseUp event but by that point, the Zoomed event has already processed so my graph is already zoomed in.
If there is a way to draw this highlight rectangle using the cursor tools or some other way without actually zooming in my graph, I would really appreciate help finding how to do that.
Thanks
Aaron Peronto
Posted: Thu Aug 28, 2008 8:23 am
by narcis
Hi Aaron,
Yes, you can do something as what was discussed
here.
Posted: Thu Aug 28, 2008 12:34 pm
by 14045609
Thanks for the quick reply as always Narcis.
I looked into the solution that you recommended.
It works in a way. It does give me the ability to draw the selection box in a similar way to how the zoom function does, however, this recommended method causes the entire chart to redraw with each mouse move that causes the highlight box to expand.
When using the zoom capability, the box that gets drawn does not seem to require the same complete redraw like this recommended solution does.
The full redraw would not be such a problem except that we produce graphs many times in the hundreds of thousands of data points. It is not unheard of for our graphs to contain several million points. You can imagine how the redraw of that would stagger with each mouse move when attempting to highlight a selection area.
I was really hoping to be able to use the exact same method that the zoom box draw uses just without executing the zoom at the end when i release the mouse button. I tried doing the tchart1.Zoom.Undo() within the Zoomed event handler. That would work except that if they perform this highlight function while their chart is already zoomed in, it will zoomed them all the way back out when the .Undo() is executed.
Any thoughts on being able to use the zoom's ability to draw the selection rectangle outside of performing an actual zoom? It does that draw really well and really fast. I just need to control if it zooms whe I release the button.
Thanks again.
Posted: Fri Aug 29, 2008 8:34 am
by narcis
Hi Aaron,
Ok, in that case, something very similar to TeeChart's zooming feature would be code below. In fact, it uses zoom rectangle painting but without zooming.
Code: Select all
public Form1()
{
InitializeComponent();
InitializeChart();
}
private Steema.TeeChart.Styles.Points points1;
private void InitializeChart()
{
tChart1.Aspect.View3D = false;
tChart1.Panning.MouseButton = MouseButtons.Middle;
points1 = new Steema.TeeChart.Styles.Points(tChart1.Chart);
points1.FillSampleValues();
tChart1.MouseDown += new MouseEventHandler(tChart1_MouseDown);
tChart1.MouseUp += new MouseEventHandler(tChart1_MouseUp);
tChart1.MouseMove += new MouseEventHandler(tChart1_MouseMove);
}
private void tChart1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
tChart1.Zoom.x0 = e.X;
tChart1.Zoom.y0 = e.Y;
tChart1.Zoom.x1 = e.X;
tChart1.Zoom.y1 = e.Y;
tChart1.Zoom.Draw();
}
}
private void tChart1_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
tChart1.Zoom.Draw();
tChart1.Zoom.x1 = e.X;
tChart1.Zoom.y1 = e.Y;
listBox1.Items.Clear();
int X0 = tChart1.Zoom.x0;
int Y0 = tChart1.Zoom.y0;
if ((X0 != -1) && (Y0 != -1))
{
for (int i = 0; i < points1.Count; i++)
{
if ((points1.CalcXPos(i) >= X0) && (points1.CalcXPos(i) <= e.X) &&
(points1.CalcYPos(i) >= Y0) && (points1.CalcYPos(i) <= e.Y))
{
listBox1.Items.Add("Point " + i.ToString() + ": " + points1.XValues[i].ToString() +
", " + points1.YValues[i].ToString());
}
}
}
}
}
private void tChart1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
if ((e.X != tChart1.Zoom.x1) || (e.Y != tChart1.Zoom.y1))
{
tChart1.Zoom.Draw();
tChart1.Zoom.x1 = e.X;
tChart1.Zoom.y1 = e.Y;
tChart1.Zoom.Draw();
}
}
}
Posted: Fri Aug 29, 2008 1:10 pm
by 14045609
Narcis,
Once again you have given me exactly what I needed.
This method works perfectly for what we are trying to do.
As alway, thank you very much for your help.
Aaron