Skip to content

Commit 086988e

Browse files
authored
Merge pull request #1362 from lvydra/HAL-2007-3.6
[HAL-2007] Fix utilization bar
2 parents a6d75dc + a1ac66e commit 086988e

1 file changed

Lines changed: 49 additions & 39 deletions

File tree

ballroom/src/main/java/org/jboss/hal/ballroom/chart/Utilization.java

Lines changed: 49 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,19 @@
3030

3131
import static org.jboss.elemento.Elements.div;
3232
import static org.jboss.elemento.Elements.span;
33-
import static org.jboss.hal.resources.CSS.*;
33+
import static org.jboss.hal.resources.CSS.progress;
34+
import static org.jboss.hal.resources.CSS.progressBar;
35+
import static org.jboss.hal.resources.CSS.progressBarDanger;
36+
import static org.jboss.hal.resources.CSS.progressBarRemaining;
37+
import static org.jboss.hal.resources.CSS.progressBarSuccess;
38+
import static org.jboss.hal.resources.CSS.progressBarWarning;
39+
import static org.jboss.hal.resources.CSS.progressContainer;
40+
import static org.jboss.hal.resources.CSS.progressDescription;
41+
import static org.jboss.hal.resources.CSS.progressDescriptionLeft;
42+
import static org.jboss.hal.resources.CSS.progressLabelRight;
43+
import static org.jboss.hal.resources.CSS.progressLabelTopRight;
44+
import static org.jboss.hal.resources.CSS.srOnly;
45+
import static org.jboss.hal.resources.CSS.width;
3446
import static org.jboss.hal.resources.UIConstants.PROGRESSBAR;
3547
import static org.jboss.hal.resources.UIConstants.ROLE;
3648
import static org.jboss.hal.resources.UIConstants.TOGGLE;
@@ -106,46 +118,44 @@ public void update(long current) {
106118
}
107119

108120
public void update(long current, long total) {
109-
if (current <= total) {
110-
this.total = total;
111-
double currentPercent = Math.round(((double) current) / ((double) total) * 100.0);
112-
long remaining = total - current;
113-
double remainingPercent = 100.0 - currentPercent;
114-
115-
valueBar.setAttribute(aria(VALUE_NOW), String.valueOf(current));
116-
valueBar.setAttribute(aria(VALUE_MAX), String.valueOf(total));
117-
valueBar.style.width = width(currentPercent + "%");
118-
Tooltip.element(valueBar).setTitle(MESSAGES.used(currentPercent));
119-
// noinspection HardCodedStringLiteral
120-
valueElement.innerHTML = new SafeHtmlBuilder()
121-
.appendHtmlConstant("<strong>")
122-
.appendEscaped(MESSAGES.currentOfTotal(current, total))
123-
.appendHtmlConstant("</strong>")
124-
.appendEscaped(" " + unit)
125-
.toSafeHtml().asString();
126-
127-
remainingBar.setAttribute(aria(VALUE_NOW), String.valueOf(remaining));
128-
remainingBar.setAttribute(aria(VALUE_MAX), String.valueOf(total));
129-
remainingBar.style.width = width(remainingPercent + "%");
130-
Tooltip.element(remainingBar).setTitle(MESSAGES.available(remainingPercent));
131-
remainingElement.textContent = MESSAGES.available(remainingPercent);
132-
133-
if (thresholds) {
134-
valueBar.classList.remove(progressBarDanger);
135-
valueBar.classList.remove(progressBarWarning);
136-
valueBar.classList.remove(progressBarSuccess);
137-
if (currentPercent > 90) {
138-
valueBar.classList.add(progressBarDanger);
139-
} else if (currentPercent > 75) {
140-
valueBar.classList.add(progressBarWarning);
141-
} else {
142-
valueBar.classList.add(progressBarSuccess);
143-
}
144-
}
145-
146-
} else {
121+
if (current > total) {
147122
logger.error("Invalid values for utilization bar chart: current > total ({} > {})", current, total);
148123
}
124+
this.total = total;
125+
double currentPercent = Math.round(((double) current) / ((double) total) * 100.0);
126+
long remaining = total - current;
127+
double remainingPercent = 100.0 - currentPercent;
128+
129+
valueBar.setAttribute(aria(VALUE_NOW), String.valueOf(current));
130+
valueBar.setAttribute(aria(VALUE_MAX), String.valueOf(total));
131+
valueBar.style.width = width(currentPercent + "%");
132+
Tooltip.element(valueBar).setTitle(MESSAGES.used(currentPercent));
133+
// noinspection HardCodedStringLiteral
134+
valueElement.innerHTML = new SafeHtmlBuilder()
135+
.appendHtmlConstant("<strong>")
136+
.appendEscaped(MESSAGES.currentOfTotal(current, total))
137+
.appendHtmlConstant("</strong>")
138+
.appendEscaped(" " + unit)
139+
.toSafeHtml().asString();
140+
141+
remainingBar.setAttribute(aria(VALUE_NOW), String.valueOf(remaining));
142+
remainingBar.setAttribute(aria(VALUE_MAX), String.valueOf(total));
143+
remainingBar.style.width = width(remainingPercent + "%");
144+
Tooltip.element(remainingBar).setTitle(MESSAGES.available(remainingPercent));
145+
remainingElement.textContent = MESSAGES.available(remainingPercent);
146+
147+
if (thresholds) {
148+
valueBar.classList.remove(progressBarDanger);
149+
valueBar.classList.remove(progressBarWarning);
150+
valueBar.classList.remove(progressBarSuccess);
151+
if (currentPercent > 90) {
152+
valueBar.classList.add(progressBarDanger);
153+
} else if (currentPercent > 75) {
154+
valueBar.classList.add(progressBarWarning);
155+
} else {
156+
valueBar.classList.add(progressBarSuccess);
157+
}
158+
}
149159
}
150160

151161
private String aria(String name) {

0 commit comments

Comments
 (0)