Example #1
0
        /// <summary>
        /// Determine the value for any minor tic.
        /// </summary>
        /// <remarks>
        /// This method properly accounts for <see cref="Scale.IsLog"/>, <see cref="Scale.IsText"/>,
        /// and other axis format settings.
        /// </remarks>
        /// <param name="baseVal">
        /// The value of the first major tic (floating point double).  This tic value is the base
        /// reference for all tics (including minor ones).
        /// </param>
        /// <param name="iTic">
        /// The major tic number (0 = first major tic).  For log scales, this is the actual power of 10.
        /// </param>
        /// <returns>
        /// The specified minor tic value (floating point double).
        /// </returns>
        internal override double CalcMinorTicValue( double baseVal, int iTic )
        {
            XDate xDate = new XDate( baseVal );

            switch ( _minorUnit )
            {
                case DateUnit.Year:
                default:
                    xDate.AddYears( (double) iTic * _minorStep );
                    break;
                case DateUnit.Month:
                    xDate.AddMonths( (double) iTic * _minorStep );
                    break;
                case DateUnit.Day:
                    xDate.AddDays( (double) iTic * _minorStep );
                    break;
                case DateUnit.Hour:
                    xDate.AddHours( (double) iTic * _minorStep );
                    break;
                case DateUnit.Minute:
                    xDate.AddMinutes( (double) iTic * _minorStep );
                    break;
                case DateUnit.Second:
                    xDate.AddSeconds( (double) iTic * _minorStep );
                    break;
            }

            return xDate.XLDate;
        }
Example #2
0
 /// <summary>
 /// The Copy Constructor
 /// </summary>
 /// <param name="rhs">The GraphPane object from which to copy</param>
 public XDate( XDate rhs )
 {
     _xlDate = rhs._xlDate;
 }
