Skip to content
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
14 changes: 14 additions & 0 deletions src/coord/axisCommonTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,20 @@ export interface NumericAxisBaseOptionCommon extends AxisBaseOptionCommon {
* Will be ignored if interval is set.
*/
alignTicks?: boolean

/**
* Data min value to be included in axis extent calculation.
* The final min value will be the minimum of this value and the data min.
* Only works for value axis.
*/
dataMin?: ScaleDataValue;

/**
* Data max value to be included in axis extent calculation.
* The final max value will be the maximum of this value and the data max.
* Only works for value axis.
*/
dataMax?: ScaleDataValue;
}

export interface CategoryAxisBaseOption extends AxisBaseOptionCommon {
Expand Down
34 changes: 31 additions & 3 deletions src/coord/scaleRawExtentInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { assert, isArray, eqNaN, isFunction } from 'zrender/src/core/util';
import Scale from '../scale/Scale';
import { AxisBaseModel } from './AxisBaseModel';
import { parsePercent } from 'zrender/src/contain/text';
import { AxisBaseOption, CategoryAxisBaseOption } from './axisCommonTypes';
import { AxisBaseOption, CategoryAxisBaseOption, NumericAxisBaseOptionCommon } from './axisCommonTypes';
import { ScaleDataValue } from '../util/types';


Expand Down Expand Up @@ -69,6 +69,9 @@ export class ScaleRawExtentInfo {
// Make that the `rawExtentInfo` can not be modified any more.
readonly frozen: boolean;

// custom dataMin/dataMax
private _dataMinNum: number;
private _dataMaxNum: number;

constructor(
scale: Scale,
Expand Down Expand Up @@ -98,6 +101,19 @@ export class ScaleRawExtentInfo {
const isOrdinal = this._isOrdinal = scale.type === 'ordinal';
this._needCrossZero = scale.type === 'interval' && model.getNeedCrossZero && model.getNeedCrossZero();

if (scale.type === 'interval' || scale.type === 'log' || scale.type === 'time') {
// Process custom dataMin/dataMax
const dataMinRaw = (model as AxisBaseModel<NumericAxisBaseOptionCommon>).get('dataMin', true);
if (dataMinRaw != null) {
this._dataMinNum = parseAxisModelMinMax(scale, dataMinRaw);
}

const dataMaxRaw = (model as AxisBaseModel<NumericAxisBaseOptionCommon>).get('dataMax', true);
if (dataMaxRaw != null) {
this._dataMaxNum = parseAxisModelMinMax(scale, dataMaxRaw);
}
}

let axisMinValue = model.get('min', true);
if (axisMinValue == null) {
axisMinValue = model.get('startValue', true);
Expand Down Expand Up @@ -173,8 +189,20 @@ export class ScaleRawExtentInfo {
// (3) If no data, it should be ensured that `scale.setBlank` is set.

const isOrdinal = this._isOrdinal;
const dataMin = this._dataMin;
const dataMax = this._dataMax;
let dataMin = this._dataMin;
let dataMax = this._dataMax;

// Include custom dataMin/dataMax in calculation
// If dataMin is set and less than current data minimum, update the minimum value
if (this._dataMinNum != null && isFinite(dataMin) && this._dataMinNum < dataMin) {
dataMin = this._dataMinNum;
}

// If dataMax is set and greater than current data maximum, update the maximum value
if (this._dataMaxNum != null && isFinite(dataMax) && this._dataMaxNum > dataMax) {
dataMax = this._dataMaxNum;
}

const axisDataLen = this._axisDataLen;
const boundaryGapInner = this._boundaryGapInner;

Expand Down
Loading