balibabu
commited on
Commit
·
3f568cf
1
Parent(s):
4ac524c
Fix: Fixed the issue that the graph could not display the grouping #4180 (#4306)
Browse files### What problem does this PR solve?
Fix: Fixed the issue that the graph could not display the grouping #4180
### Type of change
- [x] Bug Fix (non-breaking change which fixes an issue)
web/src/pages/add-knowledge/components/knowledge-chunk/components/knowledge-graph/force-graph.tsx
CHANGED
|
@@ -50,6 +50,9 @@ const ForceGraph = ({ data, show }: IProps) => {
|
|
| 50 |
enterable: true,
|
| 51 |
getContent: (e: IElementEvent, items: ElementDatum) => {
|
| 52 |
if (Array.isArray(items)) {
|
|
|
|
|
|
|
|
|
|
| 53 |
let result = ``;
|
| 54 |
items.forEach((item) => {
|
| 55 |
result += `<section style="color:${TooltipColorMap[e['targetType'] as keyof typeof TooltipColorMap]};"><h3>${item?.id}</h3>`;
|
|
|
|
| 50 |
enterable: true,
|
| 51 |
getContent: (e: IElementEvent, items: ElementDatum) => {
|
| 52 |
if (Array.isArray(items)) {
|
| 53 |
+
if (items.some((x) => x?.isCombo)) {
|
| 54 |
+
return `<p style="font-weight:600;color:red">${items?.[0]?.data?.label}</p>`;
|
| 55 |
+
}
|
| 56 |
let result = ``;
|
| 57 |
items.forEach((item) => {
|
| 58 |
result += `<section style="color:${TooltipColorMap[e['targetType'] as keyof typeof TooltipColorMap]};"><h3>${item?.id}</h3>`;
|
web/src/pages/add-knowledge/components/knowledge-chunk/components/knowledge-graph/util.ts
CHANGED
|
@@ -63,12 +63,18 @@ export const isDataExist = (data: any) => {
|
|
| 63 |
);
|
| 64 |
};
|
| 65 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
export const buildNodesAndCombos = (nodes: any[]) => {
|
| 67 |
const combos: any[] = [];
|
| 68 |
nodes.forEach((x) => {
|
| 69 |
-
const combo =
|
| 70 |
if (combo && combos.every((y) => y.data.label !== combo)) {
|
| 71 |
combos.push({
|
|
|
|
| 72 |
id: uuid(),
|
| 73 |
data: {
|
| 74 |
label: combo,
|
|
@@ -80,7 +86,7 @@ export const buildNodesAndCombos = (nodes: any[]) => {
|
|
| 80 |
const nextNodes = nodes.map((x) => {
|
| 81 |
return {
|
| 82 |
...x,
|
| 83 |
-
combo: combos.find((y) => y.data.label === x
|
| 84 |
};
|
| 85 |
});
|
| 86 |
|
|
|
|
| 63 |
);
|
| 64 |
};
|
| 65 |
|
| 66 |
+
const findCombo = (communities: string[]) => {
|
| 67 |
+
const combo = Array.isArray(communities) ? communities[0] : undefined;
|
| 68 |
+
return combo;
|
| 69 |
+
};
|
| 70 |
+
|
| 71 |
export const buildNodesAndCombos = (nodes: any[]) => {
|
| 72 |
const combos: any[] = [];
|
| 73 |
nodes.forEach((x) => {
|
| 74 |
+
const combo = findCombo(x?.communities);
|
| 75 |
if (combo && combos.every((y) => y.data.label !== combo)) {
|
| 76 |
combos.push({
|
| 77 |
+
isCombo: true,
|
| 78 |
id: uuid(),
|
| 79 |
data: {
|
| 80 |
label: combo,
|
|
|
|
| 86 |
const nextNodes = nodes.map((x) => {
|
| 87 |
return {
|
| 88 |
...x,
|
| 89 |
+
combo: combos.find((y) => y.data.label === findCombo(x?.communities))?.id,
|
| 90 |
};
|
| 91 |
});
|
| 92 |
|