(api: ExtensionAPI)
| 328 | } |
| 329 | |
| 330 | updateLayoutConfig(api: ExtensionAPI) { |
| 331 | const width = api.getWidth(); |
| 332 | const height = api.getHeight(); |
| 333 | |
| 334 | function createDragHandler(el: Element, labelLineModel: Model) { |
| 335 | return function () { |
| 336 | updateLabelLinePoints(el, labelLineModel); |
| 337 | }; |
| 338 | } |
| 339 | for (let i = 0; i < this._labelList.length; i++) { |
| 340 | const labelItem = this._labelList[i]; |
| 341 | const label = labelItem.label; |
| 342 | const hostEl = label.__hostTarget; |
| 343 | const defaultLabelAttr = labelItem.defaultAttr; |
| 344 | let layoutOption; |
| 345 | // TODO A global layout option? |
| 346 | if (isFunction(labelItem.layoutOptionOrCb)) { |
| 347 | layoutOption = labelItem.layoutOptionOrCb( |
| 348 | prepareLayoutCallbackParams(labelItem, hostEl) |
| 349 | ); |
| 350 | } |
| 351 | else { |
| 352 | layoutOption = labelItem.layoutOptionOrCb; |
| 353 | } |
| 354 | |
| 355 | layoutOption = layoutOption || {}; |
| 356 | labelItem.layoutOption = layoutOption; |
| 357 | |
| 358 | const degreeToRadian = Math.PI / 180; |
| 359 | // TODO hostEl should always exists. |
| 360 | // Or label should not have parent because the x, y is all in global space. |
| 361 | if (hostEl) { |
| 362 | hostEl.setTextConfig({ |
| 363 | // Force to set local false. |
| 364 | local: false, |
| 365 | // Ignore position and rotation config on the host el if x or y is changed. |
| 366 | position: (layoutOption.x != null || layoutOption.y != null) |
| 367 | ? null : defaultLabelAttr.attachedPos, |
| 368 | // Ignore rotation config on the host el if rotation is changed. |
| 369 | rotation: layoutOption.rotate != null |
| 370 | ? layoutOption.rotate * degreeToRadian : defaultLabelAttr.attachedRot, |
| 371 | offset: [layoutOption.dx || 0, layoutOption.dy || 0] |
| 372 | }); |
| 373 | } |
| 374 | let needsUpdateLabelLine = false; |
| 375 | if (layoutOption.x != null) { |
| 376 | // TODO width of chart view. |
| 377 | label.x = parsePercent(layoutOption.x, width); |
| 378 | label.setStyle('x', 0); // Ignore movement in style. TODO: origin. |
| 379 | needsUpdateLabelLine = true; |
| 380 | } |
| 381 | else { |
| 382 | label.x = defaultLabelAttr.x; |
| 383 | label.setStyle('x', defaultLabelAttr.style.x); |
| 384 | } |
| 385 | |
| 386 | if (layoutOption.y != null) { |
| 387 | // TODO height of chart view. |
no test coverage detected