Skip to content

Commit 855739d

Browse files
committed
handle line shapes vhv, hvh, vh and hv
1 parent c8cc834 commit 855739d

File tree

3 files changed

+186
-4
lines changed

3 files changed

+186
-4
lines changed

src/components/drawing/index.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -1540,10 +1540,16 @@ function getMarkerAngle(d, trace) {
15401540
isNumeric(x) &&
15411541
isNumeric(y)
15421542
) {
1543-
angle += atan2(
1544-
y - previousY,
1545-
x - previousX
1546-
) / Math.PI * 180 + 90;
1543+
var dX = x - previousX;
1544+
var dY = y - previousY;
1545+
1546+
var shape = trace.line ? trace.line.shape || '' : '';
1547+
1548+
var lastShapeChar = shape.slice(shape.length - 1);
1549+
if(lastShapeChar === 'h') dY = 0;
1550+
if(lastShapeChar === 'v') dX = 0;
1551+
1552+
angle += atan2(dY, dX) / Math.PI * 180 + 90;
15471553
} else {
15481554
angle = null;
15491555
}
39.5 KB
Loading
+176
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
{
2+
"data": [
3+
{
4+
"line": {
5+
"shape": "linear"
6+
},
7+
"mode": "lines+markers",
8+
"name": "'linear'",
9+
"type": "scatter",
10+
"marker": {
11+
"angleref": "previous",
12+
"symbol": "arrow-wide",
13+
"size": 10
14+
},
15+
"x": [
16+
1,
17+
2,
18+
3,
19+
4,
20+
5
21+
],
22+
"y": [
23+
1,
24+
3,
25+
2,
26+
3,
27+
1
28+
]
29+
},
30+
{
31+
"line": {
32+
"shape": "spline"
33+
},
34+
"mode": "lines+markers",
35+
"name": "'spline'",
36+
"type": "scatter",
37+
"marker": {
38+
"angleref": "previous",
39+
"symbol": "arrow-wide",
40+
"size": 10
41+
},
42+
"x": [
43+
1,
44+
2,
45+
3,
46+
4,
47+
5
48+
],
49+
"y": [
50+
6,
51+
8,
52+
7,
53+
8,
54+
6
55+
]
56+
},
57+
{
58+
"line": {
59+
"shape": "vhv"
60+
},
61+
"mode": "lines+markers",
62+
"name": "'vhv'",
63+
"type": "scatter",
64+
"marker": {
65+
"angleref": "previous",
66+
"symbol": "arrow-wide",
67+
"size": 10
68+
},
69+
"x": [
70+
1,
71+
2,
72+
3,
73+
4,
74+
5
75+
],
76+
"y": [
77+
11,
78+
13,
79+
12,
80+
13,
81+
11
82+
]
83+
},
84+
{
85+
"line": {
86+
"shape": "hvh"
87+
},
88+
"mode": "lines+markers",
89+
"name": "'hvh'",
90+
"type": "scatter",
91+
"marker": {
92+
"angleref": "previous",
93+
"symbol": "arrow-wide",
94+
"size": 10
95+
},
96+
"x": [
97+
1,
98+
2,
99+
3,
100+
4,
101+
5
102+
],
103+
"y": [
104+
16,
105+
18,
106+
17,
107+
18,
108+
16
109+
]
110+
},
111+
{
112+
"line": {
113+
"shape": "vh"
114+
},
115+
"mode": "lines+markers",
116+
"name": "'vh'",
117+
"type": "scatter",
118+
"marker": {
119+
"angleref": "previous",
120+
"symbol": "arrow-wide",
121+
"size": 10
122+
},
123+
"x": [
124+
1,
125+
2,
126+
3,
127+
4,
128+
5
129+
],
130+
"y": [
131+
21,
132+
23,
133+
22,
134+
23,
135+
21
136+
]
137+
},
138+
{
139+
"line": {
140+
"shape": "hv"
141+
},
142+
"mode": "lines+markers",
143+
"name": "'hv'",
144+
"type": "scatter",
145+
"marker": {
146+
"angleref": "previous",
147+
"symbol": "arrow-wide",
148+
"size": 10
149+
},
150+
"x": [
151+
1,
152+
2,
153+
3,
154+
4,
155+
5
156+
],
157+
"y": [
158+
26,
159+
28,
160+
27,
161+
28,
162+
26
163+
]
164+
}
165+
],
166+
"layout": {
167+
"title": {
168+
"text" : "line shape and arrows"
169+
},
170+
"legend": {
171+
"orientation": "h"
172+
},
173+
"height": 700,
174+
"width": 700
175+
}
176+
}

0 commit comments

Comments
 (0)