提交 f40e0dd1 编写于 作者: P pissang

feat(label): change label default color to black/white, 'inherit' to set color same with element

上级 7db0a9c0
...@@ -566,7 +566,7 @@ function updateStyle( ...@@ -566,7 +566,7 @@ function updateStyle(
labelFetcher: seriesModel, labelFetcher: seriesModel,
labelDataIndex: dataIndex, labelDataIndex: dataIndex,
defaultText: getDefaultLabel(seriesModel.getData(), dataIndex), defaultText: getDefaultLabel(seriesModel.getData(), dataIndex),
autoColor: style.fill as ColorString, inheritColor: style.fill as ColorString,
defaultOutsidePosition: labelPositionOutside defaultOutsidePosition: labelPositionOutside
} }
); );
......
...@@ -952,7 +952,7 @@ function updateCommon( ...@@ -952,7 +952,7 @@ function updateCommon(
labelFetcher: opt.seriesModel, labelFetcher: opt.seriesModel,
labelDataIndex: dataIndex, labelDataIndex: dataIndex,
defaultText: getDefaultLabel(opt.seriesModel.getData(), dataIndex), defaultText: getDefaultLabel(opt.seriesModel.getData(), dataIndex),
autoColor: symbolMeta.style.fill as ColorString, inheritColor: symbolMeta.style.fill as ColorString,
defaultOutsidePosition: barPositionOutside defaultOutsidePosition: barPositionOutside
} }
); );
......
...@@ -482,7 +482,7 @@ function makeRenderItem(customSeries, data, ecModel, api) { ...@@ -482,7 +482,7 @@ function makeRenderItem(customSeries, data, ecModel, api) {
: currLabelNormalModel; : currLabelNormalModel;
const textStyle = graphicUtil.createTextStyle(labelModel, null, { const textStyle = graphicUtil.createTextStyle(labelModel, null, {
autoColor: currVisualColor, inheritColor: currVisualColor,
isRectText: true isRectText: true
}); });
......
...@@ -262,7 +262,7 @@ class GaugeView extends ChartView { ...@@ -262,7 +262,7 @@ class GaugeView extends ChartView {
y: unitY * (r - splitLineLen - distance) + cy, y: unitY * (r - splitLineLen - distance) + cy,
verticalAlign: unitY < -0.4 ? 'top' : (unitY > 0.4 ? 'bottom' : 'middle'), verticalAlign: unitY < -0.4 ? 'top' : (unitY > 0.4 ? 'bottom' : 'middle'),
align: unitX < -0.4 ? 'left' : (unitX > 0.4 ? 'right' : 'center') align: unitX < -0.4 ? 'left' : (unitX > 0.4 ? 'right' : 'center')
}, {autoColor: autoColor}), }, {inheritColor: autoColor}),
silent: true silent: true
})); }));
} }
...@@ -423,7 +423,7 @@ class GaugeView extends ChartView { ...@@ -423,7 +423,7 @@ class GaugeView extends ChartView {
text: data.getName(0), text: data.getName(0),
align: 'center', align: 'center',
verticalAlign: 'middle' verticalAlign: 'middle'
}, {autoColor: autoColor}) }, {inheritColor: autoColor})
})); }));
} }
} }
...@@ -463,7 +463,7 @@ class GaugeView extends ChartView { ...@@ -463,7 +463,7 @@ class GaugeView extends ChartView {
height: isNaN(height) ? null : height, height: isNaN(height) ? null : height,
align: 'center', align: 'center',
verticalAlign: 'middle' verticalAlign: 'middle'
}, {autoColor: autoColor}) }, {inheritColor: autoColor})
})); }));
} }
} }
......
...@@ -256,7 +256,7 @@ class Line extends graphic.Group { ...@@ -256,7 +256,7 @@ class Line extends graphic.Group {
label.useStyle(graphic.createTextStyle(labelModel, { label.useStyle(graphic.createTextStyle(labelModel, {
text: normalText as string text: normalText as string
}, { }, {
autoColor: defaultLabelColor inheritColor: defaultLabelColor
})); }));
label.__align = label.style.align; label.__align = label.style.align;
......
...@@ -266,7 +266,7 @@ class Symbol extends graphic.Group { ...@@ -266,7 +266,7 @@ class Symbol extends graphic.Group {
labelFetcher: seriesModel, labelFetcher: seriesModel,
labelDataIndex: idx, labelDataIndex: idx,
defaultText: getLabelDefaultText, defaultText: getLabelDefaultText,
autoColor: visualColor as ColorString inheritColor: visualColor as ColorString
} }
); );
......
...@@ -244,6 +244,7 @@ class PieSeriesModel extends SeriesModel<PieSeriesOption> { ...@@ -244,6 +244,7 @@ class PieSeriesModel extends SeriesModel<PieSeriesOption> {
height: null, height: null,
label: { label: {
color: 'inherit',
// If rotate around circle // If rotate around circle
rotate: 0, rotate: 0,
show: true, show: true,
......
...@@ -182,6 +182,7 @@ class PiePiece extends graphic.Sector { ...@@ -182,6 +182,7 @@ class PiePiece extends graphic.Sector {
{ {
labelFetcher: data.hostModel as PieSeriesModel, labelFetcher: data.hostModel as PieSeriesModel,
labelDataIndex: idx, labelDataIndex: idx,
inheritColor: visualColor,
defaultText: seriesModel.getFormattedLabel(idx, 'normal') defaultText: seriesModel.getFormattedLabel(idx, 'normal')
|| data.getName(idx) || data.getName(idx)
}, },
...@@ -193,9 +194,7 @@ class PiePiece extends graphic.Sector { ...@@ -193,9 +194,7 @@ class PiePiece extends graphic.Sector {
// Set textConfig on sector. // Set textConfig on sector.
sector.setTextConfig({ sector.setTextConfig({
local: true, local: true,
insideStroke: visualColor, outsideFill: labelModel.get('color') === 'inherit' ? visualColor : 'auto'
// insideFill: 'auto',
outsideFill: visualColor
}); });
// Make sure update style on labelText after setLabelStyle. // Make sure update style on labelText after setLabelStyle.
......
...@@ -237,7 +237,7 @@ class RadarView extends ChartView { ...@@ -237,7 +237,7 @@ class RadarView extends ChartView {
labelDataIndex: idx, labelDataIndex: idx,
labelDimIndex: symbolPath.__dimIdx, labelDimIndex: symbolPath.__dimIdx,
defaultText: defaultText as string, defaultText: defaultText as string,
autoColor: color as ColorString inheritColor: color as ColorString
} }
); );
}); });
......
...@@ -936,7 +936,7 @@ function renderNode( ...@@ -936,7 +936,7 @@ function renderNode(
rectEl, normalLabelModel, emphasisLabelModel, rectEl, normalLabelModel, emphasisLabelModel,
{ {
defaultText: isShow ? text : null, defaultText: isShow ? text : null,
autoColor: visualColor inheritColor: visualColor
} }
); );
......
...@@ -300,7 +300,7 @@ class MarkAreaView extends MarkerView { ...@@ -300,7 +300,7 @@ class MarkAreaView extends MarkerView {
labelFetcher: maModel, labelFetcher: maModel,
labelDataIndex: idx, labelDataIndex: idx,
defaultText: areaData.getName(idx) || '', defaultText: areaData.getName(idx) || '',
autoColor: typeof style.fill === 'string' inheritColor: typeof style.fill === 'string'
? colorUtil.modifyAlpha(style.fill, 1) : '#000' ? colorUtil.modifyAlpha(style.fill, 1) : '#000'
} }
); );
......
...@@ -122,10 +122,10 @@ type TextCommonParams = { ...@@ -122,10 +122,10 @@ type TextCommonParams = {
*/ */
disableBox?: boolean disableBox?: boolean
/** /**
* Specify a color when color is 'auto', * Specify a color when color is 'inherit',
* for textFill, textStroke, textBackgroundColor, and textBorderColor. If autoColor specified, it is used as default textFill. * If inheritColor specified, it is used as default textFill.
*/ */
autoColor?: ColorString inheritColor?: ColorString
getTextPosition?: (textStyleModel: Model, isEmphasis?: boolean) => string | string[] | number[] getTextPosition?: (textStyleModel: Model, isEmphasis?: boolean) => string | string[] | number[]
...@@ -816,7 +816,7 @@ export {setLabelStyle}; ...@@ -816,7 +816,7 @@ export {setLabelStyle};
export function createTextStyle( export function createTextStyle(
textStyleModel: Model, textStyleModel: Model,
specifiedTextStyle?: TextStyleProps, // Can be overrided by settings in model. specifiedTextStyle?: TextStyleProps, // Can be overrided by settings in model.
opt?: Pick<TextCommonParams, 'autoColor' | 'disableBox'>, opt?: Pick<TextCommonParams, 'inheritColor' | 'disableBox'>,
isNotNormal?: boolean, isNotNormal?: boolean,
isAttached?: boolean // If text is attached on an element. If so, auto color will handling in zrender. isAttached?: boolean // If text is attached on an element. If so, auto color will handling in zrender.
) { ) {
...@@ -831,7 +831,7 @@ export function createTextStyle( ...@@ -831,7 +831,7 @@ export function createTextStyle(
export function createTextConfig( export function createTextConfig(
textStyle: TextStyleProps, textStyle: TextStyleProps,
textStyleModel: Model, textStyleModel: Model,
opt?: Pick<TextCommonParams, 'getTextPosition' | 'defaultOutsidePosition' | 'autoColor'>, opt?: Pick<TextCommonParams, 'getTextPosition' | 'defaultOutsidePosition' | 'inheritColor'>,
isNotNormal?: boolean isNotNormal?: boolean
) { ) {
const textConfig: ElementTextConfig = {}; const textConfig: ElementTextConfig = {};
...@@ -868,19 +868,10 @@ export function createTextConfig( ...@@ -868,19 +868,10 @@ export function createTextConfig(
} }
// fill and auto is determined by the color of path fill if it's not specified by developers. // fill and auto is determined by the color of path fill if it's not specified by developers.
textConfig.outsideFill = opt.autoColor || null;
// if (!textStyle.fill) { textConfig.outsideFill = textStyleModel.get('color') === 'inherit'
// textConfig.insideFill = 'auto'; ? (opt.inheritColor || null)
// textConfig.outsideFill = opt.autoColor || null; : 'auto';
// }
// if (!textStyle.stroke) {
// textConfig.insideStroke = 'auto';
// }
// else if (opt.autoColor) {
// // TODO: stroke set to autoColor. if label is inside?
// textConfig.insideStroke = opt.autoColor;
// }
return textConfig; return textConfig;
} }
...@@ -898,7 +889,7 @@ export function createTextConfig( ...@@ -898,7 +889,7 @@ export function createTextConfig(
function setTextStyleCommon( function setTextStyleCommon(
textStyle: TextStyleProps, textStyle: TextStyleProps,
textStyleModel: Model, textStyleModel: Model,
opt?: Pick<TextCommonParams, 'autoColor' | 'disableBox'>, opt?: Pick<TextCommonParams, 'inheritColor' | 'disableBox'>,
isNotNormal?: boolean, isNotNormal?: boolean,
isAttached?: boolean isAttached?: boolean
) { ) {
...@@ -1003,7 +994,7 @@ function setTokenTextStyle( ...@@ -1003,7 +994,7 @@ function setTokenTextStyle(
textStyle: TextStyleProps['rich'][string], textStyle: TextStyleProps['rich'][string],
textStyleModel: Model<LabelOption>, textStyleModel: Model<LabelOption>,
globalTextStyle: LabelOption, globalTextStyle: LabelOption,
opt?: Pick<TextCommonParams, 'autoColor' | 'disableBox'>, opt?: Pick<TextCommonParams, 'inheritColor' | 'disableBox'>,
isNotNormal?: boolean, isNotNormal?: boolean,
isAttached?: boolean, isAttached?: boolean,
isBlock?: boolean isBlock?: boolean
...@@ -1011,14 +1002,24 @@ function setTokenTextStyle( ...@@ -1011,14 +1002,24 @@ function setTokenTextStyle(
// In merge mode, default value should not be given. // In merge mode, default value should not be given.
globalTextStyle = !isNotNormal && globalTextStyle || EMPTY_OBJ; globalTextStyle = !isNotNormal && globalTextStyle || EMPTY_OBJ;
const autoColor = opt && opt.autoColor; const inheritColor = opt && opt.inheritColor;
let fillColor = textStyleModel.getShallow('color'); let fillColor = textStyleModel.getShallow('color');
let strokeColor = textStyleModel.getShallow('textBorderColor'); let strokeColor = textStyleModel.getShallow('textBorderColor');
if (fillColor === 'auto' && autoColor) { if (fillColor === 'inherit') {
fillColor = autoColor; if (inheritColor) {
fillColor = inheritColor;
}
else {
fillColor = null;
}
} }
if (strokeColor === 'auto' && autoColor) { if (strokeColor === 'inherit' && inheritColor) {
strokeColor = autoColor; if (inheritColor) {
strokeColor = inheritColor;
}
else {
strokeColor = inheritColor;
}
} }
fillColor = fillColor || globalTextStyle.color; fillColor = fillColor || globalTextStyle.color;
strokeColor = strokeColor || globalTextStyle.textBorderColor; strokeColor = strokeColor || globalTextStyle.textBorderColor;
...@@ -1040,8 +1041,8 @@ function setTokenTextStyle( ...@@ -1040,8 +1041,8 @@ function setTokenTextStyle(
// TODO // TODO
if (!isNotNormal && !isAttached) { if (!isNotNormal && !isAttached) {
// Set default finally. // Set default finally.
if (textStyle.fill == null && opt.autoColor) { if (textStyle.fill == null && opt.inheritColor) {
textStyle.fill = opt.autoColor; textStyle.fill = opt.inheritColor;
} }
} }
...@@ -1073,11 +1074,11 @@ function setTokenTextStyle( ...@@ -1073,11 +1074,11 @@ function setTokenTextStyle(
if (!isBlock || !opt.disableBox) { if (!isBlock || !opt.disableBox) {
if (textStyle.backgroundColor === 'auto' && autoColor) { if (textStyle.backgroundColor === 'auto' && inheritColor) {
textStyle.backgroundColor = autoColor; textStyle.backgroundColor = inheritColor;
} }
if (textStyle.borderColor === 'auto' && autoColor) { if (textStyle.borderColor === 'auto' && inheritColor) {
textStyle.borderColor = autoColor; textStyle.borderColor = inheritColor;
} }
for (let i = 0; i < TEXT_PROPS_BOX.length; i++) { for (let i = 0; i < TEXT_PROPS_BOX.length; i++) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册