@@ -20,7 +20,10 @@ import * as $eval from './helpers/eval'
2020
2121require ( './polyfills' )
2222
23- const d3Scale = { linear : d3ScaleLinear , log : d3ScaleLog }
23+ const d3Scale : {
24+ linear : ( ) => ScaleLinear < number , number > ,
25+ log : ( ) => ScaleLogarithmic < number , number >
26+ } = { linear : d3ScaleLinear , log : d3ScaleLog }
2427
2528interface ChartMetaMargin {
2629 left ?: number
@@ -45,8 +48,8 @@ export interface ChartMeta {
4548 */
4649 height ?: number
4750 zoomBehavior ?: any
48- xScale ?: ScaleLinear < number , number > // | ScaleLogarithmic<number, number>
49- yScale ?: ScaleLinear < number , number > // | ScaleLogarithmic<number, number>
51+ xScale ?: ScaleLinear < number , number > | ScaleLogarithmic < number , number >
52+ yScale ?: ScaleLinear < number , number > | ScaleLogarithmic < number , number >
5053 xAxis ?: Axis < any >
5154 yAxis ?: Axis < any >
5255 xDomain ?: number [ ]
@@ -190,7 +193,7 @@ export class Chart extends EventEmitter.EventEmitter {
190193
191194 const integerFormat = d3Format ( '~s' )
192195 const floatFormat = d3Format ( '~e' )
193- function formatter ( d : number ) : string {
196+ function formatter ( d : number ) : string {
194197 // take only the decimal part of the number
195198 const frac = Math . abs ( d ) - Math . floor ( Math . abs ( d ) )
196199 if ( frac > 0 ) {
@@ -200,7 +203,7 @@ export class Chart extends EventEmitter.EventEmitter {
200203 }
201204 }
202205
203- function computeYScale ( xScale : number [ ] ) {
206+ function computeYScale ( xScale : number [ ] ) {
204207 // assumes that xScale is a linear scale
205208 const xDiff = xScale [ 1 ] - xScale [ 0 ]
206209 return self . meta . height * xDiff / self . meta . width
@@ -243,13 +246,15 @@ export class Chart extends EventEmitter.EventEmitter {
243246 }
244247 this . meta . xScale
245248 . domain ( xDomain )
249+ // @ts -ignore domain always returns typeof this.meta.xDomain
246250 . range ( this . options . xAxis . invert ? [ this . meta . width , 0 ] : [ 0 , this . meta . width ] )
247251
248252 if ( ! this . meta . yScale ) {
249253 this . meta . yScale = d3Scale [ this . options . yAxis . type ] ( )
250254 }
251255 this . meta . yScale
252256 . domain ( yDomain )
257+ // @ts -ignore domain always returns typeof this.meta.yDomain
253258 . range ( this . options . yAxis . invert ? [ 0 , this . meta . height ] : [ this . meta . height , 0 ] )
254259
255260 if ( ! this . meta . xAxis ) {
@@ -270,7 +275,7 @@ export class Chart extends EventEmitter.EventEmitter {
270275 . y ( function ( d ) { return self . meta . yScale ( d [ 1 ] ) } )
271276 }
272277
273- drawGraphWrapper ( ) {
278+ drawGraphWrapper ( ) {
274279 const root = this . root = d3Select ( this . options . target as any )
275280 . selectAll ( 'svg' )
276281 . data ( [ this . options ] )
@@ -293,16 +298,18 @@ export class Chart extends EventEmitter.EventEmitter {
293298 this . buildAxis ( )
294299 this . buildAxisLabel ( )
295300
296- // draw each datum after the wrapper was set up
297- this . draw ( )
298-
299301 // helper to detect the closest fn to the cursor's current abscissa
300302 const tip = this . tip = mousetip ( Object . assign ( this . options . tip || { } , { owner : this } ) )
301303 this . canvas . merge ( this . canvas . enter )
302304 . call ( tip )
303305
304- this . buildZoomHelper ( )
305306 this . setUpPlugins ( )
307+
308+ // draw each datum after the wrapper and plugins were set up
309+ this . draw ( )
310+
311+ // zoom helper on top
312+ this . buildZoomHelper ( )
306313 }
307314
308315 buildTitle ( ) {
@@ -538,7 +545,7 @@ export class Chart extends EventEmitter.EventEmitter {
538545
539546 if ( ! this . meta . zoomBehavior ) {
540547 this . meta . zoomBehavior = d3Zoom ( )
541- . on ( 'zoom' , function onZoom ( ev ) {
548+ . on ( 'zoom' , function onZoom ( ev ) {
542549 self . getEmitInstance ( ) . emit ( 'all:zoom' , ev )
543550 } )
544551 // the zoom behavior must work with a copy of the scale, the zoom behavior has its own state and assumes
@@ -645,7 +652,7 @@ export class Chart extends EventEmitter.EventEmitter {
645652 }
646653
647654 const events = {
648- mousemove : function ( coordinates : { x : number , y : number } ) {
655+ mousemove : function ( coordinates : { x : number , y : number } ) {
649656 self . tip . move ( coordinates )
650657 } ,
651658
@@ -657,7 +664,7 @@ export class Chart extends EventEmitter.EventEmitter {
657664 self . tip . hide ( )
658665 } ,
659666
660- zoom : function zoom ( { transform } : any ) {
667+ zoom : function zoom ( { transform } : any ) {
661668 // disable zoom
662669 if ( self . options . disableZoom ) return
663670
@@ -668,9 +675,11 @@ export class Chart extends EventEmitter.EventEmitter {
668675 // NOTE: setting self.meta.xScale = self.meta.zoomBehavior.xScale creates artifacts and weird lines
669676 self . meta . xScale
670677 . domain ( xScaleClone . domain ( ) )
678+ // @ts -ignore domain always returns typeof this.meta.yDomain
671679 . range ( xScaleClone . range ( ) )
672680 self . meta . yScale
673681 . domain ( yScaleClone . domain ( ) )
682+ // @ts -ignore domain always returns typeof this.meta.yDomain
674683 . range ( yScaleClone . range ( ) )
675684 } ,
676685
@@ -746,7 +755,7 @@ export class Chart extends EventEmitter.EventEmitter {
746755 }
747756}
748757
749- function functionPlot ( options : FunctionPlotOptions = { target : null } ) {
758+ function functionPlot ( options : FunctionPlotOptions = { target : null } ) {
750759 options . data = options . data || [ ]
751760 let instance = Chart . cache [ options . id ]
752761 if ( ! instance ) {
0 commit comments