/*
Copyright (C) 2008 Webyog Softworks Private Limited
This file is a part of Visifire Charts.
Visifire is a free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
You should have received a copy of the GNU General Public License
along with Visifire Charts. If not, see .
If GPL is not suitable for your products or company, Webyog provides Visifire
under a flexible commercial license designed to meet your specific usage and
distribution requirements. If you have already obtained a commercial license
from Webyog, you can use this file under those license terms.
*/
#if WPF
using System;
using System.Linq;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
#else
using System;
using System.Linq;
using System.Collections.Specialized;
using System.Collections.ObjectModel;
#endif
namespace Visifire.Charts
{
///
/// X wise groupping of InternalDataPoints
/// (InternalDataPoints are grouped into positive and negative collection)
///
internal class XWiseStackedData
{
#region Public Methods
///
/// Initializes a new instance of the Visifire.Charts.XWiseStackedData class
///
public XWiseStackedData()
{
Positive = new ObservableCollection();
Negative = new ObservableCollection();
Positive.CollectionChanged += new NotifyCollectionChangedEventHandler(Positive_CollectionChanged);
Negative.CollectionChanged += new NotifyCollectionChangedEventHandler(Negative_CollectionChanged);
_isUpdated = false;
}
#endregion
#region Public Properties
///
/// Collection of InternalDataPoints with positive YValues
///
public ObservableCollection Positive
{
get;
set;
}
///
/// Collection of InternalDataPoints with negative YValues
///
public ObservableCollection Negative
{
get;
set;
}
///
/// Positive sum of YValues
///
public Double PositiveYValueSum
{
get
{
if (!_isUpdated) Update();
return _positiveYValueSum;
}
}
///
/// Negative sum of YValues
///
public Double NegativeYValueSum
{
get
{
if (!_isUpdated) Update();
return _negativeYValueSum;
}
}
///
/// Absolute sum of YValues
///
public Double AbsoluteYValueSum
{
get
{
return Math.Abs(NegativeYValueSum) + Math.Abs(PositiveYValueSum);
}
}
#endregion
#region Public Events And Delegates
#endregion
#region Protected Methods
#endregion
#region Internal Properties
#endregion
#region Private Properties
#endregion
#region Private Delegates
#endregion
#region Private Methods
///
/// Event handler manages the addition and removal of InternalDataPoints from positive collection of InternalDataPoints
///
private void Positive_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
_isUpdated = false;
}
///
/// Event handler manages the addition and removal of InternalDataPoints from negative collection of InternalDataPoints
///
private void Negative_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
_isUpdated = false;
}
///
/// Update sum of YValues
///
private void Update()
{
_isUpdated = true;
_positiveYValueSum = (from dataPoint in Positive where !Double.IsNaN(dataPoint.InternalYValue) select dataPoint.InternalYValue).Sum();
_negativeYValueSum = (from dataPoint in Negative where !Double.IsNaN(dataPoint.InternalYValue) select dataPoint.InternalYValue).Sum();
}
#endregion
#region Internal Methods
#endregion
#region Internal Events And Delegates
#endregion
#region Data
///
/// Positive sum of YValues
///
private Double _positiveYValueSum;
///
/// Negative sum of YValues
///
private Double _negativeYValueSum;
///
/// Whether the x wise data is updated
///
private Boolean _isUpdated;
#endregion
}
}