예제 #1
0
        public void Render(GraphBuilder context, IImageProcessingContext <Rgba32> renderContext, GraphicsOptions renderOptions)
        {
            // top left is renderer's origin point

            if (LineDistanceVertical.HasValue)
            {
                float          interval   = context.ToPixelsVertical(LineDistanceVertical.Value);
                int            gridLineCt = 0;
                Action <float> loopBody   = y =>
                {
                    renderContext.DrawLines(MajorVerticalGridLineInterval > 0 && gridLineCt % MajorVerticalGridLineInterval == 0 ? MajorVerticalPen : VerticalPen, new PointF[] {
                        new PointF(context.GridRegion.Left, y),
                        new PointF(context.GridRegion.Right, y)
                    }, renderOptions);
                    gridLineCt++;
                };
                // 2 loops so we're guaranteed to be aligned to the origin and X-axis
                // note that major grid lines will overlap axes
                for (float y = context.GridRegion.Top + context.Origin.Y; y < context.GridRegion.Bottom; y += interval)
                {
                    loopBody(y);
                }
                gridLineCt = 0;
                for (float y = context.GridRegion.Top + context.Origin.Y; y > context.GridRegion.Top; y -= interval)
                {
                    loopBody(y);
                }
            }
            if (LineDistanceHorizontal.HasValue)
            {
                float          interval   = context.ToPixelsHorizontal(LineDistanceHorizontal.Value);
                int            gridLineCt = 0;
                Action <float> loopBody   = x =>
                {
                    renderContext.DrawLines(MajorHorizontalGridLineInterval > 0 && gridLineCt % MajorHorizontalGridLineInterval == 0 ? MajorHorizontalPen : HorizontalPen, new PointF[] {
                        new PointF(x, context.GridRegion.Top),
                        new PointF(x, context.GridRegion.Bottom)
                    }, renderOptions);
                    gridLineCt++;
                };

                // 2 loops so we're guaranteed to be aligned to the origin and Y-axis
                for (float x = context.GridRegion.Left + context.Origin.X; x < context.GridRegion.Right; x += interval)
                {
                    loopBody(x);
                }
                gridLineCt = 0;
                for (float x = context.GridRegion.Left + context.Origin.X; x > context.GridRegion.Left; x -= interval)
                {
                    loopBody(x);
                }
            }
        }
예제 #2
0
        public void Render(GraphBuilder context, IImageProcessingContext <Rgba32> renderContext, GraphicsOptions options)
        {
            PointF originPixelPos = (context.GridRegion.Position() + context.Origin);

            if (Axis.IsHorizontal)
            {
                float leftBound  = context.GridRegion.Left;
                float rightBound = context.GridRegion.Right;

                float xData = EnableForZero ? 0 : TickDistance;
                float x     = originPixelPos.X + context.ToPixelsHorizontal(xData);

                // doesn't lend itself to log scales...
                float pixelTick = context.ToPixelsHorizontal(TickDistance);

                while (x < rightBound)
                {
                    Image <Rgba32> generatedLabel = GenerateLabel(xData, options);
                    renderContext.DrawImage(generatedLabel, generatedLabel.Size(), new Point((int)x, (int)originPixelPos.Y), options);

                    x     += pixelTick;
                    xData += TickDistance;
                }

                xData = -TickDistance;
                x     = originPixelPos.X + context.ToPixelsHorizontal(xData);


                while (x > leftBound)
                {
                    x     -= pixelTick;
                    xData -= TickDistance;
                }
            }
            else
            {
                float topBound    = context.GridRegion.Left;
                float bottomBound = context.GridRegion.Right;

                float yData = EnableForZero ? 0 : TickDistance;
                float y     = originPixelPos.Y + context.ToPixelsVertical(yData);

                // doesn't lend itself to log scales...
                float pixelTick = context.ToPixelsVertical(TickDistance);

                while (y < bottomBound)
                {
                    Image <Rgba32> generatedLabel = GenerateLabel(yData, options);
                    renderContext.DrawImage(generatedLabel, generatedLabel.Size(), new Point((int)originPixelPos.X, (int)y), options);

                    y     += pixelTick;
                    yData += TickDistance;
                }

                yData = -TickDistance;
                y     = originPixelPos.Y + context.ToPixelsVertical(yData);


                while (y > topBound)
                {
                    Image <Rgba32> generatedLabel = GenerateLabel(yData, options);
                    renderContext.DrawImage(generatedLabel, generatedLabel.Size(), new Point((int)originPixelPos.X, (int)y), options);

                    y     -= pixelTick;
                    yData -= TickDistance;
                }
            }
        }