balibabu
commited on
Commit
·
9e42ef1
1
Parent(s):
c60fd19
feat: Translate ForceGraph #162 (#1810)
Browse files### What problem does this PR solve?
feat: Translate ForceGraph #162
### Type of change
- [x] New Feature (non-breaking change which adds functionality)
- web/src/locales/en.ts +2 -0
- web/src/locales/zh-traditional.ts +2 -0
- web/src/locales/zh.ts +2 -0
- web/src/pages/add-knowledge/components/knowledge-chunk/components/knowledge-graph/force-graph.tsx +1 -1
- web/src/pages/add-knowledge/components/knowledge-chunk/components/knowledge-graph/indented-tree.tsx +4 -40
- web/src/pages/add-knowledge/components/knowledge-chunk/components/knowledge-graph/modal.tsx +12 -3
web/src/locales/en.ts
CHANGED
|
@@ -307,6 +307,8 @@ The above is the content you need to summarize.`,
|
|
| 307 |
chunkMessage: 'Please input value!',
|
| 308 |
full: 'Full text',
|
| 309 |
ellipse: 'Ellipse',
|
|
|
|
|
|
|
| 310 |
},
|
| 311 |
chat: {
|
| 312 |
newConversation: 'New conversation',
|
|
|
|
| 307 |
chunkMessage: 'Please input value!',
|
| 308 |
full: 'Full text',
|
| 309 |
ellipse: 'Ellipse',
|
| 310 |
+
graph: 'Knowledge graph',
|
| 311 |
+
mind: 'Mind map',
|
| 312 |
},
|
| 313 |
chat: {
|
| 314 |
newConversation: 'New conversation',
|
web/src/locales/zh-traditional.ts
CHANGED
|
@@ -279,6 +279,8 @@ export default {
|
|
| 279 |
chunkMessage: '請輸入值!',
|
| 280 |
full: '全文',
|
| 281 |
ellipse: '省略',
|
|
|
|
|
|
|
| 282 |
},
|
| 283 |
chat: {
|
| 284 |
newConversation: '新會話',
|
|
|
|
| 279 |
chunkMessage: '請輸入值!',
|
| 280 |
full: '全文',
|
| 281 |
ellipse: '省略',
|
| 282 |
+
graph: '知識圖譜',
|
| 283 |
+
mind: '心智圖',
|
| 284 |
},
|
| 285 |
chat: {
|
| 286 |
newConversation: '新會話',
|
web/src/locales/zh.ts
CHANGED
|
@@ -296,6 +296,8 @@ export default {
|
|
| 296 |
chunkMessage: '请输入值!',
|
| 297 |
full: '全文',
|
| 298 |
ellipse: '省略',
|
|
|
|
|
|
|
| 299 |
},
|
| 300 |
chat: {
|
| 301 |
newConversation: '新会话',
|
|
|
|
| 296 |
chunkMessage: '请输入值!',
|
| 297 |
full: '全文',
|
| 298 |
ellipse: '省略',
|
| 299 |
+
graph: '知识图谱',
|
| 300 |
+
mind: '思维导图',
|
| 301 |
},
|
| 302 |
chat: {
|
| 303 |
newConversation: '新会话',
|
web/src/pages/add-knowledge/components/knowledge-chunk/components/knowledge-graph/force-graph.tsx
CHANGED
|
@@ -127,7 +127,7 @@ const ForceGraph = ({ data, show }: IProps) => {
|
|
| 127 |
ref={containerRef}
|
| 128 |
className={styles.forceContainer}
|
| 129 |
style={{
|
| 130 |
-
width: '
|
| 131 |
height: '80vh',
|
| 132 |
display: show ? 'block' : 'none',
|
| 133 |
}}
|
|
|
|
| 127 |
ref={containerRef}
|
| 128 |
className={styles.forceContainer}
|
| 129 |
style={{
|
| 130 |
+
width: '90vw',
|
| 131 |
height: '80vh',
|
| 132 |
display: show ? 'block' : 'none',
|
| 133 |
}}
|
web/src/pages/add-knowledge/components/knowledge-chunk/components/knowledge-graph/indented-tree.tsx
CHANGED
|
@@ -18,7 +18,7 @@ import { TreeData } from '@antv/g6/lib/types';
|
|
| 18 |
import isEmpty from 'lodash/isEmpty';
|
| 19 |
import { useCallback, useEffect, useRef } from 'react';
|
| 20 |
|
| 21 |
-
const rootId = '
|
| 22 |
|
| 23 |
const COLORS = [
|
| 24 |
'#5B8FF9',
|
|
@@ -35,7 +35,7 @@ const COLORS = [
|
|
| 35 |
|
| 36 |
const TreeEvent = {
|
| 37 |
COLLAPSE_EXPAND: 'collapse-expand',
|
| 38 |
-
|
| 39 |
};
|
| 40 |
|
| 41 |
class IndentedNode extends BaseNode {
|
|
@@ -204,16 +204,6 @@ class IndentedNode extends BaseNode {
|
|
| 204 |
};
|
| 205 |
}
|
| 206 |
|
| 207 |
-
drawAddShape(attributes: any, container: any) {
|
| 208 |
-
const addStyle = this.getAddStyle(attributes);
|
| 209 |
-
const btn = this.upsert('add', Badge, addStyle as any, container);
|
| 210 |
-
|
| 211 |
-
this.forwardEvent(btn, CommonEvent.CLICK, (event: any) => {
|
| 212 |
-
event.stopPropagation();
|
| 213 |
-
attributes.context.graph.emit(TreeEvent.ADD_CHILD, { id: this.id });
|
| 214 |
-
});
|
| 215 |
-
}
|
| 216 |
-
|
| 217 |
render(attributes = this.parsedAttributes, container = this) {
|
| 218 |
super.render(attributes, container);
|
| 219 |
|
|
@@ -221,7 +211,6 @@ class IndentedNode extends BaseNode {
|
|
| 221 |
|
| 222 |
this.drawIconArea(attributes, container);
|
| 223 |
this.drawCollapseShape(attributes, container);
|
| 224 |
-
this.drawAddShape(attributes, container);
|
| 225 |
}
|
| 226 |
}
|
| 227 |
|
|
@@ -255,7 +244,6 @@ class CollapseExpandTree extends BaseBehavior {
|
|
| 255 |
graph.on(NodeEvent.POINTER_ENTER, this.showIcon);
|
| 256 |
graph.on(NodeEvent.POINTER_LEAVE, this.hideIcon);
|
| 257 |
graph.on(TreeEvent.COLLAPSE_EXPAND, this.onCollapseExpand);
|
| 258 |
-
graph.on(TreeEvent.ADD_CHILD, this.addChild);
|
| 259 |
}
|
| 260 |
|
| 261 |
unbindEvents() {
|
|
@@ -264,7 +252,6 @@ class CollapseExpandTree extends BaseBehavior {
|
|
| 264 |
graph.off(NodeEvent.POINTER_ENTER, this.showIcon);
|
| 265 |
graph.off(NodeEvent.POINTER_LEAVE, this.hideIcon);
|
| 266 |
graph.off(TreeEvent.COLLAPSE_EXPAND, this.onCollapseExpand);
|
| 267 |
-
graph.off(TreeEvent.ADD_CHILD, this.addChild);
|
| 268 |
}
|
| 269 |
|
| 270 |
status = 'idle';
|
|
@@ -294,28 +281,6 @@ class CollapseExpandTree extends BaseBehavior {
|
|
| 294 |
else await graph.expandElement(id);
|
| 295 |
this.status = 'idle';
|
| 296 |
};
|
| 297 |
-
|
| 298 |
-
addChild(event: any) {
|
| 299 |
-
const {
|
| 300 |
-
onCreateChild = () => ({
|
| 301 |
-
id: `${Date.now()}`,
|
| 302 |
-
style: { labelText: 'new node' },
|
| 303 |
-
}),
|
| 304 |
-
} = this.options;
|
| 305 |
-
const { graph } = this.context;
|
| 306 |
-
const datum = onCreateChild(event.id);
|
| 307 |
-
graph.addNodeData([datum]);
|
| 308 |
-
graph.addEdgeData([{ source: event.id, target: datum.id }]);
|
| 309 |
-
const parent = graph.getNodeData(event.id);
|
| 310 |
-
graph.updateNodeData([
|
| 311 |
-
{
|
| 312 |
-
id: event.id,
|
| 313 |
-
children: [...(parent.children || []), datum.id],
|
| 314 |
-
style: { collapsed: false },
|
| 315 |
-
},
|
| 316 |
-
]);
|
| 317 |
-
graph.render();
|
| 318 |
-
}
|
| 319 |
}
|
| 320 |
|
| 321 |
register(ExtensionCategory.NODE, 'indented', IndentedNode);
|
|
@@ -375,7 +340,7 @@ const IndentedTree = ({ data, show }: IProps) => {
|
|
| 375 |
targetPort: 'in',
|
| 376 |
stroke: (datum: any) => {
|
| 377 |
const depth = graph.getAncestorsData(datum.source, 'tree').length;
|
| 378 |
-
return COLORS[depth % COLORS.length];
|
| 379 |
},
|
| 380 |
},
|
| 381 |
},
|
|
@@ -389,7 +354,6 @@ const IndentedTree = ({ data, show }: IProps) => {
|
|
| 389 |
},
|
| 390 |
behaviors: [
|
| 391 |
'scroll-canvas',
|
| 392 |
-
'drag-branch',
|
| 393 |
'collapse-expand-tree',
|
| 394 |
{
|
| 395 |
type: 'click-select',
|
|
@@ -421,7 +385,7 @@ const IndentedTree = ({ data, show }: IProps) => {
|
|
| 421 |
id="tree"
|
| 422 |
ref={containerRef}
|
| 423 |
style={{
|
| 424 |
-
width: '
|
| 425 |
height: '80vh',
|
| 426 |
display: show ? 'block' : 'none',
|
| 427 |
}}
|
|
|
|
| 18 |
import isEmpty from 'lodash/isEmpty';
|
| 19 |
import { useCallback, useEffect, useRef } from 'react';
|
| 20 |
|
| 21 |
+
const rootId = 'root';
|
| 22 |
|
| 23 |
const COLORS = [
|
| 24 |
'#5B8FF9',
|
|
|
|
| 35 |
|
| 36 |
const TreeEvent = {
|
| 37 |
COLLAPSE_EXPAND: 'collapse-expand',
|
| 38 |
+
WHEEL: 'canvas:wheel',
|
| 39 |
};
|
| 40 |
|
| 41 |
class IndentedNode extends BaseNode {
|
|
|
|
| 204 |
};
|
| 205 |
}
|
| 206 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 207 |
render(attributes = this.parsedAttributes, container = this) {
|
| 208 |
super.render(attributes, container);
|
| 209 |
|
|
|
|
| 211 |
|
| 212 |
this.drawIconArea(attributes, container);
|
| 213 |
this.drawCollapseShape(attributes, container);
|
|
|
|
| 214 |
}
|
| 215 |
}
|
| 216 |
|
|
|
|
| 244 |
graph.on(NodeEvent.POINTER_ENTER, this.showIcon);
|
| 245 |
graph.on(NodeEvent.POINTER_LEAVE, this.hideIcon);
|
| 246 |
graph.on(TreeEvent.COLLAPSE_EXPAND, this.onCollapseExpand);
|
|
|
|
| 247 |
}
|
| 248 |
|
| 249 |
unbindEvents() {
|
|
|
|
| 252 |
graph.off(NodeEvent.POINTER_ENTER, this.showIcon);
|
| 253 |
graph.off(NodeEvent.POINTER_LEAVE, this.hideIcon);
|
| 254 |
graph.off(TreeEvent.COLLAPSE_EXPAND, this.onCollapseExpand);
|
|
|
|
| 255 |
}
|
| 256 |
|
| 257 |
status = 'idle';
|
|
|
|
| 281 |
else await graph.expandElement(id);
|
| 282 |
this.status = 'idle';
|
| 283 |
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 284 |
}
|
| 285 |
|
| 286 |
register(ExtensionCategory.NODE, 'indented', IndentedNode);
|
|
|
|
| 340 |
targetPort: 'in',
|
| 341 |
stroke: (datum: any) => {
|
| 342 |
const depth = graph.getAncestorsData(datum.source, 'tree').length;
|
| 343 |
+
return COLORS[depth % COLORS.length] || 'black';
|
| 344 |
},
|
| 345 |
},
|
| 346 |
},
|
|
|
|
| 354 |
},
|
| 355 |
behaviors: [
|
| 356 |
'scroll-canvas',
|
|
|
|
| 357 |
'collapse-expand-tree',
|
| 358 |
{
|
| 359 |
type: 'click-select',
|
|
|
|
| 385 |
id="tree"
|
| 386 |
ref={containerRef}
|
| 387 |
style={{
|
| 388 |
+
width: '90vw',
|
| 389 |
height: '80vh',
|
| 390 |
display: show ? 'block' : 'none',
|
| 391 |
}}
|
web/src/pages/add-knowledge/components/knowledge-chunk/components/knowledge-graph/modal.tsx
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import { useFetchKnowledgeGraph } from '@/hooks/chunk-hooks';
|
| 2 |
import { Flex, Modal, Segmented } from 'antd';
|
| 3 |
-
import React, { useEffect, useState } from 'react';
|
|
|
|
| 4 |
import ForceGraph from './force-graph';
|
| 5 |
import IndentedTree from './indented-tree';
|
| 6 |
import styles from './index.less';
|
|
@@ -15,6 +16,14 @@ const KnowledgeGraphModal: React.FC = () => {
|
|
| 15 |
const [isModalOpen, setIsModalOpen] = useState(false);
|
| 16 |
const { data } = useFetchKnowledgeGraph();
|
| 17 |
const [value, setValue] = useState<SegmentedValue>(SegmentedValue.Graph);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
const handleOk = () => {
|
| 20 |
setIsModalOpen(false);
|
|
@@ -32,7 +41,7 @@ const KnowledgeGraphModal: React.FC = () => {
|
|
| 32 |
|
| 33 |
return (
|
| 34 |
<Modal
|
| 35 |
-
title=
|
| 36 |
open={isModalOpen}
|
| 37 |
onOk={handleOk}
|
| 38 |
onCancel={handleCancel}
|
|
@@ -43,7 +52,7 @@ const KnowledgeGraphModal: React.FC = () => {
|
|
| 43 |
<Flex justify="end">
|
| 44 |
<Segmented
|
| 45 |
size="large"
|
| 46 |
-
options={
|
| 47 |
value={value}
|
| 48 |
onChange={(v) => setValue(v as SegmentedValue)}
|
| 49 |
/>
|
|
|
|
| 1 |
import { useFetchKnowledgeGraph } from '@/hooks/chunk-hooks';
|
| 2 |
import { Flex, Modal, Segmented } from 'antd';
|
| 3 |
+
import React, { useEffect, useMemo, useState } from 'react';
|
| 4 |
+
import { useTranslation } from 'react-i18next';
|
| 5 |
import ForceGraph from './force-graph';
|
| 6 |
import IndentedTree from './indented-tree';
|
| 7 |
import styles from './index.less';
|
|
|
|
| 16 |
const [isModalOpen, setIsModalOpen] = useState(false);
|
| 17 |
const { data } = useFetchKnowledgeGraph();
|
| 18 |
const [value, setValue] = useState<SegmentedValue>(SegmentedValue.Graph);
|
| 19 |
+
const { t } = useTranslation();
|
| 20 |
+
|
| 21 |
+
const options = useMemo(() => {
|
| 22 |
+
return [
|
| 23 |
+
{ value: SegmentedValue.Graph, label: t('chunk.graph') },
|
| 24 |
+
{ value: SegmentedValue.Mind, label: t('chunk.mind') },
|
| 25 |
+
];
|
| 26 |
+
}, [t]);
|
| 27 |
|
| 28 |
const handleOk = () => {
|
| 29 |
setIsModalOpen(false);
|
|
|
|
| 41 |
|
| 42 |
return (
|
| 43 |
<Modal
|
| 44 |
+
title={t('chunk.graph')}
|
| 45 |
open={isModalOpen}
|
| 46 |
onOk={handleOk}
|
| 47 |
onCancel={handleCancel}
|
|
|
|
| 52 |
<Flex justify="end">
|
| 53 |
<Segmented
|
| 54 |
size="large"
|
| 55 |
+
options={options}
|
| 56 |
value={value}
|
| 57 |
onChange={(v) => setValue(v as SegmentedValue)}
|
| 58 |
/>
|