Skip to content

Commit

Permalink
refactor: adjust type definition (#5545)
Browse files Browse the repository at this point in the history
* refactor: adjust type definition

* fix: fix graphlib type define
  • Loading branch information
Aarebecca authored Mar 15, 2024
1 parent 5dcbb5e commit 87621a4
Show file tree
Hide file tree
Showing 88 changed files with 432 additions and 485 deletions.
4 changes: 2 additions & 2 deletions packages/g6/__tests__/demo/animation/animation-breathe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import type { AnimationTestCase } from '../types';
type ShapeStyleProps = BaseShapeStyleProps & { size: number; color: string; outline: number; outlineOpacity: number };

class Shape extends BaseShape<ShapeStyleProps> {
private getKeyStyle({ size, color }: any = this.attributes) {
private getKeyStyle({ size, color } = this.attributes) {
return {
r: size / 2,
fill: color,
};
}

private getHaloStyle({ size, color, outline, outlineOpacity }: any = this.attributes) {
private getHaloStyle({ size, color, outline, outlineOpacity } = this.attributes) {
return {
r: size / 2,
fill: 'transparent',
Expand Down
4 changes: 2 additions & 2 deletions packages/g6/__tests__/demo/animation/animation-fade-in.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import type { AnimationTestCase } from '../types';
type ShapeStyleProps = BaseShapeStyleProps & { size: number; color: string };

class Shape extends BaseShape<ShapeStyleProps> {
private getKeyStyle({ size, color }: any = this.attributes) {
private getKeyStyle({ size, color } = this.attributes) {
return {
r: size / 2,
fill: color,
};
}

private getHaloStyle({ size, color }: any = this.attributes) {
private getHaloStyle({ size, color } = this.attributes) {
return {
r: size / 2 + 2,
fill: 'transparent',
Expand Down
4 changes: 2 additions & 2 deletions packages/g6/__tests__/demo/animation/animation-translate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import type { AnimationTestCase } from '../types';
type ShapeStyleProps = BaseShapeStyleProps & { size: number; color: string };

class Shape extends BaseShape<ShapeStyleProps> {
private getKeyStyle({ size, color }: any = this.attributes) {
private getKeyStyle({ size, color } = this.attributes) {
return {
r: size / 2,
fill: color,
};
}

private getHaloStyle({ size, color }: any = this.attributes) {
private getHaloStyle({ size, color } = this.attributes) {
return {
r: size / 2 + 2,
fill: 'transparent',
Expand Down
6 changes: 3 additions & 3 deletions packages/g6/__tests__/demo/animation/animation-wave.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@ import type { AnimationTestCase } from '../types';
type ShapeStyleProps = BaseShapeStyleProps & { size: number; color: string };

class Shape extends BaseShape<ShapeStyleProps> {
private getInnerStyle({ size, color, opacity }: any = this.attributes) {
private getInnerStyle({ size, color, opacity } = this.attributes) {
return {
r: size / 2,
fill: color,
opacity,
};
}

private getMiddleStyle({ size, color, opacity }: any = this.attributes) {
private getMiddleStyle({ size, color, opacity } = this.attributes) {
return {
r: size / 2,
fill: color,
opacity,
};
}

private getOuterStyle({ size, color, opacity }: any = this.attributes) {
private getOuterStyle({ size, color, opacity } = this.attributes) {
return {
r: size / 2,
fill: color,
Expand Down
4 changes: 2 additions & 2 deletions packages/g6/__tests__/demo/animation/animation-zoom-in.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import type { AnimationTestCase } from '../types';
type ShapeStyleProps = BaseShapeStyleProps & { size: number; color: string; outline: number; outlineOpacity: number };

class Shape extends BaseShape<ShapeStyleProps> {
private getKeyStyle({ size, color }: any = this.attributes) {
private getKeyStyle({ size, color } = this.attributes) {
return {
r: size / 2,
fill: color,
};
}

private getHaloStyle({ size, color, outline, outlineOpacity }: any = this.attributes) {
private getHaloStyle({ size, color, outline, outlineOpacity } = this.attributes) {
return {
r: size / 2,
fill: 'transparent',
Expand Down
36 changes: 12 additions & 24 deletions packages/g6/__tests__/demo/case/combo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ export const combo: STDTestCase = async (context) => {
data,
node: {
style: {
labelText: (d: any) => d.id,
labelText: (d) => d.id,
},
},
combo: {
style: {
labelText: (d: any) => d.id,
labelText: (d) => d.id,
lineDash: 0,
collapsedLineDash: [5, 5],
},
Expand All @@ -60,14 +60,13 @@ export const combo: STDTestCase = async (context) => {
const COLLAPSED_MARKER_TYPE = ['child-count', 'descendant-count', 'node-count', 'custom'];

combo.form = (panel) => {
const config = {
const config: Record<string, any> = {
combo2Type: 'circle',
collapsedOrigin: 'top',
collapsedMarker: true,
collapsedMarkerType: 'child-count',
collapseCombo1: () => {
graph.updateComboData((data) => [
...data,
graph.updateComboData([
{
id: 'combo-1',
style: {
Expand All @@ -76,16 +75,15 @@ export const combo: STDTestCase = async (context) => {
collapsedMarker: config.collapsedMarker,
collapsedMarkerType:
config.collapsedMarkerType === 'custom'
? (children: any) => children.length.toString() + 'nodes'
? (children) => children.length.toString() + 'nodes'
: config.collapsedMarkerType,
},
},
]);
graph.render();
},
expandCombo1: () => {
graph.updateComboData((data) => [
...data,
graph.updateComboData([
{
id: 'combo-1',
style: {
Expand All @@ -108,16 +106,15 @@ export const combo: STDTestCase = async (context) => {
collapsedMarker: config.collapsedMarker,
collapsedMarkerType:
config.collapsedMarkerType === 'custom'
? (children: any) => children.length.toString() + 'nodes'
? (children) => children.length.toString() + 'nodes'
: config.collapsedMarkerType,
},
},
]);
graph.render();
},
expandCombo2: () => {
graph.updateComboData((data) => [
...data,
graph.updateComboData([
{
id: 'combo-2',
style: {
Expand Down Expand Up @@ -151,21 +148,12 @@ export const combo: STDTestCase = async (context) => {
panel.add(config, 'combo2Type', COMBO_TYPE).onChange((type: string) => {
config.combo2Type = type;
const combo2Data = graph.getComboData('combo-2');
graph.updateComboData((data) => [
...data,
{ ...combo2Data, style: { ...combo2Data.style, type: config.combo2Type } },
]);
graph.updateComboData([{ ...combo2Data, style: { ...combo2Data.style, type: config.combo2Type } }]);
graph.render();
}),
panel.add(config, 'collapsedOrigin', COLLAPSED_ORIGIN).onChange((collapsedOrigin: string) => {
config.collapsedOrigin = collapsedOrigin;
}),
panel.add(config, 'collapsedMarker').onChange((collapsedMarker: boolean) => {
config.collapsedMarker = collapsedMarker;
}),
panel.add(config, 'collapsedMarkerType', COLLAPSED_MARKER_TYPE).onChange((collapsedMarkerType: string) => {
config.collapsedMarkerType = collapsedMarkerType;
}),
panel.add(config, 'collapsedOrigin', COLLAPSED_ORIGIN),
panel.add(config, 'collapsedMarker'),
panel.add(config, 'collapsedMarkerType', COLLAPSED_MARKER_TYPE),
panel.add(config, 'collapseCombo1'),
panel.add(config, 'expandCombo1'),
panel.add(config, 'collapseCombo2'),
Expand Down
2 changes: 1 addition & 1 deletion packages/g6/__tests__/demo/case/common-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const commonGraph: STDTestCase = async (context) => {
data,
node: {
style: {
fill: (d: any) => (d.id === '33' ? '#d4414c' : '#2f363d'),
fill: (d) => (d.id === '33' ? '#d4414c' : '#2f363d'),
},
},
layout: { type: 'd3force' },
Expand Down
9 changes: 5 additions & 4 deletions packages/g6/__tests__/demo/case/element-port.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Graph } from '@/src';
import { idOf } from '@/src/utils/id';
import type { STDTestCase } from '../types';

export const elementPort: STDTestCase = async (context) => {
Expand All @@ -25,10 +26,10 @@ export const elementPort: STDTestCase = async (context) => {
},
node: {
style: {
type: (d: any) => (d.id === 'node-1' ? 'circle' : 'rect'),
size: (d: any) => (d.id === 'node-1' ? 30 : [50, 150]),
type: (d) => (d.id === 'node-1' ? 'circle' : 'rect'),
size: (d) => (d.id === 'node-1' ? 30 : [50, 150]),
port: true,
ports: (d: any) =>
ports: (d) =>
d.id === 'node-2'
? [
{ key: 'port-1', placement: [0, 0.15] },
Expand All @@ -41,7 +42,7 @@ export const elementPort: STDTestCase = async (context) => {
edge: {
style: {
endArrow: true,
targetPort: (d: any) => `port-${d.id.split('-')[1]}`,
targetPort: (d) => `port-${idOf(d).toString().split('-')[1]}`,
},
},
});
Expand Down
4 changes: 2 additions & 2 deletions packages/g6/__tests__/demo/case/element-visibility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ export const elementVisibility: STDTestCase = async (context) => {
],
},
theme: 'light',
node: { style: { size: 20, labelText: (d: any) => d.id.at(-1) } },
edge: { style: { endArrow: true, labelText: (d: any) => d.id } },
node: { style: { size: 20, labelText: (d) => d.id!.toString().at(-1)! } },
edge: { style: { endArrow: true, labelText: (d) => d.id! } },
});

await graph.render();
Expand Down
2 changes: 1 addition & 1 deletion packages/g6/__tests__/demo/case/layout-circular-degree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const layoutCircularDegree: STDTestCase = async (context) => {
data,
node: {
style: {
labelText: (d: { id: string }) => d.id,
labelText: (d) => d.id,
},
},
edge: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const layoutCircularDivision: STDTestCase = async (context) => {
data,
node: {
style: {
labelText: (d: { id: string }) => d.id,
labelText: (d) => d.id,
},
},
edge: {
Expand Down
2 changes: 1 addition & 1 deletion packages/g6/__tests__/demo/case/layout-circular-spiral.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const layoutCircularSpiral: STDTestCase = async (context) => {
data,
node: {
style: {
labelText: (d: { id: string }) => d.id,
labelText: (d) => d.id,
},
},
edge: {
Expand Down
15 changes: 3 additions & 12 deletions packages/g6/__tests__/demo/case/layout-combo-combined.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@ import { Graph } from '@/src';
import data from '@@/dataset/combo.json';
import type { STDTestCase } from '../types';

type Item = {
id: string;
data: {
size?: number;
color?: string;
};
};

export const layoutComboCombined: STDTestCase = async (context) => {
const graph = new Graph({
...context,
Expand All @@ -21,13 +13,12 @@ export const layoutComboCombined: STDTestCase = async (context) => {
node: {
style: {
size: 20,
labelText: (d: Item) => d.id,
labelText: (d) => d.id,
},
},
edge: {
// @ts-expect-error
style: (model: Item) => {
const { size, color } = model.data;
style: (model) => {
const { size, color } = model.data as { size: number; color: string };
return { stroke: color || '#99ADD1', lineWidth: size || 1 };
},
},
Expand Down
13 changes: 3 additions & 10 deletions packages/g6/__tests__/demo/case/layout-dagre-flow-combo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@ import { Graph } from '@/src';
import data from '@@/dataset/dagre-combo.json';
import type { STDTestCase } from '../types';

type Item = {
id: string;
style: {
parentId: string;
};
};

export const layoutDagreFlowCombo: STDTestCase = async (context) => {
const graph = new Graph({
...context,
Expand All @@ -19,11 +12,11 @@ export const layoutDagreFlowCombo: STDTestCase = async (context) => {
type: 'rect',
size: [60, 30],
radius: 8,
labelText: (d: Item) => d.id,
labelText: (d) => d.id,
labelPlacement: 'center',
},
palette: {
field: (d: any) => d.style?.parentId,
field: (d) => d.style?.parentId,
},
},
edge: {
Expand All @@ -36,7 +29,7 @@ export const layoutDagreFlowCombo: STDTestCase = async (context) => {
style: {
type: 'rect',
radius: 8,
labelText: (d: Item) => d.id,
labelText: (d) => d.id,
lineDash: 0,
collapsedLineDash: [5, 5],
},
Expand Down
2 changes: 1 addition & 1 deletion packages/g6/__tests__/demo/case/layout-dagre-flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const layoutDagreFlow: STDTestCase = async (context) => {
size: [60, 30],
radius: 8,
labelPlacement: 'center',
labelText: (d: { id: string }) => d.id,
labelText: (d) => d.id,
},
},
edge: {
Expand Down
2 changes: 1 addition & 1 deletion packages/g6/__tests__/demo/case/layout-force.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const layoutForce: STDTestCase = async (context) => {
},
node: {
style: {
labelText: (d: any) => d.id,
labelText: (d) => d.id,
labelMaxWidth: '300%',
},
palette: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const layoutFruchtermanBasic: STDTestCase = async (context) => {
node: {
style: {
labelPlacement: 'center',
labelText: (d: any) => d.id,
labelText: (d) => d.id,
},
},
layout: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const layoutFruchtermanCluster: STDTestCase = async (context) => {
node: {
style: {
labelPlacement: 'center',
labelText: (d: any) => d.id,
labelText: (d) => d.id,
},
palette: {
field: 'cluster',
Expand Down
2 changes: 1 addition & 1 deletion packages/g6/__tests__/demo/case/layout-grid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const layoutGrid: STDTestCase = async (context) => {
data,
node: {
style: {
labelText: (d: any) => d.id,
labelText: (d) => d.id,
},
},
layout: {
Expand Down
2 changes: 1 addition & 1 deletion packages/g6/__tests__/demo/case/layout-mds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const layoutMDS: STDTestCase = async (context) => {
data,
node: {
style: {
labelText: (d: any) => d.id,
labelText: (d) => d.id,
labelPlacement: 'center',
},
},
Expand Down
2 changes: 1 addition & 1 deletion packages/g6/__tests__/demo/case/layout-radial-basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const layoutRadialBasic: STDTestCase = async (context) => {
data,
node: {
style: {
labelText: (d: { id: string }) => d.id,
labelText: (d) => d.id,
labelPlacement: 'center',
},
},
Expand Down
Loading

0 comments on commit 87621a4

Please sign in to comment.