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

Method getMarkerPosition

src/chart/bar/BaseBarSeries.ts:97–191  ·  view source on GitHub ↗
(
        value: ScaleDataValue[],
        dims?: typeof dimPermutations[number],
        startingAtTick?: boolean
    )

Source from the content-addressed store, hash-verified

95 }
96
97 getMarkerPosition(
98 value: ScaleDataValue[],
99 dims?: typeof dimPermutations[number],
100 startingAtTick?: boolean
101 ) {
102 const coordSys = this.coordinateSystem;
103 if (coordSys && coordSys.clampData) {
104 // PENDING if clamp ?
105 const clampData = coordSys.clampData(value);
106 const pt = coordSys.dataToPoint(clampData);
107 if (startingAtTick) {
108 each(coordSys.getAxes(), function (axis: Axis2D, idx: number) {
109 // If axis type is category, use tick coords instead
110 if (axis.type === 'category' && dims != null) {
111 const tickCoords = axis.getTicksCoords();
112 const alignTicksWithLabel = (axis.getTickModel() as Model<CategoryAxisBaseOption['axisTick']>)
113 .get('alignWithLabel');
114
115 let targetTickId = clampData[idx];
116 // The index of rightmost tick of markArea is 1 larger than x1/y1 index
117 const isEnd = dims[idx] === 'x1' || dims[idx] === 'y1';
118 if (isEnd && !alignTicksWithLabel) {
119 targetTickId += 1;
120 }
121
122 // The only contains one tick, tickCoords is
123 // like [{coord: 0, tickValue: 0}, {coord: 0}]
124 // to the length should always be larger than 1
125 if (tickCoords.length < 2) {
126 return;
127 }
128 else if (tickCoords.length === 2) {
129 // The left value and right value of the axis are
130 // the same. coord is 0 in both items. Use the max
131 // value of the axis as the coord
132 pt[idx] = axis.toGlobalCoord(
133 axis.getExtent()[isEnd ? 1 : 0]
134 );
135 return;
136 }
137
138 let leftCoord;
139 let coord;
140 let stepTickValue = 1;
141 for (let i = 0; i < tickCoords.length; i++) {
142 const tickCoord = tickCoords[i].coord;
143 // The last item of tickCoords doesn't contain
144 // tickValue
145 const tickValue = i === tickCoords.length - 1
146 ? tickCoords[i - 1].tickValue + stepTickValue
147 : tickCoords[i].tickValue;
148 if (tickValue === targetTickId) {
149 coord = tickCoord;
150 break;
151 }
152 else if (tickValue < targetTickId) {
153 leftCoord = tickCoord;
154 }

Callers

nothing calls this directly

Calls 13

clampDataMethod · 0.80
getTicksCoordsMethod · 0.80
getTickModelMethod · 0.80
dataToPointMethod · 0.65
toGlobalCoordMethod · 0.65
getExtentMethod · 0.65
getDataMethod · 0.65
getLayoutMethod · 0.65
getBaseAxisMethod · 0.65
eachFunction · 0.50
getAxesMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected