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

Feature: coarse pointer tolerance #918

Merged
merged 17 commits into from Aug 19, 2022
Merged

Feature: coarse pointer tolerance #918

merged 17 commits into from Aug 19, 2022

Conversation

Ovilia
Copy link
Member

@Ovilia Ovilia commented May 25, 2022

Intent

This PR is intended to increase elements' responsive area on mobile devices so that elements can be touched more easily.

The idea is inspired by W3C's Understanding Success Criterion 2.5.5: Target Size.

Algorithm

The algorithm can be briefly described as:

  1. Find the hovering element at the pointer position. If it exists, return the hovering element. Otherwise, go to 2.
  2. Calculate the elements whose bounding boxes have intersection with the touch position enlarged by "pointerSize" (which is 44px by default)
  3. Loop through different radius and angle from the pointer position to check if there are elements intersecting with it.

For cases that have too many elements, this feature can be turned off by setting ignoreCoarsePointer to the elements.

Tested with the Apache ECharts test cases and in most cases the extra calculation time is under 0.1ms.

API

zrender.init({
  useCoarsePointer: 'auto',
  pointerSize: 44,
  ...
});
  • useCoarsePointer ('auto' | true | false): whether to enable thie feature. If set to be 'auto', it's turned on only for mobile devices.
  • pointerSize (number): pointer position is increased by this size in diameter.

Each element can be set with ignoreCoarsePointer to turn off this feature individually:

el.ignoreCoarsePointer = true;

@Ovilia Ovilia marked this pull request as ready for review May 26, 2022 08:25
@Ovilia Ovilia requested a review from pissang May 26, 2022 08:25
@Ovilia Ovilia changed the base branch from master to next May 30, 2022 07:34
@Ovilia Ovilia changed the base branch from next to master July 7, 2022 09:23
src/core/event.ts Outdated Show resolved Hide resolved
src/zrender.ts Outdated Show resolved Hide resolved
src/zrender.ts Outdated Show resolved Hide resolved
src/Handler.ts Outdated Show resolved Hide resolved
src/Handler.ts Outdated Show resolved Hide resolved
@pissang
Copy link
Contributor

pissang commented Aug 12, 2022

The whole design looks good. There are several optimizations we can do to improve the code. I commented about them.

src/core/event.ts Outdated Show resolved Hide resolved
src/Handler.ts Outdated Show resolved Hide resolved
src/Handler.ts Outdated Show resolved Hide resolved
src/zrender.ts Outdated Show resolved Hide resolved
@pissang
Copy link
Contributor

pissang commented Aug 19, 2022

I have no more questions on this PR

Copy link
Collaborator

@plainheart plainheart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Ovilia Ovilia merged commit e5d275f into master Aug 19, 2022
@Ovilia Ovilia deleted the feat-coarse-pointer branch August 19, 2022 12:12
Ovilia added a commit to ecomfe/zrender-doc that referenced this pull request Sep 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants