admin管理员组文章数量:1391934
I'm working on a project using raphaelJS, I'm trying to draw arrows at both ends of an arch and while I have the arch down, but it's hard to get arrows.
Thanks in advance for any input!
the issue: how do you draw arrows at the end of curved raphael lines?
- The mockup
- What I got so far, in a JS Fiddle
The Body Tag
<html>
<body>
<div id="arrows"></div>
</body>
</html>
The 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]
THE CSS
#arrows {
display: block;
height: 500px;
width: 500px;
}
#arrows circle,
#arrows path {
stroke: #fff;
stroke-opacity: 1;
stroke-width: 2;
}
I'm working on a project using raphaelJS, I'm trying to draw arrows at both ends of an arch and while I have the arch down, but it's hard to get arrows.
Thanks in advance for any input!
the issue: how do you draw arrows at the end of curved raphael lines?
- The mockup
- What I got so far, in a JS Fiddle
The Body Tag
<html>
<body>
<div id="arrows"></div>
</body>
</html>
The 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]
THE CSS
#arrows {
display: block;
height: 500px;
width: 500px;
}
#arrows circle,
#arrows path {
stroke: #fff;
stroke-opacity: 1;
stroke-width: 2;
}
Share
Improve this question
edited Dec 9, 2014 at 11:16
user1693593
asked Dec 9, 2014 at 6:11
SJAndersonLASJAndersonLA
871 silver badge10 bronze badges
1
- refer here diveintohtml5.info/canvas.html. Very clean and nice intro. It shows how to draw arrow head. – dsharew Commented Dec 9, 2014 at 6:15
1 Answer
Reset to default 7If you are happy to switch to Raphael 2.1.0 you can simply use the arrow-end attribute. So you would add this...
arrow_1.attr({ 'arrow-end': 'classic-wide-long',
'arrow-start': 'classic-wide-long' });
jsfiddle
Docs for this bit (look under attr)
raph doc
本文标签: javascriptRaphaelJShow to draw arrowheads at the end of archsStack Overflow
版权声明:本文标题:javascript - RaphaelJS - how to draw arrow-heads at the end of archs? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744682465a2619494.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论