Skip to content
This repository has been archived by the owner on Dec 2, 2020. It is now read-only.

Pan/Zoom and Variable X Axis; many other changes #300

Open
wants to merge 41 commits into
base: feature
Choose a base branch
from

Conversation

mackworth
Copy link

@mackworth mackworth commented May 12, 2017

Summary

Pan/Zoom and Variable X Axis; many other changes

Fixes Issues

This pull request fixes the following issues:

Changes

The following changes are included in this pull request:

  • Pan/Zoom
  • Variable X Axis
  • Cubic Bezier Algorithm
  • Many others (see below for details)
  • New Features:
    • Optional user-scaling pan/zoom with double-tap to restore
    • Variable x-axis
      • Adds new delegates:
        • lineGraph:locationForPointAtIndex:
        • lineGraph:labelOnXAxisForLocation:
        • numberOfXAxisLabelsOnLineGraph:maxXValueForLineGraph:
        • minXValueForLineGraph
    • Ability to take screen shot bigger (or smaller) than screen
    • New delegate method to specify y-axis labels
    • Axis at top option
    • Cubic Bezier algorithm for smoother lines
    • Implemented numberOfXAxisLabelsOnLineGraph for indexed xAxis
    • TestBed usable on iPhone and Split View
    • NumberOfPoints entry in TestBed
    • Activity display in TestBed to test didFinish
    • Upward-compatible API

Notes

  • This pull request makes breaking changes, and if so, involves the following:
    • Public API availability
    • Internal functionality or behavior
      • All global vars changed to internal properties
      • All MutableArrays to Arrays
      • Use Views to group dots and labels over BEMLine.
      • Set size of major views at beginning, so all calcs based on those views
      • Moves getting data and calculations of points to new getData method
  • I have run and ensured that this pull request passes all XCTests

Add averageValue delegate method to allow BEMLineGraph to be separate from BEMCalculator
Restore modifyPopUpView delegate method
Use caption preferredFont instead of SystemFont fro NoData
Handle overlapping labels better
Reuse code for popup and permanent labels

Bug fixes
	ensure chart doesn't grow views when zero or one data points
Add coding to AverageLine
Move gradient properties to strong to properly retain
Fix compiler error about integers used in enums
Change alwaysDisplayPopupatIndex to use NSUInteger for index instead of float
Fix Frame warning in SimpleLineChart's launch Screen
AverageLine:
•Color should be picked up from line if not set (default nil)
Typo in encoding macro

Line:
If null data and interpolation on, then extrapolate for beginning/ending nulls.
Bezier curve should be used even when only two points.
If interpolation off, then bezier line should be interrupted by gaps (but not top/bottom).
Avoid infinity result in midPoint calculation

SimpleLineGraphView:
Support restoration during startup.
NoDataLabel color should not default from Line (which defaults to white, same as background)
If null value, ensure corresponding Dot isn't left on chart
If label isn't used after initially being created, ensure it's removed from view
If neither X nor Y reference lines, set line's enableRefLines to NO (although default, might have been previously YES
If Xaxis background is defaulting to colorBottom, then also use alphaBottom to match; same for Yaxis and colorTop.
Avoid possible infinite loop if delegate gives a zero incrementIndex for x axis
Fix one-pixel gap between yaxis and graph
Remove spurious NSLogs
Line clipsToBounds to avoid drawing outside the box (when extrapolating nulls or user set minValue too High)
Top/Bottom reference lines were outside box
When Bezier off and Interpolate nulls off, properly draws line segments now
Removed VMA NSLog from TestBed/MasterController
refactors bezier/linear processing into one method
(Still has old code to allow comparison)
Remove verticalReferenceHorizontalFringeNegation stuff
Fix background if points aren't on left/right edges
Adds new delegates: lineGraph:locationForPointAtIndex:  lineGraph:labelOnXAxisForLocation:,  numberOfXAxisLabelsOnLineGraph: maxXValueForLineGraph:, minXValueForLineGraph
Moves getting data  and calculations of points to new getData method

Adds new methods to TestBed
Adds missing icons to TestBed
Moves saving data from restoration to User defaults
Misc bug fixes in variable xAxis, esp minX/maxX
Add hints for minX/maxX in testbed
Add %nulls slider in testbed
Move from NSNotFound to -1 for empty markers in TestBed DetailVC
No vert ref lines when value null (and not interpolated)
No Labels when dot is offscreen
In testBed, don't report dots when Null value
reset minX value when setting variableXaxis
in testBed restore font to fontname field
No vert ref lines when value null (and not interpolated)
No Labels when dot is offscreen
In testBed, don't report dots when Null value
reset minX value when setting variableXaxis
in testBed restore font to fontname field
No vert ref lines when value null (and not interpolated)
No Labels when dot is offscreen
In testBed, don't report dots when Null value
reset minX value when setting variableXaxis
in testBed restore font to fontname field
Double tap to toggle full scale and zoomed
Remove touchInput recognizers when disabled
Bug fix: turning scaling off didn't redraw properly
Moved zoom management to handleGesture
Separate out two-finger pan from zoom recognizer for smoothness
Allow client setting scale/pan numbers (e.g. to sync two graphs)
Rename m--DisplayedValue to m--XDisplayedValue
Always display labels above dots
Check for all neighbors, not just two
Disappear dots outside of frame.
	Use Views to group dots and labels over BEMLine.
	Allows removal of kludgy yAxisOffset and xAxisOffset globals
	Set size of major views at beginning, so all calcs based on those views
	Changed all global mutable Arrays to NSArrays
	Used CGRectGetM... to simplify calculations
