Skip to content

Commit b44ead2

Browse files
authored
Merge pull request #4123 from VisActor/feat/scrollbar-autovisible
feat: scrollbar support auto visible. close #3972
2 parents 62be29c + 59af96f commit b44ead2

File tree

3 files changed

+44
-12
lines changed

3 files changed

+44
-12
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@visactor/vchart",
5+
"comment": "feat: scrollbar support auto visible. close #3972",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@visactor/vchart"
10+
}

packages/vchart/src/component/data-zoom/data-filter-base-component.ts

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ import {
2828
minInArray,
2929
maxInArray,
3030
abs,
31-
last
31+
last,
32+
throttle
3233
} from '@visactor/vutils';
3334
// eslint-disable-next-line no-duplicate-imports
3435
import type { IFilterMode } from './interface';
@@ -64,6 +65,8 @@ export abstract class DataFilterBaseComponent<T extends IDataFilterComponentSpec
6465
protected _orient: IOrientType = 'left';
6566
protected _isHorizontal: boolean;
6667

68+
protected _throttledHide: () => void;
69+
6770
// 是否为自动模式
6871
protected _auto?: boolean;
6972
protected _fixedBandSize?: number;
@@ -448,25 +451,25 @@ export abstract class DataFilterBaseComponent<T extends IDataFilterComponentSpec
448451
s.coordinate === 'cartesian'
449452
? (s as ICartesianSeries).getXAxisHelper()
450453
: s.coordinate === 'polar'
451-
? (s as IPolarSeries).angleAxisHelper
452-
: null;
454+
? (s as IPolarSeries).angleAxisHelper
455+
: null;
453456
const yAxisHelper =
454457
s.coordinate === 'cartesian'
455458
? (s as ICartesianSeries).getYAxisHelper()
456459
: s.coordinate === 'polar'
457-
? (s as IPolarSeries).radiusAxisHelper
458-
: null;
460+
? (s as IPolarSeries).radiusAxisHelper
461+
: null;
459462
if (!xAxisHelper || !yAxisHelper) {
460463
return;
461464
}
462465
const stateAxisHelper =
463466
xAxisHelper.getAxisId() === this._relatedAxisComponent.id
464467
? xAxisHelper
465468
: yAxisHelper.getAxisId() === this._relatedAxisComponent.id
466-
? yAxisHelper
467-
: this._isHorizontal
468-
? xAxisHelper
469-
: yAxisHelper;
469+
? yAxisHelper
470+
: this._isHorizontal
471+
? xAxisHelper
472+
: yAxisHelper;
470473
const valueAxisHelper = stateAxisHelper === xAxisHelper ? yAxisHelper : xAxisHelper;
471474

472475
dataCollection.push(s.getRawData());
@@ -642,8 +645,8 @@ export abstract class DataFilterBaseComponent<T extends IDataFilterComponentSpec
642645
start = this._spec.start
643646
? this._spec.start
644647
: this._spec.startValue
645-
? this.dataToStatePoint(this._spec.startValue)
646-
: 0;
648+
? this.dataToStatePoint(this._spec.startValue)
649+
: 0;
647650
end = this._spec.end ? this._spec.end : this._spec.endValue ? this.dataToStatePoint(this._spec.endValue) : 1;
648651
}
649652
this._startValue = this.statePointToData(start);
@@ -862,6 +865,9 @@ export abstract class DataFilterBaseComponent<T extends IDataFilterComponentSpec
862865
if (!this._activeRoam || (this._dragAttr.filter && !this._dragAttr.filter(delta, e))) {
863866
return;
864867
}
868+
if ((this._spec.roamDrag as IRoamDragSpec)?.autoVisible) {
869+
this.show();
870+
}
865871
const [dx, dy] = delta;
866872
let value = this._isHorizontal ? dx : dy;
867873
if (this._dragAttr.reverse) {
@@ -886,7 +892,7 @@ export abstract class DataFilterBaseComponent<T extends IDataFilterComponentSpec
886892

887893
protected _initCommonEvent() {
888894
const delayType: IDelayType = this._spec?.delayType ?? 'throttle';
889-
const delayTime = isValid(this._spec?.delayType) ? this._spec?.delayTime ?? 30 : 0;
895+
const delayTime = isValid(this._spec?.delayType) ? (this._spec?.delayTime ?? 30) : 0;
890896
const realTime = this._spec?.realTime ?? true;
891897
const option = { delayType, delayTime, realTime, allowComponentZoom: true };
892898
if (this._zoomAttr.enable) {
@@ -898,6 +904,13 @@ export abstract class DataFilterBaseComponent<T extends IDataFilterComponentSpec
898904
if (this._dragAttr.enable) {
899905
(this as unknown as IZoomable).initDragEventOfRegions(this._regions, null, this._handleChartDrag, option);
900906
}
907+
if ((this._spec.roamDrag as IRoamDragSpec)?.autoVisible) {
908+
const dragEnd = 'panend';
909+
this._throttledHide = throttle(() => this.hide(), 300);
910+
this.event.on(dragEnd, () => {
911+
this._throttledHide();
912+
});
913+
}
901914
}
902915

903916
updateLayoutAttribute(): void {
@@ -1038,6 +1051,10 @@ export abstract class DataFilterBaseComponent<T extends IDataFilterComponentSpec
10381051
protected _getNeedClearVRenderComponents(): IGraphic[] {
10391052
return [this._component] as unknown as IGroup[];
10401053
}
1054+
1055+
clear(): void {
1056+
this._throttledHide = null;
1057+
}
10411058
}
10421059

10431060
mixin(DataFilterBaseComponent, Zoomable);

packages/vchart/src/component/data-zoom/interface.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,11 @@ export interface IRoamDragSpec extends IRoamSpec {
169169
* @returns
170170
*/
171171
filter?: (delta: [number, number], e?: BaseEventParams['event']) => boolean;
172+
/**
173+
* 仅在画布交互展示组件
174+
* @since 2.0.3
175+
*/
176+
autoVisible?: boolean;
172177
}
173178

174179
export interface IRoamScrollSpec extends IRoamSpec {

0 commit comments

Comments
 (0)