diff --git a/src/behavior.ts b/src/behavior.ts index 809c95d..cf1264b 100644 --- a/src/behavior.ts +++ b/src/behavior.ts @@ -23,13 +23,13 @@ export interface BehaviorOptions { } export class Behavior { - public bindEvents(options: BehaviorOptions) { - this.handleCellsClick(options); - this.handleCursorsDrag(options); - this.clearCatcher(options); + public static bindEvents(options: BehaviorOptions) { + Behavior.handleCellsClick(options); + Behavior.handleCursorsDrag(options); + Behavior.clearCatcher(options); } - private handleCursorsDrag(options: BehaviorOptions) { + private static handleCursorsDrag(options: BehaviorOptions) { const dragBehavior = d3Drag() .subject((_: D3DragEvent, cursorDataPoint: ICursorDataPoint) => { cursorDataPoint.x = cursorDataPoint.selectionIndex * options.cells.cellWidth; @@ -44,7 +44,7 @@ export class Behavior { options.cursors.selection.call(dragBehavior); } - private handleCellsClick(options: BehaviorOptions) { + private static handleCellsClick(options: BehaviorOptions) { const clickHandler = (event: MouseEvent, dataPoint: ITimelineDataPoint) => { event.stopPropagation(); options.cells.callback(dataPoint, dataPoint.index, event.ctrlKey || event.metaKey || event.altKey || event.shiftKey); @@ -57,7 +57,7 @@ export class Behavior { .on("touchstart", clickHandler); } - private clearCatcher(options: BehaviorOptions) { + private static clearCatcher(options: BehaviorOptions) { options.clearCatcher .on("click", null) .on("click", options.clearSelectionHandler); diff --git a/src/timeLine.ts b/src/timeLine.ts index b67e389..9ab0ee0 100644 --- a/src/timeLine.ts +++ b/src/timeLine.ts @@ -534,7 +534,6 @@ export class Timeline implements powerbiVisualsApi.extensibility.visual.IVisual private visualSettings: TimeLineSettingsModel; private formattingSettingsService: FormattingSettingsService; - private behavior: Behavior; private timelineProperties: ITimelineProperties; @@ -596,7 +595,6 @@ export class Timeline implements powerbiVisualsApi.extensibility.visual.IVisual this.localizationManager = this.host.createLocalizationManager(); this.formattingSettingsService = new FormattingSettingsService(this.localizationManager); - this.behavior = new Behavior(); this.timelineProperties = { bottomMargin: Timeline.TimelineMargins.BottomMargin, @@ -761,7 +759,7 @@ export class Timeline implements powerbiVisualsApi.extensibility.visual.IVisual options, ); - this.behavior.bindEvents({ + Behavior.bindEvents({ selectionManager: this.selectionManager, cells: { selection: this.mainGroupSelection.selectAll(Timeline.TimelineSelectors.CellRect.selectorName), @@ -774,6 +772,7 @@ export class Timeline implements powerbiVisualsApi.extensibility.visual.IVisual onEnd: this.onCursorDragEnd.bind(this), }, clearCatcher: this.rootSelection, + // spyOn changes clearUserSelection, anonymous function is used to have link to spied function clearSelectionHandler: () => { this.clearUserSelection() }, });