diff --git a/src/index.ts b/src/index.ts index 18cd01e..0c650cc 100644 --- a/src/index.ts +++ b/src/index.ts @@ -82,6 +82,7 @@ const DEFAULT_OPTIONS: Options = { keyEvent: KeyEvent.SHIFT, panStep: DEFAULT_SCROLL_PAN_STEP, orientation: ScrollPanOrientation.HORIZONTAL, + direction: ScrollPanDirection.BOTH, }, }, }, @@ -608,11 +609,25 @@ abstract class ChartwerkPod { .text('No data points'); } + private disableScrollForward(event: any): boolean { + return event.sourceEvent.wheelDelta > 0 + && this.options.zoomEvents.scroll.pan.direction === ScrollPanDirection.FORWARD; + } + + private disableScrollBackward(event: any): boolean { + return event.sourceEvent.wheelDelta < 0 + && this.options.zoomEvents.scroll.pan.direction === ScrollPanDirection.BACKWARD; + } + protected onPanning(): void { const event = this.d3.event; if(event.sourceEvent === null || event.sourceEvent === undefined) { return; } + if (event.sourceEvent.type === 'wheel' + && (this.disableScrollBackward(event) || this.disableScrollForward(event))) { + return; + } this.rescaleMetricAndAxis(event); if(this.options.eventsCallbacks !== undefined && this.options.eventsCallbacks.panning !== undefined) { diff --git a/src/types.ts b/src/types.ts index 150bd74..17ec8a6 100644 --- a/src/types.ts +++ b/src/types.ts @@ -85,6 +85,7 @@ export type Options = { keyEvent?: KeyEvent; panStep?: number; orientation?: ScrollPanOrientation; + direction?: ScrollPanDirection; }, }, } @@ -140,6 +141,11 @@ export enum ScrollPanOrientation { VERTICAL = 'vertical', HORIZONTAL = 'horizontal', } +export enum ScrollPanDirection { + FORWARD = 'forward', + BACKWARD = 'backward', + BOTH = 'both', +} export enum AxisFormat { TIME = 'time', NUMERIC = 'numeric', @@ -177,4 +183,4 @@ export type SvgElParams = { width: number, xScale: d3.ScaleLinear, yScale: d3.ScaleLinear, -} +} \ No newline at end of file