Skip to content

Commit e6215ec

Browse files
committed
Fix 0% display to show <1% for small percentages
- Replace Math.round(percentage) === 0 with '<1%' when count > 0 - Updated 9 components with 15+ instances total: - QuantitativeChart.jsx - HorizontalRatingsChart.jsx (4 instances) - RatingsChart.jsx (2 instances) - ChannelRatingsGrid.jsx - QualityComparisonRatingsGrid.jsx - DeviceSatisfactionGrid.jsx - DesignChangesRatingsGrid.jsx - UnderstandingRatingsGrid.jsx - MatrixChart.jsx (4 instances) - Ensures responses with actual respondents never show as 0%
1 parent 39eef5d commit e6215ec

9 files changed

Lines changed: 16 additions & 16 deletions

src/components/ChannelRatingsGrid.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ const ChannelRatingsGrid = ({ filters = {}, compact = true, wasmService }) => {
271271
onMouseMove={handleBarMouseMove}
272272
>
273273
<span className="text-white font-semibold text-xs px-1">
274-
{Math.round(item.percentage)}%
274+
{Math.round(item.percentage) === 0 && item.count > 0 ? '<1%' : `${Math.round(item.percentage)}%`}
275275
</span>
276276
</div>
277277
);

src/components/DesignChangesRatingsGrid.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ const DesignChangesRatingsGrid = ({ filters = {}, wasmService }) => {
268268
}}
269269
>
270270
<span className="text-white font-semibold text-[10px] px-1">
271-
{Math.round(item.percentage)}%
271+
{Math.round(item.percentage) === 0 && item.count > 0 ? '<1%' : `${Math.round(item.percentage)}%`}
272272
</span>
273273
</div>
274274
))}

src/components/DeviceSatisfactionGrid.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ const DeviceSatisfactionGrid = ({ filters = {}, wasmService }) => {
266266
onMouseMove={handleBarMouseMove}
267267
>
268268
<span className="text-white font-semibold text-xs px-1">
269-
{Math.round(item.percentage)}%
269+
{Math.round(item.percentage) === 0 && item.count > 0 ? '<1%' : `${Math.round(item.percentage)}%`}
270270
</span>
271271
</div>
272272
);

