Browse Source

Highlight negative values in performance timeline chart

pull/8198/head
Thomas Kaul 1 day ago
parent
commit
af67e9956c
  1. 1
      apps/client/src/app/pages/portfolio/analysis/analysis-page.html
  2. 1
      libs/ui/src/lib/investment-chart/investment-chart.component.stories.ts
  3. 17
      libs/ui/src/lib/investment-chart/investment-chart.component.ts

1
apps/client/src/app/pages/portfolio/analysis/analysis-page.html

@ -449,6 +449,7 @@
groupBy="year" groupBy="year"
[benchmarkDataItems]="performancePercentagesByYear" [benchmarkDataItems]="performancePercentagesByYear"
[benchmarkDataLabel]="performanceTimelineDataLabel" [benchmarkDataLabel]="performanceTimelineDataLabel"
[colorizeSign]="true"
[colorScheme]="user?.settings?.colorScheme" [colorScheme]="user?.settings?.colorScheme"
[isInPercentage]="true" [isInPercentage]="true"
[isLoading]="isLoadingPerformanceTimelineChart" [isLoading]="isLoadingPerformanceTimelineChart"

1
libs/ui/src/lib/investment-chart/investment-chart.component.stories.ts

@ -69,6 +69,7 @@ export const PerformanceByYear: Story = {
} }
], ],
benchmarkDataLabel: 'Net Performance', benchmarkDataLabel: 'Net Performance',
colorizeSign: true,
groupBy: 'year', groupBy: 'year',
isInPercentage: true isInPercentage: true
} }

17
libs/ui/src/lib/investment-chart/investment-chart.component.ts

@ -32,6 +32,7 @@ import {
LineController, LineController,
LineElement, LineElement,
PointElement, PointElement,
type ScriptableContext,
type ScriptableLineSegmentContext, type ScriptableLineSegmentContext,
TimeScale, TimeScale,
Tooltip, Tooltip,
@ -41,6 +42,7 @@ import 'chartjs-adapter-date-fns';
import { type AnnotationOptions } from 'chartjs-plugin-annotation'; import { type AnnotationOptions } from 'chartjs-plugin-annotation';
import { isFuture } from 'date-fns'; import { isFuture } from 'date-fns';
import { NgxSkeletonLoaderModule } from 'ngx-skeleton-loader'; import { NgxSkeletonLoaderModule } from 'ngx-skeleton-loader';
import OpenColor from 'open-color';
import { import {
getTimeSeriesTooltipOptions, getTimeSeriesTooltipOptions,
@ -48,6 +50,8 @@ import {
registerChartConfiguration registerChartConfiguration
} from '../chart'; } from '../chart';
const { orange } = OpenColor;
@Component({ @Component({
changeDetection: ChangeDetectionStrategy.OnPush, changeDetection: ChangeDetectionStrategy.OnPush,
imports: [NgxSkeletonLoaderModule], imports: [NgxSkeletonLoaderModule],
@ -58,6 +62,7 @@ import {
export class GfInvestmentChartComponent implements OnChanges, OnDestroy { export class GfInvestmentChartComponent implements OnChanges, OnDestroy {
@Input() public benchmarkDataItems: InvestmentItem[] = []; @Input() public benchmarkDataItems: InvestmentItem[] = [];
@Input() public benchmarkDataLabel = ''; @Input() public benchmarkDataLabel = '';
@Input() public colorizeSign = false;
@Input() public colorScheme?: ColorScheme; @Input() public colorScheme?: ColorScheme;
@Input() public currency?: string; @Input() public currency?: string;
@Input() public groupBy?: GroupBy; @Input() public groupBy?: GroupBy;
@ -133,7 +138,17 @@ export class GfInvestmentChartComponent implements OnChanges, OnDestroy {
}), }),
datasets: [ datasets: [
{ {
backgroundColor: `rgb(${benchmarkColorRgb.r}, ${benchmarkColorRgb.g}, ${benchmarkColorRgb.b})`, backgroundColor: (context: ScriptableContext<'bar' | 'line'>) => {
if (
(context.parsed?.y ?? 0) < 0 &&
isBarChart &&
this.colorizeSign
) {
return orange[5];
}
return `rgb(${benchmarkColorRgb.r}, ${benchmarkColorRgb.g}, ${benchmarkColorRgb.b})`;
},
borderColor: `rgb(${benchmarkColorRgb.r}, ${benchmarkColorRgb.g}, ${benchmarkColorRgb.b})`, borderColor: `rgb(${benchmarkColorRgb.r}, ${benchmarkColorRgb.g}, ${benchmarkColorRgb.b})`,
borderWidth: isBarChart ? 0 : 1, borderWidth: isBarChart ? 0 : 1,
data: this.investments.map(({ date, investment }) => { data: this.investments.map(({ date, investment }) => {

Loading…
Cancel
Save