From 5a4b326f3ff14bea0f6612fed2ec6370d1da1b42 Mon Sep 17 00:00:00 2001 From: EnesSacid-Buker Date: Wed, 1 Mar 2023 10:55:34 +0300 Subject: [PATCH] Vue `Cannot read length` issue fixed Sometimes it comes 5 digit & this is causing error in charts --- app/Abstracts/Report.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/app/Abstracts/Report.php b/app/Abstracts/Report.php index 9fafb8340..9c9a92203 100644 --- a/app/Abstracts/Report.php +++ b/app/Abstracts/Report.php @@ -222,7 +222,9 @@ abstract class Report foreach ($tmp_values as $id => $value) { $labels[$id] = $this->row_names[$table_key][$id]; - $colors[$id] = ($group == 'category') ? Category::withSubCategory()->find($id)?->colorHexCode : '#' . dechex(rand(0x000000, 0xFFFFFF)); + $colors[$id] = ($group == 'category') + ? Category::withSubCategory()->find($id)?->colorHexCode + : $this->randHexColor(); $values[$id] = round(($value * 100 / $total), 0); } @@ -642,4 +644,14 @@ abstract class Report ], ]; } + + public function randHexColorPart(): string + { + return str_pad( dechex( mt_rand( 0, 255 ) ), 2, '0', STR_PAD_LEFT); + } + + public function randHexColor(): string + { + return '#' . $this->randHexColorPart() . $this->randHexColorPart() . $this->randHexColorPart(); + } }