17
17
* under the License.
18
18
*/
19
19
20
- import { bind , each , isFunction , isString , indexOf } from 'zrender/src/core/util' ;
20
+ import { bind , each , isFunction , isString , indexOf } from 'zrender/src/core/util' ;
21
21
import * as eventTool from 'zrender/src/core/event' ;
22
22
import * as graphic from '../../util/graphic' ;
23
23
import * as throttle from '../../util/throttle' ;
24
24
import DataZoomView from './DataZoomView' ;
25
- import { linearMap , asc , parsePercent } from '../../util/number' ;
25
+ import { linearMap , asc , parsePercent } from '../../util/number' ;
26
26
import * as layout from '../../util/layout' ;
27
27
import sliderMove from '../helper/sliderMove' ;
28
28
import GlobalModel from '../../model/Global' ;
@@ -41,7 +41,7 @@ import { createSymbol, symbolBuildProxies } from '../../util/symbol';
41
41
import { deprecateLog } from '../../util/log' ;
42
42
import { PointLike } from 'zrender/src/core/Point' ;
43
43
import Displayable from 'zrender/src/graphic/Displayable' ;
44
- import { createTextStyle } from '../../label/labelStyle' ;
44
+ import { createTextStyle } from '../../label/labelStyle' ;
45
45
import SeriesData from '../../data/SeriesData' ;
46
46
47
47
const Rect = graphic . Rect ;
@@ -227,7 +227,7 @@ class SliderZoomView extends DataZoomView {
227
227
// If some of x/y/width/height are not specified,
228
228
// auto-adapt according to target grid.
229
229
const coordRect = this . _findCoordRect ( ) ;
230
- const ecSize = { width : api . getWidth ( ) , height : api . getHeight ( ) } ;
230
+ const ecSize = { width : api . getWidth ( ) , height : api . getHeight ( ) } ;
231
231
// Default align by coordinate system rect.
232
232
const positionInfo = this . _orient === HORIZONTAL
233
233
? {
@@ -261,7 +261,7 @@ class SliderZoomView extends DataZoomView {
261
261
ecSize
262
262
) ;
263
263
264
- this . _location = { x : layoutRect . x , y : layoutRect . y } ;
264
+ this . _location = { x : layoutRect . x , y : layoutRect . y } ;
265
265
this . _size = [ layoutRect . width , layoutRect . height ] ;
266
266
this . _orient === VERTICAL && this . _size . reverse ( ) ;
267
267
}
@@ -375,6 +375,7 @@ class SliderZoomView extends DataZoomView {
375
375
data !== this . _shadowData || otherDim !== this . _shadowDim
376
376
|| size [ 0 ] !== oldSize [ 0 ] || size [ 1 ] !== oldSize [ 1 ]
377
377
) {
378
+ const thisDataExtent = data . getDataExtent ( info . thisDim ) ;
378
379
let otherDataExtent = data . getDataExtent ( otherDim ) ;
379
380
// Nice extent.
380
381
const otherOffset = ( otherDataExtent [ 1 ] - otherDataExtent [ 0 ] ) * 0.3 ;
@@ -388,26 +389,35 @@ class SliderZoomView extends DataZoomView {
388
389
const areaPoints = [ [ size [ 0 ] , 0 ] , [ 0 , 0 ] ] ;
389
390
const linePoints : number [ ] [ ] = [ ] ;
390
391
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 ;
392
395
393
396
// Optimize for large data shadow
394
397
const stride = Math . round ( data . count ( ) / size [ 0 ] ) ;
395
398
let lastIsEmpty : boolean ;
396
- data . each ( [ otherDim ] , function ( value : ParsedValue , index ) {
399
+
400
+ data . each ( [ info . thisDim , otherDim ] , function ( thisValue : ParsedValue , otherValue : ParsedValue , index ) {
397
401
if ( stride > 0 && ( index % stride ) ) {
398
- thisCoord += step ;
402
+ if ( ! isTimeAxis ) {
403
+ thisCoord += step ;
404
+ }
399
405
return ;
400
406
}
401
407
408
+ thisCoord = isTimeAxis
409
+ ? ( + thisValue - thisDataExtent [ 0 ] ) * normalizationConstant
410
+ : thisCoord + step ;
411
+
402
412
// FIXME
403
413
// Should consider axis.min/axis.max when drawing dataShadow.
404
414
405
415
// FIXME
406
416
// 应该使用统一的空判断?还是在list里进行空判断?
407
- const isEmpty = value == null || isNaN ( value as number ) || value === '' ;
417
+ const isEmpty = otherValue == null || isNaN ( otherValue as number ) || otherValue === '' ;
408
418
// See #4235.
409
419
const otherCoord = isEmpty
410
- ? 0 : linearMap ( value as number , otherDataExtent , otherShadowExtent , true ) ;
420
+ ? 0 : linearMap ( otherValue as number , otherDataExtent , otherShadowExtent , true ) ;
411
421
412
422
// Attempt to draw data shadow precisely when there are empty value.
413
423
if ( isEmpty && ! lastIsEmpty && index ) {
@@ -422,7 +432,6 @@ class SliderZoomView extends DataZoomView {
422
432
areaPoints . push ( [ thisCoord , otherCoord ] ) ;
423
433
linePoints . push ( [ thisCoord , otherCoord ] ) ;
424
434
425
- thisCoord += step ;
426
435
lastIsEmpty = isEmpty ;
427
436
} ) ;
428
437
@@ -440,14 +449,14 @@ class SliderZoomView extends DataZoomView {
440
449
const model = dataZoomModel . getModel ( isSelectedArea ? 'selectedDataBackground' : 'dataBackground' ) ;
441
450
const group = new graphic . Group ( ) ;
442
451
const polygon = new graphic . Polygon ( {
443
- shape : { points : polygonPts } ,
452
+ shape : { points : polygonPts } ,
444
453
segmentIgnoreThreshold : 1 ,
445
454
style : model . getModel ( 'areaStyle' ) . getAreaStyle ( ) ,
446
455
silent : true ,
447
456
z2 : - 20
448
457
} ) ;
449
458
const polyline = new graphic . Polyline ( {
450
- shape : { points : polylinePts } ,
459
+ shape : { points : polylinePts } ,
451
460
segmentIgnoreThreshold : 1 ,
452
461
style : model . getModel ( 'lineStyle' ) . getLineStyle ( ) ,
453
462
silent : true ,
@@ -489,8 +498,8 @@ class SliderZoomView extends DataZoomView {
489
498
}
490
499
491
500
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
494
503
) {
495
504
return ;
496
505
}
@@ -675,8 +684,8 @@ class SliderZoomView extends DataZoomView {
675
684
} ) ;
676
685
677
686
actualMoveZone . on ( 'mouseover' , ( ) => {
678
- api . enterEmphasis ( moveHandle ) ;
679
- } )
687
+ api . enterEmphasis ( moveHandle ) ;
688
+ } )
680
689
. on ( 'mouseout' , ( ) => {
681
690
api . leaveEmphasis ( moveHandle ) ;
682
691
} ) ;
@@ -882,8 +891,8 @@ class SliderZoomView extends DataZoomView {
882
891
return isFunction ( labelFormatter )
883
892
? labelFormatter ( value as number , valueStr )
884
893
: isString ( labelFormatter )
885
- ? labelFormatter . replace ( '{value}' , valueStr )
886
- : valueStr ;
894
+ ? labelFormatter . replace ( '{value}' , valueStr )
895
+ : valueStr ;
887
896
}
888
897
889
898
/**
@@ -1103,7 +1112,7 @@ class SliderZoomView extends DataZoomView {
1103
1112
function getOtherDim ( thisDim : 'x' | 'y' | 'radius' | 'angle' | 'single' | 'z' ) {
1104
1113
// FIXME
1105
1114
// 这个逻辑和getOtherAxis里一致,但是写在这里是否不好
1106
- const map = { x : 'y' , y : 'x' , radius : 'angle' , angle : 'radius' } ;
1115
+ const map = { x : 'y' , y : 'x' , radius : 'angle' , angle : 'radius' } ;
1107
1116
return map [ thisDim as 'x' | 'y' | 'radius' | 'angle' ] ;
1108
1117
}
1109
1118
0 commit comments