Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

OpenWPFChart: assembling charts from components: Part I - Parts

, 19 Mar 2009 CPOL
Provides the component model along with base components to assemble charts.
SourceCode.zip
trunk
ChartControls
ChartControls.csproj.user
OpenWPFChart.Chart.Icon.png
OpenWPFChart.WellLogChart.Icon.png
Properties
Themes
ChartHelpers
AxisPropertiesDialog
ChartHelpers.csproj.user
ChartScaleControl
FontChooser
ItemPropertiesDialog
Properties
ChartParts
Axes
ChartParts.csproj.user
Grid
Items
Data
DataView
Elements
Visuals
NumericalRecipes
Properties
Scales
ChartParts.vsmdi
SampleDataFiles
WellLog
Samples
ControlSamples
ColumnChartControlSample
Properties
Settings.settings
CurveChartControlSample
Properties
Settings.settings
WellLogControlSample
Properties
Settings.settings
DirectCompositionSamples
BasicSample
Properties
Settings.settings
TemperatureSample
Properties
Settings.settings
WellLogSample
Properties
Settings.settings
// <copyright file="ScatteredPointsData.cs" company="Oleg V. Polikarpotchkin">
// Copyright © 2008-2009 Oleg V. Polikarpotchkin. All Right Reserved
// </copyright>
// <author>Oleg V. Polikarpotchkin</author>
// <email>ov-p@yandex.ru</email>
// <date>2009-02-09</date>
// <summary>OpenWPFChart library. ScatteredPointsData class contains set of scattered points.</summary>
// <revision>$Id: ScatteredPointsData.cs 18093 2009-03-16 04:15:06Z unknown $</revision>

using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;

namespace OpenWPFChart.Parts
{
	/// <summary>
	/// ScatteredPointsData class contains set of scattered points.
	/// <para>The point collection should be non-strictly ordered by abscissas either 
	/// ascending or descending.</para>
	/// </summary>
	/// <typeparam name="TAbs">The type of the abscissa.</typeparam>
	/// <typeparam name="TOrd">The type of the ordinate.</typeparam>
	public class ScatteredPointsData<TAbs, TOrd> : ItemData
	{
		#region Points
		// TODO Change type of ScatteredPointsData.Points property to ObservableCollection and supply appropriate TypeConverter?
		IEnumerable<DataPoint<TAbs, TOrd>> points;
		/// <summary>
		/// Gets or sets the Points property.
		/// </summary>
		/// <value/>
		public IEnumerable<DataPoint<TAbs, TOrd>> Points
		{
			get { return points; }
			set
			{
				if (points != value)
				{
					if (points != null)
					{
						INotifyCollectionChanged iNotifyCollectionChanged
							= points as INotifyCollectionChanged;
						if (iNotifyCollectionChanged != null)
							iNotifyCollectionChanged.CollectionChanged -= CollectionChanged;
					}

					points = value;
					if (points != null)
					{
						INotifyCollectionChanged iNotifyCollectionChanged
							= points as INotifyCollectionChanged;
						if (iNotifyCollectionChanged != null)
							iNotifyCollectionChanged.CollectionChanged += CollectionChanged;
					}
					NotifyPropertyChanged("Points");
				}
			}
		}

		/// <summary>
		/// Point collection changed in some way.
		/// </summary>
		/// <param name="sender">The sender.</param>
		/// <param name="e">The <see cref="System.Collections.Specialized.NotifyCollectionChangedEventArgs"/> instance containing the event data.</param>
		private void CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
		{
			NotifyPropertyChanged("Points");
		}
		#endregion Points

		/// <inheritdoc />
		public override Type TypeOfAbscissa { get { return typeof(TAbs); } }

		/// <inheritdoc />
		public override Type TypeOfOrdinate { get { return typeof(TOrd); } }

		/// <inheritdoc />
		public override bool IsAbscissasEqual(ItemData item)
		{
			SampledCurveData<TAbs, TOrd> typed = item as SampledCurveData<TAbs, TOrd>;
			if (typed == null)
				return false;

			List<DataPoint<TAbs, TOrd>> points = Points.ToList();
			List<DataPoint<TAbs, TOrd>> otherPoints = typed.Points.ToList();
			if (points.Count != otherPoints.Count)
				return false;
			for (int i = 0; i < points.Count; ++i)
			{
				if (!(points[i].X.Equals(otherPoints[i].X)))
					return false;
			}
			return true;
		}

		/// <inheritdoc />
		public override bool IsOrdinatesEqual(ItemData item)
		{
			SampledCurveData<TAbs, TOrd> typed = item as SampledCurveData<TAbs, TOrd>;
			if (typed == null)
				return false;

			List<DataPoint<TAbs, TOrd>> points = Points.ToList();
			List<DataPoint<TAbs, TOrd>> otherPoints = typed.Points.ToList();
			if (points.Count != otherPoints.Count)
				return false;
			for (int i = 0; i < points.Count; ++i)
			{
				if (!(points[i].Y.Equals(otherPoints[i].Y)))
					return false;
			}
			return true;
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Oleg V. Polikarpotchkin
Team Leader
Russian Federation Russian Federation
No Biography provided

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150123.1 | Last Updated 19 Mar 2009
Article Copyright 2009 by Oleg V. Polikarpotchkin
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid