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

Enable interaction mode support for events #659

Merged
merged 31 commits into from Apr 4, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
631fced
Enable events triggering on all affected annotations
stockiNail Jan 26, 2022
fa34f48
removes commented code
stockiNail Jan 26, 2022
46a6ee7
removes useless if statements
stockiNail Jan 26, 2022
f0f6697
first interaction mode implementation
stockiNail Jan 27, 2022
a3765c6
removes useless callback
stockiNail Jan 27, 2022
86136ef
applies interaction mode to click events
stockiNail Jan 27, 2022
ebddfed
applies review
stockiNail Jan 27, 2022
9ece84c
removes array creation if not needed
stockiNail Jan 27, 2022
fb61612
interaction for box annotation
stockiNail Jan 31, 2022
68c76f0
Merge remote-tracking branch 'origin/master' into multipleElementsFor…
stockiNail Jan 31, 2022
f64c524
adds test cases to box.spec
stockiNail Jan 31, 2022
8078441
adds ellipse to interaction management
stockiNail Feb 1, 2022
0c47496
adds label to interaction management
stockiNail Feb 1, 2022
3f314c9
adds point to interaction management
stockiNail Feb 1, 2022
d4f2af5
adds polygon to interaction management
stockiNail Feb 1, 2022
308bd90
should fix CC on box
stockiNail Feb 2, 2022
159f155
removes inX/YRange going to a unique method inRange
stockiNail Feb 2, 2022
dd90732
adds line to interaction management
stockiNail Feb 2, 2022
5227c1f
adds mode x and y
stockiNail Feb 3, 2022
8b6c5c7
removes tabs
stockiNail Feb 3, 2022
56a555c
fixes similar code and adds point to the context of interaction tests
stockiNail Feb 3, 2022
83a8e59
adds types
stockiNail Feb 3, 2022
c2fdd06
orders the options in types for annotation node
stockiNail Feb 3, 2022
ebe1035
adds documentation
stockiNail Feb 3, 2022
03536c2
fixes typo on doc
stockiNail Feb 3, 2022
0c620d2
Merge remote-tracking branch 'origin/master' into
stockiNail Feb 4, 2022
82c7d1e
Merge remote-tracking branch 'origin/master' into
stockiNail Feb 10, 2022
049a5ba
fixes CC for function with 5 arguments (exceeds 4 allowed)
stockiNail Feb 10, 2022
6be30ed
Merge remote-tracking branch 'origin/master' into
stockiNail Apr 4, 2022
a307dbb
adds note about the breaking change using interaction
stockiNail Apr 4, 2022
a4026de
Update docs/guide/migrationV2.md
stockiNail Apr 4, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 13 additions & 9 deletions src/events.js
Expand Up @@ -66,14 +66,7 @@ function handleMoveEvents(state, event, options) {
let elements = [];

if (event.type === 'mousemove') {
if (options.interaction.mode === 'point') {
elements = state.visibleElements.filter((element) => element.inRange(event.x, event.y));
} else {
const element = getNearestItem(state.visibleElements, event);
if (element) {
elements.push(element);
}
}
elements = getItems(state, event, options);
}

const previous = state.hovered;
Expand All @@ -94,7 +87,7 @@ function dispatchMoveEvents({state, event}, hook, elements, checkElements) {

function handleClickEvents(state, event, options) {
const listeners = state.listeners;
const elements = state.visibleElements.filter((element) => element.inRange(event.x, event.y));
const elements = getItems(state, event, options);
for (const element of elements) {
const elOpts = element.options;
const dblclick = elOpts.dblclick || listeners.dblclick;
Expand All @@ -121,6 +114,17 @@ function dispatchEvent(handler, element, event) {
callback(handler, [element.$context, event]);
}

function getItems(state, event, options) {
if (options.interaction.mode === 'point') {
return state.visibleElements.filter((element) => element.inRange(event.x, event.y));
}
const element = getNearestItem(state.visibleElements, event);
stockiNail marked this conversation as resolved.
Show resolved Hide resolved
if (element) {
return [element];
}
return [];
}

function getNearestItem(elements, position) {
let minDistance = Number.POSITIVE_INFINITY;

Expand Down
2 changes: 1 addition & 1 deletion test/specs/events.spec.js
Expand Up @@ -203,7 +203,7 @@ describe('Common', function() {
}
};
const modes = ['nearest', 'point'];
const hookCallsCount = [[1, 1, 2, 0, 1], [1, 2, 2, 1, 2]];
const hookCallsCount = [[1, 1, 1, 0, 1], [1, 2, 2, 1, 2]];

for (let i = 0; i < modes.length; i++) {
const mode = modes[i];
Expand Down