@@ -92,7 +92,7 @@ export const draw = function (text: string, id: string, _version: string, diagOb
9292 // New config options with defaults
9393 const nodeWidth = conf ?. nodeWidth ?? defaultSankeyConfig . nodeWidth ?? 10 ;
9494 const nodePadding = conf ?. nodePadding ?? defaultSankeyConfig . nodePadding ?? 12 ;
95- const labelStyle = conf ?. labelStyle ?? defaultSankeyConfig . labelStyle ?? 'default ' ;
95+ const labelStyle = conf ?. labelStyle ?? defaultSankeyConfig . labelStyle ?? 'legacy ' ;
9696 const nodeColors : Record < string , string > = conf ?. nodeColors ?? { } ;
9797
9898 // Prepare data for construction based on diagObj.db
@@ -173,29 +173,34 @@ export const draw = function (text: string, id: string, _version: string, diagOb
173173 } ;
174174
175175 /**
176- * Determines label position based on node layer relative to central node.
177- * Left-of-center nodes get labels on the left, right-of-center on the right.
176+ * Determines label position based on node position or layer.
177+ * For 'outlined' style, uses layer-based positioning relative to central node.
178+ * For 'legacy' style, uses position-based positioning (original behavior).
178179 *
179- * @param d - Node data with layer information
180+ * @param d - Node data with layer/position information
180181 * @returns Object with x position and text-anchor
181182 */
182183 const getLabelPosition = ( d : any ) : { x : number ; anchor : string } => {
183- const nodeLayer = d . layer ?? 0 ;
184-
185- if ( nodeLayer < centralNodeLayer ) {
186- // Left of center: label on the left
187- return { x : d . x0 - 6 , anchor : 'end' } ;
188- } else {
189- // Right of center (or at center): label on the right
184+ if ( labelStyle === 'outlined' ) {
185+ // Layer-based: left-of-center nodes get labels on the left
186+ const nodeLayer = d . layer ?? 0 ;
187+ if ( nodeLayer < centralNodeLayer ) {
188+ return { x : d . x0 - 6 , anchor : 'end' } ;
189+ }
190+ return { x : d . x1 + 6 , anchor : 'start' } ;
191+ }
192+ // Legacy: position-based (original behavior)
193+ if ( d . x0 < width / 2 ) {
190194 return { x : d . x1 + 6 , anchor : 'start' } ;
191195 }
196+ return { x : d . x0 - 6 , anchor : 'end' } ;
192197 } ;
193198
194199 // Create labels for nodes
195200 const labelsGroup = svg . append ( 'g' ) . attr ( 'class' , 'node-labels' ) . attr ( 'font-size' , 14 ) ;
196201
197- if ( labelStyle === 'default ' ) {
198- // Default style: render background stroke first, then foreground text for readability
202+ if ( labelStyle === 'outlined ' ) {
203+ // Outlined style: render background stroke first, then foreground text for readability
199204 // Background text with white stroke for readability
200205 labelsGroup
201206 . selectAll ( '.sankey-label-bg' )
0 commit comments