Skip to content

Commit

Permalink
fix: In Line.js (used by graph and markLine), when rotation is not sp…
Browse files Browse the repository at this point in the history
…ecified by users, the "auto rotation" rule should not be broken when rendered at the second time (like when drag graph or move dataZoom). (Brought by 7c3f189 apache#12392 )
  • Loading branch information
100pah committed Aug 5, 2020
1 parent f375328 commit 6a9e723
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
18 changes: 12 additions & 6 deletions src/chart/helper/Line.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ function createSymbol(name, lineData, idx) {
);

// rotate by default if symbolRotate is not specified or NaN
symbolPath.rotation = symbolRotate == null || isNaN(symbolRotate)
? undefined
symbolPath.__specifiedRotation = symbolRotate == null || isNaN(symbolRotate)
? void 0
: +symbolRotate * Math.PI / 180 || 0;
symbolPath.name = name;

Expand Down Expand Up @@ -131,13 +131,16 @@ function updateSymbolAndLabelBeforeLineUpdate() {
// when symbol is set to be 'arrow' in markLine,
// symbolRotate value will be ignored, and compulsively use tangent angle.
// rotate by default if symbol rotation is not specified
if (symbolFrom.rotation == null
|| (symbolFrom.shape && symbolFrom.shape.symbolType === 'arrow')) {
var specifiedRotation = symbolFrom.__specifiedRotation;
if (specifiedRotation == null) {
var tangent = line.tangentAt(0);
symbolFrom.attr('rotation', Math.PI / 2 - Math.atan2(
tangent[1], tangent[0]
));
}
else {
symbolFrom.attr('rotation', specifiedRotation);
}
symbolFrom.attr('scale', [invScale * percent, invScale * percent]);
}
if (symbolTo) {
Expand All @@ -146,13 +149,16 @@ function updateSymbolAndLabelBeforeLineUpdate() {
// when symbol is set to be 'arrow' in markLine,
// symbolRotate value will be ignored, and compulsively use tangent angle.
// rotate by default if symbol rotation is not specified
if (symbolTo.rotation == null
|| (symbolTo.shape && symbolTo.shape.symbolType === 'arrow')) {
var specifiedRotation = symbolTo.__specifiedRotation;
if (specifiedRotation == null) {
var tangent = line.tangentAt(1);
symbolTo.attr('rotation', -Math.PI / 2 - Math.atan2(
tangent[1], tangent[0]
));
}
else {
symbolTo.attr('rotation', specifiedRotation);
}
symbolTo.attr('scale', [invScale * percent, invScale * percent]);
}

Expand Down
19 changes: 14 additions & 5 deletions test/markLine-symbolRotate.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6a9e723

Please sign in to comment.