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

botany

v0.0.2

Published

A library for making dynamic HTML tree-views that work with data binding and DOM manipulation

Downloads

15

Readme

Botany.js

Introduction

Botany is a JavaScript/CSS library for creating tree view components using declarative techniques. This means that, unlike imperative (but still very powerful) libraries like jsTree, botany trees can be built using the DOM templating of JavaScript frameworks like Angular, React etc., and adding or removing elements from the tree can be done without needing to tell the tree to update or redraw anything.

Demos

Have a look at a live demo here on GitHub Pages, or clone the repository and run the demo files.

Installation

Run npm install botany or git clone https://github.com/TMiguelT/botany to get the latest version of the library, then copy the contents of dist directory to your project (for example, you might put it in static/libs/botany). This directory includes the stylesheet (botany.css), the script (botany.js) and all the relevant image files (.svg)

Then you'll need to reference both the stylesheet and the script in your HTML. You'll also need to include jQuery because it's required by botany. Of course in a real website you'd put the scripts at the bottom of the page and the stylesheets in the <head>:

<link rel="stylesheet" href="static/libs/botany/botany.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script src="static/libs/botany/botany.min.js"></script>

Usage

To use botany, you first need to create an unordered list with the class botany, and give it a class indicating which theme to use (see themes for more information). For example, your list element might look like this:

<ul class="botany lines"></ul>

Then all you need to do is call $("selector").botany() on the list you just created. It may seem redundant to add the class and call a jQuery function but the class determines the styling of the list, meaning that the style won't suddenly change when you call the plugin. All the plugin does is setup the even handlers for opening and closing the nodes.

Themes

The themes (like lines) in the above example, are one of the following:

  • lines
  • no-lines
  • no-markers

Themes determine which images to use as the marker (indicating a node is open or closed), as well as the horizontal and vertical lines that make up the tree. The default three themes are pretty self explanatory, but if you want to write your own theme (use your own custom images), read the section on custom themes

Basic Customization

As shown in the demo files (have a look in the demo directory), a Botany tree consists of a <ul> element with the class botany. You can have any DOM structure inside this tree, but there are some things to note:

  • Any <ul> or <li> elements inside the .botany element will be styled.

  • The .open class indicates when a node is open, and can be manually added to nodes that you want to start open (by default nodes are closed). This class is also automatically toggled whenever a node is opened or closed by a user, so you can write your own custom styles based on this.

  • The .botany-open and .botany-closed classes are for manually specifying an open/closed indicator. Such an element should be a direct child of an <li> and these should only be used when using a theme that has no indicators itself (i.e. the no-markers theme). Have a look at the demo-bootstrap.html file for an example of using the .botany-open and .botany-closed classes.

Custom Themes

To create a custom theme for botany, all you need to do is add a .json file to the src/css/themes directory containing paths to the image files you want to use as the open and closed markers, and the vertical and horizontal lines. It's probably a good idea to use the existing json files as a template. Also note that you don't have to use SVGs as your images, you can use any image format that CSS supports (png, jpeg etc.)

Then, just add the name of that json file to the themesList variable in botany.styl. It currently looks like this:

themesList = "lines", "no-lines", "no-markers"

Adding a custom theme would make it more like this (if you had a my-theme.json file in the themes directory)

themesList = "lines", "no-lines", "no-markers", "my-theme"

Then, to re-create the stylesheet, just run gulp build, and the files in the dist directory will be rebuilt. Of course to do this you'll have to install the dev dependencies, so don't use the --production flag for npm install. You can also rebuild botany if you want to make any other changes to the main stylesheet (botany.styl) or the main script (script.js)

Contributions

If you like the project, please help make it better! At the moment the main things that need to be fixed before a 1.0.0 release are:

  • CSS improvements. The vertical lines have a few issues, like not reaching the top of the previous node, and sometimes overlapping with each other. CSS changes can be made to botany.styl in src/css.

  • Stylus improvements. In a lot of cases I may not be using the full power of stylus in the library. If you have more experience with stylus than me, feel free to simply the stylesheet and make a Pull Request.

  • Better and more themes. I'm not a graphics designed, so the SVGs I made are pretty basic (and boring). Some more markers would be a fantastic help to me.

  • Bug fixes and feature suggestions. I'm eager to hear how I can make botany work better for your use case. Just file an issue and I'll see what I can do.

Style

The only ideosyncracy with the coding style of botany is the use of braces in the stylus sheets. While braces are optional in .styl files, and aren't used in any of the example code for the Stylus library, I think it's a lot clearer to use braces to separate blocks, especially coming from a pure JavaScript/CSS background.