// Copyright (C) Stichting Deltares 2016. All rights reserved. // // This file is part of Ringtoets. // // Ringtoets is free software: you can redistribute it and/or modify // it under the terms of the GNU Lesser General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public License // along with this program. If not, see . // // All names, logos, and references to "Deltares" are registered trademarks of // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. using System; using System.Linq; using System.Windows.Forms; using Core.Components.OxyPlot.Forms.Properties; using OxyPlot; using OxyPlot.Axes; using OxyPlot.WindowsForms; using TickStyle = OxyPlot.Axes.TickStyle; namespace Core.Components.OxyPlot.Forms { /// /// This class describes a plot view with two linear axes. /// internal sealed class LinearPlotView : PlotView { /// /// Creates a new instance of . /// public LinearPlotView() { Dock = DockStyle.Fill; Model = new PlotModel { Axes = { CreateAxis(Resources.ChartControl_XAxisTitle, AxisPosition.Bottom), CreateAxis(Resources.ChartControl_YAxisTitle, AxisPosition.Left) } }; Invalidated += OnInvalidated; } /// /// Sets the title of the plot view. /// public string ModelTitle { get { return Model.Title; } set { Model.Title = value; InvalidatePlot(false); } } /// /// Sets the title of the bottom axis in the view. /// public string BottomAxisTitle { get { Axis axis = GetAxisOnPosition(AxisPosition.Bottom); return axis?.Title; } set { SetAxisTitle(AxisPosition.Bottom, value); } } /// /// Sets the title of the left axis in the view. /// public string LeftAxisTitle { get { Axis axis = GetAxisOnPosition(AxisPosition.Left); return axis?.Title; } set { SetAxisTitle(AxisPosition.Left, value); } } /// /// Zooms to a level so that everything is in view. /// public void ZoomToAll() { ActualModel.ResetAllAxes(); InvalidatePlot(false); } private void SetAxisTitle(AxisPosition axisPosition, string value) { Axis axis = GetAxisOnPosition(axisPosition); if (axis != null) { axis.Title = value; InvalidatePlot(false); } } private void OnInvalidated(object sender, EventArgs e) { FixateZoom(); } /// /// Performs a 'fake' zoom, so that the view is not updated when series are hidden or shown. /// private void FixateZoom() { ActualModel.ZoomAllAxes(1.0); } /// /// Creates an axis with default style set. /// /// The title of the . /// The of the . /// A new with given and . private static LinearAxis CreateAxis(string title, AxisPosition position) { return new LinearAxis { Title = title, Position = position, TickStyle = TickStyle.None, Layer = AxisLayer.AboveSeries, MajorGridlineStyle = LineStyle.Solid, MinorGridlineStyle = LineStyle.Dot, MinimumRange = 0.1 }; } private Axis GetAxisOnPosition(AxisPosition position) { return Model.Axes.First(a => a.Position == position); } } }