Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions src/processor/dataSample.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import { StageHandler, SeriesOption, SeriesSamplingOptionMixin } from '../util/t
import { Dictionary } from 'zrender/src/core/types';
import SeriesModel from '../model/Series';
import { isFunction, isString } from 'zrender/src/core/util';
import type SeriesData from '../data/SeriesData';
import type Axis from '../coord/Axis';


type Sampler = (frame: ArrayLike<number>) => number;
Expand Down Expand Up @@ -72,6 +74,17 @@ const indexSampler = function (frame: ArrayLike<number>) {
return Math.round(frame.length / 2);
};

function countDataInAxisExtent(data: SeriesData, baseAxis: Axis, baseDim: string) {
let count = 0;
const scale = baseAxis.scale;
data.each(baseDim, function (value: number) {
if (scale.contain(value)) {
count++;
}
});
return count;
Comment thread
susiwen8 marked this conversation as resolved.
Comment thread
susiwen8 marked this conversation as resolved.
Comment thread
susiwen8 marked this conversation as resolved.
}

export default function dataSample(seriesType: string): StageHandler {
return {

Expand All @@ -86,14 +99,18 @@ export default function dataSample(seriesType: string): StageHandler {
const coordSys = seriesModel.coordinateSystem;
const count = data.count();
// Only cartesian2d support down sampling. Disable it when there is few data.
if (count > 10 && coordSys.type === 'cartesian2d' && sampling) {
if (count > 10 && coordSys.type === 'cartesian2d' && sampling && sampling !== 'none') {
const baseAxis = coordSys.getBaseAxis();
const valueAxis = coordSys.getOtherAxis(baseAxis);
const extent = baseAxis.getExtent();
const dpr = api.getDevicePixelRatio();
// Coordinste system has been resized
const size = Math.abs(extent[1] - extent[0]) * (dpr || 1);
Comment thread
susiwen8 marked this conversation as resolved.
const rate = Math.round(count / size);
if (count <= size) {
return;
}
const dataCount = countDataInAxisExtent(data, baseAxis, data.mapDimension(baseAxis.dim));
const rate = Math.round(dataCount / size);
Comment thread
susiwen8 marked this conversation as resolved.
Comment thread
susiwen8 marked this conversation as resolved.

if (isFinite(rate) && rate > 1) {
if (sampling === 'lttb') {
Expand Down
215 changes: 215 additions & 0 deletions test/line-sampling-dataZoom-filterMode.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.