Skip to content

Commit

Permalink
feat: update advance assets
Browse files Browse the repository at this point in the history
  • Loading branch information
pomelo-nwu committed Oct 20, 2023
1 parent c21201b commit a8d7a2c
Show file tree
Hide file tree
Showing 34 changed files with 40 additions and 2,468 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { useMemoizedFn } from 'ahooks';
//@ts-nocheck
import G6, { IGraph } from '@antv/g6';
import { useMemoizedFn } from 'ahooks';
import React, { CSSProperties, useEffect, useRef } from 'react';
import { useImmer } from 'use-immer';
import { TemplateData, TemplateNode } from './type';
import { createFlowGraph, createTooltip } from './util';
import { registerNodes } from './flowNodeRegistry';
import './flowNodeRegistry';
import { registerNodes } from './flowNodeRegistry';
import './index.less';
import { TemplateData, TemplateNode } from './type';
import { createFlowGraph, createTooltip } from './util';

const { Tooltip } = G6;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//@ts-nocheck
import G6 from '@antv/g6';

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import * as React from 'react';
import { Form, Input, Popover, Tooltip } from 'antd';
//@ts-nocheck
import { PictureOutlined } from '@ant-design/icons';
import G6 from '@antv/g6';
import { TemplateNode } from './type';
import { Form, Input, Popover, Tooltip } from 'antd';
import * as React from 'react';
import RJV from 'react-json-view';
import $i18n from '../../i18n';
import { TemplateNode } from './type';

const ReactJson: any = RJV;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//@ts-nocheck
import { StarFilled } from '@ant-design/icons';
import G6, { Item } from '@antv/g6';
import G6 from '@antv/g6';
import { icons, useContext } from '@antv/gi-sdk';
import { Menu } from 'antd';
import insertCss from 'insert-css';
Expand All @@ -8,6 +9,7 @@ import { bind } from 'size-sensor';
import $i18n from '../../i18n';
import './index.less';

