Commit 4e3e4799 authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

store node positions in relative value (0 to 1).

parent 65b11f73
...@@ -216,8 +216,8 @@ ...@@ -216,8 +216,8 @@
stop: function (tool) { stop: function (tool) {
var box_top, box_left, _class; var box_top, box_left, _class;
var offset = $("[id=render]").offset(); var offset = $("[id=render]").offset();
box_top = tool.clientY - offset.top + "px"; box_top = (tool.clientY - offset.top) / $('#main').height();
box_left = tool.clientX - offset.left + "px"; box_left = (tool.clientX - offset.left) / $('#main').width();
id_container[tool.target.id] = (id_container[tool.target.id] || 0) + id_container[tool.target.id] = (id_container[tool.target.id] || 0) +
1; 1;
_class = tool.target.id.replace('-', '.'); // XXX - vs . _class = tool.target.id.replace('-', '.'); // XXX - vs .
......
...@@ -112,8 +112,10 @@ ...@@ -112,8 +112,10 @@
if (coordinate === undefined) { if (coordinate === undefined) {
coordinate = {}; coordinate = {};
element = $("#" + element_id); element = $("#" + element_id);
coordinate.top = element.css("top"); var relative_position = priv.convertToRelativePosition(
coordinate.left = element.css("left"); element.css('left'), element.css('top'));
coordinate.top = relative_position[1];
coordinate.left = relative_position[0];
} }
coordinates[element_id] = coordinate; coordinates[element_id] = coordinate;
priv.preference_container['coordinates'] = coordinates; priv.preference_container['coordinates'] = coordinates;
...@@ -127,6 +129,26 @@ ...@@ -127,6 +129,26 @@
element.css(node_style); element.css(node_style);
}; };
priv.convertToAbsolutePosition = function(x, y) {
var canvas_size_x = $('#main').width();
var canvas_size_y = $('#main').height();
var size_x = $('.window').width();
var size_y = $('.window').height();
var top = Math.floor(y * (canvas_size_y - size_y)) + "px";
var left = Math.floor(x * (canvas_size_x - size_x)) + "px";
return [left, top];
};
priv.convertToRelativePosition = function(x, y) {
var canvas_size_x = $('#main').width();
var canvas_size_y = $('#main').height();
var size_x = $('.window').width();
var size_y = $('.window').height();
var top = y.replace('px', '') / (pos.top * (canvas_size_y - size_y));
var left = x / (pos.left * (canvas_size_x - size_x));
return [left, top];
};
priv.saveNodeStyle = function (style_dict) { priv.saveNodeStyle = function (style_dict) {
var node_style = priv.preference_container['node_style'] || {}; var node_style = priv.preference_container['node_style'] || {};
$.each(style_dict, function (k, v) { $.each(style_dict, function (k, v) {
...@@ -170,19 +192,15 @@ ...@@ -170,19 +192,15 @@
contentType: 'application/json', contentType: 'application/json',
type: 'POST', type: 'POST',
success: function (data, textStatus, jqXHR) { success: function (data, textStatus, jqXHR) {
var canvas_size_x = $('#main').width();
var canvas_size_y = $('#main').height();
var size_x = $('.window').width();
var size_y = $('.window').height();
$.each(data, function (node, pos) { $.each(data, function (node, pos) {
var top = Math.floor(pos.top * (canvas_size_y - size_y)) + "px"; var absolute_position = priv.convertToAbsolutePosition(
var left = Math.floor(pos.left * (canvas_size_x - size_x)) + "px"; pos.left, pos.top);
priv.updateElementCoordinate(node, { priv.updateElementCoordinate(node, {
top: top, top: pos.top,
left: left left: pos.left
}); });
$('#'+node).css('top', top); $('#'+node).css('top', absolute_position[1]);
$('#'+node).css('left', left); $('#'+node).css('left', absolute_position[0]);
}); });
jsPlumb.repaintEverything(); jsPlumb.repaintEverything();
} }
...@@ -296,8 +314,10 @@ ...@@ -296,8 +314,10 @@
render_element.append('<div class="window ' + element._class.replace('.', '-') + '" id="' + render_element.append('<div class="window ' + element._class.replace('.', '-') + '" id="' +
element.id + '">' + element.id + '</div>'); element.id + '">' + element.id + '</div>');
box = $("#" + element.id); box = $("#" + element.id);
box.css("top", coordinate.top); var absolute_position = priv.convertToAbsolutePosition(
box.css("left", coordinate.left); coordinate.left, coordinate.top);
box.css("top", absolute_position[1]);
box.css("left", absolute_position[0]);
priv.updateNodeStyle(element.id); priv.updateNodeStyle(element.id);
// Initial DEMO code : make all the window divs draggable // Initial DEMO code : make all the window divs 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