File tree Expand file tree Collapse file tree 4 files changed +57
-5
lines changed Expand file tree Collapse file tree 4 files changed +57
-5
lines changed Original file line number Diff line number Diff line change 77 "types" : " dist/controller.d.ts" ,
88 "symfony" : {
99 "controllers" : {
10- "chart" : {
11- "main" : " dist/controller.js" ,
10+ "chart_v3" : {
11+ "main" : " dist/chart_v3_controller.js" ,
12+ "name" : " symfony--ux-chartjs--chart" ,
1213 "webpackMode" : " eager" ,
1314 "fetch" : " eager" ,
1415 "enabled" : true
16+ },
17+ "chart_v4" : {
18+ "main" : " dist/chart_v4_controller.js" ,
19+ "name" : " symfony--ux-chartjs--chart" ,
20+ "webpackMode" : " eager" ,
21+ "fetch" : " eager" ,
22+ "enabled" : false
1523 }
1624 }
1725 },
Original file line number Diff line number Diff line change 1010'use strict' ;
1111
1212import { Controller } from '@hotwired/stimulus' ;
13- import Chart from 'chart.js/auto' ;
1413
15- export default class extends Controller {
14+ export default abstract class AbstractChartController extends Controller {
1615 declare readonly viewValue : any ;
1716
1817 static values = {
@@ -35,12 +34,17 @@ export default class extends Controller {
3534 if ( ! canvasContext ) {
3635 throw new Error ( 'Could not getContext() from Element' ) ;
3736 }
38- const chart = new Chart ( canvasContext , payload ) ;
37+ const chart = this . createChart ( canvasContext , payload ) ;
3938
4039 this . _dispatchEvent ( 'chartjs:connect' , { chart } ) ;
4140 }
4241
4342 _dispatchEvent ( name : string , payload : any ) {
4443 this . element . dispatchEvent ( new CustomEvent ( name , { detail : payload } ) ) ;
4544 }
45+
46+ /**
47+ * To support v3 and v4 of chart.js this help function is added, could be refactored when support for v3 is dropped
48+ */
49+ abstract createChart ( canvasContext : any , payload : any ) : any ;
4650}
Original file line number Diff line number Diff line change 1+ /*
2+ * This file is part of the Symfony package.
3+ *
4+ * (c) Fabien Potencier <[email protected] > 5+ *
6+ * For the full copyright and license information, please view the LICENSE
7+ * file that was distributed with this source code.
8+ */
9+
10+ 'use strict' ;
11+
12+ import AbstractChartController from './abstract_controller' ;
13+ import Chart from 'chart.js/auto' ;
14+ import { ChartConfiguration , ChartItem } from 'chart.js' ;
15+
16+ export default class extends AbstractChartController {
17+ createChart ( canvasContext : ChartItem , payload : ChartConfiguration ) : any {
18+ return new Chart ( canvasContext , payload ) ;
19+ }
20+ }
Original file line number Diff line number Diff line change 1+ /*
2+ * This file is part of the Symfony package.
3+ *
4+ * (c) Fabien Potencier <[email protected] > 5+ *
6+ * For the full copyright and license information, please view the LICENSE
7+ * file that was distributed with this source code.
8+ */
9+
10+ 'use strict' ;
11+
12+ import AbstractChartController from './abstract_controller' ;
13+ import Chart from 'chart.js/auto' ;
14+ import { ChartConfiguration , ChartItem } from 'chart.js' ;
15+
16+ export default class extends AbstractChartController {
17+ createChart ( canvasContext : ChartItem , payload : ChartConfiguration ) : any {
18+ return new Chart ( canvasContext , payload ) ;
19+ }
20+ }
You can’t perform that action at this time.
0 commit comments