Skip to content

Commit

Permalink
Merge pull request #1268 from evidence-dev/funnel-percent
Browse files Browse the repository at this point in the history
Add showPercent option to funnel chart
  • Loading branch information
hughess authored Oct 15, 2023
2 parents 715892a + 5c4c36d commit cafd4b1
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
6 changes: 6 additions & 0 deletions .changeset/thirty-llamas-tap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@evidence-dev/core-components': patch
'evidence-docs': patch
---

Add showPercent option to funnel chart
11 changes: 10 additions & 1 deletion packages/core-components/src/lib/unsorted/viz/FunnelChart.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
export let colorPalette = undefined;
export let showPercent = false;
showPercent = showPercent === 'true' || showPercent === true;
// ---------------------------------------------------------------------------------------
// Variable Declaration
// ---------------------------------------------------------------------------------------
Expand Down Expand Up @@ -145,7 +148,13 @@
show: true,
position: labelPosition,
formatter: function (params) {
return formatValue(params.value, valueColFormat);
let output;
if (showPercent) {
output = `${formatValue(params.value, valueColFormat)} (${params.percent}%)`;
} else {
output = formatValue(params.value, valueColFormat);
}
return output;
}
},
labelLayout: { hideOverlap: true },
Expand Down
21 changes: 18 additions & 3 deletions sites/docs/docs/components/funnel-chart.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ title: Funnel Chart
hide_table_of_contents: false
---

![funnel](/img/funnel-default.png)
<img src="/img/funnel-default.png" width="700"/>

```markdown
<FunnelChart
Expand All @@ -18,7 +18,7 @@ hide_table_of_contents: false

### Ascending

![ascending-funnel](/img//funnel-asc.png)
<img src="/img//funnel-asc.png" width="700"/>

```markdown
<FunnelChart
Expand All @@ -31,7 +31,7 @@ hide_table_of_contents: false

### Alignment

![left-aligned-funnel](/img//funnel-align.png)
<img src="/img//funnel-align.png" width="700"/>

```markdown
<FunnelChart
Expand All @@ -42,6 +42,20 @@ hide_table_of_contents: false
/>
```

### Show Percent Label

<img src="/img/funnel-showpct.png" alt="funnel-show-percent" width="700"/>

```markdown
<FunnelChart
data={query_name}
nameCol=column_name
valueCol=column_value
showPercent=true
/>
```


## Options

### Data
Expand All @@ -61,6 +75,7 @@ hide_table_of_contents: false
<tr> <td>outlineColor</td> <td>Border color. Only accepts a single color.</td> <td class='tcenter'>-</td> <td class='tcenter'>CSS name | hexademical | RGB | HSL</td> <td class='tcenter'>transparent</td> </tr>
<tr> <td>outlineWidth</td> <td>Border Width. It should be a natural number.</td> <td class='tcenter'>-</td> <td class='tcenter'>number</td> <td class='tcenter'>1</td> </tr>
<tr> <td>labelPosition</td> <td>Position of funnel item's label.</td> <td class='tcenter'>-</td> <td class='tcenter'>left | right | inside</td> <td class='tcenter'>inside</td> </tr>
<tr> <td>showPercent</td> <td>Show percentage in data labels</td> <td class='tcenter'>-</td> <td class='tcenter'>true | false</td> <td class='tcenter'>false</td> </tr>
<tr> <td>funnelSort</td> <td>Data sorting of the chart.</td> <td class='tcenter'>-</td> <td class='tcenter'>none | ascending | descending</td> <td class='tcenter'>none</td> </tr>
<tr> <td>funnelAlign</td> <td>Alignment of funnel.</td> <td class='tcenter'>-</td> <td class='tcenter'>left | right | center</td> <td class='tcenter'>center</td> </tr>
</table>
Expand Down
Binary file added sites/docs/static/img/funnel-showpct.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit cafd4b1

Please sign in to comment.