未验证 提交 cf5812f6 编写于 作者: Y Yi Shen 提交者: GitHub

Merge pull request #12215 from susiwen8/#11829

Feat: use auto calculate if min /max is null
......@@ -87,17 +87,6 @@ export function getScaleExtent(scale, model) {
// (2) When `needCrossZero` and all data is positive/negative, should it be ensured
// that the results processed by boundaryGap are positive/negative?
if (min == null) {
min = scaleType === 'ordinal'
? (axisDataLen ? 0 : NaN)
: originalExtent[0] - boundaryGap[0] * span;
}
if (max == null) {
max = scaleType === 'ordinal'
? (axisDataLen ? axisDataLen - 1 : NaN)
: originalExtent[1] + boundaryGap[1] * span;
}
if (min === 'dataMin') {
min = originalExtent[0];
}
......@@ -118,6 +107,17 @@ export function getScaleExtent(scale, model) {
});
}
if (min == null) {
min = scaleType === 'ordinal'
? (axisDataLen ? 0 : NaN)
: originalExtent[0] - boundaryGap[0] * span;
}
if (max == null) {
max = scaleType === 'ordinal'
? (axisDataLen ? axisDataLen - 1 : NaN)
: originalExtent[1] + boundaryGap[1] * span;
}
(min == null || !isFinite(min)) && (min = NaN);
(max == null || !isFinite(max)) && (max = NaN);
......@@ -208,8 +208,24 @@ function adjustScaleForOverflow(min, max, model, barWidthAndOffset) {
export function niceScaleExtent(scale, model) {
var extent = getScaleExtent(scale, model);
var fixMin = model.getMin() != null;
var fixMax = model.getMax() != null;
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 splitNumber = model.get('splitNumber');
if (scale.type === 'log') {
......@@ -220,8 +236,8 @@ export function niceScaleExtent(scale, model) {
scale.setExtent(extent[0], extent[1]);
scale.niceExtent({
splitNumber: splitNumber,
fixMin: fixMin,
fixMax: fixMax,
fixMin: min != null,
fixMax: max != null,
minInterval: (scaleType === 'interval' || scaleType === 'time')
? model.get('minInterval') : null,
maxInterval: (scaleType === 'interval' || scaleType === 'time')
......
......@@ -601,7 +601,7 @@ echartsProto.getConnectedDataURL = function (opts) {
each(canvasList, function (item) {
var x = item.left - left;
var y = item.top - top;
content += '<g transform="translate(' + x + ","
content += '<g transform="translate(' + x + ','
+ y + ')">' + item.dom + '</g>';
});
zr.painter.getSvgRoot().innerHTML = content;
......
......@@ -68,6 +68,9 @@ under the License.
<h2>cartesian value axis | xAxis: {min: function, max: function}</h2>
<div class="chart" id="main4.1"></div>
<h2>cartesian value axis | xAxis: {min: function, max: function}</h2>
<div class="chart" id="main4.2"></div>
<h2>cartesian time axis | xAxis: {min: 'dataMin', max: 'dataMax'}</h2>
<div class="chart" id="main5"></div>
......@@ -463,6 +466,42 @@ under the License.
});
</script>
<script>
makeChart('main4.2', {
legend: {
data: ['no point', 'one point', 'two points'],
selectedMode: 'single'
},
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'line'
}
},
xAxis: {
min: function (value) {
return null
},
max: function (value) {
return null;
}
},
yAxis: {},
series: [{
name: 'no point',
type: 'line',
data: []
}, {
name: 'one point',
type: 'line',
data: [[2, 43]]
}, {
name: 'two points',
type: 'line',
data: [[2, 43], [4, 99]]
}]
});
</script>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册