diff --git a/.changeset/README.md b/.changeset/README.md new file mode 100644 index 00000000..e5b6d8d6 --- /dev/null +++ b/.changeset/README.md @@ -0,0 +1,8 @@ +# Changesets + +Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works +with multi-package repos, or single-package repos to help you version and publish your code. You can +find the full documentation for it [in our repository](https://github.com/changesets/changesets) + +We have a quick list of common questions to get you started engaging with this project in +[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md) diff --git a/.changeset/config.json b/.changeset/config.json new file mode 100644 index 00000000..ad6f18a1 --- /dev/null +++ b/.changeset/config.json @@ -0,0 +1,11 @@ +{ + "$schema": "https://unpkg.com/@changesets/config@3.1.2/schema.json", + "changelog": "@changesets/cli/changelog", + "commit": false, + "fixed": [], + "linked": [], + "access": "restricted", + "baseBranch": "main", + "updateInternalDependencies": "patch", + "ignore": [] +} diff --git a/.changeset/scale-domain-no-args.md b/.changeset/scale-domain-no-args.md new file mode 100644 index 00000000..22a620aa --- /dev/null +++ b/.changeset/scale-domain-no-args.md @@ -0,0 +1,5 @@ +--- +'chroma-js': minor +--- + +scale.domain now returns the original domain array when called with no arguments diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..1de9534f --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,39 @@ +name: CI + +on: + pull_request: + branches: + - main + push: + branches: + - main + +jobs: + lint-and-test: + runs-on: ubuntu-latest + env: + CI: true + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up pnpm + uses: pnpm/action-setup@v4 + with: + version: 10.24.0 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: 20 + cache: pnpm + + - name: Install dependencies + run: pnpm install --frozen-lockfile + + - name: Lint + run: pnpm lint + + - name: Test + run: pnpm test -- --run diff --git a/LICENSE b/LICENSE index 13a895dd..229c24a9 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ chroma.js - JavaScript library for color conversions -Copyright (c) 2011-2024, Gregor Aisch +Copyright (c) 2011-2025, Gregor Aisch All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/package.json b/package.json index c9daa71a..6b5402a7 100644 --- a/package.json +++ b/package.json @@ -51,7 +51,7 @@ }, "main": "./index.js", "scripts": { - "prepublishOnly": "npm test -- --run && node .bin/update-version.cjs && npm run build", + "prepublishOnly": "npm test -- --run && node .bin/update-version.cjs && npm run build && npm run docs", "build": "rollup -c && cross-env DEV=1 rollup -c ", "docs": "cd docs && make", "docs-preview": "cd docs && make && make preview", diff --git a/src/generator/scale.js b/src/generator/scale.js index 7ce00e12..d60b89da 100644 --- a/src/generator/scale.js +++ b/src/generator/scale.js @@ -12,6 +12,7 @@ export default function (colors) { let _nacol = chroma('#ccc'); let _spread = 0; // const _fixed = false; + let _positions = [0, 1]; let _domain = [0, 1]; let _pos = []; let _padding = [0, 0]; @@ -180,9 +181,9 @@ export default function (colors) { if (classes != null) { if (type(classes) === 'array') { _classes = classes; - _domain = [classes[0], classes[classes.length - 1]]; + _positions = [classes[0], classes[classes.length - 1]]; } else { - const d = chroma.analyze(_domain); + const d = chroma.analyze(_positions); if (classes === 0) { _classes = [d.min, d.max]; } else { @@ -196,8 +197,11 @@ export default function (colors) { f.domain = function (domain) { if (!arguments.length) { - return _pos.map(p => _min + p * (_max - _min));; + // return original domain + return _domain; } + // store original domain so we can return it later + _domain = domain.slice(0); _min = domain[0]; _max = domain[domain.length - 1]; _pos = []; @@ -228,7 +232,7 @@ export default function (colors) { } } } - _domain = [_min, _max]; + _positions = [_min, _max]; return f; }; @@ -324,8 +328,8 @@ export default function (colors) { } else if (numColors === 1) { result = [f(0.5)]; } else if (numColors > 1) { - const dm = _domain[0]; - const dd = _domain[1] - dm; + const dm = _positions[0]; + const dd = _positions[1] - dm; result = __range__(0, numColors, false).map((i) => f(dm + (i / (numColors - 1)) * dd) ); @@ -342,7 +346,7 @@ export default function (colors) { samples.push((_classes[i - 1] + _classes[i]) * 0.5); } } else { - samples = _domain; + samples = _positions; } result = samples.map((v) => f(v)); } diff --git a/test/scales.test.js b/test/scales.test.js index ed189cfd..8213b96d 100644 --- a/test/scales.test.js +++ b/test/scales.test.js @@ -413,22 +413,21 @@ describe('Some tests for scale()', () => { describe('multi-stop domain with matching ramp stops', () => { const f = scale(['yellow', 'red', 'black']).domain([0, 25, 100]); - + it('returns the original domain positions', () => { expect(f.domain()).toEqual([0, 25, 100]); }); - + it('maps first stop', () => { expect(f(0).hex()).toBe('#ffff00'); }); - + it('maps mid stop', () => { - expect(f(25).hex()).toBe('#ff8080'); + expect(f(25).hex()).toBe('#ff0000'); }); - + it('maps last stop', () => { expect(f(100).hex()).toBe('#000000'); }); }); - });