# network-tree

> Generate a Network's sitemap in json formats compliant with various graph visualization libraries

Latest version **1.1.0** (published 2016-06-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install network-tree
pnpm add network-tree
yarn add network-tree
bun add network-tree
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2016-06-20 |
| First published | 2016-06-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Raghav Dua |
| Maintainers | the-mad-king |

## Links

- npm: https://www.npmjs.com/package/network-tree
- Repository: https://github.com/duaraghav8/network-tree
- Homepage: https://github.com/duaraghav8/network-tree#readme
- Issues: https://github.com/duaraghav8/network-tree/issues
- npm.io page: https://npm.io/package/network-tree

## Dependencies (2)

- [es6-promise](https://npm.io/package/es6-promise.md) ^3.2.1
- [sitemap-generator](https://npm.io/package/sitemap-generator.md) ^4.0.0

## Recent versions

- 1.1.0 (latest) — 2016-06-20
- 1.0.0 — 2016-06-20

## README

Retrieve Sitemaps in JSON format(s) compliant with your favourite Graph Visualization Library

#Usage
```network-tree``` abstracts away the complexity of organizing a sitemap into a json suitable for the visualization library you use. This allows you to focus on making pretty visualizations rather than worrying about structuring the data.

For example, here's a typical JSON that you have to pass to a D3 Tree Visualization:
```javascript
{
	"name": "Mike and Marcia",
	"children": [
		{
			"name": "Children",
			"children": [
				{ "name": "Mikael" }
			]
		},
		{
			"name": "Pets",
			"children": [
				{
					"name": "Dogs",
					"children": [
						{ "name": "Bleu" },
						{ "name": "Tagg" }
					]
				},
				{
					"name": "Cats",
					"children": [
						{ "name": "Bob" },
						{ "name": "Peanut" }
					]
				}
			]
		}
	]
}
```

If you want to create a visualization of a website's hierarchy, you will:

			1. Retrieve the sitemap XML
			2. Write a converter to convert the XML into JSON to be used for D3
			3. Inject the JSON to create art!
			
Now imagine you decide to port to sigma.js =(

To ease your day, network-tree handles Steps 1 & 2 for all the visualization libraries. Just plug in the domain name and your library, and get the appropriate JSON. Its THAT simple! :)

#Install
```bash
npm install network-tree
```

#API
```javascript
var networkTree = require ('network-tree');
```

Use the ```new networkTree ()``` method and supply the domain name for initial setup. For retrieving the sitemap, use the object's ```getSitemap ()``` method and pass an options object to specify which libraries you want the json for.

##Options
###Setup
```javascript
var tree = new networkTree ('example.com', {
	port: 80
});
```
If unspecified, port defaults to 80

###Retrieve Sitemap
```javascript
tree.getSitemap ({
	for: ['d3', 'sigma']
});
```
If unspecified, ```for``` defaults to []. So no json will be returned

#Example

###Express
```javascript
var networkTree = require ('network-tree'),
	app = require ('express') ();

var tree, domain = 'http://raghavdua.com/';

app
	.get ('/tree/:format', function (req, res) {
		if (req.params.format && req.params.format !== 'd3') return res.sendStatus (400);	//BAD REQUEST

		tree = new networkTree (domain);
		tree
			.getSitemap ({
				for: ['d3']
			})

			.then (function (jsons) {
				res.header ('Content-Type', 'text/plain');
				res.end (JSON.stringify (jsons ['d3'], null, 2));
			})

			.catch (function (err) {
				res.sendStatus (500);
			});
	})

	.listen (3000);
```

###Test:
```bash
curl http://localhost:8080/tree/d3
```

##Support
network-tree currently supports json format of only **D3.js**. Stay tuned!

#License
MIT

---
_Source: https://npm.io/package/network-tree · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
