[Quantproject-developers] QuantProject/b5_Presentation/Charting Chart.cs,NONE,1.1
Brought to you by:
glauco_1
|
From: <gla...@pr...> - 2004-01-26 10:22:24
|
Update of /cvsroot/quantproject/QuantProject/b5_Presentation/Charting In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18649 Added Files: Chart.cs Log Message: Base class for QuantProject charting capabilities. Single interface point to the scpl library: all the scpl dependent code must be written within this class. --- NEW FILE: Chart.cs --- /* QuantProject - Quantitative Finance Library Chart.cs Copyright (C) 2003 Glauco Siliprandi This program is 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 2 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using System.Collections; using System.Drawing; using scpl; using QuantProject.ADT.Histories; namespace QuantProject.Presentation.Charting { /// <summary> /// Base class for QuantProject charting capabilities. Single interface point to /// the scpl library. All scpl dependent code must be written within this class. /// </summary> public class Chart : scpl.Windows.PlotSurface2D { private ArrayList chartPlots; public Chart() { this.chartPlots = new ArrayList(); // this.Paint += new System.Windows.Forms.PaintEventHandler(this.Chart_Paint); } public new void Clear() { this.chartPlots.Clear(); base.Clear(); } /// <summary> /// Adds a new ChartPlot to the Chart, using default values for the Color, /// the StartDateTime and the EndDateTime /// </summary> /// <param name="history">History for the new ChartPlot</param> public void Add( History history ) { ChartPlot chartPlot = new ChartPlot( history ); this.chartPlots.Add( chartPlot ); } /// <summary> /// Adds a new ChartPlot to the Chart, using the given arguments for the Color, /// the StartDate and the EndDate /// </summary> /// <param name="history">History for the new Chart Plot</param> /// <param name="color">Color for the new Chart Plot</param> /// <param name="startDateTime">StartDateTime for the new Chart Plot</param> /// <param name="endDateTime">EndDateTime for the new Chart Plot</param> public void Add( History history , Color color , DateTime startDateTime , DateTime endDateTime ) { ChartPlot chartPlot = new ChartPlot( history , color , startDateTime , endDateTime ); this.chartPlots.Add( chartPlot ); } #region "OnPaint" private void onPaint_addLinePlot( ChartPlot chartPlot ) { int npt=chartPlot.History.Count; int startIndex = chartPlot.History.IndexOfKeyOrPrevious( chartPlot.StartDateTime ); int endIndex = chartPlot.History.IndexOfKeyOrPrevious( chartPlot.EndDateTime ); int plotLength = endIndex - startIndex + 1; float [] x = new float[ plotLength ]; float [] y = new float[ plotLength ]; float step=1.0F; for ( int i=startIndex ; i<=endIndex ; i++ ) { x[i-startIndex]=i*step; y[i-startIndex]=(float)chartPlot.History.GetByIndex( i ); } LinePlot lp=new LinePlot( new ArrayAdapter(x,y) ); Pen p=new Pen( chartPlot.Color ); lp.Pen=p; // base.Clear(); this.Add(lp); } protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) { Console.WriteLine( "Chart.OnPaint()" ); foreach ( ChartPlot chartPlot in this.chartPlots ) onPaint_addLinePlot( chartPlot ); base.OnPaint( e ); } #endregion } } |