提交 b65e590a 编写于 作者: O Ovilia

fix(legend): no rotation when icon is defined

上级 589249fe
...@@ -327,7 +327,7 @@ const NON_STYLE_VISUAL_PROPS = { ...@@ -327,7 +327,7 @@ const NON_STYLE_VISUAL_PROPS = {
symbol: 1, symbol: 1,
symbolSize: 1, symbolSize: 1,
symbolKeepAspect: 1, symbolKeepAspect: 1,
legendSymbol: 1, legendIcon: 1,
visualMeta: 1, visualMeta: 1,
liftZ: 1, liftZ: 1,
decal: 1 decal: 1
......
...@@ -242,12 +242,6 @@ class MapSeries extends SeriesModel<MapSeriesOption> { ...@@ -242,12 +242,6 @@ class MapSeries extends SeriesModel<MapSeriesOption> {
// Map do not use itemStyle.borderWidth as border width // Map do not use itemStyle.borderWidth as border width
symbol.style.stroke = 'none'; symbol.style.stroke = 'none';
const symbolRotate = opt.symbolRotate === 'inherit'
? 0
: (opt.symbolRotate || 0);
symbol.rotation = symbolRotate * Math.PI / 180;
symbol.setOrigin([opt.itemWidth / 2, opt.itemHeight / 2]);
if (symbolType.indexOf('empty') > -1) { if (symbolType.indexOf('empty') > -1) {
symbol.style.stroke = symbol.style.fill; symbol.style.stroke = symbol.style.fill;
symbol.style.fill = '#fff'; symbol.style.fill = '#fff';
......
...@@ -66,7 +66,7 @@ export default function mapSymbolLayout(ecModel: GlobalModel) { ...@@ -66,7 +66,7 @@ export default function mapSymbolLayout(ecModel: GlobalModel) {
} }
}); });
// Show label of those region not has legendSymbol(which is offset 0) // Show label of those region not has legendIcon (which is offset 0)
const data = mapSeries.getData(); const data = mapSeries.getData();
data.each(function (idx) { data.each(function (idx) {
const name = data.getName(idx); const name = data.getName(idx);
......
...@@ -682,7 +682,7 @@ function resetLabelForRegion( ...@@ -682,7 +682,7 @@ function resetLabelForRegion(
// In the following cases label will be drawn // In the following cases label will be drawn
// 1. In map series and data value is NaN // 1. In map series and data value is NaN
// 2. In geo component // 2. In geo component
// 3. Region has no series legendSymbol, which will be add a showLabel flag in mapSymbolLayout // 3. Region has no series legendIcon, which will be add a showLabel flag in mapSymbolLayout
if ( if (
((isGeo || isDataNaN)) ((isGeo || isDataNaN))
|| (itemLayout && itemLayout.showLabel) || (itemLayout && itemLayout.showLabel)
......
...@@ -207,7 +207,7 @@ class LegendView extends ComponentView { ...@@ -207,7 +207,7 @@ class LegendView extends ComponentView {
if (seriesModel) { if (seriesModel) {
const data = seriesModel.getData(); const data = seriesModel.getData();
const lineVisualStyle = data.getVisual('legendLineStyle') || {}; const lineVisualStyle = data.getVisual('legendLineStyle') || {};
const symbolType = data.getVisual('legendSymbol'); const legendIcon = data.getVisual('legendIcon');
/** /**
* `data.getVisual('style')` may be the color from the register * `data.getVisual('style')` may be the color from the register
...@@ -218,7 +218,7 @@ class LegendView extends ComponentView { ...@@ -218,7 +218,7 @@ class LegendView extends ComponentView {
const itemGroup = this._createItem( const itemGroup = this._createItem(
seriesModel, name, dataIndex, seriesModel, name, dataIndex,
legendItemModel, legendModel, itemAlign, legendItemModel, legendModel, itemAlign,
lineVisualStyle, style, symbolType, selectMode lineVisualStyle, style, legendIcon, selectMode
); );
itemGroup.on('click', curry(dispatchSelectAction, name, null, api, excludeSeriesId)) itemGroup.on('click', curry(dispatchSelectAction, name, null, api, excludeSeriesId))
...@@ -245,7 +245,7 @@ class LegendView extends ComponentView { ...@@ -245,7 +245,7 @@ class LegendView extends ComponentView {
const idx = provider.indexOfName(name); const idx = provider.indexOfName(name);
const style = provider.getItemVisual(idx, 'style') as PathStyleProps; const style = provider.getItemVisual(idx, 'style') as PathStyleProps;
const symbolType = provider.getItemVisual(idx, 'legendSymbol'); const legendIcon = provider.getItemVisual(idx, 'legendIcon');
const colorArr = parse(style.fill as ColorString); const colorArr = parse(style.fill as ColorString);
// Color may be set to transparent in visualMap when data is out of range. // Color may be set to transparent in visualMap when data is out of range.
...@@ -259,7 +259,7 @@ class LegendView extends ComponentView { ...@@ -259,7 +259,7 @@ class LegendView extends ComponentView {
const itemGroup = this._createItem( const itemGroup = this._createItem(
seriesModel, name, dataIndex, seriesModel, name, dataIndex,
legendItemModel, legendModel, itemAlign, legendItemModel, legendModel, itemAlign,
{}, style, symbolType, selectMode {}, style, legendIcon, selectMode
); );
// FIXME: consider different series has items with the same name. // FIXME: consider different series has items with the same name.
...@@ -339,7 +339,7 @@ class LegendView extends ComponentView { ...@@ -339,7 +339,7 @@ class LegendView extends ComponentView {
itemAlign: LegendOption['align'], itemAlign: LegendOption['align'],
lineVisualStyle: LineStyleProps, lineVisualStyle: LineStyleProps,
itemVisualStyle: PathStyleProps, itemVisualStyle: PathStyleProps,
symbolType: string, legendIcon: string,
selectMode: LegendOption['selectedMode'] selectMode: LegendOption['selectedMode']
) { ) {
const drawType = seriesModel.visualDrawType; const drawType = seriesModel.visualDrawType;
...@@ -350,11 +350,11 @@ class LegendView extends ComponentView { ...@@ -350,11 +350,11 @@ class LegendView extends ComponentView {
let symbolRotate = itemModel.get('symbolRotate'); let symbolRotate = itemModel.get('symbolRotate');
const legendIconType = itemModel.get('icon'); const legendIconType = itemModel.get('icon');
symbolType = legendIconType || symbolType || 'roundRect'; legendIcon = legendIconType || legendIcon || 'roundRect';
const legendLineStyle = legendModel.getModel('lineStyle'); const legendLineStyle = legendModel.getModel('lineStyle');
const style = getLegendStyle( const style = getLegendStyle(
symbolType, legendIcon,
itemModel, itemModel,
legendLineStyle, legendLineStyle,
lineVisualStyle, lineVisualStyle,
...@@ -374,7 +374,7 @@ class LegendView extends ComponentView { ...@@ -374,7 +374,7 @@ class LegendView extends ComponentView {
itemGroup.add(seriesModel.getLegendIcon({ itemGroup.add(seriesModel.getLegendIcon({
itemWidth, itemWidth,
itemHeight, itemHeight,
symbolType, symbolType: legendIcon,
symbolRotate, symbolRotate,
itemStyle: style.itemStyle, itemStyle: style.itemStyle,
lineStyle: style.lineStyle lineStyle: style.lineStyle
...@@ -382,13 +382,15 @@ class LegendView extends ComponentView { ...@@ -382,13 +382,15 @@ class LegendView extends ComponentView {
} }
else { else {
// Use default legend icon policy for most series // Use default legend icon policy for most series
const rotate = symbolRotate === 'inherit' const rotate = legendIconType === 'inherit' && legendIcon
? (symbolRotate === 'inherit'
? seriesModel.get('symbolRotate') ? seriesModel.get('symbolRotate')
: symbolRotate; : symbolRotate)
: 0; // No rotation for no icon
itemGroup.add(getDefaultLegendIcon({ itemGroup.add(getDefaultLegendIcon({
itemWidth, itemWidth,
itemHeight, itemHeight,
symbolType, symbolType: legendIcon,
symbolRotate: rotate, symbolRotate: rotate,
itemStyle: style.itemStyle, itemStyle: style.itemStyle,
lineStyle: style.lineStyle lineStyle: style.lineStyle
......
...@@ -34,10 +34,10 @@ export function install(registers: EChartsExtensionInstallRegisters) { ...@@ -34,10 +34,10 @@ export function install(registers: EChartsExtensionInstallRegisters) {
const data = seriesModel.getData(); const data = seriesModel.getData();
// itemVisual symbol is for selected data // itemVisual symbol is for selected data
data.each(function (idx) { data.each(function (idx) {
data.setItemVisual(idx, 'legendSymbol', 'roundRect'); data.setItemVisual(idx, 'legendIcon', 'roundRect');
}); });
// visual is for unselected data // visual is for unselected data
data.setVisual('legendSymbol', 'roundRect'); data.setVisual('legendIcon', 'roundRect');
} }
}); });
} }
...@@ -141,7 +141,7 @@ export interface DefaultDataVisual { ...@@ -141,7 +141,7 @@ export interface DefaultDataVisual {
liftZ?: number liftZ?: number
// For legend. // For legend.
legendSymbol?: string legendIcon?: string
legendLineStyle?: LineStyleProps legendLineStyle?: LineStyleProps
// visualMap will inject visualMeta data // visualMap will inject visualMeta data
......
...@@ -175,7 +175,7 @@ class SeriesModel<Opt extends SeriesOption = SeriesOption> extends ComponentMode ...@@ -175,7 +175,7 @@ class SeriesModel<Opt extends SeriesOption = SeriesOption> extends ComponentMode
// Default symbol type. // Default symbol type.
defaultSymbol: string; defaultSymbol: string;
// Symbol provide to legend. // Symbol provide to legend.
legendSymbol: string; legendIcon: string;
// --------------------------------------- // ---------------------------------------
// Props about data selection // Props about data selection
......
...@@ -46,8 +46,8 @@ const seriesSymbolTask: StageHandler = { ...@@ -46,8 +46,8 @@ const seriesSymbolTask: StageHandler = {
) { ) {
const data = seriesModel.getData(); const data = seriesModel.getData();
if (seriesModel.legendSymbol) { if (seriesModel.legendIcon) {
data.setVisual('legendSymbol', seriesModel.legendSymbol); data.setVisual('legendIcon', seriesModel.legendIcon);
} }
if (!seriesModel.hasSymbolVisual) { if (!seriesModel.hasSymbolVisual) {
...@@ -74,7 +74,7 @@ const seriesSymbolTask: StageHandler = { ...@@ -74,7 +74,7 @@ const seriesSymbolTask: StageHandler = {
const seriesSymbolOffset = !hasSymbolOffsetCallback ? symbolOffset : null; const seriesSymbolOffset = !hasSymbolOffsetCallback ? symbolOffset : null;
data.setVisual({ data.setVisual({
legendSymbol: seriesModel.legendSymbol || seriesSymbol as string, legendIcon: seriesModel.legendIcon || seriesSymbol as string,
// If seting callback functions on `symbol` or `symbolSize`, for simplicity and avoiding // If seting callback functions on `symbol` or `symbolSize`, for simplicity and avoiding
// to bring trouble, we do not pick a reuslt from one of its calling on data item here, // to bring trouble, we do not pick a reuslt from one of its calling on data item here,
// but just use the default value. Callback on `symbol` or `symbolSize` is convenient in // but just use the default value. Callback on `symbol` or `symbolSize` is convenient in
......
...@@ -230,7 +230,8 @@ under the License. ...@@ -230,7 +230,8 @@ under the License.
name: 'Line C', name: 'Line C',
symbolRotate: -30, symbolRotate: -30,
icon: 'emptyTriangle' icon: 'emptyTriangle'
} },
'Bar D'
], ],
symbolRotate: 30, symbolRotate: 30,
itemWidth: 100 itemWidth: 100
...@@ -254,6 +255,10 @@ under the License. ...@@ -254,6 +255,10 @@ under the License.
name: 'Line C', name: 'Line C',
symbol: 'emptyTriangle', symbol: 'emptyTriangle',
symbolKeepAspect: true symbolKeepAspect: true
}, {
data: getData(0),
type: 'bar',
name: 'Bar D'
}], }],
animation: 0 animation: 0
}; };
...@@ -263,7 +268,8 @@ under the License. ...@@ -263,7 +268,8 @@ under the License.
'**Legend options should work**', '**Legend options should work**',
'Line A: the rect in the legend should be placed at the center with rotation of 30 degrees', 'Line A: the rect in the legend should be placed at the center with rotation of 30 degrees',
'Line B: the triangle in the legend should be placed at the center with rotation of 30 degrees', 'Line B: the triangle in the legend should be placed at the center with rotation of 30 degrees',
'Line C: the triangle in the legend should be placed at the center with rotation of -30 degrees' 'Line C: should not have rotate in legend',
'Bar D: should not have rotate in legend'
], ],
option: option option: option
}); });
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册