fix: pull dashboard widget data from a ChartDataService (#20)
CI / build-and-test (pull_request) Successful in 2m32s
CI / build-and-test (pull_request) Successful in 2m32s
Chart and KPI numbers were literals in DashboardView, duplicated between the line and bar chart, and only existed at construction time. Add a thin data layer as the seam for later refresh/filter work: - ChartSeries / KpiData records, immutable, carrying translation keys rather than display text so the data layer stays free of a UI locale. - ChartDataService interface plus an in-memory implementation returning the previous hardcoded numbers, so nothing changes visually. - DashboardView injects the service, lays out the KPI tiles from its list (grid ids come from the data, so saved layouts still match), and resolves the keys against the bundle. Also fixes DashboardChartPlaywrightTest, red on main since the KPI tiles landed: it patched the first apex-chart, which is now a sparkline with no xaxis.categories, so the axis-chart patch was a structural change and legitimately redrew the SVG. It now targets an axis chart. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0124BiJikbhbiEsNfJxdWM69
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
package com.example.data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* One named series of numbers plus the categories they are indexed by — the
|
||||
* shape every chart on the dashboard is fed with, axis-based or not (a pie
|
||||
* chart reads the categories as slice labels and ignores the series name).
|
||||
* <p>
|
||||
* {@code nameKey} and {@code categoryKeys} are <em>translation keys</em>, not
|
||||
* display text: the data layer must stay free of a {@code UI} and its locale,
|
||||
* so resolving them against the bundle is the view's job. Values and keys are
|
||||
* defensively copied, so a data set handed out by a
|
||||
* {@link ChartDataService} cannot be modified by its consumer.
|
||||
*/
|
||||
public record ChartSeries(String nameKey, List<Double> values, List<String> categoryKeys) {
|
||||
|
||||
public ChartSeries {
|
||||
values = List.copyOf(values);
|
||||
categoryKeys = List.copyOf(categoryKeys);
|
||||
if (values.size() != categoryKeys.size()) {
|
||||
throw new IllegalArgumentException(
|
||||
"each value needs a category: %d values, %d categories"
|
||||
.formatted(values.size(), categoryKeys.size()));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user