MCPcopy
hub / github.com/antvis/Infographic / commitTranslation

Method commitTranslation

src/editor/interactions/drag-element.ts:205–261  ·  view source on GitHub ↗
(dx: number, dy: number)

Source from the content-addressed store, hash-verified

203 }
204
205 private commitTranslation(dx: number, dy: number) {
206 if (Math.abs(dx) < 1e-6 && Math.abs(dy) < 1e-6) return;
207
208 const commands = this.dragItems.map((item) => {
209 if (item.mode === 'attr') {
210 const x = item.startX + dx;
211 const y = item.startY + dy;
212 const modifiedAttrs: Record<string, any> = { x, y };
213 const originalAttrs: Record<string, any> = {};
214
215 if (item.hasX) {
216 originalAttrs.x = item.startX;
217 } else {
218 originalAttrs.x = null;
219 }
220
221 if (item.hasY) {
222 originalAttrs.y = item.startY;
223 } else {
224 originalAttrs.y = null;
225 }
226
227 if (item.hasDataX) {
228 modifiedAttrs['data-x'] = x;
229 originalAttrs['data-x'] = item.startX;
230 }
231
232 if (item.hasDataY) {
233 modifiedAttrs['data-y'] = y;
234 originalAttrs['data-y'] = item.startY;
235 }
236
237 return new UpdateElementCommand(
238 item.element,
239 { attributes: modifiedAttrs },
240 { attributes: originalAttrs },
241 );
242 }
243
244 const transform = this.composeTransform(
245 item.startX + dx,
246 item.startY + dy,
247 item.restTransform,
248 );
249 const originalTransform =
250 item.originalTransform !== undefined ? item.originalTransform : null;
251 return new UpdateElementCommand(
252 item.element,
253 { attributes: { transform } },
254 { attributes: { transform: originalTransform } },
255 );
256 });
257
258 if (commands.length) {
259 this.commander.executeBatch(commands);
260 }
261 }
262

Callers 1

DragElementClass · 0.95

Calls 2

composeTransformMethod · 0.95
executeBatchMethod · 0.65

Tested by

no test coverage detected