@@ -10,6 +10,8 @@ var cn = require('./constants').cn;
10
10
11
11
var _ = Lib . _ ;
12
12
13
+ var linkStyleInitialized = false ;
14
+
13
15
function renderableValuePresent ( d ) { return d !== '' ; }
14
16
15
17
function ownTrace ( selection , d ) {
@@ -62,9 +64,38 @@ function nodeNonHoveredStyle(sankeyNode, d, sankey) {
62
64
}
63
65
64
66
function linkHoveredStyle ( d , sankey , visitNodes , sankeyLink ) {
65
- sankeyLink . style ( 'fill-opacity' , function ( l ) {
67
+ if ( ! linkStyleInitialized ) {
68
+ // Figure out whether the user has provided their own sankey-link-hover style.
69
+ let styleExists = false ;
70
+ for ( let i = 0 ; i < document . styleSheets . length ; i ++ ) {
71
+ const rules = document . styleSheets [ i ] . cssRules ;
72
+ for ( let j = 0 ; j < rules . length ; j ++ ) {
73
+ if ( rules [ j ] . selectorText === '.sankey-link-hover' ) {
74
+ styleExists = true ;
75
+ break ;
76
+ }
77
+ }
78
+ if ( styleExists ) break ;
79
+ }
80
+
81
+ // If not, insert a default one
82
+ if ( ! styleExists ) {
83
+ var style = document . querySelector ( 'style' ) ;
84
+ if ( ! style ) {
85
+ style = document . createElement ( 'style' ) ;
86
+ document . head . appendChild ( style ) ;
87
+ }
88
+ const sheet = style . sheet ;
89
+ // If these are not flagged as !important chrome won't render the change
90
+ sheet . insertRule ( '.sankey-link-hover { fill-opacity: 0.4 !important; }' , 0 ) ;
91
+ }
92
+
93
+ linkStyleInitialized = true ;
94
+ }
95
+
96
+ sankeyLink . classed ( 'sankey-link-hover' , function ( l ) {
66
97
if ( ! l . link . concentrationscale ) {
67
- return 0.4 ;
98
+ return true ;
68
99
}
69
100
} ) ;
70
101
@@ -74,9 +105,9 @@ function linkHoveredStyle(d, sankey, visitNodes, sankeyLink) {
74
105
ownTrace ( sankey , d )
75
106
. selectAll ( '.' + cn . sankeyLink )
76
107
. filter ( function ( l ) { return l . link . label === label ; } )
77
- . style ( 'fill-opacity ', function ( l ) {
108
+ . classed ( 'sankey-link-hover ', function ( l ) {
78
109
if ( ! l . link . concentrationscale ) {
79
- return 0.4 ;
110
+ return true ;
80
111
}
81
112
} ) ;
82
113
}
@@ -91,15 +122,15 @@ function linkHoveredStyle(d, sankey, visitNodes, sankeyLink) {
91
122
}
92
123
93
124
function linkNonHoveredStyle ( d , sankey , visitNodes , sankeyLink ) {
94
- sankeyLink . style ( 'fill-opacity ', function ( d ) { return d . tinyColorAlpha ; } ) ;
125
+ sankeyLink . classed ( 'sankey-link-hover ', false ) ;
95
126
96
127
sankeyLink . each ( function ( curLink ) {
97
128
var label = curLink . link . label ;
98
129
if ( label !== '' ) {
99
130
ownTrace ( sankey , d )
100
131
. selectAll ( '.' + cn . sankeyLink )
101
132
. filter ( function ( l ) { return l . link . label === label ; } )
102
- . style ( 'fill-opacity ', function ( d ) { return d . tinyColorAlpha ; } ) ;
133
+ . classed ( 'sankey-link-hover ', false ) ;
103
134
}
104
135
} ) ;
105
136
0 commit comments