@ts4nfdi/terminology-service-suite 5.1.8 → 5.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/index.js +191 -35
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/api/OlsApi.d.ts +2 -0
- package/dist/esm/types/app/types.d.ts +12 -0
- package/dist/esm/types/components/widgets/EntityInfoWidget/EntityInfoWidget.stories.d.ts +1 -1
- package/dist/esm/types/components/widgets/EntityInfoWidget/EntityInfoWidgetHTML.stories.d.ts +1 -1
- package/dist/esm/types/components/widgets/EntityInfoWidget/EntityInfoWidgetStories.d.ts +7 -0
- package/dist/esm/types/components/widgets/GraphViewWidget/GraphViewWidget.stories.d.ts +1 -1
- package/dist/esm/types/components/widgets/GraphViewWidget/GraphViewWidgetHTML.stories.d.ts +1 -1
- package/dist/esm/types/components/widgets/GraphViewWidget/GraphViewWidgetStories.d.ts +44 -0
- package/package.json +1 -1
package/dist/esm/index.js
CHANGED
|
@@ -3859,8 +3859,29 @@ function getReifiedJSX(entity, reified, showBadges = DEFAULT_SHOW_BADGES,
|
|
|
3859
3859
|
if (typeof value.value == "string") {
|
|
3860
3860
|
return addLinksToText(entity, value.value.toString(), undefined, showBadges, onNavigates);
|
|
3861
3861
|
}
|
|
3862
|
+
else if (typeof value.value == "object" &&
|
|
3863
|
+
value.value["http://www.w3.org/1999/02/22-rdf-syntax-ns#type"] !=
|
|
3864
|
+
undefined) {
|
|
3865
|
+
// Is converted from Skosmos
|
|
3866
|
+
switch (value.value["http://www.w3.org/1999/02/22-rdf-syntax-ns#type"]) {
|
|
3867
|
+
case "http://www.w3.org/2008/05/skos-xl#Label":
|
|
3868
|
+
const label = value.value["http://www.w3.org/2008/05/skos-xl#literalForm"]["value"];
|
|
3869
|
+
return React.createElement(React.Fragment, null, label);
|
|
3870
|
+
case "http://purl.org/vocab/changeset/schema#ChangeSet":
|
|
3871
|
+
const changeReason = value.value["http://purl.org/vocab/changeset/schema#changeReason"]["value"];
|
|
3872
|
+
const date = value.value["http://purl.org/vocab/changeset/schema#createdDate"]["value"];
|
|
3873
|
+
return (React.createElement(React.Fragment, null,
|
|
3874
|
+
date,
|
|
3875
|
+
": ",
|
|
3876
|
+
changeReason));
|
|
3877
|
+
default:
|
|
3878
|
+
console.error(`Unknown rdf syntax type: ${value.value["http://www.w3.org/1999/02/22-rdf-syntax-ns#type"]}`);
|
|
3879
|
+
return React.createElement(React.Fragment, null, JSON.stringify(value.value));
|
|
3880
|
+
}
|
|
3881
|
+
}
|
|
3862
3882
|
else {
|
|
3863
3883
|
// TODO: should not happen, prove that this is never the case
|
|
3884
|
+
console.error(`Unknown entry information format: ${value}`);
|
|
3864
3885
|
return React.createElement(React.Fragment, null, JSON.stringify(value.value));
|
|
3865
3886
|
}
|
|
3866
3887
|
}
|
|
@@ -4450,16 +4471,20 @@ function WrappedOntologyInfoWidget(props) {
|
|
|
4450
4471
|
}
|
|
4451
4472
|
|
|
4452
4473
|
function GraphViewWidget(props) {
|
|
4453
|
-
const { api, iri, ontologyId, rootWalk, className } = props;
|
|
4474
|
+
const { api, iri, ontologyId, rootWalk, className, hierarchy, edgeLabel, onNodeClick, } = props;
|
|
4454
4475
|
const [selectedIri, setSelectedIri] = useState(iri);
|
|
4455
4476
|
const [firstLoad, setFirstLoad] = useState(true);
|
|
4456
4477
|
const [dbclicked, setDbclicked] = useState(false);
|
|
4457
4478
|
const [rootWalkIsSelected, setRootWalkIsSelected] = useState(rootWalk ? rootWalk : false);
|
|
4479
|
+
const [hierarchicalView, setHierarchicalView] = useState(hierarchy ? true : false);
|
|
4458
4480
|
const [isPopoverOpen, setIsPopoverOpen] = useState(false);
|
|
4459
4481
|
// needed for useQuery. without it the graph won't get updated on switching berween rootWalk=true and false.
|
|
4460
4482
|
const [counter, setCounter] = useState(0);
|
|
4461
4483
|
const olsApi = new OlsApi(api);
|
|
4462
4484
|
const finalClassName = className || "ts4nfdi-graph-style";
|
|
4485
|
+
const subClassEdgeLabel = !edgeLabel || edgeLabel === "undefined" ? "is a" : edgeLabel;
|
|
4486
|
+
const onNodeClickCallbackIdProvided = typeof onNodeClick === "function" &&
|
|
4487
|
+
!onNodeClick.name.includes("mockConstructor");
|
|
4463
4488
|
const { data, isLoading, isError, error } = useQuery([
|
|
4464
4489
|
"termGraph",
|
|
4465
4490
|
api,
|
|
@@ -4469,21 +4494,40 @@ function GraphViewWidget(props) {
|
|
|
4469
4494
|
dbclicked,
|
|
4470
4495
|
counter,
|
|
4471
4496
|
], async () => {
|
|
4472
|
-
if (rootWalkIsSelected && firstLoad) {
|
|
4497
|
+
if (rootWalkIsSelected && firstLoad && !hierarchicalView) {
|
|
4473
4498
|
// only use this call on load. Double ckicking on a node should call the normal getTermRelations function.
|
|
4474
|
-
return
|
|
4499
|
+
return {
|
|
4500
|
+
treeData: await olsApi.getTermTree({ ontologyId: ontologyId, termIri: iri }, { viewMode: "All", siblings: false }),
|
|
4501
|
+
};
|
|
4475
4502
|
}
|
|
4476
|
-
else if (firstLoad
|
|
4477
|
-
|
|
4503
|
+
else if (rootWalkIsSelected && firstLoad && hierarchicalView) {
|
|
4504
|
+
let termTree = await olsApi.getTermTree({ ontologyId: ontologyId, termIri: iri }, { viewMode: "All", siblings: false });
|
|
4505
|
+
let termRelation = await olsApi.getTermRelations({
|
|
4478
4506
|
ontologyId: ontologyId,
|
|
4479
4507
|
termIri: selectedIri,
|
|
4480
4508
|
});
|
|
4509
|
+
return { treeData: termTree, termRelations: termRelation };
|
|
4510
|
+
}
|
|
4511
|
+
else if (firstLoad || dbclicked) {
|
|
4512
|
+
return {
|
|
4513
|
+
termRelations: await olsApi.getTermRelations({
|
|
4514
|
+
ontologyId: ontologyId,
|
|
4515
|
+
termIri: selectedIri,
|
|
4516
|
+
}),
|
|
4517
|
+
};
|
|
4481
4518
|
}
|
|
4482
4519
|
});
|
|
4483
4520
|
const nodes = useRef(new DataSet([]));
|
|
4484
4521
|
const edges = useRef(new DataSet([]));
|
|
4485
4522
|
const graphNetwork = useRef({});
|
|
4486
4523
|
const container = useRef(null);
|
|
4524
|
+
const hierarchicalConfig = {
|
|
4525
|
+
enabled: true,
|
|
4526
|
+
//@ts-ignore
|
|
4527
|
+
direction: "DU",
|
|
4528
|
+
//@ts-ignore
|
|
4529
|
+
sortMethod: "directed",
|
|
4530
|
+
};
|
|
4487
4531
|
const graphNetworkConfig = {
|
|
4488
4532
|
/**
|
|
4489
4533
|
* for more options have a look at: https://visjs.github.io/vis-network/docs/network/#options
|
|
@@ -4496,6 +4540,9 @@ function GraphViewWidget(props) {
|
|
|
4496
4540
|
randomSeed: 1,
|
|
4497
4541
|
improvedLayout: true,
|
|
4498
4542
|
clusterThreshold: 150,
|
|
4543
|
+
hierarchical: {
|
|
4544
|
+
enabled: false,
|
|
4545
|
+
},
|
|
4499
4546
|
},
|
|
4500
4547
|
physics: {
|
|
4501
4548
|
enabled: true,
|
|
@@ -4507,8 +4554,15 @@ function GraphViewWidget(props) {
|
|
|
4507
4554
|
damping: 0.09,
|
|
4508
4555
|
avoidOverlap: 0,
|
|
4509
4556
|
},
|
|
4557
|
+
hierarchicalRepulsion: {
|
|
4558
|
+
damping: 0.09,
|
|
4559
|
+
avoidOverlap: 0.9,
|
|
4560
|
+
},
|
|
4510
4561
|
},
|
|
4511
4562
|
};
|
|
4563
|
+
if (hierarchicalView) {
|
|
4564
|
+
graphNetworkConfig["layout"]["hierarchical"] = hierarchicalConfig;
|
|
4565
|
+
}
|
|
4512
4566
|
class GraphNode {
|
|
4513
4567
|
id;
|
|
4514
4568
|
label;
|
|
@@ -4565,35 +4619,17 @@ function GraphViewWidget(props) {
|
|
|
4565
4619
|
}
|
|
4566
4620
|
}
|
|
4567
4621
|
}
|
|
4568
|
-
function convertToOlsGraphFormat(listOfJsTreeNodes) {
|
|
4569
|
-
// used for converting the list of ancestors to the ols api graph endpoints format. to be consumed by GraphNode and GraphEdge classes constructor.
|
|
4570
|
-
// currently used in showing ancestors. Equivalent to is-a relation.
|
|
4571
|
-
let data = { nodes: [], edges: [] };
|
|
4572
|
-
listOfJsTreeNodes.map((treeNode) => {
|
|
4573
|
-
if (!data.nodes.find((obj) => obj.iri === treeNode.iri)) {
|
|
4574
|
-
let node = { iri: treeNode.iri, label: treeNode.text };
|
|
4575
|
-
data.nodes.push(node);
|
|
4576
|
-
}
|
|
4577
|
-
let parentNode = listOfJsTreeNodes.find((obj) => obj.id === treeNode.parent);
|
|
4578
|
-
if (parentNode) {
|
|
4579
|
-
// parent does not exists --> '#' id that indicates a node is a root.
|
|
4580
|
-
let edge = {
|
|
4581
|
-
source: treeNode.iri,
|
|
4582
|
-
target: parentNode.iri,
|
|
4583
|
-
label: "subClassOf",
|
|
4584
|
-
uri: "http://www.w3.org/2000/01/rdf-schema#subClassOf",
|
|
4585
|
-
};
|
|
4586
|
-
if (!data.edges.find((obj) => obj.source === edge.source && obj.target === edge.target)) {
|
|
4587
|
-
data.edges.push(edge);
|
|
4588
|
-
}
|
|
4589
|
-
}
|
|
4590
|
-
});
|
|
4591
|
-
return data;
|
|
4592
|
-
}
|
|
4593
4622
|
if (data && (firstLoad || dbclicked)) {
|
|
4594
|
-
let gData = data;
|
|
4595
|
-
if (rootWalkIsSelected && firstLoad) {
|
|
4596
|
-
gData = convertToOlsGraphFormat(data);
|
|
4623
|
+
let gData = data.termRelations;
|
|
4624
|
+
if (data.treeData && rootWalkIsSelected && firstLoad && !hierarchicalView) {
|
|
4625
|
+
gData = convertToOlsGraphFormat(data.treeData, undefined);
|
|
4626
|
+
}
|
|
4627
|
+
else if (data.termRelations &&
|
|
4628
|
+
data.treeData &&
|
|
4629
|
+
rootWalkIsSelected &&
|
|
4630
|
+
firstLoad &&
|
|
4631
|
+
hierarchicalView) {
|
|
4632
|
+
gData = convertToOlsGraphFormat(data.treeData, data.termRelations);
|
|
4597
4633
|
}
|
|
4598
4634
|
for (let node of gData["nodes"]) {
|
|
4599
4635
|
let gNode = new GraphNode({ node: node });
|
|
@@ -4631,6 +4667,88 @@ function GraphViewWidget(props) {
|
|
|
4631
4667
|
setDbclicked(false);
|
|
4632
4668
|
}
|
|
4633
4669
|
}
|
|
4670
|
+
function convertToOlsGraphFormat(listOfJsTreeNodes, nodeRelations) {
|
|
4671
|
+
// used for converting the list of ancestors to the ols api graph endpoints format. to be consumed by GraphNode and GraphEdge classes constructor.
|
|
4672
|
+
// currently used in showing ancestors. Equivalent to is-a relation.
|
|
4673
|
+
// first, the flat array of nodes should turn to a tree.
|
|
4674
|
+
let treeData = [];
|
|
4675
|
+
for (let node of listOfJsTreeNodes) {
|
|
4676
|
+
if (node.parent === "#") {
|
|
4677
|
+
treeData.push(node);
|
|
4678
|
+
continue;
|
|
4679
|
+
}
|
|
4680
|
+
for (let pn of listOfJsTreeNodes) {
|
|
4681
|
+
if (pn.id === node.parent) {
|
|
4682
|
+
if ("childrenList" in pn) {
|
|
4683
|
+
pn.childrenList.push(node);
|
|
4684
|
+
}
|
|
4685
|
+
else {
|
|
4686
|
+
pn.childrenList = [node];
|
|
4687
|
+
}
|
|
4688
|
+
if ("parentList" in node) {
|
|
4689
|
+
//@ts-ignore
|
|
4690
|
+
node.parentList.push(pn);
|
|
4691
|
+
}
|
|
4692
|
+
else {
|
|
4693
|
+
node.parentList = [pn];
|
|
4694
|
+
}
|
|
4695
|
+
}
|
|
4696
|
+
}
|
|
4697
|
+
}
|
|
4698
|
+
let graphData = { nodes: [], edges: [] };
|
|
4699
|
+
let q = [...treeData];
|
|
4700
|
+
let layerq = [];
|
|
4701
|
+
let height = 1;
|
|
4702
|
+
while (true) {
|
|
4703
|
+
let node = q[0];
|
|
4704
|
+
q = q.slice(1);
|
|
4705
|
+
if (!graphData.nodes.find((obj) => obj.iri === node.iri)) {
|
|
4706
|
+
let gnode = { iri: node.iri, label: node.text, level: height };
|
|
4707
|
+
graphData.nodes.push(gnode);
|
|
4708
|
+
}
|
|
4709
|
+
if (node.parentList && node.parentList.length !== 0) {
|
|
4710
|
+
node.parentList.forEach((pn) => {
|
|
4711
|
+
let edge = {
|
|
4712
|
+
source: node.iri,
|
|
4713
|
+
target: pn.iri,
|
|
4714
|
+
label: subClassEdgeLabel,
|
|
4715
|
+
uri: "http://www.w3.org/2000/01/rdf-schema#subClassOf",
|
|
4716
|
+
};
|
|
4717
|
+
if (!graphData.edges.find((obj) => obj.source === edge.source && obj.target === edge.target)) {
|
|
4718
|
+
graphData.edges.push(edge);
|
|
4719
|
+
}
|
|
4720
|
+
});
|
|
4721
|
+
}
|
|
4722
|
+
if (node.childrenList && node.childrenList.length !== 0) {
|
|
4723
|
+
layerq.push(...node.childrenList);
|
|
4724
|
+
}
|
|
4725
|
+
if (q.length === 0) {
|
|
4726
|
+
if (layerq.length === 0) {
|
|
4727
|
+
break;
|
|
4728
|
+
}
|
|
4729
|
+
height += 1;
|
|
4730
|
+
q.push(...layerq);
|
|
4731
|
+
layerq = [];
|
|
4732
|
+
}
|
|
4733
|
+
}
|
|
4734
|
+
if (nodeRelations) {
|
|
4735
|
+
// add the "has part" relation to the hierarchy
|
|
4736
|
+
let onlyHasPartRelations = {
|
|
4737
|
+
nodes: [],
|
|
4738
|
+
edges: [],
|
|
4739
|
+
};
|
|
4740
|
+
for (let edge of nodeRelations["edges"]) {
|
|
4741
|
+
if (edge["label"] === "has part") {
|
|
4742
|
+
onlyHasPartRelations.edges.push(edge);
|
|
4743
|
+
onlyHasPartRelations.nodes.push(nodeRelations.nodes.find((node) => node.iri === edge.source));
|
|
4744
|
+
onlyHasPartRelations.nodes.push(nodeRelations.nodes.find((node) => node.iri === edge.target));
|
|
4745
|
+
}
|
|
4746
|
+
}
|
|
4747
|
+
graphData["nodes"] = graphData["nodes"].concat(onlyHasPartRelations["nodes"]);
|
|
4748
|
+
graphData["edges"] = graphData["edges"].concat(onlyHasPartRelations["edges"]);
|
|
4749
|
+
}
|
|
4750
|
+
return graphData;
|
|
4751
|
+
}
|
|
4634
4752
|
function reset() {
|
|
4635
4753
|
nodes.current.clear();
|
|
4636
4754
|
edges.current.clear();
|
|
@@ -4652,7 +4770,12 @@ function GraphViewWidget(props) {
|
|
|
4652
4770
|
if (params.nodes.length > 0) {
|
|
4653
4771
|
let nodeIri = params.nodes[0];
|
|
4654
4772
|
setSelectedIri(nodeIri);
|
|
4655
|
-
|
|
4773
|
+
if (onNodeClickCallbackIdProvided) {
|
|
4774
|
+
onNodeClick(nodeIri);
|
|
4775
|
+
}
|
|
4776
|
+
else {
|
|
4777
|
+
setDbclicked(true);
|
|
4778
|
+
}
|
|
4656
4779
|
}
|
|
4657
4780
|
});
|
|
4658
4781
|
}
|
|
@@ -4665,6 +4788,36 @@ function GraphViewWidget(props) {
|
|
|
4665
4788
|
// when user change the storybook rootWalk value
|
|
4666
4789
|
setRootWalkIsSelected(rootWalk ? rootWalk : false);
|
|
4667
4790
|
}, [rootWalk]);
|
|
4791
|
+
useEffect(() => {
|
|
4792
|
+
// when user change the storybook hierarchy value
|
|
4793
|
+
setHierarchicalView(hierarchy ? hierarchy : false);
|
|
4794
|
+
}, [hierarchy]);
|
|
4795
|
+
useEffect(() => {
|
|
4796
|
+
if (hierarchicalView) {
|
|
4797
|
+
graphNetworkConfig["layout"]["hierarchical"] = hierarchicalConfig;
|
|
4798
|
+
}
|
|
4799
|
+
else {
|
|
4800
|
+
//@ts-ignore
|
|
4801
|
+
delete graphNetworkConfig["layout"]["hierarchical"];
|
|
4802
|
+
}
|
|
4803
|
+
let graphData = { nodes: nodes.current, edges: edges.current };
|
|
4804
|
+
graphNetwork.current = new Network(
|
|
4805
|
+
//@ts-ignore
|
|
4806
|
+
container.current, graphData, graphNetworkConfig);
|
|
4807
|
+
//@ts-ignore
|
|
4808
|
+
graphNetwork.current.on("doubleClick", function (params) {
|
|
4809
|
+
if (params.nodes.length > 0) {
|
|
4810
|
+
let nodeIri = params.nodes[0];
|
|
4811
|
+
setSelectedIri(nodeIri);
|
|
4812
|
+
if (onNodeClickCallbackIdProvided) {
|
|
4813
|
+
onNodeClick(nodeIri);
|
|
4814
|
+
}
|
|
4815
|
+
else {
|
|
4816
|
+
setDbclicked(true);
|
|
4817
|
+
}
|
|
4818
|
+
}
|
|
4819
|
+
});
|
|
4820
|
+
}, [hierarchicalView]);
|
|
4668
4821
|
const onButtonClick = () => setIsPopoverOpen((isPopoverOpen) => !isPopoverOpen);
|
|
4669
4822
|
const closePopover = () => setIsPopoverOpen(false);
|
|
4670
4823
|
const button = (React.createElement(EuiButtonEmpty, { iconType: "iInCircle", iconSide: "right", onClick: onButtonClick }, "Guide me"));
|
|
@@ -4682,6 +4835,9 @@ function GraphViewWidget(props) {
|
|
|
4682
4835
|
React.createElement("div", { style: { display: "inline-block", float: "right", paddingTop: 10 } },
|
|
4683
4836
|
React.createElement(EuiSwitch, { label: "root walk", checked: rootWalkIsSelected, onChange: () => {
|
|
4684
4837
|
setRootWalkIsSelected(!rootWalkIsSelected);
|
|
4838
|
+
}, title: "Enable the root walk mode in the graph: You can see the path from roots to the target node" }),
|
|
4839
|
+
React.createElement(EuiSwitch, { label: "hierarchy", checked: hierarchicalView, onChange: () => {
|
|
4840
|
+
setHierarchicalView(!hierarchicalView);
|
|
4685
4841
|
}, title: "Enable the root walk mode in the graph: You can see the path from roots to the target node" }))),
|
|
4686
4842
|
React.createElement(EuiPanel, { style: { width: 900, height: 900 }, hasShadow: false, hasBorder: true, borderRadius: "none" },
|
|
4687
4843
|
isLoading && React.createElement(EuiLoadingSpinner, { size: "m" }),
|
|
@@ -4694,7 +4850,7 @@ function WrappedGraphViewWidget(props) {
|
|
|
4694
4850
|
const queryClient = new QueryClient();
|
|
4695
4851
|
return (React.createElement(EuiProvider, { colorMode: "light", globalStyles: false },
|
|
4696
4852
|
React.createElement(QueryClientProvider, { client: queryClient },
|
|
4697
|
-
React.createElement(GraphViewWidget, { api: props.api, iri: props.iri, ontologyId: props.ontologyId, rootWalk: props.rootWalk }))));
|
|
4853
|
+
React.createElement(GraphViewWidget, { api: props.api, iri: props.iri, ontologyId: props.ontologyId, rootWalk: props.rootWalk, hierarchy: props.hierarchy, edgeLabel: props.edgeLabel, onNodeClick: props.onNodeClick }))));
|
|
4698
4854
|
}
|
|
4699
4855
|
|
|
4700
4856
|
function TermDepictionWidget(props) {
|