Skip to content

Commit ea28e44

Browse files
authored
Merge pull request #19174 from shiersansi/fix-#19050
fix(sunburst): label rotation problem when anticlockwise
2 parents 4a3d090 + 38ec1b5 commit ea28e44

File tree

1 file changed

+28
-9
lines changed

1 file changed

+28
-9
lines changed

src/chart/sunburst/SunburstPiece.ts

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import * as zrUtil from 'zrender/src/core/util';
2121
import * as graphic from '../../util/graphic';
2222
import { toggleHoverEmphasis, SPECIAL_STATES, DISPLAY_STATES } from '../../util/states';
23-
import {createTextStyle} from '../../label/labelStyle';
23+
import { createTextStyle } from '../../label/labelStyle';
2424
import { TreeNode } from '../../data/Tree';
2525
import SunburstSeriesModel, { SunburstSeriesNodeItemOption, SunburstSeriesOption } from './SunburstSeries';
2626
import GlobalModel from '../../model/Global';
@@ -29,7 +29,7 @@ import { ColorString } from '../../util/types';
2929
import Model from '../../model/Model';
3030
import { getECData } from '../../util/innerStore';
3131
import { getSectorCornerRadius } from '../helper/sectorHelper';
32-
import {createOrUpdatePatternFromDecal} from '../../util/decal';
32+
import { createOrUpdatePatternFromDecal } from '../../util/decal';
3333
import ExtensionAPI from '../../core/ExtensionAPI';
3434
import { saveOldStyle } from '../../animation/basicTransition';
3535
import { normalizeRadian } from 'zrender/src/contain/util';
@@ -153,8 +153,8 @@ class SunburstPiece extends graphic.Sector {
153153

154154
const focusOrIndices =
155155
focus === 'ancestor' ? node.getAncestorsIndices()
156-
: focus === 'descendant' ? node.getDescendantIndices()
157-
: focus;
156+
: focus === 'descendant' ? node.getDescendantIndices()
157+
: focus;
158158

159159
toggleHoverEmphasis(this, focusOrIndices, emphasisModel.get('blurScope'), emphasisModel.get('disabled'));
160160
}
@@ -217,7 +217,12 @@ class SunburstPiece extends graphic.Sector {
217217
let textAlign = getLabelAttr(labelStateModel, 'align');
218218
if (labelPosition === 'outside') {
219219
r = layout.r + labelPadding;
220-
textAlign = midAngle > Math.PI / 2 ? 'right' : 'left';
220+
if (layout.clockwise) {
221+
textAlign = midAngle > Math.PI / 2 ? 'right' : 'left';
222+
}
223+
else {
224+
textAlign = midAngle > -Math.PI * 3 / 2 ? 'right' : 'left';
225+
}
221226
}
222227
else {
223228
if (!textAlign || textAlign === 'center') {
@@ -232,14 +237,28 @@ class SunburstPiece extends graphic.Sector {
232237
}
233238
else if (textAlign === 'left') {
234239
r = layout.r0 + labelPadding;
235-
if (midAngle > Math.PI / 2 && !isRadianAroundZero(midAngle - Math.PI / 2)) {
236-
textAlign = 'right';
240+
if (layout.clockwise) {
241+
if (midAngle > Math.PI / 2 && !isRadianAroundZero(midAngle - Math.PI / 2)) {
242+
textAlign = 'right';
243+
}
244+
}
245+
else {
246+
if (midAngle > -Math.PI * 3 / 2 && !isRadianAroundZero(midAngle - Math.PI / 2)) {
247+
textAlign = 'right';
248+
}
237249
}
238250
}
239251
else if (textAlign === 'right') {
240252
r = layout.r - labelPadding;
241-
if (midAngle > Math.PI / 2 && !isRadianAroundZero(midAngle - Math.PI / 2)) {
242-
textAlign = 'left';
253+
if (layout.clockwise) {
254+
if (midAngle > Math.PI / 2 && !isRadianAroundZero(midAngle - Math.PI / 2)) {
255+
textAlign = 'left';
256+
}
257+
}
258+
else {
259+
if (midAngle > -Math.PI * 3 / 2 && !isRadianAroundZero(midAngle - Math.PI / 2)) {
260+
textAlign = 'left';
261+
}
243262
}
244263
}
245264
}

0 commit comments

Comments
 (0)