Skip to content

Charts for ResearchKit (Issue #92) - #178

Merged
YuanZhu-apple merged 102 commits into
ResearchKit:masterfrom
coxy1989:coxy-graphs
Aug 19, 2015
Merged

YuanZhu-apple merged 102 commits into
ResearchKit:masterfrom
coxy1989:coxy-graphs

Conversation

@coxy1989

Copy link
Copy Markdown
Member

API for Line, Discrete and Pie charts for RK.

Do you feel the circular progress view for the day's tasks that appears is the AppCore apps' dashboards qualifies as a chart that should be included too, seems broadly useful to most/all RK apps. Badges is another which could also be included.

I think including those charts in RK and the catalog may encourage developers to contribute their own charts to the proj which can't be a bad thing

One of the big challenges of RK apps face will be to retain participants for as long as possible, a broader range of great looking/ interesting dashboard charts is one way to do that.
#92

@rsanchezsaez

Copy link
Copy Markdown
Contributor

Hey @coxy1989, this looks like a great PR, congrats.

I've been drafting a ResearchKit Coding Style guide. It might be a good idea to make sure your PR conforms to it, as there are some divergencies between the ResearchKit and AppCore styles.

(Specially, the opening brackets on the same line item.)

Do note that the guide is a work in progress: and any comments are welcome (via Issue #174 or the mailing list).

@jwe-apple

Copy link
Copy Markdown
Member

Wow, that was quick! Thanks!

@jwe-apple

Copy link
Copy Markdown
Member

I'll review in detail tomorrow. Thanks

@jwe-apple

Copy link
Copy Markdown
Member

@rsanchezsaez to review.

@jwe-apple

Copy link
Copy Markdown
Member

btw this is not expected to go into v1.1, if we take this it'll be after the branch.

@rsanchezsaez

Copy link
Copy Markdown
Contributor

I have not started reviewing the code yet, but there seems to be a problem in the pie chart layout. The bottom percentage label overlaps the legend. @coxy1989: Could you look into that?

It happens on all devices. See an iPhone 6 screenshot below.

ios simulator screen shot 17 may 2015 22 01 03

@rsanchezsaez

Copy link
Copy Markdown
Contributor

I'm in the middle of reviewing the code, expect more comments soon. A head start: we'll need to add appledoc comments to all the new headers, it'd be a good idea to start thinking about them.

@coxy1989

Copy link
Copy Markdown
Member Author

oops sorry didn't see you were up to this before I pushed that change. Will take a look at your comments now.

@rsanchezsaez

Copy link
Copy Markdown
Contributor

I'm internally debating on what the names for the main chart classes should be.

First, there's the debate between chart vs graph. Semantically, all graphs are charts but not all charts are graphs. A pie chart is certainly not a graph, so I think it was a good call to rename APCPieGraph to ORKPieChart.

Regarding ORKBaseGraph, ORKDiscreteGraph and ORKLineGraph, I'm weakly in favour of renaming all those to ORK*Chart, to denote that they are "ResearchKit chart objects". I think I'd also drop the Base prefix from the superclass (which denotes the fact that it's an abstract class, but we can document that instead).

So I think I'd go for ORKBidimensionalChart, with its ORKDiscreteChart and ORKLineChart subclasses (or maybe ORKBidimensionalGraphChart, with its ORKDiscreteGraphChart and ORKLineGraphChart if we want to be more specific at the cost of verbosity).

@jwe-apple, @coxy1989: What are your thoughts on this?


Please also note that there is a chance for greater code reuse between the discrete and line charts. I've been noticing a good amount of duplicated code which could be moved to the superclass.

@jwe-apple

Copy link
Copy Markdown
Member

Let's not jump the gun on actually making these naming changes. I don't have time to review right now, but this needs at least a couple other reviews.

@rsanchezsaez

Copy link
Copy Markdown
Contributor

Ok, let's leave the class naming for later. I'll delve into reviewing the actual code.

Comment thread ResearchKit/Common/ORKBaseGraphView.m Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extract all colors to ORKSkin (see ORKColor() function).

Also:
- Some property renames.
- Make text property of 'copy' type.
- Remove unneeded 'hidesLegend' property.
…-graphs

# Conflicts:
#	ResearchKit.xcodeproj/project.pbxproj
#	ResearchKit/Common/ORKHelpers.h
#	ResearchKit/Common/ORKHelpers.m
#	Testing/ORKTest/ORKTest.xcodeproj/project.pbxproj
#	Testing/ORKTest/ORKTest/MainViewController.m
@rsanchezsaez

Copy link
Copy Markdown
Contributor

I have finally finished reworking and refactoring the chart code to the point I think is ready to merge into master. I submitted a new PR against @coxy1989's branch. The changeset is huge, so a peer review would quite helpful. Sorry again for the delay!

An overview of some of the changes:

  • The main chart classes (ORKPieChartView; and ORKGraphView with its ORKDiscreteGraphView and ORKLineGraphView subclasses) now operate in the same way regarding layout and animation.
  • For performance, I have decoupled graphic-element-CALayers creation from their layout. Layer creation happens when the dataSource changes (as that is what informs the number of CALayer needed). Layer layout generally happens in -layoutSubviews. When a property changes that needs layout of some elements only, the relevant layers are laid out (instead of indiscriminately re-layouting everything).
  • All three views respond to -traitCollectionDidChange: and trigger their own layout on rotation, without having to manually do so externally.
  • All three views can by animated when first appearing on screen by calling animateWithDuration: from the owning view controller's -viewWillAppear:.
  • Another performance improvement: ORKGraphView reuses the layer.contents for the single points (that was a huge performance boost when rotating the device).
  • ORKPieChartView was sliced into pie, legend and titleText views. This simplifies logic and allows to use constraints for a simple layout on the parent view. The legend and titleText views calculate their own intrinsic content size, and the pie takes the remaining space.
  • Added dynamic contentSizeCategory text support to all ORKGraphView text, and removed needless axisTitleFont property. Also renamed some properties to be more UIKit-like.
  • Made sure all custom properties propagate and work as intended. If you change a property when the graph is displayed, it re-layouts and redraws immediately if needed.
  • Simplified the ORKCatalog example to make it more visually appealing. Added a more involved ORKTest example/test. The ORKTest example changes most of the graph properties at staged delays to make sure the live updating works.
  • Minor headerdoc comment improvements.
  • Merged latest master for easy merging.

All in all, I think performance is better than it was before. Rotation of ORKPieChartView seems completely smooth on an iPhone 6. However, rotation to landscape of the ORKGraphViews is a bit janky. This is because they have a big amount of graphic sublayers (mostly the lines, as the point layers reuse memory now, as mentioned above). I couldn't figure a way using less layers, because the line layers completely depend on the plotted data.

Also, it's worth considering if we should rename ORKGraphView and its subclasses to something ending in chart, for example, ORK*GraphChartView or ORK*BidimensionalChartView for coherence with ORKPieChartView (in my mind, a graph is a subtype of chart, and a pie is another subtype of chart).

Some things we could do as follow-on issues:

  • Add a delegate method to optionally provide colors to secondary graphs on multi-plot graphs (currently, the main plot is painted of the view's tintColor, and all the secondary plots are painted of referenceLineColor).
  • Add a delegate method to allow to select which graph to scrub over on multi-plot graphs (currently, it always scrubs over the first graph).
  • Add support for graphs with a large number of points, by setting an interval for the xAxis labels and reference lines (currently the xAxis gets very crowded if you add lots of points).

If you agree this are worthwhile improvements, I can add follow-on issues tomorrow.

Also fixes a occasional crash if line/point layout is tried before obtaining the normalized y axis points.
@rsanchezsaez

Copy link
Copy Markdown
Contributor

Also, @coxy1989, thanks a lot for your previous work! It was a pleasure working with your code. For example, the scrubber animation works beautifully, I didn't had to change any of that. The rotation performance and animation issues were mostly inherited from from the AppCore architecture and implementation.

And the randomized colors-ORKPieChart example is very nice. I moved that to ORKTest (on ORKCatalog I left a very simple pie chart with the original colors).

@YuanZhu-apple

Copy link
Copy Markdown
Member

@rsanchezsaez Thanks for the great work. Tested on iPhone 6 plus, the rotation is much more smooth.

Agree, the class names should end with ChartView.
Also I agree on the three following issues.

@YuanZhu-apple

Copy link
Copy Markdown
Member

@coxy1989 Thanks your previous work too!
Can you merge @rsanchezsaez's PR ASAP, so we can review it here?

…emory usage and performance)

Also, add slight top padding so drawn are doesn't overflow graph view bounds at default text size.
…r than from 'traitCollectionDidChange:'

(Fixes a rare bug in which sometimes view width is not correct during 'layoutSubviews' after a portrait to landscape rotation. E.g.: bug is present in ORKTest, but not in ORKCatalog.)
@rsanchezsaez

Copy link
Copy Markdown
Contributor

I have added a few more commits with last minute fixes, and the final refactor to ORK*GraphChartView.

A note: performance also depends on the number of plotted graph points: it decreases quickly as you add points. For a fair comparison, try with the ORKTest example, as it has more points than the ORKCatalog one.

And the follow-on issues: #379.

Comment thread ResearchKit/Charts/ORKGraphChartView.h Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it necessary to expose this panGestureRecognizer? What is the use case of it?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess that it could be useful if the user wants to add a graph in a custom view hierarchy that has other conflicting gesture recognizers, and wants to prioritize them (same as UIScrollView's exposing their panGestureRecognizer and pinchGestureRecognizer`).

But it may be a quite unfrequent use case, I'm happy to remove it if you prefer so.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sense to keep it.

@rsanchezsaez

Copy link
Copy Markdown
Contributor

Thanks Chris. Typos fixed.

@YuanZhu-apple

Copy link
Copy Markdown
Member

Thanks @coxy1989 and @rsanchezsaez.
It looks good after my brief review. Accepting it.

YuanZhu-apple added a commit that referenced this pull request Aug 19, 2015
Charts for ResearchKit (Issue #92)
@YuanZhu-apple
YuanZhu-apple merged commit 2769b26 into ResearchKit:master Aug 19, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants