NSBezierPathを含むNSViewの描画を最適化する方法がわかりません。
私が何を意味するのか説明してみましょう。約4万点の折れ線グラフを描きたいと思います。私はすべてのポイントを持っており、次のコードを使用して完全グラフを一度描くのは簡単です。
NSInteger npoints=[delegate returnNumOfPoints:self]; //get the total number of points
aRange=NSMakeRange(0, npoints); //set the range
absMin=[delegate getMinForGraph:self inRange:aRange]; //get the Minimum y value
absMax=[delegate getMaxForGraph:self inRange:aRange]; //get the Maximum y value
float delta=absMax-absMin; //get the height of bound
float aspectRatio=self.frame.size.width/self.frame.size.heigh //compensate for the real frame
float xscale=aspectRatio*(absMax-absMin); // get the width of bound
float step=xscale/npoints; //get the unit size
[self setBounds:NSMakeRect(0.0, absMin, xscale, delta)]; //now I can set the bound
NSSize unitSize={1.0,1.0};
unitSize= [self convertSize:unitSize fromView:nil];
[NSBezierPath setDefaultLineWidth:MIN(unitSize.height,unitSize.width)];
fullGraph=[NSBezierPath bezierPath];
[fullGraph moveToPoint:NSMakePoint(0.0, [delegate getValueForGraph:self forPoint:aRange.location])];
//Create the path
for (long i=1; i<npoints; i++)
{
y=[delegate getValueForGraph:self forPoint:i];
x=i*step;
[fullGraph lineToPoint:NSMakePoint(x,y)];
}
[[NSColor redColor] set];
[fullGraph stroke];
これで、グラフ全体が実際の座標でNSBezierPath形式で保存され、ストロークできるようになりました。しかし、ここで、一度に1つのポイントをできるだけ速く追加してグラフを表示したいとします。
毎回ポイントのセット全体を描きたくありません。可能であれば、完全なグラフを使用して、ごく一部だけを視覚化したいと思います。同じフレームに最初の1000ポイントだけをレンダリングしたいとします。グラフの最初の部分だけを正しい境界でレンダリングする可能性(境界を変更し、最終的にはパスを何らかの方法でスケーリングする)はありますか?
境界を変更するとスケールが変化し、線幅の問題を修正できないため、結果を取得できませんでした。