Skip to content
Open
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
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
60 changes: 58 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 Down Expand Up @@ -81,6 +81,8 @@ type AxesMap = {

type ParsedOuterBoundsContain = 'all' | 'axisLabel';

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

// margin is [top, right, bottom, left]
const XY_TO_MARGIN_IDX = [
[3, 1], // xyIdx 0 => 'x'
Expand Down Expand Up @@ -542,6 +544,16 @@ class Grid implements CoordinateSystemMaster {

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

// 处理 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 +562,50 @@ class Grid implements CoordinateSystemMaster {
axis.scale.unionExtentFromData(data, dim);
});
}

function UnionExtentForAxisByValue(
value: any,
axis: Axis2D,
axisType: OptionAxisType,
): void {
const includeMarkerInExtent = axis.model.get('includeMarkerInExtent') ?? true;
if (includeMarkerInExtent && value != null && typeof value !== 'string' && axisType !== 'category') {
const val = axis.scale.parse(value);
if (!isNaN(val)) {
// Construct the parameter and use unionExtentFromData to avoid using the private method _innerUnionExtent
axis.scale.unionExtentFromData({
getApproximateExtent: () => [val, val]
} as any, 0);
}
}
}

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
Loading