zoom by mousewheel
This commit is contained in:
@@ -4,7 +4,8 @@
|
|||||||
(mousedown)="dragStart($event)"
|
(mousedown)="dragStart($event)"
|
||||||
(mousemove)="dragging($event)"
|
(mousemove)="dragging($event)"
|
||||||
(mouseup)="dragStop($event)"
|
(mouseup)="dragStop($event)"
|
||||||
(mouseout)="dragAbort($event)">
|
(mouseout)="dragAbort($event)"
|
||||||
|
(wheel)="zoomByScroll($event)">
|
||||||
<img
|
<img
|
||||||
id="result-image"
|
id="result-image"
|
||||||
src="{{imageUrl}}"
|
src="{{imageUrl}}"
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ export class PlotViewComponent implements OnInit {
|
|||||||
@Output()
|
@Output()
|
||||||
zoomRange : EventEmitter<SelectionRange> = new EventEmitter<SelectionRange>();
|
zoomRange : EventEmitter<SelectionRange> = new EventEmitter<SelectionRange>();
|
||||||
|
|
||||||
|
@Output()
|
||||||
|
zoomWithDateAnchor : EventEmitter<DateAnchor> = new EventEmitter<DateAnchor>();
|
||||||
|
|
||||||
in_drag_mode = false;
|
in_drag_mode = false;
|
||||||
drag_start_x = 0;
|
drag_start_x = 0;
|
||||||
@@ -57,9 +59,9 @@ export class PlotViewComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
positionInImage(event) : any {
|
positionInImage(event) : any {
|
||||||
const rect = <HTMLImageElement>document.getElementById('result-image');
|
const x= event.offsetX;
|
||||||
const x= event.clientX - rect.x;
|
const y= event.offsetY;
|
||||||
const y= event.clientY - rect.y;
|
|
||||||
return {x: x, y: y};
|
return {x: x, y: y};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,6 +103,7 @@ 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);
|
||||||
|
|
||||||
@@ -137,7 +140,7 @@ export class PlotViewComponent implements OnInit {
|
|||||||
const startPercentOfDateRange = startPxWithinPlotArea / widthPlotArea;
|
const startPercentOfDateRange = startPxWithinPlotArea / widthPlotArea;
|
||||||
const endPercentOfDateRange = endPxWithinPlotArea / widthPlotArea;
|
const endPercentOfDateRange = endPxWithinPlotArea / widthPlotArea;
|
||||||
|
|
||||||
this.zoomRange.emit(new SelectionRange(startPercentOfDateRange, endPercentOfDateRange));
|
this.zoomRange.emit(new SelectionRange(startPercentOfDateRange, endPercentOfDateRange));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -151,6 +154,23 @@ export class PlotViewComponent implements OnInit {
|
|||||||
this.hideZoomInSlider();
|
this.hideZoomInSlider();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
zoomByScroll(event) {
|
||||||
|
if (this.isInImage(event) && event.deltaY != 0) {
|
||||||
|
this.in_drag_mode = false;
|
||||||
|
this.hideZoomInSlider();
|
||||||
|
|
||||||
|
const pos = this.positionInImage(event);
|
||||||
|
|
||||||
|
const widthPlotArea = this.imageWidth() - this.gnuplotLMargin - this.gnuplotRMargin;
|
||||||
|
const cursorPxWithinPlotArea = pos.x - this.gnuplotLMargin;
|
||||||
|
const cursorPercentOfDateRange = cursorPxWithinPlotArea / widthPlotArea;
|
||||||
|
|
||||||
|
const zoomFactor = event.deltaY < 0 ? 0.5 : 2;
|
||||||
|
|
||||||
|
this.zoomWithDateAnchor.emit(new DateAnchor(cursorPercentOfDateRange, zoomFactor));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class SelectionRange {
|
export class SelectionRange {
|
||||||
@@ -161,4 +181,14 @@ export class SelectionRange {
|
|||||||
this.startPercentOfDateRange = startPercentOfDateRange;
|
this.startPercentOfDateRange = startPercentOfDateRange;
|
||||||
this.endPercentOfDateRange = endPercentOfDateRange;
|
this.endPercentOfDateRange = endPercentOfDateRange;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class DateAnchor {
|
||||||
|
cursorPercentOfDateRange : number;
|
||||||
|
zoomFactor : number;
|
||||||
|
|
||||||
|
constructor(cursorPercentOfDateRange : number, zoomFactor : number) {
|
||||||
|
this.cursorPercentOfDateRange = cursorPercentOfDateRange;
|
||||||
|
this.zoomFactor = zoomFactor;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -84,7 +84,10 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div id="results">
|
<div id="results">
|
||||||
<pdb-plot-view #plotView (zoomRange)="zoomRange($event)"></pdb-plot-view>
|
<pdb-plot-view
|
||||||
|
#plotView
|
||||||
|
(zoomRange)="zoomRange($event)"
|
||||||
|
(zoomWithDateAnchor)="zoomWithDateAnchor($event)"></pdb-plot-view>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { FormControl, Validators } from '@angular/forms';
|
|||||||
import { LimitByComponent } from '../limit-by/limit-by.component';
|
import { LimitByComponent } from '../limit-by/limit-by.component';
|
||||||
import { YAxisRangeComponent } from '../y-axis-range/y-axis-range.component';
|
import { YAxisRangeComponent } from '../y-axis-range/y-axis-range.component';
|
||||||
import { QueryAutocompleteComponent } from '../query-autocomplete/query-autocomplete.component';
|
import { QueryAutocompleteComponent } from '../query-autocomplete/query-autocomplete.component';
|
||||||
import {PlotViewComponent, SelectionRange } from '../plot-view/plot-view.component'
|
import {PlotViewComponent, SelectionRange, DateAnchor } from '../plot-view/plot-view.component'
|
||||||
import * as moment from 'moment';
|
import * as moment from 'moment';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
@@ -126,6 +126,26 @@ export class VisualizationPageComponent implements OnInit {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Zoom in/out by zoomFaktor, so that the anchorInPercentOfDateRange keeps the same position.
|
||||||
|
*
|
||||||
|
* shiftDateByAnchor(dateRangeAsString, 0.20, 0.5) zooms in by 50%, so that the date that was at 20% before the zoom is still at 20% after the zoom
|
||||||
|
* shiftDateByAnchor(dateRangeAsString, 0.33, 2) zooms out by 50%, so that the date that was at 33% before the zoom is still at 33% after the zoom
|
||||||
|
*/
|
||||||
|
shiftDateByAnchor(dateRange:string, anchorInPercentOfDateRange:number, zoomFactor:number)
|
||||||
|
{
|
||||||
|
const dateRangeParsed = this.parseDateRange(dateRange);
|
||||||
|
const dateRangeInSeconds = dateRangeParsed.duration.asSeconds();
|
||||||
|
|
||||||
|
const anchorTimestampInSeconds = dateRangeParsed.startDate.clone().add(Math.floor(dateRangeInSeconds*anchorInPercentOfDateRange), "seconds");
|
||||||
|
const newDateRangeInSeconds = dateRangeInSeconds * zoomFactor;
|
||||||
|
|
||||||
|
const newStartDate = anchorTimestampInSeconds.clone().subtract(newDateRangeInSeconds*anchorInPercentOfDateRange, "seconds");
|
||||||
|
const newEndDate = newStartDate.clone().add({seconds: newDateRangeInSeconds});;
|
||||||
|
|
||||||
|
this.setDateRange(newStartDate, newEndDate);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Zoom in/out or shift date by adding factorStartDate*dateRangeInSeconds seconds to the start date
|
* Zoom in/out or shift date by adding factorStartDate*dateRangeInSeconds seconds to the start date
|
||||||
* and factorEndDate*dateRangeInSeconds seconds to the end date.
|
* and factorEndDate*dateRangeInSeconds seconds to the end date.
|
||||||
@@ -143,7 +163,6 @@ export class VisualizationPageComponent implements OnInit {
|
|||||||
const newStartDate = dateRangeParsed.startDate.add({seconds: dateRangeInSeconds*factorStartDate});
|
const newStartDate = dateRangeParsed.startDate.add({seconds: dateRangeInSeconds*factorStartDate});
|
||||||
const newEndDate = dateRangeParsed.endDate.add({seconds: dateRangeInSeconds*factorEndDate});
|
const newEndDate = dateRangeParsed.endDate.add({seconds: dateRangeInSeconds*factorEndDate});
|
||||||
|
|
||||||
console.log(newStartDate + " - " + newEndDate);
|
|
||||||
this.setDateRange(newStartDate, newEndDate);
|
this.setDateRange(newStartDate, newEndDate);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -173,6 +192,10 @@ export class VisualizationPageComponent implements OnInit {
|
|||||||
zoomRange(range: SelectionRange) {
|
zoomRange(range: SelectionRange) {
|
||||||
this.shiftDate(this.dateRangeAsString(), range.startPercentOfDateRange, range.endPercentOfDateRange-1);
|
this.shiftDate(this.dateRangeAsString(), range.startPercentOfDateRange, range.endPercentOfDateRange-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
zoomWithDateAnchor(dateAnchor: DateAnchor){
|
||||||
|
this.shiftDateByAnchor(this.dateRangeAsString(), dateAnchor.cursorPercentOfDateRange, dateAnchor.zoomFactor);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user