Skip to content

Commit a76d0a3

Browse files
Refactored savings percentage calculation.
1 parent a715352 commit a76d0a3

3 files changed

Lines changed: 8 additions & 14 deletions

File tree

src/class-tiny-image.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,12 @@ public static function get_optimization_statistics( $settings, $result = null )
452452
);
453453
}
454454
}
455+
456+
if ( 0 != $stats['unoptimized-library-size'] ) {
457+
$stats['display-percentage'] = round( 100 - ( $stats['optimized-library-size'] / $stats['unoptimized-library-size'] * 100 ), 1 );
458+
} else {
459+
$stats['display-percentage'] = 0;
460+
}
455461
return $stats;
456462
}
457463

src/js/dashboard-widget.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252

5353
function renderWidget(data, container) {
5454
var stats = jQuery.parseJSON(data);
55-
var savings = savingsPercentage(stats);
55+
var savings = stats['display-percentage'];
5656
var libraryOptimized = optimizedPercentage(stats);
5757
renderContent(libraryOptimized, stats, savings);
5858
renderChart(savings);
@@ -98,14 +98,6 @@
9898
}
9999
}
100100

101-
function savingsPercentage(stats) {
102-
if ( 0 != stats['unoptimized-library-size'] ) {
103-
return 100 - Math.round((stats['optimized-library-size'] / stats['unoptimized-library-size'] * 1000))/ 10;
104-
} else {
105-
return 0
106-
}
107-
}
108-
109101
function renderChart(savingsPercentage) {
110102
chart = chartOptions(savingsPercentage);
111103
jQuery('#optimization-chart svg circle.main').css('stroke-dasharray', chart['dash-array-size'] + ' ' + chart['circle-size'])

src/views/bulk-optimization-chart.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@
33
$chart = array();
44

55
if ( isset( $stats ) ) {
6-
if ( 0 != $stats['unoptimized-library-size'] ) {
7-
$chart['percentage'] = round( 100 - ( $stats['optimized-library-size'] / $stats['unoptimized-library-size'] * 100 ), 1 );
8-
} else {
9-
$chart['percentage'] = 0;
10-
}
6+
$chart['percentage'] = $stats['display-percentage'];
117
} else {
128
$chart['percentage'] = 0;
139
};

0 commit comments

Comments
 (0)