d3-scale

Encodes abstract data as visual scales for position, color, size, and other chart dimensions.

Library
npm
v4.0.2
1,618 stars
ISC

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
52 /100 Fair
Development Activity 0
Maintenance 32
Community 76
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
76 /100 Good
Architecture 88
Code Quality 78
Innovation 62
Learning Curve 75

d3-scale is the scale module of D3.js, providing the functions that map a dimension of abstract data — numbers, dates, categories — onto a visual representation such as pixel position, color, or stroke width. It implements the full family of scale types used across data visualization: continuous scales (linear, power, log, symlog, radial, time/UTC) that interpolate smoothly between a domain and range, and discrete scales (ordinal, band, point, quantile, quantize, threshold) that bucket or index values instead of interpolating them. Sequential and diverging scales extend the same machinery to color encoding, commonly paired with d3-scale-chromatic’s color schemes.

Each scale is a small, composable function built on a shared continuous()/transformer() core (in src/continuous.js), so behavior like clamping, custom interpolation, and nice() domain rounding is implemented once and reused by every continuous scale type rather than duplicated per scale. The module depends on other single-purpose D3 packages (d3-array, d3-interpolate, d3-time, d3-format) instead of bundling their logic, keeping it usable standalone or as part of the full D3 bundle.

What You Get

  • Continuous scales — linear, power/sqrt, log, symlog, and radial — for mapping numeric domains to numeric ranges with optional clamping and custom interpolation
  • Time and UTC scales that map Date domains to a range, with calendar-aware tick generation and formatting
  • Discrete scales — ordinal, band, and point — for mapping categorical domains to colors, bar positions, or fixed points
  • Quantile, quantize, and threshold scales for bucketing continuous input into a fixed set of discrete outputs
  • Sequential and diverging scales for one- and two-hued color encodings, including quantile-based variants
  • Built-in nice(), ticks(), and tickFormat() helpers for producing human-readable axis gridlines from any continuous scale

Common Use Cases

  • Mapping a numeric or time-series column to horizontal/vertical pixel position in a scatterplot or line chart
  • Encoding a categorical field as color or bar position using an ordinal or band scale
  • Building a choropleth or heatmap by feeding a numeric domain through a sequential or quantile color scale
  • Generating axis ticks and labels automatically from a chart’s data domain via ticks()/tickFormat()
  • Converting a continuous data range into a fixed number of visual buckets with quantize or threshold scales

Under The Hood

Architecture

The module is organized as one small file per scale type (linear.js, log.js, time.js, ordinal.js, band.js, quantile.js, sequential.js, diverging.js, etc.), all re-exported through a flat src/index.js. Continuous numeric scales share a single core: continuous.js exposes a transformer() closure that holds domain/range/interpolate/clamp state and produces the actual scale function via bimap/polymap piecewise interpolation, plus an invert path built the same way in reverse. Scale-specific files like linear.js, log.js, and pow.js wrap this core with a transform/untransform pair (identity, log, power) rather than reimplementing interpolation, so adding a new continuous scale type is a matter of supplying two functions. Time scales (time.js) reuse the same continuous core through a calendar() wrapper that swaps in calendar-aware tick and nice logic from d3-time. Discrete scales (ordinal.js, band.js) are structurally separate, built around an InternMap-backed index rather than the continuous transformer, since they classify rather than interpolate.

Tech Stack

Plain ES modules with no build-time framework dependency — type: module in package.json, published as both raw src/**/*.js and a Rollup-built UMD/minified dist bundle for unpkg/jsdelivr. It composes rather than reimplements the rest of the D3 ecosystem: d3-array for bisect/ticks/InternMap, d3-interpolate for value interpolation, d3-time/d3-time-format for calendar scales, and d3-format for tick formatting. Tests run under Mocha with plain assert, and ESLint lints both src and test; there is no TypeScript — types ship from DefinitelyTyped separately.

Code Quality

