Skip to content
Browse files

Use Google Chart Tools for Visualization

- Replace Google Image Charts with interactive, javascript charts using
  Google Chart Tools

Charts Updated:
- Follower Count
- Group/List Count
- Client Usage
- Recent Activity
- Post Types

- Removes code from FollowerCountMySQLDAO::getHistory used to populate
  missing dates and calculate bounds for the old image charts.
  • Loading branch information...
1 parent 7a992dd commit 57f1456075a46b7b76a9f5d5c1a371f94c2e69c4 @cwarden cwarden committed
View
95 tests/TestOfFollowerCountMySQLDAO.php
@@ -79,8 +79,7 @@ public function testGetDayHistoryNoGapsMilestoneNotInSight() {
$dao = new FollowerCountMySQLDAO();
$result = $dao->getHistory('930061', 'twitter', 'DAY', 3);
- $this->assertEqual(sizeof($result), 7, '7 sets of data returned--history, percentages, Y axis, trend, '.
- 'milestone, and maximum/minimum counts');
+ $this->assertEqual(sizeof($result), 4, '4 sets of data returned--history, trend, and milestone, and vis_data');
$this->debug(Utils::varDumpToString($result));
//check history
@@ -106,20 +105,6 @@ public function testGetDayHistoryNoGapsMilestoneNotInSight() {
$this->assertEqual($result['history'][$date_ago], 14);
}
- //check percentages
- $this->assertEqual(sizeof($result['percentages']), 3, '3 percentages returned');
- $this->assertEqual($result['percentages'][0], 50);
- $this->assertEqual($result['percentages'][1], 0);
- $this->assertEqual($result['percentages'][2], 100);
-
- //check Y-axis
- $this->assertEqual(sizeof($result['y_axis']), 5, '5 Y axis points returned');
- $this->assertEqual($result['y_axis'][0], 10);
- $this->assertEqual($result['y_axis'][1], 11);
- $this->assertEqual($result['y_axis'][2], 12);
- $this->assertEqual($result['y_axis'][3], 13);
- $this->assertEqual($result['y_axis'][4], 14);
-
//check trend
$this->assertEqual($result['trend'], 1);
@@ -128,6 +113,8 @@ public function testGetDayHistoryNoGapsMilestoneNotInSight() {
//with a 1+/day trend, this should take 86 days
//that's over the "don't feel bad about yourself" threshold of 10, so milestone should be null
$this->assertNull($result['milestone']);
+
+ $this->assertNotNull($result['vis_data']);
}
public function testGetDayHistoryNoGapsMilestoneInSight() {
@@ -158,8 +145,7 @@ public function testGetDayHistoryNoGapsMilestoneInSight() {
$dao = new FollowerCountMySQLDAO();
$result = $dao->getHistory(930061, 'twitter', 'DAY', 3);
- $this->assertEqual(sizeof($result), 7, '7 sets of data returned--history, percentages, Y axis, trend, '.
- 'milestone, and maximum/minimum counts');
+ $this->assertEqual(sizeof($result), 4, '4 sets of data returned--history, trend, and milestone, and vis_data');
$this->debug(Utils::varDumpToString($result));
//check history
@@ -185,20 +171,6 @@ public function testGetDayHistoryNoGapsMilestoneInSight() {
$this->assertEqual($result['history'][$date_ago], 940);
}
- //check percentages
- $this->assertEqual(sizeof($result['percentages']), 3, '3 percentages returned');
- $this->assertEqual($result['percentages'][0], 50);
- $this->assertEqual($result['percentages'][1], 0);
- $this->assertEqual($result['percentages'][2], 100);
-
- //check Y-axis
- $this->assertEqual(sizeof($result['y_axis']), 5, '5 Y axis points returned');
- $this->assertEqual($result['y_axis'][0], 900);
- $this->assertEqual($result['y_axis'][1], 910);
- $this->assertEqual($result['y_axis'][2], 920);
- $this->assertEqual($result['y_axis'][3], 930);
- $this->assertEqual($result['y_axis'][4], 940);
-
//check trend
$this->assertEqual($result['trend'], 7);
@@ -258,8 +230,7 @@ public function testGetDayHistoryWeekNoGaps() {
$dao = new FollowerCountMySQLDAO();
$result = $dao->getHistory(930061, 'twitter', 'WEEK', 3);
- $this->assertEqual(sizeof($result), 7, '7 sets of data returned--history, percentages, Y axis, trend, '.
- 'milestone, and maximum/minimum counts');
+ $this->assertEqual(sizeof($result), 4, '4 sets of data returned--history, trend, and milestone, and vis_data');
$this->debug(Utils::varDumpToString($result));
@@ -274,27 +245,6 @@ public function testGetDayHistoryWeekNoGaps() {
$date_ago = date ($format, strtotime('-1 day'.$date));
$this->assertEqual($result['history'][$date_ago], 140);
- //check percentages
- if ($todays_day_of_the_week != 0) {
- $this->assertEqual(sizeof($result['percentages']), 3, '3 percentages returned');
- }
- //Difficult to test because the values change depending on what day of the week you're running the tests
- // $this->assertEqual($result['percentages'][0], 0);
- // $this->assertEqual($result['percentages'][1], 78);
- // $this->assertEqual($result['percentages'][2], 100);
-
- //check Y-axis
- if ($todays_day_of_the_week != 0) {
-
- $this->assertEqual(sizeof($result['y_axis']), 5, '5 Y axis points returned');
- }
- //Difficult to test because the values change depending on what day of the week you're running the tests
- // $this->assertEqual($result['y_axis'][0], 131);
- // $this->assertEqual($result['y_axis'][1], 133.25);
- // $this->assertEqual($result['y_axis'][2], 135.5);
- // $this->assertEqual($result['y_axis'][3], 137.75);
- // $this->assertEqual($result['y_axis'][4], 140);
-
//check trend
//$this->assertEqual($result['trend'], 3);
@@ -308,6 +258,7 @@ public function testGetDayHistoryWeekNoGaps() {
}
public function testGetDayHistoryWithGaps() {
+ // Filling gaps was only required by the old visualization library
$format = 'n/j';
$date = date ( $format );
@@ -322,21 +273,20 @@ public function testGetDayHistoryWithGaps() {
$dao = new FollowerCountMySQLDAO();
$result = $dao->getHistory(930061, 'twitter', 'DAY', 5);
- $this->assertEqual(sizeof($result), 7, '7 sets of data returned--history, percentages, Y axis, trend, '.
- 'milestone, and maximum/minimum counts');
+ $this->assertEqual(sizeof($result), 4, '4 sets of data returned--history, trend, and milestone, and vis_data');
//check history
- $this->assertEqual(sizeof($result['history']), 5, '5 counts returned');
+ $this->assertEqual(sizeof($result['history']), 3, '3 counts returned');
$this->debug(Utils::varDumpToString($result));
$date_ago = date ($format, strtotime('-5 day'.$date));
$this->assertEqual($result['history'][$date_ago], 120);
$date_ago = date ($format, strtotime('-4 day'.$date));
- $this->assertEqual($result['history'][$date_ago], 'no data');
+ $this->assertTrue(!isset($result['history'][$date_ago]), 'gap filled');
$date_ago = date ($format, strtotime('-3 day'.$date));
- $this->assertEqual($result['history'][$date_ago], 'no data');
+ $this->assertTrue(!isset($result['history'][$date_ago]), 'gap filled');
$date_ago = date ($format, strtotime('-2 day'.$date));
$this->assertEqual($result['history'][$date_ago], 100);
@@ -344,23 +294,6 @@ public function testGetDayHistoryWithGaps() {
$date_ago = date ($format, strtotime('-1 day'.$date));
$this->assertEqual($result['history'][$date_ago], 140);
- //check percentages
- $this->assertEqual(sizeof($result['percentages']), 5, '5 percentages returned');
- $this->assertEqual($result['percentages'][0], 50);
- $this->assertEqual($result['percentages'][1], 0);
- $this->assertEqual($result['percentages'][2], 0);
- $this->assertEqual($result['percentages'][3], 0);
- $this->assertEqual($result['percentages'][4], 100);
-
- //check y-axis
- $this->assertEqual(sizeof($result['y_axis']), 5, '5 Y axis points returned');
-
- $this->assertEqual($result['y_axis'][0], 100);
- $this->assertEqual($result['y_axis'][1], 110);
- $this->assertEqual($result['y_axis'][2], 120);
- $this->assertEqual($result['y_axis'][3], 130);
- $this->assertEqual($result['y_axis'][4], 140);
-
//check trend
$this->assertFalse($result['trend']);
@@ -386,8 +319,7 @@ public function testTrendMillionPlusFollowers() {
$dao = new FollowerCountMySQLDAO();
$result = $dao->getHistory(930061, 'twitter', 'DAY', 4);
- $this->assertEqual(sizeof($result), 7, '7 sets of data returned--history, percentages, Y axis, trend, '.
- 'milestone, and maximum/minimum counts');
+ $this->assertEqual(sizeof($result), 4, '4 sets of data returned--history, trend, and milestone, and vis_data');
$this->debug(Utils::varDumpToString($result));
@@ -416,8 +348,7 @@ public function testTrendMillionPlusFollowers2() {
$dao = new FollowerCountMySQLDAO();
$result = $dao->getHistory(930061, 'twitter', 'DAY', 4);
- $this->assertEqual(sizeof($result), 7, '7 sets of data returned--history, percentages, Y axis, trend, '.
- 'milestone, and maximum/minimum counts');
+ $this->assertEqual(sizeof($result), 4, '4 sets of data returned--history, trend, and milestone, and vis_data');
$this->debug(Utils::varDumpToString($result));
@@ -427,4 +358,4 @@ public function testTrendMillionPlusFollowers2() {
//beyond our "don't feel bad about yourself" threshold of 10, so should be null
$this->assertNull($result['milestone']);
}
-}
+}
View
85 tests/TestOfGroupMembershipCountMySQLDAO.php
@@ -98,8 +98,7 @@ public function testGetDayHistoryNoGapsMilestoneNotInSight() {
$dao = new GroupMembershipCountMySQLDAO();
$result = $dao->getHistory('930061', 'twitter', 'DAY', 3);
- $this->assertEqual(sizeof($result), 7, '7 sets of data returned--history, percentages, Y axis, trend, '.
- 'milestone, and maximum/minimum counts');
+ $this->assertEqual(sizeof($result), 4, '4 sets of data returned--history, trend, milestone, and vis_data');
$this->debug(Utils::varDumpToString($result));
//check history
@@ -125,20 +124,6 @@ public function testGetDayHistoryNoGapsMilestoneNotInSight() {
$this->assertEqual($result['history'][$date_ago], 14);
}
- //check percentages
- $this->assertEqual(sizeof($result['percentages']), 3, '3 percentages returned');
- $this->assertEqual($result['percentages'][0], 50);
- $this->assertEqual($result['percentages'][1], 0);
- $this->assertEqual($result['percentages'][2], 100);
-
- //check Y-axis
- $this->assertEqual(sizeof($result['y_axis']), 5, '5 Y axis points returned');
- $this->assertEqual($result['y_axis'][0], 10);
- $this->assertEqual($result['y_axis'][1], 11);
- $this->assertEqual($result['y_axis'][2], 12);
- $this->assertEqual($result['y_axis'][3], 13);
- $this->assertEqual($result['y_axis'][4], 14);
-
//check trend
$this->assertEqual($result['trend'], 1);
@@ -147,6 +132,8 @@ public function testGetDayHistoryNoGapsMilestoneNotInSight() {
//with a 1+/day trend, this should take 84 days
//that's over the "don't feel bad about yourself" threshold of 10, so milestone should be null
$this->assertNull($result['milestone']);
+
+ $this->assertNotNull($result['vis_data']);
}
public function testGetDayHistoryNoGapsMilestoneInSight() {
@@ -177,8 +164,7 @@ public function testGetDayHistoryNoGapsMilestoneInSight() {
$dao = new GroupMembershipCountMySQLDAO();
$result = $dao->getHistory('930061', 'twitter', 'DAY', 3);
- $this->assertEqual(sizeof($result), 7, '7 sets of data returned--history, percentages, Y axis, trend, '.
- 'milestone, and maximum/minimum counts');
+ $this->assertEqual(sizeof($result), 4, '4 sets of data returned--history, trend, milestone, and vis_data');
$this->debug(Utils::varDumpToString($result));
//check history
@@ -204,20 +190,6 @@ public function testGetDayHistoryNoGapsMilestoneInSight() {
$this->assertEqual($result['history'][$date_ago], 940);
}
- //check percentages
- $this->assertEqual(sizeof($result['percentages']), 3, '3 percentages returned');
- $this->assertEqual($result['percentages'][0], 50);
- $this->assertEqual($result['percentages'][1], 0);
- $this->assertEqual($result['percentages'][2], 100);
-
- //check Y-axis
- $this->assertEqual(sizeof($result['y_axis']), 5, '5 Y axis points returned');
- $this->assertEqual($result['y_axis'][0], 900);
- $this->assertEqual($result['y_axis'][1], 910);
- $this->assertEqual($result['y_axis'][2], 920);
- $this->assertEqual($result['y_axis'][3], 930);
- $this->assertEqual($result['y_axis'][4], 940);
-
//check trend
$this->assertEqual($result['trend'], 7);
@@ -277,8 +249,7 @@ public function testGetDayHistoryWeekNoGaps() {
$dao = new GroupMembershipCountMySQLDAO();
$result = $dao->getHistory('930061', 'twitter', 'WEEK', 3);
- $this->assertEqual(sizeof($result), 7, '7 sets of data returned--history, percentages, Y axis, trend, '.
- 'milestone, and maximum/minimum counts');
+ $this->assertEqual(sizeof($result), 4, '4 sets of data returned--history, trend, milestone, and vis_data');
$this->debug(Utils::varDumpToString($result));
@@ -293,17 +264,6 @@ public function testGetDayHistoryWeekNoGaps() {
$date_ago = date ($format, strtotime('-1 day'.$date));
$this->assertEqual($result['history'][$date_ago], 140);
- //check percentages
- if ($todays_day_of_the_week != 0) {
- $this->assertEqual(sizeof($result['percentages']), 3, '3 percentages returned');
- }
-
- //check Y-axis
- if ($todays_day_of_the_week != 0) {
-
- $this->assertEqual(sizeof($result['y_axis']), 5, '5 Y axis points returned');
- }
-
//check milestone
//latest group membership count is 140, next milestone is 1,000 group memberships
//with a 7+/day trend, this should take 123 days
@@ -314,6 +274,7 @@ public function testGetDayHistoryWeekNoGaps() {
}
public function testGetDayHistoryWithGaps() {
+ // Filling gaps was only required by the old visualization library
$format = 'n/j';
$date = date ( $format );
@@ -328,21 +289,20 @@ public function testGetDayHistoryWithGaps() {
$dao = new GroupMembershipCountMySQLDAO();
$result = $dao->getHistory('930061', 'twitter', 'DAY', 5);
- $this->assertEqual(sizeof($result), 7, '7 sets of data returned--history, percentages, Y axis, trend, '.
- 'milestone, and maximum/minimum counts');
+ $this->assertEqual(sizeof($result), 4, '4 sets of data returned--history, trend, milestone, and vis_data');
//check history
- $this->assertEqual(sizeof($result['history']), 5, '5 counts returned');
+ $this->assertEqual(sizeof($result['history']), 3, '3 counts returned');
$this->debug(Utils::varDumpToString($result));
$date_ago = date ($format, strtotime('-5 day'.$date));
$this->assertEqual($result['history'][$date_ago], 120);
$date_ago = date ($format, strtotime('-4 day'.$date));
- $this->assertEqual($result['history'][$date_ago], 'no data');
+ $this->assertTrue(!isset($result['history'][$date_ago]), 'gap filled');
$date_ago = date ($format, strtotime('-3 day'.$date));
- $this->assertEqual($result['history'][$date_ago], 'no data');
+ $this->assertTrue(!isset($result['history'][$date_ago]), 'gap filled');
$date_ago = date ($format, strtotime('-2 day'.$date));
$this->assertEqual($result['history'][$date_ago], 100);
@@ -350,23 +310,6 @@ public function testGetDayHistoryWithGaps() {
$date_ago = date ($format, strtotime('-1 day'.$date));
$this->assertEqual($result['history'][$date_ago], 140);
- //check percentages
- $this->assertEqual(sizeof($result['percentages']), 5, '5 percentages returned');
- $this->assertEqual($result['percentages'][0], 50);
- $this->assertEqual($result['percentages'][1], 0);
- $this->assertEqual($result['percentages'][2], 0);
- $this->assertEqual($result['percentages'][3], 0);
- $this->assertEqual($result['percentages'][4], 100);
-
- //check y-axis
- $this->assertEqual(sizeof($result['y_axis']), 5, '5 Y axis points returned');
-
- $this->assertEqual($result['y_axis'][0], 100);
- $this->assertEqual($result['y_axis'][1], 110);
- $this->assertEqual($result['y_axis'][2], 120);
- $this->assertEqual($result['y_axis'][3], 130);
- $this->assertEqual($result['y_axis'][4], 140);
-
//check trend
$this->assertFalse($result['trend']);
@@ -392,8 +335,7 @@ public function testTrendMillionPlusGroupMemberships() {
$dao = new GroupMembershipCountMySQLDAO();
$result = $dao->getHistory('930061', 'twitter', 'DAY', 4);
- $this->assertEqual(sizeof($result), 7, '7 sets of data returned--history, percentages, Y axis, trend, '.
- 'milestone, and maximum/minimum counts');
+ $this->assertEqual(sizeof($result), 4, '4 sets of data returned--history, trend, milestone, and vis_data');
$this->debug(Utils::varDumpToString($result));
@@ -422,8 +364,7 @@ public function testTrendMillionPlusGroupMemberships2() {
$dao = new GroupMembershipCountMySQLDAO();
$result = $dao->getHistory('930061', 'twitter', 'DAY', 4);
- $this->assertEqual(sizeof($result), 7, '7 sets of data returned--history, percentages, Y axis, trend, '.
- 'milestone, and maximum/minimum counts');
+ $this->assertEqual(sizeof($result), 4, '4 sets of data returned--history, trend, milestone, and vis_data');
$this->debug(Utils::varDumpToString($result));
@@ -433,4 +374,4 @@ public function testTrendMillionPlusGroupMemberships2() {
//beyond our "don't feel bad about yourself" threshold of 10, so should be null
$this->assertNull($result['milestone']);
}
-}
+}
View
73 tests/TestOfUtils.php
@@ -220,4 +220,75 @@ public function testPredictNextMilestoneDate() {
$expected = array('next_milestone'=>100, 'will_take'=>5);
$this->assertEqual(Utils::predictNextMilestoneDate(75, 5), $expected);
}
-}
+
+ public function testGetHotPostVisualizationData() {
+ $hot_posts = array(
+ (object)array(
+ 'post_text' => 'First Post',
+ 'favlike_count_cache' => 1,
+ 'all_retweets' => 2,
+ 'reply_count_cache' => 3,
+ ),
+ (object)array(
+ 'post_text' => 'Second Post',
+ 'favlike_count_cache' => 10,
+ 'all_retweets' => 20,
+ 'reply_count_cache' => 30,
+ )
+ );
+
+ $result = Utils::getHotPostVisualizationData($hot_posts, 'twitter');
+ $this->assertEqual(gettype($result), 'string');
+
+ $visualization_object = json_decode($result);
+ $this->assertEqual(sizeof($visualization_object->rows), 2);
+ $this->assertEqual(sizeof($visualization_object->cols), 3);
+
+ $this->assertEqual($visualization_object->cols[0]->label, 'Tweet');
+ $this->assertEqual($visualization_object->cols[1]->label, 'Retweets');
+ $this->assertEqual($visualization_object->cols[2]->label, 'Replies');
+
+ $this->assertEqual($visualization_object->rows[0]->c[0]->v, 'First Post');
+ $this->assertEqual($visualization_object->rows[0]->c[1]->v, 2);
+ $this->assertEqual($visualization_object->rows[0]->c[2]->v, 3);
+
+ $result = Utils::getHotPostVisualizationData($hot_posts, 'facebook');
+ $this->assertEqual(gettype($result), 'string');
+
+ $visualization_object = json_decode($result);
+ $this->assertEqual(sizeof($visualization_object->rows), 2);
+ $this->assertEqual(sizeof($visualization_object->cols), 3);
+
+ $this->assertEqual($visualization_object->cols[0]->label, 'Post');
+ $this->assertEqual($visualization_object->cols[1]->label, 'Likes');
+ $this->assertEqual($visualization_object->cols[2]->label, 'Replies');
+
+ $this->assertEqual($visualization_object->rows[1]->c[0]->v, 'Second Post');
+ $this->assertEqual($visualization_object->rows[1]->c[1]->v, 10);
+ $this->assertEqual($visualization_object->rows[1]->c[2]->v, 30);
+ }
+
+ public function testGetClientVisualizationData() {
+ $client_data = array(
+ 'Client 1' => 50,
+ 'Client 2' => 10,
+ );
+
+ $result = Utils::getClientUsageVisualizationData($client_data);
+ $this->assertEqual(gettype($result), 'string');
+
+ $visualization_object = json_decode($result);
+ $this->assertEqual(sizeof($visualization_object->rows), 2);
+ $this->assertEqual(sizeof($visualization_object->cols), 2);
+
+ $this->assertEqual($visualization_object->cols[0]->label, 'Client');
+ $this->assertEqual($visualization_object->cols[1]->label, 'Posts');
+
+ $this->assertEqual($visualization_object->rows[0]->c[0]->v, 'Client 1');
+ $this->assertEqual($visualization_object->rows[0]->c[0]->f, 'Client 1 (50)');
+ $this->assertEqual($visualization_object->rows[0]->c[1]->v, 50);
+
+ $this->assertEqual($visualization_object->rows[1]->c[0]->v, 'Client 2');
+ $this->assertEqual($visualization_object->rows[1]->c[1]->v, 10);
+ }
+}
View
9 webapp/_lib/controller/class.DashboardController.php
@@ -194,7 +194,9 @@ private function loadDefaultDashboard() {
true);
$this->addToView('recent_posts', $recent_posts);
$hot_posts = $post_dao->getHotPosts($this->instance->network_user_id, $this->instance->network, 20);
+ $hot_posts_data = Utils::getHotPostVisualizationData($hot_posts, $this->instance->network);
$this->addToView('hot_posts', $hot_posts);
+ $this->addToView('hot_posts_data', $hot_posts_data);
$most_replied_to_1wk = $post_dao->getMostRepliedToPostsInLastWeek($this->instance->network_username,
$this->instance->network, 5);
$this->addToView('most_replied_to_1wk', $most_replied_to_1wk);
@@ -232,11 +234,8 @@ private function loadDefaultDashboard() {
list($all_time_clients_usage, $latest_clients_usage) =
$post_dao->getClientsUsedByUserOnNetwork($this->instance->network_user_id, $this->instance->network);
- // Only show the top 10 most used clients, since forever
- $all_time_clients_usage = array_merge(
- array_slice($all_time_clients_usage, 0, 10),
- array('Others'=>array_sum(array_slice($all_time_clients_usage, 10)))
- );
+ // The sliceVisibilityThreshold option in the chart will prevent small slices from being created
+ $all_time_clients_usage = Utils::getClientUsageVisualizationData($all_time_clients_usage);
$this->addToView('all_time_clients_usage', $all_time_clients_usage);
// Only show the two most used clients for the last 25 posts
View
90 webapp/_lib/model/class.FollowerCountMySQLDAO.php
@@ -69,6 +69,37 @@ public function getHistory($network_user_id, $network, $units, $limit=10) {
$ps = $this->execute($q, $vars);
$history_rows = $this->getDataRowsAsArrays($ps);
+ $resultset = array();
+ switch ($network) {
+ case 'facebook':
+ $follower_description = 'Friends';
+ break;
+ case 'facebook page':
+ $follower_description = 'Fans';
+ break;
+ case 'twitter':
+ default:
+ $follower_description = 'Followers';
+ break;
+ }
+ foreach ($history_rows as $row) {
+ $timestamp = strtotime($row['full_date']);
+ $resultset[] = array('c' => array(
+ array('v' => sprintf('new Date(%d,%d,%d)', date('Y', $timestamp), date('n', $timestamp) - 1,
+ date('j', $timestamp)), 'f' => $row['date']),
+ array('v' => intval($row['count']))
+ ));
+ }
+ $metadata = array(
+ array('type' => 'date', 'label' => 'Date'),
+ array('type' => 'number', 'label' => $follower_description),
+ );
+ $vis_data = json_encode(array('rows' => $resultset, 'cols' => $metadata));
+ // Google Chart docs say that a string of the form "Date(Y,m,d)" should
+ // work, but chrome throws an error if we don't use an actual Date
+ // object.
+ $vis_data = preg_replace('/"(new Date[^"]+)"/', '$1', $vis_data);
+
if (sizeof($history_rows) > 1 ) {
//break down rows into a simpler date=>count assoc array
$simplified_history = array();
@@ -83,57 +114,9 @@ public function getHistory($network_user_id, $network, $units, $limit=10) {
$last_follower_count = end($simplified_history);
$trend = ($last_follower_count - $first_follower_count)/sizeof($simplified_history);
$trend = intval(round($trend));
- //complete data set
- $history = $simplified_history;
- } else { //there are dates with missing data
- //set up an array of all the dates to show in the chart
- $dates_to_display = array();
- $format = 'n/j';
- $date = date ( $format );
- $i = $limit;
- while ($i > 0 ) {
- if ($units != "MONTH") {
- $date_ago = date ($format, strtotime('-'.$i.' '.$units.$date));
- } else {
- $first_day_of_this_month = date('n/1');
- $format = 'm/d/Y';
- $date_ago = date ($format, strtotime('-'.$i.' '.$units.$first_day_of_this_month));
- }
- $dates_to_display[$date_ago] = "no data";
- $i--;
- }
- //merge the data we do have with the dates we want
- $history = array_merge($dates_to_display, $simplified_history);
}
+ $history = $simplified_history;
- //calculate the point percentages
- $percentages = array();
-
- $max_count = intval($history_rows[0]['count']);
- $min_count = intval($history_rows[0]['count']);
- foreach ($history_rows as $row) {
- $min_count = ($row['count'] < $min_count)?intval($row['count']):$min_count;
- $max_count = ($row['count'] > $max_count)?intval($row['count']):$max_count;
- }
- $difference = $max_count - $min_count;
- foreach ($history as $data_point) {
- if ($data_point == 'no data') {
- $percentages[] = 0;
- } else {
- $amount_above_min = $data_point - $min_count;
- $percentages[] = round(Utils::getPercentage($amount_above_min, $difference));
- }
- }
-
- $y_axis = array();
- $num_y_axis_points = 4;
- $y_axis_interval_size = $difference/$num_y_axis_points;
- $i = 0;
- while ($i < $num_y_axis_points) {
- $y_axis[$i] = $min_count + ($y_axis_interval_size * $i);
- $i = $i+1;
- }
- $y_axis[$num_y_axis_points] = $max_count;
$milestone = Utils::predictNextMilestoneDate(intval($history_rows[sizeof($history_rows)-1]['count']),
$trend);
if (isset($milestone)) {
@@ -145,14 +128,9 @@ public function getHistory($network_user_id, $network, $units, $limit=10) {
}
} else {
$history = false;
- $y_axis = false;
$trend = false;
- $percentages = false;
$milestone = false;
- $max_count = false;
- $min_count = false;
}
- return array('history'=>$history, 'percentages'=>$percentages, 'y_axis'=>$y_axis, 'trend'=>$trend,
- 'milestone'=> $milestone, 'max_count'=>$max_count, 'min_count'=>$min_count);
+ return array('history'=>$history, 'trend'=>$trend, 'milestone'=> $milestone, 'vis_data' => $vis_data);
}
-}
+}
View
75 webapp/_lib/model/class.GroupMembershipCountMySQLDAO.php
@@ -85,6 +85,24 @@ public function getHistory($network_user_id, $network, $units, $limit=10) {
$ps = $this->execute($q, $vars);
$history_rows = $this->getDataRowsAsArrays($ps);
+ foreach ($history_rows as $row) {
+ $timestamp = strtotime($row['full_date']);
+ $resultset[] = array('c' => array(
+ array('v' => sprintf('new Date(%d,%d,%d)', date('Y', $timestamp), date('n', $timestamp) - 1,
+ date('j', $timestamp)), 'f' => $row['date']),
+ array('v' => intval($row['count']))
+ ));
+ }
+ $metadata = array(
+ array('type' => 'date', 'label' => 'Date'),
+ array('type' => 'number', 'label' => 'Count'),
+ );
+ $vis_data = json_encode(array('rows' => $resultset, 'cols' => $metadata));
+ // Google Chart docs say that a string of the form "Date(Y,m,d)" should
+ // work, but chrome throws an error if we don't use an actual Date
+ // object.
+ $vis_data = preg_replace('/"(new Date[^"]+)"/', '$1', $vis_data);
+
if (sizeof($history_rows) > 1 ) {
//break down rows into a simpler date=>count assoc array
$simplified_history = array();
@@ -99,57 +117,9 @@ public function getHistory($network_user_id, $network, $units, $limit=10) {
$last_group_count = end($simplified_history);
$trend = ($last_group_count - $first_group_count)/sizeof($simplified_history);
$trend = intval(round($trend));
- //complete data set
- $history = $simplified_history;
- } else { //there are dates with missing data
- //set up an array of all the dates to show in the chart
- $dates_to_display = array();
- $format = 'n/j';
- $date = date ( $format );
- $i = $limit;
- while ($i > 0 ) {
- if ($units != "MONTH") {
- $date_ago = date ($format, strtotime('-'.$i.' '.$units.$date));
- } else {
- $first_day_of_this_month = date('n/1');
- $format = 'm/d/Y';
- $date_ago = date ($format, strtotime('-'.$i.' '.$units.$first_day_of_this_month));
- }
- $dates_to_display[$date_ago] = "no data";
- $i--;
- }
- //merge the data we do have with the dates we want
- $history = array_merge($dates_to_display, $simplified_history);
- }
-
- //calculate the point percentages
- $percentages = array();
-
- $max_count = intval($history_rows[0]['count']);
- $min_count = intval($history_rows[0]['count']);
- foreach ($history_rows as $row) {
- $min_count = ($row['count'] < $min_count)?intval($row['count']):$min_count;
- $max_count = ($row['count'] > $max_count)?intval($row['count']):$max_count;
- }
- $difference = $max_count - $min_count;
- foreach ($history as $data_point) {
- if ($data_point == 'no data') {
- $percentages[] = 0;
- } else {
- $amount_above_min = $data_point - $min_count;
- $percentages[] = round(Utils::getPercentage($amount_above_min, $difference));
- }
}
+ $history = $simplified_history;
- $y_axis = array();
- $num_y_axis_points = 4;
- $y_axis_interval_size = $difference/$num_y_axis_points;
- $i = 0;
- while ($i < $num_y_axis_points) {
- $y_axis[$i] = $min_count + ($y_axis_interval_size * $i);
- $i = $i+1;
- }
- $y_axis[$num_y_axis_points] = $max_count;
$milestone = Utils::predictNextMilestoneDate(intval($history_rows[sizeof($history_rows)-1]['count']),
$trend);
if (isset($milestone)) {
@@ -161,14 +131,9 @@ public function getHistory($network_user_id, $network, $units, $limit=10) {
}
} else {
$history = false;
- $y_axis = false;
$trend = false;
- $percentages = false;
$milestone = false;
- $max_count = false;
- $min_count = false;
}
- return array('history'=>$history, 'percentages'=>$percentages, 'y_axis'=>$y_axis, 'trend'=>$trend,
- 'milestone'=> $milestone, 'max_count'=>$max_count, 'min_count'=>$min_count);
+ return array('history'=>$history, 'trend'=>$trend, 'milestone'=> $milestone, 'vis_data' => $vis_data);
}
}
View
65 webapp/_lib/model/class.Utils.php
@@ -422,4 +422,69 @@ public static function predictNextMilestoneDate($current_count, $upward_incremen
return null;
}
}
+
+ /**
+ * Convert Hot Posts data to JSON for use with Google Charts
+ * @param array $hot_posts Array returned from PostDAO::getHotPosts
+ * @return string JSON
+ */
+ public static function getHotPostVisualizationData($hot_posts, $network) {
+ switch ($network) {
+ case 'twitter':
+ $post_label = 'Tweet';
+ $approval_field = 'all_retweets';
+ $approval_label = 'Retweets';
+ break;
+ case 'facebook':
+ case 'facebook page':
+ $post_label = 'Post';
+ $approval_field = 'favlike_count_cache';
+ $approval_label = 'Likes';
+ break;
+ case 'google+':
+ $post_label = 'Post';
+ $approval_field = 'favlike_count_cache';
+ $approval_label = "+1's";
+ break;
+ default:
+ $post_label = 'Post';
+ $approval_field = 'favlike_count_cache';
+ $approval_label = "Favorites";
+ break;
+ }
+ $metadata = array(
+ array('type' => 'string', 'label' => $post_label),
+ array('type' => 'number', 'label' => $approval_label),
+ array('type' => 'number', 'label' => 'Replies'),
+ );
+ $resultset = array();
+ foreach ($hot_posts as $post) {
+ $resultset[] = array('c' => array(
+ array('v' => $post->post_text),
+ array('v' => intval($post->$approval_field)),
+ array('v' => intval($post->reply_count_cache)),
+ ));
+ }
+ return json_encode(array('rows' => $resultset, 'cols' => $metadata));
+ }
+
+ /**
+ * Convert client usage data to JSON for Google Charts
+ * @param array $client_usage Array returned from PostDAO::getClientsUsedByUserOnNetwork
+ * @return string JSON
+ */
+ public static function getClientUsageVisualizationData($client_usage) {
+ $metadata = array(
+ array('type' => 'string', 'label' => 'Client'),
+ array('type' => 'number', 'label' => 'Posts'),
+ );
+ $resultset = array();
+ foreach ($client_usage as $client => $posts) {
+ $resultset[] = array('c' => array(
+ array('v' => $client, 'f' => sprintf('%s (%d)', $client, intval($posts))),
+ array('v' => intval($posts)),
+ ));
+ }
+ return json_encode(array('rows' => $resultset, 'cols' => $metadata));
+ }
}
View
5 webapp/_lib/view/_header.tpl
@@ -13,6 +13,11 @@
<link type="text/css" rel="stylesheet" href="{$site_root_path}assets/css/jquery-ui-1.7.1.custom.css">
<script type="text/javascript" src="{$site_root_path}assets/js/jquery.min-1.4.js"></script>
<script type="text/javascript" src="{$site_root_path}assets/js/jquery-ui.min-1.8.js"></script>
+
+ <!-- google chart tools -->
+ <!--Load the AJAX API-->
+ <script type="text/javascript" src="https://www.google.com/jsapi"></script>
+
<script type="text/javascript" src="{$site_root_path}plugins/twitter/assets/js/widgets.js"></script>
<script type="text/javascript">var site_root_path = '{$site_root_path}';</script>
{if $csrf_token}<script type="text/javascript">var csrf_token = '{$csrf_token}';</script>{/if}
View
465 webapp/_lib/view/dashboard.tpl
@@ -9,30 +9,30 @@
<div id="nav-sidebar">
<ul id="top-level-sidenav">
<li style="list-style: none">
- {if $instance}
- <ul>
- <li>
- <ul class="side-subnav">
- <li{if $smarty.get.v eq ''} class="currentview"{/if}><br />
- <a href="{$site_root_path}index.php?u={$instance->network_username|urlencode}&n={$instance->network|urlencode}">Dashboard</a>
+ {if $instance}
+ <ul>
+ <li>
+ <ul class="side-subnav">
+ <li{if $smarty.get.v eq ''} class="currentview"{/if}><br />
+ <a href="{$site_root_path}index.php?u={$instance->network_username|urlencode}&n={$instance->network|urlencode}">Dashboard</a>
+ </li>
+ {/if}
+ {if $sidebar_menu}
+ {foreach from=$sidebar_menu key=smkey item=sidebar_menu_item name=smenuloop}
+ {if $sidebar_menu_item->header}
+ </ul>
+ </li>
+ <li>{$sidebar_menu_item->header}
+ <ul class="side-subnav">
+ {/if}
+ <li{if $smarty.get.v eq $smkey} class="currentview"{/if}>
+ <a href="{$site_root_path}index.php?v={$smkey}&u={$instance->network_username|urlencode}&n={$instance->network|urlencode}">{$sidebar_menu_item->name}</a></li>
+ {/foreach}
+ </ul>
</li>
- {/if}
- {if $sidebar_menu}
- {foreach from=$sidebar_menu key=smkey item=sidebar_menu_item name=smenuloop}
- {if $sidebar_menu_item->header}
</ul>
+ {/if}
</li>
- <li>{$sidebar_menu_item->header}
- <ul class="side-subnav">
- {/if}
- <li{if $smarty.get.v eq $smkey} class="currentview"{/if}>
- <a href="{$site_root_path}index.php?v={$smkey}&u={$instance->network_username|urlencode}&n={$instance->network|urlencode}">{$sidebar_menu_item->name}</a></li>
- {/foreach}
- </ul>
- </li>
- </ul>
- {/if}
- </li>
</ul>
</div>
</div>
@@ -43,192 +43,289 @@
{include file="_usermessage.tpl"}
{if $instance}
- <!--begin public user dashboard-->
- {if $user_details}
- <div class="grid_18 alpha omega">
- <div class="clearfix dashboard-header round-all">
- <div class="grid_2 alpha">
- <div class="avatar-container">
- <img src="{$user_details->avatar}" class="avatar2"/>
- <img src="{$site_root_path}plugins/{$user_details->network|get_plugin_path}/assets/img/favicon.ico" class="service-icon2"/>
- </div>
- </div>
- <div class="grid_15 omega">
- <span class="tweet">{$user_details->username} <span style="color:#ccc">{$user_details->network|capitalize}</span></span><br />
- <div class="small">
- {if $instance->crawler_last_run eq 'realtime'}<span style="color:green;">&#9679;</span> Updated in realtime{else}Updated {$instance->crawler_last_run|relative_datetime} ago{/if}{if !$instance->is_active} (paused){/if}
- </div>
- </div>
- </div>
- </div>
- {/if}
+ <!--begin public user dashboard-->
+ {if $user_details}
+ <div class="grid_18 alpha omega">
+ <div class="clearfix dashboard-header round-all">
+ <div class="grid_2 alpha">
+ <div class="avatar-container">
+ <img src="{$user_details->avatar}" class="avatar2"/>
+ <img src="{$site_root_path}plugins/{$user_details->network|get_plugin_path}/assets/img/favicon.ico" class="service-icon2"/>
+ </div>
+ </div>
+ <div class="grid_15 omega">
+ <span class="tweet">{$user_details->username} <span style="color:#ccc">{$user_details->network|capitalize}</span></span><br />
+ <div class="small">
+ {if $instance->crawler_last_run eq 'realtime'}<span style="color:green;">&#9679;</span> Updated in realtime{else}Updated {$instance->crawler_last_run|relative_datetime} ago{/if}{if !$instance->is_active} (paused){/if}
+ </div>
+ </div>
+ </div>
+ </div>
+ {/if}
- {if $data_template}
- {include file=$data_template}
- <div class="float-l" id="older-posts-div">
+ {if $data_template}
+ {include file=$data_template}
+ <div class="float-l" id="older-posts-div">
{if $next_page}
<a href="{$site_root_path}index.php?{if $smarty.get.v}v={$smarty.get.v}&{/if}{if $smarty.get.u}u={$smarty.get.u}&{/if}{if $smarty.get.n}n={$smarty.get.n|urlencode}&{/if}page={$next_page}" id="next_page">&#60; Older Posts</a>
{/if}
{if $last_page}
| <a href="{$site_root_path}index.php?{if $smarty.get.v}v={$smarty.get.v}&{/if}{if $smarty.get.u}u={$smarty.get.u}&{/if}{if $smarty.get.n}n={$smarty.get.n|urlencode}&{/if}page={$last_page}" id="last_page">Newer Posts &#62;</a>
{/if}
- </div>
- {else} <!-- else if $data_template -->
- {if $hot_posts|@count > 3}
- <h2>Hot Posts</h2>
- {foreach from=$hot_posts key=tid item=t name=foo}
- {if $smarty.foreach.foo.index < 3}
- {if $instance->network eq "twitter"}
- {include file="_post.counts_no_author.tpl" post=$t}
- {else}
- {include file="_post.counts_no_author.tpl" post=$t show_favorites_instead_of_retweets=true}
- {/if}
- {/if}
- {/foreach}
- {else}
- {if $recent_posts}
- <h2>Recent posts</h2>
- {foreach from=$recent_posts key=tid item=t name=foo}
- {if $smarty.foreach.foo.index < 3}
- {if $instance->network eq "twitter"}
- {include file="_post.counts_no_author.tpl" post=$t}
- {else}
- {include file="_post.counts_no_author.tpl" post=$t show_favorites_instead_of_retweets=true}
- {/if}
- {/if}
- {/foreach}
+ </div>
+ {else} <!-- else if $data_template -->
+ {if $hot_posts|@count > 3}
+ <h2>Hot Posts</h2>
+ {foreach from=$hot_posts key=tid item=t name=foo}
+ {if $smarty.foreach.foo.index < 3}
+ {if $instance->network eq "twitter"}
+ {include file="_post.counts_no_author.tpl" post=$t}
+ {else}
+ {include file="_post.counts_no_author.tpl" post=$t show_favorites_instead_of_retweets=true}
+ {/if}
+ {/if}
+ {/foreach}
+ {else}
+ {if $recent_posts}
+ <h2>Recent posts</h2>
+ {foreach from=$recent_posts key=tid item=t name=foo}
+ {if $smarty.foreach.foo.index < 3}
+ {if $instance->network eq "twitter"}
+ {include file="_post.counts_no_author.tpl" post=$t}
+ {else}
+ {include file="_post.counts_no_author.tpl" post=$t show_favorites_instead_of_retweets=true}
+ {/if}
+ {/if}
+ {/foreach}
+ {/if}
+ {/if}
+
+ {if $hot_posts|@count > 3}
+ <div class="clearfix">
+ <!-- show retweets and replies for twitter; show favorites and replies for others -->
+ <div id="hot_posts">
+ </div>
{/if}
- {/if}
- {if $hot_posts|@count > 3}
- <h2>Recent Activity</h2>
+ {if $most_replied_to_1wk}
<div class="clearfix">
- {foreach from=$hot_posts key=post_id item=post name=foo}
- {assign var="ra_count" value="`$post->favlike_count_cache+$post->reply_count_cache+$post->all_retweets`"}
- {if $ra_max < $ra_count}
- {assign var="ra_max" value=$ra_count}
- {/if}
- {/foreach}
- {if $instance->network neq "twitter"}
- <img width="700" height="280" src="http://chart.googleapis.com/chart?chxs=0,,11&chxt=y&chxl=0:|{foreach from=$hot_posts|@array_reverse key=post_id item=post name=foo}{if $post->post_text}{$post->post_text|replace:'|':''|strip_tags|truncate:50|urlencode}{elseif $post->link->title}{$post->link->title|replace:'|':''|truncate:50|urlencode}{elseif $post->link->url}{$post->link->url|replace:'|':''|truncate:50|urlencode}{else}{$post->pub_date|date_format:"%b %e"}{/if}|{/foreach}&chd=t:{foreach from=$hot_posts key=post_id item=post name=foo}{if $post->favlike_count_cache > 0}{$post->favlike_count_cache}{else}_{/if}{if !$smarty.foreach.foo.last},{/if}{/foreach}|{foreach from=$hot_posts key=post_id item=post name=foo}{if $post->reply_count_cache > 0}{$post->reply_count_cache}{else}_{/if}{if !$smarty.foreach.foo.last},{/if}{/foreach}&chds=0,{$ra_max+5}&chbh=a&chco=FF9900,cccccc&&chdl={if $instance->network eq 'google+'}%2B1's{else}Likes{/if}|Replies&chs=700x280&cht=bhs&chm=N*s*,666666,-1,-1,11,,e:2:0">
- {else}
- <img width="700" height="280" src="http://chart.googleapis.com/chart?chxs=0,,11&chxt=y&chxl=0:|{foreach from=$hot_posts|@array_reverse key=post_id item=post name=foo}{$post->post_text|replace:'|':''|truncate:50|urlencode}|{/foreach}&chd=t:{foreach from=$hot_posts key=post_id item=post name=foo}{if $post->all_retweets > 0}{$post->all_retweets}{else}_{/if}{if !$smarty.foreach.foo.last},{/if}{/foreach}|{foreach from=$hot_posts key=post_id item=post name=foo}{if $post->reply_count_cache > 0}{$post->reply_count_cache}{else}_{/if}{if !$smarty.foreach.foo.last},{/if}{/foreach}&chds=0,{$ra_max+5}&chbh=a&chco=FF9900,cccccc&chdl=Retweets|Replies&chs=700x280&cht=bhs&chm=N*s*,666666,-1,-1,11,,e:2:0">
- {/if}
+ <h2>This Week's Most {if $instance->network eq 'google+'}Discussed{else}Replied-To{/if} Posts</h2>
+ {foreach from=$most_replied_to_1wk key=tid item=t name=foo}
+ {if $instance->network eq "twitter"}
+ {include file="_post.counts_no_author.tpl" post=$t headings="NONE"}
+ {else}
+ {include file="_post.counts_no_author.tpl" post=$t headings="NONE" show_favorites_instead_of_retweets=true}
+ {/if}
+ {/foreach}
</div>
- {/if}
-
- {if $most_replied_to_1wk}
- <div class="clearfix">
- <h2>This Week's Most {if $instance->network eq 'google+'}Discussed{else}Replied-To{/if} Posts</h2>
- {foreach from=$most_replied_to_1wk key=tid item=t name=foo}
- {if $instance->network eq "twitter"}
- {include file="_post.counts_no_author.tpl" post=$t headings="NONE"}
- {else}
- {include file="_post.counts_no_author.tpl" post=$t headings="NONE" show_favorites_instead_of_retweets=true}
- {/if}
- {/foreach}
- </div>
- {/if}
-
- {if $most_faved_1wk}
- <div class="clearfix">
- <h2>This Week's Most {if $instance->network eq 'google+'}+1'ed{else}Liked{/if} Posts</h2>
- {foreach from=$most_faved_1wk key=tid item=t name=foo}
- {include file="_post.counts_no_author.tpl" post=$t headings="NONE" show_favorites_instead_of_retweets=true}
- {/foreach}
- </div>
- {/if}
+ {/if}
- {if $follower_count_history_by_day.history && $follower_count_history_by_week.history}
- <div class="clearfix">
- <div class="grid_9 alpha">
- <h2>
- {if $instance->network eq 'twitter'}Followers {elseif $instance->network eq 'facebook page'}Fans {elseif $instance->network eq 'facebook'}Friends {/if}By Day
- {if $follower_count_history_by_day.trend}
- ({if $follower_count_history_by_day.trend > 0}<span style="color:green">+{else}<span style="color:red">{/if}
- {$follower_count_history_by_day.trend|number_format}</span>/day)
- {/if}
- </h2>
- {if !$follower_count_history_by_day.history OR $follower_count_history_by_day.history|@count < 2}
- <br /><i>Not enough data to display chart</i>
- {else}
- <img width="350" height="200" src="http://chart.apis.google.com/chart?chs=350x200&chxt=x,y&chxl=0:|{foreach from=$follower_count_history_by_day.history key=tid item=t name=foo}{$tid|date_format:"%b %d"}|{/foreach}1:|{foreach from=$follower_count_history_by_day.y_axis key=tid item=t name=foo}{$t|number_format}{if !$smarty.foreach.foo.last}|{/if}{/foreach}&cht=bvs&chco=FF9900&chd=t:{foreach from=$follower_count_history_by_day.history key=tid item=t name=foo}{if $t > 0}{$t}{else}_{/if}{if !$smarty.foreach.foo.last},{/if}{/foreach}&chbh=a&chds={$follower_count_history_by_day.min_count},{$follower_count_history_by_day.max_count}&chxr={$follower_count_history_by_day.min_count},{$follower_count_history_by_day.max_count}&chxs=1N*s*&chm=N*s*,666666,0,-1,10,,e::5" />
- {/if}
- </div>
- <div class="grid_9 omega">
- <h2>
- {if $instance->network eq 'twitter'}Followers {elseif $instance->network eq 'facebook page'}Fans {elseif $instance->network eq 'facebook'}Friends {/if} By Week
- {if $follower_count_history_by_week.trend != 0}
- ({if $follower_count_history_by_week.trend > 0}<span style="color:green">+{else}<span style="color:red">{/if}
- {$follower_count_history_by_week.trend|number_format}</span>/week)
- {/if}
- </h2>
- {if !$follower_count_history_by_week.history OR $follower_count_history_by_week.history|@count < 2}
- <br /><i>Not enough data to display chart</i><br clear="all"/>
- {else}
- <img width="350" height="200" src="http://chart.apis.google.com/chart?chs=350x200&chxt=x,y&chxl=0:|{foreach from=$follower_count_history_by_week.history key=tid item=t name=foo}{$tid|date_format:"%b %d"}|{/foreach}1:|{foreach from=$follower_count_history_by_week.y_axis key=tid item=t name=foo}{$t|number_format}{if !$smarty.foreach.foo.last}|{/if}{/foreach}&cht=bvs&chco=FF9900&chd=t:{foreach from=$follower_count_history_by_week.history key=tid item=t name=foo}{if $t > 0}{$t}{else}_{/if}{if !$smarty.foreach.foo.last},{/if}{/foreach}&chbh=a&chds={$follower_count_history_by_week.min_count},{$follower_count_history_by_week.max_count}&chxr={$follower_count_history_by_week.min_count},{$follower_count_history_by_week.max_count}&chxs=1N*s*&chm=N*s*,666666,0,-1,10,,e::5" />
- {/if}
+ {if $most_faved_1wk}
+ <div class="clearfix">
+ <h2>This Week's Most {if $instance->network eq 'google+'}+1'ed{else}Liked{/if} Posts</h2>
+ {foreach from=$most_faved_1wk key=tid item=t name=foo}
+ {include file="_post.counts_no_author.tpl" post=$t headings="NONE" show_favorites_instead_of_retweets=true}
+ {/foreach}
</div>
- </div>
- {/if}
-
- {if $follower_count_history_by_week.milestone}
- <div class="small gray">
- Next milestone: <span style="background-color:#FFFF80;color:black">{$follower_count_history_by_week.milestone.will_take} week{if $follower_count_history_by_week.milestone.will_take > 1}s{/if}</span> till you reach <span style="background-color:#FFFF80;color:black">{$follower_count_history_by_week.milestone.next_milestone|number_format} followers</span> at this rate. <a href="{$site_root_path}index.php?v=followers-history&u={$instance->network_username}&n={$instance->network}">More...</a>
- </div>
- {/if}
- {if $least_likely_followers}
- <div class="clearfix">
- <h2>Most Discerning Followers</h2>
+ {/if}
+ {if $follower_count_history_by_day.history && $follower_count_history_by_week.history}
<div class="clearfix">
- {foreach from=$least_likely_followers key=uid item=u name=foo}
- <div class="avatar-container" style="float:left;margin:7px;">
- <a href="http://twitter.com/{$u.user_name}" title="{$u.user_name}"><img src="{$u.avatar}" class="avatar2"/><img src="{$site_root_path}plugins/{$u.network}/assets/img/favicon.ico" class="service-icon2"/></a>
+ <div class="grid_9 alpha">
+ <div id="follower_count_history_by_day"></div>
+ {if $follower_count_history_by_day.trend}({if $follower_count_history_by_day.trend > 0}<span style="color:green">+{else}<span style="color:red">{/if}{$follower_count_history_by_day.trend|number_format}</span>/day){/if}
+ </div>
+ <div class="grid_9 omega">
+ <div id="follower_count_history_by_week"></div>
+ {if $follower_count_history_by_week.trend != 0}({if $follower_count_history_by_week.trend > 0}<span style="color:green">+{else}<span style="color:red">{/if}{$follower_count_history_by_week.trend|number_format}</span>/week){/if}
</div>
- {/foreach}
- <div class="clearfix small prepend">
- <br ><br >&nbsp;<a href="{$site_root_path}index.php?v=followers-leastlikely&u={$instance->network_username}&n={$instance->network}">More...</a></div>
</div>
+ <script type="text/javascript">
+ // Load the Visualization API and the standard charts
+ google.load('visualization', '1');
+ // Set a callback to run when the Google Visualization API is loaded.
+ google.setOnLoadCallback(drawCharts);
+
+ {literal}
+ function drawCharts() {
+ {/literal}
+ var follower_count_history_by_day_data = new google.visualization.DataTable(
+ {$follower_count_history_by_day.vis_data});
+ var follower_count_history_by_week_data = new google.visualization.DataTable(
+ {$follower_count_history_by_week.vis_data});
+ var follower_description = '{if $instance->network eq 'twitter'}Followers{elseif $instance->network eq 'facebook page'}Fans{elseif $instance->network eq 'facebook'}Friends{/if}';
+
+ var hot_posts_data = new google.visualization.DataTable({$hot_posts_data});
+
+ var client_usage_data = new google.visualization.DataTable({$all_time_clients_usage});
+
+ {literal}
+ var follower_count_history_by_day_chart = new google.visualization.ChartWrapper({
+ containerId: 'follower_count_history_by_day',
+ chartType: 'LineChart',
+ dataTable: follower_count_history_by_day_data,
+ options: {
+ title: follower_description + ' Count By Day',
+ titleTextStyle: {color: '#848884', fontSize: 16},
+ width: 350,
+ height: 250,
+ legend: "top",
+ interpolateNulls: true,
+ vAxis: {
+ minValue: 0
+ }
+ },
+ });
+ follower_count_history_by_day_chart.draw();
+
+ var follower_count_history_by_week_chart = new google.visualization.ChartWrapper({
+ containerId: 'follower_count_history_by_week',
+ chartType: 'LineChart',
+ dataTable: follower_count_history_by_week_data,
+ options: {
+ title: follower_description + ' Count By Week',
+ titleTextStyle: {color: '#848884', fontSize: 16},
+ width: 350,
+ height: 250,
+ legend: "top",
+ interpolateNulls: true,
+ vAxis: {
+ minValue: 0
+ }
+ },
+ });
+ follower_count_history_by_week_chart.draw();
+
+ if (typeof(replies) != 'undefined') {
+ var post_types = new google.visualization.DataTable();
+ post_types.addColumn('number', 'Conversationalist');
+ post_types.addColumn('number', 'Broadcaster');
+ post_types.addRow([{v: replies/100, f: replies + '%'}, {v: links/100, f: links + '%'}]);
+
+ var post_type_chart = new google.visualization.ChartWrapper({
+ containerId: 'post_types',
+ chartType: 'BarChart',
+ dataTable: post_types,
+ options: {
+ title: 'Post Types',
+ titleTextStyle: {color: '#848884', fontSize: 19},
+ width: 300,
+ height: 150,
+ legend: 'top',
+ hAxis: {
+ minValue: 0,
+ maxValue: 1,
+ format:'#,###%'
+ }
+ }
+ });
+ post_type_chart.draw();
+ }
+
+ var hot_posts_chart = new google.visualization.ChartWrapper({
+ containerId: 'hot_posts',
+ chartType: 'BarChart',
+ dataTable: hot_posts_data,
+ options: {
+ title: 'Recent Activity',
+ titleTextStyle: {color: '#848884', fontSize: 19},
+ isStacked: true,
+ width: 700,
+ height: 300,
+ legend: 'right',
+ hAxis: {
+ minValue: 0,
+ },
+ vAxis: {
+ textStyle: {fontSize: 9},
+ },
+ chartArea:{width:"40%"}
+ }
+ });
+ hot_posts_chart.draw();
+
+ var client_usage_chart = new google.visualization.ChartWrapper({
+ containerId: 'client_usage',
+ // chartType: 'ColumnChart',
+ chartType: 'PieChart',
+ dataTable: client_usage_data,
+ options: {
+ title: 'Client Usage (All Posts)',
+ titleTextStyle: {color: '#848884', fontSize: 19},
+ width: 400,
+ height: 300,
+ sliceVisibilityThreshold: 1/100,
+ pieSliceText: 'label',
+ }
+ });
+ client_usage_chart.draw();
+ }
+
+ {/literal}
+ </script>
+ {/if}
+
+ {if $follower_count_history_by_week.milestone}
+ <div class="small gray">
+ Next milestone: <span style="background-color:#FFFF80;color:black">{$follower_count_history_by_week.milestone.will_take} week{if $follower_count_history_by_week.milestone.will_take > 1}s{/if}</span> till you reach <span style="background-color:#FFFF80;color:black">{$follower_count_history_by_week.milestone.next_milestone|number_format} followers</span> at this rate. <a href="{$site_root_path}index.php?v=followers-history&u={$instance->network_username}&n={$instance->network}">More...</a>
</div>
- {/if}
+ {/if}
- {if $most_retweeted_1wk}
- <div class="clearfix">
- <h2>This Week's Most {if $instance->network eq 'google+'}Reshared{else}Retweeted{/if}</h2>
- {foreach from=$most_retweeted_1wk key=tid item=t name=foo}
- {include file="_post.counts_no_author.tpl" post=$t show_favorites_instead_of_retweets=false}
- {/foreach}
- </div>
- {/if}
- {if $instance->network eq 'twitter' }
- <div class="clearfix">
- <div class="public_user_stats">
- <div class="grid_8 alpha">
- <h2>Post Types</span></h2>
- <div class="clearfix small prepend">
- {$instance->percentage_replies|round}% posts are replies<br>
- {$instance->percentage_links|round}% posts contain links<br>
- </div>
- <img width="250" height="175" src="http://chart.apis.google.com/chart?chxt=x,y&cht=bhg&chd=t:{$instance->percentage_replies|round},{$instance->percentage_links|round}&chco=6184B5&chls=2.0&chs=250x175&chxl=0:|20%|60%|100%|1:|Broadcaster|Conversationalist&chxp=0,20,60,100&chbh=50" />
- </div>
- <div class="grid_8 omega">
- <h2>Client Usage <span class="detail">(all posts)</span></h2>
- <img width="400" height="200" src="http://chart.apis.google.com/chart?cht=p&chd=t:{foreach from=$all_time_clients_usage key=name item=num_posts name=foo}{if $num_posts>0}{math equation="round(x/y*100,2)" x=$num_posts y=$all_time_clients_usage|@array_sum}{else}0{/if}{if !$smarty.foreach.foo.last},{/if}{/foreach}&chs=400x200&chl={foreach from=$all_time_clients_usage key=name item=num_posts name=foo}{$name}+({$num_posts}){if !$smarty.foreach.foo.last}|{/if}{/foreach}&chco=6184B5,E6E6E6"><br /><br />
- </div>
- </div>
- </div>
- <small>Recently posting about {$instance->posts_per_day|round} times a day{if $latest_clients_usage}, mostly using {foreach from=$latest_clients_usage key=name item=num_posts name=foo}{$name}{if !$smarty.foreach.foo.last} and {/if}{/foreach}{/if}</small>
- {/if}
- {/if} <!-- end if $data_template -->
+ {if $least_likely_followers}
+ <div class="clearfix">
+ <h2>Most Discerning Followers</h2>
+ <div class="clearfix">
+ {foreach from=$least_likely_followers key=uid item=u name=foo}
+ <div class="avatar-container" style="float:left;margin:7px;">
+ <a href="http://twitter.com/{$u.user_name}" title="{$u.user_name}"><img src="{$u.avatar}" class="avatar2"/><img src="{$site_root_path}plugins/{$u.network}/assets/img/favicon.ico" class="service-icon2"/></a>
+ </div>
+ {/foreach}
+ <div class="clearfix small prepend">
+ <br ><br >&nbsp;<a href="{$site_root_path}index.php?v=followers-leastlikely&u={$instance->network_username}&n={$instance->network}">More...</a></div>
+ </div>
+ </div>
+ {/if}
+
+ {if $most_retweeted_1wk}
+ <div class="clearfix">
+ <h2>This Week's Most {if $instance->network eq 'google+'}Reshared{else}Retweeted{/if}</h2>
+ {foreach from=$most_retweeted_1wk key=tid item=t name=foo}
+ {include file="_post.counts_no_author.tpl" post=$t show_favorites_instead_of_retweets=false}
+ {/foreach}
+ </div>
+ {/if}
+
+ {if $instance->network eq 'twitter' }
+ <div class="clearfix">
+ <div class="public_user_stats">
+ <div class="grid_8 alpha">
+ <h2></h2>
+ <div id="post_types"></div>
+ <div class="clearfix small prepend">
+ {$instance->percentage_replies|round}% posts are replies<br>
+ {$instance->percentage_links|round}% posts contain links<br>
+ </div>
+ <script>
+ var replies = {$instance->percentage_replies|round};
+ var links = {$instance->percentage_links|round};
+ </script>
+ </div>
+ <div class="grid_8 omega">
+ <div id="client_usage">
+ </div>
+ </div>
+ </div>
+ <small>Recently posting about {$instance->posts_per_day|round} times a day{if $latest_clients_usage}, mostly using {foreach from=$latest_clients_usage key=name item=num_posts name=foo}{$name}{if !$smarty.foreach.foo.last} and {/if}{/foreach}{/if}</small>
+ {/if}
+ {/if} <!-- end if $data_template -->
{/if}
{if !$instance}
<div style="width:60%;text-align:center;">
{if $add_user_buttons}
- {foreach from=$add_user_buttons key=smkey item=button name=smenuloop}
- <br><br>
- <div style="float:right;"><a href="{$site_root_path}account/?p={$button}" class="tt-button ui-state-default tt-button-icon-right ui-corner-all"><span class="ui-icon ui-icon-circle-arrow-e"></span>Add a {if $button eq 'googleplus'}Google+{else}{$button|ucwords}{/if} Account</a></div>
- {/foreach}
+ {foreach from=$add_user_buttons key=smkey item=button name=smenuloop}
+ <br><br>
+ <div style="float:right;"><a href="{$site_root_path}account/?p={$button}" class="tt-button ui-state-default tt-button-icon-right ui-corner-all"><span class="ui-icon ui-icon-circle-arrow-e"></span>Add a {if $button eq 'googleplus'}Google+{else}{$button|ucwords}{/if} Account</a></div>
+ {/foreach}
{/if}
<br><br>
<div style="float:right;"><a href="{$site_root_path}account/" class="tt-button ui-state-default tt-button-icon-right ui-corner-all"><span class="ui-icon ui-icon-circle-arrow-e"></span>Adjust Your Settings</a></div>
View
105 webapp/plugins/facebook/view/facebook.followercount.tpl
@@ -9,29 +9,98 @@
</p>
{/if}
-<h2>{if $instance->network eq 'facebook page'}Fan{else}Friend{/if} Count By Day{if !$follower_count_history_by_day.history OR $follower_count_history_by_day.history|@count < 2}
-<br /><i>Not enough data to display chart</i>
-{else}
-{if $follower_count_history_by_day.trend}({if $follower_count_history_by_day.trend > 0}<span style="color:green">+{else}<span style="color:red">{/if}{$follower_count_history_by_day.trend|number_format}</span>/day){/if}</h2>
-<img src="http://chart.apis.google.com/chart?chs=710x200&chxt=x,y&chxl=0:|{foreach from=$follower_count_history_by_day.history key=tid item=t name=foo}{$tid|date_format:"%b %d"}|{/foreach}1:|{foreach from=$follower_count_history_by_day.y_axis key=tid item=t name=foo}{$t|number_format}{if !$smarty.foreach.foo.last}|{/if}{/foreach}&cht=bvs&chco=FF9900&chd=t:{foreach from=$follower_count_history_by_day.history key=tid item=t name=foo}{if $t > 0}{$t}{else}_{/if}{if !$smarty.foreach.foo.last},{/if}{/foreach}&chbh=a&chds={$follower_count_history_by_day.min_count},{$follower_count_history_by_day.max_count}&chxr={$follower_count_history_by_day.min_count},{$follower_count_history_by_day.max_count}&chxs=1N*s*&chm=N*s*,666666,0,-1,10,,e::5" />
+<script>
+var follower_description = '{if $instance->network eq 'facebook page'}Fan{else}Friend{/if}';
+</script>
+<h2>{if $follower_count_history_by_day.trend}({if $follower_count_history_by_day.trend > 0}<span style="color:green">+{else}<span style="color:red">{/if}{$follower_count_history_by_day.trend|number_format}</span>/day){/if}</h2>
+<div id="follower_count_history_by_day"></div>
{if $follower_count_history_by_day.milestone}
-<br /><small style="color:gray">NEXT MILESTONE: <span style="background-color:#FFFF80;color:black">{$follower_count_history_by_day.milestone.will_take} day{if $follower_count_history_by_day.milestone.will_take > 1}s{/if}</span> till you reach <span style="background-color:#FFFF80;color:black">{$follower_count_history_by_day.milestone.next_milestone|number_format} followers</span> at this rate.</small>
+ <br /><small style="color:gray">NEXT MILESTONE: <span style="background-color:#FFFF80;color:black">{$follower_count_history_by_day.milestone.will_take} day{if $follower_count_history_by_day.milestone.will_take > 1}s{/if}</span> till you reach <span style="background-color:#FFFF80;color:black">{$follower_count_history_by_day.milestone.next_milestone|number_format} followers</span> at this rate.</small>
{/if}
-{/if}
-<br /><br />
-<h2>{if $instance->network eq 'facebook page'}Fan{else}Friend{/if} Count By Week{if !$follower_count_history_by_week.history OR $follower_count_history_by_week.history|@count < 2}<br /><i>Not enough data to display chart</i><br clear="all"/>{else} {if $follower_count_history_by_week.trend != 0}({if $follower_count_history_by_week.trend > 0}<span style="color:green">+{else}<span style="color:red">{/if}{$follower_count_history_by_week.trend|number_format}</span>/week){/if}</h2>
-<img src="http://chart.apis.google.com/chart?chs=710x200&chxt=x,y&chxl=0:|{foreach from=$follower_count_history_by_week.history key=tid item=t name=foo}{$tid|date_format:"%b %d"}|{/foreach}1:|{foreach from=$follower_count_history_by_week.y_axis key=tid item=t name=foo}{$t|number_format}{if !$smarty.foreach.foo.last}|{/if}{/foreach}&cht=bvs&chco=FF9900&chd=t:{foreach from=$follower_count_history_by_week.history key=tid item=t name=foo}{if $t > 0}{$t}{else}_{/if}{if !$smarty.foreach.foo.last},{/if}{/foreach}&chbh=a&chds={$follower_count_history_by_week.min_count},{$follower_count_history_by_week.max_count}&chxr={$follower_count_history_by_week.min_count},{$follower_count_history_by_week.max_count}&chxs=1N*s*&chm=N*s*,666666,0,-1,10,,e::5" />
-{if $follower_count_history_by_week.milestone}
-<br /><small style="color:gray">NEXT MILESTONE: <span style="background-color:#FFFF80;color:black">{$follower_count_history_by_week.milestone.will_take} week{if $follower_count_history_by_week.milestone.will_take > 1}s{/if}</span> till you reach <span style="background-color:#FFFF80;color:black">{$follower_count_history_by_week.milestone.next_milestone|number_format} followers</span> at this rate.</small>
-{/if}
+<h2>{if $follower_count_history_by_week.trend != 0}({if $follower_count_history_by_week.trend > 0}<span style="color:green">+{else}<span style="color:red">{/if}{$follower_count_history_by_week.trend|number_format}</span>/week){/if}</h2>
+
+<div id="follower_count_history_by_week"></div>
+ {if $follower_count_history_by_week.milestone}
+<br /><small style="color:gray">NEXT MILESTONE: <span style="background-color:#FFFF80;color:black">{$follower_count_history_by_week.milestone.will_take} week{if $follower_count_history_by_week.milestone.will_take > 1}s{/if}</span> till you reach <span style="background-color:#FFFF80;color:black">{$follower_count_history_by_week.milestone.next_milestone|number_format} followers</span> at this rate.</small>
{/if}
-<br /><br />
-<h2>{if $instance->network eq 'facebook page'}Fan{else}Friend{/if} Count By Month{if !$follower_count_history_by_month.history OR $follower_count_history_by_month.history|@count < 2}<br /><i>Not enough data to display chart</i><br clear="all"/>{else} {if $follower_count_history_by_month.trend != 0}({if $follower_count_history_by_month.trend > 0}<span style="color:green">+{else}<span style="color:red">{/if}{$follower_count_history_by_month.trend|number_format}</span>/month){/if}</h2>
-<img src="http://chart.apis.google.com/chart?chs=710x200&chxt=x,y&chxl=0:|{foreach from=$follower_count_history_by_month.history key=tid item=t name=foo}{$tid|date_format:"%b '%y"}|{/foreach}1:|{foreach from=$follower_count_history_by_month.y_axis key=tid item=t name=foo}{$t|number_format}{if !$smarty.foreach.foo.last}|{/if}{/foreach}&cht=bvs&chco=FF9900&chd=t:{foreach from=$follower_count_history_by_month.history key=tid item=t name=foo}{if $t > 0}{$t}{else}_{/if}{if !$smarty.foreach.foo.last},{/if}{/foreach}&chbh=a&chds={$follower_count_history_by_month.min_count},{$follower_count_history_by_month.max_count}&chxr={$follower_count_history_by_month.min_count},{$follower_count_history_by_month.max_count}&chxs=1N*s*&chm=N*s*,666666,0,-1,10,,e::5" />
+<h2>{if $follower_count_history_by_month.trend != 0}({if $follower_count_history_by_month.trend > 0}<span style="color:green">+{else}<span style="color:red">{/if}{$follower_count_history_by_month.trend|number_format}</span>/month){/if}</h2>
+
+<div id="follower_count_history_by_month"></div>
{if $follower_count_history_by_month.milestone}
-<br /><small style="color:gray">NEXT MILESTONE: <span style="background-color:#FFFF80;color:black">{$follower_count_history_by_month.milestone.will_take} month{if $follower_count_history_by_month.milestone.will_take > 1}s{/if}</span> till you reach <span style="background-color:#FFFF80;color:black">{$follower_count_history_by_month.milestone.next_milestone|number_format} followers</span> at this rate.</small>
-{/if}
+ <br /><small style="color:gray">NEXT MILESTONE: <span style="background-color:#FFFF80;color:black">{$follower_count_history_by_month.milestone.will_take} month{if $follower_count_history_by_month.milestone.will_take > 1}s{/if}</span> till you reach <span style="background-color:#FFFF80;color:black">{$follower_count_history_by_month.milestone.next_milestone|number_format} followers</span> at this rate.</small>
{/if}
+
+<script type="text/javascript">
+// Load the Visualization API and the standard charts
+google.load('visualization', '1');
+// Set a callback to run when the Google Visualization API is loaded.
+google.setOnLoadCallback(drawCharts);
+
+{literal}
+function drawCharts() {
+{/literal}
+ var follower_count_history_by_day_data = new google.visualization.DataTable(
+ {$follower_count_history_by_day.vis_data});
+ var follower_count_history_by_week_data = new google.visualization.DataTable(
+ {$follower_count_history_by_week.vis_data});
+ var follower_count_history_by_month_data = new google.visualization.DataTable(
+ {$follower_count_history_by_month.vis_data});
+
+{literal}
+ var follower_count_history_by_day_chart = new google.visualization.ChartWrapper({
+ containerId: 'follower_count_history_by_day',
+ chartType: 'LineChart',
+ dataTable: follower_count_history_by_day_data,
+ options: {
+ title: follower_description + ' Count By Day',
+ width: 600,
+ height: 250,
+ legend: "top",
+ interpolateNulls: true,
+ vAxis: {
+ minValue: 0
+ }
+ },
+ });
+ follower_count_history_by_day_chart.draw();
+
+ var follower_count_history_by_week_chart = new google.visualization.ChartWrapper({
+ containerId: 'follower_count_history_by_week',
+ chartType: 'LineChart',
+ dataTable: follower_count_history_by_week_data,
+ options: {
+ title: follower_description + ' Count By Week',
+ width: 600,
+ height: 250,
+ legend: "top",
+ interpolateNulls: true,
+ vAxis: {
+ minValue: 0
+ }
+ },
+ });
+ follower_count_history_by_week_chart.draw();
+
+ var follower_count_history_by_month_chart = new google.visualization.ChartWrapper({
+ containerId: 'follower_count_history_by_month',
+ chartType: 'LineChart',
+ dataTable: follower_count_history_by_month_data,
+ options: {
+ title: follower_description + ' Count By Month',
+ width: 600,
+ height: 250,
+ legend: "top",
+ interpolateNulls: true,
+ vAxis: {
+ minValue: 0
+ }
+ },
+ });
+ follower_count_history_by_month_chart.draw();
+}
+
+{/literal}
+</script>
View
103 webapp/plugins/twitter/view/twitter.followercount.tpl
@@ -6,33 +6,98 @@
{if $error}
<p class="error">
{$error}
- </p>
+ </p>
{/if}
-<h2>Follower Count By Day{if !$follower_count_history_by_day.history OR $follower_count_history_by_day.history|@count < 2}
-<br /><i>Not enough data to display chart</i>
-{else}
-{if $follower_count_history_by_day.trend}({if $follower_count_history_by_day.trend > 0}<span style="color:green">+{else}<span style="color:red">{/if}{$follower_count_history_by_day.trend|number_format}</span>/day){/if}</h2>
-<img src="http://chart.apis.google.com/chart?chs=710x200&chxt=x,y&chxl=0:|{foreach from=$follower_count_history_by_day.history key=tid item=t name=foo}{$tid|date_format:"%b %d"}|{/foreach}1:|{foreach from=$follower_count_history_by_day.y_axis key=tid item=t name=foo}{$t|number_format}{if !$smarty.foreach.foo.last}|{/if}{/foreach}&cht=bvs&chco=FF9900&chd=t:{foreach from=$follower_count_history_by_day.history key=tid item=t name=foo}{if $t > 0}{$t}{else}_{/if}{if !$smarty.foreach.foo.last},{/if}{/foreach}&chbh=a&chds={$follower_count_history_by_day.min_count},{$follower_count_history_by_day.max_count}&chxr={$follower_count_history_by_day.min_count},{$follower_count_history_by_day.max_count}&chxs=1N*s*&chm=N*s*,666666,0,-1,10,,e::5" />
+<h2>{if $follower_count_history_by_day.trend}({if $follower_count_history_by_day.trend > 0}<span style="color:green">+{else}<span style="color:red">{/if}{$follower_count_history_by_day.trend|number_format}</span>/day){/if}</h2>
+<div id="follower_count_history_by_day"></div>
{if $follower_count_history_by_day.milestone}
-<br /><small style="color:gray">NEXT MILESTONE: <span style="background-color:#FFFF80;color:black">{$follower_count_history_by_day.milestone.will_take} day{if $follower_count_history_by_day.milestone.will_take > 1}s{/if}</span> till you reach <span style="background-color:#FFFF80;color:black">{$follower_count_history_by_day.milestone.next_milestone|number_format} followers</span> at this rate.</small>
+ <br /><small style="color:gray">NEXT MILESTONE: <span style="background-color:#FFFF80;color:black">{$follower_count_history_by_day.milestone.will_take} day{if $follower_count_history_by_day.milestone.will_take > 1}s{/if}</span> till you reach <span style="background-color:#FFFF80;color:black">{$follower_count_history_by_day.milestone.next_milestone|number_format} followers</span> at this rate.</small>
{/if}
-{/if}
-<br /><br />
-<h2>Follower Count By Week{if !$follower_count_history_by_week.history OR $follower_count_history_by_week.history|@count < 2}<br /><i>Not enough data to display chart</i><br clear="all"/>{else} {if $follower_count_history_by_week.trend != 0}({if $follower_count_history_by_week.trend > 0}<span style="color:green">+{else}<span style="color:red">{/if}{$follower_count_history_by_week.trend|number_format}</span>/week){/if}</h2>
-<img src="http://chart.apis.google.com/chart?chs=710x200&chxt=x,y&chxl=0:|{foreach from=$follower_count_history_by_week.history key=tid item=t name=foo}{$tid|date_format:"%b %d"}|{/foreach}1:|{foreach from=$follower_count_history_by_week.y_axis key=tid item=t name=foo}{$t|number_format}{if !$smarty.foreach.foo.last}|{/if}{/foreach}&cht=bvs&chco=FF9900&chd=t:{foreach from=$follower_count_history_by_week.history key=tid item=t name=foo}{if $t > 0}{$t}{else}_{/if}{if !$smarty.foreach.foo.last},{/if}{/foreach}&chbh=a&chds={$follower_count_history_by_week.min_count},{$follower_count_history_by_week.max_count}&chxr={$follower_count_history_by_week.min_count},{$follower_count_history_by_week.max_count}&chxs=1N*s*&chm=N*s*,666666,0,-1,10,,e::5" />
-{if $follower_count_history_by_week.milestone}
-<br /><small style="color:gray">NEXT MILESTONE: <span style="background-color:#FFFF80;color:black">{$follower_count_history_by_week.milestone.will_take} week{if $follower_count_history_by_week.milestone.will_take > 1}s{/if}</span> till you reach <span style="background-color:#FFFF80;color:black">{$follower_count_history_by_week.milestone.next_milestone|number_format} followers</span> at this rate.</small>
-{/if}
+<h2>{if $follower_count_history_by_week.trend != 0}({if $follower_count_history_by_week.trend > 0}<span style="color:green">+{else}<span style="color:red">{/if}{$follower_count_history_by_week.trend|number_format}</span>/week){/if}</h2>
+<div id="follower_count_history_by_week"></div>
+
+ {if $follower_count_history_by_week.milestone}
+<br /><small style="color:gray">NEXT MILESTONE: <span style="background-color:#FFFF80;color:black">{$follower_count_history_by_week.milestone.will_take} week{if $follower_count_history_by_week.milestone.will_take > 1}s{/if}</span> till you reach <span style="background-color:#FFFF80;color:black">{$follower_count_history_by_week.milestone.next_milestone|number_format} followers</span> at this rate.</small>
{/if}
-<br /><br />
+<h2>{if $follower_count_history_by_month.trend != 0}({if $follower_count_history_by_month.trend > 0}<span style="color:green">+{else}<span style="color:red">{/if}{$follower_count_history_by_month.trend|number_format}</span>/month){/if}</h2>
+<div id="follower_count_history_by_month"></div>
-<h2>Follower Count By Month{if !$follower_count_history_by_month.history OR $follower_count_history_by_month.history|@count < 2}<br /><i>Not enough data to display chart</i><br clear="all"/>{else} {if $follower_count_history_by_month.trend != 0}({if $follower_count_history_by_month.trend > 0}<span style="color:green">+{else}<span style="color:red">{/if}{$follower_count_history_by_month.trend|number_format}</span>/month){/if}</h2>
-<img src="http://chart.apis.google.com/chart?chs=710x200&chxt=x,y&chxl=0:|{foreach from=$follower_count_history_by_month.history key=tid item=t name=foo}{$tid|date_format:"%b '%y"}|{/foreach}1:|{foreach from=$follower_count_history_by_month.y_axis key=tid item=t name=foo}{$t|number_format}{if !$smarty.foreach.foo.last}|{/if}{/foreach}&cht=bvs&chco=FF9900&chd=t:{foreach from=$follower_count_history_by_month.history key=tid item=t name=foo}{if $t > 0}{$t}{else}_{/if}{if !$smarty.foreach.foo.last},{/if}{/foreach}&chbh=a&chds={$follower_count_history_by_month.min_count},{$follower_count_history_by_month.max_count}&chxr={$follower_count_history_by_month.min_count},{$follower_count_history_by_month.max_count}&chxs=1N*s*&chm=N*s*,666666,0,-1,10,,e::5" />
{if $follower_count_history_by_month.milestone}
-<br /><small style="color:gray">NEXT MILESTONE: <span style="background-color:#FFFF80;color:black">{$follower_count_history_by_month.milestone.will_take} month{if $follower_count_history_by_month.milestone.will_take > 1}s{/if}</span> till you reach <span style="background-color:#FFFF80;color:black">{$follower_count_history_by_month.milestone.next_milestone|number_format} followers</span> at this rate.</small>
-{/if}
+ <br /><small style="color:gray">NEXT MILESTONE: <span style="background-color:#FFFF80;color:black">{$follower_count_history_by_month.milestone.will_take} month{if $follower_count_history_by_month.milestone.will_take > 1}s{/if}</span> till you reach <span style="background-color:#FFFF80;color:black">{$follower_count_history_by_month.milestone.next_milestone|number_format} followers</span> at this rate.</small>
{/if}
+
+<script type="text/javascript">
+// Load the Visualization API and the standard charts
+google.load('visualization', '1');
+// Set a callback to run when the Google Visualization API is loaded.
+google.setOnLoadCallback(drawCharts);
+
+{literal}
+function drawCharts() {
+{/literal}
+ var follower_count_history_by_day_data = new google.visualization.DataTable(
+ {$follower_count_history_by_day.vis_data});
+ var follower_count_history_by_week_data = new google.visualization.DataTable(
+ {$follower_count_history_by_week.vis_data});
+ var follower_count_history_by_month_data = new google.visualization.DataTable(
+ {$follower_count_history_by_month.vis_data});
+
+{literal}
+ var follower_count_history_by_day_chart = new google.visualization.ChartWrapper({
+ containerId: 'follower_count_history_by_day',
+ chartType: 'LineChart',
+ dataTable: follower_count_history_by_day_data,
+ options: {
+ title: 'Follower Count By Day',
+ width: 600,
+ height: 250,
+ legend: "top",
+ interpolateNulls: true,
+ vAxis: {
+ minValue: 0
+ }
+ },
+ });
+ follower_count_history_by_day_chart.draw();
+
+ var follower_count_history_by_week_chart = new google.visualization.ChartWrapper({
+ containerId: 'follower_count_history_by_week',
+ chartType: 'LineChart',
+ dataTable: follower_count_history_by_week_data,
+ options: {
+ title: 'Follower Count By Week',
+ width: 600,
+ height: 250,
+ legend: "top",
+ interpolateNulls: true,
+ vAxis: {
+ minValue: 0
+ }
+ },
+ });
+ follower_count_history_by_week_chart.draw();
+
+ var follower_count_history_by_month_chart = new google.visualization.ChartWrapper({
+ containerId: 'follower_count_history_by_month',
+ chartType: 'LineChart',
+ dataTable: follower_count_history_by_month_data,
+ options: {
+ title: 'Follower Count By Month',
+ width: 600,
+ height: 250,
+ legend: "top",
+ interpolateNulls: true,
+ vAxis: {
+ minValue: 0
+ }
+ },
+ });
+ follower_count_history_by_month_chart.draw();
+}
+
+{/literal}
+</script>
View
91 webapp/plugins/twitter/view/twitter.listmembershipcount.tpl
@@ -9,31 +9,98 @@
</p>
{/if}
-<h2>List Membership Count By Day{if !$list_membership_count_history_by_day.history OR $list_membership_count_history_by_day.history|@count < 2}
-<br /><i>Not enough data to display chart</i>
-{else}
-{if $list_membership_count_history_by_day.trend}({if $list_membership_count_history_by_day.trend > 0}<span style="color:green">+{else}<span style="color:red">{/if}{$list_membership_count_history_by_day.trend|number_format}</span>/day){/if}</h2>
-<img src="http://chart.apis.google.com/chart?chs=710x200&chxt=x,y&chxl=0:|{foreach from=$list_membership_count_history_by_day.history key=tid item=t name=foo}{$tid|date_format:"%b %d"}|{/foreach}1:|{foreach from=$list_membership_count_history_by_day.y_axis key=tid item=t name=foo}{$t|number_format}{if !$smarty.foreach.foo.last}|{/if}{/foreach}&cht=bvs&chco=FF9900&chd=t:{foreach from=$list_membership_count_history_by_day.history key=tid item=t name=foo}{if $t > 0}{$t}{else}_{/if}{if !$smarty.foreach.foo.last},{/if}{/foreach}&chbh=a&chds={$list_membership_count_history_by_day.min_count},{$list_membership_count_history_by_day.max_count}&chxr={$list_membership_count_history_by_day.min_count},{$list_membership_count_history_by_day.max_count}&chxs=1N*s*&chm=N*s*,666666,0,-1,10,,e::5" />
+<h2>{if $list_membership_count_history_by_day.trend}({if $list_membership_count_history_by_day.trend > 0}<span style="color:green">+{else}<span style="color:red">{/if}{$list_membership_count_history_by_day.trend|number_format}</span>/day){/if}</h2>
+<div id="list_membership_count_history_by_day"></div>
{if $list_membership_count_history_by_day.milestone}
<br /><small style="color:gray">NEXT MILESTONE: <span style="background-color:#FFFF80;color:black">{$list_membership_count_history_by_day.milestone.will_take} day{if $list_membership_count_history_by_day.milestone.will_take > 1}s{/if}</span> till you reach <span style="background-color:#FFFF80;color:black">{$list_membership_count_history_by_day.milestone.next_milestone|number_format} groups</span> at this rate.</small>
{/if}
-{/if}
<br /><br />
-<h2>List Membership Count By Week{if !$list_membership_count_history_by_week.history OR $list_membership_count_history_by_week.history|@count < 2}<br /><i>Not enough data to display chart</i><br clear="all"/>{else} {if $list_membership_count_history_by_week.trend != 0}({if $list_membership_count_history_by_week.trend > 0}<span style="color:green">+{else}<span style="color:red">{/if}{$list_membership_count_history_by_week.trend|number_format}</span>/week){/if}</h2>
-<img src="http://chart.apis.google.com/chart?chs=710x200&chxt=x,y&chxl=0:|{foreach from=$list_membership_count_history_by_week.history key=tid item=t name=foo}{$tid|date_format:"%b %d"}|{/foreach}1:|{foreach from=$list_membership_count_history_by_week.y_axis key=tid item=t name=foo}{$t|number_format}{if !$smarty.foreach.foo.last}|{/if}{/foreach}&cht=bvs&chco=FF9900&chd=t:{foreach from=$list_membership_count_history_by_week.history key=tid item=t name=foo}{if $t > 0}{$t}{else}_{/if}{if !$smarty.foreach.foo.last},{/if}{/foreach}&chbh=a&chds={$list_membership_count_history_by_week.min_count},{$list_membership_count_history_by_week.max_count}&chxr={$list_membership_count_history_by_week.min_count},{$list_membership_count_history_by_week.max_count}&chxs=1N*s*&chm=N*s*,666666,0,-1,10,,e::5" />
+<h2>{if $list_membership_count_history_by_week.trend}({if $list_membership_count_history_by_week.trend > 0}<span style="color:green">+{else}<span style="color:red">{/if}{$list_membership_count_history_by_week.trend|number_format}</span>/week){/if}</h2>
+<div id="list_membership_count_history_by_week"></div>
+
{if $list_membership_count_history_by_week.milestone}
<br /><small style="color:gray">NEXT MILESTONE: <span style="background-color:#FFFF80;color:black">{$list_membership_count_history_by_week.milestone.will_take} week{if $list_membership_count_history_by_week.milestone.will_take > 1}s{/if}</span> till you reach <span style="background-color:#FFFF80;color:black">{$list_membership_count_history_by_week.milestone.next_milestone|number_format} groups</span> at this rate.</small>
{/if}
-{/if}