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

Feat: use auto calculate if min /max is null #12215

Merged
merged 3 commits into from
Mar 16, 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
46 changes: 31 additions & 15 deletions src/coord/axisHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand All @@ -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);

Expand Down Expand Up @@ -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') {
Expand All @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion src/echarts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
39 changes: 39 additions & 0 deletions test/axis-extrema.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ <h2>cartesian value axis | xAxis: {min: -10, max: 10}</h2>
<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>

Expand Down Expand Up @@ -463,6 +466,42 @@ <h2>single category axis | singleAxis: {min: function, max: function}</h2>
});
</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>



Expand Down