Skip to content

Commit

Permalink
fix apache#4158 thoroughly and apache#16992
Browse files Browse the repository at this point in the history
  • Loading branch information
jiawulin001 committed May 18, 2022
1 parent 5cf53e2 commit 2d4a8aa
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 15 deletions.
12 changes: 12 additions & 0 deletions src/coord/scaleRawExtentInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,18 @@ export class ScaleRawExtentInfo {
this._prepareParams(scale, model, originalExtent);
}

getModelMinRaw() {
return this._modelMinRaw;
}
getModelMaxRaw() {
return this._modelMaxRaw;
}
getDataMin() {
return this._dataMin;
}
getDataMax() {
return this._dataMax;
}
/**
* Parameters depending on ouside (like model, user callback)
* are prepared and fixed here.
Expand Down
39 changes: 24 additions & 15 deletions src/scale/Log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,24 @@ class LogScale extends Scale {
const val = tick.value;
let powVal = numberUtil.round(mathPow(this.base, val));

// Fix #4158
powVal = (val === extent[0] && this._fixMin)
? fixRoundingError(powVal, originalExtent[0])
// Fix #4158 & #16992
// Get the max and min of tick,
// rawMax/rawMin can get user-set max/min if they exist
let rawMax = this.rawExtentInfo.getModelMaxRaw();
let rawMin = this.rawExtentInfo.getModelMinRaw();
rawMax = rawMax === 'dataMax'
? this.rawExtentInfo.getDataMax()
: rawMax as number;
rawMin = rawMin === 'dataMin'
? this.rawExtentInfo.getDataMin()
: rawMin as number;
//If the min/max is set by user, use the user-set min/max
//If not set, then return the originalExtent directly
powVal = (val === extent[0] && this._fixMax)
? (rawMax ? rawMax : originalExtent[1])
: powVal;
powVal = (val === extent[1] && this._fixMax)
? fixRoundingError(powVal, originalExtent[1])
powVal = (val === extent[1] && this._fixMin)
? (rawMin ? rawMin : originalExtent[0])
: powVal;

return {
Expand All @@ -97,15 +109,17 @@ class LogScale extends Scale {
getExtent() {
const base = this.base;
const extent = scaleProto.getExtent.call(this);
extent[0] = mathPow(base, extent[0]);
extent[1] = mathPow(base, extent[1]);

// Fix #4158
const originalScale = this._originalScale;
const originalExtent = originalScale.getExtent();
this._fixMin && (extent[0] = fixRoundingError(extent[0], originalExtent[0]));
this._fixMax && (extent[1] = fixRoundingError(extent[1], originalExtent[1]));

// To get extent without precision problem, get the original extent directly
extent[0] = (extent[0] === mathLog(originalExtent[0])/mathLog(base))
? originalExtent[0]
: mathPow(base, extent[0]);
extent[1] = (extent[1] === mathLog(originalExtent[1])/mathLog(base))
? originalExtent[1]
: mathPow(base, extent[1]);
return extent;
}

Expand Down Expand Up @@ -198,11 +212,6 @@ const proto = LogScale.prototype;
proto.getMinorTicks = intervalScaleProto.getMinorTicks;
proto.getLabel = intervalScaleProto.getLabel;

function fixRoundingError(val: number, originalVal: number): number {
return roundingErrorFix(val, numberUtil.getPrecision(originalVal));
}


Scale.registerClass(LogScale);

export default LogScale;

0 comments on commit 2d4a8aa

Please sign in to comment.