diff --git a/packages/g6/__tests__/demos/behavior-click-element.ts b/packages/g6/__tests__/demos/behavior-click-select.ts similarity index 50% rename from packages/g6/__tests__/demos/behavior-click-element.ts rename to packages/g6/__tests__/demos/behavior-click-select.ts index 521567e93aa..76b34eb0b2f 100644 --- a/packages/g6/__tests__/demos/behavior-click-element.ts +++ b/packages/g6/__tests__/demos/behavior-click-select.ts @@ -1,8 +1,8 @@ import { Graph } from '@/src'; -import type { ClickElementOptions } from '@/src/behaviors'; +import type { ClickSelectOptions } from '@/src/behaviors'; import data from '@@/dataset/cluster.json'; -export const behaviorClickElement: TestCase = async (context) => { +export const behaviorClickSelect: TestCase = async (context) => { const graph = new Graph({ ...context, data, @@ -15,7 +15,7 @@ export const behaviorClickElement: TestCase = async (context) => { }, }, zoomRange: [0.5, 5], - behaviors: [{ type: 'click-element', key: 'click-element' }, 'drag-element'], + behaviors: [{ type: 'click-select', key: 'click-select' }, 'drag-element'], }); await graph.render(); @@ -24,27 +24,27 @@ export const behaviorClickElement: TestCase = async (context) => { multiple: false, trigger: ['shift'], degree: 0, - selectedState: 'selected', + state: 'selected', unselectedState: undefined, }; - const updateClickElementOption = (options: Partial) => { - graph.updateBehavior({ key: 'click-element', ...options }); + const updateClickSelectOption = (options: Partial) => { + graph.updateBehavior({ key: 'click-select', ...options }); }; - behaviorClickElement.form = (panel) => [ + behaviorClickSelect.form = (panel) => [ panel .add(config, 'multiple') .name('Multiple') - .onChange((multiple: boolean) => updateClickElementOption({ multiple })), + .onChange((multiple: boolean) => updateClickSelectOption({ multiple })), panel .add(config, 'trigger', ['shift', 'ctrl', 'alt', 'meta']) .name('Trigger') - .onChange((trigger: string) => updateClickElementOption({ trigger: [trigger] })), + .onChange((trigger: string) => updateClickSelectOption({ trigger: [trigger] })), panel .add(config, 'degree', [0, 1, 2, 3]) .name('Degree') - .onChange((degree: number) => updateClickElementOption({ degree })), + .onChange((degree: number) => updateClickSelectOption({ degree })), ]; return graph; diff --git a/packages/g6/__tests__/demos/behavior-hover-element.ts b/packages/g6/__tests__/demos/behavior-hover-activate.ts similarity index 73% rename from packages/g6/__tests__/demos/behavior-hover-element.ts rename to packages/g6/__tests__/demos/behavior-hover-activate.ts index abc0f1a09fb..f7ed9c03a20 100644 --- a/packages/g6/__tests__/demos/behavior-hover-element.ts +++ b/packages/g6/__tests__/demos/behavior-hover-activate.ts @@ -1,7 +1,7 @@ import { Graph } from '@/src'; import data from '@@/dataset/cluster.json'; -export const behaviorHoverElement: TestCase = async (context) => { +export const behaviorHoverActivate: TestCase = async (context) => { const graph = new Graph({ ...context, data: data, @@ -15,7 +15,7 @@ export const behaviorHoverElement: TestCase = async (context) => { }, }, zoomRange: [0.5, 5], - behaviors: [{ type: 'hover-element' }], + behaviors: [{ type: 'hover-activate' }], }); await graph.render(); @@ -24,11 +24,11 @@ export const behaviorHoverElement: TestCase = async (context) => { degree: 0, }; - behaviorHoverElement.form = (panel) => [ + behaviorHoverActivate.form = (panel) => [ panel .add(config, 'degree', 0, 3, 1) .name('Degree') - .onChange((degree: number) => graph.setBehaviors([{ type: 'hover-element', degree }])), + .onChange((degree: number) => graph.setBehaviors([{ type: 'hover-activate', degree }])), ]; return graph; diff --git a/packages/g6/__tests__/demos/index.ts b/packages/g6/__tests__/demos/index.ts index c756889a244..902ae75c34d 100644 --- a/packages/g6/__tests__/demos/index.ts +++ b/packages/g6/__tests__/demos/index.ts @@ -6,14 +6,14 @@ export { animationElementState } from './animation-element-state'; export { animationElementStateSwitch } from './animation-element-state-switch'; export { animationElementStylePosition } from './animation-element-style-position'; export { behaviorBrushSelect } from './behavior-brush-select'; -export { behaviorClickElement } from './behavior-click-element'; +export { behaviorClickSelect } from './behavior-click-select'; export { behaviorCreateEdge } from './behavior-create-edge'; export { behaviorDragCanvas } from './behavior-drag-canvas'; export { behaviorDragNode } from './behavior-drag-element'; export { behaviorExpandCollapseCombo } from './behavior-expand-collapse-combo'; export { behaviorExpandCollapseNode } from './behavior-expand-collapse-node'; export { behaviorFocusElement } from './behavior-focus-element'; -export { behaviorHoverElement } from './behavior-hover-element'; +export { behaviorHoverActivate } from './behavior-hover-activate'; export { behaviorLassoSelect } from './behavior-lasso-select'; export { behaviorScrollCanvas } from './behavior-scroll-canvas'; export { behaviorZoomCanvas } from './behavior-zoom-canvas'; diff --git a/packages/g6/__tests__/demos/transform-process-parallel-edges.ts b/packages/g6/__tests__/demos/transform-process-parallel-edges.ts index 14c8d28331a..cf51f35bf92 100644 --- a/packages/g6/__tests__/demos/transform-process-parallel-edges.ts +++ b/packages/g6/__tests__/demos/transform-process-parallel-edges.ts @@ -9,8 +9,8 @@ export const transformProcessParallelEdges: TestCase = async (context) => { behaviors: [ 'drag-element', { - type: 'hover-element', - key: 'hover-element', + type: 'hover-activate', + key: 'hover-activate', enable: (event: any) => event.targetType === 'edge', }, ], diff --git a/packages/g6/__tests__/snapshots/behaviors/click-element/after-deselect.svg b/packages/g6/__tests__/snapshots/behaviors/click-select/after-deselect.svg similarity index 100% rename from packages/g6/__tests__/snapshots/behaviors/click-element/after-deselect.svg rename to packages/g6/__tests__/snapshots/behaviors/click-select/after-deselect.svg diff --git a/packages/g6/__tests__/snapshots/behaviors/click-element/after-select.svg b/packages/g6/__tests__/snapshots/behaviors/click-select/after-select.svg similarity index 100% rename from packages/g6/__tests__/snapshots/behaviors/click-element/after-select.svg rename to packages/g6/__tests__/snapshots/behaviors/click-select/after-select.svg diff --git a/packages/g6/__tests__/snapshots/behaviors/click-element/custom-neighborSelectedState.svg b/packages/g6/__tests__/snapshots/behaviors/click-select/custom-neighborState.svg similarity index 100% rename from packages/g6/__tests__/snapshots/behaviors/click-element/custom-neighborSelectedState.svg rename to packages/g6/__tests__/snapshots/behaviors/click-select/custom-neighborState.svg diff --git a/packages/g6/__tests__/snapshots/behaviors/click-element/custom-state.svg b/packages/g6/__tests__/snapshots/behaviors/click-select/custom-state.svg similarity index 100% rename from packages/g6/__tests__/snapshots/behaviors/click-element/custom-state.svg rename to packages/g6/__tests__/snapshots/behaviors/click-select/custom-state.svg diff --git a/packages/g6/__tests__/snapshots/behaviors/click-element/default.svg b/packages/g6/__tests__/snapshots/behaviors/click-select/default.svg similarity index 100% rename from packages/g6/__tests__/snapshots/behaviors/click-element/default.svg rename to packages/g6/__tests__/snapshots/behaviors/click-select/default.svg diff --git a/packages/g6/__tests__/snapshots/behaviors/click-element/edge-1-degree.svg b/packages/g6/__tests__/snapshots/behaviors/click-select/edge-1-degree.svg similarity index 100% rename from packages/g6/__tests__/snapshots/behaviors/click-element/edge-1-degree.svg rename to packages/g6/__tests__/snapshots/behaviors/click-select/edge-1-degree.svg diff --git a/packages/g6/__tests__/snapshots/behaviors/click-element/multiple-meta.svg b/packages/g6/__tests__/snapshots/behaviors/click-select/multiple-meta.svg similarity index 100% rename from packages/g6/__tests__/snapshots/behaviors/click-element/multiple-meta.svg rename to packages/g6/__tests__/snapshots/behaviors/click-select/multiple-meta.svg diff --git a/packages/g6/__tests__/snapshots/behaviors/click-element/multiple-shift.svg b/packages/g6/__tests__/snapshots/behaviors/click-select/multiple-shift.svg similarity index 100% rename from packages/g6/__tests__/snapshots/behaviors/click-element/multiple-shift.svg rename to packages/g6/__tests__/snapshots/behaviors/click-select/multiple-shift.svg diff --git a/packages/g6/__tests__/snapshots/behaviors/click-element/node-1-degree.svg b/packages/g6/__tests__/snapshots/behaviors/click-select/node-1-degree.svg similarity index 100% rename from packages/g6/__tests__/snapshots/behaviors/click-element/node-1-degree.svg rename to packages/g6/__tests__/snapshots/behaviors/click-select/node-1-degree.svg diff --git a/packages/g6/__tests__/snapshots/behaviors/hover-element/1-degree-edge.svg b/packages/g6/__tests__/snapshots/behaviors/hover-activate/1-degree-edge.svg similarity index 100% rename from packages/g6/__tests__/snapshots/behaviors/hover-element/1-degree-edge.svg rename to packages/g6/__tests__/snapshots/behaviors/hover-activate/1-degree-edge.svg diff --git a/packages/g6/__tests__/snapshots/behaviors/hover-element/1-degree-node.svg b/packages/g6/__tests__/snapshots/behaviors/hover-activate/1-degree-node.svg similarity index 100% rename from packages/g6/__tests__/snapshots/behaviors/hover-element/1-degree-node.svg rename to packages/g6/__tests__/snapshots/behaviors/hover-activate/1-degree-node.svg diff --git a/packages/g6/__tests__/snapshots/behaviors/hover-element/2-degree-edge.svg b/packages/g6/__tests__/snapshots/behaviors/hover-activate/2-degree-edge.svg similarity index 100% rename from packages/g6/__tests__/snapshots/behaviors/hover-element/2-degree-edge.svg rename to packages/g6/__tests__/snapshots/behaviors/hover-activate/2-degree-edge.svg diff --git a/packages/g6/__tests__/snapshots/behaviors/hover-element/2-degree-node.svg b/packages/g6/__tests__/snapshots/behaviors/hover-activate/2-degree-node.svg similarity index 100% rename from packages/g6/__tests__/snapshots/behaviors/hover-element/2-degree-node.svg rename to packages/g6/__tests__/snapshots/behaviors/hover-activate/2-degree-node.svg diff --git a/packages/g6/__tests__/snapshots/behaviors/hover-element/after-hover-out.svg b/packages/g6/__tests__/snapshots/behaviors/hover-activate/after-hover-out.svg similarity index 100% rename from packages/g6/__tests__/snapshots/behaviors/hover-element/after-hover-out.svg rename to packages/g6/__tests__/snapshots/behaviors/hover-activate/after-hover-out.svg diff --git a/packages/g6/__tests__/snapshots/behaviors/hover-element/after-hover.svg b/packages/g6/__tests__/snapshots/behaviors/hover-activate/after-hover.svg similarity index 100% rename from packages/g6/__tests__/snapshots/behaviors/hover-element/after-hover.svg rename to packages/g6/__tests__/snapshots/behaviors/hover-activate/after-hover.svg diff --git a/packages/g6/__tests__/snapshots/behaviors/hover-element/default.svg b/packages/g6/__tests__/snapshots/behaviors/hover-activate/default.svg similarity index 100% rename from packages/g6/__tests__/snapshots/behaviors/hover-element/default.svg rename to packages/g6/__tests__/snapshots/behaviors/hover-activate/default.svg diff --git a/packages/g6/__tests__/snapshots/behaviors/hover-element/state.svg b/packages/g6/__tests__/snapshots/behaviors/hover-activate/state.svg similarity index 100% rename from packages/g6/__tests__/snapshots/behaviors/hover-element/state.svg rename to packages/g6/__tests__/snapshots/behaviors/hover-activate/state.svg diff --git a/packages/g6/__tests__/unit/behaviors/click-element.spec.ts b/packages/g6/__tests__/unit/behaviors/click-select.spec.ts similarity index 76% rename from packages/g6/__tests__/unit/behaviors/click-element.spec.ts rename to packages/g6/__tests__/unit/behaviors/click-select.spec.ts index b3735d10980..cad026570ee 100644 --- a/packages/g6/__tests__/unit/behaviors/click-element.spec.ts +++ b/packages/g6/__tests__/unit/behaviors/click-select.spec.ts @@ -1,12 +1,12 @@ -import { behaviorClickElement } from '@/__tests__/demos'; +import { behaviorClickSelect } from '@/__tests__/demos'; import { CommonEvent, type Graph } from '@/src'; import { createDemoGraph } from '@@/utils'; -describe('behavior click element', () => { +describe('behavior click-select element', () => { let graph: Graph; beforeAll(async () => { - graph = await createDemoGraph(behaviorClickElement, { animation: false }); + graph = await createDemoGraph(behaviorClickSelect, { animation: false }); }); afterAll(() => { @@ -23,37 +23,37 @@ describe('behavior click element', () => { await expect(graph).toMatchSnapshot(__filename, 'after-deselect'); }); - it('selectedState and unselectedState', async () => { - graph.setBehaviors([{ type: 'click-element', selectedState: 'active', unselectedState: 'inactive' }]); + it('state and unselectedState', async () => { + graph.setBehaviors([{ type: 'click-select', state: 'active', unselectedState: 'inactive' }]); graph.emit(`node:${CommonEvent.CLICK}`, { target: { id: '0' }, targetType: 'node' }); await expect(graph).toMatchSnapshot(__filename, 'custom-state'); graph.emit(`node:${CommonEvent.CLICK}`, { target: { id: '0' }, targetType: 'node' }); }); - it('selectedState and neighborSelectedState', async () => { + it('state and neighborState', async () => { graph.setBehaviors([ { - type: 'click-element', - selectedState: 'selected', - neighborSelectedState: 'active', + type: 'click-select', + state: 'selected', + neighborState: 'active', unselectedState: 'inactive', degree: 1, }, ]); graph.emit(`node:${CommonEvent.CLICK}`, { target: { id: '0' }, targetType: 'node' }); - await expect(graph).toMatchSnapshot(__filename, 'custom-neighborSelectedState'); + await expect(graph).toMatchSnapshot(__filename, 'custom-neighborState'); graph.emit(`node:${CommonEvent.CLICK}`, { target: { id: '0' }, targetType: 'node' }); }); it('1 degree', async () => { graph.setBehaviors([ { - type: 'click-element', + type: 'click-select', degree: 1, - selectedState: 'selected', - neighborSelectedState: 'selected', + state: 'selected', + neighborState: 'selected', unselectedState: undefined, }, ]); @@ -68,7 +68,7 @@ describe('behavior click element', () => { }); it('multiple', async () => { - graph.setBehaviors([{ type: 'click-element', multiple: true, degree: 0 }]); + graph.setBehaviors([{ type: 'click-select', multiple: true, degree: 0 }]); graph.emit(`node:${CommonEvent.CLICK}`, { target: { id: '0' }, targetType: 'node' }); graph.emit(CommonEvent.KEY_DOWN, { key: 'shift' }); @@ -77,7 +77,7 @@ describe('behavior click element', () => { await expect(graph).toMatchSnapshot(__filename, 'multiple-shift'); - graph.setBehaviors([{ type: 'click-element', multiple: true, trigger: ['meta'] }]); + graph.setBehaviors([{ type: 'click-select', multiple: true, trigger: ['meta'] }]); graph.emit(`node:${CommonEvent.CLICK}`, { target: { id: '0' }, targetType: 'node' }); graph.emit(CommonEvent.KEY_DOWN, { key: 'meta' }); diff --git a/packages/g6/__tests__/unit/behaviors/hover-element.spec.ts b/packages/g6/__tests__/unit/behaviors/hover-activate.spec.ts similarity index 78% rename from packages/g6/__tests__/unit/behaviors/hover-element.spec.ts rename to packages/g6/__tests__/unit/behaviors/hover-activate.spec.ts index 2bba6c1e614..94ab6ed7247 100644 --- a/packages/g6/__tests__/unit/behaviors/hover-element.spec.ts +++ b/packages/g6/__tests__/unit/behaviors/hover-activate.spec.ts @@ -1,12 +1,12 @@ -import { behaviorHoverElement } from '@/__tests__/demos'; +import { behaviorHoverActivate } from '@/__tests__/demos'; import { CommonEvent, type Graph } from '@/src'; import { createDemoGraph } from '@@/utils'; -describe('behavior hover element', () => { +describe('behavior hover-activate element', () => { let graph: Graph; beforeAll(async () => { - graph = await createDemoGraph(behaviorHoverElement, { animation: false }); + graph = await createDemoGraph(behaviorHoverActivate, { animation: false }); }); afterAll(() => { @@ -25,8 +25,8 @@ describe('behavior hover element', () => { await expect(graph).toMatchSnapshot(__filename, 'after-hover-out'); }); - it('activeState and inactiveState', async () => { - graph.setBehaviors([{ type: 'hover-element', activeState: 'active', inactiveState: 'inactive' }]); + it('state and inactiveState', async () => { + graph.setBehaviors([{ type: 'hover-activate', state: 'active', inactiveState: 'inactive' }]); graph.emit(`node:${CommonEvent.POINTER_OVER}`, { target: { id: '0' }, targetType: 'node' }); @@ -36,7 +36,7 @@ describe('behavior hover element', () => { }); it('1 degree', async () => { - graph.setBehaviors([{ type: 'hover-element', activeState: 'active', inactiveState: 'inactive', degree: 1 }]); + graph.setBehaviors([{ type: 'hover-activate', state: 'active', inactiveState: 'inactive', degree: 1 }]); graph.emit(`node:${CommonEvent.POINTER_OVER}`, { target: { id: '0' }, targetType: 'node' }); @@ -52,7 +52,7 @@ describe('behavior hover element', () => { }); it('2 degree', async () => { - graph.setBehaviors([{ type: 'hover-element', activeState: 'active', inactiveState: 'inactive', degree: 2 }]); + graph.setBehaviors([{ type: 'hover-activate', state: 'active', inactiveState: 'inactive', degree: 2 }]); graph.emit(`node:${CommonEvent.POINTER_OVER}`, { target: { id: '0' }, targetType: 'node' }); diff --git a/packages/g6/src/behaviors/click-element.ts b/packages/g6/src/behaviors/click-select.ts similarity index 88% rename from packages/g6/src/behaviors/click-element.ts rename to packages/g6/src/behaviors/click-select.ts index ab1e1d70488..2a05885da54 100644 --- a/packages/g6/src/behaviors/click-element.ts +++ b/packages/g6/src/behaviors/click-select.ts @@ -15,7 +15,7 @@ import { BaseBehavior } from './base-behavior'; * * Click element behavior options */ -export interface ClickElementOptions extends BaseBehaviorOptions { +export interface ClickSelectOptions extends BaseBehaviorOptions { /** * 是否启用动画 * @@ -58,14 +58,14 @@ export interface ClickElementOptions extends BaseBehaviorOptions { * The state to be applied when an element is selected * @defaultValue 'selected' */ - selectedState?: State; + state?: State; /** * 当有元素选中时,其相邻 n 度关系的元素应用的状态。n 的值由属性 degree 控制,例如 degree 为 1 时表示直接相邻的元素 * * The state to be applied to the neighboring elements within n degrees when an element is selected. The value of n is controlled by the degree property, for instance, a degree of 1 indicates direct neighbors * @defaultValue 'selected' */ - neighborSelectedState?: State; + neighborState?: State; /** * 当有元素被选中时,除了选中元素及其受影响的邻居元素外,其他所有元素应用的状态。 * @@ -106,26 +106,26 @@ export interface ClickElementOptions extends BaseBehaviorOptions { * * When the mouse clicks on an element, you can activate the state of the element, such as selecting nodes or edges. When the degree is 1, clicking on a node will highlight the current node and its directly adjacent nodes and edges. */ -export class ClickElement extends BaseBehavior { +export class ClickSelect extends BaseBehavior { private selectedElementIds: Set = new Set(); private neighborSelectedElementIds: Set = new Set(); private shortcut: Shortcut; - static defaultOptions: Partial = { + static defaultOptions: Partial = { animation: true, enable: true, multiple: false, trigger: ['shift'], - selectedState: 'selected', - neighborSelectedState: 'selected', + state: 'selected', + neighborState: 'selected', unselectedState: undefined, degree: 0, }; - constructor(context: RuntimeContext, options: ClickElementOptions) { - super(context, Object.assign({}, ClickElement.defaultOptions, options)); + constructor(context: RuntimeContext, options: ClickSelectOptions) { + super(context, Object.assign({}, ClickSelect.defaultOptions, options)); this.shortcut = new Shortcut(context.graph); this.bindEvents(); } @@ -134,12 +134,12 @@ export class ClickElement extends BaseBehavior { const { graph } = this.context; this.unbindEvents(); ELEMENT_TYPES.forEach((type) => { - graph.on(`${type}:${CommonEvent.CLICK}`, this.onClickElement); + graph.on(`${type}:${CommonEvent.CLICK}`, this.onClickSelect); }); graph.on(`canvas:${CommonEvent.CLICK}`, this.onClickCanvas); } - private onClickElement = (event: IPointerEvent) => { + private onClickSelect = (event: IPointerEvent) => { if (!this.validate(event)) return; this.updateElementsState(event, false); this.updateElementsState(event, true); @@ -155,7 +155,7 @@ export class ClickElement extends BaseBehavior { }; private updateElementsState = (event: IPointerEvent, add: boolean) => { - if (!this.options.selectedState && !this.options.unselectedState) return; + if (!this.options.state && !this.options.unselectedState) return; const { graph } = this.context; const { target } = event as { target: Element }; @@ -175,17 +175,14 @@ export class ClickElement extends BaseBehavior { const states: Record = {}; - if (this.options.selectedState) { - Object.assign( - states, - this.getElementsState(Array.from(this.selectedElementIds), this.options.selectedState, add), - ); + if (this.options.state) { + Object.assign(states, this.getElementsState(Array.from(this.selectedElementIds), this.options.state, add)); } - if (this.options.neighborSelectedState && this.neighborSelectedElementIds.size > 0) { + if (this.options.neighborState && this.neighborSelectedElementIds.size > 0) { Object.assign( states, - this.getElementsState(Array.from(this.neighborSelectedElementIds), this.options.neighborSelectedState, add), + this.getElementsState(Array.from(this.neighborSelectedElementIds), this.options.neighborState, add), ); } @@ -236,7 +233,7 @@ export class ClickElement extends BaseBehavior { const { graph } = this.context; ELEMENT_TYPES.forEach((type) => { - graph.off(`${type}:${CommonEvent.CLICK}`, this.onClickElement); + graph.off(`${type}:${CommonEvent.CLICK}`, this.onClickSelect); }); graph.off(`canvas:${CommonEvent.CLICK}`, this.onClickCanvas); } diff --git a/packages/g6/src/behaviors/hover-element.ts b/packages/g6/src/behaviors/hover-activate.ts similarity index 90% rename from packages/g6/src/behaviors/hover-element.ts rename to packages/g6/src/behaviors/hover-activate.ts index b8800a335b4..cf5ed26dcf6 100644 --- a/packages/g6/src/behaviors/hover-element.ts +++ b/packages/g6/src/behaviors/hover-activate.ts @@ -13,7 +13,7 @@ import { BaseBehavior } from './base-behavior'; * * Hover element behavior options */ -export interface HoverElementOptions extends BaseBehaviorOptions { +export interface HoverActivateOptions extends BaseBehaviorOptions { /** * 是否启用动画 * @@ -45,7 +45,7 @@ export interface HoverElementOptions extends BaseBehaviorOptions { * Active element state, default to`active` * @defaultValue 'active' */ - activeState?: State; + state?: State; /** * 非激活元素的状态,默认为不改变 * @@ -75,19 +75,19 @@ export interface HoverElementOptions extends BaseBehaviorOptions { * * When the mouse hovers over an element, you can activate the state of the element, such as highlighting nodes or edges. */ -export class HoverElement extends BaseBehavior { - static defaultOptions: Partial = { +export class HoverActivate extends BaseBehavior { + static defaultOptions: Partial = { animation: false, enable: true, degree: 0, - activeState: 'active', + state: 'active', inactiveState: undefined, }; private isFrozen = false; - constructor(context: RuntimeContext, options: HoverElementOptions) { - super(context, Object.assign({}, HoverElement.defaultOptions, options)); + constructor(context: RuntimeContext, options: HoverActivateOptions) { + super(context, Object.assign({}, HoverActivate.defaultOptions, options)); this.bindEvents(); } @@ -122,7 +122,7 @@ export class HoverElement extends BaseBehavior { }; private updateElementsState = (event: IPointerEvent, add: boolean) => { - if (!this.options.activeState && !this.options.inactiveState) return; + if (!this.options.state && !this.options.inactiveState) return; const { graph } = this.context; const { targetType, target } = event; @@ -136,8 +136,8 @@ export class HoverElement extends BaseBehavior { const states: Record = {}; - if (this.options.activeState) { - Object.assign(states, this.getElementsState(activeIds, this.options.activeState, add)); + if (this.options.state) { + Object.assign(states, this.getElementsState(activeIds, this.options.state, add)); } if (this.options.inactiveState) { diff --git a/packages/g6/src/behaviors/index.ts b/packages/g6/src/behaviors/index.ts index 4386011b9ba..85972af6bf6 100644 --- a/packages/g6/src/behaviors/index.ts +++ b/packages/g6/src/behaviors/index.ts @@ -1,27 +1,27 @@ export { BaseBehavior } from './base-behavior'; export { BrushSelect } from './brush-select'; -export { ClickElement } from './click-element'; +export { ClickSelect } from './click-select'; export { CollapseExpand } from './collapse-expand'; export { CreateEdge } from './create-edge'; export { DragCanvas } from './drag-canvas'; export { DragElement } from './drag-element'; export { DragElementForce } from './drag-element-force'; export { FocusElement } from './focus-element'; -export { HoverElement } from './hover-element'; +export { HoverActivate } from './hover-activate'; export { LassoSelect } from './lasso-select'; export { ScrollCanvas } from './scroll-canvas'; export { ZoomCanvas } from './zoom-canvas'; export type { BaseBehaviorOptions } from './base-behavior'; export type { BrushSelectOptions } from './brush-select'; -export type { ClickElementOptions } from './click-element'; +export type { ClickSelectOptions } from './click-select'; export type { CollapseExpandOptions } from './collapse-expand'; export type { CreateEdgeOptions } from './create-edge'; export type { DragCanvasOptions } from './drag-canvas'; export type { DragElementOptions } from './drag-element'; export type { DragElementForceOptions } from './drag-element-force'; export type { FocusElementOptions } from './focus-element'; -export type { HoverElementOptions } from './hover-element'; +export type { HoverActivateOptions } from './hover-activate'; export type { LassoSelectOptions } from './lasso-select'; export type { ScrollCanvasOptions } from './scroll-canvas'; export type { ZoomCanvasOptions } from './zoom-canvas'; diff --git a/packages/g6/src/exports.ts b/packages/g6/src/exports.ts index 5341d1d534b..e5aefd3ab63 100644 --- a/packages/g6/src/exports.ts +++ b/packages/g6/src/exports.ts @@ -1,14 +1,14 @@ export { BaseBehavior, BrushSelect, - ClickElement, + ClickSelect, CollapseExpand, CreateEdge, DragCanvas, DragElement, DragElementForce, FocusElement, - HoverElement, + HoverActivate, LassoSelect, ScrollCanvas, ZoomCanvas, @@ -106,14 +106,14 @@ export type { AnimationContext, AnimationEffectTiming, AnimationExecutor, Animat export type { BaseBehaviorOptions, BrushSelectOptions, - ClickElementOptions, + ClickSelectOptions, CollapseExpandOptions, CreateEdgeOptions, DragCanvasOptions, DragElementForceOptions, DragElementOptions, FocusElementOptions, - HoverElementOptions, + HoverActivateOptions, LassoSelectOptions, ScrollCanvasOptions, ZoomCanvasOptions, diff --git a/packages/g6/src/registry/build-in.ts b/packages/g6/src/registry/build-in.ts index 34449c3f916..d4cb6af78f4 100644 --- a/packages/g6/src/registry/build-in.ts +++ b/packages/g6/src/registry/build-in.ts @@ -1,14 +1,14 @@ import { ComboCollapse, ComboExpand, Fade, NodeCollapse, NodeExpand, PathIn, PathOut, Translate } from '../animations'; import { BrushSelect, - ClickElement, + ClickSelect, CollapseExpand, CreateEdge, DragCanvas, DragElement, DragElementForce, FocusElement, - HoverElement, + HoverActivate, LassoSelect, ScrollCanvas, ZoomCanvas, @@ -99,8 +99,8 @@ export const BUILT_IN_EXTENSIONS: ExtensionRegistry = { 'drag-element-force': DragElementForce, 'scroll-canvas': ScrollCanvas, 'collapse-expand': CollapseExpand, - 'click-element': ClickElement, - 'hover-element': HoverElement, + 'click-select': ClickSelect, + 'hover-activate': HoverActivate, 'focus-element': FocusElement, 'create-edge': CreateEdge, 'brush-select': BrushSelect, diff --git a/packages/site/common/api/behaviors/click-element.md b/packages/site/common/api/behaviors/click-element.md index 9b4a81ada14..307f0d89d0e 100644 --- a/packages/site/common/api/behaviors/click-element.md +++ b/packages/site/common/api/behaviors/click-element.md @@ -31,8 +31,8 @@ createGraph( }, behaviors: [ { - type: 'click-element', - key: 'click-element', + type: 'click-select', + key: 'click-select', }, ], plugins: ['grid-line'], @@ -41,13 +41,13 @@ createGraph( { width: 600, height: 300 }, (gui, graph) => { const options = { - key: 'click-element', - type: 'click-element', + key: 'click-select', + type: 'click-select', animation: true, enable: true, multiple: false, trigger: 'shift+click', - selectedState: 'selected', + state: 'selected', unselectedState: undefined, degree: 0, }; @@ -56,7 +56,7 @@ createGraph( optionFolder.add(options, 'animation'); optionFolder.add(options, 'enable'); optionFolder.add(options, 'degree', 0, 2, 1); - optionFolder.add(options, 'selectedState', ['active', 'selected', 'custom']); + optionFolder.add(options, 'state', ['active', 'selected', 'custom']); optionFolder.add(options, 'unselectedState', [undefined, 'inactive']); optionFolder.add(options, 'multiple').onChange((v) => trigger.show(v)); const trigger = optionFolder @@ -68,7 +68,7 @@ createGraph( optionFolder.onChange(({ property, value }) => { graph.updateBehavior({ - key: 'click-element', + key: 'click-select', [property]: value, }); graph.render(); diff --git a/packages/site/common/api/behaviors/hover-element.md b/packages/site/common/api/behaviors/hover-element.md index 7db7f1f00f0..102fae0908a 100644 --- a/packages/site/common/api/behaviors/hover-element.md +++ b/packages/site/common/api/behaviors/hover-element.md @@ -31,8 +31,8 @@ createGraph( }, behaviors: [ { - type: 'hover-element', - key: 'hover-element', + type: 'hover-activate', + key: 'hover-activate', }, ], plugins: ['grid-line'], @@ -41,12 +41,12 @@ createGraph( { width: 600, height: 300 }, (gui, graph) => { const options = { - key: 'hover-element', - type: 'hover-element', + key: 'hover-activate', + type: 'hover-activate', animation: true, enable: true, degree: 0, - activeState: 'active', + state: 'active', inactiveState: undefined, }; const optionFolder = gui.addFolder('ZoomCanvas Options'); @@ -54,12 +54,12 @@ createGraph( optionFolder.add(options, 'animation'); optionFolder.add(options, 'enable'); optionFolder.add(options, 'degree', 0, 2, 1); - optionFolder.add(options, 'activeState', ['active', 'selected', 'custom']); + optionFolder.add(options, 'state', ['active', 'selected', 'custom']); optionFolder.add(options, 'inactiveState', [undefined, 'inactive']); optionFolder.onChange(({ property, value }) => { graph.updateBehavior({ - key: 'hover-element', + key: 'hover-activate', [property]: value, }); graph.render(); diff --git a/packages/site/docs/manual/core-concept/behavior.en.md b/packages/site/docs/manual/core-concept/behavior.en.md index 8f63882e5e3..5805791db2e 100644 --- a/packages/site/docs/manual/core-concept/behavior.en.md +++ b/packages/site/docs/manual/core-concept/behavior.en.md @@ -16,13 +16,13 @@ In G6 5.x, the concept of "interaction mode" (Mode) has been removed. Users only G6 provides a rich set of interactive features, and users can choose the appropriate interactive behaviors according to their needs, including: - [Brush Select](/en/api/behaviors/brush-select): Box Selection -- [Click Select](/en/api/behaviors/click-element): Single Click Selection +- [Click Select](/en/api/behaviors/click-select): Single Click Selection - [Collapse Expand](/en/api/behaviors/collapse-expand): Expand and Collapse - [Create Edge](/en/api/behaviors/create-edge): Create an Edge - [Drag Canvas](/en/api/behaviors/drag-canvas): Drag the Canvas - [Drag Element](/en/api/behaviors/drag-element): Drag an Element - [Focus Element](/en/api/behaviors/focus-element): Focus on an Element -- [Hover Element](/en/api/behaviors/hover-element): Hover Over an Element +- [Hover Element](/en/api/behaviors/hover-activate): Hover Over an Element - [Lasso Select](/en/api/behaviors/lasso-select): Lasso Selection - [Zoom Canvas](/en/api/behaviors/zoom-canvas): Zoom the Canvas diff --git a/packages/site/docs/manual/core-concept/behavior.zh.md b/packages/site/docs/manual/core-concept/behavior.zh.md index 8ebbb08f1ab..0f63a4eb210 100644 --- a/packages/site/docs/manual/core-concept/behavior.zh.md +++ b/packages/site/docs/manual/core-concept/behavior.zh.md @@ -16,13 +16,13 @@ G6 5.x 已经移除了“交互模式”(Mode)这一概念,用户只需要管 G6 提供了丰富的交互功能,用户可以根据自己的需求选择合适的交互行为,包括: - [Brush Select](/api/behaviors/brush-select):框选 -- [Click Element](/api/behaviors/click-element):单击选中 +- [Click Element](/api/behaviors/click-select):单击选中 - [Collapse Expand](/api/behaviors/collapse-expand):展开收起 - [Create Edge](/api/behaviors/create-edge):创建边 - [Drag Canvas](/api/behaviors/drag-canvas):拖拽画布 - [Drag Element](/api/behaviors/drag-element):拖拽元素 - [Focus Element](/api/behaviors/focus-element):聚焦元素 -- [Hover Element](/api/behaviors/hover-element):悬停元素 +- [Hover Element](/api/behaviors/hover-activate):悬停元素 - [Lasso Select](/api/behaviors/lasso-select):套索选择 - [Zoom Canvas](/api/behaviors/zoom-canvas):缩放画布 diff --git a/packages/site/examples/behavior/highlight-element/demo/activate-relations.js b/packages/site/examples/behavior/highlight-element/demo/activate-relations.js index 5ae7926ce25..7d0479d8635 100644 --- a/packages/site/examples/behavior/highlight-element/demo/activate-relations.js +++ b/packages/site/examples/behavior/highlight-element/demo/activate-relations.js @@ -17,7 +17,7 @@ fetch('https://gw.alipayobjects.com/os/antvdemo/assets/data/xiaomi.json') data: format(data), behaviors: [ { - type: 'hover-element', + type: 'hover-activate', degree: 1, // 👈🏻 Activate relations. }, ], diff --git a/packages/site/examples/behavior/highlight-element/demo/basic.js b/packages/site/examples/behavior/highlight-element/demo/basic.js index 359608fa131..be742b732b9 100644 --- a/packages/site/examples/behavior/highlight-element/demo/basic.js +++ b/packages/site/examples/behavior/highlight-element/demo/basic.js @@ -15,7 +15,7 @@ fetch('https://gw.alipayobjects.com/os/antvdemo/assets/data/xiaomi.json') container: 'container', autoFit: 'view', data: format(data), - behaviors: ['hover-element'], + behaviors: ['hover-activate'], layout: { type: 'force', preventOverlap: true, diff --git a/packages/site/examples/behavior/highlight-element/demo/config-params.js b/packages/site/examples/behavior/highlight-element/demo/config-params.js index bc0cfe68b5c..dbaf7a030ed 100644 --- a/packages/site/examples/behavior/highlight-element/demo/config-params.js +++ b/packages/site/examples/behavior/highlight-element/demo/config-params.js @@ -37,10 +37,10 @@ fetch('https://gw.alipayobjects.com/os/antvdemo/assets/data/xiaomi.json') }, behaviors: [ { - type: 'hover-element', + type: 'hover-activate', enable: (event) => event.targetType === 'node', degree: 1, // 👈🏻 Activate relations. - activeState: 'highlight', + state: 'highlight', inactiveState: 'dim', onHover: (event) => { event.view.setCursor('pointer'); diff --git a/packages/site/examples/behavior/select/demo/click.js b/packages/site/examples/behavior/select/demo/click.js index 868fd72b8e1..897232f99d6 100644 --- a/packages/site/examples/behavior/select/demo/click.js +++ b/packages/site/examples/behavior/select/demo/click.js @@ -10,7 +10,7 @@ const data = { const graph = new Graph({ data, - behaviors: [{ type: 'click-element', multiple: true, trigger: ['shift'] }, 'drag-element'], + behaviors: [{ type: 'click-select', multiple: true, trigger: ['shift'] }, 'drag-element'], autoFit: 'center', }); diff --git a/packages/site/src/constants/locales/page-name.json b/packages/site/src/constants/locales/page-name.json index 8de0259bd42..b022affa3e7 100644 --- a/packages/site/src/constants/locales/page-name.json +++ b/packages/site/src/constants/locales/page-name.json @@ -44,14 +44,14 @@ "RandomLayout": ["Random", "随机布局"], "BaseBehavior": ["BaseBehavior", "基础交互"], "BrushSelect": ["BrushSelect", "框选"], - "ClickElement": ["ClickElement", "点击选中"], + "ClickSelect": ["ClickSelect", "点击选中"], "CollapseExpand": ["CollapseExpand", "展开折叠Combo"], "CreateEdge": ["CreateEdge", "创建边"], "DragCanvas": ["DragCanvas", "拖拽画布"], "DragElement": ["DragElement", "拖拽元素"], "DragElementForce": ["DragElementForce", "力导向拖拽元素"], "FocusElement": ["FocusElement", "聚焦元素"], - "HoverElement": ["HoverElement", "悬停激活"], + "HoverActivate": ["HoverActivate", "悬停激活"], "LassoSelect": ["LassoSelect", "套索选择"], "ScrollCanvas": ["ScrollCanvas", "滚动画布"], "ZoomCanvas": ["ZoomCanvas", "缩放画布"],