Percentage Zoom

Apr 2, 2010 at 12:40 AM

Hi,

I need to add a slider (like in MS Office) to zoom in / out the viewport, i wanna bind (in two way) the value of my slider to a zoom percentage of chart, how i can do this?

Thanks.

Tiago

Apr 2, 2010 at 4:56 PM

Below is how I sent my Visible bounds based on what I want to show.  So for you, do your zoom calculation to get your Region or Interest, and go from there.

 

        private void setVisibleBounds(double minX, double minY, double width, double height, bool addRestriction) {
            if ((width > 0) && (height > 0)) {
                DataRect v = plotter.Visible;
                v.XMin = minX;
                v.Width = width;
                v.YMin = minY;
                v.Height = height;

                plotter.Visible = v;

                if (addRestriction) {
                    BoundViewport bvp = new BoundViewport();
                    bvp.MinXValue = minX;
                    bvp.MaxXValue = minX + width;
                    bvp.MinYValue = minY;
                    bvp.MaxYValue = minY + height;

                    plotter.Viewport.Restrictions.Add(bvp);
                }
            }
        }

 

 

E.

Editor
Apr 3, 2010 at 2:06 AM

Hi Tiago!

 

I've uploaded a sample showing the feature you want: http://cid-eaf0a921258b5980.skydrive.live.com/self.aspx/.Public/D3/ZoomSliderSample.zip

Best regards,

Mikhail.

Sep 10, 2010 at 12:47 PM
Edited Sep 10, 2010 at 1:14 PM

Hi !

I wish to read somewhere the zoom value currently used by the plotter. Does anyone knows which property to read? Thanks!

The compressed folder  ZoomSliderSample.zip give me "Error in compressed file" when I try to open it...

Sep 10, 2010 at 1:35 PM

Here is the source code from the Zoom slider example (I can't remember if I changed anything but it is working and will show you what you need to know)

As you can see it is just a matter of setting the ChartPlotter's Visible property to an appropriate DataRect

ZoomSlider.xaml

<Window x:Class="ZoomSliderSample.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d3="http://research.microsoft.com/DynamicDataDisplay/1.0"
    Title="Zoom Slider Sample">
    <Grid>
        <d3:ChartPlotter Name="plotter">
        </d3:ChartPlotter>
    </Grid>
</Window>
ZoomSlider.xaml.cs
using System.Windows;
using System.Windows.Controls;
using Microsoft.Research.DynamicDataDisplay;

namespace ZoomSliderSample
{
	/// <summary>
	/// Interaction logic for Window1.xaml
	/// </summary>
	public partial class Window1 : Window
	{
		private Slider zoomSlider = new Slider
		{
			Margin = new Thickness(20),
			Orientation = Orientation.Vertical,
			Height = 200,
			Minimum = 1,
			Maximum = 3
		};

		public Window1()
		{
			InitializeComponent();

			zoomSlider.ValueChanged += zoomSlider_ValueChanged;
			plotter.MainCanvas.Children.Add(zoomSlider);
		}

		void zoomSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
		{
			DataRect visible = new DataRect(0, 0, 1, 1).ZoomInToCenter(e.NewValue);
			plotter.Visible = visible;
		}
	}
}

Feb 3, 2011 at 8:05 PM

I can not find ZoomInToCenter() function. Is there an alternative way?



        
    
Feb 4, 2011 at 9:34 PM
ZoomInToCenter() is in the source, in DataRectExtensions.cs.