Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
56 changes: 55 additions & 1 deletion 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 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,48 @@ class Grid implements CoordinateSystemMaster {
axis.scale.unionExtentFromData(data, dim);
});
}

function UnionExtentForAxisByValue(
value: any,
axis: Axis2D,
axisType: string,
): void {
if (value != null && typeof value !== 'string' && axisType !== 'category') {
const val = axis.scale.parse(value);
if (!isNaN(val)) {
axis.scale._innerUnionExtent([val, val]);
}
}
}

function unionMarkerExtent(
markerData: any[],
xAxis: Axis2D,
yAxis: Axis2D,
): void {
each(markerData, function (item) {
if (!item) {
return;
}
const items = isObject(item) && !item.coord && !item.xAxis && !item.yAxis
? (Array.isArray(item) ? 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
228 changes: 228 additions & 0 deletions test/axis-marker-extent.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.