diff --git a/app/assets/javascripts/metamaps/Metamaps.JIT.js b/app/assets/javascripts/metamaps/Metamaps.JIT.js index 8c6cb11e..41ff23ba 100644 --- a/app/assets/javascripts/metamaps/Metamaps.JIT.js +++ b/app/assets/javascripts/metamaps/Metamaps.JIT.js @@ -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); + } + } }; \ No newline at end of file diff --git a/app/assets/javascripts/metamaps/Metamaps.js b/app/assets/javascripts/metamaps/Metamaps.js index 61dd77f5..820c6395 100644 --- a/app/assets/javascripts/metamaps/Metamaps.js +++ b/app/assets/javascripts/metamaps/Metamaps.js @@ -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()); } }); diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 9d17ce88..d7b824bb 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -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; } diff --git a/app/views/maps/show.html.erb b/app/views/maps/show.html.erb index 19924710..77cb06f9 100644 --- a/app/views/maps/show.html.erb +++ b/app/views/maps/show.html.erb @@ -42,6 +42,11 @@ +
+
+
-
+
C
+
E
+
diff --git a/db/schema.rb b/db/schema.rb index ec86b421..c3fce2b2 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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