Skip to content

Implement Search Mechanism#98

Open
uvotguy wants to merge 1 commit into
fperucic:masterfrom
uvotguy:master
Open

Implement Search Mechanism#98
uvotguy wants to merge 1 commit into
fperucic:masterfrom
uvotguy:master

Conversation

@uvotguy

@uvotguy uvotguy commented Dec 4, 2017

Copy link
Copy Markdown

Hello,

I'm new at github, so forgive me if I'm doing things out of order. Also, I'm not an ace JavaScript programmer, so there may be a better way of doing some of these things.

I've implemented a search mechanism for Treant-js trees. It's not really functionality related to tree drawing, but more in the nature of useful utilities. So I added new file TreantUtil.js and TreantUtil.css.

The problem I'm trying to solve is this. You have a large organization with many subunits. You want to find "Joe Engineer", and you want to know who he works for. This is a very common use for an Org Chart.

Insert a couple of web controls in your index file, like those found in examples/search/index.html, and you'll be able to quickly find people. It starts by collapsing the tree (assuming branches are collapsible) and fading (lowering the opacity of) all nodes. The code searches all nodes for the search term, and make an array of them. For each matching node, it uncollapses the node's parent and unfades the node and its parent. Repeat till you get to the top of the tree.

When it's done, you'll see all nodes and their parents. It seems to work fine on all devices I've tried (though a limited number).

NOTE: the "Expand All", "Collapse All", and "Reset" functions are a biproduct of the search algorithm. I included the buttons in the example, but perhaps they could be separated out as stand-alone examples.

Please let me know what you think. If it's not something you're interested in, I'll delete my fork and use the code on my company's website. No worries!

Scott Koch

@taniqsut

Copy link
Copy Markdown

Great job!

Do you have any example how to addNode or delete Node in run time?

Best regards,

@egor-progger

Copy link
Copy Markdown

@uvotguy , @taniqsut , @T-Scott-Koch I ported treantjs to Typescript. You can try https://www.npmjs.com/package/pointlinejs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants