Skip to content

Commit

Permalink
zoom. n.line: Fix mobile pinch zoom
Browse files Browse the repository at this point in the history
  • Loading branch information
vezwork committed May 30, 2024
1 parent c735ae8 commit eea5f0a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 15 deletions.
13 changes: 8 additions & 5 deletions dist/demo/articles/exploring_spaces_3_and_a_half/dragging0.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,19 @@ let state = {
this._pos = x;
},
render() {
// scale and negate pos so dragging is in the right direction and not too fast.
const x = this._pos;
// NUM, ZOOM, LAYOUT CALC
const zoomBaseExponent = zoom / 3000;
const zz = BASE ** zoomBaseExponent;
// ARBITRARY PRECISION INDEPENDENT:
const halfWidth = (svg.clientWidth * SVG_WIDTH_SCALE) / 2;
const thing = Math.floor(halfWidth / SPACING); // should be ceil
const thing = Math.ceil(halfWidth / SPACING);
// ARBITRARY PRECISION SIMPLE NUMBER
const zoomBaseExponent = zoom / 3000;
const maxIterationsForHalfTicks = thing * 10 ** mod(-zoomBaseExponent, 1);
const baseExponent = -Math.ceil(zoomBaseExponent);
// NUM, ZOOM, LAYOUT CALC
// EXP
const zz = BASE ** zoomBaseExponent;
const numTickGap = BASE ** baseExponent;
// TRUNC
// as you zoom in this uses more of x, as you zoom out it truncates
const startInGapBase = Math.round(x / numTickGap);
const startX = startInGapBase * numTickGap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function makeDraggable(el, eventToCoordinates, onMove = ([x, y]) => { },
const curDiff = Math.abs(evCache[0].clientX - evCache[1].clientX);
if (prevDiff > 0) {
const diff = curDiff - prevDiff;
onZoom(diff);
onZoom(diff * 10);
}
// Cache the distance for the next move event
prevDiff = curDiff;
Expand Down
19 changes: 11 additions & 8 deletions src/demo/articles/exploring_spaces_3_and_a_half/dragging0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,23 @@ let state = {
this._pos = x;
},
render() {
// scale and negate pos so dragging is in the right direction and not too fast.
const x = this._pos;
// ARBITRARY PRECISION INDEPENDENT:
const halfWidth = (svg.clientWidth * SVG_WIDTH_SCALE) / 2;
const thing = Math.ceil(halfWidth / SPACING);

// NUM, ZOOM, LAYOUT CALC

// ARBITRARY PRECISION SIMPLE NUMBER
const zoomBaseExponent = zoom / 3000;
const zz = BASE ** zoomBaseExponent;

const halfWidth = (svg.clientWidth * SVG_WIDTH_SCALE) / 2;
const thing = Math.floor(halfWidth / SPACING); // should be ceil
const maxIterationsForHalfTicks = thing * 10 ** mod(-zoomBaseExponent, 1);

const baseExponent = -Math.ceil(zoomBaseExponent);

// NUM, ZOOM, LAYOUT CALC

// EXP
const zz = BASE ** zoomBaseExponent;
const numTickGap = BASE ** baseExponent;

// TRUNC
// as you zoom in this uses more of x, as you zoom out it truncates
const startInGapBase = Math.round(x / numTickGap);
const startX = startInGapBase * numTickGap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export function makeDraggable(

if (prevDiff > 0) {
const diff = curDiff - prevDiff;
onZoom(diff);
onZoom(diff * 10);
}

// Cache the distance for the next move event
Expand Down

0 comments on commit eea5f0a

Please sign in to comment.