Skip to content

✨ Innovative and open-source visualization application that transforms various data formats, such as JSON, YAML, XML and CSV into interactive graphs.

highlight searched content

AykutSarac150e759a1636
diff --git a/src/components/CustomNode/ObjectNode.tsx b/src/components/CustomNode/ObjectNode.tsx
index 5b05fb42..0c69a116 100644
--- a/src/components/CustomNode/ObjectNode.tsx
+++ b/src/components/CustomNode/ObjectNode.tsx
@@ -16,15 +16,14 @@ const ObjectNode: React.FC<CustomNodeProps<[string, string][]>> = ({
{value.map(
(val, idx) =>
val[1] && (
- <Styled.StyledRow key={idx} width={width}>
- <Styled.StyledKey
- data-x={x}
- data-y={y}
- data-key={val[1]}
- objectKey
- >
- {val[0]}:{" "}
- </Styled.StyledKey>
+ <Styled.StyledRow
+ data-key={val[1]}
+ data-x={x}
+ data-y={y}
+ key={idx}
+ width={width}
+ >
+ <Styled.StyledKey objectKey>{val[0]}: </Styled.StyledKey>
{val[1]}
</Styled.StyledRow>
)
diff --git a/src/components/CustomNode/styles.tsx b/src/components/CustomNode/styles.tsx
index da82f41f..988954a6 100644
--- a/src/components/CustomNode/styles.tsx
+++ b/src/components/CustomNode/styles.tsx
@@ -28,6 +28,11 @@ export const StyledForeignObject = styled.foreignObject`
border: 2px solid ${({ theme }) => theme.TEXT_POSITIVE};
border-radius: 2px;
}
+
+ .highlight {
+ background-color: rgba(255, 0, 255, 0.5);
+ filter: hue-rotate();
+ }
`;
export const StyledKey = styled.span<{
@@ -38,7 +43,7 @@ export const StyledKey = styled.span<{
parent ? theme.ORANGE : objectKey ? "#5c87ff" : theme.TEXT_POSITIVE};
`;
-export const StyledRow = styled.div<{ width: number }>`
+export const StyledRow = styled.span<{ width: number }>`
height: fit-content;
overflow: hidden;
text-overflow: ellipsis;
diff --git a/src/hooks/useFocusNode.tsx b/src/hooks/useFocusNode.tsx
index b8c739a4..c989d1da 100644
--- a/src/hooks/useFocusNode.tsx
+++ b/src/hooks/useFocusNode.tsx
@@ -53,7 +53,7 @@ export const useFocusNode = () => {
zoomPanPinch.clientHeight / 2 -
matchedNode.getBoundingClientRect().height / 2;
- highlightMatchedNodes(matchedNodes);
+ highlightMatchedNodes(matchedNodes, selectedNode);
settings.zoomPanPinch?.setTransform(newPositionX, newPositionY, newScale);
} else {
diff --git a/src/utils/search.ts b/src/utils/search.ts
index ad1a2398..43c807c8 100644
--- a/src/utils/search.ts
+++ b/src/utils/search.ts
@@ -3,17 +3,23 @@ export const searchQuery = (param: string) => {
};
export const cleanupHighlight = () => {
- const nodes = document.querySelectorAll("foreignObject.searched");
+ const nodes = document.querySelectorAll("foreignObject.searched, .highlight");
nodes?.forEach((node) => {
+ node.classList.remove("highlight");
node.classList.remove("searched");
});
};
-export const highlightMatchedNodes = (nodes: NodeListOf<Element>) => {
+export const highlightMatchedNodes = (
+ nodes: NodeListOf<Element>,
+ selectedNode: number
+) => {
nodes?.forEach((node) => {
node.parentElement?.parentElement
?.closest("foreignObject")
?.classList.add("searched");
});
+
+ nodes[selectedNode].classList.add("highlight");
};