Compare commits

..

2 Commits

Author SHA1 Message Date
terryworona e74bef481b pinch and zoom almost sorta not working 2016-08-28 18:55:55 -07:00
terryworona 212e14e1e2 getting there 2016-08-28 18:23:45 -07:00
4 changed files with 127 additions and 58 deletions
-17
View File
@@ -1,22 +1,5 @@
# Change Log
## [v3.0.13](https://github.com/Jawbone/JBChartView/tree/v3.0.13) (2017-02-08)
[Full Changelog](https://github.com/Jawbone/JBChartView/compare/v3.0.12...v3.0.13)
**Fixed bugs:**
- selectionColorForDotAtHorizontalIndex doesn't change color [\#221](https://github.com/Jawbone/JBChartView/issues/221)
- 内存泄露(leak!) [\#219](https://github.com/Jawbone/JBChartView/issues/219)
- wrong dot color with NAN after click graph [\#216](https://github.com/Jawbone/JBChartView/issues/216)
**Closed issues:**
- Amazing issue with width of JBLineChartView [\#220](https://github.com/Jawbone/JBChartView/issues/220)
- Bar chart doesn't paint inside selected UITableViewCell [\#214](https://github.com/Jawbone/JBChartView/issues/214)
- Does not conform with protocol [\#212](https://github.com/Jawbone/JBChartView/issues/212)
- \[question\] Does JBChartView support logarithmic scale? [\#211](https://github.com/Jawbone/JBChartView/issues/211)
- Fixed tool tip in Bar chart [\#210](https://github.com/Jawbone/JBChartView/issues/210)
## [v3.0.12](https://github.com/Jawbone/JBChartView/tree/v3.0.12) (2016-06-22)
[Full Changelog](https://github.com/Jawbone/JBChartView/compare/v3.0.11...v3.0.12)
+90
View File
@@ -14,8 +14,16 @@ CGFloat const kJBChartViewDefaultAnimationDuration = 0.25f;
// Color (JBChartSelectionView)
static UIColor *kJBChartVerticalSelectionViewDefaultBgColor = nil;
@interface JAPinchZoomView : UIView <UIScrollViewDelegate>
@property (nonatomic, strong) UIScrollView *scrollView;
@property (nonatomic, strong) UIImageView *pinchZoomImageView;
@end
@interface JBChartView ()
@property (nonatomic, strong) JAPinchZoomView *pinchZoomView;
@property (nonatomic, assign) BOOL hasMaximumValue;
@property (nonatomic, assign) BOOL hasMinimumValue;
@@ -61,6 +69,36 @@ static UIColor *kJBChartVerticalSelectionViewDefaultBgColor = nil;
- (void)constructChartView
{
self.clipsToBounds = YES;
UIPinchGestureRecognizer *pinchGestureRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinchGestureRecognized:)];
pinchGestureRecognizer.cancelsTouchesInView = NO;
[self addGestureRecognizer:pinchGestureRecognizer];
}
#pragma mark - Gestures
- (void)pinchGestureRecognized:(UIPinchGestureRecognizer *)pinchGestureRecognizer
{
if (pinchGestureRecognizer.state == UIGestureRecognizerStateBegan)
{
for (UIView *subview in self.subviews)
{
//subview.hidden = YES;
}
self.pinchZoomView = [[JAPinchZoomView alloc] init];
self.pinchZoomView.pinchZoomImageView.image = [JBChartView imageWithView:self];
self.pinchZoomView.frame = self.bounds;
[self addSubview:self.pinchZoomView];
}
else if (pinchGestureRecognizer.state == UIGestureRecognizerStateEnded)
{
for (UIView *subview in self.subviews)
{
// subview.hidden = NO;
}
//[self.pinchZoomView removeFromSuperview];
}
}
#pragma mark - Public
@@ -77,6 +115,17 @@ static UIColor *kJBChartVerticalSelectionViewDefaultBgColor = nil;
NSAssert((self.headerView.bounds.size.height + self.footerView.bounds.size.height) <= self.bounds.size.height, @"JBChartView // the combined height of the footer and header can not be greater than the total height of the chart.");
}
#pragma mark - Getters
+ (UIImage *)imageWithView:(UIView *)view
{
UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, 0.0);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
#pragma mark - Setters
- (void)setHeaderView:(UIView *)headerView
@@ -233,3 +282,44 @@ static UIColor *kJBChartVerticalSelectionViewDefaultBgColor = nil;
}
@end
@implementation JAPinchZoomView
#pragma mark - Alloc/Init
- (instancetype)init
{
self = [super init];
if (self)
{
_scrollView = [[UIScrollView alloc] init];
_scrollView.delegate = self;
_scrollView.minimumZoomScale = 1.0;
_scrollView.maximumZoomScale = 6.0;
[self addSubview:_scrollView];
_pinchZoomImageView = [[UIImageView alloc] init];
[_scrollView addSubview:_pinchZoomImageView];
}
return self;
}
#pragma mark - Layout
- (void)layoutSubviews
{
[super layoutSubviews];
self.scrollView.frame = self.bounds;
self.pinchZoomImageView.frame = self.scrollView.bounds;
}
#pragma mark - UIScrollViewDelegate
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
return self.pinchZoomImageView;
}
@end
+35 -39
View File
@@ -112,13 +112,12 @@ NSInteger const kJBLineChartDotsViewUnselectedLineIndex = -1;
JBLineChartPoint *lineChartPoint = [sortedLineChartPoints objectAtIndex:horizontalIndex];
if(lineChartPoint.hidden)
{
[mutableDotViews addObject:[NSNull null]];
continue;
continue;
}
UIView *dotView = [self dotViewForHorizontalIndex:horizontalIndex atLineIndex:lineIndex];
dotView.center = CGPointMake(lineChartPoint.position.x, lineChartPoint.position.y);
[mutableDotViews addObject:dotView];
[mutableDotViews addObject:dotView];
[self addSubview:dotView];
}
[mutableDotViewsDict setObject:[NSArray arrayWithArray:mutableDotViews] forKey:[NSNumber numberWithInteger:lineIndex]];
@@ -159,42 +158,39 @@ NSInteger const kJBLineChartDotsViewUnselectedLineIndex = -1;
if ([key isKindOfClass:[NSNumber class]])
{
NSInteger lineIndex = [((NSNumber *)key) intValue];
if (![dotView isKindOfClass:[NSNull class]])
{
// Internal dot
if ([dotView isKindOfClass:[JBLineChartDotView class]])
{
if (weakSelf.selectedLineIndex == lineIndex)
{
NSAssert([self.dataSource respondsToSelector:@selector(lineChartDotsView:selectedColorForDotAtHorizontalIndex:atLineIndex:)], @"JBLineChartDotsView // dataSource must implement - (UIColor *)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView selectedColorForDotAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex");
dotView.backgroundColor = [self.dataSource lineChartDotsView:self selectedColorForDotAtHorizontalIndex:horizontalIndex atLineIndex:lineIndex];
}
else
{
NSAssert([self.dataSource respondsToSelector:@selector(lineChartDotsView:colorForDotAtHorizontalIndex:atLineIndex:)], @"JBLineChartDotsView // dataSource must implement - (UIColor *)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView colorForDotAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex");
dotView.backgroundColor = [self.dataSource lineChartDotsView:self colorForDotAtHorizontalIndex:horizontalIndex atLineIndex:lineIndex];
NSAssert([self.dataSource respondsToSelector:@selector(lineChartDotsView:dimmedSelectionDotOpacityAtLineIndex:)], @"JBLineChartLinesView // dataSource must implement - (CGFloat)lineChartDotsView:(JBLineChartLinesView *)lineChartLinesView dimmedSelectionDotOpacityAtLineIndex:(NSUInteger)lineIndex");
dotView.alpha = (weakSelf.selectedLineIndex == kJBLineChartDotsViewUnselectedLineIndex) ? 1.0f : [self.dataSource lineChartDotsView:self dimmedSelectionDotOpacityAtLineIndex:lineIndex];
}
}
// Custom dot
else
{
NSAssert([self.dataSource respondsToSelector:@selector(lineChartDotsView:shouldHideDotViewOnSelectionAtHorizontalIndex:atLineIndex:)], @"JBLineChartDotsView // dataSource must implement - (BOOL)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView shouldHideDotViewOnSelectionAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex");
BOOL hideDotView = [self.dataSource lineChartDotsView:self shouldHideDotViewOnSelectionAtHorizontalIndex:horizontalIndex atLineIndex:lineIndex];
if (weakSelf.selectedLineIndex == lineIndex)
{
NSAssert([self.dataSource respondsToSelector:@selector(lineChartDotsView:dimmedSelectionDotOpacityAtLineIndex:)], @"JBLineChartLinesView // dataSource must implement - (CGFloat)lineChartDotsView:(JBLineChartLinesView *)lineChartLinesView dimmedSelectionDotOpacityAtLineIndex:(NSUInteger)lineIndex");
dotView.alpha = hideDotView ? [self.dataSource lineChartDotsView:self dimmedSelectionDotOpacityAtLineIndex:lineIndex] : 1.0f;
}
else
{
dotView.alpha = 1.0;
}
}
}
// Internal dot
if ([dotView isKindOfClass:[JBLineChartDotView class]])
{
if (weakSelf.selectedLineIndex == lineIndex)
{
NSAssert([self.dataSource respondsToSelector:@selector(lineChartDotsView:selectedColorForDotAtHorizontalIndex:atLineIndex:)], @"JBLineChartDotsView // dataSource must implement - (UIColor *)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView selectedColorForDotAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex");
dotView.backgroundColor = [self.dataSource lineChartDotsView:self selectedColorForDotAtHorizontalIndex:horizontalIndex atLineIndex:lineIndex];
}
else
{
NSAssert([self.dataSource respondsToSelector:@selector(lineChartDotsView:colorForDotAtHorizontalIndex:atLineIndex:)], @"JBLineChartDotsView // dataSource must implement - (UIColor *)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView colorForDotAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex");
dotView.backgroundColor = [self.dataSource lineChartDotsView:self colorForDotAtHorizontalIndex:horizontalIndex atLineIndex:lineIndex];
NSAssert([self.dataSource respondsToSelector:@selector(lineChartDotsView:dimmedSelectionDotOpacityAtLineIndex:)], @"JBLineChartLinesView // dataSource must implement - (CGFloat)lineChartDotsView:(JBLineChartLinesView *)lineChartLinesView dimmedSelectionDotOpacityAtLineIndex:(NSUInteger)lineIndex");
dotView.alpha = (weakSelf.selectedLineIndex == kJBLineChartDotsViewUnselectedLineIndex) ? 1.0f : [self.dataSource lineChartDotsView:self dimmedSelectionDotOpacityAtLineIndex:lineIndex];
}
}
// Custom dot
else
{
NSAssert([self.dataSource respondsToSelector:@selector(lineChartDotsView:shouldHideDotViewOnSelectionAtHorizontalIndex:atLineIndex:)], @"JBLineChartDotsView // dataSource must implement - (BOOL)lineChartDotsView:(JBLineChartDotsView *)lineChartDotsView shouldHideDotViewOnSelectionAtHorizontalIndex:(NSUInteger)horizontalIndex atLineIndex:(NSUInteger)lineIndex");
BOOL hideDotView = [self.dataSource lineChartDotsView:self shouldHideDotViewOnSelectionAtHorizontalIndex:horizontalIndex atLineIndex:lineIndex];
if (weakSelf.selectedLineIndex == lineIndex)
{
NSAssert([self.dataSource respondsToSelector:@selector(lineChartDotsView:dimmedSelectionDotOpacityAtLineIndex:)], @"JBLineChartLinesView // dataSource must implement - (CGFloat)lineChartDotsView:(JBLineChartLinesView *)lineChartLinesView dimmedSelectionDotOpacityAtLineIndex:(NSUInteger)lineIndex");
dotView.alpha = hideDotView ? [self.dataSource lineChartDotsView:self dimmedSelectionDotOpacityAtLineIndex:lineIndex] : 1.0f;
}
else
{
dotView.alpha = 1.0;
}
}
}
horizontalIndex++;
}
+2 -2
View File
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "JBChartView"
s.version = "3.0.13"
s.version = "3.0.12"
s.summary = "Jawbone's iOS-based charting library for both line and bar graphs."
s.homepage = "https://github.com/Jawbone/JBChartView"
@@ -10,7 +10,7 @@ Pod::Spec.new do |s|
s.author = { "Terry Worona" => "tworona@jawbone.com" }
s.source = {
:git => "https://github.com/Jawbone/JBChartView.git",
:tag => "v3.0.13"
:tag => "v3.0.12"
}
s.platform = :ios, '6.0'