Skip to content
Snippets Groups Projects
Commit 0dfed6ed authored by Marcos Pieras's avatar Marcos Pieras Committed by Marcos Pieras
Browse files

feat(visKPI): updates with new count

parent 65492044
Branches
Tags v1.172.0
1 merge request!502feat(visKPI): updates with new count
Pipeline #148599 passed
import { Button } from '@/lib/components/buttons';
import { Input } from '@/lib/components/inputs';
import { EntityPill, RelationPill } from '@/lib/components/pills/Pill';
import { useActiveQuery, useActiveSaveState } from '@/lib/data-access';
import { useActiveQuery, useActiveSaveState, useGraphQueryCounts } from '@/lib/data-access';
import { SettingsContainer } from '@/lib/vis/components/config';
import html2canvas from 'html2canvas';
import React, { forwardRef, useEffect, useImperativeHandle, useRef, useState } from 'react';
......@@ -33,6 +33,7 @@ const formatNumber = (number: number) => {
const Vis0D = forwardRef<Vis0DVisHandle, VisualizationPropTypes<Vis0DProps>>(({ data, settings, graphMetadata }, refExternal) => {
const [statRender, setStatRender] = useState<number | undefined>(undefined);
const activeQuery = useActiveQuery();
const countsGraph = useGraphQueryCounts();
const internalRef = useRef<HTMLDivElement>(null);
useImperativeHandle(refExternal, () => ({
......@@ -71,7 +72,13 @@ const Vis0D = forwardRef<Vis0DVisHandle, VisualizationPropTypes<Vis0DProps>>(({
}));
useEffect(() => {
if (settings.selectedEntity != '' && graphMetadata.nodes.types && settings.selectedAttribute != '' && settings.selectedStat != '') {
if (
settings.selectedEntity != '' &&
graphMetadata.nodes.types &&
settings.selectedAttribute != '' &&
settings.selectedStat != '' &&
!settings.showTotal
) {
const nodesLabels = graphMetadata.nodes.labels;
const edgesLabels = graphMetadata.edges.labels;
......@@ -87,22 +94,6 @@ const Vis0D = forwardRef<Vis0DVisHandle, VisualizationPropTypes<Vis0DProps>>(({
return;
}
if (settings.showTotal) {
let statValue = 0;
if (nodesLabels.includes(settings.selectedEntity)) {
const keys = activeQuery?.graph.nodes.filter(node => node.attributes.schemaKey === settings.selectedEntity).map(node => node.key);
if (!keys || keys.length === 0) return;
statValue = keys.reduce((acc, key) => {
acc += activeQuery?.graphCounts.nodeCounts?.[key + '_count'] ?? 0;
return acc;
}, 0);
} else {
statValue = graphMetadata.edges.types[settings.selectedEntity].count;
}
setStatRender(statValue);
return;
}
// Actual stat calculation
let statsAvailable = [];
......@@ -128,8 +119,39 @@ const Vis0D = forwardRef<Vis0DVisHandle, VisualizationPropTypes<Vis0DProps>>(({
} else {
setStatRender(undefined);
}
} else if (settings.selectedEntity != '' && graphMetadata.nodes && graphMetadata.edges && settings.showTotal) {
const nodesLabels = graphMetadata.nodes.labels;
if (settings.showTotal) {
if (nodesLabels.includes(settings.selectedEntity) && countsGraph?.nodeCounts.updatedAt !== 0) {
const keys = activeQuery?.graph.nodes.filter(node => node.attributes.schemaKey === settings.selectedEntity).map(node => node.key);
if (!keys || keys.length === 0) return;
const statValue = keys.reduce((acc, key) => {
acc += countsGraph?.nodeCounts?.[key + '_count'];
return acc;
}, 0);
if (Number.isNaN(statValue)) {
setStatRender(undefined);
} else {
setStatRender(statValue);
}
} else if (graphMetadata.edges.labels.includes(settings.selectedEntity)) {
const statValue = graphMetadata.edges.types[settings.selectedEntity].count;
setStatRender(statValue);
} else {
setStatRender(undefined);
}
}
}
}, [settings.selectedEntity, settings.selectedAttribute, settings.selectedStat, settings.showTotal]);
}, [
settings.selectedEntity,
settings.selectedAttribute,
settings.selectedStat,
settings.showTotal,
activeQuery?.graph.nodes,
graphMetadata,
countsGraph,
]);
return (
<div className="h-full w-full flex flex-col items-center justify-center overflow-hidden" ref={internalRef}>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment