Commit 45fec358 authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

cleanup zoom code.

parent 39d400d1
...@@ -304,7 +304,7 @@ path, ._jsPlumb_endpoint { ...@@ -304,7 +304,7 @@ path, ._jsPlumb_endpoint {
background-color:#fdd; background-color:#fdd;
} }
.window { .window, .dummy_window {
border:1px solid lightgray; border:1px solid lightgray;
width:100px; width:100px;
height:64px; height:64px;
...@@ -327,6 +327,13 @@ path, ._jsPlumb_endpoint { ...@@ -327,6 +327,13 @@ path, ._jsPlumb_endpoint {
color:white; color:white;
} }
.dummy_window {
position: absolute;
top: 0;
left: 0;
visibility: hidden;
}
#debug textarea { #debug textarea {
width:100%; width:100%;
} }
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
<body data-demo-id="flowchartConnectorsDemo" data-library="jquery"> <body data-demo-id="flowchartConnectorsDemo" data-library="jquery">
<div class="container"> <div class="container">
<div class="dummy_window"></div>
<div id="headerWrapper"> <div id="headerWrapper">
<div id="header"></div> <div id="header"></div>
</div> </div>
......
...@@ -149,62 +149,36 @@ ...@@ -149,62 +149,36 @@
}; };
priv.updateNodeStyle = function (element_id) { priv.updateNodeStyle = function (element_id) {
var node_style = priv.preference_container['node_style']; var zoom_level = (priv.preference_container['zoom_level'] || 1.0) * 1.1111;
var element = $("#" + element_id); var element = $("#" + element_id);
if (node_style !== undefined) { $.each(priv.style_attr_list, function (i, j) {
element.css(node_style); var new_value = $('.dummy_window').css(j).replace('px', '') * zoom_level + 'px';
} else { element.css(j, new_value);
var style_dict = {}; });
$.each(priv.style_attr_list, function (i, j) {
style_dict[j] = $('.window').css(j);
});
priv.saveNodeStyle(style_dict);
}
}; };
priv.convertToAbsolutePosition = function (x, y) { priv.convertToAbsolutePosition = function (x, y) {
var zoom_level = (priv.preference_container['zoom_level'] || 1.0) * 1.1111;
var canvas_size_x = $('#main').width(); var canvas_size_x = $('#main').width();
var canvas_size_y = $('#main').height(); var canvas_size_y = $('#main').height();
var node_style = priv.preference_container['node_style']; var size_x = $('.dummy_window').width() * zoom_level;
var size_x, size_y; var size_y = $('.dummy_window').height() * zoom_level;
if (node_style === undefined) {
size_x = $('.window').css('width').replace('px', '');
size_y = $('.window').css('height').replace('px', '');
} else {
size_x = node_style['width'].replace('px', '');
size_y = node_style['height'].replace('px', '');
}
var top = Math.floor(y * (canvas_size_y - size_y)) + "px"; var top = Math.floor(y * (canvas_size_y - size_y)) + "px";
var left = Math.floor(x * (canvas_size_x - size_x)) + "px"; var left = Math.floor(x * (canvas_size_x - size_x)) + "px";
return [left, top]; return [left, top];
}; };
that.convertToRelativePosition = function (x, y) { that.convertToRelativePosition = function (x, y) {
var zoom_level = (priv.preference_container['zoom_level'] || 1.0) * 1.1111;
var canvas_size_x = $('#main').width(); var canvas_size_x = $('#main').width();
var canvas_size_y = $('#main').height(); var canvas_size_y = $('#main').height();
var node_style = priv.preference_container['node_style']; var size_x = $('.dummy_window').width() * zoom_level;
var size_x, size_y; var size_y = $('.dummy_window').height() * zoom_level;
if (node_style === undefined) {
size_x = $('.window').width();
size_y = $('.window').height();
} else {
size_x = node_style['width'].replace('px', '');
size_y = node_style['height'].replace('px', '');
}
var top = Math.max(Math.min(y.replace('px', '') / (canvas_size_y - size_y), 1), 0); var top = Math.max(Math.min(y.replace('px', '') / (canvas_size_y - size_y), 1), 0);
var left = Math.max(Math.min(x.replace('px', '') / (canvas_size_x - size_x), 1), 0); var left = Math.max(Math.min(x.replace('px', '') / (canvas_size_x - size_x), 1), 0);
return [left, top]; return [left, top];
}; };
priv.saveNodeStyle = function (style_dict) {
var node_style = priv.preference_container['node_style'] || {};
$.each(style_dict, function (k, v) {
node_style[k] = v;
});
priv.preference_container['node_style'] = node_style;
priv.onDataChange();
};
priv.draggable = function () { priv.draggable = function () {
// make all the window divs draggable // make all the window divs draggable
var stop = function (element) { var stop = function (element) {
...@@ -278,25 +252,26 @@ ...@@ -278,25 +252,26 @@
}; };
that.zoom_in = function () { that.setZoom = function (zoom_level) {
var style_dict = {};
$.each(priv.style_attr_list, function (i, j) { $.each(priv.style_attr_list, function (i, j) {
var new_value = $('.window').css(j).replace('px', '') * 1.1111 + 'px'; var new_value = $('.dummy_window').css(j).replace('px', '') * zoom_level + 'px';
$('.window').css(j, new_value); $('.window').css(j, new_value);
style_dict[j] = new_value;
}); });
priv.saveNodeStyle(style_dict); };
that.zoom_in = function () {
var zoom_level = (priv.preference_container['zoom_level'] || 1.0) * 1.1111;
that.setZoom(zoom_level);
priv.preference_container['zoom_level'] = zoom_level;
priv.onDataChange();
that.redraw(); that.redraw();
}; };
that.zoom_out = function () { that.zoom_out = function () {
var style_dict = {}; var zoom_level = (priv.preference_container['zoom_level'] || 1.0) * 0.9;
$.each(priv.style_attr_list, function (i, j) { that.setZoom(zoom_level);
var new_value = $('.window').css(j).replace('px', '') * 0.9 + 'px'; priv.preference_container['zoom_level'] = zoom_level;
$('.window').css(j, new_value); priv.onDataChange();
style_dict[j] = new_value;
});
priv.saveNodeStyle(style_dict);
that.redraw(); that.redraw();
}; };
...@@ -400,6 +375,8 @@ ...@@ -400,6 +375,8 @@
that.setPreferences = function (preferences) { that.setPreferences = function (preferences) {
priv.preference_container = preferences; priv.preference_container = preferences;
var zoom_level = priv.preference_container['zoom_level'] || 1.0;
that.setZoom(zoom_level);
}; };
that.setGeneralProperties = function (properties) { that.setGeneralProperties = function (properties) {
...@@ -423,7 +400,7 @@ ...@@ -423,7 +400,7 @@
coordinate.left, coordinate.top); coordinate.left, coordinate.top);
box.css("top", absolute_position[1]); box.css("top", absolute_position[1]);
box.css("left", absolute_position[0]); box.css("left", absolute_position[0]);
priv.updateNodeStyle(element.id); priv.updateNodeStyle(element.element_id);
// Initial DEMO code : make all the window divs draggable // Initial DEMO code : make all the window divs draggable
priv.draggable(); priv.draggable();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment