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

Bar::getClientOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 6
c 1
b 0
f 1
dl 0
loc 9
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 Bar
10
 *
11
 * @package backend\widgets\chart\morris
12
 */
13
class Bar extends Base
14
{
15
    /**
16
     * Client Options
17
     *
18
     * @return array
19
     */
20
    public function getClientOptions()
21
    {
22
        $clientOptions = ArrayHelper::merge(parent::getClientOptions(), [
23
            'barColors' => [],
24
            'xkey' => 'y',
25
            'ykeys' => [],
26
            'labels' => [],
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_bar_{$this->id} = new Morris.Bar({$clientOptions});
41
            // Fix for charts under tabs
42
            $('ul.nav a').on('shown.bs.tab', function () {
43
                morris_bar_{$this->id}.redraw();
44
            });
45
         ";
46
        $view->registerJs($script);
47
    }
48
}
49