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 a1290b2
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 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, TextState } from 'zrender';

interface LabelDesc {
label: ZRText
Expand Down Expand Up @@ -313,6 +314,14 @@ class LabelManager {
});
}

updateLabelStatusStyle<T extends keyof TextState['style']>(
labelState:TextState,
key:T,
val: TextState['style'][T]) {
labelState.style = labelState.style || {};
labelState.style[key] = val;
}

updateLayoutConfig(api: ExtensionAPI) {
const width = api.getWidth();
const height = api.getHeight();
Expand Down Expand Up @@ -389,6 +398,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 +416,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 a1290b2

Please sign in to comment.