Beispiel #1
0
        /// <summary>
        /// Generates the label of the specified <see cref="Category"/>.
        /// </summary>
        /// <param name="category">The specified <see cref="Category"/>.</param>
        /// <returns>The generated <see cref="UIView"/> representing the label of the <see cref="Category"/>.</returns>
        private static UIView GetLabel(Category category)
        {
            if (category == null)
            {
                throw new ArgumentNullException();
            }

            var circle = new UIButton();

            circle.WidthAnchor.ConstraintEqualTo(Constants.LabelCircleRadius * 2).Active  = true;
            circle.HeightAnchor.ConstraintEqualTo(Constants.LabelCircleRadius * 2).Active = true;
            circle.Layer.CornerRadius = Constants.LabelCircleRadius;
            circle.BackgroundColor    = category.Color.ToUIColor();

            var text = new UILabel
            {
                Text      = category.Label,
                Font      = UIFont.SystemFontOfSize(Constants.LabelFontSize),
                TextColor = Constants.LabelTextColor
            };

            text.SizeToFit();

            var stackView = DataVisualizationUtils.GenerateStackView(Constants.LabelStackViewAxis,
                                                                     Constants.LabelStackViewAlignment,
                                                                     Constants.LabelStackViewDistribution,
                                                                     Constants.LabelStackViewSpacing,
                                                                     new UIView[] { circle, text });

            ConfigureBarChartLegendAccessibilityAttributes(circle, text);

            return(DataVisualizationUtils.WrapStackView(stackView,
                                                        text.Frame.Width + Constants.LabelStackViewSpacing + Constants.LabelCircleRadius * 2,
                                                        Constants.LegendHeight, NSLayoutAttribute.CenterX, NSLayoutAttribute.CenterY));
        }
Beispiel #2
0
        /// <summary>
        /// Generates the legend of the data visualization given the specified <see cref="Category"/>s.
        /// </summary>
        /// <param name="categories">The specified <see cref="Category"/>s.</param>
        /// <returns>The generated <see cref="UIView"/> representing the legend.</returns>
        private UIView GenerateLegend(IEnumerable <Category> categories)
        {
            if (categories == null)
            {
                throw new ArgumentNullException();
            }

            Labels = new Dictionary <Category, UIView>();

            var categoriesList = categories.ToList();

            var totalLength = (nfloat)0.0;

            foreach (var category in categoriesList)
            {
                var label = GetLabel(category);
                Labels.Add(category, label);
                totalLength += label.Frame.Width;
            }

            var stackView = DataVisualizationUtils.GenerateStackView(Constants.LegendStackViewAxis,
                                                                     Constants.LegendStackViewAlignment,
                                                                     Constants.LegendStackViewDistribution,
                                                                     Constants.LegendStackViewSpacing,
                                                                     Labels.Select(pair => pair.Value));

            totalLength += Labels.Count * Constants.LegendStackViewSpacing;

            return(DataVisualizationUtils.WrapStackView(stackView, totalLength, Constants.LegendHeight,
                                                        NSLayoutAttribute.LeadingMargin, NSLayoutAttribute.CenterY));
        }
Beispiel #3
0
        protected override UIView GenerateChart(IEnumerable <Dictionary <Category, int> > allDataPoints,
                                                IEnumerable <Category> allCategories)
        {
            if (allDataPoints == null || allCategories == null)
            {
                throw new ArgumentNullException();
            }

            var allDataPointsList = allDataPoints.ToList();

            _input             = allDataPointsList;
            BarCharts          = new List <BarChart>();
            _enabledCategories = new HashSet <Category>();
            _maxDataPoints     = new Dictionary <Category, int>();
            _maxDataPointSet   = new SortedSet <int>();

            foreach (var dataPoints in allDataPointsList)
            {
                var barChart = new BarChart(dataPoints, allCategories);
                BarCharts.Add(barChart);
                barChart.ParentBarChartSeries = this;

                foreach (var categoryDataPointPair in dataPoints)
                {
                    var category  = categoryDataPointPair.Key;
                    var dataPoint = categoryDataPointPair.Value;
                    if (_maxDataPoints.ContainsKey(category))
                    {
                        _maxDataPoints[category] = Math.Max(_maxDataPoints[category], dataPoint);
                    }
                    else
                    {
                        _maxDataPoints[category] = dataPoint;
                    }
                }
            }

            var stackView = DataVisualizationUtils.GenerateStackView(Constants.BarChartSeriesStackViewAxis,
                                                                     Constants.BarChartSeriesStackViewAlignment,
                                                                     Constants.BarChartSeriesStackViewDistribution,
                                                                     Constants.BarChartSeriesStackViewSpacing,
                                                                     BarCharts.Select(barChart => barChart.Chart));

            var imageCount = allDataPointsList.Count();
            var width      = imageCount * Constants.BarChartWidth +
                             (imageCount - 1) * Constants.BarChartSeriesStackViewSpacing;

            return(DataVisualizationUtils.WrapStackView(stackView, width, Constants.BarChartSeriesStackViewHeight,
                                                        NSLayoutAttribute.CenterX, NSLayoutAttribute.CenterY));
        }