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

angular-treemendous

v0.2.4

Published

simple, flexible, angular tree with grouping

Downloads

4

Readme

angular-treemendous

Simple, flexible Angular tree with grouping.

Yes, another recursive tree directive.

Instead of providing a ton of features in one monolithic directive, angular-treemendous is very lightweight and modular - other sub-directives provide additional features like selection, asynchronous loading, etc.

Usage

Install with bower or npm.

$ bower install angular-treemendous or $ npm install angular-treemendous.

To include angular-treemendous, first load the script (or require it if you're using browserify).

<script src="bower_components/angular-treemendous/angular-treemendous.min.js"></script>

Then add the treemendous module as a dependency in your Angular code.

var myAppModule = angular.module('myApp', ['treemendous']);

This is very much a DIY directive, providing lots of flexibility by leaving the specifics up to you. angular-treemendous focuses on two core aspects of building a tree:

  • recursion
  • grouping

There are also sub-directives that add other features - so far:

  • tree-select
  • tree-expand (this allows async loading)

Recursion

Using the tree-branch directive within tree-mendous creates the recursive structure. tree-branch works a lot like ng-transclude, transcluding the markup contained in the tree-mendous directive - this is a recursive process, as tree-branch is itself transcluded.

At each level, the expression provided to the nodes attribute is evaluated and set as scope.nodes.

<tree-mendous nodes="collection">
  <div ng-repeat="item in nodes">
    <tree-branch nodes="item.children"></tree-branch>
  </div>
</tree-mendous>

<!-- this could be compiled into something like this: -->

<tree-mendous nodes="collection">
  <div ng-repeat="item in nodes">
    <tree-branch nodes="item.children">
      <div ng-repeat="item in nodes">
        <tree-branch nodes="item.children"></tree-branch>
      </div>
    </tree-branch>
  </div>
</tree-mendous>

Grouping

At the root tree-mendous level and in each tree-branch, the collection provided to the directive may be grouped according to a given property (which should be present on each item in that collection).

The groups are represented by new "intermediate" branches in the tree. The scope of these branches will contain a special scope.$intermediate property, set to true.

<tree-mendous nodes="collection group by type">
  <div ng-repeat="item in nodes">
    {{$intermediate === true}}
    <tree-branch nodes="item.children"></tree-branch>
  </div>
</tree-mendous>

This will create an intermediate branch for each distinct value of the type property found on items in collection. Grouping occurs at every level in the tree - this means that every other level will contain "intermediate" branches.

When groups are created they are given a property named by the "group by" clause - so, in this example, each group has a property called type. All the nodes in that level with the same type are then added to the group under the children property - unless a different property name is specified like so:

<tree-mendous nodes="collection group by type as someOtherName">
  <div ng-repeat="item in nodes">
    <tree-branch nodes="item.someOtherName"></tree-branch>
  </div>
</tree-mendous>

This is helpful if your data source uses a property other than children to name each node's children. Then tree-mendous will create groups that match your data source.

Selection

Add the tree-select directive to any element within the tree to enable selection, in the form of adding a $selected boolean to the surrounding scope.

tree-select may also be given a function, which is called each time its element is selected (i.e. every other single click). This function may return false to prevent the selection - or a promise which, if rejected or returns false, may also prevent the selection.

tree-mendous supports four different select modes:

  • none prevents any selection at all.
  • single allows only one scope to be selected at a time.
  • active allows only one selected scope, but multile $active scopes.
  • multi allows any number of scopes to be selected.

This is set on the tree-mendous directive like so:

<tree-mendous nodes="collection" select-mode="single">

Expansion

The tree-expand directive operates just like tree-select - it toggles a $expanded boolean on its scope. It may also be given a function that can return false (or a promise) to prevent the expansion.

That function may also be used to add asynchronous loading behavior. Take the following example:

<tree-mendous nodes="collection">
  <div ng-repeat="item in nodes" tree-expand="expandFn(item)">
    <tree-branch nodes="item.children" ng-show="$expanded"></tree-branch>
  </div>
</tree-mendous>

The expand function could run an async call (via $http or similar), use the result to set the item.children property, then return true to allow the expansion - setting $expanded to true and showing the next branch of the tree.

If tree-expand is used on the same element as tree-select, it will require a double-click to trigger.

Development

First, run npm install from the project directory to install dev dependencies.

This module uses Gulp to build:

$ gulp build

Karma - using Mocha and Chai - to test:

$ gulp test or $ npm test

And to watch files - linting, testing and building on changes:

$ gulp watch


© 2014 Weston Fribley

This software is MIT licensed - please see LICENCE for details.