SmartQuant.FinChart.Chart.Update C# (CSharp) Method

Update() private method

private Update ( Graphics graphics ) : void
graphics System.Drawing.Graphics
return void
        private void Update(Graphics graphics)
        {
            if (this.lastIndex - this.firstIndex + 1 == 0)
                return;
            int num1 = Width - this.canvasLeftOffset - this.canvasRightOffset;
            int height = Height;
            this.intervalWidth = (double)(num1 / (this.lastIndex - this.firstIndex + 1));

            if (this.contentUpdated)
            {
                if (this.bitmap != null)
                    this.bitmap.Dispose();
                this.bitmap = new Bitmap(Width, Height);
                using (var g = Graphics.FromImage(this.bitmap))
                {
                   
                    g.SmoothingMode = SmoothingMode;
                    g.Clear(ChartBackColor);

                    this.graphics = g;
                    int val1 = int.MinValue;
                    foreach (Pad pad in this.pads)
                    {
                        pad.PrepareForUpdate();
                        val1 = Math.Max(val1, pad.AxisGap + 2);
                    }
                    this.canvasRightOffset = Math.Max(val1, this.minAxisGap);
                    foreach (Pad pad in this.pads)
                    {
                        pad.DrawItems = DrawItems;
                        pad.Width = Width - this.canvasRightOffset - this.canvasLeftOffset;
                    }
                    g.FillRectangle(new SolidBrush(this.canvasColor), this.canvasLeftOffset, this.canvasTopOffset, Width - this.canvasRightOffset - this.canvasLeftOffset, this.Height - this.canvasBottomOffset - this.canvasLeftOffset);
                    if (this.polosaDate != DateTime.MinValue)
                    {
                        int num2 = this.ClientX(this.polosaDate);
                        if (num2 > this.canvasLeftOffset && num2 < this.Width - this.canvasRightOffset)
                            g.FillRectangle(new SolidBrush(this.selectedFillHighlightColor), (float)num2 - (float)this.intervalWidth / 2f, this.canvasTopOffset, (float)this.intervalWidth, Height - this.canvasBottomOffset - this.canvasLeftOffset);
                    }
                    g.DrawRectangle(new Pen(this.borderColor), this.canvasLeftOffset, this.canvasTopOffset, Width - this.canvasRightOffset - this.canvasLeftOffset, Height - this.canvasBottomOffset - this.canvasLeftOffset);
                    if (this.mainSeries != null && this.mainSeries.Count != 0)
                        this.axisBottom.PaintWithDates(this.mainSeries.GetDateTime(this.firstIndex), this.mainSeries.GetDateTime(this.lastIndex));
                    foreach (Pad pad in this.pads)
                        pad.Update(g);
                    for (int i = 1; i < this.pads.Count; ++i)
                        g.DrawLine(new Pen(this.splitterColor), this.pads[i].X1, this.pads[i].Y1, this.pads[i].X2, this.pads[i].Y1);
                }
                this.contentUpdated = false;
            }

            // Draw date and value tips
            if (MainSeries != null && MainSeries.Count != 0 && ActionType == ChartActionType.Cross && this.isMouseOverCanvas && this.bitmap != null)
            {
                graphics.DrawImage(this.bitmap, 0, 0);
                graphics.SmoothingMode = SmoothingMode;
                graphics.DrawLine(new Pen(CrossColor, 0.5f), this.canvasLeftOffset, this.mouseY, this.mouseX - 10, this.mouseY);
                graphics.DrawLine(new Pen(CrossColor, 0.5f), this.mouseX + 10, this.mouseY, Width - this.canvasRightOffset, this.mouseY);
                graphics.DrawLine(new Pen(CrossColor, 0.5f), this.mouseX, this.canvasTopOffset, this.mouseX, this.mouseY - 10);
                graphics.DrawLine(new Pen(CrossColor, 0.5f), this.mouseX, this.mouseY + 10, this.mouseX, Height - this.canvasBottomOffset);
                string dateTip = GetDateTime(this.mouseX).ToString();
                var dateTipSize = graphics.MeasureString(dateTip, this.Font);
                graphics.FillRectangle(new SolidBrush(DateTipRectangleColor), this.mouseX - dateTipSize.Width / 2 - 2f, Height - this.canvasBottomOffset, dateTipSize.Width, dateTipSize.Height + 2f);
                graphics.DrawString(dateTip, Font, new SolidBrush(DateTipTextColor), this.mouseX - dateTipSize.Width / 2 - 1f, Height - this.canvasBottomOffset + 2f);
                double num2 = 0.0;
                for (int i = 0; i < this.pads.Count; ++i)
                {
                    Pad pad = this.pads[i];
                    if (pad.Y1 < this.mouseY && this.mouseY < pad.Y2)
                    {
                        num2 = pad.WorldY(this.mouseY);
                        break;
                    }
                }
                string valTip = num2.ToString("F" + this.LabelDigitsCount);
                var valTipSize = graphics.MeasureString(valTip, this.Font);
                graphics.FillRectangle(new SolidBrush(ValTipRectangleColor),  Width - this.canvasRightOffset, this.mouseY - valTipSize.Height / 2 - 2f, valTipSize.Width, valTipSize.Height + 2f);
                graphics.DrawString(valTip, Font, new SolidBrush(ValTipTextColor), Width - this.canvasRightOffset + 2f, this.mouseY - valTipSize.Height / 2 - 1f);
            }
            else
            {
                if (this.bitmap != null)
                    graphics.DrawImage(this.bitmap, 0, 0);
            }
        }