Skip to content

Commit

Permalink
added zoom in and out buttons and sort button
Browse files Browse the repository at this point in the history
  • Loading branch information
EgbertW committed May 29, 2014
1 parent 380e78c commit fbbc862
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 13 deletions.
73 changes: 60 additions & 13 deletions assets/javascripts/planning.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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;
}
});
};
Expand Down
3 changes: 3 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 3 additions & 0 deletions config/locales/nl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit fbbc862

Please sign in to comment.