Merge pull request #5065 from antvis/fix-modes

fix: handle the case when modes is empty
This commit is contained in:
Yanyan Wang 2023-10-16 14:45:10 +08:00 committed by GitHub
commit 3e7c7a6958
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 7 deletions

View File

@ -860,6 +860,8 @@ export class ItemController {
private onMapperChange = ({ type, mapper }) => { private onMapperChange = ({ type, mapper }) => {
if (!mapper) return; if (!mapper) return;
/** update this.nodeMapper or this.edgeMapper */
this[`${type}Mapper`] = mapper;
this.itemMap.forEach((item) => { this.itemMap.forEach((item) => {
const itemTye = item.getType(); const itemTye = item.getType();
if (itemTye !== type) return; if (itemTye !== type) return;

View File

@ -2,11 +2,11 @@ import EventEmitter from '@antv/event-emitter';
import { import {
AABB, AABB,
Canvas, Canvas,
Cursor,
DataURLType, DataURLType,
DisplayObject, DisplayObject,
PointLike, PointLike,
Rect, Rect,
Cursor,
} from '@antv/g'; } from '@antv/g';
import { GraphChange, ID } from '@antv/graphlib'; import { GraphChange, ID } from '@antv/graphlib';
import { import {
@ -46,7 +46,9 @@ import type {
StandardLayoutOptions, StandardLayoutOptions,
} from '../types/layout'; } from '../types/layout';
import type { NodeDisplayModel, NodeModel, NodeModelData } from '../types/node'; import type { NodeDisplayModel, NodeModel, NodeModelData } from '../types/node';
import { Plugin as PluginBase } from '../types/plugin';
import type { RendererName } from '../types/render'; import type { RendererName } from '../types/render';
import { ComboMapper, EdgeMapper, NodeMapper } from '../types/spec';
import type { import type {
ThemeOptionsOf, ThemeOptionsOf,
ThemeRegistry, ThemeRegistry,
@ -54,11 +56,9 @@ import type {
} from '../types/theme'; } from '../types/theme';
import { FitViewRules, GraphTransformOptions } from '../types/view'; import { FitViewRules, GraphTransformOptions } from '../types/view';
import { changeRenderer, createCanvas } from '../util/canvas'; import { changeRenderer, createCanvas } from '../util/canvas';
import { formatPadding } from '../util/shape';
import { getLayoutBounds } from '../util/layout';
import { createDOM } from '../util/dom'; import { createDOM } from '../util/dom';
import { Plugin as PluginBase } from '../types/plugin'; import { getLayoutBounds } from '../util/layout';
import { ComboMapper, EdgeMapper, NodeMapper } from '../types/spec'; import { formatPadding } from '../util/shape';
import { import {
DataController, DataController,
ExtensionController, ExtensionController,
@ -1954,8 +1954,9 @@ export class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
}); });
// update the graph specification // update the graph specification
modesArr.forEach((mode) => { modesArr.forEach((mode) => {
this.specification.modes[mode] = this.specification.modes[mode] = (
this.specification.modes[mode].concat(behaviorsArr); this.specification.modes[mode] || []
).concat(behaviorsArr);
}); });
} }
/** /**
@ -1975,6 +1976,9 @@ export class Graph<B extends BehaviorRegistry, T extends ThemeRegistry>
// update the graph specification // update the graph specification
modesArr.forEach((mode) => { modesArr.forEach((mode) => {
behaviorKeys.forEach((key) => { behaviorKeys.forEach((key) => {
if (!this.specification.modes[mode]) {
return;
}
const oldBehavior = this.specification.modes[mode].find( const oldBehavior = this.specification.modes[mode].find(
(behavior) => isObject(behavior) && behavior.key === key, (behavior) => isObject(behavior) && behavior.key === key,
); );