コード例 #1
0
        private void SetBestFormat(FormulaCanvas Canvas, FormulaArea Area, int Start)
        {
            int k = Start;

            for (int i = 0; i < LabelValues.Length; i++)
            {
                double d = (LabelValues[i] / MultiplyFactor);
                k = FormulaHelper.TestBestFormat(d, k);
            }

            bool b = false;

            for (int i = 0; i < Area.FormulaDataArray.Count; i++)
            {
                FormulaRenderType frt = (Area.FormulaDataArray[i] as FormulaData).RenderType;
                if (frt == FormulaRenderType.STOCK)
                {
                    double d = GetLastValue(Canvas, Area, i);
                    if (!double.IsNaN(d))
                    {
                        k = FormulaHelper.TestBestFormat(d, k);
                        b = true;
                    }
                }
            }

            if (format != null && format.Length > 1 && !b)
            {
                format = "f" + format.Substring(1);
            }
            else
            {
                format = "f" + k;
            }
        }
コード例 #2
0
ファイル: FormulaAxisX.cs プロジェクト: Bulletz4mysa/NBTrade
 public void Render(FormulaCanvas Canvas, FormulaArea fa)
 {
     if (this.Visible)
     {
         if (fa.AxisY.AxisPos == AxisPos.Left)
         {
             this.Rect.X--;
         }
         Graphics currentGraph = Canvas.CurrentGraph;
         this.Back.Render(currentGraph, this.Rect);
     }
     if (this.MajorTick.Visible || this.MinorTick.Visible)
     {
         double[] data = fa.Parent.DataProvider["DATE"];
         this.fdDate        = new FormulaData(data);
         this.fdDate.Canvas = Canvas;
         this.fdDate.AxisY  = fa.AxisY;
         PointF[] points = this.fdDate.GetPoints();
         this.MajorTick.DataCycle          = this.DataCycle;
         this.MajorTick.Format             = this.Format;
         this.MajorTick.DateFormatProvider = this.DateFormatProvider;
         this.MajorTick.DrawXAxisTick(Canvas, data, this.fdDate, points, this, this.IntradayInfo);
         this.MinorTick.DrawXAxisTick(Canvas, data, this.fdDate, points, this, this.IntradayInfo);
     }
 }
コード例 #3
0
        /// <summary>
        /// Render the X-Axis
        /// </summary>
        /// <param name="Canvas">FormulaCanvas</param>
        /// <param name="fa">FormulaArea</param>
        public void Render(FormulaCanvas Canvas, FormulaArea fa)
        {
            if (Visible)
            {
                if (fa.AxisY.AxisPos == AxisPos.Left)
                {
                    Rect.X--;
                }
                Graphics g = Canvas.CurrentGraph;
                Back.Render(g, Rect);
            }

            if (majorTick.Visible || minorTick.Visible)
            {
                double[] Date;
                Date          = fa.Parent.DataProvider["DATE"];
                fdDate        = new FormulaData(Date);
                fdDate.Canvas = Canvas;
                fdDate.AxisY  = fa.AxisY;

                PointF[] pfs = fdDate.GetPoints();

                majorTick.DataCycle          = DataCycle;
                majorTick.Format             = Format;
                majorTick.DateFormatProvider = DateFormatProvider;

                majorTick.DrawXAxisTick(Canvas, Date, fdDate, pfs, this, IntradayInfo);
                minorTick.DrawXAxisTick(Canvas, Date, fdDate, pfs, this, IntradayInfo);
            }
        }
コード例 #4
0
        public int CalcLabelWidth(FormulaCanvas Canvas)
        {
            Graphics currentGraph = Canvas.CurrentGraph;

            this.CalcLableLine(Canvas);
            int num = -2147483648;

            if (this.AutoFormat)
            {
                if ((this.MaxY <= 10.0) && (this.MinY < 1.0))
                {
                    this.format = "f3";
                }
                else
                {
                    this.format = "f2";
                }
            }
            for (int i = -1; i < this.LabelValues.Length; i++)
            {
                string str;
                if (i < 0)
                {
                    str = this.MultiplyFactorToString();
                }
                else
                {
                    str = (this.LabelValues[i] / this.MultiplyFactor).ToString(this.Format);
                }
                num = Math.Max(num, (int)currentGraph.MeasureString(str, this.LabelFont).Width);
            }
            return(num);
        }
