balibabu
commited on
Commit
·
38b46ea
1
Parent(s):
7f2b93e
Fix: Fixed the issue that the page crashed when the node ID was the same as the combo ID #4180 (#4191)
Browse files### What problem does this PR solve?
Fix: Fixed the issue that the page crashed when the node ID was the same
as the combo ID #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/util.ts +11 -4
- web/src/pages/force-graph/constant.ts +0 -241
- web/src/pages/force-graph/index.less +0 -4
- web/src/pages/force-graph/index.tsx +0 -3
- web/src/pages/force-graph/input-upload.tsx +0 -59
- web/src/pages/force-graph/next.tsx +0 -37
- web/src/pages/force-graph/util.ts +0 -55
- web/src/routes.ts +0 -5
web/src/pages/add-knowledge/components/knowledge-chunk/components/knowledge-graph/util.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
import { isEmpty } from 'lodash';
|
|
|
|
| 2 |
|
| 3 |
class KeyGenerator {
|
| 4 |
idx = 0;
|
|
@@ -64,16 +65,22 @@ export const isDataExist = (data: any) => {
|
|
| 64 |
|
| 65 |
export const buildNodesAndCombos = (nodes: any[]) => {
|
| 66 |
const combos: any[] = [];
|
| 67 |
-
|
| 68 |
const combo = Array.isArray(x?.communities) ? x.communities[0] : undefined;
|
| 69 |
-
if (combo && combos.every((y) => y.
|
| 70 |
combos.push({
|
| 71 |
-
id:
|
|
|
|
|
|
|
|
|
|
| 72 |
});
|
| 73 |
}
|
|
|
|
|
|
|
|
|
|
| 74 |
return {
|
| 75 |
...x,
|
| 76 |
-
combo,
|
| 77 |
};
|
| 78 |
});
|
| 79 |
|
|
|
|
| 1 |
import { isEmpty } from 'lodash';
|
| 2 |
+
import { v4 as uuid } from 'uuid';
|
| 3 |
|
| 4 |
class KeyGenerator {
|
| 5 |
idx = 0;
|
|
|
|
| 65 |
|
| 66 |
export const buildNodesAndCombos = (nodes: any[]) => {
|
| 67 |
const combos: any[] = [];
|
| 68 |
+
nodes.forEach((x) => {
|
| 69 |
const combo = Array.isArray(x?.communities) ? x.communities[0] : undefined;
|
| 70 |
+
if (combo && combos.every((y) => y.data.label !== combo)) {
|
| 71 |
combos.push({
|
| 72 |
+
id: uuid(),
|
| 73 |
+
data: {
|
| 74 |
+
label: combo,
|
| 75 |
+
},
|
| 76 |
});
|
| 77 |
}
|
| 78 |
+
});
|
| 79 |
+
|
| 80 |
+
const nextNodes = nodes.map((x) => {
|
| 81 |
return {
|
| 82 |
...x,
|
| 83 |
+
combo: combos.find((y) => y.data.label === x.id)?.id,
|
| 84 |
};
|
| 85 |
});
|
| 86 |
|
web/src/pages/force-graph/constant.ts
DELETED
|
@@ -1,241 +0,0 @@
|
|
| 1 |
-
const nodes = [
|
| 2 |
-
{
|
| 3 |
-
type: '"ORGANIZATION"',
|
| 4 |
-
description:
|
| 5 |
-
'"厦门象屿是一家公司,其营业收入和市场占有率在2018年至2022年间有所变化。"',
|
| 6 |
-
source_id: '0',
|
| 7 |
-
id: '"厦门象屿"',
|
| 8 |
-
},
|
| 9 |
-
{
|
| 10 |
-
type: '"EVENT"',
|
| 11 |
-
description:
|
| 12 |
-
'"2018年是一个时间点,标志着厦门象屿营业收入和市场占有率的记录开始。"',
|
| 13 |
-
source_id: '0',
|
| 14 |
-
entity_type: '"EVENT"',
|
| 15 |
-
id: '"2018"',
|
| 16 |
-
},
|
| 17 |
-
{
|
| 18 |
-
type: '"EVENT"',
|
| 19 |
-
description:
|
| 20 |
-
'"2019年是一个时间点,厦门象屿的营业收入和市场占有率在此期间有所变化。"',
|
| 21 |
-
source_id: '0',
|
| 22 |
-
entity_type: '"EVENT"',
|
| 23 |
-
id: '"2019"',
|
| 24 |
-
},
|
| 25 |
-
{
|
| 26 |
-
type: '"EVENT"',
|
| 27 |
-
description:
|
| 28 |
-
'"2020年是一个时间点,厦门象屿的营业收入和市场占有率在此期间有所变化。"',
|
| 29 |
-
source_id: '0',
|
| 30 |
-
entity_type: '"EVENT"',
|
| 31 |
-
id: '"2020"',
|
| 32 |
-
},
|
| 33 |
-
{
|
| 34 |
-
type: '"EVENT"',
|
| 35 |
-
description:
|
| 36 |
-
'"2021年是一个时间点,厦门象屿的营业收入和市场占有率在此期间有所变化。"',
|
| 37 |
-
source_id: '0',
|
| 38 |
-
entity_type: '"EVENT"',
|
| 39 |
-
id: '"2021"',
|
| 40 |
-
},
|
| 41 |
-
{
|
| 42 |
-
type: '"EVENT"',
|
| 43 |
-
description:
|
| 44 |
-
'"2022年是一个时间点,厦门象屿的营业收入和市场占有率在此期间有所变化。"',
|
| 45 |
-
source_id: '0',
|
| 46 |
-
entity_type: '"EVENT"',
|
| 47 |
-
id: '"2022"',
|
| 48 |
-
},
|
| 49 |
-
{
|
| 50 |
-
type: '"ORGANIZATION"',
|
| 51 |
-
description:
|
| 52 |
-
'"厦门象屿股份有限公司是一家公司,中文简称为厦门象屿,外文名称为Xiamen Xiangyu Co.,Ltd.,外文名称缩写为Xiangyu,法定代表人为邓启东。"',
|
| 53 |
-
source_id: '1',
|
| 54 |
-
id: '"厦门象屿股份有限公司"',
|
| 55 |
-
},
|
| 56 |
-
{
|
| 57 |
-
type: '"PERSON"',
|
| 58 |
-
description: '"邓启东是厦门象屿股份有限公司的法定代表人。"',
|
| 59 |
-
source_id: '1',
|
| 60 |
-
entity_type: '"PERSON"',
|
| 61 |
-
id: '"邓启东"',
|
| 62 |
-
},
|
| 63 |
-
{
|
| 64 |
-
type: '"GEO"',
|
| 65 |
-
description: '"厦门是一个地理位置,与厦门象屿股份有限公司相关。"',
|
| 66 |
-
source_id: '1',
|
| 67 |
-
entity_type: '"GEO"',
|
| 68 |
-
id: '"厦门"',
|
| 69 |
-
},
|
| 70 |
-
{
|
| 71 |
-
type: '"PERSON"',
|
| 72 |
-
description:
|
| 73 |
-
'"廖杰 is the Board Secretary, responsible for handling board-related matters and communications."',
|
| 74 |
-
source_id: '2',
|
| 75 |
-
id: '"廖杰"',
|
| 76 |
-
},
|
| 77 |
-
{
|
| 78 |
-
type: '"PERSON"',
|
| 79 |
-
description:
|
| 80 |
-
'"史经洋 is the Securities Affairs Representative, responsible for handling securities-related matters and communications."',
|
| 81 |
-
source_id: '2',
|
| 82 |
-
entity_type: '"PERSON"',
|
| 83 |
-
id: '"史经洋"',
|
| 84 |
-
},
|
| 85 |
-
{
|
| 86 |
-
type: '"GEO"',
|
| 87 |
-
description:
|
| 88 |
-
'"A geographic location in Xiamen, specifically in the Free Trade Zone, where the company\'s office is situated."',
|
| 89 |
-
source_id: '2',
|
| 90 |
-
entity_type: '"GEO"',
|
| 91 |
-
id: '"厦门市湖里区自由贸易试验区厦门片区"',
|
| 92 |
-
},
|
| 93 |
-
{
|
| 94 |
-
type: '"GEO"',
|
| 95 |
-
description:
|
| 96 |
-
'"The building where the company\'s office is located, situated at Xiangyu Road, Xiamen."',
|
| 97 |
-
source_id: '2',
|
| 98 |
-
entity_type: '"GEO"',
|
| 99 |
-
id: '"象屿集团大厦"',
|
| 100 |
-
},
|
| 101 |
-
{
|
| 102 |
-
type: '"EVENT"',
|
| 103 |
-
description:
|
| 104 |
-
'"Refers to the year 2021, used for comparing financial metrics with the year 2022."',
|
| 105 |
-
source_id: '3',
|
| 106 |
-
id: '"2021年"',
|
| 107 |
-
},
|
| 108 |
-
{
|
| 109 |
-
type: '"EVENT"',
|
| 110 |
-
description:
|
| 111 |
-
'"Refers to the year 2022, used for presenting current financial metrics and comparing them with the year 2021."',
|
| 112 |
-
source_id: '3',
|
| 113 |
-
entity_type: '"EVENT"',
|
| 114 |
-
id: '"2022年"',
|
| 115 |
-
},
|
| 116 |
-
{
|
| 117 |
-
type: '"EVENT"',
|
| 118 |
-
description:
|
| 119 |
-
'"Indicates the focus on key financial metrics in the table, such as weighted averages and percentages."',
|
| 120 |
-
source_id: '3',
|
| 121 |
-
entity_type: '"EVENT"',
|
| 122 |
-
id: '"主要财务指标"',
|
| 123 |
-
},
|
| 124 |
-
].map(({ type, ...x }) => ({ ...x }));
|
| 125 |
-
|
| 126 |
-
const edges = [
|
| 127 |
-
{
|
| 128 |
-
weight: 2.0,
|
| 129 |
-
description: '"厦门象屿在2018年的营业收入和市场占有率被记录。"',
|
| 130 |
-
source_id: '0',
|
| 131 |
-
source: '"厦门象屿"',
|
| 132 |
-
target: '"2018"',
|
| 133 |
-
},
|
| 134 |
-
{
|
| 135 |
-
weight: 2.0,
|
| 136 |
-
description: '"厦门象屿在2019年的营业收入和市场占有率有所变化。"',
|
| 137 |
-
source_id: '0',
|
| 138 |
-
source: '"厦门象屿"',
|
| 139 |
-
target: '"2019"',
|
| 140 |
-
},
|
| 141 |
-
{
|
| 142 |
-
weight: 2.0,
|
| 143 |
-
description: '"厦门象屿在2020年的营业收入和市场占有率有所变化。"',
|
| 144 |
-
source_id: '0',
|
| 145 |
-
source: '"厦门象屿"',
|
| 146 |
-
target: '"2020"',
|
| 147 |
-
},
|
| 148 |
-
{
|
| 149 |
-
weight: 2.0,
|
| 150 |
-
description: '"厦门象屿在2021年的营业收入和市场占有率有所变化。"',
|
| 151 |
-
source_id: '0',
|
| 152 |
-
source: '"厦门象屿"',
|
| 153 |
-
target: '"2021"',
|
| 154 |
-
},
|
| 155 |
-
{
|
| 156 |
-
weight: 2.0,
|
| 157 |
-
description: '"厦门象屿在2022年的营业收入和市场占有率有所变化。"',
|
| 158 |
-
source_id: '0',
|
| 159 |
-
source: '"厦门象屿"',
|
| 160 |
-
target: '"2022"',
|
| 161 |
-
},
|
| 162 |
-
{
|
| 163 |
-
weight: 2.0,
|
| 164 |
-
description: '"厦门象屿股份有限公司的法定代表人是邓启东。"',
|
| 165 |
-
source_id: '1',
|
| 166 |
-
source: '"厦门象屿股份有限公司"',
|
| 167 |
-
target: '"邓启东"',
|
| 168 |
-
},
|
| 169 |
-
{
|
| 170 |
-
weight: 2.0,
|
| 171 |
-
description: '"厦门象屿股份有限公���位于厦门。"',
|
| 172 |
-
source_id: '1',
|
| 173 |
-
source: '"厦门象屿股份有限公司"',
|
| 174 |
-
target: '"厦门"',
|
| 175 |
-
},
|
| 176 |
-
{
|
| 177 |
-
weight: 2.0,
|
| 178 |
-
description:
|
| 179 |
-
'"廖杰\'s office is located in the Xiangyu Group Building, indicating his workplace."',
|
| 180 |
-
source_id: '2',
|
| 181 |
-
source: '"廖杰"',
|
| 182 |
-
target: '"象屿集团大厦"',
|
| 183 |
-
},
|
| 184 |
-
{
|
| 185 |
-
weight: 2.0,
|
| 186 |
-
description:
|
| 187 |
-
'"廖杰 works in the Xiamen Free Trade Zone, a specific area within Xiamen."',
|
| 188 |
-
source_id: '2',
|
| 189 |
-
source: '"廖杰"',
|
| 190 |
-
target: '"厦门市湖里区自由贸易试验区厦门片区"',
|
| 191 |
-
},
|
| 192 |
-
{
|
| 193 |
-
weight: 2.0,
|
| 194 |
-
description:
|
| 195 |
-
'"史经洋\'s office is also located in the Xiangyu Group Building, indicating his workplace."',
|
| 196 |
-
source_id: '2',
|
| 197 |
-
source: '"史经洋"',
|
| 198 |
-
target: '"象屿集团大厦"',
|
| 199 |
-
},
|
| 200 |
-
{
|
| 201 |
-
weight: 2.0,
|
| 202 |
-
description:
|
| 203 |
-
'"史经洋 works in the Xiamen Free Trade Zone, a specific area within Xiamen."',
|
| 204 |
-
source_id: '2',
|
| 205 |
-
source: '"史经洋"',
|
| 206 |
-
target: '"厦门市湖里区自由贸易试验区厦门片区"',
|
| 207 |
-
},
|
| 208 |
-
{
|
| 209 |
-
weight: 2.0,
|
| 210 |
-
description:
|
| 211 |
-
'"The years 2021 and 2022 are related as they are used for comparing financial metrics, showing changes and adjustments over time."',
|
| 212 |
-
source_id: '3',
|
| 213 |
-
source: '"2021年"',
|
| 214 |
-
target: '"2022年"',
|
| 215 |
-
},
|
| 216 |
-
{
|
| 217 |
-
weight: 2.0,
|
| 218 |
-
description:
|
| 219 |
-
'"The \'主要财务指标\' is related to the year 2021 as it provides the basis for financial comparisons and adjustments."',
|
| 220 |
-
source_id: '3',
|
| 221 |
-
source: '"2021年"',
|
| 222 |
-
target: '"主要财务指标"',
|
| 223 |
-
},
|
| 224 |
-
{
|
| 225 |
-
weight: 2.0,
|
| 226 |
-
description:
|
| 227 |
-
'"The \'主要财务指标\' is related to the year 2022 as it presents the current financial metrics and their changes compared to 2021."',
|
| 228 |
-
source_id: '3',
|
| 229 |
-
source: '"2022年"',
|
| 230 |
-
target: '"主要财务指标"',
|
| 231 |
-
},
|
| 232 |
-
];
|
| 233 |
-
|
| 234 |
-
export const graphData = {
|
| 235 |
-
directed: false,
|
| 236 |
-
multigraph: false,
|
| 237 |
-
graph: {},
|
| 238 |
-
nodes,
|
| 239 |
-
edges,
|
| 240 |
-
combos: [],
|
| 241 |
-
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
web/src/pages/force-graph/index.less
DELETED
|
@@ -1,4 +0,0 @@
|
|
| 1 |
-
.container {
|
| 2 |
-
width: 100%;
|
| 3 |
-
height: 100%;
|
| 4 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
web/src/pages/force-graph/index.tsx
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
import InputWithUpload from './input-upload';
|
| 2 |
-
|
| 3 |
-
export default InputWithUpload;
|
|
|
|
|
|
|
|
|
|
|
|
web/src/pages/force-graph/input-upload.tsx
DELETED
|
@@ -1,59 +0,0 @@
|
|
| 1 |
-
import { Authorization } from '@/constants/authorization';
|
| 2 |
-
import { getAuthorization } from '@/utils/authorization-util';
|
| 3 |
-
import { PlusOutlined } from '@ant-design/icons';
|
| 4 |
-
import type { UploadFile, UploadProps } from 'antd';
|
| 5 |
-
import { Image, Input, Upload } from 'antd';
|
| 6 |
-
import { useState } from 'react';
|
| 7 |
-
|
| 8 |
-
const InputWithUpload = () => {
|
| 9 |
-
const [previewOpen, setPreviewOpen] = useState(false);
|
| 10 |
-
const [previewImage, setPreviewImage] = useState('');
|
| 11 |
-
const [fileList, setFileList] = useState<UploadFile[]>([]);
|
| 12 |
-
|
| 13 |
-
const handleChange: UploadProps['onChange'] = ({ fileList: newFileList }) =>
|
| 14 |
-
setFileList(newFileList);
|
| 15 |
-
|
| 16 |
-
const uploadButton = (
|
| 17 |
-
<button style={{ border: 0, background: 'none' }} type="button">
|
| 18 |
-
<PlusOutlined />
|
| 19 |
-
<div style={{ marginTop: 8 }}>Upload</div>
|
| 20 |
-
</button>
|
| 21 |
-
);
|
| 22 |
-
return (
|
| 23 |
-
<>
|
| 24 |
-
<Input placeholder="Basic usage"></Input>
|
| 25 |
-
<Upload
|
| 26 |
-
action="/v1/document/upload_and_parse"
|
| 27 |
-
listType="picture-card"
|
| 28 |
-
fileList={fileList}
|
| 29 |
-
onChange={handleChange}
|
| 30 |
-
multiple
|
| 31 |
-
headers={{ [Authorization]: getAuthorization() }}
|
| 32 |
-
data={{ conversation_id: '9e9f7d2453e511efb18efa163e197198' }}
|
| 33 |
-
method="post"
|
| 34 |
-
>
|
| 35 |
-
{fileList.length >= 8 ? null : uploadButton}
|
| 36 |
-
</Upload>
|
| 37 |
-
{previewImage && (
|
| 38 |
-
<Image
|
| 39 |
-
wrapperStyle={{ display: 'none' }}
|
| 40 |
-
preview={{
|
| 41 |
-
visible: previewOpen,
|
| 42 |
-
onVisibleChange: (visible) => setPreviewOpen(visible),
|
| 43 |
-
afterOpenChange: (visible) => !visible && setPreviewImage(''),
|
| 44 |
-
}}
|
| 45 |
-
src={previewImage}
|
| 46 |
-
/>
|
| 47 |
-
)}
|
| 48 |
-
</>
|
| 49 |
-
);
|
| 50 |
-
};
|
| 51 |
-
|
| 52 |
-
export default () => {
|
| 53 |
-
return (
|
| 54 |
-
<section style={{ height: 500, width: 400 }}>
|
| 55 |
-
<div style={{ height: 200 }}></div>
|
| 56 |
-
<InputWithUpload></InputWithUpload>
|
| 57 |
-
</section>
|
| 58 |
-
);
|
| 59 |
-
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
web/src/pages/force-graph/next.tsx
DELETED
|
@@ -1,37 +0,0 @@
|
|
| 1 |
-
import { useEffect, useRef } from 'react';
|
| 2 |
-
import { ForceGraph2D } from 'react-force-graph';
|
| 3 |
-
import { graphData } from './constant';
|
| 4 |
-
|
| 5 |
-
const Next = () => {
|
| 6 |
-
const graphRef = useRef<ForceGraph2D>();
|
| 7 |
-
|
| 8 |
-
useEffect(() => {
|
| 9 |
-
graphRef.current.d3Force('cluster');
|
| 10 |
-
}, []);
|
| 11 |
-
|
| 12 |
-
return (
|
| 13 |
-
<div>
|
| 14 |
-
<ForceGraph2D
|
| 15 |
-
ref={graphRef}
|
| 16 |
-
graphData={graphData}
|
| 17 |
-
nodeAutoColorBy={'type'}
|
| 18 |
-
nodeLabel={(node) => {
|
| 19 |
-
return node.id;
|
| 20 |
-
}}
|
| 21 |
-
// nodeVal={(node) => {
|
| 22 |
-
// return <div>xxx</div>;
|
| 23 |
-
// }}
|
| 24 |
-
// nodeVal={(node) => 100 / (node.level + 1)}
|
| 25 |
-
linkAutoColorBy={'type'}
|
| 26 |
-
nodeCanvasObjectMode={() => 'after'}
|
| 27 |
-
nodeCanvasObject={(node, ctx) => {
|
| 28 |
-
console.info(ctx);
|
| 29 |
-
return ctx.canvas;
|
| 30 |
-
}}
|
| 31 |
-
// nodeVal={'id'}
|
| 32 |
-
/>
|
| 33 |
-
</div>
|
| 34 |
-
);
|
| 35 |
-
};
|
| 36 |
-
|
| 37 |
-
export default Next;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
web/src/pages/force-graph/util.ts
DELETED
|
@@ -1,55 +0,0 @@
|
|
| 1 |
-
class KeyGenerator {
|
| 2 |
-
idx = 0;
|
| 3 |
-
chars: string[] = [];
|
| 4 |
-
constructor() {
|
| 5 |
-
const chars = Array(26)
|
| 6 |
-
.fill(1)
|
| 7 |
-
.map((x, idx) => String.fromCharCode(97 + idx)); // 26 char
|
| 8 |
-
this.chars = chars;
|
| 9 |
-
}
|
| 10 |
-
generateKey() {
|
| 11 |
-
const key = this.chars[this.idx];
|
| 12 |
-
this.idx++;
|
| 13 |
-
return key;
|
| 14 |
-
}
|
| 15 |
-
}
|
| 16 |
-
|
| 17 |
-
// Classify nodes based on edge relationships
|
| 18 |
-
export class Converter {
|
| 19 |
-
keyGenerator;
|
| 20 |
-
dict: Record<string, string> = {}; // key is node id, value is combo
|
| 21 |
-
constructor() {
|
| 22 |
-
this.keyGenerator = new KeyGenerator();
|
| 23 |
-
}
|
| 24 |
-
buildDict(edges: { source: string; target: string }[]) {
|
| 25 |
-
edges.forEach((x) => {
|
| 26 |
-
if (this.dict[x.source] && !this.dict[x.target]) {
|
| 27 |
-
this.dict[x.target] = this.dict[x.source];
|
| 28 |
-
} else if (!this.dict[x.source] && this.dict[x.target]) {
|
| 29 |
-
this.dict[x.source] = this.dict[x.target];
|
| 30 |
-
} else if (!this.dict[x.source] && !this.dict[x.target]) {
|
| 31 |
-
this.dict[x.source] = this.dict[x.target] =
|
| 32 |
-
this.keyGenerator.generateKey();
|
| 33 |
-
}
|
| 34 |
-
});
|
| 35 |
-
return this.dict;
|
| 36 |
-
}
|
| 37 |
-
buildNodesAndCombos(nodes: any[], edges: any[]) {
|
| 38 |
-
this.buildDict(edges);
|
| 39 |
-
const nextNodes = nodes.map((x) => ({ ...x, combo: this.dict[x.id] }));
|
| 40 |
-
|
| 41 |
-
const combos = Object.values(this.dict).reduce<any[]>((pre, cur) => {
|
| 42 |
-
if (pre.every((x) => x.id !== cur)) {
|
| 43 |
-
pre.push({
|
| 44 |
-
id: cur,
|
| 45 |
-
data: {
|
| 46 |
-
label: `Combo ${cur}`,
|
| 47 |
-
},
|
| 48 |
-
});
|
| 49 |
-
}
|
| 50 |
-
return pre;
|
| 51 |
-
}, []);
|
| 52 |
-
|
| 53 |
-
return { nodes: nextNodes, combos };
|
| 54 |
-
}
|
| 55 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
web/src/routes.ts
CHANGED
|
@@ -129,11 +129,6 @@ const routes = [
|
|
| 129 |
component: '@/pages/document-viewer',
|
| 130 |
layout: false,
|
| 131 |
},
|
| 132 |
-
{
|
| 133 |
-
path: 'force',
|
| 134 |
-
component: '@/pages/force-graph',
|
| 135 |
-
layout: false,
|
| 136 |
-
},
|
| 137 |
{
|
| 138 |
path: '/*',
|
| 139 |
component: '@/pages/404',
|
|
|
|
| 129 |
component: '@/pages/document-viewer',
|
| 130 |
layout: false,
|
| 131 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 132 |
{
|
| 133 |
path: '/*',
|
| 134 |
component: '@/pages/404',
|