Skip to content

Commit 60ec47c

Browse files
committed
🚚 merge treeviz-react
1 parent b3991ed commit 60ec47c

32 files changed

+12881
-222
lines changed

.gitignore

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
node_modules
2-
dist/index.html
1+
**/node_modules/**
2+
**/dist/**
3+
**/storybook-static/**
34
yarn-error.log
4-
.DS_Store
5+
.DS_Store

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
src
22
demo
33
public
4+
treeviz-react

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Also, but not recommended, you can use : `<script src="https://rawgit.com/Pierre
2525

2626
#### React
2727

28-
Check the treeviz wrapper for react: [treeviz-react](https://github.com/PierreCapo/treeviz-react)
28+
Check the treeviz wrapper for react: [treeviz-react](./treeviz-react)
2929

3030
#### Vanilla JavaScript
3131

@@ -74,7 +74,10 @@ The tree will be clever enough to updates only the part of the trees that have b
7474
var hierarchical_data_example = {
7575
name: "Mom",
7676
qty: 10,
77-
children: [{ name: "Son A", qty: 3 }, { name: "Son B", qty: 7 }],
77+
children: [
78+
{ name: "Son A", qty: 3 },
79+
{ name: "Son B", qty: 7 },
80+
],
7881
};
7982

8083
var myTree = Treeviz.create({

treeviz-react/.npmignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
src
2+
storybook-static
3+
stories
4+
public
5+
.storybook

treeviz-react/.storybook/addons.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import "@storybook/addon-links/register";
2+
import "@storybook/addon-knobs/register";

treeviz-react/.storybook/config.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { configure } from "@storybook/react";
2+
// automatically import all files ending in *.stories.tsx
3+
const req = require.context("../stories", true, /\.stories\.tsx$/);
4+
5+
function loadStories() {
6+
req.keys().forEach(req);
7+
}
8+
9+
configure(loadStories, module);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module.exports = ({ config, mode }) => {
2+
config.module.rules.push({
3+
test: /\.(ts|tsx)$/,
4+
loader: require.resolve("babel-loader"),
5+
options: {
6+
presets: [["react-app", { flow: false, typescript: true }]]
7+
}
8+
});
9+
config.resolve.extensions.push(".ts", ".tsx");
10+
return config;
11+
};

treeviz-react/README.md

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# Treeviz-react
2+
3+
[![Known Vulnerabilities](https://snyk.io/test/github/dwyl/hapi-auth-jwt2/badge.svg?targetFile=package.json)](https://snyk.io/test/github/dwyl/hapi-auth-jwt2?targetFile=package.json)
4+
![David](https://img.shields.io/david/PierreCapo/treeviz-react)
5+
[![license](https://badgen.now.sh/badge/license/MIT)](./LICENSE)
6+
7+
[Treeviz](https://github.com/PierreCapo/treeviz) implementation for React
8+
9+
![](https://i.imgur.com/zFKuIgC.gif)
10+
11+
<p align="center">
12+
💅 <a href="https://pierrecapo.github.io/treeviz-react">Come play with the Treeviz storybook!</a> 💅
13+
</p>
14+
15+
### Usage
16+
17+
```
18+
npm install treeviz-react
19+
20+
// or
21+
22+
yarn add treeviz-react
23+
```
24+
25+
```js
26+
import React from "react";
27+
import { TreevizReact } from "treeviz-react";
28+
29+
const data = [
30+
{ id: 1, text_1: "Chaos", text_2: "Void", father: null, color: "#FF5722" },
31+
{ id: 2, text_1: "Tartarus", text_2: "Abyss", father: 1, color: "#FFC107" },
32+
{ id: 3, text_1: "Gaia", text_2: "Earth", father: 1, color: "#8BC34A" },
33+
{ id: 4, text_1: "Eros", text_2: "Desire", father: 1, color: "#00BCD4" }
34+
];
35+
36+
const Foo = () => {
37+
return (
38+
<TreevizReact
39+
data={data}
40+
idKey={"id"}
41+
relationnalField={"father"}
42+
nodeWidth={200}
43+
nodeHeight={100}
44+
mainAxisNodeSpacing={2}
45+
secondaryAxisNodeSpacing={1.3}
46+
renderNode={node =>
47+
`<div style="height:${
48+
node.settings.nodeHeight
49+
}px;display:flex;align-items:center;margin-left:12px">Node name: ${
50+
node.data.text_1
51+
}</div>`
52+
}
53+
onNodeClick={node => console.log("you clicked on node " + node.id)}
54+
duration={500}
55+
linkWidth={node => 3}
56+
/>
57+
);
58+
};
59+
```
60+
61+
The tree will automatically update whenever one of those props change. Note that is not recommended to update the relationnalField and the idKey prop once the component has been mounted.
62+
63+
### API
64+
65+
| Prop | Type | Default | Definition |
66+
| -------------------------- | --------------------------------------------- | ------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
67+
| `idKey` | string | "id" | The unique identifier field in the dataset representing the node |
68+
| `relationnalField` | string | "father" | In case of flat dataset, usually the relationnal field between each node is the field representing the father of the node, linking it to the id of the field. (See example below). |
69+
| `hasFlatData` | boolean | true | Specify whether the data passed to the tree is flat or already hierarchical |
70+
| `hasPanAndZoom` | boolean | true | Toggle the ability to pan and zoom the tree |
71+
| `nodeWidth` | number | 160 | Width of a node in px |
72+
| `nodeHeight` | number | 100 | Height of a node in px |
73+
| `linkColor` | function | (node) => "#ffcc80" | Color of the link |
74+
| `linkWidth` | function | (node) => 10 | Width of the link |
75+
| `linkShape` | "quadraticBeziers" \| "orthogonal" \| "curve" | "quadraticBeziers" | Shape of the link |
76+
| `renderNode` | function | (node) => null | HTML template for every node |
77+
| `isHorizontal` | boolean | true | Direction of the tree. If true, the tree expands from left to right. If false, it goes from top to bottom |
78+
| `onNodeClick` | function | (node) => null | Function handling the event when someone click on it |
79+
| `onNodeMouseEnter` | function | (node) => null | Function handling the event when someone hover a node |
80+
| `onNodeMouseLeave` | function | (node) => null | Function handling the event when the mouse pointer leaves a node |
81+
| `mainAxisNodeSpacing` | number or "auto" | 1.3 | Set the distance in pixels between two depths in the tree. If the value is `auto` it will automatically display the tree to fit the size of the container. |
82+
| `secondaryAxisNodeSpacing` | number | 1.25 | Set the distance between nodes in the same level as a coefficient of node dimensions. Recommended to have the value superior to 1 |
83+
| `marginTop` | number | 1.25 | Set the margin between the SVG element and the tree |
84+
| `marginBottom` | number | 1.25 | Set the margin between the SVG element and the tree |
85+
| `marginLeft` | number | 1.25 | Set the margin between the SVG element and the tree |
86+
| `marginRight` | number | 1.25 | Set the margin between the SVG element and the tree |
87+
| `areaHeight` | number | 800 | The height of the area that displays the tree |
88+
| `areaWidth` | number | 500 | the width of the area that displays the tree |
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"files": {
3+
"main.js": "/static/js/main.c01ce7dc.chunk.js",
4+
"main.js.map": "/static/js/main.c01ce7dc.chunk.js.map",
5+
"runtime~main.js": "/static/js/runtime~main.a8a9905a.js",
6+
"runtime~main.js.map": "/static/js/runtime~main.a8a9905a.js.map",
7+
"static/js/2.0cecaac4.chunk.js": "/static/js/2.0cecaac4.chunk.js",
8+
"static/js/2.0cecaac4.chunk.js.map": "/static/js/2.0cecaac4.chunk.js.map",
9+
"index.html": "/index.html",
10+
"precache-manifest.1e75288e59b8859f9d2633d7a719179b.js": "/precache-manifest.1e75288e59b8859f9d2633d7a719179b.js",
11+
"service-worker.js": "/service-worker.js"
12+
}
13+
}

treeviz-react/build/favicon.ico

3.78 KB
Binary file not shown.

treeviz-react/build/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="shortcut icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><link rel="manifest" href="/manifest.json"/><title>React App</title></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div><script>!function(l){function e(e){for(var r,t,n=e[0],o=e[1],u=e[2],f=0,i=[];f<n.length;f++)t=n[f],p[t]&&i.push(p[t][0]),p[t]=0;for(r in o)Object.prototype.hasOwnProperty.call(o,r)&&(l[r]=o[r]);for(s&&s(e);i.length;)i.shift()();return c.push.apply(c,u||[]),a()}function a(){for(var e,r=0;r<c.length;r++){for(var t=c[r],n=!0,o=1;o<t.length;o++){var u=t[o];0!==p[u]&&(n=!1)}n&&(c.splice(r--,1),e=f(f.s=t[0]))}return e}var t={},p={1:0},c=[];function f(e){if(t[e])return t[e].exports;var r=t[e]={i:e,l:!1,exports:{}};return l[e].call(r.exports,r,r.exports,f),r.l=!0,r.exports}f.m=l,f.c=t,f.d=function(e,r,t){f.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:t})},f.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},f.t=function(r,e){if(1&e&&(r=f(r)),8&e)return r;if(4&e&&"object"==typeof r&&r&&r.__esModule)return r;var t=Object.create(null);if(f.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:r}),2&e&&"string"!=typeof r)for(var n in r)f.d(t,n,function(e){return r[e]}.bind(null,n));return t},f.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return f.d(r,"a",r),r},f.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},f.p="/";var r=window.webpackJsonp=window.webpackJsonp||[],n=r.push.bind(r);r.push=e,r=r.slice();for(var o=0;o<r.length;o++)e(r[o]);var s=n;a()}([])</script><script src="/static/js/2.0cecaac4.chunk.js"></script><script src="/static/js/main.c01ce7dc.chunk.js"></script></body></html>

treeviz-react/build/manifest.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"short_name": "React App",
3+
"name": "Create React App Sample",
4+
"icons": [
5+
{
6+
"src": "favicon.ico",
7+
"sizes": "64x64 32x32 24x24 16x16",
8+
"type": "image/x-icon"
9+
}
10+
],
11+
"start_url": ".",
12+
"display": "standalone",
13+
"theme_color": "#000000",
14+
"background_color": "#ffffff"
15+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
self.__precacheManifest = (self.__precacheManifest || []).concat([
2+
{
3+
"revision": "ad935d05b2fce185b244b2bebd26efe9",
4+
"url": "/index.html"
5+
},
6+
{
7+
"revision": "305128248157a3330939",
8+
"url": "/static/js/2.0cecaac4.chunk.js"
9+
},
10+
{
11+
"revision": "93db34ffc52e57655e9a",
12+
"url": "/static/js/main.c01ce7dc.chunk.js"
13+
},
14+
{
15+
"revision": "42ac5946195a7306e2a5",
16+
"url": "/static/js/runtime~main.a8a9905a.js"
17+
}
18+
]);

treeviz-react/build/service-worker.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* Welcome to your Workbox-powered service worker!
3+
*
4+
* You'll need to register this file in your web app and you should
5+
* disable HTTP caching for this file too.
6+
* See https://goo.gl/nhQhGp
7+
*
8+
* The rest of the code is auto-generated. Please don't update this file
9+
* directly; instead, make changes to your Workbox build configuration
10+
* and re-run your build process.
11+
* See https://goo.gl/2aRDsh
12+
*/
13+
14+
importScripts("https://storage.googleapis.com/workbox-cdn/releases/4.3.1/workbox-sw.js");
15+
16+
importScripts(
17+
"/precache-manifest.1e75288e59b8859f9d2633d7a719179b.js"
18+
);
19+
20+
self.addEventListener('message', (event) => {
21+
if (event.data && event.data.type === 'SKIP_WAITING') {
22+
self.skipWaiting();
23+
}
24+
});
25+
26+
workbox.core.clientsClaim();
27+
28+
/**
29+
* The workboxSW.precacheAndRoute() method efficiently caches and responds to
30+
* requests for URLs in the manifest.
31+
* See https://goo.gl/S9QRab
32+
*/
33+
self.__precacheManifest = [].concat(self.__precacheManifest || []);
34+
workbox.precaching.precacheAndRoute(self.__precacheManifest, {});
35+
36+
workbox.routing.registerNavigationRoute(workbox.precaching.getCacheKeyForURL("/index.html"), {
37+
38+
blacklist: [/^\/_/,/\/[^/]+\.[^/]+$/],
39+
});

treeviz-react/build/static/js/2.0cecaac4.chunk.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

treeviz-react/build/static/js/2.0cecaac4.chunk.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

treeviz-react/build/static/js/main.c01ce7dc.chunk.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)