Skip to content

Commit

Permalink
refactor: rename toggle-label-visibility to auto-adapt-label
Browse files Browse the repository at this point in the history
  • Loading branch information
yvonneyx committed Oct 11, 2024
1 parent b5863ee commit 3240665
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import data from '@@/dataset/language-tree.json';
import { Graph, IPointerEvent, type Element } from '@antv/g6';

export const behaviorToggleLabelVisibility: TestCase = async (context) => {
export const behaviorAutoAdaptLabel: TestCase = async (context) => {
const graph = new Graph({
...context,
padding: 20,
Expand Down Expand Up @@ -44,7 +44,7 @@ export const behaviorToggleLabelVisibility: TestCase = async (context) => {
};
},
{
type: 'toggle-label-visibility',
type: 'auto-adapt-label',
padding: 0,
},
],
Expand Down
2 changes: 1 addition & 1 deletion packages/g6/__tests__/demos/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export { animationElementPosition } from './animation-element-position';
export { animationElementState } from './animation-element-state';
export { animationElementStateSwitch } from './animation-element-state-switch';
export { animationElementStylePosition } from './animation-element-style-position';
export { behaviorAutoAdaptLabel } from './behavior-auto-adapt-label';
export { behaviorBrushSelect } from './behavior-brush-select';
export { behaviorClickSelect } from './behavior-click-select';
export { behaviorCreateEdge } from './behavior-create-edge';
Expand All @@ -18,7 +19,6 @@ export { behaviorHoverActivate } from './behavior-hover-activate';
export { behaviorLassoSelect } from './behavior-lasso-select';
export { behaviorOptimizeViewportTransform } from './behavior-optimize-viewport-transform';
export { behaviorScrollCanvas } from './behavior-scroll-canvas';
export { behaviorToggleLabelVisibility } from './behavior-toggle-label-visibility';
export { behaviorZoomCanvas } from './behavior-zoom-canvas';
export { bugTooltipResize } from './bug-tooltip-resize';
export { canvasCursor } from './canvas-cursor';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { CanvasEvent, positionOf, type Graph } from '@/src';
import { behaviorToggleLabelVisibility } from '@@/demos';
import { behaviorAutoAdaptLabel } from '@@/demos';
import { createDemoGraph } from '@@/utils';

describe('behavior toggle label visibility', () => {
let graph: Graph;

beforeAll(async () => {
graph = await createDemoGraph(behaviorToggleLabelVisibility, { animation: false });
graph = await createDemoGraph(behaviorAutoAdaptLabel, { animation: false });
});

afterAll(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { BaseBehavior } from './base-behavior';
*
* <en/> Toggle label visibility options
*/
export interface ToggleLabelVisibilityOptions extends BaseBehaviorOptions {
export interface AutoAdaptLabelOptions extends BaseBehaviorOptions {
/**
* <zh/> 是否启用
*
Expand Down Expand Up @@ -74,16 +74,16 @@ export interface ToggleLabelVisibilityOptions extends BaseBehaviorOptions {
*
* <en/> Dynamically adjust the visibility of element labels to ensure they are clearly visible within the view, prevent label overlap and reduce visual clutter.
*/
export class ToggleLabelVisibility extends BaseBehavior<ToggleLabelVisibilityOptions> {
static defaultOptions: Partial<ToggleLabelVisibilityOptions> = {
export class AutoAdaptLabel extends BaseBehavior<AutoAdaptLabelOptions> {
static defaultOptions: Partial<AutoAdaptLabelOptions> = {
enable: true,
throttle: 100,
padding: 0,
nodeSorter: { type: 'degree' },
};

constructor(context: RuntimeContext, options: ToggleLabelVisibilityOptions) {
super(context, Object.assign({}, ToggleLabelVisibility.defaultOptions, options));
constructor(context: RuntimeContext, options: AutoAdaptLabelOptions) {
super(context, Object.assign({}, AutoAdaptLabel.defaultOptions, options));
this.bindEvents();
}

Expand Down
4 changes: 2 additions & 2 deletions packages/g6/src/behaviors/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { AutoAdaptLabel } from './auto-adapt-label';
export { BaseBehavior } from './base-behavior';
export { BrushSelect } from './brush-select';
export { ClickSelect } from './click-select';
Expand All @@ -12,9 +13,9 @@ export { HoverActivate } from './hover-activate';
export { LassoSelect } from './lasso-select';
export { OptimizeViewportTransform } from './optimize-viewport-transform';
export { ScrollCanvas } from './scroll-canvas';
export { ToggleLabelVisibility } from './toggle-label-visibility';
export { ZoomCanvas } from './zoom-canvas';

export type { AutoAdaptLabelOptions } from './auto-adapt-label';
export type { BaseBehaviorOptions } from './base-behavior';
export type { BrushSelectOptions } from './brush-select';
export type { ClickSelectOptions } from './click-select';
Expand All @@ -29,5 +30,4 @@ export type { HoverActivateOptions } from './hover-activate';
export type { LassoSelectOptions } from './lasso-select';
export type { OptimizeViewportTransformOptions } from './optimize-viewport-transform';
export type { ScrollCanvasOptions } from './scroll-canvas';
export type { ToggleLabelVisibilityOptions } from './toggle-label-visibility';
export type { ZoomCanvasOptions } from './zoom-canvas';
4 changes: 2 additions & 2 deletions packages/g6/src/registry/build-in.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
} from '@antv/g';
import { ComboCollapse, ComboExpand, Fade, NodeCollapse, NodeExpand, PathIn, PathOut, Translate } from '../animations';
import {
AutoAdaptLabel,
BrushSelect,
ClickSelect,
CollapseExpand,
Expand All @@ -25,7 +26,6 @@ import {
LassoSelect,
OptimizeViewportTransform,
ScrollCanvas,
ToggleLabelVisibility,
ZoomCanvas,
} from '../behaviors';
import {
Expand Down Expand Up @@ -129,7 +129,7 @@ const BUILT_IN_EXTENSIONS: ExtensionRegistry = {
'focus-element': FocusElement,
'hover-activate': HoverActivate,
'lasso-select': LassoSelect,
'toggle-label-visibility': ToggleLabelVisibility,
'auto-adapt-label': AutoAdaptLabel,
'optimize-viewport-transform': OptimizeViewportTransform,
'scroll-canvas': ScrollCanvas,
'zoom-canvas': ZoomCanvas,
Expand Down
1 change: 1 addition & 0 deletions packages/site/src/constants/locales/page-name.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"RadialLayout": ["Radial", "径向布局"],
"RandomLayout": ["Random", "随机布局"],
"BaseBehavior": ["BaseBehavior", "基础交互"],
"AutoAdaptLabel": ["AutoAdaptLabel", "基于密度标签自适应"],
"BrushSelect": ["BrushSelect", "框选"],
"ClickSelect": ["ClickSelect", "点击选中"],
"CollapseExpand": ["CollapseExpand", "展开/收起元素"],
Expand Down

0 comments on commit 3240665

Please sign in to comment.