コード例 #5
0
        private void CalcLableLine(FormulaCanvas Canvas)
        {
            double minY = this.MinY;
            double maxY = this.MaxY;

            if (this.ShowAsPercent)
            {
                minY = (minY / this.RefValue) - 1.0;
                maxY = (maxY / this.RefValue) - 1.0;
            }
            double d    = maxY - minY;
            double num4 = Math.Pow(10.0, Math.Floor(Math.Log10(d)) + 1.0);

            double[] numArray = new double[] { 2.0, 2.5, 2.0 };
            for (int i = 0; (((d / num4) * Canvas.LabelHeight) * 3.0) < Canvas.Rect.Height; i++)
            {
                num4 /= numArray[i % numArray.Length];
            }
            double num6 = Math.Floor((double)(minY / num4)) * num4;
            double num7 = Math.Ceiling((double)(maxY / num4)) * num4;
            int    num8 = (int)((num7 - num6) / num4);

            this.LabelPos    = new float[num8 + 1];
            this.LabelValues = new double[num8 + 1];
            for (int j = 0; j <= num8; j++)
            {
                this.LabelValues[j] = num6 + (num4 * j);
                if (this.ShowAsPercent)
                {
                    this.LabelPos[j] = this.CalcY((this.LabelValues[j] + 1.0) * this.RefValue);
                }
                else
                {
                    this.LabelPos[j] = this.CalcY(this.LabelValues[j]);
                }
            }
            if (this.AutoMultiply && !this.ShowAsPercent)
            {
                this.MultiplyFactor = 1.0;
                int[] numArray2 = new int[] { this.ZeroLog10(minY), this.ZeroLog10(maxY) };
                if (Math.Sign(numArray2[1]) != Math.Sign(numArray2[0]))
                {
                    numArray2[0] = 0;
                }
                foreach (int num10 in numArray2)
                {
                    if (num10 > 3)
                    {
                        this.MultiplyFactor = Math.Max(this.MultiplyFactor, Math.Pow(10.0, (double)(num10 - 3)));
                    }
                    else if (num10 < -1)
                    {
                        this.MultiplyFactor = Math.Min(this.MultiplyFactor, Math.Pow(10.0, (double)(num10 + 1)));
                    }
                }
            }
        }
コード例 #6
0
        /// <summary>
        /// Calc Y-axis width
        /// </summary>
        /// <param name="Canvas"></param>
        /// <returns></returns>
        public int CalcLabelWidth(FormulaCanvas Canvas, FormulaArea Area)
        {
            Graphics g = Canvas.CurrentGraph;

            CalcLableLine(Canvas);
            int    LabelWidth = int.MinValue;
            string s;

            int Start = 0;

            if (AutoFormat)
            {
                if (MaxY <= 10 && MinY < 1)
                {
                    Start = 3;
                }
                else if (MaxY <= 100)
                {
                    Start = 2;
                }
                else if (MaxY <= 1000)
                {
                    Start = 1;
                }
                else
                {
                    Start = 0;
                }
                format = "Z" + Start;
            }
            if (format.StartsWith("Z"))
            {
                SetBestFormat(Canvas, Area, Start);
            }

            for (int i = -1; i < LabelValues.Length; i++)
            {
                if (i < 0)
                {
                    s = MultiplyFactorToString();
                }
                else
                {
                    double d = (LabelValues[i] / MultiplyFactor);
                    s = FormulaHelper.FormatDouble(d, format);
                }
                LabelWidth = Math.Max(LabelWidth, (int)g.MeasureString(s, LabelFont).Width);
            }
            return(LabelWidth + majorTick.TickWidth);
        }
コード例 #7
0
        private double GetLastValue(FormulaCanvas Canvas, FormulaArea Area, int LineIndex, out bool IsUp)
        {
            LatestValueType lvt = Area.Parent.LatestValueType;
            FormulaData     f   = Area.FormulaDataArray[LineIndex];
            double          d   = double.NaN;

            IsUp = true;
            if (Area.AxisYs[f.AxisYIndex] == this &&
                ((lvt == LatestValueType.All && f.ValueTextMode != ValueTextMode.None /*!f.TextInvisible*/) ||
                 ((lvt == LatestValueType.All || lvt == LatestValueType.StockOnly) && f.RenderType == FormulaRenderType.STOCK) ||
                 (lvt == LatestValueType.Custom && f.LastValueInAxis)))
            {
                int Start = Math.Max(0, Canvas.Start);
                if (f.Length > Start)
                {
                    int LastIndex = f.Length - 1 - Start;
                    for (int k = f.Length - 1 - Start; k >= 0; k--)
                    {
                        if (!double.IsNaN(f[k]))
                        {
                            LastIndex = k;
                            break;
                        }
                    }

                    d = f[LastIndex];
                    if (LastIndex > 0)
                    {
                        if (f[LastIndex - 1] > d)
                        {
                            IsUp = false;
                        }
                    }
                }
            }
            return(d);
        }
コード例 #8
0
        /// <summary>
        /// Render Y-axis
        /// </summary>
        /// <param name="Canvas"></param>
        /// <param name="Area"></param>
        public void Render(FormulaCanvas Canvas, FormulaArea Area)
        {
            CalcLableLine(Canvas);
            Rectangle R = FrameRect;            //Canvas.FrameRect;
            Graphics  g = Canvas.CurrentGraph;

            int X = R.Left;

            if (AxisPos == AxisPos.Left)
            {
                X = R.Right;
            }

            int w1 = majorTick.TickWidth;

            if (majorTick.FullTick)
            {
                w1 = R.Width;
            }
            if (majorTick.Inside)
            {
                w1 = -w1;
            }

            int w2 = MinorTick.TickWidth;

            if (MinorTick.FullTick)
            {
                w2 = R.Width;
            }
            if (MinorTick.Inside)
            {
                w2 = -w2;
            }

            if (AxisPos == AxisPos.Left)
            {
                w1 = -w1;
                w2 = -w2;
            }

            Back.Render(g, R);

            if (!LineBinded)
            {
                return;
            }

            Pen MajorLinePen = majorTick.LinePen.GetPen();
            Pen MajorTickPen = majorTick.TickPen.GetPen();
            Pen MinorLinePen = minorTick.LinePen.GetPen();
            Pen MinorTickPen = minorTick.TickPen.GetPen();

            float LastY = float.MaxValue;
            Brush LB    = labelBrush.GetBrush();

            for (int i = 0; i < LabelPos.Length; i++)
            {
                if (LabelPos[i] >= Canvas.Rect.Top && LabelPos[i] <= Canvas.Rect.Bottom)
                {
                    int    TextX     = X;
                    double d         = (LabelValues[i] / MultiplyFactor);
                    string s         = FormulaHelper.FormatDouble(d, format);
                    SizeF  LabelSize = g.MeasureString(s, LabelFont);
                    if (AxisPos == AxisPos.Left)
                    {
                        TextX -= (int)LabelSize.Width;
                        if (w1 < 0)
                        {
                            TextX += w1;
                        }
                    }
                    else
                    {
                        if (w1 > 0)
                        {
                            TextX += w1;
                        }
                    }
                    float TextY = LabelPos[i] - Canvas.LabelHeight / 2;

                    if (majorTick.ShowText && LastY - TextY > LabelSize.Height)
                    {
                        g.DrawString(
                            s,
                            labelFont,
                            LB,
                            TextX,
                            TextY);
                        LastY = TextY;
                    }

                    if (majorTick.ShowLine)
                    {
                        g.DrawLine(MajorLinePen, Canvas.Rect.Left, LabelPos[i], Canvas.Rect.Right, LabelPos[i]);
                    }

                    if (majorTick.ShowTick)
                    {
                        g.DrawLine(MajorTickPen,
                                   X, LabelPos[i],
                                   X + w1, LabelPos[i]);
                    }
                }

                if (minorTick.Visible && !double.IsInfinity(LabelPos[i]))
                {
                    if (i != LabelPos.Length - 1)
                    {
                        int TickCount = MinorTick.Count;
                        if (minorTick.MinimumPixel != 0)
                        {
                            TickCount = (int)((LabelPos[i] - LabelPos[i + 1]) / MinorTick.MinimumPixel);
                        }

                        if (minorTick.ShowTick)
                        {
                            for (float d1 = LabelPos[i]; d1 > LabelPos[i + 1]; d1 += (float)(LabelPos[i + 1] - LabelPos[i]) / TickCount)
                            {
                                if (d1 >= R.Top && d1 <= R.Bottom)
                                {
                                    g.DrawLine(MinorTickPen,
                                               X, d1,
                                               X + w2, d1);
                                }
                            }
                        }
                    }
                }
            }

//			if (customTick.Visible)
//			{
//				for(int i=0; i<CustomPos.Length; i++)
//				{
//					if (customTick.ShowText && LastY-TextY>LabelSize.Height)
//					{
//						g.DrawString(
//							s,
//							labelFont,
//							LB,
//							TextX,
//							TextY);
//						LastY = TextY;
//					}
//
//					if (customTick.ShowLine)
//						g.DrawLine(MajorLinePen,Canvas.Rect.Left,CustomPos[i],Canvas.Rect.Right,CustomPos[i]);
//				}
//			}

            // Draw multiply factor
            if (MultiplyFactor != 1)
            {
                string    s  = MultiplyFactorToString();
                Rectangle MR = R;
                MR.Y = (int)(MR.Bottom - Canvas.LabelHeight - 2);
                if (Area.AxisX.Visible)
                {
                    MR.Y -= (int)(Canvas.LabelHeight / 2 + 1);
                }
                MR.Height = (int)Canvas.LabelHeight;
                MR.Width  = (int)g.MeasureString(s, LabelFont).Width + 1;

                if (AxisPos == AxisPos.Left)
                {
                    MR.Offset(R.Width - MR.Width - 2, 0);
                }

                MultiplyBack.Render(g, MR);
                g.DrawString(s, LabelFont, LB, MR);
            }

            //Draw selected frame
            if (Area.Selected)
            {
                if (Area.SelectedPen != null)
                {
                    Rectangle SelectRect = R;
                    SelectRect.Inflate(-1, -1);
                    g.DrawRectangle(Area.SelectedPen, SelectRect);
                }
            }

            LatestValueType lvt = Area.Parent.LatestValueType;

            if (lvt != LatestValueType.None)
            {
                for (int i = 0; i < Area.FormulaDataArray.Count; i++)
                {
                    bool   IsUp;
                    double d = GetLastValue(Canvas, Area, i, out IsUp);
                    if (!double.IsNaN(d))
                    {
//					}
                        FormulaData f = Area.FormulaDataArray[i];
//					if (Area.AxisYs[f.AxisYIndex]==this &&
//						((lvt==LatestValueType.All && !f.TextInvisible) ||
//						((lvt==LatestValueType.All || lvt==LatestValueType.StockOnly) && f.RenderType==FormulaRenderType.STOCK) ||
//						(lvt==LatestValueType.Custom && f.LastValueInAxis)	))
//					{
                        FormulaLabel fl = Area.Labels[2];
                        if (lvt != LatestValueType.StockOnly)
                        {
                            fl = (FormulaLabel)fl.Clone();
                            Pen p = Area.GetCurrentPen(f, i);
                            fl.BGColor = Color.FromArgb(255, p.Color);
                            if (fl.BGColor == Color.Empty)
                            {
                                fl.BGColor = Color.White;
                            }
                            fl.SetProperTextColor();
                        }
//						int Start = Math.Max(0,Canvas.Start);
//						if (f.Length>Start)
//						{
//							int LastIndex = f.Length-1-Start;
//							for(int k = f.Length-1-Start; k>=0; k--)
//								if (!double.IsNaN(f[k]))
//								{
//									LastIndex = k;
//									break;
//								}
//
//							double d = f[LastIndex];
                        if (lvt == LatestValueType.StockOnly)
                        {
//								if (LastIndex>0)
//									if (f[LastIndex-1]>d)
                            if (!IsUp)
                            {
                                fl = Area.Labels[1];
                            }
                        }
                        string       s  = " " + FormulaHelper.FormatDouble(d / MultiplyFactor, format);
                        FormulaAlign fa = FormulaAlign.Left;
                        if (AxisPos == AxisPos.Left)
                        {
                            fa = FormulaAlign.Right;
                        }
                        fl.DrawString(g, s, LabelFont, fl.TextBrush, VerticalAlign.Bottom, fa, new PointF(X, CalcY(d)), false);
//						}
                    }
                }
            }
        }
コード例 #9
0
        private double GetLastValue(FormulaCanvas Canvas, FormulaArea Area, int LineIndex)
        {
            bool IsUp;

            return(GetLastValue(Canvas, Area, LineIndex, out IsUp));
        }
コード例 #10
0
        private void CalcLableLine(FormulaCanvas Canvas)
        {
            double CalcMinY = this.MinY;
            double CalcMaxY = this.MaxY;

            if (ShowAsPercent && !double.IsNaN(RefValue))
            {
                CalcMinY = CalcMinY / RefValue - 1;
                CalcMaxY = CalcMaxY / RefValue - 1;
            }

            double SpanY = CalcMaxY - CalcMinY;

            double Step = Math.Pow(10, Math.Floor(Math.Log10(SpanY)) + 1);

            double[] DivStep = { 2, 2.5, 2 };

            if (IsBond && Step < 1)
            {
                Step = 1;
            }
            for (int k = 0; SpanY / Step * Canvas.LabelHeight * 3 < Canvas.Rect.Height; k++)
            {
                if (IsBond && Step <= 1)
                {
                    Step /= 2;
                }
                else
                {
                    Step /= DivStep[k % DivStep.Length];
                }
            }

            double LabelMinY = Math.Floor(CalcMinY / Step) * Step;
            double LabelMaxY = Math.Ceiling(CalcMaxY / Step) * Step;

            int N = (int)((LabelMaxY - LabelMinY) / Step);

            bool IsCustom = CustomLine != null && CustomLine.Length > 0;

            if (IsCustom)
            {
                N = CustomLine.Length - 1;
            }

            LabelPos    = new float[N + 1];
            LabelValues = new double[N + 1];
            for (int i = 0; i <= N; i++)
            {
                if (IsCustom)
                {
                    LabelValues[i] = CustomLine[i];
                }
                else
                {
                    LabelValues[i] = LabelMinY + Step * i;
                }
                if (ShowAsPercent && !double.IsNaN(RefValue))
                {
                    LabelPos[i] = CalcY((LabelValues[i] + 1) * RefValue);
                }
                else
                {
                    LabelPos[i] = CalcY(LabelValues[i]);
                }
            }

            if (AutoMultiply && !ShowAsPercent)
            {
                MultiplyFactor = 1;
                int[] L = { ZeroLog10(CalcMinY), ZeroLog10(CalcMaxY) };
                if (Math.Sign(L[1]) != Math.Sign(L[0]))
                {
                    L[0] = 0;
                }
                foreach (int i in L)
                {
                    if (i > 3)
                    {
                        MultiplyFactor = Math.Max(MultiplyFactor, Math.Pow(10, i - 3));
                    }
                    else if (i < -1)
                    {
                        MultiplyFactor = Math.Min(MultiplyFactor, Math.Pow(10, i + 1));
                    }
                }
            }
        }
