在Chrome上SVG图表箭头标记-mid被查看3次而不是1次

时间:2016-05-23 07:18:43

标签: javascript d3.js svg

我在D3.js中创建了简单的力图。

节点和节点之间有中间标记的链接(使用标记中)。

问题在于,由于某种原因,在Chrome上这个标记会呈现3次而不是1.在IE和FF上它运行良好。

下面我只在SVG中发布代码,因为这是我认为路径问题没有连接到D3.js.

    <svg class="baseSVG" style="width: 100%; height: 90%;">
  <g class="chart_wrapper">
    <g class="links">
      <g class="link_wrapper">
        <path class="link hate" marker-mid="url(#arrow)" d="M 342.9891277180959 320.7671874251745 A 190.7182256881292 190.7182256881292 0 0 1 225.76595293193114 281.82896265692517 A 190.7182256881292 190.7182256881292 0 0 1 156.98831902253903 179.22732948826612"></path>
      </g>
    </g>
    <g id="person0" class="node person Adam" transform="translate(156.98831902253903,179.22732948826612)">
      <g class="node_inner" transform="translate(-50,-30)">
        <rect width="100" height="60" rx="15" ry="15" class="node_background"></rect>
        <text text-anchor="middle" transform="translate(50,70)">Adam</text>
      </g>
    </g>
    <g id="person1" class="node person Eve" transform="translate(342.9891277180959,320.7671874251745)">
      <g class="node_inner" transform="translate(-50,-30)">
        <rect width="100" height="60" rx="15" ry="15" class="node_background"></rect>
        <text text-anchor="middle" transform="translate(50,70)">Eve</text>
      </g>
    </g>
    <g id="person2" class="node person Kazik" transform="translate(179.355374155828,342.83615430106596)">
      <g class="node_inner" transform="translate(-50,-30)">
        <rect width="100" height="60" rx="15" ry="15" class="node_background"></rect>
        <text text-anchor="middle" transform="translate(50,70)">Kazik</text>
      </g>
    </g>
    <g id="person3" class="node person Janina" transform="translate(320.66071665952427,157.09136472857676)">
      <g class="node_inner" transform="translate(-50,-30)">
        <rect width="100" height="60" rx="15" ry="15" class="node_background"></rect>
        <text text-anchor="middle" transform="translate(50,70)">Janina</text>
      </g>
    </g>
  </g>
  <defs>
    <marker id="double-arrow" refY="0" refX="0" viewBox="0 -20 40 40" markerWidth="40" markerHeight="40" markerUnits="userSpaceOnUse" class="double-arrow" orient="auto">
      <path d="M0,-5L10,0L0,5" transform="translate(20)"></path>
      <path d="M0,0L10,-5L10,5" transform="translate(0)"></path>
    </marker>
  </defs>
  <defs></defs>
  <defs>
    <marker id="arrow" viewBox="0 -5 10 10" refX="5" refY="0" markerWidth="10" markerHeight="10" orient="auto" markerUnits="userSpaceOnUse" class="arrow">
      <path d="M0,-5L10,0L0,5"></path>
    </marker>
  </defs>
  <defs></defs>
</svg>

Example in JSFiddle

1 个答案:

答案 0 :(得分:1)

如果有人在寻找答案。

@theOneGuy和@echonax是对的。要解决的问题是我不能使用marker-mid而是使用marker-start。

因此,不是一个显示带有marker-mid的行的路径定义,而是有两条路径在图表上相遇,创建一条线。第二条路径有标记开始。

标记开始是因为在第二条路径上,因为它需要在z-index方面处于最前面。

 <svg class="baseSVG" style="width: 100%; height: 90%;">
  <g class="chart_wrapper">
    <g class="links">
      <g class="link_wrapper">
        <path class="link love half1" half1="true" d="M 346.8046341906862 223.99666940803763 L 242.21936721772218 252.41406759336707"></path>
        <path class="link love half2" marker-start="url(#arrow)" half1="false" d="M 242.21936721772218 252.41406759336707 L 137.63410024475814 280.8314657786965"></path>
      </g>
      <g class="link_wrapper">
        <path class="link love half1" half1="true" d="M 346.8046341906862 223.99666940803763 A 303.64066468574316 303.64066468574316 0 0 1 247.4635305967095 271.71429428774377"></path>
        <path class="link love half2" marker-start="url(#arrow)" half1="false" d="M 247.4635305967095 271.71429428774377 A 303.64066468574316 303.64066468574316 0 0 1 137.63410024475814 280.8314657786965"></path>
      </g>
      <g class="link_wrapper">
        <path class="link hate half1" half1="true" d="M 137.63410024475814 280.8314657786965 A 166.82033234287158 166.82033234287158 0 0 1 231.73104045974543 213.81361420460564"></path>
        <path class="link hate half2" marker-start="url(#double-arrow)" half1="false" d="M 231.73104045974543 213.81361420460564 A 166.82033234287158 166.82033234287158 0 0 1 346.8046341906862 223.99666940803763"></path>
      </g>
    </g>
    <g id="person0" class="node person Adam" transform="translate(346.8046341906862,223.99666940803763)">
      <g class="node_inner" transform="translate(-50,-30)">
        <rect width="100" height="60" rx="15" ry="15" class="node_background"></rect>
        <text text-anchor="middle" transform="translate(50,70)">Adam</text>
      </g>
    </g>
    <g id="person1" class="node person Eve" transform="translate(137.63410024475814,280.8314657786965)">
      <g class="node_inner" transform="translate(-50,-30)">
        <rect width="100" height="60" rx="15" ry="15" class="node_background"></rect>
        <text text-anchor="middle" transform="translate(50,70)">Eve</text>
      </g>
    </g>
    <g id="person2" class="node person Kazik" transform="translate(289.2970047078608,367.65475135214126)">
      <g class="node_inner" transform="translate(-50,-30)">
        <rect width="100" height="60" rx="15" ry="15" class="node_background"></rect>
        <text text-anchor="middle" transform="translate(50,70)">Kazik</text>
      </g>
    </g>
    <g id="person3" class="node person Janina" transform="translate(226.0636547128077,127.42597160431035)">
      <g class="node_inner" transform="translate(-50,-30)">
        <rect width="100" height="60" rx="15" ry="15" class="node_background"></rect>
        <text text-anchor="middle" transform="translate(50,70)">Janina</text>
      </g>
    </g>
  </g>
  <defs>
    <marker id="double-arrow" refY="0" refX="0" viewBox="0 -20 40 40" markerWidth="40" markerHeight="40" markerUnits="userSpaceOnUse" class="double-arrow" orient="auto">
      <path d="M0,-5L10,0L0,5" transform="translate(20)"></path>
      <path d="M0,0L10,-5L10,5" transform="translate(0)"></path>
    </marker>
  </defs>
  <defs>
    <marker id="arrow" viewBox="0 -5 10 10" refX="5" refY="0" markerWidth="10" markerHeight="10" orient="auto" markerUnits="userSpaceOnUse" class="arrow">
      <path d="M0,-5L10,0L0,5"></path>
    </marker>
  </defs>
</svg>

此外,我已更新Js Fiddle