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 7
7
"types" : " dist/controller.d.ts" ,
8
8
"symfony" : {
9
9
"controllers" : {
10
- "chart" : {
11
- "main" : " dist/controller.js" ,
10
+ "chart_v3" : {
11
+ "main" : " dist/chart_v3_controller.js" ,
12
+ "name" : " symfony--ux-chartjs--chart" ,
12
13
"webpackMode" : " eager" ,
13
14
"fetch" : " eager" ,
14
15
"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
15
23
}
16
24
}
17
25
},
Original file line number Diff line number Diff line change 10
10
'use strict' ;
11
11
12
12
import { Controller } from '@hotwired/stimulus' ;
13
- import Chart from 'chart.js/auto' ;
14
13
15
- export default class extends Controller {
14
+ export default abstract class AbstractChartController extends Controller {
16
15
declare readonly viewValue : any ;
17
16
18
17
static values = {
@@ -35,12 +34,17 @@ export default class extends Controller {
35
34
if ( ! canvasContext ) {
36
35
throw new Error ( 'Could not getContext() from Element' ) ;
37
36
}
38
- const chart = new Chart ( canvasContext , payload ) ;
37
+ const chart = this . createChart ( canvasContext , payload ) ;
39
38
40
39
this . _dispatchEvent ( 'chartjs:connect' , { chart } ) ;
41
40
}
42
41
43
42
_dispatchEvent ( name : string , payload : any ) {
44
43
this . element . dispatchEvent ( new CustomEvent ( name , { detail : payload } ) ) ;
45
44
}
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 ;
46
50
}
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