Skip to content

Commit

Permalink
fix: label rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
Swiftwork committed Jun 11, 2021
1 parent c34e640 commit 11b4486
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/lib/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export class FunnelGraph {
const data = this.data as FunnelDataLayered;
const subLabelDisplayValue =
this.subLabelValue === 'percent'
? `${twoDimPercentages[index][j]}%`
? `${twoDimPercentages[index][j] || 0}%`
: formatNumber(data.values[index][j] || 0);
percentageList += `
<li class="fg-label__segment-item">${subLabel}:
Expand Down Expand Up @@ -315,7 +315,7 @@ export class FunnelGraph {
}

const max = Math.max(...values);
return values.map((value) => (value === 0 ? 0 : roundPoint((value * 100) / max)));
return values.map((value) => (value ? roundPoint((value * 100) / max) : 0));
}

getSVG() {
Expand Down Expand Up @@ -522,20 +522,20 @@ export class FunnelGraph {
redraw = true;
}

if (data.labels) {
const labels = this.container.querySelector('.fg-labels');
if (labels) labels.remove();
this.data.labels = data.labels;
this.addLabels();
}

if (isLayered(data) && data.subLabels) {
const subLabels = this.container.querySelector('.fg-sub-labels');
if (subLabels) subLabels.remove();
(this.data as FunnelDataLayered).subLabels = data.subLabels;
this.addSubLabels();
}

if (data.labels) {
const labels = this.container.querySelector('.fg-labels');
if (labels) labels.remove();
this.data.labels = data.labels;
this.addLabels();
}

if (redraw) {
this.makeSVG();
this.drawPaths();
Expand Down

0 comments on commit 11b4486

Please sign in to comment.