Skip to content

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

reduce element count

AykutSarac978cee573d5f
diff --git a/src/components/CustomNode/ObjectNode.tsx b/src/components/CustomNode/ObjectNode.tsx
index a6de9353..6bd03b02 100644
--- a/src/components/CustomNode/ObjectNode.tsx
+++ b/src/components/CustomNode/ObjectNode.tsx
@@ -15,25 +15,23 @@ const ObjectNode: React.FC<CustomNodeProps<[string, string][]>> = ({
return (
<Styled.StyledForeignObject width={width} height={height} x={0} y={0}>
<ConditionalWrapper condition={settings.performance}>
- <Styled.StyledTextWrapper>
- <Styled.StyledText width={width} height={height}>
- {value.map(
- (val, idx) =>
- val[1] && (
- <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>
- )
- )}
- </Styled.StyledText>
- </Styled.StyledTextWrapper>
+ <Styled.StyledText width={width} height={height}>
+ {value.map(
+ (val, idx) =>
+ val[1] && (
+ <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>
+ )
+ )}
+ </Styled.StyledText>
</ConditionalWrapper>
</Styled.StyledForeignObject>
);
diff --git a/src/components/CustomNode/TextNode.tsx b/src/components/CustomNode/TextNode.tsx
index e4826f1e..ab73520d 100644
--- a/src/components/CustomNode/TextNode.tsx
+++ b/src/components/CustomNode/TextNode.tsx
@@ -16,18 +16,16 @@ const TextNode: React.FC<CustomNodeProps<string>> = ({
return (
<Styled.StyledForeignObject width={width} height={height} x={0} y={0}>
<ConditionalWrapper condition={settings.performance}>
- <Styled.StyledTextWrapper>
- <Styled.StyledText width={width} height={height}>
- <Styled.StyledKey
- data-x={x}
- data-y={y}
- data-key={value}
- parent={isParent}
- >
- {value}
- </Styled.StyledKey>
- </Styled.StyledText>
- </Styled.StyledTextWrapper>
+ <Styled.StyledText width={width} height={height}>
+ <Styled.StyledKey
+ data-x={x}
+ data-y={y}
+ data-key={value}
+ parent={isParent}
+ >
+ {value}
+ </Styled.StyledKey>
+ </Styled.StyledText>
</ConditionalWrapper>
</Styled.StyledForeignObject>
);
diff --git a/src/components/CustomNode/index.tsx b/src/components/CustomNode/index.tsx
index 3936aacb..945f127f 100644
--- a/src/components/CustomNode/index.tsx
+++ b/src/components/CustomNode/index.tsx
@@ -2,6 +2,7 @@ import React from "react";
import RenderIfVisible from "react-render-if-visible";
import { Label, Node, NodeProps } from "reaflow";
import ObjectNode from "./ObjectNode";
+import { StyledTextWrapper } from "./styles";
import TextNode from "./TextNode";
export interface CustomNodeProps<T> {
@@ -23,7 +24,13 @@ export const ConditionalWrapper: React.FC<{
condition?: boolean;
children: React.ReactNode;
}> = ({ condition, children }) =>
- condition ? <RenderIfVisible>{children}</RenderIfVisible> : <>{children}</>;
+ condition ? (
+ <RenderIfVisible rootElementClass="renderVisible">
+ {children}
+ </RenderIfVisible>
+ ) : (
+ <StyledTextWrapper>{children}</StyledTextWrapper>
+ );
export const CustomNode = (nodeProps: NodeProps) => {
const { properties } = nodeProps;
diff --git a/src/components/CustomNode/styles.tsx b/src/components/CustomNode/styles.tsx
index 8125413d..31b412a8 100644
--- a/src/components/CustomNode/styles.tsx
+++ b/src/components/CustomNode/styles.tsx
@@ -37,6 +37,17 @@ export const StyledForeignObject = styled.foreignObject`
background-color: rgba(255, 0, 255, 0.5);
filter: hue-rotate();
}
+
+ .renderVisible {
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ font-size: 12px;
+ width: 100%;
+ height: 100%;
+ overflow: hidden;
+ cursor: pointer;
+ }
`;
export const StyledKey = styled.span<{