How do I pad a graph so that lines aren't clipped by the edges?

◇◆丶佛笑我妖孽 提交于 2019-12-11 06:29:44

问题


I've had a pretty good look around for an answer to this, and tried several solutions in my code, nothing found so far.

I have a line graph that I am plotting, a CPTScatterPlot graph, and I have got points adding to it correctly. I want to show each of these points as a dot about 3-5 pixels in diameter, and connected by lines that are about 3 pixels wide. This all works fine.

The problem is that when the plot is a straight along one of the edges of the graph hosting view, the lines and dots are clipped and don't look right at all.

This is a mockup of what it should look like:

And this is the effect I am seeing much of the time at the moment:

I apologise for the small images, but hopefully you can see that in the second one, the line and dots are rendered only a few pixels into the graph view, not fully in view. In the second one the data is actually at y=1 for the first 75%, then falls down to y=0.

How can I inset the drawing of the graph components by several pixels to prevent the clipping of any shapes?

So far:

  • I have tried setting the padding on the graph, but that just contracts the area it draws to, I suppose to make room for titles which I am not using.

  • I have also tried adding to the min/max x/y range settings which I recalculate based on the data I am updating in the background. This works, but obviously only if the amount I add to those values is correct in relation to the drawing scale that will be used for the data values I am inputting.

  • I am on Mac OS using NSView (actually CPTGraphHostingView) so clipsToBounds isn't available. Also, I tried masksToBounds and masksToBorder on CPTXYGraph.


回答1:


I think the easiest way to handle this is to simply extend your ranges by a small amount. There is a method in CPTPlotRange that makes it very easy to extend a given range by a fixed percentage (e.g. 1%). I think the main test app example even shows this in action.

Another option would be to turn off the masksToBounds and/or masksToBorder on the CPTPlotArea (plotArea) and possibly the CPTPlotAreaFrame (plotAreaFrame). You access them both via properties of the graph.




回答2:


This might be of help..

The default padding on the graph itself (not the plot area frame) is 20 pixels on each side. You can change that, too.

graph.paddingLeft = 0.0;
graph.paddingTop = 0.0;
graph.paddingRight = 0.0;
graph.paddingBottom = 0.0;


来源:https://stackoverflow.com/questions/10068283/how-do-i-pad-a-graph-so-that-lines-arent-clipped-by-the-edges

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!