From e82976c0bfd5568cc242e752ac799000a1051845 Mon Sep 17 00:00:00 2001 From: Ovilia Date: Wed, 31 Jan 2018 15:09:17 +0800 Subject: [PATCH] feat(axis): enable arrow axis offset for polar axis fix and close #7422 --- src/component/axis/AxisBuilder.js | 38 +++++++++++++------------------ test/polarLine.html | 7 +++++- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/src/component/axis/AxisBuilder.js b/src/component/axis/AxisBuilder.js index 5cf864b06..7ba76fa72 100644 --- a/src/component/axis/AxisBuilder.js +++ b/src/component/axis/AxisBuilder.js @@ -189,10 +189,16 @@ var builders = { var symbolWidth = arrowSize[0]; var symbolHeight = arrowSize[1]; - each([ - [opt.rotation + Math.PI / 2, pt1], - [opt.rotation - Math.PI / 2, pt2] - ], function (item, index) { + each([{ + rotate: opt.rotation + Math.PI / 2, + offset: arrowOffset[0], + r: 0 + }, { + rotate: opt.rotation - Math.PI / 2, + offset: arrowOffset[1], + r: Math.sqrt((pt1[0] - pt2[0]) * (pt1[0] - pt2[0]) + + (pt1[1] - pt2[1]) * (pt1[1] - pt2[1])) + }], function (point, index) { if (arrows[index] !== 'none' && arrows[index] != null) { var symbol = createSymbol( arrows[index], @@ -205,26 +211,14 @@ var builders = { ); // Calculate arrow position with offset - var pos; - if (index === 0) { - if (opt.rotation === 0) { - pos = [item[1][0] + arrowOffset[0], item[1][1]]; - } - else { - pos = [item[1][0], item[1][1] + arrowOffset[0]]; - } - } - else { - if (opt.rotation === 0) { - pos = [item[1][0] + arrowOffset[1], item[1][1]]; - } - else { - pos = [item[1][0], item[1][1] + arrowOffset[1]]; - } - } + var r = point.r + point.offset; + var pos = [ + pt1[0] + r * Math.cos(opt.rotation), + pt1[1] - r * Math.sin(opt.rotation) + ]; symbol.attr({ - rotation: item[0], + rotation: point.rotate, position: pos, silent: true }); diff --git a/test/polarLine.html b/test/polarLine.html index 7948eaa48..f1ddca0ca 100644 --- a/test/polarLine.html +++ b/test/polarLine.html @@ -53,9 +53,14 @@ polar: {}, angleAxis: { // data: ['类目1', '类目2', '类目3', '类目4', '类目5',] - data: xAxisData + data: xAxisData, + startAngle: 30 }, radiusAxis: { + axisLine: { + symbol: 'arrow', + symbolOffset: [20, -20] + } }, series: [{ coordinateSystem: 'polar', -- GitLab