$days Date to totals, oldest first. * @return void */ public static function render( array $days ): void { $max = 0; foreach ( $days as $day ) { $max = max( $max, $day['saved'] ); } if ( 0 === $max ) { echo '

' . esc_html__( 'No space was saved in the last 30 days.', 'pixelkeep' ) . '

'; return; } $scale = self::nice_ceiling( $max ); $plot_h = self::HEIGHT - self::TOP - self::BOTTOM; $plot_w = self::WIDTH - self::LEFT; $slot = $plot_w / max( 1, count( $days ) ); $base = self::TOP + $plot_h; $total = array_sum( array_column( $days, 'saved' ) ); ?>
$day ) : $x = self::LEFT + $index * $slot; $label = self::date_label( (string) $date ); $tip = sprintf( /* translators: 1: Date, 2: Size, 3: Number of images. */ _n( '%1$s: %2$s saved on %3$d image', '%1$s: %2$s saved on %3$d images', $day['images'], 'pixelkeep' ), $label, Format::bytes( $day['saved'] ), $day['images'] ); ?> 0 ) : ?>
$day ) : ?> 0 ) : ?>

= $unit * 1024 ) { $unit *= 1024; } $scaled = max( 1, $value ) / $unit; $magnitude = 10 ** (int) floor( log10( $scaled ) ); foreach ( array( 1, 2, 5, 10 ) as $step ) { if ( $step * $magnitude >= $scaled ) { return (int) ( $step * $magnitude * $unit ); } } return $value; } /** * Formats a date for the axis. * * @param string $date Y-m-d. * @return string */ private static function date_label( string $date ): string { return (string) wp_date( 'M j', (int) strtotime( $date . ' 12:00:00 UTC' ) ); } /** * Builds a bar with rounded top corners, anchored to the baseline. * * @param float $x Left edge. * @param float $width Width. * @param float $base Baseline. * @param float $height Height. * @return string */ private static function bar_path( float $x, float $width, float $base, float $height ): string { $r = min( 4, $width / 2, $height ); $t = $base - $height; return sprintf( 'M%1$.2f %2$.2f V%3$.2f Q%1$.2f %4$.2f %5$.2f %4$.2f H%6$.2f Q%7$.2f %4$.2f %7$.2f %3$.2f V%2$.2f Z', $x, $base, $t + $r, $t, $x + $r, $x + $width - $r, $x + $width ); } }