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

table-packer

v1.0.0

Published

A simple, pure JS UI layout library for HTML5 canvas and non browser based

Downloads

4

Readme

table-packer

A simple, pure JS UI layout library for HTML5 canvas and non browser based JavaScript. It's great if you're using JavaScript as a scripting engine in a game, and you want it to run on multiple platforms.

##Documentation ###Creating a new table

    var table = new TablePacker(xPos, yPos, width, height);

Where xPos and yPos represent the top-left corner of the table.

###Adding things

To add an item to the table, use the add method.

    table.add(myItem);

You can set horizontal alignments using the left and right functions. You can also set the margin to one value on all sides using the margin function with one parameter. The below snippet aligns left with 10 margin.

    table.add(myItem).margin(10).left();

You can also set individual margins. Valid margin sides are "left", "right", "top" and "bottom".

    table.add(myItem).margin("left", 10);

The row function completes the current row and starts a new one. The height of a row is is the height of the highest item including margins. If the current row is epty, the row function returns it.

    table.row();

The row function also returns a row object. You can set the margins and alignments on rows just like cells. (Valid values for alignments are "top", "bottom" and "center".) .You can also add cells to rows after advancing to the next row. To do this, you need to pass in a cell object, not just your item. If the item does not fit, it will ignore your overflowPolicy setting and do something similar to to SQUASH policy. For example, in this snippet, we add an item to a row that is already completed.

    var row = table.row();
    table.add(myItem1);
    row.add(new TablePacker.Cell(table, myItem2);

###Laying out items

Once you've added everything to the table, call layout. It updates the position of each element.

    table.layout();

###Setting default values

The TablePacker.defaults object describes default settings. As well as default margins and alignments, it contains accessor functions that are used to get and set the x, y, height and width values. You can change them to suit your own data structures.

    TablePacker.defaults.align = "center";
    TablePacker.defaults.margin = 0;
    TablePacker.defaults.rowMargin = 10;
    TablePacker.defaults.rowAlign = "top";
    TablePacker.defaults.getX = function (o) { return o.position.x; };
    TablePacker.defaults.getY = function (o) { return o.position.y; };
    TablePacker.defaults.setX = function (o, x) { o.position.x = x; };
    TablePacker.defaults.setY = function (o, y) { o.position.y = y; };
    TablePacker.defaults.getWidth = function (o)  { return o.width; };
    TablePacker.defaults.getHeight = function (o) { return o.height;};
    TablePacker.defaults.overflowPolicy = TablePacker.OVERFLOW_POLICY.NEW_ROW;

The TablePacker.defaults.overflowPolicy descibes what happens when there is no more room in the table. Valid values are:

  • EXCEPTION: Throws an exception when there is no more room in the table.
  • SQUISH: Don't care about overflows.
  • DISCARD: Ignore insersions that don't fit.
  • NEW_ROW (default): Create a new row when the current row is full.

###Other things

The each method is calls a function for each item in the table.

    table.each(function(item) { /* Do stuff with item */ });

The setBounds method can resize the table.

    table.setBounds(xPos, yPos, width, height);

###TODO list:

  • Tests
  • Better demo
  • Better overflow policies