{"id":13482129,"url":"https://github.com/PierreCapo/treeviz","last_synced_at":"2025-03-27T12:32:18.774Z","repository":{"id":32726199,"uuid":"136829698","full_name":"PierreCapo/treeviz","owner":"PierreCapo","description":"Tree diagrams with JavaScript :evergreen_tree: :chart_with_upwards_trend:","archived":false,"fork":false,"pushed_at":"2024-04-03T19:05:28.000Z","size":1891,"stargazers_count":165,"open_issues_count":10,"forks_count":28,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-01-23T09:48:26.708Z","etag":null,"topics":["big-data","family-tree","hierarchy","javascript","represent-tree-diagrams","tree","visualization"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PierreCapo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-06-10T17:23:40.000Z","updated_at":"2025-01-17T06:28:28.000Z","dependencies_parsed_at":"2023-01-14T22:15:14.166Z","dependency_job_id":"1d5ed595-f2b8-4b5c-85d7-e802f5ebff77","html_url":"https://github.com/PierreCapo/treeviz","commit_stats":{"total_commits":77,"total_committers":8,"mean_commits":9.625,"dds":0.4415584415584416,"last_synced_commit":"88f5e9ba13795e84271868e9d15582023293709c"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PierreCapo%2Ftreeviz","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PierreCapo%2Ftreeviz/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PierreCapo%2Ftreeviz/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PierreCapo%2Ftreeviz/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PierreCapo","download_url":"https://codeload.github.com/PierreCapo/treeviz/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245493464,"owners_count":20624501,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["big-data","family-tree","hierarchy","javascript","represent-tree-diagrams","tree","visualization"],"created_at":"2024-07-31T17:00:59.263Z","updated_at":"2025-03-27T12:32:18.459Z","avatar_url":"https://github.com/PierreCapo.png","language":"TypeScript","readme":"# Treeviz\n\n[![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)\n[![license](https://badgen.now.sh/badge/license/MIT)](./LICENSE)\n\nThis javascript module aims at providing an easy interface in order to represent tree diagrams on screen with the ability to handle dynamic data flows. The data format must be JSON.\n\n![](https://i.imgur.com/vyB2Erg.gif)\n\n## Installation\n\nWith npm : \n\n```Bash\nnpm install treeviz\n```\n\nand then you can use it with : \n\n```JavaScript\nimport {Treeviz} from 'treeviz';\n```\n\nOr download this zip repository in the Github Release section and link the dist/treeviz.js file in your page directly : `\u003cscript src=\"./dist/index.js\u003e\u003cscript\u003e`\n\n## Usage\n\n#### Vanilla JavaScript\n\n```HTML\n// Define a tree element where dimensions are mandatory\n\u003cdiv id=\"tree\" style=\"height:700px; width:900px\"\u003e\u003c/div\u003e\n\n\u003cscript\u003e\n// Define a dataset\nvar data = [\n  { id: 1, text_1: \"Father\", father: null },\n  { id: 2, text_1: \"Child A\", father: 1 },\n  { id: 3, text_1: \"Child B\", father: 1 },\n  { id: 4, text_1: \"Subchild C\", father: 2 }\n];\n\n// Define and configure a tree object\nvar myTree = Treeviz.create({\n  htmlId: \"tree\",\n  idKey: \"id\",\n  hasFlatData: true,\n  nodeColor: (nodeData) =\u003e \"grey\",\n  relationnalField: \"father\",\n});\n\n// Display the tree based on the data\nmyTree.refresh(data);\n\u003c/script\u003e\n```\n\nTo update the tree visually you will just have to pass new data to the `refresh` method like this :\n\n```JS\nmyTree.refresh(data);\nmyTree.refresh(data_update1);\nmyTree.refresh(data_update2);\n```\n\nThe tree will be clever enough to updates only the part of the trees that have been added or removed in the dataset, and so it won't redraw the entire tree.\n\n[Treeviz Example](https://codepen.io/pierrecapo/pen/MPbBdv)\n\n#### Hierarchical data case :\n\n```js\nvar hierarchical_data_example = {\n  name: \"Mom\",\n  qty: 10,\n  children: [\n    { name: \"Son A\", qty: 3 },\n    { name: \"Son B\", qty: 7 },\n  ],\n};\n\nvar myTree = Treeviz.create({\n  htmlId: \"tree\",\n  idKey: \"name\",\n  hasFlatData: false,\n  relationnalField: \"children\",\n});\n\nmyTree.refresh(hierarchical_data_example);\n```\n\n## API\n\nThe big part of the API is configuring the tree before passing data to it :\n\n```JS\nTreeviz.create(config);\n```\n\nThe table below lists all the avalaible key that the config object can have\n\n| Key                        | Type                                          | Default                 | Definition                                                                                                                                                                         |\n| -------------------------- | --------------------------------------------- | ----------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| `htmlId`                   | string (Required)                             |                         | The HTML id tag on the page where the tree should be drawn. It must have a width and an height specified                                                                           |\n| `idKey`                    | string                                        | \"id\"                    | The key in a data item representing the unique identifier of a node                                                                                                                |\n| `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). |\n| `hasFlatData`              | boolean                                       | true                    | Specify whether the data passed to the tree is flat or already hierarchical                                                                                                        |\n| `hasPan`                   | boolean                                       | false                   | Toggle the ability to pan the tree                                                                                                                                                 |\n| `hasZoom`                  | boolean                                       | false                   | Toggle the ability to zoom the tree                                                                                                                                                |\n| `nodeWidth`                | number                                        | 160                     | Width of a node in px                                                                                                                                                              |\n| `nodeHeight`               | number                                        | 100                     | Height of a node in px                                                                                                                                                             |\n| `linkColor`                | function                                      | (node: NodeData) =\u003e \"#ffcc80\" | Color of the link                                                                                                                                                                  |\n| `linkWidth`                | function                                      | (node: NodeData) =\u003e 10        | Width of the link                                                                                                                                                                  |\n| `linkShape`                | \"quadraticBeziers\" \\| \"orthogonal\" \\| \"curve\" | \"quadraticBeziers\"      | Shape of the link                                                                                                                                                                  |\n| `renderNode`               | function                                      | (node: NodeData) =\u003e null      | HTML template for every node                                                                                                                                                       |\n| `isHorizontal`             | boolean                                       | true                    | Direction of the tree. If true, the tree expands from left to right. If false, it goes from top to bottom                                                                          |\n| `onNodeClick`              | function                                      | (node: NodeData) =\u003e null      | Function handling the event when someone click on it                                                                                                                               |\n| `onNodeMouseEnter`         | function                                      | (node: NodeData) =\u003e null      | Function handling the event when someone hover a node                                                                                                                              |\n| `onNodeMouseLeave`         | function                                      | (node: NodeData) =\u003e null      | Function handling the event when the mouse pointer leaves a node                                                                                                                   |\n| `mainAxisNodeSpacing`      | number or \"auto\"                              | 300                     | 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.                         |\n| `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                                                  |\n| `marginTop`                | number                                        | 1.25                    | Set the margin between the SVG element and the tree                                                                                                                                |\n| `marginBottom`             | number                                        | 1.25                    | Set the margin between the SVG element and the tree                                                                                                                                |\n| `marginLeft`               | number                                        | 1.25                    | Set the margin between the SVG element and the tree                                                                                                                                |\n| `marginRight`              | number                                        | 1.25                    | Set the margin between the SVG element and the tree                                                                                                                                |\n| `duration`              | number                                        | 600                    | The duration of the animation transition between layouts                                                                                                                                |\n| `data`              | any                                        |                     | Needed for Typescript projects only to type the `NodeData` argument                                                                                                                                |\n\nAnd then, we have the `NodeData` type that is passed as callback of some functions:\n`\ntype NodeData {\n  data: // the data of each item\n  settings: // the settings object\n}\n`\n\n## Contributing\n\n- Clone the repo.\n- Run `npm install`.\n- Run `npm run dev`, then you can edit the files in the `./src` folder and the `./example/index.html` file.\n- To publish (admin rights), run `npm run build \u0026\u0026 npm publish`.\n\n## Credits\n\nThis module is based on d3 library, credit to all the contributors of this project.\n\n## License\n\nMIT\n","funding_links":[],"categories":["Miscellaneous","TypeScript","javascript","Libraries"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FPierreCapo%2Ftreeviz","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FPierreCapo%2Ftreeviz","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FPierreCapo%2Ftreeviz/lists"}