From 493d52629c386aab0a8452295ed23f976474d3d0 Mon Sep 17 00:00:00 2001 From: glitch4347 Date: Wed, 10 Jan 2024 00:22:41 +0100 Subject: [PATCH] onclick --- src/index.ts | 27 ++++++++++++++++----------- src/models/options.ts | 6 ++++++ src/types.ts | 1 + 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/index.ts b/src/index.ts index 66c46d4..58b6869 100644 --- a/src/index.ts +++ b/src/index.ts @@ -30,8 +30,6 @@ import { palette } from './colors'; import * as d3 from 'd3'; -import first from 'lodash/first'; -import last from 'lodash/last'; import debounce from 'lodash/debounce'; @@ -156,6 +154,7 @@ abstract class ChartwerkPod { protected abstract onMouseOver(): void; protected abstract onMouseOut(): void; protected abstract onMouseMove(): void; + protected abstract onMouseClick(): void; public abstract renderSharedCrosshair(values: { x?: number, y?: number }): void; public abstract hideSharedCrosshair(): void; @@ -327,12 +326,21 @@ abstract class ChartwerkPod { // TODO: refactor for a new mouse/scroll events const panKeyEvent = this.options.mousePanEvent.keyEvent; const isPanActive = this.options.mousePanEvent.isActive; - if(isPanActive === true && panKeyEvent === KeyEvent.MAIN) { - this.initPan(); - this.initBrush(); + const isBrushActive = this.options.mouseZoomEvent.isActive; + if(panKeyEvent === KeyEvent.MAIN) { + if(isPanActive) { + this.initPan(); + } + if(isBrushActive) { + this.initBrush(); + } } else { - this.initBrush(); - this.initPan(); + if(isBrushActive) { + this.initBrush(); + } + if(isPanActive) { + this.initPan(); + } } this.ensureOverlayExisting(); @@ -341,6 +349,7 @@ abstract class ChartwerkPod { .on('mouseover', this.onMouseOver.bind(this)) .on('mouseout', this.onMouseOut.bind(this)) .on('mousemove', this.onMouseMove.bind(this)) + .on('click', this.onMouseClick.bind(this)) .on('dblclick', () => { d3.event.stopPropagation(); // TODO: add the same check as we have in line-pod @@ -372,10 +381,6 @@ abstract class ChartwerkPod { } protected initBrush(): void { - const isBrushActive = this.options.mouseZoomEvent.isActive; - if(isBrushActive === false) { - return; - } switch(this.options.mouseZoomEvent.orientation) { case BrushOrientation.VERTICAL: this.brush = d3.brushY(); diff --git a/src/models/options.ts b/src/models/options.ts index 791a5df..9e99799 100644 --- a/src/models/options.ts +++ b/src/models/options.ts @@ -230,4 +230,10 @@ export class CoreOptions { this._options.eventsCallbacks.mouseOut(); } } + + callbackMouseClick(event): void { + if(has(this._options.eventsCallbacks, 'mouseClick')) { + this._options.eventsCallbacks.mouseClick(event); + } + } } diff --git a/src/types.ts b/src/types.ts index ba6356b..9353026 100644 --- a/src/types.ts +++ b/src/types.ts @@ -22,6 +22,7 @@ export type Options = { panningEnd?: (range: AxisRange[]) => void, zoomOut?: (centers: {x: number, y: number}) => void, mouseMove?: (evt: any) => void, + mouseClick?: (evt: any) => void, mouseOut?: () => void, onLegendClick?: (idx: number) => void, onLegendLabelClick?: (idx: number) => void,