Skip to content

Commit

Permalink
✨ Add option to switch order of Alluvial labels/values
Browse files Browse the repository at this point in the history
  • Loading branch information
joao-m-santos authored and joao committed Jul 14, 2023
1 parent a2d400c commit 3322cf2
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ Interface: `AlluvialDiagramOptions`
| nodeSort | `(a: SankeyNode, b: SankeyNode) => number` | Defines the node sort method. [Read more](https://github.com/d3/d3-sankey#sankey_nodeSort) |
| nodeWidth | `number` | Sets the node block width. |
| linkSort | `(a: SankeyLink, b: SankeyLink) => number` | Defines the link sort method. [Read more](https://github.com/d3/d3-sankey#sankey_linkSort) |
| switchText | `boolean` | Controls whether the node label/value order should be switched (`true` makes the value be displayed first.) |
| valueFormat | `string \| (currentValue: number, baseValue: number) => number \| string` | A format specifier string for [d3-format](https://github.com/d3/d3-format) or a formatting function. The function receives the contextual node value and the base node value. |

#### Highlighted elements
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
<template>
<text class="lume-alluvial-group__node-label">
<text
class="lume-alluvial-group__node-label"
:dy="bottom ? '1.2em' : ''"
>
<slot />
</text>
</template>

<script lang="ts" setup>
defineProps({
bottom: { type: Boolean, default: false },
});
</script>

<style lang="scss" scoped>
@use '../../styles';
</style>
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
<template>
<text
class="lume-alluvial-group__node-value"
x="0"
dy="1.2em"
:dy="bottom ? '1.2em' : ''"
>
<slot />
</text>
</template>

<script lang="ts" setup>
defineProps({
bottom: { type: Boolean, default: true },
});
</script>

<style lang="scss" scoped>
@use '../../styles';
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@
)
"
>
<lume-alluvial-node-label>
<lume-alluvial-node-label :bottom="options.switchText">
{{ block.node.label }}
</lume-alluvial-node-label>
<lume-alluvial-node-value>
<lume-alluvial-node-value :bottom="!options.switchText">
{{
formatValue(
block.node.transitionValue || block.node.value,
Expand Down
1 change: 1 addition & 0 deletions packages/lib/src/composables/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export interface AlluvialDiagramOptions extends ChartOptions {
a: SankeyLink<SankeyNodeProps, unknown>,
b: SankeyLink<SankeyNodeProps, unknown>
) => number | undefined | null;
switchText?: boolean;
valueFormat?: Format;
}

Expand Down

0 comments on commit 3322cf2

Please sign in to comment.