Skip to content

Commit

Permalink
Changed Event listeners from document to canvas
Browse files Browse the repository at this point in the history
Signed-off-by: muddana-satish <satish.muddana@ericsson.com>
  • Loading branch information
muddana-satish authored and MatthewKhouzam committed Oct 7, 2020
1 parent 412579e commit 924c35d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 15 deletions.
5 changes: 4 additions & 1 deletion example/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,15 @@ const chartHTMLContainer = document.createElement('div');
chartHTMLContainer.id = 'main_chart';
container.appendChild(chartHTMLContainer);

const chartCanvas = document.createElement('canvas');
chartCanvas.tabIndex = 1;

const timeGraphChartContainer = new TimeGraphContainer({
id: timeGraph.id + '_chart',
height: styleConfig.mainHeight,
width: styleConfig.mainWidth,
backgroundColor: styleConfig.chartBackgroundColor
}, unitController);
}, unitController, chartCanvas);
chartHTMLContainer.appendChild(timeGraphChartContainer.canvas);

const timeGraphChartGridLayer = new TimeGraphChartGrid('timeGraphGrid', rowHeight);
Expand Down
14 changes: 10 additions & 4 deletions timeline-chart/src/layer/time-graph-chart-cursors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ export class TimeGraphChartCursors extends TimeGraphChartLayer {
this.mouseIsDown = false;
this.shiftKeyDown = false
this.stage.interactive = true;
document.addEventListener('keydown', (event: KeyboardEvent) => {

const keyDownHandler = (event: KeyboardEvent) => {
this.shiftKeyDown = event.shiftKey;
// TODO: keyCode is deprecated. We should change these.
if (event.keyCode === keyboardKey.ArrowLeft) {
this.navigateOrSelectLeft();
} else if (event.keyCode === keyboardKey.ArrowRight) {
Expand All @@ -36,10 +38,14 @@ export class TimeGraphChartCursors extends TimeGraphChartLayer {
} else if (event.keyCode === keyboardKey.ArrowDown) {
this.navigateDown();
}
});
document.addEventListener('keyup', (event: KeyboardEvent) => {
};

const keyUpHandler = (event: KeyboardEvent) => {
this.shiftKeyDown = event.shiftKey;
});
};

this.onCanvasEvent('keydown', keyDownHandler);
this.onCanvasEvent('keyup', keyUpHandler);

this.stage.on('mousedown', (event: PIXI.InteractionEvent) => {
this.mouseIsDown = true;
Expand Down
24 changes: 14 additions & 10 deletions timeline-chart/src/layer/time-graph-chart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,12 @@ export class TimeGraphChart extends TimeGraphChartLayer {
}
};

document.addEventListener('mousemove', (event: MouseEvent) => {
const mouseMoveHandler = (event: MouseEvent) => {
mousePositionX = event.offsetX;
mousePositionY = event.offsetY;
})
};

document.addEventListener('keydown', (event: KeyboardEvent) => {
const keyDownHandler = (event: KeyboardEvent) => {
this.shiftKeyDown = event.shiftKey;
this.ctrlKeyDown = event.ctrlKey;
let keyPressed = event.key;
Expand All @@ -133,12 +133,12 @@ export class TimeGraphChart extends TimeGraphChartLayer {
event.preventDefault();
}

});
};

document.addEventListener('keyup', (event: KeyboardEvent) => {
const keyUpHandler = (event: KeyboardEvent) => {
this.shiftKeyDown = event.shiftKey;
this.ctrlKeyDown = event.ctrlKey;
});
};

this.stage.addListener('mouseover', (event: MouseEvent) => {
triggerKeyEvent = true;
Expand All @@ -148,7 +148,7 @@ export class TimeGraphChart extends TimeGraphChartLayer {
triggerKeyEvent = false;
});

const mw = (ev: WheelEvent) => {
const mouseWheelHandler = (ev: WheelEvent) => {
if (this.ctrlKeyDown) {
const zoomPosition = (ev.offsetX / this.stateController.zoomFactor);
const deltaLength = (ev.deltaY / this.stateController.zoomFactor);
Expand Down Expand Up @@ -187,9 +187,13 @@ export class TimeGraphChart extends TimeGraphChartLayer {
this.rowController.verticalOffset = verticalOffset;
}
ev.preventDefault();
}
this.onCanvasEvent('mousewheel', mw);
this.onCanvasEvent('wheel', mw);
};

this.onCanvasEvent('mousemove', mouseMoveHandler);
this.onCanvasEvent('keydown', keyDownHandler);
this.onCanvasEvent('keyup', keyUpHandler);
this.onCanvasEvent('mousewheel', mouseWheelHandler);
this.onCanvasEvent('wheel', mouseWheelHandler);

this.rowController.onVerticalOffsetChangedHandler(verticalOffset => {
this.layer.position.y = -verticalOffset;
Expand Down

0 comments on commit 924c35d

Please sign in to comment.