{"id":29210798,"url":"https://github.com/komed3/scalax","last_synced_at":"2026-07-03T09:05:52.901Z","repository":{"id":299983498,"uuid":"1004625236","full_name":"komed3/scalax","owner":"komed3","description":"Lightweight package for calculating linear, logarithmic and radial scales","archived":false,"fork":false,"pushed_at":"2026-06-29T22:04:22.000Z","size":182,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-06-30T00:06:36.419Z","etag":null,"topics":["linear-scale","logarithmic-scale","radial-scale","scales"],"latest_commit_sha":null,"homepage":"https://npmjs.com/package/scalax","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/komed3.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-06-18T23:38:37.000Z","updated_at":"2026-06-29T22:05:02.000Z","dependencies_parsed_at":"2025-07-09T22:09:00.908Z","dependency_job_id":"6765b9df-734c-4f0f-8ff7-9f17b0d47061","html_url":"https://github.com/komed3/scalax","commit_stats":null,"previous_names":["komed3/scalax"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/komed3/scalax","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/komed3%2Fscalax","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/komed3%2Fscalax/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/komed3%2Fscalax/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/komed3%2Fscalax/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/komed3","download_url":"https://codeload.github.com/komed3/scalax/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/komed3%2Fscalax/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35079399,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-03T02:00:05.635Z","response_time":110,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["linear-scale","logarithmic-scale","radial-scale","scales"],"created_at":"2025-07-02T21:38:06.245Z","updated_at":"2026-07-03T09:05:52.893Z","avatar_url":"https://github.com/komed3.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Scalax – Calculating Numerical Scales\n\n[![GitHub License](https://img.shields.io/github/license/komed3/scalax?style=for-the-badge\u0026logo=unlicense\u0026logoColor=fff)](LICENSE)\n[![Static Badge](https://img.shields.io/badge/Typescript-support?style=for-the-badge\u0026logo=typescript\u0026logoColor=fff\u0026color=blue)](https://www.typescriptlang.org)\n[![GitHub package.json version](https://img.shields.io/github/package-json/v/komed3/scalax?style=for-the-badge\u0026logo=npm\u0026logoColor=fff)](https://npmjs.com/package/scalax)\n[![npm bundle size](https://img.shields.io/bundlephobia/min/scalax?style=for-the-badge\u0026logo=gitlfs\u0026logoColor=fff)](https://bundlephobia.com/package/scalax)\n[![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/komed3/scalax/build.yml?style=for-the-badge\u0026logo=educative\u0026logoColor=fff)](https://github.com/komed3/scalax/actions/workflows/build.yml)\n\nThe `scalax` npm package is a lightweight and extensible TypeScript library for calculating numerical scales. It is designed for use in data visualization, charting, and any context where you need to map values between different numeric domains. The library supports linear, logarithmic, and radial (circular) scales, each with a consistent and intuitive API.\n\nCore features include locating “nice” step values at the same intervals, freely selectable granularity (how close together ticks may be) and the calculation of scales in both directions from zero – particularly useful for logarithmic scales. In addition, the library allows the computation of percentages into scale values and vice versa to facilitate graphical representations for data points.\n\n**This library is the successor to the two npm packages [linscale](https://www.npmjs.com/package/linscale) and [logarscale](https://www.npmjs.com/package/logarscale).**\n\n## Installation\n\nYou can install `scalax` via npm:\n\n```sh\nnpm install scalax\n```\n\nUse the package in browser environments via jsDelivr:\n\n```html\n\u003cscript type=\"module\"\u003e\n  import { Scale } from 'https://cdn.jsdelivr.net/npm/scalax@1.0.1/+esm';\n  const scale = new Scale.linear( … );\n\u003c/script\u003e\n```\n\n## Quick Start\n\nHere is a minimal example of how to use `scalax` to create a logarithmic scale and retrieve tick values:\n\n```typescript\nimport { Scale } from 'scalax';\n\n// Create a logarithmic scale from -9 to 953 with up to 10 ticks and base 10\nconst scale = new Scale.logarithmic( -9, 953, 10, 0.01, 10 ).run();\n\nconsole.log( scale.getTicks() ); // [ -10, -1, -0.1, 0, 0.1, 1, 10, 100, 1000 ]\nconsole.log( scale.getPointAt( 0.5 ) ); // Value at 50% along the scale\nconsole.log( scale.getPct( 10 ) ); // Percentage position of value 10 on the scale\n```\n\n## Scale Types\n\n`scalax` comes with three main scale types, each suited for different use cases:\n\n- **Linear scale**: Maps values evenly between a lower and upper bound. Useful for standard numeric axes.\n- **Logarithmic scale**: Maps values logarithmically, supporting both positive and negative domains as well as zero-crossing. Ideal for data spanning several orders of magnitude.\n- **Radial scale**: Designed for circular or angular data, such as degrees in a circle or arc segments. Handles wrap-around and arbitrary angular ranges.\n\nEach scale type is available via the `Scale` export:\n\n```typescript\nimport { Scale } from 'scalax';\n\nconst linear = new Scale.linear( … );\nconst logarithmic = new Scale.logarithmic( … );\nconst radial = new Scale.radial( … );\n```\n\n## Common API\n\nAll scale classes share a consistent set of methods and options, inherited form the abstract base class `Scale`.\n\n### Constructor\n\nEach scale can be constructed with the following parameters:\n\n- `low` (number): The lower bound of the scale.\n- `high` (number): The upper bound of the scale.\n- `maxTicks` (number): The maximum number of ticks to generate.\n- `precision` (number, optional): The minimum step size or granularity (not used for radial scales).\n- `base` (number, only for logarithmic scales): The logarithmic base (e.g., 10 for decades).\n\n### `setBounds( low, high ), setMaxTicks( maxTicks ), setPrecision( precision )`\n\nAllows you to set / update the bounds, maximum ticks, or precision after construction. These methods return the scale instance for chaining.\n\n### `centerAt( value = 0 )`\n\nAllows you to centers the scale around a given value. The lower and upper bounds will be adjusted to be equidistant from this value.\n\n### `run()`\n\nAfter setting up the scale, call `run()` to compute all internal values and ticks. This method must be called before using most other methods.\n\n### `getBounds(), getMaxTicks(), getPrecision()`\n\nReturns the current lower and upper bounds, the maximum number of ticks and the precision for the scale.\n\n### `isReady()`\n\nReturns `true` if the scale has been computed and is ready for use.\n\n### `isNegative(), crossesZero()`\n\nChecks if the scale is entirely negative or crosses the zero point.\n\n### `getMinimum(), getMaximum(), getExtrema()`\n\nReturns the minimum, maximum, or both extrema of the scale after computation.\n\n### `getStepSize()`\n\nReturns the computed step size between ticks.  \n**Note:** This will stay `undefined` for logarithmic scales.\n\n### `getTickAmount()`\n\nReturns the number of ticks generated for the scale.\n\n### `getRange()`\n\nReturns the numeric range (`max - min`) of the scale.\n\n### `getTicks(), getTicksReverse()`\n\nReturning arrays of tick values (`min` to `max` or in reversed order) computed for the scale, suitable for axis labeling or grid lines.\n\n### `getPointAt( pct )`\n\nGiven a percentage (between `0` and `1`, or `0` and `100`), returns the corresponding value on the scale. For example, `getPointAt( 0.5 )` returns the value halfway along the scale.\n\n### `getPct( value, ref = 'min' )`\n\nGiven a value within the scale's range, returns its relative position as a percentage (between `0` and `1`). The optional `ref` parameter can be `min` or `max` to specify the reference direction.\n\n## Scale-Specific Features\n\n### Logarithmic scale\n\n- Supports both positive and negative domains, as well as zero-crossing.\n- The `base` parameter allows you to set the logarithmic base (e.g., `2`, `10`, `e`).\n- Ticks are always exact powers of the base, and `0` is included if the scale crosses zero.\n- Methods: `setBase( base )`, `getBase()` to set and get the logarithmic base.\n\n### Linear scale\n\n- Standard linear mapping and tick generation.\n- Precision controls the minimum step size between ticks.\n\n### Radial scale\n\n- Designed for angular data (degrees).\n- Handles full circles and arbitrary arc segments.\n- Ensures correct wrap-around and tick placement for circular charts.\n- The minimal granularity is `1` to return nicely calculated values.\n\n## Example: Creating and Using a Scale\n\n```typescript\nimport { Scale } from 'scalax';\n\n// Linear scale from 3 to 99 with max. 10 ticks\nconst linear = new Scale.linear( 3, 99, 10 ).run();\nconsole.log( linear.getTicks() ); // [ 0, 20, 40, 60, 80, 100 ]\nconsole.log( linear.getPointAt( 0.25 ) ); // 25\n\n// Logarithmic scale from -56 to 186 with the base 2\nconst log = new Scale.logarithmic( -56, 186, 8, 2, 2 ).run();\nconsole.log( log.getTicks() ); // [ -64, -32, 0, 32, 64, 128, 256 ]\nconsole.log( log.getPct( 10 ) ); // 0.495...\n\n// Radial scale for a half-circle ( 0 to 180 degrees ) with 5 ticks\nconst radial = new Scale.radial( 0, 180, 5 ).run();\nconsole.log( radial.getTicks() ); // [ 0, 45, 90, 135, 180 ]\n```\n\n_Try with [OneCompiler](https://onecompiler.com/nodejs/43nh9mk6n)_\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkomed3%2Fscalax","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkomed3%2Fscalax","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkomed3%2Fscalax/lists"}