Exemple #1
0
        private double FromStartTime(double D)
        {
            if (OneDay == -1)
            {
                OneDay = IntradayInfo.GetOpenTimePerDay();
            }
            double d1 = StartTime.ToOADate();

            if ((int)d1 == (int)D)
            {
                return(IntradayInfo.OneDayTime(D) - IntradayInfo.OneDayTime(d1));
            }
            else
            {
                return(OneDay - IntradayInfo.OneDayTime(d1) + IntradayInfo.OneDayTime(D) +
                       IntradayInfo.RawDaysBetween(d1, D) * OneDay);
            }
        }
Exemple #2
0
        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
            {
            }
        }
Exemple #3
0
        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;
                        }
                    }
                }
            }
        }