Skip to content

Commit

Permalink
Merge c031b77 into 73ec89d
Browse files Browse the repository at this point in the history
  • Loading branch information
lxfu1 committed Jul 30, 2021
2 parents 73ec89d + c031b77 commit 777b0d5
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/graphs/flowAnalysisGraph/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ const FlowAnalysisGraph: React.FC<FlowAnalysisGraphConfig> = (props) => {
processMinimap(minimapCfg, graph);
bindStateEvents(graph, uProps as FlowAnalysisGraphConfig);
if (markerCfg) {
bindSourceMapCollapseEvents(graph, data as FlowAnalysisGraphConfig['data']);
bindSourceMapCollapseEvents(graph);
}
renderGraph(graph, data);
if (onReady) {
Expand Down
2 changes: 1 addition & 1 deletion src/graphs/fundFlowGraph/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ const FundFlowGraph: React.FC<FundFlowGraphConfig> = (props) => {
processMinimap(minimapCfg, graph);
bindStateEvents(graph, uProps as FundFlowGraphConfig);
if (markerCfg) {
bindSourceMapCollapseEvents(graph, data as FundFlowGraphConfig['data']);
bindSourceMapCollapseEvents(graph);
}
renderGraph(graph, data);
if (onReady) {
Expand Down
35 changes: 20 additions & 15 deletions src/graphs/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
CardNodeCfg,
IArrowConfig,
NodeData,
FlowGraphDatum,
CommonConfig,
IGraph,
IG6GraphEvent,
Expand All @@ -20,9 +19,6 @@ import {
MarkerCfg,
} from './interface';
import { defaultMinimapCfg, defaultNodeSize, defaultCardStyle } from './constants';
import { FundFlowGraphConfig } from './fundFlowGraph';
import { FlowAnalysisGraphConfig } from './flowAnalysisGraph';

export const getGraphSize = (
width: number | undefined,
height: number | undefined,
Expand All @@ -42,6 +38,20 @@ export const getGraphSize = (
return [width || CANVAS_WIDTH || 500, height || CANVAS_HEIGHT || 500];
};

type Datum = any;
class EventData {
data: Datum;
constructor(data?: Datum) {
data && this.setData(data);
}
getData(): Datum {
return this.data;
}
setData(data: Datum) {
this.data = data;
}
}

// 展开&折叠事件
export const bindDefaultEvents = (graph: IGraph) => {
const onClick = (e: IG6GraphEvent) => {
Expand All @@ -64,6 +74,7 @@ export const bindDefaultEvents = (graph: IGraph) => {
export const renderGraph = (graph: IGraph, data: any) => {
const originData = deepClone(data);
graph.data(originData);
graph.set('eventData', new EventData(data));
graph.render();
// 关闭局部刷新,各种 bug
graph.get('canvas').set('localRefresh', false);
Expand Down Expand Up @@ -96,7 +107,7 @@ export const getGraphId = (graph: { current?: string }) => {
if (graph.current) {
return graph.current;
}
graph.current = `IndentedTreeGraph-${getUuid()}`;
graph.current = `Graph-${getUuid()}`;
return graph.current;
};

Expand Down Expand Up @@ -130,16 +141,10 @@ export const getMarkerPosition = (direction: string = 'right', size: number[]) =
* 流向图展开收起
*/
type CollapsedNode = NodeData<unknown> & { collapsedLevel: number };
export const bindSourceMapCollapseEvents = (
graph: IGraph,
fullData:
| FundFlowGraphConfig['data']
| FlowAnalysisGraphConfig['data']
| FlowGraphDatum
| undefined,
) => {
const controlData = deepClone(fullData);

export const bindSourceMapCollapseEvents = (graph: IGraph) => {
const onClick = (e: IG6GraphEvent) => {
const controlData: { edges: any[]; nodes: any[] } = graph.get('eventData').getData();
if (e.target.get('name') === 'collapse-icon') {
const item = e.item as INode;
let collapsed = item.getModel().collapsed;
Expand All @@ -152,7 +157,7 @@ export const bindSourceMapCollapseEvents = (
}
// @ts-ignore
const marker = e.item._cfg.group.getChildren().find((item) => item.cfg.type === 'marker');
const { edges: fullEdges = [] } = fullData ?? {};
const { edges: fullEdges = [] } = controlData ?? {};
const { id: nodeId } = item.getModel();
const targetNodeIds: string[] = [];
const updateItems: INode[] = [];
Expand Down
1 change: 1 addition & 0 deletions src/hooks/useGraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export default function useInit(
useEffect(() => {
if (graphInstance && !graphInstance.destroyed) {
graphInstance.changeData(data);
graphInstance.get('eventData')?.setData(data);
}
}, [data]);

Expand Down

0 comments on commit 777b0d5

Please sign in to comment.