Code Monkey home page Code Monkey logo

adhavocbinarytree's Introduction

AdHavocBinaryTree

Javascript library for drawing nice binary trees

I found that I needed to display a binary tree nicely and didn't like the options out there. I came up with an algorithm to display them, but I also wanted to tell others how I did it. And I wanted it to look nice too. So I added some animation in as well.

To use this:

Download the latest copy of velocity. It can be found at http://velocityjs.org, but the actual file should be here: https://raw.githubusercontent.com/julianshapiro/velocity/master/velocity.min.js

In the of your HTML page, include this:

<script src='velocity.min.js'></script>
<script src="AdHavocBinaryTree.js"></script>
<link rel="stylesheet" type="text/css" media="screen" href="AdHavocBinaryTree.css" />

Set your tree in the body with an SVG like this:

<svg id="exampleSvg" xmlns="http://www.w3.org/2000/svg" version="1.1" width="1000px" height="1000px" preserveAspectRatio="xMinYMin meet"></svg>

Initialize the tree with some data using javascript like this:

var treeText ="<root startNode=\"1\"><node id=\"1\" left=\"2\" right=\"3\"/><node id=\"2\"/><node id=\"3\"/></root>"
var tree = AdHavocBinaryTree.createTreeFromXml(treeText, document.getElementById("exampleSvg"));

adhavocbinarytree's People

Contributors

adhavoc avatar

Stargazers

Narendra Pathai avatar

Watchers

 avatar

Forkers

slothy

adhavocbinarytree's Issues

No nullity checked for left and right children

In many places of your code, you did not check if the left or right child is null. You only used .IsLeaf() to check for the case where both children are null, but not for the case when only one of them is.

Your demo is still working without problem because in your trees, every node has no child or two children.

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.