Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(dataZoom): Add 'no-function-keys' option to RoamController and InsideZoomModel #20660

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/component/dataZoom/InsideZoomModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import DataZoomModel, {DataZoomOption} from './DataZoomModel';
import { inheritDefaultOption } from '../../util/component';
import { RoamKeysSetting } from '../helper/RoamController';

export interface InsideDataZoomOption extends DataZoomOption {

Expand All @@ -32,11 +33,11 @@ export interface InsideDataZoomOption extends DataZoomOption {
*/
zoomLock?: boolean

zoomOnMouseWheel?: boolean | 'shift' | 'ctrl' | 'alt'
zoomOnMouseWheel?: RoamKeysSetting

moveOnMouseMove?: boolean | 'shift' | 'ctrl' | 'alt'
moveOnMouseMove?: RoamKeysSetting

moveOnMouseWheel?: boolean | 'shift' | 'ctrl' | 'alt'
moveOnMouseWheel?: RoamKeysSetting

preventDefaultMouseMove?: boolean

Expand Down
20 changes: 13 additions & 7 deletions src/component/helper/RoamController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ import Group from 'zrender/src/graphic/Group';
// Can be null/undefined or true/false
// or 'pan/move' or 'zoom'/'scale'
export type RoamType = RoamOptionMixin['roam'];
export type RoamKeysSetting = boolean | 'ctrl' | 'shift' | 'alt' | 'no-function-keys';

interface RoamOption {
zoomOnMouseWheel?: boolean | 'ctrl' | 'shift' | 'alt'
moveOnMouseMove?: boolean | 'ctrl' | 'shift' | 'alt'
moveOnMouseWheel?: boolean | 'ctrl' | 'shift' | 'alt'
zoomOnMouseWheel?: RoamKeysSetting
moveOnMouseMove?: RoamKeysSetting
moveOnMouseWheel?: RoamKeysSetting
/**
* If fixed the page when pan
*/
Expand Down Expand Up @@ -327,16 +328,21 @@ function trigger<T extends RoamEventType>(
// moveOnMouseMove
// moveOnMouseWheel
// }
// The value can be: true / false / 'shift' / 'ctrl' / 'alt'.
// The value can be: true / false / 'shift' / 'ctrl' / 'alt', 'no-function-keys'.
function isAvailableBehavior(
behaviorToCheck: RoamBehavior,
e: ZRElementEvent,
settings: Pick<RoamOption, RoamBehavior>
) {
if (!behaviorToCheck) return true;
const setting = settings[behaviorToCheck];
return !behaviorToCheck || (
setting && (!isString(setting) || e.event[setting + 'Key' as 'shiftKey' | 'ctrlKey' | 'altKey'])
);
if (isString(setting)) {
const event = e.event;
return setting == 'no-function-keys' ?
!event.shiftKey && !event.ctrlKey && !event.altKey :
event[setting + 'Key' as 'shiftKey' | 'ctrlKey' | 'altKey'];
}
return setting;
}

export default RoamController;