This is an automated email from the ASF dual-hosted git repository. wangzx pushed a commit to branch fix-label-z in repository https://gitbox.apache.org/repos/asf/echarts.git
commit c152d9129784385e3c18504f10cfbdad917b3bcf Author: plainheart <y...@all-my-life.cn> AuthorDate: Sat Mar 27 14:45:30 2021 +0800 fix(label): fix labels are not on the top bug. --- src/chart/line/LineView.ts | 5 ++++ src/core/echarts.ts | 60 +++++++++++++++++++++++++++------------------- 2 files changed, 40 insertions(+), 25 deletions(-) diff --git a/src/chart/line/LineView.ts b/src/chart/line/LineView.ts index 10b0b26..3721ded 100644 --- a/src/chart/line/LineView.ts +++ b/src/chart/line/LineView.ts @@ -840,6 +840,11 @@ class LineView extends ChartView { seriesModel.get('zlevel'), seriesModel.get('z') ); + + // ensure label text of the temporal symbol is on the top of line and area polygon + const symbolLabel = symbol.getSymbolPath().getTextContent(); + symbolLabel && (symbolLabel.z = this._polyline.z + 1); + (symbol as SymbolExtended).__temp = true; data.setItemGraphicEl(dataIndex, symbol); diff --git a/src/core/echarts.ts b/src/core/echarts.ts index b272247..95bd8ff 100644 --- a/src/core/echarts.ts +++ b/src/core/echarts.ts @@ -2157,34 +2157,44 @@ class ECharts extends Eventful<ECEventDefinition> { if (model.preventAutoZ) { return; } - const z = model.get('z'); - const zlevel = model.get('zlevel'); // Set z and zlevel - view.group.traverse(function (el: Displayable) { - if (!el.isGroup) { - z != null && (el.z = z); - zlevel != null && (el.zlevel = zlevel); - - // TODO if textContent is on group. - const label = el.getTextContent(); - const labelLine = el.getTextGuideLine(); - if (label) { - label.z = el.z; - label.zlevel = el.zlevel; - // lift z2 of text content - // TODO if el.emphasis.z2 is spcefied, what about textContent. - label.z2 = el.z2 + 2; - } - if (labelLine) { - const showAbove = el.textGuideLineConfig && el.textGuideLineConfig.showAbove; - labelLine.z = el.z; - labelLine.zlevel = el.zlevel; - labelLine.z2 = el.z2 + (showAbove ? 1 : -1); - } - } - }); + _updateZ(view.group, model.get('z'), model.get('zlevel')); }; + function _updateZ(el: Element, z: number, zlevel: number) { + // Group may also have textContent + const label = el.getTextContent(); + const labelLine = el.getTextGuideLine(); + const isGroup = el.isGroup; + + // always set z and zlevel if label/labelLine exists + if (label || labelLine) { + if (label) { + label.z = z + 1; + label.zlevel = zlevel; + // lift z2 of text content + // TODO if el.emphasis.z2 is spcefied, what about textContent. + isGroup || (label.z2 = (el as Displayable).z2 + 2); + } + else { + const showAbove = el.textGuideLineConfig && el.textGuideLineConfig.showAbove; + labelLine.z = z + 1; + labelLine.zlevel = zlevel; + isGroup || (labelLine.z2 = (el as Displayable).z2 + (showAbove ? 1 : -1)); + } + } + + if (isGroup) { + // set z & zlevel of children elements of Group + el.traverse((childEl: Element) => _updateZ(childEl, z, zlevel)); + } + else { + // not Group + z != null && ((el as Displayable).z = z); + zlevel != null && ((el as Displayable).zlevel = zlevel); + } + } + // Clear states without animation. // TODO States on component. function clearStates(model: ComponentModel, view: ComponentView | ChartView): void { --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@echarts.apache.org For additional commands, e-mail: commits-h...@echarts.apache.org