npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-d3-tree-editor

v3.1.4

Published

D3 tree component for React

Downloads

45

Readme

react-d3-tree-editor

React d3 editor is a d3 tree based editor, fully featured with context menu support. You can dynamicly edit, create and delete chiled nodes. nodes are based on icons you provide for styling.

NPM JavaScript Style Guide

Contents

Demo

  • Find a demo on https://naihan.github.io/react-d3-tree-editor/

Install

npm install --save react-d3-tree-editor

Basic Usage

import React, { Component } from 'react'
import TreeEditor from 'react-d3-tree-editor'

export default class App extends Component {

  constructor() {
    
    //the actual tree data
    this.treeData = {
        name: 'Root Node',
        
        children: [{
            name: 'new node'
            
        }, {
            name: 'new node'
        }]
    }

    //the d3 tree config 
    this.treeConfig = {
      margin: {
        top: 20,
        right: 120,
        bottom: 20,
        left: 120
      },
      textMargin: 20,
      duration: 750,
      nodeSize: [40, 70]
    }
  }
  render() {
    return (
      return (
        <TreeEditor treeData={this.treeData}
            treeConfig={this.treeConfig}/>
        )
    )
  }
}

Fully Featured Usage

  class App extends React.Component {

      constructor(props) {
          super(props);
          
          this.treeRef = null;

          this.treeData = {
              //the actual data
              name: 'Root Node',
            
              children: [{
                  name: 'new node'
                  
              }, {
                  name: 'new node'
              }]
          }
          this.treeConfig = {
              //the d3 tree config 
              margin: {
                  top: 20,
                  right: 120,
                  bottom: 20,
                  left: 120
              },
              textMargin: 20,
              duration: 750,
              nodeSize: [40, 70]
          }
      }

      filterTextName = (d) => {
          //will be fired for each element once to decide which propery be used to display the name 
          return d.name;
      }


      contextMenuOpen = (d) => {
          console.log('contextMenuOpen');
          //will be fired when context menu opended
      }

      contextMenuClose = (d) => {
          console.log('contextMenuClose');
          //will be fired when context menu closed
      }

      selectImageLink = (d) => {
          //will be fired once for each element to decide the icon for that element
          return "http://mojedelo.webfactional.com/img/ikone/mdikona4.png"
      }

      getContextMenu = (e) => {
          //will be fired on each element for attaching a context menu
          return [{
                  title: 'Add Item',
                  action: () => {
                      this.treeRef.addNode(e, {
                          name: 'new node'
                      })
                  },
                  enabled: true
              },
              {
                  title: 'Delete Item',
                  action: (e) => {
                      this.treeRef.removeNode(e);
                  },
                  enabled: true
              },
              {
                  title: 'Delete Children',
                  action: () => {
                      this.treeRef.removeChildren(e);
                  },
                  enabled: true
              },
              {
                  title: 'Expand All',
                  action: () => {
                      this.treeRef.expandAllElements(e);
                      this.treeRef.update(e);
                  },
                  enabled: true
              },
              {
                  title: 'Collapse All',
                  action: () => {
                      this.treeRef.collapseAllElements(e);
                      this.treeRef.update(e);
                  },
                  enabled: true
              },

          ];
      }

      treeRenderedCallback = (d) => {
          console.log('treeRenderedCallback');
          //will be fired when tree finish render
      }
      render() {
          return (
          <TreeEditor treeData={this.treeData}
              treeConfig={this.treeConfig}
              onRef={ref => (this.treeRef=ref)}
              filterTextName={this.filterTextName}
              contextMenuOpen={this.contextMenuOpen}
              contextMenuClose={this.contextMenuClose}
              selectImageLink={this.selectImageLink}
              getContextMenu={this.getContextMenu}
              treeRenderedCallback={this.treeRenderedCallback}/>
          )
      }
  }

Props

|Prop name|Mandatory|DefaultValue|Description| |:-|:-:|:--------:|:-| |treeData|true|N/A|The actual d3.tree data. you can append any data to a node and it will be avalable. Each child node should be a part of node.children array. Nodes contain an 'id' attribute which you can either manage by yourself or let the tree manage it automaticly. |treeConfig| true|N/A| The d3 tree configuration |onRef|false|N/A|executed when the tree is first generated, the purpose of this callbact is to give the developer the tree referance for lated use |filterTextName|false|name|will be fired for each element once to decide which attribute be used to display the name of the element. If not implemented, the tree will assume that the 'name' attribute will be used |contextMenuOpen|false|N/A|will be fired when context menu opended |contextMenuClose|false|N/A|will be fired when context menu closed |selectImageLink|false|N/A|will be fired once for each element to decide the icon for that element.If not specified a default image will be presented. |getContextMenu|false|N/A|will be fired on each element for attaching a context menu, see Context Menu for details |treeRenderedCallback|false|N/A|Will be fired when tree finish render |treeNodeAction|false|N/A|will executed every time tree action occurred #Context Menu

Context menu is an object array that each object consist of the following properties

  • title: the title of the option that will be displayed
  • enabled: (bool) will it be enabled or not.
  • action: the action that will be executed on the tree node
    [
      {
        title: 'Collapse All',
        action: () => {
            this.treeRef.collapseAllElements(e);
            this.treeRef.update(e);
        },
        enabled: true
      }
    ]

License

MIT © https://github.com/Naihan/react-d3-tree-editor