Skip to content

Commit 6bda901

Browse files
refactor(label): remove unnecessary if
1 parent 8126d2f commit 6bda901

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

src/label/LabelManager.ts

+16-16
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ import Model from '../model/Model';
5555
import { prepareLayoutList, hideOverlap, shiftLayoutOnX, shiftLayoutOnY } from './labelLayoutHelper';
5656
import { labelInner, animateLabelValue } from './labelStyle';
5757
import { normalizeRadian } from 'zrender/src/contain/util';
58+
import { TextProps } from 'zrender';
5859

5960
interface LabelDesc {
6061
label: ZRText
@@ -389,6 +390,13 @@ class LabelManager {
389390

390391
const labelLayoutStore = labelLayoutInnerStore(label);
391392
labelLayoutStore.needsUpdateLabelLine = needsUpdateLabelLine;
393+
394+
label.rotation = layoutOption.rotate != null
395+
? layoutOption.rotate * degreeToRadian : defaultLabelAttr.rotation;
396+
397+
label.scaleX = defaultLabelAttr.scaleX;
398+
label.scaleY = defaultLabelAttr.scaleY;
399+
392400
for (const state of DISPLAY_STATES) {
393401
const isNormal = state === 'normal';
394402
const labelState = isNormal ? label : label.ensureState(state);
@@ -400,25 +408,17 @@ class LabelManager {
400408
labelState.y = parsePercent(layoutOption.y, height);
401409
}
402410

403-
if (layoutOption.align != null) {
404-
labelState.style = labelState.style || {};
405-
labelState.style.align = layoutOption.align;
406-
}
407-
408-
if (layoutOption.verticalAlign != null) {
409-
labelState.style = labelState.style || {};
410-
labelState.style.verticalAlign = layoutOption.verticalAlign;
411-
}
412-
413-
labelState.rotation = layoutOption.rotate != null
414-
? layoutOption.rotate * degreeToRadian : defaultLabelAttr.rotation;
415-
416-
labelState.scaleX = defaultLabelAttr.scaleX;
417-
labelState.scaleY = defaultLabelAttr.scaleY;
418411

419412
for (let k = 0; k < LABEL_OPTION_TO_STYLE_KEYS.length; k++) {
420413
const key = LABEL_OPTION_TO_STYLE_KEYS[k];
421-
label.setStyle(key, layoutOption[key] != null ? layoutOption[key] : defaultLabelAttr.style[key]);
414+
const val = layoutOption[key];
415+
if (isNormal) {
416+
label.setStyle(key, val != null ? val : defaultLabelAttr.style[key]);
417+
}
418+
else if (val != null) {
419+
labelState.style = labelState.style || {};
420+
(labelState.style[key] as TextProps['style'][typeof key]) = val;
421+
}
422422
}
423423

424424

0 commit comments

Comments
 (0)