Skip to content

Commit

Permalink
added support for mouseover events to cahrtview
Browse files Browse the repository at this point in the history
  • Loading branch information
luddep committed Dec 28, 2009
1 parent b674485 commit 59fad15
Showing 1 changed file with 48 additions and 4 deletions.
52 changes: 48 additions & 4 deletions LPChartView.j
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ var labelViewHeight = 20,
@implementation LPChartView : CPView
{
id dataSource @accessors;
id delegate @accessors;
id drawView @accessors;

LPGridView gridView;
Expand Down Expand Up @@ -183,9 +184,10 @@ var labelViewHeight = 20,
{
drawViewSize = [drawView bounds].size;

//if (_currentSize && CGSizeEqualToSize(_currentSize, drawViewSize))
// return _framesSet;
//_currentSize = drawViewSize;
if (_currentSize && CGSizeEqualToSize(_currentSize, drawViewSize))
return _framesSet;

_currentSize = drawViewSize;

// Reset frames set
_framesSet = [CPArray array];
Expand Down Expand Up @@ -238,6 +240,29 @@ var labelViewHeight = 20,
return [dataSource chart:self labelValueForIndex:anIndex];
}

- (void)mouseMoved:(CPEvent)anEvent
{
if (delegate && [delegate respondsToSelector:@selector(chart:didMouseOverItemAtIndex:)])
{
var itemFrames = [self itemFrames][0],
locationInDrawView = [drawView convertPoint:[anEvent locationInWindow] fromView:nil];

for (var i = 0; i < itemFrames.length; i++)
{
var itemFrame = itemFrames[i];

if (itemFrame.origin.x <= locationInDrawView.x && (itemFrame.origin.x + itemFrame.size.width) > locationInDrawView.x)
[delegate chart:self didMouseOverItemAtIndex:i];
}
}
}

- (void)mouseExited:(CPEvent)anEvent
{
if (delegate && [delegate respondsToSelector:@selector(chart:didMouseOverItemAtIndex:)])
[delegate chart:self didMouseOverItemAtIndex:-1];
}

@end


Expand Down Expand Up @@ -302,6 +327,15 @@ var LPChartViewDataSourceKey = @"LPChartViewDataSourceKey",
{
}

- (void)initWithFrame:(CGRect)aFrame
{
if (self = [super initWithFrame:aFrame])
{
[self setHitTests:NO];
}
return self;
}

- (void)drawRect:(CGRect)aRect
{
if (itemFrames = [[self superview] itemFrames])
Expand Down Expand Up @@ -337,6 +371,15 @@ var LPChartViewDataSourceKey = @"LPChartViewDataSourceKey",
{
}

- (id)initWithFrame:(CPRect)aFrame
{
if (self = [super initWithFrame:aFrame])
{
[self setHitTests:NO];
}
return self;
}

- (void)drawRect:(CGRect)aRect
{
if (itemFrames = [[self superview] itemFrames])
Expand Down Expand Up @@ -527,7 +570,8 @@ var LPChartLabelViewChartKey = @"LPChartLabelViewChartKey",
{
if (self = [super initWithFrame:aFrame])
{
[self setValue:CPCenterTextAlignment forThemeAttribute:@"alignment"];
[self setHitTests:NO];
//[self setValue:CPCenterTextAlignment forThemeAttribute:@"alignment"];
/*[self setFont:[CPFont boldFontWithName:@"Lucida Grande" size:10]];
[self setTextColor:[CPColor colorWithHexString:@"333"]];*/
}
Expand Down

0 comments on commit 59fad15

Please sign in to comment.