1717* under the License.
1818*/
1919
20- import { bind , each , isFunction , isString , indexOf } from 'zrender/src/core/util' ;
20+ import { bind , each , isFunction , isString , indexOf } from 'zrender/src/core/util' ;
2121import * as eventTool from 'zrender/src/core/event' ;
2222import * as graphic from '../../util/graphic' ;
2323import * as throttle from '../../util/throttle' ;
2424import DataZoomView from './DataZoomView' ;
25- import { linearMap , asc , parsePercent } from '../../util/number' ;
25+ import { linearMap , asc , parsePercent } from '../../util/number' ;
2626import * as layout from '../../util/layout' ;
2727import sliderMove from '../helper/sliderMove' ;
2828import GlobalModel from '../../model/Global' ;
@@ -41,7 +41,7 @@ import { createSymbol, symbolBuildProxies } from '../../util/symbol';
4141import { deprecateLog } from '../../util/log' ;
4242import { PointLike } from 'zrender/src/core/Point' ;
4343import Displayable from 'zrender/src/graphic/Displayable' ;
44- import { createTextStyle } from '../../label/labelStyle' ;
44+ import { createTextStyle } from '../../label/labelStyle' ;
4545import SeriesData from '../../data/SeriesData' ;
4646
4747const Rect = graphic . Rect ;
@@ -227,7 +227,7 @@ class SliderZoomView extends DataZoomView {
227227 // If some of x/y/width/height are not specified,
228228 // auto-adapt according to target grid.
229229 const coordRect = this . _findCoordRect ( ) ;
230- const ecSize = { width : api . getWidth ( ) , height : api . getHeight ( ) } ;
230+ const ecSize = { width : api . getWidth ( ) , height : api . getHeight ( ) } ;
231231 // Default align by coordinate system rect.
232232 const positionInfo = this . _orient === HORIZONTAL
233233 ? {
@@ -261,7 +261,7 @@ class SliderZoomView extends DataZoomView {
261261 ecSize
262262 ) ;
263263
264- this . _location = { x : layoutRect . x , y : layoutRect . y } ;
264+ this . _location = { x : layoutRect . x , y : layoutRect . y } ;
265265 this . _size = [ layoutRect . width , layoutRect . height ] ;
266266 this . _orient === VERTICAL && this . _size . reverse ( ) ;
267267 }
@@ -375,6 +375,7 @@ class SliderZoomView extends DataZoomView {
375375 data !== this . _shadowData || otherDim !== this . _shadowDim
376376 || size [ 0 ] !== oldSize [ 0 ] || size [ 1 ] !== oldSize [ 1 ]
377377 ) {
378+ const thisDataExtent = data . getDataExtent ( info . thisDim ) ;
378379 let otherDataExtent = data . getDataExtent ( otherDim ) ;
379380 // Nice extent.
380381 const otherOffset = ( otherDataExtent [ 1 ] - otherDataExtent [ 0 ] ) * 0.3 ;
@@ -388,26 +389,35 @@ class SliderZoomView extends DataZoomView {
388389 const areaPoints = [ [ size [ 0 ] , 0 ] , [ 0 , 0 ] ] ;
389390 const linePoints : number [ ] [ ] = [ ] ;
390391 const step = thisShadowExtent [ 1 ] / ( data . count ( ) - 1 ) ;
391- let thisCoord = 0 ;
392+ const normalizationConstant = size [ 0 ] / ( thisDataExtent [ 1 ] - thisDataExtent [ 0 ] ) ;
393+ const isTimeAxis = info . thisAxis . type === 'time' ;
394+ let thisCoord = - step ;
392395
393396 // Optimize for large data shadow
394397 const stride = Math . round ( data . count ( ) / size [ 0 ] ) ;
395398 let lastIsEmpty : boolean ;
396- data . each ( [ otherDim ] , function ( value : ParsedValue , index ) {
399+
400+ data . each ( [ info . thisDim , otherDim ] , function ( thisValue : ParsedValue , otherValue : ParsedValue , index ) {
397401 if ( stride > 0 && ( index % stride ) ) {
398- thisCoord += step ;
402+ if ( ! isTimeAxis ) {
403+ thisCoord += step ;
404+ }
399405 return ;
400406 }
401407
408+ thisCoord = isTimeAxis
409+ ? ( + thisValue - thisDataExtent [ 0 ] ) * normalizationConstant
410+ : thisCoord + step ;
411+
402412 // FIXME
403413 // Should consider axis.min/axis.max when drawing dataShadow.
404414
405415 // FIXME
406416 // 应该使用统一的空判断?还是在list里进行空判断?
407- const isEmpty = value == null || isNaN ( value as number ) || value === '' ;
417+ const isEmpty = otherValue == null || isNaN ( otherValue as number ) || otherValue === '' ;
408418 // See #4235.
409419 const otherCoord = isEmpty
410- ? 0 : linearMap ( value as number , otherDataExtent , otherShadowExtent , true ) ;
420+ ? 0 : linearMap ( otherValue as number , otherDataExtent , otherShadowExtent , true ) ;
411421
412422 // Attempt to draw data shadow precisely when there are empty value.
413423 if ( isEmpty && ! lastIsEmpty && index ) {
@@ -422,7 +432,6 @@ class SliderZoomView extends DataZoomView {
422432 areaPoints . push ( [ thisCoord , otherCoord ] ) ;
423433 linePoints . push ( [ thisCoord , otherCoord ] ) ;
424434
425- thisCoord += step ;
426435 lastIsEmpty = isEmpty ;
427436 } ) ;
428437
@@ -440,14 +449,14 @@ class SliderZoomView extends DataZoomView {
440449 const model = dataZoomModel . getModel ( isSelectedArea ? 'selectedDataBackground' : 'dataBackground' ) ;
441450 const group = new graphic . Group ( ) ;
442451 const polygon = new graphic . Polygon ( {
443- shape : { points : polygonPts } ,
452+ shape : { points : polygonPts } ,
444453 segmentIgnoreThreshold : 1 ,
445454 style : model . getModel ( 'areaStyle' ) . getAreaStyle ( ) ,
446455 silent : true ,
447456 z2 : - 20
448457 } ) ;
449458 const polyline = new graphic . Polyline ( {
450- shape : { points : polylinePts } ,
459+ shape : { points : polylinePts } ,
451460 segmentIgnoreThreshold : 1 ,
452461 style : model . getModel ( 'lineStyle' ) . getLineStyle ( ) ,
453462 silent : true ,
@@ -489,8 +498,8 @@ class SliderZoomView extends DataZoomView {
489498 }
490499
491500 if ( showDataShadow !== true && indexOf (
492- SHOW_DATA_SHADOW_SERIES_TYPE , seriesModel . get ( 'type' )
493- ) < 0
501+ SHOW_DATA_SHADOW_SERIES_TYPE , seriesModel . get ( 'type' )
502+ ) < 0
494503 ) {
495504 return ;
496505 }
@@ -675,8 +684,8 @@ class SliderZoomView extends DataZoomView {
675684 } ) ;
676685
677686 actualMoveZone . on ( 'mouseover' , ( ) => {
678- api . enterEmphasis ( moveHandle ) ;
679- } )
687+ api . enterEmphasis ( moveHandle ) ;
688+ } )
680689 . on ( 'mouseout' , ( ) => {
681690 api . leaveEmphasis ( moveHandle ) ;
682691 } ) ;
@@ -882,8 +891,8 @@ class SliderZoomView extends DataZoomView {
882891 return isFunction ( labelFormatter )
883892 ? labelFormatter ( value as number , valueStr )
884893 : isString ( labelFormatter )
885- ? labelFormatter . replace ( '{value}' , valueStr )
886- : valueStr ;
894+ ? labelFormatter . replace ( '{value}' , valueStr )
895+ : valueStr ;
887896 }
888897
889898 /**
@@ -1103,7 +1112,7 @@ class SliderZoomView extends DataZoomView {
11031112function getOtherDim ( thisDim : 'x' | 'y' | 'radius' | 'angle' | 'single' | 'z' ) {
11041113 // FIXME
11051114 // 这个逻辑和getOtherAxis里一致,但是写在这里是否不好
1106- const map = { x : 'y' , y : 'x' , radius : 'angle' , angle : 'radius' } ;
1115+ const map = { x : 'y' , y : 'x' , radius : 'angle' , angle : 'radius' } ;
11071116 return map [ thisDim as 'x' | 'y' | 'radius' | 'angle' ] ;
11081117}
11091118
0 commit comments