Skip to content

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

improve array text detection

Aykut Saraç0f94dc90466d
diff --git a/src/components/Button/index.tsx b/src/components/Button/index.tsx
index b4e1edb1..fea5cf9f 100644
--- a/src/components/Button/index.tsx
+++ b/src/components/Button/index.tsx
@@ -5,7 +5,7 @@ enum ButtonType {
PRIMARY = "SILVER_DARK",
SECONDARY = "BLURPLE",
DANGER = "DANGER",
- SUCCESS = "SEAGREEN",
+ SUCCESS = "LIGHTGREEN",
WARNING = "ORANGE",
}
diff --git a/src/containers/LiveEditor/CustomNode/ObjectNode.tsx b/src/containers/LiveEditor/CustomNode/ObjectNode.tsx
index 2fc87025..3845b5cb 100644
--- a/src/containers/LiveEditor/CustomNode/ObjectNode.tsx
+++ b/src/containers/LiveEditor/CustomNode/ObjectNode.tsx
@@ -15,7 +15,7 @@ const ObjectNode: React.FC<CustomNodeProps<[string, unknown][]>> = ({
(val, idx) =>
val[1] && (
<Styled.StyledRow key={idx} width={width}>
- <Styled.StyledKey>{val[0]}: </Styled.StyledKey>
+ <Styled.StyledKey objectKey>{val[0]}: </Styled.StyledKey>
{val[1]}
</Styled.StyledRow>
)
diff --git a/src/containers/LiveEditor/CustomNode/BondNode.tsx b/src/containers/LiveEditor/CustomNode/TextNode.tsx
similarity index 68%
rename from src/containers/LiveEditor/CustomNode/BondNode.tsx
rename to src/containers/LiveEditor/CustomNode/TextNode.tsx
index c5111131..07048893 100644
--- a/src/containers/LiveEditor/CustomNode/BondNode.tsx
+++ b/src/containers/LiveEditor/CustomNode/TextNode.tsx
@@ -2,12 +2,17 @@ import React from "react";
import { CustomNodeProps } from ".";
import * as Styled from "./styles";
-const BondNode: React.FC<CustomNodeProps<string>> = ({ width, height, value }) => {
+const BondNode: React.FC<CustomNodeProps<string>> = ({
+ width,
+ height,
+ value,
+ isParent = false,
+}) => {
return (
<Styled.StyledForeignObject width={width} height={height} x={0} y={0}>
<Styled.StyledTextWrapper>
<Styled.StyledText width={width} height={height}>
- <Styled.StyledKey bond>{value}</Styled.StyledKey>
+ <Styled.StyledKey parent={isParent}>{value}</Styled.StyledKey>
</Styled.StyledText>
</Styled.StyledTextWrapper>
</Styled.StyledForeignObject>
diff --git a/src/containers/LiveEditor/CustomNode/index.tsx b/src/containers/LiveEditor/CustomNode/index.tsx
index f31ce95e..4698466d 100644
--- a/src/containers/LiveEditor/CustomNode/index.tsx
+++ b/src/containers/LiveEditor/CustomNode/index.tsx
@@ -1,13 +1,13 @@
import React from "react";
import { Label, Node, Port, NodeProps } from "reaflow";
-import ArrayNode from "./ArrayNode";
-import BondNode from "./BondNode";
import ObjectNode from "./ObjectNode";
+import TextNode from "./TextNode";
export interface CustomNodeProps<T> {
width: number;
height: number;
value: T;
+ isParent?: boolean;
}
const baseLabelStyle = {
@@ -33,16 +33,18 @@ export const CustomNode = (nodeProps: NodeProps) => {
const { width, height } = nodeProps;
if (data.text instanceof Object) {
- if (Object.keys(data.text).every((val) => !isNaN(+val))) {
- const text = Object.values(data.text).join("");
- return <ArrayNode width={width} height={height} value={text} />;
- }
-
const entries = Object.entries(data.text);
return <ObjectNode width={width} height={height} value={entries} />;
}
- return <BondNode width={width} height={height} value={data.text} />;
+ return (
+ <TextNode
+ isParent={data.data.isParent}
+ width={width}
+ height={height}
+ value={data.text}
+ />
+ );
}}
</Node>
);
diff --git a/src/containers/LiveEditor/helpers.ts b/src/containers/LiveEditor/helpers.ts
index 621918cb..36a62226 100644
--- a/src/containers/LiveEditor/helpers.ts
+++ b/src/containers/LiveEditor/helpers.ts
@@ -22,6 +22,9 @@ export function getEdgeNodes(graph: any, isExpanded: boolean = true): any {
nodes.push({
id: el.id,
text: el.text,
+ data: {
+ isParent: el.parent,
+ },
width: isExpanded ? 35 + longestLine * 8 : 180,
height: isExpanded ? 30 + lines.length * 10 : 50,
});
diff --git a/src/typings/styled.d.ts b/src/typings/styled.d.ts
index 5a3faea8..22691608 100644
--- a/src/typings/styled.d.ts
+++ b/src/typings/styled.d.ts
@@ -19,7 +19,7 @@ declare module "styled-components" {
CRIMSON: string;
DARK_SALMON: string;
DANGER: string;
- SEAGREEN: string;
+ LIGHTGREEN: string;
ORANGE: string;
SILVER: string;
SILVER_DARK: string;
diff --git a/src/utils/json-editor-parser.ts b/src/utils/json-editor-parser.ts
index a2dddc42..7c50781f 100644
--- a/src/utils/json-editor-parser.ts
+++ b/src/utils/json-editor-parser.ts
@@ -14,23 +14,31 @@ export const parser = (input: string | string[]) => {
) => {
if (!os) return [];
- return [os].flat().map((o) => ({
- id: nextId(),
- text: Object.fromEntries(
- Object.entries(o).filter(
- ([k, v]) => !Array.isArray(v) && !(v instanceof Object)
- )
- ),
- children: Object.entries(o)
- .filter(([k, v]) => Array.isArray(v) || typeof v === "object")
- .flatMap(([k, v]) => [
- {
- id: nextId(),
- text: k,
- children: extract(v, nextId),
- },
- ]),
- }));
+ return [os].flat().map((o) => {
+ const isObject = o instanceof Object;
+
+ return {
+ id: nextId(),
+ text: !isObject
+ ? o.toString()
+ : Object.fromEntries(
+ Object.entries(o).filter(
+ ([k, v]) => !Array.isArray(v) && !(v instanceof Object)
+ )
+ ),
+ parent: false,
+ children: Object.entries(o)
+ .filter(([k, v]) => Array.isArray(v) || typeof v === "object")
+ .flatMap(([k, v]) => [
+ {
+ id: nextId(),
+ text: k,
+ parent: true,
+ children: extract(v, nextId),
+ },
+ ]),
+ };
+ });
};
const relationships = (xs: { id: string; children: never[] }[]) => {