Skip to content

Commit f598c92

Browse files
committed
add arrowanchor property
1 parent 51fcb2e commit f598c92

File tree

7 files changed

+24
-2
lines changed

7 files changed

+24
-2
lines changed

src/components/annotations/attributes.js

+8
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,14 @@ module.exports = {
175175
editType: 'arraydraw',
176176
description: 'Sets the annotation arrow head style.'
177177
},
178+
arrowanchor: {
179+
valType: 'enumerated',
180+
values: ['end', 'start', 'start+end'],
181+
dflt: 'end',
182+
role: 'style',
183+
editType: 'arraydraw',
184+
description: 'Sets the annotation arrow head position.'
185+
},
178186
arrowsize: {
179187
valType: 'number',
180188
min: 0.3,

src/components/annotations/common_defaults.js

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ module.exports = function handleAnnotationCommonDefaults(annIn, annOut, fullLayo
3737
if(showArrow) {
3838
coerce('arrowcolor', borderOpacity ? annOut.bordercolor : Color.defaultLine);
3939
coerce('arrowhead');
40+
coerce('arrowanchor');
4041
coerce('arrowsize');
4142
coerce('arrowwidth', ((borderOpacity && borderWidth) || 1) * 2);
4243
coerce('standoff');

src/components/annotations/draw.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,8 @@ function drawRaw(gd, options, index, subplotId, xa, ya) {
509509
});
510510

511511
var strokewidth = options.arrowwidth,
512-
arrowColor = options.arrowcolor;
512+
arrowColor = options.arrowcolor,
513+
arrowAnchor = options.arrowanchor;
513514

514515
var arrowGroup = annGroup.append('g')
515516
.style({opacity: Color.opacity(arrowColor)})
@@ -520,7 +521,7 @@ function drawRaw(gd, options, index, subplotId, xa, ya) {
520521
.style('stroke-width', strokewidth + 'px')
521522
.call(Color.stroke, Color.rgb(arrowColor));
522523

523-
drawArrowHead(arrow, 'end', options);
524+
drawArrowHead(arrow, arrowAnchor, options);
524525

525526
// the arrow dragger is a small square right at the head, then a line to the tail,
526527
// all expanded by a stroke width of 6px plus the arrow line width

src/components/annotations3d/attributes.js

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ module.exports = overrideAll({
7272
showarrow: annAtts.showarrow,
7373
arrowcolor: annAtts.arrowcolor,
7474
arrowhead: annAtts.arrowhead,
75+
arrowanchor: annAtts.arrowanchor,
7576
arrowsize: annAtts.arrowsize,
7677
arrowwidth: annAtts.arrowwidth,
7778
standoff: annAtts.standoff,

test/image/baselines/annotations.png

131 Bytes
Loading

test/image/mocks/annotations.json

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"arrowcolor":"rgb(166, 28, 0)","borderpad":3,"textangle":50,"x":5,"y":1
4646
},
4747
{"text":"","showarrow":true,"borderwidth":1.2,"arrowhead":2,"axref":"x","ayref":"y","x":5,"y":3,"ax":4,"ay":5},
48+
{"text":"","showarrow":true,"borderwidth":1.2,"arrowhead":2,"arrowanchor":"start+end","axref":"x","ayref":"y","x":2,"y":4,"ax":3,"ay":4},
4849
{"text":"","showarrow":true,"borderwidth":1.2,"arrowhead":2,"axref":"x","ayref":"y","x":6,"y":2,"ax":3,"ay":3},
4950
{
5051
"text": "arrow ML<br>+standoff", "x": 2, "y": 2, "ax": 20, "ay": 20,

test/jasmine/tests/annotations_test.js

+10
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,16 @@ describe('Test annotations', function() {
140140
expect(layoutOut.annotations[2]._xclick).toBe(2, 'log');
141141
expect(layoutOut.annotations[2]._yclick).toBe('A', 'category');
142142
});
143+
144+
it('should default to end for arrowanchor', function() {
145+
var layoutIn = {
146+
annotations: [{ showarrow: true, arrowhead: 2 }]
147+
};
148+
149+
var out = _supply(layoutIn);
150+
151+
expect(out[0].arrowanchor).toEqual('end');
152+
});
143153
});
144154
});
145155

0 commit comments

Comments
 (0)