Browse Source

added scroll direction option

merge-requests/13/head
dv4mp1r3 3 years ago
parent
commit
1ca60e3e3e
  1. 15
      src/index.ts
  2. 8
      src/types.ts

15
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<T extends TimeSerie, O extends Options> {
.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) {

8
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<number, number>,
yScale: d3.ScaleLinear<number, number>,
}
}
Loading…
Cancel
Save