diff --git a/src/chart/treemap/TreemapView.ts b/src/chart/treemap/TreemapView.ts index b0c6226b30..1a5341448f 100644 --- a/src/chart/treemap/TreemapView.ts +++ b/src/chart/treemap/TreemapView.ts @@ -1004,6 +1004,14 @@ function renderNode( } const textStyle = textEl.style; const textPadding = normalizeCssArray(textStyle.padding || 0); + const textPosition = normalLabelModel.getShallow('position'); + // An explicit rich text height becomes the block height, leaving its tokens + // at the top of the block even when that block is aligned to the bottom. + const isRichTextBottomPosition = textStyle.rich && ( + textPosition === 'insideBottom' + || textPosition === 'insideBottomLeft' + || textPosition === 'insideBottomRight' + ); if (upperLabelRect) { rectEl.setTextConfig({ @@ -1015,9 +1023,12 @@ function renderNode( const width = Math.max( (upperLabelRect ? upperLabelRect.width : rectEl.shape.width) - textPadding[1] - textPadding[3], 0 ); - const height = Math.max( - (upperLabelRect ? upperLabelRect.height : rectEl.shape.height) - textPadding[0] - textPadding[2], 0 - ); + const height = isRichTextBottomPosition + ? null + : Math.max( + (upperLabelRect ? upperLabelRect.height : rectEl.shape.height) + - textPadding[0] - textPadding[2], 0 + ); if (textStyle.width !== width || textStyle.height !== height) { textEl.setStyle({ width, diff --git a/test/treemap-label-position-rich.html b/test/treemap-label-position-rich.html new file mode 100644 index 0000000000..23c500c1aa --- /dev/null +++ b/test/treemap-label-position-rich.html @@ -0,0 +1,98 @@ + + + +
+ + + + + + + + + + + + + + + diff --git a/test/ut/spec/series/treemap.test.ts b/test/ut/spec/series/treemap.test.ts new file mode 100644 index 0000000000..0ad2a81e49 --- /dev/null +++ b/test/ut/spec/series/treemap.test.ts @@ -0,0 +1,113 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import { EChartsType } from '@/src/echarts'; +import { TreemapSeriesOption } from '@/src/chart/treemap/TreemapSeries'; +import Text, { TextStyleProps } from 'zrender/src/graphic/Text'; +import TSpan from 'zrender/src/graphic/TSpan'; +import { createChart, getGraphicElements } from '../../core/utHelper'; + +type TreemapLabelPosition = NonNullable