コード例 #1
0
        internal void UpdateValues()
        {
            Debug.Assert(_values.Count == _items.Count);

            _values.Start();
            foreach (InfoPanelItem item in _items)
            {
                Label label = _values.GetPaintObject();
                label._textBlock.Text = item.ValueEx;
            }
            _values.Stop();
        }
コード例 #2
0
ファイル: Utils.cs プロジェクト: traderdata/COMPONENTES
        public static Label DrawText(double x, double y, string text, Brush foreground, double fontSize, FontFamily fontFamily,
                                     PaintObjectsManager <Label> labels)
        {
            Label label = labels.GetPaintObject();

            label._textBlock.Text       = text;
            label._textBlock.Foreground = foreground;
            label._textBlock.FontSize   = fontSize;
            label._textBlock.FontFamily = fontFamily;
            label.Left = x;
            label.Top  = y;

            return(label);
        }
コード例 #3
0
        internal void Render()
        {
            if (_linesPath == null)
            {
                _linesPath = new Path
                {
                    StrokeThickness = 1
                };
                Children.Add(_linesPath);
                SetZIndex(_linesPath, ZIndexConstants.GridLines);

                _linesPath.SetBinding(Shape.StrokeProperty, _chartPanel._chartX.CreateOneWayBinding("GridStroke"));
            }

            _labels.C = this;
            _labels.Start();

            Rect rcBounds = new Rect(0, 0, ActualWidth, ActualHeight);

            if (Utils.GetIsInDesignMode(this))
            {
                _min = 0;
                _max = 1;
            }

            if (rcBounds.Height < 2)
            {
                return;
            }

            //int decimals = _chartPanel._hasVolume ? 0 : _chartPanel._chartX.ScalePrecision;
            string formatString = _chartPanel.FormatYValueString;
            bool   isVolume     = _chartPanel._hasVolume; // && (_chartPanel._chartX.VolumePostfixLetter.Length > 0);


            double k = rcBounds.Height / LabelCount;

            double min = _chartPanel.ScalingType == ScalingTypeEnum.Linear || isVolume
        ? _min
        : (_min > 0 ? Math.Log10(_min) : 0);
            double max = _chartPanel.ScalingType == ScalingTypeEnum.Linear || isVolume ? _max : Math.Log10(_max);

            double startValue = min + (max - min) * (_chartPanel._yOffset / rcBounds.Height);

            GridStep = (max - min) / LabelCount;

            _chartPanel.StartPaintingYGridLines();

            GeometryGroup gLines = new GeometryGroup();

            StringBuilder stringBuilder = new StringBuilder();
            double        textHeight    = _chartPanel._chartX.GetTextHeight("9");

            for (int i = 0; i < LabelCount; i++)
            {
                double y = rcBounds.Height - (i * k);
                if (double.IsNaN(y))
                {
                    continue;
                }

                if (y < 0)
                {
                    break;
                }

                if (i > 0)
                {
                    gLines.Children.Add(new LineGeometry
                    {
                        StartPoint = new Point(_isLeftAligned ? rcBounds.Width - 10 : 0, y),
                        EndPoint   = new Point(_isLeftAligned ? rcBounds.Width : 10, y),
                    });

                    _chartPanel.PaintYGridLine(y);
                }

                stringBuilder.Length = 0;
                double value = startValue + (GridStep * i);
                if (_chartPanel.ScalingType == ScalingTypeEnum.Semilog && !isVolume)
                {
                    value = Math.Pow(10, value);
                }

                if (isVolume)
                {
                    value /= _chartPanel._chartX.VolumeDivisor;
                }

                stringBuilder.AppendFormat(formatString, value);

                if (isVolume && !string.IsNullOrEmpty(_chartPanel._chartX.VolumePostfixLetter))
                {
                    stringBuilder.Append(" ").Append(_chartPanel._chartX.VolumePostfixLetter);
                }

                if (!string.IsNullOrEmpty(_chartPanel.YAxisPostFix))
                {
                    stringBuilder.Append(_chartPanel.YAxisPostFix);
                }

                Label tb = _labels.GetPaintObject();
                tb.Text = stringBuilder.ToString();
                tb.Left = _isLeftAligned ? rcBounds.Width -
                          _chartPanel._chartX.GetTextWidth(stringBuilder.ToString()) - 2 : 2;
                tb.Top = y - textHeight - 2;
            }

            gLines.Children.Add(new LineGeometry
            {
                StartPoint = new Point(_isLeftAligned ? rcBounds.Width - 1 : 1, 0),
                EndPoint   = new Point(_isLeftAligned ? rcBounds.Width - 1 : 1, rcBounds.Height),
            });

            _chartPanel.StopPaintingYGridLines();
            _painted = true;
            _labels.Stop();
            _linesPath.Data = gLines;
        }
コード例 #4
0
        internal void Paint()
        {
            try
            {
                if (_painting)
                {
                    return;
                }

                _painting = true;

                _timerRepaint.StopTimerWork(TimerRepaint);
#if WPF
#if DEMO
                if (!string.IsNullOrEmpty(_demoText) && _labelDemo == null)
                {
                    _labelDemo = new Label();
                    _labelDemo.AddTo(this);
                    _labelDemo.Left = 10;
                    _labelDemo.Top  = 2;
//        _labelDemo._textBlock.Opacity = 0.7;
                    _labelDemo._textBlock.Foreground = Brushes.Red;
                    _labelDemo.Text = _demoText;
                    _labelDemo._textBlock.FontSize = 16;
                    _labelDemo.ZIndex = 100;
                }
#endif
#endif
                Rect rcBounds = new Rect(0, 0, ActualWidth, ActualHeight);

                if (_linesPath == null)
                {
                    _linesPath = new Path
                    {
                        Stroke          = _chartX.GridStroke,
                        StrokeThickness = 1,
                    };
                    Children.Add(_linesPath);
                }

                //Background = _chartX.Background;
                //_lines.C = this;
                _labels.C = this;
                //_lines.Start();
                _labels.Start();

                int           startIndex = _chartX._startIndex;
                GeometryGroup lines      = new GeometryGroup();

                //Utils.DrawLine(rcBounds.Left, 0, rcBounds.Right, 0, _chartX.GridStroke, LinePattern.Solid, 1, _lines);
                lines.Children.Add(new LineGeometry
                {
                    StartPoint = new Point(rcBounds.Left, 0),
                    EndPoint   = new Point(rcBounds.Right, 0),
                });

                int    rcnt         = _chartX.VisibleRecordCount;
                double periodPixels = _chartX.GetXPixel(rcnt) / rcnt;
                if (periodPixels < 1)
                {
                    periodPixels = 1;
                }

                _chartX._xGridMap.Clear();
                double tradeWeek  = periodPixels * 5;                // 5 trading days in a week (avg)
                double tradeMonth = periodPixels * 20;               // 20 trading days in a month (avg)
                double tradeYear  = periodPixels * 253;              // 253 trading days in a year (avg)

                double averageCharWidth = _chartX.GetTextWidth("0");

                // Level 1:
                // YYYY
                double level1 = averageCharWidth * 4;

                // Level 2:
                // YY F M A M J J A S O N D
                double level2 = averageCharWidth * 2;

                // Level 3:
                // YY Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
                double level3 = averageCharWidth * 3;

                // Level 4:
                // YYYY February March April May June July August September October November December
                double level4 = averageCharWidth * 9;

                // Level 5:
                // From -5 periods on right end, begin:
                // Jan DD  Feb DD  Mar DD  Apr DD  May DD  Jun DD  Jul DD  Aug DD  Sep DD  Oct DD  Nov DD  Dec DD
                double level5 = averageCharWidth * 6;

                // Level 6
                // Jan DD HH:MM
                double level6 = averageCharWidth * 10;

                double incr;
                int    xGrid = 0;
                double x, lx = 0;

                if (_chartX.RealTimeXLabels)
                {
                    string prevDay = "";

                    incr = level6;
                    string timeFormat = "HH:mm";
                    if (_chartX.ShowSeconds)
                    {
                        incr      += averageCharWidth * 2;
                        timeFormat = "HH:mm:ss";
                    }

                    for (int period = 0; period < rcnt; period++)
                    {
                        x = _chartX.GetXPixel(period);
                        if (x == lx)
                        {
                            continue;
                        }
                        DateTime dDate = DM.GetTimeStampByIndex(period + startIndex);
                        //if (dDate.Minute % 15 != 0) continue;
                        if (incr > level6)
                        {
                            incr = 0;
                            //Draw vertical line
                            //_renderDevice.PlotUnitSeparator((float)x, true, 0);
                            //Utils.DrawLine(x, 0, x, rcBounds.Height / 2, _chartX.GridStroke, LinePattern.Solid, 1, _lines);
                            lines.Children.Add(new LineGeometry
                            {
                                StartPoint = new Point(x, 0),
                                EndPoint   = new Point(x, rcBounds.Height / 2)
                            });

                            string szTime  = dDate.ToString(timeFormat);
                            string szDay   = dDate.ToString("dd");
                            string szMonth = dDate.ToString("MMM");

                            string szDate;
                            if (prevDay != szDay)
                            {
                                prevDay = szDay;
                                szDate  = szMonth + " " + szDay + " " + szTime;
                                level6  = averageCharWidth * 12;
                                lx     += level6 / 2;
                            }
                            else
                            {
                                szDate = szTime;
                            }

                            //_renderDevice.PlotUnitText((float)x, szDate, 0);
                            var lb = _labels.GetPaintObject();
                            lb.Left = x;
                            lb.Top  = 1;
                            lb.Text = szDate;
                            //Utils.DrawText(x, 1, szDate, _chartX.FontForeground, _chartX.FontSize, _chartX.FontFamily, _labels);
                            _chartX._xGridMap[xGrid++] = x;
                        }

                        incr += x - lx;
                        lx    = x;
                    }

                    _painting = false;

                    _linesPath.Data = (System.Windows.Media.Geometry)lines.GetAsFrozen();
                    //_lines.Stop();
                    _labels.Stop();
                    return;
                }

                lx = 0;
                double   oldX   = -1;
                string   sCache = "#";
                string   sDate;
                DateTime timestamp;
                DateTime?prevDate = null;
                if (level5 <= tradeWeek)
                {
                    incr = level5;
                    for (int period = 0; period < rcnt; period++)
                    {
                        x         = _chartX.GetXPixel(period);
                        timestamp = DM.GetTimeStampByIndex(period + startIndex);

                        if (prevDate.HasValue && prevDate.Value.Year != timestamp.Year)
                        {
                            sDate = timestamp.ToString("yyyy MMM");
                        }
                        else
                        {
                            sDate = timestamp.ToString("dd MMM");
                        }

                        prevDate = timestamp;

                        if (incr > level5 && sCache != sDate && oldX != x)
                        {
                            incr = 0;                             //Reset

                            lines.Children.Add(new LineGeometry
                            {
                                StartPoint = new Point(x, 0),
                                EndPoint   = new Point(x, rcBounds.Height / 2)
                            });

                            var lb = _labels.GetPaintObject();
                            lb.Left = x + 2;
                            lb.Top  = 1;
                            lb.Text = sDate;

                            sCache = sDate;
                            oldX   = x;
                            _chartX._xGridMap[xGrid++] = x;
                        }
                        incr += (x - lx);
                        lx    = x;
                    }
                }
                else if (level4 <= tradeMonth)
                {
                    incr = level4;
                    for (int period = 0; period < rcnt; period++)
                    {
                        x = _chartX.GetXPixel(period);

                        timestamp = DM.GetTimeStampByIndex(period + startIndex);
                        sDate     = timestamp.ToString("MMMM");
                        if (timestamp.Month == 1)
                        {
                            sDate = timestamp.ToString("yyyy MMM");
                        }

                        if (incr > level4 && sDate != sCache)
                        {
                            incr = 0;
                            lines.Children.Add(new LineGeometry
                            {
                                StartPoint = new Point(x, 0),
                                EndPoint   = new Point(x, rcBounds.Height / 2)
                            });

                            var lb = _labels.GetPaintObject();
                            lb.Left = x;
                            lb.Top  = 1;
                            lb.Text = sDate;

                            xGrid++;
                        }
                        sCache = sDate;
                        incr  += (x - lx);
                        lx     = x;

                        _chartX._xGridMap[xGrid] = x;
                    }
                }
                else if (level3 + 2 <= tradeMonth)
                {
                    incr   = level3;
                    sCache = "#";
                    for (int period = 0; period < rcnt; period++)
                    {
                        x = _chartX.GetXPixel(period);

                        timestamp = DM.GetTimeStampByIndex(period + startIndex);

                        sDate = timestamp.ToString("MMM");
                        if (timestamp.Month == 1)
                        {
                            sDate = timestamp.ToString("yy");
                        }

                        if (incr > level3 && sCache != sDate)
                        {
                            incr = 0;
                            lines.Children.Add(new LineGeometry
                            {
                                StartPoint = new Point(x, 0),
                                EndPoint   = new Point(x, rcBounds.Height / 2)
                            });

                            var lb = _labels.GetPaintObject();
                            lb.Left = x;
                            lb.Top  = 1;
                            lb.Text = sDate;

                            xGrid++;
                        }
                        sCache = sDate;
                        incr  += (x - lx);
                        lx     = x;

                        _chartX._xGridMap[xGrid] = x;
                    }
                }
                else if (level2 <= tradeMonth)
                {
                    incr   = level2;
                    sCache = "#";
                    for (int period = 0; period < rcnt; period++)
                    {
                        x = _chartX.GetXPixel(period);

                        timestamp = DM.GetTimeStampByIndex(period + startIndex);
                        sDate     = timestamp.ToString("MMM");
                        string sTemp;
                        if (timestamp.Month == 1)
                        {
                            sDate = timestamp.ToString("yy");
                            sTemp = sDate;
                        }
                        else
                        {
                            sTemp = sDate.Substring(0, 1);
                        }
                        if (incr > level2 && sCache != sDate)
                        {
                            incr = 0;

                            lines.Children.Add(new LineGeometry
                            {
                                StartPoint = new Point(x, 0),
                                EndPoint   = new Point(x, rcBounds.Height / 2)
                            });

                            var lb = _labels.GetPaintObject();
                            lb.Left = x;
                            lb.Top  = 1;
                            lb.Text = sTemp;

                            xGrid++;
                        }
                        sCache = sDate;
                        incr  += (x - lx);
                        lx     = x;

                        _chartX._xGridMap[xGrid] = x;
                    }
                }
                else if (level1 <= tradeYear)
                {
                    incr   = level1;
                    sCache = "#";
                    for (int period = 0; period < rcnt; period++)
                    {
                        x = _chartX.GetXPixel(period);
                        if (x == -1)
                        {
                            break;
                        }

                        timestamp = DM.GetTimeStampByIndex(period + startIndex);
                        sDate     = timestamp.ToString("yyyy");

                        if (incr > level1 && sDate != sCache)
                        {
                            incr = 0;

                            lines.Children.Add(new LineGeometry
                            {
                                StartPoint = new Point(x, 0),
                                EndPoint   = new Point(x, rcBounds.Height / 2)
                            });

                            var lb = _labels.GetPaintObject();
                            lb.Left = x;
                            lb.Top  = 1;
                            lb.Text = sDate;

                            xGrid++;
                        }
                        sCache = sDate;
                        incr  += (x - lx);
                        lx     = x;

                        _chartX._xGridMap[xGrid] = x;
                    }
                }

                //_lines.Stop();
                _linesPath.Data = (System.Windows.Media.Geometry)lines.GetAsFrozen();
                _labels.Stop();
            }
            finally
            {
                _painting = false;

                //after calendar is painted must instruct each panel to repaint the X Grid if needed
                if (_chartX.XGrid)
                {
                    foreach (var panel in _chartX.PanelsCollection)
                    {
                        panel.PaintXGrid();
                    }
                }
            }
        }
コード例 #5
0
        internal void RecalculateLayout()
        {
            Debug.Assert(_chartX != null);

            _values.Start();
            _labels.Start();
            _values.C = this;
            _labels.C = this;

            double labelsMaxWidth          = double.MinValue;
            double valuesMaxWidth          = double.MinValue;
            double valuesNoCaptionMaxWidth = double.MinValue;
            int    valueIndex;

            _entries.Clear();

            foreach (InfoPanelItem item in _items)
            {
                _entries.Add(new Tuple <string, string>(item.Caption, item.ValueEx));

                if (!item._noCaption)
                {
                    Label labelCaption = _labels.GetPaintObject();
                    labelCaption._textBlock.Text       = item.Caption;
                    labelCaption._textBlock.FontFamily = _chartX.InfoPanelFontFamily;
                    labelCaption._textBlock.FontSize   = _chartX.InfoPanelFontSize;
                    labelCaption._textBlock.Foreground = _chartX.InfoPanelLabelsForeground;
                    SetZIndex(labelCaption._textBlock, 5);
                }

                Label labelValue = _values.GetPaintObject();
                labelValue._textBlock.Text       = item.ValueEx;
                labelValue._textBlock.FontFamily = _chartX.InfoPanelFontFamily;
                labelValue._textBlock.FontSize   = _chartX.InfoPanelFontSize;
                labelValue._textBlock.Foreground = _chartX.InfoPanelValuesForeground;
                SetZIndex(labelValue._textBlock, 5);
            }
            _values.Stop();
            _labels.Stop();

            int    labelIndex = valueIndex = 0;
            double top        = 1;

            foreach (InfoPanelItem item in _items)
            {
                Label labelValue = _values[valueIndex++];

                if (!item._noCaption)
                {
                    Label labelCaption = _labels[labelIndex++];
                    if (labelCaption._textBlock.ActualWidth > labelsMaxWidth)
                    {
                        labelsMaxWidth = labelCaption._textBlock.ActualWidth;
                    }
                    SetLeft(labelCaption._textBlock, 1);
                    SetTop(labelCaption._textBlock, top - 1);
                }

                top += labelValue._textBlock.ActualHeight + 2;
            }

            top        = 1;
            valueIndex = 0;
            foreach (InfoPanelItem item in _items)
            {
                Label labelValue = _values[valueIndex++];

                if (item._noCaption)
                {
                    SetLeft(labelValue._textBlock, 2);
                    if (labelValue._textBlock.ActualWidth > valuesNoCaptionMaxWidth)
                    {
                        valuesNoCaptionMaxWidth = labelValue._textBlock.ActualWidth;
                    }
                }
                else
                {
                    SetLeft(labelValue._textBlock, labelsMaxWidth + 3);
                    if (labelValue._textBlock.ActualWidth > valuesMaxWidth)
                    {
                        valuesMaxWidth = labelValue._textBlock.ActualWidth;
                    }
                }
                SetTop(labelValue._textBlock, top - 1);

                top += labelValue._textBlock.ActualHeight + 2;
            }

            double maxWidth = labelsMaxWidth + valuesMaxWidth + 4;

            Width = Math.Max(maxWidth, valuesNoCaptionMaxWidth);

            if (_rectLabels == null)
            {
                _rectLabels = new Rectangle {
                    Stroke = null, StrokeThickness = 0
                };
                Children.Add(_rectLabels);
                _rectValues = new Rectangle {
                    Stroke = null, StrokeThickness = 0
                };
                Children.Add(_rectValues);
            }

            SetLeft(_rectLabels, 0);
            SetTop(_rectLabels, 0);
            _rectLabels.Width  = labelsMaxWidth + 2;
            _rectLabels.Height = top;
            _rectLabels.Fill   = _chartX.InfoPanelLabelsBackground;

            SetLeft(_rectValues, GetLeft(_rectLabels) + _rectLabels.Width);
            SetTop(_rectValues, 0);
            _rectValues.Width  = Math.Max(maxWidth, valuesNoCaptionMaxWidth) - labelsMaxWidth + 2;
            _rectValues.Height = top;
            _rectValues.Fill   = _chartX.InfoPanelValuesBackground;

            Height = top;
        }