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 🙏

© 2026 – Pkg Stats / Ryan Hefner

squarified

v1.0.0

Published

squarified tree map

Readme

Squarified

A minimal and powerful treemap visualization library for creating interactive hierarchical data visualizations.

Features

  • 🚀 Lightweight: Minimal bundle size with maximum performance
  • 🎨 Customizable: Rich theming and styling options
  • 🔌 Plugin System: Extensible architecture with built-in plugins
  • 📱 Responsive: Automatic resizing
  • Interactive: Built-in zoom, drag, highlight, and menu interactions
  • 🎯 TypeScript: Full type safety and excellent DX

Installation

npm install squarified
# or
yarn add squarified
# or
pnpm add squarified

Quick Start

import { c2m, createTreemap, sortChildrenByKey } from 'squarified'

// Create a treemap instance
const treemap = createTreemap({
  plugins: [
    // Add built-in plugins for interactions
  ]
})

// Initialize with a DOM element
const container = document.querySelector('#treemap-container')
treemap.init(container)

// Set your data
treemap.setOptions({
  data: [
    {
      id: 'root',
      label: 'Root',
      weight: 100,
      groups: [
        { id: 'child1', label: 'Child 1', weight: 60 },
        { id: 'child2', label: 'Child 2', weight: 40 }
      ]
    }
  ]
})

Complete Example

import {
  c2m,
  createTreemap,
  presetColorPlugin,
  presetDragElementPlugin,
  presetHighlightPlugin,
  presetMenuPlugin,
  presetScalePlugin,
  presetZoomablePlugin,
  sortChildrenByKey
} from 'squarified'

// Create treemap with plugins
const treemap = createTreemap({
  plugins: [
    presetColorPlugin,
    presetZoomablePlugin,
    presetHighlightPlugin,
    presetDragElementPlugin,
    presetScalePlugin(),
    presetMenuPlugin({
      style: {
        borderRadius: '5px',
        padding: '6px 12px',
        backgroundColor: 'rgba(0, 0, 0, 0.8)',
        color: 'white',
        cursor: 'pointer',
        userSelect: 'none'
      },
      render: () => [
        { html: '<span>🔍 Zoom In</span>', action: 'zoom' },
        { html: '<span>🔄 Reset</span>', action: 'reset' }
      ],
      onClick(action, module) {
        switch (action) {
          case 'zoom':
            if (module?.node.id) {
              treemap.zoom(module.node.id)
            }
            break
          case 'reset':
            treemap.resize()
            break
        }
      }
    })
  ]
})

// Convert and prepare data
async function loadData() {
  const response = await fetch('/api/data')
  const rawData = await response.json()

  // Transform data structure
  const convertedData = rawData.map((item) => ({
    ...item,
    groups: item.children?.map((child) => convertChildrenToGroups(child))
  }))

  // Convert to treemap format and sort
  const treemapData = sortChildrenByKey(
    convertedData.map((item) =>
      c2m(item, 'value', (d) => ({
        ...d,
        id: d.path,
        label: d.name
      }))
    ),
    'weight'
  )

  return treemapData
}

// Initialize
const container = document.querySelector('#app')
treemap.init(container)

// Load and set data
loadData().then((data) => {
  treemap.setOptions({ data })
})

// Handle events
treemap.on('click', (event, module) => {
  console.log('Clicked:', module?.node)
})

// Auto-resize on container changes
new ResizeObserver(() => {
  treemap.resize()
}).observe(container)

API Reference

Creating a Treemap

createTreemap(options?)

Creates a new treemap instance.

interface CreateTreemapOptions {
  plugins?: Plugin[]
}

Instance Methods

init(element: HTMLElement)

Initialize the treemap with a DOM container.

setOptions(options: TreemapOptions)

Update treemap configuration and data.

resize()

Manually trigger a resize recalculation.

on(event: string, handler: Function)

Subscribe to treemap events.

dispose()

Clean up the treemap instance.

Data Format

interface TreemapNode {
  id: string
  label: string
  weight: number
  groups?: TreemapNode[]
  // Custom properties...
}

Utility Functions

c2m(data, weightKey, transform?)

Convert hierarchical data to treemap format.

sortChildrenByKey(data, key)

Sort treemap nodes by a specific key.

Built-in Plugins

  • presetColorPlugin: Automatic color assignment
  • presetZoomablePlugin: Zoom interactions
  • presetHighlightPlugin: Hover highlighting
  • presetDragElementPlugin: Drag interactions
  • presetScalePlugin: Scaling controls
  • presetMenuPlugin: Context menus

Browser Support

  • Chrome/Edge 80+
  • Firefox 75+
  • Safari 13+

Performance

Squarified is optimized for performance with:

  • Canvas-based rendering
  • Efficient layout algorithms
  • Smart redraw optimizations
  • Memory-conscious design

Contributing

Contributions are welcome! Please read our contributing guide for details.

License

MIT

Auth

Kanno

Credits

Algorithm ported from esbuild Bundle Size Analyzer by Evan Wallace, refactored and optimized for general-purpose treemap visualization.