From ed9c607f01c4f03617e74a44020ae2068fe52431 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Kr=C3=B6g?= Date: Sat, 3 Dec 2022 01:14:15 +0100 Subject: [PATCH 1/2] Fix centering of gis data in plot MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The image was not centered because the border (either x or y) was not included in the calculation Signed-off-by: Maximilian Krög --- libraries/classes/Gis/GisVisualization.php | 4 ++-- psalm-baseline.xml | 8 ++++---- test/classes/Gis/GisVisualizationTest.php | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/libraries/classes/Gis/GisVisualization.php b/libraries/classes/Gis/GisVisualization.php index b9abe2708b..8f33256c72 100644 --- a/libraries/classes/Gis/GisVisualization.php +++ b/libraries/classes/Gis/GisVisualization.php @@ -608,14 +608,14 @@ class GisVisualization if ($x_ratio < $y_ratio) { // center horizontally - $x = ($min_max['maxX'] + $min_max['minX'] - $plot_width / $scale) / 2; + $x = ($min_max['maxX'] + $min_max['minX'] - $this->settings['width'] / $scale) / 2; // fit vertically $y = $min_max['minY'] - ($border / $scale); } else { // fit horizontally $x = $min_max['minX'] - ($border / $scale); // center vertically - $y = ($min_max['maxY'] + $min_max['minY'] - $plot_height / $scale) / 2; + $y = ($min_max['maxY'] + $min_max['minY'] - $this->settings['height'] / $scale) / 2; } return [ diff --git a/psalm-baseline.xml b/psalm-baseline.xml index ae47a9bebc..328f9db5a4 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -7569,11 +7569,9 @@ $border / $scale $border / $scale - $min_max['maxX'] + $min_max['minX'] - $plot_width / $scale - $min_max['maxY'] + $min_max['minY'] - $plot_height / $scale + $min_max['maxX'] + $min_max['minX'] - $this->settings['width'] / $scale + $min_max['maxY'] + $min_max['minY'] - $this->settings['height'] / $scale $plot_height - $plot_height - $plot_width $plot_width $ratio $scale @@ -7581,6 +7579,8 @@ $this->prepareDataSet($this->data, $scale_data, 'ol', '') $this->prepareDataSet($this->data, $scale_data, 'svg', '') $this->settings['height'] + $this->settings['height'] + $this->settings['width'] $this->settings['width'] diff --git a/test/classes/Gis/GisVisualizationTest.php b/test/classes/Gis/GisVisualizationTest.php index 6e234458c5..5d2c9e4fbc 100644 --- a/test/classes/Gis/GisVisualizationTest.php +++ b/test/classes/Gis/GisVisualizationTest.php @@ -43,7 +43,7 @@ class GisVisualizationTest extends AbstractTestCase [ 'scale' => 1, 'x' => -15.0, - 'y' => -210.0, + 'y' => -225.0, 'minX' => 0.0, 'maxX' => 0.0, 'minY' => 0.0, @@ -69,7 +69,7 @@ class GisVisualizationTest extends AbstractTestCase $this->assertSame( [ 'scale' => 2.1, - 'x' => -38.21428571428572, + 'x' => -45.35714285714286, 'y' => 42.85714285714286, 'minX' => 17.0, 'maxX' => 178.0, From a90cff2f7fc6c2ad392a339df34b49d72a97a752 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Kr=C3=B6g?= Date: Sat, 10 Dec 2022 20:13:16 +0100 Subject: [PATCH 2/2] Fix centering of gis plot MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the ratio in one or both dimensions is zero (all points at the same width or height) place it in the center. Signed-off-by: Maximilian Krög --- libraries/classes/Gis/GisVisualization.php | 18 +++++++----------- psalm-baseline.xml | 4 +--- test/classes/Gis/GisVisualizationTest.php | 2 +- 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/libraries/classes/Gis/GisVisualization.php b/libraries/classes/Gis/GisVisualization.php index 8f33256c72..af53773baa 100644 --- a/libraries/classes/Gis/GisVisualization.php +++ b/libraries/classes/Gis/GisVisualization.php @@ -606,17 +606,13 @@ class GisVisualization $scale = $ratio != 0 ? 1 / $ratio : 1; - if ($x_ratio < $y_ratio) { - // center horizontally - $x = ($min_max['maxX'] + $min_max['minX'] - $this->settings['width'] / $scale) / 2; - // fit vertically - $y = $min_max['minY'] - ($border / $scale); - } else { - // fit horizontally - $x = $min_max['minX'] - ($border / $scale); - // center vertically - $y = ($min_max['maxY'] + $min_max['minY'] - $this->settings['height'] / $scale) / 2; - } + // Center plot + $x = $ratio == 0 || $x_ratio < $y_ratio + ? ($min_max['maxX'] + $min_max['minX'] - $this->settings['width'] / $scale) / 2 + : $min_max['minX'] - ($border / $scale); + $y = $ratio == 0 || $x_ratio >= $y_ratio + ? ($min_max['maxY'] + $min_max['minY'] - $this->settings['height'] / $scale) / 2 + : $min_max['minY'] - ($border / $scale); return [ 'scale' => $scale, diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 328f9db5a4..40ddebd805 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -7546,7 +7546,7 @@ $row[$this->settings['spatialColumn']] $row[$this->settings['spatialColumn']] - + $label $pdf $plot_height @@ -7557,10 +7557,8 @@ $row $scale $x - $x $x_ratio $y - $y $y_ratio diff --git a/test/classes/Gis/GisVisualizationTest.php b/test/classes/Gis/GisVisualizationTest.php index 5d2c9e4fbc..617d8397b2 100644 --- a/test/classes/Gis/GisVisualizationTest.php +++ b/test/classes/Gis/GisVisualizationTest.php @@ -42,7 +42,7 @@ class GisVisualizationTest extends AbstractTestCase $this->assertSame( [ 'scale' => 1, - 'x' => -15.0, + 'x' => -300.0, 'y' => -225.0, 'minX' => 0.0, 'maxX' => 0.0,