Пример #1
0
        public override void PaintValue(PaintValueEventArgs e)
        {
            BrushMapper bm = (BrushMapper)e.Value;

            e.Graphics.FillRectangle(bm.GetBrush(e.Bounds), e.Bounds);
            base.PaintValue(e);
        }
Пример #2
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);
//						}
                    }
                }
            }
        }
Пример #3
0
 public void DrawString(string s, Graphics g, RectangleF Rect)
 {
     g.DrawString(s, textFont, textBrush.GetBrush(Rect), Rect, GetStringFormat());
 }