Uploaded image for project: 'ZABBIX BUGS AND ISSUES'
  1. ZABBIX BUGS AND ISSUES
  2. ZBX-23253

SVG Graph Hint Box Does Not Display Unit Overrides Correctly

XMLWordPrintable

    • Sprint 103 (Aug 2023)
    • 0.25

      Steps to reproduce:

      1. Create an SVG Graph, select a metric to plot in the graph
      2. On the Axes tab, set a static unit that is different from the original unit of the metric.
      3. Note that the legend on the bottom and the values in the Hint Box in the widget grid will display the original units of the metric, not the 'Static' override

       

      I've gone through the code, and I think I have a prototype of a fix. These changes pass in the $options['axes'] array which is used to check if a static unit was set for both the left and right y-axis. In the if-construct it appears we need to update both the $metrics array and the $item array, since the $metrics array is used by the javascript for the HintBox and the $item array is what is shown in the legend underneath the x-axis in the widget grid. Hopefully this makes sense...

      I'm not the best at PHP,but the following diffs were able to produce what I expect to occur in the SVG Graph widget:

      diff --git a/ui/include/classes/helpers/CSvgGraphHelper.php b/ui/include/classes/helpers/CSvgGraphHelper.php
      index d12e5c230e7..97b249bc85d 100644
      --- a/ui/include/classes/helpers/CSvgGraphHelper.php
      +++ b/ui/include/classes/helpers/CSvgGraphHelper.php
      @@ -63,7 +63,7 @@ class CSvgGraphHelper {
                      // Load aggregated Data for each dataset.
                      self::getMetricsAggregatedData($metrics, $width, $options['data_sets']);
       
      -               $legend = self::getLegend($metrics, $options['legend']);
      +               $legend = self::getLegend($metrics, $options['legend'], $options['axes']);
       
                      $svg_height = $height - ($legend !== null ? $legend->getLinesCount() * CSvgGraphLegend::LINE_HEIGHT : 0);
       
      @@ -703,19 +703,32 @@ class CSvgGraphHelper {
                      }
              }
       
      -       private static function getLegend(array $metrics, array $legend_options): ?CSvgGraphLegend {
      +       private static function getLegend(array &$metrics, array $legend_options, array $axes_options): ?CSvgGraphLegend {
                      if ($legend_options['show_legend'] != SVG_GRAPH_LEGEND_ON) {
                              return null;
                      }
       
                      $items = [];
       
      -               foreach ($metrics as $metric) {
      +               foreach ($metrics as $index => &$metric) {
                              $item = [
                                      'name' => $metric['name'],
                                      'color' => $metric['options']['color']
                              ];
       
      +                       $yaxis = $metric['options']['axisy'];
      +                       if ($yaxis == GRAPH_YAXIS_SIDE_RIGHT && isset($axes_options['right_y_units'])) {
      +                               $units = $axes_options['right_y_units'];
      +                               $metrics[$index]['units'] = $axes_options['right_y_units'];
      +                       }
      +                       elseif ($yaxis == GRAPH_YAXIS_SIDE_LEFT && isset($axes_options['left_y_units'])) {
      +                               $units = $axes_options['left_y_units'];
      +                               $metrics[$index]['units'] = $axes_options['left_y_units'];
      +                       }
      +                       else {
      +                               $units = $metric['units'];
      +                       }
      +
                              if ($metric['points']) {
                                      switch ($metric['options']['approximation']) {
                                              case APPROXIMATION_MIN:
      @@ -729,7 +742,7 @@ class CSvgGraphHelper {
                                      }
       
                                      $item += [
      -                                       'units' => $metric['units'],
      +                                       'units' => $units,
                                              'min' => min($values),
                                              'avg' => array_sum($values) / count($values),
                                              'max' => max($values)

       

       

            HunterCRS Alexander Shubin
            GRyan337 Ryan Eberly
            Team A
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: