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

Enhancement: Linked x-axis or stacked y-axis. #1022

Closed
aastein opened this issue May 12, 2016 · 8 comments
Closed

Enhancement: Linked x-axis or stacked y-axis. #1022

aastein opened this issue May 12, 2016 · 8 comments

Comments

@aastein
Copy link

aastein commented May 12, 2016

I need to plot data over the same range, but with drastically different values. It would be great if there was a way to stack/merge plots so the x-axis limits remain the same with any gestures. This means y-axis scaling and values would remain independent. It would also be great if the vertical line used to focus on a single data point could extend to all of the plots.

Image showing what this enhancement could be applied to:
thumb_img_1396_1024

@liuxuan30
Copy link
Member

liuxuan30 commented May 12, 2016

well it's a highly special chart, looks like put 3 different charts together, just with same xIndex. That's a workaround.

For the native support, I guess it's beyond the purpose of this library and arch. It's nice to have, but a lot of work to be done in order to achieve so. If you can work it out and file a PR, you are more than welcome.

@aastein
Copy link
Author

aastein commented May 13, 2016

Thanks @liuxuan30,I think I may have to do that.

For now, how can I set the chart to be displayed with a set min and max x axis?
So: My x axis has values 0 to 20, but I want to programmatically display "zoomed in" to values 5 to 8.

Is this possible at the moment?

Using ChartView.highestVisibleXIndex and ChartView.lowestVisibleXIndex would get the values in chartTranslated function. I'm not sure how to use those values to resize the other charts.

If this is not implemented in any intentional way, do you know what functions/classes are used to set the x-axis viewable limits?

@aastein
Copy link
Author

aastein commented May 15, 2016

@liuxuan30 I have implemented a fix for linking navigation, it is not implemented in the library so i guess it's technically a work around, but the behavior is the same as "real" fix would be. What do you think the best way to implement this in the library is? Maybe package it so you can use

chartView.linkedCharts = ["identifier1", "identifier2", "identifier3"]

For panning:

  1. Add an identifier variable to your ChartViewBase class
  2. Use chartTranslated, a ChartViewBase protocol method, in your chart delegate to get the translation of the chart your fingers are touching
  3. Use the logic in performPanChange, a function in BarLineChartViewBase, on the other charts.
  4. you may want to set the dY to 0.

For pinch zooming:

  1. Add an identifier variable to your ChartViewBase class
  2. Use chartScaled, a ChartViewBase protocol method, in your chart delegate to get the scale of the chart your fingers are touching.
  3. Change this line

delegate?.chartScaled?(self, scaleX: scaleX, scaleY: scaleY)

to this

delegate?.chartScaled?(self, scaleX: scaleX, scaleY: scaleY, location: location)

in BarLineChartViewBase.swift and update the protocol method it is calling in ChartViewBase to be this:

optional func chartScaled(chartView: ChartViewBase, scaleX: CGFloat, scaleY: CGFloat, location: CGPoint)

  1. Use this part of the logic inpinchGestureRecognized, a function in BarLineChartViewBase, on the other charts, when you call chartScaled in your chart delegate. You may want to not change the y-scale on pinch.
var matrix = CGAffineTransformMakeTranslation(location.x, location.y)
                    matrix = CGAffineTransformScale(matrix, scaleX, scaleY)
                    matrix = CGAffineTransformTranslate(matrix,
                        -location.x, -location.y)

                    matrix = CGAffineTransformConcat(_viewPortHandler.touchMatrix, matrix)

                    _viewPortHandler.refresh(newMatrix: matrix, chart: self, invalidate: true)

@liuxuan30
Copy link
Member

try setVisibleXRangeMaximum

@aastein
Copy link
Author

aastein commented May 16, 2016

that was the first thing I tried. It didn't work, I like my solution better because it actually links the user input.

@liuxuan30
Copy link
Member

if setVisibleXRangeMaximum not work, then a bug I guess, though I don't know why and how to fix. Sorry that you had a lot of info that I can't digest in a short time.
You can keep your solution, or try fix the real issue :)

@aastein
Copy link
Author

aastein commented May 16, 2016

It's not entirely a bug. Even if that feature worked as intended it would not present the desired behavior.

If I pan on chart A, with chart A zoomed in, so that new data is shown I want the same type of "scrolling through the data" animation on/in charts B and C.

With setVisibleXRangeMaximum working correctly, charts B and C would be reloaded with the correct data limits, but the scrolling or zooming animation wouldn't be present. This would be very visible if gridlines were enabled on the xAxis.

@danielgindi
Copy link
Collaborator

I think that with the current callbacks and methods - you could easily sync the viewports between charts...

@jjatie jjatie closed this as completed Apr 1, 2018
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

4 participants