Skip to content

Commit

Permalink
Refactor behavior.ts into static
Browse files Browse the repository at this point in the history
  • Loading branch information
adiletelf committed Apr 2, 2024
1 parent 4c252af commit 752cb80
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
14 changes: 7 additions & 7 deletions src/behavior.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any, ICursorDataPoint>()
.subject((_: D3DragEvent<any, ICursorDataPoint, ICursorDataPoint>, cursorDataPoint: ICursorDataPoint) => {
cursorDataPoint.x = cursorDataPoint.selectionIndex * options.cells.cellWidth;
Expand All @@ -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);
Expand All @@ -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);
Expand Down
5 changes: 2 additions & 3 deletions src/timeLine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,6 @@ export class Timeline implements powerbiVisualsApi.extensibility.visual.IVisual

private visualSettings: TimeLineSettingsModel;
private formattingSettingsService: FormattingSettingsService;
private behavior: Behavior;

private timelineProperties: ITimelineProperties;

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand All @@ -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() },
});

Expand Down

0 comments on commit 752cb80

Please sign in to comment.