Skip to content

Commit a67972f

Browse files
committed
Fix overlib graph popup layout
1 parent 3dc8638 commit a67972f

1 file changed

Lines changed: 12 additions & 16 deletions

File tree

LibreNMS/Util/Url.php

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
use App\Models\Device;
3131
use App\Models\Port;
3232
use Carbon\Carbon;
33-
use Carbon\CarbonImmutable;
3433
use Illuminate\Support\Facades\Gate;
3534
use Illuminate\Support\Facades\URL as LaravelUrl;
3635
use Illuminate\Support\Str;
@@ -406,34 +405,31 @@ public static function graphTag($args)
406405
return '<img class="graph-image" src="' . url('graph.php') . '?' . implode('&amp;', $urlargs) . '" style="border:0;" />';
407406
}
408407

409-
public static function graphPopup($args, $content = null, $link = null)
408+
public static function graphPopup($args, $content = null, $link = null, array $graph_periods = ['-1d', '-1w', '-1mo', '-1y']): string
410409
{
411410
// Take $args and print day,week,month,year graphs in overlib, hovered over graph
412411
$original_from = $args['from'] ?? '';
413412
$popup_title = $args['popup_title'] ?? 'Graph';
414-
$now = CarbonImmutable::now();
415413

416-
$graph = $content ?: self::graphTag($args);
417-
$popup = "<div class=\'list-large\'>$popup_title</div>";
418-
$popup .= '<div style="width: 850px">';
419414
$args['width'] = 340;
420415
$args['height'] = 100;
421416
$args['legend'] = 'yes';
422-
$args['from'] = $now->subDay()->timestamp;
423-
$popup .= self::graphTag($args);
424-
$args['from'] = $now->subWeek()->timestamp;
425-
$popup .= self::graphTag($args);
426-
$args['from'] = $now->subMonth()->timestamp;
427-
$popup .= self::graphTag($args);
428-
$args['from'] = $now->subYear()->timestamp;
429-
$popup .= self::graphTag($args);
417+
$columns = count($graph_periods) < 4 ? 1 : 2;
418+
419+
$graph = $content ?: self::graphTag($args);
420+
$popup = "<div class=\'list-large\'>$popup_title</div>";
421+
$popup .= "<div style=\"display:grid;grid-template-columns:repeat($columns,max-content);\">";
422+
foreach ($graph_periods as $period) {
423+
$args['from'] = $period;
424+
$popup .= ' ' . self::graphTag($args);
425+
}
430426
$popup .= '</div>';
431427

432428
$args['from'] = $original_from;
433429

434430
$args['link'] = $link ?: self::generate($args, ['page' => 'graphs', 'height' => null, 'width' => null, 'bg' => null]);
435431

436-
return self::overlibLink($args['link'], $graph, $popup, null);
432+
return self::overlibLink($args['link'], $graph, $popup);
437433
}
438434

439435
public static function lazyGraphTag($args, string $class = 'img-responsive'): string
@@ -453,7 +449,7 @@ public static function lazyGraphTag($args, string $class = 'img-responsive'): st
453449
return $tag . ' />';
454450
}
455451

456-
public static function overlibLink($url, $text, $contents, $class = null)
452+
public static function overlibLink($url, $text, $contents, $class = null): string
457453
{
458454
$contents = "<div class=\'overlib-contents\'>" . $contents . '</div>';
459455
$contents = str_replace('"', "\'", $contents);

0 commit comments

Comments
 (0)