magicapple123 opened a new pull request, #21762:
URL: https://github.com/apache/echarts/pull/21762

   ## Brief Information
   
   This pull request is in the type of:
   
   - [x] bug fixing
   - [ ] new feature
   - [ ] others
   
   ### What does this PR do?
   
   Keeps the position of a dragged line label (e.g. edge labels of graph 
series) instead of recalculating it from the line geometry on every update, so 
that `labelLayout.draggable` works for edge labels.
   
   ### Fixed issues
   
   - #18752: `labelLayout.draggable` in series of type `graph` doesn't affect 
edge labels.
   
   ## Details
   
   ### Before: What was the problem?
   
   `labelLayout.draggable` works for node labels but not for edge labels: 
dragging an edge label has no effect, the label snaps back to its original 
position immediately.
   
   Reproduce: a graph series with `labelLayout: { draggable: true }` and 
`edgeLabel: { show: true }` — drag an edge label with the mouse; it instantly 
returns to the line midpoint.
   
   Root cause: `Line.beforeUpdate()` (`src/chart/helper/Line.ts`) resets 
`label.x = label.y = 0` and recomputes the label position from the line 
geometry on every update of the element. Dragging the label marks the host 
`Line` group dirty, so the recomputation runs on the frame right after the drag 
move and wipes the dragged position. This also explains why `labelLayout.dx/dy` 
survive (they are stored in `textConfig.offset`, which `beforeUpdate` does not 
touch) while `x/y` and dragging do not.
   
   ### After: How does it behave after the fixing?
   
   The label now stays where the user drops it:
   
   - In `_updateCommonStl`, a `drag` listener marks the label as dragged 
(`__labelDragged`).
   - In `beforeUpdate`, the position recomputation is skipped when the label is 
draggable and has been dragged, so the dragged position persists (the label 
scale is still updated).
   - The dragged position lasts until the next data update (`updateData`), 
consistent with how dragged labels behave in other series.
   - A test case is added at `test/graph-edge-label-draggable.html`.
   
   ### Test
   
   - `npm test` (jest): 26 suites / 194 tests passed.
   - `npx eslint src/chart/helper/Line.ts` and `npx tsc --noEmit` pass.
   - Manually verified with the added test page: dragging an edge label keeps 
it at the dropped position; a chart update (`setOption`) restores the default 
position.
   
   ## Document Info
   
   One of the following should be checked.
   
   - [x] This PR doesn't relate to document changes
   - [ ] The document should be updated later
   - [ ] The document changes have been made in apache/echarts-doc#xxx
   
   ## Misc
   
   ### Security Checking
   
   - [ ] This PR uses security-sensitive Web APIs.
   
   ### ZRender Changes
   
   - [ ] This PR depends on ZRender changes.
   
   ### Merging options
   
   - [x] Please squash the commits into a single one when merging.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to