Skip to content

Commit

Permalink
fix: consistent chart metric name formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
pocin committed Apr 2, 2024
1 parent ae69807 commit af6603f
Showing 1 changed file with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,29 @@ const V2StrategyMetricsChart: React.FC<{
selectedInterval: ChartSupportedTimeInterval;
}> = ({ dashboardData, selectedMetric, selectedInterval }) => {
// uncamel-case the metric names
const formatMetricName = (name: string) =>
// format only the selected metric name (the selected metric or all lines in a TRV chart)
name === selectedMetric || isTRVDashboard(dashboardData.key)
? name
const formatMetricName = (name: string) => {
// format only
// - the selected metric
// - all lines in TRV chart
// - netDebt chart components
// the remaining cases are individual debt tokens (sUSDe, sDAI, rsETH, ...)
// which we keep as is
if (
name === selectedMetric ||
isTRVDashboard(dashboardData.key) ||
selectedMetric === 'netDebtUSD'
) {
return (
name
// // insert a space before all caps
.replace(/([A-Z][a-z])/g, ' $1')
// // uppercase the first character
.replace(/^./, (str) => str.toUpperCase())
.replace(/USD$/, '')
: // Individual debt token tickers remain unchanged
name;
);
}
return name;
};
const tooltipValuesFormatter = (value: number, name: string) => [
numberFormatter.format(value),
formatMetricName(name),
Expand Down

0 comments on commit af6603f

Please sign in to comment.