예제 #1
0
 /// <summary>
 /// Indexer: get the Sample instance at the specified ordinal position in the list
 /// </summary>
 /// <param name="index">
 /// The ordinal position in the list of samples
 /// </param>
 /// <returns>
 /// Returns a <see cref="PointPair"/> instance containing the data specified by <see cref="XType"/> and <see cref="YType"/>
 /// </returns>
 public PointPair this[int index]
 {
     get
     {
         PointPair pt = new PointPair();
         Sample sample = (Sample)this.list[index];
         pt.X = this.GetValue(sample, this.XType);
         pt.Y = this.GetValue(sample, this.YType);
         return pt;
     }
 }
예제 #2
0
파일: Bar.cs 프로젝트: tu-tran/FareLiz
        /// <summary>
        /// Draw the <see cref="Bar"/> to the specified <see cref="Graphics"/> device at the specified location.  This routine draws a single bar.
        /// </summary>
        /// <param name="g">
        /// A graphic device object to be drawn into.  This is normally e.Graphics from the PaintEventArgs argument to the Paint() method.
        /// </param>
        /// <param name="pane">
        /// A reference to the <see cref="GraphPane"/> object that is the parent or owner of this object.
        /// </param>
        /// <param name="left">
        /// The x position of the left side of the bar in pixel units
        /// </param>
        /// <param name="right">
        /// The x position of the right side of the bar in pixel units
        /// </param>
        /// <param name="top">
        /// The y position of the top of the bar in pixel units
        /// </param>
        /// <param name="bottom">
        /// The y position of the bottom of the bar in pixel units
        /// </param>
        /// <param name="scaleFactor">
        /// The scaling factor for the features of the graph based on the <see cref="PaneBase.BaseDimension"/>.  This scaling factor is calculated by the
        /// <see cref="PaneBase.CalcScaleFactor"/> method.  The scale factor represents a linear multiple to be applied to font sizes, symbol sizes, etc.
        /// </param>
        /// <param name="fullFrame">
        /// true to draw the bottom portion of the border around the bar (this is for legend entries)
        /// </param>
        /// <param name="isSelected">
        /// Indicates that the <see cref="Bar"/> should be drawn with attributes from the <see cref="Selection"/> class.
        /// </param>
        /// <param name="dataValue">
        /// The data value to be used for a value-based color gradient.  This is only applicable for <see cref="FillType.GradientByX"/>,
        /// <see cref="FillType.GradientByY"/> or <see cref="FillType.GradientByZ"/>.
        /// </param>
        public void Draw(
            Graphics g, 
            GraphPane pane, 
            float left, 
            float right, 
            float top, 
            float bottom, 
            float scaleFactor, 
            bool fullFrame, 
            bool isSelected, 
            PointPair dataValue)
        {
            // Do a sanity check to make sure the top < bottom.  If not, reverse them
            if (top > bottom)
            {
                float junk = top;
                top = bottom;
                bottom = junk;
            }

            // Do a sanity check to make sure the left < right.  If not, reverse them
            if (left > right)
            {
                float junk = right;
                right = left;
                left = junk;
            }

            if (top < -10000)
            {
                top = -10000;
            }
            else if (top > 10000)
            {
                top = 10000;
            }

            if (left < -10000)
            {
                left = -10000;
            }
            else if (left > 10000)
            {
                left = 10000;
            }

            if (right < -10000)
            {
                right = -10000;
            }
            else if (right > 10000)
            {
                right = 10000;
            }

            if (bottom < -10000)
            {
                bottom = -10000;
            }
            else if (bottom > 10000)
            {
                bottom = 10000;
            }

            // Make a rectangle for the bar and draw it
            RectangleF rect = new RectangleF(left, top, right - left, bottom - top);

            this.Draw(g, pane, rect, scaleFactor, fullFrame, isSelected, dataValue);
        }
예제 #3
0
        /// <summary>
        /// The handle edit drag.
        /// </summary>
        /// <param name="mousePt">
        /// The mouse pt.
        /// </param>
        private void HandleEditDrag(Point mousePt)
        {
            // get the scale values that correspond to the current point
            double curX, curY;
            this._dragPane.ReverseTransform(
                mousePt,
                this._dragCurve.IsX2Axis,
                this._dragCurve.IsY2Axis,
                this._dragCurve.YAxisIndex,
                out curX,
                out curY);
            double startX, startY;
            this._dragPane.ReverseTransform(
                this._dragStartPt,
                this._dragCurve.IsX2Axis,
                this._dragCurve.IsY2Axis,
                this._dragCurve.YAxisIndex,
                out startX,
                out startY);

            // calculate the new scale values for the point
            PointPair newPt = new PointPair(this._dragStartPair);

            Scale xScale = this._dragCurve.GetXAxis(this._dragPane)._scale;
            if (this._isEnableHEdit)
            {
                newPt.X = xScale.DeLinearize(xScale.Linearize(newPt.X) + xScale.Linearize(curX) - xScale.Linearize(startX));
            }

            Scale yScale = this._dragCurve.GetYAxis(this._dragPane)._scale;
            if (this._isEnableVEdit)
            {
                newPt.Y = yScale.DeLinearize(yScale.Linearize(newPt.Y) + yScale.Linearize(curY) - yScale.Linearize(startY));
            }

            // save the data back to the point list
            IPointListEdit list = this._dragCurve.Points as IPointListEdit;
            if (list != null)
            {
                list[this._dragIndex] = newPt;
            }

            // force a redraw
            this.Refresh();
        }
예제 #4
0
파일: StockPt.cs 프로젝트: tu-tran/FareLiz
 /// <summary>
 /// Initializes a new instance of the <see cref="StockPt"/> class. 
 /// The StockPt copy constructor.
 /// </summary>
 /// <param name="rhs">
 /// The basis for the copy.
 /// </param>
 public StockPt(PointPair rhs)
     : base(rhs)
 {
     if (rhs is StockPt)
     {
         StockPt pt = rhs as StockPt;
         this.Open = pt.Open;
         this.Close = pt.Close;
         this.Vol = pt.Vol;
         this.ColorValue = rhs.ColorValue;
     }
     else
     {
         this.Open = Missing;
         this.Close = Missing;
         this.Vol = Missing;
         this.ColorValue = Missing;
     }
 }
예제 #5
0
파일: Line.cs 프로젝트: tu-tran/FareLiz
        /// <summary>
        /// This method just handles the case where one or more of the coordinates are outrageous, or GDI+ threw an exception.  This method attempts to correct
        /// the outrageous coordinates by interpolating them to a point (along the original line) that lies at the edge of the ChartRect so that GDI+ will handle
        /// it properly.  GDI+ will throw an exception, or just plot the data incorrectly if the coordinates are too large (empirically, this appears to be when
        /// the coordinate value is greater than 5,000,000 or less than -5,000,000).  Although you typically would not see coordinates like this, if you
        /// repeatedly zoom in on a ZedGraphControl, eventually all your points will be way outside the bounds of the plot.
        /// </summary>
        /// <param name="g">
        /// The g.
        /// </param>
        /// <param name="pane">
        /// The pane.
        /// </param>
        /// <param name="curve">
        /// The curve.
        /// </param>
        /// <param name="lastPt">
        /// The last Pt.
        /// </param>
        /// <param name="scaleFactor">
        /// The scale Factor.
        /// </param>
        /// <param name="pen">
        /// The pen.
        /// </param>
        /// <param name="lastX">
        /// The last X.
        /// </param>
        /// <param name="lastY">
        /// The last Y.
        /// </param>
        /// <param name="tmpX">
        /// The tmp X.
        /// </param>
        /// <param name="tmpY">
        /// The tmp Y.
        /// </param>
        private void InterpolatePoint(
            Graphics g, 
            GraphPane pane, 
            CurveItem curve, 
            PointPair lastPt, 
            float scaleFactor, 
            Pen pen, 
            float lastX, 
            float lastY, 
            float tmpX, 
            float tmpY)
        {
            try
            {
                RectangleF chartRect = pane.Chart._rect;

                // try to interpolate values
                bool lastIn = chartRect.Contains(lastX, lastY);
                bool curIn = chartRect.Contains(tmpX, tmpY);

                // If both points are outside the ChartRect, make a new point that is on the LastX/Y
                // side of the ChartRect, and fall through to the code that handles lastIn == true
                if (!lastIn)
                {
                    float newX, newY;

                    if (Math.Abs(lastX) > Math.Abs(lastY))
                    {
                        newX = lastX < 0 ? chartRect.Left : chartRect.Right;
                        newY = lastY + (tmpY - lastY) * (newX - lastX) / (tmpX - lastX);
                    }
                    else
                    {
                        newY = lastY < 0 ? chartRect.Top : chartRect.Bottom;
                        newX = lastX + (tmpX - lastX) * (newY - lastY) / (tmpY - lastY);
                    }

                    lastX = newX;
                    lastY = newY;
                }

                if (!curIn)
                {
                    float newX, newY;

                    if (Math.Abs(tmpX) > Math.Abs(tmpY))
                    {
                        newX = tmpX < 0 ? chartRect.Left : chartRect.Right;
                        newY = tmpY + (lastY - tmpY) * (newX - tmpX) / (lastX - tmpX);
                    }
                    else
                    {
                        newY = tmpY < 0 ? chartRect.Top : chartRect.Bottom;
                        newX = tmpX + (lastX - tmpX) * (newY - tmpY) / (lastY - tmpY);
                    }

                    tmpX = newX;
                    tmpY = newY;
                }

                /*
                if ( this.StepType == StepType.ForwardStep )
                {
                    g.DrawLine( pen, lastX, lastY, tmpX, lastY );
                    g.DrawLine( pen, tmpX, lastY, tmpX, tmpY );
                }
                else if ( this.StepType == StepType.RearwardStep )
                {
                    g.DrawLine( pen, lastX, lastY, lastX, tmpY );
                    g.DrawLine( pen, lastX, tmpY, tmpX, tmpY );
                }
                else 		// non-step
                    g.DrawLine( pen, lastX, lastY, tmpX, tmpY );
                */
                if (!curve.IsSelected && this._gradientFill.IsGradientValueType)
                {
                    using (Pen tPen = this.GetPen(pane, scaleFactor, lastPt))
                    {
                        if (this.StepType == StepType.NonStep)
                        {
                            g.DrawLine(tPen, lastX, lastY, tmpX, tmpY);
                        }
                        else if (this.StepType == StepType.ForwardStep)
                        {
                            g.DrawLine(tPen, lastX, lastY, tmpX, lastY);
                            g.DrawLine(tPen, tmpX, lastY, tmpX, tmpY);
                        }
                        else if (this.StepType == StepType.RearwardStep)
                        {
                            g.DrawLine(tPen, lastX, lastY, lastX, tmpY);
                            g.DrawLine(tPen, lastX, tmpY, tmpX, tmpY);
                        }
                        else if (this.StepType == StepType.ForwardSegment)
                        {
                            g.DrawLine(tPen, lastX, lastY, tmpX, lastY);
                        }
                        else
                        {
                            g.DrawLine(tPen, lastX, tmpY, tmpX, tmpY);
                        }
                    }
                }
                else
                {
                    if (this.StepType == StepType.NonStep)
                    {
                        g.DrawLine(pen, lastX, lastY, tmpX, tmpY);
                    }
                    else if (this.StepType == StepType.ForwardStep)
                    {
                        g.DrawLine(pen, lastX, lastY, tmpX, lastY);
                        g.DrawLine(pen, tmpX, lastY, tmpX, tmpY);
                    }
                    else if (this.StepType == StepType.RearwardStep)
                    {
                        g.DrawLine(pen, lastX, lastY, lastX, tmpY);
                        g.DrawLine(pen, lastX, tmpY, tmpX, tmpY);
                    }
                    else if (this.StepType == StepType.ForwardSegment)
                    {
                        g.DrawLine(pen, lastX, lastY, tmpX, lastY);
                    }
                    else if (this.StepType == StepType.RearwardSegment)
                    {
                        g.DrawLine(pen, lastX, tmpY, tmpX, tmpY);
                    }
                }
            }
            catch
            {
            }
        }
