@@ -192,9 +192,9 @@ var Workflows = {
192192 $ ( '#node-modal-form-title' ) . val ( data . name ) ;
193193 $ ( '#node-modal-form-description' ) . val ( data . description ) ;
194194 if ( data . color ) {
195- $ ( '#node-modal-form-colour' ) [ 0 ] . jscolor . fromString ( data . color ) ;
195+ $ ( '#node-modal-form-colour' ) . val ( data . color ) ;
196196 } else if ( data . parent ) {
197- $ ( '#node-modal-form-colour' ) [ 0 ] . jscolor . fromString ( cy . $ ( '#' + data . parent ) . data ( 'color' ) ) ;
197+ $ ( '#node-modal-form-colour' ) . val ( cy . $ ( '#' + data . parent ) . data ( 'color' ) ) ;
198198 }
199199 $ ( '#node-modal-form-parent-id' ) . val ( data . parent ) ;
200200 $ ( '#node-modal-form-x' ) . val ( position . x ) ;
@@ -211,7 +211,7 @@ var Workflows = {
211211 description : $ ( '#node-modal-form-description' ) . val ( ) ,
212212 html_description : MarkdownIt . render ( $ ( '#node-modal-form-description' ) . val ( ) ) ,
213213 color : $ ( '#node-modal-form-colour' ) . val ( ) ,
214- font_color : $ ( '#node-modal-form-colour' ) . css ( "color" ) ,
214+ font_color : Workflows . getTextColor ( $ ( '#node-modal-form-colour' ) . val ( ) ) ,
215215 parent : $ ( '#node-modal-form-parent-id' ) . val ( ) ,
216216 associatedResources : Workflows . associatedResources . fetch ( ) ,
217217 ontologyTerms : Workflows . ontologyTerms . fetch ( )
@@ -470,6 +470,21 @@ var Workflows = {
470470 ) ;
471471 }
472472 }
473+ } ,
474+ getTextColor : function ( hex ) {
475+ // Remove the leading '#', if present
476+ hex = hex . replace ( '#' , '' ) ;
477+
478+ // Parse r, g, b values
479+ const r = parseInt ( hex . substring ( 0 , 2 ) , 16 ) ;
480+ const g = parseInt ( hex . substring ( 2 , 4 ) , 16 ) ;
481+ const b = parseInt ( hex . substring ( 4 , 6 ) , 16 ) ;
482+
483+ // Calculate perceived brightness (luminance)
484+ const brightness = ( 0.299 * r ) + ( 0.587 * g ) + ( 0.114 * b ) ;
485+
486+ // Threshold of ~186 is a common practical cutoff
487+ return brightness > 186 ? '#000000' : '#FFFFFF' ;
473488 }
474489} ;
475490
@@ -621,7 +636,6 @@ document.addEventListener("turbolinks:load", function() {
621636 // Initialize
622637 Workflows . cancelState ( ) ;
623638 Workflows . history . initialize ( ) ;
624- jscolor . installByClassName ( 'jscolor' ) ;
625639 } else {
626640 // Hiding/revealing of child nodes
627641 if ( hideChildNodes ) {
0 commit comments