refactor: rename DTree to DValue
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
COMPONENT(Request& context)
|
||||
{
|
||||
DTree asset_props;
|
||||
DValue asset_props;
|
||||
asset_props["css"]["0"] = "themes/common/css/gauges.css";
|
||||
asset_props["js"]["0"] = "components/gauges/common.js";
|
||||
print(component("../theme/assets", asset_props, context));
|
||||
@@ -11,7 +11,7 @@ COMPONENT(Request& context)
|
||||
String title = context.props["title"].to_string();
|
||||
String subtitle = context.props["subtitle"].to_string();
|
||||
String style = context.props["style"].to_string();
|
||||
DTree scale = context.props["scale"];
|
||||
DValue scale = context.props["scale"];
|
||||
|
||||
<>
|
||||
<div class="arcgauge-set" id="<?= gauge_attr_id(gauge_id) ?>" style="<?= style ?>">
|
||||
@@ -22,9 +22,9 @@ COMPONENT(Request& context)
|
||||
</div>
|
||||
<? } ?>
|
||||
<div class="arcgauge-grid">
|
||||
<? context.props["items"].each([&](DTree item, String item_id_raw) {
|
||||
DTree merged = scale;
|
||||
item.each([&](DTree value, String key) { merged[key] = value; });
|
||||
<? context.props["items"].each([&](DValue item, String item_id_raw) {
|
||||
DValue merged = scale;
|
||||
item.each([&](DValue value, String key) { merged[key] = value; });
|
||||
String item_id = gauge_attr_id(item_id_raw);
|
||||
f64 value = float_val(first(merged["value"].to_string(), "0"));
|
||||
f64 max_value = float_val(first(merged["max"].to_string(), "100"));
|
||||
|
||||
@@ -21,10 +21,10 @@ String gauge_attr_id(String value)
|
||||
return(ascii_safe_name(value));
|
||||
}
|
||||
|
||||
String gauge_range_color(DTree ranges, f64 value)
|
||||
String gauge_range_color(DValue ranges, f64 value)
|
||||
{
|
||||
String matched = "";
|
||||
ranges.each([&](DTree range, String key) {
|
||||
ranges.each([&](DValue range, String key) {
|
||||
f64 from_value = float_val(first(range["from"].to_string(), "-999999999"));
|
||||
f64 to_value = float_val(first(range["to"].to_string(), "999999999"));
|
||||
if(value >= from_value && value <= to_value && matched == "")
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
COMPONENT(Request& context)
|
||||
{
|
||||
DTree asset_props;
|
||||
DValue asset_props;
|
||||
asset_props["css"]["0"] = "themes/common/css/gauges.css";
|
||||
asset_props["js"]["0"] = "components/gauges/common.js";
|
||||
print(component("../theme/assets", asset_props, context));
|
||||
@@ -12,7 +12,7 @@ COMPONENT(Request& context)
|
||||
String title = context.props["title"].to_string();
|
||||
String subtitle = context.props["subtitle"].to_string();
|
||||
f64 size = float_val(first(context.props["size"].to_string(), "200"));
|
||||
DTree scale = context.props["scale"];
|
||||
DValue scale = context.props["scale"];
|
||||
f64 scale_angle_start = float_val(first(scale["angle_start"].to_string(), std::to_string(-gauge_pi())));
|
||||
f64 scale_angle_end = float_val(first(scale["angle_end"].to_string(), "0"));
|
||||
f64 img_height = float_val(first(context.props["img_height"].to_string(), std::to_string(size * std::max(cos(scale_angle_start), cos(scale_angle_end)))));
|
||||
@@ -26,9 +26,9 @@ COMPONENT(Request& context)
|
||||
</div>
|
||||
<? } ?>
|
||||
<div class="needlegauge-grid">
|
||||
<? context.props["items"].each([&](DTree item, String item_id_raw) {
|
||||
DTree merged = scale;
|
||||
item.each([&](DTree value, String key) { merged[key] = value; });
|
||||
<? context.props["items"].each([&](DValue item, String item_id_raw) {
|
||||
DValue merged = scale;
|
||||
item.each([&](DValue value, String key) { merged[key] = value; });
|
||||
String item_id = gauge_attr_id(item_id_raw);
|
||||
String label = first(merged["label"].to_string(), item_id_raw);
|
||||
String tooltip = merged["tooltip"].to_string();
|
||||
@@ -85,7 +85,7 @@ COMPONENT(Request& context)
|
||||
String segments_html = "";
|
||||
if(merged["color"].get_type_name() == "array")
|
||||
{
|
||||
merged["color"].each([&](DTree range, String key) {
|
||||
merged["color"].each([&](DValue range, String key) {
|
||||
f64 range_from = std::max(float_val(first(range["from"].to_string(), std::to_string(min_value))), min_value);
|
||||
f64 range_to = std::min(float_val(first(range["to"].to_string(), std::to_string(max_value))), max_value);
|
||||
f64 angle_from = angle_start + ((range_from - min_value) / vrange) * (angle_end - angle_start);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
COMPONENT(Request& context)
|
||||
{
|
||||
DTree asset_props;
|
||||
DValue asset_props;
|
||||
asset_props["css"]["0"] = "themes/common/css/gauges.css";
|
||||
asset_props["js"]["0"] = "components/gauges/common.js";
|
||||
print(component("../theme/assets", asset_props, context));
|
||||
@@ -17,8 +17,8 @@ COMPONENT(Request& context)
|
||||
String subtitle = context.props["subtitle"].to_string();
|
||||
String layout = first(context.props["layout"].to_string(), "horizontal");
|
||||
String bar_color_default = context.props["bar-color"].to_string();
|
||||
DTree scale = context.props["scale"];
|
||||
DTree markers = context.props["markers"];
|
||||
DValue scale = context.props["scale"];
|
||||
DValue markers = context.props["markers"];
|
||||
|
||||
StringList default_palette;
|
||||
default_palette.push_back("var(--success, #10b981)");
|
||||
@@ -37,9 +37,9 @@ COMPONENT(Request& context)
|
||||
<? } ?>
|
||||
<? if(layout == "horizontal") { ?>
|
||||
<div class="progressbar-grid progressbar-grid-horizontal">
|
||||
<? context.props["items"].each([&](DTree bar, String bar_id) {
|
||||
DTree merged = scale;
|
||||
bar.each([&](DTree item, String key) { merged[key] = item; });
|
||||
<? context.props["items"].each([&](DValue bar, String bar_id) {
|
||||
DValue merged = scale;
|
||||
bar.each([&](DValue item, String key) { merged[key] = item; });
|
||||
String item_id = gauge_attr_id(bar_id);
|
||||
String merged_item_style = item_style;
|
||||
if(merged["style"].to_string() != "")
|
||||
@@ -73,7 +73,7 @@ COMPONENT(Request& context)
|
||||
<div class="progressbar-background progressbar-background-horizontal">
|
||||
<div class="progressbar-bar" id="<?= gauge_attr_id(gauge_id) ?>-<?= item_id ?>-bar"
|
||||
style="background-color: <?= resolved_color ?>; <?= bar_style ?> opacity: <?= opacity ?>; width: <?= std::to_string(pct_value) ?>%;"></div>
|
||||
<? markers.each([&](DTree marker, String marker_id) {
|
||||
<? markers.each([&](DValue marker, String marker_id) {
|
||||
f64 marker_value = float_val(first(marker["value"].to_string(), "0"));
|
||||
f64 marker_pct = gauge_clamp_value(((marker_value - min_value) / vrange) * 100.0, 0.0, 100.0);
|
||||
String marker_color = first(marker["color"].to_string(), "var(--primary-light)");
|
||||
@@ -89,9 +89,9 @@ COMPONENT(Request& context)
|
||||
</div>
|
||||
<? } else { ?>
|
||||
<div class="progressbar-grid progressbar-grid-vertical" style="--progressbar-height: <?= first(context.props["height"].to_string(), "240") ?>px;">
|
||||
<? context.props["items"].each([&](DTree bar, String bar_id) {
|
||||
DTree merged = scale;
|
||||
bar.each([&](DTree item, String key) { merged[key] = item; });
|
||||
<? context.props["items"].each([&](DValue bar, String bar_id) {
|
||||
DValue merged = scale;
|
||||
bar.each([&](DValue item, String key) { merged[key] = item; });
|
||||
String item_id = gauge_attr_id(bar_id);
|
||||
String merged_item_style = item_style;
|
||||
if(merged["style"].to_string() != "")
|
||||
@@ -122,7 +122,7 @@ COMPONENT(Request& context)
|
||||
<div class="progressbar-background progressbar-background-vertical">
|
||||
<div class="progressbar-bar" id="<?= gauge_attr_id(gauge_id) ?>-<?= item_id ?>-bar"
|
||||
style="background-color: <?= resolved_color ?>; <?= bar_style ?> opacity: <?= opacity ?>; height: <?= std::to_string(pct_value) ?>%;"></div>
|
||||
<? markers.each([&](DTree marker, String marker_id) {
|
||||
<? markers.each([&](DValue marker, String marker_id) {
|
||||
f64 marker_value = float_val(first(marker["value"].to_string(), "0"));
|
||||
f64 marker_pct = gauge_clamp_value(((marker_value - min_value) / vrange) * 100.0, 0.0, 100.0);
|
||||
String marker_color = first(marker["color"].to_string(), "var(--primary-light)");
|
||||
|
||||
Reference in New Issue
Block a user