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

decision-tree-builder

v0.2.6

Published

A tool to build data classification rules using visual flowchart-style decision tree

Downloads

5

Readme

decision-tree-builder NPM version NPM Downloads

A tool to build data classification rules using visual flowchart-style decision tree. Uses d3.js v4 for SVG drawing.

Screenshot

terminology / concepts

  • Property: a (data) attribute being evaluated as part a decision (e.g. Property: "animal")
  • Value: a value being used in a conditional statement to evaluate a property (e.g. does Property "animal" equal the Value "cat")
  • Operator: the logical operator used to evaluate a properties value (e.g. "equals", "less than" etc.)
  • Condition: the logical operator (AND/OR) used to evaluate decisions that have more than one rule, e.g. rule1 AND rule2.
  • Decision: a conditional operation determining which of two paths the program will take
  • Result Node: aka a leaf node, represents the final result when an input is evaluated by the decision tree
  • TreeSchema: the JSON serialised representation of a decision tree
  • DataSchema: the actual things/options that may be used to define a tree (the Properties, Values, and Operators that are available - this is not handled by this tool, user defined).

notes

  • You should not directly modify the node object that is broadcast with the nodeClick event as this may cause issues with d3's internal data structure. You should instead use cloneAndStripNode or similar to get a distinct copy of the nodes values.
  • Decision nodes are if/else binary decision only, the data is structured such that the two children of a decision [0,1], are in a meaningful array order, i.e.
    • the child at 0 index represents a false decision outcome
    • the child at 1 index represents a true decision outcome
    • so; when we query the tree as well as getting a result/leaf node, we also get a binary representation of the path, i.e.
      • 0110 indicates four decisions were taken to reach a result => false, true, true, false
  • We do not provide any validation of decision tree conditional logic (it is distinct from the tree data structure... well more accurately the decision logic is simply stored as tree node metadata).
    • for example; you could make a change to a parent node which renders its children completely redundant, and it will still be valid (children won't be auto pruned, do it yourself man).

example use

Initialise with data and options:

let options = {
	layout: {
		divId: "tree-panel",
		svgWidth: 1200,
		svgHeight: 1000,
		svgMargin: {
			top: 20,
			right: 90,
			bottom: 30,
			left: 90
		},
		nodeWidth: 250,
		nodeHeight: 250,
		nodeMargin: {
			x: 100,
			y: 250
		},
		zoomScale: [-1, 100],
		transitionDuration: 750
	},
	// defined for use with `queryDecisionTree` example
	operatorFunctions: {
        equal: function(a, b){
            return new Promise((resolve, reject) => {
                resolve(a == b);
            });
        }
    }
};

let myBuilder = new DecisionTreeBuilder(treeData, options); // see demo for expected data format

Then listen for nodeClick events, you will be passed the target node in the event detail:

window.addEventListener('nodeClick', function (e) {

	var node = e.detail;
	// perform action with the node..

});

You can optionally color stroke of nodes and links based on their truthy/falsey status, see demo.css for example.

core methods

  • addChildNodes(node, newNodesData)
  • updateDecisionNodeData(node, newData)
  • pruneNode(node)
  • serialiseTreeToJSON()
  • queryDecisionTree(target) // returns the value of resulting leaf node, and a binary path to the result.
  • setHighlighted(node, ignoreToggleState)
  • fitBounds(paddingPercent, transitionDuration)
  • adjustBounds(offset)
  • destroy()

See demo.js for example.

shout outs / other tools

license

The MIT License (MIT)