Skip to content

Commit f949aeb

Browse files
committed
fix(line): rotate by default if symbolRotate in markLine is not specified or NaN.
1 parent 695375d commit f949aeb

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

src/chart/helper/Line.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ function createSymbol(name, lineData, idx) {
5656
symbolSize[0], symbolSize[1], color
5757
);
5858

59-
symbolPath.rotation = (symbolRotate || 0) * Math.PI / 180 || 0;
59+
// rotate by default if symbolRotate is not specified or NaN
60+
symbolPath.rotation = symbolRotate == null || isNaN(symbolRotate)
61+
? undefined
62+
: +symbolRotate * Math.PI / 180 || 0;
6063
symbolPath.name = name;
6164

6265
return symbolPath;
@@ -125,9 +128,11 @@ function updateSymbolAndLabelBeforeLineUpdate() {
125128
if (symbolFrom) {
126129
symbolFrom.attr('position', fromPos);
127130
// Fix #12388
128-
// when symbol is set to be 'arrow' in markLine,
129-
// symbolRotate value will be ignored, and compulsively use tangent angle.
130-
if(symbolFrom.shape && symbolFrom.shape.symbolType === 'arrow') {
131+
// when symbol is set to be 'arrow' in markLine,
132+
// symbolRotate value will be ignored, and compulsively use tangent angle.
133+
// rotate by default if symbol rotation is not specified
134+
if (symbolFrom.rotation == null
135+
|| (symbolFrom.shape && symbolFrom.shape.symbolType === 'arrow')) {
131136
var tangent = line.tangentAt(0);
132137
symbolFrom.attr('rotation', Math.PI / 2 - Math.atan2(
133138
tangent[1], tangent[0]
@@ -140,7 +145,9 @@ function updateSymbolAndLabelBeforeLineUpdate() {
140145
// Fix #12388
141146
// when symbol is set to be 'arrow' in markLine,
142147
// symbolRotate value will be ignored, and compulsively use tangent angle.
143-
if(symbolTo.shape && symbolTo.shape.symbolType === 'arrow') {
148+
// rotate by default if symbol rotation is not specified
149+
if (symbolTo.rotation == null
150+
|| (symbolTo.shape && symbolTo.shape.symbolType === 'arrow')) {
144151
var tangent = line.tangentAt(1);
145152
symbolTo.attr('rotation', -Math.PI / 2 - Math.atan2(
146153
tangent[1], tangent[0]

test/markLine-symbolRotate.html

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,12 @@
116116
}),
117117
markLine: {
118118
silent: true,
119+
// symbol: 'triangle',
119120
data: [
120121
{
121122
yAxis: 50,
122-
symbolRotate: 60,
123+
// symbolRotate: 0,
124+
// symbolRotate: null,
123125
symbol: 'triangle',
124126
symbolSize: 20
125127
},{
@@ -153,7 +155,8 @@
153155
symbolRotate: 180,
154156
label: {
155157
position: 'start',
156-
formatter: 'Average'
158+
formatter: 'Average',
159+
distance: 10
157160
},
158161
type: 'average',
159162
lineStyle: {

0 commit comments

Comments
 (0)