提交 dde51711 编写于 作者: S sushuang

re support stacked by index (for 3d case)

上级 6ee37650
import {each, isString} from 'zrender/src/core/util';
/**
* Note that it is too complicated to support 3d stack by value
* (have to create two-dimension inverted index), so in 3d case
* we just support that stacked by index.
*
* @param {module:echarts/model/Series} seriesModel
* @param {Array.<string|Object>} dimensionInfoList The same as the input of <module:echarts/data/List>.
* The input dimensionInfoList will be modified.
* @param {Object} [opt]
* @param {boolean} [opt.stackedCoordDimension=''] Specify a coord dimension if needed.
* @param {boolean} [opt.byIndex=false]
* @return {Object} calculationInfo
* {
* stackedDimension: stackedDimInfo.name,
* stackedByDimension: stackedByDimension,
* stackedOverDimension: stackedOverDimension,
* stackResultDimension: stackResultDimension
* stackedDimension: string
* stackedByDimension: string
* isStackedByIndex: boolean
* stackedOverDimension: string
* stackResultDimension: string
* }
*/
export function enableDataStack(seriesModel, dimensionInfoList) {
export function enableDataStack(seriesModel, dimensionInfoList, opt) {
opt = opt || {};
var byIndex = opt.byIndex;
var stackedCoordDimension = opt.stackedCoordDimension;
// Compatibal: when `stack` is set as '', do not stack.
var mayStack = !!(seriesModel && seriesModel.get('stack'));
var stackedByDimInfo;
......@@ -27,13 +39,14 @@ export function enableDataStack(seriesModel, dimensionInfoList) {
if (mayStack && !dimensionInfo.isExtraCoord) {
// Find the first ordinal dimension as the stackedByDimInfo.
if (!stackedByDimInfo && dimensionInfo.ordinalMeta) {
if (!byIndex && !stackedByDimInfo && dimensionInfo.ordinalMeta) {
stackedByDimInfo = dimensionInfo;
}
// Find the first stackable dimension as the stackedDimInfo.
if (!stackedDimInfo
&& dimensionInfo.type !== 'ordinal'
&& dimensionInfo.type !== 'time'
&& (!stackedCoordDimension || stackedCoordDimension === dimensionInfo.coordDim)
) {
stackedDimInfo = dimensionInfo;
}
......@@ -43,13 +56,15 @@ export function enableDataStack(seriesModel, dimensionInfoList) {
// Add stack dimension, they can be both calculated by coordinate system in `unionExtent`.
// That put stack logic in List is for using conveniently in echarts extensions, but it
// might not be a good way.
if (stackedByDimInfo && stackedDimInfo) {
if (stackedDimInfo && (byIndex || stackedByDimInfo)) {
// Use a weird name that not duplicated with other names.
stackResultDimension = '__\0ecstackresult';
stackedOverDimension = '__\0ecstackedover';
// Create inverted index to fast query index by value.
stackedByDimInfo.createInvertedIndices = true;
if (stackedByDimInfo) {
stackedByDimInfo.createInvertedIndices = true;
}
var stackedDimCoordDim = stackedDimInfo.coordDim;
var stackedDimType = stackedDimInfo.type;
......@@ -83,14 +98,24 @@ export function enableDataStack(seriesModel, dimensionInfoList) {
return {
stackedDimension: stackedDimInfo && stackedDimInfo.name,
stackedByDimension: stackedByDimInfo && stackedByDimInfo.name,
isStackedByIndex: byIndex,
stackedOverDimension: stackedOverDimension,
stackResultDimension: stackResultDimension
};
}
/**
* @param {module:echarts/data/List} data
* @param {string} stackedDim
* @param {string} [stackedByDim] If not input this parameter, check whether
* stacked by index.
*/
export function isDimensionStacked(data, stackedDim, stackedByDim) {
return stackedDim
&& stackedByDim
&& stackedDim === data.getCalculationInfo('stackedDimension')
&& stackedByDim === data.getCalculationInfo('stackedByDimension');
&& (
stackedByDim != null
? stackedByDim === data.getCalculationInfo('stackedByDimension')
: data.getCalculationInfo('isStackedByIndex')
);
}
......@@ -5,7 +5,7 @@ import * as axisHelper from './coord/axisHelper';
import axisModelCommonMixin from './coord/axisModelCommonMixin';
import Model from './model/Model';
import {getLayoutRect} from './util/layout';
import {enableDataStack, isDimensionStacked} from './data/helper/dataStackHelper';
/**
* Create a muti dimension List structure from seriesModel.
......@@ -31,6 +31,11 @@ export {default as completeDimensions} from './data/helper/completeDimensions';
export {default as createDimensions} from './data/helper/createDimensions';
export var dataStack = {
isDimensionStacked: isDimensionStacked,
enableDataStack: enableDataStack
};
/**
* Create a symbol element with given symbol configuration: shape, x, y, width, height, color
* @see http://echarts.baidu.com/option.html#series-scatter.symbol
......
......@@ -14,19 +14,29 @@ export default function (ecModel) {
var stackInfoList = stackInfoMap.get(stack) || stackInfoMap.set(stack, []);
var data = seriesModel.getData();
stackInfoList.length && data.setCalculationInfo(
'stackedOnSeries', stackInfoList[stackInfoList.length - 1].seriesModel
);
stackInfoList.push({
var stackInfo = {
// Used for calculate axis extent automatically.
stackResultDimension: data.getCalculationInfo('stackResultDimension'),
stackedOverDimension: data.getCalculationInfo('stackedOverDimension'),
stackedDimension: data.getCalculationInfo('stackedDimension'),
stackedByDimension: data.getCalculationInfo('stackedByDimension'),
isStackedByIndex: data.getCalculationInfo('isStackedByIndex'),
data: data,
seriesModel: seriesModel
});
};
// If stacked on axis that do not support data stack.
if (!stackInfo.stackedDimension
|| !(stackInfo.isStackedByIndex || stackInfo.stackedByDimension)
) {
return;
}
stackInfoList.length && data.setCalculationInfo(
'stackedOnSeries', stackInfoList[stackInfoList.length - 1].seriesModel
);
stackInfoList.push(stackInfo);
}
});
......@@ -39,6 +49,7 @@ function calculateStack(stackInfoList) {
var resultNaN = [NaN, NaN];
var dims = [targetStackInfo.stackResultDimension, targetStackInfo.stackedOverDimension];
var targetData = targetStackInfo.data;
var isStackedByIndex = targetStackInfo.isStackedByIndex;
// Should not write on raw data, because stack series model list changes
// depending on legend selection.
......@@ -51,14 +62,26 @@ function calculateStack(stackInfoList) {
return resultNaN;
}
var byValue = targetData.get(targetStackInfo.stackedByDimension, dataIndex);
var byValue;
var stackedDataRawIndex;
if (isStackedByIndex) {
stackedDataRawIndex = targetData.getRawIndex(dataIndex);
}
else {
byValue = targetData.get(targetStackInfo.stackedByDimension, dataIndex);
}
var stackedOver = 0;
for (var j = idxInStack - 1; j >= 0; j--) {
var stackInfo = stackInfoList[j];
// Has been optimized by inverted indices on `stackedByDimension`.
var stackedDataRawIndex = stackInfo.data.rawIndexOf(stackInfo.stackedByDimension, byValue);
if (!isStackedByIndex) {
stackedDataRawIndex = stackInfo.data.rawIndexOf(stackInfo.stackedByDimension, byValue);
}
if (stackedDataRawIndex >= 0) {
var val = stackInfo.data.getByRawIndex(stackInfo.stackResultDimension, stackedDataRawIndex);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册