using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.Research.DynamicDataDisplay.Charts; using System.Windows; using Microsoft.Research.DynamicDataDisplay.Common; namespace Microsoft.Research.DynamicDataDisplay { public sealed class GenericChartPlotter { private readonly AxisBase horizontalAxis; public AxisBase HorizontalAxis { get { return horizontalAxis; } } private readonly AxisBase verticalAxis; public AxisBase VerticalAxis { get { return verticalAxis; } } private readonly ChartPlotter plotter; public ChartPlotter Plotter { get { return plotter; } } public Func HorizontalToDoubleConverter { get { return horizontalAxis.ConvertToDouble; } } public Func DoubleToHorizontalConverter { get { return horizontalAxis.ConvertFromDouble; } } public Func VerticalToDoubleConverter { get { return verticalAxis.ConvertToDouble; } } public Func DoubleToVerticalConverter { get { return verticalAxis.ConvertFromDouble; } } internal GenericChartPlotter(ChartPlotter plotter) : this(plotter, plotter.MainHorizontalAxis as AxisBase, plotter.MainVerticalAxis as AxisBase) { } internal GenericChartPlotter(ChartPlotter plotter, AxisBase horizontalAxis, AxisBase verticalAxis) { if (horizontalAxis == null) throw new ArgumentNullException(Strings.Exceptions.PlotterMainHorizontalAxisShouldNotBeNull); if (verticalAxis == null) throw new ArgumentNullException(Strings.Exceptions.PlotterMainVerticalAxisShouldNotBeNull); this.horizontalAxis = horizontalAxis; this.verticalAxis = verticalAxis; this.plotter = plotter; } public GenericRect ViewportRect { get { DataRect viewportRect = plotter.Viewport.Visible; return CreateGenericRect(viewportRect); } set { DataRect viewportRect = CreateRect(value); plotter.Viewport.Visible = viewportRect; } } public GenericRect DataRect { get { DataRect dataRect = plotter.Viewport.Visible.ViewportToData(plotter.Viewport.Transform); return CreateGenericRect(dataRect); } set { DataRect dataRect = CreateRect(value); plotter.Viewport.Visible = dataRect.DataToViewport(plotter.Viewport.Transform); } } private DataRect CreateRect(GenericRect value) { double xMin = HorizontalToDoubleConverter(value.XMin); double xMax = HorizontalToDoubleConverter(value.XMax); double yMin = VerticalToDoubleConverter(value.YMin); double yMax = VerticalToDoubleConverter(value.YMax); return new DataRect(new Point(xMin, yMin), new Point(xMax, yMax)); } private GenericRect CreateGenericRect(DataRect rect) { double xMin = rect.XMin; double xMax = rect.XMax; double yMin = rect.YMin; double yMax = rect.YMax; GenericRect res = new GenericRect( DoubleToHorizontalConverter(xMin), DoubleToVerticalConverter(yMin), DoubleToHorizontalConverter(xMax), DoubleToVerticalConverter(yMax)); return res; } } }