Browse Source

Merge branch 'scroll-direction-option' into 'main'

Scroll direction option

See merge request chartwerk/core!13
merge-requests/14/head
rozetko 3 years ago
parent
commit
e8c07388b0
  1. 6
      dist/index.d.ts
  2. 2
      dist/index.js
  3. 6
      dist/types.d.ts
  4. 18
      src/index.ts
  5. 6
      src/types.ts

6
dist/index.d.ts vendored

@ -2,7 +2,7 @@
import VueChartwerkPodMixin from './VueChartwerkPodMixin'; import VueChartwerkPodMixin from './VueChartwerkPodMixin';
import { PodState } from './state'; import { PodState } from './state';
import { Grid } from './components/grid'; import { Grid } from './components/grid';
import { Margin, TimeSerie, Options, TickOrientation, TimeFormat, BrushOrientation, AxisFormat, CrosshairOrientation, SvgElementAttributes, KeyEvent, PanOrientation, yAxisOrientation, ScrollPanOrientation, AxisOption } from './types'; import { Margin, TimeSerie, Options, TickOrientation, TimeFormat, BrushOrientation, AxisFormat, CrosshairOrientation, SvgElementAttributes, KeyEvent, PanOrientation, yAxisOrientation, ScrollPanOrientation, ScrollPanDirection, AxisOption } from './types';
import { palette } from './colors'; import { palette } from './colors';
import * as d3 from 'd3'; import * as d3 from 'd3';
declare abstract class ChartwerkPod<T extends TimeSerie, O extends Options> { declare abstract class ChartwerkPod<T extends TimeSerie, O extends Options> {
@ -72,6 +72,8 @@ declare abstract class ChartwerkPod<T extends TimeSerie, O extends Options> {
protected renderYLabel(): void; protected renderYLabel(): void;
protected renderXLabel(): void; protected renderXLabel(): void;
protected renderNoDataPointsMessage(): void; protected renderNoDataPointsMessage(): void;
private disableScrollForward;
private disableScrollBackward;
protected onPanning(): void; protected onPanning(): void;
rescaleMetricAndAxis(event: d3.D3ZoomEvent<any, any>): void; rescaleMetricAndAxis(event: d3.D3ZoomEvent<any, any>): void;
protected onPanningRescale(event: d3.D3ZoomEvent<any, any>): void; protected onPanningRescale(event: d3.D3ZoomEvent<any, any>): void;
@ -107,4 +109,4 @@ declare abstract class ChartwerkPod<T extends TimeSerie, O extends Options> {
protected get rectClipId(): string; protected get rectClipId(): string;
isOutOfChart(): boolean; isOutOfChart(): boolean;
} }
export { ChartwerkPod, VueChartwerkPodMixin, Margin, TimeSerie, Options, TickOrientation, TimeFormat, BrushOrientation, PanOrientation, AxisFormat, yAxisOrientation, CrosshairOrientation, ScrollPanOrientation, KeyEvent, palette }; export { ChartwerkPod, VueChartwerkPodMixin, Margin, TimeSerie, Options, TickOrientation, TimeFormat, BrushOrientation, PanOrientation, AxisFormat, yAxisOrientation, CrosshairOrientation, ScrollPanOrientation, ScrollPanDirection, KeyEvent, palette };

2
dist/index.js vendored

File diff suppressed because one or more lines are too long

6
dist/types.d.ts vendored

@ -93,6 +93,7 @@ export declare type Options = {
keyEvent?: KeyEvent; keyEvent?: KeyEvent;
panStep?: number; panStep?: number;
orientation?: ScrollPanOrientation; orientation?: ScrollPanOrientation;
direction?: ScrollPanDirection;
}; };
}; };
}; };
@ -148,6 +149,11 @@ export declare enum ScrollPanOrientation {
VERTICAL = "vertical", VERTICAL = "vertical",
HORIZONTAL = "horizontal" HORIZONTAL = "horizontal"
} }
export declare enum ScrollPanDirection {
FORWARD = "forward",
BACKWARD = "backward",
BOTH = "both"
}
export declare enum AxisFormat { export declare enum AxisFormat {
TIME = "time", TIME = "time",
NUMERIC = "numeric", NUMERIC = "numeric",

18
src/index.ts

@ -18,6 +18,7 @@ import {
PanOrientation, PanOrientation,
yAxisOrientation, yAxisOrientation,
ScrollPanOrientation, ScrollPanOrientation,
ScrollPanDirection,
AxisOption, AxisOption,
SvgElParams, SvgElParams,
} from './types'; } from './types';
@ -82,6 +83,7 @@ const DEFAULT_OPTIONS: Options = {
keyEvent: KeyEvent.SHIFT, keyEvent: KeyEvent.SHIFT,
panStep: DEFAULT_SCROLL_PAN_STEP, panStep: DEFAULT_SCROLL_PAN_STEP,
orientation: ScrollPanOrientation.HORIZONTAL, orientation: ScrollPanOrientation.HORIZONTAL,
direction: ScrollPanDirection.BOTH,
}, },
}, },
}, },
@ -608,11 +610,25 @@ abstract class ChartwerkPod<T extends TimeSerie, O extends Options> {
.text('No data points'); .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 { protected onPanning(): void {
const event = this.d3.event; const event = this.d3.event;
if(event.sourceEvent === null || event.sourceEvent === undefined) { if(event.sourceEvent === null || event.sourceEvent === undefined) {
return; return;
} }
if (event.sourceEvent.type === 'wheel'
&& (this.disableScrollBackward(event) || this.disableScrollForward(event))) {
return;
}
this.rescaleMetricAndAxis(event); this.rescaleMetricAndAxis(event);
if(this.options.eventsCallbacks !== undefined && this.options.eventsCallbacks.panning !== undefined) { if(this.options.eventsCallbacks !== undefined && this.options.eventsCallbacks.panning !== undefined) {
@ -1111,6 +1127,6 @@ abstract class ChartwerkPod<T extends TimeSerie, O extends Options> {
export { export {
ChartwerkPod, VueChartwerkPodMixin, ChartwerkPod, VueChartwerkPodMixin,
Margin, TimeSerie, Options, TickOrientation, TimeFormat, BrushOrientation, PanOrientation, Margin, TimeSerie, Options, TickOrientation, TimeFormat, BrushOrientation, PanOrientation,
AxisFormat, yAxisOrientation, CrosshairOrientation, ScrollPanOrientation, KeyEvent, AxisFormat, yAxisOrientation, CrosshairOrientation, ScrollPanOrientation, ScrollPanDirection, KeyEvent,
palette palette
}; };

6
src/types.ts

@ -85,6 +85,7 @@ export type Options = {
keyEvent?: KeyEvent; keyEvent?: KeyEvent;
panStep?: number; panStep?: number;
orientation?: ScrollPanOrientation; orientation?: ScrollPanOrientation;
direction?: ScrollPanDirection;
}, },
}, },
} }
@ -140,6 +141,11 @@ export enum ScrollPanOrientation {
VERTICAL = 'vertical', VERTICAL = 'vertical',
HORIZONTAL = 'horizontal', HORIZONTAL = 'horizontal',
} }
export enum ScrollPanDirection {
FORWARD = 'forward',
BACKWARD = 'backward',
BOTH = 'both',
}
export enum AxisFormat { export enum AxisFormat {
TIME = 'time', TIME = 'time',
NUMERIC = 'numeric', NUMERIC = 'numeric',

Loading…
Cancel
Save