Browse Source

Enhance chart configurations with improved date display formats and refined max value handling for better readability and scalability.

pull/5021/head
Finn Fischer 5 days ago
parent
commit
ed4619f8a5
  1. 7
      apps/client/src/app/components/benchmark-comparator/benchmark-comparator.component.ts
  2. 43
      apps/client/src/app/components/investment-chart/investment-chart.component.ts
  3. 9
      libs/common/src/lib/helper.ts

7
apps/client/src/app/components/benchmark-comparator/benchmark-comparator.component.ts

@ -191,7 +191,12 @@ export class BenchmarkComparatorComponent implements OnChanges, OnDestroy {
type: 'time', type: 'time',
time: { time: {
tooltipFormat: getDateFormatString(this.locale), tooltipFormat: getDateFormatString(this.locale),
unit: 'year' unit: 'year',
displayFormats: {
day: 'MMM d',
month: 'MMM yyyy',
year: 'yyyy'
}
} }
}, },
y: { y: {

43
apps/client/src/app/components/investment-chart/investment-chart.component.ts

@ -40,11 +40,11 @@ import 'chartjs-adapter-date-fns';
import annotationPlugin from 'chartjs-plugin-annotation'; import annotationPlugin from 'chartjs-plugin-annotation';
import { import {
isAfter, isAfter,
subDays,
subYears,
startOfMonth, startOfMonth,
startOfWeek,
startOfYear, startOfYear,
startOfWeek subDays,
subYears
} from 'date-fns'; } from 'date-fns';
@Component({ @Component({
@ -280,7 +280,7 @@ export class InvestmentChartComponent implements OnChanges, OnDestroy {
} }
private getChartXAxis() { private getChartXAxis() {
let min: number; let min: number | undefined;
let unit: 'day' | 'month' | 'week' | 'year' = 'year'; let unit: 'day' | 'month' | 'week' | 'year' = 'year';
switch (this.dateRange) { switch (this.dateRange) {
@ -293,7 +293,7 @@ export class InvestmentChartComponent implements OnChanges, OnDestroy {
unit = 'day'; unit = 'day';
break; break;
case 'wtd': case 'wtd':
min = startOfWeek(new Date()).getTime(); min = startOfWeek(new Date(), { weekStartsOn: 1 }).getTime();
unit = 'day'; unit = 'day';
break; break;
case 'ytd': case 'ytd':
@ -308,9 +308,28 @@ export class InvestmentChartComponent implements OnChanges, OnDestroy {
min = subYears(new Date(), 5).getTime(); min = subYears(new Date(), 5).getTime();
unit = 'year'; unit = 'year';
break; break;
case 'max':
// For 'max', we don't set a min value to show all available data
// Use 'year' unit for better scale with long-term data
unit = 'year';
break;
default:
// For any other value (like specific years), use year unit
unit = 'year';
break;
} }
return { const config: any = {
type: 'time',
time: {
unit,
// Add display formats for better readability
displayFormats: {
day: 'MMM d',
month: 'MMM yyyy',
year: 'yyyy'
}
},
border: { border: {
color: `rgba(${getTextColor(this.colorScheme)}, 0.1)`, color: `rgba(${getTextColor(this.colorScheme)}, 0.1)`,
width: this.groupBy ? 0 : 1 width: this.groupBy ? 0 : 1
@ -318,13 +337,15 @@ export class InvestmentChartComponent implements OnChanges, OnDestroy {
display: true, display: true,
grid: { grid: {
display: false display: false
},
min,
type: 'time',
time: {
unit
} }
}; };
// Only add min if it's defined (not for 'max' range)
if (min !== undefined) {
config.min = min;
}
return config;
} }
private getTooltipPluginConfiguration() { private getTooltipPluginConfiguration() {

9
libs/common/src/lib/helper.ts

@ -444,12 +444,3 @@ export function resolveMarketCondition(
return { emoji: undefined }; return { emoji: undefined };
} }
} }
export function isBenchmark(
aSymbol: string,
aBenchmarks: AssetProfileIdentifier[]
) {
return aBenchmarks.some(({ symbol }) => {
return symbol === aSymbol;
});
}

Loading…
Cancel
Save