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