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

Area   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A registerAsset() 0 13 1
A getClientOptions() 0 9 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 Area
10
 *
11
 * @package backend\widgets\chart\morris
12
 */
13
class Area extends Base
14
{
15
    /**
16
     * Client Options
17
     *
18
     * @return array
19
     */
20
    public function getClientOptions()
21
    {
22
        $clientOptions = ArrayHelper::merge(parent::getClientOptions(), [
23
            'xkey' => 'y',
24
            'ykeys' => [],
25
            'labels' => [],
26
            'lineColors' => [],
27
        ]);
28
        return ArrayHelper::merge($clientOptions, $this->clientOptions);
29
    }
30
31
    /**
32
     * Register Asset
33
     */
34
    public function registerAsset()
35
    {
36
        parent::registerAsset();
37
        $view = $this->getView();
38
        $clientOptions = Json::encode($this->getClientOptions());
39
        $script = "
40
            let morris_area_{$this->id} = new Morris.Area({$clientOptions});
41
            // Fix for charts under tabs
42
            $('ul.nav a').on('shown.bs.tab', function () {
43
                morris_area_{$this->id}.redraw();
44
            });
45
         ";
46
        $view->registerJs($script);
47
    }
48
}
49