diff --git a/packages/sankey/src/Sankey.js b/packages/sankey/src/Sankey.js
index b704a4ab4..ff00edeca 100644
--- a/packages/sankey/src/Sankey.js
+++ b/packages/sankey/src/Sankey.js
@@ -6,7 +6,7 @@
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
-import React from 'react'
+import React, { Fragment } from 'react'
import { uniq } from 'lodash'
import { Container, SvgWrapper } from '@nivo/core'
import { BoxLegendSvg } from '@nivo/legends'
@@ -65,6 +65,8 @@ const Sankey = ({
legends,
legendData,
+
+ layers,
}) => {
let isCurrentNode = () => false
let isCurrentLink = () => false
@@ -100,54 +102,85 @@ const Sankey = ({
motionDamping={motionDamping}
motionStiffness={motionStiffness}
>
- {({ showTooltip, hideTooltip }) => (
-
-
-
- {enableLabels && (
+ {({ showTooltip, hideTooltip }) => {
+ const layerProps = {
+ links,
+ nodes,
+ margin,
+ width,
+ height,
+ outerWidth,
+ outerHeight,
+ }
+
+ const layerById = {
+ links: (
+
+ ),
+ nodes: (
+
+ ),
+ labels: null,
+ legends: legends.map((legend, i) => (
+
+ )),
+ }
+
+ if (enableLabels) {
+ layerById.labels = (
- )}
- {legends.map((legend, i) => (
-
- ))}
-
- )}
+ )
+ }
+
+ return (
+
+ {layers.map((layer, i) => {
+ if (typeof layer === 'function') {
+ return {layer(layerProps)}
+ }
+
+ return layerById[layer]
+ })}
+
+ )
+ }}
)
}
diff --git a/packages/sankey/src/props.js b/packages/sankey/src/props.js
index 473e6bb4f..00aa81034 100644
--- a/packages/sankey/src/props.js
+++ b/packages/sankey/src/props.js
@@ -83,6 +83,13 @@ export const SankeyPropTypes = {
tooltipFormat: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
legends: PropTypes.arrayOf(PropTypes.shape(LegendPropShape)).isRequired,
+
+ layers: PropTypes.arrayOf(
+ PropTypes.oneOfType([
+ PropTypes.oneOf(['links', 'nodes', 'labels', 'legends']),
+ PropTypes.func,
+ ])
+ ).isRequired,
}
export const SankeyDefaultProps = {
@@ -119,4 +126,6 @@ export const SankeyDefaultProps = {
onClick: noop,
legends: [],
+
+ layers: ['links', 'nodes', 'labels', 'legends'],
}