예제 #6
0
        /// <summary>
        /// The update graph.
        /// </summary>
        /// <param name="isAdding">
        /// The is adding.
        /// </param>
        /// <param name="tagData">
        /// The tag data.
        /// </param>
        private void UpdateGraph(bool isAdding, object tagData)
        {
            try
            {
                if (tagData is DateTime)
                {
                    // Change data date
                    var date = (DateTime)tagData;

                    foreach (var pair in this._graphData)
                    {
                        var pointList = pair.Value;
                        if (isAdding)
                        {
                            var journey = pair.Key;
                            foreach (var d in journey.Data)
                            {
                                if (d.DataDate.Date == date && d.Flights.Count > 0)
                                {
                                    Flight cheapestFlight = d.Flights[0];
                                    double cheapestPrice = cheapestFlight.Price;
                                    foreach (var f in d.Flights)
                                    {
                                        if (f.Price < cheapestPrice)
                                        {
                                            cheapestFlight = f;
                                            cheapestPrice = f.Price;
                                        }
                                    }

                                    var newPoint = new PointPair(new XDate(d.DataDate), cheapestPrice) { Tag = cheapestFlight };
                                    pointList.Add(newPoint);
                                }
                            }

                            pointList.Sort(SortType.XValues);
                        }
                        else
                        {
                            for (int i = 0; i < pointList.Count; i++)
                            {
                                var point = pointList[i];
                                if (new XDate(point.X).DateTime.Date == date.Date)
                                {
                                    pointList.RemoveAt(i--);
                                }
                            }
                        }
                    }
                }
                else if (tagData is DatePeriod)
                {
                    // Change travel period
                    var date = (DatePeriod)tagData;
                    foreach (var pair in this._graphData)
                    {
                        var pointList = pair.Value;
                        var targetCurveList = isAdding ? this._hiddenCurves : this.graph.GraphPane.CurveList;
                        for (int i = 0; i < targetCurveList.Count; i++)
                        {
                            var curve = targetCurveList[i];
                            DatePeriod tagPeriod = curve.Tag as DatePeriod;
                            if (tagPeriod.StartDate == date.StartDate && tagPeriod.EndDate == date.EndDate)
                            {
                                if (isAdding)
                                {
                                    this.graph.GraphPane.CurveList.Add(curve);
                                    this._hiddenCurves.RemoveAt(i);
                                }
                                else
                                {
                                    this._hiddenCurves.Add(curve);
                                    this.graph.GraphPane.CurveList.RemoveAt(i);
                                }

                                return;
                            }
                        }
                    }
                }
            }
            finally
            {
                if (!this._suppressDraw)
                {
                    this.RefreshGraph();
                }
            }
        }
예제 #7
0
파일: Fill.cs 프로젝트: tu-tran/FareLiz
        /// <summary>
        /// The get gradient color.
        /// </summary>
        /// <param name="dataValue">
        /// The data value.
        /// </param>
        /// <returns>
        /// The <see cref="Color"/>.
        /// </returns>
        internal Color GetGradientColor(PointPair dataValue)
        {
            double val;

            if (dataValue == null)
            {
                val = this._rangeDefault;
            }
            else if (this._type == FillType.GradientByColorValue)
            {
                val = dataValue.ColorValue;
            }
            else if (this._type == FillType.GradientByZ)
            {
                val = dataValue.Z;
            }
            else if (this._type == FillType.GradientByY)
            {
                val = dataValue.Y;
            }
            else
            {
                val = dataValue.X;
            }

            return this.GetGradientColor(val);
        }
예제 #8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PointPair"/> class. 
        /// The PointPair copy constructor.
        /// </summary>
        /// <param name="rhs">
        /// The basis for the copy.
        /// </param>
        public PointPair(PointPair rhs)
            : base(rhs)
        {
            this.Z = rhs.Z;

            if (rhs.Tag is ICloneable)
            {
                this.Tag = ((ICloneable)rhs.Tag).Clone();
            }
            else
            {
                this.Tag = rhs.Tag;
            }
        }
예제 #9
0
        /// <summary>
        /// Add a set of points to the <see cref="RollingPointPairList"/> from three arrays of type double. If the X or Y array is null, then a set of ordinal
        /// values is automatically generated in its place (see <see cref="AxisType.Ordinal"/>. If the <see paramref="z"/> value is null, then it is set to
        /// zero. If the arrays are of different size, then the larger array prevails and the smaller array is padded with <see cref="PointPairBase.Missing"/>
        /// values.
        /// </summary>
        /// <param name="x">
        /// A double[] array of X values
        /// </param>
        /// <param name="y">
        /// A double[] array of Y values
        /// </param>
        /// <param name="z">
        /// A double[] array of Z values
        /// </param>
        public void Add(double[] x, double[] y, double[] z)
        {
            int len = 0;

            if (x != null)
            {
                len = x.Length;
            }

            if (y != null && y.Length > len)
            {
                len = y.Length;
            }

            if (z != null && z.Length > len)
            {
                len = z.Length;
            }

            for (int i = 0; i < len; i++)
            {
                PointPair point = new PointPair();

                if (x == null)
                {
                    point.X = i + 1.0;
                }
                else if (i < x.Length)
                {
                    point.X = x[i];
                }
                else
                {
                    point.X = PointPairBase.Missing;
                }

                if (y == null)
                {
                    point.Y = i + 1.0;
                }
                else if (i < y.Length)
                {
                    point.Y = y[i];
                }
                else
                {
                    point.Y = PointPairBase.Missing;
                }

                if (z == null)
                {
                    point.Z = i + 1.0;
                }
                else if (i < z.Length)
                {
                    point.Z = z[i];
                }
                else
                {
                    point.Z = PointPairBase.Missing;
                }

                this.Add(point);
            }
        }
