Skip to content

Commit

Permalink
Users are allowed to set a zoom-in&zoom-out limit
Browse files Browse the repository at this point in the history
  • Loading branch information
dabeng committed Mar 4, 2017
1 parent 0db0520 commit c73a0e0
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,12 @@ $('#chartContainerId').orgchart(options);
<tr>
<td>zoom</td><td>boolean</td><td>no</td><td>false</td><td>Users could zoomin/zoomout the orgchart by mouse wheel if they enable this option.</td>
</tr>
<tr>
<td>zoominLimit</td><td>number</td><td>no</td><td>7</td><td>Users are allowed to set a zoom-in limit.</td>
</tr>
<tr>
<td>zoomoutLimit</td><td>number</td><td>no</td><td>0.5</td><td>Users are allowed to set a zoom-out limit.</td>
</tr>
<tr>
<td>direction</td><td>string</td><td>no</td><td>"t2b"</td><td>The available values are t2b(implies "top to bottom", it's default value), b2t(implies "bottom to top"), l2r(implies "left to right"), r2l(implies "right to left").</td>
</tr>
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "orgchart",
"version": "1.3.5",
"version": "1.3.6",
"homepage": "https://github.com/dabeng/OrgChart",
"authors": [
"dabeng <[email protected]>"
Expand Down
18 changes: 15 additions & 3 deletions dist/js/jquery.orgchart.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
'draggable': false,
'direction': 't2b',
'pan': false,
'zoom': false
'zoom': false,
'zoominLimit': 7,
'zoomoutLimit': 0.5
};

switch (options) {
Expand Down Expand Up @@ -293,14 +295,24 @@
}

function setChartScale($chart, newScale) {
var opts = $chart.data('options');
var lastTf = $chart.css('transform');
var matrix = '';
var targetScale = 1;
if (lastTf === 'none') {
$chart.css('transform', 'scale(' + newScale + ',' + newScale + ')');
} else {
matrix = lastTf.split(',');
if (lastTf.indexOf('3d') === -1) {
$chart.css('transform', lastTf + ' scale(' + newScale + ',' + newScale + ')');
targetScale = window.parseFloat(matrix[3]) * newScale;
if (targetScale > opts.zoomoutLimit && targetScale < opts.zoominLimit) {
$chart.css('transform', lastTf + ' scale(' + newScale + ',' + newScale + ')');
}
} else {
$chart.css('transform', lastTf + ' scale3d(' + newScale + ',' + newScale + ', 1)');
targetScale = window.parseFloat(matrix[1]) * newScale;
if (targetScale > opts.zoomoutLimit && targetScale < opts.zoominLimit) {
$chart.css('transform', lastTf + ' scale3d(' + newScale + ',' + newScale + ', 1)');
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "orgchart",
"version": "1.3.5",
"version": "1.3.6",
"description": "Simple and direct organization chart(tree-like hierarchy) plugin based on pure DOM and jQuery.",
"main": "./dist/js/jquery.orgchart.js",
"style": [
Expand Down

0 comments on commit c73a0e0

Please sign in to comment.