
Product
Introducing GitHub Actions Scanning Support
Detect malware, unsafe data flows, and license issues in GitHub Actions with Socket’s new workflow scanning support.
squarified
Advanced tools
A minimal and powerful treemap visualization library for creating interactive hierarchical data visualizations.
npm install squarified
# or
yarn add squarified
# or
pnpm add squarified
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 }
]
}
]
})
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)
createTreemap(options?)Creates a new treemap instance.
interface CreateTreemapOptions {
plugins?: Plugin[]
}
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.
interface TreemapNode {
id: string
label: string
weight: number
groups?: TreemapNode[]
// Custom properties...
}
c2m(data, weightKey, transform?)Convert hierarchical data to treemap format.
sortChildrenByKey(data, key)Sort treemap nodes by a specific key.
Squarified is optimized for performance with:
Contributions are welcome! Please read our contributing guide for details.
Kanno
Algorithm ported from esbuild Bundle Size Analyzer by Evan Wallace, refactored and optimized for general-purpose treemap visualization.
1.0.0
First stable release.
FAQs
squarified tree map
We found that squarified demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Detect malware, unsafe data flows, and license issues in GitHub Actions with Socket’s new workflow scanning support.

Product
Add real-time Socket webhook events to your workflows to automatically receive pull request scan results and security alerts in real time.

Research
The Socket Threat Research Team uncovered malicious NuGet packages typosquatting the popular Nethereum project to steal wallet keys.