fix range selection when moving from right to left

This commit is contained in:
2019-11-01 09:00:05 +01:00
parent 3303afd115
commit d91481809e

View File

@@ -59,8 +59,14 @@ export class PlotViewComponent implements OnInit {
} }
positionInImage(event) : any { positionInImage(event) : any {
const x= event.offsetX; const rect = (<HTMLImageElement>document.getElementById('result-image')).getBoundingClientRect();
const y= event.offsetY; const x= event.clientX - rect.left;
const y= event.clientY - rect.top;
//console.log("pos: " + x+"x" +y+ " rect: "+rect.x+"x"+rect.y + " client: "+ event.clientX+"x"+ event.clientY + " offset:" + event.offsetX+"x"+event.offsetY );
console.log(JSON.stringify(rect));
return {x: x, y: y}; return {x: x, y: y};
} }
@@ -104,17 +110,16 @@ export class PlotViewComponent implements OnInit {
if (this.in_drag_mode && event.buttons == 1){ if (this.in_drag_mode && event.buttons == 1){
const pos = this.positionInImage(event); const pos = this.positionInImage(event);
this.drag_end_x = Math.max(Math.min(pos.x, this.imageWidth()-this.gnuplotRMargin), this.gnuplotLMargin); this.drag_end_x = Math.max(Math.min(pos.x, this.imageWidth()-this.gnuplotRMargin), this.gnuplotLMargin);
const left = this.drag_start_x < this.drag_end_x ? this.drag_start_x : this.drag_end_x; const left = this.drag_start_x < this.drag_end_x ? this.drag_start_x : this.drag_end_x;
const width = Math.abs(this.drag_start_x - this.drag_end_x); const width = Math.abs(this.drag_start_x - this.drag_end_x);
if (width > 10) { if (width > 10) {
//this.zoomInSliderStyle="position: absolute; left: "+left+"px; width: "+width+"px; top:"+this.gnuplotTMargin+"px; bottom: "+this.gnuplotBMargin+"px;";
this.zoomInSliderStyleDisplay = "block"; this.zoomInSliderStyleDisplay = "block";
this.zoomInSliderStyleLeft= left+"px"; this.zoomInSliderStyleLeft= left+"px";
this.zoomInSliderStyleWidth= width+"px"; this.zoomInSliderStyleWidth= width+"px";
this.zoomInSliderStyleBottomMargin = "calc(100% - "+(this.imageHeight()-this.gnuplotBMargin)+"px)";
} else { } else {
this.hideZoomInSlider(); this.hideZoomInSlider();
} }