|
|
@ -3,7 +3,7 @@ import { |
|
|
getIntervalFromDateRange |
|
|
getIntervalFromDateRange |
|
|
} from '@ghostfolio/common/calculation-helper'; |
|
|
} from '@ghostfolio/common/calculation-helper'; |
|
|
import { getTooltipOptions } from '@ghostfolio/common/chart-helper'; |
|
|
import { getTooltipOptions } from '@ghostfolio/common/chart-helper'; |
|
|
import { getLocale } from '@ghostfolio/common/helper'; |
|
|
import { canOpenHoldingDetail, getLocale } from '@ghostfolio/common/helper'; |
|
|
import { |
|
|
import { |
|
|
AssetProfileIdentifier, |
|
|
AssetProfileIdentifier, |
|
|
PortfolioPosition |
|
|
PortfolioPosition |
|
|
@ -21,9 +21,8 @@ import { |
|
|
output, |
|
|
output, |
|
|
viewChild |
|
|
viewChild |
|
|
} from '@angular/core'; |
|
|
} from '@angular/core'; |
|
|
import { DataSource } from '@prisma/client'; |
|
|
|
|
|
import { Big } from 'big.js'; |
|
|
import { Big } from 'big.js'; |
|
|
import type { ChartData, TooltipOptions } from 'chart.js'; |
|
|
import type { ActiveElement, ChartData, TooltipOptions } from 'chart.js'; |
|
|
import { Chart, LinearScale, Tooltip } from 'chart.js'; |
|
|
import { Chart, LinearScale, Tooltip } from 'chart.js'; |
|
|
import { TreemapController, TreemapElement } from 'chartjs-chart-treemap'; |
|
|
import { TreemapController, TreemapElement } from 'chartjs-chart-treemap'; |
|
|
import { isUUID } from 'class-validator'; |
|
|
import { isUUID } from 'class-validator'; |
|
|
@ -154,6 +153,23 @@ export class GfTreemapChartComponent |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private getHolding( |
|
|
|
|
|
chart: Chart<'treemap'>, |
|
|
|
|
|
activeElement: ActiveElement |
|
|
|
|
|
): PortfolioPosition | undefined { |
|
|
|
|
|
if (!activeElement) { |
|
|
|
|
|
return undefined; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const dataset = orderBy( |
|
|
|
|
|
chart.data.datasets[activeElement.datasetIndex].tree, |
|
|
|
|
|
['allocationInPercentage'], |
|
|
|
|
|
['desc'] |
|
|
|
|
|
) as PortfolioPosition[]; |
|
|
|
|
|
|
|
|
|
|
|
return dataset[activeElement.index]; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
private initialize() { |
|
|
private initialize() { |
|
|
const holdings = this.holdings(); |
|
|
const holdings = this.holdings(); |
|
|
|
|
|
|
|
|
@ -323,27 +339,24 @@ export class GfTreemapChartComponent |
|
|
animation: false, |
|
|
animation: false, |
|
|
onClick: (_, activeElements, chart: Chart<'treemap'>) => { |
|
|
onClick: (_, activeElements, chart: Chart<'treemap'>) => { |
|
|
try { |
|
|
try { |
|
|
const dataIndex = activeElements[0].index; |
|
|
const holding = this.getHolding(chart, activeElements[0]); |
|
|
const datasetIndex = activeElements[0].datasetIndex; |
|
|
|
|
|
|
|
|
|
|
|
const dataset = orderBy( |
|
|
if (holding && canOpenHoldingDetail(holding)) { |
|
|
chart.data.datasets[datasetIndex].tree, |
|
|
this.treemapChartClicked.emit({ |
|
|
['allocationInPercentage'], |
|
|
dataSource: holding.assetProfile.dataSource, |
|
|
['desc'] |
|
|
symbol: holding.assetProfile.symbol |
|
|
) as PortfolioPosition[]; |
|
|
}); |
|
|
|
|
|
} |
|
|
const dataSource: DataSource = |
|
|
|
|
|
dataset[dataIndex].assetProfile.dataSource; |
|
|
|
|
|
|
|
|
|
|
|
const symbol: string = dataset[dataIndex].assetProfile.symbol; |
|
|
|
|
|
|
|
|
|
|
|
this.treemapChartClicked.emit({ dataSource, symbol }); |
|
|
|
|
|
} catch {} |
|
|
} catch {} |
|
|
}, |
|
|
}, |
|
|
onHover: (event, chartElement) => { |
|
|
onHover: (event, chartElements, chart: Chart<'treemap'>) => { |
|
|
if (this.cursor()) { |
|
|
if (this.cursor()) { |
|
|
|
|
|
const holding = this.getHolding(chart, chartElements[0]); |
|
|
|
|
|
|
|
|
(event.native?.target as HTMLElement).style.cursor = |
|
|
(event.native?.target as HTMLElement).style.cursor = |
|
|
chartElement[0] ? this.cursor() : 'default'; |
|
|
holding && canOpenHoldingDetail(holding) |
|
|
|
|
|
? this.cursor() |
|
|
|
|
|
: 'default'; |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
plugins: { |
|
|
plugins: { |
|
|
|