Example #1
0
        /// <summary>
        /// Measures the height of the text.
        /// </summary>
        /// <returns>The text height.</returns>
        /// <param name="axis">Axis.</param>
        private double MeasureTextHeight(LinearAxis axis)
        {
            IList <double> majorLabelValues = new List <double>();
            IList <double> majorTickValues  = new List <double>();
            IList <double> minorTickValues  = new List <double>();

            if (axis.ActualMinorStep == 0 || axis.ActualMajorStep == 0)
            {
                return(0);
            }

            axis.GetTickValues(out majorLabelValues, out majorTickValues, out minorTickValues);

            double bestHeight = 0;

            foreach (var label in majorLabelValues)
            {
                var size = rc.MeasureText(axis.LabelFormatter(label), axis.Font, axis.FontSize, axis.FontWeight);
                if (size.Width > bestHeight)
                {
                    bestHeight = size.Height;
                }
            }

            return(bestHeight);
        }
Example #2
0
        /// <summary>
        /// Measures the largest text size for the axis.
        /// </summary>
        /// <returns>The text.</returns>
        /// <param name="axis">Axis.</param>
        private double MeasureTextWidth(LinearAxis axis)
        {
            IList <double> majorLabelValues = new List <double>();
            IList <double> majorTickValues  = new List <double>();
            IList <double> minorTickValues  = new List <double>();

            if (axis.ActualMinorStep == 0 || axis.ActualMajorStep == 0)
            {
                return(0);
            }

            try {
                if (axis.LabelFormatter != null)
                {
                    axis.GetTickValues(out majorLabelValues, out majorTickValues, out minorTickValues);

                    double bestWidth = 0;
                    foreach (var label in majorLabelValues)
                    {
                        var size = rc.MeasureText(axis.LabelFormatter(label), axis.Font, axis.FontSize, axis.FontWeight);
                        if (size.Width > bestWidth)
                        {
                            bestWidth = size.Width;
                        }
                    }

                    return(bestWidth);
                }
                else
                {
                    return(0);
                }
            } catch (Exception e) {
                Log.E(this, "Failing to measure text width", e);
                return(0);
            }
        }