in src/component/legend/LegendView.ts [594:676]
function getLegendStyle(
iconType: string,
legendItemModel: LegendModel['_data'][number],
lineVisualStyle: PathStyleProps,
itemVisualStyle: PathStyleProps,
drawType: 'fill' | 'stroke',
isSelected: boolean,
api: ExtensionAPI
) {
/**
* Use series style if is inherit;
* elsewise, use legend style
*/
function handleCommonProps(style: PathStyleProps, visualStyle: PathStyleProps) {
// If lineStyle.width is 'auto', it is set to be 2 if series has border
if ((style.lineWidth as any) === 'auto') {
style.lineWidth = (visualStyle.lineWidth > 0) ? 2 : 0;
}
each(style, (propVal, propName) => {
style[propName] === 'inherit' && ((style as any)[propName] = visualStyle[propName]);
});
}
// itemStyle
const itemStyleModel = legendItemModel.getModel('itemStyle') as Model<LegendItemStyleOption>;
const itemStyle = itemStyleModel.getItemStyle();
const iconBrushType = iconType.lastIndexOf('empty', 0) === 0 ? 'fill' : 'stroke';
const decalStyle = itemStyleModel.getShallow('decal');
itemStyle.decal = (!decalStyle || decalStyle === 'inherit')
? itemVisualStyle.decal
: createOrUpdatePatternFromDecal(decalStyle, api);
if (itemStyle.fill === 'inherit') {
/**
* Series with visualDrawType as 'stroke' should have
* series stroke as legend fill
*/
itemStyle.fill = itemVisualStyle[drawType];
}
if (itemStyle.stroke === 'inherit') {
/**
* icon type with "emptyXXX" should use fill color
* in visual style
*/
itemStyle.stroke = itemVisualStyle[iconBrushType];
}
if ((itemStyle.opacity as any) === 'inherit') {
/**
* Use lineStyle.opacity if drawType is stroke
*/
itemStyle.opacity = (drawType === 'fill' ? itemVisualStyle : lineVisualStyle).opacity;
}
handleCommonProps(itemStyle, itemVisualStyle);
// lineStyle
const legendLineModel = legendItemModel.getModel('lineStyle') as Model<LegendLineStyleOption>;
const lineStyle: LineStyleProps = legendLineModel.getLineStyle();
handleCommonProps(lineStyle, lineVisualStyle);
// Fix auto color to real color
(itemStyle.fill === 'auto') && (itemStyle.fill = itemVisualStyle.fill);
(itemStyle.stroke === 'auto') && (itemStyle.stroke = itemVisualStyle.fill);
(lineStyle.stroke === 'auto') && (lineStyle.stroke = itemVisualStyle.fill);
if (!isSelected) {
const borderWidth = legendItemModel.get('inactiveBorderWidth');
/**
* Since stroke is set to be inactiveBorderColor, it may occur that
* there is no border in series but border in legend, so we need to
* use border only when series has border if is set to be auto
*/
const visualHasBorder = itemStyle[iconBrushType];
itemStyle.lineWidth = borderWidth === 'auto'
? (itemVisualStyle.lineWidth > 0 && visualHasBorder ? 2 : 0)
: itemStyle.lineWidth;
itemStyle.fill = legendItemModel.get('inactiveColor');
itemStyle.stroke = legendItemModel.get('inactiveBorderColor');
lineStyle.stroke = legendLineModel.get('inactiveColor');
lineStyle.lineWidth = legendLineModel.get('inactiveWidth');
}
return { itemStyle, lineStyle };
}