✨ Innovative and open-source visualization application that transforms various data formats, such as JSON, YAML, XML and CSV into interactive graphs.
performance and styling fixes
AykutSarac3680f677958b
diff --git a/src/components/Graph/CustomNode/styles.tsx b/src/components/Graph/CustomNode/styles.tsxindex c410d9ff..9e1a41d8 100644--- a/src/components/Graph/CustomNode/styles.tsx+++ b/src/components/Graph/CustomNode/styles.tsx@@ -16,6 +16,7 @@ export const StyledLinkItUrl = styled(LinkItUrl)``;export const StyledForeignObject = styled.foreignObject<{ $isObject?: boolean }>`+ content-visibility: auto;text-align: ${({ $isObject }) => !$isObject && "center"};font-size: 12px;overflow: hidden;diff --git a/src/components/Graph/PremiumView.tsx b/src/components/Graph/PremiumView.tsxindex 02910412..c5a8f1d7 100644--- a/src/components/Graph/PremiumView.tsx+++ b/src/components/Graph/PremiumView.tsx@@ -12,10 +12,10 @@ const StyledPremiumView = styled.div`justify-content: center;width: 100%;height: 100%;- background: #020015;+ background: ${({ theme }) => theme.GRID_COLOR_SECONDARY};img {- filter: drop-shadow(2px 4px 6px black);+ filter: drop-shadow(2px 2px 1px black);}.glowing {@@ -160,7 +160,7 @@ export const PremiumView = () => (<StyledPremiumView><StyledContent><Title align="center">- <Image width="300" src="assets/icon.png" alt="JSON Crack" />+ <Image width="400" src="assets/icon.png" alt="JSON Crack" /></Title><StyledInfo>Upgrade JSON Crack to premium and explore full potantial of your data!diff --git a/src/components/Graph/index.tsx b/src/components/Graph/index.tsxindex 6dfe231c..bef8efa6 100644--- a/src/components/Graph/index.tsx+++ b/src/components/Graph/index.tsx@@ -111,10 +111,10 @@ const GraphCanvas = ({ isWidget }: { isWidget: boolean }) => {setPaneHeight((layout.height as number) + 50);setTimeout(() => {- setLoading(false);validateHiddenNodes();window.requestAnimationFrame(() => {if (changeRatio > 70 || isWidget) centerView();+ setLoading(false);});});}@@ -170,6 +170,7 @@ const GraphCanvas = ({ isWidget }: { isWidget: boolean }) => {export const Graph = ({ isWidget = false }: GraphProps) => {const setViewPort = useGraph(state => state.setViewPort);+ const loading = useGraph(state => state.loading);const isPremium = useUser(state => state.premium);const viewType = useGraph(state =>state.nodes.length > 6_000 ? "error" : state.nodes.length > 250 ? "premium" : "graph"@@ -200,7 +201,7 @@ export const Graph = ({ isWidget = false }: GraphProps) => {return (<>- <Loading message="Painting graph..." />+ <Loading loading={loading} message="Painting graph..." /><StyledEditorWrapper$widget={isWidget}onContextMenu={e => e.preventDefault()}diff --git a/src/constants/previewSection.ts b/src/constants/previewSection.tsdeleted file mode 100644index cd4f531d..00000000--- a/src/constants/previewSection.ts+++ /dev/null@@ -1,91 +0,0 @@-import { defaultJson } from "./data";--export const TABS = [- {- id: 0,- name: "Standard JSON",- json: defaultJson,- },- {- id: 1,- name: "Gallery",- json: JSON.stringify(- {- "cats! 🐾": [- "https://gifimage.net/wp-content/uploads/2017/10/cool-cat-gif-1.gif",- "https://media.tenor.com/vRHYVqQCMQAAAAAM/cool-cat-chilling.gif",- "https://media.tenor.com/k6B6P_kvBSYAAAAM/awesome-cat.gif",- ],- },- null,- 2- ),- },- {- id: 2,- name: "Nested JSON",- json: JSON.stringify(- [- {- id: "0001",- type: "donut",- name: "Cake",- ppu: 0.55,- batters: {- batter: [- { id: "1001", type: "Regular" },- { id: "1002", type: "Chocolate" },- { id: "1003", type: "Blueberry" },- { id: "1004", type: "Devil's Food" },- ],- },- topping: [- { id: "5001", type: "None" },- { id: "5002", type: "Glazed" },- { id: "5005", type: "Sugar" },- { id: "5007", type: "Powdered Sugar" },- { id: "5006", type: "Chocolate with Sprinkles" },- { id: "5003", type: "Chocolate" },- { id: "5004", type: "Maple" },- ],- },- {- id: "0002",- type: "donut",- name: "Raised",- ppu: 0.55,- batters: {- batter: [{ id: "1001", type: "Regular" }],- },- topping: [- { id: "5001", type: "None" },- { id: "5002", type: "Glazed" },- { id: "5005", type: "Sugar" },- { id: "5003", type: "Chocolate" },- { id: "5004", type: "Maple" },- ],- },- {- id: "0003",- type: "donut",- name: "Old Fashioned",- ppu: 0.55,- batters: {- batter: [- { id: "1001", type: "Regular" },- { id: "1002", type: "Chocolate" },- ],- },- topping: [- { id: "5001", type: "None" },- { id: "5002", type: "Glazed" },- { id: "5003", type: "Chocolate" },- { id: "5004", type: "Maple" },- ],- },- ],- null,- 2- ),- },-];diff --git a/src/containers/Modals/SettingsModal/index.tsx b/src/containers/Modals/SettingsModal/index.tsxindex 76dafb19..04402274 100644--- a/src/containers/Modals/SettingsModal/index.tsx+++ b/src/containers/Modals/SettingsModal/index.tsx@@ -3,10 +3,16 @@ import { Modal, Group, Switch, Stack, ModalProps } from "@mantine/core";import useStored from "src/store/useStored";export const SettingsModal: React.FC<ModalProps> = ({ opened, onClose }) => {+ // const { validateHiddenNodes } = useToggleHide();+ // const isPremium = useUser(state => state.premium);+ // const setVisible = useModal(state => state.setVisible);+ // const toggleCollapseAll = useGraph(state => state.toggleCollapseAll);+ // const collapseAll = useGraph(state => state.collapseAll);const setLightTheme = useStored(state => state.setLightTheme);const toggleHideCollapse = useStored(state => state.toggleHideCollapse);const toggleChildrenCount = useStored(state => state.toggleChildrenCount);const toggleImagePreview = useStored(state => state.toggleImagePreview);+const hideCollapse = useStored(state => state.hideCollapse);const childrenCount = useStored(state => state.childrenCount);const imagePreview = useStored(state => state.imagePreview);@@ -37,6 +43,28 @@ export const SettingsModal: React.FC<ModalProps> = ({ opened, onClose }) => {onChange={e => toggleChildrenCount(e.currentTarget.checked)}checked={childrenCount}/>+ {/* <Switch+ label={+ <Flex align="center" gap="xs">+ Collapse All by Default+ <Badge size="xs" color="violet" variant="outline" radius="sm">+ For Big Datasets+ </Badge>+ </Flex>+ }+ size="md"+ color="violet"+ onChange={e => {+ if (isPremium) {+ toggleCollapseAll(e.currentTarget.checked);+ return validateHiddenNodes();+ }+ setVisible("premium")(true);+ onClose();+ }}+ checked={collapseAll}+ offLabel={isPremium ? null : <VscLock size="12" />}+ /> */}<Switchlabel="Light Theme"size="md"diff --git a/src/layout/Loading/index.tsx b/src/layout/Loading/index.tsxindex 2b243bfa..05df7eed 100644--- a/src/layout/Loading/index.tsx+++ b/src/layout/Loading/index.tsx@@ -1,7 +1,6 @@import React from "react";import styled, { keyframes } from "styled-components";import { Center, Image, Stack } from "@mantine/core";-import useGraph from "src/store/useGraph";import { JSONCrackLogo } from "../JsonCrackLogo";interface LoadingProps {@@ -30,7 +29,7 @@ const StyledLoading = styled.div<{ $visible: boolean }>`z-index: 100;pointer-events: visiblePainted;cursor: wait;- animation: 0.2s ${fadeIn};+ animation: 200ms ${fadeIn};animation-fill-mode: forwards;visibility: hidden;backdrop-filter: blur(5px);@@ -47,9 +46,7 @@ const StyledMessage = styled.div`font-weight: 600;`;-export const Loading: React.FC<LoadingProps> = ({ loading: innerLoading = false, message }) => {- const loading = useGraph(state => state.loading || innerLoading);-+export const Loading: React.FC<LoadingProps> = ({ loading = false, message }) => {return (<Center mx="auto"><StyledLoading $visible={loading}>diff --git a/src/store/useFile.ts b/src/store/useFile.tsindex 3f4bd85e..347bfa07 100644--- a/src/store/useFile.ts+++ b/src/store/useFile.ts@@ -68,10 +68,10 @@ const isURL = (value: string) => {);};-const debouncedUpdateJson = debounce(- (value: unknown) => useJson.getState().setJson(JSON.stringify(value, null, 2)),- 800-);+const debouncedUpdateJson = debounce((value: unknown) => {+ useGraph.getState().setLoading(true);+ useJson.getState().setJson(JSON.stringify(value, null, 2));+}, 800);const filterArrayAndObjectFields = (obj: object) => {const result = {};diff --git a/src/store/useGraph.ts b/src/store/useGraph.tsindex 391727f6..1e9db5cc 100644--- a/src/store/useGraph.ts+++ b/src/store/useGraph.ts@@ -14,6 +14,7 @@ export interface Graph {graphCollapsed: boolean;foldNodes: boolean;fullscreen: boolean;+ collapseAll: boolean;nodes: NodeData[];edges: EdgeData[];collapsedNodes: string[];@@ -30,6 +31,7 @@ const initialStates: Graph = {graphCollapsed: false,foldNodes: false,fullscreen: false,+ collapseAll: false,nodes: [],edges: [],collapsedNodes: [],@@ -54,6 +56,7 @@ interface GraphActions {getCollapsedEdgeIds: () => string[];toggleFold: (value: boolean) => void;toggleFullscreen: (value: boolean) => void;+ toggleCollapseAll: (value: boolean) => void;zoomIn: () => void;zoomOut: () => void;centerView: () => void;@@ -62,6 +65,10 @@ interface GraphActions {const useGraph = create<Graph & GraphActions>((set, get) => ({...initialStates,+ toggleCollapseAll: collapseAll => {+ set({ collapseAll });+ get().collapseGraph();+ },clearGraph: () => set({ nodes: [], edges: [], loading: false }),getCollapsedNodeIds: () => get().collapsedNodes,getCollapsedEdgeIds: () => get().collapsedEdges,@@ -69,16 +76,20 @@ const useGraph = create<Graph & GraphActions>((set, get) => ({setGraph: (data, options) => {const { nodes, edges } = parser(data ?? useJson.getState().json);- set({- nodes,- edges,- collapsedParents: [],- collapsedNodes: [],- collapsedEdges: [],- graphCollapsed: false,- loading: true,- ...options,- });+ if (get().collapseAll) {+ set({ nodes, edges, ...options });+ get().collapseGraph();+ } else {+ set({+ nodes,+ edges,+ collapsedParents: [],+ collapsedNodes: [],+ collapsedEdges: [],+ graphCollapsed: false,+ ...options,+ });+ }},setDirection: (direction = "RIGHT") => {set({ direction });@@ -184,16 +195,18 @@ const useGraph = create<Graph & GraphActions>((set, get) => ({},zoomIn: () => {const viewPort = get().viewPort;- viewPort?.camera.recenter(viewPort.centerX, viewPort.centerY, viewPort.zoomFactor + 0.1);+ viewPort?.camera?.recenter(viewPort.centerX, viewPort.centerY, viewPort.zoomFactor + 0.1);},zoomOut: () => {const viewPort = get().viewPort;- viewPort?.camera.recenter(viewPort.centerX, viewPort.centerY, viewPort.zoomFactor - 0.1);+ viewPort?.camera?.recenter(viewPort.centerX, viewPort.centerY, viewPort.zoomFactor - 0.1);},centerView: () => {const viewPort = get().viewPort;- const canvas = document.querySelector(".jsoncrack-canvas") as HTMLElement;- viewPort?.camera.centerFitElementIntoView(canvas);+ const canvas = document.querySelector(".jsoncrack-canvas") as HTMLElement | null;+ if (canvas) {+ viewPort?.camera?.centerFitElementIntoView(canvas);+ }},toggleFold: foldNodes => {set({ foldNodes });