Every scale type has a dedicated *-test.js file exercising defaults, edge cases (reversed domains, degenerate zero-width domains, clamping), and copy() independence, run via TZ=America/Los_Angeles mocha 'test/**/*-test.js' so time-scale tests are timezone-deterministic. Code style favors terse, functional closures over classes — mutable state is closed over in local vars and every scale returns a plain function object with methods attached, a longstanding D3 idiom rather than an ES class. No runtime type checking; correctness leans entirely on the test suite and ESLint rather than TypeScript. CI (GitHub Actions) runs the Node test matrix plus lint on every push and PR.

What Makes It Unique

Rather than one monolithic scale abstraction, d3-scale factors the numeric-continuous case into a single reusable transformer shared by seven+ scale types (linear, pow, sqrt, log, symlog, radial, time), while keeping genuinely different behavior (ordinal/band’s index-based classification, quantile/quantize/threshold’s bucketing) as separate implementations — avoiding both a bloated one-size-fits-all scale class and needless duplication across the continuous family. This is a deliberate, narrow design choice rather than a novel algorithm, consistent with D3’s broader philosophy of small, focused, composable modules.

Used by 18 apps in this directory

TypeScript
65%
Other

NocoDB

Databases · Low Code Platforms · No Code Platforms

65,340

Turn any SQL database into a collaborative no-code spreadsheet with automatic REST APIs and real-time views.

View details
91
Repo Health
77
Technical
63
Dependency
Built with
TypeScript 65%
Vue 30%
Updated 6 days ago
TypeScript
81%
MIT

OpenCode

AI Code Assistants

220,711

A fully open-source AI coding agent built for the terminal, with a TUI, desktop app, web client, plugin system, and SDK — one of the most-starred AI coding agents on GitHub.

View details
89
Repo Health
76
Technical
66
Dependency
Built with
TypeScript 81%
MDX 16%
Updated 6 days ago
TypeScript
39%
AGPL 3.0

OpenObserve

Analytics · Devops · Monitoring

22,475

Open source observability platform for logs, metrics, traces, and real user monitoring — delivering 140x lower storage costs than Elasticsearch with a single binary you can run in under 2 minutes.

View details
90
Repo Health
9
Technical
68
Dependency
Built with
TypeScript 39%
Rust 30%
Vue 17%
Updated 6 days ago
Python
55%
Other

PostHog

Ab Testing Experimentation · Analytics · Developer Tools

40,397

The all-in-one open source product platform combining analytics, session replay, feature flags, error tracking, AI observability, and a built-in data warehouse in a single self-hostable stack.

View details
92
Repo Health
80
Technical
65
Dependency
Built with
Python 55%
TypeScript 36%
Updated 6 days ago
Go
40%
Apache 2.0

Rill

Analytics · Data Engineering

2,962

The fastest BI tool for humans and agents — define metrics, models, and dashboards as code and query them instantly on ClickHouse or DuckDB.

View details
88
Repo Health
88
Technical
64
Dependency
Built with
Go 40%
TypeScript 38%
Svelte 21%
Updated 6 days ago
TypeScript
51%
AGPL 3.0

Sink

Analytics · Bookmarks Archiving

7,231

Serverless link shortener with real-time analytics, powered by Cloudflare

View details
84
Repo Health
80
Technical
0
Dependency
Built with
TypeScript 51%
Vue 47%
Updated 1 months ago
TypeScript
97%
AGPL 3.0

Swetrix

Analytics

1,213

Privacy-first, cookieless web analytics with error tracking, session replays, and performance monitoring — self-host or use Cloud.

View details
87
Repo Health
71
Technical
66
Dependency
Built with
TypeScript 97%
Updated 1 weeks ago
Go
75%
AGPL 3.0

Teleport

Authentication · Security

21,016

Zero-trust infrastructure access platform that replaces credentials and VPNs with short-lived certificates, SSO, and identity-aware proxies for SSH, Kubernetes, databases, RDP, and AI agents.

View details
94
Repo Health
81
Technical
68
Dependency
Built with
Go 75%
TypeScript 16%
Updated 1 weeks ago
TypeScript
72%
Apache 2.0

Valmis

AI Agents

108

A security-focused, self-hostable AI agent platform for production work — agents run in isolated containers that access credentials only through a host-side proxy, so the AI itself never sees API keys or plaintext credentials.

View details
51
Repo Health
69
Technical
70
Dependency
Built with
TypeScript 72%
Svelte 27%
Updated 1 months ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers