Skip to content

Commit

Permalink
feat(rstream-gestures): add zoomDelta output
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Apr 11, 2019
1 parent f2efaa5 commit 68c4b45
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
10 changes: 5 additions & 5 deletions packages/rstream-gestures/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Unified mouse, mouse wheel & single-touch event stream abstraction.
Stream emits tuples of:

```ts
[type, {pos, click?, delta?, zoom}]
[type, { pos, click?, delta?, zoom, zoomDelta }]
```

The `click` and `delta` values are only present if `type ==
Expand All @@ -25,7 +25,7 @@ events. The value will be constrained to `minZoom` ... `maxZoom`
interval (provided via options object).

Also see the
[`GestureStreamOpts`](https://github.com/thi-ng/umbrella/tree/master/packages/rstream-gestures/src/index.ts#L26)
[`GestureStreamOpts`](https://github.com/thi-ng/umbrella/tree/master/packages/rstream-gestures/src/index.ts#L31)
config options for further details.

## Installation
Expand Down Expand Up @@ -60,15 +60,15 @@ import { trace } from "@thi.ng/rstream";
import { comp, dedupe, filter, map } from "@thi.ng/transducers";

// create event stream with custom option
const gestures = gestureStream(document.body, { smooth: 0.5 });
const gestures = gestureStream(document.body, { smooth: 0.01 });

// subscription logging zoom value changes
gestures.subscribe(
// trace is simply logging received values to console
trace("zoom"),
// composed transducer, `dedupe` ensures only changed values are received
comp(
map(([_, {zoom}]) => zoom),
map(([_, { zoom }]) => zoom),
dedupe()
)
);
Expand All @@ -78,7 +78,7 @@ gestures.subscribe(
trace("distance"),
comp(
filter(([type]) => type === GestureType.DRAG),
map(([_, {delta}]) => Math.hypot(...delta))
map(([_, { delta }]) => Math.hypot(...delta))
)
);
```
Expand Down
12 changes: 6 additions & 6 deletions packages/rstream-gestures/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface GestureInfo {
click: number[];
delta: number[];
zoom: number;
zoomDelta: number;
}

export interface GestureEvent {
Expand Down Expand Up @@ -172,7 +173,7 @@ export const gestureStream = (
pos[0] *= dpr;
pos[1] *= dpr;
}
const body = <GestureInfo>{ pos, zoom };
const body = <GestureInfo>{ pos, zoom, zoomDelta: 0 };
switch (type) {
case GestureType.START:
isDown = true;
Expand All @@ -187,15 +188,14 @@ export const gestureStream = (
body.delta = [pos[0] - clickPos[0], pos[1] - clickPos[1]];
break;
case GestureType.ZOOM:
const zdelta = (<WheelEvent>e).deltaY * opts.smooth;
body.zoom = zoom = opts.absZoom
? Math.min(
Math.max(
zoom + (<WheelEvent>e).deltaY * opts.smooth,
opts.minZoom
),
Math.max(zoom + zdelta, opts.minZoom),
opts.maxZoom
)
: (<WheelEvent>e).deltaY * opts.smooth;
: zdelta;
body.zoomDelta = zdelta;
break;
default:
}
Expand Down

0 comments on commit 68c4b45

Please sign in to comment.