提交 6d3114b1 编写于 作者: S sushuang

Fix axis extent when stack series exists.

上级 66f6e070
...@@ -42,10 +42,10 @@ export function prepareDataCoordInfo(coordSys, data, valueOrigin) { ...@@ -42,10 +42,10 @@ export function prepareDataCoordInfo(coordSys, data, valueOrigin) {
var stacked; var stacked;
var stackResultDim = data.getCalculationInfo('stackResultDimension'); var stackResultDim = data.getCalculationInfo('stackResultDimension');
if (stacked |= isDimensionStacked(data, dims[0], dims[1])) { // jshint ignore:line if (stacked |= isDimensionStacked(data, dims[0] /*, dims[1]*/)) { // jshint ignore:line
dims[0] = stackResultDim; dims[0] = stackResultDim;
} }
if (stacked |= isDimensionStacked(data, dims[1], dims[0])) { // jshint ignore:line if (stacked |= isDimensionStacked(data, dims[1] /*, dims[0]*/)) { // jshint ignore:line
dims[1] = stackResultDim; dims[1] = stackResultDim;
} }
......
...@@ -60,7 +60,7 @@ function markerTypeCalculatorWithExtent( ...@@ -60,7 +60,7 @@ function markerTypeCalculatorWithExtent(
) { ) {
var coordArr = []; var coordArr = [];
var stacked = isDimensionStacked(data, targetDataDim, otherDataDim); var stacked = isDimensionStacked(data, targetDataDim /*, otherDataDim*/);
var calcDataDim = stacked var calcDataDim = stacked
? data.getCalculationInfo('stackResultDimension') ? data.getCalculationInfo('stackResultDimension')
: targetDataDim; : targetDataDim;
......
...@@ -35,6 +35,7 @@ import { ...@@ -35,6 +35,7 @@ import {
import Cartesian2D from './Cartesian2D'; import Cartesian2D from './Cartesian2D';
import Axis2D from './Axis2D'; import Axis2D from './Axis2D';
import CoordinateSystem from '../../CoordinateSystem'; import CoordinateSystem from '../../CoordinateSystem';
import {getStackedDimension} from '../../data/helper/dataStackHelper';
// Depends on GridModel, AxisModel, which performs preprocess. // Depends on GridModel, AxisModel, which performs preprocess.
import './GridModel'; import './GridModel';
...@@ -491,7 +492,12 @@ gridProto._updateScale = function (ecModel, gridModel) { ...@@ -491,7 +492,12 @@ gridProto._updateScale = function (ecModel, gridModel) {
function unionExtent(data, axis, seriesModel) { function unionExtent(data, axis, seriesModel) {
each(data.mapDimension(axis.dim, true), function (dim) { each(data.mapDimension(axis.dim, true), function (dim) {
axis.scale.unionExtentFromData(data, dim); axis.scale.unionExtentFromData(
// For example, the extent of the orginal dimension
// is [0.1, 0.5], the extent of the `stackResultDimension`
// is [7, 9], the final extent should not include [0.1, 0.5].
data, getStackedDimension(data, dim)
);
}); });
} }
}; };
......
...@@ -28,8 +28,8 @@ import { ...@@ -28,8 +28,8 @@ import {
niceScaleExtent niceScaleExtent
} from '../../coord/axisHelper'; } from '../../coord/axisHelper';
import CoordinateSystem from '../../CoordinateSystem'; import CoordinateSystem from '../../CoordinateSystem';
import {getStackedDimension} from '../../data/helper/dataStackHelper';
// 依赖 PolarModel 做预处理
import './PolarModel'; import './PolarModel';
/** /**
...@@ -68,10 +68,14 @@ function updatePolarScale(ecModel, api) { ...@@ -68,10 +68,14 @@ function updatePolarScale(ecModel, api) {
if (seriesModel.coordinateSystem === polar) { if (seriesModel.coordinateSystem === polar) {
var data = seriesModel.getData(); var data = seriesModel.getData();
zrUtil.each(data.mapDimension('radius', true), function (dim) { zrUtil.each(data.mapDimension('radius', true), function (dim) {
radiusAxis.scale.unionExtentFromData(data, dim); radiusAxis.scale.unionExtentFromData(
data, getStackedDimension(data, dim)
);
}); });
zrUtil.each(data.mapDimension('angle', true), function (dim) { zrUtil.each(data.mapDimension('angle', true), function (dim) {
angleAxis.scale.unionExtentFromData(data, dim); angleAxis.scale.unionExtentFromData(
data, getStackedDimension(data, dim)
);
}); });
} }
}); });
......
...@@ -130,15 +130,27 @@ export function enableDataStack(seriesModel, dimensionInfoList, opt) { ...@@ -130,15 +130,27 @@ export function enableDataStack(seriesModel, dimensionInfoList, opt) {
/** /**
* @param {module:echarts/data/List} data * @param {module:echarts/data/List} data
* @param {string} stackedDim * @param {string} stackedDim
*/
export function isDimensionStacked(data, stackedDim /*, stackedByDim*/) {
// Each single series only maps to one pair of axis. So we do not need to
// check stackByDim, whatever stacked by a dimension or stacked by index.
return !!stackedDim && stackedDim === data.getCalculationInfo('stackedDimension');
// && (
// stackedByDim != null
// ? stackedByDim === data.getCalculationInfo('stackedByDimension')
// : data.getCalculationInfo('isStackedByIndex')
// );
}
/**
* @param {module:echarts/data/List} data
* @param {string} targetDim
* @param {string} [stackedByDim] If not input this parameter, check whether * @param {string} [stackedByDim] If not input this parameter, check whether
* stacked by index. * stacked by index.
* @return {string} dimension
*/ */
export function isDimensionStacked(data, stackedDim, stackedByDim) { export function getStackedDimension(data, targetDim) {
return stackedDim return isDimensionStacked(data, targetDim)
&& stackedDim === data.getCalculationInfo('stackedDimension') ? data.getCalculationInfo('stackResultDimension')
&& ( : targetDim;
stackedByDim != null
? stackedByDim === data.getCalculationInfo('stackedByDimension')
: data.getCalculationInfo('isStackedByIndex')
);
} }
...@@ -24,7 +24,11 @@ import * as axisHelper from './coord/axisHelper'; ...@@ -24,7 +24,11 @@ import * as axisHelper from './coord/axisHelper';
import axisModelCommonMixin from './coord/axisModelCommonMixin'; import axisModelCommonMixin from './coord/axisModelCommonMixin';
import Model from './model/Model'; import Model from './model/Model';
import {getLayoutRect} from './util/layout'; import {getLayoutRect} from './util/layout';
import {enableDataStack, isDimensionStacked} from './data/helper/dataStackHelper'; import {
enableDataStack,
isDimensionStacked,
getStackedDimension
} from './data/helper/dataStackHelper';
/** /**
* Create a muti dimension List structure from seriesModel. * Create a muti dimension List structure from seriesModel.
...@@ -52,7 +56,8 @@ export {default as createDimensions} from './data/helper/createDimensions'; ...@@ -52,7 +56,8 @@ export {default as createDimensions} from './data/helper/createDimensions';
export var dataStack = { export var dataStack = {
isDimensionStacked: isDimensionStacked, isDimensionStacked: isDimensionStacked,
enableDataStack: enableDataStack enableDataStack: enableDataStack,
getStackedDimension: getStackedDimension
}; };
/** /**
......
...@@ -284,7 +284,7 @@ export function layout(seriesType, ecModel) { ...@@ -284,7 +284,7 @@ export function layout(seriesType, ecModel) {
var valueDim = data.mapDimension(valueAxis.dim); var valueDim = data.mapDimension(valueAxis.dim);
var baseDim = data.mapDimension(baseAxis.dim); var baseDim = data.mapDimension(baseAxis.dim);
var stacked = isDimensionStacked(data, valueDim, baseDim); var stacked = isDimensionStacked(data, valueDim /*, baseDim*/);
var isValueAxisH = valueAxis.isHorizontal(); var isValueAxisH = valueAxis.isHorizontal();
var valueAxisStart = getValueAxisStart(baseAxis, valueAxis, stacked); var valueAxisStart = getValueAxisStart(baseAxis, valueAxis, stacked);
......
...@@ -81,7 +81,7 @@ function barLayoutPolar(seriesType, ecModel, api) { ...@@ -81,7 +81,7 @@ function barLayoutPolar(seriesType, ecModel, api) {
var valueDim = data.mapDimension(valueAxis.dim); var valueDim = data.mapDimension(valueAxis.dim);
var baseDim = data.mapDimension(baseAxis.dim); var baseDim = data.mapDimension(baseAxis.dim);
var stacked = isDimensionStacked(data, valueDim, baseDim); var stacked = isDimensionStacked(data, valueDim /*, baseDim*/);
var valueAxisStart = valueAxis.getExtent()[0]; var valueAxisStart = valueAxis.getExtent()[0];
......
...@@ -43,10 +43,10 @@ export default function (seriesType) { ...@@ -43,10 +43,10 @@ export default function (seriesType) {
var dimLen = dims.length; var dimLen = dims.length;
var stackResultDim = data.getCalculationInfo('stackResultDimension'); var stackResultDim = data.getCalculationInfo('stackResultDimension');
if (isDimensionStacked(data, dims[0], dims[1])) { if (isDimensionStacked(data, dims[0] /*, dims[1]*/)) {
dims[0] = stackResultDim; dims[0] = stackResultDim;
} }
if (isDimensionStacked(data, dims[1], dims[0])) { if (isDimensionStacked(data, dims[1] /*, dims[0]*/)) {
dims[1] = stackResultDim; dims[1] = stackResultDim;
} }
......
<html> <html>
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<script src="http://requirejs.org/docs/release/2.2.0/minified/require.js"></script> <script src="lib/esl.js"></script>
<script src="lib/config.js"></script> <script src="lib/config.js"></script>
<script src="lib/jquery.min.js"></script>
<script src="lib/facePrint.js"></script>
<script src="lib/testHelper.js"></script>
<link rel="stylesheet" href="lib/reset.css" />
<meta name="viewport" content="user-scalable=no,width=device-width,height=device-height"> <meta name="viewport" content="user-scalable=no,width=device-width,height=device-height">
</head> </head>
<body> <body>
<style> <style>
html, body, #main { .test-title {
width: 100%; background: #146402;
height: 100%; color: #fff;
} }
</style> </style>
<div id="main"></div>
<div id="main0"></div>
<div id="main1"></div>
<script> <script>
require([ require([
'echarts' 'echarts'
// 'echarts/chart/line',
// 'echarts/component/legend',
// 'echarts/component/gridSimple',
// 'echarts/component/tooltip',
// 'zrender/vml/vml'
], function (echarts) { ], function (echarts) {
var chart = echarts.init(document.getElementById('main')); var chart = echarts.init(document.getElementById('main0'));
var xAxisData = []; var xAxisData = [];
var data1 = []; var data1 = [];
...@@ -97,7 +107,7 @@ ...@@ -97,7 +107,7 @@
} }
}; };
chart.setOption({ var option = {
legend: { legend: {
}, },
toolbox: { toolbox: {
...@@ -210,9 +220,185 @@ ...@@ -210,9 +220,185 @@
connectNulls: false, connectNulls: false,
smooth: true smooth: true
}] }]
};
testHelper.create(echarts, 'main0', {
title: 'line break',
option: option,
height: 600
}); });
}) })
</script> </script>
<script>
require([
'echarts'/*, 'map/js/china' */
], function (echarts) {
var xAxisData = ["2018-04-11 13:30:00","2018-04-11 13:45:00","2018-04-11 14:00:00","2018-04-11 14:30:00","2018-04-11 14:45:00","2018-04-11 15:00:00","2018-04-11 15:15:00","2018-04-11 15:30:00","2018-04-11 15:45:00","2018-04-12 09:30:00","2018-04-12 09:45:00","2018-04-12 10:00:00","2018-04-12 10:15:00","2018-04-12 10:30:00","2018-04-12 10:45:00","2018-04-12 11:00:00","2018-04-12 11:15:00","2018-04-12 11:30:00","2018-04-12 11:45:00","2018-04-12 12:00:00","2018-04-12 12:15:00","2018-04-12 12:30:00","2018-04-12 12:45:00","2018-04-12 13:00:00","2018-04-12 13:15:00","2018-04-12 13:30:00","2018-04-12 13:45:00","2018-04-12 14:00:00","2018-04-12 14:15:00","2018-04-12 14:30:00","2018-04-12 14:45:00","2018-04-12 15:00:00","2018-04-12 15:15:00","2018-04-12 15:30:00","2018-04-12 15:45:00","2018-04-13 09:30:00","2018-04-13 09:45:00","2018-04-13 10:00:00","2018-04-13 10:15:00","2018-04-13 10:30:00","2018-04-13 10:45:00","2018-04-13 11:00:00","2018-04-13 11:15:00","2018-04-13 11:45:00","2018-04-13 12:00:00","2018-04-13 12:15:00","2018-04-13 12:45:00","2018-04-13 13:00:00","2018-04-13 13:30:00","2018-04-13 13:45:00","2018-04-13 14:00:00","2018-04-13 14:30:00","2018-04-13 14:45:00","2018-04-13 15:00:00","2018-04-13 15:15:00","2018-04-13 15:30:00","2018-04-13 15:45:00","2018-04-16 09:30:00","2018-04-16 09:45:00","2018-04-16 10:00:00","2018-04-16 10:15:00","2018-04-16 10:30:00","2018-04-16 10:45:00","2018-04-16 11:00:00","2018-04-16 11:15:00","2018-04-16 11:45:00","2018-04-16 12:00:00","2018-04-16 12:15:00","2018-04-16 12:30:00","2018-04-16 12:45:00","2018-04-16 13:00:00","2018-04-16 13:15:00","2018-04-16 13:30:00","2018-04-16 13:45:00","2018-04-16 14:00:00","2018-04-16 14:15:00","2018-04-16 14:30:00","2018-04-16 14:45:00","2018-04-16 15:00:00","2018-04-16 15:15:00","2018-04-16 15:30:00","2018-04-16 15:45:00","2018-04-17 09:30:00","2018-04-17 09:45:00","2018-04-17 10:00:00","2018-04-17 10:15:00","2018-04-17 10:30:00","2018-04-17 10:45:00","2018-04-17 11:00:00","2018-04-17 11:15:00","2018-04-17 11:30:00","2018-04-17 11:45:00","2018-04-17 12:00:00","2018-04-17 12:30:00","2018-04-17 13:00:00","2018-04-17 13:15:00","2018-04-17 13:30:00","2018-04-17 13:45:00","2018-04-17 14:15:00","2018-04-17 14:30:00","2018-04-17 14:45:00","2018-04-17 15:00:00","2018-04-17 15:15:00","2018-04-17 15:30:00","2018-04-17 15:45:00","2018-04-18 09:30:00","2018-04-18 09:45:00","2018-04-18 10:00:00","2018-04-18 10:15:00","2018-04-18 10:30:00","2018-04-18 10:45:00","2018-04-18 11:00:00","2018-04-18 11:15:00","2018-04-18 11:30:00","2018-04-18 11:45:00","2018-04-18 12:00:00","2018-04-18 12:15:00","2018-04-18 12:30:00","2018-04-18 12:45:00","2018-04-18 13:00:00","2018-04-18 13:15:00","2018-04-18 13:30:00","2018-04-18 13:45:00","2018-04-18 14:00:00","2018-04-18 14:15:00","2018-04-18 14:45:00","2018-04-18 15:00:00","2018-04-18 15:15:00","2018-04-18 15:30:00","2018-04-18 15:45:00"];
var dataUpper = [6.89,6.9,6.9,6.9,6.89,6.87,6.86,6.83,6.8,6.78,6.75,6.71,6.67,6.65,6.64,6.62,6.61,6.6,6.6,6.61,6.65,6.67,6.68,6.69,6.72,6.74,6.79,6.83,6.87,6.9,6.93,6.95,6.98,6.99,7.01,7.01,7.02,7.02,7,7,7.02,7.01,7.01,7,6.98,6.97,6.97,6.97,6.97,6.97,6.97,6.97,6.98,6.98,6.98,6.99,6.99,6.99,6.99,6.99,6.98,6.97,6.97,6.97,6.97,6.99];
var dataMiddle = [6.7,6.69,6.67,6.66,6.64,6.63,6.61,6.6,6.59,6.58,6.57,6.56,6.55,6.54,6.54,6.53,6.53,6.53,6.52,6.53,6.53,6.54,6.55,6.56,6.58,6.59,6.61,6.62,6.64,6.65,6.67,6.68,6.7,6.72,6.73,6.75,6.77,6.78,6.81,6.82,6.84,6.85,6.86,6.87,6.88,6.89,6.89,6.89,6.89,6.89,6.89,6.89,6.89,6.9,6.9,6.9,6.91,6.91,6.91,6.91,6.9,6.91,6.9,6.9,6.9,6.89];
var dataLower = [6.51,6.48,6.45,6.42,6.4,6.38,6.37,6.37,6.38,6.38,6.39,6.4,6.43,6.43,6.44,6.44,6.45,6.45,6.45,6.44,6.42,6.42,6.42,6.43,6.44,6.44,6.42,6.41,6.4,6.4,6.4,6.41,6.42,6.44,6.46,6.49,6.52,6.54,6.61,6.65,6.66,6.68,6.71,6.75,6.77,6.8,6.81,6.81,6.81,6.81,6.81,6.81,6.81,6.81,6.82,6.82,6.82,6.82,6.82,6.82,6.83,6.84,6.84,6.83,6.83,6.79];
dataUpper = dataUpper.map(function (value, index) {
return value - dataMiddle[index];
});
dataMiddle = dataMiddle.map(function (value, index) {
return value - dataLower[index];
});
var option = {
"series": [
{
"smooth": true,
"lineStyle": {
"normal": {
"opacity": 0.5,
"width": 1
}
},
"name": "range",
"id": "lower",
"stack": "range",
"data": dataLower,
"type": "line",
"showSymbol": false
},
{
"smooth": true,
"lineStyle": {
"normal": {
"opacity": 0.5,
"width": 1
}
},
"name": "range",
"id": "middle",
"stack": "range",
"data": dataMiddle,
"areaStyle": {
"normal": {
"color": "rgba(102, 202, 196, .3)"
}
},
"type": "line",
"showSymbol": false
},
{
"smooth": true,
"lineStyle": {
"normal": {
"opacity": 0.5,
"width": 1
}
},
"name": "range",
"id": "upper",
"stack": "range",
"data": dataUpper,
"areaStyle": {
"normal": {
"color": "rgba(102, 202, 196, .3)"
}
},
"type": "line",
"showSymbol": false
}
],
"tooltip": {
"trigger": "axis"
},
"grid": [
{
"containLabel": false,
"show": false
}
],
"xAxis": [
{
"type": "category",
"boundaryGap": true,
"max": "dataMax",
"axisLabel": {
"show": false
},
"axisLine": {
"show": false
},
"axisTick": {
"show": false
},
"splitLine": {
"show": true,
"lineStyle": {
"color": "#edeff2"
}
},
"data": xAxisData
}
],
"yAxis": [
{
"scale": true,
"boundaryGap": [
"5%",
"5%"
],
"splitArea": {
"show": false
},
"axisLabel": {
"color": "#32325d",
"fontFamily": "rubiklight",
"fontSize": 14,
"showMinLabel": false,
"showMaxLabel": false
},
"axisLine": {
"lineStyle": {
"color": "#32325d"
}
},
"splitLine": {
"lineStyle": {
"color": "#edeff2"
}
},
"position": "right"
}
],
"axisPointer": {
"link": {
"xAxis": "all"
},
"lineStyle": {
"color": "#c3c6c9",
"type": "dotted"
}
}
};
testHelper.create(echarts, 'main1', {
title: 'yAxis extent should not contain 0 (should about [5, 8])',
option: option
});
});
</script>
</body> </body>
</html> </html>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册