Skip to content

Commit ec1787a

Browse files
committed
arrow_paths noRotate option
instead of hard-coding these in drawArrowHead
1 parent 05107ed commit ec1787a

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/components/annotations/arrow_paths.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,15 @@
1212
* All paths are tuned for maximum scalability of the arrowhead,
1313
* ie throughout arrowwidth=0.3..3 the head is joined smoothly
1414
* to the line, with the line coming from the left and ending at (0, 0).
15+
*
1516
* `backoff` is the distance to move the arrowhead and the end of the line,
1617
* in order that the arrowhead points to the desired place, either at
1718
* the tip of the arrow or (in the case of circle or square)
1819
* the center of the symbol.
20+
*
21+
* `noRotate`, if truthy, says that this arrowhead should not rotate with the
22+
* arrow. That's the case for squares, which should always be straight, and
23+
* circles, for which it's irrelevant.
1924
*/
2025

2126
module.exports = [
@@ -52,11 +57,13 @@ module.exports = [
5257
// circle
5358
{
5459
path: 'M2,0A2,2 0 1,1 0,-2A2,2 0 0,1 2,0Z',
55-
backoff: 0
60+
backoff: 0,
61+
noRotate: true
5662
},
5763
// square
5864
{
5965
path: 'M2,2V-2H-2V2Z',
60-
backoff: 0
66+
backoff: 0,
67+
noRotate: true
6168
}
6269
];

src/components/annotations/draw_arrow_head.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,15 @@ module.exports = function drawArrowHead(el3, ends, options) {
113113

114114
function drawhead(p, rot) {
115115
if(!headStyle.path) return;
116-
if(options.arrowhead > 5) rot = 0; // don't rotate square or circle
116+
if(headStyle.noRotate) rot = 0;
117117

118118
d3.select(el.parentNode).append('path')
119119
.attr({
120120
'class': el3.attr('class'),
121121
d: headStyle.path,
122122
transform:
123123
'translate(' + p.x + ',' + p.y + ')' +
124-
'rotate(' + (rot * 180 / Math.PI) + ')' +
124+
(rot ? 'rotate(' + (rot * 180 / Math.PI) + ')' : '') +
125125
'scale(' + scale + ')'
126126
})
127127
.style({

0 commit comments

Comments
 (0)