+44
-7
@@ -6,3 +6,3 @@ /** | ||
| * @author komed3 (Paul Köhler) | ||
| * @version 1.0.1 | ||
| * @version 1.0.2 | ||
| * @license MIT | ||
@@ -19,3 +19,3 @@ */ | ||
| if ( _low && _high ) { | ||
| if ( _low !== undefined && _high !== undefined ) { | ||
@@ -26,3 +26,3 @@ this.setBounds( _low, _high ); | ||
| if ( _ticks ) { | ||
| if ( _ticks !== undefined ) { | ||
@@ -110,3 +110,3 @@ this.setMaxTicks( _ticks ); | ||
| this.maxTicks = parseInt( ticks ); | ||
| this.maxTicks = Math.max( 1, parseInt( ticks ) ); | ||
@@ -124,3 +124,6 @@ this.is = false; | ||
| if ( this.lowerBound && this.upperBound ) { | ||
| if ( | ||
| this.lowerBound !== undefined && | ||
| this.upperBound !== undefined | ||
| ) { | ||
@@ -146,7 +149,11 @@ value = parseFloat( value ); | ||
| * | ||
| * @returns {Boolean} scale successfully generated | ||
| * @returns {Boolean} true if the scale is successfully generated | ||
| */ | ||
| calculate () { | ||
| if ( this.lowerBound && this.upperBound && this.maxTicks ) { | ||
| if ( | ||
| this.lowerBound !== undefined && | ||
| this.upperBound !== undefined && | ||
| this.maxTicks !== undefined | ||
| ) { | ||
@@ -182,2 +189,32 @@ let range = this.#nearest( | ||
| /** | ||
| * checks if the entire scale is negative | ||
| * | ||
| * @returns {Boolean} true if the scale is negative | ||
| */ | ||
| isNegative () { | ||
| if ( this.is ) { | ||
| return this.max <= 0; | ||
| } | ||
| }; | ||
| /** | ||
| * checks if the scale crosses zero | ||
| * | ||
| * @returns {Boolean} true if the scale crosses zero | ||
| */ | ||
| crossesZero () { | ||
| if ( this.is ) { | ||
| return this.min < 0 && this.max > 0; | ||
| } | ||
| }; | ||
| /** | ||
| * get step size | ||
@@ -184,0 +221,0 @@ * |
+1
-1
@@ -10,3 +10,3 @@ { | ||
| "homepage": "https://github.com/komed3/linscale#readme", | ||
| "version": "1.0.1", | ||
| "version": "1.0.2", | ||
| "license": "MIT", | ||
@@ -13,0 +13,0 @@ "keywords": [ |
+20
-3
@@ -5,3 +5,3 @@ # linscale | ||
| Install | ||
| ## Install | ||
@@ -41,2 +41,5 @@ Using Node.js, install the package with the following shell command: | ||
| let crossesZero = scale.crossesZero(); | ||
| // expected: true | ||
| } | ||
@@ -50,3 +53,3 @@ ``` | ||
| ```js | ||
| import LinScale from 'https://cdn.jsdelivr.net/npm/linscale@1.0.1/+esm'; | ||
| import LinScale from 'https://cdn.jsdelivr.net/npm/linscale@1.0.2/+esm'; | ||
| ``` | ||
@@ -94,2 +97,10 @@ | ||
| ### ``isNegative()`` | ||
| Checks if the entire scale is negative. Returns ``true`` if the scale is negative. | ||
| ### ``crossesZero()`` | ||
| Checks if the scale crosses zero. Returns ``true`` if the scale crosses zero. | ||
| ### ``getTicks()`` | ||
@@ -109,2 +120,8 @@ | ||
| ### 1.0.2 | ||
| * Add ``isNegative`` method | ||
| * Add ``crossesZero`` method | ||
| * Fixed lower / upper bound couldn’t be zero | ||
| ### 1.0.1 | ||
@@ -116,2 +133,2 @@ | ||
| * Initial release | ||
| * Initial release |
10803
11.71%230
13.3%129
16.22%