Example #3
0
        /// <summary>
        /// Provides binding between <see cref="DataSource"/> and the specified pane.  Extracts the
        /// data from <see cref="DataSource"/> and copies it into the appropriate
        /// <see cref="IPointList"/> for each <see cref="CurveItem"/> in the
        /// specified <see cref="GraphPane"/>.
        /// </summary>
        /// <param name="g">The <see cref="Graphics"/> object to be used for rendering the data.</param>
        /// <param name="pane">The <see cref="GraphPane"/> object which will receive the data.</param>
        protected void PopulateByDataSource( Graphics g, GraphPane pane )
        {
            if ( this.CurveList.Count == 0 )
                return;

            //If the Datasource column names are available we can bind them
            // correctly to their corresponding DataMember.
            if ( this.DataMember != null && this.DataMember != String.Empty
                && this.DataSource != null
                && this.DataSource is ITypedList
                && this.DataSource is IListSource
                )
            {
                ITypedList tlist = this.DataSource as ITypedList;
                IListSource listSource = this.DataSource as IListSource;
                IList list = listSource.GetList();
                PropertyDescriptorCollection pdc = tlist.GetItemProperties( null );
                bool bListContainsList = listSource.ContainsListCollection;

                //Get the DataMember and Type of the base axis in the DataSource
                string baseDataMember = this.DataMember;
                PropertyDescriptor basePd = pdc.Find( baseDataMember, true );
                if ( basePd == null )
                    throw new System.Exception( "Can't find DataMember '" + baseDataMember + "' in DataSource for the base axis." );
                baseDataMember = basePd.Name;
                Type baseDataType = basePd.PropertyType;
                int indexBaseColumn = pdc.IndexOf( basePd );

                //Foreach bar/curve
                //  Get its DataMember and Type in the DataSource
                //	Add the curve to the pane
                //  Add all corresponding points(baseAxis,valueAxis,0)
                //Note: Z axis is not supported
                foreach ( ZeeGraphWebCurveItem curveItem in this.CurveList )
                {
                    //Axis valueAxis = curveItem.ValueAxis;
                    PropertyDescriptorCollection pdcValue = pdc;
                    IList valueList = list;
                    bool bValueListContainsList = bListContainsList;

                    //If present, use DataSource of Curve instead of main DataSource
                    if ( curveItem.DataSource != null
                        && curveItem.DataSource is ITypedList
                        && curveItem.DataSource is IListSource )
                    {
                        ITypedList valueTlist = curveItem.DataSource as ITypedList;
                        pdcValue = valueTlist.GetItemProperties( null );
                        IListSource valueListSource = curveItem.DataSource as IListSource;
                        valueList = valueListSource.GetList();
                        bValueListContainsList = valueListSource.ContainsListCollection;
                    }

                    string valueDataMember = curveItem.DataMember;
                    PropertyDescriptor pd = pdcValue.Find( valueDataMember, true );
                    if ( pd == null )
                        throw new System.Exception( "Can't find DataMember '" + valueDataMember + "' in DataSource for the " + curveItem.Label + " axis." );
                    valueDataMember = pd.Name; //Get the exact case-dependent name
                    Type valueDataType = pd.PropertyType;
                    int indexValueColumn = pdcValue.IndexOf( pd );

                    //Add points
                    PointPairList points = new PointPairList();
                    PointPair pair = new PointPair();
                    object oColumnValue;

                    try
                    {
                        int nRow = 0;
                        foreach ( object row in list )
                        {
                            //
                            // Value axis binding (Y axis)
                            //
                            object valueRow = valueList[nRow];

                            //Get item value in 'row'
                            if ( bValueListContainsList )
                            {
                                if ( !( valueRow is IList ) )
                                    throw new System.InvalidCastException( "The DataSource contains a list which declares its items as lists, but these don't support the IList interface." );
                                oColumnValue = ( valueRow as IList )[indexValueColumn];
                            }
                            else
                            {
                                oColumnValue = pd.GetValue( valueRow );
                            }

                            //Convert value to double (always double)
                            double v = 0;
                            switch ( oColumnValue.GetType().ToString() )
                            {
                                case "System.DateTime":
                                    v = new XDate( Convert.ToDateTime( oColumnValue ) ).XLDate;
                                    break;
                                default:
                                    try
                                    {
                                        v = Convert.ToDouble( oColumnValue );
                                    }
                                    catch
                                    {
                                        throw new NotImplementedException( "Conversion from " + oColumnValue.GetType() + " to double not implemented." );
                                    }
                                    break;
                            }

                            //
                            // Base axis binding (X axis)
                            //
                            pair.Tag = oColumnValue; //Original typed value
                            pair.Y = v;
                            if ( this.XAxis.Type == AxisType.DateAsOrdinal
                                || this.XAxis.Type == AxisType.Date )
                            {
                                pair.X = new XDate( Convert.ToDateTime( basePd.GetValue( row ) ) ).XLDate;
                            }
                            else
                                pair.X = Convert.ToDouble( basePd.GetValue( row ) );

                            points.Add( pair );

                            nRow++;
                        }
                    }
                    catch ( System.ArgumentOutOfRangeException )
                    {
                        //A local datasource was set on this curve but it has fewer rows than the axis datasource.
                        //So we stop feeding this curve.
                    }

                    //Create curve in pane with its points
                    curveItem.CreateInPane( pane, points );
                }
            }
            else
            {
                //Add curves and values set in designer
                ZeeGraphWebCurveItem curve;
                for ( int i = 0; i < CurveList.Count; i++ )
                {
                    curve = CurveList[i];

                    PointPairList points = new PointPairList();
                    PointPair pair = new PointPair();
                    for ( int j = 0; j < curve.Points.Count; j++ )
                    {
                        curve.Points[j].CopyTo( pair );
                        points.Add( pair );
                    }

                    curve.CreateInPane( pane, points );
                }
            }

            //NOTE: ZeeGraphWeb.DataMember = base axis
            //NOTE: ZedGraphCurveItem.DataMember = Y
            //NOTE: Z values are only supported via the callback (???)
            //TODO: cache the data-map table before processing rows (???)
        }