@@ -20,7 +20,7 @@ import { HiPlotPluginData } from "../plugin";
2020import { ResizableH } from "../lib/resizable" ;
2121import { Filter , FilterType , apply_filters } from "../filters" ;
2222import { foDynamicSizeFitContent , foCreateAxisLabel } from "../lib/svghelpers" ;
23- import { IS_SAFARI , IS_MOBILE_SAFARI , redrawAllForeignObjectsIfSafari } from "../lib/browsercompat" ;
23+ import { IS_SAFARI , redrawForeignObject } from "../lib/browsercompat" ;
2424
2525interface StringMapping < V > { [ key : string ] : V ; } ;
2626
@@ -163,7 +163,24 @@ export class ParallelPlot extends React.Component<ParallelPlotData, ParallelPlot
163163 g = g . transition ( ) ;
164164 }
165165 g . attr ( "transform" , function ( this : ParallelPlot , p ) { return "translate(" + this . position ( p ) + ")" ; } . bind ( this ) ) ;
166- redrawAllForeignObjectsIfSafari ( ) ;
166+
167+ // Safari: apply CSS transforms to foreignObjects during drag, redraw after
168+ if ( IS_SAFARI ) {
169+ if ( this . state . dragging ) {
170+ const me = this ;
171+ this . dimensions_dom . each ( function ( dim : string ) {
172+ const fo = d3 . select ( this ) . select ( "foreignObject" ) ;
173+ const delta = me . position ( dim ) - me . xscale ( dim ) ;
174+ fo . style ( "transform" , delta !== 0 ? `translateX(${ delta } px)` : null ) ;
175+ } ) ;
176+ } else {
177+ // Not dragging - force redraw all foreignObjects to ensure correct position
178+ this . dimensions_dom . selectAll ( "foreignObject" ) . each ( function ( ) {
179+ redrawForeignObject ( this as SVGForeignObjectElement ) ;
180+ } ) ;
181+ }
182+ }
183+
167184 this . update_ticks ( ) ;
168185 this . updateAxisTitlesAnglesAndFontSize ( ) ;
169186 // Notify parent of hidden columns count change (dimensions affects can_restore_axis)
@@ -378,9 +395,23 @@ export class ParallelPlot extends React.Component<ParallelPlotData, ParallelPlot
378395 me . setState ( { dimensions : new_dimensions } ) ;
379396 }
380397 me . dimensions_dom . attr ( "transform" , function ( d ) { return "translate(" + me . position ( d ) + ")" ; } ) ;
381- redrawAllForeignObjectsIfSafari ( ) ;
398+
399+ // Safari doesn't update foreignObject positions when parent transforms change.
400+ // Apply the position delta directly to each foreignObject as a CSS transform.
401+ if ( IS_SAFARI ) {
402+ me . dimensions_dom . each ( function ( dim : string ) {
403+ const fo = d3 . select ( this ) . select ( "foreignObject" ) ;
404+ const delta = me . position ( dim ) - me . xscale ( dim ) ;
405+ fo . style ( "transform" , delta !== 0 ? `translateX(${ delta } px)` : null ) ;
406+ } ) ;
407+ }
382408 } )
383409 . on ( "end" , function ( event , d : string ) {
410+ // Clear Safari CSS transforms from foreignObjects
411+ if ( IS_SAFARI ) {
412+ me . dimensions_dom . selectAll ( "foreignObject" ) . style ( "transform" , null ) ;
413+ }
414+
384415 if ( ! me . state . dragging . dragging ) {
385416 // no movement, invert axis
386417 var extent = invert_axis ( d ) ;
@@ -393,11 +424,16 @@ export class ParallelPlot extends React.Component<ParallelPlotData, ParallelPlot
393424 const element = this ;
394425 me . setState ( { order : Array . from ( me . state . dimensions ) , dragging : null } , function ( ) {
395426 // reorder axes
396- var drag : any = d3 . select ( this ) ;
397- if ( ! IS_SAFARI ) {
398- drag = drag . transition ( ) ;
427+ const parentG = d3 . select ( element . parentElement . parentElement ) ;
428+ if ( IS_SAFARI ) {
429+ // Skip transition on Safari - it causes foreignObject positioning issues
430+ parentG . attr ( "transform" , "translate(" + me . xscale ( d ) + ")" ) ;
431+ // Force redraw of the foreignObject to ensure correct position
432+ const fo = parentG . select ( "foreignObject" ) . node ( ) as SVGForeignObjectElement ;
433+ if ( fo ) redrawForeignObject ( fo ) ;
434+ } else {
435+ parentG . transition ( ) . attr ( "transform" , "translate(" + me . xscale ( d ) + ")" ) ;
399436 }
400- d3 . select ( element . parentElement . parentElement ) . attr ( "transform" , "translate(" + me . xscale ( d ) + ")" ) ;
401437 var extents = brush_extends ( ) ;
402438 extent = extents [ d ] ;
403439 me . update_ticks ( d , extent ) ;
0 commit comments