mirror of
https://github.com/IRBorisov/ConceptPortal.git
synced 2025-06-26 04:50:36 +03:00
Add graph visualization via reagraph
This commit is contained in:
parent
200f7b0b7a
commit
37c052f73d
3289
rsconcept/frontend/package-lock.json
generated
3289
rsconcept/frontend/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
|
@ -21,7 +21,8 @@
|
||||||
"react-router-dom": "^6.14.2",
|
"react-router-dom": "^6.14.2",
|
||||||
"react-select": "^5.7.4",
|
"react-select": "^5.7.4",
|
||||||
"react-tabs": "^6.0.2",
|
"react-tabs": "^6.0.2",
|
||||||
"react-toastify": "^9.1.3"
|
"react-toastify": "^9.1.3",
|
||||||
|
"reagraph": "^4.11.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^20.4.5",
|
"@types/node": "^20.4.5",
|
||||||
|
|
|
@ -1,18 +1,53 @@
|
||||||
import PrettyJson from '../../components/Common/PrettyJSON';
|
import { useMemo } from 'react';
|
||||||
|
import { darkTheme, GraphCanvas, GraphEdge, GraphNode, lightTheme } from 'reagraph';
|
||||||
|
|
||||||
import { useRSForm } from '../../context/RSFormContext';
|
import { useRSForm } from '../../context/RSFormContext';
|
||||||
import { GraphNode } from '../../utils/Graph';
|
import { useConceptTheme } from '../../context/ThemeContext';
|
||||||
|
import { resources } from '../../utils/constants';
|
||||||
|
|
||||||
function EditorTermGraph() {
|
function EditorTermGraph() {
|
||||||
const { schema } = useRSForm();
|
const { schema } = useRSForm();
|
||||||
|
const { darkMode } = useConceptTheme();
|
||||||
|
|
||||||
const data: GraphNode[] = [];
|
const nodes: GraphNode[] = useMemo(() => {
|
||||||
schema?.graph.visitDFS(node => data.push(node));
|
return schema?.items.map(cst => {
|
||||||
|
return {
|
||||||
|
id: String(cst.id),
|
||||||
|
label: (cst.term.resolved || cst.term.raw) ? `${cst.alias}: ${cst.term.resolved || cst.term.raw}` : cst.alias
|
||||||
|
}}
|
||||||
|
) ?? [];
|
||||||
|
}, [schema?.items]);
|
||||||
|
|
||||||
|
const edges = useMemo(() => {
|
||||||
|
const result: GraphEdge[] = [];
|
||||||
|
let edgeID = 1;
|
||||||
|
schema?.graph.nodes.forEach(source => {
|
||||||
|
source.adjacent.forEach(target => {
|
||||||
|
result.push({
|
||||||
|
id: String(edgeID),
|
||||||
|
source: String(source.id),
|
||||||
|
target: String(target)
|
||||||
|
});
|
||||||
|
edgeID += 1;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
}, [schema?.graph]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div className='flex-wrap w-full h-full overflow-auto'>
|
||||||
<PrettyJson data={data} />
|
<div className='relative border w-[1240px] h-[800px] 2xl:w-[1880px] 2xl:h-[800px]'>
|
||||||
|
<GraphCanvas
|
||||||
|
nodes={nodes}
|
||||||
|
edges={edges}
|
||||||
|
draggable
|
||||||
|
theme={darkMode ? darkTheme : lightTheme}
|
||||||
|
labelFontUrl={resources.graph_font}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export default EditorTermGraph;
|
export default EditorTermGraph;
|
||||||
|
|
|
@ -22,4 +22,8 @@ export const urls = {
|
||||||
full_course: 'https://www.youtube.com/playlist?list=PLGe_JiAwpqu1C70ruQmCm_OWTWU3KJwDo'
|
full_course: 'https://www.youtube.com/playlist?list=PLGe_JiAwpqu1C70ruQmCm_OWTWU3KJwDo'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const resources = {
|
||||||
|
graph_font: 'https://ey2pz3.csb.app/NotoSansSC-Regular.ttf'
|
||||||
|
}
|
||||||
|
|
||||||
export const config = process.env.NODE_ENV === 'production' ? prod : dev;
|
export const config = process.env.NODE_ENV === 'production' ? prod : dev;
|
||||||
|
|
|
@ -295,9 +295,9 @@ export function LoadRSFormData(schema: IRSFormData): IRSForm {
|
||||||
result.graph.addNode(cst.id);
|
result.graph.addNode(cst.id);
|
||||||
const dependencies = extractGlobals(cst.definition.formal);
|
const dependencies = extractGlobals(cst.definition.formal);
|
||||||
dependencies.forEach(value => {
|
dependencies.forEach(value => {
|
||||||
const destination = schema.items.find(cst => cst.alias === value)
|
const source = schema.items.find(cst => cst.alias === value)
|
||||||
if (destination) {
|
if (source) {
|
||||||
result.graph.addEdge(cst.id, destination.id);
|
result.graph.addEdge(source.id, cst.id);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user