/// <summary>
 /// constructor
 /// </summary>
 /// <param name="x">the x-value of the highlighted value</param>
 /// <param name="y">the y-value of the highlighted value</param>
 /// <param name="xPx"></param>
 /// <param name="yPx"></param>
 /// <param name="dataSetIndex"> the index of the DataSet the highlighted value belongs to</param>
 /// <param name="axis"></param>
 public Highlight(float x, float y, float xPx, float yPx, int dataSetIndex, YAxisDependency axis)
 {
     X            = x;
     Y            = y;
     XPx          = xPx;
     YPx          = yPx;
     DataSetIndex = dataSetIndex;
     Axis         = axis;
 }
Beispiel #2
0
        /// <summary>
        /// draws the y-axis labels to the screen
        /// </summary>
        public virtual void RenderAxisLabels(SKCanvas c)
        {
            if (!YAxis.IsEnabled || !YAxis.IsDrawLabelsEnabled)
            {
                return;
            }

            SKPoint[] positions = GetTransformedPositions();

            AxisLabelPaint.Typeface = YAxis.Typeface;
            AxisLabelPaint.TextSize = YAxis.TextSize;
            AxisLabelPaint.Color    = YAxis.TextColor;

            float xoffset = YAxis.XOffset;
            float yoffset = AxisLabelPaint.MeasureHeight("A") / 2.5f + YAxis.YOffset;

            YAxisDependency dependency = YAxis.AxisDependency;

            YAxis.YAxisLabelPosition labelPosition = YAxis.Position;

            float xPos;

            if (dependency == YAxisDependency.Left)
            {
                if (labelPosition == YAxis.YAxisLabelPosition.OutSideChart)
                {
                    AxisLabelPaint.TextAlign = SKTextAlign.Right;
                    xPos = ViewPortHandler.OffsetLeft - xoffset;
                }
                else
                {
                    AxisLabelPaint.TextAlign = SKTextAlign.Left;
                    xPos = ViewPortHandler.OffsetLeft + xoffset;
                }
            }
            else
            {
                if (labelPosition == YAxis.YAxisLabelPosition.OutSideChart)
                {
                    AxisLabelPaint.TextAlign = SKTextAlign.Left;
                    xPos = ViewPortHandler.ContentRight + xoffset;
                }
                else
                {
                    AxisLabelPaint.TextAlign = SKTextAlign.Right;
                    xPos = ViewPortHandler.ContentRight - xoffset;
                }
            }

            DrawYLabels(c, xPos, positions, yoffset);
        }
Beispiel #3
0
        public override void RenderAxisLabels(SKCanvas c)
        {
            if (!YAxis.IsEnabled || !YAxis.IsDrawLabelsEnabled)
            {
                return;
            }

            SKPoint[] positions = GetTransformedPositions();

            AxisLabelPaint.Typeface  = YAxis.Typeface;
            AxisLabelPaint.TextSize  = YAxis.TextSize;
            AxisLabelPaint.Color     = YAxis.TextColor;
            AxisLabelPaint.TextAlign = SKTextAlign.Center;

            float baseYOffset = 2.5f.DpToPixel();
            float textHeight  = AxisLabelPaint.MeasureHeight("Q");

            YAxisDependency dependency = YAxis.AxisDependency;

            YAxis.YAxisLabelPosition labelPosition = YAxis.Position;

            float yPos;

            if (dependency == YAxisDependency.Left)
            {
                if (labelPosition == YAxis.YAxisLabelPosition.OutSideChart)
                {
                    yPos = ViewPortHandler.ContentTop - baseYOffset;
                }
                else
                {
                    yPos = ViewPortHandler.ContentTop - baseYOffset;
                }
            }
            else
            {
                if (labelPosition == YAxis.YAxisLabelPosition.OutSideChart)
                {
                    yPos = ViewPortHandler.ContentBottom + textHeight + baseYOffset;
                }
                else
                {
                    yPos = ViewPortHandler.ContentBottom + textHeight + baseYOffset;
                }
            }

            DrawYLabels(c, yPos, positions, YAxis.YOffset);
        }
        /// <summary>
        /// Returns the Highlight of the DataSet that contains the closest value on the
        /// y-axis.
        /// </summary>
        /// <param name="closestValues">contains two Highlight objects per DataSet closest to the selected x-position(determined by
        ///                             rounding up an down)</param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="axis"> the closest axis</param>
        /// <param name="minSelectionDistance"></param>
        /// <returns></returns>
        public Highlight GetClosestHighlightByPixel(IList <Highlight> closestValues, float x, float y,
                                                    YAxisDependency axis, float minSelectionDistance)
        {
            Highlight closest  = null;
            float     distance = minSelectionDistance;

            for (int i = 0; i < closestValues.Count; i++)
            {
                Highlight high = closestValues[i];

                if (high.Axis == axis)
                {
                    float cDistance = GetDistance(x, y, high.XPx, high.YPx);

                    if (cDistance < distance)
                    {
                        closest  = high;
                        distance = cDistance;
                    }
                }
            }

            return(closest);
        }
 /// <summary>
 ///  Constructor, only used for stacked-barchart.
 /// </summary>
 /// <param name="x">the index of the highlighted value on the x-axis</param>
 /// <param name="y">the y-value of the highlighted value</param>
 /// <param name="xPx"></param>
 /// <param name="yPx"></param>
 /// <param name="dataSetIndex">the index of the DataSet the highlighted value belongs to</param>
 /// <param name="stackIndex">references which value of a stacked-bar entry has been selected</param>
 /// <param name="axis"></param>
 public Highlight(float x, float y, float xPx, float yPx, int dataSetIndex, int stackIndex, YAxisDependency axis) : this(x, y, xPx, yPx, dataSetIndex, axis)
 {
     StackIndex = stackIndex;
 }
 public override Point GetPosition(Entry e, YAxisDependency axis)
 {
     if (e == null)
     {
         return(default);
        /// <summary>
        /// Returns the minimum distance from a touch value (in pixels) to the
        /// closest value(in pixels) that is displayed in the chart.
        /// </summary>
        protected float GetMinimumDistance(IList <Highlight> closestValues, float pos, YAxisDependency axis)
        {
            float distance = float.MaxValue;

            for (int i = 0; i < closestValues.Count; i++)
            {
                Highlight high = closestValues[i];

                if (high.Axis == axis)
                {
                    float tempDistance = Math.Abs(GetHighlightPos(high) - pos);
                    if (tempDistance < distance)
                    {
                        distance = tempDistance;
                    }
                }
            }

            return(distance);
        }