Skip to content

Commit 76d1816

Browse files
committed
feat(sampling-in-dataZoom): initial commit
1 parent f27b086 commit 76d1816

File tree

3 files changed

+195
-41
lines changed

3 files changed

+195
-41
lines changed

src/component/dataZoom/SliderZoomModel.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,15 @@ import {
2424
LineStyleOption,
2525
AreaStyleOption,
2626
ItemStyleOption,
27-
LabelOption
27+
LabelOption,
28+
SeriesSamplingOptionMixin
2829
} from '../../util/types';
2930
import { inheritDefaultOption } from '../../util/component';
3031

31-
export interface SliderDataZoomOption extends DataZoomOption, BoxLayoutOptionMixin {
32+
export interface SliderDataZoomOption extends
33+
DataZoomOption,
34+
BoxLayoutOptionMixin,
35+
SeriesSamplingOptionMixin {
3236

3337
show?: boolean
3438
/**
@@ -207,8 +211,10 @@ class SliderZoomModel extends DataZoomModel<SliderDataZoomOption> {
207211
moveHandleStyle: {
208212
color: '#8FB0F7'
209213
}
210-
}
214+
},
215+
216+
sampling: 'none'
211217
} as SliderDataZoomOption);
212218
}
213219

214-
export default SliderZoomModel;
220+
export default SliderZoomModel;

src/component/dataZoom/SliderZoomView.ts

Lines changed: 78 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -384,50 +384,91 @@ class SliderZoomView extends DataZoomView {
384384
];
385385
const otherShadowExtent = [0, size[1]];
386386
const thisShadowExtent = [0, size[0]];
387-
388-
const areaPoints = [[size[0], 0], [0, 0]];
389-
const linePoints: number[][] = [];
390-
const step = thisShadowExtent[1] / (data.count() - 1);
391-
let thisCoord = 0;
387+
let lastIsEmpty: boolean;
392388

393389
// Optimize for large data shadow
394390
const stride = Math.round(data.count() / size[0]);
395-
let lastIsEmpty: boolean;
396-
data.each([otherDim], function (value: ParsedValue, index) {
397-
if (stride > 0 && (index % stride)) {
398-
thisCoord += step;
399-
return;
400-
}
401-
402-
// FIXME
403-
// Should consider axis.min/axis.max when drawing dataShadow.
404-
405-
// FIXME
406-
// 应该使用统一的空判断?还是在list里进行空判断?
407-
const isEmpty = value == null || isNaN(value as number) || value === '';
408-
// See #4235.
409-
const otherCoord = isEmpty
410-
? 0 : linearMap(value as number, otherDataExtent, otherShadowExtent, true);
411-
412-
// Attempt to draw data shadow precisely when there are empty value.
413-
if (isEmpty && !lastIsEmpty && index) {
414-
areaPoints.push([areaPoints[areaPoints.length - 1][0], 0]);
415-
linePoints.push([linePoints[linePoints.length - 1][0], 0]);
416-
}
417-
else if (!isEmpty && lastIsEmpty) {
418-
areaPoints.push([thisCoord, 0]);
419-
linePoints.push([thisCoord, 0]);
391+
const coordSys = seriesModel.coordinateSystem;
392+
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);
396+
397+
let downsampled = data;
398+
if (sampling === 'lttb') {
399+
downsampled = data.lttbDownSample(data.mapDimension(valueAxis.dim), 1 / stride);
420400
}
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+
});
421426

422-
areaPoints.push([thisCoord, otherCoord]);
423-
linePoints.push([thisCoord, otherCoord]);
427+
polygonPts = this._shadowPolygonPts = ap;
428+
polylinePts = this._shadowPolylinePts = lp;
429+
}
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;
435+
436+
data.each([otherDim], function (value: ParsedValue, index) {
437+
if (stride > 0 && (index % stride)) {
438+
thisCoord += step;
439+
return;
440+
}
441+
442+
// FIXME
443+
// Should consider axis.min/axis.max when drawing dataShadow.
444+
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);
451+
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+
}
461+
462+
areaPoints.push([thisCoord, otherCoord]);
463+
linePoints.push([thisCoord, otherCoord]);
424464

425-
thisCoord += step;
426-
lastIsEmpty = isEmpty;
427-
});
465+
thisCoord += step;
466+
lastIsEmpty = isEmpty;
467+
});
428468

429-
polygonPts = this._shadowPolygonPts = areaPoints;
430-
polylinePts = this._shadowPolylinePts = linePoints;
469+
polygonPts = this._shadowPolygonPts = areaPoints;
470+
polylinePts = this._shadowPolylinePts = linePoints;
471+
}
431472

432473
}
433474
this._shadowData = data;

test/dataZoom-sampling.html

Lines changed: 107 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)