react-vis sankey 字幕和图例

react-vis sankey captions and legend

我正在尝试为 React 寻找桑基图组件。 Vis.JS 有一个带有 D3 和 D3 Sankey 插件的包装器 - react-vis。它毫不费力地吸引了 Sankey。有几个问题 - "an invalid" 数组节点可以降低浏览器 - 可以通过验证解决,图表上没有标签 and/or "series" 的名称。 Sankey 的示例代码如下:

  const nodes = [{name: 'a'}, {name: 'b'}, {name: 'c'}];
  const links = [
    {source: 0, target: 1, value: 10, opacity: 0.2},
    {source: 0, target: 2, value: 20},
    {source: 1, target: 2, value: 30}
  ];

  class Flow extends Component {
    render() {
      return  (
        <div style={{display: 'flex', flexDirection: 'row'}}>
          <div style={{marginLeft: '50px', marginRight: '50px', flexGrow: 1}}>
            <Sankey
              nodes={nodes}
              links={links}
              width={200}
              height={200}
            />
          </div>
        </div>
      );
    }
  }

此图的绘制与演示中的完全相同。添加节点或自定义它们都没有问题。 如果您知道如何使用 react-vis 或 Google 图表反应包装器显示节点名称,请告知。

我刚刚this PR为react-vis的Sankey添加了对标签的支持,实际上并没有实现,很好!

我所做的只是在节点 <g> 中渲染一个 <text> 元素,并根据其在整个图中的位置更改文本方向。

<text
  textAnchor={node.x < width / 2 ? 'start' : 'end'}
  dy=".35em"
  x={node.x < width / 2 ? nWidth + 10 : -10}
  y={node.dy / 2}
>
  {node.name}
</text>

请稍等片刻,直到在新版本中对其进行审核和起草。