MCPcopy Index your code
hub / github.com/apache/echarts / computeLabelGeometry

Function computeLabelGeometry

src/label/labelLayoutHelper.ts:156–215  ·  view source on GitHub ↗
(
    out: Partial<TOut>,
    label: ZRText,
    opt?: Pick<LabelLayoutData, 'marginForce' | 'minMarginForce' | 'marginDefault'>
)

Source from the content-addressed store, hash-verified

154 * The props in `out` will be filled if existing, or created.
155 */
156export function computeLabelGeometry<TOut extends LabelGeometry>(
157 out: Partial<TOut>,
158 label: ZRText,
159 opt?: Pick<LabelLayoutData, 'marginForce' | 'minMarginForce' | 'marginDefault'>
160): TOut {
161 // [CAUTION] These props may be modified directly for performance consideration,
162 // therefore, do not output the internal data structure of zrender Element.
163
164 const rawTransform = label.getComputedTransform();
165 out.transform = ensureCopyTransform(out.transform, rawTransform);
166
167 // NOTE: should call `getBoundingRect` after `getComputedTransform`, or may get an inaccurate bounding rect.
168 // The reason is that `getComputedTransform` calls `__host.updateInnerText()` internally, which updates the label
169 // by `textConfig` mounted on the host.
170 // PENDING: add a dirty bit for that in zrender?
171 const outLocalRect = out.localRect = ensureCopyRect(out.localRect, label.getBoundingRect());
172
173 const labelStyleExt = label.style as LabelExtendedTextStyle;
174 let margin = labelStyleExt.margin;
175 const marginForce = opt && opt.marginForce;
176 const minMarginForce = opt && opt.minMarginForce;
177 const marginDefault = opt && opt.marginDefault;
178 let marginType = labelStyleExt.__marginType;
179 if (marginType == null && marginDefault) {
180 margin = marginDefault;
181 marginType = LabelMarginType.textMargin;
182 }
183 // `textMargin` and `minMargin` can not exist both.
184 for (let i = 0; i < 4; i++) {
185 _tmpLabelMargin[i] =
186 (marginType === LabelMarginType.minMargin && minMarginForce && minMarginForce[i] != null)
187 ? minMarginForce[i]
188 : (marginForce && marginForce[i] != null)
189 ? marginForce[i]
190 : (margin ? margin[i] : 0);
191 }
192 if (marginType === LabelMarginType.textMargin) {
193 expandOrShrinkRect(outLocalRect, _tmpLabelMargin, false, false);
194 }
195
196 const outGlobalRect = out.rect = ensureCopyRect(out.rect, outLocalRect);
197 if (rawTransform) {
198 outGlobalRect.applyTransform(rawTransform);
199 }
200
201 // Notice: label.style.margin is actually `minMargin / 2`, handled by `setTextStyleCommon`.
202 if (marginType === LabelMarginType.minMargin) {
203 expandOrShrinkRect(outGlobalRect, _tmpLabelMargin, false, false);
204 }
205
206 out.axisAligned = isBoundingRectAxisAligned(rawTransform);
207
208 (out.label = out.label || {} as TOut['label']).ignore = label.ignore;
209
210 setLabelLayoutDirty(out as TOut, false);
211 setLabelLayoutDirty(out as TOut, true, LABEL_LAYOUT_DIRTY_BIT_OBB);
212 // Do not remove `obb` (if existing) for reuse, just reset the dirty bit.
213

Callers 2

computeLabelGlobalRectFunction · 0.90

Calls 6

ensureCopyTransformFunction · 0.90
ensureCopyRectFunction · 0.90
expandOrShrinkRectFunction · 0.90
setLabelLayoutDirtyFunction · 0.85
getBoundingRectMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…