< Summary

Information
Class: Pomodoro.Web.Services.ChartService
Assembly: Pomodoro.Web
File(s): /home/runner/work/Pomodoro/Pomodoro/src/Pomodoro.Web/Services/ChartService.cs
Line coverage
100%
Covered lines: 36
Uncovered lines: 0
Coverable lines: 36
Total lines: 79
Line coverage: 100%
Branch coverage
100%
Covered branches: 2
Total branches: 2
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
CreateBarChartAsync()100%11100%
CreateGroupedBarChartAsync()100%11100%
UpdateChartAsync()100%11100%
DestroyChartAsync()100%11100%
EnsureInitializedAsync()100%22100%
DisposeAsync()100%11100%

File(s)

/home/runner/work/Pomodoro/Pomodoro/src/Pomodoro.Web/Services/ChartService.cs

#LineLine coverage
 1using Microsoft.JSInterop;
 2
 3namespace Pomodoro.Web.Services;
 4
 5/// <summary>
 6/// Service for Chart.js JavaScript interop
 7/// </summary>
 8public class ChartService : IAsyncDisposable
 9{
 10    private readonly IJSRuntime _jsRuntime;
 11    private bool _initialized;
 12
 28213    public ChartService(IJSRuntime jsRuntime)
 28214    {
 28215        _jsRuntime = jsRuntime;
 28216    }
 17
 18    /// <summary>
 19    /// Creates a bar chart with the specified configuration
 20    /// </summary>
 21    public async Task CreateBarChartAsync(string canvasId, string[] labels, int[] data, string label = Constants.Charts.
 1122    {
 1123        await EnsureInitializedAsync();
 1124        await _jsRuntime.InvokeVoidAsync(Constants.ChartJsFunctions.CreateBarChart, canvasId, labels, data, label, highl
 1125    }
 26
 27    /// <summary>
 28    /// Creates a grouped bar chart with focus time and break data
 29    /// </summary>
 30    public async Task CreateGroupedBarChartAsync(string canvasId, string[] labels, int[] focusData, int[] breakData, int
 5831    {
 5832        await EnsureInitializedAsync();
 5833        await _jsRuntime.InvokeVoidAsync(Constants.ChartJsFunctions.CreateGroupedBarChart, canvasId, labels, focusData, 
 5834    }
 35
 36    /// <summary>
 37    /// Updates an existing chart with new data
 38    /// </summary>
 39    public async Task UpdateChartAsync(string canvasId, int[] data)
 240    {
 241        await _jsRuntime.InvokeVoidAsync(Constants.ChartJsFunctions.UpdateChart, canvasId, data);
 142    }
 43
 44    /// <summary>
 45    /// Destroys a chart to free resources
 46    /// </summary>
 47    public virtual async Task DestroyChartAsync(string canvasId)
 4648    {
 49        try
 4650        {
 4651            await _jsRuntime.InvokeVoidAsync(Constants.ChartJsFunctions.DestroyChart, canvasId);
 4052        }
 653        catch (Exception)
 654        {
 55            // Ignore errors during disposal - chart may not exist or already destroyed
 656        }
 4657    }
 58
 59    private async Task EnsureInitializedAsync()
 6960    {
 7961        if (_initialized) return;
 62
 63        try
 5964        {
 5965            await _jsRuntime.InvokeVoidAsync(Constants.ChartJsFunctions.EnsureInitialized);
 5666            _initialized = true;
 5667        }
 368        catch
 369        {
 70            // Chart.js may not be loaded yet, will be handled gracefully
 371        }
 6972    }
 73
 74    public async ValueTask DisposeAsync()
 275    {
 76        // Charts will be cleaned up by the browser when the page unloads
 277        await Task.CompletedTask;
 278    }
 79}