@@ -141,6 +141,18 @@ import clonedeep from 'lodash.clonedeep';
141141 * @property {string } [shadowColor] - 阴影颜色。
142142 */
143143
144+ /**
145+ * @typedef {Object } KnowledgeGraph.highlightParams - 高亮节点、边的参数, 默认高亮样式和hover高亮样式一致。
146+ * @property {Array } nodeIDs - 高亮节点id数组。
147+ * @property {Array } edgeIDs - 高亮边id数组。
148+ * @property {KnowledgeGraph.NodeStyle } [nodeStateStyles] - 高亮节点样式。
149+ * @property {KnowledgeGraph.EdgeStyle } [edgeStateStyles] - 高亮边样式。
150+ */
151+ /**
152+ * @typedef {Object } KnowledgeGraph.clearHighlightParams - 取消高亮节点、边的参数。
153+ * @property {Array } nodeIDs - 高亮节点id数组。
154+ * @property {Array } edgeIDs - 高亮边id数组。
155+ */
144156export class KnowledgeGraph {
145157 constructor ( config , type = 'G6' ) {
146158 /**
@@ -183,7 +195,7 @@ export class KnowledgeGraph {
183195 . filter ( ( id ) => id !== '' )
184196 . forEach ( ( id ) => {
185197 const item = this . findById ( id ) ;
186- callback ( item ) ;
198+ callback ( item , 'node' ) ;
187199 } ) ;
188200 }
189201
@@ -194,23 +206,32 @@ export class KnowledgeGraph {
194206 const item = this . find ( 'edge' , ( edge ) => {
195207 return edge . get ( 'model' ) . edgeId == id ;
196208 } ) ;
197- callback ( item ) ;
209+ callback ( item , 'edge' ) ;
198210 } ) ;
199211 }
200212
201213 /**
202214 * @function KnowledgeGraph.prototype.highlight
203215 * @version 11.2.0
204216 * @description 高亮节点和边。
205- * @param {Object } params - { nodeIDs, edgeIDs}, 高亮节点id数组,高亮边id数组 。
217+ * @param {KnowledgeGraph.highlightParams } params - 高亮参数 。
206218 */
207219 highlight ( params ) {
208220 const { nodeIDs = [ ] , edgeIDs = [ ] } = params ;
209221 const graph = this . graph ;
210- const activeCallback = ( item ) => {
222+ const activeCallback = ( item , type = 'node' ) => {
211223 if ( ! item ) {
212224 return ;
213225 }
226+ const stateStyles = params [ type + 'StateStyles' ] ;
227+ if ( stateStyles ) {
228+ graph . updateItem ( item , {
229+ style : item . style ,
230+ stateStyles : {
231+ actived : stateStyles
232+ }
233+ } ) ;
234+ }
214235 graph . setItemState ( item , 'actived' , true ) ;
215236 graph . paint ( ) ;
216237 graph . setAutoPaint ( true ) ;
@@ -223,13 +244,10 @@ export class KnowledgeGraph {
223244 * @function KnowledgeGraph.prototype.clearHighlight
224245 * @version 11.2.0
225246 * @description 取消之前高亮节点和边。
226- * @param {Object } params - { nodeIDs, edgeIDs}取消高亮节点id数组和边id数组 。
247+ * @param {KnowledgeGraph.clearHighlightParams } [ params] - 取消高亮节点id数组和边id数组, 不传默认取消所有激活状态的高亮 。
227248 */
228249 clearHighlight ( params ) {
229250 const graph = this . graph ;
230- const { nodeIDs = [ ] , edgeIDs = [ ] } = params ;
231- graph . setAutoPaint ( false ) ;
232-
233251 const clearCallback = ( item ) => {
234252 if ( ! item ) {
235253 return ;
@@ -238,6 +256,17 @@ export class KnowledgeGraph {
238256 graph . paint ( ) ;
239257 graph . setAutoPaint ( true ) ;
240258 } ;
259+ graph . setAutoPaint ( false ) ;
260+ if ( ! params ) {
261+ graph . getNodes ( ) . forEach ( function ( node ) {
262+ clearCallback ( node ) ;
263+ } ) ;
264+ graph . getEdges ( ) . forEach ( function ( edge ) {
265+ clearCallback ( edge ) ;
266+ } ) ;
267+ return ;
268+ }
269+ const { nodeIDs = [ ] , edgeIDs = [ ] } = params ;
241270 this . _handleNodes ( nodeIDs , clearCallback ) ;
242271 this . _handleEdges ( edgeIDs , clearCallback ) ;
243272 }
0 commit comments