MCPcopy
hub / github.com/apache/echarts / updateMarkerLayout

Function updateMarkerLayout

src/component/marker/MarkPointView.ts:38–92  ·  view source on GitHub ↗
(
    mpData: SeriesData<MarkPointModel>,
    seriesModel: SeriesModel,
    api: ExtensionAPI
)

Source from the content-addressed store, hash-verified

36import SeriesDimensionDefine from '../../data/SeriesDimensionDefine';
37
38function updateMarkerLayout(
39 mpData: SeriesData<MarkPointModel>,
40 seriesModel: SeriesModel,
41 api: ExtensionAPI
42) {
43 const coordSys = seriesModel.coordinateSystem;
44 const apiWidth = api.getWidth();
45 const apiHeight = api.getHeight();
46 const coordRect = coordSys && coordSys.getArea && coordSys.getArea();
47 mpData.each(function (idx: number) {
48 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
63 let point;
64 const xPx = numberUtil.parsePercent(itemModel.get('x'), width) + left;
65 const yPx = numberUtil.parsePercent(itemModel.get('y'), height) + top;
66 if (!isNaN(xPx) && !isNaN(yPx)) {
67 point = [xPx, yPx];
68 }
69 // Chart like bar may have there own marker positioning logic
70 else if (seriesModel.getMarkerPosition) {
71 // Use the getMarkerPosition
72 point = seriesModel.getMarkerPosition(
73 mpData.getValues(mpData.dimensions, idx)
74 );
75 }
76 else if (coordSys) {
77 const x = mpData.get(coordSys.dimensions[0], idx);
78 const y = mpData.get(coordSys.dimensions[1], idx);
79 point = coordSys.dataToPoint([x, y]);
80 }
81
82 // Use x, y if has any
83 if (!isNaN(xPx)) {
84 point[0] = xPx;
85 }
86 if (!isNaN(yPx)) {
87 point[1] = yPx;
88 }
89
90 mpData.setItemLayout(idx, point);
91 });
92}
93
94class MarkPointView extends MarkerView {
95

Callers 2

updateTransformMethod · 0.85
renderSeriesMethod · 0.85

Calls 10

getItemModelMethod · 0.80
setItemLayoutMethod · 0.80
getWidthMethod · 0.65
getHeightMethod · 0.65
getMarkerPositionMethod · 0.65
dataToPointMethod · 0.65
getAreaMethod · 0.45
eachMethod · 0.45
getMethod · 0.45
getValuesMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…