Skip to content

Commit d85c0fa

Browse files
[fix]知识图谱修复 review by xiongjj
1 parent 137e993 commit d85c0fa

File tree

3 files changed

+17
-14
lines changed

3 files changed

+17
-14
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@
144144
"insert-css": "^2.0.0",
145145
"jsonsql": "0.2.5",
146146
"leaflet": "1.9.4",
147+
"lodash.clonedeep": "^4.5.0",
147148
"lodash.difference": "^4.5.0",
148149
"lodash.remove": "^4.7.0",
149150
"lodash.topairs": "4.3.0",

src/common/overlay/KnowledgeGraph.js

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { transformGraphMap } from './knowledge-graph/format';
22
import { G6Render } from './knowledge-graph/G6Render';
3+
import clonedeep from 'lodash.clonedeep';
34

45
/**
56
* @class KnowledgeGraph
@@ -146,7 +147,7 @@ export class KnowledgeGraph {
146147
* @description graph实例。
147148
*/
148149
this.graph = null;
149-
this.config = config;
150+
this.config = clonedeep(config);
150151
this.graphRender = null;
151152
this.type = type;
152153
this.createGraphRender(this.type);
@@ -429,7 +430,7 @@ export class KnowledgeGraph {
429430
* @function KnowledgeGraph.prototype.setData
430431
* @description 设置默认数据
431432
* @param {KnowledgeGraph.Data} data - graph数据。
432-
* @param {Object} [graph = this.graph] - graph实例, 默认是
433+
* @param {Object} [graph = this.graph] - graph实例。
433434
*/
434435
setData(data, graph = this.graph) {
435436
data = data || { nodes: [], edges: [] };
@@ -444,19 +445,20 @@ export class KnowledgeGraph {
444445
/**
445446
* @function KnowledgeGraph.prototype.render
446447
* @description 根据提供的数据渲染视图。
448+
* @param {Object} [graph = this.graph] - graph实例。
447449
*/
448-
render(graph) {
449-
this.graphRender.render(graph);
450+
render(graph = this.graph) {
451+
graph && this.graphRender.render(graph);
450452
}
451453

452454
/**
453455
* @function KnowledgeGraph.prototype.updateGraph
454456
* @description 更新数据
455457
* @param {KnowledgeGraph.Data} data - graph数据。
456-
* @param {Object} graph - graph实例。
458+
* @param {Object} [graph = this.graph] - graph实例。
457459
*/
458-
updateGraph(data, graph) {
459-
this.graphRender.updateGraph(data, graph);
460+
updateGraph(data, graph = this.graph) {
461+
graph && this.graphRender.updateGraph(data, graph);
460462
}
461463

462464
/**
@@ -630,7 +632,6 @@ export class KnowledgeGraph {
630632
* @function KnowledgeGraph.prototype.collapseNode
631633
* @description 收起当前节点。
632634
* @param {string} id - 元素 ID。
633-
* @param {Object} graph - graph实例。
634635
*/
635636
collapseNode(id) {
636637
const item = this.findById(id);
@@ -827,19 +828,19 @@ export class KnowledgeGraph {
827828
/**
828829
* @function KnowledgeGraph.prototype.clear
829830
* @description 清除画布元素。
830-
* @param {Object} graph - graph实例。
831+
* @param {Object} [graph = this.graph] - graph实例。
831832
*/
832-
clear(graph) {
833-
graph.clear();
833+
clear(graph = this.graph) {
834+
graph && graph.clear();
834835
}
835836

836837
/**
837838
* @function KnowledgeGraph.prototype.destroy
838839
* @description 销毁画布。
839-
* @param {Object} graph - graph实例。
840+
* @param {Object} [graph = this.graph] - graph实例。
840841
*/
841-
destroy(graph) {
842-
graph.destroy();
842+
destroy(graph = this.graph) {
843+
graph && graph.destroy();
843844
}
844845
}
845846

src/common/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"promise-polyfill": "8.2.3",
2323
"lodash.topairs": "4.3.0",
2424
"lodash.uniqby": "^4.7.0",
25+
"lodash.clonedeep": "^4.5.0",
2526
"mapv": "2.0.62",
2627
"flatgeobuf": "3.23.1",
2728
"rbush": "^2.0.2",

0 commit comments

Comments
 (0)