From c854eff7979c3d0191dbef58b5f1bbc60317854a Mon Sep 17 00:00:00 2001 From: pissang Date: Mon, 27 Jul 2020 15:51:59 +0800 Subject: [PATCH] fix(treemap): optimize treemap label display in zoom animation --- src/chart/treemap/TreemapView.ts | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/chart/treemap/TreemapView.ts b/src/chart/treemap/TreemapView.ts index 1601e01ff..3dce26578 100644 --- a/src/chart/treemap/TreemapView.ts +++ b/src/chart/treemap/TreemapView.ts @@ -17,7 +17,7 @@ * under the License. */ -import {bind, each, indexOf, curry, extend, retrieve} from 'zrender/src/core/util'; +import {bind, each, indexOf, curry, extend, retrieve, normalizeCssArray} from 'zrender/src/core/util'; import * as graphic from '../../util/graphic'; import { isHighDownDispatcher, @@ -56,7 +56,6 @@ import { ColorString, ECElement } from '../../util/types'; import { windowOpen } from '../../util/format'; import { TextStyleProps } from 'zrender/src/graphic/Text'; import { setLabelStyle, getLabelStatesModels } from '../../label/labelStyle'; -import { rectCoordAxisHandleRemove } from '../../component/axis/axisSplitHelper'; const Group = graphic.Group; const Rect = graphic.Rect; @@ -973,19 +972,30 @@ function renderNode( } ); + const textEl = rectEl.getTextContent(); + const textStyle = textEl.style; + const textPadding = normalizeCssArray(textStyle.padding || 0); + if (upperLabelRect) { rectEl.setTextConfig({ layoutRect: upperLabelRect }); - const textEl = rectEl.getTextContent(); (textEl as ECElement).disableLabelLayout = true; } + else { + textEl.beforeUpdate = function () { + const width = Math.max(rectEl.shape.width - textPadding[1] - textPadding[3], 0); + const height = Math.max(rectEl.shape.height - textPadding[0] - textPadding[2], 0); + if (textStyle.width !== width || textStyle.height !== height) { + textEl.setStyle({ + width, + height + }); + } + }; + } - const textEl = rectEl.getTextContent(); - const textStyle = textEl.style; textStyle.truncateMinChar = 2; - textStyle.width = width; - textStyle.height = height; textStyle.lineOverflow = 'truncate'; addDrillDownIcon(textStyle, upperLabelRect, thisLayout); -- GitLab