-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: [IGL-109] AreaChart dot colors (#622)
- Loading branch information
1 parent
dd2579d
commit fece90c
Showing
5 changed files
with
150 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@igloo-ui/area-chart": minor | ||
--- | ||
|
||
Updated AreaChart's dot colors for Workleap on both the line and tooltip. Also fixed the DataRange min and max prop types so that it only accepts specific string values; like it always should have been. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,99 +1,107 @@ | ||
import * as React from 'react'; | ||
import cx from 'classnames'; | ||
import { TooltipProps } from 'recharts'; | ||
import * as React from "react"; | ||
import cx from "classnames"; | ||
import type { TooltipProps } from "recharts"; | ||
|
||
import { | ||
NameType, | ||
ValueType, | ||
} from 'recharts/types/component/DefaultTooltipContent'; | ||
import type { | ||
NameType, | ||
ValueType | ||
} from "recharts/types/component/DefaultTooltipContent"; | ||
|
||
import './chart-tooltip.scss'; | ||
import "./chart-tooltip.scss"; | ||
|
||
export interface ChartTooltipProps extends TooltipProps<ValueType, NameType> { | ||
dateFormatter: (date: number) => string; | ||
scoreFormatter?: (score: number) => string; | ||
unavailableDataMessage?: string; | ||
dateFormatter: (date: number) => string; | ||
scoreFormatter?: (score: number) => string; | ||
getDataScoreHue?: (score: number) => string; | ||
unavailableDataMessage?: string; | ||
} | ||
|
||
export interface TooltipScoreProps { | ||
score: number; | ||
text: string; | ||
isSecondary?: boolean; | ||
scoreFormatter?: (score: number) => string; | ||
score: number; | ||
text: string; | ||
isSecondary?: boolean; | ||
formatter?: (score: number) => string; | ||
dotColor?: string; | ||
} | ||
|
||
const ChartTooltip: React.FunctionComponent<ChartTooltipProps> = ( | ||
props: ChartTooltipProps, | ||
props: ChartTooltipProps | ||
) => { | ||
const { | ||
active, | ||
payload, | ||
label, | ||
dateFormatter, | ||
scoreFormatter, | ||
unavailableDataMessage, | ||
} = props; | ||
const { | ||
active, | ||
payload, | ||
label, | ||
dateFormatter, | ||
scoreFormatter, | ||
getDataScoreHue, | ||
unavailableDataMessage | ||
} = props; | ||
|
||
const isValidScore = (score: number): boolean => { | ||
return score !== undefined && score !== null; | ||
}; | ||
const isValidScore = (score: number): boolean => { | ||
return score !== undefined && score !== null; | ||
}; | ||
|
||
const TooltipScore = (scoreProps: TooltipScoreProps): JSX.Element => { | ||
const { score, text, isSecondary, scoreFormatter } = scoreProps; | ||
const formattedScore = scoreFormatter ? scoreFormatter(score) : score; | ||
const TooltipScore = (scoreProps: TooltipScoreProps): JSX.Element => { | ||
const { score, text, isSecondary, formatter, dotColor } = scoreProps; | ||
const formattedScore = formatter ? formatter(score) : score; | ||
|
||
return ( | ||
<div className="ids-tooltip-score"> | ||
<div | ||
className={cx('ids-tooltip-score__circle', { | ||
'ids-tooltip-score__circle--secondary': isSecondary, | ||
})} | ||
/> | ||
<div className="ids-tooltip-score__value">{formattedScore}</div> | ||
<div className="ids-tooltip-score__text">{text}</div> | ||
</div> | ||
); | ||
}; | ||
return ( | ||
<div className="ids-tooltip-score" | ||
style={{ | ||
"--ids-tooltip-score-dot-color": dotColor ? dotColor : undefined | ||
} as React.CSSProperties} | ||
> | ||
<div | ||
className={cx("ids-tooltip-score__circle", { | ||
"ids-tooltip-score__circle--secondary": isSecondary | ||
})} | ||
/> | ||
<div className="ids-tooltip-score__value">{formattedScore}</div> | ||
<div className="ids-tooltip-score__text">{text}</div> | ||
</div> | ||
); | ||
}; | ||
|
||
if (active && payload && payload[0]) { | ||
const isPrimaryScoreValid = isValidScore(payload[0].payload.score); | ||
const isSecondaryScoreValid = isValidScore( | ||
payload[0].payload.secondaryScore, | ||
); | ||
if (active && payload && payload[0]) { | ||
const isPrimaryScoreValid = isValidScore(payload[0].payload.score); | ||
const isSecondaryScoreValid = isValidScore( | ||
payload[0].payload.secondaryScore | ||
); | ||
|
||
return ( | ||
<div className="ids-chart-tooltip"> | ||
{isPrimaryScoreValid || isSecondaryScoreValid ? ( | ||
<div> | ||
<div className="ids-chart-tooltip__date"> | ||
{dateFormatter(label)} | ||
return ( | ||
<div className="ids-chart-tooltip"> | ||
{isPrimaryScoreValid || isSecondaryScoreValid ? ( | ||
<div> | ||
<div className="ids-chart-tooltip__date"> | ||
{dateFormatter(label)} | ||
</div> | ||
{isPrimaryScoreValid && ( | ||
<TooltipScore | ||
score={Number(payload[0].payload.score)} | ||
text={payload[0].payload.name || ""} | ||
formatter={scoreFormatter} | ||
dotColor={getDataScoreHue?.(payload[0].payload.score)} | ||
/> | ||
)} | ||
{isSecondaryScoreValid && ( | ||
<TooltipScore | ||
score={Number(payload[0].payload.secondaryScore)} | ||
text={payload[0].payload.secondaryName || ""} | ||
formatter={scoreFormatter} | ||
isSecondary | ||
/> | ||
)} | ||
</div> | ||
) : ( | ||
<div className="ids-chart-tooltip__unavailable-score"> | ||
{unavailableDataMessage} | ||
</div> | ||
)} | ||
</div> | ||
{isPrimaryScoreValid && ( | ||
<TooltipScore | ||
score={Number(payload[0].payload.score)} | ||
text={payload[0].payload.name || ''} | ||
scoreFormatter={scoreFormatter} | ||
/> | ||
)} | ||
{isSecondaryScoreValid && ( | ||
<TooltipScore | ||
score={Number(payload[0].payload.secondaryScore)} | ||
text={payload[0].payload.secondaryName || ''} | ||
scoreFormatter={scoreFormatter} | ||
isSecondary | ||
/> | ||
)} | ||
</div> | ||
) : ( | ||
<div className="ids-chart-tooltip__unavailable-score"> | ||
{unavailableDataMessage} | ||
</div> | ||
)} | ||
</div> | ||
); | ||
} | ||
); | ||
} | ||
|
||
return null; | ||
return null; | ||
}; | ||
|
||
export default ChartTooltip; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters