1
-
2
1
import { useState , useEffect , useRef , useContext } from "react" ;
3
2
// import { Chart } from 'chart.js';
4
3
import { applyZoom , getZoomedBoudingClientRect } from "../../../utils/zoom" ;
5
4
6
-
7
5
import "./Charts.css" ;
8
6
import DropDownMenu from "../../generic/UserInputs/DropDownMenu" ;
9
7
10
-
11
8
import { AppContext } from "../../../App" ;
12
9
13
10
export default function Charts ( { selectedPeriod } ) {
@@ -18,8 +15,12 @@ export default function Charts({ selectedPeriod }) {
18
15
* 2: Subjects average | radar
19
16
*/
20
17
21
- // States
22
- const [ chartType , setChartType ] = useState ( 0 ) ;
18
+ // States
19
+
20
+ const { useUserSettings } = useContext ( AppContext ) ;
21
+
22
+ const settings = useUserSettings ( )
23
+ const [ selectedChart , setSelectedChart ] = useState ( settings . get ( "selectedChart" ) ) ;
23
24
24
25
const chartContainerRef = useRef ( null ) ;
25
26
const canvasContainerRef = useRef ( null ) ;
@@ -40,7 +41,6 @@ export default function Charts({ selectedPeriod }) {
40
41
}
41
42
42
43
useEffect ( ( ) => {
43
-
44
44
window . addEventListener ( "resize" , resizeChart ) ;
45
45
resizeChart ( ) ;
46
46
@@ -49,16 +49,15 @@ export default function Charts({ selectedPeriod }) {
49
49
}
50
50
} , [ ] )
51
51
52
-
53
52
function getChartData ( ) {
54
53
/**
55
- * return the appropriate dataset according to the chartType
54
+ * return the appropriate dataset according to the selectedChart
56
55
*/
57
56
const userData = useUserData ( ) ;
58
57
const minMaxEnabled = userData . get ( "gradesEnabledFeatures" ) ?. moyenneMin && userData . get ( "gradesEnabledFeatures" ) ?. moyenneMax ;
59
58
60
59
61
- switch ( chartType ) {
60
+ switch ( selectedChart ) {
62
61
case 0 :
63
62
// General average + streak history | line
64
63
chartOptions . current = {
@@ -71,17 +70,17 @@ export default function Charts({ selectedPeriod }) {
71
70
suggestedMax : 20
72
71
} ,
73
72
// y1: {
74
- // type: 'linear',
75
- // display: true,
76
- // position: 'right',
77
- // suggestedMax: 20
73
+ // type: 'linear',
74
+ // display: true,
75
+ // position: 'right',
76
+ // suggestedMax: 20
78
77
// }
79
78
// xAxes: [{
80
- // type: 'time',
81
- // ticks: {
82
- // autoSkip: true,
83
- // maxTicksLimit: 20
84
- // }
79
+ // type: 'time',
80
+ // ticks: {
81
+ // autoSkip: true,
82
+ // maxTicksLimit: 20
83
+ // }
85
84
// }]
86
85
} ,
87
86
interaction : {
@@ -179,24 +178,24 @@ export default function Charts({ selectedPeriod }) {
179
178
order : 1 ,
180
179
} ,
181
180
// {
182
- // type: "line",
183
- // label: "Moyennes max classe",
184
- // data: subjectsComparativeInformation[selectedPeriod].map((subject) => subject.maxAverage),
185
- // borderColor: 'rgb(53, 162, 235)',
186
- // backgroundColor: 'rgba(53, 162, 235, 0.5)',
187
- // tension: 0.2,
188
- // // yAxisID: "y1"
189
- // order: 2,
181
+ // type: "line",
182
+ // label: "Moyennes max classe",
183
+ // data: subjectsComparativeInformation[selectedPeriod].map((subject) => subject.maxAverage),
184
+ // borderColor: 'rgb(53, 162, 235)',
185
+ // backgroundColor: 'rgba(53, 162, 235, 0.5)',
186
+ // tension: 0.2,
187
+ // // yAxisID: "y1"
188
+ // order: 2,
190
189
// },
191
190
// {
192
- // type: "line",
193
- // label: "Moyennes min classe",
194
- // data: subjectsComparativeInformation[selectedPeriod].map((subject) => subject.minAverage),
195
- // borderColor: 'rgb(53, 162, 235)',
196
- // backgroundColor: 'rgba(53, 162, 235, 0.5)',
197
- // tension: 0.2,
198
- // // yAxisID: "y1"
199
- // order: 3,
191
+ // type: "line",
192
+ // label: "Moyennes min classe",
193
+ // data: subjectsComparativeInformation[selectedPeriod].map((subject) => subject.minAverage),
194
+ // borderColor: 'rgb(53, 162, 235)',
195
+ // backgroundColor: 'rgba(53, 162, 235, 0.5)',
196
+ // tension: 0.2,
197
+ // // yAxisID: "y1"
198
+ // order: 3,
200
199
// },
201
200
] ,
202
201
} ;
@@ -214,7 +213,7 @@ export default function Charts({ selectedPeriod }) {
214
213
beginAtZero : true ,
215
214
suggestedMax : 20 ,
216
215
grid : {
217
- color : actualDisplayTheme == "dark" ? "rgba(180, 180, 240, .4)" : "rgba(76, 76, 184, .4)"
216
+ color : actualDisplayTheme == "dark" ? "rgba(180, 180, 240, .4)" : "rgba(76, 76, 184, .4)"
218
217
}
219
218
}
220
219
} ,
@@ -308,9 +307,9 @@ export default function Charts({ selectedPeriod }) {
308
307
}
309
308
310
309
useEffect ( ( ) => {
311
- console . log ( chartType ) ;
312
310
refreshChart ( ) ;
313
- } , [ chartType , activeAccount , selectedPeriod ] ) ;
311
+ useUserSettings ( "selectedChart" ) . set ( selectedChart ) ;
312
+ } , [ selectedChart , activeAccount , selectedPeriod ] ) ;
314
313
315
314
useEffect ( ( ) => {
316
315
const script = document . createElement ( "script" ) ;
@@ -330,7 +329,15 @@ export default function Charts({ selectedPeriod }) {
330
329
return (
331
330
< div id = "charts" >
332
331
< div className = "top-container" >
333
- < DropDownMenu name = "chart-type" options = { [ 0 , 1 , 2 ] } displayedOptions = { [ "Moyenne générale Courbe" , "Moyennes par matière Barres" , "Moyennes par matière Radar" ] } selected = { chartType } onChange = { ( value ) => setChartType ( parseInt ( value ) ) } />
332
+ < DropDownMenu
333
+ name = "chart-type"
334
+ options = { [ 0 , 1 , 2 ] }
335
+ displayedOptions = { [ "Moyenne générale Courbe" , "Moyennes par matière Barres" , "Moyennes par matière Radar" ] }
336
+ selected = { selectedChart }
337
+ onChange = { ( value ) => {
338
+ setSelectedChart ( parseInt ( value ) ) ;
339
+ } }
340
+ />
334
341
< h3 > Graphiques</ h3 >
335
342
< div className = "artificial-horizontal-center" > </ div >
336
343
</ div >
0 commit comments