@@ -9,13 +9,36 @@ import { AxisZoomCapture } from "./AxisZoomCapture";
9
9
import { colorToRGBA , first , getStrokeDasharray , identity , isDefined , isNotDefined , last , strokeDashTypes , zipper } from "../utils" ;
10
10
11
11
interface AxisProps {
12
+ readonly axisZoomCallback ?: any ; // func
13
+ readonly bg : {
14
+ h : number ;
15
+ x : number ;
16
+ w : number ;
17
+ y : number ;
18
+ } ;
19
+ readonly className ?: string ;
20
+ readonly domainClassName ?: string ;
21
+ readonly edgeClip : boolean ;
22
+ readonly fill ?: string ;
12
23
readonly flexTicks ?: boolean ;
13
24
readonly fontFamily ?: string ;
14
25
readonly fontSize ?: number ;
15
26
readonly fontWeight ?: number ;
16
- readonly orient ?: "top" | "left" | "right" | "bottom" ;
27
+ readonly getMouseDelta : any ; // func
28
+ readonly getScale : any ; // func
17
29
readonly innerTickSize ?: number ;
18
- readonly outerTickSize ?: number ;
30
+ readonly inverted ?: boolean ;
31
+ readonly onContextMenu ?: any ; // func
32
+ readonly onDoubleClick ?: any ; // func
33
+ readonly orient ?: "top" | "left" | "right" | "bottom" ;
34
+ readonly outerTickSize : number ;
35
+ readonly range : number [ ] ;
36
+ readonly showDomain ?: boolean ;
37
+ readonly showTicks ?: boolean ;
38
+ readonly showTickLabel ?: boolean ;
39
+ readonly stroke : string ;
40
+ readonly strokeOpacity ?: number ;
41
+ readonly strokeWidth : number ;
19
42
readonly tickFormat ?: ( data : any ) => string ;
20
43
readonly tickPadding ?: number ;
21
44
readonly tickSize ?: number ;
@@ -28,43 +51,28 @@ interface AxisProps {
28
51
readonly tickValues ?: number [ ] | any ; // func
29
52
readonly tickInterval ?: number ;
30
53
readonly tickIntervalFunction ?: any ; // func
31
- readonly showDomain ?: boolean ;
32
- readonly showTicks ?: boolean ;
33
- readonly showTickLabel ?: boolean ;
34
- readonly className ?: string ;
35
- readonly axisZoomCallback ?: any ; // func
54
+ readonly transform : number [ ] ;
36
55
readonly zoomEnabled ?: boolean ;
37
- readonly inverted ?: boolean ;
38
56
readonly zoomCursorClassName ?: string ;
39
- readonly transform : number [ ] ;
40
- readonly range : number [ ] ;
41
- readonly getMouseDelta : any ; // func
42
- readonly getScale : any ; // func
43
- readonly bg : {
44
- h : number ;
45
- x : number ;
46
- w : number ;
47
- y : number ;
48
- } ;
49
- readonly edgeClip : boolean ;
50
- readonly onContextMenu ?: any ; // func
51
- readonly onDoubleClick ?: any ; // func
52
57
}
53
58
54
59
class Axis extends React . Component < AxisProps > {
55
60
56
61
public static defaultProps = {
62
+ edgeClip : false ,
57
63
zoomEnabled : false ,
58
64
zoomCursorClassName : "" ,
59
- edgeClip : false ,
60
65
} ;
61
66
62
- private node ;
67
+ private node ?: GenericChartComponent ;
63
68
64
69
public render ( ) {
65
- const { bg, axisZoomCallback, className, zoomCursorClassName, zoomEnabled, getScale, inverted } = this . props ;
66
- const { transform, getMouseDelta, edgeClip } = this . props ;
67
- const { onContextMenu, onDoubleClick } = this . props ;
70
+ const {
71
+ bg, axisZoomCallback, className,
72
+ zoomCursorClassName, zoomEnabled, getScale,
73
+ inverted, transform, getMouseDelta,
74
+ edgeClip, onContextMenu, onDoubleClick,
75
+ } = this . props ;
68
76
69
77
const zoomCapture = zoomEnabled
70
78
? < AxisZoomCapture
@@ -97,12 +105,12 @@ class Axis extends React.Component<AxisProps> {
97
105
) ;
98
106
}
99
107
100
- private readonly saveNode = ( node ) => {
108
+ private readonly saveNode = ( node : GenericChartComponent ) => {
101
109
this . node = node ;
102
110
}
103
111
104
112
private readonly getMoreProps = ( ) => {
105
- return this . node . getMoreProps ( ) ;
113
+ return this . node ! . getMoreProps ( ) ;
106
114
}
107
115
108
116
private readonly renderSVG = ( moreProps ) => {
@@ -118,13 +126,16 @@ class Axis extends React.Component<AxisProps> {
118
126
</ g > ;
119
127
}
120
128
121
- private readonly drawOnCanvas = ( ctx , moreProps ) => {
129
+ private readonly drawOnCanvas = ( ctx : CanvasRenderingContext2D , moreProps ) => {
122
130
const { showDomain, showTicks, transform, range, getScale } = this . props ;
123
131
124
132
ctx . save ( ) ;
125
133
ctx . translate ( transform [ 0 ] , transform [ 1 ] ) ;
126
134
127
- if ( showDomain ) { drawAxisLine ( ctx , this . props , range ) ; }
135
+ if ( showDomain ) {
136
+ drawAxisLine ( ctx , this . props , range ) ;
137
+ }
138
+
128
139
if ( showTicks ) {
129
140
const tickProps = tickHelper ( this . props , getScale ( moreProps ) ) ;
130
141
drawTicks ( ctx , tickProps ) ;
@@ -136,14 +147,25 @@ class Axis extends React.Component<AxisProps> {
136
147
137
148
function tickHelper ( props , scale ) {
138
149
const {
139
- orient, innerTickSize, tickFormat, tickPadding,
140
- tickLabelFill, tickStrokeWidth, tickStrokeDasharray,
141
- fontSize, fontFamily, fontWeight, showTicks, flexTicks,
150
+ orient,
151
+ innerTickSize,
152
+ tickFormat,
153
+ tickPadding,
154
+ tickLabelFill,
155
+ tickStrokeWidth,
156
+ tickStrokeDasharray,
157
+ fontSize,
158
+ fontFamily,
159
+ fontWeight,
160
+ showTicks,
161
+ flexTicks,
142
162
showTickLabel,
143
- } = props ;
144
- const {
145
- ticks : tickArguments , tickValues : tickValuesProp ,
146
- tickStroke, tickStrokeOpacity, tickInterval, tickIntervalFunction,
163
+ ticks : tickArguments ,
164
+ tickValues : tickValuesProp ,
165
+ tickStroke,
166
+ tickStrokeOpacity,
167
+ tickInterval,
168
+ tickIntervalFunction,
147
169
} = props ;
148
170
149
171
let tickValues ;
@@ -172,7 +194,7 @@ function tickHelper(props, scale) {
172
194
173
195
const format = isNotDefined ( tickFormat )
174
196
? baseFormat
175
- : ( d ) => tickFormat ( d ) || "" ;
197
+ : ( d : any ) => tickFormat ( d ) || "" ;
176
198
177
199
const sign = orient === "top" || orient === "left" ? - 1 : 1 ;
178
200
const tickSpacing = Math . max ( innerTickSize , 0 ) + tickPadding ;
@@ -266,9 +288,8 @@ function tickHelper(props, scale) {
266
288
} ;
267
289
}
268
290
269
- function axisLineSVG ( props , range ) {
270
- const { orient, outerTickSize } = props ;
271
- const { domainClassName, fill, stroke, strokeWidth, opacity } = props ;
291
+ function axisLineSVG ( props : AxisProps , range ) {
292
+ const { domainClassName, orient, outerTickSize, fill, stroke, strokeWidth, strokeOpacity } = props ;
272
293
273
294
const sign = orient === "top" || orient === "left" ? - 1 : 1 ;
274
295
@@ -285,22 +306,22 @@ function axisLineSVG(props, range) {
285
306
className = { domainClassName }
286
307
d = { d }
287
308
fill = { fill }
288
- opacity = { opacity }
309
+ opacity = { strokeOpacity }
289
310
stroke = { stroke }
290
311
strokeWidth = { strokeWidth } >
291
312
</ path >
292
313
) ;
293
314
}
294
315
295
- function drawAxisLine ( ctx , props , range ) {
316
+ function drawAxisLine ( ctx : CanvasRenderingContext2D , props : AxisProps , range ) {
296
317
297
- const { orient, outerTickSize, stroke, strokeWidth, opacity } = props ;
318
+ const { orient, outerTickSize, stroke, strokeWidth, strokeOpacity } = props ;
298
319
299
320
const sign = orient === "top" || orient === "left" ? - 1 : 1 ;
300
321
const xAxis = ( orient === "bottom" || orient === "top" ) ;
301
322
302
323
ctx . lineWidth = strokeWidth ;
303
- ctx . strokeStyle = colorToRGBA ( stroke , opacity ) ;
324
+ ctx . strokeStyle = colorToRGBA ( stroke , strokeOpacity ) ;
304
325
305
326
ctx . beginPath ( ) ;
306
327
@@ -409,7 +430,7 @@ function axisTicksSVG(props, scale) {
409
430
) ;
410
431
}
411
432
412
- function drawTicks ( ctx , result ) {
433
+ function drawTicks ( ctx : CanvasRenderingContext2D , result ) {
413
434
414
435
const { tickStroke, tickStrokeOpacity, tickLabelFill } = result ;
415
436
const { textAnchor, fontSize, fontFamily, fontWeight, ticks, showTickLabel } = result ;
@@ -433,19 +454,22 @@ function drawTicks(ctx, result) {
433
454
}
434
455
}
435
456
436
- function drawEachTick ( ctx , tick , result ) {
457
+ function drawEachTick ( ctx : CanvasRenderingContext2D , tick , result ) {
437
458
const { tickStrokeWidth, tickStrokeDasharray } = result ;
438
459
439
460
ctx . beginPath ( ) ;
440
461
441
462
ctx . moveTo ( tick . x1 , tick . y1 ) ;
442
463
ctx . lineTo ( tick . x2 , tick . y2 ) ;
443
464
ctx . lineWidth = tickStrokeWidth ;
444
- ctx . setLineDash ( getStrokeDasharray ( tickStrokeDasharray ) . split ( "," ) ) ;
465
+
466
+ const lineDash = getStrokeDasharray ( tickStrokeDasharray ) . split ( "," ) . map ( ( dash ) => Number ( dash ) ) ;
467
+
468
+ ctx . setLineDash ( lineDash ) ;
445
469
ctx . stroke ( ) ;
446
470
}
447
471
448
- function drawEachTickLabel ( ctx , tick , result ) {
472
+ function drawEachTickLabel ( ctx : CanvasRenderingContext2D , tick , result ) {
449
473
const { canvas_dy, format } = result ;
450
474
451
475
ctx . beginPath ( ) ;
0 commit comments