From 6a44b7886aa3d7bd2c78eb5f7873d12cb21ec246 Mon Sep 17 00:00:00 2001 From: Artem Zubkov Date: Thu, 10 Jan 2013 18:14:54 +0700 Subject: [PATCH 1/2] Update js/gexfjs.js Fast fix Issue #6 --- js/gexfjs.js | 47 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/js/gexfjs.js b/js/gexfjs.js index da07c1d..3277d6c 100644 --- a/js/gexfjs.js +++ b/js/gexfjs.js @@ -438,7 +438,15 @@ function loadGraph() { _r = _col.attr("r"), _g = _col.attr("g"), _b = _col.attr("b"), - _attr = _n.find("attvalue"); + _attr = _n.find("attvalue"), + _img = _n.attr("img_url") //name of param which contains data about img url; + + _d.img = new Image(); + _d.img.onload = (funciont(_nd) { return function() { _nd.loaded = true; }})(_d); + //_d.img.onerror + _d.src = _img; + + _d.coords = { base : { x : _deltax + _echelle * _x, @@ -670,11 +678,18 @@ function traceMap() { if (i != _centralNode) { _d.coords.real = ( ( GexfJS.params.useLens && GexfJS.mousePosition ) ? calcCoord( GexfJS.mousePosition.x , GexfJS.mousePosition.y , _d.coords.actual ) : _d.coords.actual ); _d.isTag = ( _tagsMisEnValeur.indexOf(parseInt(i)) != -1 ); - GexfJS.ctxGraphe.beginPath(); - GexfJS.ctxGraphe.fillStyle = ( ( _tagsMisEnValeur.length && !_d.isTag ) ? _d.color.gris : _d.color.base ); - GexfJS.ctxGraphe.arc( _d.coords.real.x , _d.coords.real.y , _d.coords.real.r , 0 , Math.PI*2 , true ); - GexfJS.ctxGraphe.closePath(); - GexfJS.ctxGraphe.fill(); + + if (_d.img && _d.imgloaded) { + //draw image on canvas + GexfJS.ctxGraphe.drawImage(_d.img, _d.coords.real.x - _d.img.width / 2, _d.coords.real.y - _d.img.height / 2); + } + else { + GexfJS.ctxGraphe.beginPath(); + GexfJS.ctxGraphe.fillStyle = ( ( _tagsMisEnValeur.length && !_d.isTag ) ? _d.color.gris : _d.color.base ); + GexfJS.ctxGraphe.arc( _d.coords.real.x , _d.coords.real.y , _d.coords.real.r , 0 , Math.PI*2 , true ); + GexfJS.ctxGraphe.closePath(); + GexfJS.ctxGraphe.fill(); + } } } } @@ -706,12 +721,18 @@ function traceMap() { } if (_centralNode != -1) { - GexfJS.ctxGraphe.fillStyle = _dnc.color.base; - GexfJS.ctxGraphe.beginPath(); - GexfJS.ctxGraphe.arc( _dnc.coords.real.x , _dnc.coords.real.y , _dnc.coords.real.r , 0 , Math.PI*2 , true ); - GexfJS.ctxGraphe.closePath(); - GexfJS.ctxGraphe.fill(); - GexfJS.ctxGraphe.stroke(); + if (_dnc.img && _dnc.imgloaded) { + //draw image on canvas + GexfJS.ctxGraphe.drawImage(_dnc.img, _dnc.coords.real.x - _dnc.img.width / 2, _dnc.coords.real.y - _dnc.img.height / 2); + } + else { + GexfJS.ctxGraphe.fillStyle = _dnc.color.base; + GexfJS.ctxGraphe.beginPath(); + GexfJS.ctxGraphe.arc( _dnc.coords.real.x , _dnc.coords.real.y , _dnc.coords.real.r , 0 , Math.PI*2 , true ); + GexfJS.ctxGraphe.closePath(); + GexfJS.ctxGraphe.fill(); + GexfJS.ctxGraphe.stroke(); + } var _fs = Math.max(_limTxt + 2, _dnc.coords.real.r * _textSizeFactor) + 2; GexfJS.ctxGraphe.font = "bold " + Math.floor( _fs )+"px Arial"; GexfJS.ctxGraphe.textAlign = "center"; @@ -939,4 +960,4 @@ $(document).ready(function() { } return false; }); -}); \ No newline at end of file +}); From 30fa265386a6c49968689e702d0300a4ccf632a6 Mon Sep 17 00:00:00 2001 From: Artem Zubkov Date: Fri, 11 Jan 2013 11:27:54 +0700 Subject: [PATCH 2/2] Update js/gexfjs.js fix #6 added: drawing image on node --- js/gexfjs.js | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/js/gexfjs.js b/js/gexfjs.js index 3277d6c..df5a1ed 100644 --- a/js/gexfjs.js +++ b/js/gexfjs.js @@ -439,13 +439,18 @@ function loadGraph() { _g = _col.attr("g"), _b = _col.attr("b"), _attr = _n.find("attvalue"), - _img = _n.attr("img_url") //name of param which contains data about img url; + _shape = _n.find("viz\\:shape,shape"), + _img = _shape ? _shape.attr("uri") : 0; //name of param which contains data about img url - _d.img = new Image(); - _d.img.onload = (funciont(_nd) { return function() { _nd.loaded = true; }})(_d); - //_d.img.onerror - _d.src = _img; - + if (_shape && _img) { + _d.img = new Image(); + _d.img.onload = (function(_nd) { return function() { + _nd.imgloaded = true; + GexfJS.params.redraw = true; + }})(_d); + //_d.img.onerror + _d.img.src = _img; + } _d.coords = { base : { @@ -585,6 +590,7 @@ function traceMap() { for (var i in GexfJS.params) { _identical = _identical && ( GexfJS.params[i] == GexfJS.oldParams[i] ); } + GexfJS.params.redraw = false; if (_identical) { return; } else { @@ -681,7 +687,7 @@ function traceMap() { if (_d.img && _d.imgloaded) { //draw image on canvas - GexfJS.ctxGraphe.drawImage(_d.img, _d.coords.real.x - _d.img.width / 2, _d.coords.real.y - _d.img.height / 2); + GexfJS.ctxGraphe.drawImage(_d.img, _d.coords.real.x - _d.coords.real.r / 2, _d.coords.real.y - _d.coords.real.r / 2, _d.coords.real.r, _d.coords.real.r); } else { GexfJS.ctxGraphe.beginPath(); @@ -723,7 +729,7 @@ function traceMap() { if (_centralNode != -1) { if (_dnc.img && _dnc.imgloaded) { //draw image on canvas - GexfJS.ctxGraphe.drawImage(_dnc.img, _dnc.coords.real.x - _dnc.img.width / 2, _dnc.coords.real.y - _dnc.img.height / 2); + GexfJS.ctxGraphe.drawImage(_dnc.img, _dnc.coords.real.x - _dnc.coords.real.r / 2, _dnc.coords.real.y - _dnc.coords.real.r / 2, _dnc.coords.real.r, _dnc.coords.real.r); } else { GexfJS.ctxGraphe.fillStyle = _dnc.color.base;