From 8fea28469a4c6927f5c13aa7ea187e66a19565d1 Mon Sep 17 00:00:00 2001 From: pissang Date: Tue, 21 Jul 2020 16:58:21 +0800 Subject: [PATCH] fix(label): support legacy style color: 'auto' for color: 'inherit' usage. Not breaking the exists code. --- src/chart/gauge/GaugeView.ts | 4 +++- src/label/labelStyle.ts | 46 +++++++++++++++++++++++++++++------- 2 files changed, 40 insertions(+), 10 deletions(-) diff --git a/src/chart/gauge/GaugeView.ts b/src/chart/gauge/GaugeView.ts index 309bc49c5..acd83fa17 100644 --- a/src/chart/gauge/GaugeView.ts +++ b/src/chart/gauge/GaugeView.ts @@ -264,7 +264,9 @@ class GaugeView extends ChartView { y: unitY * (r - splitLineLen - distance) + cy, verticalAlign: unitY < -0.4 ? 'top' : (unitY > 0.4 ? 'bottom' : 'middle'), align: unitX < -0.4 ? 'left' : (unitX > 0.4 ? 'right' : 'center') - }, {inheritColor: autoColor}), + }, { + inheritColor: autoColor + }), silent: true })); } diff --git a/src/label/labelStyle.ts b/src/label/labelStyle.ts index 731d1bb4f..449e9f2a4 100644 --- a/src/label/labelStyle.ts +++ b/src/label/labelStyle.ts @@ -16,6 +16,8 @@ import { import GlobalModel from '../model/Global'; import { isFunction, retrieve2, extend, keys, trim } from 'zrender/src/core/util'; import { SPECIAL_STATES, DISPLAY_STATES } from '../util/states'; +import { __DEV__ } from '../config'; +import { deprecateReplaceLog } from '../util/log'; type TextCommonParams = { /** @@ -30,6 +32,11 @@ type TextCommonParams = { defaultOutsidePosition?: LabelOption['position'] + /** + * If support legacy 'auto' for 'inherit' usage. + */ + // supportLegacyAuto?: boolean + textStyle?: ZRStyleProps }; const EMPTY_OBJ = {}; @@ -406,7 +413,12 @@ function setTokenTextStyle( const inheritColor = opt && opt.inheritColor; let fillColor = textStyleModel.getShallow('color'); let strokeColor = textStyleModel.getShallow('textBorderColor'); - if (fillColor === 'inherit') { + if (fillColor === 'inherit' || fillColor === 'auto') { + if (__DEV__) { + if (fillColor === 'auto') { + deprecateReplaceLog('color: \'auto\'', 'color: \'inherit\''); + } + } if (inheritColor) { fillColor = inheritColor; } @@ -414,12 +426,17 @@ function setTokenTextStyle( fillColor = null; } } - if (strokeColor === 'inherit' && inheritColor) { + if (strokeColor === 'inherit' || (strokeColor === 'auto')) { + if (__DEV__) { + if (strokeColor === 'auto') { + deprecateReplaceLog('color: \'auto\'', 'color: \'inherit\''); + } + } if (inheritColor) { strokeColor = inheritColor; } else { - strokeColor = inheritColor; + strokeColor = null; } } fillColor = fillColor || globalTextStyle.color; @@ -465,12 +482,6 @@ function setTokenTextStyle( } } if (!isBlock || !opt.disableBox) { - if (textStyle.backgroundColor === 'auto' && inheritColor) { - textStyle.backgroundColor = inheritColor; - } - if (textStyle.borderColor === 'auto' && inheritColor) { - textStyle.borderColor = inheritColor; - } for (let i = 0; i < TEXT_PROPS_BOX.length; i++) { const key = TEXT_PROPS_BOX[i]; const val = textStyleModel.getShallow(key); @@ -478,6 +489,23 @@ function setTokenTextStyle( (textStyle as any)[key] = val; } } + + if ((textStyle.backgroundColor === 'auto' || textStyle.backgroundColor === 'inherit') && inheritColor) { + if (__DEV__) { + if (textStyle.backgroundColor === 'auto') { + deprecateReplaceLog('backgroundColor: \'auto\'', 'backgroundColor: \'inherit\''); + } + } + textStyle.backgroundColor = inheritColor; + } + if ((textStyle.borderColor === 'auto' || textStyle.borderColor === 'inherit') && inheritColor) { + if (__DEV__) { + if (textStyle.borderColor === 'auto') { + deprecateReplaceLog('borderColor: \'auto\'', 'borderColor: \'inherit\''); + } + } + textStyle.borderColor = inheritColor; + } } } export function getFont( -- GitLab