Spamworldpro Mini Shell
Spamworldpro


Server : Apache
System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64
User : corals ( 1002)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/corals/dceprojects.corals.io/Corals/modules/Timesheet/Widgets/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/dceprojects.corals.io/Corals/modules/Timesheet/Widgets/BasePieChart.php
<?php

namespace Corals\Modules\Timesheet\Widgets;

use ConsoleTVs\Charts\Classes\Chartjs\Chart;

abstract class BasePieChart extends Chart
{
    protected static string $defaultLegendPosition = 'down';

    public function __construct()
    {
        parent::__construct();

        $this->type('pie');
    }

    protected $colors = [
        '#a6cee3',
        '#8dd3c7',
        '#1f78b4',
        '#ffffb3',
        '#b2df8a',
        '#bebada',
        '#33a02c',
        '#fb8072',
        '#fb9a99',
        '#80b1d3',
        '#e31a1c',
        '#fdb462',
        '#fdbf6f',
        '#b3de69',
        '#ff7f00',
        '#fccde5',
        '#cab2d6',
        '#d9d9d9',
        '#6a3d9a',
        '#bc80bd',
        '#ffff99',
        '#ccebc5',
        '#b15928',
        '#ffed6f',

        '#8c510a',
        '#b2182b',
        '#3288bd',
        '#bf812d',
        '#d6604d',
        '#66c2a5',
        '#dfc27d',
        '#f4a582',
        '#abdda4',
        '#f6e8c3',
        '#fddbc7',
        '#e6f598',
        '#f5f5f5',
        '#ffffff',
        '#ffffbf',
        '#c7eae5',
        '#e0e0e0',
        '#fee08b',
        '#80cdc1',
        '#bababa',
        '#fdae61',
        '#35978f',
        '#878787',
        '#f46d43',
        '#01665e',
        '#4d4d4d',
        '#d53e4f',
    ];

    protected function generateRandomColors($length)
    {
        for ($i = 0; $i < $length; $i++) {
            if (isset($this->colors[$i])) {
                $this->customGeneratedColors[] = $this->colors[$i];
            } else {
                $this->customGeneratedColors[] = '#' . str_pad(dechex(mt_rand(0, 0xFFFFFF)), 6, '0', STR_PAD_LEFT);
            }
        }

        return $this->customGeneratedColors;
    }

    public function setData(array $labels, array $data)
    {
        return $this->labels($labels)->dataset('', 'pie', $data);
    }

    protected function generateCustomLegend(array $labels, array $data, $legend = 'right')
    {
        $legendHtml = '<ul class="list-unstyled">';

        foreach ($labels as $index => $label) {
            if (!$data[$index]) {
                continue;
            }
            $legendHtml .= '<li class="d-flex align-items-center mb-2">';
            $legendHtml .= '<span class="d-inline-block" style="background-color: ' . $this->colors[$index] . '; width: 15px; height: 15px; margin-right: 10px;"></span>';
            $legendHtml .= $label . ': ' . \Timesheet::getLoggedTimeInHMFormat($data[$index], 0) . ' hours';
            $legendHtml .= '</li>';
        }

        $legendHtml .= '</ul>';

        return $legendHtml;
    }

    protected function wrapChartWithLegend($chartHtml, $legendHtml, $legendPosition)
    {
        $containerHtml = '<div class="row">';

        switch ($legendPosition) {
            case 'left':
                $containerHtml .= '<div class="col-md-6">' . $legendHtml . '</div>';
                $containerHtml .= '<div class="col-md-6">' . $chartHtml . '</div>';
                break;
            case 'right':
                $containerHtml .= '<div class="col-md-6">' . $chartHtml . '</div>';
                $containerHtml .= '<div class="col-md-6">' . $legendHtml . '</div>';
                break;
            case 'top':
                $containerHtml .= '<div class="col-md-12">' . $legendHtml . '</div>';
                $containerHtml .= '<div class="col-md-12">' . $chartHtml . '</div>';
                break;
            default:
                $containerHtml .= '<div class="col-md-12">' . $chartHtml . '</div>';
                $containerHtml .= '<div class="col-md-12">' . $legendHtml . '</div>';
                break;
        }

        $containerHtml .= '</div>';

        return $containerHtml;
    }
}

Spamworldpro Mini