I work on my first OSX app in Swift and I'm lost in some Cocoa concepts.
I have a custom NSView placed inside NSScrollView. I draw complicated chart in overrided drawRect function. Chart is pretty big but NSScrollView does its job to scroll the whole view.
What I'm not happy about is that I redraw the whole chart each time drawRect is called and it's called really frequently when scrolling, resizing, etc.
Drawing a chart requires a lot of calculations and a lot of shapes need to be painted. Doing it each time a drawRect is called seems to be wrong. I know I could limit drawing to the visible / dirty rectangle, but it would be even more complicated and require even more calculations.
Is there a better approach to drawing such a scrollable chart? It would be perfect to draw the whole chart once and not to worry about redrawing it later.
I want to add some interactivity (mouse clicks) to my chart in the future. It might be important information.
Thank you