Esempio n. 1
0
        /// <summary>
        /// Draws the point plot using the Drawing Context and x and y axes supplied
        /// </summary>
        /// <param name="ctx">The Drawing Context with which to draw.</param>
        /// <param name="xAxis">The X-Axis to draw against.</param>
        /// <param name="yAxis">The Y-Axis to draw against.</param>
        public virtual void Draw(Context ctx, PhysicalAxis xAxis, PhysicalAxis yAxis)
        {
            SequenceAdapter data_ = new SequenceAdapter(DataSource, DataMember, OrdinateData, AbscissaData);

            double leftCutoff_  = xAxis.PhysicalMin.X - marker.Size;
            double rightCutoff_ = xAxis.PhysicalMax.X + marker.Size;

            ctx.Save();
            ctx.SetColor(marker.LineColor);
            ctx.SetLineWidth(marker.LineWidth);

            for (int i = 0; i < data_.Count; ++i)
            {
                if (!Double.IsNaN(data_[i].X) && !Double.IsNaN(data_[i].Y))
                {
                    Point xPos = xAxis.WorldToPhysical(data_[i].X, false);
                    if (xPos.X < leftCutoff_ || rightCutoff_ < xPos.X)
                    {
                        continue;
                    }

                    Point yPos = yAxis.WorldToPhysical(data_[i].Y, false);
                    marker.Draw(ctx, xPos.X, yPos.Y);
                    if (marker.DropLine)
                    {
                        Point yMin   = new Point(data_[i].X, Math.Max(0.0, yAxis.Axis.WorldMin));
                        Point yStart = yAxis.WorldToPhysical(yMin.Y, false);
                        ctx.MoveTo(xPos.X, yStart.Y);
                        ctx.LineTo(xPos.X, yPos.Y);
                        ctx.Stroke();
                    }
                }
            }
            ctx.Restore();
        }
Esempio n. 2
0
        /// <summary>
        /// Calculates the physical (not world) separation between abscissa values.
        /// </summary>
        /// <param name="cd">Candle adapter containing data</param>
        /// <param name="xAxis">Physical x axis the data is plotted against.</param>
        /// <returns>physical separation between abscissa values.</returns>
        private static double CalculatePhysicalSeparation(CandleDataAdapter cd, PhysicalAxis xAxis)
        {
            if (cd.Count > 1)
            {
                double xPos1   = (xAxis.WorldToPhysical(((PointOLHC)cd[0]).X, false)).X;
                double xPos2   = (xAxis.WorldToPhysical(((PointOLHC)cd[1]).X, false)).X;
                double minDist = xPos2 - xPos1;

                if (cd.Count > 2)                    // to be pretty sure we get the smallest gap.
                {
                    double xPos3 = (xAxis.WorldToPhysical(((PointOLHC)cd[2]).X, false)).X;
                    if (xPos3 - xPos2 < minDist)
                    {
                        minDist = xPos3 - xPos2;
                    }

                    if (cd.Count > 3)
                    {
                        double xPos4 = (xAxis.WorldToPhysical(((PointOLHC)cd[3]).X, false)).X;
                        if (xPos4 - xPos3 < minDist)
                        {
                            minDist = xPos4 - xPos3;
                        }
                    }
                }
                return(minDist);
            }
            return(0);
        }
Esempio n. 3
0
 /// <summary>
 /// Does all the work in drawing grid lines.
 /// </summary>
 /// <param name="ctx">The graphics context with which to draw</param>
 /// <param name="axis">TODO</param>
 /// <param name="orthogonalAxis">TODO</param>
 /// <param name="a">the list of world values to draw grid lines at.</param>
 /// <param name="horizontal">true if want horizontal lines, false otherwise.</param>
 /// <param name="color">the color to draw the grid lines.</param>
 private void DrawGridLines(Context ctx,
                            PhysicalAxis axis, PhysicalAxis orthogonalAxis,
                            System.Collections.ArrayList a, bool horizontal)
 {
     for (int i = 0; i < a.Count; ++i)
     {
         Point p1 = axis.WorldToPhysical((double)a[i], true);
         Point p2 = p1;
         Point p3 = orthogonalAxis.PhysicalMax;
         Point p4 = orthogonalAxis.PhysicalMin;
         if (horizontal)
         {
             p1.Y = p4.Y;
             p2.Y = p3.Y;
         }
         else
         {
             p1.X = p4.X;
             p2.X = p3.X;
         }
         ctx.MoveTo(p1);
         ctx.LineTo(p2);
     }
     ctx.SetLineWidth(1);
     ctx.SetColor(gridColor);
     ctx.SetLineDash(0, gridDash);
     ctx.Stroke();
 }
Esempio n. 4
0
        /// <summary>
        /// Draws the horizontal line plot using the Context and the x and y axes specified
        /// </summary>
        /// <param name="ctx">The Context with which to draw.</param>
        /// <param name="xAxis">The X-Axis to draw against.</param>
        /// <param name="yAxis">The Y-Axis to draw against.</param>
        public void Draw(Context ctx, PhysicalAxis xAxis, PhysicalAxis yAxis)
        {
            double xMin = xAxis.PhysicalMin.X;
            double xMax = xAxis.PhysicalMax.X;

            xMin += pixelIndent_;
            xMax -= pixelIndent_;

            double length       = Math.Abs(xMax - xMin);
            double lengthDiff   = length - length * scale_;
            double indentAmount = lengthDiff / 2;

            xMin += indentAmount;
            xMax -= indentAmount;

            double yPos = yAxis.WorldToPhysical(value_, false).Y;

            ctx.Save();
            ctx.SetLineWidth(1);
            ctx.SetColor(color_);
            ctx.MoveTo(xMin, yPos);
            ctx.LineTo(xMax, yPos);
            ctx.Stroke();
            ctx.Restore();

            // todo:  clip and proper logic for flipped axis min max.
        }
Esempio n. 5
0
        /// <summary>
        /// Draws the vertical line using the Context and the x and y axes specified
        /// </summary>
        /// <param name="ctx">The Context with which to draw.</param>
        /// <param name="xAxis">The X-Axis to draw against.</param>
        /// <param name="yAxis">The Y-Axis to draw against.</param>
        public void Draw(Context ctx, PhysicalAxis xAxis, PhysicalAxis yAxis)
        {
            double yMin = yAxis.PhysicalMin.Y;
            double yMax = yAxis.PhysicalMax.Y;

            yMin -= PixelIndent;
            yMax += PixelIndent;

            double length       = Math.Abs(yMax - yMin);
            double lengthDiff   = length - length * LengthScale;
            double indentAmount = lengthDiff / 2;

            yMin -= indentAmount;
            yMax += indentAmount;

            double xPos = xAxis.WorldToPhysical(AbscissaValue, false).X;

            ctx.Save();
            ctx.SetLineWidth(1);
            ctx.SetColor(Color);
            ctx.MoveTo(xPos, yMin);
            ctx.LineTo(xPos, yMax);
            ctx.Stroke();
            ctx.Restore();
            // todo:  clip and proper logic for flipped axis min max.
        }
Esempio n. 6
0
        /// <summary>
        /// Draws the marker on a plot surface.
        /// </summary>
        /// <param name="ctx">The Drawing Context with which to draw</param>
        /// <param name="xAxis">The X-Axis to draw against.</param>
        /// <param name="yAxis">The Y-Axis to draw against.</param>
        public void Draw(Context ctx, PhysicalAxis xAxis, PhysicalAxis yAxis)
        {
            Point point = new Point(
                xAxis.WorldToPhysical(x_, true).X,
                yAxis.WorldToPhysical(y_, true).Y);

            marker_.Draw(ctx, point.X, point.Y);
        }
