// 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.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Windows.Forms; using Core.Common.Base; using Core.Components.Charting.Data; using Core.Components.Charting.Forms; using Core.Components.OxyPlot.Converter; using OxyPlot.WindowsForms; namespace Core.Components.OxyPlot.Forms { /// /// This class describes a plot view with configured representation of axes. /// public sealed class ChartControl : Control, IObserver, IChartControl { private readonly ChartSeriesFactory seriesFactory = new ChartSeriesFactory(); private LinearPlotView view; private DynamicPlotController controller; /// /// Creates a new instance of . /// public ChartControl() { InitializePlotView(); MinimumSize = new Size(50, 75); Data = new ChartDataCollection(new List(), "Root"); Data.Attach(this); DrawSeries(); } /// /// Initialize the for the . /// private void InitializePlotView() { view = new LinearPlotView(); controller = new DynamicPlotController(); view.Controller = controller; Controls.Add(view); } /// /// Draws series based on the currently set . /// private void DrawSeries() { view.Model.Series.Clear(); if (Data != null) { foreach (var series in seriesFactory.Create(Data)) { view.Model.Series.Add(series); } } view.InvalidatePlot(true); } #region IChart public bool IsPanningEnabled { get { return controller.IsPanningEnabled; } } public bool IsRectangleZoomingEnabled { get { return controller.IsRectangleZoomingEnabled; } } [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] public ChartDataCollection Data { get; private set; } public string ChartTitle { get { return view.ModelTitle; } set { view.ModelTitle = value; } } public string BottomAxisTitle { get { return view.BottomAxisTitle; } set { view.BottomAxisTitle = value; } } public string LeftAxisTitle { get { return view.LeftAxisTitle; } set { view.LeftAxisTitle = value; } } public void TogglePanning() { controller.TogglePanning(); } public void ToggleRectangleZooming() { controller.ToggleRectangleZooming(); } public void ZoomToAll() { view.ZoomToAll(); } public void UpdateObserver() { DrawSeries(); } #endregion } }