Esempio n. 1
0
 public static Point PointToChart(DateTime x, double y, ChartPlotInfo info)
 {
     var point = new Point();
     point.X = DateToChart(x, info);
     point.Y = YCoordToChart(y, info);
     return point;
 }
Esempio n. 2
0
 public static double DateToChart(DateTime x, ChartPlotInfo info)
 {
     if (info.DaysWidth == 1)
     {
         return(info.MaxWidth / 2);
     }
     return((x - info.MinX).Days * info.WidthScale + info.LeftMarginWidth + ChartPlotInfo.CHART_START_END_INDENTATION);
 }
Esempio n. 3
0
 public static double DateToChart(DateTime x, ChartPlotInfo info)
 {
     if (info.DaysWidth == 1)
     {
         return info.MaxWidth / 2;
     }
     return (x - info.MinX).Days * info.WidthScale + info.LeftMarginWidth + ChartPlotInfo.CHART_START_END_INDENTATION;
 }
Esempio n. 4
0
        public static Point PointToChart(DateTime x, double y, ChartPlotInfo info)
        {
            var point = new Point();

            point.X = DateToChart(x, info);
            point.Y = YCoordToChart(y, info);
            return(point);
        }
Esempio n. 5
0
 private void DrawSeria(IEnumerable<SeriesDateBasedElement> seria, ChartPlotInfo info, Brush brush)
 {
     var timeOrderedSeria = seria.OrderBy(x => x.Argument).ToList();
     var prevItem = timeOrderedSeria.First();
     foreach (var item in timeOrderedSeria.Skip(1))
     {
         DrawLine(
             prevItem.Argument,
             prevItem.Value,
             item.Argument,
             item.Value,
             info,
             brush);
         prevItem = item;
     }
     foreach (var item in timeOrderedSeria)
     {
         DrawCircle(item.Argument, item.Value, info, brush);
     }
 }
Esempio n. 6
0
        private void DrawLine(double x1, double y1, double x2, double y2, ChartPlotInfo info, Brush brush, bool isDashed = false)
        {
            var line = new Line();
            line.X1 = GeometricHelper.XCoordToChart(x1, info);
            line.X2 = GeometricHelper.XCoordToChart(x2, info);
            line.Y1 = GeometricHelper.YCoordToChart(y1, info);
            line.Y2 = GeometricHelper.YCoordToChart(y2, info);
            line.Stroke = brush;
            line.StrokeThickness = 2;
            if (isDashed)
            {
                line.StrokeThickness = 1;
                line.StrokeDashOffset = 5;
            }

            RenderElement(line);
        }
Esempio n. 7
0
        private void DrawLine(DateTime x1, double y1, DateTime x2, double y2, ChartPlotInfo info, Brush brush, bool isDashed = false)
        {
            var line = new Line();
            line.X1 = GeometricHelper.DateToChart(x1, info);
            line.X2 = GeometricHelper.DateToChart(x2, info);
            line.Y1 = GeometricHelper.YCoordToChart(y1, info);
            line.Y2 = GeometricHelper.YCoordToChart(y2, info);
            line.Stroke = brush;
            line.StrokeThickness = 2;
            if (isDashed)
            {
                DoubleCollection dashes = new DoubleCollection(2);
                dashes.Add(5);
                dashes.Add(5);
                line.StrokeThickness = 1;
                line.StrokeDashArray = dashes;
            }

            RenderElement(line);
        }
Esempio n. 8
0
        private void DrawLabel(LabelModel labelModel, ChartPlotInfo info, LabelAlign align = LabelAlign.Left)
        {
            switch (align)
            {
                case LabelAlign.Left:
                    break;
                case LabelAlign.Center:
                    labelModel.XPix -= labelModel.Text.Length * 4;
                    break;
                case LabelAlign.Right:
                    break;
                default:
                    break;
            }

            var textBlock = new TextBlock();
            textBlock.Text = labelModel.Text;

            RenderElement(textBlock, labelModel.XPix, labelModel.YPix);
        }
Esempio n. 9
0
        private void DrawCircle(DateTime dateTime, double p, ChartPlotInfo info, Brush brush)
        {
            var circle = new Ellipse();

            circle.ToolTip = string.Format("Дата: {0:yyyy MMM dd}, значення: {1}", dateTime, p);

            circle.Stroke = brush;
            circle.Fill = Brushes.White;

            circle.Width = 10;
            circle.Height = 10;
            circle.StrokeThickness = 2;
            var x = GeometricHelper.DateToChart(dateTime, info) - circle.Width/2;
            var y = GeometricHelper.YCoordToChart(p, info) - circle.Height/2;
            Canvas.SetTop(circle, y);
            Canvas.SetLeft(circle, x);

            RenderElement(circle);
        }
Esempio n. 10
0
        private void DrawBezierSegment(Point p1, Point p2, Point p3, ChartPlotInfo info, Brush brush)
        {
            //var line = new BezierSegment();
            //line.Point1 = GeometricHelper.PointToChart(p1, info);
            //line.Point2 = GeometricHelper.PointToChart(p2, info);
            //line.Point3 = GeometricHelper.PointToChart(p3, info);
            //line.Stroke = brush;
            //line.StrokeThickness = 2;

            //RenderElement(line);
        }
