Esempio n. 1
0
        private IEnumerable <AxisIncrementToRender> GetLabels(GraphView graph, Rect bounds)
        {
            // if no labels
            if (Increment == 0)
            {
                yield break;
            }

            int labels = 0;
            int x      = GetAxisXPosition(graph);

            // remember screen space is top down so the lowest graph
            // space value is at the bottom of the screen
            var start = graph.ScreenToGraphSpace(x, bounds.Height - 1);
            var end   = graph.ScreenToGraphSpace(x, 0);

            // don't draw labels below the minimum
            if (Minimum.HasValue)
            {
                start.Y = Math.Max(start.Y, Minimum.Value);
            }

            var current = start;
            var dontDrawBelowScreenY = bounds.Height - graph.MarginBottom;

            while (current.Y < end.Y)
            {
                int screenY = graph.GraphSpaceToScreen(new PointF(current.X, current.Y)).Y;

                // if the axis label is above the bottom margin (screen y starts at 0 at the top)
                if (screenY < dontDrawBelowScreenY)
                {
                    // Create the axis symbol
                    var toRender = new AxisIncrementToRender(Orientation, screenY, current.Y);

                    // and the label (if we are due one)
                    if (ShowLabelsEvery != 0)
                    {
                        // if this increment also needs a label
                        if (labels++ % ShowLabelsEvery == 0)
                        {
                            toRender.Text = LabelGetter(toRender);
                        }
                        ;
                    }

                    // draw the axis symbol (and label if it has one)
                    yield return(toRender);
                }

                current.Y += Increment;
            }
        }
Esempio n. 2
0
        private IEnumerable <AxisIncrementToRender> GetLabels(GraphView graph, Rect bounds)
        {
            // if no labels
            if (Increment == 0)
            {
                yield break;
            }

            int labels = 0;
            int y      = GetAxisYPosition(graph);

            var start = graph.ScreenToGraphSpace(0, y);
            var end   = graph.ScreenToGraphSpace(bounds.Width, y);

            // don't draw labels below the minimum
            if (Minimum.HasValue)
            {
                start.X = Math.Max(start.X, Minimum.Value);
            }

            var current = start;

            while (current.X < end.X)
            {
                int screenX = graph.GraphSpaceToScreen(new PointF(current.X, current.Y)).X;

                // Ensure the axis point does not draw into the margin
                if (screenX >= graph.MarginLeft)
                {
                    // The increment we will render (normally a top T unicode symbol)
                    var toRender = new AxisIncrementToRender(Orientation, screenX, current.X);

                    // Not every increment has to have a label
                    if (ShowLabelsEvery != 0)
                    {
                        // if this increment does also needs a label
                        if (labels++ % ShowLabelsEvery == 0)
                        {
                            toRender.Text = LabelGetter(toRender);
                        }
                        ;
                    }

                    // Label or no label definetly render it
                    yield return(toRender);
                }

                current.X += Increment;
            }
        }
Esempio n. 3
0
 private string DefaultLabelGetter(AxisIncrementToRender toRender)
 {
     return(toRender.Value.ToString("N0"));
 }