@@ -24,7 +24,7 @@ export function differenceY(
24
24
stroke,
25
25
strokeOpacity,
26
26
z = maybeColorChannel ( stroke ) [ 0 ] ,
27
- clip = true ,
27
+ clip, // optional additional clip for area
28
28
tip,
29
29
render,
30
30
...options
@@ -45,7 +45,8 @@ export function differenceY(
45
45
z,
46
46
fill : positiveFill ,
47
47
fillOpacity : positiveFillOpacity ,
48
- render : composeRender ( render , clipDifference ( true ) ) ,
48
+ render : composeRender ( render , clipDifferenceY ( true ) ) ,
49
+ clip,
49
50
...options
50
51
} ) ,
51
52
{ ariaLabel : "positive difference" }
@@ -61,7 +62,8 @@ export function differenceY(
61
62
z,
62
63
fill : negativeFill ,
63
64
fillOpacity : negativeFillOpacity ,
64
- render : composeRender ( render , clipDifference ( false ) ) ,
65
+ render : composeRender ( render , clipDifferenceY ( false ) ) ,
66
+ clip,
65
67
...options
66
68
} ) ,
67
69
{ ariaLabel : "negative difference" }
@@ -74,7 +76,7 @@ export function differenceY(
74
76
stroke,
75
77
strokeOpacity,
76
78
tip,
77
- clip,
79
+ clip : true ,
78
80
...options
79
81
} )
80
82
) ;
@@ -108,20 +110,24 @@ function memo(v) {
108
110
return { transform : ( data ) => V || ( V = valueof ( data , value ) ) , label} ;
109
111
}
110
112
111
- function clipDifference ( positive ) {
113
+ function clipDifferenceY ( positive ) {
112
114
return ( index , scales , channels , dimensions , context , next ) => {
113
- const clip = getClipId ( ) ;
114
- const clipPath = create ( "svg:clipPath" , context ) . attr ( "id" , clip ) . node ( ) ;
115
115
const { x1, x2} = channels ;
116
116
const { height} = dimensions ;
117
117
const y1 = new Float32Array ( x1 . length ) ;
118
118
const y2 = new Float32Array ( x2 . length ) ;
119
119
( positive === inferScaleOrder ( scales . y ) < 0 ? y1 : y2 ) . fill ( height ) ;
120
- const c = next ( index , scales , { ...channels , x2 : x1 , y2} , dimensions , context ) ;
121
- clipPath . append ( ...c . childNodes ) ;
122
- const g = next ( index , scales , { ...channels , x1 : x2 , y1} , dimensions , context ) ;
123
- g . insertBefore ( clipPath , g . firstChild ) ;
124
- g . setAttribute ( "clip-path" , `url(#${ clip } )` ) ;
125
- return g ;
120
+ const oc = next ( index , scales , { ...channels , x2 : x1 , y2} , dimensions , context ) ;
121
+ const og = next ( index , scales , { ...channels , x1 : x2 , y1} , dimensions , context ) ;
122
+ const c = oc . querySelector ( "g" ) ?? oc ; // applyClip
123
+ const g = og . querySelector ( "g" ) ?? og ; // applyClip
124
+ for ( let i = 0 ; c . firstChild ; i += 2 ) {
125
+ const id = getClipId ( ) ;
126
+ const clipPath = create ( "svg:clipPath" , context ) . attr ( "id" , id ) . node ( ) ;
127
+ clipPath . appendChild ( c . firstChild ) ;
128
+ g . childNodes [ i ] . setAttribute ( "clip-path" , `url(#${ id } )` ) ;
129
+ g . insertBefore ( clipPath , g . childNodes [ i ] ) ;
130
+ }
131
+ return og ;
126
132
} ;
127
133
}
0 commit comments