From da94ef92b3a10952b35780af5810c9c78e9c9b0d Mon Sep 17 00:00:00 2001 From: MiniPear Date: Tue, 4 Jul 2023 11:47:23 +0800 Subject: [PATCH] feat(handle): rotate label for vertical (#294) --- __tests__/integration/snapshots/Slider2.png | Bin 1933 -> 1958 bytes __tests__/integration/snapshots/Slider7.png | Bin 2661 -> 2797 bytes src/ui/slider/handle.ts | 4 +++- src/ui/slider/index.ts | 19 +++++++++++++++---- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/__tests__/integration/snapshots/Slider2.png b/__tests__/integration/snapshots/Slider2.png index add2aa1d5024fe95c30dfdf282e2dd59178cd9ce..fb8da46820160dd60a42e2e17a82b6305a73c57c 100644 GIT binary patch delta 981 zcmV;`11kKD52g>0Hh)`5L_t(|obBAtYn%lh$MGjlrs-tzt5Itc?IK}QtF`FT1x4^s z1rH*4+k))Hf5L+&*~1?8t^F7U*hi9HC3IG5A004mBo}O+FpPHH)DSwLML{StYJ305pjT;L+ zJw0z6KYo01C+7mNeO(L4)YQ~SrBeB9baZs6R;%^z}b&7;NZ`W z)$8^Co}QlZY=1QXZdNw~vZd+i>5e{s?AWm`Z2~~5lz<2Vz^!lF0eS8pi!XLEcxK_k zq%MTs+?&v_@e@1t5_VQYF{?z5k z(<|-1)=tg^VEelI3}kt&+Is)%gP(Ns8UU2zwz3xh;MOD{07L`?fQWzq5D^dnBD*Fa z>+7xCR)3q{_O)BhQr?aSpfja^SzkQ!=2+vxN8{I57HU5p>)kuJw(p*YuT1>u#KoRU z?~O9|17LHd2IS(Iw+>u6|H0h{AADwJc>KYo-fC@Qy>+d!Ja=y3(r0h~;oK*$Rwf^P zex}SF0oYur0a=>;eBZ&N&tAA|;<5SvEi|zA`+vOyw=e7+ysI_+{y!fmib6mDcA-+A zfmHVlTwiXS-}IjquPt8euT*R8UwbD2wx`rPkb_5`y>#~7myiDI?Y|B8kKEnt?W?bU z-)>b}%|`#V#Y;mIe}3+ZGWP>uYo!LHHaxcW@Y64yYJBzK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K zmFO+av1=Cmp|?!n)3KjK+r)QMbv}IpPFV2U5Yn@P3iE`yDp^pNU6K9MRR_h-x76%I z)vg9z{*hq0A43+}luz$xH{IS~f_(y`om4f-f9JYkl84zB=p6QL!F$kd)FOu!+W75J z25bvy8Izo}eGM<*=HP(XyhKLD>(PH_x#M9wqXR715p=-mLI)fxQDw;ncZ#tPddhJr zXIYVAcWCXiZF$sC7p0R<`4zQrJQTO^X9NTlgRi$I&;moHnoNe-V@{P>qJ?qSGozW(Z?ePcAjlcOG z^SM-`bQQ;D_ofSqZ{c|v%sgGMA*3xQi(hxhU#7v)FlVO)e+(!^RF96@KFiX;m0)_$uQ)lWK8ELtZwI`|_k&bKt1%DH9{P4f#%+G;t& zMtg@ruZW#KT;}MAy&+WrimVYgw&AWwfNbqj3uB!OWu8e-{}5wWwPt1wX|`Df3|xm} zCVXdWYB36G5S}!llOc4YFSuS&yw%Z?$q5H6vWcBRzU5`O%p6p{EU!Xi7}5gY7%Sx! za(K~$wL9+7b&{uBAJ`8B3O*JL#P8Zwd8ZOM@WBD#n44Q%d>nAc%M1A6{o?y3ynhM* zx8LEOJRACs9N~wR=cCWeqLfI~y1e{~P{mpA7pwMEUhsOUz5hm8BO;ofLJ2y&XnRYm z;iKv#z3gr_y`4g^^1K71Jn9gTr56Piy(=0X%~u*_Kh!2QO9vv+S`Dm_@I{%i{vcE3 zU#XU{DCof7|jO1b%_Q#Gxst>O{`cmCi0;)V)-1} z0D4p!G*kJ%s*s{@V1|h=b$qj(OJZ`x)IEJ4+rghiZvKt5o3Hw1NIU<>q { private renderLabel(container: Group) { const { showLabel } = this.attributes; - const style = subStyleProps(this.attributes, 'label'); + const { transform, ...style } = subStyleProps(this.attributes, 'label'); const [labelStyle, groupStyle] = splitStyle(style, []); const labelGroup = select(container).maybeAppendByClassName(CLASS_NAMES.labelGroup, 'g').styles(groupStyle); + // @ts-ignore const { text, ...rest } = { ...HANDLE_LABEL_DEFAULT_CFG, ...labelStyle }; ifShow(!!showLabel, labelGroup, (group) => { this.label = group.maybeAppendByClassName(CLASS_NAMES.label, 'text').styles({ ...rest, + transform, text: `${text}`, }); diff --git a/src/ui/slider/index.ts b/src/ui/slider/index.ts index e537f8b0d..bdd2ec452 100644 --- a/src/ui/slider/index.ts +++ b/src/ui/slider/index.ts @@ -296,6 +296,14 @@ export class Slider extends GUI { }; } + private inferTextStyle(handleType: HandleType): Record { + const { orientation } = this.attributes; + if (orientation === 'horizontal') return {}; + if (handleType === 'start') return { transform: 'rotate(90)', textAlign: 'start' }; + if (handleType === 'end') return { transform: 'rotate(90)', textAlign: 'end' }; + return {}; + } + /** * 计算手柄应当处于的位置 * @param handleType start手柄还是end手柄 @@ -315,6 +323,7 @@ export class Slider extends GUI { const temp = new Text({ style: { ...labelStyle, + ...this.inferTextStyle(handleType), text, }, }); @@ -332,8 +341,8 @@ export class Slider extends GUI { // 相对于获取两端可用空间 const { width: iW, height: iH } = this.availableSpace; const { x: fX, y: fY, width: fW, height: fH } = this.calcMask(); + const totalSpacing = spacing + size; if (orientation === 'horizontal') { - const totalSpacing = spacing + size; const finalWidth = totalSpacing + textWidth / 2; if (handleType === 'start') { const left = fX - totalSpacing - textWidth; @@ -343,11 +352,12 @@ export class Slider extends GUI { x = sign ? finalWidth : -finalWidth; } } else { - const finalWidth = spacing + size; + const positiveSize = totalSpacing; + const negativeSize = textHeight + totalSpacing; if (handleType === 'start') { - y = fY - size > textHeight ? -finalWidth : finalWidth; + y = fY - size > textHeight ? -negativeSize : positiveSize; } else { - y = iH - fY - fH - size > textHeight ? finalWidth : -finalWidth; + y = iH - (fY + fH) - size > textHeight ? negativeSize : -positiveSize; } } return { x, y, text }; @@ -360,6 +370,7 @@ export class Slider extends GUI { return { ...style, ...this.calcHandleText(handleType), + ...this.inferTextStyle(handleType), }; }