提交 5b10d82e 编写于 作者: O Ovilia

WIP(legend): move default legend icon logic from series to legend

上级 dc2282fa
......@@ -18,7 +18,9 @@
*/
import * as zrUtil from 'zrender/src/core/util';
import {createSymbol} from '../../util/symbol';
import { DisplayableState } from 'zrender/src/graphic/Displayable';
import { PathStyleProps } from 'zrender/src/graphic/Path';
import { parse, stringify } from 'zrender/src/tool/color';
import * as graphic from '../../util/graphic';
import { enableHoverEmphasis } from '../../util/states';
import {setLabelStyle, createTextStyle} from '../../label/labelStyle';
......@@ -30,27 +32,17 @@ import GlobalModel from '../../model/Global';
import ExtensionAPI from '../../core/ExtensionAPI';
import {
ZRTextAlign,
ZRColor,
ItemStyleOption,
ZRRectLike,
CommonTooltipOption,
ColorString,
SeriesOption,
SymbolOptionMixin,
LineStyleOption,
DecalObject
SymbolOptionMixin
} from '../../util/types';
import Model from '../../model/Model';
import Displayable, { DisplayableState } from 'zrender/src/graphic/Displayable';
import { PathStyleProps } from 'zrender/src/graphic/Path';
import { parse, stringify } from 'zrender/src/tool/color';
import {PatternObject} from 'zrender/src/graphic/Pattern';
import {SeriesModel} from '../../echarts';
import linesLayout from '../../chart/lines/linesLayout';
import {LineStyleProps, LINE_STYLE_KEY_MAP} from '../../model/mixin/lineStyle';
import {ItemStyleProps, ITEM_STYLE_KEY_MAP} from '../../model/mixin/itemStyle';
import {number} from '../../export/api';
import makeStyleMapper from '../../model/mixin/makeStyleMapper';
import {ITEM_STYLE_KEY_MAP} from '../../model/mixin/itemStyle';
import {createSymbol, ECSymbol} from '../../util/symbol';
const curry = zrUtil.curry;
const each = zrUtil.each;
......@@ -393,17 +385,18 @@ class LegendView extends ComponentView {
const textStyleModel = itemModel.getModel('textStyle');
itemGroup.add(
seriesModel.getLegendIcon({
series: seriesModel,
itemWidth,
itemHeight,
symbolType: dataSymbolType || 'roundRect',
symbolKeepAspect,
itemStyle: style.itemStyle,
lineStyle: style.lineStyle
})
)
const getLegendIcon = typeof seriesModel.getLegendIcon === 'function'
? seriesModel.getLegendIcon
: getDefaultLegendIcon;
itemGroup.add(getLegendIcon({
series: seriesModel,
itemWidth,
itemHeight,
symbolType: dataSymbolType || 'roundRect',
symbolKeepAspect,
itemStyle: style.itemStyle,
lineStyle: style.lineStyle
}));
const textX = itemAlign === 'left' ? itemWidth + 5 : -5;
const textAlign = itemAlign as ZRTextAlign;
......@@ -637,6 +630,35 @@ function getLegendStyle(
return { itemStyle, lineStyle };
}
function getDefaultLegendIcon(opt: {
series: SeriesModel,
itemWidth: number,
itemHeight: number,
symbolType: string,
symbolKeepAspect: boolean,
itemStyle: PathStyleProps,
lineStyle: LineStyleProps
}): ECSymbol {
const symbol = createSymbol(
opt.symbolType,
0,
0,
opt.itemWidth,
opt.itemHeight,
opt.itemStyle.fill,
opt.symbolKeepAspect
);
symbol.setStyle(opt.itemStyle);
if (opt.symbolType.indexOf('empty') > -1) {
symbol.style.stroke = symbol.style.fill;
symbol.style.fill = '#fff';
}
return symbol;
}
function dispatchSelectAction(
seriesName: string,
dataName: string,
......
import {PathStyleProps} from 'zrender/src/graphic/Path';
import {SeriesModel} from '../../export/api';
import {LineStyleProps} from '../../model/mixin/lineStyle';
import {Group} from '../../util/graphic';
import {createSymbol, ECSymbol} from '../../util/symbol';
export function defaultSeriesLegendIcon(opt: {
series: SeriesModel,
itemWidth: number,
itemHeight: number,
symbolType: string,
symbolKeepAspect: boolean,
itemStyle: PathStyleProps,
lineStyle: LineStyleProps
}): ECSymbol | Group {
const symbol = createSymbol(
opt.symbolType,
0,
0,
opt.itemWidth,
opt.itemHeight,
opt.itemStyle.fill,
opt.symbolKeepAspect
);
symbol.setStyle(opt.itemStyle);
if (opt.symbolType.indexOf('empty') > -1) {
symbol.style.stroke = symbol.style.fill;
symbol.style.fill = '#fff';
}
return symbol;
}
......@@ -20,6 +20,7 @@
import * as zrUtil from 'zrender/src/core/util';
import env from 'zrender/src/core/env';
import type {MorphDividingMethod} from 'zrender/src/tool/morphPath';
import {PathStyleProps} from 'zrender/src/graphic/Path';
import * as modelUtil from '../util/model';
import {
DataHost, DimensionName, StageHandlerProgressParams,
......@@ -50,8 +51,6 @@ import { Source } from '../data/Source';
import { defaultSeriesFormatTooltip } from '../component/tooltip/seriesFormatTooltip';
import {ECSymbol} from '../util/symbol';
import {Group} from '../util/graphic';
import {defaultSeriesLegendIcon} from '../component/legend/seriesLegendIcon';
import {PathStyleProps} from 'zrender/src/graphic/Path';
import {LineStyleProps} from './mixin/lineStyle';
const inner = modelUtil.makeInner<{
......@@ -95,6 +94,19 @@ interface SeriesModel {
*/
getMarkerPosition(value: ScaleDataValue[]): number[];
/**
* Get legend icon symbol according to each series type
*/
getLegendIcon(opt: {
series: SeriesModel,
itemWidth: number,
itemHeight: number,
symbolType: string,
symbolKeepAspect: boolean,
itemStyle: PathStyleProps,
lineStyle: LineStyleProps
}): ECSymbol | Group;
/**
* See `component/brush/selector.js`
* Defined the brush selector for this series.
......@@ -438,18 +450,6 @@ class SeriesModel<Opt extends SeriesOption = SeriesOption> extends ComponentMode
});
}
getLegendIcon(opt: {
series: SeriesModel,
itemWidth: number,
itemHeight: number,
symbolType: string,
symbolKeepAspect: boolean,
itemStyle: PathStyleProps,
lineStyle: LineStyleProps
}): ECSymbol | Group {
return defaultSeriesLegendIcon(opt);
}
isAnimationEnabled(): boolean {
if (env.node) {
return false;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册