// Copyright (C) Stichting Deltares and State of the Netherlands 2025. All rights reserved. // // This file is part of Riskeer. // // Riskeer 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. /// Thrown when /// are already present. public void AddColumn(string name) { if (rows.Any()) { throw new InvalidOperationException("Cannot add columns when rows already present."); } if (name == null) { throw new ArgumentNullException(nameof(name)); } columns.Add(name); } /// /// 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 there are no /// added yet. /// Thrown when the amount of /// is not equal to the amount of . public void AddRow(string name, double[] values, Color? color = null) { if (values == null) { throw new ArgumentNullException(nameof(values)); } if (!Columns.Any()) { throw new InvalidOperationException("Cannot add rows before columns are added."); } if (values.Length != columns.Count) { throw new ArgumentException(@"The number of value items must be the same as the number of columns.", nameof(values)); } rows.Add(new RowChartData(name, values, color)); } /// /// Clears the rows and columns of the . /// public void Clear() { columns.Clear(); rows.Clear(); } } }