Esempio n. 7
0
        /// <summary>
        /// Draws the histogram.
        /// </summary>
        /// <param name="ctx">The Drawing Context with which to draw</param>
        /// <param name="xAxis">The X-Axis to draw against.</param>
        /// <param name="yAxis">The Y-Axis to draw against.</param>
        public void Draw(Context ctx, PhysicalAxis xAxis, PhysicalAxis yAxis)
        {
            double yoff;
            SequenceAdapter data = new SequenceAdapter (DataSource, DataMember, OrdinateData, AbscissaData);

            ctx.Save ();
            ctx.SetLineWidth (1);

            for (int i=0; i<data.Count; ++i ) {

                // (1) determine the top left hand point of the bar (assuming not centered)
                Point p1 = data[i];
                if (double.IsNaN(p1.X) || double.IsNaN(p1.Y)) {
                    continue;
                }

                // (2) determine the top right hand point of the bar (assuming not centered)
                Point p2 = Point.Zero;;
                if (i+1 != data.Count) {
                    p2 = data[i+1];
                    if (double.IsNaN(p2.X) || double.IsNaN(p2.Y)) {
                        continue;
                    }
                    p2.Y = p1.Y;
                }
                else if (i != 0) {
                    p2 = data[i-1];
                    if (double.IsNaN(p2.X) || double.IsNaN(p2.Y)) {
                        continue;
                    }
                    double offset = p1.X - p2.X;
                    p2.X = p1.X + offset;
                    p2.Y = p1.Y;
                }
                else {
                    double offset = 1.0;
                    p2.X = p1.X + offset;
                    p2.Y = p1.Y;
                }

                // (3) now account for plots this may be stacked on top of.
                HistogramPlot currentPlot = this;
                yoff = 0.0;
                double yval = 0.0;
                while (currentPlot.IsStacked) {
                    SequenceAdapter stackedToData = new SequenceAdapter (
                        currentPlot.stackedTo.DataSource,
                        currentPlot.stackedTo.DataMember,
                        currentPlot.stackedTo.OrdinateData,
                        currentPlot.stackedTo.AbscissaData );

                    yval += stackedToData[i].Y;
                    yoff = yAxis.WorldToPhysical (yval, false).Y;
                    p1.Y += stackedToData[i].Y;
                    p2.Y += stackedToData[i].Y;
                    currentPlot = currentPlot.stackedTo;
                }

                // (4) now account for centering
                if (Center) {
                    double offset = (p2.X - p1.X) / 2.0;
                    p1.X -= offset;
                    p2.X -= offset;
                }

                // (5) now account for BaseOffset (shift of bar sideways).
                p1.X += BaseOffset;
                p2.X += BaseOffset;

                // (6) now get physical coordinates of top two points.
                Point xPos1 = xAxis.WorldToPhysical (p1.X, false);
                Point yPos1 = yAxis.WorldToPhysical (p1.Y, false);
                Point xPos2 = xAxis.WorldToPhysical (p2.X, false);

                if (IsStacked) {
                    currentPlot = this;
                    while (currentPlot.IsStacked) {
                        currentPlot = currentPlot.stackedTo;
                    }
                    baseWidth = currentPlot.baseWidth;
                }

                double width = xPos2.X - xPos1.X;
                double height;
                if (IsStacked) {
                    height = -yPos1.Y+yoff;
                }
                else {
                    height = -yPos1.Y+yAxis.PhysicalMin.Y;
                }

                double xoff = (1.0 - baseWidth)/2.0*width;
                Rectangle bar = new Rectangle (xPos1.X+xoff, yPos1.Y, width-2*xoff, height);

                ctx.Rectangle (bar);
                if (Filled) {
                    if (bar.Height != 0 && bar.Width != 0) {
                        if (FillGradient != null) {
                            // Scale FillGradient to bar rectangle
                            double sX = bar.X + fillGradient.StartPoint.X * bar.Width;
                            double sY = bar.Y + fillGradient.StartPoint.Y * bar.Height;
                            double eX = bar.X + fillGradient.EndPoint.X * bar.Width;
                            double eY = bar.Y + fillGradient.EndPoint.Y * bar.Height;
                            LinearGradient g = new LinearGradient (sX, sY, eX, eY);
                            g.AddColorStop (0, FillGradient.StartColor);
                            g.AddColorStop (1, FillGradient.EndColor);
                            ctx.Pattern = g;
                        } else {
                            ctx.SetColor (FillColor);
                        }
                        ctx.FillPreserve ();
                    }
                }
                ctx.SetColor (BorderColor);
                ctx.Stroke ();
            }
            ctx.Restore ();
        }
Esempio n. 8
0
        /// <summary>
        /// Draws the candle plot with the specified Drawing Context and X,Y axes
        /// </summary>
        /// <param name="ctx">The Drawing Context with which to draw</param>
        /// <param name="xAxis">The physical X-Axis to draw against</param>
        /// <param name="yAxis">The physical Y-Axis to draw against</param>
        public void Draw(Context ctx, PhysicalAxis xAxis, PhysicalAxis yAxis)
        {
            CandleDataAdapter cd = new CandleDataAdapter(DataSource, DataMember,
                                                         AbscissaData, OpenData, LowData, HighData, CloseData);

            double offset = 0;

            if (Centered)
            {
                offset = CalculatePhysicalSeparation(cd, xAxis) / 2;
            }

            double addAmount  = StickWidth / 2;
            double stickWidth = StickWidth;

            if (StickWidth == AutoScaleStickWidth)
            {
                // default
                addAmount  = 2;
                stickWidth = 4;

                double minDist = CalculatePhysicalSeparation(cd, xAxis);

                addAmount  = minDist / 3;
                stickWidth = addAmount * 2;
            }

            ctx.Save();
            ctx.SetLineWidth(1);

            /*
             * // brant hyatt proposed.
             * if (Style == Styles.Stick)
             * {
             *      p.Width = stickWidth;
             *      addAmount = stickWidth + 2;
             * }
             */

            for (int i = 0; i < cd.Count; ++i)
            {
                PointOLHC point = (PointOLHC)cd [i];
                if ((!double.IsNaN(point.Open)) && (!double.IsNaN(point.High)) &&
                    (!double.IsNaN(point.Low)) && (!double.IsNaN(point.Close)))
                {
                    double xPos = (xAxis.WorldToPhysical(point.X, false)).X;

                    if (xPos + offset + addAmount < xAxis.PhysicalMin.X || xAxis.PhysicalMax.X < xPos + offset - addAmount)
                    {
                        continue;
                    }

                    double yLo  = (yAxis.WorldToPhysical(point.Low, false)).Y;
                    double yHi  = (yAxis.WorldToPhysical(point.High, false)).Y;
                    double yOpn = (yAxis.WorldToPhysical(point.Open, false)).Y;
                    double yCls = (yAxis.WorldToPhysical(point.Close, false)).Y;

                    if (Style == Styles.Stick)
                    {
                        /*
                         * // brant hyatt proposed.
                         * if (i > 0)
                         * {
                         *      if ( ((PointOLHC)cd[i]).Close > ((PointOLHC)cd[i-1]).Close)
                         *      {
                         *              p.Color = BullishColor;
                         *      }
                         *      else
                         *      {
                         *              p.Color = BearishColor;
                         *      }
                         * }
                         */
                        ctx.SetColor(Color);
                        ctx.MoveTo(xPos + offset, yLo);
                        ctx.LineTo(xPos + offset, yHi);                                 // Low to High line

                        ctx.MoveTo(xPos - addAmount + offset, yOpn);
                        ctx.LineTo(xPos + offset, yOpn);                                // Open line

                        ctx.MoveTo(xPos + addAmount + offset, yCls);
                        ctx.LineTo(xPos + offset, yCls);                                // Close line
                        ctx.Stroke();
                    }
                    else if (Style == Styles.Filled)
                    {
                        ctx.MoveTo(xPos + offset, yLo);
                        ctx.LineTo(xPos + offset, yHi);
                        ctx.Stroke();
                        if (yOpn > yCls)
                        {
                            ctx.SetColor(BullishColor);
                            ctx.Rectangle(xPos - addAmount + offset, yCls, stickWidth, yOpn - yCls);
                            ctx.FillPreserve();
                            ctx.SetColor(Color);
                            ctx.Stroke();
                        }
                        else if (yOpn < yCls)
                        {
                            ctx.SetColor(BearishColor);
                            ctx.Rectangle(xPos - addAmount + offset, yOpn, stickWidth, yCls - yOpn);
                            ctx.FillPreserve();
                            ctx.SetColor(Color);
                            ctx.Stroke();
                        }
                        else                            // Cls == Opn
                        {
                            ctx.MoveTo(xPos - addAmount + offset, yOpn);
                            ctx.LineTo(xPos - addAmount + stickWidth + offset, yCls);
                            ctx.Stroke();
                        }
                    }
                }
            }
            ctx.Restore();
        }
Esempio n. 9
0
        /// <summary>
        /// Draws the step plot using a Drawing Context against the provided x and y axes.
        /// </summary>
        /// <param name="ctx">The Drawing Context with which to draw.</param>
        /// <param name="xAxis">The X-Axis to draw against.</param>
        /// <param name="yAxis">The Y-Axis to draw against.</param>
        public virtual void Draw(Context ctx, PhysicalAxis xAxis, PhysicalAxis yAxis )
        {
            SequenceAdapter data =
                new SequenceAdapter (DataSource, DataMember, OrdinateData, AbscissaData);

            double leftCutoff = xAxis.PhysicalToWorld(xAxis.PhysicalMin, false);
            double rightCutoff = xAxis.PhysicalToWorld(xAxis.PhysicalMax, false);

            ctx.Save ();
            ctx.SetColor (Color);
            ctx.SetLineWidth (1);

            for (int i=0; i<data.Count; ++i) {
                Point p1 = data[i];
                if (Double.IsNaN(p1.X) || Double.IsNaN(p1.Y)) {
                    continue;
                }

                Point p2;
                Point p3;
                if (i+1 != data.Count) {
                    p2 = data[i+1];
                    if (Double.IsNaN(p2.X) || Double.IsNaN(p2.Y)) {
                        continue;
                    }
                    p2.Y = p1.Y;
                    p3 = data[i+1];
                }
                else {
                    // Check that we are not dealing with a DataSource of 1 point.
                    // This check is done here so it is only checked on the end
                    // condition and not for every point in the DataSource.
                    if (data.Count > 1) {
                        p2 = data[i - 1];
                    }
                    else {
                        p2 = p1;
                    }
                    double offset = p1.X - p2.X;
                    p2.X = p1.X + offset;
                    p2.Y = p1.Y;
                    p3 = p2;
                }

                if (centre) {
                    double offset = ( p2.X - p1.X ) / 2.0;
                    p1.X -= offset;
                    p2.X -= offset;
                    p3.X -= offset;
                }

                Point xPos1 = xAxis.WorldToPhysical (p1.X, false);
                Point yPos1 = yAxis.WorldToPhysical (p1.Y, false);
                Point xPos2 = xAxis.WorldToPhysical (p2.X, false);
                Point yPos2 = yAxis.WorldToPhysical (p2.Y, false);
                Point xPos3 = xAxis.WorldToPhysical (p3.X, false);
                Point yPos3 = yAxis.WorldToPhysical (p3.Y, false);

                // do horizontal clipping here, to speed up
                if ((p1.X<leftCutoff && p2.X<leftCutoff && p3.X<leftCutoff) || (p1.X>rightCutoff && p2.X>rightCutoff && p3.X>rightCutoff)) {
                    continue;
                }

                if (!this.hideHorizontalSegments) {
                    if (scale != 1) {
                        double middle = (xPos2.X + xPos1.X) / 2;
                        double width = xPos2.X - xPos1.X;
                        width *= this.scale;
                        ctx.MoveTo (middle-width/2, yPos1.Y);
                        ctx.LineTo (middle+width/2, yPos2.Y);
                    }
                    else {
                        ctx.MoveTo (xPos1.X, yPos1.Y);
                        ctx.LineTo (xPos2.X, yPos2.Y);
                    }
                    ctx.Stroke ();
                }

                if (!this.hideVerticalSegments) {
                    ctx.MoveTo (xPos2.X, yPos2.Y);
                    ctx.LineTo (xPos3.X, yPos3.Y);
                    ctx.Stroke ();
                }
            }
            ctx.Restore ();
        }
Esempio n. 10
0
        /// <summary>
        /// Draw using the Drawing Context and Axes supplied
        /// </summary>
        /// <remarks>TODO: block positions may be off by a pixel or so. maybe. Re-think calculations</remarks>
        public void Draw(Context ctx, PhysicalAxis xAxis, PhysicalAxis yAxis)
        {
            if (data == null || data.GetLength(0) == 0 || data.GetLength(1) == 0)
            {
                return;
            }

            double worldWidth          = xAxis.Axis.WorldMax - xAxis.Axis.WorldMin;
            double numBlocksHorizontal = worldWidth / xStep;
            double worldHeight         = yAxis.Axis.WorldMax - yAxis.Axis.WorldMin;
            double numBlocksVertical   = worldHeight / yStep;

            double physicalWidth = xAxis.PhysicalMax.X - xAxis.PhysicalMin.X;
            double blockWidth    = physicalWidth / numBlocksHorizontal;
            bool   wPositive     = true;

            if (blockWidth < 0.0)
            {
                wPositive = false;
            }
            blockWidth = Math.Abs(blockWidth) + 1;

            double physicalHeight = yAxis.PhysicalMax.Y - yAxis.PhysicalMin.Y;
            double blockHeight    = physicalHeight / numBlocksVertical;
            bool   hPositive      = true;

            if (blockHeight < 0.0)
            {
                hPositive = false;
            }
            blockHeight = Math.Abs(blockHeight) + 1;

            ctx.Save();
            for (int i = 0; i < data.GetLength(0); ++i)
            {
                for (int j = 0; j < data.GetLength(1); ++j)
                {
                    double wX = (double)j * xStep + xStart;
                    double wY = (double)i * yStep + yStart;
                    if (!hPositive)
                    {
                        wY += yStep;
                    }
                    if (!wPositive)
                    {
                        wX += xStep;
                    }
                    if (Center)
                    {
                        wX -= xStep / 2.0;
                        wY -= yStep / 2.0;
                    }
                    Color color = Gradient.GetColor((data[i, j] - DataMin) / (DataMax - DataMin));
                    ctx.SetColor(color);
                    double x = xAxis.WorldToPhysical(wX, false).X;
                    double y = yAxis.WorldToPhysical(wY, false).Y;
                    ctx.Rectangle(x, y, blockWidth, blockHeight);
                    ctx.Fill();
                }
            }
            ctx.Restore();
        }
