Skip to content
Open
Show file tree
Hide file tree
Changes from 8 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
2 changes: 1 addition & 1 deletion src/component/marker/checkMarkerInSeries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import { isArray } from 'zrender/src/core/util';
import { SeriesOption } from '../../util/types';

type MarkerTypes = 'markPoint' | 'markLine' | 'markArea';
export type MarkerTypes = 'markPoint' | 'markLine' | 'markArea';

type SeriesWithMarkerOption = SeriesOption & Partial<Record<MarkerTypes, unknown>>;

Expand Down
2 changes: 2 additions & 0 deletions src/coord/cartesian/AxisModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ export type CartesianAxisOption = AxisBaseOption & {
// Offset is for multiple axis on the same position.
offset?: number;
categorySortInfo?: OrdinalSortInfo;
// Whether to include marker data (markPoint, markLine, markArea) in axis extent calculation
includeMarkerInExtent?: boolean;
};

export type XAXisOption = CartesianAxisOption & {
Expand Down
56 changes: 54 additions & 2 deletions src/coord/cartesian/Grid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import GlobalModel from '../../model/Global';
import ExtensionAPI from '../../core/ExtensionAPI';
import { Dictionary } from 'zrender/src/core/types';
import {CoordinateSystemMaster} from '../CoordinateSystem';
import { NullUndefined, ScaleDataValue } from '../../util/types';
import { NullUndefined, ScaleDataValue, SeriesOption } from '../../util/types';
import SeriesData from '../../data/SeriesData';
import OrdinalScale from '../../scale/Ordinal';
import {
Expand All @@ -53,7 +53,7 @@ import {
updateCartesianAxisViewCommonPartBuilder,
isCartesian2DInjectedAsDataCoordSys
} from './cartesianAxisHelper';
import { CategoryAxisBaseOption, NumericAxisBaseOptionCommon } from '../axisCommonTypes';
import { CategoryAxisBaseOption, NumericAxisBaseOptionCommon, OptionAxisType } from '../axisCommonTypes';
import { AxisBaseModel } from '../AxisBaseModel';
import { isIntervalOrLogScale } from '../../scale/helper';
import { alignScaleTicks } from '../axisAlignTicks';
Expand All @@ -70,6 +70,7 @@ import { error, log } from '../../util/log';
import { AxisTickLabelComputingKind } from '../axisTickLabelBuilder';
import { injectCoordSysByOption } from '../../core/CoordinateSystem';
import { mathMax, parsePositionSizeOption } from '../../util/number';
import { MarkerTypes } from '../../component/marker/checkMarkerInSeries';

type Cartesian2DDimensionName = 'x' | 'y';

Expand Down Expand Up @@ -542,6 +543,16 @@ class Grid implements CoordinateSystemMaster {

unionExtent(data, xAxis);
unionExtent(data, yAxis);

// Handle markPoint, markLine, markArea
const markerTypes: MarkerTypes[] = ['markPoint', 'markLine', 'markArea'];

markerTypes.forEach(markerType => {
const markerOpt = seriesModel.get(markerType as keyof SeriesOption);
if (markerOpt && markerOpt.data) {
unionMarkerExtent(markerOpt.data, xAxis, yAxis);
}
});
}
}, this);

Expand All @@ -550,6 +561,47 @@ class Grid implements CoordinateSystemMaster {
axis.scale.unionExtentFromData(data, dim);
});
}

function unionExtentForAxisByValue(
value: any,
axis: Axis2D,
axisType: OptionAxisType,
): void {
const includeMarkerInExtent = axis.model.get('includeMarkerInExtent') ?? false;
if (includeMarkerInExtent && value != null && typeof value !== 'string' && axisType !== 'category') {
const val = axis.scale.parse(value);
if (!isNaN(val)) {
axis.scale.unionExtentByValue(val);
}
}
}

function unionMarkerExtent(
markerData: any[],
xAxis: Axis2D,
yAxis: Axis2D,
): void {
each(markerData, function (item) {
if (!item) {
return;
}
const items = Array.isArray(item) ? item : [item];

each(items, function (markerItem) {
if (!markerItem) {
return;
}

unionExtentForAxisByValue(markerItem.xAxis, xAxis, xAxis.type);
unionExtentForAxisByValue(markerItem.yAxis, yAxis, yAxis.type);

if (markerItem.coord && Array.isArray(markerItem.coord)) {
unionExtentForAxisByValue(markerItem.coord[0], xAxis, xAxis.type);
unionExtentForAxisByValue(markerItem.coord[1], yAxis, yAxis.type);
}
});
});
}
}

/**
Expand Down
12 changes: 12 additions & 0 deletions src/scale/Scale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,18 @@ abstract class Scale<SETTING extends ScaleSettingDefault = ScaleSettingDefault>
this._innerUnionExtent(data.getApproximateExtent(dim));
}

/**
* Update extent by value
*/
unionExtentByValue(value: number): void {
const extent = this._extent;
// Considered that number could be NaN and should not write into the extent.
this._innerSetExtent(
value < extent[0] ? value : extent[0],
value > extent[1] ? value : extent[1]
);
}

/**
* Get a new slice of extent.
* Extent is always in increase order.
Expand Down
Loading