示例#1
0
        public void Render(IHasData data)
        {
            if (data is IHasVolumeData volume)
            {
                var volumeData = volume.GetData();

                if (volumeData.DataSources != null && volumeData.DataSources.Any())
                {
                    var volumeItems = volumeData.DataSources;
                    var visuals     = new List <Visual>();
                    for (int i = 0; i <= volumeData.VisualRangeEndIndex - volumeData.VisualRangeStartIndex; i++)
                    {
                        var volumeItem = volumeItems[i + volumeData.VisualRangeStartIndex];
                        var visual     = new DrawingVisual();

                        using (var context = visual.RenderOpen())
                        {
                            var LeftBottomPoint = new Point
                            {
                                X = i * (volumeData.DataWidth + volumeData.DataMargin * 2) + volumeData.Margin.Left + volumeData.DataMargin,
                                Y = volumeData.ActualHeight - volumeData.Margin.Bottom
                            };

                            var LeftTopPoint = new Point
                            {
                                X = LeftBottomPoint.X,
                                Y = volumeData.ActualHeight - Convert.ToDouble(volumeItem.Volume) * volumeData.YAxisCoordinateAndPixelProportion * 0.96 - volumeData.Margin.Bottom
                            };

                            var RightTopPoint = new Point
                            {
                                X = LeftBottomPoint.X + volumeData.DataWidth,
                                Y = LeftTopPoint.Y
                            };

                            var RightBottomPoint = new Point
                            {
                                X = RightTopPoint.X,
                                Y = LeftBottomPoint.Y
                            };

                            var brush = volumeItem.Open < volumeItem.Close ? volumeData.RiseBrush : volumeData.FallBrush;

                            context.DrawRectangle(brush, null, new Rect(LeftBottomPoint, RightTopPoint));
                            visuals.Add(visual);
                        }
                    }
                    volumeData.UpdateVisuals(nameof(VolumeRenderer), visuals);
                }
                else
                {
                    volumeData.UpdateVisual(nameof(VolumeRenderer), null);
                }
            }
        }
示例#2
0
 public void Render(IHasData data)
 {
     if (data is IHasAxisLineData axisData)
     {
         var axis   = axisData.GetData();
         var visual = new DrawingVisual();
         using (var context = visual.RenderOpen())
         {
             var pen = new Pen {
                 Brush = axis.AxisBrush
             };
             //画X轴
             var axisXStartPoint = new Point {
                 X = axis.Margin.Left, Y = axis.ActualHeight - axis.Margin.Bottom
             };
             var axisXEndPoint = new Point {
                 X = axis.ActualWidth - axis.Margin.Right, Y = axis.ActualHeight - axis.Margin.Bottom
             };
             context.DrawLine(pen, axisXStartPoint, axisXEndPoint);
             //画Y轴
             var axisYStartPoint = new Point {
                 X = axis.ActualWidth - axis.Margin.Right, Y = 0
             };
             var axisYEndPoint = new Point {
                 X = axis.ActualWidth - axis.Margin.Right, Y = axis.ActualHeight - axis.Margin.Bottom
             };
             context.DrawLine(pen, axisYStartPoint, axisYEndPoint);
             var proportion = 1 / axis.YAxisCoordinateCount;
             var linePen    = new Pen {
                 Brush = axis.ReferenceLineBrush
             };
             for (int i = 0; i < axis.YAxisCoordinateCount; i++)
             {
                 //坐标点的位置
                 //获取当前Y刻度位置是从可视区域底部开始开始向上画
                 //以Y轴最高值和Y轴最低值之间的差值乘以刻度比例再加上底部补偿值
                 var currentYPoint = (axis.YAxisCoordinateCount - i - 1) * proportion * axis.YAxisActualHeight + axis.Margin.Bottom;
                 var pointStart    = new Point {
                     X = axis.ActualWidth - axis.Margin.Right, Y = currentYPoint
                 };
                 var pointEnd = new Point {
                     X = pointStart.X + 10, Y = currentYPoint
                 };
                 //参考线的位置
                 var linePointStart = new Point {
                     X = axis.Margin.Left, Y = currentYPoint
                 };
                 context.DrawLine(pen, pointStart, pointEnd);
                 context.DrawLine(linePen, linePointStart, pointStart);
             }
         }
         axis.UpdateVisual(nameof(AxisLineRenderer), visual);
     }
 }
示例#3
0
        public void Render(IHasData data)
        {
            if (data is IHasLineData avgLineData)
            {
                var lineDatas = avgLineData.GetData();

                if (lineDatas != null)
                {
                    if (lineDatas.DataSources != null)
                    {
                        var margin = lineDatas.DataWidth + lineDatas.DataMargin * 2;
                        var visual = new DrawingVisual();
                        using (var context = visual.RenderOpen())
                        {
                            for (int i = 0; i <= lineDatas.VisualRangeEndIndex - lineDatas.VisualRangeStartIndex - 1; i++)
                            {
                                var index = i + lineDatas.VisualRangeStartIndex;
                                var x1    = lineDatas.Margin.Left + margin * i + lineDatas.DataWidth / 2;
                                var x2    = x1 + margin;

                                foreach (var line in lineDatas.DataSources)
                                {
                                    if (line.Datas == null || line.Brush == null)
                                    {
                                        continue;
                                    }

                                    var y1 = ChartHelper.ComputeYCoordinate(lineDatas.ActualHeight, lineDatas.YAxisCoordinateMinValue, lineDatas.YAxisCoordinateAndPixelProportion, lineDatas.Margin.Top, Convert.ToDouble(line.Datas[index]));
                                    var y2 = ChartHelper.ComputeYCoordinate(lineDatas.ActualHeight, lineDatas.YAxisCoordinateMinValue, lineDatas.YAxisCoordinateAndPixelProportion, lineDatas.Margin.Top, Convert.ToDouble(line.Datas[index + 1]));

                                    var point1 = new Point(x1, y1);
                                    var point2 = new Point(x2, y2);
                                    var pen    = new Pen {
                                        Brush = line.Brush
                                    };
                                    if (point1.Y > 0 && point1.X > 0)
                                    {
                                        context.DrawLine(pen, point1, point2);
                                    }
                                }
                            }
                        }

                        lineDatas.UpdateVisual(Name, visual);
                    }
                    else
                    {
                        lineDatas.UpdateVisual(Name, null);
                    }
                }
            }
        }
示例#4
0
        public void Render(IHasData data)
        {
            if (data is IHasTimeLableData timeLableData)
            {
                var lableData = timeLableData.GetData();

                var labelFormat = timeLabelMapper.MapToFormat(lableData.TimeSpan, lableData.StickWidth, lableData.DateTimes);

                var visual = new DrawingVisual();
                using (var context = visual.RenderOpen())
                {
                    var pen = new Pen {
                        Brush = lableData.Brush
                    };

                    foreach (var index in labelFormat.TimeIndexs)
                    {
                        var format     = labelFormat.Format;
                        var pointStart = new Point()
                        {
                            X = index * (lableData.DataWidth + lableData.DataMargin * 2) + lableData.Margin.Left + lableData.DataMargin + lableData.DataWidth / 2, Y = lableData.ActualHeight - lableData.Margin.Bottom
                        };
                        var pointEnd = new Point()
                        {
                            X = pointStart.X,
                            Y = pointStart.Y + 5
                        };

                        //如果为0点则显示为天数
                        if (lableData.DateTimes[index].ToLocalTime().ToString("HH:mm:ss") == "00:00:00")
                        {
                            format = "M月d日";
                        }

                        var text = new FormattedText(lableData.DateTimes[index].ToString(format), CultureInfo.GetCultureInfo("en-us"), FlowDirection.LeftToRight, lableData.Typeface, lableData.FontSize, lableData.Brush, 1.25);

                        var textPoint = new Point()
                        {
                            X = pointStart.X - text.Width / 2,
                            Y = pointEnd.Y
                        };

                        context.DrawLine(pen, pointStart, pointEnd);
                        context.DrawText(text, textPoint);
                    }
                }

                lableData.UpdateVisual(nameof(TimeLabelRenderer), visual);
            }
        }
示例#5
0
        public void Render(IHasData data)
        {
            if (data is IHasKlineInfoData klineInfoData)
            {
                var klineInfo = klineInfoData.GetData();
                if (klineInfo.Render)
                {
                    var point = new Point();

                    var visual = new DrawingVisual();
                    using (var context = visual.RenderOpen())
                    {
                        List <KlineInfo> texts = new List <KlineInfo>
                        {
                            new KlineInfo {
                                Title = "时间:", Info = $"{klineInfo.OHLC.Time:yyyy-MM-dd HH:mm}"
                            },
示例#6
0
 public void Render(IHasData data)
 {
     if (data is IHasAxisLableData axisData)
     {
         var lableData = axisData.GetData();
         var visual    = new DrawingVisual();
         using (var context = visual.RenderOpen())
         {
             var proportion = 1 / lableData.YAxisCoordinateCount;
             for (int i = 0; i < lableData.YAxisCoordinateCount; i++)
             {
                 var currentValue = (i + 1) * proportion * lableData.YAxisValueRange + lableData.YAxisCoordinateMinValue;
                 var textPoint    = new Point
                 {
                     X = lableData.ActualWidth - lableData.Margin.Right + 15,
                     Y = (lableData.YAxisCoordinateCount - i - 1) * proportion * lableData.YAxisActualHeight + lableData.Margin.Bottom - lableData.FontSize / 2
                 };
                 var text = new FormattedText(currentValue.ToString(lableData.TextFormat), CultureInfo.GetCultureInfo("en-us"), FlowDirection.LeftToRight, lableData.Typeface, lableData.FontSize, lableData.Brush, 1.25);
                 context.DrawText(text, textPoint);
             }
         }
         lableData.UpdateVisual(nameof(AxisLabelRenderer), visual);
     }
 }
示例#7
0
        public void Render(IHasData data)
        {
            if (data is IHasGuideLineData guideLineData)
            {
                var lineData = guideLineData.GetData();
                var visual   = new DrawingVisual();

                using (var context = visual.RenderOpen())
                {
                    var pen = new Pen {
                        Brush = lineData.Brush
                    };
                    pen.DashStyle = DashStyles.Dash;

                    int index = Convert.ToInt32(Math.Floor((lineData.MousePoint.X - lineData.DataMargin - lineData.Margin.Left) / (lineData.DataWidth + lineData.DataMargin * 2)));

                    if (0 <= index && index <= (lineData.ViewAreaEndIndex - lineData.ViewAreaStartIndex))
                    {
                        var XAxisStartPoint = new Point
                        {
                            X = lineData.Margin.Left,
                            Y = lineData.MousePoint.Y
                        };

                        var XAxisEndPoint = new Point
                        {
                            X = lineData.ActualWidth - lineData.Margin.Right,
                            Y = lineData.MousePoint.Y
                        };

                        var YAxisStartPoint = new Point
                        {
                            X = index * (lineData.DataWidth + lineData.DataMargin * 2) + lineData.Margin.Left + lineData.DataMargin + lineData.DataWidth / 2,
                            Y = 0
                        };

                        var YAxisEndPoint = new Point
                        {
                            X = index * (lineData.DataWidth + lineData.DataMargin * 2) + lineData.Margin.Left + lineData.DataMargin + lineData.DataWidth / 2,
                            Y = lineData.ActualHeight - lineData.Margin.Bottom
                        };

                        var YActualHeight = lineData.ActualHeight - lineData.Margin.Bottom;
                        var PriceValue    = ((YActualHeight - lineData.MousePoint.Y) / YActualHeight) * lineData.YAxisValueRange + lineData.YAxisCoordinateMinValue;

                        //画价格的文字
                        var priceText = new FormattedText(PriceValue.ToString(lineData.TextFormat), CultureInfo.GetCultureInfo("en-us"), FlowDirection.LeftToRight, lineData.Typeface, lineData.FontSize, lineData.TextBrush, 1.25);

                        var PriceRectangleStartLeftTopPoint = new Point()
                        {
                            X = XAxisEndPoint.X,
                            Y = XAxisEndPoint.Y - priceText.Height / 2
                        };

                        var PriceTextPoint = new Point()
                        {
                            X = PriceRectangleStartLeftTopPoint.X + 7.5,
                            Y = PriceRectangleStartLeftTopPoint.Y
                        };

                        if (lineData.MousePoint.X > 0 && lineData.MousePoint.Y > 0 && lineData.MousePoint.Y < lineData.ActualHeight - lineData.Margin.Bottom)
                        {
                            context.DrawLine(pen, XAxisStartPoint, XAxisEndPoint);
                            context.DrawLine(pen, YAxisStartPoint, YAxisEndPoint);
                            context.DrawRectangle(lineData.RectengelBrush, new Pen()
                            {
                                Brush = lineData.RectengelBrush
                            }, new Rect(PriceRectangleStartLeftTopPoint, new Size {
                                Height = priceText.Height + 5, Width = priceText.Width + 15
                            }));
                            context.DrawText(priceText, PriceTextPoint);
                        }
                        else if (lineData.MousePoint.X > 0)
                        {
                            context.DrawLine(pen, YAxisStartPoint, YAxisEndPoint);
                        }

                        if (lineData.Times != null)
                        {
                            //画时间的文字
                            var timeText = new FormattedText(lineData.Times[index].ToString("M月dd日 HH:mm"), CultureInfo.GetCultureInfo("en-us"), FlowDirection.LeftToRight, lineData.Typeface, lineData.FontSize, lineData.TextBrush, 1.25);

                            var TimeRectangleStartLeftTopPoint = new Point()
                            {
                                X = index * (lineData.DataWidth + lineData.DataMargin * 2) + lineData.Margin.Left + lineData.DataMargin + lineData.DataWidth - timeText.Width / 2 - 5,
                                Y = lineData.ActualHeight - lineData.Margin.Bottom
                            };

                            var TimeTextPoint = new Point()
                            {
                                X = TimeRectangleStartLeftTopPoint.X + 2.5,
                                Y = TimeRectangleStartLeftTopPoint.Y + 2.5
                            };

                            context.DrawRectangle(lineData.RectengelBrush, new Pen()
                            {
                                Brush = lineData.RectengelBrush
                            }, new Rect(TimeRectangleStartLeftTopPoint, new Size {
                                Height = timeText.Height + 5, Width = timeText.Width + 5
                            }));
                            context.DrawText(timeText, TimeTextPoint);
                        }
                    }
                    lineData.UpdateVisual(nameof(GuideLineRenderer), visual);
                }
            }
        }
示例#8
0
        public void Render(IHasData data)
        {
            if (data is IHasKLineData kline)
            {
                var kLineData = kline.GetData();

                if ((kLineData.DataSources != null && kLineData.DataSources.Any()) && AllowRender)
                {
                    var ohlcs   = kLineData.DataSources;
                    var visuals = new List <Visual>();
                    for (int i = 0; i <= kLineData.VisualRangeEndIndex - kLineData.VisualRangeStartIndex; i++)
                    {
                        var ohlc   = ohlcs[i + kLineData.VisualRangeStartIndex];
                        var visual = new DrawingVisual();
                        using (var context = visual.RenderOpen())
                        {
                            var openCloseMaxPoint = new Point
                            {
                                X = i * (kLineData.DataWidth + kLineData.DataMargin * 2) + kLineData.Margin.Left + kLineData.DataMargin,
                                Y = ChartHelper.ComputeYCoordinate(kLineData.ActualHeight, kLineData.YAxisCoordinateMinValue, kLineData.YAxisCoordinateAndPixelProportion, kLineData.Margin.Top, Convert.ToDouble(Math.Max(ohlc.Open, ohlc.Close)))
                            };
                            var openCloseMinPoint = new Point
                            {
                                X = i * (kLineData.DataWidth + kLineData.DataMargin * 2) + kLineData.Margin.Left + kLineData.DataMargin + kLineData.DataWidth,
                                Y = ChartHelper.ComputeYCoordinate(kLineData.ActualHeight, kLineData.YAxisCoordinateMinValue, kLineData.YAxisCoordinateAndPixelProportion, kLineData.Margin.Top, Convert.ToDouble(Math.Min(ohlc.Open, ohlc.Close)))
                            };
                            var midLineHeightPoint = new Point
                            {
                                X = openCloseMaxPoint.X + kLineData.DataWidth / 2,
                                Y = ChartHelper.ComputeYCoordinate(kLineData.ActualHeight, kLineData.YAxisCoordinateMinValue, kLineData.YAxisCoordinateAndPixelProportion, kLineData.Margin.Top, Convert.ToDouble(ohlc.Height))
                            };
                            var midLineLowPoint = new Point
                            {
                                X = openCloseMaxPoint.X + kLineData.DataWidth / 2,
                                Y = ChartHelper.ComputeYCoordinate(kLineData.ActualHeight, kLineData.YAxisCoordinateMinValue, kLineData.YAxisCoordinateAndPixelProportion, kLineData.Margin.Top, Convert.ToDouble(ohlc.Low))
                            };

                            //设置最小蜡烛宽度
                            if ((openCloseMinPoint.Y - openCloseMaxPoint.Y) < 3)
                            {
                                openCloseMinPoint.Y = openCloseMaxPoint.Y + 3;
                            }

                            var brush = ohlc.Open < ohlc.Close ? kLineData.RiseBrush : kLineData.FallBrush;
                            context.DrawRectangle(brush, null, new Rect(openCloseMaxPoint, openCloseMinPoint));
                            context.DrawLine(new Pen {
                                Brush = brush, Thickness = kLineData.DataWidth / 8
                            }, midLineHeightPoint, midLineLowPoint);

                            visuals.Add(visual);
                            kLineData.Mapping.Add(visual, new Model.KlineMappingData {
                                OHLC = ohlc, MidLineHeightPoint = midLineHeightPoint, MidLineLowPoint = midLineLowPoint
                            });
                        }
                    }
                    kLineData.UpdateVisuals(nameof(KLineRenderer), visuals);
                }
                else
                {
                    kLineData.UpdateVisual(nameof(KLineRenderer), null);
                }
            }
        }