Feature/add story for portfolio proportion chart component (#384)

* Add story

* Use new component

* Update changelog
pull/385/head
Thomas Kaul 3 years ago committed by GitHub
parent 5cd6edaf3a
commit af022ae316
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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 story for the portfolio proportion chart component
## 1.55.0 - 20.09.2021 ## 1.55.0 - 20.09.2021
### Changed ### Changed

@ -1,10 +1,10 @@
import { CommonModule } from '@angular/common'; import { CommonModule } from '@angular/common';
import { CUSTOM_ELEMENTS_SCHEMA, NgModule } from '@angular/core'; import { CUSTOM_ELEMENTS_SCHEMA, NgModule } from '@angular/core';
import { MatCardModule } from '@angular/material/card'; import { MatCardModule } from '@angular/material/card';
import { GfPortfolioProportionChartModule } from '@ghostfolio/client/components/portfolio-proportion-chart/portfolio-proportion-chart.module';
import { GfPositionsTableModule } from '@ghostfolio/client/components/positions-table/positions-table.module'; import { GfPositionsTableModule } from '@ghostfolio/client/components/positions-table/positions-table.module';
import { GfToggleModule } from '@ghostfolio/client/components/toggle/toggle.module'; import { GfToggleModule } from '@ghostfolio/client/components/toggle/toggle.module';
import { GfWorldMapChartModule } from '@ghostfolio/client/components/world-map-chart/world-map-chart.module'; import { GfWorldMapChartModule } from '@ghostfolio/client/components/world-map-chart/world-map-chart.module';
import { GfPortfolioProportionChartModule } from '@ghostfolio/ui/portfolio-proportion-chart/portfolio-proportion-chart.module';
import { AllocationsPageRoutingModule } from './allocations-page-routing.module'; import { AllocationsPageRoutingModule } from './allocations-page-routing.module';
import { AllocationsPageComponent } from './allocations-page.component'; import { AllocationsPageComponent } from './allocations-page.component';

@ -123,7 +123,7 @@ export function resolveFearAndGreedIndex(aValue: number) {
return { emoji: '😐', text: 'Neutral' }; return { emoji: '😐', text: 'Neutral' };
} else if (aValue < 75) { } else if (aValue < 75) {
return { emoji: '😜', text: 'Greed' }; return { emoji: '😜', text: 'Greed' };
} else if (aValue >= 75) { } else {
return { emoji: '🤪', text: 'Extreme Greed' }; return { emoji: '🤪', text: 'Extreme Greed' };
} }
} }

@ -0,0 +1,38 @@
import { CommonModule } from '@angular/common';
import { Meta, Story, moduleMetadata } from '@storybook/angular';
import { NgxSkeletonLoaderModule } from 'ngx-skeleton-loader';
import { PortfolioProportionChartComponent } from './portfolio-proportion-chart.component';
import { Currency } from '.prisma/client';
export default {
title: 'Portfolio Proportion Chart',
component: PortfolioProportionChartComponent,
decorators: [
moduleMetadata({
declarations: [PortfolioProportionChartComponent],
imports: [CommonModule, NgxSkeletonLoaderModule]
})
]
} as Meta<PortfolioProportionChartComponent>;
const Template: Story<PortfolioProportionChartComponent> = (
args: PortfolioProportionChartComponent
) => ({
props: args
});
export const Simple = Template.bind({});
Simple.args = {
baseCurrency: Currency.USD,
keys: ['name'],
locale: 'en-US',
positions: {
Africa: { name: 'Africa', value: 983.22461479889288 },
Asia: { name: 'Asia', value: 12074.754633964973 },
Europe: { name: 'Europe', value: 34432.837085290535 },
'North America': { name: 'North America', value: 26539.89987780503 },
Oceania: { name: 'Oceania', value: 1402.220605072031 },
'South America': { name: 'South America', value: 4938.25202180719859 }
}
};

@ -1,10 +1,11 @@
import { import {
AfterViewInit,
ChangeDetectionStrategy, ChangeDetectionStrategy,
Component, Component,
ElementRef,
Input, Input,
OnChanges, OnChanges,
OnDestroy, OnDestroy,
OnInit,
ViewChild ViewChild
} from '@angular/core'; } from '@angular/core';
import { UNKNOWN_KEY } from '@ghostfolio/common/config'; import { UNKNOWN_KEY } from '@ghostfolio/common/config';
@ -26,19 +27,19 @@ import * as Color from 'color';
styleUrls: ['./portfolio-proportion-chart.component.scss'] styleUrls: ['./portfolio-proportion-chart.component.scss']
}) })
export class PortfolioProportionChartComponent export class PortfolioProportionChartComponent
implements OnChanges, OnDestroy, OnInit implements AfterViewInit, OnChanges, OnDestroy
{ {
@Input() baseCurrency: Currency; @Input() baseCurrency: Currency;
@Input() isInPercent: boolean; @Input() isInPercent = false;
@Input() keys: string[]; @Input() keys: string[] = [];
@Input() locale: string; @Input() locale = '';
@Input() maxItems?: number; @Input() maxItems?: number;
@Input() showLabels = false; @Input() showLabels = false;
@Input() positions: { @Input() positions: {
[symbol: string]: Pick<PortfolioPosition, 'type'> & { value: number }; [symbol: string]: Pick<PortfolioPosition, 'type'> & { value: number };
}; } = {};
@ViewChild('chartCanvas') chartCanvas; @ViewChild('chartCanvas') chartCanvas: ElementRef<HTMLCanvasElement>;
public chart: Chart; public chart: Chart;
public isLoading = true; public isLoading = true;
@ -59,7 +60,11 @@ export class PortfolioProportionChartComponent
); );
} }
public ngOnInit() {} public ngAfterViewInit() {
if (this.positions) {
this.initialize();
}
}
public ngOnChanges() { public ngOnChanges() {
if (this.positions) { if (this.positions) {
@ -260,7 +265,7 @@ export class PortfolioProportionChartComponent
anchor: 'end', anchor: 'end',
formatter: (value, context) => { formatter: (value, context) => {
return value > 0 return value > 0
? context.chart.data.labels[context.dataIndex] ? context.chart.data.labels?.[context.dataIndex]
: ''; : '';
}, },
offset: 8 offset: 8
@ -274,7 +279,7 @@ export class PortfolioProportionChartComponent
const labelIndex = const labelIndex =
(data.datasets[context.datasetIndex - 1]?.data?.length ?? (data.datasets[context.datasetIndex - 1]?.data?.length ??
0) + context.dataIndex; 0) + context.dataIndex;
const label = context.chart.data.labels[labelIndex]; const label = context.chart.data.labels?.[labelIndex] ?? '';
if (this.isInPercent) { if (this.isInPercent) {
const value = 100 * <number>context.raw; const value = 100 * <number>context.raw;

@ -15,7 +15,7 @@
], ],
"compilerOptions": { "compilerOptions": {
"forceConsistentCasingInFileNames": true, "forceConsistentCasingInFileNames": true,
"strict": true, "strict": false,
"noImplicitReturns": true, "noImplicitReturns": true,
"noFallthroughCasesInSwitch": true "noFallthroughCasesInSwitch": true
}, },

Loading…
Cancel
Save