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

@memberjunction/ng-word-cloud

v5.37.0

Published

MemberJunction: Reusable SVG-based word cloud component for Angular.

Readme

@memberjunction/ng-word-cloud

A reusable, SVG-based word cloud component for Angular. Renders weighted text items in a spiral or rectangular layout with collision detection. Supports multiple color modes using MJ design tokens, optional entry animation, and click/hover interaction.

Installation

npm install @memberjunction/ng-word-cloud

Usage

The component is standalone and can be imported directly:

import { MJWordCloudComponent } from '@memberjunction/ng-word-cloud';

@Component({
    imports: [MJWordCloudComponent],
    template: `
        <mj-word-cloud
            [Items]="Words"
            [MaxFontSize]="56"
            ColorMode="categorical"
            (ItemClick)="OnWordClick($event)">
        </mj-word-cloud>
    `
})
export class MyComponent {
    Words: WordCloudItem[] = [
        { Text: 'Machine Learning', Weight: 1.0 },
        { Text: 'Data Science', Weight: 0.8, Category: 'analytics' },
        { Text: 'Neural Networks', Weight: 0.6, Category: 'ai' },
    ];

    OnWordClick(event: WordCloudItemEvent): void {
        console.log('Clicked:', event.Item.Text);
    }
}

Component API

Selector

mj-word-cloud

Inputs

| Input | Type | Default | Description | |-------|------|---------|-------------| | Items | WordCloudItem[] | [] | Data items to display in the cloud | | MinFontSize | number | 12 | Minimum font size in pixels for the lowest-weighted item | | MaxFontSize | number | 48 | Maximum font size in pixels for the highest-weighted item | | Layout | 'spiral' \| 'rectangular' | 'spiral' | Layout algorithm for word placement | | ColorMode | 'brand' \| 'categorical' \| 'weight-gradient' | 'brand' | How colors are assigned to words (see Color Modes below) | | Interactive | boolean | true | Whether words are clickable and hoverable | | MaxItems | number | 100 | Maximum number of items to display (heaviest items are kept) | | Animate | boolean | true | Whether to animate words in with a staggered fade |

Outputs

| Output | Type | Description | |--------|------|-------------| | ItemClick | EventEmitter<WordCloudItemEvent> | Emitted when a word is clicked | | ItemHover | EventEmitter<WordCloudItemEvent> | Emitted when the pointer enters a word | | ItemLeave | EventEmitter<WordCloudItemEvent> | Emitted when the pointer leaves a word |

Types

WordCloudItem

interface WordCloudItem {
    Text: string;                           // Display text
    Weight: number;                         // Importance (0.0 - 1.0), determines font size
    Category?: string;                      // Optional category for color grouping
    Metadata?: Record<string, unknown>;     // Optional metadata passed through events
}

WordCloudItemEvent

interface WordCloudItemEvent {
    Item: WordCloudItem;    // The item that was interacted with
    Event: MouseEvent;      // The original DOM event
}

Color Modes

brand

All words use --mj-brand-primary. Opacity varies with weight (range 0.4--1.0), giving higher-weighted words more visual prominence.

categorical

Words with the same Category share a color from a fixed palette of MJ design tokens: --mj-brand-primary, --mj-status-success, --mj-status-warning, --mj-status-error, --mj-status-info, and others. Words without a Category each get their own color.

weight-gradient

Interpolates between --mj-text-muted (low weight) and --mj-brand-primary (high weight) using color-mix(). Provides a smooth gradient that adapts to both light and dark themes.

Rendering Approach

The component renders entirely in SVG using an <svg> element with a computed viewBox and preserveAspectRatio="xMidYMid meet" so the cloud scales to fill its container.

Layout Algorithm

  1. Items are sorted by weight (heaviest first) and trimmed to MaxItems.
  2. For each item, the engine computes a font size by linear interpolation between MinFontSize and MaxFontSize based on weight.
  3. Roughly 20% of words are rotated 90 degrees for visual variety (deterministic based on index).
  4. The engine generates candidate positions using the selected algorithm:
    • Spiral -- Archimedean spiral expanding from the center.
    • Rectangular -- concentric rectangular rings expanding from the center.
  5. For each candidate position, an axis-aligned bounding box is computed (accounting for rotation) and tested against all previously placed items.
  6. The first non-colliding position is accepted. If no position is found after 500 attempts, the word is skipped.
  7. The overall SVG viewBox is computed to fit all placed items with 20px padding.

Text width is estimated using an average character width ratio of 0.6x the font size (no DOM measurement required), making the layout engine fully deterministic and SSR-compatible.

Design Token Compliance

All colors use MJ semantic design tokens exclusively. No hardcoded hex values are used in the component's styles or color logic. The component adapts automatically to light and dark themes via the --mj-* CSS custom properties.

Tokens used:

  • --mj-brand-primary, --mj-brand-primary-hover -- brand color mode
  • --mj-status-success, --mj-status-warning, --mj-status-error, --mj-status-info -- categorical palette
  • --mj-text-muted -- weight-gradient low end
  • --mj-font-family -- inherited font family

Change Detection

The component uses ChangeDetectionStrategy.OnPush for performance. The layout is recomputed whenever any @Input changes (via ngOnChanges).