Difficulty in implementing cytoscape.js-qtip - qtip2

Part I
I am finding it difficult to replicate the functionality of cytoscape.js-qtip in my code.
Here is the JavaScript Code:
$(function()
{
$('#cy').cytoscape
({
style: cytoscape.stylesheet()
.selector('node').css({'content': 'data(name)'})
.selector('edge').css({'target-arrow-shape': 'triangle'})
.selector(':selected').css({'line-color': 'black'})
elements: {
nodes: [
{ data: { id: '1', name: '1' } },
{ data: { id: '2', name: '2' } },
],
edges: [{ data: { source: '1', target: '2' } }]
},
layout: { name: 'grid'},
ready: function()
{
window.cy = this;
cy.panzoom({});
cy.cxtmenu
({ commands:[{ content: '<span class="fa fa-flash fa-2x"></span>',
select: function() {console.log( this.id() );}
},
{ content: '<span class="fa fa-star fa-li "></span>',
select: function(){ console.log( this.data('name') );}
},
{ content: 'Text',
select: function(){ console.log( this.position() );}
}
]});
cy.elements().qtip
({
content: function(){ return 'this is tool tip for ' + this.id() },
position: { my: 'top center',at: 'bottom center'},
style: {classes: 'qtip-bootstrap',tip: {width: 16,height: 8}}
});
cy.qtip
({
content: 'tool tip about the core of the layout',
position: { my: 'top center', at: 'bottom center'},
show: { cyBgOnly: true},
style: {classes: 'qtip-bootstrap',tip: {width: 16,height: 8}}
});
}
});
});
I have already gone through these threads:
displaying qtip hover on outer nodes of cytoscape.js graph
how to use tooltip javascript library qtip.js together with cytoscape.js
how to add tooltip on mouseover event on nodes in graph with cytoscape.js
referencing cytoscape elements from external code
cytoscape.js force-directed layouts and node placement
Errors shown in Browser Console:
TypeError: qtip.$domEle.qtip is not a function
File : cytoscape.js-qtip
Line : 88
Col : 1
Code : qtip.$domEle.qtip( opts );
Part II
Also when I am trying the example provided over here, I see no qtip on tapping.
Note: I tried on both Mozilla Firefox & Google Chrome.
And encountered the following Errors in the Browser Console:
Mozilla Firefox
GET http://cdnjs.cloudflare.com/ajax/libs/qtip2/2.2.0/jquery.qtip.min.js
[HTTP/1.1 503 Service Unavailable 0ms]
TypeError: qtip.$domEle.qtip is not a function
File : cytoscape.js-qtip
Line : 97
Col : 6
Google Chrome:
GET https://cdn.rawgit.com/cytoscape/cytoscape.js-qtip/70964f0306e770837dbe2b81197c12fdc7804e38/cytoscape-qtip.js runner-3.25.19.min.js:1
TypeError: Object [object Object] has no method 'qtip'
at HTMLDocument. (http://null.jsbin.com/runner:27:12)
at j (http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js:2:27244)
at Object.k.fireWith [as resolveWith] (http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js:2:28057)
at Function.m.extend.ready (http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js:2:29891)
at HTMLDocument.J (http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js:2:30257) runner-3.25.19.min.js:1
Uncaught TypeError: Object [object Object] has no method 'qtip' runner:27
(anonymous function) runner:27
j
k.fireWith
m.extend.ready

Answer to Part I
The actual mistake was in the order of importing of JavaScript within the HTML file.
Mistake:
<script src="jquery.qtip.js"></script>
<script src="jquery-2.0.3.js"></script>
Correction:
<script src="jquery-2.0.3.js"></script>
<script src="jquery.qtip.js"></script>
Conclusion:
Correct Order of importing
jquery-2.0.3.js
jquery.qtip.js
Reason:
The order of importing/ loading is important as jquery.qtip.js is dependent on jquery-2.0.3.js.
For better understanding:
Read : cytoscape.js-qtip#description

Related

Expected array for `items` polymer in my console

I'm learning Polymer 1.8 and I'm trying to get data from an api.
after that i want to bind data from my ontap() function with a dom-repeate, but I'm getting a weird error in the console:
[dom-repeat::dom-repeat]: expected array for items, found [{"requestnum":"1045","orgid":"EAGLENA"},{"requestnum":"1046","orgid":"EAGLENA"},{"requestnum":"1047","orgid":"EAGLENA"},{"requestnum":"1048","orgid":"EAGLENA"},{"requestnum":"1049","orgid":"EAGLENA"}]
i can't solve this problem could any one help me?
What is wrong in this code????
im using polymer 1.8
*this is my html file maximo-test-card.html:
<dom-module id="maximo-test-card">
<template>
<template is="dom-repeat" items="{{hi}}">
<li>
<span>{{item.requestnum}}</span>
</li>
</template>
<div>{{hi}}</div>
<iron-ajax
id="requestRepos"
headers='{"Content-Type": "application/json", "Accept": "someAccept", "Authorization": "someAuthorizationToken"}'
url="http://vaganet.vaganet.fr:9080/maximo/oslc/os/mxinvres?oslc.select=*"
handle-as="json"
on-response="ontap"> </iron-ajax> </template>
<script src="maximo-test-card.js"></script>
</dom-module>
*this is my js file maximo-test-card.js:
Polymer({
is: 'maximo-test-card',
properties: {
repos: {
type: Array
},
githubrepository:{
type: Array
},
hi:{
type: Array,
},
},
ready: function () {
this.$.requestRepos.generateRequest();
//console.log(hi)
//this.name=hi
},
ontap: function (data) {
this.repos = data.detail.response.member;
hi = []
for (var i = 0; i < 5; i++) {
hi[i] = {"requestnum":this.repos[i].requestnum,"orgid":this.repos[i].orgid}
}
this.hi = JSON.stringify(hi)
alert(this.hi);
return this.hi;
},
});

Saving layer from OpenLayer 3 Map created by user

I'm trying to correctly save an OpenLayer 3 Map layer created by a user in order to display it another map using geoJSON, but I'm having troubles with this.
On the client side I save the dinamic layer in this function:
function addInteractions() {
draw = new ol.interaction.Draw({
source: source,
type: typeSelect.value
});
draw.on("drawend", function(e) {
var f = e.feature;
features.push(f);
geoJson = format.writeFeatures(features);
console.log(geoJson);
document.getElementById('js-textarea').value = geoJson;
});
map.addInteraction(draw);
snap = new ol.interaction.Snap({source: source});
map.addInteraction(snap);
}
Then the geoJSON object is saved into a .json file, but when I try to display it, it doesn't appear on the map.
Here his my display function:
var geoDataUrl = '/data/' + '{{percorso._id}}' + '.json';
var vectorLayer = new ol.layer.Vector({
source: new ol.source.Vector({
url: geoDataUrl,
format: new ol.format.GeoJSON()
}),
style: new ol.style.Style({
fill: new ol.style.Fill({
color: 'rgba(255, 255, 255, 0.2)'
}),
stroke: new ol.style.Stroke({
color: '#ffcc33',
width: 2
}),
image: new ol.style.Circle({
radius: 7,
fill: new ol.style.Fill({
color: '#ffcc33'
})
})
})
});
var raster = new ol.layer.Tile({
source: new ol.source.OSM()
});
var map = new ol.Map({
layers: [raster, vectorLayer],
target: 'map',
view: new ol.View({
center: {{#if percorso.mapCenter}}[{{percorso.mapCenter}}] {{else}} ol.proj.transform([9.688053, 45.362760], 'EPSG:4326', 'EPSG:3857'){{/if}},
zoom: {{#if percorso.zoomLevel}}{{percorso.zoomLevel}} {{else}} 13{{/if}}
})
});
I also tested the display function with other layers (for example the provided one on the OpenLayer examples website ) and it works fine
On the server side I save the geoJSONobject with this function, where oggetto_mappa is the dinamic geoJSON object:
var jsonMappa = JSON.stringify(eval("(" + oggetto_mappa + ")"));
require("fs").writeFile("./public/data/" + id_perc + ".json", jsonMappa, 'utf8', function(f_err) {
if(f_err)
console.log(f_err);
});
For refernce this is what my function saves onto the .json file:
{
"type":"FeatureCollection",
"features":[
{
"type":"Feature",
"id" : "aa",
"geometry":
{
"type":"LineString",
"coordinates":[
[1073328.751180445,5680150.227413875],
[1077857.6451063417,5682481.556776573],
[1070385.9255914658,5679156.546046168],
[1076825.7452244917,5680226.66444216],
[1073328.751180445,5680169.336670946]
]
},
"properties":null
},
{
"type":"Feature",
"id" : "ab",
"geometry":
{
"type":"LineString",
"coordinates":[
[1073328.751180445,5680169.336670946],
[1071628.0273010998,5677130.96479661]
]
},
"properties":null}
]
}
To get things working, replace
geoJson = format.writeFeatures(features)
with
geoJson = format.writeFeatures(features, {featureProjection: 'EPSG:3857'})
You may wonder why?
When you draw in OpenLayers, you are drawing in the projection of the map (the default is EPSG:3857) whereas when you consume a GeoJSON the expected projection is EPSG:4326.
See the API documentation from ol.format.GeoJSON writeFeatures to understand better
Some additional informations:
when you consume the GeoJSON from your drawing as the coordinates are not in decimal degrees (EPSG:4326) but in meters (EPSG:3857)
the order of magnitude for coordinates is different (millions for EPSG:3857 and less than some hundred for EPSG:4326) without accounting for the positive/negative coordinates

Getting Kendo UI, DataViz Map, & Angular 2 To Work Together

I'm using Kendo UI & Angular 2 in a project, but cannot for the life of me seem to get the map widget to work with shapefiles in Angular 2.
It looks like I have to integrate with jQuery since the map component is not listed as an Angular 2 component yet. So, I've followed the instructions outlined here. However, it still doesn't seem to work. Here's what I currently have:
exampe.module.ts
...
import "#progress/kendo-ui";
...
example-map.html
<div #kendoMap style="height: 1000px;">
</div>
example-map.component.ts:
import { AfterViewInit, Component, ElementRef, OnDestroy, ViewChild } from '#angular/core';
declare var kendo: any;
#Component({
selector: 'example-map',
templateUrl: './example-map.html'
})
export class ExampleComponent implements AfterViewInit, OnDestroy {
#ViewChild('kendoMap')
kendoMap: ElementRef;
constructor () { }
ngAfterViewInit() {
const element = kendo.jQuery(this.kendoMap.nativeElement);
// This line throws an error
element.kendoMap({
controls: {
attribution: false,
navigator: false,
zoom: false
},
zoom: 7,
center: [32.7767, 96.7970],
layers: [
{
type: 'tile',
zIndex: -1,
urlTemplate: "https://#= subdomain #.tile.openstreetmap.org/#= zoom #/#= x #/#= y #.png"
},
{
type: 'shape',
style: { fill: { opacity: 0.7 } }
// shapefile layer data will be added here later by ajax
}
],
markers: []
});
}
ngOnDestroy() { kendo.destroy(this.kendoMap.nativeElement); }
}
This was throwing an error:
TypeError: Function has non-object prototype 'undefined' in instanceof check.
To fix that, I included the version of jQuery they were using in my index.html file:
<script src="http://code.jquery.com/jquery-3.3.1.slim.min.js"
integrity="sha256-3edrmyuQ0w65f8gfBsqowzjJe2iM6n0nKciPUp8y+7E=" crossorigin="anonymous"></script>
But now it's barfing about access 'width' off of something undefined.
ExampleComponent.html ERROR TypeError: Cannot read property 'width' of undefined
at init.translate (http://localhost:3000/vendor.bundle.js:89908:98)
at init.translate (http://localhost:3000/vendor.bundle.js:262525:25)
at init._translateSurface (http://localhost:3000/vendor.bundle.js:224872:31)
at init._reset (http://localhost:3000/vendor.bundle.js:224758:19)
at init.proxy (http://localhost:3000/vendor.bundle.js:52589:13)
at init.trigger (http://localhost:3000/vendor.bundle.js:4780:34)
at init.window.kendo.window.kendo.devtools.kendo.ui.Widget.trigger (eval at _translateSurface (http://localhost:3000/vendor.bundle.js:224869:27), <anonymous>:587:33)
at init._reset (http://localhost:3000/vendor.bundle.js:337450:19)
Has anyone hit this before or know a great tutorial to use Kendo Maps w/ Angular 2+ ?
The issue with this was the order in which the component was rendering versus what was in the DOM. Moving the initialization into a jQuery block resolved the issue, like so:
ngAfterViewInit() {
kendo.jQuery(() => {
const element = kendo.jQuery(this.kendoMap.nativeElement);
...
});
}

Restrict qtip2 inside a container

How to keep all the qtips inside a container (I have already tried position.container, position.viewport and position.adjust.method) without any luck, my best guess is that I am not using them correctly.
Update:1 I have created a sample app with more details on below url
http://secure.chiwater.com/CodeSample/Home/Qtip
Update:2 I have created jsfiddle link too. http://jsfiddle.net/Lde45mmv/2/
Please refer below screen shot for layout details.
I am calling the area shown between two lines as $container in my js code.
So far I have tried tweaking viewport, adjust method but nothing helped. I am hoping this is possible and I would greatly appreciate any help.
Below is my javascript code which creates qtip2.
//Now create tooltip for each of this Comment number
$('#cn_' + num).qtip({
id: contentElementID,
content: {
text: .....
var $control = $('<div class="qtip-parent">' +
' <div class="qtip-comment-contents">......</div>' +
' <div class="clearfix"></div>' +
' <div class="qtip-footer"><span class="qtip-commenter">...</span><span class="pull-right">...</span></div>' +
'</div>'
);
return $control;
},
button: false
},
show: 'click',
hide: {
fixed: true,
event: 'unfocus'
},
position: {
my: 'top right',
at: 'bottom right',
target: $('#cn_' + num),
container: $container,
//viewport: true,
adjust: { method: 'shift none' }
},
style: {
tip: {
corner: true,
mimic: 'center',
width: 12,
height: 12,
border: true, // Detect border from tooltip style
//offset: 25
},
classes: 'qtip-comment'
},
events: {
show: function (event, api) {
...
},
hide: function (event, api) {
...
}
}
});
Example of jalopnik page which shows what I am looking for (FWIW jalopnik example doesn't use qtip2).
I don't think qtip API supports this functionality. I ended up re-positioning the tooltip on visible event.
I have updated the demo page and jsfiddle link below is code for doing this.
events: {
visible: function (event, api) {
var $qtipControl = $(event.target);
$qtipControl.css({ 'left': contentPosition.left + "px" });
var $qtipTipControl = $qtipControl.find(".qtip-tip");
var $target = api.get("position.target");
$qtipTipControl.css({ "right": 'auto' });
//I am using jquery.ui position
$qtipTipControl.position({
my: "center top",
at: "center bottom",
of: $target
});
}
}
Problem with this approach is that there is noticeable jump when I re-position the qTip. But in lack of any other option for time being I will settle with this.
The ideal approach would be to allow callback method thru position.adjust currently it only supports static values for x and y, if a method was allowed here it would make things much smoother.

options is not defined in qTip2

I've got Uncaught ReferenceError: options is not defined.
Here is the code:
// Create the tooltips only when document ready
$(document).ready(function()
{
// MAKE SURE YOUR SELECTOR MATCHES SOMETHING IN YOUR HTML!!!
$('a').qtip({
content: {
title: {
text: 'text',
button: 'close'
},
text: 'asfaf'
},
hide: {
fixed: true,
delay: 300
},
position: {
my: 'left center',
at: 'right center',
target: 'event'
}
});
});
You can also visit http://jsfiddle.net/H4aTZ/2/ .
Apparently there is a problem regarding the title and position working together. Probably they are going to release a update soon.
Meanwhile, if you use nightly version it actually works :)
http://qtip2.com/v/nightly/

Resources