Skip to content

Commit fd53517

Browse files
committed
feedbacks
1 parent 8a401c4 commit fd53517

File tree

1 file changed

+45
-60
lines changed
  • packages/@coorpacademy-components/src/molecule/learning-profile-radar-chart

1 file changed

+45
-60
lines changed

packages/@coorpacademy-components/src/molecule/learning-profile-radar-chart/index.tsx

Lines changed: 45 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -36,24 +36,28 @@ import {
3636
learningProfileRadarChartPropTypes
3737
} from './types';
3838

39-
// TICK_POSITIONS
39+
/* TICK_POSITIONS */
4040
const top: TickType = {offset: {x: -100, y: -65}, alignment: 'center', margin: 'auto'};
4141
const bottom: TickType = {offset: {x: -100, y: 10}, alignment: 'center', margin: 'auto'};
4242
const right: TickType = {offset: {x: 30, y: -10}, alignment: 'start', marginRight: 'auto'};
4343
const left: TickType = {offset: {x: -230, y: -10}, alignment: 'end', marginLeft: 'auto'};
4444

45-
// CONSTANTS
45+
/* CONSTANTS */
46+
const BLACK = '#000000ff';
47+
const WHITE = '#ffffffff';
48+
const DEFAULT_MAIN_COLOR = '#0062ffff';
49+
4650
const DEFAULT_COLORS: FormatedColorsType = {
4751
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]
5054
},
5155
percentage: {
52-
color: '#000000ff',
53-
background: '#ffffff'
56+
color: BLACK,
57+
background: WHITE
5458
},
5559
label: {
56-
color: '#000000ff'
60+
color: BLACK
5761
}
5862
};
5963

@@ -80,7 +84,7 @@ const CHART_CONFIGS = {
8084
}
8185
} as const;
8286

83-
const CUSTOM_DOT_DEFAULT_PROPS = {
87+
const DOT_DEFAULT_PROPS = {
8488
strokeWidth: 4,
8589
strokeOpacity: 0.2,
8690
fill: '#fff',
@@ -89,7 +93,7 @@ const CUSTOM_DOT_DEFAULT_PROPS = {
8993
style: {cursor: 'pointer'}
9094
} as const;
9195

92-
const CUSTOM_DOT_ACTIVE_PROPS = {
96+
const DOT_ACTIVE_PROPS = {
9397
fill: '#fff',
9498
r: 8,
9599
strokeWidth: 6,
@@ -102,9 +106,7 @@ const RADAR_DEFAULT_PROPS = {
102106
fillOpacity: 0.2
103107
} as const;
104108

105-
const CHART_CONFIGS_BY_SIDE_COUNT = pipe(keyBy('sideCount'), mapValues('name'));
106-
107-
// COMPONENTS
109+
/* COMPONENTS */
108110
const Gradient = ({type, colors: [firstColor, secondColor]}: {type: string; colors: string[]}) => (
109111
<defs>
110112
<linearGradient id={`gradient-${type}`} x1="0%" y1="0%" x2="0%" y2="100%">
@@ -122,24 +124,19 @@ const CustomTooltip = ({
122124
active?: boolean;
123125
payload?: {value: number}[];
124126
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;
136134

137135
const CustomDot = ({
138136
cx,
139137
cy,
140138
payload,
141139
onDotClick,
142-
dataKey,
143140
stroke,
144141
activeDot
145142
}: {
@@ -150,32 +147,23 @@ const CustomDot = ({
150147
dataKey: string;
151148
stroke: string;
152149
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+
);
179167

180168
const buildRadars = (
181169
totalDataset: number,
@@ -194,13 +182,13 @@ const buildRadars = (
194182
key={dataset}
195183
name={dataset}
196184
dataKey={datakey}
197-
// only on mobile
198-
// to handle dot style on hover (convert to click)
199-
// use with the tooltip component
200185
activeDot={{
201-
...CUSTOM_DOT_ACTIVE_PROPS,
186+
...DOT_ACTIVE_PROPS,
202187
stroke: `url(#gradient-stroke-${index})`
203188
}}
189+
// only on mobile
190+
// to handle dot style on hover (convert to click)
191+
// use with the tooltip component
204192
dot={
205193
<CustomDot
206194
onDotClick={handleOnDotClick(datakey)}
@@ -269,7 +257,9 @@ const buildCustomLabel = ({
269257
);
270258
};
271259

272-
// UTILS
260+
/* UTILS */
261+
const CHART_CONFIGS_BY_SIDE_COUNT = pipe(keyBy('sideCount'), mapValues('name'));
262+
273263
const formatValues_: (values_: number | number[]) => Record<string, number> = pipe(
274264
values_ => flatten([values_]),
275265
values_ => values_.map((val: number, i: number): [string, number] => [`value${i + 1}`, val]),
@@ -330,11 +320,6 @@ const LearningProfileRadarChart = ({
330320

331321
useEffect(() => {
332322
setIsMobile_();
333-
window.addEventListener('resize', setIsMobile_);
334-
335-
return () => {
336-
window.removeEventListener('resize', setIsMobile_);
337-
};
338323
}, [setIsMobile_]);
339324

340325
useEffect(() => {

0 commit comments

Comments
 (0)