Skip to content

Commit 2b0bd9a

Browse files
authored
Merge pull request #20166 from apache/feat/stock-marker
feat(marker): add `relativeTo` option for specifying the relative target of marker position
2 parents 2a3b098 + beb3636 commit 2b0bd9a

File tree

6 files changed

+242
-4
lines changed

6 files changed

+242
-4
lines changed

src/component/marker/MarkPointView.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,28 @@ function updateMarkerLayout(
4141
api: ExtensionAPI
4242
) {
4343
const coordSys = seriesModel.coordinateSystem;
44+
const apiWidth = api.getWidth();
45+
const apiHeight = api.getHeight();
46+
const coordRect = coordSys.getArea && coordSys.getArea();
4447
mpData.each(function (idx: number) {
4548
const itemModel = mpData.getItemModel<MarkPointDataItemOption>(idx);
49+
const isRelativeToCoordinate = itemModel.get('relativeTo') === 'coordinate';
50+
const width = isRelativeToCoordinate
51+
? (coordRect ? coordRect.width : 0)
52+
: apiWidth;
53+
const height = isRelativeToCoordinate
54+
? (coordRect ? coordRect.height : 0)
55+
: apiHeight;
56+
const left = isRelativeToCoordinate && coordRect
57+
? coordRect.x
58+
: 0;
59+
const top = isRelativeToCoordinate && coordRect
60+
? coordRect.y
61+
: 0;
62+
4663
let point;
47-
const xPx = numberUtil.parsePercent(itemModel.get('x'), api.getWidth());
48-
const yPx = numberUtil.parsePercent(itemModel.get('y'), api.getHeight());
64+
const xPx = numberUtil.parsePercent(itemModel.get('x'), width) + left;
65+
const yPx = numberUtil.parsePercent(itemModel.get('y'), height) + top;
4966
if (!isNaN(xPx) && !isNaN(yPx)) {
5067
point = [xPx, yPx];
5168
}

src/component/marker/MarkerModel.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export interface MarkerPositionOption {
5353
// Absolute position, px or percent string
5454
x?: number | string
5555
y?: number | string
56+
relativeTo?: 'container' | 'coordinate'
5657

5758
/**
5859
* Coord on any coordinate system

src/component/marker/markerHelper.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ export function dataTransform(
153153
// x y is provided
154154
if (item.coord == null || !isArray(dims)) {
155155
item.coord = [];
156+
const baseAxis = seriesModel.getBaseAxis();
157+
const otherAxis = coordSys.getOtherAxis(baseAxis);
158+
item.value = numCalculate(data, data.mapDimension(otherAxis.dim), item.type);
156159
}
157160
else {
158161
// Each coord support max, min, average

src/coord/CoordinateSystem.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,11 @@ export interface CoordinateSystemHostModel extends ComponentModel {
174174
* It is used to clip the graphic elements with the contain methods.
175175
*/
176176
export interface CoordinateSystemClipArea {
177-
contain(x: number, y: number): boolean
177+
x: number;
178+
y: number;
179+
width: number;
180+
height: number;
181+
contain(x: number, y: number): boolean;
178182
}
179183

180184
export function isCoordinateSystemType<T extends CoordinateSystem, S = T['type']>(

src/coord/polar/Polar.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,13 @@ class Polar implements CoordinateSystem, CoordinateSystemMaster {
235235
// minus a tiny value 1e-4 in double side to avoid being clipped unexpectedly
236236
// r == r0 contain nothing
237237
return r !== r0 && (d2 - EPSILON) <= r * r && (d2 + EPSILON) >= r0 * r0;
238-
}
238+
},
239+
240+
// As the bounding box
241+
x: this.cx - radiusExtent[1],
242+
y: this.cy - radiusExtent[1],
243+
width: radiusExtent[1] * 2,
244+
height: radiusExtent[1] * 2
239245
};
240246
}
241247

test/markPoint-stock.html

Lines changed: 207 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)