From ea5594dd0e4da4732473411a313bb1703830241e Mon Sep 17 00:00:00 2001 From: JoryHogeveen Date: Mon, 18 Nov 2024 15:25:20 +0100 Subject: [PATCH] Add horizontal allocation bar with colors --- .../top-holdings/top-holdings.component.html | 16 ++++++ .../top-holdings/top-holdings.component.scss | 11 ++++ .../top-holdings/top-holdings.component.ts | 54 ++++++++++++++++++- 3 files changed, 80 insertions(+), 1 deletion(-) diff --git a/libs/ui/src/lib/top-holdings/top-holdings.component.html b/libs/ui/src/lib/top-holdings/top-holdings.component.html index 19d853767..a93f4829c 100644 --- a/libs/ui/src/lib/top-holdings/top-holdings.component.html +++ b/libs/ui/src/lib/top-holdings/top-holdings.component.html @@ -69,6 +69,22 @@ class="allocationByParent" >
+
+ @for ( + parentHolding of element.parents.slice(0, 10); + track parentHolding; + let i = $index + ) { +
+ {{ parentHolding?.symbol }} +
+ } +
+ @for (parentHolding of element.parents; track parentHolding) { diff --git a/libs/ui/src/lib/top-holdings/top-holdings.component.scss b/libs/ui/src/lib/top-holdings/top-holdings.component.scss index 301596a86..d49dc926f 100644 --- a/libs/ui/src/lib/top-holdings/top-holdings.component.scss +++ b/libs/ui/src/lib/top-holdings/top-holdings.component.scss @@ -22,6 +22,17 @@ .holdingParents { padding: 1em 0; + .holdingParentProportionChart { + height: 2em; + + div { + box-sizing: border-box; + line-height: 2em; + padding: 0 0.5em; + overflow: hidden; + } + } + table, tr, td { diff --git a/libs/ui/src/lib/top-holdings/top-holdings.component.ts b/libs/ui/src/lib/top-holdings/top-holdings.component.ts index 67178e480..25333f48f 100644 --- a/libs/ui/src/lib/top-holdings/top-holdings.component.ts +++ b/libs/ui/src/lib/top-holdings/top-holdings.component.ts @@ -24,10 +24,26 @@ import { MatListModule } from '@angular/material/list'; import { MatPaginator, MatPaginatorModule } from '@angular/material/paginator'; import { MatSort, MatSortModule } from '@angular/material/sort'; import { MatTableDataSource, MatTableModule } from '@angular/material/table'; +import { MatTooltipModule } from '@angular/material/tooltip'; import { get } from 'lodash'; import { NgxSkeletonLoaderModule } from 'ngx-skeleton-loader'; import { Subject } from 'rxjs'; +const { + blue, + cyan, + grape, + green, + indigo, + lime, + orange, + pink, + red, + teal, + violet, + yellow +} = require('open-color'); + @Component({ animations: [ trigger('detailExpand', [ @@ -44,10 +60,11 @@ import { Subject } from 'rxjs'; CommonModule, GfValueComponent, MatButtonModule, + MatListModule, MatPaginatorModule, MatSortModule, MatTableModule, - MatListModule, + MatTooltipModule, NgxSkeletonLoaderModule ], schemas: [CUSTOM_ELEMENTS_SCHEMA], @@ -65,6 +82,10 @@ export class GfTopHoldingsComponent implements OnChanges, OnDestroy { @ViewChild(MatPaginator) paginator: MatPaginator; @ViewChild(MatSort) sort: MatSort; + private colorMap: { + [symbol: string]: string; + } = {}; + public dataSource = new MatTableDataSource(); public displayedColumns: string[] = [ 'name', @@ -75,6 +96,37 @@ export class GfTopHoldingsComponent implements OnChanges, OnDestroy { private unsubscribeSubject = new Subject(); + private colorPaletteIndex = 0; + private colorPalette = [ + blue[5], + teal[5], + lime[5], + orange[5], + pink[5], + violet[5], + indigo[5], + cyan[5], + green[5], + yellow[5], + red[5], + grape[5] + ]; + + public getColor(symbol) { + if (this.colorMap[symbol]) { + // Reuse color + return this.colorMap[symbol]; + } else { + const color = this.colorPalette[this.colorPaletteIndex]; + this.colorPaletteIndex = + this.colorPaletteIndex < this.colorPalette.length + ? this.colorPaletteIndex + 1 + : 0; + this.colorMap[symbol] = color; + return color; + } + } + public ngOnChanges() { this.isLoading = true;