New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

bubble-chart-js

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bubble-chart-js

bubbleChartJs is a lightweight, customizable JavaScript library for creating stacked bubble charts. It arranges bubbles based on their values, with the largest bubble positioned at the top and surrounding bubbles decreasing in size accordingly.

latest
Source
npmnpm
Version
2.1.3
Version published
Weekly downloads
587
54.07%
Maintainers
1
Weekly downloads
 
Created
Source

bubble-chart-js

A high-performance, fully configurable Bubble Chart library for high-density analytics dashboards.

Zero dependencies. Framework-agnostic. Ships as ESM, CJS, and UMD.

npm version npm downloads License: MIT

Demo

bubble-chart-js demo

View the Live Interactive Demo →

Features

  • Dual renderer — auto-selects Canvas (large datasets) or SVG (small datasets); override with render.mode
  • Physics & static layouts — force-directed physics simulation with fully tunable parameters, or instant static placement
  • Glass & flat themes — built-in visual themes with GPU-accelerated bloom and glow effects
  • Per-bubble customization — individual color, opacity, label, icon, and font overrides per data item
  • Live updates — call chart.update(newData) for smooth, reconciled transitions without re-initializing
  • Pluggable layer hooks — inject custom draw calls into any render layer (background, bubbles, text, overlay, …)
  • Event system — subscribe to bubble:click, bubble:hover, and more with a clean pub/sub API
  • Angular-ready — ships full TypeScript types; integrates seamlessly into Angular, React, Vue, or vanilla JS
  • Tiny footprint — zero runtime dependencies; tree-shakeable ESM build

Installation

npm install bubble-chart-js

CDN (no build step)

<script src="https://unpkg.com/bubble-chart-js/dist/bubbleChart.umd.js"></script>

Quick Start

Vanilla JavaScript / TypeScript

<!-- index.html -->
<div id="chart" style="width: 800px; height: 500px;"></div>
import { initializeChart } from "bubble-chart-js";

const chart = initializeChart({
  canvasContainerId: "chart",
  data: [
    { id: "chrome", label: "Chrome", value: 65, bubbleColor: "#4285F4" },
    { id: "safari", label: "Safari", value: 19, bubbleColor: "#34A853" },
    { id: "firefox", label: "Firefox", value: 10, bubbleColor: "#FF6D00" },
    { id: "edge", label: "Edge", value: 6, bubbleColor: "#0078D4" },
  ],
  layout: { type: "physics" },
  render: { mode: "auto", theme: "glass" },
});

// React to bubble clicks
chart.on("bubble:click", ({ item }) => console.log("Clicked:", item.label));

// Push new data — smooth animated transition
chart.update(newData);

// Teardown (stops animation loop, removes DOM elements)
chart.destroy();

Angular

// chart.component.ts
import { Component, OnDestroy, AfterViewInit } from "@angular/core";
import { initializeChart, BubbleChart } from "bubble-chart-js";

@Component({
  selector: "app-chart",
  template: `<div id="bubble-chart" style="width:100%;height:500px"></div>`,
})
export class ChartComponent implements AfterViewInit, OnDestroy {
  private chart!: BubbleChart;

  ngAfterViewInit(): void {
    this.chart = initializeChart({
      canvasContainerId: "bubble-chart",
      data: [
        { id: "revenue", label: "Revenue", value: 840, bubbleColor: "#6366f1" },
        { id: "churn", label: "Churn", value: 230, bubbleColor: "#f43f5e" },
        { id: "nps", label: "NPS", value: 510, bubbleColor: "#10b981" },
      ],
      layout: { type: "physics" },
      render: { theme: "glass" },
    });
  }

  ngOnDestroy(): void {
    this.chart.destroy();
  }
}

Browser Script Tag (UMD)

<div id="chart" style="width:800px;height:500px"></div>
<script src="https://unpkg.com/bubble-chart-js/dist/bubbleChart.umd.js"></script>
<script>
  const chart = window.initializeChart({
    canvasContainerId: "chart",
    data: [
      { label: "Alpha", value: 120, bubbleColor: "#6366f1" },
      { label: "Beta", value: 80, bubbleColor: "#f43f5e" },
      { label: "Gamma", value: 55, bubbleColor: "#10b981" },
    ],
  });
</script>

API Reference

initializeChart(config)

Creates and renders the chart. Returns a BubbleChart instance.

import { initializeChart } from "bubble-chart-js";
const chart = initializeChart(config);

BubbleChart Instance Methods

MethodSignatureDescription
update(newData: DataItem[]) => voidRe-render with new data; animates transitions
on(event, handler) => UnsubscribeFnSubscribe to chart events (bubble:click, bubble:hover)
destroy() => voidStop animation, remove DOM nodes, clear all subscriptions
addLayerHook(hook) => stringInject a custom draw call into a named render layer
removeLayerHook(id: string) => voidRemove a layer hook by ID
simulationReadonly<SimulationSnapshot>Snapshot of the last physics simulation tick

topN(data, n) Utility

Selects the top N items by value — useful for capping high-cardinality datasets before render.

import { initializeChart, topN } from "bubble-chart-js";

initializeChart({ canvasContainerId: "chart", data: topN(rawData, 25) });

Configuration Reference

DataItem

PropertyTypeRequiredDescription
idstringNoStable key for reconciliation on update(). Auto-derived if omitted.
labelstringYesText displayed inside the bubble
valuenumberYesDetermines bubble radius relative to the dataset
bubbleColorstringNoCSS color string for this specific bubble
opacitynumberNoFill opacity 0–1. Overrides global bubbleAppearance.opacity
iconstringNoUnicode codepoint or ligature string (e.g. "trending_up")
iconFontstringNoFont family for the icon, e.g. "Material Symbols Outlined"

Configuration (top-level)

PropertyTypeDefaultDescription
canvasContainerIdstringRequired. ID of the host DOM element
dataDataItem[]Required. Array of bubble data
colorPalettestring[]built-inFallback color cycle for bubbles without an explicit bubbleColor
minRadiusnumber20Minimum bubble radius in pixels
canvasBackgroundColorstringtransparentCanvas background fill color
isResizeCanvasOnWindowSizeChangebooleantrueAuto-resize chart on window resize
theme"flat" | "glass""flat"Shorthand alias for render.theme

layout

PropertyTypeDefaultDescription
type"static" | "physics""static"Layout engine selection
physics.seednumberSeed for deterministic initial bubble placement
physics.centerStrengthnumber0.012Strength of the centering force
physics.collisionPadnumber3Extra padding (px) added to each bubble's collision radius
physics.velocityDecaynumber0.82Velocity decay per tick (0–1)
physics.alphaDecaynumber0.0228Alpha decay rate per tick
physics.maxVelocitynumber8Maximum velocity magnitude per tick
physics.updateBehavior"restart" | "momentum""restart"How update() affects a running simulation

render

PropertyTypeDefaultDescription
mode"auto" | "svg" | "canvas""auto"Renderer selection (auto picks Canvas for >25 items)
theme"flat" | "glass""flat"Visual theme
glassPerformanceHint"safe" | "full""safe"full = GPU feGaussianBlur bloom; safe = CSS drop-shadow
glassOptions.glowIntensitynumber0.35Glow intensity 0–1 (glass theme only)
glassOptions.blurRadiusnumber12Outer halo blur radius in px (full mode only)

interaction

PropertyTypeDefaultDescription
hoverScalenumber1.08Scale factor applied to the hovered bubble
hoverEasenumber0.10Lerp factor for hover animation (0–1)
tooltipEnabledbooleantrueShow tooltip on hover

animation

PropertyTypeDefaultDescription
entryDurationnumber25Entry animation duration in frames
transitionEasing(t: number) => numberCustom easing function for position/radius tweens

Tooltip (tooltipOptions)

Full CSS-style control over the hover tooltip. Accepts backgroundColor, fontColor, fontFamily, fontSize, padding, borderColor, boxShadow, zIndex, and more. Supply a formatter function for fully custom HTML content:

tooltipOptions: {
  backgroundColor: '#1e1e2e',
  fontColor: '#cdd6f4',
  formatter: (item) => `<strong>${item.label}</strong>: ${item.value.toLocaleString()}`,
},

Events

EventPayloadDescription
bubble:click{ item: DataItem, event: PointerEvent }Fired when a bubble is clicked
bubble:hover{ item: DataItem | null, event: PointerEvent }Fired on hover enter / leave
const unsub = chart.on("bubble:click", ({ item }) => {
  console.log(`${item.label}: ${item.value}`);
});

// Stop listening
unsub();

Layer Hooks

Inject custom Canvas 2D draw calls into any render layer for complete visual control:

chart.addLayerHook({
  layer: "overlay",
  draw: ({ ctx, bubbles }) => {
    bubbles.forEach((b) => {
      ctx.strokeStyle = "rgba(255,255,255,0.4)";
      ctx.lineWidth = 2;
      ctx.beginPath();
      ctx.arc(b.x, b.y, b.r + 4, 0, Math.PI * 2);
      ctx.stroke();
    });
  },
});

Available layers: background, shadows, bubbles, text, overlay, debug.

Contributing

Contributions, bug reports, and feature requests are welcome. Please open an issue or submit a pull request on GitHub.

License

MIT © Pragadeeshwaran Pasupathi

Keywords

bubble

FAQs

Package last updated on 31 Mar 2026

Did you know?

Socket

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.

Install

Related posts