1919
2020import { bind , each , isFunction , isString , indexOf } from 'zrender/src/core/util' ;
2121import * as eventTool from 'zrender/src/core/event' ;
22+ import { Dictionary } from 'zrender/src/core/types' ;
2223import * as graphic from '../../util/graphic' ;
2324import * as throttle from '../../util/throttle' ;
2425import DataZoomView from './DataZoomView' ;
@@ -43,6 +44,7 @@ import { PointLike } from 'zrender/src/core/Point';
4344import Displayable from 'zrender/src/graphic/Displayable' ;
4445import { createTextStyle } from '../../label/labelStyle' ;
4546import SeriesData from '../../data/SeriesData' ;
47+ import { doDataSampling } from '../../processor/dataSample' ;
4648
4749const Rect = graphic . Rect ;
4850
@@ -384,91 +386,75 @@ class SliderZoomView extends DataZoomView {
384386 ] ;
385387 const otherShadowExtent = [ 0 , size [ 1 ] ] ;
386388 const thisShadowExtent = [ 0 , size [ 0 ] ] ;
389+
390+ const areaPoints = [ [ size [ 0 ] , 0 ] , [ 0 , 0 ] ] ;
391+ const linePoints : number [ ] [ ] = [ ] ;
392+
387393 let lastIsEmpty : boolean ;
388394
389395 // Optimize for large data shadow
390396 const stride = Math . round ( data . count ( ) / size [ 0 ] ) ;
391397 const coordSys = seriesModel . coordinateSystem ;
392398 const sampling = this . dataZoomModel . get ( 'sampling' ) ;
393- if ( data . count ( ) > 10 && coordSys . type === 'cartesian2d' && ( sampling && sampling !== 'none' ) ) {
394- const baseAxis = coordSys . getBaseAxis ( ) ;
395- const valueAxis = coordSys . getOtherAxis ( baseAxis ) ;
399+ let sampledData = data ;
396400
397- let downsampled = data ;
398- if ( sampling === 'lttb' ) {
399- downsampled = data . lttbDownSample ( data . mapDimension ( valueAxis . dim ) , 1 / stride ) ;
401+ let useOldSampling = true ;
402+ if ( data . count ( ) > 10 && coordSys . type === 'cartesian2d' && ( sampling && sampling !== 'none' ) ) {
403+ const downsampled = doDataSampling (
404+ data ,
405+ sampling ,
406+ seriesModel . coordinateSystem ,
407+ this . api . getDevicePixelRatio ( )
408+ ) ;
409+ if ( downsampled ) {
410+ useOldSampling = false ;
411+ sampledData = downsampled ;
400412 }
401- // TODO: 支持其他类型的 sampling
402-
403- const lp = [ [ size [ 0 ] , 0 ] , [ 0 , 0 ] ] ;
404- const ap : number [ ] [ ] = [ ] ;
405- downsampled . each ( [ otherDim ] , function ( value : ParsedValue , index ) {
406- const isEmpty = value == null || isNaN ( value as number ) || value === '' ;
407- // See #4235.
408- const otherCoord = isEmpty
409- ? 0 : linearMap ( value as number , otherDataExtent , otherShadowExtent , true ) ;
410-
411- // Attempt to draw data shadow precisely when there are empty value.
412- if ( isEmpty && ! lastIsEmpty && index ) {
413- ap . push ( [ ap [ ap . length - 1 ] [ 0 ] , 0 ] ) ;
414- lp . push ( [ lp [ lp . length - 1 ] [ 0 ] , 0 ] ) ;
415- }
416- else if ( ! isEmpty && lastIsEmpty ) {
417- ap . push ( [ index , 0 ] ) ;
418- lp . push ( [ index , 0 ] ) ;
419- }
420-
421- ap . push ( [ index , otherCoord ] ) ;
422- lp . push ( [ index , otherCoord ] ) ;
423-
424- lastIsEmpty = isEmpty ;
425- } ) ;
426-
427- polygonPts = this . _shadowPolygonPts = ap ;
428- polylinePts = this . _shadowPolylinePts = lp ;
429413 }
430- else {
431- const areaPoints = [ [ size [ 0 ] , 0 ] , [ 0 , 0 ] ] ;
432- const linePoints : number [ ] [ ] = [ ] ;
433- const step = thisShadowExtent [ 1 ] / ( data . count ( ) - 1 ) ;
434- let thisCoord = 0 ;
435414
436- data . each ( [ otherDim ] , function ( value : ParsedValue , index ) {
415+ const step = thisShadowExtent [ 1 ] / ( data . count ( ) - 1 ) ;
416+ let thisCoord = 0 ;
417+
418+ sampledData . each ( [ otherDim ] , function ( value : ParsedValue , index ) {
419+ if ( useOldSampling ) {
437420 if ( stride > 0 && ( index % stride ) ) {
438421 thisCoord += step ;
439422 return ;
440423 }
424+ }
425+ else {
426+ thisCoord = index ;
427+ }
441428
442- // FIXME
443- // Should consider axis.min/axis.max when drawing dataShadow.
429+ // FIXME
430+ // Should consider axis.min/axis.max when drawing dataShadow.
444431
445- // FIXME
446- // 应该使用统一的空判断?还是在list里进行空判断?
447- const isEmpty = value == null || isNaN ( value as number ) || value === '' ;
448- // See #4235.
449- const otherCoord = isEmpty
450- ? 0 : linearMap ( value as number , otherDataExtent , otherShadowExtent , true ) ;
432+ // FIXME
433+ // 应该使用统一的空判断?还是在list里进行空判断?
434+ const isEmpty = value == null || isNaN ( value as number ) || value === '' ;
435+ // See #4235.
436+ const otherCoord = isEmpty
437+ ? 0 : linearMap ( value as number , otherDataExtent , otherShadowExtent , true ) ;
451438
452- // Attempt to draw data shadow precisely when there are empty value.
453- if ( isEmpty && ! lastIsEmpty && index ) {
454- areaPoints . push ( [ areaPoints [ areaPoints . length - 1 ] [ 0 ] , 0 ] ) ;
455- linePoints . push ( [ linePoints [ linePoints . length - 1 ] [ 0 ] , 0 ] ) ;
456- }
457- else if ( ! isEmpty && lastIsEmpty ) {
458- areaPoints . push ( [ thisCoord , 0 ] ) ;
459- linePoints . push ( [ thisCoord , 0 ] ) ;
460- }
439+ // Attempt to draw data shadow precisely when there are empty value.
440+ if ( isEmpty && ! lastIsEmpty && index ) {
441+ areaPoints . push ( [ areaPoints [ areaPoints . length - 1 ] [ 0 ] , 0 ] ) ;
442+ linePoints . push ( [ linePoints [ linePoints . length - 1 ] [ 0 ] , 0 ] ) ;
443+ }
444+ else if ( ! isEmpty && lastIsEmpty ) {
445+ areaPoints . push ( [ thisCoord , 0 ] ) ;
446+ linePoints . push ( [ thisCoord , 0 ] ) ;
447+ }
461448
462- areaPoints . push ( [ thisCoord , otherCoord ] ) ;
463- linePoints . push ( [ thisCoord , otherCoord ] ) ;
449+ areaPoints . push ( [ thisCoord , otherCoord ] ) ;
450+ linePoints . push ( [ thisCoord , otherCoord ] ) ;
464451
465- thisCoord += step ;
466- lastIsEmpty = isEmpty ;
467- } ) ;
452+ thisCoord += step ;
453+ lastIsEmpty = isEmpty ;
454+ } ) ;
468455
469- polygonPts = this . _shadowPolygonPts = areaPoints ;
470- polylinePts = this . _shadowPolylinePts = linePoints ;
471- }
456+ polygonPts = this . _shadowPolygonPts = areaPoints ;
457+ polylinePts = this . _shadowPolylinePts = linePoints ;
472458
473459 }
474460 this . _shadowData = data ;
0 commit comments