Skip to content

Commit

Permalink
d3
Browse files Browse the repository at this point in the history
  • Loading branch information
leodc committed May 2, 2016
1 parent bbcaaaf commit f6bfeda
Show file tree
Hide file tree
Showing 20 changed files with 3,055 additions and 148 deletions.
134 changes: 86 additions & 48 deletions lovelace.js
Original file line number Diff line number Diff line change
@@ -1,65 +1,103 @@
/**
* Module Dependencies
* */
var express = require('express');
var app = express();
var http = require('http').Server(app);
var path = require('path');
var bodyParser = require('body-parser');
var io = require('socket.io')(http);
var rethinkdb = require("./rethinkDB.js");
var mongoDB = require("./mongoDB.js");
var pgrouting = require("./pgrouting.js");
var express = require('express');
var app = express();
var http = require('http').Server(app);
var path = require('path');
var bodyParser = require('body-parser');
var io = require('socket.io')(http);
var rethinkdb = require("./rethinkDB.js");
var mongoDB = require("./mongoDB.js");
var pgrouting = require("./pgrouting.js");



/**
* View engine
* */
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');

app.use(bodyParser.json()); //json as param support
app.use(bodyParser.urlencoded({ extended: false })); //data as param support

app.use(express.static(path.join(__dirname, 'public'))); //Make resources public
app.use('/mapa', express.static('public')); //Make resources public at mapa/css/xxx
app.use(express.static(path.join(__dirname, 'test'))); //Make test directory public... for... testing....


/**
*
* Set rethinkDB and mongoDB... and pgrouting as a global resource.
* Somebody please optimize this @_@.
*
* */
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");

req.rethinkdb = rethinkdb;
req.mongoDB = mongoDB;
req.pgrouting = pgrouting;
req.io = io;

next();
});
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');

app.use(bodyParser.json()); //json as param support
app.use(bodyParser.urlencoded({ extended: false })); //data as param support

app.use(express.static(path.join(__dirname, 'public'))); //Make resources public
app.use('/map', express.static('public')); //Make resources public at mapa/css/xxx
app.use('/cars', express.static('public')); //Make resources public at car/css/xxx
app.use(express.static(path.join(__dirname, 'test'))); //Make test directory public... for... testing....



/**
* Set rethinkDB and mongoDB... and pgrouting as a global resource.
* Someday i'm going to optimize this @_@...
* */
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");

req.rethinkdb = rethinkdb;
req.mongoDB = mongoDB;
req.pgrouting = pgrouting;
req.io = io;

next();
});



/**
*
* Routers controllers
*
* */
var indexRouter = require("./routes/router.js");
var mapaRouter = require("./routes/map.js");
var carRouter = require("./routes/car.js");
var tripsRouter = require("./routes/trips.js");

var indexRouter = require("./routes/router.js");
var mapaRouter = require("./routes/map.js");
var carRouter = require("./routes/car.js");
var carsRouter = require("./routes/cars.js");


app.use("/", indexRouter);
app.use("/map", mapaRouter);
app.use("/car", carRouter);
app.use("/cars", carsRouter);

app.use("/", indexRouter);
app.use("/map", mapaRouter);
app.use("/car", carRouter);
app.use("/trips", tripsRouter);


/**
* Socket handlers
* */
io.on('connection', function(socket){

socket.on("carsData", function(){
mongoDB.getCollections(function(collections){
for(var i = 0; i < collections.length; i++){
findAndEmit(collections[i].name, socket);
}
});
});

socket.on("carFeatures", function(idCar) {
mongoDB.getCollectionData({},idCar, function(err, data) {
if(!err){
socket.emit("carFeatures", data);
}
});
});
});


function findAndEmit(idCar, socket){
mongoDB.getCollectionData({collectionProperties: true}, idCar, function(err,data){
if( !err ){
var transferObject = {
idCar: idCar,
data: data[0]
};

socket.emit("carData", transferObject);
}
});
}


/**
Expand Down
15 changes: 10 additions & 5 deletions mongoDB.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ var mongodb = require('mongodb');
* */
var HOST = "107.170.232.222";
var PORT = 27017;
var DB = "lovelace_test";
var COLLECTION = "cars";
var DB = "lovelace";


/**
Expand All @@ -36,6 +35,8 @@ var insert = function(idCar, data, callback){
* Updates the collection properties of the car: new_collection.properties.idCar
* */
var updateCollectionProperties = function(collection, last_trip, callback){
delete last_trip.isochrone;

var server = new mongodb.Server(HOST, PORT);
var db = new mongodb.Db(DB, server);

Expand Down Expand Up @@ -84,13 +85,17 @@ var getCollections = function(callback){

db.listCollections().toArray(function(err, collectionsNames){
db.close();
callback(err, collectionsNames);
if(err){
console.log("Error getting the collection names", err);
}else{
callback(collectionsNames);
}
});
});
};


var getCollectionData = function(collection, callback){
var getCollectionData = function(filter, collection, callback){
var server = new mongodb.Server(HOST, PORT);
var db = new mongodb.Db(DB, server);

Expand All @@ -99,7 +104,7 @@ var getCollectionData = function(collection, callback){
console.log("Error ", err);
}

client.collection(collection).find().toArray(function(err, result){
client.collection(collection).find(filter).toArray(function(err, result){
db.close();
callback(err,result);
});
Expand Down
32 changes: 32 additions & 0 deletions public/css/car.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
svg {
font: 10px sans-serif;
}

.background path {
fill: none;
stroke: #ddd;
shape-rendering: crispEdges;
}

.foreground path {
fill: none;
stroke: steelblue;
}

.brush .extent {
fill-opacity: .3;
stroke: #fff;
shape-rendering: crispEdges;
}

.axis line,
.axis path {
fill: none;
stroke: #000;
shape-rendering: crispEdges;
}

.axis text {
text-shadow: 0 1px 0 #fff, 1px 0 0 #fff, 0 -1px 0 #fff, -1px 0 0 #fff;
cursor: move;
}
48 changes: 48 additions & 0 deletions public/js/d3/d3.parcoords.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
.parcoords > svg, .parcoords > canvas {
font: 14px sans-serif;
position: absolute;
}
.parcoords > canvas {
pointer-events: none;
}

.parcoords text.label {
cursor: default;
}

.parcoords rect.background {
fill: transparent;
}
.parcoords rect.background:hover {
fill: rgba(120,120,120,0.2);
}
.parcoords .resize rect {
fill: rgba(0,0,0,0.1);
}
.parcoords rect.extent {
fill: rgba(255,255,255,0.25);
stroke: rgba(0,0,0,0.6);
}
.parcoords .axis line, .parcoords .axis path {
fill: none;
stroke: #222;
shape-rendering: crispEdges;
}
.parcoords canvas {
opacity: 1;
-moz-transition: opacity 0.3s;
-webkit-transition: opacity 0.3s;
-o-transition: opacity 0.3s;
}
.parcoords canvas.faded {
opacity: 0.25;
}
.parcoords {
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
background-color: white;
}
Loading

0 comments on commit f6bfeda

Please sign in to comment.