Warning: session_start(): open(/var/lib/php/sessions/sess_n8200ack3me3hf6emoabgde5gf, O_RDWR) failed: No space left on device (28) in /var/www/tb-usercake/models/config.php on line 51
Warning: session_start(): Failed to read session data: files (path: /var/lib/php/sessions) in /var/www/tb-usercake/models/config.php on line 51
// background color is set with setBackground
sclass JMultiColorBar > JComponentWithChangeListeners {
class Entry {
settable double value;
settable Color color;
settable S text;
settable S toolTip;
}
L entries = notifyingList(l0 repaint);
settableWithVar double max = 100;
settable L defaultColors = ll(Color.red, Color.blue);
swappable Color defaultColor(int index) {
ret getCyclic(defaultColors, index);
}
Entry addEntry aka add(S text, double value) {
ret addAndReturn(entries, new Entry().+value.color(defaultColor(l(entries))));
}
Entry addEntry aka add(double value, Color color) {
ret addAndReturn(entries, new Entry().+value.+color);
}
S toolTipForEntry(Entry e) {
ret e == null ?: spaceCombine(or2(e.toolTip, e.text), str(e.value));
}
S toolTipForPosition(Pt p) {
int w = getWidth();
Entry e = lastThat(entries, _e -> p.x < xForEntry(_e, w));
ret toolTipForEntry(e);
}
*() {
varMax().onChange(l0 repaint);
jMinSize(50, 10, this);
new InstantNeverHideToolTip(l1 toolTipForPosition, this);
}
int xForEntry(Entry e, int w) {
ret iround(w*clampZeroToOne(doubleRatio(e.value, max)))
}
public void paintComponent(Graphics g) {
super.paintComponent(g); // paint background
int w = getWidth(), h = getHeight();
int x = 0;
for (e : entries) {
int x2 = main max(x, xForEntry(e, w));
if (x2 > x)
fillRect(g, x+1, 0, x2-x, h, e.color);
x = x2;
}
}
}