Skip to content

Commit 8c71507

Browse files
committed
Fix: Chart height, webhook duration, sparse data visibility, and legend size
1. Increased chart height from h-64 to h-96 for better visibility 2. Fixed webhook duration conversion from seconds to milliseconds (* 1000) 3. Fixed API requests not showing by displaying individual points for sparse data (< 10 records) 4. Reduced legend circle size with pointStyleWidth: 8 5. Added pointBackgroundColor for visible points in sparse data
1 parent a39e6aa commit 8c71507

2 files changed

Lines changed: 24 additions & 9 deletions

File tree

addon/components/widget/api-metrics.hbs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<h4 class="mb-4 text-sm font-semibold text-gray-700 dark:text-gray-200">
55
{{t "developers.component.widget.api-metrics.api-requests"}}
66
</h4>
7-
<div class="h-64">
7+
<div class="h-96">
88
<Chart @type="line" @datasets={{this.apiRequestData}} @options={{this.chartOptions}} />
99
</div>
1010
</div>
@@ -13,7 +13,7 @@
1313
<h4 class="mb-4 text-sm font-semibold text-gray-700 dark:text-gray-200">
1414
{{t "developers.component.widget.api-metrics.api-error"}}
1515
</h4>
16-
<div class="h-64">
16+
<div class="h-96">
1717
<Chart @type="line" @datasets={{this.apiErrorDistributionData}} @options={{this.chartOptions}} />
1818
</div>
1919
</div>
@@ -22,7 +22,7 @@
2222
<h4 class="mb-4 text-sm font-semibold text-gray-700 dark:text-gray-200">
2323
{{t "developers.component.widget.api-metrics.webhooks"}}
2424
</h4>
25-
<div class="h-64">
25+
<div class="h-96">
2626
<Chart @type="line" @datasets={{this.webhookRequestData}} @options={{this.chartOptions}} />
2727
</div>
2828
</div>
@@ -31,7 +31,7 @@
3131
<h4 class="mb-4 text-sm font-semibold text-gray-700 dark:text-gray-200">
3232
{{t "developers.component.widget.api-metrics.webhooks-response"}}
3333
</h4>
34-
<div class="h-64">
34+
<div class="h-96">
3535
<Chart @type="line" @datasets={{this.webhookRequestTimingData}} @options={{this.chartOptions}} />
3636
</div>
3737
</div>

addon/components/widget/api-metrics.js

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,21 @@ export default class WidgetApiMetricsComponent extends Component {
1313

1414
/**
1515
* Create time-series data from records grouped by hour
16+
* For sparse data (< 10 records), show individual points instead of grouping
1617
*/
1718
createTimeSeriesData(records, filterFn = () => true) {
1819
const filtered = records.filter(filterFn);
19-
const grouped = {};
20+
21+
// If we have very few records, don't group - show each one
22+
if (filtered.length < 10) {
23+
return filtered.map((record) => ({
24+
x: new Date(record.created_at),
25+
y: 1,
26+
}));
27+
}
2028

21-
// Group by hour
29+
// For larger datasets, group by hour
30+
const grouped = {};
2231
filtered.forEach((record) => {
2332
const timestamp = new Date(record.created_at);
2433
const hourKey = format(timestamp, 'yyyy-MM-dd HH:00:00');
@@ -61,6 +70,9 @@ export default class WidgetApiMetricsComponent extends Component {
6170
return statusCode >= 400;
6271
});
6372

73+
// Show points if we have sparse data
74+
const showPoints = records.length < 10;
75+
6476
resolve([
6577
{
6678
label: this.intl.t('developers.component.widget.api-metrics.success-label'),
@@ -70,8 +82,9 @@ export default class WidgetApiMetricsComponent extends Component {
7082
borderWidth: 3,
7183
fill: true,
7284
tension: 0.4,
73-
pointRadius: 0,
85+
pointRadius: showPoints ? 4 : 0,
7486
pointHoverRadius: 6,
87+
pointBackgroundColor: 'rgb(16, 185, 129)',
7588
pointHoverBackgroundColor: 'rgb(16, 185, 129)',
7689
pointHoverBorderColor: '#fff',
7790
pointHoverBorderWidth: 2,
@@ -84,8 +97,9 @@ export default class WidgetApiMetricsComponent extends Component {
8497
borderWidth: 3,
8598
fill: true,
8699
tension: 0.4,
87-
pointRadius: 0,
100+
pointRadius: showPoints ? 4 : 0,
88101
pointHoverRadius: 6,
102+
pointBackgroundColor: 'rgb(239, 68, 68)',
89103
pointHoverBackgroundColor: 'rgb(239, 68, 68)',
90104
pointHoverBorderColor: '#fff',
91105
pointHoverBorderWidth: 2,
@@ -234,7 +248,7 @@ export default class WidgetApiMetricsComponent extends Component {
234248
.then((webhookRequestLogs) => {
235249
const data = webhookRequestLogs.toArray().map((req) => ({
236250
x: new Date(req.created_at),
237-
y: req.duration || 0,
251+
y: (req.duration || 0) * 1000, // Convert seconds to milliseconds
238252
}));
239253

240254
resolve([
@@ -277,6 +291,7 @@ export default class WidgetApiMetricsComponent extends Component {
277291
labels: {
278292
color: '#9CA3AF',
279293
usePointStyle: true,
294+
pointStyleWidth: 8,
280295
padding: 15,
281296
font: {
282297
size: 12,

0 commit comments

Comments
 (0)