コード例 #1
0
ファイル: DiagramDrawer.cs プロジェクト: mli2805/MoneyKeeper
        public DrawingImage Draw(DiagramDataSeriesUnited diagramData, DiagramDataExtremums diagramDataExtremums,
                                 DiagramDrawingCalculator diagramDrawingCalculator, DiagramMode diagramMode, Every groupInterval)
        {
            _diagramData = diagramData;
            _extremums   = diagramDataExtremums;
            _diagramDrawingCalculator = diagramDrawingCalculator;
            _diagramMode   = diagramMode;
            _groupInterval = groupInterval;

            var drawingGroup = new DrawingGroup();

            drawingGroup.Children.Add(FullDiagramBackground(_diagramDrawingCalculator));
            drawingGroup.Children.Add(DiagramRegionBackground(_diagramDrawingCalculator));

            drawingGroup.Children.Add(HorizontalAxes(_diagramDrawingCalculator));
            drawingGroup.Children.Add(VerticalGridLines(_diagramDrawingCalculator));

            drawingGroup.Children.Add(XAxisDashes(Dock.Top, _diagramDrawingCalculator));
            drawingGroup.Children.Add(XAxisDashes(Dock.Bottom, _diagramDrawingCalculator));
            drawingGroup.Children.Add(XAxisMarkers(Dock.Top, _diagramDrawingCalculator));
            drawingGroup.Children.Add(XAxisMarkers(Dock.Bottom, _diagramDrawingCalculator));

            drawingGroup.Children.Add(VerticalAxes(_diagramDrawingCalculator));

            drawingGroup.Children.Add(YAxisDashes(Dock.Left, _diagramDrawingCalculator));
            drawingGroup.Children.Add(YAxisMarkers(Dock.Left, _diagramDrawingCalculator));
            drawingGroup.Children.Add(YAxisDashes(Dock.Right, _diagramDrawingCalculator));
            drawingGroup.Children.Add(YAxisMarkers(Dock.Right, _diagramDrawingCalculator));

            drawingGroup.Children.Add(HorizontalGridLines(_diagramDrawingCalculator));

            if (_diagramMode == DiagramMode.BarVertical || _diagramMode == DiagramMode.BarVertical100)
            {
                BarVerticalDiagram(_diagramDrawingCalculator, ref drawingGroup);
            }
            if (_diagramMode == DiagramMode.Lines)
            {
                for (var j = 0; j < _diagramData.SeriesCount; j++)
                {
                    drawingGroup.Children.Add(OneSeriesLine(_diagramDrawingCalculator, j));
                }
            }
            if (_diagramMode == DiagramMode.SeparateLines)
            {
                drawingGroup.Children.Add(OneSeriesLine(_diagramDrawingCalculator, diagramData.ActiveLine));
            }

            return(new DrawingImage(drawingGroup));
        }
コード例 #2
0
        public DiagramDataExtremums FindDataExtremums(DiagramMode diagramMode)
        {
            var dataExtremums = new DiagramDataExtremums();

            dataExtremums.MinDate = DiagramData.ElementAt(0).Key;
            dataExtremums.MaxDate = DiagramData.Last().Key;

            switch (diagramMode)
            {
            case DiagramMode.SeparateLines:
                // экстремумы определяются по одной, активной сейчас линии
                dataExtremums.MinValue = double.PositiveInfinity;
                dataExtremums.MaxValue = Double.NegativeInfinity;
                foreach (var day in DiagramData)
                {
                    if (day.Value[ActiveLine] < dataExtremums.MinValue)
                    {
                        dataExtremums.MinValue = day.Value[ActiveLine];
                    }
                    if (day.Value[ActiveLine] > dataExtremums.MaxValue)
                    {
                        dataExtremums.MaxValue = day.Value[ActiveLine];
                    }
                }
                break;

            case DiagramMode.Lines:
            case DiagramMode.BarHorizontal:
                // это вариант , когда столбцы разных серий стоят рядом
                dataExtremums.MinValue = DiagramData.Values.Min(l => l.Min());
                dataExtremums.MaxValue = DiagramData.Values.Max(l => l.Max());
                break;

            case DiagramMode.BarVertical:
                // ряд серий отрицательные, либо даже просто значение отрицательное в положительной серии
                dataExtremums.MinValue = dataExtremums.MaxValue = 0;
                foreach (var day in DiagramData)
                {
                    var plus  = day.Value.Where(values => values > 0).Sum();
                    var minus = day.Value.Where(values => values < 0).Sum();
                    if (plus > dataExtremums.MaxValue)
                    {
                        dataExtremums.MaxValue = plus;
                    }
                    if (minus < dataExtremums.MinValue)
                    {
                        dataExtremums.MinValue = minus;
                    }
                }
                break;

            case DiagramMode.BarVertical100:
                dataExtremums.MinValue = 0;
                dataExtremums.MaxValue = 100;
                break;
            }

            if ((int)diagramMode < 100)
            {
                if (dataExtremums.MaxValue > 0 && dataExtremums.MinValue > 0)
                {
                    dataExtremums.MinValue = 0;
                }
                if (dataExtremums.MaxValue < 0 && dataExtremums.MinValue < 0)
                {
                    dataExtremums.MaxValue = 0;
                }
            }

            return(dataExtremums);
        }
コード例 #3
0
        public bool ZoomLimits(DiagramDataSeriesUnited currentSeriesUnited, Every groupInterval, int delta, ref DiagramDataExtremums extremums)
        {
            if (delta < 0)// increase picture
            {
                if (currentSeriesUnited.DiagramData.Count < 6)
                {
                    return(false);
                }
            }
            else
            {
            }

            int shiftDateRange = (extremums.MaxDate - extremums.MinDate).Days * delta / 1200;

            if (Math.Abs(shiftDateRange) < 31 && groupInterval == Every.Month)
            {
                shiftDateRange = 31 * Math.Sign(delta);
            }
            if (Math.Abs(shiftDateRange) < 366 && groupInterval == Every.Year)
            {
                shiftDateRange = 366 * Math.Sign(delta);
            }
            extremums.MinDate = extremums.MinDate.AddDays(-shiftDateRange);
            extremums.MaxDate = extremums.MaxDate.AddDays(shiftDateRange);
            return(true);
        }
コード例 #4
0
        public bool MoveLimits(DiagramDataSeriesUnited etalonSeriesUnited, DiagramDrawingCalculator calculator, int horizontalPoints, int verticalPoints, ref DiagramDataExtremums extremums)
        {
            var delta = (int)Math.Round(Math.Abs(horizontalPoints / calculator.PointPerDay));

            if (horizontalPoints < 0) // двигаем влево
            {
                if (extremums.MaxDate == etalonSeriesUnited.DiagramData.Last().Key)
                {
                    return(false);
                }
                if ((etalonSeriesUnited.DiagramData.Last().Key - extremums.MaxDate).Days < delta)
                {
                    delta = (etalonSeriesUnited.DiagramData.Last().Key - extremums.MaxDate).Days;
                }
                extremums.MaxDate = extremums.MaxDate.AddDays(delta);
                extremums.MinDate = extremums.MinDate.AddDays(delta);
            }
            else // вправо
            {
                if (extremums.MinDate == etalonSeriesUnited.DiagramData.ElementAt(0).Key)
                {
                    return(false);
                }
                if ((extremums.MinDate - etalonSeriesUnited.DiagramData.ElementAt(0).Key).Days < delta)
                {
                    delta = (extremums.MinDate - etalonSeriesUnited.DiagramData.ElementAt(0).Key).Days;
                }
                extremums.MinDate = extremums.MinDate.AddDays(-delta);
                extremums.MaxDate = extremums.MaxDate.AddDays(-delta);
            }
            return(true);
        }