src/components/HorizontalRatingsChart.jsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ const HorizontalRatingsChart = ({ questionId, questionTitle, filters = {}, showR
456456

457457
// Determine if percentage text fits inside bar with padding
458458
// Calculate approximate text width: each char ~7px, padding pl-2 pr-2 = 16px total
459-
const percentageText = `${Math.round(item.percentage)}%`;
459+
const percentageText = Math.round(item.percentage) === 0 && item.count > 0 ? '<1%' : `${Math.round(item.percentage)}%`;
460460
const textWidth = percentageText.length * 7; // approximate char width for text-xs font-bold
461461
const paddingWidth = 16; // pl-2 (8px) + pr-2 (8px)
462462
const minRequiredWidth = textWidth + paddingWidth;
@@ -501,7 +501,7 @@ const HorizontalRatingsChart = ({ questionId, questionTitle, filters = {}, showR
501501
{/* Percentage inside the bar on the left (only if it fits) */}
502502
{percentageFitsInside && (
503503
<span className="text-white text-xs font-bold pl-2 pr-2">
504-
{Math.round(item.percentage)}%
504+
{Math.round(item.percentage) === 0 && item.count > 0 ? '<1%' : `${Math.round(item.percentage)}%`}
505505
</span>
506506
)}
507507
</div>
@@ -523,7 +523,7 @@ const HorizontalRatingsChart = ({ questionId, questionTitle, filters = {}, showR
523523
{/* Show percentage closest to bar, then descriptor */}
524524
{!percentageFitsInside && (
525525
<span className="text-gray-900 text-xs font-bold whitespace-nowrap">
526-
{Math.round(item.percentage)}%
526+
{Math.round(item.percentage) === 0 && item.count > 0 ? '<1%' : `${Math.round(item.percentage)}%`}
527527
</span>
528528
)}
529529
<span className="text-gray-700 text-xs font-semibold uppercase whitespace-nowrap">
@@ -545,7 +545,7 @@ const HorizontalRatingsChart = ({ questionId, questionTitle, filters = {}, showR
545545
{/* Show percentage closest to bar if it doesn't fit inside, then descriptor */}
546546
{!percentageFitsInside && (
547547
<span className="text-gray-900 text-xs font-bold whitespace-nowrap">
548-
{Math.round(item.percentage)}%
548+
{Math.round(item.percentage) === 0 && item.count > 0 ? '<1%' : `${Math.round(item.percentage)}%`}
549549
</span>
550550
)}
551551
<span className="text-gray-700 text-xs font-semibold uppercase whitespace-nowrap">

src/components/MatrixChart.jsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ const MatrixChart = ({ questionId, questionTitle, filters, _color, wasmService }
166166
event.stopPropagation();
167167

168168
if (device.count > 0) {
169-
setTooltipContent(`${device.count} respondents (${Math.round(device.percentage)}%)`);
169+
setTooltipContent(`${device.count} respondents (${Math.round(device.percentage) === 0 && device.count > 0 ? '<1%' : `${Math.round(device.percentage)}%`})`);
170170

171171
const screenY = event.clientY;
172172
const screenX = event.clientX;
@@ -242,7 +242,7 @@ const MatrixChart = ({ questionId, questionTitle, filters, _color, wasmService }
242242
>
243243
{device.percentage > 0 && (
244244
<span className={`text-white font-semibold text-xs ${idx === 0 ? 'pl-2 pr-1' : idx === 2 ? 'pl-1 pr-2' : 'px-1'}`}>
245-
{Math.round(device.percentage)}%
245+
{Math.round(device.percentage) === 0 && device.count > 0 ? '<1%' : `${Math.round(device.percentage)}%`}
246246
</span>
247247
)}
248248
</div>
@@ -321,7 +321,7 @@ const MatrixChart = ({ questionId, questionTitle, filters, _color, wasmService }
321321
event.stopPropagation();
322322

323323
if (device.count > 0) {
324-
setTooltipContent(`${Math.round(device.percentage)}%`);
324+
setTooltipContent(`${Math.round(device.percentage) === 0 && device.count > 0 ? '<1%' : `${Math.round(device.percentage)}%`}`);
325325

326326
const screenY = event.clientY;
327327
const screenX = event.clientX;
@@ -397,7 +397,7 @@ const MatrixChart = ({ questionId, questionTitle, filters, _color, wasmService }
397397
>
398398
{device.percentage > 0 && (
399399
<span className={`text-white font-semibold text-xs ${idx === 0 ? 'pl-2 pr-1' : idx === 2 ? 'pl-1 pr-2' : 'px-1'}`}>
400-
{Math.round(device.percentage)}%
400+
{Math.round(device.percentage) === 0 && device.count > 0 ? '<1%' : `${Math.round(device.percentage)}%`}
401401
</span>
402402
)}
403403
</div>

src/components/QualityComparisonRatingsGrid.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ const QualityComparisonRatingsGrid = ({ filters = {}, wasmService }) => {
259259
}}
260260
>
261261
<span className="text-white font-semibold text-xs px-1">
262-
{Math.round(item.percentage)}%
262+
{Math.round(item.percentage) === 0 && item.count > 0 ? '<1%' : `${Math.round(item.percentage)}%`}
263263
</span>
264264
</div>
265265
))}

src/components/QuantitativeChart.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ const QuantitativeChart = ({ questionId, questionTitle, filterType, filters = {}
6868
return {
6969
Resource: cleanAnswer,
7070
resource: cleanAnswer,
71-
[columnName]: item.percentage ? `${Math.round(item.percentage)}%` : '0%',
71+
[columnName]: item.percentage ? (Math.round(item.percentage) === 0 && item.count > 0 ? '<1%' : `${Math.round(item.percentage)}%`) : '0%',
7272
count: item.count
7373
};
7474
});

src/components/RatingsChart.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ const RatingsChart = ({ questionId, questionTitle, filters = {}, _color, _colorS
265265
>
266266
{/* Percentage text inside bar - always show */}
267267
<span className="text-white font-semibold text-xs px-1">
268-
{Math.round(item.percentage)}%
268+
{Math.round(item.percentage) === 0 && item.count > 0 ? '<1%' : `${Math.round(item.percentage)}%`}
269269
</span>
270270
</div>
271271
);
@@ -309,7 +309,7 @@ const RatingsChart = ({ questionId, questionTitle, filters = {}, _color, _colorS
309309
minWidth: item.percentage > 0 ? '30px' : '0'
310310
}}
311311
>
312-
{item.percentage >= 5 && `${Math.round(item.percentage)}%`}
312+
{item.percentage >= 5 && (Math.round(item.percentage) === 0 && item.count > 0 ? '<1%' : `${Math.round(item.percentage)}%`)}
313313
</div>
314314
</div>
315315
<div className="text-xs text-gray-500 w-12 text-right">

src/components/UnderstandingRatingsGrid.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ const UnderstandingRatingsGrid = ({ filters = {}, wasmService }) => {
258258
onMouseMove={handleBarMouseMove}
259259
>
260260
<span className="text-white font-semibold text-xs px-1">
261-
{Math.round(item.percentage)}%
261+
{Math.round(item.percentage) === 0 && item.count > 0 ? '<1%' : `${Math.round(item.percentage)}%`}
262262
</span>
263263
</div>
264264
);

0 commit comments

Comments
 (0)