@@ -8,52 +8,66 @@ export function createCSSEmphasis(
88 attrs : SVGVNodeAttrs ,
99 scope : BrushScope
1010) {
11- if ( ! el . ignore && el . __metaData ) {
12- const emphasisStyle = el . states . emphasis && el . states . emphasis . style
13- ? el . states . emphasis . style
14- : { } ;
15- let fill = emphasisStyle . fill ;
16- if ( ! fill ) {
17- // No empahsis fill, lift color
18- const normalFill = el . style && el . style . fill ;
19- const selectFill = el . states . select
20- && el . states . select . style
21- && el . states . select . style . fill ;
22- const fromFill = el . currentStates . indexOf ( 'select' ) >= 0
23- ? ( selectFill || normalFill )
24- : normalFill ;
25- if ( fromFill ) {
26- fill = liftColor ( fromFill ) ;
27- }
28- }
29- let lineWidth = emphasisStyle . lineWidth ;
30- if ( lineWidth ) {
31- // Symbols use transform to set size, so lineWidth
32- // should be divided by scaleX
33- const scaleX = ( ! emphasisStyle . strokeNoScale && el . transform )
34- ? el . transform [ 0 ]
35- : 1 ;
36- lineWidth = lineWidth / scaleX ;
37- }
38- const style = {
39- cursor : 'pointer' , // TODO: Should this be customized?
40- } as any ;
41- if ( fill ) {
42- style . fill = fill ;
43- }
44- if ( emphasisStyle . stroke ) {
45- style . stroke = emphasisStyle . stroke ;
11+ if ( ! el . ignore ) {
12+ if ( el . isSilent ( ) ) {
13+ // If el is silent, it can not be hovered nor selected.
14+ // So set pointer-events to pass through.
15+ const style = {
16+ 'pointer-events' : 'none'
17+ } ;
18+ setClassAttribute ( style , attrs , scope , true ) ;
4619 }
47- if ( lineWidth ) {
48- style [ 'stroke-width' ] = lineWidth ;
49- }
50- const styleKey = JSON . stringify ( style ) ;
51- let className = scope . cssStyleCache [ styleKey ] ;
52- if ( ! className ) {
53- className = scope . zrId + '-cls-' + getClassId ( ) ;
54- scope . cssStyleCache [ styleKey ] = className ;
55- scope . cssNodes [ '.' + className + ':hover' ] = style ;
20+ else {
21+ const emphasisStyle = el . states . emphasis && el . states . emphasis . style
22+ ? el . states . emphasis . style
23+ : { } ;
24+ let fill = emphasisStyle . fill ;
25+ if ( ! fill ) {
26+ // No empahsis fill, lift color
27+ const normalFill = el . style && el . style . fill ;
28+ const selectFill = el . states . select
29+ && el . states . select . style
30+ && el . states . select . style . fill ;
31+ const fromFill = el . currentStates . indexOf ( 'select' ) >= 0
32+ ? ( selectFill || normalFill )
33+ : normalFill ;
34+ if ( fromFill ) {
35+ fill = liftColor ( fromFill ) ;
36+ }
37+ }
38+ let lineWidth = emphasisStyle . lineWidth ;
39+ if ( lineWidth ) {
40+ // Symbols use transform to set size, so lineWidth
41+ // should be divided by scaleX
42+ const scaleX = ( ! emphasisStyle . strokeNoScale && el . transform )
43+ ? el . transform [ 0 ]
44+ : 1 ;
45+ lineWidth = lineWidth / scaleX ;
46+ }
47+ const style = {
48+ cursor : 'pointer' , // TODO: Should this be customized?
49+ } as any ;
50+ if ( fill ) {
51+ style . fill = fill ;
52+ }
53+ if ( emphasisStyle . stroke ) {
54+ style . stroke = emphasisStyle . stroke ;
55+ }
56+ if ( lineWidth ) {
57+ style [ 'stroke-width' ] = lineWidth ;
58+ }
59+ setClassAttribute ( style , attrs , scope , true ) ;
5660 }
57- attrs . class = attrs . class ? ( attrs . class + ' ' + className ) : className ;
5861 }
5962}
63+
64+ function setClassAttribute ( style : object , attrs : SVGVNodeAttrs , scope : BrushScope , withHover : boolean ) {
65+ const styleKey = JSON . stringify ( style ) ;
66+ let className = scope . cssStyleCache [ styleKey ] ;
67+ if ( ! className ) {
68+ className = scope . zrId + '-cls-' + getClassId ( ) ;
69+ scope . cssStyleCache [ styleKey ] = className ;
70+ scope . cssNodes [ '.' + className + ( withHover ? ':hover' : '' ) ] = style as any ;
71+ }
72+ attrs . class = attrs . class ? ( attrs . class + ' ' + className ) : className ;
73+ }
0 commit comments