如何填充图形,使线条不被边缘剪切? [英] How do I pad a graph so that lines aren't clipped by the edges?
问题描述
我有一个很好的环顾四周的答案,并在我的代码尝试了几个解决方案,到目前为止还没有发现。
我有一行我绘制的图,一个 CPTScatterPlot
图,我有正确添加点。我想将这些点显示为直径约3-5个像素的点,并通过大约3个像素宽的线连接。这一切都很好。
问题是,当绘图是沿着主图视图的一条边的直线时,线和点被剪切,
这是一个应该看起来像样的模型:
这是我看到很多时间的效果时刻:
我为小图片道歉,但希望你能看到在第二个,线和点渲染只有几个像素到图形视图,不完全在视图中。在第二个数据实际上在第一个75%的y = 1,然后下降到y = 0。
如何插入图纸
到目前为止:
-
我已经尝试在图形上设置填充,但是只是
收缩它绘制的区域,我想为标题腾出空间
不使用。 -
我也尝试添加到最小/最大x / y范围设置,I
根据我更新的数据重新计算在背景中。这个
工作,但显然只有当我添加到这些值的
正确的相对于绘图比例将被用于我输入的
数据值。 -
我在Mac OS上使用NSView(实际上是CPTGraphHostingView),因此
clipsToBounds
不可用。此外,我在CPTXYGraph上尝试了masksToBounds
和masksToBorder
。 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 triedmasksToBounds
andmasksToBorder
on CPTXYGraph.
我认为最简单的处理方式是简单地扩展你的范围。在CPTPlotRange中有一种方法,它使得很容易将给定范围扩展固定的百分比(例如1%)。
另一种选择是关闭CPOTlotArea(plotArea)上的masksToBounds和/或masksToBorder, CPTPlotAreaFrame(plotAreaFrame)。您可以通过图表的属性访问它们。
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 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.
这篇关于如何填充图形,使线条不被边缘剪切?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!