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 options on annotations to apply automatically when hovered #840

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
renames active elements
  • Loading branch information
stockiNail committed Jan 31, 2023
commit 528c45ef5cc5e46036a6222ed1e281d555ecdd3e
6 changes: 3 additions & 3 deletions src/annotation.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {Chart} from 'chart.js';
import {clipArea, unclipArea, isObject, isArray} from 'chart.js/helpers';
import {handleEvent, eventHooks, updateListeners} from './events';
import {handleHoverElements} from './hover';
import {handleActiveElements} from './hover';
import {invokeHook, elementHooks, updateHooks} from './hooks';
import {adjustScaleRange, verifyScaleOptions} from './scale';
import {updateElements, resolveType} from './elements';
Expand Down Expand Up @@ -40,7 +40,7 @@ export default {
hooks: {},
hooked: false,
hovered: [],
highlighted: []
activeElements: []
});
},

Expand Down Expand Up @@ -94,7 +94,7 @@ export default {

beforeEvent(chart, args, options) {
const state = chartStates.get(chart);
const hovered = handleHoverElements(chart, state, args.event, options);
const hovered = handleActiveElements(chart, state, args.event, options);
if (handleEvent(state, args.event, options) || hovered) {
args.changed = true;
}
Expand Down
12 changes: 6 additions & 6 deletions src/hover.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {hoverElements} from './elements';
* @param {AnnotationPluginOptions} options
* @return {boolean|undefined}
*/
export function handleHoverElements(chart, state, event, options) {
export function handleActiveElements(chart, state, event, options) {
if (options.hover.enabled) {
switch (event.type) {
case 'mousemove':
Expand All @@ -33,15 +33,15 @@ function handleMoveEvents(chart, state, event, options) {
elements = [];
}

if (!state.highlighted.length && !elements.length) {
if (!state.activeElements.length && !elements.length) {
return false;
}

const unhovered = state.highlighted.filter((el) => !elements.includes(el));
const unhovered = state.activeElements.filter((el) => !elements.includes(el));
setActive(unhovered, false);
state.highlighted = elements;
setActive(state.highlighted, true);
hoverElements(chart, state, options, unhovered.concat(state.highlighted));
state.activeElements = elements;
setActive(elements, true);
hoverElements(chart, state, options, unhovered.concat(elements));
return true;
}

Expand Down