added production line stop count chart
This commit is contained in:
@@ -79,41 +79,57 @@ class ProductionLineStopChart extends ChartWidget
|
||||
$backgroundColors = [];
|
||||
$borderColors = [];
|
||||
|
||||
function generateColor(string $key, float $opacity): string {
|
||||
// Use a stable hash of the key, no randomness
|
||||
$hash = md5($key);
|
||||
|
||||
// Get the RGB components from the hash
|
||||
$r = hexdec(substr($hash, 0, 2)); // Red component
|
||||
$g = hexdec(substr($hash, 2, 2)); // Green component
|
||||
$b = hexdec(substr($hash, 4, 2)); // Blue component
|
||||
|
||||
// Avoid deep green colors for the `code`
|
||||
if ($g > 150 && $g < 255) {
|
||||
// Adjust green component if it's in the deep green range
|
||||
$g = 150; // Assign a fixed, safe value for green
|
||||
}
|
||||
|
||||
// Return the color as rgba with the specified opacity
|
||||
return "rgba($r, $g, $b, $opacity)";
|
||||
}
|
||||
|
||||
$totalStopMinutes = 0;
|
||||
|
||||
foreach ($query as $row) {
|
||||
// --- STOP TIME (HH.MM format) ---
|
||||
$code = $row->code;
|
||||
$reason = $row->reason;
|
||||
|
||||
$stopHours = $row->total_stop_hours;
|
||||
$stopMinutes = $row->total_stop_minutes;
|
||||
$visualTotal = $stopHours + ($stopMinutes / 100); // e.g., 0.15 (15 mins), 1.30 (1h 30m)
|
||||
$visualTotal = $stopHours + ($stopMinutes / 100);
|
||||
|
||||
// --- RUNTIME (HH.MM format) ---
|
||||
// 1. Convert stop time to total minutes
|
||||
$totalStopMinutes = ($stopHours * 60) + $stopMinutes;// Using 60 for minutes conversion
|
||||
|
||||
// Calculate remaining minutes (1440 = 24 hours)
|
||||
$remainingMinutes = 1440 - $totalStopMinutes;
|
||||
|
||||
// Convert back to "HH.MM" format (e.g., 22.59 = 22 hours 59 minutes)
|
||||
$runtimeHours = floor($remainingMinutes / 60);
|
||||
$runtimeMinutes = $remainingMinutes % 60;
|
||||
$runtime = $runtimeHours + ($runtimeMinutes / 100); // Remaining hours correctly calculated
|
||||
|
||||
// Labels for stop and runtime
|
||||
$stopLabel = $row->code . ' - ' . $row->reason . ' (Stop)';
|
||||
$runtimeLabel = $row->code . ' - ' . $row->reason . ' (Runtime)';
|
||||
|
||||
// Red bar = visual format using stop time
|
||||
$labels[] = $stopLabel;
|
||||
$codeLabel = "$code - $reason";
|
||||
$labels[] = $codeLabel;
|
||||
$data[] = $visualTotal;
|
||||
$backgroundColors[] = 'rgba(255, 99, 132, 0.7)';
|
||||
$borderColors[] = 'rgba(255, 99, 132, 1)';
|
||||
$backgroundColors[] = generateColor($code, 0.7); // Unique color for each stop code
|
||||
$borderColors[] = generateColor($code, 1.0);
|
||||
|
||||
// Green bar = correct runtime math
|
||||
$labels[] = $runtimeLabel;
|
||||
$data[] = $runtime;
|
||||
$backgroundColors[] = 'rgba(75, 192, 75, 0.4)';
|
||||
$borderColors[] = 'rgba(75, 192, 75, 1)';
|
||||
// Accumulate total stop time (in minutes)
|
||||
$totalStopMinutes += ($stopHours * 60) + $stopMinutes;
|
||||
}
|
||||
|
||||
// Calculate remaining time (1440 minutes = 24 hours)
|
||||
$remainingMinutes = 1440 - $totalStopMinutes;
|
||||
$runtimeHours = floor($remainingMinutes / 60);
|
||||
$runtimeMinutes = $remainingMinutes % 60;
|
||||
$runtimeVisual = $runtimeHours + ($runtimeMinutes / 100);
|
||||
|
||||
// Add runtime slice with green color (either light or dark green)
|
||||
$labels[] = 'Available Runtime';
|
||||
$data[] = $runtimeVisual;
|
||||
$backgroundColors[] = 'rgba(47, 218, 47, 0.94)'; // Green for runtime
|
||||
$borderColors[] = 'rgba(75, 192, 75, 1)';
|
||||
|
||||
return [
|
||||
'datasets' => [[
|
||||
'label' => 'Line Stop Durations (hrs)',
|
||||
@@ -126,10 +142,9 @@ class ProductionLineStopChart extends ChartWidget
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
protected function getType(): string
|
||||
{
|
||||
return 'doughnut';
|
||||
return 'pie';
|
||||
}
|
||||
|
||||
protected function getFilters(): ?array
|
||||
@@ -137,8 +152,53 @@ class ProductionLineStopChart extends ChartWidget
|
||||
return [
|
||||
'today' => 'Today',
|
||||
'yesterday' => 'Yesterday',
|
||||
'this_week'=> 'This Week',
|
||||
'this_month'=> 'This Month',
|
||||
];
|
||||
}
|
||||
|
||||
protected function getOptions(): array
|
||||
{
|
||||
return [
|
||||
'responsive' => true,
|
||||
'plugins' => [
|
||||
'legend' => [
|
||||
'position' => 'bottom',
|
||||
],
|
||||
'tooltip' => [
|
||||
'enabled' => true, // Tooltips enabled on hover
|
||||
],
|
||||
],
|
||||
'scales' => [
|
||||
'x' => [
|
||||
'display' => false, // Disable x-axis
|
||||
],
|
||||
'y' => [
|
||||
'display' => false, // Disable y-axis
|
||||
],
|
||||
],
|
||||
'elements' => [
|
||||
'arc' => [
|
||||
'hover' => [
|
||||
'scale' => 1.1, // Increase the slice size by 10% on hover
|
||||
'borderWidth' => 3, // Optionally increase border width on hover
|
||||
'offset' => 10, // Make the slice move outside of the pie chart on hover
|
||||
],
|
||||
// This ensures that animation and hover effects work as expected
|
||||
'animation' => [
|
||||
'duration' => 500, // Duration for the hover animation (smooth pop)
|
||||
'easing' => 'easeOutQuad', // Smooth easing for pop-up effect
|
||||
],
|
||||
],
|
||||
],
|
||||
'hover' => [
|
||||
'mode' => 'nearest', // Hover mode: nearest slice
|
||||
'intersect' => true, // Only trigger hover if intersecting a slice
|
||||
'animationDuration' => 500, // Duration of hover animation
|
||||
],
|
||||
'animation' => [
|
||||
'duration' => 1000, // Overall animation duration
|
||||
'easing' => 'easeInOutQuart', // Easing function for smooth transition
|
||||
],
|
||||
'maintainAspectRatio' => false,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user