1
1
import { transformGraphMap } from './knowledge-graph/format' ;
2
2
import { G6Render } from './knowledge-graph/G6Render' ;
3
+ import clonedeep from 'lodash.clonedeep' ;
3
4
4
5
/**
5
6
* @class KnowledgeGraph
@@ -146,7 +147,7 @@ export class KnowledgeGraph {
146
147
* @description graph实例。
147
148
*/
148
149
this . graph = null ;
149
- this . config = config ;
150
+ this . config = clonedeep ( config ) ;
150
151
this . graphRender = null ;
151
152
this . type = type ;
152
153
this . createGraphRender ( this . type ) ;
@@ -429,7 +430,7 @@ export class KnowledgeGraph {
429
430
* @function KnowledgeGraph.prototype.setData
430
431
* @description 设置默认数据
431
432
* @param {KnowledgeGraph.Data } data - graph数据。
432
- * @param {Object } [graph = this.graph] - graph实例, 默认是 。
433
+ * @param {Object } [graph = this.graph] - graph实例。
433
434
*/
434
435
setData ( data , graph = this . graph ) {
435
436
data = data || { nodes : [ ] , edges : [ ] } ;
@@ -444,19 +445,20 @@ export class KnowledgeGraph {
444
445
/**
445
446
* @function KnowledgeGraph.prototype.render
446
447
* @description 根据提供的数据渲染视图。
448
+ * @param {Object } [graph = this.graph] - graph实例。
447
449
*/
448
- render ( graph ) {
449
- this . graphRender . render ( graph ) ;
450
+ render ( graph = this . graph ) {
451
+ graph && this . graphRender . render ( graph ) ;
450
452
}
451
453
452
454
/**
453
455
* @function KnowledgeGraph.prototype.updateGraph
454
456
* @description 更新数据
455
457
* @param {KnowledgeGraph.Data } data - graph数据。
456
- * @param {Object } graph - graph实例。
458
+ * @param {Object } [ graph = this.graph] - graph实例。
457
459
*/
458
- updateGraph ( data , graph ) {
459
- this . graphRender . updateGraph ( data , graph ) ;
460
+ updateGraph ( data , graph = this . graph ) {
461
+ graph && this . graphRender . updateGraph ( data , graph ) ;
460
462
}
461
463
462
464
/**
@@ -630,7 +632,6 @@ export class KnowledgeGraph {
630
632
* @function KnowledgeGraph.prototype.collapseNode
631
633
* @description 收起当前节点。
632
634
* @param {string } id - 元素 ID。
633
- * @param {Object } graph - graph实例。
634
635
*/
635
636
collapseNode ( id ) {
636
637
const item = this . findById ( id ) ;
@@ -827,19 +828,19 @@ export class KnowledgeGraph {
827
828
/**
828
829
* @function KnowledgeGraph.prototype.clear
829
830
* @description 清除画布元素。
830
- * @param {Object } graph - graph实例。
831
+ * @param {Object } [ graph = this.graph] - graph实例。
831
832
*/
832
- clear ( graph ) {
833
- graph . clear ( ) ;
833
+ clear ( graph = this . graph ) {
834
+ graph && graph . clear ( ) ;
834
835
}
835
836
836
837
/**
837
838
* @function KnowledgeGraph.prototype.destroy
838
839
* @description 销毁画布。
839
- * @param {Object } graph - graph实例。
840
+ * @param {Object } [ graph = this.graph] - graph实例。
840
841
*/
841
- destroy ( graph ) {
842
- graph . destroy ( ) ;
842
+ destroy ( graph = this . graph ) {
843
+ graph && graph . destroy ( ) ;
843
844
}
844
845
}
845
846
0 commit comments