コード例 #11
0
        public void Render(FormulaCanvas Canvas, FormulaArea Area)
        {
            this.CalcLableLine(Canvas);
            Rectangle frameRect    = this.FrameRect;
            Graphics  currentGraph = Canvas.CurrentGraph;
            int       left         = frameRect.Left;

            if (this.AxisPos == Easychart.Finance.AxisPos.Left)
            {
                left = frameRect.Right;
            }
            int tickWidth = this.MajorTick.TickWidth;

            if (this.MajorTick.FullTick)
            {
                tickWidth = frameRect.Width;
            }
            if (this.MajorTick.Inside)
            {
                tickWidth = -tickWidth;
            }
            int width = this.MinorTick.TickWidth;

            if (this.MinorTick.FullTick)
            {
                width = frameRect.Width;
            }
            if (this.MinorTick.Inside)
            {
                width = -width;
            }
            if (this.AxisPos == Easychart.Finance.AxisPos.Left)
            {
                tickWidth = -tickWidth;
                width     = -width;
            }
            this.Back.Render(currentGraph, frameRect);
            float maxValue = float.MaxValue;

            for (int i = 0; i < this.LabelPos.Length; i++)
            {
                if ((this.LabelPos[i] >= Canvas.Rect.Top) && (this.LabelPos[i] <= Canvas.Rect.Bottom))
                {
                    int    num6 = left;
                    string text = (this.LabelValues[i] / this.MultiplyFactor).ToString(this.Format);
                    SizeF  ef   = currentGraph.MeasureString(text, this.LabelFont);
                    if (this.AxisPos == Easychart.Finance.AxisPos.Left)
                    {
                        num6 -= (int)ef.Width;
                        if (tickWidth < 0)
                        {
                            num6 += tickWidth;
                        }
                    }
                    else if (tickWidth > 0)
                    {
                        num6 += tickWidth;
                    }
                    float y = this.LabelPos[i] - (Canvas.LabelHeight / 2f);
                    if ((maxValue - y) > ef.Height)
                    {
                        currentGraph.DrawString(text, this.LabelFont, this.LabelBrush, (float)num6, y);
                        maxValue = y;
                    }
                    if (this.MajorTick.ShowLine)
                    {
                        currentGraph.DrawLine(this.MajorTick.LinePen, (float)Canvas.Rect.Left, this.LabelPos[i], (float)Canvas.Rect.Right, this.LabelPos[i]);
                    }
                    if (this.MajorTick.ShowTick)
                    {
                        currentGraph.DrawLine(this.MajorTick.TickPen, (float)left, this.LabelPos[i], (float)(left + tickWidth), this.LabelPos[i]);
                    }
                }
                if ((this.MinorTick.Visible && !double.IsInfinity((double)this.LabelPos[i])) && (i != (this.LabelPos.Length - 1)))
                {
                    int count = this.MinorTick.Count;
                    if (this.MinorTick.MinimumPixel != 0)
                    {
                        count = (int)((this.LabelPos[i] - this.LabelPos[i + 1]) / ((float)this.MinorTick.MinimumPixel));
                    }
                    for (float j = this.LabelPos[i]; j > this.LabelPos[i + 1]; j += (this.LabelPos[i + 1] - this.LabelPos[i]) / ((float)count))
                    {
                        if ((j >= frameRect.Top) && (j <= frameRect.Bottom))
                        {
                            currentGraph.DrawLine(this.MinorTick.TickPen, (float)left, j, (float)(left + width), j);
                        }
                    }
                }
            }
            if (this.MultiplyFactor != 1.0)
            {
                string    str2 = this.MultiplyFactorToString();
                Rectangle r    = frameRect;
                r.Y = (int)((r.Bottom - Canvas.LabelHeight) - 2f);
                if (Area.AxisX.Visible)
                {
                    r.Y -= (int)((Canvas.LabelHeight / 2f) + 1f);
                }
                r.Height = (int)Canvas.LabelHeight;
                r.Width  = ((int)currentGraph.MeasureString(str2, this.LabelFont).Width) + 1;
                if (this.AxisPos == Easychart.Finance.AxisPos.Left)
                {
                    r.Offset((frameRect.Width - r.Width) - 2, 0);
                }
                this.MultiplyBack.Render(currentGraph, r);
                currentGraph.DrawString(str2, this.LabelFont, this.LabelBrush, r);
            }
            if (Area.Selected && (Area.SelectedPen != null))
            {
                Rectangle rect = frameRect;
                rect.Inflate(-1, -1);
                currentGraph.DrawRectangle(Area.SelectedPen, rect);
            }
            LatestValueType latestValueType = Area.Parent.LatestValueType;

            if (latestValueType != LatestValueType.None)
            {
                for (int k = 0; k < Area.FormulaDataArray.Count; k++)
                {
                    FormulaData data = Area.FormulaDataArray[k];
                    if ((!data.TextInvisible || (data.RenderType == FormulaRenderType.STOCK)) && (((latestValueType == LatestValueType.All) || ((latestValueType == LatestValueType.StockOnly) && (Area.AxisYs[data.AxisYIndex] == this))) || ((latestValueType == LatestValueType.Custom) && data.LastValueInAxis)))
                    {
                        FormulaLabel label = Area.Labels[2];
                        if (latestValueType != LatestValueType.StockOnly)
                        {
                            label = (FormulaLabel)label.Clone();
                            Pen currentPen = Area.GetCurrentPen(k);
                            label.BGColor = currentPen.Color;
                            if (label.BGColor == Color.Empty)
                            {
                                label.BGColor = Color.White;
                            }
                            label.SetProperTextColor();
                        }
                        if (data.Length > Canvas.Start)
                        {
                            double d = data[(data.Length - 1) - Canvas.Start];
                            if (((latestValueType == LatestValueType.StockOnly) && (data.Length > (Canvas.Start + 1))) && (data[(data.Length - 2) - Canvas.Start] > d))
                            {
                                label = Area.Labels[1];
                            }
                            string       str3  = " " + ((d / this.MultiplyFactor)).ToString(this.Format);
                            FormulaAlign right = FormulaAlign.Left;
                            if (this.AxisPos == Easychart.Finance.AxisPos.Left)
                            {
                                right = FormulaAlign.Right;
                            }
                            label.DrawString(currentGraph, str3, this.LabelFont, label.TextBrush, VerticalAlign.Bottom, right, new PointF((float)left, this.CalcY(d)), false);
                        }
                    }
                }
            }
        }
コード例 #12
0
ファイル: FormulaTick.cs プロジェクト: Bulletz4mysa/NBTrade
        public void DrawXAxisTick(FormulaCanvas Canvas, double[] Date, FormulaData fdDate, PointF[] pfs, FormulaAxisX fax, ExchangeIntraday ei)
        {
            if (DataCycle == null)
            {
                return;
            }

            try
            {
                int      LastCycle   = -1;
                int      NowCycle    = 0;
                string   LastExtDate = "";
                string   NowExtDate;
                int      LastX     = -10000;
                int      LastIndex = -1;
                Graphics g         = Canvas.CurrentGraph;

                double DateSpan = 0;
                if (Date.Length > 0)
                {
                    DateSpan = Date[Date.Length - 1] - Date[0];
                }

                double[] SeqDate = Date;
                if (ei != null && ei.NativeCycle)
                {
                    SeqDate = new double[Date.Length];
                    for (int i = 0; i < SeqDate.Length; i++)
                    {
                        SeqDate[i] = (int)Date[i] + ei.OneDayTime(Date[i]);
                    }
                }

                ArrayList alTick = new ArrayList();
                Font      F      = fax.LabelFont;
                Pen       LP     = LinePen.GetPen();
                Pen       TP     = TickPen.GetPen();
                for (int i = pfs.Length - 1; i >= 0; i--)
                {
                    int      DateIndex = Date.Length - 1 - Math.Max(0, Canvas.Start) - i;
                    double   d         = Date[DateIndex];
                    DateTime D         = DateTime.FromOADate(d);
                    NowCycle = DataCycle.GetSequence(SeqDate[DateIndex]);

                    if (NowCycle != LastCycle)
                    {
                        PointF P = pfs[i];
                        LastCycle = NowCycle;
                        if (ShowLine)
                        {
                            int B = Canvas.Rect.Bottom;
                            if (!fax.Visible)
                            {
                                B = Canvas.FrameRect.Bottom;
                            }
                            g.DrawLine(LP, P.X, Canvas.FrameRect.Top, P.X, B);
                        }

                        if (fax.Visible && ShowTick)
                        {
                            int TickHeight = TickWidth;
                            if (FullTick)
                            {
                                TickHeight = fax.Rect.Height;
                            }
                            if (Inside)
                            {
                                TickHeight = -TickHeight;
                            }
                            g.DrawLine(TP, P.X, fax.Rect.Top, P.X, TickHeight + fax.Rect.Top);
                        }

                        string s  = D.ToString(Format, DateFormatProvider);
                        int    i1 = s.IndexOf('{');
                        int    i2 = s.IndexOf('}');
                        if (i2 > i1)
                        {
                            NowExtDate = s.Substring(i1 + 1, i2 - i1 - 1);
                            if (NowExtDate != LastExtDate)
                            {
                                if (NowExtDate.StartsWith("$"))
                                {
                                    s = s.Remove(i2, s.Length - i2).Remove(i1, 2);
                                }
                                else
                                {
                                    s = s.Remove(i1, 1).Remove(i2 - 1, 1);
                                }
                            }
                            else
                            {
                                s = s.Substring(0, i1) + s.Substring(i2 + 1);
                            }
                            LastExtDate = NowExtDate;
                        }

                        float LabelWidth = g.MeasureString(s, F).Width;
                        float LabelX     = P.X;

                        switch (fax.AxisLabelAlign)
                        {
                        case AxisLabelAlign.TickCenter:
                            LabelX -= LabelWidth / 2;
                            break;

                        case AxisLabelAlign.TickLeft:
                            LabelX -= LabelWidth;
                            break;
                        }
                        if (LabelX < fax.Rect.Left)
                        {
                            LabelX = fax.Rect.Left;
                        }

                        if (fax.Visible && ShowText /*&& LastX+MinimumPixel<LabelX*/)
                        {
                            if (ei == null || ei.ShowFirstXLabel || i < pfs.Length - 1 || DateSpan > 1)
                            {
                                alTick.Add(new object[] { s, LabelX, LabelWidth, d, LastX + MinimumPixel < LabelX });
                                //g.DrawString(s,F,fax.LabelBrush,LabelX,fax.Rect.Top);
                                LastX = (int)(LabelX + LabelWidth);
                            }
                            LastIndex = i;
                        }
                    }             //if (NowCycle!=LastCycle)
                }                 //for

                //Second pass
                for (int i = 0; i < alTick.Count; i++)
                {
                    object[] os = (object[])alTick[i];
                    if (!(bool)os[4])
                    {
                        if ((int)(double)((object[])alTick[i - 1])[3] == (int)(double)((object[])alTick[i])[3])
                        {
                            alTick.RemoveAt(i);
                        }
                        else
                        {
                            alTick.RemoveAt(i - 1);
                        }
                        i--;
                    }
                }

                //Third pass
                Brush lb = fax.LabelBrush.GetBrush();
                for (int i = 0; i < alTick.Count; i++)
                {
                    object[] os = (object[])alTick[i];
                    g.DrawString((string)os[0], F, lb, (float)os[1], fax.Rect.Top);
                }
            }
            catch
            {
            }
        }
