Giter VIP home page Giter VIP logo

js_family_tree's Introduction

js_family_tree

Interactive visualization and -exploration tool for large family trees.

Author: Benjamin W. Portner

License: GNU General Public License v3.0

Live example here. (Kudos to Pavel Puchkin from githack.com for providing the caching proxy!)

JSFiddle here.

Features

The code is based on the collapsible d3 tree example by d3noob.

Features in the original:

  • uses d3-hierarchy
  • collapsible children nodes
  • nice transitions

New features:

  • uses d3-dag instead of d3-hierarchy (allows two parents per node)
  • introduces union nodes to connect parents and children via common way point
  • nodes are collapsible in all directions: children, parents, partners (nodes memorize their dependencies)
  • use d3-tip to show metadata on hover
  • use d3-zoom to enable zooming and panning

How to use

  • Edit data/data.js to represent your family tree
  • Open familytree.html
  • Done!

Data format

The file data/data.js contains a single javascript object, which represents the family tree. The fields are as follows:

  • start: Enter here the id of the person, which should be the starting point of the family tree.
  • persons: Contains metadata about each person. Make sure each id is unique. Also, make sure each element in own_unions refers to a valid union defined in data.unions.
  • unions: Contains metadata about each family. Each entry in partner and children must refer to a valid person defined in data.persons.
  • links: Defines how unions and persons are to be linked (edge list). Basically an alternative representation of the information contained in person.own_unions, union.partner and union.children. Unfortunately, this redundancy is for now necessary to ensure proper functioning of the code!
data = {
    "start":"id4",
    "persons": {
        "id1": { "id": "id1", "name": "Adam", "birthyear": 1900, "deathyear": 1980, "own_unions": ["u1"], "birthplace":"Alberta", "deathplace":"Austin"},
        "id2": { "id": "id2", "name": "Berta", "birthyear": 1901, "deathyear": 1985, "own_unions": ["u1"], "birthplace":"Berlin", "deathplace":"Bern" },
        "id3": { "id": "id3", "name": "Charlene", "birthyear": 1930, "deathyear": 2010, "own_unions": ["u3", "u4"], "parent_union": "u1", "birthplace":"Château", "deathplace":"Cuxhaven" },
        "id4": { "id": "id4", "name": "Dan", "birthyear": 1926, "deathyear": 2009, "own_unions": [], "parent_union": "u1", "birthplace":"den Haag", "deathplace":"Derince" },
        "id5": { "id": "id5", "name": "Eric", "birthyear": 1931, "deathyear": 2015, "own_unions": ["u3"], "parent_union": "u2", "birthplace":"Essen", "deathplace":"Edinburgh" },
        "id6": { "id": "id6", "name": "Francis", "birthyear": 1902, "deathyear": 1970, "own_unions": ["u2"], "birthplace":"Firenze", "deathplace":"Faizabad" },
        "id7": { "id": "id7", "name": "Greta", "birthyear": 1905, "deathyear": 1990, "own_unions": ["u2"] },
        "id8": { "id": "id8", "name": "Heinz", "birthyear": 1970, "own_unions": ["u5"], "parent_union": "u3" },
        "id9": { "id": "id9", "name": "Iver", "birthyear": 1925, "deathyear": 1963, "own_unions": ["u4"] },
        "id10": { "id": "id10", "name": "Jennifer", "birthyear": 1950, "own_unions": [], "parent_union": "u4" },
        "id11": { "id": "id11", "name": "Klaus", "birthyear": 1933, "deathyear": 2013, "own_unions": [], "parent_union": "u1" },
        "id12": { "id": "id12", "name": "Lennart", "birthyear": 1999, "own_unions": [], "parent_union": "u5" },
    },
    "unions": {
        "u1": { "id": "u1", "partner": ["id1", "id2"], "children": ["id3", "id4", "id11"] },
        "u2": { "id": "u2", "partner": ["id6", "id7"], "children": ["id5"] },
        "u3": { "id": "u3", "partner": ["id3", "id5"], "children": ["id8"] },
        "u4": { "id": "u4", "partner": ["id3", "id9"], "children": ["id10"] },
        "u5": { "id": "u5", "partner": ["id8"], "children": ["id12"] },
    },
    "links": [
        ["id1", "u1"],
        ["id2", "u1"],
        ["u1", "id3"],
        ["u1", "id4"],
        ["id6", "u2"],
        ["id7", "u2"],
        ["u2", "id5"],
        ["id3", "u3"],
        ["id5", "u3"],
        ["u3", "id8"],
        ["id3", "u4"],
        ["id9", "u4"],
        ["u4", "id10"],
        ["u1", "id11"],
        ["id8", "u5"],
        ["u5", "id12"],
    ]
}

js_family_tree's People

Contributors

benportner avatar djbirdman avatar dthemg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

js_family_tree's Issues

advice for dynamic data

IS there a way for changing the basic data variables dynamically (persons, links, unions) and the DAG automatically adjusts itself to new info. - for example if I add a person with the correct links in the appropriate [data.persons, data.unions, data.links]
new information should be auto updated in the dag. If not auto updated at least a refresh function to take care of new data.

Thanks for any help.

Guide to Insert|Delete|Update node

HI
YOU ARE AMAZING
It is the most beautiful tree I found.

In fact, I am new to d3 world and if you can help me how to insert child node or delete or update I will appreciate you

Anyway THANKS

tooltip_div blocks mouse events from underlying nodes when faded out by opacity

The tooltip_div is faded in by a mouseover event and faded out by mouseout on a node or its text. I've noticed that while the div is hidden by setting opacity:0 it still blocks mouse events from happening on nodes it previously covered. Only by setting visibility:hidden the div will stop blocking mouse events on underlying nodes.
I've made too much specific changes in my fork to be able to create a pull request (Also I'm not too much of a git expert). But here are the changes I made to circumvent this: unverbuggt@ea56f2e

Formatting options for family tree usage

Hey, love the project but I'm pretty basic with JS. The issue is that I'm trying to use the code to set up a big family tree but I can't specify who is married / divorced to whom. Could you suggest a place to start ? My first thought would be to make a new version of the links with a separate colour but I think integrating it would be a bit messy.

Thanks for the work anyway

Sort visible nodes at each hierarchy layer

The use of d3-dag, unions and collapsible node works really nicely.

I'm new to d3 / d3-dag, so am wondering how to ensure the following:

  • the newly inserted partner of would display immediately underneath their partner, i.e. the partner of the eldest child should display directly underneath them and above the second-eldest child when clicking on the eldest child triggers the uncollapse
  • sort order stays the same across generations of a family, i.e. the eldest children of the eldest child always displaying at the top in the 'grandchildren' layer of the hierarchy. At the moment, at each uncollapse, the newly inserted children always just display at the bottom, e.g. if I uncollapse the eldest child their children display, then uncollapse the second-eldest child their children show below the eldest child's children, then collapsing the eldest child leaves just the second-eldest child's children, but uncollapsing the eldest child now displays their children below the second-eldest child's children

NB: first thing I did was change y_sep to -50 instead of 50, to get the children sorting eldest-to-youngest (reading top to bottom) instead of the other way around.

Rendering Issue when Clicking Rapidly

First, thank you for this interesting project!

While testing the example code, I found that I can consistently produce a couple visual glitches while clicking on the same node twice within transition_duration. The most common issue - nodes and their labels disappearing when clicking a node as its children are being hidden - can be seen below, produced on both your githack link and my own fork of the repository:
image

I have implemented a couple of exploratory workarounds for this in my own fork at bniedzie@6331114 - speeding up the transitions and preventing click() from firing often enough to cause the problem seems to avoid the above issue. Neither seems particularly elegant, but it has resolved the problem for me.

I have also found that repeatedly clicking the same node causes the view to gradually zoom in, despite the above change.

Thanks in advance for any thoughts you might have on this!