type Item = any;
export interface GraphAnnotationProps {
contextmenu: any;
annotationWay: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { CaretRightOutlined, DeleteOutlined } from '@ant-design/icons';
import { Item } from '@antv/g6';

import { useContext } from '@antv/gi-sdk';
import { Button, Collapse, message, Select } from 'antd';
import React from 'react';
import { useImmer } from 'use-immer';
import $i18n from '../../i18n';
import { LAYOUTS } from './const';
import { ILayoutOption } from './typing';
import { updateLayout, getLayoutOptions } from './utils';
import './index.less';
import $i18n from '../../i18n';
import { ILayoutOption } from './typing';
import { getLayoutOptions, updateLayout } from './utils';

type Item = any;

const { Panel } = Collapse;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { GraphData, IGraph } from '@antv/g6';
import { LAYOUTS, LayoutMap } from './const';
import { Graph, GraphData } from '@antv/g6';
import { ILayoutOption } from './typing';

/**
Expand All @@ -13,16 +13,19 @@ export const cropGraphByNodes = (graphData: GraphData, targetNodes: { id: string
const ids = targetNodes.map(node => node.id);
const newEdges = edges!.filter(edge => {
const { source, target } = edge;
//@ts-ignore
if (ids.indexOf(source!) !== -1 && ids.indexOf(target!) !== -1) {
return true;
}
return false;
});
const newNodes = nodes!
.filter(node => {
//@ts-ignore
return ids.indexOf(node.id) !== -1;
})
.map(node => {
//@ts-ignore
// 映射节点大小,用于圆形布局防重叠:https://github.com/antvis/layout/blob/master/src/layout/circular.ts#L213
node.size = node.style?.keyshape?.size || 26;
/*
Expand All @@ -46,7 +49,7 @@ export const cropGraphByNodes = (graphData: GraphData, targetNodes: { id: string
*/
export const updateLayout = (
layouts: ILayoutOption[],
graph: Graph,
graph: IGraph,
gap: number,
direction: 'vertical' | 'horizontal',
) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { IEdge, INode } from '@antv/g6';
import { useContext } from '@antv/gi-sdk';
import { S2Event, SpreadSheet } from '@antv/s2';
import React from 'react';

import { useContext } from '@antv/gi-sdk';
type IEdge = any;
type INode = any;
const useListenEdgeSelect = (isSelectedActive: boolean, s2Instance: SpreadSheet | null, isFullScreen: boolean) => {
const { data: graphData, graph, largeGraphData, updateContext } = useContext();
React.useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { IEdge, INode } from '@antv/g6';
import { S2Event, SpreadSheet } from '@antv/s2';
import React from 'react';
type IEdge = any;
type INode = any;

import { useContext } from '@antv/gi-sdk';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { IEdge, INode } from '@antv/g6';
type IEdge = any;
type INode = any;
export const highlightBySelectedNodes = (selectedNodes: Set<any>, context) => {
const { updateContext, largeGraphData, data: graphData, graph } = context;
if (largeGraphData) {
Expand Down
190 changes: 5 additions & 185 deletions packages/gi-assets-advance/src/components/hooks/useRedoUndo.tsx
Original file line number Diff line number Diff line change
@@ -1,205 +1,25 @@
import { Stack } from '@antv/algorithm';
import { Graph, GraphData, GraphinContext, IG6GraphEvent } from '@antv/graphin';
import React from 'react';
export interface Redo {
visible: boolean;
color: string;
hasDivider: boolean;
}
//修复异常数据
const fixNodePosition = (graph: Graph, graphData: GraphData): GraphData => {
const currentData = graph.save() as any;
const nodeMap: any = {};
currentData.nodes?.forEach((n: any) => {
nodeMap[n.id] = n;
});
const nodes = graphData.nodes?.map((n: any) => {
if (typeof n.x !== 'number' || typeof n.y !== 'number') {
const node = nodeMap[n.id];
if (node) {
return {
...n,
x: node.x,
y: node.y,
};
} else {
return {
...n,
x: 0,
y: 0,
};
}
}
return n;
});
return {
...graphData,
nodes,
};
};

const useRedoUndo = (): {
redo: () => void;
undo: () => void;
undoStack: Stack;
redoStack: Stack;
} => {
const { graph } = React.useContext(GraphinContext);
const [stackInfo, setStackInfo] = React.useState(() => {
return {
undoStack: graph.getUndoStack(),
redoStack: graph.getRedoStack(),
};
});
const redo = () => {
const redoStack = graph.getRedoStack();

if (!redoStack || redoStack.length === 0) {
return;
}

const currentData = redoStack.pop();
if (currentData) {
const { action } = currentData;
let data = currentData.data.after;
graph.pushStack(action, {
...currentData.data,
after: fixNodePosition(graph, currentData.data.after),
before: fixNodePosition(graph, currentData.data.before),
});
if (action === 'delete') {
data = currentData.data.before;
}
update(action, data);
}
};
const undo = () => {
const undoStack = graph.getUndoStack();

if (!undoStack || undoStack.length === 1) {
return;
}

const currentData = undoStack.pop();
if (currentData) {
const { action } = currentData;
graph.pushStack(
action,
{
...currentData.data,
after: fixNodePosition(graph, currentData.data.after),
before: fixNodePosition(graph, currentData.data.before),
},
'redo',
);
let data = currentData.data.before;

if (action === 'add') {
data = currentData.data.after;
}
update(action, data);
}
};
const update = (action: string, data: GraphData) => {
if (!data) return;

switch (action) {
case 'visible': {
Object.keys(data).forEach(key => {
const array = data[key];
if (!array) return;
array.forEach((model: any) => {
const item = graph.findById(model.id);
if (!item) {
return;
}
if (model.visible) {
graph.showItem(item, false);
} else {
graph.hideItem(item, false);
}
});
});
break;
}
case 'render':
case 'update':
const nodeMap = graph.getNodes().reduce((map: any, node: any) => {
map[node.getID()] = node;
return map;
}, {});
Object.keys(data).forEach(key => {
const array = data[key];
if (!array) return;
array.forEach((model: any) => {
if (nodeMap[model.id]) {
graph.updateItem(model.id, model, false);
}
});
});
break;
case 'changedata':
graph.changeData(data, false);
break;
case 'delete': {
Object.keys(data).forEach(key => {
const array = data[key];
if (!array) return;
array.forEach((model: any) => {
const itemType = model.itemType;
delete model.itemType;
graph.addItem(itemType, model, false);
});
});
break;
}
case 'add':
Object.keys(data).forEach(key => {
const array = data[key];
if (!array) return;
array.forEach((model: any) => {
graph.removeItem(model.id, false);
});
});
break;
case 'updateComboTree':
const comboMap: any = {};
graph.getCombos().forEach(combo => {
comboMap[combo.getID()] = combo;
});
Object.keys(data).forEach(key => {
const array = data[key];
if (!array) return;
array.forEach((model: any) => {
if (!comboMap[model.id] || (model.parentId && !comboMap[model.parentId])) {
return;
}
graph.updateComboTree(model.id, model.parentId, false);
});
});
break;
default:
}
};
const redo = () => {};
const undo = () => {};

React.useEffect(() => {
const handleStackChanage = (evt: IG6GraphEvent) => {
const { undoStack, redoStack } = evt as any;
setStackInfo({
undoStack,
redoStack,
});
};
graph.on('stackchange', handleStackChanage);
return () => {
graph.off('stackchange', handleStackChanage);
};
}, [graph]);
//@ts-ignore
return {
...stackInfo,
undoStack: [],
redoStack: [],
redo,
undo,
...stackInfo,
} as any;
};

Expand Down
8 changes: 4 additions & 4 deletions packages/gi-assets-advance/src/components/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
// import SearchBar from './SearchBar';
import AddSheetbar from './AddSheetbar';
import CypherQuery from './CypherQuery';
import GraphAnnotation from './GraphAnnotation';
// import GraphAnnotation from './GraphAnnotation';
import GremlinQuery from './GremlinQuery';
import ModeSwitch from './ModeSwitch';
import Redo from './Redo';
import Sheetbar from './Sheetbar';
// import SnapshotGallery from './SnapshotGallery';
import AnalysisHistory from './AnalysisHistory';
// import AnalysisHistory from './AnalysisHistory';
import Assistant from './Assistant';
import JSONMode from './JSONMode';
import StructAnalysis from './StructAnalysis';
Expand All @@ -27,11 +27,11 @@ import ThemeSetting from './ThemeSetting';
import Undo from './Undo';
export {
AddSheetbar,
AnalysisHistory,
// AnalysisHistory,
Assistant,
// TemplateQuery,
CypherQuery,
GraphAnnotation,
// GraphAnnotation,
// SnapshotGallery,
GremlinQuery,
JSONMode,
Expand Down
Loading

0 comments on commit a8d7a2c

Please sign in to comment.