Skip to content

Commit

Permalink
fix: cr issues
Browse files Browse the repository at this point in the history
  • Loading branch information
yvonneyx committed Mar 25, 2024
1 parent 3b5c377 commit fcf0d00
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 26 deletions.
24 changes: 12 additions & 12 deletions packages/g6/__tests__/unit/utils/relation.spec.ts
@@ -1,4 +1,4 @@
import { getElementNthDegreeIDs, getNodeNthDegreeIDs } from '@/src/utils/relation';
import { getElementNthDegreeIds, getNodeNthDegreeIds } from '@/src/utils/relation';
import { Graph } from '../../../src';

describe('relation', () => {
Expand All @@ -23,18 +23,18 @@ describe('relation', () => {
combos: [{ id: 'combo1' }],
},
});
it('getElementNthDegreeIDs', () => {
expect(getElementNthDegreeIDs(graph, 'node', '1', 0)).toEqual(['1']);
expect(getElementNthDegreeIDs(graph, 'node', '1', 1)).toEqual(['1', '1-2', '1-3', '2', '3']);
expect(getElementNthDegreeIDs(graph, 'edge', '1-2', 0)).toEqual(['1-2']);
expect(getElementNthDegreeIDs(graph, 'edge', '1-2', 1)).toEqual(['1', '2', '1-2']);
expect(getElementNthDegreeIDs(graph, 'edge', '1-2', 2)).toEqual(['1', '1-2', '1-3', '2', '3', '2-4', '4']);
expect(getElementNthDegreeIDs(graph, 'combo', 'combo1', 1)).toEqual(['combo1', 'combo1-6', '6']);
it('getElementNthDegreeIds', () => {
expect(getElementNthDegreeIds(graph, 'node', '1', 0)).toEqual(['1']);
expect(getElementNthDegreeIds(graph, 'node', '1', 1)).toEqual(['1', '1-2', '1-3', '2', '3']);
expect(getElementNthDegreeIds(graph, 'edge', '1-2', 0)).toEqual(['1-2']);
expect(getElementNthDegreeIds(graph, 'edge', '1-2', 1)).toEqual(['1', '2', '1-2']);
expect(getElementNthDegreeIds(graph, 'edge', '1-2', 2)).toEqual(['1', '1-2', '1-3', '2', '3', '2-4', '4']);
expect(getElementNthDegreeIds(graph, 'combo', 'combo1', 1)).toEqual(['combo1', 'combo1-6', '6']);
});

it('getNodeNthDegreeIDs', () => {
expect(getNodeNthDegreeIDs(graph, '1', 0)).toEqual(['1']);
expect(getNodeNthDegreeIDs(graph, '1', 1)).toEqual(['1', '1-2', '1-3', '2', '3']);
expect(getNodeNthDegreeIDs(graph, '1', 2)).toEqual(['1', '1-2', '1-3', '2', '2-4', '3', '3-5', '4', '5']);
it('getNodeNthDegreeIds', () => {
expect(getNodeNthDegreeIds(graph, '1', 0)).toEqual(['1']);
expect(getNodeNthDegreeIds(graph, '1', 1)).toEqual(['1', '1-2', '1-3', '2', '3']);
expect(getNodeNthDegreeIds(graph, '1', 2)).toEqual(['1', '1-2', '1-3', '2', '2-4', '3', '3-5', '4', '5']);
});
});
8 changes: 4 additions & 4 deletions packages/g6/src/behaviors/hover-element.ts
@@ -1,12 +1,12 @@
import { FederatedMouseEvent } from '@antv/g';
import { ID } from '@antv/graphlib';
import type { FederatedMouseEvent } from '@antv/g';
import type { ID } from '@antv/graphlib';
import { isFunction } from '@antv/util';
import { CommonEvent } from '../constants';
import { ELEMENT_TYPES } from '../constants/element';
import type { RuntimeContext } from '../runtime/types';
import type { BehaviorEvent, ElementType, State } from '../types';
import { getIds } from '../utils/id';
import { getElementNthDegreeIDs } from '../utils/relation';
import { getElementNthDegreeIds } from '../utils/relation';
import type { BaseBehaviorOptions } from './base-behavior';
import { BaseBehavior } from './base-behavior';

Expand Down Expand Up @@ -97,7 +97,7 @@ export class HoverElement extends BaseBehavior<HoverElementOptions> {
const { graph } = this.context;
const { targetType, target } = event;

const activeIds = getElementNthDegreeIDs(graph, targetType as ElementType, target.id, this.options.degree);
const activeIds = getElementNthDegreeIds(graph, targetType as ElementType, target.id, this.options.degree);

const states: Record<ID, State[]> = {};

Expand Down
4 changes: 1 addition & 3 deletions packages/g6/src/constants/element.ts
@@ -1,9 +1,7 @@
import type { ElementType } from '../types';

/**
* <zh/> 根据不同的 node,自动计算 icon 的大小之后,乘以一下缩放系数,防止贴的太紧密。
* <en/> According to the different nodes, the size of the icon is automatically calculated, and then multiplied by the following scaling factor to prevent it from being too close.
*/
export const ICON_SIZE_RATIO = 0.8;

export const ELEMENT_TYPES: ElementType[] = ['node', 'edge', 'combo'];
export const ELEMENT_TYPES = ['node', 'edge', 'combo'] as const;
4 changes: 2 additions & 2 deletions packages/g6/src/runtime/element.ts
Expand Up @@ -7,6 +7,7 @@ import { groupBy, isEmpty } from '@antv/util';
import { executor as animationExecutor } from '../animations';
import type { AnimationContext } from '../animations/types';
import { AnimationType, ChangeTypeEnum, GraphEvent } from '../constants';
import { ELEMENT_TYPES } from '../constants/element';
import type { BaseNode } from '../elements/nodes';
import type { BaseShape } from '../elements/shapes';
import { getExtension } from '../registry';
Expand Down Expand Up @@ -72,8 +73,7 @@ export class ElementController {
}

private forEachElementData(callback: (elementType: ElementType, elementData: ElementData) => void) {
const elementTypes: ElementType[] = ['node', 'edge', 'combo'];
elementTypes.forEach((elementType) => {
ELEMENT_TYPES.forEach((elementType) => {
const elementData = this.context.model.getElementData(elementType);
callback(elementType, elementData);
});
Expand Down
10 changes: 5 additions & 5 deletions packages/g6/src/utils/relation.ts
Expand Up @@ -20,16 +20,16 @@ import { bfs } from './traverse';
* @param degree - <zh/> 指定的度数 | <en/> the specified degree
* @returns - <zh/> 返回节点和边的 ID 数组 | <en/> Returns an array of node and edge IDs
*/
export function getElementNthDegreeIDs(graph: Graph, elementType: ElementType, elementId: ID, degree: number): ID[] {
export function getElementNthDegreeIds(graph: Graph, elementType: ElementType, elementId: ID, degree: number): ID[] {
if (elementType === 'combo' || elementType === 'node') {
return getNodeNthDegreeIDs(graph, elementId, degree);
return getNodeNthDegreeIds(graph, elementId, degree);
}

const edgeData = graph.getEdgeData(elementId);
if (!edgeData) return [];

const sourceRelations = getNodeNthDegreeIDs(graph, edgeData.source, degree - 1);
const targetRelations = getNodeNthDegreeIDs(graph, edgeData.target, degree - 1);
const sourceRelations = getNodeNthDegreeIds(graph, edgeData.source, degree - 1);
const targetRelations = getNodeNthDegreeIds(graph, edgeData.target, degree - 1);

return Array.from(new Set<ID>([...sourceRelations, ...targetRelations, elementId]));
}
Expand All @@ -47,7 +47,7 @@ export function getElementNthDegreeIDs(graph: Graph, elementType: ElementType, e
* @param degree - <zh/> 指定的度数 | <en/> The specified degree
* @returns - <zh/> 返回节点和边的 ID 数组 | <en/> Returns an array of node and edge IDs
*/
export function getNodeNthDegreeIDs(graph: Graph, startNodeId: ID, degree: number): ID[] {
export function getNodeNthDegreeIds(graph: Graph, startNodeId: ID, degree: number): ID[] {
const visitedNodes = new Set<ID>();
const visitedEdges = new Set<ID>();
const relations = new Set<ID>();
Expand Down

0 comments on commit fcf0d00

Please sign in to comment.