diff --git a/google_analytics_reports/google_analytics_reports.blocks.inc b/google_analytics_reports/google_analytics_reports.blocks.inc index c9bcaed..f25799c 100644 --- a/google_analytics_reports/google_analytics_reports.blocks.inc +++ b/google_analytics_reports/google_analytics_reports.blocks.inc @@ -9,14 +9,14 @@ */ function google_analytics_reports_path_mini_ajax() { $path = isset($_GET['path']) ? $_GET['path'] : '/index.html'; - return drupal_json_output(array('content' => google_analytics_reports_path_mini_build($path))); + drupal_json_output(google_analytics_reports_path_mini_build($path)); } /** * Page callback for google-analytics-reports/ajax/dashboard. */ function google_analytics_reports_dashboard_ajax() { - return drupal_json_output(array('content' => google_analytics_reports_dashboard_build())); + drupal_json_output(google_analytics_reports_dashboard_build()); } /** @@ -44,29 +44,50 @@ function google_analytics_reports_path_mini_build($path) { return '

' . _google_analytics_reports_error_message() . '

'; } $max_visits = 0; + $data = array(); foreach ($feed->results as $row) { $data[] = $row['pageviews']; $max_visits = max($row['pageviews'], $max_visits); } - $chart = array( - '#title' => '', - '#chart_id' => 'pageviews_small_30d', - '#data' => $data, - '#type' => CHART_TYPE_LINE . ':nda', - '#size' => chart_size(500, 40), - '#adjust_resolution' => TRUE, - '#data_colors' => array('AAAAAA'), - '#chart_fill' => chart_fill('bg', '00000000'), - '#shape_markers' => array(chart_shape_marker(0, 0, 'B', 0, $color = 'EEEEEE')), - '#line_styles' => array(chart_line_style(2, 10, 0)), + + $series = array('No of pageviews' => $data); + $settings = array(); + $settings['chart']['pageviews_small_30d'] = array( + 'containerId' => 'pageviews_small_30d', + 'header' => array_fill(0, count($data), ''), + 'rows' => array_values($series), + 'columns' => array_keys($series), + 'chartType' => 'AreaChart', + 'options' => array( + 'title' => 'Pageviews', + 'width' => '100%', + 'height' => 40, + 'axisTitlesPosition' => 'none', + 'vAxis' => array( + 'textPosition' => 'none', + 'baselineColor' => 'transparent', + 'gridlines' => array( + 'color' => 'transparent', + ), + ), + 'legend' => array( + 'position' => 'none', + ), + 'chartArea' => array( + 'width' => '100%', + 'height' => '100%', + ), + 'colors' => array('#AAAAAA'), + ), ); - $last_day = end($feed->results); - $title = t('The most views on a single day was @max. Yesterday there were @yesterday views.', array('@max' => $max_visits, '@yesterday' => $last_day['pageviews'])); + $chart = draw_chart($settings); + $report['chart'] = l($chart['markup'], 'admin/reports/google-analytics/detail', array('query' => array('path' => $path), 'html' => TRUE)); - $chart['#attributes'] = array('title' => $title, 'style' => 'height:' . $chart['#size']['#height'] . 'px; width:100%'); - $report['chart'] = l(theme('chart', array('chart' => $chart)), 'admin/reports/google-analytics/detail', array('query' => array('path' => $path), 'html' => TRUE)); $report['views'] = l(t('@views views this month', array('@views' => number_format($feed->totals['pageviews']))), 'admin/reports/google-analytics/detail', array('query' => array('path' => $path))); - return theme('google_analytics_reports_path_mini', $report); + return array( + 'content' => theme('google_analytics_reports_path_mini', $report), + 'settings' => $settings, + ); } /** @@ -85,27 +106,48 @@ function google_analytics_reports_dashboard_build() { return FALSE; } $max_visits = 0; + $data = array(); foreach ($feed->results as $row) { $data[] = $row['visits']; $max_visits = max($row['visits'], $max_visits); } - $chart = array( - '#title' => '', - '#chart_id' => 'visits_large_30d', - '#data' => $data, - '#type' => CHART_TYPE_LINE . ':nda', - '#size' => chart_size(1000, 80), - '#adjust_resolution' => TRUE, - '#data_colors' => array('AAAAAA'), - '#chart_fill' => chart_fill('bg', '00000000'), - '#shape_markers' => array(chart_shape_marker(0, 0, 'B', 0, $color = 'EEEEEE')), - '#line_styles' => array(chart_line_style(2, 10, 0)), + + $series = array('No of visits' => $data); + $settings = array(); + $settings['chart']['visits_large_30d'] = array( + 'containerId' => 'visits_large_30d', + 'header' => array_fill(0, count($data), ''), + 'rows' => array_values($series), + 'columns' => array_keys($series), + 'chartType' => 'AreaChart', + 'options' => array( + 'title' => 'Pageviews', + 'width' => '100%', + 'height' => 80, + 'axisTitlesPosition' => 'none', + 'vAxis' => array( + 'textPosition' => 'none', + 'baselineColor' => 'transparent', + 'gridlines' => array( + 'color' => 'transparent', + ), + ), + 'legend' => array( + 'position' => 'none', + ), + 'chartArea' => array( + 'width' => '100%', + 'height' => '100%', + ), + 'colors' => array('#AAAAAA'), + ), ); - $last_day = end($feed->results); - $title = t('The most visits on a single day was @max. Yesterday there were @yesterday visits.', array('@max' => $max_visits, '@yesterday' => $last_day['visits'])); - $chart['#attributes'] = array('title' => $title, 'style' => 'height:' . $chart['#size']['#height'] . 'px; width:100%'); - $report['chart'] = theme('chart', array('chart' => $chart)); - $report['chart'] = l($report['chart'], 'admin/reports/google-analytics', array('html' => TRUE)); + $chart = draw_chart($settings); + $report['chart'] = l($chart['markup'], 'admin/reports/google-analytics', array('html' => TRUE)); + $report['visits'] = l(t('@visits visits this month', array('@visits' => number_format($feed->totals['visits']))), 'admin/reports/google-analytics'); - return theme('google_analytics_reports_dashboard', $report); -} \ No newline at end of file + return array( + 'content' => theme('google_analytics_reports_dashboard', $report), + 'settings' => $settings, + ); +} diff --git a/google_analytics_reports/google_analytics_reports.info b/google_analytics_reports/google_analytics_reports.info index 38c44f0..e410b78 100644 --- a/google_analytics_reports/google_analytics_reports.info +++ b/google_analytics_reports/google_analytics_reports.info @@ -3,7 +3,7 @@ package = Statistics description = "Provides interface to access Google Analytics API statistics." core = 7.x dependencies[] = google_analytics_api -dependencies[] = chart +dependencies[] = google_chart_tools files[] = google_analytics_reports.blocks.inc files[] = google_analytics_reports.css diff --git a/google_analytics_reports/google_analytics_reports.js b/google_analytics_reports/google_analytics_reports.js index ee8cec5..b79da29 100644 --- a/google_analytics_reports/google_analytics_reports.js +++ b/google_analytics_reports/google_analytics_reports.js @@ -16,6 +16,7 @@ Drupal.behaviors.googleAnalyticsReports = { data: ({ path: window.location.pathname + window.location.search }), success: function(data) { $('.google-analytics-reports-path-mini', context).html(data.content).hide().slideDown('fast'); + GoogleChartTools.drawChart(data.settings); }, error: function(data) { // @TODO @@ -29,6 +30,7 @@ Drupal.behaviors.googleAnalyticsReports = { dataType: 'json', success: function(data) { $('.google-analytics-reports-dashboard', context).html(data.content).hide().slideDown('fast'); + GoogleChartTools.drawChart(data.settings); }, error: function(data) { // @TODO @@ -38,4 +40,4 @@ Drupal.behaviors.googleAnalyticsReports = { } } -})(jQuery); \ No newline at end of file +})(jQuery); diff --git a/google_analytics_reports/google_analytics_reports.module b/google_analytics_reports/google_analytics_reports.module index 8bf9b14..6daea62 100644 --- a/google_analytics_reports/google_analytics_reports.module +++ b/google_analytics_reports/google_analytics_reports.module @@ -66,10 +66,12 @@ function google_analytics_reports_block_view($delta = '') { } switch ($delta) { case 'path_mini': + google_charts_tools_add_library(); $block['subject'] = t('Page traffic'); $block['content'] = '
'; return $block; case 'dashboard': + google_charts_tools_add_library(); $block['subject'] = t('Google Analytics Summary'); $block['content'] = '
'; return $block; @@ -141,4 +143,4 @@ function _google_analytics_reports_error_message() { $message .= ' ' . t('Please review the watchdog for details.', array('!url' => url('admin/reports/dblog'))); } return $message; -} \ No newline at end of file +} diff --git a/google_analytics_reports/google_analytics_reports.pages.inc b/google_analytics_reports/google_analytics_reports.pages.inc index 5bd1487..fc3ba2d 100644 --- a/google_analytics_reports/google_analytics_reports.pages.inc +++ b/google_analytics_reports/google_analytics_reports.pages.inc @@ -73,26 +73,44 @@ function _google_analytics_reports_visits() { return FALSE; } $max_visits = 0; + $data = array(); foreach ($feed->results as $row) { $data[] = $row['visits']; $max_visits = max($row['visits'], $max_visits); } - $chart = array( - '#title' => '', - '#chart_id' => 'visits_large_30d', - '#data' => $data, - '#type' => CHART_TYPE_LINE . ':nda', - '#size' => chart_size(1000, 80), - '#adjust_resolution' => TRUE, - '#data_colors' => array('AAAAAA'), - '#chart_fill' => chart_fill('bg', '00000000'), - '#shape_markers' => array(chart_shape_marker(0, 0, 'B', 0, $color = 'EEEEEE')), - '#line_styles' => array(chart_line_style(2, 10, 0)), + + $series = array('No of visits' => $data); + $settings = array(); + $settings['chart']['visits_large_30d'] = array( + 'header' => array_fill(0, count($data), ''), + 'rows' => array_values($series), + 'columns' => array_keys($series), + 'chartType' => 'AreaChart', + 'options' => array( + 'title' => 'Visits', + 'width' => '100%', + 'height' => 80, + 'axisTitlesPosition' => 'none', + 'vAxis' => array( + 'textPosition' => 'none', + 'baselineColor' => 'transparent', + 'gridlines' => array( + 'color' => 'transparent', + ), + ), + 'legend' => array( + 'position' => 'none', + ), + 'chartArea' => array( + 'width' => '100%', + 'height' => '100%', + ), + 'colors' => array('#AAAAAA'), + ), ); - $last_day = end($feed->results); - $title = t('The most visits on a single day was @max. Yesterday there were @yesterday visits.', array('@max' => $max_visits, '@yesterday' => $last_day['visits'])); - $chart['#attributes'] = array('title' => $title, 'style' => 'height:' . $chart['#size']['#height'] . 'px; width:100%'); - $output = theme('chart', array('chart' => $chart)); + $chart = draw_chart($settings); + $output = $chart['markup']; + return $output; } @@ -113,26 +131,44 @@ function _google_analytics_reports_pageviews($path) { return FALSE; } $max_views = 0; + $data = array(); foreach ($feed->results as $row) { $data[] = $row['pageviews']; $max_views = max($row['pageviews'], $max_views); } - $chart = array( - '#title' => '', - '#chart_id' => 'visits_large_30d', - '#data' => $data, - '#type' => CHART_TYPE_LINE . ':nda', - '#size' => chart_size(1000, 80), - '#adjust_resolution' => TRUE, - '#data_colors' => array('AAAAAA'), - '#chart_fill' => chart_fill('bg', '00000000'), - '#shape_markers' => array(chart_shape_marker(0, 0, 'B', 0, $color = 'EEEEEE')), - '#line_styles' => array(chart_line_style(2, 10, 0)), + + $series = array('No of pageviews' => $data); + $settings = array(); + $settings['chart']['pageviews_large_30d'] = array( + 'header' => array_fill(0, count($data), ''), + 'rows' => array_values($series), + 'columns' => array_keys($series), + 'chartType' => 'AreaChart', + 'options' => array( + 'title' => 'Pageviews', + 'width' => '100%', + 'height' => 80, + 'axisTitlesPosition' => 'none', + 'vAxis' => array( + 'textPosition' => 'none', + 'baselineColor' => 'transparent', + 'gridlines' => array( + 'color' => 'transparent', + ), + ), + 'legend' => array( + 'position' => 'none', + ), + 'chartArea' => array( + 'width' => '100%', + 'height' => '100%', + ), + 'colors' => array('#AAAAAA'), + ), ); - $last_day = end($feed->results); - $title = t('The most views on a single day was @max. Yesterday there were @yesterday views.', array('@max' => $max_views, '@yesterday' => $last_day['pageviews'])); - $chart['#attributes'] = array('title' => $title, 'style' => 'height:' . $chart['#size']['#height'] . 'px; width:100%'); - $output = theme('chart', array('chart' => $chart)); + $chart = draw_chart($settings); + $output = $chart['markup']; + return $output; } @@ -236,4 +272,4 @@ function _google_analytics_reports_top_keywords($path = '') { return FALSE; } return $feed->results; -} \ No newline at end of file +} diff --git a/google_analytics_reports/google_analytics_reports.theme.inc b/google_analytics_reports/google_analytics_reports.theme.inc index 7ccfdcc..2246ac2 100644 --- a/google_analytics_reports/google_analytics_reports.theme.inc +++ b/google_analytics_reports/google_analytics_reports.theme.inc @@ -88,4 +88,4 @@ function theme_google_analytics_reports_path_mini($report) { */ function theme_google_analytics_reports_dashboard($report) { return '

' . t('Visits over the last 30 days') . '

' . $report['chart'] . '

' . $report['visits'] . '

'; -} \ No newline at end of file +}