Page 1 of 1

Disabling/restricting scrolling and zooming

Posted: Wed Jul 16, 2008 7:08 pm
by 9336349
Hi

I have a set of points plotted on a 2-D Chart with a horizontal and a vertical axis.

is it possible to disable the Right mouse drag scrolling?

Is it possible to disable the left mouse 'region' zoom?

Is it possible to disable one of the above without the other.

Also is it possible to restrict scrolling and/or zooming to be within specified bounds e.g. for horizontal scrolling I do not want to be able to scroll before the first point or after the last point. For vertical scrolling I do not want to scrol past the highest value point, but I would like to be able to scroll down no further than the lowest value point or the origin (whichever is the smaller), but no lower. Similar for when I zoom, by whatever method of zooming that is employed.

I tried code such as axis.minimum := max (axis.minimum,first point x coordinate) but although this disallowed scrolling before the first point, if I dragged with the right mouse button, the chart was stretched instead, rather than scrolled, which was not what I wanted. I wanted to be unable to scroll anymore.

I would like to be able to disable and/or restrict scrolling and or zooming independently of each other, for all methods of scrolling whether by dragging with the mouse or by using ordinary scrollbars or chartscrollbars or axisarrowtools or using delphi code or for whatever method it is possible to use to scroll. Similarly for zooming.

I would also like there to be some visual indication when the scrolling or zooming is disabled.

Sorry for all the questions in one go, but they are related.

Thanks

Colin

Posted: Thu Jul 17, 2008 7:38 am
by narcis
Hi Colin,
is it possible to disable the Right mouse drag scrolling?
Yes, you can do this:

Code: Select all

  Chart1.AllowPanning:=pmNone;
Is it possible to disable the left mouse 'region' zoom?
Yes, similar to scroll:

Code: Select all

  Chart1.AllowZoom:=false;
Is it possible to disable one of the above without the other.
Yes, both settings are independent.
Also is it possible to restrict scrolling and/or zooming to be within specified bounds e.g. for horizontal scrolling I do not want to be able to scroll before the first point or after the last point. For vertical scrolling I do not want to scrol past the highest value point, but I would like to be able to scroll down no further than the lowest value point or the origin (whichever is the smaller), but no lower. Similar for when I zoom, by whatever method of zooming that is employed.
Yes, you could try using OnMouseMove event and something like this:

Code: Select all

procedure TForm1.Chart1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
var XVal, YVal: Double;
begin
  XVal:=Chart1.Axes.Bottom.CalcPosPoint(X);
  YVal:=Chart1.Axes.Left.CalcPosPoint(Y);

  if ((XVal > Series1.MaxXValue) or (XVal < Series1.MinXValue)
      or (YVal > Series1.MaxYValue) or (YVal < Series1.MinYValue)) then
    Chart1.AllowPanning:=pmNone
  else
    Chart1.AllowPanning:=pmBoth;
end;
Axes and series have several methods from converting screen coordinates to axes coordinates and series points to screen coordinates.
I would also like there to be some visual indication when the scrolling or zooming is disabled.
You can use any chart element and modify it according to if those features are active or not.

Restricting scrolling/zooming

Posted: Sat Jul 19, 2008 3:10 pm
by 9336349
Many thanks for your helpful answers.

However I probably did not explain things clearly enough when I talked about restricting scrolling and/or zooming to a region.

For example if a vertical axis originally goes from 0 to 100 in values, then if a 10% zoom is made, the axis values normally then go from -10 to 110. However, I would like the vertical axis to never be less than zero, so the axis labels should be 0 and 110. However if I zoomed the other way, then it would be OK for the vertical axis to range from 10 to 90, if they originally ranged from 0 to 100.


Similarly, when scrolling, horizontally. Suppose originally the range of x coordinate values goes from 50 to 275 and the horizontal axis has a range of 100, so not all the points are shown at once. Then when I scroll horizontally, I want to scroll to the left up to the value 50 but not before 50 or to scroll up to the value 275 but not after 275. I do not want to completely disable being able to scroll when I reach these limits e.g. if I scroll left to 50, I then want to be able to scroll right all the way up to 275. When I reach 275 I then want to be able to scroll left all the way back to 50 and so on. I just want to be able to scroll horizontally between the limits of 50 and 275.

Similarly if I zoomed, rather than scrolled, I would never want to see axis labels less than 50 nor axis labels greater than 275, but I still want to be able to zoom out and zoom in, within these limits.

Regards

Colin

Posted: Mon Jul 21, 2008 8:21 am
by narcis
Hi Colin,

In that case, I'd try using OnZoom and OnScroll events for checking if axes minimum and maximum values are within series range (eg.: Series1.MinXValue and Series1.MaxXValue) and if not manually set the minimum and/or maximum to desired value.

Hope this helps!

Posted: Tue Jul 22, 2008 5:47 pm
by 9336349
Hi

As I mentioned in my first email, that is precisely what I did.

However, if say I fix the left hand horizontal minimum to be the value zero, then it is OK if I then drag the mouse leftwards, because the minimum visible chart value is then greater than zero.

However, if I drag the mouse rightwards instead, then the chart streches/zooms horizontally which is not what I want. What I want in this case is for nothing to happen.

Regards

Colin

Posted: Wed Jul 23, 2008 7:47 am
by narcis
Hi Colin,

In that case you can do something like this:

Code: Select all

procedure TForm1.Chart1Scroll(Sender: TObject);
var BottomRange, LeftRange: double;
begin
  BottomRange:=Chart1.Axes.Bottom.Maximum - Chart1.Axes.Bottom.Minimum;
  LeftRange:=Chart1.Axes.Left.Maximum - Chart1.Axes.Left.Minimum;

  if Chart1.Axes.Bottom.Minimum < Series1.MinXValue then
    Chart1.Axes.Bottom.SetMinMax(Series1.MinXValue, Series1.MinXValue + BottomRange);

  if Chart1.Axes.Bottom.Maximum > Series1.MaxXValue then
    Chart1.Axes.Bottom.SetMinMax(Series1.MaxXValue - BottomRange, Series1.MaxXValue);

  if Chart1.Axes.Left.Minimum < Series1.MinYValue then
    Chart1.Axes.Left.SetMinMax(Series1.MinYValue, Series1.MinYValue + LeftRange);

  if Chart1.Axes.Left.Maximum > Series1.MaxYValue then
    Chart1.Axes.Left.SetMinMax(Series1.MaxYValue - LeftRange, Series1.MaxYValue);
end;

Posted: Thu Jul 24, 2008 5:33 pm
by 9336349
Hi

Many thanks for that code. It worked great for scrolling.

However, I tried to use the same code, to similarly restrict zooming. However that did not work at all.

There is a difference, because zooming is usually symmetric, but when a bounding point is reached, then the zoom has to be asymmetrical.

Is there some, way to confine the zooming to be within the data point boundaries?

Thanks

Colin

Posted: Mon Jul 28, 2008 9:36 am
by narcis
Hi Colin,

For zooming you can do this:

Code: Select all

procedure TForm1.Chart1Zoom(Sender: TObject);
var BottomRange, LeftRange: double;
begin
  BottomRange:=Chart1.Axes.Bottom.Maximum - Chart1.Axes.Bottom.Minimum;
  LeftRange:=Chart1.Axes.Left.Maximum - Chart1.Axes.Left.Minimum;

  if Chart1.Axes.Bottom.Minimum < Series1.MinXValue then
    Chart1.Axes.Bottom.SetMinMax(Series1.MinXValue, Chart1.Axes.Bottom.Maximum);

  if Chart1.Axes.Bottom.Maximum > Series1.MaxXValue then
    Chart1.Axes.Bottom.SetMinMax(Chart1.Axes.Bottom.Minimum, Series1.MaxXValue);

  if Chart1.Axes.Left.Minimum < Series1.MinYValue then
    Chart1.Axes.Left.SetMinMax(Series1.MinYValue, Chart1.Axes.Left.Maximum);

  if Chart1.Axes.Left.Maximum > Series1.MaxYValue then
    Chart1.Axes.Left.SetMinMax(Chart1.Axes.Left.Minimum, Series1.MaxYValue);
end;