Skip to content

Commit

Permalink
feat: include chartjs script in asset bundle via cdn
Browse files Browse the repository at this point in the history
limited to chartjs 3.9.1 as 4.0 is an esm-only package

Refs: #25
  • Loading branch information
gwynbox committed Aug 30, 2024
1 parent b3c35ae commit a2629fd
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/assets/ChartjsAsset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

namespace practically\chartjs\assets;

use Yii;
use yii\helpers\Url;
use yii\web\AssetBundle;
use yii\web\View;

/**
* @copyright 2024 Practically.io. All rights reserved
*/
class ChartjsAsset extends AssetBundle
{

/**
* @var array
*/
public $js = [
'https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.9.1/chart.min.js',
];

/**
* @var array
*/
public $depends = [
'yii\web\YiiAsset',
];

}
3 changes: 3 additions & 0 deletions src/widget/Chart.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace practically\chartjs\widget;

use practically\chartjs\assets\ChartjsAsset;
use practically\chartjs\components\Dataset;
use practically\chartjs\components\ScatterDataset;
use Yii;
Expand Down Expand Up @@ -121,6 +122,8 @@ public function init(): void
$this->jsVar = $this->id;
}

ChartjsAsset::register($this->view);

parent::init();
}

Expand Down

0 comments on commit a2629fd

Please sign in to comment.