Skip to content

Migrate typescript#19

Open
utix wants to merge 4 commits into
masterfrom
migrate_typescript
Open

Migrate typescript#19
utix wants to merge 4 commits into
masterfrom
migrate_typescript

Conversation

@utix
Copy link
Copy Markdown
Collaborator

@utix utix commented May 23, 2026

Rewrite in TypeScript + new charting features

Summary

Complete rewrite of the library from CoffeeScript to TypeScript, with new rendering capabilities, input validation, a test suite, and a significantly smaller bundle.

What changed

Core rewrite

  • TypeScript source in src/ compiled via esbuild (bundle) + tsc (types only)
  • Zero runtime dependencies — chalk replaced by a 15-line inline ANSI helper
  • Bundle size: 31KB → 9.3KB, matching the original CoffeeScript output
  • Fixed all crash bugs: diffX=0, diff=0, numBkts=1 division by zero

Rendering improvements

  • Partial bar resolution upgraded from 2 levels (▄) to 8 levels (▁▂▃▄▅▆▇█)
  • Horizontal bars with 8-level ▏▎▍▌▋▊▉█ characters (direction: 'horizontal')
  • Reference/threshold line (refY) rendered as ╌ dashes across the chart
  • Horizontal grid lines restored to match original behaviour

New options

Option Values Description
aggregation avg sum min max last count How to combine multiple points per bucket
yScale linear log Log scale for exponential data
refY number Horizontal threshold line
direction vertical horizontal Bar orientation
Categorical points [string, number][] Named X axis buckets

Quality

  • 76 unit and integration tests (Vitest)
  • Full input validation with typed errors (TypeError, RangeError)
  • examples/advanced.js — 13 corner cases
  • examples/features.js — 8 feature combination demos

Breaking changes

None — same function signature babar(points, options?), same option names, same return type.

Closes #8
Closes #12
Closes #13

utix and others added 4 commits May 23, 2026 18:53
- Replace CoffeeScript source with TypeScript (src/babar.ts, buckets.ts, draw.ts, types.ts, validate.ts)
- Replace `colors` with `chalk` (no String.prototype mutation)
- Add input validation with clear error messages (empty array, non-finite values, bad options)
- Fix crash bugs: diffX=0, diff=0, numBkts=1 division by zero
- Upgrade partial bar rendering from 2 levels (▄) to 8 levels (▁▂▃▄▅▆▇█)
- Restore horizontal grid lines (_) above bars, matching original behavior
- Add 48 unit and integration tests with Vitest
- Add advanced.js example covering 13 corner cases
- Bump version to 0.3.0

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
…is, and horizontal bars

- aggregation option: avg (default), sum, min, max, last, count
- yScale option: linear (default) or log for exponential data
- refY option: draws a ╌ threshold line at a given Y value (| in ascii mode)
- Categorical X axis: accept [string, number][] points with named buckets
- direction option: horizontal renders bars left-to-right with 8-level ▏▎▍▌▋▊▉█ chars
- Horizontal mode supports refY as a vertical reference column
- Categorical + horizontal combined: leaderboard-style charts
- All features combinable (e.g. categorical + log + horizontal + refY)
- 28 new tests covering all features and error cases
- features.js example demonstrating all 8 feature combinations

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
maxLabelW was computed only from minX, so single-digit x values (0, 2)
produced narrower labels than double-digit ones (10, 12), shifting bar
start positions. Now measured across all generated x labels.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
- Add src/ansi.ts: 15-line ANSI colorize/bold replacing chalk entirely
- Switch build from tsc (JS emit) to esbuild --bundle --minify for lib/babar.js
- tsc now only emits .d.ts declarations (emitDeclarationOnly: true)
- Remove chalk from dependencies (bundled → zero runtime deps)
- Bundle size: 31KB → 9.3KB (same as original CoffeeScript output)
- lib/ output: single babar.js + .d.ts files only (no .js.map, no sub-modules)

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Any interest in rewriting to Typescript? Caption per bar Chart labels to accept strings

1 participant