From 0a1868deeb8d6a9ec2f2f3fdc0d65647a608a2d2 Mon Sep 17 00:00:00 2001 From: ozhozh Date: Mon, 7 Sep 2009 21:33:47 +0000 Subject: [PATCH] - More functions for stat page - CSS & JS for stat page (tabs) git-svn-id: http://yourls.googlecode.com/svn/trunk@134 12232710-3e20-11de-b438-597f59cd7555 --- css/infos.css | 60 +++++++++++ includes/functions-infos.php | 38 ++++--- js/infos.js | 23 +++++ yourls-infos.php | 186 +++++++++++++++++++++++------------ 4 files changed, 227 insertions(+), 80 deletions(-) create mode 100644 css/infos.css create mode 100644 js/infos.js diff --git a/css/infos.css b/css/infos.css new file mode 100644 index 0000000..9404994 --- /dev/null +++ b/css/infos.css @@ -0,0 +1,60 @@ + +#tabs ul#headers { + display:none; + list-style-type:none; + border-bottom:1px solid #ccc; + padding:12px 5px 3px 5px; + margin-left:0; + width:70em; +} + +#tabs ul#headers li { + padding:0; +} + +#tabs ul#headers li a { + color:#595441; + border:1px solid #ccc; + -moz-border-radius-topleft:10px; + -moz-border-radius-topright:10px; + -webkit-border-top-left-radius:10px; + -webkit-border-top-right-radius:10px; + padding:10px 5px 5px 15px; + background:#dde; +} + +#tabs ul#headers li a:hover { + text-decoration:none; + background:#eef; +} + +#tabs ul#headers li a.selected { + border-bottom:2px solid #fff; + background:#fff; +} + +#tabs ul#headers li a.selected:hover { + background:#fff; +} +#tabs ul#headers li, #tabs ul#headers li h2 { + display: inline; + margin-right: 10px; +} + +.tab { + padding:10px; +} + +li#sites_various { padding-left:22px; padding-top:4px;} + +#referrer_cell { min-width: 300px;} + +ul.no_bullet { + list-style-type: none; + margin-left:0; + padding:0; +} + +ul.no_bullet li { + margin-bottom:5px; +} diff --git a/includes/functions-infos.php b/includes/functions-infos.php index 3fd9764..3df6d8e 100644 --- a/includes/functions-infos.php +++ b/includes/functions-infos.php @@ -2,7 +2,6 @@ // Echoes an image tag of Google Charts map from sorted array of 'country_code' => 'number of visits' (sort by DESC) function yourls_stats_countries_map( $countries ) { - arsort( $countries ); $map = array( 'cht' => 't', 'chs' => '440x220', @@ -16,34 +15,43 @@ function yourls_stats_countries_map( $countries ) { echo ""; } -// Echoes an image tag of Google Charts pie from sorted array of 'country_code' => 'number of visits' (sort by DESC). Optional $limit = (integer) limit list of X first countries, sorted by most visits -function yourls_stats_countries_pie( $countries, $limit = 10 ) { - if ( count( $countries ) > $limit ) { +// Echoes an image tag of Google Charts pie from sorted array of 'data' => 'value' (sort by DESC). Optional $limit = (integer) limit list of X first countries, sorted by most visits +function yourls_stats_pie( $data, $limit = 10, $size = '340x220' ) { + // Trim array: $limit first item + the sum of all others + if ( count( $data ) > $limit ) { $i= 0; - $trim_countries = array('Others' => 0); - foreach( $countries as $country_code=>$visits ) { + $trim_data = array('Others' => 0); + foreach( $data as $item=>$value ) { $i++; if( $i <= $limit ) { - $trim_countries[$country_code] = $visits; + $trim_data[$item] = $value; } else { - $trim_countries['Others'] += $visits; + $trim_data['Others'] += $value; } } - $countries = $trim_countries; + $data = $trim_data; } + + // Scale items (biggest = 100) + $max = max( $data ); + foreach( $data as $k=>$v ) { + $data[$k] = intval( $v / $max * 100 ); + } + + // Hmmm, pie $pie = array( 'cht' => 'p', - 'chs' => '340x220', - 'chd' => 't:'.( join(',' , $countries ) ), + 'chs' => $size, + 'chd' => 't:'.( join(',' , $data ) ), 'chco'=> '202040,9090AA', - 'chl' => join('|' , array_keys( $countries ) ) + 'chl' => join('|' , array_keys( $data ) ) ); $pie_src = 'http://chart.apis.google.com/chart?' . http_build_query( $pie ); echo ""; } // Echoes an image tag of Google Charts bar graph from list of chronologically sorted array of [year][month][day] => 'number of clicks' -function yourls_stats_clicks_bar( $dates ) { +function yourls_stats_clicks_line( $dates ) { /* Say we have an array like: $dates = array ( 2009 => array ( @@ -127,13 +135,13 @@ function yourls_stats_get_best_day( $dates ) { foreach( $days as $day=>$visits ) { if( $visits > $max ) { $max = intval($visits); - $day = "$year-$month-$day"; + $bday = "$year-$month-$day"; } } } } - return array( 'day' => $day, 'max' => $max ); + return array( 'day' => $bday, 'max' => $max ); } diff --git a/js/infos.js b/js/infos.js new file mode 100644 index 0000000..7d6506c --- /dev/null +++ b/js/infos.js @@ -0,0 +1,23 @@ + +$(document).ready(function(){ + $('#tabs ul#headers').css('display', 'block'); + $('.tab h2').css('display','none'); + + $('#tabs ul#headers li a').click(function(){ + var target = $(this).attr('href').replace('#', ''); + $('#tabs div.tab').css('display', 'none'); + $('#tabs div#'+target).css('display', 'block'); + $('#tabs ul#headers li a').removeClass('selected'); + $(this).addClass('selected').css('outline', 'none').blur(); + return false; + }); + + $('#tabs ul#headers li a:first').click(); + + $('a.details').click(function(){ + var target = $(this).attr('id').replace('more_', 'details_'); + $('#'+target).toggle(); + return false; + }); + +}); \ No newline at end of file diff --git a/yourls-infos.php b/yourls-infos.php index 63f5a6c..f2a82bd 100644 --- a/yourls-infos.php +++ b/yourls-infos.php @@ -112,74 +112,130 @@

Long URL:

Number of hits since : hit 1 ? 's' : ''); ?>

-

Traffic statistics

- -

- - -

Best day: hit 1 ? 's' : ''); ?> on . -Click for more details

- - + \ No newline at end of file -- 2.45.0