3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
+ declare (strict_types=1 );
7
+
6
8
namespace Magento \Backend \Block \Dashboard ;
7
9
8
10
/**
@@ -15,7 +17,7 @@ class Graph extends \Magento\Backend\Block\Dashboard\AbstractDashboard
15
17
/**
16
18
* Api URL
17
19
*/
18
- const API_URL = 'http ://chart.apis.google .com/chart ' ;
20
+ const API_URL = 'https ://image-charts .com/chart ' ;
19
21
20
22
/**
21
23
* All series
@@ -76,6 +78,7 @@ class Graph extends \Magento\Backend\Block\Dashboard\AbstractDashboard
76
78
/**
77
79
* Google chart api data encoding
78
80
*
81
+ * @deprecated since the Google Image Charts API not accessible from March 14, 2019
79
82
* @var string
80
83
*/
81
84
protected $ _encoding = 'e ' ;
@@ -187,11 +190,12 @@ public function getChartUrl($directUrl = true)
187
190
{
188
191
$ params = [
189
192
'cht ' => 'lc ' ,
190
- 'chf ' => 'bg,s,ffffff ' ,
191
- 'chco ' => 'ef672f ' ,
192
193
'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 ' ,
194
+ 'chf ' => 'bg,s,f4f4f4|c,lg,90,ffffff,0.1,ededed,0 ' ,
195
+ 'chm ' => 'B,f4d4b2,0,0,0 ' ,
196
+ 'chco ' => 'db4814 ' ,
197
+ 'chxs ' => '0,0,11|1,0,11 ' ,
198
+ 'chma ' => '15,15,15,15 '
195
199
];
196
200
197
201
$ this ->_allSeries = $ this ->getRowsData ($ this ->_dataRows );
@@ -279,20 +283,11 @@ public function getChartUrl($directUrl = true)
279
283
$ this ->_axisLabels ['x ' ] = $ dates ;
280
284
$ this ->_allSeries = $ datas ;
281
285
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
- }
286
+ // Image-Charts Awesome data format values
287
+ $ params ['chd ' ] = "a: " ;
288
+ $ dataDelimiter = ", " ;
289
+ $ dataSetdelimiter = "| " ;
290
+ $ dataMissing = "_ " ;
296
291
297
292
// process each string in the array, and find the max length
298
293
$ localmaxvalue = [0 ];
@@ -306,7 +301,6 @@ public function getChartUrl($directUrl = true)
306
301
$ minvalue = min ($ localminvalue );
307
302
308
303
// default values
309
- $ yrange = 0 ;
310
304
$ yLabels = [];
311
305
$ miny = 0 ;
312
306
$ maxy = 0 ;
@@ -321,52 +315,21 @@ public function getChartUrl($directUrl = true)
321
315
$ maxy = ceil ($ maxvalue + 1 );
322
316
$ yLabels = range ($ miny , $ maxy , 1 );
323
317
}
324
- $ yrange = $ maxy ;
325
318
$ yorigin = 0 ;
326
319
}
327
320
328
321
$ chartdata = [];
329
322
330
323
foreach ($ this ->getAllSeries () as $ index => $ serie ) {
331
324
$ 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
- }
325
+ $ count = count ($ thisdataarray );
326
+ for ($ j = 0 ; $ j < $ count ; $ j ++) {
327
+ $ currentvalue = $ thisdataarray [$ j ];
328
+ if (is_numeric ($ currentvalue )) {
329
+ $ ylocation = $ yorigin + $ currentvalue ;
330
+ $ chartdata [] = $ ylocation . $ dataDelimiter ;
331
+ } else {
332
+ $ chartdata [] = $ dataMissing . $ dataDelimiter ;
370
333
}
371
334
}
372
335
$ chartdata [] = $ dataSetdelimiter ;
@@ -381,45 +344,13 @@ public function getChartUrl($directUrl = true)
381
344
382
345
$ valueBuffer = [];
383
346
384
- if (sizeof ($ this ->_axisLabels ) > 0 ) {
347
+ if (count ($ this ->_axisLabels ) > 0 ) {
385
348
$ params ['chxt ' ] = implode (', ' , array_keys ($ this ->_axisLabels ));
386
349
$ indexid = 0 ;
387
350
foreach ($ this ->_axisLabels as $ idx => $ labels ) {
388
351
if ($ idx == 'x ' ) {
389
- /**
390
- * Format date
391
- */
392
- foreach ($ this ->_axisLabels [$ idx ] as $ _index => $ _label ) {
393
- if ($ _label != '' ) {
394
- $ period = new \DateTime ($ _label , new \DateTimeZone ($ timezoneLocal ));
395
- switch ($ this ->getDataHelper ()->getParam ('period ' )) {
396
- case '24h ' :
397
- $ this ->_axisLabels [$ idx ][$ _index ] = $ this ->_localeDate ->formatDateTime (
398
- $ period ->setTime ($ period ->format ('H ' ), 0 , 0 ),
399
- \IntlDateFormatter::NONE ,
400
- \IntlDateFormatter::SHORT
401
- );
402
- break ;
403
- case '7d ' :
404
- case '1m ' :
405
- $ this ->_axisLabels [$ idx ][$ _index ] = $ this ->_localeDate ->formatDateTime (
406
- $ period ,
407
- \IntlDateFormatter::SHORT ,
408
- \IntlDateFormatter::NONE
409
- );
410
- break ;
411
- case '1y ' :
412
- case '2y ' :
413
- $ this ->_axisLabels [$ idx ][$ _index ] = date ('m/Y ' , strtotime ($ _label ));
414
- break ;
415
- }
416
- } else {
417
- $ this ->_axisLabels [$ idx ][$ _index ] = '' ;
418
- }
419
- }
420
-
352
+ $ this ->formatAxisLabelDate ($ idx , $ timezoneLocal );
421
353
$ tmpstring = implode ('| ' , $ this ->_axisLabels [$ idx ]);
422
-
423
354
$ valueBuffer [] = $ indexid . ":| " . $ tmpstring ;
424
355
} elseif ($ idx == 'y ' ) {
425
356
$ valueBuffer [] = $ indexid . ":| " . implode ('| ' , $ yLabels );
@@ -447,6 +378,46 @@ public function getChartUrl($directUrl = true)
447
378
}
448
379
}
449
380
381
+ /**
382
+ * Format dates for axis labels
383
+ *
384
+ * @param string $idx
385
+ * @param string $timezoneLocal
386
+ *
387
+ * @return void
388
+ */
389
+ private function formatAxisLabelDate ($ idx , $ timezoneLocal )
390
+ {
391
+ foreach ($ this ->_axisLabels [$ idx ] as $ _index => $ _label ) {
392
+ if ($ _label != '' ) {
393
+ $ period = new \DateTime ($ _label , new \DateTimeZone ($ timezoneLocal ));
394
+ switch ($ this ->getDataHelper ()->getParam ('period ' )) {
395
+ case '24h ' :
396
+ $ this ->_axisLabels [$ idx ][$ _index ] = $ this ->_localeDate ->formatDateTime (
397
+ $ period ->setTime ($ period ->format ('H ' ), 0 , 0 ),
398
+ \IntlDateFormatter::NONE ,
399
+ \IntlDateFormatter::SHORT
400
+ );
401
+ break ;
402
+ case '7d ' :
403
+ case '1m ' :
404
+ $ this ->_axisLabels [$ idx ][$ _index ] = $ this ->_localeDate ->formatDateTime (
405
+ $ period ,
406
+ \IntlDateFormatter::SHORT ,
407
+ \IntlDateFormatter::NONE
408
+ );
409
+ break ;
410
+ case '1y ' :
411
+ case '2y ' :
412
+ $ this ->_axisLabels [$ idx ][$ _index ] = date ('m/Y ' , strtotime ($ _label ));
413
+ break ;
414
+ }
415
+ } else {
416
+ $ this ->_axisLabels [$ idx ][$ _index ] = '' ;
417
+ }
418
+ }
419
+ }
420
+
450
421
/**
451
422
* Get rows data
452
423
*
@@ -540,6 +511,8 @@ protected function getHeight()
540
511
}
541
512
542
513
/**
514
+ * Sets data helper
515
+ *
543
516
* @param \Magento\Backend\Helper\Dashboard\AbstractDashboard $dataHelper
544
517
* @return void
545
518
*/
0 commit comments