提交 801fc009 编写于 作者: S sushuang

[pie] Fix #7515 (selected does not work in option data item).

上级 b449ed4f
......@@ -5,6 +5,7 @@
*/
import * as zrUtil from 'zrender/src/core/util';
import {retrieveRawAttr} from '../../data/helper/dataProvider';
export default {
......@@ -22,7 +23,11 @@ export default {
var valueDim = ecList.mapDimension('value');
var targetList = this._targetList = [];
for (var i = 0, len = ecList.count(); i < len; i++) {
targetList.push({name: ecList.getName(i), value: ecList.get(valueDim, i)});
targetList.push({
name: ecList.getName(i),
value: ecList.get(valueDim, i),
selected: retrieveRawAttr(ecList, i, 'selected')
});
}
}
this._selectTargetMap = zrUtil.reduce(targetList || [], function (targetMap, target) {
......
......@@ -3,13 +3,15 @@
// merge with defaultDimValueGetter?
import {__DEV__} from '../../config';
import {isTypedArray, extend, assert, each} from 'zrender/src/core/util';
import {isTypedArray, extend, assert, each, isObject} from 'zrender/src/core/util';
import {getDataItemValue, isDataItemOption} from '../../util/model';
import {parseDate} from '../../util/number';
import Source from '../Source';
import {
SOURCE_FORMAT_TYPED_ARRAY,
SOURCE_FORMAT_ARRAY_ROWS
SOURCE_FORMAT_ARRAY_ROWS,
SOURCE_FORMAT_ORIGINAL,
SOURCE_FORMAT_OBJECT_ROWS
} from './sourceType';
/**
......@@ -325,3 +327,37 @@ export function retrieveRawValue(data, dataIndex, dim) {
return rawValueGetters[sourceFormat](dataItem, dataIndex, dimIndex, dimName);
}
/**
* Compatible with some cases (in pie, map) like:
* data: [{name: 'xx', value: 5, selected: true}, ...]
* where only sourceFormat is 'original' and 'objectRows' supported.
*
* ??? TODO
* Supported detail options in data item when using 'arrayRows'.
*
* @param {module:echarts/data/List} data
* @param {number} dataIndex
* @param {string} attr like 'selected'
*/
export function retrieveRawAttr(data, dataIndex, attr) {
if (!data) {
return;
}
var sourceFormat = data.getProvider().getSource().sourceFormat;
if (sourceFormat !== SOURCE_FORMAT_ORIGINAL
&& sourceFormat !== SOURCE_FORMAT_OBJECT_ROWS
) {
return;
}
var dataItem = data.getRawDataItem(dataIndex);
if (sourceFormat === SOURCE_FORMAT_ORIGINAL && !isObject(dataItem)) {
dataItem = null;
}
if (dataItem) {
return dataItem[attr];
}
}
......@@ -51,7 +51,7 @@
};
chart.setOption({
legend: {
data: ['直接访问','邮件营销','联盟广告','视频广告','搜索引擎']
data: ['直接访问(初始就被选中)','邮件营销','联盟广告','视频广告','搜索引擎']
// data: []
},
toolbox: {
......@@ -89,7 +89,12 @@
// }
// },
data:[
{value:235, name:'直接访问', cursor: 'move'},
{
value:235,
name:'直接访问(初始就被选中)',
cursor: 'move',
selected: true
},
{value: 163, name: '标签在内部',
label: {
normal: {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册