Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Last Country in ImageGraph shows a wrong flag #13039

Closed
pcruhlm opened this issue Jun 6, 2018 · 4 comments · Fixed by #13041
Closed

Last Country in ImageGraph shows a wrong flag #13039

pcruhlm opened this issue Jun 6, 2018 · 4 comments · Fixed by #13041
Labels
Bug For errors / faults / flaws / inconsistencies etc. duplicate For issues that already existed in our issue tracker and were reported previously.
Milestone

Comments

@pcruhlm
Copy link

pcruhlm commented Jun 6, 2018

Hello i´m using the ImageGraph from the HTML API to show a horizontal bar graph image with the countries of the visitors. In this image the last entry always get a wrong flag (exception is if i have a high amount of countries that i get 'other' in the last row without a flag). The country is correct.
The actual version 3.5.1 of matomo is installed

image

image

If i use the dashboard to show the visitorr countries i get the identical number of visitors per country with the correct flags.

image

I use this code to call the image:

https://xxxxxxxxxxx.de/analytics/piwik/index.php?module=API&method=ImageGraph.get&idSite=1&apiModule=UserCountry&apiAction=getCountry&token_auth=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&graphType=horizontalBar&period=month&date=today&showLegend=1&width=700&height=460&fontSize=8&textColor=7f5500&backgroundColor=ffaa00&gridColor=7f5500&colors=7f0000&legendFontSize=8&alt=''

Is there a known issue in the ImageGrapf functionality or maybe i´ve done somethimg wrong?

@fdellwing
Copy link
Contributor

Ok, I debugged this and I'm pretty fucking confused...

I put two debug logs into plugins/ImageGraph/StaticGraph/HorizontalBar.php to track what exactly is happening...

error_log(print_r($this->abscissaLogos, true));

for ($i = 0; $i < $numberOfRows; $i++) {
	if (isset($this->abscissaLogos[$i])) {
		$logoPath = $this->abscissaLogos[$i];
		
		if ($i+1 == $numberOfRows) error_log(print_r($this->abscissaLogos, true));
		
		if (isset($logoPathToHeight[$logoPath])) {
			$logoHeight = $logoPathToHeight[$logoPath];

			$pathInfo = pathinfo($logoPath);
			$logoExtension = strtoupper($pathInfo['extension']);
			$drawingFunction = 'drawFrom' . $logoExtension;

			$logoYPosition =
				($logoInterleave * $i)
				+ $this->getGridTopMargin(true, $verticalLegend)
				+ $graphData['Axis'][1]['Margin']
				- $logoHeight / 2
				+ 1;

			if (method_exists($this->pImage, $drawingFunction)) {
				$this->pImage->$drawingFunction(
					$gridLeftMarginBeforePadding,
					$logoYPosition,
					$logoPath
				);
			}
		}
	}
}

Output:

PHP message: Array
(
    [0] => /var/www/piwik/tmp/assets/618acf5cf2f6d9786d10497b5f916da4.png
    [1] => /var/www/piwik/tmp/assets/0cfbd21e15d47179c65b9cfb3c1c0aae.png
    [2] => /var/www/piwik/tmp/assets/f4122cf44de3a2b36c0c9d4fade5fbad.png
    [3] => /var/www/piwik/tmp/assets/38e2f005d9dda18b9e2158ca6eb3955d.png
    [4] => /var/www/piwik/tmp/assets/e865535557881fd67d7f74f22755b1a7.png
    [5] => /var/www/piwik/tmp/assets/b270ed655f4506b887d52f0919f4a51b.png
)

PHP message: Array
(
    [0] => /var/www/piwik/tmp/assets/618acf5cf2f6d9786d10497b5f916da4.png
    [1] => /var/www/piwik/tmp/assets/0cfbd21e15d47179c65b9cfb3c1c0aae.png
    [2] => /var/www/piwik/tmp/assets/f4122cf44de3a2b36c0c9d4fade5fbad.png
    [3] => /var/www/piwik/tmp/assets/38e2f005d9dda18b9e2158ca6eb3955d.png
    [4] => /var/www/piwik/tmp/assets/e865535557881fd67d7f74f22755b1a7.png
    [5] => /var/www/piwik/tmp/assets/e865535557881fd67d7f74f22755b1a7.png
)

So the question is, what happens in $numberOfRows - 2 (second last iteration) that changes the $this->abscissaLogos array to contain the wrong value?

@fdellwing
Copy link
Contributor

fdellwing commented Jun 6, 2018

Ok I tracked it down to the line that breaks it: $logoPath = $this->abscissaLogos[$i];.

After this line is called the current $logoPath is set in $this->abscissaLogos[$i] AND $this->abscissaLogos[$numberOfRows - 1] (last index).

@pcruhlm
Copy link
Author

pcruhlm commented Jun 7, 2018

Hello. I did a little strange hack for some tests and got it working correctly (but i don´t know why the original code works wrong).

I changed the loop direction from "starting with the lowest index counting upwards" to "starting with the highest index counting downwards".

// for ($i = 0; $i < $numberOfRows; $i++) { // old counting upwards
for ($i = $numberOfRows-1; $i >= 0; $i--) { // new counting downwards

image

Thanks for Your help

Michael

@fdellwing
Copy link
Contributor

There is already a PR for this -> #13041

Your solution is no fix for this issue but a workaround. The array still breaks.

@diosmosis diosmosis added this to the 3.6.0 milestone Jun 7, 2018
@diosmosis diosmosis added the Bug For errors / faults / flaws / inconsistencies etc. label Jun 7, 2018
@mattab mattab added the duplicate For issues that already existed in our issue tracker and were reported previously. label Aug 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug For errors / faults / flaws / inconsistencies etc. duplicate For issues that already existed in our issue tracker and were reported previously.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants