Permalink
Browse files

Adding a dashboard for the logger

  • Loading branch information...
1 parent 7153584 commit 98cf876de21f722f67264bfad4b91b95ea6c5802 @saikat committed Sep 2, 2010
Showing with 68 additions and 13 deletions.
  1. +68 −13 example/dashboard/AppController.j
@@ -2,38 +2,93 @@
* AppController.j
* dashboard
*
- * Created by You on September 1, 2010.
- * Copyright 2010, Your Company All rights reserved.
+ * Created by Saikat Chakrabarti on September 1, 2010.
+ * Copyright 2010, Saikat Chakrabarti All rights reserved.
*/
@import <Foundation/CPObject.j>
-
+@import <SCSocket/SCSocket.j>
+@import <LPKit/LPSparkLine.j>
+@import <LPKit/LPChartView.j>
@implementation AppController : CPObject
{
+ SCSocket theSocket;
+ LPChartView barChart;
+ LPPieChartView pieChart;
+ CPArray values;
}
- (void)applicationDidFinishLaunching:(CPNotification)aNotification
{
+
+ theSocket = [[SCSocket alloc] initWithURL:[CPURL URLWithString:"http://localhost:8080"] delegate:self];
+ [theSocket connect];
+}
+
+- (void)socketDidConnect:(SCSocket)aSocket
+{
+ [theSocket sendMessage:{'auth_token' : 'my_secret_token_for_the_dashboard_client'}];
var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMakeZero() styleMask:CPBorderlessBridgeWindowMask],
- contentView = [theWindow contentView];
+ contentView = [theWindow contentView],
+ label1 = [CPTextField labelWithTitle:"Breakdown"],
+ label2 = [CPTextField labelWithTitle:"Letters per second"];
- var label = [[CPTextField alloc] initWithFrame:CGRectMakeZero()];
+ values = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
+ [label1 setFont:[CPFont fontWithName:"Helvetica" size:48]];
+ [label2 setFont:[CPFont fontWithName:"Helvetica" size:48]];
- [label setStringValue:@"Hello World!"];
- [label setFont:[CPFont boldSystemFontOfSize:24.0]];
+ [label1 setTextColor:[CPColor colorWithCalibratedRed:93.0 / 255.0 green:93.0 / 255.0 blue:93.0 / 255.0 alpha:1.0]];
+ [label1 setTextShadowColor:[CPColor colorWithCalibratedRed:225.0 / 255.0 green:255.0 / 255.0 blue:255.0 / 255.0 alpha:0.7]];
+ [label1 setTextShadowOffset:CGSizeMake(0.0, 1.0)];
- [label sizeToFit];
+ [label2 setTextColor:[CPColor colorWithCalibratedRed:93.0 / 255.0 green:93.0 / 255.0 blue:93.0 / 255.0 alpha:1.0]];
+ [label2 setTextShadowColor:[CPColor colorWithCalibratedRed:225.0 / 255.0 green:255.0 / 255.0 blue:255.0 / 255.0 alpha:0.7]];
+ [label2 setTextShadowOffset:CGSizeMake(0.0, 1.0)];
- [label setAutoresizingMask:CPViewMinXMargin | CPViewMaxXMargin | CPViewMinYMargin | CPViewMaxYMargin];
- [label setCenter:[contentView center]];
+ [label1 sizeToFit];
+ [label2 sizeToFit];
- [contentView addSubview:label];
+ var barChart = [[LPChartView alloc] initWithFrame:CGRectMake(0, 0, 400, 400)];
+ [barChart setDrawView:[[LPChartDrawView alloc] init]];
+ [barChart setCenter:[contentView center]];
+ [barChart setDataSource:self];
+ [barChart setDisplayGrid:YES];
+ [contentView addSubview:barChart];
+ [contentView addSubview:label1];
+ [label1 setCenter:CGPointMake([contentView center].x, [barChart frame].origin.y + [barChart frame].size.height + 50)];
+ [contentView setBackgroundColor:[CPColor colorWithHexString:"E0E0E0"]];
[theWindow orderFront:self];
+}
+
+- (void)socket:(SCSocket)aSocket didReceiveMessage:(CPString)aMessage
+{
+ var theLetter = aMessage.body.c;
+ var theIndex = theLetter.charCodeAt(0) - 'a'.charCodeAt(0);
+ values[theIndex]++;
+ [barChart reloadData];
+}
+
+- (unsigned)numberOfSetsInChart:(LPChartView)aChart
+{
+ return 1;
+}
+
+- (CPString)chart:(LPChartView)aChart labelValueForIndex:(unsigned)anIndex
+{
+ return String.fromCharCode(anIndex + 65);
+}
- // Uncomment the following line to turn on the standard menu bar.
- //[CPMenu setMenuBarVisible:YES];
+- (unsigned)chart:(LPChartView)aChart numberOfValuesInSet:(unsigned)setIndex
+{
+ return values.length;
}
+- (unsigned)chart:(LPChartView)aChart valueForIndex:(unsigned)anIndex set:(unsigned)setIndex
+{
+ return values[anIndex];
+}
+
+
@end

0 comments on commit 98cf876

Please sign in to comment.