Added Recenter map, zoom in, zoom out, Zoom to extents and buttons for each. Also, renamed selection function to just SelectWithBox()

This commit is contained in:
Robert Best 2014-08-06 04:22:06 -04:00
parent 910c6a8984
commit f75c2c1f8a
5 changed files with 271 additions and 135 deletions

View file

@ -8,6 +8,10 @@ Metamaps.JIT = {
var self = Metamaps.JIT;
self.prepareVizData();
$(".zoomIn").click(self.zoomIn);
$(".zoomOut").click(self.zoomOut);
$(".centerMap").click(self.centerMap);
$(".zoomExtents").click(self.zoomExtents);
},
/**
* convert our topic JSON into something JIT can use
@ -307,7 +311,7 @@ Metamaps.JIT = {
if (Metamaps.Mouse.boxStartCoordinates) {
Metamaps.Visualize.mGraph.busy = false;
Metamaps.Mouse.boxEndCoordinates = eventInfo.getPos();
Metamaps.JIT.selectNodesWithBox(e);
Metamaps.JIT.selectWithBox(e);
return;
}
@ -331,7 +335,7 @@ Metamaps.JIT = {
if (Metamaps.Mouse.boxStartCoordinates) {
Metamaps.Visualize.mGraph.busy = false;
Metamaps.Mouse.boxEndCoordinates = eventInfo.getPos();
Metamaps.JIT.selectNodesWithBox(e);
Metamaps.JIT.selectWithBox(e);
return;
}
@ -897,7 +901,7 @@ Metamaps.JIT = {
}
return 'nothing'; //case 4?
}, // handleSelectionBeforeDragging
selectNodesWithBox: function (e) {
selectWithBox: function (e) {
var sX = Metamaps.Mouse.boxStartCoordinates.x,
sY = Metamaps.Mouse.boxStartCoordinates.y,
@ -1025,7 +1029,7 @@ Metamaps.JIT = {
Metamaps.Mouse.boxStartCoordinates = false;
Metamaps.Mouse.boxEndCoordinates = false;
Metamaps.Visualize.mGraph.plot();
}, // selectNodesWithBox
}, // selectWithBox
drawSelectBox: function (eventInfo, e) {
var ctx = Metamaps.Visualize.mGraph.canvas.getCtx();
@ -1425,5 +1429,91 @@ Metamaps.JIT = {
y: posChild.y
}, 13, inv, canvas, 0.3);
}
} //renderEdgeArrows
}, //renderEdgeArrows
zoomIn: function () {
Metamaps.Visualize.mGraph.canvas.scale(1.25,1.25);
},
zoomOut: function () {
Metamaps.Visualize.mGraph.canvas.scale(0.8,0.8);
},
centerMap: function () {
var canvas = Metamaps.Visualize.mGraph.canvas;
var offsetScale = canvas.scaleOffsetX;
canvas.scale(1/offsetScale,1/offsetScale);
var offsetX = canvas.translateOffsetX;
var offsetY = canvas.translateOffsetY;
canvas.translate(-1*offsetX,-1*offsetY);
},
zoomExtents: function () {
Metamaps.JIT.centerMap();
var height = $(document).height(),
width = $(document).width(),
maxX, minX, maxY, minY, counter = 0;
var nodes = Metamaps.Visualize.mGraph.graph;
if(Object.keys(nodes).length >1){
nodes.eachNode(function (n) {
var x = n.pos.x,
y = n.pos.y;
if (counter == 0){
maxX = x;
minX = x;
maxY = y;
minY = y;
}
maxX = Math.max(x,maxX);
maxY = Math.max(y,maxY);
minX = Math.min(x,minX);
minY = Math.min(y,minY);
counter++;
});
var spanX = maxX - minX;
var spanY = maxY - minY;
var ratioX = spanX / width;
var ratioY = spanY / height;
var newRatio = Math.max(ratioX,ratioY);
var canvas = Metamaps.Visualize.mGraph.canvas;
canvas.scale(1/newRatio*0.9,1/newRatio*0.9);
counter = 0;
nodes.eachNode(function (n) {
var x = n.pos.x,
y = n.pos.y;
if (counter == 0){
maxX = x;
minX = x;
maxY = y;
minY = y;
}
maxX = Math.max(x,maxX);
maxY = Math.max(y,maxY);
minX = Math.min(x,minX);
minY = Math.min(y,minY);
counter++;
});
var cogX = (maxX + minX)/2;
var cogY = (maxY + minY)/2;
canvas.translate(-1* cogX, -1* cogY);
}
}
};

View file

@ -2060,7 +2060,7 @@ Metamaps.Filter = {
var addedSynapses = [];
Metamaps.Synapses.each(function(synapse) {
if (newSynapsesList.indexOf(synapse.get('desc')) === -1) {
if (synapse.get('desc') && newSynapsesList.indexOf(synapse.get('desc')) === -1) {
newSynapsesList.push(synapse.get('desc').toString());
}
});

View file

@ -791,6 +791,47 @@ li.accountInvite span {
width: 35px;
height: 35px;
}
.zoomIn {
position: absolute;
bottom: 100px;
right: 20px;
z-index: 200;
width: 35px;
height: 35px;
background: blue;
}
.zoomOut {
position: absolute;
bottom: 60px;
right: 20px;
z-index: 200;
width: 35px;
height: 35px;
background: blue;
}
.centerMap {
position: absolute;
bottom: 140px;
right: 20px;
z-index: 200;
width: 35px;
height: 35px;
background: blue;
}
.zoomExtents {
position: absolute;
bottom: 180px;
right: 20px;
z-index: 200;
width: 35px;
height: 35px;
background: blue;
}
.sidebarFilter.loggedout {
right: 35px;
}

View file

@ -42,6 +42,11 @@
</div>
</div>
<div class="zoomIn">+</div>
<div class="zoomOut">-</div>
<div class="centerMap">C</div>
<div class="zoomExtents">E</div>
<div class="index">
<div class="openCheatsheet openLightbox" data-open="cheatsheet"></div>
<span class="mapInfo"></span>

View file

@ -1,129 +1,129 @@
# encoding: UTF-8
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# Note that this schema.rb definition is the authoritative source for your
# database schema. If you need to create the application database on another
# system, you should be using db:schema:load, not running all the migrations
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
# you'll amass, the slower it'll run and the greater likelihood for issues).
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20140707161810) do
create_table "in_metacode_sets", :force => true do |t|
t.integer "metacode_id"
t.integer "metacode_set_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
add_index "in_metacode_sets", ["metacode_id"], :name => "index_in_metacode_sets_on_metacode_id"
add_index "in_metacode_sets", ["metacode_set_id"], :name => "index_in_metacode_sets_on_metacode_set_id"
create_table "mappings", :force => true do |t|
t.text "category"
t.integer "xloc"
t.integer "yloc"
t.integer "topic_id"
t.integer "synapse_id"
t.integer "map_id"
t.integer "user_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "maps", :force => true do |t|
t.text "name"
t.boolean "arranged"
t.text "desc"
t.text "permission"
t.integer "user_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.boolean "featured"
end
create_table "metacode_sets", :force => true do |t|
t.string "name"
t.text "desc"
t.integer "user_id"
t.boolean "mapperContributed"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
add_index "metacode_sets", ["user_id"], :name => "index_metacode_sets_on_user_id"
create_table "metacodes", :force => true do |t|
t.text "name"
t.string "icon"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "synapses", :force => true do |t|
t.text "desc"
t.text "category"
t.text "weight"
t.text "permission"
t.integer "node1_id"
t.integer "node2_id"
t.integer "user_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "topics", :force => true do |t|
t.text "name"
t.text "desc"
t.text "link"
t.text "permission"
t.integer "user_id"
t.integer "metacode_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "image_file_name"
t.string "image_content_type"
t.integer "image_file_size"
t.datetime "image_updated_at"
t.string "audio_file_name"
t.string "audio_content_type"
t.integer "audio_file_size"
t.datetime "audio_updated_at"
end
create_table "users", :force => true do |t|
t.string "name"
t.string "email"
t.text "settings"
t.string "code", :limit => 8
t.string "joinedwithcode", :limit => 8
t.string "crypted_password"
t.string "password_salt"
t.string "persistence_token"
t.string "perishable_token"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "encrypted_password", :limit => 128, :default => ""
t.string "remember_token"
t.datetime "remember_created_at"
t.string "reset_password_token"
t.datetime "last_sign_in_at"
t.string "last_sign_in_ip"
t.integer "sign_in_count", :default => 0
t.datetime "current_sign_in_at"
t.string "current_sign_in_ip"
t.datetime "reset_password_sent_at"
t.boolean "admin"
t.string "image_file_name"
t.string "image_content_type"
t.integer "image_file_size"
t.datetime "image_updated_at"
end
add_index "users", ["reset_password_token"], :name => "index_users_on_reset_password_token", :unique => true
end
# encoding: UTF-8
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# Note that this schema.rb definition is the authoritative source for your
# database schema. If you need to create the application database on another
# system, you should be using db:schema:load, not running all the migrations
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
# you'll amass, the slower it'll run and the greater likelihood for issues).
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20140707161810) do
create_table "in_metacode_sets", :force => true do |t|
t.integer "metacode_id"
t.integer "metacode_set_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
add_index "in_metacode_sets", ["metacode_id"], :name => "index_in_metacode_sets_on_metacode_id"
add_index "in_metacode_sets", ["metacode_set_id"], :name => "index_in_metacode_sets_on_metacode_set_id"
create_table "mappings", :force => true do |t|
t.text "category"
t.integer "xloc"
t.integer "yloc"
t.integer "topic_id"
t.integer "synapse_id"
t.integer "map_id"
t.integer "user_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "maps", :force => true do |t|
t.text "name"
t.boolean "arranged"
t.text "desc"
t.text "permission"
t.integer "user_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.boolean "featured"
end
create_table "metacode_sets", :force => true do |t|
t.string "name"
t.text "desc"
t.integer "user_id"
t.boolean "mapperContributed"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
add_index "metacode_sets", ["user_id"], :name => "index_metacode_sets_on_user_id"
create_table "metacodes", :force => true do |t|
t.text "name"
t.string "icon"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "synapses", :force => true do |t|
t.text "desc"
t.text "category"
t.text "weight"
t.text "permission"
t.integer "node1_id"
t.integer "node2_id"
t.integer "user_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "topics", :force => true do |t|
t.text "name"
t.text "desc"
t.text "link"
t.text "permission"
t.integer "user_id"
t.integer "metacode_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "image_file_name"
t.string "image_content_type"
t.integer "image_file_size"
t.datetime "image_updated_at"
t.string "audio_file_name"
t.string "audio_content_type"
t.integer "audio_file_size"
t.datetime "audio_updated_at"
end
create_table "users", :force => true do |t|
t.string "name"
t.string "email"
t.text "settings"
t.string "code", :limit => 8
t.string "joinedwithcode", :limit => 8
t.string "crypted_password"
t.string "password_salt"
t.string "persistence_token"
t.string "perishable_token"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "encrypted_password", :limit => 128, :default => ""
t.string "remember_token"
t.datetime "remember_created_at"
t.string "reset_password_token"
t.datetime "last_sign_in_at"
t.string "last_sign_in_ip"
t.integer "sign_in_count", :default => 0
t.datetime "current_sign_in_at"
t.string "current_sign_in_ip"
t.datetime "reset_password_sent_at"
t.boolean "admin"
t.string "image_file_name"
t.string "image_content_type"
t.integer "image_file_size"
t.datetime "image_updated_at"
end
add_index "users", ["reset_password_token"], :name => "index_users_on_reset_password_token", :unique => true
end