提交 3966af83 编写于 作者: O Ovilia

refactor(legend): render legend in legendView when icon is defined

上级 da6d0409
......@@ -39,10 +39,8 @@ import {
import List from '../../data/List';
import type Cartesian2D from '../../coord/cartesian/Cartesian2D';
import type Polar from '../../coord/polar/Polar';
import {PathStyleProps} from 'zrender/src/graphic/Path';
import {createSymbol, ECSymbol} from '../../util/symbol';
import {Group} from '../../util/graphic';
import {LineStyleProps} from '../../model/mixin/lineStyle';
import {LegendSymbolParams} from '../../component/legend/LegendModel';
type LineDataValue = OptionDataValue | OptionDataValue[];
......@@ -217,27 +215,23 @@ class LineSeriesModel extends SeriesModel<LineSeriesOption> {
getLegendIcon(opt: LegendSymbolParams): ECSymbol | Group {
const group = new Group();
// Draw line only if legend.icon is not defined
if (!opt.legendIconType) {
const line = createSymbol(
'line',
0,
opt.itemHeight / 2,
opt.itemWidth,
0,
opt.lineStyle.stroke,
false
);
group.add(line);
line.setStyle(opt.lineStyle);
}
const line = createSymbol(
'line',
0,
opt.itemHeight / 2,
opt.itemWidth,
0,
opt.lineStyle.stroke,
false
);
group.add(line);
line.setStyle(opt.lineStyle);
const visualType = opt.series.getData().getVisual('symbol');
const symbolType = opt.legendIconType
|| (visualType === 'none' ? 'circle' : visualType);
const visualType = this.getData().getVisual('symbol');
const symbolType = visualType === 'none' ? 'circle' : visualType;
// Symbol size is 80% when there is a line
const size = opt.itemHeight * (opt.legendIconType ? 1 : 0.8);
const size = opt.itemHeight * 0.8;
const symbol = createSymbol(
symbolType,
(opt.itemWidth - size) / 2,
......
......@@ -140,17 +140,12 @@ export interface LegendTooltipFormatterParams {
}
export interface LegendSymbolParams {
series: SeriesModel,
itemWidth: number,
itemHeight: number,
/**
* symbolType is from legend.icon, legend.data.icon, or series visual
*/
symbolType: string,
/**
* legendIconType is from legend.icon or legend.data.icon
*/
legendIconType: string,
symbolKeepAspect: boolean,
itemStyle: PathStyleProps,
lineStyle: LineStyleProps
......
......@@ -353,14 +353,14 @@ class LegendView extends ComponentView {
const textStyleModel = itemModel.getModel('textStyle');
if (typeof seriesModel.getLegendIcon === 'function') {
if (typeof seriesModel.getLegendIcon === 'function'
&& !legendIconType
) {
// Series has specific way to define legend icon
itemGroup.add(seriesModel.getLegendIcon({
series: seriesModel,
itemWidth,
itemHeight,
symbolType,
legendIconType: legendIconType,
symbolKeepAspect,
itemStyle: style.itemStyle,
lineStyle: style.lineStyle
......@@ -369,11 +369,9 @@ class LegendView extends ComponentView {
else {
// Use default legend icon policy for most series
itemGroup.add(getDefaultLegendIcon({
series: seriesModel,
itemWidth,
itemHeight,
symbolType,
legendIconType,
symbolKeepAspect,
itemStyle: style.itemStyle,
lineStyle: style.lineStyle
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册