a-frame-components
Advanced tools
Comparing version
@@ -39,2 +39,4 @@ var __assign = (this && this.__assign) || function () { | ||
percentageTextFont: { type: 'string', default: '' }, | ||
min: { type: 'number', default: 0 }, | ||
max: { type: 'number', default: 0 } | ||
}; | ||
@@ -138,3 +140,4 @@ AFRAME.registerComponent('gui-slider', __assign(__assign(__assign(__assign({ schema: guiSliderSchema }, mixin), { init: function () { | ||
}, getText: function () { | ||
return "".concat(Math.round(this.data.percent * 100)); | ||
var num = mapRange(this.data.percent * 100, this.data.min, this.data.max); | ||
return "".concat(Math.round(num * 100) / 100); | ||
}, positionElements: function () { | ||
@@ -384,2 +387,21 @@ var el = this.el; | ||
} | ||
/** | ||
* Maps a number from one range to another. | ||
* | ||
* @param value The number to map. | ||
* @param fromLow The lower bound of the value's current range. | ||
* @param fromHigh The upper bound of the value's current range. | ||
* @param toLow The lower bound of the value's target range. | ||
* @param toHigh The upper bound of the value's target range. | ||
* @returns The number mapped to the new range. | ||
*/ | ||
function mapRange(value, toLow, toHigh, fromLow, fromHigh) { | ||
if (fromLow === void 0) { fromLow = 0; } | ||
if (fromHigh === void 0) { fromHigh = 1; } | ||
// First, find the ratio of the position of 'value' relative to its current range | ||
var ratio = (value - fromLow) / (fromHigh - fromLow); | ||
// Then, scale this ratio to the target range | ||
var mappedValue = ratio * (toHigh - toLow) + toLow; | ||
return mappedValue; | ||
} | ||
} |
{ | ||
"name": "a-frame-components", | ||
"version": "1.0.242", | ||
"version": "1.0.243", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -29,2 +29,4 @@ import { AFRAME } from "../../react/root"; | ||
percentageTextFont: { type: 'string', default: '' }, | ||
min: { type: 'number', default: 0 }, | ||
max: { type: 'number', default: 0 } | ||
}; | ||
@@ -149,3 +151,4 @@ | ||
getText: function () { | ||
return `${Math.round(this.data.percent * 100)}`; | ||
let num = mapRange(this.data.percent * 100, this.data.min, this.data.max) | ||
return `${Math.round(num * 100) / 100}`; | ||
}, | ||
@@ -441,2 +444,25 @@ positionElements: function () { | ||
} | ||
/** | ||
* Maps a number from one range to another. | ||
* | ||
* @param value The number to map. | ||
* @param fromLow The lower bound of the value's current range. | ||
* @param fromHigh The upper bound of the value's current range. | ||
* @param toLow The lower bound of the value's target range. | ||
* @param toHigh The upper bound of the value's target range. | ||
* @returns The number mapped to the new range. | ||
*/ | ||
function mapRange( | ||
value: number, | ||
toLow: number, | ||
toHigh: number, | ||
fromLow: number = 0, | ||
fromHigh: number = 1, | ||
): number { | ||
// First, find the ratio of the position of 'value' relative to its current range | ||
const ratio = (value - fromLow) / (fromHigh - fromLow); | ||
// Then, scale this ratio to the target range | ||
const mappedValue = ratio * (toHigh - toLow) + toLow; | ||
return mappedValue; | ||
} | ||
} |
1758478
0.12%29976
0.16%