Passed
Push — master ( a3074c...38e910 )
by Alexey
02:36
created

Donut::getClientOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 3
c 1
b 0
f 1
dl 0
loc 6
rs 10
cc 1
nc 1
nop 0
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
            $('ul.nav a').on('shown.bs.tab', function () {
40
                morris_donut_{$this->id}.redraw();
41
            });
42
         ";
43
        $view->registerJs($script);
44
    }
45
}
46