All Projects → ErikGartner → Dtree

ErikGartner / Dtree

Licence: mit
A library for visualizing data trees with multiple parents, such as family trees. Built on top of D3.

Programming Languages

javascript
184084 projects - #8 most used programming language

Labels

Projects that are alternatives of or similar to Dtree

game of life-elixir
An implementation of Conway's Game of Life in Elixir
Stars: ✭ 22 (-92.86%)
Mutual labels:  d3
Plottable
📊 A library of modular chart components built on D3
Stars: ✭ 2,834 (+820.13%)
Mutual labels:  d3
Doctor
基于知识图谱的医学诊断系统。Medical Diagnosis System Based on Knowledge Map.
Stars: ✭ 286 (-7.14%)
Mutual labels:  d3
pdf2xml-viewer
A simple viewer and inspection tool for text boxes in PDF documents
Stars: ✭ 82 (-73.38%)
Mutual labels:  d3
cryptoization
Data visualization application showing all BTC transactions in real-time
Stars: ✭ 12 (-96.1%)
Mutual labels:  d3
React Native Svg Charts Examples
A collection of usage examples of react-native-svg-charts
Stars: ✭ 266 (-13.64%)
Mutual labels:  d3
simple-square-packing
werehamster.github.io/simple-square-packing/
Stars: ✭ 12 (-96.1%)
Mutual labels:  d3
Carbon Charts
📊 📈⠀Robust dataviz framework implemented using D3 & typescript
Stars: ✭ 287 (-6.82%)
Mutual labels:  d3
comparative-layout-explorer
📊 x 📊 =❓An online gallery to explore the design space of comparative layouts
Stars: ✭ 16 (-94.81%)
Mutual labels:  d3
Realize
A React component tree visualizer
Stars: ✭ 285 (-7.47%)
Mutual labels:  d3
react-org-chart
Component for displaying an org chart for a large organization. Supports lazy load and export.
Stars: ✭ 147 (-52.27%)
Mutual labels:  d3
d3-sankey-circular
A fork of the d3-sankey library to allow circular links.
Stars: ✭ 65 (-78.9%)
Mutual labels:  d3
D3 Extended
Extends D3 with some common jQuery functions and more
Stars: ✭ 269 (-12.66%)
Mutual labels:  d3
vue-d3-charts
D3 charts for Vue
Stars: ✭ 66 (-78.57%)
Mutual labels:  d3
Victory Chart
Chart Component for Victory
Stars: ✭ 286 (-7.14%)
Mutual labels:  d3
github-contribution-graph
Add beautiful GitHub contribution/commit graph to your profile README!
Stars: ✭ 37 (-87.99%)
Mutual labels:  d3
Floweaver
View flow data as Sankey diagrams
Stars: ✭ 266 (-13.64%)
Mutual labels:  d3
Rumble Charts
React components for building composable and flexible charts
Stars: ✭ 293 (-4.87%)
Mutual labels:  d3
Recharts
Redefined chart library built with React and D3
Stars: ✭ 17,455 (+5567.21%)
Mutual labels:  d3
D3 Funnel
A JavaScript library for rendering funnel charts using the D3.js framework.
Stars: ✭ 283 (-8.12%)
Mutual labels:  d3

dTree

A library for visualizing data trees with multiple parents built on top of D3.

npm Bower

Using dTree? Send me a message with a link to your website to be listed below.

The Online Viewer

There exists an online viewer for dTree graphs called Treehouse, similar to https://bl.ocks.org/ for D3. Treehouse allows anybody to host a dTree graph without having to create a website or interact directly with the library. It fetches data from Github's gists and displays it in a nice format. All graphs are unlisted so without your Gist ID nobody else can view them. Checkout the demo graph for dTree:

https://treehouse.gartner.io/ErikGartner/58e58be650453b6d49d7

The same demo is also available on JSFiddle.

Installation

There are several ways to use dTree. One way is to simply include the compiled file dTree.js that then exposes a dTree variable. dTree is available on both NPM and Bower as d3-dtree.

npm install d3-dtree
bower install d3-dtree
yarn add d3-dtree

Lastly dTree is also available through several CDNs such as jsDelivr:

https://cdn.jsdelivr.net/npm/[email protected]/dist/dTree.min.js

Requirements

To use the library the follow dependencies must be loaded:

Usage

To create a graph from data use the following command:

tree = dTree.init(data, options);

The data object should have the following structure:

[{
  name: "Father",                         // The name of the node
  class: "node",                          // The CSS class of the node
  textClass: "nodeText",                  // The CSS class of the text in the node
  depthOffset: 1,                         // Generational height offset
  marriages: [{                           // Marriages is a list of nodes
    spouse: {                             // Each marriage has one spouse
      name: "Mother",
    },
    children: [{                          // List of children nodes
      name: "Child",
    }]
  }],
  extra: {}                               // Custom data passed to renderers
}]

The following CSS sets some good defaults:

.linage {
    fill: none;
    stroke: black;
}
.marriage {
    fill: none;
    stroke: black;
}
.node {
    background-color: lightblue;
    border-style: solid;
    border-width: 1px;
}
.nodeText{
    font: 10px sans-serif;
}
.marriageNode {
    background-color: black;
    border-radius: 50%;
}

The options object has the following default values:

{
  target: '#graph',
  debug: false,
  width: 600,
  height: 600,
  hideMarriageNodes: true,
  marriageNodeSize: 10,
  callbacks: {
    /*
      Callbacks should only be overwritten on a need to basis.
      See the section about callbacks below.
    */
  },
  margin: {
    top: 0,
    right: 0,
    bottom: 0,
    left: 0
  },
  nodeWidth: 100,
  styles: {
    node: 'node',
    linage: 'linage',
    marriage: 'marriage',
    text: 'nodeText'
  }
}

Zooming

The returned object, tree = dTree.init(data, options), contains functions to control the viewport.

  • tree.resetZoom(duration = 500) - Reset zoom and position to initial state
  • zoomTo(x, y, zoom = 1, duration = 500) - Zoom to a specific position
  • zoomToNode(nodeId, zoom = 2, duration = 500) - Zoom to a specific node
  • zoomToFit(duration = 500) - Zoom to fit the entire tree into the viewport

Callbacks

Below follows a short descriptions of the available callback functions that may be passed to dTree. See dtree.js for the default implementations. Information about e.g. mouse cursor position can retrieved by interacting with the this object, i.e. d3.mouse(this).

nodeClick

function(name, extra, id)

The nodeClick function is called by dTree when the node or text is clicked by the user. It shouldn't return any value.

nodeRightClick

function(name, extra, id)

The nodeRightClick function is called by dTree when the node or text is right-clicked by the user. It shouldn't return any value.

nodeRenderer

function(name, x, y, height, width, extra, id, nodeClass, textClass, textRenderer)

The nodeRenderer is called once for each node and is expected to return a string containing the node. By default the node is rendered using a div containing the text returned from the default textRendeder. See the JSFiddle above for an example on how to set the callback.

nodeHeightSeperation

function(nodeWidth, nodeMaxHeight)

The nodeHeightSeperation is called during intial layout calculation. It shall return one number representing the distance between the levels in the graph.

nodeSize

function(nodes, width, textRenderer)

This nodeSize function takes all nodes and a preferred width set by the user. It is then expected to return an array containing the width and height for all nodes (they all share the same width and height during layout though nodes may be rendered as smaller by the nodeRenderer).

nodeSorter

function(aName, aExtra, bName, bExtra)

The nodeSorterer takes two nodes names and extra data, it then expected to return -1, 0 or 1 depending if A is less, equal or greater than B. This is used for sorting the nodes in the tree during layout.

textRenderer

function(name, extra, textClass)

The textRenderer function returns the formatted text to the nodeRenderer. This way the user may chose to overwrite only what text is shown but may opt to keep the default nodeRenderer.

marriageClick

function(extra, id)

Same as nodeClick but for the marriage nodes (connector).

marriageRightClick

function(extra, id)

Same as nodeRightClick but for the marriage nodes (connector).

marriageRenderer

function(x, y, height, width, extra, id, nodeClass)

Same as nodeRenderer but for the marriage nodes (connector).

marriageSize

function(nodes, size)

Same as nodeSize but for the marriage nodes (connector).

Development

dTree has the following development environment:

  • node v11.x (use Docker image node:11)
  • gulp 3.x
  • Yarn instead of npm.

To setup and build the library from scratch follow these steps:

  1. yarn install
  2. yarn run build

A demo is available by running:

yarn run demo

It hosts a demo on localhost:3000/ by serving test/demo and using the latest compiled local version of the library.

Contributing

Contributions are very welcomed! Checkout the CONTRIBUTING document for style information. A good place to start is to make a pull request to solve an open issue. Feel free to ask questions regarding the issue since most have a sparse description.

License

The MIT License (MIT)

Copyright (c) 2015-2020 Erik Gärtner

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].