New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

treefun2

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

treefun2

Tree diagram generator

  • 2.0.13
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
decreased by-77.78%
Maintainers
1
Weekly downloads
 
Created
Source

treefun2

A tree diagram (SVG) generator. A modernized version of treefun, a tree builder that was delivered as a static JS file. This new version can be installed with NPM, is written in ES6 and has Typescript support.

Online demo https://treefun.appspot.com/

NPM package https://www.npmjs.com/package/treefun2

Blog article https://jimblackler.net/blog/?p=567

Simple tree image

Use in a node project

npm install treefun2

Browser example

This example generates and adds a diagram to the current document body.

const treefun2 = require('treefun2');

const tree = [{
  label: 'World',
  children: [{
    label: 'Europe',
    children: [{
      label: 'France',
    }, {
      label: 'Germany'
    }]
  }]
}];

treefun2.treeToDiagram(document, document.body, tree, {}, '');

Browser example with options and custom CSS

const treefun2 = require('treefun2');

const tree = [{
  label: 'World',
  children: [{
    label: 'Europe',
    children: [{
      label: 'France',
    }, {
      label: 'Germany'
    }]
  }]
}];

const options = {
  flipXY: false,
  width: 320,
  height: 450,
  labelLineSpacing: 15,
  labelPadding: 2,
  arrowHeadWidth: 5,
  arrowHeadHeight: 5,
  arrowsUp: false,
  minimumSiblingGap: 0.1,
  idealSiblingGap: 0.1,
  minimumCousinGap: 0.2,
  idealCousinGap: 1.2,
  levelsGap: 1.2,
  cornerRounding: 4,
  minimumDepth: 0,
  minimumBreadth: 0
};

const css = `
  text {
    text-anchor: middle;
    font-size: x-small;
  }
  
  rect {
    fill: ghostwhite;
    stroke: black;
    stroke-width: 0.3px;
  }
  
  line {
    stroke: black;
    opacity: 0.5;
    stroke-width: 0.3px;
  }
`;

treefun2.treeToDiagram(document, document.body, tree, options, css);

Server example

Diagrams can be generated in server-side code with the use of JSDOM. The below example creates a diagram and writes it to a file diagram.svg.

npm install jsdom
const fs = require('fs');
const jsdom = require('jsdom');
const treefun2 = require('treefun2');

const document = new jsdom.JSDOM().window.document;

const tree = [{
  label: 'World',
  children: [{
    label: 'Europe',
    children: [{
      label: 'France',
    }, {
      label: 'Germany'
    }]
  }]
}];

treefun2.treeToDiagram(document, document.body, tree, {}, '');
fs.writeFileSync('diagram.svg', document.body.innerHTML);

FAQs

Package last updated on 16 Mar 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc