diff --git a/src/chart/graph/GraphView.js b/src/chart/graph/GraphView.js index 1b5477f18dd52cfc75fcaed191582a1f6daadc47..e9f5529258f4553868b537f5779beaa60d40390f 100644 --- a/src/chart/graph/GraphView.js +++ b/src/chart/graph/GraphView.js @@ -62,7 +62,7 @@ function fadeOutItem(item, opacityPath, opacityRatio) { function fadeInItem(item, opacityPath) { var opacity = getItemOpacity(item, opacityPath); var el = item.getGraphicEl(); - // Should go back to normal opacity first, consider hoverLayer, + // Should go back to normal opacity first, consider hoverLayer, // where current state is copied to elMirror, and support // emphasis opacity here. el.traverse(function (child) { @@ -221,17 +221,25 @@ export default echarts.extendChartView({ rad = rad - Math.PI; } var textPosition = isLeft ? 'left' : 'right'; - symbolPath.setStyle({ - textRotation: -rad, - textPosition: textPosition, - textOrigin: 'center' - }); - symbolPath.hoverStyle && (symbolPath.hoverStyle.textPosition = textPosition); + graphic.modifyLabelStyle( + symbolPath, + { + textRotation: -rad, + textPosition: textPosition, + textOrigin: 'center' + }, + { + textPosition: textPosition + } + ); } else { - symbolPath.setStyle({ - textRotation: labelRotate *= Math.PI / 180 - }); + graphic.modifyLabelStyle( + symbolPath, + { + textRotation: labelRotate *= Math.PI / 180 + } + ); } }); diff --git a/src/util/graphic.js b/src/util/graphic.js index b8c2373d4c878a9057fcc0a58d19cd04caf172dc..8795440adbc1b812b91d4f6495861ce6659f7dad 100644 --- a/src/util/graphic.js +++ b/src/util/graphic.js @@ -657,6 +657,29 @@ export function setLabelStyle( emphasisStyle.text = emphasisStyleText; } +/** + * Modify label style manually. + * Only works after `setLabelStyle` and `setElementHoverStyle` called. + * + * @param {module:zrender/src/Element} el + * @param {Object} [normalStyleProps] optional + * @param {Object} [emphasisStyleProps] optional + */ +export function modifyLabelStyle(el, normalStyleProps, emphasisStyleProps) { + var elStyle = el.style; + if (normalStyleProps) { + rollbackDefaultTextStyle(elStyle); + el.setStyle(normalStyleProps); + applyDefaultTextStyle(elStyle); + } + elStyle = el.__hoverStl; + if (emphasisStyleProps && elStyle) { + rollbackDefaultTextStyle(elStyle); + zrUtil.extend(elStyle, emphasisStyleProps); + applyDefaultTextStyle(elStyle); + } +} + /** * Set basic textStyle properties. * See more info in `setTextStyleCommon`. @@ -842,10 +865,6 @@ function setTokenTextStyle(textStyle, textStyleModel, globalTextStyle, opt, isEm globalTextStyle.textBorderWidth ); - // Save original textPosition, because style.textPosition will be repalced by - // real location (like [10, 30]) in zrender. - textStyle.insideRawTextPosition = textStyle.textPosition; - if (!isEmphasis) { if (isBlock) { textStyle.insideRollbackOpt = opt; @@ -936,7 +955,7 @@ function applyDefaultTextStyle(textStyle) { } var useInsideStyle = opt.useInsideStyle; - var textPosition = textStyle.insideRawTextPosition; + var textPosition = textStyle.textPosition; var insideRollback; var autoColor = opt.autoColor;