From 769973ebeda39e1bfb7977aa29c776bce03872a5 Mon Sep 17 00:00:00 2001 From: philippe Date: Fri, 5 Jun 2026 15:09:52 +0200 Subject: [PATCH 1/5] Fix date label formatting --- src/Dashboard/Widgets/SharpGraphWidgetDataSet.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Dashboard/Widgets/SharpGraphWidgetDataSet.php b/src/Dashboard/Widgets/SharpGraphWidgetDataSet.php index 154e7f2d8..cccfdb738 100644 --- a/src/Dashboard/Widgets/SharpGraphWidgetDataSet.php +++ b/src/Dashboard/Widgets/SharpGraphWidgetDataSet.php @@ -56,9 +56,10 @@ protected function formatValues(array $values): array protected function formatLabels(array $values): array { if ($this->hasDateLabels) { - return array_map(function ($value) { - return (new Carbon($value))->setTimezone(config('app.timezone'))->toAtomString(); - }, array_keys($values)); + return array_map( + fn ($value) => Carbon::createFromFormat('!Y-m-d', $value, 'UTC')->toAtomString(), + array_keys($values) + ); } return array_keys($values); From b98c6aebeff454164e72cb30979b2fe8db39c895 Mon Sep 17 00:00:00 2001 From: philippe Date: Fri, 5 Jun 2026 15:26:48 +0200 Subject: [PATCH 2/5] Add missing unit tests for widget data set --- .../Widgets/SharpGraphWidgetDataSetTest.php | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 tests/Unit/Dashboard/Widgets/SharpGraphWidgetDataSetTest.php diff --git a/tests/Unit/Dashboard/Widgets/SharpGraphWidgetDataSetTest.php b/tests/Unit/Dashboard/Widgets/SharpGraphWidgetDataSetTest.php new file mode 100644 index 000000000..fcc813373 --- /dev/null +++ b/tests/Unit/Dashboard/Widgets/SharpGraphWidgetDataSetTest.php @@ -0,0 +1,75 @@ + 1, 'b' => 2, 'c' => 3]); + + expect($dataSet->toArray()['data'])->toEqual([1.0, 2.0, 3.0]); +}); + +it('formats string numeric values as floats', function () { + $dataSet = SharpGraphWidgetDataSet::make(['a' => '1.5', 'b' => '2.7']); + + expect($dataSet->toArray()['data'])->toEqual([1.5, 2.7]); +}); + +it('returns array keys as labels by default', function () { + $dataSet = SharpGraphWidgetDataSet::make(['foo' => 10, 'bar' => 20]); + + expect($dataSet->toArray()['labels'])->toEqual(['foo', 'bar']); +}); + +it('accepts a collection', function () { + $dataSet = SharpGraphWidgetDataSet::make(collect(['a' => 1, 'b' => 2])); + + expect($dataSet->toArray()['data'])->toEqual([1.0, 2.0]) + ->and($dataSet->toArray()['labels'])->toEqual(['a', 'b']); +}); + +it('sets a label', function () { + $dataSet = SharpGraphWidgetDataSet::make(['a' => 1]) + ->setLabel('My Dataset'); + + expect($dataSet->toArray()['label'])->toEqual('My Dataset'); +}); + +it('does not include label key when not set', function () { + $dataSet = SharpGraphWidgetDataSet::make(['a' => 1]); + + expect($dataSet->toArray())->not->toHaveKey('label'); +}); + +it('sets a color', function () { + $dataSet = SharpGraphWidgetDataSet::make(['a' => 1]) + ->setColor('#ff0000'); + + expect($dataSet->toArray()['color'])->toEqual('#ff0000'); +}); + +it('does not include color key when not set', function () { + $dataSet = SharpGraphWidgetDataSet::make(['a' => 1]); + + expect($dataSet->toArray())->not->toHaveKey('color'); +}); + +it('formats date labels as UTC atom strings regardless of app timezone', function (string $timezone) { + config(['app.timezone' => $timezone]); + + $dataSet = SharpGraphWidgetDataSet::make(['2024-01-15' => 10])->withDateLabels(); + + expect($dataSet->toArray()['labels'][0])->toEqual('2024-01-15T00:00:00+00:00'); +})->with([ + 'UTC', + 'America/New_York', // UTC-5 + 'Asia/Tokyo', // UTC+9 +]); + +it('returns plain keys when withDateLabels is not called', function () { + $dataSet = SharpGraphWidgetDataSet::make([ + '2024-01-15' => 10, + '2024-06-01' => 20, + ]); + + expect($dataSet->toArray()['labels'])->toEqual(['2024-01-15', '2024-06-01']); +}); From 11b31c7045b8458fa9d2c3176f7225366cc973d9 Mon Sep 17 00:00:00 2001 From: philippe Date: Fri, 5 Jun 2026 15:27:06 +0200 Subject: [PATCH 3/5] Fix edge case: label with time --- src/Dashboard/Widgets/SharpGraphWidgetDataSet.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Dashboard/Widgets/SharpGraphWidgetDataSet.php b/src/Dashboard/Widgets/SharpGraphWidgetDataSet.php index cccfdb738..b73366393 100644 --- a/src/Dashboard/Widgets/SharpGraphWidgetDataSet.php +++ b/src/Dashboard/Widgets/SharpGraphWidgetDataSet.php @@ -57,7 +57,7 @@ protected function formatLabels(array $values): array { if ($this->hasDateLabels) { return array_map( - fn ($value) => Carbon::createFromFormat('!Y-m-d', $value, 'UTC')->toAtomString(), + fn ($value) => (new Carbon($value))->shiftTimezone('UTC')->toAtomString(), array_keys($values) ); } From b10079caac6440802aa97e9d7dde501706c17df3 Mon Sep 17 00:00:00 2001 From: philippe Date: Fri, 5 Jun 2026 15:31:46 +0200 Subject: [PATCH 4/5] Even better --- src/Dashboard/Widgets/SharpGraphWidgetDataSet.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Dashboard/Widgets/SharpGraphWidgetDataSet.php b/src/Dashboard/Widgets/SharpGraphWidgetDataSet.php index b73366393..e948b6ab7 100644 --- a/src/Dashboard/Widgets/SharpGraphWidgetDataSet.php +++ b/src/Dashboard/Widgets/SharpGraphWidgetDataSet.php @@ -57,7 +57,7 @@ protected function formatLabels(array $values): array { if ($this->hasDateLabels) { return array_map( - fn ($value) => (new Carbon($value))->shiftTimezone('UTC')->toAtomString(), + fn ($value) => (new Carbon($value, 'UTC'))->toAtomString(), array_keys($values) ); } From b62b10c16a6d3209a78b3433576f6f9632561404 Mon Sep 17 00:00:00 2001 From: philippe Date: Fri, 5 Jun 2026 15:37:00 +0200 Subject: [PATCH 5/5] Add test --- src/Dashboard/Widgets/SharpGraphWidgetDataSet.php | 2 +- tests/Unit/Dashboard/SharpDashboardTest.php | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Dashboard/Widgets/SharpGraphWidgetDataSet.php b/src/Dashboard/Widgets/SharpGraphWidgetDataSet.php index e948b6ab7..b73366393 100644 --- a/src/Dashboard/Widgets/SharpGraphWidgetDataSet.php +++ b/src/Dashboard/Widgets/SharpGraphWidgetDataSet.php @@ -57,7 +57,7 @@ protected function formatLabels(array $values): array { if ($this->hasDateLabels) { return array_map( - fn ($value) => (new Carbon($value, 'UTC'))->toAtomString(), + fn ($value) => (new Carbon($value))->shiftTimezone('UTC')->toAtomString(), array_keys($values) ); } diff --git a/tests/Unit/Dashboard/SharpDashboardTest.php b/tests/Unit/Dashboard/SharpDashboardTest.php index d506ced64..a7c85d6d5 100644 --- a/tests/Unit/Dashboard/SharpDashboardTest.php +++ b/tests/Unit/Dashboard/SharpDashboardTest.php @@ -193,6 +193,7 @@ protected function buildWidgetsData(): void '2026-04-03' => 10, '2026-04-04 12:30:04' => 20, '2026-04-05' => 30, + '2026-04-06 12:30:04+02:00' => 40, ])->setLabel('test')->setColor('blue')); } }; @@ -203,7 +204,7 @@ protected function buildWidgetsData(): void 'key' => 'widget', 'datasets' => [ [ - 'data' => [10, 20, 30], + 'data' => [10, 20, 30, 40], 'label' => 'test', 'color' => 'blue', ], @@ -212,6 +213,7 @@ protected function buildWidgetsData(): void '2026-04-03T00:00:00+00:00', '2026-04-04T12:30:04+00:00', '2026-04-05T00:00:00+00:00', + '2026-04-06T12:30:04+00:00', ], ], ]);