#load "../../lib/app.uce"
COMPONENT:PROGRESSBAR(Request& context)
{
starter_register_js("components/gauges/common.js", context);
starter_register_css("themes/common/css/gauges.css", context);
String gauge_id = first(context.call["id"].to_string(), "progressbar-" + std::to_string((u64)time()));
String layout = first(context.call["layout"].to_string(), "horizontal");
String style = context.call["style"].to_string();
String item_style = context.call["item-style"].to_string();
String value_style = context.call["value-style"].to_string();
String bar_style = context.call["bar-style"].to_string();
String title = context.call["title"].to_string();
String subtitle = context.call["subtitle"].to_string();
<>
if(title != "") { ?>
} ?>
if(layout == "horizontal") { ?>
context.call["items"].each([&](DTree bar, String bar_id) {
DTree merged = context.call["scale"];
bar.each([&](DTree item, String key) { merged[key] = item; });
String label = first(merged["label"].to_string(), bar_id);
String tooltip = merged["tooltip"].to_string();
String unit = merged["unit"].to_string();
f64 min_value = atof(first(merged["min"].to_string(), "0").c_str());
f64 max_value = atof(first(merged["max"].to_string(), "100").c_str());
f64 value = atof(first(merged["value"].to_string(), "0").c_str());
f64 vrange = max_value - min_value;
if(vrange == 0) vrange = 1;
s32 pct = (s32)std::max(0.0, std::min(100.0, ((value - min_value) / vrange) * 100.0));
String color = first(merged["color"].to_string(), "var(--primary)");
?>
= label ?>
= merged["value"].to_string() + unit ?>
if(tooltip != "") { ?>= tooltip ?>
} ?>
}); ?>
} else { ?>
px;">
context.call["items"].each([&](DTree bar, String bar_id) {
DTree merged = context.call["scale"];
bar.each([&](DTree item, String key) { merged[key] = item; });
String label = first(merged["label"].to_string(), bar_id);
String tooltip = merged["tooltip"].to_string();
String unit = merged["unit"].to_string();
f64 min_value = atof(first(merged["min"].to_string(), "0").c_str());
f64 max_value = atof(first(merged["max"].to_string(), "100").c_str());
f64 value = atof(first(merged["value"].to_string(), "0").c_str());
f64 vrange = max_value - min_value;
if(vrange == 0) vrange = 1;
s32 pct = (s32)std::max(0.0, std::min(100.0, ((value - min_value) / vrange) * 100.0));
String color = first(merged["color"].to_string(), "var(--primary)");
?>
= label ?>
= merged["value"].to_string() + unit ?>
if(tooltip != "") { ?>= tooltip ?>
} ?>
}); ?>
} ?>
if(context.call["listen"].to_string() != "") { ?>
} ?>
>
}
COMPONENT:NEEDLEGAUGE(Request& context)
{
starter_register_css("themes/common/css/gauges.css", context);
String gauge_id = first(context.call["id"].to_string(), "needlegauge-" + std::to_string((u64)time()));
String style = context.call["style"].to_string();
String title = context.call["title"].to_string();
String subtitle = context.call["subtitle"].to_string();
s32 size = (s32)int_val(first(context.call["size"].to_string(), "200"));
<>
if(title != "") { ?> } ?>
context.call["items"].each([&](DTree item, String item_id) {
String label = first(item["label"].to_string(), item_id);
String tooltip = item["tooltip"].to_string();
String unit = item["unit"].to_string();
f64 min_value = atof(first(item["min"].to_string(), "0").c_str());
f64 max_value = atof(first(item["max"].to_string(), "100").c_str());
f64 value = atof(first(item["value"].to_string(), "0").c_str());
f64 pct = (value - min_value) / (max_value - min_value == 0 ? 1.0 : (max_value - min_value));
pct = std::max(0.0, std::min(1.0, pct));
f64 angle = -2.6 + pct * 2.2;
?>
= label ?>
= item["value"].to_string() + unit ?>
if(tooltip != "") { ?>
= tooltip ?>
} ?>
}); ?>
if(context.call["listen"].to_string() != "") { ?>
} ?>
>
}
COMPONENT:ARCGAUGE(Request& context)
{
starter_register_js("components/gauges/common.js", context);
starter_register_css("themes/common/css/gauges.css", context);
String gauge_id = first(context.call["id"].to_string(), "arcgauge-" + std::to_string((u64)time()));
String title = context.call["title"].to_string();
String subtitle = context.call["subtitle"].to_string();
String style = context.call["style"].to_string();
<>
if(title != "") { ?> } ?>
context.call["items"].each([&](DTree item, String item_id) {
f64 value = atof(first(item["value"].to_string(), "0").c_str());
f64 max_value = atof(first(item["max"].to_string(), "100").c_str());
s32 precision = (s32)int_val(first(item["precision"].to_string(), "1"));
f64 pct = max_value > 0.0 ? std::max(0.0, std::min(100.0, (value / max_value) * 100.0)) : 0.0;
f64 arc_length = (pct / 100.0) * 157.08;
char buf[64];
snprintf(buf, sizeof(buf), ("%." + std::to_string(precision) + "f").c_str(), value);
?>
= first(item["label"].to_string(), item_id) ?>
= first(item["meta"].to_string(), "--") ?>
}); ?>
if(context.call["listen"].to_string() != "") { ?>
} ?>
>
}