Browse Source

Merge 6967c10ddd into 366af5cac7

pull/8284/merge
Mister_Ideas 2 weeks ago
committed by GitHub
parent
commit
bdf8f86fcb
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 6
      CHANGELOG.md
  2. 1
      apps/client/src/app/components/home-overview/home-overview.html
  3. 15
      libs/common/src/lib/chart-helper.spec.ts
  4. 77
      libs/common/src/lib/chart-helper.ts
  5. 12
      libs/ui/src/lib/line-chart/line-chart.component.ts

6
CHANGELOG.md

@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## Unreleased
### Added
- Added a dashed baseline (0 %) to the performance chart on the overview page and made the zero line of the benchmark comparator and the investment chart dashed and more visible
## 3.100.0 - 2026-11-15 ## 3.100.0 - 2026-11-15
### Changed ### Changed

1
apps/client/src/app/components/home-overview/home-overview.html

@ -70,6 +70,7 @@
<gf-line-chart <gf-line-chart
class="position-absolute" class="position-absolute"
unit="%" unit="%"
[baseline]="0"
[class.pe-3]="deviceType() === 'mobile'" [class.pe-3]="deviceType() === 'mobile'"
[colorScheme]="user()?.settings?.colorScheme" [colorScheme]="user()?.settings?.colorScheme"
[hidden]="historicalDataItems()?.length === 0" [hidden]="historicalDataItems()?.length === 0"

15
libs/common/src/lib/chart-helper.spec.ts

@ -1,4 +1,4 @@
import { getTooltipOptions } from './chart-helper'; import { getBaselineAnnotation, getTooltipOptions } from './chart-helper';
describe('getTooltipOptions', () => { describe('getTooltipOptions', () => {
const getLabel = ({ const getLabel = ({
@ -47,3 +47,16 @@ describe('getTooltipOptions', () => {
expect(getLabel({ locale: 'de', y: 1234.5 })).toBe('Performance: 1.234,50'); expect(getLabel({ locale: 'de', y: 1234.5 })).toBe('Performance: 1.234,50');
}); });
}); });
describe('getBaselineAnnotation', () => {
it('returns a dashed horizontal line at the value', () => {
expect(
getBaselineAnnotation({ colorScheme: 'LIGHT', value: 0 })
).toMatchObject({
borderDash: [4, 4],
scaleID: 'y',
type: 'line',
value: 0
});
});
});

77
libs/common/src/lib/chart-helper.ts

@ -219,6 +219,50 @@ export function getValueAxisOptions({
}; };
} }
/**
* Returns a plugin which draws a dashed horizontal line at the baseline of a
* chart above the datasets. Unlike an annotation, it does not follow the
* custom animations of the data points
*/
export function getBaselinePlugin<T extends 'line' | 'bar'>({
colorScheme,
getValue
}: {
colorScheme?: ColorScheme;
getValue: () => number | undefined;
}): Plugin<T> {
return {
afterDatasetsDraw: (chart) => {
const value = getValue();
const yScale = chart.scales['y'];
if (value === undefined || !yScale) {
return;
}
const y = yScale.getPixelForValue(value);
const { bottom, left, right, top } = chart.chartArea;
if (!Number.isFinite(y) || y < top || y > bottom) {
return;
}
const context = chart.ctx;
context.save();
context.beginPath();
context.lineWidth = 1;
context.setLineDash(BASELINE_DASH);
context.strokeStyle = getBaselineColor(colorScheme);
context.moveTo(left, y);
context.lineTo(right, y);
context.stroke();
context.restore();
},
id: 'baseline'
};
}
export function getVerticalHoverLinePlugin<T extends 'line' | 'bar'>( export function getVerticalHoverLinePlugin<T extends 'line' | 'bar'>(
chartCanvas: ElementRef<HTMLCanvasElement>, chartCanvas: ElementRef<HTMLCanvasElement>,
colorScheme?: ColorScheme colorScheme?: ColorScheme
@ -255,18 +299,41 @@ export function getVerticalHoverLinePlugin<T extends 'line' | 'bar'>(
}; };
} }
export function getZeroLineAnnotation( const BASELINE_DASH = [4, 4];
colorScheme?: ColorScheme
): AnnotationOptions<'line'> { function getBaselineColor(colorScheme?: ColorScheme) {
return `rgba(${getTextColor(colorScheme)}, 0.4)`;
}
/**
* Returns a dashed horizontal line at the baseline of a chart (e.g. 0 % for
* the performance), which stands out from the grid lines
*/
export function getBaselineAnnotation({
colorScheme,
value = 0
}: {
colorScheme?: ColorScheme;
value?: number;
}): AnnotationOptions<'line'> {
return { return {
borderColor: getChartBorderColor(colorScheme), borderColor: getBaselineColor(colorScheme),
borderDash: BASELINE_DASH,
borderWidth: 1, borderWidth: 1,
// Above the area of a filled line
drawTime: 'afterDatasetsDraw',
scaleID: 'y', scaleID: 'y',
type: 'line', type: 'line',
value: 0 value
}; };
} }
export function getZeroLineAnnotation(
colorScheme?: ColorScheme
): AnnotationOptions<'line'> {
return getBaselineAnnotation({ colorScheme });
}
export function transformTickToAbbreviation(value: number) { export function transformTickToAbbreviation(value: number) {
if (value === 0) { if (value === 0) {
return '0'; return '0';

12
libs/ui/src/lib/line-chart/line-chart.component.ts

@ -1,4 +1,5 @@
import { import {
getBaselinePlugin,
getChartBorderColor, getChartBorderColor,
getTimeAxisOptions, getTimeAxisOptions,
getValueAxisOptions, getValueAxisOptions,
@ -58,6 +59,8 @@ export class GfLineChartComponent
{ {
@Input() benchmarkDataItems: NullableLineChartItem[] = []; @Input() benchmarkDataItems: NullableLineChartItem[] = [];
@Input() benchmarkLabel = ''; @Input() benchmarkLabel = '';
/** Value of a horizontal reference line (e.g. 0 for a change in percent) */
@Input() baseline?: number;
@Input() colorScheme?: ColorScheme; @Input() colorScheme?: ColorScheme;
@Input() currency?: string; @Input() currency?: string;
@Input() historicalDataItems: LineChartItem[] | null; @Input() historicalDataItems: LineChartItem[] | null;
@ -271,12 +274,21 @@ export class GfLineChartComponent
}), }),
max: this.yMax, max: this.yMax,
min: this.yMin, min: this.yMin,
// The baseline stays visible if all values are on one side
suggestedMax: this.baseline,
suggestedMin: this.baseline,
type: 'linear' type: 'linear'
} }
}, },
spanGaps: true spanGaps: true
}, },
plugins: [ plugins: [
getBaselinePlugin({
colorScheme: this.colorScheme,
getValue: () => {
return this.baseline;
}
}),
getVerticalHoverLinePlugin(this.chartCanvas, this.colorScheme) getVerticalHoverLinePlugin(this.chartCanvas, this.colorScheme)
], ],
type: 'line' type: 'line'

Loading…
Cancel
Save