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 2da948a
Showing 1 changed file with 23 additions and 16 deletions.
39 changes: 23 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 @@ -378,6 +387,12 @@ class LabelManager {
label.setStyle('y', defaultLabelAttr.style.y);
}

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

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

if (layoutOption.labelLinePoints) {
const guideLine = hostEl.getTextGuideLine();
if (guideLine) {
Expand All @@ -400,25 +415,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 2da948a

Please sign in to comment.