From d060b54cc3f06b2edc2cb6cb70627f45837d5037 Mon Sep 17 00:00:00 2001 From: pomelo-nwu Date: Fri, 13 Oct 2023 15:23:09 +0800 Subject: [PATCH 1/2] fix: handle the case when modes is empty --- packages/g6/src/runtime/graph.ts | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/packages/g6/src/runtime/graph.ts b/packages/g6/src/runtime/graph.ts index 00a0313e3d..84802217b9 100644 --- a/packages/g6/src/runtime/graph.ts +++ b/packages/g6/src/runtime/graph.ts @@ -2,11 +2,11 @@ import EventEmitter from '@antv/event-emitter'; import { AABB, Canvas, + Cursor, DataURLType, DisplayObject, PointLike, Rect, - Cursor, } from '@antv/g'; import { GraphChange, ID } from '@antv/graphlib'; import { @@ -46,7 +46,9 @@ import type { StandardLayoutOptions, } from '../types/layout'; import type { NodeDisplayModel, NodeModel, NodeModelData } from '../types/node'; +import { Plugin as PluginBase } from '../types/plugin'; import type { RendererName } from '../types/render'; +import { ComboMapper, EdgeMapper, NodeMapper } from '../types/spec'; import type { ThemeOptionsOf, ThemeRegistry, @@ -54,11 +56,9 @@ import type { } from '../types/theme'; import { FitViewRules, GraphTransformOptions } from '../types/view'; import { changeRenderer, createCanvas } from '../util/canvas'; -import { formatPadding } from '../util/shape'; -import { getLayoutBounds } from '../util/layout'; import { createDOM } from '../util/dom'; -import { Plugin as PluginBase } from '../types/plugin'; -import { ComboMapper, EdgeMapper, NodeMapper } from '../types/spec'; +import { getLayoutBounds } from '../util/layout'; +import { formatPadding } from '../util/shape'; import { DataController, ExtensionController, @@ -1954,8 +1954,9 @@ export class Graph }); // update the graph specification modesArr.forEach((mode) => { - this.specification.modes[mode] = - this.specification.modes[mode].concat(behaviorsArr); + this.specification.modes[mode] = ( + this.specification.modes[mode] || [] + ).concat(behaviorsArr); }); } /** @@ -1975,6 +1976,9 @@ export class Graph // update the graph specification modesArr.forEach((mode) => { behaviorKeys.forEach((key) => { + if (!this.specification.modes[mode]) { + return; + } const oldBehavior = this.specification.modes[mode].find( (behavior) => isObject(behavior) && behavior.key === key, ); From 79ce55618b2604d57bcf5fa81da734786344c2ca Mon Sep 17 00:00:00 2001 From: pomelo-nwu Date: Mon, 16 Oct 2023 13:57:53 +0800 Subject: [PATCH 2/2] feat: update itemMapper --- packages/g6/src/runtime/controller/item.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/g6/src/runtime/controller/item.ts b/packages/g6/src/runtime/controller/item.ts index 454067bf9e..bf4d364444 100644 --- a/packages/g6/src/runtime/controller/item.ts +++ b/packages/g6/src/runtime/controller/item.ts @@ -860,6 +860,8 @@ export class ItemController { private onMapperChange = ({ type, mapper }) => { if (!mapper) return; + /** update this.nodeMapper or this.edgeMapper */ + this[`${type}Mapper`] = mapper; this.itemMap.forEach((item) => { const itemTye = item.getType(); if (itemTye !== type) return;