@pcruhlm opened this Issue on June 6th 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 commented on June 6th 2018 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 commented on June 6th 2018 Contributor

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 commented on June 7th 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 commented on June 7th 2018 Contributor

There is already a PR for this -> #13041

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

This Issue was closed on June 10th 2018
Powered by GitHub Issue Mirror