RaphaelJS - 如何在弧线末端绘制箭头?

3

我正在使用raphaelJS开发一个项目,尝试在拱形的两端绘制箭头。虽然我已经完成了弧线,但是很难得到箭头。

非常感谢您提供的任何帮助!

问题:如何在曲线raphael线的末端绘制箭头?

Body标签

<html>
  <body>
    <div id="arrows"></div>
  </body>
</html>

Coffeescript/Javascript

window.ready = ->
  $canvas = $('body').find '#arrows'
  paper = Raphael $canvas[0], 500, 500

  WIDTH = 500
  HEIGHT = 500
  center = [WIDTH / 2, HEIGHT / 2]
  radius = 230
  stroke = 5

  paper.customAttributes.arc = (center_x, center_y, degrees, radius) ->
    return unless radius
    radians = (90 - degrees) * Math.PI / 180
    arc_x = center_x + radius * Math.cos radians
    arc_y = center_y - radius * Math.sin radians
    path = [
      ['M', center_x, center_y - radius]
      ['M', center_x, center_y - radius]
      ['A', radius, radius, 0, +(degrees > 180), 1, arc_x, arc_y]
    ]
    return {path}

  arrow_1 = paper.path()
  arrow_1.node.setAttribute 'class', 'arrow_1'
  arrow_1.attr {arc: [center[0], center[1], 80, radius]}
  arrow_1.rotate 80, center[1], center[0]

CSS

#arrows {
  display: block;
  height: 500px;
  width: 500px;
}
#arrows circle,
#arrows path {
  stroke: #fff;
  stroke-opacity: 1;
  stroke-width: 2;
}

参考此处http://diveintohtml5.info/canvas.html。非常干净和好的介绍。它展示了如何绘制箭头头。 - dsharew
1个回答

7

如果您愿意切换到Raphael 2.1.0,您可以直接使用arrow-end属性。因此,您需要添加以下内容...

arrow_1.attr({ 'arrow-end':   'classic-wide-long', 
               'arrow-start': 'classic-wide-long' });

jsfiddle

这部分的文档(请查看attr下面的内容)

raph文档


有趣的是,当前 Raphael 文档只列出了 "arrow-end" 而没有 "arrow-start"。幸运的是,这似乎是文档错误,因为它确实有效。起初我以为可能是我错过了某些基本的东西,这可以解释为什么路径只在末尾有箭头! - T.J. Crowder

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接