@@ -36,24 +36,28 @@ import {
36
36
learningProfileRadarChartPropTypes
37
37
} from './types' ;
38
38
39
- // TICK_POSITIONS
39
+ /* TICK_POSITIONS */
40
40
const top : TickType = { offset : { x : - 100 , y : - 65 } , alignment : 'center' , margin : 'auto' } ;
41
41
const bottom : TickType = { offset : { x : - 100 , y : 10 } , alignment : 'center' , margin : 'auto' } ;
42
42
const right : TickType = { offset : { x : 30 , y : - 10 } , alignment : 'start' , marginRight : 'auto' } ;
43
43
const left : TickType = { offset : { x : - 230 , y : - 10 } , alignment : 'end' , marginLeft : 'auto' } ;
44
44
45
- // CONSTANTS
45
+ /* CONSTANTS */
46
+ const BLACK = '#000000ff' ;
47
+ const WHITE = '#ffffffff' ;
48
+ const DEFAULT_MAIN_COLOR = '#0062ffff' ;
49
+
46
50
const DEFAULT_COLORS : FormatedColorsType = {
47
51
gradient : {
48
- fill : [ '#0062ffff' , '#0062ffff' ] ,
49
- stroke : [ '#0062ffff' , '#0062ffff ' ]
52
+ fill : [ DEFAULT_MAIN_COLOR , DEFAULT_MAIN_COLOR ] ,
53
+ stroke : [ DEFAULT_MAIN_COLOR , DEFAULT_MAIN_COLOR ]
50
54
} ,
51
55
percentage : {
52
- color : '#000000ff' ,
53
- background : '#ffffff'
56
+ color : BLACK ,
57
+ background : WHITE
54
58
} ,
55
59
label : {
56
- color : '#000000ff'
60
+ color : BLACK
57
61
}
58
62
} ;
59
63
@@ -80,7 +84,7 @@ const CHART_CONFIGS = {
80
84
}
81
85
} as const ;
82
86
83
- const CUSTOM_DOT_DEFAULT_PROPS = {
87
+ const DOT_DEFAULT_PROPS = {
84
88
strokeWidth : 4 ,
85
89
strokeOpacity : 0.2 ,
86
90
fill : '#fff' ,
@@ -89,7 +93,7 @@ const CUSTOM_DOT_DEFAULT_PROPS = {
89
93
style : { cursor : 'pointer' }
90
94
} as const ;
91
95
92
- const CUSTOM_DOT_ACTIVE_PROPS = {
96
+ const DOT_ACTIVE_PROPS = {
93
97
fill : '#fff' ,
94
98
r : 8 ,
95
99
strokeWidth : 6 ,
@@ -102,9 +106,7 @@ const RADAR_DEFAULT_PROPS = {
102
106
fillOpacity : 0.2
103
107
} as const ;
104
108
105
- const CHART_CONFIGS_BY_SIDE_COUNT = pipe ( keyBy ( 'sideCount' ) , mapValues ( 'name' ) ) ;
106
-
107
- // COMPONENTS
109
+ /* COMPONENTS */
108
110
const Gradient = ( { type, colors : [ firstColor , secondColor ] } : { type : string ; colors : string [ ] } ) => (
109
111
< defs >
110
112
< linearGradient id = { `gradient-${ type } ` } x1 = "0%" y1 = "0%" x2 = "0%" y2 = "100%" >
@@ -122,24 +124,19 @@ const CustomTooltip = ({
122
124
active ?: boolean ;
123
125
payload ?: { value : number } [ ] ;
124
126
label ?: string ;
125
- } ) => {
126
- if ( active && payload && payload . length > 0 )
127
- return (
128
- < div className = { style . tooltip } >
129
- < p > { label } </ p >
130
- < p > { payload [ 0 ] . value } %</ p >
131
- </ div >
132
- ) ;
133
-
134
- return null ;
135
- } ;
127
+ } ) =>
128
+ active && payload && payload . length > 0 ? (
129
+ < div className = { style . tooltip } >
130
+ < p > { label } </ p >
131
+ < p > { payload [ 0 ] . value } %</ p >
132
+ </ div >
133
+ ) : null ;
136
134
137
135
const CustomDot = ( {
138
136
cx,
139
137
cy,
140
138
payload,
141
139
onDotClick,
142
- dataKey,
143
140
stroke,
144
141
activeDot
145
142
} : {
@@ -150,32 +147,23 @@ const CustomDot = ({
150
147
dataKey : string ;
151
148
stroke : string ;
152
149
activeDot ?: ActiveDotType ;
153
- } ) => {
154
- const activeDotValue = activeDot ?. value ;
155
- const activeDotLabel = activeDot ?. label ;
156
- const label = payload ?. payload . subject ;
157
- const value = payload ?. payload [ dataKey ] ;
158
- // maybe remove value comparison ???
159
- const isCurrentDotActive = value === activeDotValue && label === activeDotLabel ;
160
-
161
- return (
162
- < circle
163
- { ...{
164
- ...CUSTOM_DOT_DEFAULT_PROPS ,
165
- ...( isCurrentDotActive && CUSTOM_DOT_ACTIVE_PROPS ) ,
166
- stroke,
167
- cx,
168
- cy,
169
- onClick : e => {
170
- e . stopPropagation ( ) ;
171
-
172
- if ( ! payload ?. name ) return ;
173
- onDotClick ( payload . name ) ;
174
- }
175
- } }
176
- />
177
- ) ;
178
- } ;
150
+ } ) => (
151
+ < circle
152
+ { ...{
153
+ ...DOT_DEFAULT_PROPS ,
154
+ ...( payload ?. payload . subject === activeDot ?. label && DOT_ACTIVE_PROPS ) ,
155
+ stroke,
156
+ cx,
157
+ cy,
158
+ onClick : e => {
159
+ e . stopPropagation ( ) ;
160
+
161
+ if ( ! payload ?. name ) return ;
162
+ onDotClick ( payload . name ) ;
163
+ }
164
+ } }
165
+ />
166
+ ) ;
179
167
180
168
const buildRadars = (
181
169
totalDataset : number ,
@@ -194,13 +182,13 @@ const buildRadars = (
194
182
key = { dataset }
195
183
name = { dataset }
196
184
dataKey = { datakey }
197
- // only on mobile
198
- // to handle dot style on hover (convert to click)
199
- // use with the tooltip component
200
185
activeDot = { {
201
- ...CUSTOM_DOT_ACTIVE_PROPS ,
186
+ ...DOT_ACTIVE_PROPS ,
202
187
stroke : `url(#gradient-stroke-${ index } )`
203
188
} }
189
+ // only on mobile
190
+ // to handle dot style on hover (convert to click)
191
+ // use with the tooltip component
204
192
dot = {
205
193
< CustomDot
206
194
onDotClick = { handleOnDotClick ( datakey ) }
@@ -269,7 +257,9 @@ const buildCustomLabel = ({
269
257
) ;
270
258
} ;
271
259
272
- // UTILS
260
+ /* UTILS */
261
+ const CHART_CONFIGS_BY_SIDE_COUNT = pipe ( keyBy ( 'sideCount' ) , mapValues ( 'name' ) ) ;
262
+
273
263
const formatValues_ : ( values_ : number | number [ ] ) => Record < string , number > = pipe (
274
264
values_ => flatten ( [ values_ ] ) ,
275
265
values_ => values_ . map ( ( val : number , i : number ) : [ string , number ] => [ `value${ i + 1 } ` , val ] ) ,
@@ -330,11 +320,6 @@ const LearningProfileRadarChart = ({
330
320
331
321
useEffect ( ( ) => {
332
322
setIsMobile_ ( ) ;
333
- window . addEventListener ( 'resize' , setIsMobile_ ) ;
334
-
335
- return ( ) => {
336
- window . removeEventListener ( 'resize' , setIsMobile_ ) ;
337
- } ;
338
323
} , [ setIsMobile_ ] ) ;
339
324
340
325
useEffect ( ( ) => {
0 commit comments