Skip to content

Commit

Permalink
refactor(label): remove unnecessary if
Browse files Browse the repository at this point in the history
  • Loading branch information
A0nameless0man committed Nov 7, 2024
1 parent 8126d2f commit 6bda901
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions src/label/LabelManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import Model from '../model/Model';
import { prepareLayoutList, hideOverlap, shiftLayoutOnX, shiftLayoutOnY } from './labelLayoutHelper';
import { labelInner, animateLabelValue } from './labelStyle';
import { normalizeRadian } from 'zrender/src/contain/util';
import { TextProps } from 'zrender';

interface LabelDesc {
label: ZRText
Expand Down Expand Up @@ -389,6 +390,13 @@ class LabelManager {

const labelLayoutStore = labelLayoutInnerStore(label);
labelLayoutStore.needsUpdateLabelLine = needsUpdateLabelLine;

label.rotation = layoutOption.rotate != null
? layoutOption.rotate * degreeToRadian : defaultLabelAttr.rotation;

label.scaleX = defaultLabelAttr.scaleX;
label.scaleY = defaultLabelAttr.scaleY;

for (const state of DISPLAY_STATES) {
const isNormal = state === 'normal';
const labelState = isNormal ? label : label.ensureState(state);
Expand All @@ -400,25 +408,17 @@ class LabelManager {
labelState.y = parsePercent(layoutOption.y, height);
}

if (layoutOption.align != null) {
labelState.style = labelState.style || {};
labelState.style.align = layoutOption.align;
}

if (layoutOption.verticalAlign != null) {
labelState.style = labelState.style || {};
labelState.style.verticalAlign = layoutOption.verticalAlign;
}

labelState.rotation = layoutOption.rotate != null
? layoutOption.rotate * degreeToRadian : defaultLabelAttr.rotation;

labelState.scaleX = defaultLabelAttr.scaleX;
labelState.scaleY = defaultLabelAttr.scaleY;

for (let k = 0; k < LABEL_OPTION_TO_STYLE_KEYS.length; k++) {
const key = LABEL_OPTION_TO_STYLE_KEYS[k];
label.setStyle(key, layoutOption[key] != null ? layoutOption[key] : defaultLabelAttr.style[key]);
const val = layoutOption[key];
if (isNormal) {
label.setStyle(key, val != null ? val : defaultLabelAttr.style[key]);
}
else if (val != null) {
labelState.style = labelState.style || {};
(labelState.style[key] as TextProps['style'][typeof key]) = val;
}
}


Expand Down

0 comments on commit 6bda901

Please sign in to comment.