From fd53517aaedb2ec1a06cc65c091766491d5622da Mon Sep 17 00:00:00 2001 From: adamska27 Date: Tue, 2 Apr 2024 16:51:45 +0200 Subject: [PATCH] feedbacks --- .../learning-profile-radar-chart/index.tsx | 105 ++++++++---------- 1 file changed, 45 insertions(+), 60 deletions(-) diff --git a/packages/@coorpacademy-components/src/molecule/learning-profile-radar-chart/index.tsx b/packages/@coorpacademy-components/src/molecule/learning-profile-radar-chart/index.tsx index a961d68186..3066161a3a 100644 --- a/packages/@coorpacademy-components/src/molecule/learning-profile-radar-chart/index.tsx +++ b/packages/@coorpacademy-components/src/molecule/learning-profile-radar-chart/index.tsx @@ -36,24 +36,28 @@ import { learningProfileRadarChartPropTypes } from './types'; -// TICK_POSITIONS +/* TICK_POSITIONS */ const top: TickType = {offset: {x: -100, y: -65}, alignment: 'center', margin: 'auto'}; const bottom: TickType = {offset: {x: -100, y: 10}, alignment: 'center', margin: 'auto'}; const right: TickType = {offset: {x: 30, y: -10}, alignment: 'start', marginRight: 'auto'}; const left: TickType = {offset: {x: -230, y: -10}, alignment: 'end', marginLeft: 'auto'}; -// CONSTANTS +/* CONSTANTS */ +const BLACK = '#000000ff'; +const WHITE = '#ffffffff'; +const DEFAULT_MAIN_COLOR = '#0062ffff'; + const DEFAULT_COLORS: FormatedColorsType = { gradient: { - fill: ['#0062ffff', '#0062ffff'], - stroke: ['#0062ffff', '#0062ffff '] + fill: [DEFAULT_MAIN_COLOR, DEFAULT_MAIN_COLOR], + stroke: [DEFAULT_MAIN_COLOR, DEFAULT_MAIN_COLOR] }, percentage: { - color: '#000000ff', - background: '#ffffff' + color: BLACK, + background: WHITE }, label: { - color: '#000000ff' + color: BLACK } }; @@ -80,7 +84,7 @@ const CHART_CONFIGS = { } } as const; -const CUSTOM_DOT_DEFAULT_PROPS = { +const DOT_DEFAULT_PROPS = { strokeWidth: 4, strokeOpacity: 0.2, fill: '#fff', @@ -89,7 +93,7 @@ const CUSTOM_DOT_DEFAULT_PROPS = { style: {cursor: 'pointer'} } as const; -const CUSTOM_DOT_ACTIVE_PROPS = { +const DOT_ACTIVE_PROPS = { fill: '#fff', r: 8, strokeWidth: 6, @@ -102,9 +106,7 @@ const RADAR_DEFAULT_PROPS = { fillOpacity: 0.2 } as const; -const CHART_CONFIGS_BY_SIDE_COUNT = pipe(keyBy('sideCount'), mapValues('name')); - -// COMPONENTS +/* COMPONENTS */ const Gradient = ({type, colors: [firstColor, secondColor]}: {type: string; colors: string[]}) => ( @@ -122,24 +124,19 @@ const CustomTooltip = ({ active?: boolean; payload?: {value: number}[]; label?: string; -}) => { - if (active && payload && payload.length > 0) - return ( -
-

{label}

-

{payload[0].value}%

-
- ); - - return null; -}; +}) => + active && payload && payload.length > 0 ? ( +
+

{label}

+

{payload[0].value}%

+
+ ) : null; const CustomDot = ({ cx, cy, payload, onDotClick, - dataKey, stroke, activeDot }: { @@ -150,32 +147,23 @@ const CustomDot = ({ dataKey: string; stroke: string; activeDot?: ActiveDotType; -}) => { - const activeDotValue = activeDot?.value; - const activeDotLabel = activeDot?.label; - const label = payload?.payload.subject; - const value = payload?.payload[dataKey]; - // maybe remove value comparison ??? - const isCurrentDotActive = value === activeDotValue && label === activeDotLabel; - - return ( - { - e.stopPropagation(); - - if (!payload?.name) return; - onDotClick(payload.name); - } - }} - /> - ); -}; +}) => ( + { + e.stopPropagation(); + + if (!payload?.name) return; + onDotClick(payload.name); + } + }} + /> +); const buildRadars = ( totalDataset: number, @@ -194,13 +182,13 @@ const buildRadars = ( key={dataset} name={dataset} dataKey={datakey} - // only on mobile - // to handle dot style on hover (convert to click) - // use with the tooltip component activeDot={{ - ...CUSTOM_DOT_ACTIVE_PROPS, + ...DOT_ACTIVE_PROPS, stroke: `url(#gradient-stroke-${index})` }} + // only on mobile + // to handle dot style on hover (convert to click) + // use with the tooltip component dot={ Record = pipe( values_ => flatten([values_]), values_ => values_.map((val: number, i: number): [string, number] => [`value${i + 1}`, val]), @@ -330,11 +320,6 @@ const LearningProfileRadarChart = ({ useEffect(() => { setIsMobile_(); - window.addEventListener('resize', setIsMobile_); - - return () => { - window.removeEventListener('resize', setIsMobile_); - }; }, [setIsMobile_]); useEffect(() => {