diff options
author | Andrejs Verza <andrejs.verza@zabbix.com> | 2022-07-08 13:24:01 +0300 |
---|---|---|
committer | Andrejs Verza <andrejs.verza@zabbix.com> | 2022-07-08 13:26:09 +0300 |
commit | fb986df78a91a956232d3fa3b98da641c89ec4e2 (patch) | |
tree | 6ce3944810794666020b2606468229be29154afd | |
parent | ecf5c53725b806f2461eeb692bf022bc488f413e (diff) |
..F....... [ZBX-18957] fixed not displaying years on X axis of classic graphs
Merge in ZBX/zabbix from feature/ZBX-18957-5.0 to release/5.0
* commit 'f595bf2a06151ad1af4f131f0be6cac7cb4531f5':
..F....... [ZBX-18957] fixed not displaying years on X axis of classic graphs
(cherry picked from commit 9f69cc0f03e5c3efc65f808cbcf3a7f8a847f4d5)
-rw-r--r-- | ChangeLog.d/bugfix/ZBX-18957 | 1 | ||||
-rw-r--r-- | ui/include/classes/graphdraw/CLineGraphDraw.php | 22 |
2 files changed, 16 insertions, 7 deletions
diff --git a/ChangeLog.d/bugfix/ZBX-18957 b/ChangeLog.d/bugfix/ZBX-18957 new file mode 100644 index 00000000000..3e445a962c6 --- /dev/null +++ b/ChangeLog.d/bugfix/ZBX-18957 @@ -0,0 +1 @@ +..F....... [ZBX-18957] fixed not displaying years on X axis of classic graphs (averza) diff --git a/ui/include/classes/graphdraw/CLineGraphDraw.php b/ui/include/classes/graphdraw/CLineGraphDraw.php index a4988b1e782..585fe26262f 100644 --- a/ui/include/classes/graphdraw/CLineGraphDraw.php +++ b/ui/include/classes/graphdraw/CLineGraphDraw.php @@ -930,12 +930,14 @@ class CLineGraphDraw extends CGraphDraw { /** * Get best matching X-axis interval specification for the preferred sub-interval. * - * @param int $pref_sub_interval Preferred sub-interval in seconds. - * @param float $min_sub_interval Preferred minimal sub-interval in seconds (float). Discarded if no matches. + * @param int $pref_sub_interval Preferred sub-interval in seconds. + * @param float $min_sub_interval Preferred minimal sub-interval in seconds (float). Discarded if no matches. + * @param string $magnitude The highest non-permanent date component (Y, m, d, H, i, s). * * @return array */ - private function getOptimalDateTimeIntervalSpec(int $pref_sub_interval, float $min_sub_interval): array { + private function getOptimalDateTimeIntervalSpec(int $pref_sub_interval, float $min_sub_interval, + string $magnitude): array { // Possible X-axis main and sub-intervals. $intervals = [ 'PT1M' => ['PT1S', 'PT5S', 'PT10S', 'PT30S'], @@ -962,9 +964,9 @@ class CLineGraphDraw extends CGraphDraw { $formats = [ 'PT1M' => ['main' => TIME_FORMAT, 'sub' => _('H:i:s')], 'PT1H' => ['main' => TIME_FORMAT, 'sub' => TIME_FORMAT], - 'P1D' => ['main' => _('m-d'), 'sub' => TIME_FORMAT], - 'P1W' => ['main' => _('m-d'), 'sub' => _('m-d')], - 'P1M' => ['main' => _('m-d'), 'sub' => _('m-d')], + 'P1D' => ['main' => $magnitude === 'Y' ? DATE_FORMAT : _('m-d'), 'sub' => TIME_FORMAT], + 'P1W' => ['main' => $magnitude === 'Y' ? DATE_FORMAT : _('m-d'), 'sub' => _('m-d')], + 'P1M' => ['main' => $magnitude === 'Y' ? DATE_FORMAT : _('m-d'), 'sub' => _('m-d')], 'P1Y' => ['main' => _x('Y', DATE_FORMAT_CONTEXT), 'sub' => _('M')], 'P10Y' => ['main' => _x('Y', DATE_FORMAT_CONTEXT), 'sub' => _x('Y', DATE_FORMAT_CONTEXT)] ]; @@ -1082,7 +1084,13 @@ class CLineGraphDraw extends CGraphDraw { $preferred_sub_interval = (int) ($this->period * $this->cell_width / $this->sizeX); - $optimal = $this->getOptimalDateTimeIntervalSpec($preferred_sub_interval, $label_size); + foreach (['Y', 'm', 'd', 'H', 'i', 's'] as $magnitude) { + if (date($magnitude, $this->stime) !== date($magnitude, $this->stime + $this->period)) { + break; + } + } + + $optimal = $this->getOptimalDateTimeIntervalSpec($preferred_sub_interval, $label_size, $magnitude); // Align starting date and time with the interval. $start = strtotime(date($optimal['aligner']['trim'], $this->stime)); |