Created
February 8, 2021 14:04
-
-
Save wpmu-authors/b9ab3a82e64a5ac4e4f40c489491be7e to your computer and use it in GitHub Desktop.
graph.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function dashboard_widget_display_enqueues( $hook ) { | |
if( 'index.php' != $hook ) { | |
return; | |
} | |
wp_enqueue_style( 'dashboard-widget-styles', plugins_url( '', __FILE__ ) . '/widgets.css' ); | |
} | |
add_action( 'admin_enqueue_scripts', 'dashboard_widget_display_enqueues' ); | |
function register_comment_stats_dashboard_widget() { | |
wp_add_dashboard_widget( | |
'comment_stats_widget', | |
'Comment Stats', | |
'comment_stats_dashboard_widget_display' | |
); | |
} | |
add_action( 'wp_dashboard_setup', 'register_comment_stats_dashboard_widget' ); | |
function comment_stats_dashboard_widget_display() { | |
$comment_counts = array( 20, 29, 39, 33, 17 ); | |
$highest_value = max( $comment_counts ); | |
$data_points = count( $comment_counts ); | |
$bar_width = 100 / $data_points - 2; | |
$total_height = 120; | |
?>; | |
<div class="comment-stat-bars" style="height:<?php echo $total_height ?>px;"> | |
<?php | |
foreach( $comment_counts as $count ) : | |
$count_percentage = $count/$highest_value; | |
$bar_height = $total_height * $count_percentage; | |
$border_width = $total_height - $bar_height; | |
?> | |
<div class="comment-stat-bar" style="height:<?php echo $total_height ?>px; border-top-width:<?php echo $border_width ?>px; width: <?php echo $bar_width ?>%;"></div> | |
<?php endforeach ?> | |
</div> | |
<div class='comment-stat-labels'> | |
<?php foreach( $comment_counts as $count ) : ?> | |
<div class='comment-stat-label' style='width: <?php echo $bar_width ?>%;'><?php echo $count ?></div> | |
<?php endforeach ?> | |
</div> | |
<div class='comment-stat-caption'>Comments in the past 5 weeks</div> | |
<?php | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment