allow frequency display precision to be set via configuration

This commit is contained in:
Jakob Ketterl
2020-12-10 20:58:07 +01:00
parent 05096c2a16
commit 23080dbe22
5 changed files with 31 additions and 4 deletions

View File

@ -1,6 +1,7 @@
function FrequencyDisplay(element) {
this.element = $(element);
this.digits = [];
this.precision = 4;
this.setupElements();
this.setFrequency(0);
}
@ -14,7 +15,10 @@ FrequencyDisplay.prototype.setupElements = function() {
FrequencyDisplay.prototype.setFrequency = function(freq) {
this.frequency = freq;
var formatted = (freq / 1e6).toLocaleString(undefined, {maximumFractionDigits: 4, minimumFractionDigits: 4});
var formatted = (freq / 1e6).toLocaleString(
undefined,
{maximumFractionDigits: this.precision, minimumFractionDigits: this.precision}
);
var children = this.digitContainer.children();
for (var i = 0; i < formatted.length; i++) {
if (!this.digits[i]) {
@ -34,6 +38,12 @@ FrequencyDisplay.prototype.setFrequency = function(freq) {
}
};
FrequencyDisplay.prototype.setFrequencyPrecision = function(precision) {
if (!precision) return;
this.precision = precision;
this.setFrequency(this.frequency);
};
function TuneableFrequencyDisplay(element) {
FrequencyDisplay.call(this, element);
this.setupEvents();