// Copyright (C) Stichting Deltares 2017. 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 Core.Components.Charting.Data;
using OxyPlot.Series;
namespace Core.Components.OxyPlot.Converter
{
///
/// Abstract base class for transforming data into data.
///
/// The type of item based chart data to convert.
/// The type of series to set the converted data to.
public abstract class ChartDataConverter
where TChartData : ChartData
where TSeries : Series
{
///
/// Converts all item related data from to .
///
/// The data to convert the item related data from.
/// The series to convert the item related data to.
/// Thrown when or is null.
public void ConvertSeriesItems(TChartData data, TSeries series)
{
ValidateParameters(data, series);
SetSeriesItems(data, series);
}
///
/// Converts all general properties (like and )
/// from to .
///
/// The data to convert the general properties from.
/// The series to convert the general properties to.
/// Thrown when or is null.
public void ConvertSeriesProperties(TChartData data, TSeries series)
{
ValidateParameters(data, series);
series.Title = data.Name;
series.IsVisible = data.IsVisible;
SetSeriesStyle(data, series);
}
///
/// Sets items to based on .
///
/// The data to create the items from.
/// The series to set the items to.
protected abstract void SetSeriesItems(TChartData data, TSeries series);
///
/// Set a style to based on .
///
/// The data to create the style from.
/// The series to set the style to.
protected abstract void SetSeriesStyle(TChartData data, TSeries series);
private static void ValidateParameters(TChartData data, TSeries series)
{
if (data == null)
{
throw new ArgumentNullException(nameof(data), @"Null data cannot be converted into series data.");
}
if (series == null)
{
throw new ArgumentNullException(nameof(series), @"Null data cannot be used as conversion target.");
}
}
}
}