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

boxjam

v0.0.21

Published

Take the boxes, and jam them in the bigger box

Downloads

1

Readme

boxjam

Make the little boxes fit inside the bigger box.

Description

This module was created as part of the Choirless project.

We needed a way to figure out how to fit n rectangles of varying dimensions into a set space so we could render a video wall of varying participant numbers without having to have preset spaces or dimensions for each case.

boxjam allows you to pass through a container size and a list of rectangles of varying sizes, and will proportionately scale and position those rectangles until they fit inside the container.

Usage

Installation

npm i -S boxjam

Example

const boxjam = require('boxjam');

const rectangles = [
    {id : 1, width : 640, height : 480 },
    {id : 2, width : 720, height : 480 },
    {id : 3, width : 200, height : 100},
    {id : 4, width : 300, height : 150 }
];

const container = { width : 1920, height : 1080 };
const margin = 10;
const shouldCenter = true

// Scaled and positioned rectangles
const adjustedRectangles = boxjam(rectangles, container, margin, shouldCenter);

console.log(adjustedRectangles);

/*
[
    { id: 1, width: 576, height: 432, x: 343, y: 103 },
    { id: 2, width: 648, height: 432, x: 929, y: 103 },
    { id: 3, width: 864, height: 432, x: 91, y: 545 },
    { id: 4, width: 864, height: 432, x: 965, y: 545 }
]
*/ 

boxjam Arguments

boxjam([RECTANGLES ARRAY], [CONTAINER OBJ], [MARGIN NUMBER], [SHOULD CENTER BOOL])

RECTANGLES

This is a list of objects which have width and height properties. The width and height properties should be integers, but will work with floats. Floats and integers will be rounded by the algorithm. The objects can have other properties passed (such as an ID) which will be returned along with the calculated values.

[ 
    {
        width : <NUMBER>,
        height : <NUMBER>
    },
    {
        width : <NUMBER>,
        height : <NUMBER>
    } 
]

CONTAINER

An object which contains height and width properties of the container you wish to fit the rectangles into.

{
    width : <NUMBER>
    height : <NUMBER>
}

MARGIN

Default: 0

If you wish to have a space between your rectangles, you can pass a number as the margin argument. This value is relative to the container dimensions and the spaces.

SHOULD CENTER

Default: false

If you wish to have the rectangles vertically and horizontally aligned within the container when the scaling and positioning has completed, you can pass true and the rectangles will be aligned. Otherise, they will align from the top left.