✨ Innovative and open-source visualization application that transforms various data formats, such as JSON, YAML, XML and CSV into interactive graphs.
refactor custom node
AykutSaracae0f8efad6ae
diff --git a/src/components/Graph/CustomNode/ObjectNode.tsx b/src/components/Graph/CustomNode/ObjectNode.tsxindex d5311c65..c60e92c8 100644--- a/src/components/Graph/CustomNode/ObjectNode.tsx+++ b/src/components/Graph/CustomNode/ObjectNode.tsx@@ -20,7 +20,9 @@ const Row = ({ val, x, y, index }: RowProps) => {data-y={y + index * 17.8}$type={JSON.stringify(val[1])}>- <Styled.StyledKey $objectKey>{JSON.stringify(val[0]).replaceAll('"', "")}: </Styled.StyledKey>+ <Styled.StyledKey $type="object">+ {JSON.stringify(val[0]).replaceAll('"', "")}:{" "}+ </Styled.StyledKey><TextRenderer>{JSON.stringify(val[1])}</TextRenderer></Styled.StyledRow>);diff --git a/src/components/Graph/CustomNode/TextNode.tsx b/src/components/Graph/CustomNode/TextNode.tsxindex 8539a3bc..9f74a48f 100644--- a/src/components/Graph/CustomNode/TextNode.tsx+++ b/src/components/Graph/CustomNode/TextNode.tsx@@ -81,7 +81,7 @@ const Node: React.FC<CustomNodeProps> = ({ node, x, y, hasCollapse = false }) =>data-key={JSON.stringify(text)}$hasCollapse={isParent && hideCollapse}>- <Styled.StyledKey $parent={isParent} type={type}>+ <Styled.StyledKey $parent={isParent} $type={type}><TextRenderer>{JSON.stringify(text).replaceAll('"', "")}</TextRenderer></Styled.StyledKey>{isParent && childrenCount > 0 && showChildrenCount && (diff --git a/src/components/Graph/CustomNode/styles.tsx b/src/components/Graph/CustomNode/styles.tsxindex 5bd7aa44..d262caf5 100644--- a/src/components/Graph/CustomNode/styles.tsx+++ b/src/components/Graph/CustomNode/styles.tsx@@ -1,4 +1,5 @@import styled, { DefaultTheme } from "styled-components";+import { NodeType } from "jsonc-parser";import { LinkItUrl } from "react-linkify-it";import { firaMono } from "src/constants/fonts";@@ -10,6 +11,15 @@ function getTypeColor(value: string, theme: DefaultTheme) {return theme.NODE_COLORS.NODE_VALUE;}+function getKeyColor(theme: DefaultTheme, parent: boolean, type: NodeType) {+ if (parent) {+ if (type === "array") return theme.NODE_COLORS.PARENT_ARR;+ return theme.NODE_COLORS.PARENT_OBJ;+ }+ if (type === "object") return theme.NODE_COLORS.NODE_KEY;+ return theme.NODE_COLORS.TEXT;+}+export const StyledLinkItUrl = styled(LinkItUrl)`text-decoration: underline;pointer-events: all;@@ -47,29 +57,14 @@ export const StyledForeignObject = styled.foreignObject<{ $isObject?: boolean }>}`;-function getKeyColor(theme: DefaultTheme, parent: boolean, type: string, objectKey: boolean) {- if (parent) {- if (type === "array") return theme.NODE_COLORS.PARENT_ARR;- return theme.NODE_COLORS.PARENT_OBJ;- }- if (objectKey) return theme.NODE_COLORS.NODE_KEY;- return theme.NODE_COLORS.TEXT;-}--export const StyledKey = styled.span<{- $objectKey?: boolean;- $parent?: boolean;- type?: string;- value?: string;-}>`+export const StyledKey = styled.span<{ $parent?: boolean; $type?: NodeType }>`display: inline;flex: 1;- color: ${({ theme, type = "null", $objectKey = false, $parent = false }) =>- getKeyColor(theme, $parent, type, $objectKey)};+ color: ${({ theme, $type = "null", $parent = false }) => getKeyColor(theme, $parent, $type)};font-size: ${({ $parent }) => $parent && "14px"};overflow: hidden;text-overflow: ellipsis;- padding: ${({ $objectKey }) => !$objectKey && "10px"};+ padding: ${({ $type }) => $type !== "object" && "10px"};white-space: nowrap;`;