11import { transformGraphMap } from './knowledge-graph/format' ;
22import { 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
0 commit comments