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

grid-model

v0.0.2

Published

This project is a simple library to model a grid and access information about the cells within it.

Downloads

2

Readme

Grid Model Logo

Grid Model

Grid Model is a simple library to model a grid and access information about the cells within it.

Quickstart

Docs

View the docs in your default browser using:

yarn run docs

Build

The project is built using rollup using the config file rollup.config.js. It is transpiled using babel.

yarn run build

Test

Test the project using jest

yarn run test

Release

Bump the version (patch, minor, major, prepatch, preminor, premajor, prerelease)

npm version patch -m "Bump version to  %s"

Publish to NPM:

npm publish

Elements Of A Grid

Diagram of grid

Usage

This library contains a few objects you need to understand.

  • grid represents a series of cells aranged in rows and columns.
  • point represents a point in 2D space within the grid.
  • dimensions represents an area in 2D space within the grid.
  • region represents location and dimensions of a part of the grid encompassing one or more cells.

In the event that you supply parameters that can't be reconciled into a valid grid, it will error. It will not be able to reconcile the params if:

  • You don't give it enough information about the grid
  • You give it conflicting params that can't be reconciled.

For example, if you just supply a width and height, there is no way it can know how many rows and columns you want, but if you supply a cellWidth and a cellHeight alongside, it can calculate the number of rows, columns and gutters for a valid grid. An example of conflicting params would be if you supplied width, columns and cellWidth which didn't correlate, for example if the width was 100, columns was 10 and cellWidth was 20. In this instance you could drop the width and let it be calculated from the columns and cellWidth, drop the columns and let it be calculated from the width and cellWidth or drop the cellWidth and let it be calculated from the width and columns.

Note: The numeric values for width height, cellWidth, cellHeight, gutterWidth and gutterHeight are unitless. The do not represent any specific unit of measurement like cm or px. It is up to you to either use values that reflect whatever units you are using in your layout, or convert the values of the grid as needed.

Example

For this example we'll use a 6 * 8 grid with a 3:4 aspect ratio with even gutters and (almost) square cells:

Create a grid:

const grid = createGrid({
  width: 400,
  height: 300,
  columns: 6,
  rows: 8,
  gutter: 6
})

Retrieve basic information about the grid. Note: for most properties you can either use the property name directly or access through a dimensions object.

Dimensions

The grid's dimensions are its total height and total width.

grid.width // 400
grid.height // 300
grid.aspectRatio // 0.75
grid.dimensions.width // 400
grid.dimensions.height // 300
grid.dimensions.aspectRatio // 0.75

Matrix Dimensions

The grid's matrix dimensions are the number of columns and cells it has.

grid.columns // 6
grid.rows // 8
grid.matrix.width // 6
grid.matrix.height // 8

Cell Dimensions

The grid's cell dimensions are the with and height of the cells within it. All cells in a grid have the same width and height.

grid.cellWidth // 40
grid.cellHeight // 39.5
grid.cellDimensions.width // 40
grid.cellDimensions.height // 39.5

Gutter Dimensions

The grid's gutter dimensions are the with and height of the gutters throughout the grid. Gutters are the spaces between the cells. The width of the gutters represents the space between columns and the height of the gutters represents the space between rows.

grid.gutterWidth // 3
grid.gutterHeight // 3
grid.cellDimensions.width // 3
grid.cellDimensions.height // 3

Each of the dimensions objects also exposes an area property:

grid.dimensions.area // 120000
grid.matrix.area // 48

Retrieve the total number of cells in a grid.

grid.cellCount // 48

Individual Cells

You can retrieve information about a single cell in the grid using its column and row index.