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 }) => {
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;

View File

@ -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<B extends BehaviorRegistry, T extends ThemeRegistry>
});
// 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<B extends BehaviorRegistry, T extends ThemeRegistry>
// 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,
);