Allow to save maps.
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
function ScholarCrawler(parser, nodes, edges)
|
||||
{
|
||||
this.stack = [];
|
||||
this.edge_ids = {};
|
||||
this.node_ids = {};
|
||||
|
||||
this.nodes = nodes;
|
||||
this.edges = edges;
|
||||
@@ -121,9 +119,8 @@ ScholarCrawler.prototype._add_child_article = function(child_article, parent_nod
|
||||
|
||||
edge._id = edge.id;
|
||||
|
||||
if(!(edge._id in this.edge_ids))
|
||||
if(this.edges.getIds().indexOf(edge._id) < 0)
|
||||
{
|
||||
this.edge_ids[edge._id] = true;
|
||||
this.edges.add(edge);
|
||||
citations_db.insert(edge);
|
||||
}
|
||||
@@ -136,9 +133,8 @@ ScholarCrawler.prototype._add_child_article = function(child_article, parent_nod
|
||||
else
|
||||
this.push(child_node, levels-1);
|
||||
|
||||
if(!(child_node._id in this.node_ids))
|
||||
if(this.nodes.getIds().indexOf(child_node._id) < 0)
|
||||
{
|
||||
this.node_ids[child_node._id] = true;
|
||||
this.nodes.add(child_node);
|
||||
}
|
||||
else
|
||||
@@ -155,14 +151,14 @@ ScholarCrawler.prototype.push = function(parent_node, levels)
|
||||
if(!parent_node.is_dummy)
|
||||
{
|
||||
parent_node.group = "processing";
|
||||
if(parent_node._id in this.node_ids)
|
||||
if(this.nodes.getIds().indexOf(parent_node._id) >= 0)
|
||||
{
|
||||
this.nodes.update(parent_node);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
ScholarCrawler.prototype.next = function()
|
||||
ScholarCrawler.prototype.start = function()
|
||||
{
|
||||
if(this.stack.length > 0)
|
||||
{
|
||||
@@ -171,5 +167,5 @@ ScholarCrawler.prototype.next = function()
|
||||
}
|
||||
|
||||
var crawler = this;
|
||||
setTimeout(function() { crawler.next() }, 1000);
|
||||
setTimeout(function() { crawler.start() }, 1000);
|
||||
};
|
||||
|
||||
@@ -4,7 +4,7 @@ var nedb = require('nedb');
|
||||
var path = require('path');
|
||||
var win = gui.Window.get();
|
||||
|
||||
win.maximize();
|
||||
//win.maximize();
|
||||
|
||||
function createDB(name)
|
||||
{
|
||||
@@ -22,5 +22,6 @@ function open_external(url)
|
||||
|
||||
var articles_db = createDB("articles");
|
||||
var citations_db = createDB("citations");
|
||||
var maps_db = createDB("maps");
|
||||
|
||||
new MainMenuView().render(document.getElementById("main"));
|
||||
|
||||
8
src/app/model/map.js
Normal file
8
src/app/model/map.js
Normal file
@@ -0,0 +1,8 @@
|
||||
function ScholarMap(seed_url)
|
||||
{
|
||||
this.edges = [];
|
||||
this.nodes = [];
|
||||
this.seed_url = seed_url;
|
||||
this.is_initialized = false;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
<div class="frame">
|
||||
<h1>Scholarium</h1>
|
||||
<form action="">
|
||||
<input name="url" autocomplete="off"></input>
|
||||
</form>
|
||||
<div class="outer_frame">
|
||||
<div class="widget_box search_box">
|
||||
<h1>Scholarium</h1>
|
||||
<form action="">
|
||||
<input name="url" autocomplete="off"></input>
|
||||
</form>
|
||||
</div>
|
||||
<div class="widget_box">
|
||||
<h2>Saved maps</h2>
|
||||
<ul id="saved_maps_container"></ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -5,13 +5,34 @@ MainMenuView.prototype.render = function(container)
|
||||
var main_menu_div = document.createElement("div");
|
||||
$(main_menu_div).addClass("main_menu");
|
||||
|
||||
$(main_menu_div).load("app/templates/main_menu.html", function() {
|
||||
document.forms[0].onsubmit = function() {
|
||||
$(main_menu_div).load("app/templates/main_menu.html", function()
|
||||
{
|
||||
document.forms[0].onsubmit = function()
|
||||
{
|
||||
var seed_url = $("input[name=url]").val();
|
||||
var view = new ShowMapView(seed_url);
|
||||
var view = new ShowMapView(new ScholarMap(seed_url));
|
||||
view.render(container);
|
||||
return false;
|
||||
};
|
||||
|
||||
maps_db.find({}, function(err, maps)
|
||||
{
|
||||
maps.forEach(function(map)
|
||||
{
|
||||
var ul = document.getElementById('saved_maps_container');
|
||||
var li = document.createElement("li");
|
||||
var a = document.createElement("a");
|
||||
a.onclick = function() {
|
||||
new ShowMapView(map).render(container);
|
||||
return false;
|
||||
};
|
||||
a.href = "";
|
||||
$(a).append(map.nodes[0].title);
|
||||
li.appendChild(a);
|
||||
ul.appendChild(li);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
$(container).empty();
|
||||
|
||||
@@ -1,33 +1,58 @@
|
||||
function ShowMapView(seed_url) {
|
||||
this.seed_url = seed_url;
|
||||
//function ShowMapView(seed_url) {
|
||||
// this.seed_url = seed_url;
|
||||
//};
|
||||
|
||||
function ShowMapView(map) {
|
||||
this.map = map;
|
||||
};
|
||||
|
||||
ShowMapView.prototype.render = function(container)
|
||||
{
|
||||
var edges = new vis.DataSet();
|
||||
var nodes = new vis.DataSet();
|
||||
this.nodes = new vis.DataSet();
|
||||
this.edges = new vis.DataSet();
|
||||
|
||||
this.nodes.add(this.map.nodes);
|
||||
this.edges.add(this.map.edges);
|
||||
|
||||
var parser = new ScopusParser();
|
||||
var crawler = new ScholarCrawler(parser, nodes, edges);
|
||||
crawler.push({ is_dummy: true, article: { citations_url: this.seed_url } }, 2);
|
||||
crawler.next();
|
||||
var crawler = new ScholarCrawler(parser, this.nodes, this.edges);
|
||||
crawler.start();
|
||||
|
||||
document.crawler = crawler;
|
||||
|
||||
if(!this.map.is_initialized)
|
||||
{
|
||||
crawler.push({ is_dummy: true, article: { citations_url: this.map.seed_url } }, 2);
|
||||
this.map.is_initialized = true;
|
||||
}
|
||||
|
||||
var network_div = document.createElement('div');
|
||||
$(network_div).addClass("mynetwork");
|
||||
$(container).empty();
|
||||
container.appendChild(network_div)
|
||||
|
||||
var data = { nodes: nodes, edges: edges };
|
||||
var network = new vis.Network(network_div, data, visjs_options);
|
||||
var data = { nodes: this.nodes, edges: this.edges };
|
||||
this.network = new vis.Network(network_div, data, visjs_options);
|
||||
|
||||
network.on('doubleClick', function(params) {
|
||||
this.network.on('doubleClick', function(params) {
|
||||
if(params.nodes.length > 0)
|
||||
crawler.push(nodes.get(params.nodes[0]), 1);
|
||||
});
|
||||
{
|
||||
crawler.push(this.nodes.get(params.nodes[0]), 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
console.log("saving map");
|
||||
this.network.storePosition();
|
||||
this.map.nodes = this.nodes.get();
|
||||
this.map.edges = this.edges.get();
|
||||
if(!this.map._id)
|
||||
maps_db.insert(this.map);
|
||||
else
|
||||
maps_db.update({_id: this.map._id}, this.map);
|
||||
}
|
||||
}.bind(this));
|
||||
|
||||
network.on("resize", function(params) {
|
||||
this.network.on("resize", function(params) {
|
||||
var height = $(window).height();
|
||||
var width = $(window).width();
|
||||
$(".mynetwork").css("width", width);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
@import url(http://fonts.googleapis.com/css?family=Dosis:400,700&subset=latin,latin-ext);
|
||||
|
||||
body {
|
||||
background-color: #066;
|
||||
background-color: #056;
|
||||
}
|
||||
|
||||
html, body {
|
||||
|
||||
@@ -1,36 +1,55 @@
|
||||
.main_menu {
|
||||
text-align: center;
|
||||
font-size: 16px;
|
||||
font-family: sans;
|
||||
height: 100vh;
|
||||
text-align: center;
|
||||
font-size: 16px;
|
||||
font-family: sans;
|
||||
height: 100vh;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.main_menu input {
|
||||
color: #000;
|
||||
background-color: #fff;
|
||||
border: 0;
|
||||
border: 2px solid #fff;
|
||||
color: #000;
|
||||
background-color: #fff;
|
||||
border: 0;
|
||||
border: 2px solid #fff;
|
||||
|
||||
font-size: 20px;
|
||||
font-size: 20px;
|
||||
min-width: 600px;
|
||||
padding: 8px 12px;
|
||||
outline: 0;
|
||||
padding: 8px 12px;
|
||||
outline: 0;
|
||||
|
||||
}
|
||||
|
||||
.main_menu h1 {
|
||||
color: #fff;
|
||||
font-size: 60px;
|
||||
.main_menu h1,
|
||||
.main_menu h2 {
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
.main_menu .frame {
|
||||
margin: 0 auto;
|
||||
padding: 1px 1px 50px 1px;
|
||||
background-color: rgba(0,0,0,0);
|
||||
box-shadow: 2px 2px 100px #388;
|
||||
width: 800px;
|
||||
|
||||
top: 50%;
|
||||
position: relative;
|
||||
-webkit-transform: translateY(-50%);
|
||||
.main_menu h1 {
|
||||
font-size: 60px;
|
||||
}
|
||||
|
||||
.main_menu .widget_box {
|
||||
margin: 10px auto;
|
||||
padding: 1px 1px 50px 1px;
|
||||
background-color: rgba(255,255,255,0.03);
|
||||
box-shadow: 0px 0px 30px #378;
|
||||
width: 800px;
|
||||
|
||||
}
|
||||
|
||||
.main_menu .outer_frame {
|
||||
padding: 1px;
|
||||
top: 50%;
|
||||
position: relative;
|
||||
-webkit-transform: translateY(-50%);
|
||||
}
|
||||
|
||||
.main_menu ul {
|
||||
text-align: left;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.main_menu a {
|
||||
color: #fff;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
@@ -1,25 +1,27 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Scholar Explorer</title>
|
||||
<title>Scholar Explorer</title>
|
||||
|
||||
<script type="text/javascript" src="lib/jquery.min.js"></script>
|
||||
<script type="text/javascript" src="lib/vis.js"></script>
|
||||
<script type="text/javascript" src="lib/md5.js"></script>
|
||||
<script type="text/javascript" src="lib/jquery.min.js"></script>
|
||||
<script type="text/javascript" src="lib/vis.js"></script>
|
||||
<script type="text/javascript" src="lib/md5.js"></script>
|
||||
|
||||
<script type="text/javascript" src="app/scopus.js"></script>
|
||||
<script type="text/javascript" src="app/crawler.js"></script>
|
||||
<script type="text/javascript" src="app/config.js"></script>
|
||||
<script type="text/javascript" src="app/scopus.js"></script>
|
||||
<script type="text/javascript" src="app/crawler.js"></script>
|
||||
<script type="text/javascript" src="app/config.js"></script>
|
||||
|
||||
<script type="text/javascript" src="app/views/show_map.js"></script>
|
||||
<script type="text/javascript" src="app/views/main_menu.js"></script>
|
||||
<script type="text/javascript" src="app/model/map.js"></script>
|
||||
|
||||
<link rel="stylesheet" type="text/css" href="css/main.css">
|
||||
<link rel="stylesheet" type="text/css" href="css/main_menu.css">
|
||||
<script type="text/javascript" src="app/views/show_map.js"></script>
|
||||
<script type="text/javascript" src="app/views/main_menu.js"></script>
|
||||
|
||||
<link rel="stylesheet" type="text/css" href="css/main.css">
|
||||
<link rel="stylesheet" type="text/css" href="css/main_menu.css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="main"></div>
|
||||
<script type="text/javascript" src="app/main.js"></script>
|
||||
<div id="main"></div>
|
||||
<script type="text/javascript" src="app/main.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user