// 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 System.Collections.Generic;
using System.Drawing;
using System.Linq;
using Core.Common.Base;
namespace Core.Components.Stack.Data
{
///
/// Class for data with the purpose of becoming visible in stack charting components.
///
public class StackChartData : Observable
{
private readonly List columns;
private readonly List rows;
///
/// Creates a new instance of .
///
public StackChartData()
{
columns = new List();
rows = new List();
}
///
/// Gets the columns of the .
///
public IEnumerable Columns
{
get
{
return columns;
}
}
///
/// Gets the rows of the .
///
public IEnumerable Rows
{
get
{
return rows;
}
}
///
/// Adds a column to the .
///
/// The name of the column.
/// Thrown when
/// is null.
public void AddColumn(string name)
{
if (name == null)
{
throw new ArgumentNullException(nameof(name));
}
columns.Add(name);
}
///
/// Adds a columns to with
/// values to add to the rows that are already present.
///
/// The name of the column.
/// The values to add to the rows for this column.
/// Thrown when no
/// are present.
/// Thrown when
/// is null.
/// Thrown when the amount of
/// is not equal to the amount of .
public void AddColumnWithValues(string name, List values)
{
if (!Rows.Any())
{
throw new InvalidOperationException("Rows should be added before this method is called.");
}
if (values == null)
{
throw new ArgumentNullException(nameof(values));
}
if (values.Count != rows.Count)
{
throw new ArgumentException("The number of value items must be the same as the number of rows.");
}
AddColumn(name);
for (var i = 0; i < values.Count; i++)
{
rows[i].Values.Add(values[i]);
}
}
///
/// Adds a row to the .
///
/// The name of the row.
/// The values of the row.
/// The color of the row.
/// Thrown when
/// or is null.
/// Thrown when the amount of
/// is not equal to the amount of .
public void AddRow(string name, List values, Color? color = null)
{
if (values == null)
{
throw new ArgumentNullException(nameof(values));
}
if (values.Count != columns.Count)
{
throw new ArgumentException("The number of value items must be the same as the number of columns.");
}
rows.Add(new RowChartData(name, values, color));
}
///
/// Clears the rows and columns of the .
///
public void Clear()
{
columns.Clear();
rows.Clear();
}
}
}