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

@d3-composer/grid

v0.8.0

Published

CSS grid layout for SVG and Canvas

Downloads

60

Readme

@d3-composer/grid

Example

import { template } from '@d3-composer/grid';

const grid = template(`
  "title title" 50
  "y_axis chart" auto
  ". x_axis" 50
  / 50 auto
`, { width: 600, height: 400 });

// grid = {
//   areas: {
//     title: {
//       x: 0, y: 0, width: 600, height: 50,
//       top: 0, right: 600, bottom: 50, left: 0
//     },
//     y_axis: { x: 0, y: 50, width: 50, height: 300 },
//     chart: { x: 50, y: 50, width: 550, height: 300 },
//     x_axis: { x: 50, y: 350, width: 550, height: 50 }
//   },
//   rows: [[0, 50], [50, 350], [350, 400]]
//   columns: [[0, 50], [50, 600]]
//   items: [
//     { x: 0, y: 0, ...}
//     ...items correspond to each grid position
//        from left-to-right, top-to-bottom
//        (6 in this example)
//   ]
// }

API

# template(spec, options)

Create grid calculation from grid-template specification. spec should follow the grid-template format (see A Complete Guide To Grid or MDN grid-template), although it is a simplified approach with the following rules:

spec

grid-template spec string or object with rows, columns, and [areas].

options

  • width - Overall width
  • height - Overall height
  • [gap] - Gap between each row and column
  • [row_gap] - Gap between each row (unitless value, e.g. 20)
  • [column_gap] - Gap between each column (unitless value, e.g. 30)
  • [padding] - Number, object, or array of padding from outer width/height and grid items

Notes:

  • Fixed values should not include a unit (e.g. 20 instead of 20px)
  • "auto" does not behave according to CSS Grid spec and is instead treated like 1fr in all cases
// chart with 50-unit high title
const grid = template(`
  "title" 50
  "chart" auto
  / auto
`, { width, height })

// chart with y-axis (25-unit width) and y-axis title (25-unit width)
const grid = template(`
  "y_title y_axis chart" auto
  / 25 25 auto
`, { width, height })

// chart with outer padding ([top, right, bottom, left])
const grid = template(
  `"chart" auto / auto`,
  { width, height, padding: [20, 40, 20, 40] }
);

// | title    (title)  (title) | 50
// | y_axis | chart  | legend  | auto
// | .      | x_axis | .       | 25
//   25       auto     100
const grid = template(`
  "title  title  title " 50
  "y_axis chart  legend" auto
  ".      x_axis .     " 25
  / 25    auto   100
`, { width, height });

// Grid template with row and column sizing
const grid = template(
  { rows: '50 auto 25', columns: '25 auto 100' },
  { width, height }
);

// equivalent to:

const grid = template(`50 auto 25 / 25 auto 100`, { width, height });

// repeat and minmax are supported

const grid = template(`repeat(4, 1fr) / minmax(100, 0.5fr) 1fr`, { width, height });