using System; using HeuristicLab.Core; namespace HeuristicLab.Visualization { public partial class LineChart : ViewBase { private readonly IChartDataRowsModel model; /// /// This constructor shouldn't be called. Only required for the designer. /// public LineChart() { InitializeComponent(); } /// /// Initializes the chart. /// /// public LineChart(IChartDataRowsModel model) : this() { if (model == null) { throw new NullReferenceException("Model cannot be null."); } this.model = model; Reset(); } /// /// Resets the line chart by deleting all shapes and reloading all data from the model. /// private void Reset() { BeginUpdate(); // TODO clear existing shapes // reload data from the model and create shapes foreach (ChartDataRowsModelColumn column in model.Columns) { AddColumn(column.ColumnId, column.Values); } EndUpdate(); } /// /// Event handler which gets called when data in the model changes. /// /// Type of change /// Id of the changed column /// Values contained within the changed column private void OnDataChanged(ChangeType type, long columnId, double[] values) { switch (type) { case ChangeType.Add: AddColumn(columnId, values); break; case ChangeType.Modify: ModifyColumn(columnId, values); break; case ChangeType.Remove: RemoveColumn(columnId); break; default: throw new ArgumentOutOfRangeException("type"); } } /// /// Adds a new column to the chart. /// /// Id of the column /// Values of the column private void AddColumn(long columnId, double[] values) { throw new NotImplementedException(); } /// /// Modifies an existing column of the chart. /// /// Id of the column /// Values of the column private void ModifyColumn(long columnId, double[] values) { throw new NotImplementedException(); } /// /// Removes a column from the chart. /// /// Id of the column private void RemoveColumn(long columnId) { throw new NotImplementedException(); } #region Add-/RemoveItemEvents protected override void AddItemEvents() { base.AddItemEvents(); model.ColumnChanged += OnDataChanged; } protected override void RemoveItemEvents() { base.RemoveItemEvents(); model.ColumnChanged -= OnDataChanged; } #endregion #region Begin-/EndUpdate private int beginUpdateCount = 0; public void BeginUpdate() { beginUpdateCount++; } public void EndUpdate() { if (beginUpdateCount == 0) { throw new InvalidOperationException("Too many EndUpdates."); } beginUpdateCount--; if (beginUpdateCount == 0) { Invalidate(); } } #endregion } }