-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
59 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const getRange = { | ||
x: (settings, width, height) => settings.reverseX ? [width, 0] : typeof settings.xRange === 'function' ? settings.xRange({ width, height }) : (settings.xRange || [0, width]), | ||
y: (settings, width, height) => settings.reverseY ? [height, 0] : typeof settings.yRange === 'function' ? settings.yRange({ width, height }) : (settings.yRange || [0, height]), | ||
r: (settings, width, height) => !settings.rRange ? [1, 25] : typeof settings.rRange === 'function' ? settings.rRange({ width, height }) : settings.rRange | ||
}; | ||
|
||
export default function getDefaultRange (s, settings, width, height) { | ||
return getRange[s](settings, width, height); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* globals describe it */ | ||
import getDefaultRange from '../src/settings/getDefaultRange.js'; | ||
import * as assert from 'assert'; | ||
|
||
const name = 'getDefaultRange'; | ||
|
||
const width = 900; | ||
const height = 500; | ||
|
||
const tests = [ | ||
/* -------------------------------------------- | ||
* Defaults | ||
*/ | ||
{ args: ['x', { }, width, height], expected: [0, width] }, | ||
{ args: ['y', { }, width, height], expected: [0, height] }, | ||
{ args: ['r', { }, width, height], expected: [1, 25] }, | ||
/* -------------------------------------------- | ||
* Reverse it | ||
*/ | ||
{ args: ['x', { reverseX: true }, width, height], expected: [width, 0] }, | ||
{ args: ['y', { reverseY: true }, width, height], expected: [height, 0] }, | ||
/* -------------------------------------------- | ||
* Set a manual default | ||
*/ | ||
{ args: ['x', { xRange: [-100, 100] }, width, height], expected: [-100, 100] }, | ||
{ args: ['y', { yRange: [-100, 100] }, width, height], expected: [-100, 100] }, | ||
{ args: ['r', { rRange: [-100, 100] }, width, height], expected: [-100, 100] }, | ||
/* -------------------------------------------- | ||
* Functions! | ||
*/ | ||
{ args: ['x', { xRange: ({ width, height }) => [0, width / 2] }, width, height], expected: [0, width / 2] }, | ||
{ args: ['y', { yRange: ({ width, height }) => [0, height / 2] }, width, height], expected: [0, height / 2] }, | ||
{ args: ['r', { rRange: ({ width, height }) => [width / 2, height / 2] }, width, height], expected: [width / 2, height / 2] } | ||
]; | ||
|
||
describe(name, function () { | ||
tests.forEach(test => { | ||
describe(JSON.stringify(test.args), function () { | ||
it(`should equal ${JSON.stringify(test.expected)}`, function () { | ||
const actual = getDefaultRange(...test.args); | ||
assert.deepStrictEqual(actual, test.expected); | ||
}); | ||
}); | ||
}); | ||
}); |