Esempio n. 11
0
        private void DrawBackground(ChartPlotInfo plotInfo)
        {
            var chartBack = new Rectangle();
            chartBack.Width = plotInfo.MaxWidth;
            chartBack.Height = plotInfo.MaxHeight;
            Canvas.SetLeft(chartBack, plotInfo.LeftMarginWidth);
            Canvas.SetTop(chartBack, plotInfo.HeaderHeight);
            chartBack.Fill = ChartBackground;

            plotArea.Children.Add(chartBack);
        }
Esempio n. 12
0
        private ChartPlotInfo CalculatePlotInfo()
        {
            ChartPlotInfo plotInfo = new ChartPlotInfo();

            DateTime minDate = Series.FirstOrDefault().Min(element => element.Argument);
            DateTime maxDate = Series.FirstOrDefault().Max(element => element.Argument);
            double maxValue = Series.FirstOrDefault().Max(element => element.Value);
            foreach (var seria in Series.Skip(1))
            {
                var minX = seria.Min(el => el.Argument);
                if (minX < minDate)
                {
                    minDate = minX;
                }
                var maxX = seria.Max(el => el.Argument);
                if (maxX > maxDate)
                {
                    maxDate = maxX;
                }
                var maxY = seria.Max(el => el.Value);
                if (maxY > maxValue)
                {
                    maxValue = maxY;
                }
            }

            plotInfo.MaxX = maxDate;
            plotInfo.MaxY = maxValue;
            plotInfo.MinX = minDate;
            plotInfo.MinY = 0;

            plotInfo.XStep = new TimeSpan((int)Math.Ceiling(plotInfo.DaysWidth / MAX_DESIRED_X_VALUES), 0, 0, 0);

            var valuesPower = Math.Log10(plotInfo.MaxY * 10);
            var valuesPowerRounded = Math.Ceiling(valuesPower);
            plotInfo.YStep = 100 / Math.Pow(10, valuesPowerRounded) / 2;
            plotInfo.MaxY = Math.Ceiling(plotInfo.MaxY / plotInfo.YStep) * plotInfo.YStep;

            plotInfo.FooterHeight = 50;
            plotInfo.HeaderHeight = 50;
            plotInfo.LeftMarginWidth = 40;
            plotInfo.RightMarginWidth = 20;

            return plotInfo;
        }
Esempio n. 13
0
 public LabelModel(ChartPlotInfo info)
 {
     this.info = info;
 }
Esempio n. 14
0
 public static double YCoordToChart(double y, ChartPlotInfo info)
 {
     return((info.PhysHeight - y) * info.HeightScale + info.HeaderHeight);
 }
Esempio n. 15
0
 public static double XCoordToChart(double x, ChartPlotInfo info)
 {
     return(x + info.LeftMarginWidth + ChartPlotInfo.CHART_START_END_INDENTATION);
 }
Esempio n. 16
0
 public static double XCoordToChart(double x, ChartPlotInfo info)
 {
     return x + info.LeftMarginWidth + ChartPlotInfo.CHART_START_END_INDENTATION;
 }
Esempio n. 17
0
 public static double YCoordToChart(double y, ChartPlotInfo info)
 {
     return (info.PhysHeight - y) * info.HeightScale + info.HeaderHeight;
 }
Esempio n. 18
0
        private void DrawGrid(ChartPlotInfo info)
        {
            var frameBrush = Brushes.SteelBlue;
            var gridBrush = Brushes.LightSteelBlue;

            //Grid
            for (DateTime x = info.MinX; x < info.MaxX; x += info.XStep)
            {
                if (x > info.MinX)
                {
                    DrawLine(x, 0, x, info.PhysHeight, info, gridBrush, true);
                }
                var labelModel = new LabelModel(info)
                {
                    Text = string.Format("{0:dd MMM yyyy}", x),
                    XPhys = x,
                    YPix = info.MaxHeight + ARGUMENT_LABEL_VERTICAL_SHIFT + info.HeaderHeight
                };

                DrawLabel(labelModel, info);
            }

            for (var y = info.MinY; y <= info.MaxY; y += info.YStep)
            {
                DrawLine(0, y, info.Width, y, info, gridBrush, true);

                var labelModel = new LabelModel(info)
                {
                    Text = string.Format("{0:F1}", y),
                    XPix = VALUE_LABEL_HORIZONTAL_SHIFT,
                    YPhys = y
                };
                DrawLabel(labelModel, info);
            }

            //Frame
            //left
            DrawLine(0, 0, 0, info.MaxY, info, frameBrush);
            //right
            DrawLine(info.Width, 0, info.Width, info.MaxY, info, frameBrush);
            //bottom
            DrawLine(0, info.MaxY, info.Width, info.MaxY, info, frameBrush);
            //top
            DrawLine(0, 0, info.Width, 0, info, frameBrush);
        }