ui: fix endpointing sankey main node calculation

This commit is contained in:
nick-delirium 2025-05-05 17:37:54 +02:00 committed by Delirium
parent b477f9637d
commit 360d6ca382
2 changed files with 5 additions and 2 deletions

View file

@ -34,11 +34,12 @@ interface Props {
onChartClick?: (filters: any[]) => void; onChartClick?: (filters: any[]) => void;
isUngrouped?: boolean; isUngrouped?: boolean;
inGrid?: boolean; inGrid?: boolean;
startPoint: 'end' | 'start'
} }
const EChartsSankey: React.FC<Props> = (props) => { const EChartsSankey: React.FC<Props> = (props) => {
const { t } = useTranslation(); const { t } = useTranslation();
const { data, height = 240, onChartClick, isUngrouped } = props; const { data, height = 240, onChartClick, isUngrouped, startPoint } = props;
const chartRef = React.useRef<HTMLDivElement>(null); const chartRef = React.useRef<HTMLDivElement>(null);
const [finalNodeCount, setFinalNodeCount] = React.useState(data.nodes.length); const [finalNodeCount, setFinalNodeCount] = React.useState(data.nodes.length);
@ -110,8 +111,9 @@ const EChartsSankey: React.FC<Props> = (props) => {
if (echartNodes.length === 0) return; if (echartNodes.length === 0) return;
const mainNodeLink = startPoint === 'end' ? echartNodes.findIndex(n => n.id === 0) : 0;
const startNodeValue = echartLinks const startNodeValue = echartLinks
.filter((link) => link.source === 0) .filter((link) => startPoint === 'start' ? link.source === mainNodeLink : link.target === mainNodeLink)
.reduce((sum, link) => sum + link.value, 0); .reduce((sum, link) => sum + link.value, 0);
Object.keys(nodeValues).forEach((nodeId) => { Object.keys(nodeValues).forEach((nodeId) => {

View file

@ -538,6 +538,7 @@ function WidgetChart(props: Props) {
dashboardStore.drillDownFilter.merge({ filters, page: 1 }); dashboardStore.drillDownFilter.merge({ filters, page: 1 });
}} }}
isUngrouped={isUngrouped} isUngrouped={isUngrouped}
startPoint={metric.startType}
/> />
); );
} }