예제 #10
0
파일: Fill.cs 프로젝트: tu-tran/FareLiz
        /// <summary>
        /// Create a fill brush using current properties.  This method will construct a brush based on the settings of <see cref="Fill.Type"/>,
        /// <see cref="Fill.Color"/>
        /// and <see cref="Fill.Brush"/>.  If
        /// <see cref="Fill.Type"/> is set to <see cref="FillType.Brush"/> and
        /// <see cref="Fill.Brush"/>
        /// is null, then a <see cref="LinearGradientBrush"/> will be created between the colors of
        /// <see cref="System.Drawing.Color.White"/> and <see cref="Fill.Color"/>.
        /// </summary>
        /// <param name="rect">
        /// A rectangle that bounds the object to be filled.  This determines the start and end of the gradient fill.
        /// </param>
        /// <param name="dataValue">
        /// The data value to be used for a value-based color gradient.  This is only applicable for <see cref="FillType.GradientByX"/>,
        /// <see cref="FillType.GradientByY"/> or <see cref="FillType.GradientByZ"/>.
        /// </param>
        /// <returns>
        /// A <see cref="System.Drawing.Brush"/> class representing the fill brush
        /// </returns>
        public Brush MakeBrush(RectangleF rect, PointPair dataValue)
        {
            // get a brush
            if (this.IsVisible && (!this._color.IsEmpty || this._brush != null))
            {
                if (rect.Height < 1.0F)
                {
                    rect.Height = 1.0F;
                }

                if (rect.Width < 1.0F)
                {
                    rect.Width = 1.0F;
                }

                // Brush	brush;
                if (this._type == FillType.Brush)
                {
                    return this.ScaleBrush(rect, this._brush, this._isScaled);
                }

                if (this.IsGradientValueType)
                {
                    if (dataValue != null)
                    {
                        if (!this._secondaryValueGradientColor.IsEmpty)
                        {
                            // Go ahead and create a new Fill so we can do all the scaling, etc.,
                            // that is associated with a gradient
                            Fill tmpFill = new Fill(this._secondaryValueGradientColor, this.GetGradientColor(dataValue), this._angle);
                            return tmpFill.MakeBrush(rect);
                        }

                        return new SolidBrush(this.GetGradientColor(dataValue));
                    }

                    if (this._rangeDefault != double.MaxValue)
                    {
                        if (!this._secondaryValueGradientColor.IsEmpty)
                        {
                            // Go ahead and create a new Fill so we can do all the scaling, etc.,
                            // that is associated with a gradient
                            Fill tmpFill = new Fill(this._secondaryValueGradientColor, this.GetGradientColor(this._rangeDefault), this._angle);
                            return tmpFill.MakeBrush(rect);
                        }

                        return new SolidBrush(this.GetGradientColor(this._rangeDefault));
                    }

                    return this.ScaleBrush(rect, this._brush, true);
                }

                return new SolidBrush(this._color);
            }

            // Always return a suitable default
            return new SolidBrush(Color.White);
        }
예제 #11
0
 /// <summary>
 /// Add a <see cref="PointPair"/> onto the head of the queue, overwriting old values if the buffer is full.
 /// </summary>
 /// <param name="item">
 /// The <see cref="PointPair"/> to be added.
 /// </param>
 public void Add(PointPair item)
 {
     this._mBuffer[this.GetNextIndex()] = item;
 }
예제 #12
0
        /// <summary>
        /// Draw the <see cref="JapaneseCandleStick"/> to the specified <see cref="Graphics"/>
        /// device at the specified location.
        /// </summary>
        /// <param name="g">
        /// A graphic device object to be drawn into.  This is normally e.Graphics from the PaintEventArgs argument to the Paint() method.
        /// </param>
        /// <param name="pane">
        /// A reference to the <see cref="GraphPane"/> object that is the parent or owner of this object.
        /// </param>
        /// <param name="isXBase">
        /// boolean value that indicates if the "base" axis for this
        /// <see cref="JapaneseCandleStick"/> is the X axis.  True for an <see cref="XAxis"/> base, false for a <see cref="YAxis"/> or <see cref="Y2Axis"/>
        /// base.
        /// </param>
        /// <param name="pixBase">
        /// The independent axis position of the center of the candlestick in pixel units
        /// </param>
        /// <param name="pixHigh">
        /// The high value position of the candlestick in pixel units
        /// </param>
        /// <param name="pixLow">
        /// The low value position of the candlestick in pixel units
        /// </param>
        /// <param name="pixOpen">
        /// The opening value position of the candlestick in pixel units
        /// </param>
        /// <param name="pixClose">
        /// The closing value position of the candlestick in pixel units
        /// </param>
        /// <param name="halfSize">
        /// The scaled width of one-half of a bar, in pixels
        /// </param>
        /// <param name="scaleFactor">
        /// The scaling factor for the features of the graph based on the <see cref="PaneBase.BaseDimension"/>.  This scaling factor is calculated by the
        /// <see cref="PaneBase.CalcScaleFactor"/> method.  The scale factor represents a linear multiple to be applied to font sizes, symbol sizes, etc.
        /// </param>
        /// <param name="pen">
        /// A pen with the <see cref="Color"/> attribute for this
        /// <see cref="JapaneseCandleStick"/>
        /// </param>
        /// <param name="fill">
        /// The <see cref="Fill"/> instance to be used for filling this
        /// <see cref="JapaneseCandleStick"/>
        /// </param>
        /// <param name="border">
        /// The <see cref="Border"/> instance to be used for drawing the border around the <see cref="JapaneseCandleStick"/> filled box
        /// </param>
        /// <param name="pt">
        /// The <see cref="PointPair"/> to be used for determining the
        /// <see cref="Fill"/>, just in case it's a <see cref="FillType.GradientByX"/>,
        /// <see cref="FillType.GradientByY"/>, or
        /// <see cref="FillType.GradientByZ"/> <see cref="FillType"/>
        /// </param>
        public void Draw(
            Graphics g, 
            GraphPane pane, 
            bool isXBase, 
            float pixBase, 
            float pixHigh, 
            float pixLow, 
            float pixOpen, 
            float pixClose, 
            float halfSize, 
            float scaleFactor, 
            Pen pen, 
            Fill fill, 
            Border border, 
            PointPair pt)
        {
            // float halfSize = (int) ( _size * scaleFactor / 2.0f + 0.5f );
            if (pixBase != PointPairBase.Missing && Math.Abs(pixLow) < 1000000 && Math.Abs(pixHigh) < 1000000)
            {
                RectangleF rect;
                if (isXBase)
                {
                    rect = new RectangleF(pixBase - halfSize, Math.Min(pixOpen, pixClose), halfSize * 2.0f, Math.Abs(pixOpen - pixClose));

                    g.DrawLine(pen, pixBase, pixHigh, pixBase, pixLow);
                }
                else
                {
                    rect = new RectangleF(Math.Min(pixOpen, pixClose), pixBase - halfSize, Math.Abs(pixOpen - pixClose), halfSize * 2.0f);

                    g.DrawLine(pen, pixHigh, pixBase, pixLow, pixBase);
                }

                if (this._isOpenCloseVisible && Math.Abs(pixOpen) < 1000000 && Math.Abs(pixClose) < 1000000)
                {
                    if (rect.Width == 0)
                    {
                        rect.Width = 1;
                    }

                    if (rect.Height == 0)
                    {
                        rect.Height = 1;
                    }

                    fill.Draw(g, rect, pt);
                    border.Draw(g, pane, scaleFactor, rect);
                }
            }
        }
예제 #13
0
파일: LineBase.cs 프로젝트: tu-tran/FareLiz
        /// <summary>
        /// Create a <see cref="Pen"/> object based on the properties of this
        /// <see cref="LineBase"/>.
        /// </summary>
        /// <param name="pane">
        /// The owner <see cref="GraphPane"/> of this
        /// <see cref="LineBase"/>.
        /// </param>
        /// <param name="scaleFactor">
        /// The scaling factor to be used for rendering objects.  This is calculated and passed down by the parent <see cref="GraphPane"/> object using the
        /// <see cref="PaneBase.CalcScaleFactor"/> method, and is used to proportionally adjust font sizes, etc. according to the actual size of the graph.
        /// </param>
        /// <param name="dataValue">
        /// The data value to be used for a value-based color gradient.  This is only applicable if <see cref="Fill.Type">GradientFill.Type</see>
        /// is one of <see cref="FillType.GradientByX"/>,
        /// <see cref="FillType.GradientByY"/>, <see cref="FillType.GradientByZ"/>, or <see cref="FillType.GradientByColorValue"/>.
        /// </param>
        /// <returns>
        /// A <see cref="Pen"/> object with the properties of this <see cref="LineBase"/>
        /// </returns>
        public Pen GetPen(PaneBase pane, float scaleFactor, PointPair dataValue)
        {
            Color color = this._color;
            if (this._gradientFill.IsGradientValueType)
            {
                color = this._gradientFill.GetGradientColor(dataValue);
            }

            Pen pen = new Pen(color, pane.ScaledPenWidth(this._width, scaleFactor));

            pen.DashStyle = this._style;

            if (this._style == DashStyle.Custom)
            {
                if (this._dashOff > 1e-10 && this._dashOn > 1e-10)
                {
                    pen.DashStyle = DashStyle.Custom;
                    float[] pattern = new float[2];
                    pattern[0] = this._dashOn;
                    pattern[1] = this._dashOff;
                    pen.DashPattern = pattern;
                }
                else
                {
                    pen.DashStyle = DashStyle.Solid;
                }
            }

            return pen;
        }
예제 #14
0
파일: Bar.cs 프로젝트: tu-tran/FareLiz
 /// <summary>
 /// Draw the <see cref="Bar"/> to the specified <see cref="Graphics"/> device at the specified location.  This routine draws a single bar.
 /// </summary>
 /// <param name="g">
 /// A graphic device object to be drawn into.  This is normally e.Graphics from the PaintEventArgs argument to the Paint() method.
 /// </param>
 /// <param name="pane">
 /// A reference to the <see cref="GraphPane"/> object that is the parent or owner of this object.
 /// </param>
 /// <param name="rect">
 /// The rectangle (pixels) to contain the bar
 /// </param>
 /// <param name="scaleFactor">
 /// The scaling factor for the features of the graph based on the <see cref="PaneBase.BaseDimension"/>.  This scaling factor is calculated by the
 /// <see cref="PaneBase.CalcScaleFactor"/> method.  The scale factor represents a linear multiple to be applied to font sizes, symbol sizes, etc.
 /// </param>
 /// <param name="fullFrame">
 /// true to draw the bottom portion of the border around the bar (this is for legend entries)
 /// </param>
 /// <param name="isSelected">
 /// Indicates that the <see cref="Bar"/> should be drawn with attributes from the <see cref="Selection"/> class.
 /// </param>
 /// <param name="dataValue">
 /// The data value to be used for a value-based color gradient.  This is only applicable for <see cref="FillType.GradientByX"/>,
 /// <see cref="FillType.GradientByY"/> or <see cref="FillType.GradientByZ"/>.
 /// </param>
 public void Draw(Graphics g, GraphPane pane, RectangleF rect, float scaleFactor, bool fullFrame, bool isSelected, PointPair dataValue)
 {
     if (isSelected)
     {
         Selection.Fill.Draw(g, rect, dataValue);
         Selection.Border.Draw(g, pane, scaleFactor, rect);
     }
     else
     {
         this._fill.Draw(g, rect, dataValue);
         this._border.Draw(g, pane, scaleFactor, rect);
     }
 }
예제 #15
0
파일: Fill.cs 프로젝트: tu-tran/FareLiz
 /// <summary>
 /// Fill the background of the <see cref="RectangleF"/> area, using the fill type from this <see cref="Fill"/>.
 /// </summary>
 /// <param name="g">
 /// A graphic device object to be drawn into.  This is normally e.Graphics from the PaintEventArgs argument to the Paint() method.
 /// </param>
 /// <param name="rect">
 /// The <see cref="RectangleF"/> struct specifying the area to be filled
 /// </param>
 /// <param name="pt">
 /// The data value to be used in case it's a
 /// <see cref="FillType.GradientByX"/>, <see cref="FillType.GradientByY"/>, or
 /// <see cref="FillType.GradientByZ"/> <see cref="FillType"/>.
 /// </param>
 public void Draw(Graphics g, RectangleF rect, PointPair pt)
 {
     if (this.IsVisible)
     {
         using (Brush brush = this.MakeBrush(rect, pt))
         {
             g.FillRectangle(brush, rect);
         }
     }
 }
예제 #16
0
        /// <summary>
        /// Indexer to access the specified <see cref="PointPair"/> object by its ordinal position in the list.
        /// </summary>
        /// <param name="index">
        /// The ordinal position (zero-based) of the
        /// <see cref="PointPair"/> object to be accessed.
        /// </param>
        /// <value>
        /// A <see cref="PointPair"/> object reference.
        /// </value>
        /// <returns>
        /// The <see cref="PointPair"/>.
        /// </returns>
        public PointPair this[int index]
        {
            get
            {
                if (index < 0 || index >= this._bindingSource.Count)
                {
                    throw new ArgumentOutOfRangeException("Error: Index out of range");
                }

                object row = this._bindingSource[index];

                double x = this.GetDouble(row, this._xDataMember, index);
                double y = this.GetDouble(row, this._yDataMember, index);
                double z = this.GetDouble(row, this._zDataMember, index);
                object tag = this.GetObject(row, this._tagDataMember);

                PointPair pt = new PointPair(x, y, z);
                pt.Tag = tag;
                return pt;
            }
        }
예제 #17
0
파일: ErrorBar.cs 프로젝트: tu-tran/FareLiz
 /// <summary>
 /// Draw the <see cref="ErrorBar"/> to the specified <see cref="Graphics"/>
 /// device at the specified location.
 /// </summary>
 /// <param name="g">
 /// A graphic device object to be drawn into.  This is normally e.Graphics from the PaintEventArgs argument to the Paint() method.
 /// </param>
 /// <param name="pane">
 /// A reference to the <see cref="GraphPane"/> object that is the parent or owner of this object.
 /// </param>
 /// <param name="isXBase">
 /// boolean value that indicates if the "base" axis for this
 /// <see cref="ErrorBar"/> is the X axis.  True for an <see cref="XAxis"/> base, false for a <see cref="YAxis"/> or <see cref="Y2Axis"/> base.
 /// </param>
 /// <param name="pixBase">
 /// The independent axis position of the center of the error bar in pixel units
 /// </param>
 /// <param name="pixValue">
 /// The dependent axis position of the top of the error bar in pixel units
 /// </param>
 /// <param name="pixLowValue">
 /// The dependent axis position of the bottom of the error bar in pixel units
 /// </param>
 /// <param name="scaleFactor">
 /// The scaling factor for the features of the graph based on the <see cref="PaneBase.BaseDimension"/>.  This scaling factor is calculated by the
 /// <see cref="PaneBase.CalcScaleFactor"/> method.  The scale factor represents a linear multiple to be applied to font sizes, symbol sizes, etc.
 /// </param>
 /// <param name="pen">
 /// A pen with attributes of <see cref="Color"/> and
 /// <see cref="PenWidth"/> for this <see cref="ErrorBar"/>
 /// </param>
 /// <param name="isSelected">
 /// Indicates that the <see cref="ErrorBar"/> should be drawn with attributes from the <see cref="Selection"/> class.
 /// </param>
 /// <param name="dataValue">
 /// The data value to be used for a value-based color gradient.  This is only applicable for <see cref="FillType.GradientByX"/>,
 /// <see cref="FillType.GradientByY"/> or <see cref="FillType.GradientByZ"/>.
 /// </param>
 public void Draw(
     Graphics g, 
     GraphPane pane, 
     bool isXBase, 
     float pixBase, 
     float pixValue, 
     float pixLowValue, 
     float scaleFactor, 
     Pen pen, 
     bool isSelected, 
     PointPair dataValue)
 {
     if (isXBase)
     {
         g.DrawLine(pen, pixBase, pixValue, pixBase, pixLowValue);
         this._symbol.DrawSymbol(g, pane, (int)pixBase, (int)pixValue, scaleFactor, isSelected, dataValue);
         this._symbol.DrawSymbol(g, pane, (int)pixBase, (int)pixLowValue, scaleFactor, isSelected, dataValue);
     }
     else
     {
         g.DrawLine(pen, pixValue, pixBase, pixLowValue, pixBase);
         this._symbol.DrawSymbol(g, pane, (int)pixValue, (int)pixBase, scaleFactor, isSelected, dataValue);
         this._symbol.DrawSymbol(g, pane, (int)pixLowValue, (int)pixBase, scaleFactor, isSelected, dataValue);
     }
 }
예제 #18
0
        /// <summary>
        /// Add a <see cref="PointPair"/> object to the end of the points collection for this curve.
        /// </summary>
        /// <remarks>
        /// This method will only work if the <see cref="IPointList"/> instance reference at <see cref="Points"/> supports the <see cref="IPointListEdit"/>
        /// interface. Otherwise, it does nothing.
        /// </remarks>
        /// <param name="point">
        /// A reference to the <see cref="PointPair"/> object to be added
        /// </param>
        public void AddPoint(PointPair point)
        {
            if (this._points == null)
            {
                this.Points = new PointPairList();
            }

            if (this._points is IPointListEdit)
            {
                (this._points as IPointListEdit).Add(point);
            }
            else
            {
                throw new NotImplementedException();
            }
        }
예제 #19
0
파일: Symbol.cs 프로젝트: tu-tran/FareLiz
        /// <summary>
        /// Draw the <see cref="Symbol"/> to the specified <see cref="Graphics"/> device at the specified location.  This routine draws a single
        /// symbol.
        /// </summary>
        /// <param name="g">
        /// A graphic device object to be drawn into.  This is normally e.Graphics from the PaintEventArgs argument to the Paint() method.
        /// </param>
        /// <param name="pane">
        /// A reference to the <see cref="GraphPane"/> object that is the parent or owner of this object.
        /// </param>
        /// <param name="x">
        /// The x position of the center of the symbol in pixel units
        /// </param>
        /// <param name="y">
        /// The y position of the center of the symbol in pixel units
        /// </param>
        /// <param name="scaleFactor">
        /// The scaling factor for the features of the graph based on the <see cref="PaneBase.BaseDimension"/>.  This scaling factor is calculated by the
        /// <see cref="PaneBase.CalcScaleFactor"/> method.  The scale factor represents a linear multiple to be applied to font sizes, symbol sizes, etc.
        /// </param>
        /// <param name="isSelected">
        /// Indicates that the <see cref="Symbol"/> should be drawn with attributes from the <see cref="Selection"/> class.
        /// </param>
        /// <param name="dataValue">
        /// The data value to be used for a value-based color gradient.  This is only applicable for <see cref="FillType.GradientByX"/>,
        /// <see cref="FillType.GradientByY"/> or <see cref="FillType.GradientByZ"/>.
        /// </param>
        public void DrawSymbol(Graphics g, GraphPane pane, int x, int y, float scaleFactor, bool isSelected, PointPair dataValue)
        {
            Symbol source = this;
            if (isSelected)
            {
                source = Selection.Symbol;
            }

            // Only draw if the symbol is visible
            if (this._isVisible && this.Type != SymbolType.None && x < 100000 && x > -100000 && y < 100000 && y > -100000)
            {
                SmoothingMode sModeSave = g.SmoothingMode;
                if (this._isAntiAlias)
                {
                    g.SmoothingMode = SmoothingMode.HighQuality;
                }

                using (Pen pen = this._border.GetPen(pane, scaleFactor, dataValue))
                using (GraphicsPath path = this.MakePath(g, scaleFactor))
                using (Brush brush = this.Fill.MakeBrush(path.GetBounds(), dataValue))
                {
                    this.DrawSymbol(g, x, y, path, pen, brush);
                }

                g.SmoothingMode = sModeSave;
            }
        }
예제 #20
0
파일: Line.cs 프로젝트: tu-tran/FareLiz
        /// <summary>
        /// Draw the this <see cref="CurveItem"/> to the specified <see cref="Graphics"/>
        /// device.  The format (stair-step or line) of the curve is defined by the <see cref="StepType"/> property.  The routine only draws the line segments;
        /// the symbols are drawn by the
        /// <see cref="Symbol.Draw"/> method.  This method is normally only called by the Draw method of the
        /// <see cref="CurveItem"/> object
        /// </summary>
        /// <param name="g">
        /// A graphic device object to be drawn into.  This is normally e.Graphics from the PaintEventArgs argument to the Paint() method.
        /// </param>
        /// <param name="pane">
        /// A reference to the <see cref="GraphPane"/> object that is the parent or owner of this object.
        /// </param>
        /// <param name="curve">
        /// A <see cref="LineItem"/> representing this curve.
        /// </param>
        /// <param name="scaleFactor">
        /// The scaling factor to be used for rendering objects.  This is calculated and passed down by the parent <see cref="GraphPane"/> object using the
        /// <see cref="PaneBase.CalcScaleFactor"/> method, and is used to proportionally adjust font sizes, etc. according to the actual size of the graph.
        /// </param>
        public void DrawCurveOriginal(Graphics g, GraphPane pane, CurveItem curve, float scaleFactor)
        {
            Line source = this;
            if (curve.IsSelected)
            {
                source = Selection.Line;
            }

            float tmpX, tmpY, lastX = float.MaxValue, lastY = float.MaxValue;
            double curX, curY, lowVal;
            PointPair curPt, lastPt = new PointPair();

            bool lastBad = true;
            IPointList points = curve.Points;
            ValueHandler valueHandler = new ValueHandler(pane, false);
            Axis yAxis = curve.GetYAxis(pane);
            Axis xAxis = curve.GetXAxis(pane);

            bool xIsLog = xAxis._scale.IsLog;
            bool yIsLog = yAxis._scale.IsLog;

            float minX = pane.Chart.Rect.Left;
            float maxX = pane.Chart.Rect.Right;
            float minY = pane.Chart.Rect.Top;
            float maxY = pane.Chart.Rect.Bottom;

            using (Pen pen = source.GetPen(pane, scaleFactor))
            {
                if (points != null && !this._color.IsEmpty && this.IsVisible)
                {
                    // bool lastOut = false;
                    bool isOut;

                    // Loop over each point in the curve
                    for (int i = 0; i < points.Count; i++)
                    {
                        curPt = points[i];
                        if (pane.LineType == LineType.Stack)
                        {
                            if (!valueHandler.GetValues(curve, i, out curX, out lowVal, out curY))
                            {
                                curX = PointPairBase.Missing;
                                curY = PointPairBase.Missing;
                            }
                        }
                        else
                        {
                            curX = curPt.X;
                            curY = curPt.Y;
                        }

                        // Any value set to double max is invalid and should be skipped
                        // This is used for calculated values that are out of range, divide
                        // by zero, etc.
                        // Also, any value <= zero on a log scale is invalid
                        if (curX == PointPairBase.Missing || curY == PointPairBase.Missing || double.IsNaN(curX) || double.IsNaN(curY)
                            || double.IsInfinity(curX) || double.IsInfinity(curY) || (xIsLog && curX <= 0.0) || (yIsLog && curY <= 0.0))
                        {
                            // If the point is invalid, then make a linebreak only if IsIgnoreMissing is false
                            // LastX and LastY are always the last valid point, so this works out
                            lastBad = lastBad || !pane.IsIgnoreMissing;
                            isOut = true;
                        }
                        else
                        {
                            // Transform the current point from user scale units to
                            // screen coordinates
                            tmpX = xAxis.Scale.Transform(curve.IsOverrideOrdinal, i, curX);
                            tmpY = yAxis.Scale.Transform(curve.IsOverrideOrdinal, i, curY);
                            isOut = (tmpX < minX && lastX < minX) || (tmpX > maxX && lastX > maxX) || (tmpY < minY && lastY < minY)
                                    || (tmpY > maxY && lastY > maxY);

                            if (!lastBad)
                            {
                                try
                                {
                                    // GDI+ plots the data wrong and/or throws an exception for
                                    // outrageous coordinates, so we do a sanity check here
                                    if (lastX > 5000000 || lastX < -5000000 || lastY > 5000000 || lastY < -5000000 || tmpX > 5000000
                                        || tmpX < -5000000 || tmpY > 5000000 || tmpY < -5000000)
                                    {
                                        this.InterpolatePoint(g, pane, curve, lastPt, scaleFactor, pen, lastX, lastY, tmpX, tmpY);
                                    }
                                    else if (!isOut)
                                    {
                                        if (!curve.IsSelected && this._gradientFill.IsGradientValueType)
                                        {
                                            using (Pen tPen = this.GetPen(pane, scaleFactor, lastPt))
                                            {
                                                if (this.StepType == StepType.NonStep)
                                                {
                                                    g.DrawLine(tPen, lastX, lastY, tmpX, tmpY);
                                                }
                                                else if (this.StepType == StepType.ForwardStep)
                                                {
                                                    g.DrawLine(tPen, lastX, lastY, tmpX, lastY);
                                                    g.DrawLine(tPen, tmpX, lastY, tmpX, tmpY);
                                                }
                                                else if (this.StepType == StepType.RearwardStep)
                                                {
                                                    g.DrawLine(tPen, lastX, lastY, lastX, tmpY);
                                                    g.DrawLine(tPen, lastX, tmpY, tmpX, tmpY);
                                                }
                                                else if (this.StepType == StepType.ForwardSegment)
                                                {
                                                    g.DrawLine(tPen, lastX, lastY, tmpX, lastY);
                                                }
                                                else
                                                {
                                                    g.DrawLine(tPen, lastX, tmpY, tmpX, tmpY);
                                                }
                                            }
                                        }
                                        else
                                        {
                                            if (this.StepType == StepType.NonStep)
                                            {
                                                g.DrawLine(pen, lastX, lastY, tmpX, tmpY);
                                            }
                                            else if (this.StepType == StepType.ForwardStep)
                                            {
                                                g.DrawLine(pen, lastX, lastY, tmpX, lastY);
                                                g.DrawLine(pen, tmpX, lastY, tmpX, tmpY);
                                            }
                                            else if (this.StepType == StepType.RearwardStep)
                                            {
                                                g.DrawLine(pen, lastX, lastY, lastX, tmpY);
                                                g.DrawLine(pen, lastX, tmpY, tmpX, tmpY);
                                            }
                                            else if (this.StepType == StepType.ForwardSegment)
                                            {
                                                g.DrawLine(pen, lastX, lastY, tmpX, lastY);
                                            }
                                            else if (this.StepType == StepType.RearwardSegment)
                                            {
                                                g.DrawLine(pen, lastX, tmpY, tmpX, tmpY);
                                            }
                                        }
                                    }
                                }
                                catch
                                {
                                    this.InterpolatePoint(g, pane, curve, lastPt, scaleFactor, pen, lastX, lastY, tmpX, tmpY);
                                }
                            }

                            lastPt = curPt;
                            lastX = tmpX;
                            lastY = tmpY;
                            lastBad = false;

                            // lastOut = isOut;
                        }
                    }
                }
            }
        }
예제 #21
0
        /// <summary>The populate data.</summary>
        private void PopulateData()
        {
            Dictionary<string, object> travelPeriod = new Dictionary<string, object>();
            Dictionary<string, object> dataDate = new Dictionary<string, object>();

            foreach (var j in this._journeyData)
            {
                var travelDate = new DatePeriod(j.DepartureDate, j.ReturnDate);
                travelPeriod.Add(j.DepartureDate.ToString("ddd dd/MM/yyyy") + " - " + j.ReturnDate.ToString("ddd dd/MM/yyyy"), travelDate);
                var points = new PointPairList();

                var sortedData = j.Data.OrderBy(d => d.DataDate);
                foreach (var d in sortedData)
                {
                    var cheapestFlight = d.Flights.OrderBy(f => f.Price).FirstOrDefault();
                    if (cheapestFlight != null)
                    {
                        var str = d.DataDate.ToLongDateString();
                        if (!dataDate.ContainsKey(str))
                        {
                            dataDate.Add(str, d.DataDate.Date);
                        }

                        var x = (double)new XDate(d.DataDate);
                        var newPoint = new PointPair(x, cheapestFlight.Price) { Tag = cheapestFlight };
                        points.Add(newPoint);
                    }
                }

                this._graphData.Add(j, points);
            }

            // Render listview
            this.PopulateListView(travelPeriod, this.lvTravelPeriod, false);
            this.PopulateListView(dataDate, this.lvDataDate, true);
        }