diff --git a/assets/javascripts/planning.js b/assets/javascripts/planning.js index f4a5f4f..85d4791 100644 --- a/assets/javascripts/planning.js +++ b/assets/javascripts/planning.js @@ -465,23 +465,42 @@ PlanningChart.prototype.mousewheel = function (e) ++zoom; else if (e.deltaY < 0) --zoom; - var min_zoom_level = -2; - var zoom_upper_limit = 3; - var zoom_factor = 1.5; - zoom = Math.min(Math.max(this.options.min_zoom_level, zoom), this.options.max_zoom_level); - this.options.zoom_level = zoom; + this.setZoom(zoom, e.offsetX, e.offsetY); + } +}; + +PlanningChart.prototype.setZoom = function (zoom, x, y) +{ + var min_zoom_level = -2; + var zoom_upper_limit = 3; + var zoom_factor = 1.5; + zoom = rmp_clamp(zoom, this.options.min_zoom_level, this.options.max_zoom_level); + + if (zoom === this.options.zoom_level) + return; - // Determine new width and height - var new_w = Math.round(this.chart_area.width() / Math.pow(this.options.zoom_factor, zoom)); - var new_h = Math.round(this.chart_area.height() / Math.pow(this.options.zoom_factor, zoom)); + this.options.zoom_level = zoom; - // We want the center to go to the point where the scroll button was hit - var center_pos = this.clientToCanvas(e.offsetX, e.offsetY); - var cx = new_w < this.viewbox.w ? Math.round(center_pos[0] - new_w / 2) : this.viewbox.x; - var cy = new_h < this.viewbox.h ? Math.round(center_pos[1] - new_h / 2) : this.viewbox.y; + // Determine new width and height + var new_w = Math.round(this.chart_area.width() / Math.pow(this.options.zoom_factor, zoom)); + var new_h = Math.round(this.chart_area.height() / Math.pow(this.options.zoom_factor, zoom)); - this.setViewBox(cx, cy, new_w, new_h); + // We want the center to go to the point where the scroll button was hit + var cx = this.viewbox.x; + var cy = this.viewbox.y; + + if (x !== undefined && y !== undefined) + { + console.log([x, y]); + var center_pos = this.clientToCanvas(x, y); + console.log('argh'); + if (new_w < this.viewbox.w) + cx = Math.round(center_pos[0] - new_w / 2); + if (new_h < this.viewbox.h) + cy = Math.round(center_pos[1] - new_h / 2); } + + this.setViewBox(cx, cy, new_w, new_h); }; PlanningChart.prototype.resize = function () @@ -624,6 +643,27 @@ PlanningChart.prototype.setupDOMElements = function () } ], [ + { + type: 'button', + id: 'planning_sort_button', + data: {type: 'sort'}, + icon: 'ion-android-sort', + title: this.t('sort') + }, + { + type: 'button', + id: 'planning_zoom_in_button', + data: {type: 'zoom', direction: 1}, + icon: 'ion-plus-round', + title: this.t('zoom_in') + }, + { + type: 'button', + id: 'planning_zoom_out_button', + data: {type: 'zoom', direction: -1}, + icon: 'ion-minus-round', + title: this.t('zoom_out') + }, { type: 'button', id: 'planning_fullscreen_button', @@ -752,6 +792,13 @@ PlanningChart.prototype.setupDOMElements = function () case "fullscreen": chart.toggleFullscreen(); break; + case "zoom": + chart.setZoom(chart.options.zoom_level + button.data('direction')); + break; + case "sort": + chart.sortIssues(); + chart.draw(); + break; } }); }; diff --git a/config/locales/en.yml b/config/locales/en.yml index d82110d..b245671 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -20,6 +20,9 @@ en: leaf_task: "Leaf task" yes: "yes" no: "no" + sort: "Sort issues" + zoom_in: "Zoom in" + zoom_out: "Zoom out" project: "Project" unavailable: "unavailable" adding_relation_failed: "Adding relation failed" diff --git a/config/locales/nl.yml b/config/locales/nl.yml index c4c43a2..f60b5da 100644 --- a/config/locales/nl.yml +++ b/config/locales/nl.yml @@ -20,6 +20,9 @@ nl: leaf_task: "Kinderloos" yes: "ja" no: "nee" + sort: "Sorteer issues" + zoom_in: "Inzoomen" + zoom_out: "Uitzoomen" project: "Project" unavailable: "niet beschibaar" adding_relation_failed: "Toevoegen relatie is mislukt"