Esempio n. 11
0
        /// <summary>
        /// Draws the candle plot with the specified Drawing Context and X,Y axes
        /// </summary>
        /// <param name="ctx">The Drawing Context with which to draw</param>
        /// <param name="xAxis">The physical X-Axis to draw against</param>
        /// <param name="yAxis">The physical Y-Axis to draw against</param>
        public void Draw(Context ctx, PhysicalAxis xAxis, PhysicalAxis yAxis)
        {
            CandleDataAdapter cd = new CandleDataAdapter (DataSource, DataMember,
                AbscissaData, OpenData, LowData, HighData, CloseData);

            double offset = 0;
            if (Centered) {
                offset = CalculatePhysicalSeparation (cd,xAxis)/2;
            }

            double addAmount = StickWidth/2;
            double stickWidth = StickWidth;

            if (StickWidth == AutoScaleStickWidth) {
                // default
                addAmount = 2;
                stickWidth = 4;

                double minDist = CalculatePhysicalSeparation (cd, xAxis);

                addAmount = minDist / 3;
                stickWidth = addAmount * 2;
            }

            ctx.Save ();
            ctx.SetLineWidth (1);

            /*
            // brant hyatt proposed.
            if (Style == Styles.Stick)
            {
                p.Width = stickWidth;
                addAmount = stickWidth + 2;
            }
            */

            for (int i=0; i<cd.Count; ++i) {

                PointOLHC point = (PointOLHC)cd [i];
                if ((!double.IsNaN (point.Open)) && (!double.IsNaN(point.High))
                 && (!double.IsNaN (point.Low)) && (!double.IsNaN(point.Close))) {
                    double xPos = (xAxis.WorldToPhysical (point.X, false)).X;

                    if (xPos + offset + addAmount < xAxis.PhysicalMin.X || xAxis.PhysicalMax.X < xPos + offset - addAmount) {
                        continue;
                    }

                    double yLo  = (yAxis.WorldToPhysical (point.Low,  false)).Y;
                    double yHi  = (yAxis.WorldToPhysical (point.High, false)).Y;
                    double yOpn = (yAxis.WorldToPhysical (point.Open, false)).Y;
                    double yCls = (yAxis.WorldToPhysical (point.Close,false)).Y;

                    if (Style == Styles.Stick) {
                        /*
                        // brant hyatt proposed.
                        if (i > 0)
                        {
                            if ( ((PointOLHC)cd[i]).Close > ((PointOLHC)cd[i-1]).Close)
                            {
                                p.Color = BullishColor;
                            }
                            else
                            {
                                p.Color = BearishColor;
                            }
                        }
                        */
                        ctx.SetColor (Color);
                        ctx.MoveTo (xPos+offset, yLo);
                        ctx.LineTo (xPos+offset, yHi);		// Low to High line

                        ctx.MoveTo (xPos-addAmount+offset, yOpn);
                        ctx.LineTo (xPos+offset, yOpn);		// Open line

                        ctx.MoveTo (xPos+addAmount+offset, yCls);
                        ctx.LineTo (xPos+offset, yCls);		// Close line
                        ctx.Stroke ();
                    }
                    else if (Style == Styles.Filled) {
                        ctx.MoveTo (xPos+offset, yLo);
                        ctx.LineTo (xPos+offset, yHi);
                        ctx.Stroke ();
                        if (yOpn > yCls) {
                            ctx.SetColor (BullishColor);
                            ctx.Rectangle (xPos-addAmount+offset, yCls, stickWidth, yOpn - yCls);
                            ctx.FillPreserve ();
                            ctx.SetColor (Color);
                            ctx.Stroke ();
                        }
                        else if (yOpn < yCls) {
                            ctx.SetColor (BearishColor);
                            ctx.Rectangle (xPos-addAmount+offset, yOpn, stickWidth, yCls - yOpn);
                            ctx.FillPreserve ();
                            ctx.SetColor (Color);
                            ctx.Stroke ();
                        }
                        else {	// Cls == Opn
                            ctx.MoveTo (xPos-addAmount+offset, yOpn);
                            ctx.LineTo (xPos-addAmount+stickWidth+offset, yCls);
                            ctx.Stroke ();
                        }
                    }
                }
            }
            ctx.Restore ();
        }
Esempio n. 12
0
        /// <summary>
        /// Draws the arrow on a plot surface.
        /// </summary>
        /// <param name="ctx">the Drawing Context with which to draw</param>
        /// <param name="xAxis">The X-Axis to draw against.</param>
        /// <param name="yAxis">The Y-Axis to draw against.</param>
        public void Draw(Context ctx, PhysicalAxis xAxis, PhysicalAxis yAxis )
        {
            if (To.X > xAxis.Axis.WorldMax || To.X < xAxis.Axis.WorldMin) {
                return;
            }
            if (To.Y > yAxis.Axis.WorldMax || To.Y < yAxis.Axis.WorldMin) {
                return;
            }

            ctx.Save ();

            TextLayout layout = new TextLayout ();
            layout.Font = textFont_;
            layout.Text = text_;

            double angle = angle_;
            if (angle_ < 0.0) {
                int mul = -(int)(angle_ / 360.0) + 2;
                angle = angle_ + 360.0 * (double)mul;
            }

            double normAngle = (double)angle % 360.0;	// angle in range 0 -> 360.

            Point toPoint = new Point (
                xAxis.WorldToPhysical (to_.X, true).X,
                yAxis.WorldToPhysical (to_.Y, true).Y);

            double xDir = Math.Cos (normAngle * 2.0 * Math.PI / 360.0);
            double yDir = Math.Sin (normAngle * 2.0 * Math.PI / 360.0);

            toPoint.X += xDir*headOffset_;
            toPoint.Y += yDir*headOffset_;

            double xOff = physicalLength_ * xDir;
            double yOff = physicalLength_ * yDir;

            Point fromPoint = new Point(
                (int)(toPoint.X + xOff),
                (int)(toPoint.Y + yOff) );

            ctx.SetLineWidth (1);
            ctx.SetColor (arrowColor_);
            ctx.MoveTo (fromPoint);
            ctx.LineTo (toPoint);
            ctx.Stroke ();

            xOff = headSize_ * Math.Cos ((normAngle-headAngle_/2) * 2.0 * Math.PI / 360.0);
            yOff = headSize_ * Math.Sin ((normAngle-headAngle_/2) * 2.0 * Math.PI / 360.0);

            ctx.LineTo (toPoint.X + xOff, toPoint.Y + yOff);

            double xOff2 = headSize_ * Math.Cos ((normAngle+headAngle_/2) * 2.0 * Math.PI / 360.0);
            double yOff2 = headSize_ * Math.Sin ((normAngle+headAngle_/2) * 2.0 * Math.PI / 360.0);

            ctx.LineTo (toPoint.X + xOff2, toPoint.Y + yOff2);
            ctx.LineTo (toPoint);
            ctx.ClosePath ();
            ctx.SetColor (arrowColor_);
            ctx.Fill ();

            Size textSize = layout.GetSize ();
            Size halfSize = new Size (textSize.Width/2, textSize.Height/2);

            double quadrantSlideLength = halfSize.Width + halfSize.Height;

            double quadrantD = normAngle / 90.0;		// integer part gives quadrant.
            int quadrant = (int)quadrantD;				// quadrant in.
            double prop = quadrantD - (double)quadrant;	// proportion of way through this qadrant.
            double dist = prop * quadrantSlideLength;	// distance along quarter of bounds rectangle.

            // now find the offset from the middle of the text box that the
            // rear end of the arrow should end at (reverse this to get position
            // of text box with respect to rear end of arrow).
            //
            // There is almost certainly an elgant way of doing this involving
            // trig functions to get all the signs right, but I'm about ready to
            // drop off to sleep at the moment, so this blatent method will have
            // to do.
            Point offsetFromMiddle = new Point (0, 0);
            switch (quadrant) {
            case 0:
                if (dist > halfSize.Height) {
                    dist -= halfSize.Height;
                    offsetFromMiddle = new Point ( -halfSize.Width + dist, halfSize.Height );
                }
                else {
                    offsetFromMiddle = new Point ( -halfSize.Width, - dist );
                }
                break;
            case 1:
                if (dist > halfSize.Width) {
                    dist -= halfSize.Width;
                    offsetFromMiddle = new Point ( halfSize.Width, halfSize.Height - dist );
                }
                else {
                    offsetFromMiddle = new Point ( dist, halfSize.Height );
                }
                break;
            case 2:
                if (dist > halfSize.Height) {
                    dist -= halfSize.Height;
                    offsetFromMiddle = new Point ( halfSize.Width - dist, -halfSize.Height );
                }
                else {
                    offsetFromMiddle = new Point ( halfSize.Width, -dist );
                }
                break;
            case 3:
                if (dist > halfSize.Width) {
                    dist -= halfSize.Width;
                    offsetFromMiddle = new Point ( -halfSize.Width, -halfSize.Height + dist );
                }
                else {
                    offsetFromMiddle = new Point ( -dist, -halfSize.Height );
                }
                break;
            default:
                throw new XwPlotException( "Programmer error." );
            }

            ctx.SetColor (textColor_);
            double x = fromPoint.X - halfSize.Width - offsetFromMiddle.X;
            double y = fromPoint.Y - halfSize.Height + offsetFromMiddle.Y;
            ctx.DrawTextLayout (layout, x, y);

            ctx.Restore ();
        }
Esempio n. 13
0
        /// <summary>
        /// Draws the arrow on a plot surface.
        /// </summary>
        /// <param name="ctx">the Drawing Context with which to draw</param>
        /// <param name="xAxis">The X-Axis to draw against.</param>
        /// <param name="yAxis">The Y-Axis to draw against.</param>
        public void Draw(Context ctx, PhysicalAxis xAxis, PhysicalAxis yAxis)
        {
            if (To.X > xAxis.Axis.WorldMax || To.X < xAxis.Axis.WorldMin)
            {
                return;
            }
            if (To.Y > yAxis.Axis.WorldMax || To.Y < yAxis.Axis.WorldMin)
            {
                return;
            }

            ctx.Save();

            TextLayout layout = new TextLayout();

            layout.Font = textFont_;
            layout.Text = text_;

            double angle = angle_;

            if (angle_ < 0.0)
            {
                int mul = -(int)(angle_ / 360.0) + 2;
                angle = angle_ + 360.0 * (double)mul;
            }

            double normAngle = (double)angle % 360.0;                   // angle in range 0 -> 360.

            Point toPoint = new Point(
                xAxis.WorldToPhysical(to_.X, true).X,
                yAxis.WorldToPhysical(to_.Y, true).Y);


            double xDir = Math.Cos(normAngle * 2.0 * Math.PI / 360.0);
            double yDir = Math.Sin(normAngle * 2.0 * Math.PI / 360.0);

            toPoint.X += xDir * headOffset_;
            toPoint.Y += yDir * headOffset_;

            double xOff = physicalLength_ * xDir;
            double yOff = physicalLength_ * yDir;

            Point fromPoint = new Point(
                (int)(toPoint.X + xOff),
                (int)(toPoint.Y + yOff));

            ctx.SetLineWidth(1);
            ctx.SetColor(arrowColor_);
            ctx.MoveTo(fromPoint);
            ctx.LineTo(toPoint);
            ctx.Stroke();

            xOff = headSize_ * Math.Cos((normAngle - headAngle_ / 2) * 2.0 * Math.PI / 360.0);
            yOff = headSize_ * Math.Sin((normAngle - headAngle_ / 2) * 2.0 * Math.PI / 360.0);

            ctx.LineTo(toPoint.X + xOff, toPoint.Y + yOff);

            double xOff2 = headSize_ * Math.Cos((normAngle + headAngle_ / 2) * 2.0 * Math.PI / 360.0);
            double yOff2 = headSize_ * Math.Sin((normAngle + headAngle_ / 2) * 2.0 * Math.PI / 360.0);

            ctx.LineTo(toPoint.X + xOff2, toPoint.Y + yOff2);
            ctx.LineTo(toPoint);
            ctx.ClosePath();
            ctx.SetColor(arrowColor_);
            ctx.Fill();

            Size textSize = layout.GetSize();
            Size halfSize = new Size(textSize.Width / 2, textSize.Height / 2);

            double quadrantSlideLength = halfSize.Width + halfSize.Height;

            double quadrantD = normAngle / 90.0;                        // integer part gives quadrant.
            int    quadrant  = (int)quadrantD;                          // quadrant in.
            double prop      = quadrantD - (double)quadrant;            // proportion of way through this qadrant.
            double dist      = prop * quadrantSlideLength;              // distance along quarter of bounds rectangle.

            // now find the offset from the middle of the text box that the
            // rear end of the arrow should end at (reverse this to get position
            // of text box with respect to rear end of arrow).
            //
            // There is almost certainly an elgant way of doing this involving
            // trig functions to get all the signs right, but I'm about ready to
            // drop off to sleep at the moment, so this blatent method will have
            // to do.
            Point offsetFromMiddle = new Point(0, 0);

            switch (quadrant)
            {
            case 0:
                if (dist > halfSize.Height)
                {
                    dist            -= halfSize.Height;
                    offsetFromMiddle = new Point(-halfSize.Width + dist, halfSize.Height);
                }
                else
                {
                    offsetFromMiddle = new Point(-halfSize.Width, -dist);
                }
                break;

            case 1:
                if (dist > halfSize.Width)
                {
                    dist            -= halfSize.Width;
                    offsetFromMiddle = new Point(halfSize.Width, halfSize.Height - dist);
                }
                else
                {
                    offsetFromMiddle = new Point(dist, halfSize.Height);
                }
                break;

            case 2:
                if (dist > halfSize.Height)
                {
                    dist            -= halfSize.Height;
                    offsetFromMiddle = new Point(halfSize.Width - dist, -halfSize.Height);
                }
                else
                {
                    offsetFromMiddle = new Point(halfSize.Width, -dist);
                }
                break;

            case 3:
                if (dist > halfSize.Width)
                {
                    dist            -= halfSize.Width;
                    offsetFromMiddle = new Point(-halfSize.Width, -halfSize.Height + dist);
                }
                else
                {
                    offsetFromMiddle = new Point(-dist, -halfSize.Height);
                }
                break;

            default:
                throw new XwPlotException("Programmer error.");
            }

            ctx.SetColor(textColor_);
            double x = fromPoint.X - halfSize.Width - offsetFromMiddle.X;
            double y = fromPoint.Y - halfSize.Height + offsetFromMiddle.Y;

            ctx.DrawTextLayout(layout, x, y);

            ctx.Restore();
        }
Esempio n. 14
0
        /// <summary>
        /// Draws the step plot using a Drawing Context against the provided x and y axes.
        /// </summary>
        /// <param name="ctx">The Drawing Context with which to draw.</param>
        /// <param name="xAxis">The X-Axis to draw against.</param>
        /// <param name="yAxis">The Y-Axis to draw against.</param>
        public virtual void Draw(Context ctx, PhysicalAxis xAxis, PhysicalAxis yAxis)
        {
            SequenceAdapter data =
                new SequenceAdapter(DataSource, DataMember, OrdinateData, AbscissaData);

            double leftCutoff  = xAxis.PhysicalToWorld(xAxis.PhysicalMin, false);
            double rightCutoff = xAxis.PhysicalToWorld(xAxis.PhysicalMax, false);

            ctx.Save();
            ctx.SetColor(Color);
            ctx.SetLineWidth(1);

            for (int i = 0; i < data.Count; ++i)
            {
                Point p1 = data[i];
                if (Double.IsNaN(p1.X) || Double.IsNaN(p1.Y))
                {
                    continue;
                }

                Point p2;
                Point p3;
                if (i + 1 != data.Count)
                {
                    p2 = data[i + 1];
                    if (Double.IsNaN(p2.X) || Double.IsNaN(p2.Y))
                    {
                        continue;
                    }
                    p2.Y = p1.Y;
                    p3   = data[i + 1];
                }
                else
                {
                    // Check that we are not dealing with a DataSource of 1 point.
                    // This check is done here so it is only checked on the end
                    // condition and not for every point in the DataSource.
                    if (data.Count > 1)
                    {
                        p2 = data[i - 1];
                    }
                    else
                    {
                        p2 = p1;
                    }
                    double offset = p1.X - p2.X;
                    p2.X = p1.X + offset;
                    p2.Y = p1.Y;
                    p3   = p2;
                }

                if (centre)
                {
                    double offset = (p2.X - p1.X) / 2.0;
                    p1.X -= offset;
                    p2.X -= offset;
                    p3.X -= offset;
                }

                Point xPos1 = xAxis.WorldToPhysical(p1.X, false);
                Point yPos1 = yAxis.WorldToPhysical(p1.Y, false);
                Point xPos2 = xAxis.WorldToPhysical(p2.X, false);
                Point yPos2 = yAxis.WorldToPhysical(p2.Y, false);
                Point xPos3 = xAxis.WorldToPhysical(p3.X, false);
                Point yPos3 = yAxis.WorldToPhysical(p3.Y, false);

                // do horizontal clipping here, to speed up
                if ((p1.X < leftCutoff && p2.X < leftCutoff && p3.X < leftCutoff) || (p1.X > rightCutoff && p2.X > rightCutoff && p3.X > rightCutoff))
                {
                    continue;
                }

                if (!this.hideHorizontalSegments)
                {
                    if (scale != 1)
                    {
                        double middle = (xPos2.X + xPos1.X) / 2;
                        double width  = xPos2.X - xPos1.X;
                        width *= this.scale;
                        ctx.MoveTo(middle - width / 2, yPos1.Y);
                        ctx.LineTo(middle + width / 2, yPos2.Y);
                    }
                    else
                    {
                        ctx.MoveTo(xPos1.X, yPos1.Y);
                        ctx.LineTo(xPos2.X, yPos2.Y);
                    }
                    ctx.Stroke();
                }

                if (!this.hideVerticalSegments)
                {
                    ctx.MoveTo(xPos2.X, yPos2.Y);
                    ctx.LineTo(xPos3.X, yPos3.Y);
                    ctx.Stroke();
                }
            }
            ctx.Restore();
        }
Esempio n. 15
0
 /// <summary>
 /// Transforms the given world point to physical coordinates
 /// </summary>
 /// <param name="x">x coordinate of world point to transform.</param>
 /// <param name="y">y coordinate of world point to transform.</param>
 /// <returns>the corresponding physical point.</returns>
 public Point Transform(double x, double y)
 {
     return(new Point(xAxis_.WorldToPhysical(x, false).X, yAxis_.WorldToPhysical(y, false).Y));
 }
Esempio n. 16
0
        /// <summary>
        /// Draws the histogram.
        /// </summary>
        /// <param name="ctx">The Drawing Context with which to draw</param>
        /// <param name="xAxis">The X-Axis to draw against.</param>
        /// <param name="yAxis">The Y-Axis to draw against.</param>
        public void Draw(Context ctx, PhysicalAxis xAxis, PhysicalAxis yAxis)
        {
            double          yoff;
            SequenceAdapter data = new SequenceAdapter(DataSource, DataMember, OrdinateData, AbscissaData);

            ctx.Save();
            ctx.SetLineWidth(1);

            for (int i = 0; i < data.Count; ++i)
            {
                // (1) determine the top left hand point of the bar (assuming not centered)
                Point p1 = data[i];
                if (double.IsNaN(p1.X) || double.IsNaN(p1.Y))
                {
                    continue;
                }

                // (2) determine the top right hand point of the bar (assuming not centered)
                Point p2 = Point.Zero;;
                if (i + 1 != data.Count)
                {
                    p2 = data[i + 1];
                    if (double.IsNaN(p2.X) || double.IsNaN(p2.Y))
                    {
                        continue;
                    }
                    p2.Y = p1.Y;
                }
                else if (i != 0)
                {
                    p2 = data[i - 1];
                    if (double.IsNaN(p2.X) || double.IsNaN(p2.Y))
                    {
                        continue;
                    }
                    double offset = p1.X - p2.X;
                    p2.X = p1.X + offset;
                    p2.Y = p1.Y;
                }
                else
                {
                    double offset = 1.0;
                    p2.X = p1.X + offset;
                    p2.Y = p1.Y;
                }

                // (3) now account for plots this may be stacked on top of.
                HistogramPlot currentPlot = this;
                yoff = 0.0;
                double yval = 0.0;
                while (currentPlot.IsStacked)
                {
                    SequenceAdapter stackedToData = new SequenceAdapter(
                        currentPlot.stackedTo.DataSource,
                        currentPlot.stackedTo.DataMember,
                        currentPlot.stackedTo.OrdinateData,
                        currentPlot.stackedTo.AbscissaData);

                    yval       += stackedToData[i].Y;
                    yoff        = yAxis.WorldToPhysical(yval, false).Y;
                    p1.Y       += stackedToData[i].Y;
                    p2.Y       += stackedToData[i].Y;
                    currentPlot = currentPlot.stackedTo;
                }

                // (4) now account for centering
                if (Center)
                {
                    double offset = (p2.X - p1.X) / 2.0;
                    p1.X -= offset;
                    p2.X -= offset;
                }

                // (5) now account for BaseOffset (shift of bar sideways).
                p1.X += BaseOffset;
                p2.X += BaseOffset;

                // (6) now get physical coordinates of top two points.
                Point xPos1 = xAxis.WorldToPhysical(p1.X, false);
                Point yPos1 = yAxis.WorldToPhysical(p1.Y, false);
                Point xPos2 = xAxis.WorldToPhysical(p2.X, false);

                if (IsStacked)
                {
                    currentPlot = this;
                    while (currentPlot.IsStacked)
                    {
                        currentPlot = currentPlot.stackedTo;
                    }
                    baseWidth = currentPlot.baseWidth;
                }

                double width = xPos2.X - xPos1.X;
                double height;
                if (IsStacked)
                {
                    height = -yPos1.Y + yoff;
                }
                else
                {
                    height = -yPos1.Y + yAxis.PhysicalMin.Y;
                }

                double    xoff = (1.0 - baseWidth) / 2.0 * width;
                Rectangle bar  = new Rectangle(xPos1.X + xoff, yPos1.Y, width - 2 * xoff, height);

                ctx.Rectangle(bar);
                if (Filled)
                {
                    if (bar.Height != 0 && bar.Width != 0)
                    {
                        if (FillGradient != null)
                        {
                            // Scale FillGradient to bar rectangle
                            double         sX = bar.X + fillGradient.StartPoint.X * bar.Width;
                            double         sY = bar.Y + fillGradient.StartPoint.Y * bar.Height;
                            double         eX = bar.X + fillGradient.EndPoint.X * bar.Width;
                            double         eY = bar.Y + fillGradient.EndPoint.Y * bar.Height;
                            LinearGradient g  = new LinearGradient(sX, sY, eX, eY);
                            g.AddColorStop(0, FillGradient.StartColor);
                            g.AddColorStop(1, FillGradient.EndColor);
                            ctx.Pattern = g;
                        }
                        else
                        {
                            ctx.SetColor(FillColor);
                        }
                        ctx.FillPreserve();
                    }
                }
                ctx.SetColor(BorderColor);
                ctx.Stroke();
            }
            ctx.Restore();
        }
