Making Viewport2D.Domain a DP

Jan 27, 2010 at 11:45 PM

I have been struggling to set the domain on my plotter.  I load many different datasets, and they have different values so I cannot use a fixed Domain.

Ideally, since with FitToView the Visible rect size is already calculated it would be wonderful to have a 'LockAtMax' property- which basically sets the Domain to the fitted to view rect.  This would prevent scrolling out and panning out to where there is no data.

But short of this, if I have to calculate my own Domain rect based on my data, can Domain be made a dependency property so I can bind it?  As it stands, it is only useful if you hardcode the values in.

Or, if there is another way to lock the scrolling and zoom out please let me know!

Thanks!

Feb 4, 2010 at 6:57 PM

Hi,

you can inherit MouseNavigation class and override ShouldStartPanning and ShouldStartZoom to check your conditions. You must remove default MouseNavigation and Add your implementation of this class.

 

Jefferson Soares

 

Jun 16, 2010 at 7:02 PM

I would like to make Viewport2D.Domain a dependency property so I can bind my DataRect to it in Xaml with something like this:

<d3:ChartPlotter x:Name="chartPlotterCandela" Margin="5,15,5,5" MinWidth="600" MinHeight="600" Domain="{Binding MyViewportDomain, UpdateSourceTrigger=PropertyChanged}">

 

How can I make this happen?

Editor
Jun 20, 2010 at 2:18 PM

Domain property of ChartPlotter.Viewport is now a dependency property.

 

Code is uploaded here: http://cid-eaf0a921258b5980.office.live.com/self.aspx/.Public/D3/DynamicDataDisplay%20for%20Brian%20Bauer.zip

Mikhail.

Jun 23, 2010 at 4:37 PM

This works great, however you can only set the binding in the code behind. I have yet to find a way to set the binding in xaml. How can you access the Domain in xaml? Here is my xaml snippet. I would like to say this somewhere: Domain="{Binding MyCustomDomain}", however I cannot figure out where to do so.

<!-- CandelaColorChart -->
<d3:ChartPlotter x:Name="chartPlotterCandela" Margin="5,15,5,5" MinWidth="600" MaxWidth="750" MinHeight="600">
    <d3:Header TextBlock.FontSize="18" Content="{Binding ChartHeader}" VerticalAlignment="Top" Margin="5"  FontFamily="Arial" FontSize="16"/>
    <d3:HorizontalAxisTitle x:Name="horizontalAxisTitleCandela" Content="Horizontal Angle" FontSize="11" Margin="5"/>
    <d3:VerticalAxisTitle x:Name="verticalAxisTitleCandela" Content="Vertical Angle" FontSize="11" Margin="5"/>
    <d3:ViewportHostPanel>
        <Image x:Name="imageCandela" Stretch="Fill" Source="{Binding CandelaBitmapSource}"/>
    </d3:ViewportHostPanel>
    <d3:DraggablePoint x:Name="draggablePointCandela" Position="0.5,0.5" PositionChanged="draggablePointCandela_PositionChanged"/>
    <d3:VerticalLine x:Name="verticalLineCandela" Value="{Binding DraggablePointX}" Stroke="Red"/>
    <d3:HorizontalLine x:Name="horizontalLineCandela" Value="{Binding DraggablePointY}" Stroke="Red"/>
    <d3:CursorCoordinateGraph />
    <d3:AxisCursorGraph/>
</d3:ChartPlotter>
<!-- END CandelaColorChart -->

 

Jul 6, 2010 at 7:07 AM

Add a new DependencyProperty of "Domain" to Plotter2D to facilitate the binding:

/// Gets or sets the domain - rectangle in viewport coordinates that limits maximal size of  rectangle.
/// The domain.
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public DataRect Domain
{
    get { return (DataRect)GetValue(DomainProperty); }
    set { SetValue(DomainProperty, value); }
}

/// The Domain dependency property
public static readonly DependencyProperty DomainProperty = DependencyProperty.Register(
  "Domain",
  typeof(DataRect),
  typeof(Plotter2D),
  new FrameworkPropertyMetadata(DataRect.Empty, OnDomainReplaced));

private static void OnDomainReplaced(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
    Plotter2D owner = (Plotter2D)d;
    if (owner != null)
        owner.OnDomainChanged((DataRect)e.NewValue);
}

private void OnDomainChanged(DataRect rect)
{
    viewport.Domain = rect;                        
}