ChartsOrg / Charts

Beautiful charts for iOS/tvOS/OSX! The Apple side of the crossplatform MPAndroidChart.
Apache License 2.0
27.6k stars 6k forks source link

Draggable LimitLine #1374

Open rschweda opened 8 years ago

rschweda commented 8 years ago

Hi,

thank you for this great Library. Is there any way I can make a LimitLine (in my case in a LineChart) draggable by the user? What would be the best approach to achieve this behaviour? Thank you in advance.

Bye Robert

liuxuan30 commented 8 years ago

Great question. But some context: if you zoomed in, seems there is a gesture conflict if you want draggable lines.

If we managed to solve that or you don't need zoomed in to drag, there is another issue: due to the fact the limit lines are rendered in drawRect()(in swift 3.0 it's called draw), everything is redrawn, so seems we would have performance issues if we want smooth animation while dragging. If I were doing this, I would first figure out how to only render the limit line and override some methods. This still make use of renderLimitLines() to help calculate the coordinates.

Another idea is writing some delegates to let you know where the current position is, and you directly draw a line with that position coordinates. This can be done outside of the chart, only adding a few delegate methods.

It really depends on your requirement, e.g how do you handle gesture conflicts, where user can drag, in chart or outside chart, etc.

rschweda commented 8 years ago

Thank you very much for this detailed answer. I will have a talk with the product owner because we don't have detailed information regarding the interaction with the chart. I implemented for testing the possibility to move the LimitLine by tapping and noticed also the potential rendering performance issues you mentioned, but I think that will be easy to overcome.

I like the idea with the delegate, maybe I can implement it when I know more.

Thank you again, you will surely hear from me in future :D