Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: axis min/max function return null: #12371

Merged
merged 1 commit into from
Apr 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 14 additions & 23 deletions src/coord/axisHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ export function getScaleExtent(scale, model) {

var min = model.getMin();
var max = model.getMax();
var fixMin = min != null;
var fixMax = max != null;
var originalExtent = scale.getExtent();

var axisDataLen;
Expand Down Expand Up @@ -107,6 +105,9 @@ export function getScaleExtent(scale, model) {
});
}

var fixMin = min != null;
var fixMax = max != null;

if (min == null) {
min = scaleType === 'ordinal'
? (axisDataLen ? 0 : NaN)
Expand Down Expand Up @@ -168,7 +169,13 @@ export function getScaleExtent(scale, model) {
}
}

return [min, max];
return {
extent: [min, max],
// "fix" means "fixed", the value should not be
// changed in the subsequent steps.
fixMin: fixMin,
fixMax: fixMax
};
}

function adjustScaleForOverflow(min, max, model, barWidthAndOffset) {
Expand Down Expand Up @@ -207,24 +214,8 @@ function adjustScaleForOverflow(min, max, model, barWidthAndOffset) {
}

export function niceScaleExtent(scale, model) {
var extent = getScaleExtent(scale, model);
var min = model.getMin();
var max = model.getMax();
var originalExtent = scale.getExtent();

if (typeof min === 'function') {
min = min({
min: originalExtent[0],
max: originalExtent[1]
});
}

if (typeof max === 'function') {
max = max({
min: originalExtent[0],
max: originalExtent[1]
});
}
var extentInfo = getScaleExtent(scale, model);
var extent = extentInfo.extent;

var splitNumber = model.get('splitNumber');

Expand All @@ -236,8 +227,8 @@ export function niceScaleExtent(scale, model) {
scale.setExtent(extent[0], extent[1]);
scale.niceExtent({
splitNumber: splitNumber,
fixMin: min != null,
fixMax: max != null,
fixMin: extentInfo.fixMin,
fixMax: extentInfo.fixMin,
minInterval: (scaleType === 'interval' || scaleType === 'time')
? model.get('minInterval') : null,
maxInterval: (scaleType === 'interval' || scaleType === 'time')
Expand Down
2 changes: 1 addition & 1 deletion src/coord/radar/Radar.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ Radar.prototype.update = function (ecModel, api) {
}
// Force all the axis fixing the maxSplitNumber.
zrUtil.each(indicatorAxes, function (indicatorAxis, idx) {
var rawExtent = getScaleExtent(indicatorAxis.scale, indicatorAxis.model);
var rawExtent = getScaleExtent(indicatorAxis.scale, indicatorAxis.model).extent;
niceScaleExtent(indicatorAxis.scale, indicatorAxis.model);

var axisModel = indicatorAxis.model;
Expand Down
117 changes: 104 additions & 13 deletions test/min-max-function.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,33 +21,29 @@
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1" />
<script src="lib/esl.js"></script>
<script src="lib/config.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<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" />
</head>
<body>
<style>
html, body, .chart {
width: 100%;
margin: 0;
}

.chart {
height: 400px;
}
</style>

<div id="chart-1" class="chart"></div>
<div id="main1"></div>


<script>

require([
'echarts'
// 'echarts/chart/bar',
// 'echarts/chart/line',
// 'echarts/component/tooltip',
// 'echarts/component/dataZoom',
// 'echarts/component/markPoint',
// 'echarts/component/toolbox',
// 'zrender/vml/vml'
], function (echarts) {

var chart = echarts.init(document.getElementById('chart-1'));
Expand Down Expand Up @@ -125,5 +121,100 @@
});
});
</script>




<script>

require([
'echarts'
], function (echarts) {
function xAxisData() { return ['a', 'b', 'c']; };
function seriesData() { return [12, 32, 44]; };
var gridWidth = 100;
var gridBottom = 80;
var gridGap = 50;
var gridCurrLeft = gridGap;
var nameTextStyle = {align: 'left'};

function getGridLeft() {
var left = gridCurrLeft;
gridCurrLeft += gridWidth + gridGap;
return left;
}

var option = {
dataZoom: [
{type: 'inside', yAxisIndex: 1},
{type: 'inside', yAxisIndex: 3}
],
grid: [
{width: gridWidth, bottom: gridBottom, left: getGridLeft()},
{width: gridWidth, bottom: gridBottom, left: getGridLeft()},
{width: gridWidth, bottom: gridBottom, left: getGridLeft()},
{width: gridWidth, bottom: gridBottom, left: getGridLeft()}
],
xAxis: [
{gridIndex: 0, data: xAxisData()},
{gridIndex: 1, data: xAxisData()},
{gridIndex: 2, data: xAxisData()},
{gridIndex: 3, data: xAxisData()}
],
yAxis: [{
gridIndex: 0,
name: 'y min/max:\nfunction return null\nno dataZoom',
nameTextStyle: nameTextStyle,
min: function (param) {
return null;
},
max: function (param) {
return null;
}
}, {
gridIndex: 1,
name: 'y min/max:\nfunction return null\ny inside dataZoom',
nameTextStyle: nameTextStyle,
min: function (param) {
return null;
},
max: function (param) {
return null;
}
}, {
gridIndex: 2,
name: 'y min/max:\nnull\nno dataZoom',
nameTextStyle: nameTextStyle,
min: null,
max: null
}, {
gridIndex: 3,
name: 'y min/max:\nnull\ny inside dataZoom',
nameTextStyle: nameTextStyle,
min: null,
max: null
}],
series: [
{type: 'scatter', data: seriesData(), xAxisIndex: 0, yAxisIndex: 0},
{type: 'scatter', data: seriesData(), xAxisIndex: 1, yAxisIndex: 1},
{type: 'scatter', data: seriesData(), xAxisIndex: 2, yAxisIndex: 2},
{type: 'scatter', data: seriesData(), xAxisIndex: 3, yAxisIndex: 3},
]
};

var chart = testHelper.create(echarts, 'main1', {
title: [
'Y range should be all the same',
'dataZoom should be normal'
],
option: option
});

});

</script>



</body>
</html>