3

I have large volumes of data (items/row) stored in a file with extension .rec (just like .text) I need to show the vertices in a line graph supporting pinch zoom and dragging. I can draw the line graph with CoreGraphics. But it doesn't work well with large volumes of vertices. For large volume data it takes more than 3 mins to draw the graph. I need to draw at least 80,000 items (vertices) promptly. My current solution can handle 500 items smoothly. I have no idea how can I handle large volume of items.

I am also showing the items(Only data like row vs column, not graph) in a UICollectionView. Loading time of UICollectionView blocks the main thread and app become fridge. Can you please give me some suggestion how can I support to load large volume data.

You can find the full code, and data file on Github, I need help both on drawing the line graph and UICollectionView.

8000 Data plotted, took 1.5 mins Data on tabular form with collection view

Community
  • 1
  • 1
kallol
  • 319
  • 1
  • 13
  • This question is too broad and lacks a [Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve). The only reason why this question has not been closes is because of the bounty attached. – JAL Jul 18 '16 at 19:45
  • Did you see my codes on Github ? https://github.com/kallolfrisky/LineGraph So how can I improve my question to get solution... – kallol Jul 19 '16 at 06:26

2 Answers2

2

Don't, the screen resolution isn't high enough to make that volume of points useful anyway. Normalise your data such that you have multiple different zoom levels, like you would when tiling a map. So when zoomed out you see the overall flow, but not specific detail. As you zoom in you use 'more' data points, but in a reduced range, so overall the complexity of the graph remains the same at all levels.

The collection view is a completely different thing. Re-rendering each graph every time the collection scrolls is not going to work well. You'll need to do some caching, either of the graphs or snapshot images of the graphs. You'll need to be careful of memory usage and it'll be very difficult not to have some lag while scrolling to new graphs of you don't prepare them (or snapshots of them) in advance. You should also have paging turned on so you don't have multiple graphs on screen at the same time.

Wain
  • 118,658
  • 15
  • 128
  • 151
  • Thank you so much. My context is scrollable, you can see by running the codes. Your idea is good but I could not manage to implement in code level. I am showing only data on collection view not graph... – kallol Jul 17 '16 at 16:13
  • I just edited my post and uploaded images, so that you get the better scene about the problem... – kallol Jul 17 '16 at 16:22
  • for the graph you need to do something like take groups of X points and average the values, then draw this new smaller set of values as the graph. change X as the zoom scale changes. for the collection view you need to batch / page load, and / or load the data in the background – Wain Jul 17 '16 at 16:41
1

I suggest you watch Session 211 of WWDC 2012, Building Concurrent User Interfaces and apply the concepts there. This features cells whose contents are independently queried and rendered. It involves a table view but the same concept can apply to collection views.

The basic concept is as follows:
1. In tableView:cellForRowAtIndexPath, a cell is instantiated.
2. In the same method, an operation for retrieving the data to populate the cell is created and stored into a dictionary. A reference to the cell is passed to the operation. The operation has a completion handler that populates the cell and removes the operation from the dictionary.
3. Before the cell is returned from the method, the operation is added to an operation queue.
4. In tableView:didEndDisplayingCell:forRowAtIndexPath, operations for cells that have moved off-screen are cancelled and removed from the dictionary.

jp2g
  • 682
  • 4
  • 8
  • Thanks buddy, this Concurrent task handling with NSOperationQueue helps me to run the data parsing on separate thread and keep main thread fee but drawing graph still with no solution and taking too much time. – kallol Jul 16 '16 at 01:44