Skip to content

Commit 4814db8

Browse files
authored
Merge pull request #14 from kelvinmaues/master
Fix/ Percentage calculation for zero values
2 parents 3c528cc + b199a22 commit 4814db8

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

src/js/main.js

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,17 @@ class FunnelGraph {
3838
------
3939
---#1----------------
4040
#0-----------------
41-
4241
Main axis is the primary axis of the graph.
4342
In a horizontal graph it's the X axis, and Y is the cross axis.
4443
However we use the names "main" and "cross" axis,
4544
because in a vertical graph the primary axis is the Y axis
4645
and the cross axis is the X axis.
47-
4846
First step of drawing the funnel graph is getting the coordinates of points,
4947
that are used when drawing the paths.
50-
5148
There are 4 paths in the example above: A, B, C and D.
5249
Such funnel has 3 labels and 3 subLabels.
5350
This means that the main axis has 4 points (number of labels + 1)
5451
One the ASCII illustrated graph above, those points are illustrated with a # symbol.
55-
5652
*/
5753
getMainAxisPoints() {
5854
const size = this.getDataSize();
@@ -183,10 +179,7 @@ class FunnelGraph {
183179

184180
const percentageValue = document.createElement('div');
185181
percentageValue.setAttribute('class', 'label__percentage');
186-
187-
if (percentage !== 100) {
188-
percentageValue.textContent = `${percentage.toString()}%`;
189-
}
182+
percentageValue.textContent = `${percentage.toString()}%`;
190183

191184
labelElement.appendChild(value);
192185
labelElement.appendChild(title);
@@ -322,7 +315,7 @@ class FunnelGraph {
322315
}
323316

324317
const max = Math.max(...values);
325-
return values.map(value => roundPoint(value * 100 / max));
318+
return values.map(value => value === 0 ? 0 : roundPoint(value * 100 / max));
326319
}
327320

328321
applyGradient(svg, path, colors, index) {
@@ -663,4 +656,4 @@ class FunnelGraph {
663656
}
664657
}
665658

666-
export default FunnelGraph;
659+
export default FunnelGraph;

0 commit comments

Comments
 (0)