Can it be used in a react or vue framework?

Tried importing familyTree.js in a react project and it throws below error:

Error in /~/familyTree.js (129:25)
Class extends value undefined is not a constructor or null

It seems there is a circular reference and not allowing to run the FamilyTree class instances.

Sample code:

`import * as React from 'react';
import './style.css';
import {FamilyTree} from './familyTree.js';
import { data } from './data.js';
import * as d3 from 'd3';

const svg = d3
.select("body")
.append("svg")

let FT = new FamilyTree(data, svg);

export default function App() {
svg
.attr("width", document.body.offsetWidth)
.attr("height", document.documentElement.clientHeight);

// make family tree object

// draw family tree
FT.draw();

return (


Hello StackBlitz!


Start editing to see some magic happen :)



);
}
`

Can someone help?

Cannot set property 'points' of undefined

Hi @BenPortner,
I really like your work and I am trying to implement it!

I am using this data set:

data = {
    "persons": {
        "id2": {
            "id": "id2",
            "own_unions": ["u2"],
            "parent_union": "u1",
            "name": "item01",
            "birthyear": 1900,
            "deathyear": 1980,
        },
        "id1": {
            "id": "id1",
            "own_unions": ["u1"],
            "name": "item00",
            "birthyear": 1901,
            "deathyear": 1985,
        },
        "id4": {
            "id": "id4",
            "own_unions": ["u4"],
            "parent_union": "u3",
            "name": "item02",
            "birthyear": 1926,
            "deathyear": 2009,
        },
        "id3": {
            "id": "id3",
            "own_unions": ["u3"],
            "parent_union": "u2",
            "name": "topic00",
            "birthyear": 1902,
            "deathyear": 1970,
        },
        "id6": {
            "id": "id6",
            "own_unions": [],
            "parent_union": "u4",
            "name": "item04",
            "birthyear": 1931,
            "deathyear": 2015,
        },
        "id5": {
            "id": "id5",
            "own_unions": ["u4"],
            "parent_union": "u3",
            "name": "item03",
            "birthyear": 1930,
            "deathyear": 2010,
        },
    },
    "unions": {
        "u1": {
            "id": "u1",
            "partner": ["id1"],
            "children": ["id2"]
        },
        "u2": {
            "id": "u2",
            "partner": ["id2"],
            "children": ["id3"]
        },
        "u3": {
            "id": "u3",
            "partner": ["id3"],
            "children": ["id4", "id5"]
        },
        "u4": {
            "id": "u4",
            "partner": ["id4", "id5"],
            "children": ["id6"]
        },
    },
    "links": [
        ["id1", "u1"],
        ["u1", "id2"],
        ["id2", "u2"],
        ["u2", "id3"],
        ["id3", "u3"],
        ["u3", "id4"],
        ["u3", "id5"],
        ["id4", "u4"],
        ["id5", "u4"],
        ["u4", "id6"],
    ]
};

But i encounter the error:

Uncaught TypeError: Cannot set property 'points' of undefined
    at d3-dag.min.js:2
    at Array.map (<anonymous>)
    at d3-dag.min.js:2
    at B.each (d3-dag.min.js:2)
    at d3-dag.min.js:2
    at l (d3-dag.min.js:2)
    at update (..)
    at SVGGElement.click (..)
    at SVGGElement.<anonymous> (d3.min.js:2)

Why does this error happen?

Thanks in advance.

"Maximum call stack exceeded" error

Ben,
Thanks for the work on this family tree it's much appreciated. I've been building my own family tree using your software. It goes back 7 generations. However, I have stumbled on a bug with the code that specifically relates to inter family marriages. I have a situation where two first cousins have married and so have a union between them. When I initially expand the nodes it displays correctly. When I collapse the node and attempt to re-expand the link. The screen just freezes for about 10 seconds. When I then attempt to expand any other nodes i get the same behaviour. I've included chrome development mode screenshots that highlight the issue and offending code.
Thanks again,
Anthony
1
2
3

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.