コード例 #13
0
ファイル: FormulaTick.cs プロジェクト: Bulletz4mysa/NBTrade
        public void DrawXAxisTick(FormulaCanvas Canvas, double[] Date, FormulaData fdDate, PointF[] pfs, FormulaAxisX fax, ExchangeIntraday ei)
        {
            if (this.DataCycle != null)
            {
                int      num          = 0;
                int      sequence     = 0;
                string   str          = "";
                int      num3         = -10000;
                int      num4         = -1;
                Graphics currentGraph = Canvas.CurrentGraph;
                double   num5         = 0.0;
                if (Date.Length > 0)
                {
                    num5 = Date[Date.Length - 1] - Date[0];
                }
                double[] numArray = Date;
                if ((ei != null) && ei.NativeCycle)
                {
                    numArray = new double[Date.Length];
                    for (int j = 0; j < numArray.Length; j++)
                    {
                        numArray[j] = ((int)Date[j]) + ei.OneDayTime(Date[j]);
                    }
                }
                for (int i = pfs.Length - 1; i >= 0; i--)
                {
                    int      index = ((Date.Length - 1) - Canvas.Start) - i;
                    double   d     = Date[index];
                    DateTime time  = DateTime.FromOADate(d);
                    sequence = this.DataCycle.GetSequence(numArray[index]);
                    if (sequence != num)
                    {
                        PointF tf = pfs[i];
                        num = sequence;
                        if (this.ShowLine)
                        {
                            int bottom = Canvas.Rect.Bottom;
                            if (!fax.Visible)
                            {
                                bottom = Canvas.FrameRect.Bottom;
                            }
                            currentGraph.DrawLine(this.LinePen, tf.X, (float)Canvas.FrameRect.Top, tf.X, (float)bottom);
                        }
                        if (fax.Visible && this.ShowTick)
                        {
                            int tickWidth = this.TickWidth;
                            if (this.FullTick)
                            {
                                tickWidth = fax.Rect.Height;
                            }
                            if (this.Inside)
                            {
                                tickWidth = -tickWidth;
                            }
                            currentGraph.DrawLine(this.TickPen, tf.X, (float)fax.Rect.Top, tf.X, (float)(tickWidth + fax.Rect.Top));
                        }
                        string text       = time.ToString(this.Format, this.DateFormatProvider);
                        int    startIndex = text.IndexOf('{');
                        int    num13      = text.IndexOf('}');
                        if (num13 > startIndex)
                        {
                            string str2 = text.Substring(startIndex + 1, (num13 - startIndex) - 1);
                            if (str2 != str)
                            {
                                text = text.Remove(startIndex, 1).Remove(num13 - 1, 1);
                            }
                            else
                            {
                                text = text.Substring(0, startIndex) + text.Substring(num13 + 1);
                            }
                            str = str2;
                        }
                        Font  labelFont = fax.LabelFont;
                        float width     = currentGraph.MeasureString(text, labelFont).Width;
                        float x         = tf.X;
                        switch (fax.AxisLabelAlign)
                        {
                        case AxisLabelAlign.TickCenter:
                            x -= width / 2f;
                            break;

                        case AxisLabelAlign.TickLeft:
                            x -= width;
                            break;
                        }
                        if (x < fax.Rect.Left)
                        {
                            x = fax.Rect.Left;
                        }
                        if ((fax.Visible && this.ShowText) && ((num3 + this.MinimumPixel) < x))
                        {
                            if (((ei == null) || ei.ShowFirstXLabel) || ((i < (pfs.Length - 1)) || (num5 > 1.0)))
                            {
                                currentGraph.DrawString(text, labelFont, fax.LabelBrush, x, (float)fax.Rect.Top);
                                num3 = (int)(x + width);
                            }
                            num4 = i;
                        }
                    }
                }
            }
        }