Skip to content

Commit f92c8fd

Browse files
committed
MAGETWO-98584: Google chart API used by Magento dashboard scheduled to be turned off
1 parent 77297a1 commit f92c8fd

File tree

1 file changed

+21
-59
lines changed
  • app/code/Magento/Backend/Block/Dashboard

1 file changed

+21
-59
lines changed

app/code/Magento/Backend/Block/Dashboard/Graph.php

Lines changed: 21 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Graph extends \Magento\Backend\Block\Dashboard\AbstractDashboard
1515
/**
1616
* Api URL
1717
*/
18-
const API_URL = 'http://chart.apis.google.com/chart';
18+
const API_URL = 'https://image-charts.com/chart';
1919

2020
/**
2121
* All series
@@ -76,6 +76,7 @@ class Graph extends \Magento\Backend\Block\Dashboard\AbstractDashboard
7676
/**
7777
* Google chart api data encoding
7878
*
79+
* @deprecated since the Google Image Charts API not accessible from March 14, 2019
7980
* @var string
8081
*/
8182
protected $_encoding = 'e';
@@ -187,11 +188,12 @@ public function getChartUrl($directUrl = true)
187188
{
188189
$params = [
189190
'cht' => 'lc',
190-
'chf' => 'bg,s,ffffff',
191-
'chco' => 'ef672f',
192191
'chls' => '7',
193-
'chxs' => '0,676056,15,0,l,676056|1,676056,15,0,l,676056',
194-
'chm' => 'h,f2ebde,0,0:1:.1,1,-1',
192+
'chf' => 'bg,s,f4f4f4|c,lg,90,ffffff,0.1,ededed,0',
193+
'chm' => 'B,f4d4b2,0,0,0',
194+
'chco' => 'db4814',
195+
'chxs' => '0,0,11|1,0,11',
196+
'chma' => '15,15,15,15'
195197
];
196198

197199
$this->_allSeries = $this->getRowsData($this->_dataRows);
@@ -279,20 +281,11 @@ public function getChartUrl($directUrl = true)
279281
$this->_axisLabels['x'] = $dates;
280282
$this->_allSeries = $datas;
281283

282-
//Google encoding values
283-
if ($this->_encoding == "s") {
284-
// simple encoding
285-
$params['chd'] = "s:";
286-
$dataDelimiter = "";
287-
$dataSetdelimiter = ",";
288-
$dataMissing = "_";
289-
} else {
290-
// extended encoding
291-
$params['chd'] = "e:";
292-
$dataDelimiter = "";
293-
$dataSetdelimiter = ",";
294-
$dataMissing = "__";
295-
}
284+
// Image-Charts Awesome data format values
285+
$params['chd'] = "a:";
286+
$dataDelimiter = ",";
287+
$dataSetdelimiter = "|";
288+
$dataMissing = "_";
296289

297290
// process each string in the array, and find the max length
298291
$localmaxvalue = [0];
@@ -306,7 +299,6 @@ public function getChartUrl($directUrl = true)
306299
$minvalue = min($localminvalue);
307300

308301
// default values
309-
$yrange = 0;
310302
$yLabels = [];
311303
$miny = 0;
312304
$maxy = 0;
@@ -321,52 +313,20 @@ public function getChartUrl($directUrl = true)
321313
$maxy = ceil($maxvalue + 1);
322314
$yLabels = range($miny, $maxy, 1);
323315
}
324-
$yrange = $maxy;
325316
$yorigin = 0;
326317
}
327318

328319
$chartdata = [];
329320

330321
foreach ($this->getAllSeries() as $index => $serie) {
331322
$thisdataarray = $serie;
332-
if ($this->_encoding == "s") {
333-
// SIMPLE ENCODING
334-
for ($j = 0; $j < sizeof($thisdataarray); $j++) {
335-
$currentvalue = $thisdataarray[$j];
336-
if (is_numeric($currentvalue)) {
337-
$ylocation = round(
338-
(strlen($this->_simpleEncoding) - 1) * ($yorigin + $currentvalue) / $yrange
339-
);
340-
$chartdata[] = substr($this->_simpleEncoding, $ylocation, 1) . $dataDelimiter;
341-
} else {
342-
$chartdata[] = $dataMissing . $dataDelimiter;
343-
}
344-
}
345-
} else {
346-
// EXTENDED ENCODING
347-
for ($j = 0; $j < sizeof($thisdataarray); $j++) {
348-
$currentvalue = $thisdataarray[$j];
349-
if (is_numeric($currentvalue)) {
350-
if ($yrange) {
351-
$ylocation = 4095 * ($yorigin + $currentvalue) / $yrange;
352-
} else {
353-
$ylocation = 0;
354-
}
355-
$firstchar = floor($ylocation / 64);
356-
$secondchar = $ylocation % 64;
357-
$mappedchar = substr(
358-
$this->_extendedEncoding,
359-
$firstchar,
360-
1
361-
) . substr(
362-
$this->_extendedEncoding,
363-
$secondchar,
364-
1
365-
);
366-
$chartdata[] = $mappedchar . $dataDelimiter;
367-
} else {
368-
$chartdata[] = $dataMissing . $dataDelimiter;
369-
}
323+
for ($j = 0; $j < sizeof($thisdataarray); $j++) {
324+
$currentvalue = $thisdataarray[$j];
325+
if (is_numeric($currentvalue)) {
326+
$ylocation = $yorigin + $currentvalue;
327+
$chartdata[] = $ylocation . $dataDelimiter;
328+
} else {
329+
$chartdata[] = $dataMissing . $dataDelimiter;
370330
}
371331
}
372332
$chartdata[] = $dataSetdelimiter;
@@ -540,6 +500,8 @@ protected function getHeight()
540500
}
541501

542502
/**
503+
* Sets data helper
504+
*
543505
* @param \Magento\Backend\Helper\Dashboard\AbstractDashboard $dataHelper
544506
* @return void
545507
*/

0 commit comments

Comments
 (0)