Donut   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 2
eloc 11
c 1
b 0
f 1
dl 0
loc 31
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getClientOptions() 0 6 1
A registerAsset() 0 13 1
1
<?php
2
3
namespace backend\widgets\chart\morris;
4
5
use yii\helpers\ArrayHelper;
6
use yii\helpers\Json;
7
8
/**
9
 * Class Donut
10
 *
11
 * @package backend\widgets\chart\morris
12
 */
13
class Donut extends Base
14
{
15
    /**
16
     * Client Options
17
     *
18
     * @return array
19
     */
20
    public function getClientOptions()
21
    {
22
        $clientOptions = ArrayHelper::merge(parent::getClientOptions(), [
23
            'colors' => [],
24
        ]);
25
        return ArrayHelper::merge($clientOptions, $this->clientOptions);
26
    }
27
28
    /**
29
     * Register Asset
30
     */
31
    public function registerAsset()
32
    {
33
        parent::registerAsset();
34
        $view = $this->getView();
35
        $clientOptions = Json::encode($this->getClientOptions());
36
        $script = "
37
            let morris_donut_{$this->id} = new Morris.Donut({$clientOptions});
38
            // Fix for charts under tabs
39
            $('a[data-toggle=tab').on('shown.bs.tab', function () {
40
                morris_donut_{$this->id}.redraw();
41
            });
42
         ";
43
        $view->registerJs($script);
44
    }
45
}
46