Fixes:
	Animation w/o displaying dots during left dots off previously
	Implemented numberOfXAxisLabelsOnLineGraph for indexed xAxis (in addition to previous location xAxis)
  	Added min 5 points between xAxisLabels
	Rewrite panZoom logic
Remove all global vars
Change all MutableArrays to Arrays
Remove ReferenceLine properties, hand directly to masterline instead
Rename AxisValues to Locations
Remove quadratic bezier algorithm
Add some missing property restorers?
…for cubic bezier algorithm to work properly

After merge of cubic algorithm, found conflict with variable X axis work. Limited control points x-value to following point's x value.
Fixed startup problem for restoring scale and zoom
The usual random stuff from storyboard
mackworth added 5 commits May 6, 2017 23:50
   Some reference lines not appearing
   Sometimes highest xaxis label doesn't appear
   Nudge y labels onto page
   Highest y label doesn't appear when averagelabel is off
   When changing data sources, sometimes minXDisplayed gets out of sync
  Several properties not properly restored.
Enable signed conversion checking and fix issues
Fix test for white/alpha to handle extended Grey space
…2 bit fr

Add EOL to some files
Fix for bezier edge of closed background (need to simplify)
New delegate to reformat yaxis labels
don't remove top level views when no data
Calc locations after sections laid out
Fix for right hand label out of bounds
Move locationForPointAtIndex to datasource
Fix minor doc issues.
Fixed case where label is partially onscreen, but point is not.
Don't allow zooming infinitely small
Simplify handling of zero points
Add NumberOfPoints field to TestBed
Fix bug when increasing numberofPoints by more than two
Add Activity Indicator to testBed to test didFinishDrawing
@mackworth
Copy link
Author

Supersedes PR #295, which also incorporates the changes mentioned above. I created a separate pull request in case the addition of the pan/zoom and variableX are determined to be inappropriate for this library. Let me know what you think, especially on API additions, and/or if you have any problems with this build, and/or if there's any thing else you want me to implement, while I'm on a roll...

@Boris-Em
Copy link
Owner

Thank you so much for your contributions @mackworth! As soon as we get your other PR (#295) merged in, I'll take a look at this one. If you plan on contributing more to the project, please keep on breaking your PRs as much as possible like you did.

mackworth and others added 5 commits May 14, 2017 17:33
Spacing consistency with rest of project
topline fix
Move UIButton+switch and UITextField+Numbers from Master to separate files
Title of Master "Options"
Add Graph button if collapsed
include fixes from other PR
Don't allow animation during redrawing for snapshot
Rounding issue on right edge for label/dots disappearing too soon
Better calculation for interpolating nulls on left edge of canvas during zoom
…r on all datapoints (as it was and is the default) or just on currently displayed graph)

Change to labelOnXAxisForLocation to report which label on screen this is.
Align left-most and right-most labels left and right respecrtively.
Bug Fixes:
	Restore enableReferenceFrame functionality
	Use font's lineheight instead of pointsize to correctly calculate line height.
	Move zoomGestures to self rather than labelView to allow panning on XAxis
	Property remove zoomPanGesture (overlooked before)
	Avoid duplicate labels when delegate specified numberOfXAxisLabels is greater than actual number of labels
        Avoid some flickering due to rounding for dots on edge of screen.
	Avoid problem when switching back to indexed from location based axis
	In Master, Correctly load int and float defaults even when they are zero
	In Master, avoid some -1 issues.
	Some documentation typos
@mackworth
Copy link
Author

Added a few bug fixes. Also realized an ambiguity about calculations on graphDatapoints when you have pan/zoom. Does it mean calculate with the currently displayed points or all data points? I think both are useful, so I added a switch.

Double-tap restores zoom, but at double-tap location
Better behavior when sliding finger off screen.
Fix compiler error for nil font and NSInteger
Fix label tests
@mackworth
Copy link
Author

A couple bug fixes based on field testing of my app.
Noticed that the last set of commits broke the test, so undid one of my changes there.

@Sam-Spencer
Copy link
Collaborator

Hi @mackworth, is there any way you can split out a separate pull request with only the pan / zoom feature - and nothing else?

There are a lot of changes here, and it is very difficult to accurately sift through everything. I do, however, have a few thoughts on what I have seen:

  • Zoom and pan feature seems really nice in the brief tests I did.
  • Not sure how I feel about the cubic curve change from quadratic curves. Could be a matter of personal taste, but I don't like how this looks as much. While some regions of the graph with shallow slopes are displayed better, there's an odd kind of "tilt" to each large curve.
  • Some of these added and updated APIs would be much appreciated (in fact they would address many of the issues currently open on this project). However, my fear is that these changes to the public API may confuse or overburden BEMSimpleLineGraphView in its current state. Before continuing to add more features I think the project needs to be refactored. This would be quite the undertaking, but I believe that if done correctly it would make pull requests likes this much easier to merge, manage, and create in the first place. @Boris-Em what do you think? Maybe we can start a refactoring project to discuss how to approach this?

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

Successfully merging this pull request may close these issues.

3 participants