-
New Feature Request
-
Resolution: Unresolved
-
Minor
-
None
-
6.0.10
-
None
I recently had some users ask if it was possible to hide items in the graph widget if the values for that item were all 0. Their use case made sense and it seems that Grafana and Kibana have this feature out of the box. It does appear to have some utility. I looked through the code and was able to create a mock-up that is also functional. I haven't submitted a pull request because I'm not sure that my changes fully fit the Zabbix coding style. But I've attached a screenshot of what it could look like along with the changes to the frontend code. Could this be implemented?
include/classes/widgets/forms/CWidgetFormSvgGraph.php
63 $field_exclude_zeros = (new CWidgetFieldCheckBox('suppress_zero_values', _('Suppress Zero Values')))->setDefault(SVG_GRAPH_SUPPRESS_ZEROS_FALSE);
64
65 if (array_key_exists('suppress_zero_values', $this->data))
68
69 $this->fields[$field_exclude_zeros->getName()] = $field_exclude_zeros;
include/classes/helpers/CSvgGraphHelper.php
62 if ($options['suppress_zero_values'] == SVG_GRAPH_SUPPRESS_ZEROS_TRUE) {
63 foreach ($metrics as $data => $metric) {
64 $all_zero = true;
65 foreach ($metric['points'] as $point) {
66 if (array_key_exists('value', $point)) {
67 if ($point['value'] != 0 && $point['value'] != 0.0)
71 }
72 }
73 if ($all_zero)
76 }
77 }
include/classes/widgets/views/widget.svggraph.form.view.php216 $tab_displaying_opt = (new CFormList())
217 ->addRow(CWidgetHelper::getLabel($fields['source'], null,
218 "when choosing 'Trends', aggregation interval must be minimum of 1h if using aggregation functions"),
219 CWidgetHelper::getRadioButtonList($fields['source'], $form_name)
220 )
221 ->addRow(CWidgetHelper::getLabel($fields['suppress_zero_values'], null,
222 "selecting this option will remove metrics where all values are 0 for the selected time-picker period"),
223 CWidgetHelper::getCheckBox($fields['suppress_zero_values'])
224 );
include/defines.inc.php
define('SVG_GRAPH_SUPPRESS_ZEROS_TRUE', 1);
define('SVG_GRAPH_SUPPRESS_ZEROS_FALSE', 0);
app/controllers/CControllerWidgetSvgGraphView.php
63 'suppress_zero_values' => $fields['suppress_zero_values'],
js/class.tab-indicators.js
1233 class GraphOptionsTabIndicatorItem extends TabIndicatorItem {
1234
1235 constructor()
1238
1239 getValue() {
1240 const element = document.querySelector("[name='source']:checked");
1241 const suppress_zero_values = document.getElementById('suppress_zero_values');
1242
1243 if (element !== null && element.value > 0)
1246
1247 if (suppress_zero_values !== null && suppress_zero_values.checked)
1250
1251 return false;
1252 }
1253
1254 initObserver() {
1255 document.getElementById('tabs').addEventListener(TAB_INDICATOR_UPDATE_EVENT, () =>
);
1258 }