Skip to content

Commit 18226eb

Browse files
authored
Merge pull request #305 from Dessia-tech/fix/prevent_default
fix(prevent_default): add line codes to prevent defualt
2 parents fa52fb6 + d8e6739 commit 18226eb

3 files changed

Lines changed: 13 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
- Handle empty elements in Scatter
1111
- Offset & Margin in ParallelPlot
1212
- Performance for curves drawing in ParallelPlot
13+
- Events on window outside canvas are disabled
1314

1415
### Add
1516
- Parallel plot feature with:

src/multiplots.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1897,6 +1897,7 @@ export class MultiplePlots {
18971897
});
18981898

18991899
window.addEventListener('keyup', e => {
1900+
e.preventDefault();
19001901
if (e.key == "Control") ctrlKey = false;
19011902
if (e.key == "Shift") {
19021903
shiftKey = false;
@@ -1907,6 +1908,7 @@ export class MultiplePlots {
19071908
});
19081909

19091910
this.canvas.addEventListener('mousedown', e => {
1911+
e.preventDefault();
19101912
isDrawing = true;
19111913
mouse1X = e.offsetX;
19121914
mouse1Y = e.offsetY;
@@ -1937,6 +1939,7 @@ export class MultiplePlots {
19371939
});
19381940

19391941
this.canvas.addEventListener('mousemove', e => {
1942+
e.preventDefault();
19401943
var old_mouse2X = mouse2X; var old_mouse2Y = mouse2Y;
19411944
mouse2X = e.offsetX; mouse2Y = e.offsetY;
19421945
if (this.isSelecting) this.canvas.style.cursor = 'crosshair';
@@ -1999,6 +2002,7 @@ export class MultiplePlots {
19992002
});
20002003

20012004
this.canvas.addEventListener('mouseup', e => {
2005+
e.preventDefault();
20022006
mouse3X = e.offsetX;
20032007
mouse3Y = e.offsetY;
20042008
var click_on_manip_button = Shape.isInRect(mouse3X, mouse3Y, this.transbutton_x, this.button_y, this.button_w, this.button_h);

src/subplots.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1881,21 +1881,24 @@ export class Figure extends PlotData {
18811881
if (!ctrlKey) { this.isSelecting = true; canvas.style.cursor = 'crosshair'; this.draw() };
18821882
}
18831883
if (e.key == " ") {
1884+
e.preventDefault();
18841885
spaceKey = true;
18851886
if (ctrlKey && this.isInCanvas(absoluteMouse)) this.resetView();
18861887
}
18871888
});
18881889

18891890
window.addEventListener('keyup', e => {
1891+
e.preventDefault();
18901892
if (e.key == "Control") ctrlKey = false;
18911893
if (e.key == " ") spaceKey = false;
18921894
if (e.key == "Shift") { shiftKey = false; this.isSelecting = false; this.is_drawing_rubber_band = false; canvas.style.cursor = 'default'; this.draw() };
18931895
});
18941896

18951897
canvas.addEventListener('mousemove', e => {
1898+
e.preventDefault();
18961899
[canvasMouse, frameMouse, absoluteMouse] = this.projectMouse(e);
18971900
this.mouseMove(canvasMouse, frameMouse, absoluteMouse);
1898-
if (this.isZooming) canvas.style.cursor = 'crosshair';
1901+
if (this.isZooming || this.isSelecting) canvas.style.cursor = 'crosshair';
18991902
if (this.interaction_ON) {
19001903
if (isDrawing) {
19011904
const translation = this.mouseTranslate(canvasMouse, canvasDown);
@@ -1914,14 +1917,14 @@ export class Figure extends PlotData {
19141917
if (!mouseInCanvas) isDrawing = false;
19151918
});
19161919

1917-
canvas.addEventListener('mousedown', e => {
1920+
canvas.addEventListener('mousedown', () => {
19181921
[canvasDown, frameDown, clickedObject] = this.mouseDown(canvasMouse, frameMouse, absoluteMouse);
19191922
if (!(clickedObject instanceof newAxis)) this.is_drawing_rubber_band = this.isSelecting;
19201923
if (ctrlKey && shiftKey) this.reset();
19211924
isDrawing = true;
19221925
});
19231926

1924-
canvas.addEventListener('mouseup', e => {
1927+
canvas.addEventListener('mouseup', () => {
19251928
if (this.isZooming) {
19261929
this.switchZoom();
19271930
this.zoomBoxUpdateAxes(zoomBox);
@@ -1933,14 +1936,15 @@ export class Figure extends PlotData {
19331936
})
19341937

19351938
canvas.addEventListener('wheel', e => {
1939+
e.preventDefault();
19361940
if (this.interaction_ON) {
19371941
this.wheelFromEvent(e);
19381942
this.updateWithScale();
19391943
this.draw();
19401944
}
19411945
});
19421946

1943-
canvas.addEventListener('mouseleave', e => {
1947+
canvas.addEventListener('mouseleave', () => {
19441948
isDrawing = false;
19451949
ctrlKey = false;
19461950
this.axes.forEach(axis => axis.saveLocation());

0 commit comments

Comments
 (0)