Skip to content

Commit

Permalink
style(graphin):fix typing error
Browse files Browse the repository at this point in the history
  • Loading branch information
pomelo-nwu committed Jan 5, 2021
1 parent 8c8a5bd commit d62768f
Show file tree
Hide file tree
Showing 11 changed files with 186 additions and 161 deletions.
5 changes: 2 additions & 3 deletions packages/graphin-components/src/EdgeBundling/demos/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from 'react';
import Graphin, { Utils, GraphinContext } from '@antv/graphin';
import { ContextMenu, EdgeBundling } from '@antv/graphin-components';
import G6 from '@antv/g6';
import Graphin, { Utils, G6 } from '@antv/graphin';
import { EdgeBundling } from '@antv/graphin-components';

// Do not forget to import CSS
import '@antv/graphin/dist/index.css';
Expand Down
10 changes: 5 additions & 5 deletions packages/graphin-components/src/EdgeBundling/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ import React from 'react';

import { GraphinContext, G6 } from '@antv/graphin';

interface IEdgeBundlingProps {}
let edgeBundling;
const EdgeBundling: React.FunctionComponent<IEdgeBundlingProps> = (props) => {
const EdgeBundling: React.FunctionComponent = () => {
const { graph } = React.useContext(GraphinContext);

React.useEffect(() => {
edgeBundling = new G6.Bundling({
const edgeBundling = new G6.Bundling({
bundleThreshold: 0.6,
K: 100,
});
const data = graph.save();
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const data = graph.save() as any;
graph.addPlugin(edgeBundling);

edgeBundling.bundling(data);
graph.data(data);
graph.render();
Expand Down
10 changes: 7 additions & 3 deletions packages/graphin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@ import registerGraphinForce from './layout/inner/registerGraphinForce';
import registerRenderLayout from './layout/inner/registerRenderLayout';
import { registerGraphinCircle } from './shape';

export { default as G6 } from '@antv/g6';
export {
/** G6类抛出去 */
default as G6,
/** 外部用户需要断言的 G6 类型 */
Graph,
IG6GraphEvent,
} from '@antv/g6';

export default Graphin;
export { Utils, Layout, GraphinContext, Behaviors };

export { IG6GraphEvent } from '@antv/g6/es/types';

export interface GraphEvent extends MouseEvent {
item: any;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down
2 changes: 1 addition & 1 deletion packages/graphin/src/layout/force/Elements.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable max-classes-per-file */
import { Node as NodeType, Edge as EdgeType } from '../../types';
import { IUserNode as NodeType, IUserEdge as EdgeType } from '../../typings/type';

export class Node {
id: string;
Expand Down
5 changes: 3 additions & 2 deletions packages/graphin/src/layout/force/ForceLayout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import Point from './Point';
import { Node, Edge } from './Elements';
import Spring from './Spring';
import { getDegree } from '../utils/graph';
import { Data, Node as NodeType, Graph } from '../../types';
import { Item } from '@antv/g6/lib/types';
import { IGraphData as Data, IUserNode as NodeType } from '../../typings/type';
import { Item, Graph } from '@antv/g6/';

type ForceNodeType = Node;

Expand Down Expand Up @@ -155,6 +155,7 @@ class ForceLayout {
this.sourceData = {
nodes: [],
edges: [],
combos: [],
};
this.nodes = [];
this.edges = [];
Expand Down
2 changes: 1 addition & 1 deletion packages/graphin/src/layout/force/Point.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Vector from './Vector';
import { Node } from '../../types';
import { IUserNode as Node } from '../../typings/type';

class Point {
/** 点的位置,用[x,y]向量来表示 */
Expand Down
12 changes: 6 additions & 6 deletions packages/graphin/src/layout/inner/tweak.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Data, Node, Edge } from '../../types';
import { IGraphData, IUserNode, IUserEdge } from '../../typings/type';

/* eslint-disable no-param-reassign */
const getRandomPosition = () => {
Expand All @@ -12,13 +12,13 @@ const getRandomPosition = () => {

const width = 500;
const height = 300;
const tweak = (currentData: Data, prevData: Data) => {
const tweak = (currentData: IGraphData, prevData: IGraphData) => {
const { nodes: currNodes, edges: currEdges } = currentData;
const { nodes: preNodes } = prevData;

/** 将图上之前节点的位置信息存储在positionMap中 */
const positionMap = new Map();
preNodes.forEach((item: Node) => {
preNodes.forEach((item: IUserNode) => {
const { id, x, y } = item;
positionMap.set(id, {
x,
Expand All @@ -27,7 +27,7 @@ const tweak = (currentData: Data, prevData: Data) => {
});

const incrementNodesMap = new Map();
currNodes.forEach((node: Node) => {
currNodes.forEach((node: IUserNode) => {
const { id } = node;
const position = positionMap.get(id);
if (position) {
Expand All @@ -39,7 +39,7 @@ const tweak = (currentData: Data, prevData: Data) => {
});

const incrementPositonMap = new Map();
currEdges.forEach((edge: Edge) => {
currEdges.forEach((edge: IUserEdge) => {
const { source, target } = edge;

const nodeInSource = incrementNodesMap.get(source);
Expand All @@ -63,7 +63,7 @@ const tweak = (currentData: Data, prevData: Data) => {
}
});

currNodes.forEach((node: Node) => {
currNodes.forEach((node: IUserNode) => {
const { id } = node;
const position = positionMap.get(id) || incrementPositonMap.get(id);

Expand Down
2 changes: 1 addition & 1 deletion packages/graphin/src/layout/utils/graph.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable import/prefer-default-export */
import { Edge } from '../../layout/force/Elements';
import { Node } from '../../types';
import { IUserNode as Node } from '../../typings/type';

export const getDegree = (node: Node, edges: Edge[]) => {
const nodeId = node.data.id;
Expand Down
Loading

0 comments on commit d62768f

Please sign in to comment.