* Refresh gauge with new values * @param {number} val - New value * @param {number} [max] - New maximum value * @param {number} [min] - New minimum value * @param {string} [label] - New label
(val, max, min, label)
| 905 | * @param {string} [label] - New label |
| 906 | */ |
| 907 | refresh(val, max, min, label) { |
| 908 | if (!isNumber(val)) { |
| 909 | throw new Error('JustGage: refresh() requires a numeric value'); |
| 910 | } |
| 911 | |
| 912 | // Store current value to animate from |
| 913 | const currentValue = this._getCurrentDisplayValue(); |
| 914 | |
| 915 | // Store original value for display formatting (before clamping) |
| 916 | const originalVal = val; |
| 917 | |
| 918 | // Update label if provided |
| 919 | if (label !== null && label !== undefined) { |
| 920 | this.config.label = label; |
| 921 | if (this.canvas.label) { |
| 922 | this.canvas.label.attr({ text: this.config.label }); |
| 923 | } |
| 924 | } |
| 925 | |
| 926 | // Update minimum value if provided |
| 927 | if (isNumber(min)) { |
| 928 | this.config.min = min; |
| 929 | |
| 930 | // Update min text display |
| 931 | if (this.canvas.min) { |
| 932 | const minText = this._formatDisplayText(this.config.min, this.config, 'min'); |
| 933 | this.canvas.min.attr({ text: minText }); |
| 934 | } |
| 935 | } |
| 936 | |
| 937 | // Update maximum value if provided |
| 938 | if (isNumber(max)) { |
| 939 | this.config.max = max; |
| 940 | |
| 941 | // Update max text display |
| 942 | if (this.canvas.max) { |
| 943 | const maxText = this._formatDisplayText(this.config.max, this.config, 'max'); |
| 944 | this.canvas.max.attr({ text: maxText }); |
| 945 | } |
| 946 | } |
| 947 | |
| 948 | // Store the actual value (no clamping) - visual clamping happens in _drawLevel and _drawPointer |
| 949 | val = val * 1; |
| 950 | |
| 951 | // Format display value using original logic |
| 952 | let displayVal = originalVal; // Use original input value for display |
| 953 | |
| 954 | if (this.config.textRenderer && this.config.textRenderer(displayVal) !== false) { |
| 955 | displayVal = this.config.textRenderer(displayVal); |
| 956 | } else if (this.config.humanFriendly) { |
| 957 | displayVal = |
| 958 | humanFriendlyNumber(displayVal, this.config.humanFriendlyDecimal) + this.config.symbol; |
| 959 | } else if (this.config.formatNumber) { |
| 960 | displayVal = |
| 961 | formatNumber((displayVal * 1).toFixed(this.config.decimals)) + this.config.symbol; |
| 962 | } else if (this.config.displayRemaining) { |
| 963 | displayVal = |
| 964 | ((this.config.max - displayVal) * 1).toFixed(this.config.decimals) + this.config.symbol; |