Skip to content

Commit

Permalink
Added YBMGraphView example, minor bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeylenkov committed Nov 25, 2011
1 parent 89f992d commit 0ff4bbd
Show file tree
Hide file tree
Showing 14 changed files with 3,834 additions and 41 deletions.
53 changes: 28 additions & 25 deletions Classes/YBGraphView.h
Expand Up @@ -11,6 +11,32 @@
#import "YBBullet.h"
#import "YBPointInfo.h"

@class YBGraphView;

@protocol YBGraphViewDataSource

@optional

- (NSColor *)graphView:(YBGraphView *)graph colorForGraph:(NSInteger)index;
- (NSString *)graphView:(YBGraphView *)graph legendTitleForGraph:(NSInteger)index;
- (NSString *)graphView:(YBGraphView *)graph markerTitleForGraph:(NSInteger)graphIndex forElement:(NSInteger)elementIndex;

@required

- (NSInteger)numberOfGraphsInGraphView:(YBGraphView *)graph;
- (NSArray *)graphView:(YBGraphView *)graph valuesForGraph:(NSInteger)index;
- (NSArray *)seriesForGraphView:(YBGraphView *)graph;

@end

@protocol YBGraphViewDelegate

@optional

- (void)graphView:(YBGraphView *)graph mouseMovedAboveElement:(NSInteger)index;

@end

@interface YBGraphView : NSView {
NSMutableArray *series;
NSMutableArray *graphs;
Expand Down Expand Up @@ -61,8 +87,6 @@
@property (nonatomic, copy) NSString *info;
@property (nonatomic, assign) BOOL drawLegend;
@property (nonatomic, assign) BOOL showMarker;
@property (nonatomic, retain) id delegate;
@property (nonatomic, retain) id dataSource;
@property (nonatomic, retain) YBMarker *marker;
@property (nonatomic, retain) YBBullet *bullet;
@property (nonatomic, retain) NSFont *font;
Expand All @@ -81,6 +105,8 @@
@property (nonatomic, assign) NSInteger roundGridYTo;
@property (nonatomic, assign) BOOL isRoundGridY;
@property (nonatomic, assign) BOOL showMarkerNearPoint;
@property (nonatomic, assign) IBOutlet id <YBGraphViewDelegate> delegate;
@property (nonatomic, assign) IBOutlet id <YBGraphViewDataSource> dataSource;

- (void)draw;
- (void)drawLegendInRect:(NSRect)rect;
Expand All @@ -89,26 +115,3 @@

@end

@protocol YBGraphViewDataSource

@optional

- (NSColor *)graphView:(YBGraphView *)graph colorForGraph:(NSInteger)index;
- (NSString *)graphView:(YBGraphView *)graph legendTitleForGraph:(NSInteger)index;
- (NSString *)graphView:(YBGraphView *)graph markerTitleForGraph:(NSInteger)graphIndex forElement:(NSInteger)elementIndex;

@required

- (NSInteger)numberOfGraphsInGraphView:(YBGraphView *)graph;
- (NSArray *)graphView:(YBGraphView *)graph valuesForGraph:(NSInteger)index;
- (NSArray *)seriesForGraphView:(YBGraphView *)graph;

@end

@protocol YBGraphViewDelegate

@optional

- (void)graphView:(YBGraphView *)graph mouseMovedAboveElement:(NSInteger)index;

@end
8 changes: 4 additions & 4 deletions Classes/YBGraphView.m
Expand Up @@ -109,7 +109,7 @@ - (void)draw {

[series addObjectsFromArray:[dataSource seriesForGraphView:self]];

int count = [dataSource numberOfGraphsInGraphView:self];
NSInteger count = [dataSource numberOfGraphsInGraphView:self];

for (int i = 0; i < count; i++) {
[graphs addObject:[dataSource graphView:self valuesForGraph:i]];
Expand Down Expand Up @@ -243,11 +243,11 @@ - (void)drawRect:(NSRect)rect {

[paragraphStyle release];

int maxStep;
NSInteger maxStep;

if ([series count] > 5) {
int stepCount = 5;
int count = [series count] - 1;
NSInteger count = [series count] - 1;

for (int i = 4; i < 8; i++) {
if (count % i == 0) {
Expand Down Expand Up @@ -320,7 +320,7 @@ - (void)drawRect:(NSRect)rect {
x = self.frame.size.width - (offsetX * 2);
}

int index = i * step;
NSInteger index = i * step;

if (index >= [series count]) {
index = [series count] - 1;
Expand Down
5 changes: 2 additions & 3 deletions Classes/YBMapView.h
Expand Up @@ -40,7 +40,6 @@
BOOL enableMarker;
NSTrackingArea *trackingArea;
NSPoint mousePoint;

NSColor *backgroundColor;
NSColor *textColor;
NSColor *maxColor;
Expand All @@ -66,8 +65,8 @@
@property (nonatomic, retain) YBMarker *marker;
@property (nonatomic, assign) BOOL showMarker;
@property (nonatomic, assign) BOOL showMarkerForZeroValue;
@property (nonatomic, retain) IBOutlet id <YBMapViewDelegate> delegate;
@property (nonatomic, retain) IBOutlet id <YBMapViewDataSource> dataSource;
@property (nonatomic, assign) IBOutlet id <YBMapViewDelegate> delegate;
@property (nonatomic, assign) IBOutlet id <YBMapViewDataSource> dataSource;

- (void)draw;
- (void)drawHighlightInRect:(NSRect)rect forCountry:(NSString *)code;
Expand Down
11 changes: 2 additions & 9 deletions Classes/YBMapView.m
Expand Up @@ -455,20 +455,13 @@ - (NSColor *)colorForValue:(float)value {
return zeroColor;
}

//float hue = [maxColor hueComponent];
//float saturation = (value / 70.0);
float brightness = 1.0 - (value / 50.0);
//float alfa = 1.0;

/*if (saturation < 0.1) {
saturation = 0.1;
}*/


if (brightness < 0.2) {
brightness = 0.2;
}

return [maxColor highlightWithLevel:brightness]; //[NSColor colorWithCalibratedHue:hue saturation:100.0 brightness:100.0 alpha:1.0];
return [maxColor highlightWithLevel:brightness];
}

- (void)mouseEntered:(NSEvent *)event {
Expand Down

0 comments on commit 0ff4bbd

Please sign in to comment.