Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Selectable marker view & images at Y axis #485

Closed
aenglund opened this issue Oct 20, 2015 · 8 comments
Closed

Selectable marker view & images at Y axis #485

aenglund opened this issue Oct 20, 2015 · 8 comments

Comments

@aenglund
Copy link

Hi!
I would like to have my marker view tappable, but as far as I can tell, I can't really provide an actual UIView to be presented inside the marker view. The marker view class is only responsible for directly drawing on the provided CGContext. Is there a neat way to approach this, or is it the best option to add a gesture recognizer to the chart and check if the tap point is at the marker?

Also, I am looking to change the labels on the X axis of my bar chart into images. I'm really not sure how to approach this either. I'm thinking that maybe I should create a custom ChartAxisRenderer..? Or layout the images as subviews on a containing view, and then try to reposition them accordingly as the chart is panned, resized or translated in any way?

Thanks in advance.

@danielgindi
Copy link
Collaborator

  1. You can place a UIView, listen to highlight events of the chart and place your UIView. Or add a gesture recognizer and then show the UIView. Anyway - not that complex...
  2. Yes as it is currently not a feature, you could just provide a custom renderer and render your images

@aenglund
Copy link
Author

Thanks for your help!

  1. If I take that approach. Do you know if there is a great way to react when the chart is panned or redrawn so that I can recalculate the position? The current marker view solution has this nice way of being animated alongside the bar which I would like to keep if possible.
  2. Seems fair!

@liuxuan30
Copy link
Member

Let me save your day :)
I have already did this. A more friendly approach for what I could come up with is, you extend the ChartViewBase, add a marker selected handler, and sub class the chart view delegate and add this handler. Then you can handle it in your vc.

You need to calculate the tap point I think. Using UIView will cost you a lot (think about zooming/scrolling) to write a similar one.

If you don't allow to tap the marker while animating, it seems not that hard to write.

Some downside is that if you have many chart markers, determining which one is the closest to the tap point is O(n) cost.

@aenglund
Copy link
Author

Thanks @liuxuan30. Feels like the best way to handle this. I have tried to extend the BarLineChartViewBase and add a new target to the already existing tap gesture recognizer. Did you take the same approach?
The default behaviour is to deselect the highlighted bar if the same index is selected. Causing the array of highlighted bars to be empty when my new target in the extension gets called. I could of course rehighlight it if the tap is inside the marker, but it feels a bit annoying. Did you have a better solution to this? I don't see how you can get a way with extending just the ChartViewBase?

@liuxuan30
Copy link
Member

Just put your delegate at the last line of recognizer.state == UIGestureRecognizerState.Ended. Then it will not be interfered by deSelect
You have already extended BarLineChartViewBase, why can't ChartViewBase? :)

@aenglund
Copy link
Author

Okay! I see what you mean. When you said extend, I thought you where talking about a Swift-extension. I would preferably try to find a solution that doesn't require me to modify the actual framework, but rather introspect or subclass the framework classes. That will make it easier to maintain and update the framework to newer versions later on.
I will try to go with your solution but instead subclass the BarChartView and add an additional tap gesture recognizer with a dependency to the _tapGestureRecognizer in BarLineChartViewBase. If I can make that work, I will at least keep my modifications isolated from the classes provided by the framework. I of course need to have my own fork, since my classes needs to access some instance variables marked as internal, but it will at least be conflict free merges when newer versions is released.
I'll get back to you when I've tried it out!

@aenglund
Copy link
Author

Yes, that solution did work in the way I expected. Now it seems like I can achieve what I want without modifying any classes in the framework. Thanks for your help @liuxuan30
I did also implemented my own ChartAxisRenderer with support of drawing images on the X-axis. Thanks also to you, @danielgindi

@liuxuan30
Copy link
Member

Hey I do mean swift extension by saying 'extending'. Just like category to ObjC.
You have a ChartViewBase extension, add a markerSelected method, and then you have you own tapGestureHandler and call the delegate.
You don't need to add a new tap gesture, just have your own tapGestureHandler, because it's private now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants