Changeset 3384
- Timestamp:
- 06/16/2016 11:03:59 AM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/js/stats.js
r3221 r3384 53 53 } 54 54 55 var bar_headers = [], 56 bar_values = [], 57 version_list = [], 58 to_combine = [], 59 older_versions = 0, 60 combine_limit = 6, 61 combine_percentage = 1, 62 version, 63 index, 64 bar_table_versions, 65 formatter; 66 67 // Start of the Google Datatable requirements. 68 bar_headers.push( '' ); 69 bar_values.push( '' ); 55 var barHeaders = [ '' ], 56 barValues = [ '' ], 57 versionList = [], 58 index = 0, 59 version, data, formatter; 70 60 71 61 // Gather and sort the list of versions. 72 for ( version in versions) {73 version _list.push( version );74 } 62 $.each( versions, function( version ) { 63 versionList.push( version ); 64 } ); 75 65 76 66 // Sort the version list by version. 77 version _list.sort( function( a, b ) {67 versionList.sort( function( a, b ) { 78 68 a = a.split( '.' ); 79 69 b = b.split( '.' ); … … 81 71 } ); 82 72 83 // Move any versions (old or new) with < combine_percentage into the combined list. 84 for ( index in version_list ) { 85 version = version_list[ index ]; 86 if ( versions[ version ] <= combine_percentage ) { 87 to_combine.push( version ); 88 } 89 } 90 91 // If a plugin has more than 6 versions, combine the older ones into a "Older Versions" group. 92 if ( version_list.length > combine_limit ) { 93 for ( index in version_list ) { 94 version = version_list[ index ]; 95 if ( ( version_list.length - to_combine.length ) <= combine_limit ) { 96 break; 97 } 98 if ( to_combine.indexOf( version ) > -1 ) { 99 continue; // Next. 100 } 101 to_combine.push( version ); 102 } 103 } 104 105 // Only combine when there's multiples in there 106 if ( to_combine.length > 1 ) { 107 to_combine.forEach( function( version ) { 108 older_versions += versions[ version ]; 109 110 delete versions[ version ]; 111 delete version_list[ version_list.indexOf( version ) ]; 112 } ); 113 } 114 115 if ( older_versions ) { 116 bar_headers.push( settings.l10n.otherVersions ); 117 bar_values.push( Math.round( older_versions * 100 ) / 100 ); 118 } 73 // Move 'other' versions to the beginning. 74 versionList.unshift( versionList.pop() ); 119 75 120 76 // Add all the versions 121 version _list.forEach( function( version ) {122 bar _headers.push( version );123 bar _values.push( versions[ version ] );77 versionList.forEach( function( version ) { 78 barHeaders.push( version ); 79 barValues.push( versions[ version ] ); 124 80 } ); 125 81 126 bar_headers.push( { role: 'annotation' } ); 127 bar_values.push( '' ); 128 129 bar_table_versions = google.visualization.arrayToDataTable([ 130 bar_headers, 131 bar_values 82 data = google.visualization.arrayToDataTable([ 83 barHeaders, 84 barValues 132 85 ]); 133 86 134 87 // Format it as percentages 135 formatter = new google.visualization.NumberFormat( {88 formatter = new google.visualization.NumberFormat( { 136 89 fractionDigits: 1, 137 90 suffix: '%' 138 });139 140 index = 0;141 bar_values.forEach( function( value ) {142 if ( bar_values[ value ] ) {143 formatter.format( bar_table_versions, index );144 }145 index++;146 91 } ); 147 92 148 new google.visualization.BarChart( document.getElementById( 'plugin-version-stats' ) ).draw( bar_table_versions, { 93 $.each( barValues, function( value ) { 94 if ( barValues[ value ] ) { 95 formatter.format( data, ++index ); 96 } 97 } ); 98 99 new google.visualization.BarChart( document.getElementById( 'plugin-version-stats' ) ).draw( data, { 149 100 legend: { 150 101 position: 'bottom'
Note: See TracChangeset
for help on using the changeset viewer.