@@ -47,6 +47,7 @@ import {
4747import { MouseEventBinder } from "#src/util/mouse_bindings.js" ;
4848import { startRelativeMouseDrag } from "#src/util/mouse_drag.js" ;
4949import type { Uint64 } from "#src/util/uint64.js" ;
50+ import { getWheelZoomAmount } from "#src/util/wheel_zoom.js" ;
5051import type { WatchableVisibilityPriority } from "#src/visibility_priority/frontend.js" ;
5152import type { Buffer } from "#src/webgl/buffer.js" ;
5253import { getMemoizedBuffer } from "#src/webgl/buffer.js" ;
@@ -1257,6 +1258,7 @@ const inputEventMap = EventActionMap.fromObject({
12571258 "shift?+mousedown0" : { action : "add-or-drag-point" } ,
12581259 "shift+dblclick0" : { action : "remove-point" } ,
12591260 "shift?+mousedown2" : { action : "change-point-color" } ,
1261+ "shift?+wheel" : { action : "zoom-via-wheel" } ,
12601262} ) ;
12611263
12621264/**
@@ -1323,6 +1325,40 @@ class TransferFunctionController extends RefCounted {
13231325 }
13241326 } ,
13251327 ) ;
1328+ registerActionListener < WheelEvent > (
1329+ element ,
1330+ "zoom-via-wheel" ,
1331+ ( actionEvent ) => {
1332+ const wheelEvent = actionEvent . detail ;
1333+ const zoomAmount = getWheelZoomAmount ( wheelEvent ) ;
1334+ const relativeX = this . getTargetFraction ( wheelEvent ) ;
1335+ const { dataType } = this ;
1336+ const model = this . getModel ( ) ;
1337+ const newLower = computeLerp (
1338+ model . window ,
1339+ dataType ,
1340+ relativeX * ( 1 - zoomAmount ) ,
1341+ ) ;
1342+ const newUpper = computeLerp (
1343+ model . window ,
1344+ dataType ,
1345+ ( 1 - relativeX ) * zoomAmount + relativeX ,
1346+ ) ;
1347+ if ( newLower !== newUpper ) {
1348+ this . setModel ( {
1349+ ...model ,
1350+ window : [ newLower , newUpper ] as DataTypeInterval ,
1351+ } ) ;
1352+ }
1353+ } ,
1354+ ) ;
1355+ }
1356+ /**
1357+ * Get fraction of distance in x along bounding rect for a MouseEvent.
1358+ */
1359+ getTargetFraction ( event : MouseEvent ) {
1360+ const clientRect = this . element . getBoundingClientRect ( ) ;
1361+ return ( event . clientX - clientRect . left ) / clientRect . width ;
13261362 }
13271363 updateValue ( value : TransferFunctionParameters | undefined ) {
13281364 if ( value === undefined ) return ;
@@ -1600,16 +1636,14 @@ class TransferFunctionWidget extends Tab {
16001636 this . updateControlPointsAndDraw ( ) ;
16011637 } ) ,
16021638 ) ;
1603- updateInputBoundValue (
1604- this . window . inputs [ 0 ] ,
1605- this . trackable . value . window [ 0 ] ,
1606- ) ;
1607- updateInputBoundValue (
1608- this . window . inputs [ 1 ] ,
1609- this . trackable . value . window [ 1 ] ,
1610- ) ;
16111639 }
16121640 updateView ( ) {
1641+ for ( let i = 0 ; i < 2 ; ++ i ) {
1642+ updateInputBoundValue (
1643+ this . window . inputs [ i ] ,
1644+ this . trackable . value . window [ i ] ,
1645+ ) ;
1646+ }
16131647 this . transferFunctionPanel . scheduleRedraw ( ) ;
16141648 }
16151649 updateControlPointsAndDraw ( ) {
0 commit comments