Added last value in StaticGraph
Former-commit-id: 1cdf967b8bb05eff14b22684e8960c60d5b1d397
This commit is contained in:
parent
73e5dcf7f2
commit
7ddc4a70f1
|
@ -47,6 +47,10 @@ final class StaticGraph extends Item
|
||||||
static::issetInArray($data, ['statusImageSrc']),
|
static::issetInArray($data, ['statusImageSrc']),
|
||||||
null
|
null
|
||||||
);
|
);
|
||||||
|
$return['lastValue'] = static::notEmptyStringOr(
|
||||||
|
static::issetInArray($data, ['lastValue']),
|
||||||
|
null
|
||||||
|
);
|
||||||
|
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
@ -174,6 +178,35 @@ final class StaticGraph extends Item
|
||||||
// Get the img src.
|
// Get the img src.
|
||||||
$data['statusImageSrc'] = \visual_map_get_image_status_element($data);
|
$data['statusImageSrc'] = \visual_map_get_image_status_element($data);
|
||||||
|
|
||||||
|
// Get last value.
|
||||||
|
if (isset($data['show_last_value']) && $data['show_last_value'] !== 2) {
|
||||||
|
$img_style_title = '';
|
||||||
|
|
||||||
|
$unit_text = \trim(
|
||||||
|
\io_safe_output(
|
||||||
|
\modules_get_unit($moduleId)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$value = \modules_get_last_value($moduleId);
|
||||||
|
|
||||||
|
if ((!\modules_is_boolean($moduleId))
|
||||||
|
|| (\modules_is_boolean($moduleId) && $data['show_last_value'] != 0)
|
||||||
|
) {
|
||||||
|
if (\is_numeric($value)) {
|
||||||
|
$img_style_title .= __('Last value: ').remove_right_zeros($value);
|
||||||
|
} else {
|
||||||
|
$img_style_title .= __('Last value: ').$value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($unit_text) === false && empty($img_style_title) === false) {
|
||||||
|
$img_style_title .= ' '.$unit_text;
|
||||||
|
}
|
||||||
|
|
||||||
|
$data['lastValue'] = $img_style_title;
|
||||||
|
}
|
||||||
|
|
||||||
// Restore connection.
|
// Restore connection.
|
||||||
if ($nodeConnected === true) {
|
if ($nodeConnected === true) {
|
||||||
\metaconsole_restore_db();
|
\metaconsole_restore_db();
|
||||||
|
|
|
@ -16,6 +16,7 @@ export type StaticGraphProps = {
|
||||||
imageSrc: string; // URL?
|
imageSrc: string; // URL?
|
||||||
showLastValueTooltip: "default" | "enabled" | "disabled";
|
showLastValueTooltip: "default" | "enabled" | "disabled";
|
||||||
statusImageSrc: string | null; // URL?
|
statusImageSrc: string | null; // URL?
|
||||||
|
lastValue: string | null;
|
||||||
} & ItemProps &
|
} & ItemProps &
|
||||||
(WithModuleProps | LinkedVisualConsoleProps);
|
(WithModuleProps | LinkedVisualConsoleProps);
|
||||||
|
|
||||||
|
@ -58,6 +59,7 @@ export function staticGraphPropsDecoder(
|
||||||
imageSrc: data.imageSrc,
|
imageSrc: data.imageSrc,
|
||||||
showLastValueTooltip: parseShowLastValueTooltip(data.showLastValueTooltip),
|
showLastValueTooltip: parseShowLastValueTooltip(data.showLastValueTooltip),
|
||||||
statusImageSrc: notEmptyStringOr(data.statusImageSrc, null),
|
statusImageSrc: notEmptyStringOr(data.statusImageSrc, null),
|
||||||
|
lastValue: notEmptyStringOr(data.lastValue, null),
|
||||||
...modulePropsDecoder(data), // Object spread. It will merge the properties of the two objects.
|
...modulePropsDecoder(data), // Object spread. It will merge the properties of the two objects.
|
||||||
...linkedVCPropsDecoder(data) // Object spread. It will merge the properties of the two objects.
|
...linkedVCPropsDecoder(data) // Object spread. It will merge the properties of the two objects.
|
||||||
};
|
};
|
||||||
|
@ -69,7 +71,16 @@ export default class StaticGraph extends Item<StaticGraphProps> {
|
||||||
img.className = "static-graph";
|
img.className = "static-graph";
|
||||||
img.src = this.props.statusImageSrc || this.props.imageSrc;
|
img.src = this.props.statusImageSrc || this.props.imageSrc;
|
||||||
|
|
||||||
// TODO: Show last value in a tooltip.
|
// Show last value in a tooltip.
|
||||||
|
if (
|
||||||
|
this.props.lastValue !== null &&
|
||||||
|
this.props.showLastValueTooltip !== "disabled"
|
||||||
|
) {
|
||||||
|
img.className = "static-graph image forced_title";
|
||||||
|
img.setAttribute("data-use_title_for_force_title", "1");
|
||||||
|
img.setAttribute("data-title", this.props.lastValue);
|
||||||
|
img.alt = this.props.lastValue;
|
||||||
|
}
|
||||||
|
|
||||||
return img;
|
return img;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue