Skip to content

Commit f1c5b88

Browse files
author
quao
committed
fix 数值轴取值范围兼顾marker标记
1 parent 6b82c48 commit f1c5b88

File tree

2 files changed

+283
-1
lines changed

2 files changed

+283
-1
lines changed

src/coord/cartesian/Grid.ts

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ import GlobalModel from '../../model/Global';
4444
import ExtensionAPI from '../../core/ExtensionAPI';
4545
import { Dictionary } from 'zrender/src/core/types';
4646
import {CoordinateSystemMaster} from '../CoordinateSystem';
47-
import { NullUndefined, ScaleDataValue } from '../../util/types';
47+
import { NullUndefined, ScaleDataValue, SeriesOption } from '../../util/types';
4848
import SeriesData from '../../data/SeriesData';
4949
import OrdinalScale from '../../scale/Ordinal';
5050
import {
@@ -81,6 +81,8 @@ type AxesMap = {
8181

8282
type ParsedOuterBoundsContain = 'all' | 'axisLabel';
8383

84+
type MarkerTypes = 'markPoint' | 'markLine' | 'markArea';
85+
8486
// margin is [top, right, bottom, left]
8587
const XY_TO_MARGIN_IDX = [
8688
[3, 1], // xyIdx 0 => 'x'
@@ -542,6 +544,16 @@ class Grid implements CoordinateSystemMaster {
542544

543545
unionExtent(data, xAxis);
544546
unionExtent(data, yAxis);
547+
548+
// 处理 markPoint、markLine、markArea
549+
const markerTypes: MarkerTypes[] = ['markPoint', 'markLine', 'markArea'];
550+
551+
markerTypes.forEach(markerType => {
552+
const markerOpt = seriesModel.get(markerType as keyof SeriesOption);
553+
if (markerOpt && markerOpt.data) {
554+
unionMarkerExtent(markerOpt.data, xAxis, yAxis);
555+
}
556+
});
545557
}
546558
}, this);
547559

@@ -550,6 +562,48 @@ class Grid implements CoordinateSystemMaster {
550562
axis.scale.unionExtentFromData(data, dim);
551563
});
552564
}
565+
566+
function UnionExtentForAxisByValue(
567+
value: any,
568+
axis: Axis2D,
569+
axisType: string,
570+
): void {
571+
if (value != null && typeof value !== 'string' && axisType !== 'category') {
572+
const val = axis.scale.parse(value);
573+
if (!isNaN(val)) {
574+
axis.scale._innerUnionExtent([val, val]);
575+
}
576+
}
577+
}
578+
579+
function unionMarkerExtent(
580+
markerData: any[],
581+
xAxis: Axis2D,
582+
yAxis: Axis2D,
583+
): void {
584+
each(markerData, function (item) {
585+
if (!item) {
586+
return;
587+
}
588+
const items = isObject(item) && !item.coord && !item.xAxis && !item.yAxis
589+
? (Array.isArray(item) ? item : [item])
590+
: [item];
591+
592+
each(items, function (markerItem) {
593+
if (!markerItem) {
594+
return;
595+
}
596+
597+
UnionExtentForAxisByValue(markerItem.xAxis, xAxis, xAxis.type);
598+
UnionExtentForAxisByValue(markerItem.yAxis, yAxis, yAxis.type);
599+
600+
if (markerItem.coord && Array.isArray(markerItem.coord)) {
601+
UnionExtentForAxisByValue(markerItem.coord[0], xAxis, xAxis.type);
602+
UnionExtentForAxisByValue(markerItem.coord[1], yAxis, yAxis.type);
603+
}
604+
});
605+
});
606+
}
553607
}
554608

555609
/**

test/axis-marker-extent.html

Lines changed: 228 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)