@@ -57,44 +57,43 @@ export class AxisX {
57
57
} ,
58
58
context
59
59
) {
60
- const {
61
- axis,
62
- fontVariant,
63
- grid,
64
- label,
65
- labelAnchor,
66
- labelOffset,
67
- line,
68
- name,
69
- tickRotate
70
- } = this ;
60
+ const { axis, fontVariant, grid, label, labelAnchor, labelOffset, line, name, tickRotate} = this ;
71
61
const offset = name === "x" ? 0 : axis === "top" ? marginTop - facetMarginTop : marginBottom - facetMarginBottom ;
72
62
const offsetSign = axis === "top" ? - 1 : 1 ;
73
63
const ty = offsetSign * offset + ( axis === "top" ? marginTop : height - marginBottom ) ;
74
64
return create ( "svg:g" , context )
75
- . call ( applyAria , this )
76
- . attr ( "transform" , `translate(${ offsetLeft } ,${ ty } )` )
77
- . call ( createAxis ( axis === "top" ? axisTop : axisBottom , x , this ) )
78
- . call ( maybeTickRotate , tickRotate )
79
- . attr ( "font-size" , null )
80
- . attr ( "font-family" , null )
81
- . attr ( "font-variant" , fontVariant )
82
- . call ( ! line ? g => g . select ( ".domain" ) . remove ( ) : ( ) => { } )
83
- . call ( ! grid ? ( ) => { }
84
- : fy ? gridFacetX ( index , fy , - ty )
85
- : gridX ( offsetSign * ( marginBottom + marginTop - height ) ) )
86
- . call ( ! label ? ( ) => { } : g => g . append ( "text" )
87
- . attr ( "fill" , "currentColor" )
88
- . attr ( "transform" , `translate(${
89
- labelAnchor === "center" ? ( width + marginLeft - marginRight ) / 2
90
- : labelAnchor === "right" ? width + labelMarginRight
91
- : - labelMarginLeft
92
- } ,${ labelOffset * offsetSign } )`)
93
- . attr ( "dy" , axis === "top" ? "1em" : "-0.32em" )
94
- . attr ( "text-anchor" , labelAnchor === "center" ? "middle"
95
- : labelAnchor === "right" ? "end"
96
- : "start" )
97
- . text ( label ) )
65
+ . call ( applyAria , this )
66
+ . attr ( "transform" , `translate(${ offsetLeft } ,${ ty } )` )
67
+ . call ( createAxis ( axis === "top" ? axisTop : axisBottom , x , this ) )
68
+ . call ( maybeTickRotate , tickRotate )
69
+ . attr ( "font-size" , null )
70
+ . attr ( "font-family" , null )
71
+ . attr ( "font-variant" , fontVariant )
72
+ . call ( ! line ? ( g ) => g . select ( ".domain" ) . remove ( ) : ( ) => { } )
73
+ . call (
74
+ ! grid ? ( ) => { } : fy ? gridFacetX ( index , fy , - ty ) : gridX ( offsetSign * ( marginBottom + marginTop - height ) )
75
+ )
76
+ . call (
77
+ ! label
78
+ ? ( ) => { }
79
+ : ( g ) =>
80
+ g
81
+ . append ( "text" )
82
+ . attr ( "fill" , "currentColor" )
83
+ . attr (
84
+ "transform" ,
85
+ `translate(${
86
+ labelAnchor === "center"
87
+ ? ( width + marginLeft - marginRight ) / 2
88
+ : labelAnchor === "right"
89
+ ? width + labelMarginRight
90
+ : - labelMarginLeft
91
+ } ,${ labelOffset * offsetSign } )`
92
+ )
93
+ . attr ( "dy" , axis === "top" ? "1em" : "-0.32em" )
94
+ . attr ( "text-anchor" , labelAnchor === "center" ? "middle" : labelAnchor === "right" ? "end" : "start" )
95
+ . text ( label )
96
+ )
98
97
. node ( ) ;
99
98
}
100
99
}
@@ -136,106 +135,93 @@ export class AxisY {
136
135
render (
137
136
index ,
138
137
{ [ this . name ] : y , fx} ,
139
- {
140
- width,
141
- height,
142
- marginTop,
143
- marginRight,
144
- marginBottom,
145
- marginLeft,
146
- offsetTop = 0 ,
147
- facetMarginLeft,
148
- facetMarginRight
149
- } ,
138
+ { width, height, marginTop, marginRight, marginBottom, marginLeft, offsetTop = 0 , facetMarginLeft, facetMarginRight} ,
150
139
context
151
140
) {
152
- const {
153
- axis,
154
- fontVariant,
155
- grid,
156
- label,
157
- labelAnchor,
158
- labelOffset,
159
- line,
160
- name,
161
- tickRotate
162
- } = this ;
141
+ const { axis, fontVariant, grid, label, labelAnchor, labelOffset, line, name, tickRotate} = this ;
163
142
const offset = name === "y" ? 0 : axis === "left" ? marginLeft - facetMarginLeft : marginRight - facetMarginRight ;
164
143
const offsetSign = axis === "left" ? - 1 : 1 ;
165
144
const tx = offsetSign * offset + ( axis === "right" ? width - marginRight : marginLeft ) ;
166
145
return create ( "svg:g" , context )
167
- . call ( applyAria , this )
168
- . attr ( "transform" , `translate(${ tx } ,${ offsetTop } )` )
169
- . call ( createAxis ( axis === "right" ? axisRight : axisLeft , y , this ) )
170
- . call ( maybeTickRotate , tickRotate )
171
- . attr ( "font-size" , null )
172
- . attr ( "font-family" , null )
173
- . attr ( "font-variant" , fontVariant )
174
- . call ( ! line ? g => g . select ( ".domain" ) . remove ( ) : ( ) => { } )
175
- . call ( ! grid ? ( ) => { }
176
- : fx ? gridFacetY ( index , fx , - tx )
177
- : gridY ( offsetSign * ( marginLeft + marginRight - width ) ) )
178
- . call ( ! label ? ( ) => { } : g => g . append ( "text" )
179
- . attr ( "fill" , "currentColor" )
180
- . attr ( "font-variant" , fontVariant == null ? null : "normal" )
181
- . attr ( "transform" , `translate(${ labelOffset * offsetSign } ,${
182
- labelAnchor === "center" ? ( height + marginTop - marginBottom ) / 2
183
- : labelAnchor === "bottom" ? height - marginBottom
184
- : marginTop
185
- } )${ labelAnchor === "center" ? ` rotate(-90)` : "" } `)
186
- . attr ( "dy" , labelAnchor === "center" ? ( axis === "right" ? "-0.32em" : "0.75em" )
187
- : labelAnchor === "bottom" ? "1.4em"
188
- : "-1em" )
189
- . attr ( "text-anchor" , labelAnchor === "center" ? "middle"
190
- : axis === "right" ? "end"
191
- : "start" )
192
- . text ( label ) )
146
+ . call ( applyAria , this )
147
+ . attr ( "transform" , `translate(${ tx } ,${ offsetTop } )` )
148
+ . call ( createAxis ( axis === "right" ? axisRight : axisLeft , y , this ) )
149
+ . call ( maybeTickRotate , tickRotate )
150
+ . attr ( "font-size" , null )
151
+ . attr ( "font-family" , null )
152
+ . attr ( "font-variant" , fontVariant )
153
+ . call ( ! line ? ( g ) => g . select ( ".domain" ) . remove ( ) : ( ) => { } )
154
+ . call ( ! grid ? ( ) => { } : fx ? gridFacetY ( index , fx , - tx ) : gridY ( offsetSign * ( marginLeft + marginRight - width ) ) )
155
+ . call (
156
+ ! label
157
+ ? ( ) => { }
158
+ : ( g ) =>
159
+ g
160
+ . append ( "text" )
161
+ . attr ( "fill" , "currentColor" )
162
+ . attr ( "font-variant" , fontVariant == null ? null : "normal" )
163
+ . attr (
164
+ "transform" ,
165
+ `translate(${ labelOffset * offsetSign } ,${
166
+ labelAnchor === "center"
167
+ ? ( height + marginTop - marginBottom ) / 2
168
+ : labelAnchor === "bottom"
169
+ ? height - marginBottom
170
+ : marginTop
171
+ } )${ labelAnchor === "center" ? ` rotate(-90)` : "" } `
172
+ )
173
+ . attr (
174
+ "dy" ,
175
+ labelAnchor === "center"
176
+ ? axis === "right"
177
+ ? "-0.32em"
178
+ : "0.75em"
179
+ : labelAnchor === "bottom"
180
+ ? "1.4em"
181
+ : "-1em"
182
+ )
183
+ . attr ( "text-anchor" , labelAnchor === "center" ? "middle" : axis === "right" ? "end" : "start" )
184
+ . text ( label )
185
+ )
193
186
. node ( ) ;
194
187
}
195
188
}
196
189
197
- function applyAria ( selection , {
198
- name,
199
- label,
200
- ariaLabel = `${ name } -axis` ,
201
- ariaDescription = label
202
- } ) {
190
+ function applyAria ( selection , { name, label, ariaLabel = `${ name } -axis` , ariaDescription = label } ) {
203
191
applyAttr ( selection , "aria-label" , ariaLabel ) ;
204
192
applyAttr ( selection , "aria-description" , ariaDescription ) ;
205
193
}
206
194
207
195
function gridX ( y2 ) {
208
- return g => g . selectAll ( ".tick line" )
209
- . clone ( true )
210
- . attr ( "stroke-opacity" , 0.1 )
211
- . attr ( "y2" , y2 ) ;
196
+ return ( g ) => g . selectAll ( ".tick line" ) . clone ( true ) . attr ( "stroke-opacity" , 0.1 ) . attr ( "y2" , y2 ) ;
212
197
}
213
198
214
199
function gridY ( x2 ) {
215
- return g => g . selectAll ( ".tick line" )
216
- . clone ( true )
217
- . attr ( "stroke-opacity" , 0.1 )
218
- . attr ( "x2" , x2 ) ;
200
+ return ( g ) => g . selectAll ( ".tick line" ) . clone ( true ) . attr ( "stroke-opacity" , 0.1 ) . attr ( "x2" , x2 ) ;
219
201
}
220
202
221
203
function gridFacetX ( index , fy , ty ) {
222
204
const dy = fy . bandwidth ( ) ;
223
205
const domain = fy . domain ( ) ;
224
- return g => g . selectAll ( ".tick" )
225
- . append ( "path" )
206
+ return ( g ) =>
207
+ g
208
+ . selectAll ( ".tick" )
209
+ . append ( "path" )
226
210
. attr ( "stroke" , "currentColor" )
227
211
. attr ( "stroke-opacity" , 0.1 )
228
- . attr ( "d" , ( index ? take ( domain , index ) : domain ) . map ( v => `M0,${ fy ( v ) + ty } v${ dy } ` ) . join ( "" ) ) ;
212
+ . attr ( "d" , ( index ? take ( domain , index ) : domain ) . map ( ( v ) => `M0,${ fy ( v ) + ty } v${ dy } ` ) . join ( "" ) ) ;
229
213
}
230
214
231
215
function gridFacetY ( index , fx , tx ) {
232
216
const dx = fx . bandwidth ( ) ;
233
217
const domain = fx . domain ( ) ;
234
- return g => g . selectAll ( ".tick" )
235
- . append ( "path" )
218
+ return ( g ) =>
219
+ g
220
+ . selectAll ( ".tick" )
221
+ . append ( "path" )
236
222
. attr ( "stroke" , "currentColor" )
237
223
. attr ( "stroke-opacity" , 0.1 )
238
- . attr ( "d" , ( index ? take ( domain , index ) : domain ) . map ( v => `M${ fx ( v ) + tx } ,0h${ dx } ` ) . join ( "" ) ) ;
224
+ . attr ( "d" , ( index ? take ( domain , index ) : domain ) . map ( ( v ) => `M${ fx ( v ) + tx } ,0h${ dx } ` ) . join ( "" ) ) ;
239
225
}
240
226
241
227
function maybeTicks ( ticks ) {
@@ -250,10 +236,13 @@ function maybeTickFormat(tickFormat) {
250
236
// an ordinal domain is numbers or dates, and we want null to mean the empty
251
237
// string, not the default identity format.
252
238
export function maybeAutoTickFormat ( tickFormat , domain ) {
253
- return tickFormat === undefined ? ( isTemporal ( domain ) ? formatIsoDate : string )
254
- : typeof tickFormat === "function" ? tickFormat
255
- : ( typeof tickFormat === "string" ? ( isTemporal ( domain ) ? utcFormat : format )
256
- : constant ) ( tickFormat ) ;
239
+ return tickFormat === undefined
240
+ ? isTemporal ( domain )
241
+ ? formatIsoDate
242
+ : string
243
+ : typeof tickFormat === "function"
244
+ ? tickFormat
245
+ : ( typeof tickFormat === "string" ? ( isTemporal ( domain ) ? utcFormat : format ) : constant ) ( tickFormat ) ;
257
246
}
258
247
259
248
function createAxis ( axis , scale , { ticks, tickSize, tickPadding, tickFormat} ) {
@@ -280,7 +269,10 @@ function maybeTickRotate(g, rotate) {
280
269
text . setAttribute ( "text-anchor" , Math . abs ( rotate ) < 10 ? "middle" : ( rotate < 0 ) ^ ( s > 0 ) ? "start" : "end" ) ;
281
270
} else {
282
271
const s = Math . sign ( x ) ;
283
- text . setAttribute ( "transform" , `translate(${ x + s * 4 * Math . abs ( Math . sin ( rotate * radians ) ) } , 0) rotate(${ rotate } )` ) ;
272
+ text . setAttribute (
273
+ "transform" ,
274
+ `translate(${ x + s * 4 * Math . abs ( Math . sin ( rotate * radians ) ) } , 0) rotate(${ rotate } )`
275
+ ) ;
284
276
text . setAttribute ( "text-anchor" , Math . abs ( rotate ) > 60 ? "middle" : s > 0 ? "start" : "end" ) ;
285
277
}
286
278
text . removeAttribute ( "x" ) ;
0 commit comments