Esempio n. 17
0
        /// <summary>
        /// Draws the plot using the Drawing Context and X, Y axes supplied.
        /// </summary>
        public override void Draw(Context ctx, PhysicalAxis xAxis, PhysicalAxis yAxis)
        {
            SequenceAdapter data =
                new SequenceAdapter (this.DataSource, this.DataMember, this.OrdinateData, this.AbscissaData);

            TextDataAdapter textData =
                new TextDataAdapter (this.DataSource, this.DataMember, this.TextData);

            TextLayout layout = new TextLayout ();
            layout.Font = Font;

            ctx.Save ();
            ctx.SetColor (Colors.Black);

            for (int i=0; i<data.Count; ++i) {
                try {
                    Point p = data[i];
                    if (!Double.IsNaN(p.X) && !Double.IsNaN(p.Y)) {
                        Point xPos = xAxis.WorldToPhysical (p.X, false);
                        Point yPos = yAxis.WorldToPhysical (p.Y, false);
                        // first plot the marker
                        Marker.Draw (ctx, xPos.X, yPos.Y);
                        // then the label
                        if (textData[i] != "") {
                            layout.Text = textData[i];
                            Size size = layout.GetSize ();
                            switch (labelTextPosition) {
                            case LabelPositions.Above:
                                p.X = xPos.X-size.Width/2;
                                p.Y = yPos.Y-size.Height-Marker.Size*2/3;
                                break;
                            case LabelPositions.Below:
                                p.X = xPos.X-size.Width/2;
                                p.Y = yPos.Y+Marker.Size*2/3;
                                break;
                            case LabelPositions.Left:
                                p.X = xPos.X-size.Width-Marker.Size*2/3;
                                p.Y = yPos.Y-size.Height/2;
                                break;
                            case LabelPositions.Right:
                                p.X = xPos.X+Marker.Size*2/3;
                                p.Y = yPos.Y-size.Height/2;
                                break;
                            }
                            ctx.DrawTextLayout (layout, p);
                        }
                    }
                }
                catch {
                    throw new XwPlotException ("Error in TextPlot.Draw");
                }
            }
            ctx.Restore ();
        }
Esempio n. 18
0
        /// <summary>
        /// Draws the plot using the Drawing Context and X, Y axes supplied.
        /// </summary>
        public override void Draw(Context ctx, PhysicalAxis xAxis, PhysicalAxis yAxis)
        {
            SequenceAdapter data =
                new SequenceAdapter(this.DataSource, this.DataMember, this.OrdinateData, this.AbscissaData);

            TextDataAdapter textData =
                new TextDataAdapter(this.DataSource, this.DataMember, this.TextData);

            TextLayout layout = new TextLayout();

            layout.Font = Font;

            ctx.Save();
            ctx.SetColor(Colors.Black);

            for (int i = 0; i < data.Count; ++i)
            {
                try {
                    Point p = data[i];
                    if (!Double.IsNaN(p.X) && !Double.IsNaN(p.Y))
                    {
                        Point xPos = xAxis.WorldToPhysical(p.X, false);
                        Point yPos = yAxis.WorldToPhysical(p.Y, false);
                        // first plot the marker
                        Marker.Draw(ctx, xPos.X, yPos.Y);
                        // then the label
                        if (textData[i] != "")
                        {
                            layout.Text = textData[i];
                            Size size = layout.GetSize();
                            switch (labelTextPosition)
                            {
                            case LabelPositions.Above:
                                p.X = xPos.X - size.Width / 2;
                                p.Y = yPos.Y - size.Height - Marker.Size * 2 / 3;
                                break;

                            case LabelPositions.Below:
                                p.X = xPos.X - size.Width / 2;
                                p.Y = yPos.Y + Marker.Size * 2 / 3;
                                break;

                            case LabelPositions.Left:
                                p.X = xPos.X - size.Width - Marker.Size * 2 / 3;
                                p.Y = yPos.Y - size.Height / 2;
                                break;

                            case LabelPositions.Right:
                                p.X = xPos.X + Marker.Size * 2 / 3;
                                p.Y = yPos.Y - size.Height / 2;
                                break;
                            }
                            ctx.DrawTextLayout(layout, p);
                        }
                    }
                }
                catch {
                    throw new XwPlotException("Error in TextPlot.Draw");
                }
            }
            ctx.Restore();
        }
Esempio n. 19
0
        /// <summary>
        /// Does all the work in drawing grid lines.
        /// </summary>
        /// <param name="ctx">The graphics context with which to draw</param>
        /// <param name="axis">TODO</param>
        /// <param name="orthogonalAxis">TODO</param>
        /// <param name="a">the list of world values to draw grid lines at.</param>
        /// <param name="horizontal">true if want horizontal lines, false otherwise.</param>
        /// <param name="color">the color to draw the grid lines.</param>
        private void DrawGridLines(Context ctx,
			PhysicalAxis axis, PhysicalAxis orthogonalAxis,
			System.Collections.ArrayList a, bool horizontal)
        {
            for (int i=0; i<a.Count; ++i) {
                Point p1 = axis.WorldToPhysical ((double)a[i], true);
                Point p2 = p1;
                Point p3 = orthogonalAxis.PhysicalMax;
                Point p4 = orthogonalAxis.PhysicalMin;
                if (horizontal) {
                    p1.Y = p4.Y;
                    p2.Y = p3.Y;
                }
                else {
                    p1.X = p4.X;
                    p2.X = p3.X;
                }
                ctx.MoveTo (p1);
                ctx.LineTo (p2);
            }
            ctx.SetLineWidth (1);
            ctx.SetColor (gridColor);
            ctx.SetLineDash (0, gridDash);
            ctx.Stroke ();
        }
Esempio n. 20
0
        /// <summary>
        /// Draws the marker on a plot surface.
        /// </summary>
        /// <param name="ctx">The Drawing Context with which to draw</param>
        /// <param name="xAxis">The X-Axis to draw against.</param>
        /// <param name="yAxis">The Y-Axis to draw against.</param>
        public void Draw(Context ctx, PhysicalAxis xAxis, PhysicalAxis yAxis)
        {
            Point point = new Point (
                xAxis.WorldToPhysical (x_, true).X,
                yAxis.WorldToPhysical (y_, true ).Y);

            marker_.Draw (ctx, point.X, point.Y );
        }
Esempio n. 21
0
        /// <summary>
        /// Draw using the Drawing Context and Axes supplied
        /// </summary>
        /// <remarks>TODO: block positions may be off by a pixel or so. maybe. Re-think calculations</remarks>
        public void Draw(Context ctx, PhysicalAxis xAxis, PhysicalAxis yAxis)
        {
            if (data==null || data.GetLength(0) == 0 || data.GetLength(1) == 0) {
                return;
            }

            double worldWidth = xAxis.Axis.WorldMax - xAxis.Axis.WorldMin;
            double numBlocksHorizontal = worldWidth / xStep;
            double worldHeight = yAxis.Axis.WorldMax - yAxis.Axis.WorldMin;
            double numBlocksVertical = worldHeight / yStep;

            double physicalWidth = xAxis.PhysicalMax.X - xAxis.PhysicalMin.X;
            double blockWidth = physicalWidth / numBlocksHorizontal;
            bool wPositive = true;
            if (blockWidth < 0.0) {
                wPositive = false;
            }
            blockWidth = Math.Abs (blockWidth)+1;

            double physicalHeight = yAxis.PhysicalMax.Y - yAxis.PhysicalMin.Y;
            double blockHeight = physicalHeight / numBlocksVertical;
            bool hPositive = true;
            if (blockHeight < 0.0) {
                hPositive = false;
            }
            blockHeight = Math.Abs(blockHeight)+1;

            ctx.Save ();
            for (int i=0; i<data.GetLength(0); ++i) {
                for (int j=0; j<data.GetLength(1); ++j) {
                    double wX = (double)j*xStep + xStart;
                    double wY = (double)i*yStep + yStart;
                    if (!hPositive) {
                        wY += yStep;
                    }
                    if (!wPositive ) {
                        wX += xStep;
                    }
                    if (Center) {
                        wX -= xStep/2.0;
                        wY -= yStep/2.0;
                    }
                    Color color = Gradient.GetColor ((data[i,j]-DataMin)/(DataMax-DataMin));
                    ctx.SetColor (color);
                    double x = xAxis.WorldToPhysical(wX,false).X;
                    double y = yAxis.WorldToPhysical(wY,false).Y;
                    ctx.Rectangle (x, y, blockWidth, blockHeight);
                    ctx.Fill ();
                }
            }
            ctx.Restore ();
        }
Esempio n. 22
0
        /// <summary>
        /// Calculates the physical (not world) separation between abscissa values.
        /// </summary>
        /// <param name="cd">Candle adapter containing data</param>
        /// <param name="xAxis">Physical x axis the data is plotted against.</param>
        /// <returns>physical separation between abscissa values.</returns>
        private static double CalculatePhysicalSeparation(CandleDataAdapter cd, PhysicalAxis xAxis)
        {
            if (cd.Count > 1) {
                double xPos1 = (xAxis.WorldToPhysical( ((PointOLHC)cd[0]).X, false )).X;
                double xPos2 = (xAxis.WorldToPhysical( ((PointOLHC)cd[1]).X, false )).X;
                double minDist = xPos2 - xPos1;

                if (cd.Count > 2) {  // to be pretty sure we get the smallest gap.
                    double xPos3 = (xAxis.WorldToPhysical(((PointOLHC)cd[2]).X, false)).X;
                    if (xPos3 - xPos2 < minDist) {
                        minDist = xPos3 - xPos2;
                    }

                    if (cd.Count > 3) {
                        double xPos4 = (xAxis.WorldToPhysical(((PointOLHC)cd[3]).X, false)).X;
                        if (xPos4 - xPos3 < minDist) {
                            minDist = xPos4 - xPos3;
                        }
                    }
                }
                return minDist;
            }
            return 0;
        }
Esempio n. 23
0
        /// <summary>
        /// Draws the point plot using the Drawing Context and x and y axes supplied
        /// </summary>
        /// <param name="ctx">The Drawing Context with which to draw.</param>
        /// <param name="xAxis">The X-Axis to draw against.</param>
        /// <param name="yAxis">The Y-Axis to draw against.</param>
        public virtual void Draw(Context ctx, PhysicalAxis xAxis, PhysicalAxis yAxis)
        {
            SequenceAdapter data_ = new SequenceAdapter (DataSource, DataMember, OrdinateData, AbscissaData );

            double leftCutoff_ = xAxis.PhysicalMin.X - marker.Size;
            double rightCutoff_ = xAxis.PhysicalMax.X + marker.Size;

            ctx.Save ();
            ctx.SetColor (marker.LineColor);
            ctx.SetLineWidth (marker.LineWidth);

            for (int i=0; i<data_.Count; ++i) {
                if (!Double.IsNaN(data_[i].X) && !Double.IsNaN(data_[i].Y)) {
                    Point xPos = xAxis.WorldToPhysical (data_[i].X, false);
                    if (xPos.X < leftCutoff_ || rightCutoff_ < xPos.X) {
                        continue;
                    }

                    Point yPos = yAxis.WorldToPhysical (data_[i].Y, false);
                    marker.Draw (ctx, xPos.X, yPos.Y);
                    if (marker.DropLine) {
                        Point yMin = new Point (data_[i].X, Math.Max (0.0, yAxis.Axis.WorldMin));
                        Point yStart = yAxis.WorldToPhysical (yMin.Y, false);
                        ctx.MoveTo (xPos.X, yStart.Y);
                        ctx.LineTo (xPos.X, yPos.Y);
                        ctx.Stroke ();
                    }
                }
            }
            ctx.Restore ();
        }
Esempio n. 24
0
        /// <summary>
        /// Draws the horizontal line plot using the Context and the x and y axes specified
        /// </summary>
        /// <param name="ctx">The Context with which to draw.</param>
        /// <param name="xAxis">The X-Axis to draw against.</param>
        /// <param name="yAxis">The Y-Axis to draw against.</param>
        public void Draw(Context ctx, PhysicalAxis xAxis, PhysicalAxis yAxis)
        {
            double xMin = xAxis.PhysicalMin.X;
            double xMax = xAxis.PhysicalMax.X;

            xMin += pixelIndent_;
            xMax -= pixelIndent_;

            double length = Math.Abs (xMax - xMin);
            double lengthDiff = length - length*scale_;
            double indentAmount = lengthDiff/2;

            xMin += indentAmount;
            xMax -= indentAmount;

            double yPos = yAxis.WorldToPhysical (value_, false).Y;

            ctx.Save ();
            ctx.SetLineWidth (1);
            ctx.SetColor (color_);
            ctx.MoveTo (xMin, yPos);
            ctx.LineTo (xMax, yPos);
            ctx.Stroke ();
            ctx.Restore ();

            // todo:  clip and proper logic for flipped axis min max.
        }
Esempio n. 25
0
        /// <summary>
        /// Draws the vertical line using the Context and the x and y axes specified
        /// </summary>
        /// <param name="ctx">The Context with which to draw.</param>
        /// <param name="xAxis">The X-Axis to draw against.</param>
        /// <param name="yAxis">The Y-Axis to draw against.</param>
        public void Draw(Context ctx, PhysicalAxis xAxis, PhysicalAxis yAxis)
        {
            double yMin = yAxis.PhysicalMin.Y;
            double yMax = yAxis.PhysicalMax.Y;

            yMin -= PixelIndent;
            yMax += PixelIndent;

            double length = Math.Abs (yMax - yMin);
            double lengthDiff = length - length*LengthScale;
            double indentAmount = lengthDiff/2;

            yMin -= indentAmount;
            yMax += indentAmount;

            double xPos = xAxis.WorldToPhysical (AbscissaValue, false).X;

            ctx.Save ();
            ctx.SetLineWidth (1);
            ctx.SetColor (Color);
            ctx.MoveTo (xPos, yMin);
            ctx.LineTo (xPos, yMax);
            ctx.Stroke ();
            ctx.Restore ();
            // todo:  clip and proper logic for flipped axis min max.
        }