Exemplo n.º 1
0
        private void RenderGrid(DrawingContext drawingContext)
        {
            var interval = LinearAxis.CalculateActualInterval(_graphContext.GraphHeigh, _graphContext.Min, _graphContext.Max, 4);
            var ticks    = LinearAxis.GetMajorValues(_graphContext.GraphHeigh, _graphContext.Min, _graphContext.Max, interval).ToList();

            var typeface = new Typeface(new FontFamily("Segoe UI"), FontStyles.Normal, FontWeights.Normal, FontStretches.Normal);

            _graphContext.MaxTextWidth  = 0;
            _graphContext.MaxTextHeight = 0;

            foreach (var tick in ticks)
            {
                var text = new FormattedText(tick.ToString(_graphContext.DisplayFormat), CultureInfo.CurrentUICulture, FlowDirection.LeftToRight, typeface, 11, Brushes.Black);

                var width = Math.Floor(text.Width) + 1.5;
                if (width > _graphContext.MaxTextWidth)
                {
                    _graphContext.MaxTextWidth = width;
                }

                var height = Math.Floor(text.Height) + 1.5;
                if (height > _graphContext.MaxTextHeight)
                {
                    _graphContext.MaxTextHeight = height;
                }
            }

            _graphContext.MaxTextHeight = Math.Ceiling(_graphContext.MaxTextHeight);
            _graphContext.MaxTextWidth  = Math.Ceiling(_graphContext.MaxTextWidth);

            _graphContext.GraphWidth = Math.Floor(ActualWidth - _graphContext.MaxTextWidth);
            _graphContext.GraphHeigh = Math.Floor(ActualHeight - _graphContext.MaxTextHeight);

            foreach (var tick in ticks)
            {
                var y = Math.Round(_graphContext.GraphHeigh - ((tick - _graphContext.Min) / (_graphContext.Max - _graphContext.Min) * _graphContext.GraphHeigh));

                var text = new FormattedText(tick.ToString(_graphContext.DisplayFormat), CultureInfo.CurrentUICulture, FlowDirection.LeftToRight, typeface, 10, Brushes.Black);
                drawingContext.DrawText(text, new Point(_graphContext.GraphWidth, y - text.Height / 2));

                var pen = new Pen(Brushes.Black, 1);
                drawingContext.PushOpacity(0.25);
                drawingContext.DrawLine(pen, new Point(0, y), new Point(_graphContext.GraphWidth - 1, y));
                drawingContext.Pop();
            }
        }
Exemplo n.º 2
0
        private void CalculateGrid(RenderingContext context)
        {
            var format = MaxPrice > 10 ? "0" : "0.0000";

            var typeface = new Typeface(new FontFamily("Segoe UI"), FontStyles.Normal, FontWeights.Normal, FontStretches.Normal);
            var testText = new FormattedText(context.MaxPrice.ToString(format), CultureInfo.CurrentUICulture, FlowDirection.LeftToRight, typeface, 10, Brushes.Black);

            context.SimulationHeight = (int)(context.Height - testText.Height - 2);
            context.SimulationWidth  = (int)(context.Width - testText.Width - 2);

            var intervalHorizontal = LinearAxis.CalculateActualInterval(context.SimulationHeight, context.MinPrice, context.MaxPrice, 4);

            context.HorizontalTicks = LinearAxis.GetMajorValues(context.SimulationHeight, context.MinPrice, context.MaxPrice, intervalHorizontal).ToList();

            var maxTime          = context.EndDate.Subtract(context.StartDate.Date).TotalDays;
            var delta            = context.StartDate.Subtract(context.StartDate.Date).TotalDays;
            var intervalVertical = LinearAxis.CalculateActualInterval(context.SimulationWidth, 0, maxTime, 4);

            context.VerticalTicks = LinearAxis.GetMajorValues(context.SimulationWidth, 0, maxTime, intervalVertical).Select(t => t - delta).ToList();
        }