New maps in progress. Added tooltip plugin to test.

This commit is contained in:
Arturo Gonzalez 2016-02-18 10:51:33 +01:00
parent fb3b4d8a6f
commit 42e962c5ed
7 changed files with 366 additions and 79 deletions

View File

@ -45,7 +45,8 @@ abstract class Map {
$this->requires_js = array();
$this->requires_js[] = "include/javascript/d3.3.5.14.js";
$this->requires_js[] = "include/javascript/map/MapController.js";
$this->requires_js[] = "include/javascript/jquery.tooltipster.js";
if (!$this->loadDB()) {
$this->status = STATUS_ERROR;
}

View File

@ -12,7 +12,8 @@
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// Constructor
/*-------------------Constructor-------------------*/
var MapController = function(target) {
this._target = target;
@ -21,13 +22,20 @@ var MapController = function(target) {
this._marginConstant = 50;
}
// Atributes
/*--------------------Atributes--------------------*/
MapController.prototype._id = null;
MapController.prototype._dialogNodeMargin = 0; //To be beauty
MapController.prototype._marginConstant = 0; //To be beauty
// Methods
/*--------------------Methods----------------------*/
/*
Function init_map
Return void
This function init the map
*/
MapController.prototype.init_map = function() {
var svg = d3.select("#map svg");
@ -95,13 +103,28 @@ MapController.prototype.init_map = function() {
.attr("style", "fill: rgb(50, 50, 128);")
.attr("r", "6");
//Runs tooltipster plugin
$(document).ready(function() {
$('.tooltip').tooltipster();
});
this.init_events();
};
/*
Function init_events
Return boolean
This function init click events in the map
*/
MapController.prototype.init_events = function(principalObject) {
$(this._target + " svg *, " + this._target + " svg").on("mousedown", {map: this}, this.click_event);
}
/*
Function click_event
Return void
This function manages mouse clicks and run events in consecuence
*/
MapController.prototype.click_event = function(event) {
var self = event.data.map;
event.preventDefault();
@ -109,7 +132,7 @@ MapController.prototype.click_event = function(event) {
switch (event.which) {
case 1:
if ($(event.currentTarget).attr("class") == "node") {
self.popup_map(self, event);
self.tooltip_map(self, event);
}
break;
case 2:
@ -121,81 +144,22 @@ MapController.prototype.click_event = function(event) {
}
}
MapController.prototype.popup_map = function(self, event) {
// Node position and radius
nodeX = parseInt($(event.currentTarget).attr("cx"));
nodeY = parseInt($(event.currentTarget).attr("cy"));
nodeR = parseInt($(event.currentTarget).attr("r"));
/*
Function popup_map
Return void
This function manages nodes tooltips
*/
MapController.prototype.tooltip_map = function(self, event) {
/*------------------- PRUEBA CON TOOLTIPSTER ----------------------*/
$(this._target + " svg").after($("<div>").attr("id", "tooltipster_node"));
// Map dimensions in pixels
var map_width_with_px = $(self._target + " svg").attr("width");
var map_height_with_px = $(self._target + " svg").attr("height");
// Map dimensions in numbers
var map_width = parseInt(map_width_with_px.slice(0, map_width_with_px.length - 2));
var map_height = parseInt(map_height_with_px.slice(0, map_height_with_px.length - 2));
// Dialog dimensions
var dialog_width = 300;
var dialog_height = 200;
//To know the position of the dialog box
if (self.xOffset(map_width, nodeX, dialog_width) && self.yOffset(map_height, nodeY, dialog_height)) {
var dialogClass = "nodeDialogBottom";
var xPos = event.pageX - dialog_width + nodeR;
var yPos = event.clientY - dialog_height - nodeR - self._dialogNodeMargin;
}
else if (self.yOffset(map_height, nodeY, dialog_height)) {
var dialogClass = "nodeDialogBottom2";
var xPos = event.pageX - nodeR;
var yPos = event.clientY + -dialog_height - nodeR - self._dialogNodeMargin;
}
else if (self.xOffset(map_width, nodeX, dialog_width)) {
var dialogClass = "nodeDialogTop2";
var xPos = event.pageX - dialog_width + nodeR;
var yPos = event.clientY + nodeR + self._dialogNodeMargin;
}
else {
var dialogClass = "nodeDialogTop";
var xPos = event.pageX - nodeR;
var yPos = event.clientY + nodeR + self._dialogNodeMargin;
}
$(self._target + " svg").after($("<div>").attr("id", "dialog_popup"));
$("#dialog_popup").dialog({
dialogClass: dialogClass,
modal: false,
closeOnEscape: true,
show: {effect: 'fade', speed: 1000},
title: "Node dialog",
resizable: false,
position: [xPos,yPos],
height: dialog_height,
width: dialog_width
$('#tooltipster_node').tooltipster({
arrow: true,
autoClose: false,
multiple: true,
content: 'I\'M A FUCKING TOOLTIP!!'
});
}
/*
Function xOffset
Return boolean
This function returns true if dialog cuts map's x axis
*/
MapController.prototype.xOffset = function(map_w, node_x, dialog_w) {
if ((map_w - node_x - this._marginConstant) < dialog_w) {
return true;
}
return false;
}
/*
Function yOffset
Return boolean
This function returns true if dialog cuts map's y axis
*/
MapController.prototype.yOffset = function(map_h, node_y, dialog_h) {
if ((map_h - node_y - this._marginConstant) < dialog_h) {
return true;
}
return false;
$('#tooltipster_node').tooltipster("show");
/*-----------------------------------------------------------------*/
}

View File

@ -0,0 +1,12 @@
.tooltipster-light {
border-radius: 5px;
border: 1px solid #cccccc;
background: #ededed;
color: #666666;
}
.tooltipster-light .tooltipster-content {
font-family: Arial, sans-serif;
font-size: 14px;
line-height: 16px;
padding: 8px 10px;
}

View File

@ -0,0 +1,12 @@
.tooltipster-noir {
border-radius: 0px;
border: 3px solid #2c2c2c;
background: #fff;
color: #2c2c2c;
}
.tooltipster-noir .tooltipster-content {
font-family: 'Georgia', serif;
font-size: 14px;
line-height: 16px;
padding: 8px 10px;
}

View File

@ -0,0 +1,12 @@
.tooltipster-punk {
border-radius: 5px;
border-bottom: 3px solid #f71169;
background: #2a2a2a;
color: #fff;
}
.tooltipster-punk .tooltipster-content {
font-family: 'Courier', monospace;
font-size: 14px;
line-height: 16px;
padding: 8px 10px;
}

View File

@ -0,0 +1,12 @@
.tooltipster-shadow {
border-radius: 5px;
background: #fff;
box-shadow: 0px 0px 14px rgba(0,0,0,0.3);
color: #2c2c2c;
}
.tooltipster-shadow .tooltipster-content {
font-family: 'Arial', sans-serif;
font-size: 14px;
line-height: 16px;
padding: 8px 10px;
}

View File

@ -0,0 +1,274 @@
/* This is the default Tooltipster theme (feel free to modify or duplicate and create multiple themes!): */
.tooltipster-default {
border-radius: 5px;
border: 2px solid #000;
background: #4c4c4c;
color: #fff;
}
/* Use this next selector to style things like font-size and line-height: */
.tooltipster-default .tooltipster-content {
font-family: Arial, sans-serif;
font-size: 14px;
line-height: 16px;
padding: 8px 10px;
overflow: hidden;
}
/* This next selector defines the color of the border on the outside of the arrow. This will automatically match the color and size of the border set on the main tooltip styles. Set display: none; if you would like a border around the tooltip but no border around the arrow */
.tooltipster-default .tooltipster-arrow .tooltipster-arrow-border {
/* border-color: ... !important; */
}
/* If you're using the icon option, use this next selector to style them */
.tooltipster-icon {
cursor: help;
margin-left: 4px;
}
/* This is the base styling required to make all Tooltipsters work */
.tooltipster-base {
padding: 0;
font-size: 0;
line-height: 0;
position: absolute;
left: 0;
top: 0;
z-index: 9999999;
pointer-events: none;
width: auto;
overflow: visible;
}
.tooltipster-base .tooltipster-content {
overflow: hidden;
}
/* These next classes handle the styles for the little arrow attached to the tooltip. By default, the arrow will inherit the same colors and border as what is set on the main tooltip itself. */
.tooltipster-arrow {
display: block;
text-align: center;
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
z-index: -1;
}
.tooltipster-arrow span, .tooltipster-arrow-border {
display: block;
width: 0;
height: 0;
position: absolute;
}
.tooltipster-arrow-top span, .tooltipster-arrow-top-right span, .tooltipster-arrow-top-left span {
border-left: 8px solid transparent !important;
border-right: 8px solid transparent !important;
border-top: 8px solid;
bottom: -7px;
}
.tooltipster-arrow-top .tooltipster-arrow-border, .tooltipster-arrow-top-right .tooltipster-arrow-border, .tooltipster-arrow-top-left .tooltipster-arrow-border {
border-left: 9px solid transparent !important;
border-right: 9px solid transparent !important;
border-top: 9px solid;
bottom: -7px;
}
.tooltipster-arrow-bottom span, .tooltipster-arrow-bottom-right span, .tooltipster-arrow-bottom-left span {
border-left: 8px solid transparent !important;
border-right: 8px solid transparent !important;
border-bottom: 8px solid;
top: -7px;
}
.tooltipster-arrow-bottom .tooltipster-arrow-border, .tooltipster-arrow-bottom-right .tooltipster-arrow-border, .tooltipster-arrow-bottom-left .tooltipster-arrow-border {
border-left: 9px solid transparent !important;
border-right: 9px solid transparent !important;
border-bottom: 9px solid;
top: -7px;
}
.tooltipster-arrow-top span, .tooltipster-arrow-top .tooltipster-arrow-border, .tooltipster-arrow-bottom span, .tooltipster-arrow-bottom .tooltipster-arrow-border {
left: 0;
right: 0;
margin: 0 auto;
}
.tooltipster-arrow-top-left span, .tooltipster-arrow-bottom-left span {
left: 6px;
}
.tooltipster-arrow-top-left .tooltipster-arrow-border, .tooltipster-arrow-bottom-left .tooltipster-arrow-border {
left: 5px;
}
.tooltipster-arrow-top-right span, .tooltipster-arrow-bottom-right span {
right: 6px;
}
.tooltipster-arrow-top-right .tooltipster-arrow-border, .tooltipster-arrow-bottom-right .tooltipster-arrow-border {
right: 5px;
}
.tooltipster-arrow-left span, .tooltipster-arrow-left .tooltipster-arrow-border {
border-top: 8px solid transparent !important;
border-bottom: 8px solid transparent !important;
border-left: 8px solid;
top: 50%;
margin-top: -7px;
right: -7px;
}
.tooltipster-arrow-left .tooltipster-arrow-border {
border-top: 9px solid transparent !important;
border-bottom: 9px solid transparent !important;
border-left: 9px solid;
margin-top: -8px;
}
.tooltipster-arrow-right span, .tooltipster-arrow-right .tooltipster-arrow-border {
border-top: 8px solid transparent !important;
border-bottom: 8px solid transparent !important;
border-right: 8px solid;
top: 50%;
margin-top: -7px;
left: -7px;
}
.tooltipster-arrow-right .tooltipster-arrow-border {
border-top: 9px solid transparent !important;
border-bottom: 9px solid transparent !important;
border-right: 9px solid;
margin-top: -8px;
}
/* Some CSS magic for the awesome animations - feel free to make your own custom animations and reference it in your Tooltipster settings! */
.tooltipster-fade {
opacity: 0;
-webkit-transition-property: opacity;
-moz-transition-property: opacity;
-o-transition-property: opacity;
-ms-transition-property: opacity;
transition-property: opacity;
}
.tooltipster-fade-show {
opacity: 1;
}
.tooltipster-grow {
-webkit-transform: scale(0,0);
-moz-transform: scale(0,0);
-o-transform: scale(0,0);
-ms-transform: scale(0,0);
transform: scale(0,0);
-webkit-transition-property: -webkit-transform;
-moz-transition-property: -moz-transform;
-o-transition-property: -o-transform;
-ms-transition-property: -ms-transform;
transition-property: transform;
-webkit-backface-visibility: hidden;
}
.tooltipster-grow-show {
-webkit-transform: scale(1,1);
-moz-transform: scale(1,1);
-o-transform: scale(1,1);
-ms-transform: scale(1,1);
transform: scale(1,1);
-webkit-transition-timing-function: cubic-bezier(0.175, 0.885, 0.320, 1);
-webkit-transition-timing-function: cubic-bezier(0.175, 0.885, 0.320, 1.15);
-moz-transition-timing-function: cubic-bezier(0.175, 0.885, 0.320, 1.15);
-ms-transition-timing-function: cubic-bezier(0.175, 0.885, 0.320, 1.15);
-o-transition-timing-function: cubic-bezier(0.175, 0.885, 0.320, 1.15);
transition-timing-function: cubic-bezier(0.175, 0.885, 0.320, 1.15);
}
.tooltipster-swing {
opacity: 0;
-webkit-transform: rotateZ(4deg);
-moz-transform: rotateZ(4deg);
-o-transform: rotateZ(4deg);
-ms-transform: rotateZ(4deg);
transform: rotateZ(4deg);
-webkit-transition-property: -webkit-transform, opacity;
-moz-transition-property: -moz-transform;
-o-transition-property: -o-transform;
-ms-transition-property: -ms-transform;
transition-property: transform;
}
.tooltipster-swing-show {
opacity: 1;
-webkit-transform: rotateZ(0deg);
-moz-transform: rotateZ(0deg);
-o-transform: rotateZ(0deg);
-ms-transform: rotateZ(0deg);
transform: rotateZ(0deg);
-webkit-transition-timing-function: cubic-bezier(0.230, 0.635, 0.495, 1);
-webkit-transition-timing-function: cubic-bezier(0.230, 0.635, 0.495, 2.4);
-moz-transition-timing-function: cubic-bezier(0.230, 0.635, 0.495, 2.4);
-ms-transition-timing-function: cubic-bezier(0.230, 0.635, 0.495, 2.4);
-o-transition-timing-function: cubic-bezier(0.230, 0.635, 0.495, 2.4);
transition-timing-function: cubic-bezier(0.230, 0.635, 0.495, 2.4);
}
.tooltipster-fall {
top: 0;
-webkit-transition-property: top;
-moz-transition-property: top;
-o-transition-property: top;
-ms-transition-property: top;
transition-property: top;
-webkit-transition-timing-function: cubic-bezier(0.175, 0.885, 0.320, 1);
-webkit-transition-timing-function: cubic-bezier(0.175, 0.885, 0.320, 1.15);
-moz-transition-timing-function: cubic-bezier(0.175, 0.885, 0.320, 1.15);
-ms-transition-timing-function: cubic-bezier(0.175, 0.885, 0.320, 1.15);
-o-transition-timing-function: cubic-bezier(0.175, 0.885, 0.320, 1.15);
transition-timing-function: cubic-bezier(0.175, 0.885, 0.320, 1.15);
}
.tooltipster-fall-show {
}
.tooltipster-fall.tooltipster-dying {
-webkit-transition-property: all;
-moz-transition-property: all;
-o-transition-property: all;
-ms-transition-property: all;
transition-property: all;
top: 0px !important;
opacity: 0;
}
.tooltipster-slide {
left: -40px;
-webkit-transition-property: left;
-moz-transition-property: left;
-o-transition-property: left;
-ms-transition-property: left;
transition-property: left;
-webkit-transition-timing-function: cubic-bezier(0.175, 0.885, 0.320, 1);
-webkit-transition-timing-function: cubic-bezier(0.175, 0.885, 0.320, 1.15);
-moz-transition-timing-function: cubic-bezier(0.175, 0.885, 0.320, 1.15);
-ms-transition-timing-function: cubic-bezier(0.175, 0.885, 0.320, 1.15);
-o-transition-timing-function: cubic-bezier(0.175, 0.885, 0.320, 1.15);
transition-timing-function: cubic-bezier(0.175, 0.885, 0.320, 1.15);
}
.tooltipster-slide.tooltipster-slide-show {
}
.tooltipster-slide.tooltipster-dying {
-webkit-transition-property: all;
-moz-transition-property: all;
-o-transition-property: all;
-ms-transition-property: all;
transition-property: all;
left: 0px !important;
opacity: 0;
}
/* CSS transition for when contenting is changing in a tooltip that is still open. The only properties that will NOT transition are: width, height, top, and left */
.tooltipster-content-changing {
opacity: 0.5;
-webkit-transform: scale(1.1, 1.1);
-moz-transform: scale(1.1, 1.1);
-o-transform: scale(1.1, 1.1);
-ms-transform: scale(1.1, 1.1);
transform: scale(1.1, 1.1);
}