-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: basic navigation #92
Conversation
@@ -89,11 +89,16 @@ const relationships = (xs: { id: string; children: never[] }[]) => { | |||
]); | |||
}; | |||
|
|||
export const flattenTree = tree => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've needed to break in two the function parser on line 97.
- extractTree will take as input the JSON data, and outputs the node tree that contains the
id
andchildren
keys. This is the main data structure to work on. - flattenTree is the function that will take as an input the extracted tree produced by extractTree, and will flatten it to an array. That array can be later on used to split the nodes and edges. I am missing some tests here, because on the test files you can take a look at the input/output data structures and have a better idea of what each function does, without need to read the source code of them. Take a look at this branch's folder to see the tests
Thank you for creating such feature, I have merged the PR branch with upstream so you can continue. Good luck! |
…e json feat: added parent_id data each node of the tree representation of the json
…gets drawn on canvas
Thanks for the update on the branch @AykutSarac . It was very helpful, and I could make some updates to the branch.
Pending work:
If you need me to improve something more on this PR just say it here. I did enjoy working on your project. I have some ideas that may be interesting to build, for example:
If you need something else just ping me. |
For this part, I think it would be better to just leave the parent node as is for now. The less customization the better it is.
I think we could put a navigation mode once this PR comes to a final, user can choose between navigation modes at sidebar. I have good UI & UX plans for this one.
@KarlHeitmann Thank you so much for the contribution, it is especially so awesome when people adding new feature to the project. |
Thanks! I'm going to take a look at #51 and #27 I was looking for something additional to do.
Ok! I like keeping things simple. However, yesterday I've had an idea that needs only two lines of code to be changed. Take a look at this branch I leaved on my fork https://github.com/KarlHeitmann/jsonvisio.com/tree/aesthetic_suggestion_to_nav With these changes the graph looks something like this |
const subTree = searchSubTree(mainTree, props.id); | ||
|
||
if (subTree.length) { | ||
const flatTree = flattenTree(subTree); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
flattenTree from json-editor-parser.ts
is applied to the sub tree whose node is clicked by the user. Here you apply the same function applied on line 64 of this file into a subtree. FRACTAL.
@@ -46,6 +44,24 @@ export function getEdgeNodes( | |||
}; | |||
} | |||
|
|||
|
|||
export function searchSubTree (trees: any[], id: string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extremely simple function to search a match id
, and take a subtree from the JSON data.
@@ -0,0 +1,190 @@ | |||
import { extractTree } from "src/utils/json-editor-parser" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test files
Hi!
Here is an idea I've built some weeks ago. I wanted to add navigation through the nodes of the JSON. Once upon the user clicks on a node of the graph, the
id
of the node is sent throughprops.id
to the handleClick function, and the handle click will search thatid
on the original graph structure of the JSON. When it finds the match, the function that is applied to the original JSON main tree is applied on the subtree whose root is theid
that matchesprops.id
The navigation feature is toggled by a new button on the sidebar. If the button is pressed by second time (thus, disabling navigation) it will reset the graph and display again the main tree.
The navigation button was originally meant to be a patch, because I wanted to add a
parent node
to the subtree, when this parent node is clicked, it will search for theid
of the parent node of the subtree on the main tree, and then display that broader subtree on the display window.Adding this
parent node
to the subtree was not a task as easy as displaying the subtree, that's the reason why I decided to add more tests to the project. You can see them on this branch on my forkI was working on it, but when I visited the changes on the upstream repo (yours) a couple days ago, I found out that you changed the structure of
Graph/index.tsx
component, and you now useReact.memo
. I've tried doing a rebase on the upstream but I was not able to add navigation to subtrees using the newGraph/index.tsx
component that uses theReact.memo
function. That's the reason why I am submitting this PR. Can you help me doing the merge, so I can continue working on this feature? My attempt to do the rebase is here if you want to take a look at it.I will be on the lookout for any comment, suggestion and/or feedback over this feature.
Best regards